From 1248283536 at qq.com Mon Aug 1 00:20:13 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Mon, 1 Aug 2011 12:20:13 +0800 Subject: how to solve it? Message-ID: from matplotlib.matlab import * Traceback (most recent call last): File "", line 1, in ImportError: No module named matlab -------------- next part -------------- An HTML attachment was scrubbed... URL: From ghodmode at ghodmode.com Mon Aug 1 00:56:38 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Mon, 1 Aug 2011 12:56:38 +0800 Subject: Spam Message-ID: I've noticed that python-list gets significantly more spam than the other lists I subscribe to. There's an example below. I'm wondering how the list is managed. Can anyone post, or only members? I've picked the email addresses of the list managers out of the list info page, but I wonder if you guys have enough time to skim the list and boot offending members. If not, is there someone who is active on the list that you could delegate administration privileges to? Maybe someone who has been an active member for a long time? I'm willing, but probably not qualified. I've been lurking on the list for a while, but I don't contribute much because I'm not very proficient with Python. Thank you. -- Ghodmode http://www.ghodmode.com/blog ---------- Forwarded message ---------- From: Ashraf Ali Date: Mon, Aug 1, 2011 at 10:54 AM Subject: Hello My Sweet Friends. To: python-list at python.org Hello Friends. How are you all? Please Visit the following link if you know about Pakistan and what happening in the world. http://bollywoodactresseshotpictures.blogspot.com/ http://jobopportunitiesinpakistan.blogspot.com/ http://hotfemaletennisplayershotphotos.blogspot.com/ http://watchonlineindianmovies.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list From tkjthingone at gmail.com Mon Aug 1 01:04:10 2011 From: tkjthingone at gmail.com (Ira Gray) Date: Sun, 31 Jul 2011 22:04:10 -0700 Subject: Quick question about threads and interpreters. Message-ID: Lets say I have a program that is running a python interpreter in the main thread. I come along, write a .DLL and throw it into the program. My .dll has its own thread (right?), separate from the main thread, and then makes a pyrun_simplestring call to the pythonxx.dll. The pyrun_simplestring call attempts to make contact with a function in the original python program. In short, I'm attempting to leverage existing functionality in the original python program from my .DLL. I'm sure that sounds confusing, so maybe: PythonInterpreter_MainThread is running some SourceCode, MyDLL_PyRun_SimpleString_OtherThread makes call(?) to the same SourceCode. Now, my question is: What happens? Is another python interpreter instance created in my .dll thread to handle that call? is my call 'separate' from the main thread interpreter? I'm hoping someone can point me towards some material to better understand what might happen if I did what I outlined above. It's a small school project (not homework, just a "hey, remember when I asked you about blahblah, well I got it working!") and I'd appreciate any guidance I could get into the dark arts of multiple threads and how they relate to python interpreters, and if multiple python interpreters are created (one for each thread) how making calls to the same code works. Thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 1 01:50:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 06:50:16 +0100 Subject: Spam In-Reply-To: References: Message-ID: On Mon, Aug 1, 2011 at 5:56 AM, Ghodmode wrote: > I'm willing, but probably not qualified. ?I've been lurking on the > list for a while, but I don't contribute much because I'm not very > proficient with Python. > I don't see Python proficiency as a prerequisite for recognizing spammers :) If you are willing to take on the job, I would support your application for the power to do it. Chris Angelico From rosuav at gmail.com Mon Aug 1 01:57:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 06:57:41 +0100 Subject: Quick question about threads and interpreters. In-Reply-To: References: Message-ID: On Mon, Aug 1, 2011 at 6:04 AM, Ira Gray wrote: > I come along, write a .DLL and throw it into the program. My .dll has its > own thread (right?), Not unless you actually create one. A DLL is simply a puddle of code; the application calls your code, you do whatever you do, you return. At no time will this start another thread, unless you explicitly do so. I think the easiest way to do what you're talking about is to keep it all on the same thread, and then call back into Python. Use the same global and local dictionaries, and then the Python namespace will be common across both your original code and the code your DLL is invoking - which will allow you to call that "existing functionality" you referred to. You will have to be careful to ensure that your DLL calls into the exact same Python library that the main application is. This might be a bit tricky, if you're not 100% sure of where your DLL is going to be called from. It might be easier and safer to have your parent program actually provide a function pointer to the DLL, which the DLL can then use to call on Python; that way, there's no direct linkage from your DLL to the Python library. Chris Angelico From clp2 at rebertia.com Mon Aug 1 02:05:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jul 2011 23:05:04 -0700 Subject: Spam In-Reply-To: References: Message-ID: On Sun, Jul 31, 2011 at 9:56 PM, Ghodmode wrote: > I've noticed that python-list gets significantly more spam than the > other lists I subscribe to. ?There's an example below. > > I'm wondering how the list is managed. ?Can anyone post, or only > members? Since we're gatewayed to USENET's comp.lang.python anyway, I'd strongly suspect the former. So unfortunately, I doubt your idea could be implemented short of making the list moderated (very unlikely to happen due to the level of activity) or disabling the gateway (again unlikely due to historical momentum and USENET dinosaurs). I understand that there are spam filters in place though, so it might be worth asking that they be tweaked. (e.g. I doubt there are many legit posts involving Bollywood.) >?I've picked the email addresses of the list managers out of > the list info page, but I wonder if you guys have enough time to skim > the list and boot offending members. ?If not, is there someone who is > active on the list that you could delegate administration privileges > to? ?Maybe someone who has been an active member for a long time? > > I'm willing, but probably not qualified. ?I've been lurking on the > list for a while, but I don't contribute much because I'm not very > proficient with Python. > > Thank you. > > -- > Ghodmode > http://www.ghodmode.com/blog > > > ---------- Forwarded message ---------- > From: Ashraf Ali And off to abuse at gmail.com I dash. Fsck you Mr. Ali. (Yeah, not their real name, I know. Still worth reporting such accounts.) Cheers, Chris > Date: Mon, Aug 1, 2011 at 10:54 AM > Subject: Hello My Sweet Friends. > To: python-list at python.org > > > Hello Friends. > How are you all? > Please Visit the following link if you know about Pakistan and what > happening in the world. P.S. Please redact the actual spam links next time so that they don't get further Google juice. From greg.ewing at canterbury.ac.nz Mon Aug 1 02:25:35 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:25:35 +1200 Subject: What's in a name? In-Reply-To: References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> Message-ID: <99mv71F594U1@mid.individual.net> Andrew Berg wrote: > Well of course. All the good names are taken. :P > I even came up with cavelib and it was taken ( > http://www.mechdyne.com/cavelib.aspx ). A couple of ideas that don't seem to turn up anything software-related: Flummux Flavius -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 1 02:29:12 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:29:12 +1200 Subject: Deeply nested dictionaries - should I look into a database or am I just doing it wrong? In-Reply-To: References: Message-ID: <99mvdqF6nqU1@mid.individual.net> Andrew Berg wrote: > I have a method that writes the data to disk, but at this point, I don't > see any problems with just pickling the class instance. Just keep in mind that if you're not careful, pickles can end up being tied more closely that you would like to various internal details of your program, such as the precise names of the classes involved and which modules they live in. -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 1 02:34:47 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:34:47 +1200 Subject: Spam In-Reply-To: References: Message-ID: <99mvoaF8q8U1@mid.individual.net> Chris Rebert wrote: > On Sun, Jul 31, 2011 at 9:56 PM, Ghodmode wrote: > >>I'm wondering how the list is managed. Can anyone post, or only >>members? > > Since we're gatewayed to USENET's comp.lang.python anyway, I'd > strongly suspect the former. You may get a better experience by reading the usenet group instead, and doing it through a good news site. I'm using news.individual.de, and seeing near enough to zero spam on comp.lang.python, so they must be doing a good job of filtering. -- Greg From steve+comp.lang.python at pearwood.info Mon Aug 1 04:11:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 18:11:16 +1000 Subject: Spam References: Message-ID: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Ghodmode wrote: > I've noticed that python-list gets significantly more spam than the > other lists I subscribe to. There's an example below. Thanks for that! I missed it the first time, so it is very helpful for you to forward it. It's especially helpful that you included all the spammer's URLs, as that will help improve their Google page ranks. I'm sure the spammer will thank you for your assistance. -- Steven From tlikonen at iki.fi Mon Aug 1 04:19:49 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Mon, 01 Aug 2011 11:19:49 +0300 Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877h6xzgpm.fsf@mithlond.arda> * 2011-07-30T10:57:29+10:00 * Steven D'Aprano wrote: > Teemu Likonen wrote: >> Pathnames and the separator for pathname components should be >> abstracted away, to a pathname object. > > Been there, done that, floundered on the inability of people to work > out the details. > > http://www.python.org/dev/peps/pep-0355/ I'm very much a Lisp person and obviously got the idea of pathname objects from Common Lisp. Lazily I'm also learning Python too but at the moment I can't comment on the details of that PEP. Yet, generally I think that's the way to improve pathnames, not the "rantinrick's". From rosuav at gmail.com Mon Aug 1 04:41:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 09:41:11 +0100 Subject: Question In-Reply-To: References: Message-ID: On Sun, Jul 31, 2011 at 12:38 AM, Camilo Andres Roca Duarte wrote: > $ python myfunctions.py > SyntaxError: invalid syntax > This is an error from Python, so it probably means something is wrong in your .py file. Check the contents of the file with 'cat myfunctions.py'. Is the first line the one that starts 'def is_divisible', and is the last line 'doctest.testmod()'? If not, you might have picked up some extra junk that Python can't understand. You say it works in a separate window. Does this mean inside IDLE? It's possible you have two versions of Python installed somehow. What does this display: $ python -V If it doesn't say Python 2.7.2, then you already had an older Python. All the best! Chris Angelico From bahamutzero8825 at gmail.com Mon Aug 1 04:54:06 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 01 Aug 2011 03:54:06 -0500 Subject: Question In-Reply-To: References: Message-ID: <4E3669AE.4070301@gmail.com> On 2011.07.30 06:38 PM, Camilo Andres Roca Duarte wrote: > $ python myfunctions.py > SyntaxError: invalid syntax It helps to include the full traceback. If we don't know the code that caused the error, it's pretty hard to say what went wrong, especially with an exception as broad as SyntaxError. It's easier to ignore extra information than it is to extrapolate missing information. Also, please use more specific subject lines. That way, others know whether it's worth their time to read the message. Some even ignore all messages with generic subject lines completely. It also makes your message easier to find if you ever need to search for it later. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From steve+comp.lang.python at pearwood.info Mon Aug 1 04:55:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 18:55:32 +1000 Subject: Question References: Message-ID: <4e366a05$0$29968$c3e8da3$5496439d@news.astraweb.com> Camilo Andres Roca Duarte wrote: > Hello > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > Python version. The problem is that anytime I try to run a script from the > Python Shell it returns an error message. I am new using python so I am > not sure what to do since what I'm typing in the shell is in a > BegginersTutorial. > > $ python myfunctions.py > SyntaxError: invalid syntax I would be very surprised if that is the real error message you get. I would expect something like this: [steve at sylar ~]$ python test.py File "test.py", line 1 def func: ^ SyntaxError: invalid syntax Note that the error shows the line that is bad, and puts an up-arrow ^ directly under where it goes bad. Please COPY and PASTE the FULL error. Do not re-type it from memory, summarise it, put it in your own words, or otherwise change it in any way. -- Steven From chenjii at gmail.com Mon Aug 1 05:11:16 2011 From: chenjii at gmail.com (jc) Date: Mon, 1 Aug 2011 02:11:16 -0700 (PDT) Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR Message-ID: # Get Fibonacci Value # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) # # n = 900 is OK # n = 1000 is ERROR , Why # # What Wrong? # cache = [] def fibo( n ): try: if cache[n] != -1: return cache[n] else: if 0 == n: r = 0 elif 1 == n: r = 1 else: r = fibo(n-1) + fibo(n-2) cache[n] = r return r except: print "EXCEPT: " + str(n) if __name__ == '__main__': # This n = 900 is OK # But n = 1000 is ERROR n = 900 cache = range(0 , n + 1 , 1) for i in cache: cache[i] = -1 print "Fibo(" + str(n) + ") = " + str(fibo(n)) print "\n" print "\n" From __peter__ at web.de Mon Aug 1 05:14:22 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Aug 2011 11:14:22 +0200 Subject: Question References: Message-ID: Camilo Andres Roca Duarte wrote: > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > Python version. The problem is that anytime I try to run a script from the > Python Shell it returns an error message. I am new using python so I am > not sure what to do since what I'm typing in the shell is in a > BegginersTutorial. > > $ python myfunctions.py > SyntaxError: invalid syntax You shouldn't type the line $ python myfunctions.py into Idle's "Python Shell" window. The $ is the prompt of Unix shells like bash. You have to open such a shell and type the command there, without the leading $. If you are on Windows you have to open a "DOS Prompt" or "Command Window". You can then set the working directory with cd some\path Of course you have to replace some\path with the path where the file myfunctions.py is actually stored. Finally you can invoke your script with python myfunctions.py From steve+comp.lang.python at pearwood.info Mon Aug 1 05:19:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 19:19:30 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: <4e366fa7$0$29971$c3e8da3$5496439d@news.astraweb.com> jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why How should we know? Please tell us what the error is, don't expect us to guess. [...] > if __name__ == '__main__': > # This n = 900 is OK > # But n = 1000 is ERROR Hint: how big is the cache? If the cache has 900 items, what makes you think you can look up the 1000th item? > n = 900 > cache = range(0 , n + 1 , 1) > for i in cache: > cache[i] = -1 This is a waste of time. Better to write: cache = [-1]*900 Even better is to use a dict instead of a list. -- Steven From gennad.zlobin at gmail.com Mon Aug 1 05:23:20 2011 From: gennad.zlobin at gmail.com (Gennadiy Zlobin) Date: Mon, 1 Aug 2011 16:23:20 +0700 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: The maximum depth of the Python interpreter stack is limited to 1000 calls by default. You can get it by import sys; sys.getrecursionlimit() and set a new value to sys.setrecursionlimit(new_value) - Gennadiy On Mon, Aug 1, 2011 at 4:11 PM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # > > cache = [] > > def fibo( n ): > > try: > if cache[n] != -1: > return cache[n] > else: > if 0 == n: > r = 0 > elif 1 == n: > r = 1 > else: > r = fibo(n-1) + fibo(n-2) > > cache[n] = r > return r > except: > print "EXCEPT: " + str(n) > > > if __name__ == '__main__': > > # This n = 900 is OK > # But n = 1000 is ERROR > > n = 900 > cache = range(0 , n + 1 , 1) > > for i in cache: > cache[i] = -1 > > print "Fibo(" + str(n) + ") = " + str(fibo(n)) > print "\n" > print "\n" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anddimario at gmail.com Mon Aug 1 05:56:04 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Mon, 1 Aug 2011 11:56:04 +0200 Subject: Notifications when process is killed Message-ID: Hi, i've created a twisted server application and i want that the server send me a message when someone stops or kills the process. I want to override reactor.stop(), but do this way send me message when the process is stopped by a system kill? Could you suggest me if there's a way to do this? Thanks, regards. -- Andrea Di Mario From ulrich.eckhardt at dominolaser.com Mon Aug 1 06:50:24 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 01 Aug 2011 12:50:24 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e366fa7$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4icig8-tln.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > jc wrote: >> n = 900 >> cache = range(0 , n + 1 , 1) >> for i in cache: >> cache[i] = -1 > > This is a waste of time. Better to write: > > cache = [-1]*900 Since he's computing the Fibonacci number of n, and n is 900, he needs cache = [-1] * (n + 1) ;^) > Even better is to use a dict instead of a list. Simpler, yes. Better for a beginner, of course. Better, maybe not. The use case here will cause the cache to be used from index 1 upwards, so using an array to store the element is faster and smaller. I'd consider resizing the cache dynamically though. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From t at jollybox.de Mon Aug 1 06:52:03 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 01 Aug 2011 12:52:03 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: <4E368553.6080406@jollybox.de> On 01/08/11 11:56, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > Could you suggest me if there's a way to do this? > > Thanks, regards. > I don't know anything about Twisted, but you'd usually want to install a signal handler for SIGTERM, and perhaps SIGINT (unless you handle KeyboardInterrupt exceptions) and SIGHUP (for when the controlling terminal is lost, which usually causes a process to quit) I'm assuming you're using a UNIX-like system - Thomas From michael.poeltl at univie.ac.at Mon Aug 1 06:59:07 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 1 Aug 2011 12:59:07 +0200 Subject: how to solve it? In-Reply-To: References: Message-ID: <20110801105907.GA2101@horus.cms.at> * ???? <1248283536 at qq.com> [2011-08-01 06:22]: > from matplotlib.matlab import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named matlab does this work? >>> import matplotlib next check 'gallery' at http://matplotlib.sourceforge.net/index.html choose the graph (click it) you need, and there you can browse the source-code (python-code) this is maybe the best starting-point, I guess. cheers Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From davea at ieee.org Mon Aug 1 07:15:20 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 01 Aug 2011 07:15:20 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: <4E368AC8.3030906@ieee.org> On 01/-10/-28163 02:59 PM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # > > cache = [] > > def fibo( n ): > > try: > if cache[n] != -1: > return cache[n] > else: > if 0 == n: > r = 0 > elif 1 == n: > r = 1 > else: > r = fibo(n-1) + fibo(n-2) > > cache[n] = r > return r > except: > print "EXCEPT: " + str(n) > > > if __name__ == '__main__': > > # This n = 900 is OK > # But n = 1000 is ERROR > > n = 900 > cache = range(0 , n + 1 , 1) > > for i in cache: > cache[i] = -1 > > print "Fibo(" + str(n) + ") = " + str(fibo(n)) > print "\n" > print "\n" > > It'd be really nice if you bothered to state what "ERROR" you get. Show the traceback or since the output is pretty long, at least show part of it. copy/paste it from the shell. In any case, it's clearly a recursion problem, due to the default limit of the CPython stack (1000). This succeeds for 999, and gets a stack overflow at 1000. A solution that lets you go much higher would be to insert before the lines: if cache[n] != -1: return cache[n] The following: if n > MAXDEPTH: if n%MAXDEPTH: for i in xrange(0, n, 200): fibo(i) #calc value just to prefill the cache where an easy value for MAXDEPTH is 200. Think about what this does, and you should see why it'll help. I tried it for 100,000 and it doesn't blow up. I didn't however check any of the other logic. DaveA From grzegorz.tezycki at gmail.com Mon Aug 1 07:22:36 2011 From: grzegorz.tezycki at gmail.com (k2) Date: Mon, 1 Aug 2011 04:22:36 -0700 (PDT) Subject: How add/change password for RSA priv key using PyCrypto Message-ID: Hi, maybe somebody be able to help me. I'm using PyCrypto to generate a pair of RSA keys. The public key and private key. I try to add a password to the private key, and I do not know how to do it. This is a piece of my code. #encoding:utf-8 from Crypto.PublicKey import RSA pass_alice='ala' private_alice_key = RSA.generate(1024) public_alice_key = private_alice_key.publickey() str_priv = private_alice_key.exportKey() str_pub = public_alice_key.exportKey() print str_priv print str_pub # HOW ADD OR CHANGE PASSWORD FOR private_alice_key From msarro at gmail.com Mon Aug 1 07:42:13 2011 From: msarro at gmail.com (Matty Sarro) Date: Mon, 1 Aug 2011 07:42:13 -0400 Subject: Spam In-Reply-To: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: I agree, the Bollywood spam sucks. There's not even any boobies! On Aug 1, 2011 4:16 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Ghodmode wrote: > >> I've noticed that python-list gets significantly more spam than the >> other lists I subscribe to. There's an example below. > > Thanks for that! I missed it the first time, so it is very helpful for you > to forward it. It's especially helpful that you included all the spammer's > URLs, as that will help improve their Google page ranks. I'm sure the > spammer will thank you for your assistance. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From markferg at gmail.com Mon Aug 1 08:00:26 2011 From: markferg at gmail.com (mark ferguson) Date: Mon, 1 Aug 2011 13:00:26 +0100 Subject: Question In-Reply-To: References: Message-ID: Peter - well caught! I've been wondering how that line could have arisen when running a script through the interpreter from the command line! Pasting it into Idle gives exactly that output. It was the leading $ that threw me, I took it as the shell prompt. I think that Camilo was actually typing it into Idle as well. On 1 August 2011 10:14, Peter Otten <__peter__ at web.de> wrote: > Camilo Andres Roca Duarte wrote: > > > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > > Python version. The problem is that anytime I try to run a script from > the > > Python Shell it returns an error message. I am new using python so I am > > not sure what to do since what I'm typing in the shell is in a > > BegginersTutorial. > > > > $ python myfunctions.py > > SyntaxError: invalid syntax > > You shouldn't type the line > > $ python myfunctions.py > > into Idle's "Python Shell" window. The $ is the prompt of Unix shells like > bash. You have to open such a shell and type the command there, without the > leading $. > > If you are on Windows you have to open a "DOS Prompt" or "Command Window". > You can then set the working directory with > > cd some\path > > Of course you have to replace some\path with the path where the file > myfunctions.py is actually stored. Finally you can invoke your script with > > python myfunctions.py > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.poeltl at univie.ac.at Mon Aug 1 08:51:16 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 1 Aug 2011 14:51:16 +0200 Subject: how to solve it? In-Reply-To: References: Message-ID: <20110801125116.GD2101@horus.cms.at> * ???? <1248283536 at qq.com> [2011-08-01 06:22]: > from matplotlib.matlab import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named matlab is this what you were looking for? >>> from matplotlib.pylab import * cheers Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From thorsten at thorstenkampe.de Mon Aug 1 08:54:36 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 1 Aug 2011 14:54:36 +0200 Subject: [ANN] IPython 0.11 is officially out References: Message-ID: * Fernando Perez (Sun, 31 Jul 2011 17:26:50 +0000 (UTC)) > on behalf of the IPython development team, I'm thrilled to announce, > after more than two years of development work, the official release of > IPython 0.11. > > This release brings a long list of improvements and new features > (along with hopefully few new bugs). We have completely refactored > IPython, making it a much more friendly project to participate in by > having better separated and organized internals. We hope you will not > only use the new tools and libraries, but also join us with new ideas > and development. > [...] > Here is a quick listing of the major new features: > [...] > - New configuration system > [...] And the best thing is: IPython 0.11 is not compatible to 0.10 so if you had your own customized ipythonrc you can start from scratch. The documentation[1] says "If you are upgrading to version 0.11 of IPython, you will need to migrate your old ipythonrc or ipy_user_conf.py configuration files to the new system. Read on for information on how to do this." Unfortunately there is no more mentioning of "migration", so the developers' approach seems to be: "read all about the new configuration system and see if you can somehow duplicate your old ipythonrc settings. Good luck!". By the way: "configuration object", "applications", "configurables", "singletons", ... Am I really supposed to understand all this? Thorsten [1] http://ipython.org/ipython-doc/stable/config/overview.html From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Mon Aug 1 10:00:57 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Mon, 01 Aug 2011 10:00:57 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: On 08/01/2011 05:11 AM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # I have fixed the problem for you: def fibo(n): phi = (1+5**.5)/2; iphi = 1-phi; return (phi**n - iphi**n) / (5**.5) -- Bill From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Aug 1 10:25:43 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 01 Aug 2011 16:25:43 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: Am 01.08.2011 11:11 schrieb jc: > except: > print "EXCEPT: " + str(n) If you catch all exceptions here, it is clear that you only get this. Why don't you do except Exception, e: print "EXCEPT: " + str(n), e ? Then you could at least ask "why do I get a unsupported operand type(s) for +: 'NoneType' and 'long'"? Well, these are the consequences of returning nothing (aka None) in the case of earlier errors. The first of these errors comes from EXCEPT: 4 maximum recursion depth exceeded so - you simply go too deep. If you "pre-calculate" the stuff before, calling fibo(n/2) before the line with 'print "Fibo(" + str(n) + ") = " + str(fibo(n))', it succeeds. Thomas From warriorlance at gmail.com Mon Aug 1 11:05:27 2011 From: warriorlance at gmail.com (Tong Zhang) Date: Mon, 1 Aug 2011 23:05:27 +0800 Subject: python reading file memory cost Message-ID: <000f01cc505c$74e01e80$5ea05b80$@com> Hello, everyone! I am trying to read a little big txt file (~1 GB) by python2.7, what I want to do is to read these data into a array, meanwhile, I monitor the memory cost, I found that it cost more than 6 GB RAM! So I have two questions: 1: How to estimate memory cost before exec python script? 2: How to save RAM while do not increase exec time? Any answer will be grateful! --Tony Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Mon Aug 1 11:16:58 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 01 Aug 2011 17:16:58 +0200 Subject: PEP 8 and extraneous whitespace References: <4E286704.5060201@gmail.com> <4E2870A2.1070600@jollybox.de> <4E287406.8080608@gmail.com> <98tahoFcblU1@mid.individual.net> <98u00kFnfiU1@mid.individual.net> <2364463.r0ecnVBMoN@PointedEars.de> Message-ID: <1915354.HBgK6uhDRg@PointedEars.de> OKB (not okblacke) wrote: > Thomas 'PointedEars' Lahn wrote: >> Automatic word-wrap, where available, really is not a solution; it >> is a bad workaround to a problem caused by the original author of >> the source code that can be easily avoided by them taking more care >> while coding. > > I think exactly the opposite. The source file should reflect the > semantic organization of the code, without extraneous concessions to > visual display (like "lining things up" with spaces or splitting long > lines with hard newlines). The editor should present the code nicely. > People already argue for this general mindset when they say that "any > good edit will let you set the tab width", etc. Your approach would require all source code editors to have the same minimum feature set as you described, with the same settings, which is unrealistic. And it would make especially Python code a lot harder to read (as indentation matters in Python). Your From header field value is borken. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From t at jollybox.de Mon Aug 1 11:29:08 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 01 Aug 2011 17:29:08 +0200 Subject: python reading file memory cost In-Reply-To: <000f01cc505c$74e01e80$5ea05b80$@com> References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: <4E36C644.6070800@jollybox.de> On 01/08/11 17:05, Tong Zhang wrote: > Hello, everyone! > > > > I am trying to read a little big txt file (~1 GB) by python2.7, what I > want to do is to read these data into a array, meanwhile, I monitor the > memory cost, I found that it cost more than 6 GB RAM! So I have two > questions: > > 1: How to estimate memory cost before exec python script? > > 2: How to save RAM while do not increase exec time? How are you reading the file? If you are using file_object.read(), .readlines(), or similar, to read the whole file at once: don't. This is a tremendous waste of memory, and probably slows things down. Usually, the best approach is to iterate over the file object itself (for line in file_object: # process line) Without knowing what you're doing with the data (or, what "data" is here), we can't really do much to help you. My best guess would be that you're unnecessarily storing the data multiple times. Perhaps you can use the csv module? Do you really need to hold all the data in memory all the time, or can you process the data in the order it is in the file, never actually holding more than one (or a few) records in memory? With generators, Python has excellent support for working with streams of data like this. (and it would save you a lot of RAM) - Thomas From alimanfoo at googlemail.com Mon Aug 1 11:33:45 2011 From: alimanfoo at googlemail.com (aliman) Date: Mon, 1 Aug 2011 08:33:45 -0700 (PDT) Subject: Complex sort on big files Message-ID: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Hi all, Apologies I'm sure this has been asked many times, but I'm trying to figure out the most efficient way to do a complex sort on very large files. I've read the recipe at [1] and understand that the way to sort a large file is to break it into chunks, sort each chunk and write sorted chunks to disk, then use heapq.merge to combine the chunks as you read them. What I'm having trouble figuring out is what to do when I want to sort by one key ascending then another key descending (a "complex sort"). I understand that sorts are stable, so I could just repeat the whole sort process once for each key in turn, but that would involve going to and from disk once for each step in the sort, and I'm wondering if there is a better way. I also thought you could apply the complex sort to each chunk before writing it to disk, so each chunk was completely sorted, but then the heapq.merge wouldn't work properly, because afaik you can only give it one key. Any help much appreciated (I may well be missing something glaringly obvious). Cheers, Alistair [1] http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ From anddimario at gmail.com Mon Aug 1 11:39:23 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Mon, 1 Aug 2011 17:39:23 +0200 Subject: Notifications when process is killed Message-ID: Thanks Thomas, it is what i'm looking for. Regards -- Andrea Di Mario From drsalists at gmail.com Mon Aug 1 12:30:54 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 09:30:54 -0700 Subject: python reading file memory cost In-Reply-To: <000f01cc505c$74e01e80$5ea05b80$@com> References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: A code snippet would work wonders in making sure you've communicated what you really need, or at least what you have now. But if you read the data into one big string, that'll be much more efficient than if you read it as a list of integers or even as a list of lines. Processing the data one chunk or one line at a time will be far more memory-efficient. 2011/8/1 Tong Zhang > Hello, everyone!**** > > ** ** > > I am trying to read a little big txt file (~1 GB) by python2.7, what I want > to do is to read these data into a array, meanwhile, I monitor the memory > cost, I found that it cost more than 6 GB RAM! So I have two questions:*** > * > > 1: How to estimate memory cost before exec python script?**** > > 2: How to save RAM while do not increase exec time?**** > > ** ** > > Any answer will be grateful!**** > > ** ** > > --Tony Zhang**** > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Aug 1 12:45:54 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 09:45:54 -0700 Subject: Complex sort on big files In-Reply-To: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Python 2.x, or Python 3.x? What are the types of your sort keys? If you're on 3.x and the key you need reversed is numeric, you can negate the key. If you're on 2.x, you can use an object with a __cmp__ method to compare objects however you require. You probably should timsort the chunks (which is the standard list_.sort() - it's a very good in-memory sort), and then merge them afterward using the merge step of merge sort. heapq's not unreasonable for the merging, but I think it's more common to use a short list. I have a bunch of Python sorts at http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find your need is specialized (EG, 3.x sorting by a secondary key that's a string, in reverse), you could adapt one of these to do what you need. heapq is not bad, but if you find you need a logn datastructure, you might check out http://stromberg.dnsalias.org/~dstromberg/treap/ - a treap is also logn, but has a very good amortized cost because it sacrifices keeping things perfectly balanced (and rebalancing, and rebalancing...) to gain speed. But still, you might be better off with a short list and min. On Mon, Aug 1, 2011 at 8:33 AM, aliman wrote: > Hi all, > > Apologies I'm sure this has been asked many times, but I'm trying to > figure out the most efficient way to do a complex sort on very large > files. > > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. > > What I'm having trouble figuring out is what to do when I want to sort > by one key ascending then another key descending (a "complex sort"). > > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. > > I also thought you could apply the complex sort to each chunk before > writing it to disk, so each chunk was completely sorted, but then the > heapq.merge wouldn't work properly, because afaik you can only give it > one key. > > Any help much appreciated (I may well be missing something glaringly > obvious). > > Cheers, > > Alistair > > [1] > http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Aug 1 13:00:03 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Aug 2011 19:00:03 +0200 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: aliman wrote: > Apologies I'm sure this has been asked many times, but I'm trying to > figure out the most efficient way to do a complex sort on very large > files. > > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. > > What I'm having trouble figuring out is what to do when I want to sort > by one key ascending then another key descending (a "complex sort"). > > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. > > I also thought you could apply the complex sort to each chunk before > writing it to disk, so each chunk was completely sorted, but then the > heapq.merge wouldn't work properly, because afaik you can only give it > one key. You can make that key as complex as needed: >>> class Key(object): ... def __init__(self, obj): ... self.asc = obj[1] ... self.desc = obj[2] ... def __cmp__(self, other): ... return cmp(self.asc, other.asc) or -cmp(self.desc, other.desc) ... >>> sorted(["abc", "aba", "bbb", "aaa", "aab"], key=Key) ['aab', 'aaa', 'abc', 'bbb', 'aba'] See also http://docs.python.org/library/functools.html#functools.total_ordering From bahamutzero8825 at gmail.com Mon Aug 1 13:11:04 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 01 Aug 2011 12:11:04 -0500 Subject: What's in a name? In-Reply-To: <4E361F36.4030802@gmail.com> References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> <4E361F36.4030802@gmail.com> Message-ID: <4E36DE28.3030407@gmail.com> Hmm.... How about Rainbow Video Encoder Wrapper (Rainbow View for short - RView is taken, possibly multiple times)? I added an arbitrary word to a generic name, and the result doesn't seem to be taken by anything software-related. It wraps more than just video encoders (in fact, x264 will likely be the only one it wraps until it's matured quite a bit :P ), but I didn't want the name to get too long. The module itself will likely be called just rainbow.py. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From psyking841 at gmail.com Mon Aug 1 13:38:07 2011 From: psyking841 at gmail.com (happykid) Date: Mon, 1 Aug 2011 10:38:07 -0700 (PDT) Subject: os.path.dirname(sys.argv[0]) always returns nothing Message-ID: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> I want to use this function to get the directory path of the running script, but it always returns empty string. Can anyone help me solve this? Thank you. From rosuav at gmail.com Mon Aug 1 13:53:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 18:53:30 +0100 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: On Mon, Aug 1, 2011 at 6:38 PM, happykid wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. As long as you haven't changed directory since startup, you should be able to use os.path.abspath(sys.argv[0]) to get the absolute path name. It'll automatically fill in the path from the current directory if it's not provided. See: http://docs.python.org/py3k/library/os.path.html#os.path.abspath ChrisA From thijs at buckazoids.com Mon Aug 1 13:55:11 2011 From: thijs at buckazoids.com (Thijs Engels) Date: Mon, 01 Aug 2011 19:55:11 +0200 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: <1312221311.721.2158243397@webmail.messagingengine.com> On Mon, 01 Aug 2011 10:38 -0700, "happykid" wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list I think this is what you are after: import os.path path = os.path.abspath(os.path.dirname(__file__)) argv[0] returns the name of the current file (string), but no path information if I recall correct. Thijs From benjamin.kaplan at case.edu Mon Aug 1 13:56:31 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Aug 2011 13:56:31 -0400 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: On Mon, Aug 1, 2011 at 1:38 PM, happykid wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. > -- > sys.argv[0] is the name of the script you called. If you call "python spam.py", sys.argv[0] will be spam.py. Not /full/path/spam.py. Just spam.py. And the directory part of "spam.py" is "". You'll have to call os.path.abspath(sys.argv[0]) to get the full path, then get dirname. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Aug 1 13:58:27 2011 From: gordon at panix.com (John Gordon) Date: Mon, 1 Aug 2011 17:58:27 +0000 (UTC) Subject: os.path.dirname(sys.argv[0]) always returns nothing References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: In <9797b629-3fba-4b90-920f-e426683599e1 at a12g2000vbf.googlegroups.com> happykid writes: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. What is the value of sys.argv[0]? You're supposed to pass a full pathname to os.path.dirname, like so: >>> import os >>> os.path.dirname('/a/b/c/d/e.txt') '/a/b/c/d' >>> If sys.argv[0] is just the program name, then it doesn't have a path, which is why you get no results from os.path.dirname: >>> import os >>> os.path.dirname('foo.py') '' >>> Are you trying to obtain the full pathname of the program? That's an entirely different question. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Mon Aug 1 14:01:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 19:01:08 +0100 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <1312221311.721.2158243397@webmail.messagingengine.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> <1312221311.721.2158243397@webmail.messagingengine.com> Message-ID: On Mon, Aug 1, 2011 at 6:55 PM, Thijs Engels wrote: > argv[0] returns the name of the current file (string), but no path > information if I recall correct. It will give path information if you're invoking a script from another directory. Under some circumstances it might happen to give an absolute path for something in the current directory, but that can't be assumed or relied upon. ChrisA From harmar at member.fsf.org Mon Aug 1 15:17:05 2011 From: harmar at member.fsf.org (harrismh777) Date: Mon, 01 Aug 2011 14:17:05 -0500 Subject: Spam In-Reply-To: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> I've noticed that python-list gets significantly more spam than the >> > other lists I subscribe to. There's an example below. > Thanks for that! I missed it the first time, so it is very helpful for you > to forward it. It's especially helpful that you included all the spammer's > URLs, as that will help improve their Google page ranks. I'm sure the > spammer will thank you for your assistance. Yeah, a couple of good rules to follow for well intentioned citizens: 1) don't feed the trolls 2) don't repackage spam Having said that, either because I was tired or because I dropped my defensive posture, I have messed up on those two little rules more than once. It is possible to filter spam very effectively. My mail client has a spam-can based on a multitude of trial and guess rules that with almost oh 97 percent rate puts the right stuff into the can and saves me the trouble of manually filtering it. Granted, I still need to quickly peek through the can files... but this is pretty easy to do... because non spam shows up like a rose among thorns in a spam-can. The trouble is that this group does like to debate off-topic stuff frequently (usually its at least edge related to Python) and so who is to tell (as a moderator) what is spam? Well, your example is fairly obvious, but other stuff (even like this note) may not be. I don't consider this spam, because its related to this list and because I am interested in the same issue as your OP complaint. But, I am absolutely sure that others will view your note, and mine, as spam... see the problem? -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From steve+comp.lang.python at pearwood.info Mon Aug 1 18:06:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Aug 2011 08:06:53 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > I have fixed the problem for you: > > > def fibo(n): > phi = (1+5**.5)/2; iphi = 1-phi; > return (phi**n - iphi**n) / (5**.5) Does your definition of "fixed" mean "gives wrong results for n >= 4 "? >>> fibo(4) == 3 False -- Steven From drsalists at gmail.com Mon Aug 1 18:35:21 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 15:35:21 -0700 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: I've been testing my Python code on these using virtualbox and/or physical machines (but mostly virtualbox): CentOS 6.0 Debian DragonflyBSD Fedora 15 FreeBSD Haiku R1 alpha 3 Linux Mint Minix OpenIndiana openSUSE Sabayon Scientific Linux 6 Slackware Solaris Express Ubuntu Windows 7 Sadly, I don't have enough physmem to run them all concurrently, so I boot, test, shutdown; boot, test, shutdown... On Mon, Aug 1, 2011 at 3:42 PM, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as well > as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. ;) > > Any recommendations on which linuces to pick? > > ~Ethan~ > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Aug 1 18:42:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 01 Aug 2011 15:42:19 -0700 Subject: test systems Message-ID: <4E372BCB.3030003@stoneleaf.us> Howdy, I'm going to setup a few linux systems for testing (probably three) as well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. ;) Any recommendations on which linuces to pick? ~Ethan~ From alister.ware at ntlworld.com Mon Aug 1 18:42:47 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 01 Aug 2011 22:42:47 GMT Subject: test systems References: Message-ID: On Mon, 01 Aug 2011 15:42:19 -0700, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? > > ~Ethan~ I would suggest you ned something from the main core distributions so something debian based & something Red hat based, i would also suggest looking at slackware @ gentoo to add completness of course if you are really ambitious you could try linux from scratch :-) -- Hate the sin and love the sinner. -- Mahatma Gandhi From steve+comp.lang.python at pearwood.info Mon Aug 1 18:54:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Aug 2011 08:54:45 +1000 Subject: test systems References: Message-ID: <4e372eb6$0$30001$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? What are you testing? Is this for buildbots? Are you testing consumer-level software? Who is your software aimed at? Depending on the answer to that, normally I would say one each from the Debian and Redhat families, plus one other. E.g. pick one from each: (1) Debian, Ubuntu, Linux Mint (2) RHEL (if you can afford the licence fee), Centos, Fedora (3) Gentoo, Arch Linux, Suse, Slackware Some additional thoughts: I presume you're using VMs rather than six physical machines. What, no Apple Mac? Keep in mind that Arch uses Python 3 for the system python. Also keep in mind that Arch is generally considered to be so far out on the bleeding edge that even Slackware users consider them nuts. :) -- Steven From tim at johnsons-web.com Mon Aug 1 19:05:33 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 1 Aug 2011 15:05:33 -0800 Subject: Hostmonster : Installing MySQLdb at a specific location In-Reply-To: <20110731194135.GD3358@johnsons-web.com> References: <20110731185034.GC3358@johnsons-web.com> <20110731194135.GD3358@johnsons-web.com> Message-ID: <20110801230533.GA14664@johnsons-web.com> * Tim Johnson [110731 11:47]: > I don't want to discourage any further input, but I'm looking at > https://my.hostmonster.com/cgi/help/000531?step=000531 > regarding installing django and I think the instructions can be > extrapolated for MySQLdb. I will report what happens... I received a link for the Hostmonster helpdesk to https://my.hostmonster.com/cgi/help/530 My experience was that I had to modify some of the paths from the original. When I ran the python setup.py install routine, python complained that it could not find `lib64' thusly, I created $HOME/.local/lib/python2.4/site-packages Furthermore, seems that setup.py did not copy all files from the installation directory. The result was a UserWarning regarding multiple imports of the _mysql module when I invoked import MySQLdb. I solved that by adding the installation directory to my PYTHONPATH. A relevant excerpt from .bashrc looks like this: #BEGIN - # line one export PYTHONPATH=$HOME/.local/lib64/python/site-packages:$PYTHONPATH # line two export PYTHONPATH=$HOME/.local/lib64/python2.4/site-packages:$PYTHONPATH # line three export PYTHONPATH=$HOME/admin/.install/MySQL-python-1.2.3:$PYTHONPATH # line four export PATH=$HOME/.local/bin:$PATH #END Where $HOME/admin/.install/MySQL-python-1.2.3 is the package install directory. I have been spoiled by ubuntu. Furthemore, it has been a long time since I did a package install where I don't have root privileges. Results may vary, I hope this is helpful to someone else. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From greg.ewing at canterbury.ac.nz Mon Aug 1 19:57:11 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 02 Aug 2011 11:57:11 +1200 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: <99osqsFk1aU1@mid.individual.net> Thijs Engels wrote: > argv[0] returns the name of the current file (string), but no path > information if I recall correct. It's the path that was used to specify the script by whatever launched it, so it could be either absolute or relative to the current directory. -- Greg From ramit.prasad at jpmorgan.com Mon Aug 1 20:32:32 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 1 Aug 2011 20:32:32 -0400 Subject: Convert '165.0' to int In-Reply-To: <993q91FebkU2@mid.individual.net> References: <4e281f97$0$16404$426a74cc@news.free.fr> <4230ed8b-5173-4408-938f-3777dcd60588@t7g2000vbv.googlegroups.com> <3d6b3ab4-6682-4e33-ab03-098d2f82c20d@o18g2000yqm.googlegroups.com> <58cdafad-e1ea-4774-984f-aa13cf2a9ef1@fq4g2000vbb.googlegroups.com> <993q91FebkU2@mid.individual.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA72036B3@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Gregory Ewing Sent: Sunday, July 24, 2011 7:05 PM To: python-list at python.org Subject: Re: Convert '165.0' to int Frank Millman wrote: > I know I am flogging a dead horse here, but IMHO, '165', '165.', > '165.0', and '165.00' are all valid string representations of the > integer 165.[1] > > Therefore, for practical purposes, it would not be wrong for python's > 'int' function to accept these without complaining. How far would you go with that? Would you also accept '1.65e2' as a valid representation of the integer 165? -- Greg -- ================================ No, YAGNI (You Aren't Going To Need It). Do the minimum that works for your use case. If you only expect ###.# then code for that. Avoid trying to over-engineer your solution. *If* you think you are going to receive information that might be like '1.65e2' then code for it, otherwise spend your time working on other problems. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From t at jollybox.de Mon Aug 1 20:33:18 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 02:33:18 +0200 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: <4E3745CE.8080609@jollybox.de> On 02/08/11 00:42, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? I would say that the Debian vs Red Hat issue is secondary compared to how recent the installed packages are. IMHO, you'll want: (1) "state of the art" - newest Ubuntu, Fedora Core, or perhaps openSUSE release (2) stable/"business-level" maturity - Debian stable, CentOS (or Scientific Linux/RHEL/other RHEL rebuild), Ubuntu LTS release and, perhaps: (3) bleeding edge - Arch / Gentoo You may also want to consider non-current releases. If I had to chose three, it might be Ubuntu 11.04, Debian 6, and CentOS 5. - Thomas From ramit.prasad at jpmorgan.com Mon Aug 1 20:42:05 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 1 Aug 2011 20:42:05 -0400 Subject: Convert '165.0' to int In-Reply-To: References: <4e281f97$0$16404$426a74cc@news.free.fr> <4230ed8b-5173-4408-938f-3777dcd60588@t7g2000vbv.googlegroups.com> <3d6b3ab4-6682-4e33-ab03-098d2f82c20d@o18g2000yqm.googlegroups.com> <58cdafad-e1ea-4774-984f-aa13cf2a9ef1@fq4g2000vbb.googlegroups.com> <993q91FebkU2@mid.individual.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA72036BD@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Frank Millman Sent: Monday, July 25, 2011 12:51 AM To: python-list at python.org Subject: Re: Convert '165.0' to int On Jul 25, 2:04?am, Gregory Ewing wrote: > Frank Millman wrote: > > I know I am flogging a dead horse here, but IMHO, '165', '165.', > > '165.0', and '165.00' are all valid string representations of the > > integer 165.[1] > > > Therefore, for practical purposes, it would not be wrong for python's > > 'int' function to accept these without complaining. > > How far would you go with that? Would you also accept > '1.65e2' as a valid representation of the integer 165? > To be honest, I don't even know what that means! I could read up on it, but I think this has gone far enough. Having flogged this horse to death, I will now let it rest in peace :-) Frank -- http://mail.python.org/mailman/listinfo/python-list ======================== '1.65e2' is a fairly standard representation of scientific notation. It basically translates to: 1.65 x 10^2 For more details, see: http://en.wikipedia.org/wiki/Scientific_notation Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Mon Aug 1 21:29:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 02:29:53 +0100 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: On Mon, Aug 1, 2011 at 11:42 PM, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as well > as the three FreeBSD, OpenBSD, and (possibly) NetBsd. ?Oh, and Windows. ?;) > > Any recommendations on which linuces to pick? Others have made recommendations of distro (and are far better qualified than I to do so), but one small point to add: Test a mix of 32-bit and 64-bit systems, unless you only support the latter. This is particularly important with installers and such; installing a 32-bit library on a 64-bit Linux may mean putting it in a special directory. Chris Angelico From nytrokiss at gmail.com Mon Aug 1 21:50:43 2011 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 1 Aug 2011 21:50:43 -0400 Subject: test systems In-Reply-To: References: <4E372BCB.3030003@stoneleaf.us> Message-ID: Wow, why don't you find some cloud providers and write bootstrap programs. James On Mon, Aug 1, 2011 at 6:35 PM, Dan Stromberg wrote: > > I've been testing my Python code on these using virtualbox and/or physical > machines (but mostly virtualbox): > > CentOS 6.0 > Debian > DragonflyBSD > Fedora 15 > FreeBSD > Haiku R1 alpha 3 > Linux Mint > Minix > OpenIndiana > openSUSE > Sabayon > Scientific Linux 6 > Slackware > Solaris Express > Ubuntu > Windows 7 > > Sadly, I don't have enough physmem to run them all concurrently, so I boot, > test, shutdown; boot, test, shutdown... > > > On Mon, Aug 1, 2011 at 3:42 PM, Ethan Furman wrote: > >> Howdy, >> >> I'm going to setup a few linux systems for testing (probably three) as >> well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. >> ;) >> >> Any recommendations on which linuces to pick? >> >> ~Ethan~ >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://www.theboxery.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From warriorlance at gmail.com Mon Aug 1 23:22:50 2011 From: warriorlance at gmail.com (Tony Zhang) Date: Tue, 02 Aug 2011 11:22:50 +0800 Subject: python reading file memory cost In-Reply-To: References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: <1312255370.31275.20.camel@ZTFEL> Thanks! Actually, I used .readline() to parse file line by line, because I need to find out the start position to extract data into list, and the end point to pause extracting, then repeat until the end of file. My file to read is formatted like this: blabla...useless.... useless... /sign/ data block(e.g. 10 cols x 1000 rows) ... blank line /sign/ data block(e.g. 10 cols x 1000 rows) ... blank line ... ... EOF let's call this file 'myfile' and my python snippet: f=open('myfile','r') blocknum=0 #number the data block data=[] while True" # find the extract begnning while not f.readline().startswith('/a1/'):pass # creat multidimensional list to store data block data=append([]) blocknum +=1 line=f.readline() while line.strip(): # check if the line is a blank line, i.e the end of one block data[blocknum-1].append(["2.6E" %float(x) for x in line.split()]) line = f.readline() print "Read Block %d" %blocknum if not f.readline(): break The running result was that read a 500M file consume almost 2GB RAM, I cannot figure it out, somebody help! Thanks very much! --Tony From ghodmode at ghodmode.com Mon Aug 1 23:58:10 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Tue, 2 Aug 2011 11:58:10 +0800 Subject: Spam In-Reply-To: References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 3:17 AM, harrismh777 wrote: > Steven D'Aprano wrote: > >> I've noticed that python-list gets significantly more spam than the >>> > other lists I subscribe to. There's an example below. >>> >> Thanks for that! I missed it the first time, so it is very helpful for you >> to forward it. It's especially helpful that you included all the spammer's >> URLs, as that will help improve their Google page ranks. I'm sure the >> spammer will thank you for your assistance. >> > > Yeah, a couple of good rules to follow for well intentioned citizens: > 1) don't feed the trolls > 2) don't repackage spam > I hope it's clear that reading an email doesn't constitute visiting all of the sites linked in the email and therefore doesn't improve Google page ranks or provide any other tracking information. Also note that the original email didn't have anything like a tracking pixel. Even the urls were just text. They only became links if the readers' email client turned them into links. My email wasn't dangerous or helpful to the spammer in any way. Having said that, either because I was tired or because I dropped my > defensive posture, I have messed up on those two little rules more than > once. > > It is possible to filter spam very effectively. My mail client has a > spam-can based on a multitude of trial and guess rules that with almost oh > 97 percent rate puts the right stuff into the can and saves me the trouble > of manually filtering it. Granted, I still need to quickly peek through the > can files... but this is pretty easy to do... because non spam shows up like > a rose among thorns in a spam-can. > > The trouble is that this group does like to debate off-topic stuff > frequently (usually its at least edge related to Python) and so who is to > tell (as a moderator) what is spam? Well, your example is fairly obvious, > but other stuff (even like this note) may not be. I don't consider this > spam, because its related to this list and because I am interested in the > same issue as your OP complaint. But, I am absolutely sure that others will > view your note, and mine, as spam... see the problem? > I think we have a generally accepted idea of what spam is, and it's much different from off-topic threads. An automated system might not be able to identify the differences as easily, but a person could. Especially if that person is an active member of the community and reads all of the threads anyway. > -- > m harris > > FSF ...free as in freedom/ > http://webpages.charter.net/**harrismh777/gnulinux/gnulinux.**htm > > -- > http://mail.python.org/**mailman/listinfo/python-list > My intentions were constructive and helpful, but it has gotten a little out of hand. Based on some of the information provided, my idea might not be technically feasible anyway. So, I won't be reading or commenting on this thread further. I am truly sorry for any misunderstandings or time lost. -- Ghodmode http://www.ghodmode.com/blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.pricejones at gmail.com Tue Aug 2 00:10:44 2011 From: m.pricejones at gmail.com (mpj) Date: Mon, 1 Aug 2011 21:10:44 -0700 (PDT) Subject: Map-based module imports with import hook Message-ID: <13064e6e-6d3d-457d-bd90-1bb4a3150eb9@e20g2000prf.googlegroups.com> Hi, I've experience working at companies where, because of the network set up, having a long PYTHONPATH and searching it is quite a heavy task and can slow down the start up of the interpreter when there are lots of imports. As a proof of concept I wanted to look at a map-based approach. The theory being that instead of having a linear list of paths to search with heavy disk checks, if we could encode the location of the modules in an environment variable we would be able to jump to the correct location much quicker. As a result I've written: https://github.com/michaeljones/porter Which implements an import hook (PEP 302) that can be set up to look at an environment variable with the following format: name=location[:name=location[:name=location[:...]]] This is parsed into a standard dict and used for quick lookups when possible, falling back to the standard Python import mechanism when nothing is found. The implementation is new and not production tested, but I was hoping to get some external thoughts on the idea, especially to hear any functionality that this might disrupt. I've only written basic tests to check import behaviour and am aware that I probably don't really appreciate the full consequences of this idea. Cheers, Michael From drsalists at gmail.com Tue Aug 2 01:01:46 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 22:01:46 -0700 Subject: python reading file memory cost In-Reply-To: <1312255370.31275.20.camel@ZTFEL> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: You could try forcing a garbage collection... On Mon, Aug 1, 2011 at 8:22 PM, Tony Zhang wrote: > Thanks! > > Actually, I used .readline() to parse file line by line, because I need > to find out the start position to extract data into list, and the end > point to pause extracting, then repeat until the end of file. > My file to read is formatted like this: > > blabla...useless.... > useless... > > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > ... > ... > EOF > let's call this file 'myfile' > and my python snippet: > > f=open('myfile','r') > blocknum=0 #number the data block > data=[] > while True" > # find the extract begnning > while not f.readline().startswith('/a1/'):pass > # creat multidimensional list to store data block > data=append([]) > blocknum +=1 > line=f.readline() > > while line.strip(): > # check if the line is a blank line, i.e the end of one block > data[blocknum-1].append(["2.6E" %float(x) for x in > line.split()]) > line = f.readline() > print "Read Block %d" %blocknum > if not f.readline(): break > > The running result was that read a 500M file consume almost 2GB RAM, I > cannot figure it out, somebody help! > Thanks very much! > > --Tony > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 2 01:41:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 06:41:41 +0100 Subject: Spam In-Reply-To: References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 4:58 AM, Ghodmode wrote: > I hope it's clear that reading an email doesn't constitute visiting all of > the sites linked in the email and therefore doesn't improve Google page > ranks or provide any other tracking information.? Also note that the > original email didn't have anything like a tracking pixel.? Even the urls > were just text.? They only became links if the readers' email client turned > them into links.? My email wasn't dangerous or helpful to the spammer in any > way. You're correct about emails per se, but list mail gets archived to web-accessible pages: http://mail.python.org/pipermail/python-list/2011-August/1277607.html And yes, URLs become clickable. ChrisA From clp2 at rebertia.com Tue Aug 2 02:55:15 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Aug 2011 23:55:15 -0700 Subject: python reading file memory cost In-Reply-To: <1312255370.31275.20.camel@ZTFEL> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: On Mon, Aug 1, 2011 at 8:22 PM, Tony Zhang wrote: > Thanks! > > Actually, I used .readline() to parse file line by line, because I need > to find out the start position to extract data into list, and the end > point to pause extracting, then repeat until the end of file. > My file to read is formatted like this: > > blabla...useless.... > useless... > > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > ... > ... > EOF > let's call this file 'myfile' > and my python snippet: > > f=open('myfile','r') > blocknum=0 #number the data block > data=[] > while True" > ? ? ? ?# find the extract begnning > ? ? ? ?while not f.readline().startswith('/a1/'):pass > ? ? ? ?# creat multidimensional list to store data block > ? ? ? ?data=append([]) > ? ? ? ?blocknum +=1 > ? ? ? ?line=f.readline() > > ? ? ? ?while line.strip(): > ? ? ? ?# check if the line is a blank line, i.e the end of one block > ? ? ? ? ? ? ? ?data[blocknum-1].append(["2.6E" %float(x) for x in line.split()]) > ? ? ? ? ? ? ? ?line = f.readline() > ? ? ? ?print "Read Block %d" %blocknum > ? ? ? ?if not f.readline(): break > > The running result was that read a 500M file consume almost 2GB RAM, I > cannot figure it out, somebody help! If you could store the floats themselves, rather than their string representations, that would be more space-efficient. You could then also use the `array` module, which is more space-efficient than lists (http://docs.python.org/library/array.html ). Numpy would also be worth investigating since multidimensional arrays are involved. The next obvious question would then be: do you /really/ need /all/ of the data in memory at once? Also, just so you're aware: http://docs.python.org/library/sys.html#sys.getsizeof Cheers, Chris -- http://rebertia.com From harmar at member.fsf.org Tue Aug 2 03:12:20 2011 From: harmar at member.fsf.org (harrismh777) Date: Tue, 02 Aug 2011 02:12:20 -0500 Subject: range() vs xrange() Python2|3 issues for performance Message-ID: The following is intended as a helpful small extension to the xrange() range() discussion brought up this past weekend by Billy Mays... With Python2 you basically have two ways to get a range of numbers: range() , which returns a list, and xrange() , which returns an iterator. With Python3 you must use range(), which produces an iterator; while xrange() does not exist at all (at least not on 3.2). I have been doing some research in number theory related to Mersenne Primes and perfect numbers (perfects, those integers whose primary divisors when summed result in the number, not including the number itself)... the first few of those being 6, 28, 496, 8128, 33550336, etc Never mind, but you know... are there an infinite number of them? ... and of course, are there any "odd" perfect numbers... well not under 10^1500.... I digress, sorry ... This brought up the whole range() xrange() thing for me again because Python in any case is just not fast enough (no brag, just fact). So my perfect number stuff is written in C, for the moment. But, what about the differences in performance (supposing we were to stay in Python for small numbers) between xrange() vs range() [on Python2] versus range() [on Python3]? I have put my code snips below, with some explanation below that... these will run on either Python2 or Python3... except that if you substitute xrange() for range() for Python2 they will throw an exception on Python3... doh. So, here is PyPerfectNumbers.py ---------------------------- def PNums(q): for i in range(2, q): m = 1 s = 0 while m <= i/2: if not i%m: s += m m += 1 if i == s: print(i) return 0 def perf(n): sum = 0 for i in range(1, n): if n % i == 0: sum += i return sum == n fperf = lambda n: n == sum(i for i in range(1, n) if n % i == 0) -----------------/end--------------------------------------- PNums(8200) will crunch out the perfect numbers below 8200. perf(33550336) will test to see if 33550336 is a perfect number fperf(33550336) is the lambda equivalent of perf() These are coded with range(). The interesting thing to note is that xrange() on Python2 runs "considerably" faster than the same code using range() on Python3. For large perfect numbers (above 8128) the performance difference for perf() is orders of magnitude. Actually, range() on Python2 runs somewhat slower than xrange() on Python2, but things are much worse on Python3. This is something I never thought to test before Billy's question, because I had already decided to work in C for most of my integer stuff... like perfects. But now that it sparked my interest, I'm wondering if there might be some focus placed on range() performance in Python3 for the future, PEP? kind regards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From anddimario at gmail.com Tue Aug 2 03:30:52 2011 From: anddimario at gmail.com (AndDM) Date: Tue, 2 Aug 2011 00:30:52 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: On Aug 1, 5:39?pm, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Hi, i've a little problem, here the code that i use: def receive_signal(signum, stack): logging.info('Received: %s' % signum) reactor.stop() signal.signal(signal.SIGTERM, receive_signal) signal.signal(signal.SIGHUP, receive_signal) signal.signal(signal.SIGINT, receive_signal) The function works for SIGHUP and SIGINT, but it doesn't work for SIGTERM. I've tried with simple killall and with -15 option. Have you some ideas? Thanks, regards. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Aug 2 03:51:51 2011 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 2 Aug 2011 07:51:51 +0000 (UTC) Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: harrismh777 wrote: these will run on either Python2 or > Python3... except that if you substitute xrange() for range() for > Python2 they will throw an exception on Python3... doh. if 'xrange' not in dir(__builtins__): xrange = range at the beginning of your program will fix that. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From __peter__ at web.de Tue Aug 2 04:26:22 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 10:26:22 +0200 Subject: python reading file memory cost References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: Chris Rebert wrote: >> The running result was that read a 500M file consume almost 2GB RAM, I >> cannot figure it out, somebody help! > > If you could store the floats themselves, rather than their string > representations, that would be more space-efficient. You could then > also use the `array` module, which is more space-efficient than lists > (http://docs.python.org/library/array.html ). Numpy would also be > worth investigating since multidimensional arrays are involved. > > The next obvious question would then be: do you /really/ need /all/ of > the data in memory at once? This is what you (OP) should think about really hard before resorting to the optimizations mentioned above. Perhaps you can explain what you are doing with the data once you've loaded it into memory? > Also, just so you're aware: > http://docs.python.org/library/sys.html#sys.getsizeof To give you an idea how memory usage explodes: >>> line = "1.23 4.56 7.89 0.12\n" >>> len(line) # size in the file 20 >>> sys.getsizeof(line) 60 >>> formatted = ["%2.6E" % float(x) for x in line.split()] >>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) 312 From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 04:26:22 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 10:26:22 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: Am 02.08.2011 09:30 schrieb AndDM: > The function works for SIGHUP and SIGINT, but it doesn't work for > SIGTERM. I've tried with simple killall and with -15 option. > Have you some ideas? SIGTERM cannot be caught - it kills the process the hard way. HTH, Thomas From rosuav at gmail.com Tue Aug 2 05:01:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 10:01:26 +0100 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 8:30 AM, AndDM wrote: > ? ? ? ?def receive_signal(signum, stack): > ? ? ? ? ? ? ? ?logging.info('Received: %s' % signum) > ? ? ? ? ? ? ? ?reactor.stop() > ? ? ? ?signal.signal(signal.SIGTERM, receive_signal) > ? ? ? ?signal.signal(signal.SIGHUP, receive_signal) > ? ? ? ?signal.signal(signal.SIGINT, receive_signal) > > The function works for SIGHUP and SIGINT, but it doesn't work for > SIGTERM. I've tried with simple killall and with -15 option. > Have you some ideas? You won't be able to catch SIGTERM, as Thomas said, but if you need to know what caused a process to end, the best way is to have code in the parent process to catch SIGCHLD. When the child ends, for any reason, its parent is sent SIGCHLD with some parameters, including the signal number that caused the termination; you can then log anything you want. Chris Angelico From __peter__ at web.de Tue Aug 2 05:05:43 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 11:05:43 +0200 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: harrismh777 wrote: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. > > With Python3 you must use range(), which produces an iterator; while > xrange() does not exist at all (at least not on 3.2). > > I have been doing some research in number theory related to Mersenne > Primes and perfect numbers (perfects, those integers whose primary > divisors when summed result in the number, not including the number > itself)... the first few of those being 6, 28, 496, 8128, 33550336, etc > > Never mind, but you know... are there an infinite number of them? > ... and of course, are there any "odd" perfect numbers... well not under > 10^1500.... I digress, sorry ... > > This brought up the whole range() xrange() thing for me again > because Python in any case is just not fast enough (no brag, just fact). > So my perfect number stuff is written in C, for the moment. But, what > about the differences in performance (supposing we were to stay in > Python for small numbers) between xrange() vs range() [on Python2] > versus range() [on Python3]? I have put my code snips below, with some > explanation below that... these will run on either Python2 or > Python3... except that if you substitute xrange() for range() for > Python2 they will throw an exception on Python3... doh. try: range = xrange except NameError: pass > > So, here is PyPerfectNumbers.py ---------------------------- > > def PNums(q): > for i in range(2, q): > m = 1 > s = 0 > while m <= i/2: i/2 returns a float in Python 3; you should use i//2 for consistency. > if not i%m: > s += m > m += 1 > if i == s: > print(i) > return 0 > > def perf(n): > sum = 0 > for i in range(1, n): > if n % i == 0: > sum += i > return sum == n > > fperf = lambda n: n == sum(i for i in range(1, n) if n % i == 0) > > -----------------/end--------------------------------------- > > PNums(8200) will crunch out the perfect numbers below 8200. > > perf(33550336) will test to see if 33550336 is a perfect number > > fperf(33550336) is the lambda equivalent of perf() > > > These are coded with range(). The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Python 3's range() is indeed slower, but not orders of magnitude: $ python3.2 -m timeit -s"r = range(33550336)" "for i in r: pass" 10 loops, best of 3: 1.88 sec per loop $ python2.7 -m timeit -s"r = xrange(33550336)" "for i in r: pass" 10 loops, best of 3: 1.62 sec per loop $ cat tmp.py try: range = xrange except NameError: pass def fperf(n): return n == sum(i for i in range(1, n) if not n % i) if __name__ == "__main__": print(fperf(33550336)) $ time python2.7 tmp.py True real 0m6.481s user 0m6.100s sys 0m0.000s $ time python3.2 tmp.py True real 0m7.925s user 0m7.520s sys 0m0.040s I don't know what's causing the slowdown, maybe the int/long unification is to blame. > Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? From phil at freehackers.org Tue Aug 2 05:17:54 2011 From: phil at freehackers.org (BlueBird) Date: Tue, 2 Aug 2011 02:17:54 -0700 (PDT) Subject: Deeply nested dictionaries - should I look into a database or am I just doing it wrong? References: <4E35A0BB.5010201@gmail.com> Message-ID: <0693ae3d-d95d-4b8d-a397-53b7bdf995d8@a10g2000yqn.googlegroups.com> I love named tuples, they rock for this kind of task: storing complicated structure in a python compatible way, without too much hassle. And as far as load/save on disk is concerned, I simply use regular python structure with safe eval [1]. I get all the flexibility that I need for the file format, without the annoyance of writing a conversion layer. [1]: http://code.activestate.com/recipes/364469-safe-eval/ From stefan_ml at behnel.de Tue Aug 2 05:20:41 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 02 Aug 2011 11:20:41 +0200 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: harrismh777, 02.08.2011 09:12: > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. > > With Python3 you must use range(), which produces an iterator; while > xrange() does not exist at all (at least not on 3.2). That's a good thing. There should be one - and preferably only one - obvious way to do it. iterable: range(N) list: list(range(N)) tuple: tuple(range(N)) set: set(range(N)) ... Less special cases in the language. > This brought up the whole range() xrange() thing for me again because > Python in any case is just not fast enough (no brag, just fact). So my > perfect number stuff is written in C, for the moment. Or use Cython or PyPy, both of which are simpler ways to get your code up to speed. > The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. Are you sure that's due to Py3 range() vs. Py2 xrange()? Py3 has a different implementation for integers (which is still being optimised, BTW). That's much more likely to make a difference here. What version of Py3 were you using? If you used the latest, maybe even the latest hg version, you will notice that that's substantially faster for integers than, e.g. 3.1.x. Stefan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 05:26:45 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 11:26:45 +0200 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: Am 02.08.2011 09:12 schrieb harrismh777: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. No. An iterable. As already said, iterators are the ones stopping forever when the end is reached. Generally, iterables are allowed to iterate multiple times. xrange() resp. range() yield iterables. > The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. That sounds strange at the first glance. > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? I'm sure it is a matter of implementation. You cannot define by PEP what performance the implementations should have. Maybe range() in 3 is defined differently to xrange() in 2. I'm not so familiar with 3 to definitely confirm or decline that. The behaviour, though, seems to be the same, but range3 (as I call it now) has some more methods than xrange, like the rich comparison ones. Indexing works with all of them. Thomas From jldunn2000 at gmail.com Tue Aug 2 05:32:54 2011 From: jldunn2000 at gmail.com (loial) Date: Tue, 2 Aug 2011 02:32:54 -0700 (PDT) Subject: Hardlink sub-directories and files Message-ID: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> I am trying to hardlink all files in a directory structure using os.link. This works fine for files, but the directory also contains sub- directories (which themselves contain files and sub-directories). However I do not think it is possible to hard link directories ? So presumably I would need to do a mkdir for each sub-directory encountered? Or is there an easier way to hardlink everything in a directory structure?. The requirement is for hard links, not symbolic links From rosuav at gmail.com Tue Aug 2 05:52:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 10:52:59 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 10:20 AM, Stefan Behnel wrote: > What version of Py3 were you using? If you used the latest, maybe even the > latest hg version, you will notice that that's substantially faster for > integers than, e.g. 3.1.x. > I just tried this out, using a slightly modified script but the same guts: ----- import sys print(sys.version) import time def PNums(q): start=time.clock() for i in range(2, q): m = 1 s = 0 while m <= i/2: if not i%m: s += m m += 1 if i == s: print(i) print("Time: %f"%(time.clock()-start)) return # PNums(33550337) PNums(10000) ----- On my dual-core Windows laptop (it always saturates one core with this, leaving the other for the rest of the system), the results show no statistically significant difference between xrange and range in Python 2, but notably slower overall performance in Python 3: 2.4.5 (#1, Dec 15 2009, 16:41:19) [GCC 4.1.1] Time: 14.474343 Using xrange: 14.415412 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] Time: 8.990142 Using xrange: 9.015566 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] Time: 24.401461 Since I don't have a build environment in which to test the latest from hg, I switched to a Linux box. The following timings therefore cannot be compared with the above ones. 3.3a0 (default:b95096303ed2, Jun 2 2011, 20:43:01) [GCC 4.4.5] Time: 34.390000 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] Time: 13.730000 Using xrange: 13.670000 My 3.3a0 is freshly pulled from hg, although I'm not sure if sys.version has been correctly built. Once again, 2.6.6 shows no significant difference between range and xrange, but 3 is noticeably slower than 2. (I did several runs, but the variance between the runs wasn't significant.) Of course, this is all fairly moot; if you're doing really heavy number crunching, CPython isn't the platform to use. ChrisA From __peter__ at web.de Tue Aug 2 06:01:19 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 12:01:19 +0200 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > > This works fine for files, but the directory also contains sub- > directories (which themselves contain files and sub-directories). > However I do not think it is possible to hard link directories ? > > So presumably I would need to do a mkdir for each sub-directory > encountered? > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links You cannot make hardlinks for directories, that's a restriction imposed by the operating system. Look for shutil.copytree() for a template of what you are trying to do; you might even monkepatch it # untested copy2 = shutil.copy2 shutil.copy2 = os.link try: shutil.copytree(source, dest) finally: shutil.copy2 = copy2 if you are OK with a quick-and-dirty solution. From t at jollybox.de Tue Aug 2 06:13:35 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 12:13:35 +0200 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <4E37CDCF.7060501@jollybox.de> On 02/08/11 11:32, loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > > This works fine for files, but the directory also contains sub- > directories (which themselves contain files and sub-directories). > However I do not think it is possible to hard link directories ? > > So presumably I would need to do a mkdir for each sub-directory > encountered? > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links > Yes, you have to mkdir everything. However, there is an easier way: subprocess.Popen(['cp','-Rl','target','link']) This is assuming that you're only supporting Unices with a working cp program, but as you're using hard links, that's quite a safe bet, I should think. - Thomas From rosuav at gmail.com Tue Aug 2 06:19:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 11:19:53 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 10:05 AM, Peter Otten <__peter__ at web.de> wrote: > i/2 returns a float in Python 3; you should use i//2 for consistency. > And I forgot to make this change before doing my tests. Redoing the Python 3 ones with // quite drastically changes things! 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] Time: 17.917331 That's a lot closer to the 10-14 seconds that Python 2 was doing, but still somewhat worse. Of course, no surprises that 2.6 is faster than 2.4. But now, here's a fairly small change that makes a LOT of difference, and reveals the value of range/xrange. Notice that m is just being a classic iteration counter (it starts at 1, increments to a top limit)... ----- for m in xrange(1,i//2+1): if not i%m: s += m ----- This brings 2.6.5 down to 5.359383 seconds, or 4.703364 with xrange. (I'm now changing two references from range to xrange.) Meanwhile, 3.2 has come down to 7.096237 seconds, and 2.4.5 to 8.222261. Comparing the latest 3.3a0 and 2.6.6 on the other box shows that there's still a difference. Both of them improve with range instead of manual incrementing, but 2.6.6 takes 6.950000 seconds and 3.3a0 takes 13.830000 (down from 13.730000 and 34.390000 in the previous test). Conclusion: Python 3 is notably slower comparing floating point and integer than Python 2 is comparing int and int. No surprises there! But get everything working with integers, and use range() instead of manually incrementing a variable, and things come much more even. But as I said, CPython isn't the ideal language for heavy number crunching. On the same Windows box, a Pike program using the same algorithm took only 2.055 seconds. And a C program took 0.328 seconds. But if you have other reasons for keeping it in Python, do keep it to integers! ChrisA From alimanfoo at googlemail.com Tue Aug 2 06:25:05 2011 From: alimanfoo at googlemail.com (Alistair Miles) Date: Tue, 2 Aug 2011 11:25:05 +0100 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Hi Dan, Thanks for the reply. On Mon, Aug 1, 2011 at 5:45 PM, Dan Stromberg wrote: > > Python 2.x, or Python 3.x? Currently Python 2.x. > What are the types of your sort keys? Both numbers and strings. > If you're on 3.x and the key you need reversed is numeric, you can negate > the key. I did wonder about that. Would that not be doable also in Python 2.7, using sorted(key=...)? > If you're on 2.x, you can use an object with a __cmp__ method to compare > objects however you require. OK, right. Looking at the HowTo/Sorting again [1] and the bit about cmp_to_key, could you also achieve the same effect by returning a key with custom implementations of rich comparison functions? > You probably should timsort the chunks (which is the standard list_.sort() - > it's a very good in-memory sort), and then merge them afterward using the > merge step of merge sort. Yes, that's what I understood by the activestate recipe [2]. So I guess my question boils down to, how do you do the merge step for a complex sort? (Assuming each chunk had been completely sorted first.) Maybe the answer is also to construct a key with custom implementation of rich comparisons? Now I'm also wondering about the best way to sort each chunk. The examples in [1] of complex sorts suggest the best way to do it is to first sort by the secondary key, then sort by the primary key, relying on the stability of the sort to get the desired outcome. But would it not be better to call sorted() once, supplying a custom key function? (As an aside, at the end of the section in [1] on Sort Stability and Complex sorts, it says "The Timsort algorithm used in Python does multiple sorts efficiently because it can take advantage of any ordering already present in a dataset." - I get that that's true, but I don't see how that's relevant to this strategy for doing complex sorts. I.e., if you sort first by the secondary key, you don't get any ordering that's helpful when you subsequently sort by the primary key. ...?) (Sorry, another side question, I'm guessing reading a chunk of data into a list and using Timsort, i.e., calling list.sort() or sorted(mylist), is quicker than using bisect to keep the chunk sorted as you build it?) > heapq's not unreasonable for the merging, but I think it's more common to > use a short list. Do you mean a regular Python list, and calling min()? > I have a bunch of Python sorts at > http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find your > need is specialized (EG, 3.x sorting by a secondary key that's a string, in > reverse), you could adapt one of these to do what you need. Thanks. Re 3.x sorting by a secondary key that's a string, in reverse, which one were you thinking of in particular? > heapq is not bad, but if you find you need a logn datastructure, you might > check out http://stromberg.dnsalias.org/~dstromberg/treap/ - a treap is also > logn, but has a very good amortized cost because it sacrifices keeping > things perfectly balanced (and rebalancing, and rebalancing...) to gain > speed.? But still, you might be better off with a short list and min. Thanks, that's really helpful. Cheers, Alistair [1] http://wiki.python.org/moin/HowTo/Sorting/ [2] http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ > On Mon, Aug 1, 2011 at 8:33 AM, aliman wrote: >> >> Hi all, >> >> Apologies I'm sure this has been asked many times, but I'm trying to >> figure out the most efficient way to do a complex sort on very large >> files. >> >> I've read the recipe at [1] and understand that the way to sort a >> large file is to break it into chunks, sort each chunk and write >> sorted chunks to disk, then use heapq.merge to combine the chunks as >> you read them. >> >> What I'm having trouble figuring out is what to do when I want to sort >> by one key ascending then another key descending (a "complex sort"). >> >> I understand that sorts are stable, so I could just repeat the whole >> sort process once for each key in turn, but that would involve going >> to and from disk once for each step in the sort, and I'm wondering if >> there is a better way. >> >> I also thought you could apply the complex sort to each chunk before >> writing it to disk, so each chunk was completely sorted, but then the >> heapq.merge wouldn't work properly, because afaik you can only give it >> one key. >> >> Any help much appreciated (I may well be missing something glaringly >> obvious). >> >> Cheers, >> >> Alistair >> >> [1] >> http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- -- Alistair Miles Head of Epidemiological Informatics Centre for Genomics and Global Health The Wellcome Trust Centre for Human Genetics Roosevelt Drive Oxford OX3 7BN United Kingdom Web: http://purl.org/net/aliman Email: alimanfoo at gmail.com Tel: +44 (0)1865 287669 From anddimario at gmail.com Tue Aug 2 06:36:44 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Tue, 2 Aug 2011 12:36:44 +0200 Subject: Notifications when process is killed Message-ID: > You won't be able to catch SIGTERM, as Thomas said, but if you need to > know what caused a process to end, the best way is to have code in the > parent process to catch SIGCHLD. When the child ends, for any reason, > its parent is sent SIGCHLD with some parameters, including the signal > number that caused the termination; you can then log anything you > want. Hi, i understand, i've read that SIGKILL can't catch, but nothing about SIGTERM. If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or not? Thanks, regards. -- Andrea Di Mario From rosuav at gmail.com Tue Aug 2 06:44:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 11:44:01 +0100 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:36 AM, Andrea Di Mario wrote: > If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or not? What you would do is create two processes. Set up your signal handlers, then fork; in the parent, just watch for the child's death - in the child, do all your work. When the parent receives SIGCHLD, it can ascertain the cause of death. ChrisA From tzhang at sinap.ac.cn Tue Aug 2 07:00:39 2011 From: tzhang at sinap.ac.cn (=?gb2312?B?1cXNrg==?=) Date: Tue, 2 Aug 2011 19:00:39 +0800 Subject: python reading file memory cost In-Reply-To: References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> Thanks Peter! Your explanation is great! And one more question: Why it is still keeping the memory even when I del the large array in interactive python mode? -----Original Message----- From: Peter Otten [mailto:__peter__ at web.de] Sent: Tuesday, August 02, 2011 4:26 PM To: python-list at python.org Subject: Re: python reading file memory cost Chris Rebert wrote: >> The running result was that read a 500M file consume almost 2GB RAM, >> I cannot figure it out, somebody help! > > If you could store the floats themselves, rather than their string > representations, that would be more space-efficient. You could then > also use the `array` module, which is more space-efficient than lists > (http://docs.python.org/library/array.html ). Numpy would also be > worth investigating since multidimensional arrays are involved. > > The next obvious question would then be: do you /really/ need /all/ of > the data in memory at once? This is what you (OP) should think about really hard before resorting to the optimizations mentioned above. Perhaps you can explain what you are doing with the data once you've loaded it into memory? > Also, just so you're aware: > http://docs.python.org/library/sys.html#sys.getsizeof To give you an idea how memory usage explodes: >>> line = "1.23 4.56 7.89 0.12\n" >>> len(line) # size in the file 20 >>> sys.getsizeof(line) 60 >>> formatted = ["%2.6E" % float(x) for x in line.split()] >>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) 312 From no at nowhere.net.no Tue Aug 2 07:06:55 2011 From: no at nowhere.net.no (TheSaint) Date: Tue, 02 Aug 2011 19:06:55 +0800 Subject: how to solve it? References: Message-ID: ???? wrote: > from matplotlib.matlab import * maybe you didn't install it http://matplotlib.sourceforge.net/ BTW you haven't mention what version of python you're running. From t at jollybox.de Tue Aug 2 07:09:57 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 13:09:57 +0200 Subject: python reading file memory cost In-Reply-To: <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> Message-ID: <4E37DB05.1020500@jollybox.de> On 02/08/11 13:00, ?? wrote: > Thanks Peter! Your explanation is great! > And one more question: > Why it is still keeping the memory even when I del the large array in > interactive python mode? This is an optimisation of the way the Python interpreter allocates memory: it holds on to memory it's not using any more for a while so it can be easily re-used for new objects --- this is more efficient than giving the memory back to the operating system only to request it again shortly afterwards. > > -----Original Message----- > From: Peter Otten [mailto:__peter__ at web.de] > Sent: Tuesday, August 02, 2011 4:26 PM > To: python-list at python.org > Subject: Re: python reading file memory cost > > Chris Rebert wrote: > >>> The running result was that read a 500M file consume almost 2GB RAM, >>> I cannot figure it out, somebody help! >> >> If you could store the floats themselves, rather than their string >> representations, that would be more space-efficient. You could then >> also use the `array` module, which is more space-efficient than lists >> (http://docs.python.org/library/array.html ). Numpy would also be >> worth investigating since multidimensional arrays are involved. >> >> The next obvious question would then be: do you /really/ need /all/ of >> the data in memory at once? > > This is what you (OP) should think about really hard before resorting to the > optimizations mentioned above. Perhaps you can explain what you are doing > with the data once you've loaded it into memory? > >> Also, just so you're aware: >> http://docs.python.org/library/sys.html#sys.getsizeof > > To give you an idea how memory usage explodes: > >>>> line = "1.23 4.56 7.89 0.12\n" >>>> len(line) # size in the file > 20 >>>> sys.getsizeof(line) > 60 >>>> formatted = ["%2.6E" % float(x) for x in line.split()] >>>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) > 312 > > > > From kushal.kumaran+python at gmail.com Tue Aug 2 07:15:17 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 2 Aug 2011 16:45:17 +0530 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 1:56 PM, Thomas Rachel wrote: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. > You must mean SIGKILL. There's nothing special about SIGTERM, except that it's the default for the kill command. -- regards, kushal From python.list at tim.thechases.com Tue Aug 2 07:17:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 02 Aug 2011 06:17:10 -0500 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <4E37DCB6.4070704@tim.thechases.com> On 08/02/2011 04:32 AM, loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links While Peter & Thomas gave good answers, also be aware that hard-links can't cross mount-points (an OS limitation). So if you have something mounted under the directory you're trying to hard-link-copy, attempting to create a hard-link will fail for things within that mount. -tkc From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 07:40:22 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 13:40:22 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: Am 02.08.2011 10:26 schrieb Thomas Rachel: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. Thank you for pointing out (via email) that this is wrong: SIGTERM is a normal signal which can be caught in the normal way. SIGKILL is (besides SIGSTOP) the one which cannot be caught, blocked or ignored. Thomas From kliateni at gmail.com Tue Aug 2 07:45:15 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 13:45:15 +0200 Subject: Please code review. Message-ID: <4E37E34B.5080707@gmail.com> Hello, I need a generator to create the cellname in a excell (using pyuno) document to assign value to the correct cell. The following code does this but do you have some optimizations on it, for instance to get the alphabetic chars instead of hard-coding it. Cheers karim Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def _xrange_cellnames(rows, cols): ... """Internal iterator function to compute excell table cellnames.""" ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ... for row in xrange(1, rows+1): ... for char in cellnames.replace('', ' ').split()[:cols]: ... yield char + str(row) ... >>> list( _xrange_cellnames(rows=3,cols=4)) ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] From paul at subsignal.org Tue Aug 2 08:04:45 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Tue, 02 Aug 2011 14:04:45 +0200 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: Am 02.08.2011 13:45, schrieb Karim: > > Hello, > > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to > the correct cell. The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. you can use: import string cellnames = string.ascii_uppercase not sure why you need the .replace().split() stuff... def _xrange_cellnames(rows, cols): cellnames = string.ascii_uppercase for row in xrange(1, rows+1): for char in cellnames[:rows]: yield char + str(row) cheers Paul > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > > From rosuav at gmail.com Tue Aug 2 08:07:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 13:07:28 +0100 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: On Tue, Aug 2, 2011 at 12:45 PM, Karim wrote: > ... ? ? ? ? for char in cellnames.replace('', ' ').split()[:cols]: for char in cellnames[:cols]: Strings are iterable over their characters. Alternatively, you could use chr and ord, but it's probably cleaner and simpler to have the string there. It also automatically and implicitly caps your columns at 26. On the other hand, if you want to support more than 26 columns, you may want to make your own generator function to yield 'A', 'B',... 'Z', 'AA', 'AB', etc. ChrisA From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 08:16:00 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 08:16:00 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2011 06:06 PM, Steven D'Aprano wrote: > Does your definition of "fixed" mean "gives wrong results for n>= 4 "? > >>>> fibo(4) == 3 > False > Well, I don't know if you're trolling or just dumb: http://en.wikipedia.org/wiki/Fibonacci_number In [2]: for i in range(10): ...: print fibo(i) ...: ...: 0.0 1.0 1.0 2.0 3.0 5.0 8.0 13.0 21.0 34.0 -- Bill From grco at brute4ce.com Tue Aug 2 08:22:17 2011 From: grco at brute4ce.com (Martin Gracik) Date: Tue, 2 Aug 2011 14:22:17 +0200 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: On Tue, Aug 2, 2011 at 1:45 PM, Karim wrote: > > Hello, > > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to > the correct cell. The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=**4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > > > -- > http://mail.python.org/**mailman/listinfo/python-list > You could use something like this: Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import imap, product >>> import string >>> >>> def get_cellnames(rows, cols): ... return imap(str().join, product(string.ascii_uppercase[:cols], ... imap(str, range(1, rows + 1)))) ... >>> print list(get_cellnames(rows=3, cols=4)) ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3', 'D1', 'D2', 'D3'] -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Aug 2 08:27:03 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 14:27:03 +0200 Subject: Please code review. References: <4E37E34B.5080707@gmail.com> Message-ID: Karim wrote: > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to the correct cell. Isn't there a way to use a (row, column) tuple directly? If so I'd prefer that. Also, there used to be an alternative format to address a spreadsheet cell with something like "R1C2". > The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table > cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: That is interesting ;) But for maximum clarity use for char in cellnames[:cols]: instead. > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] Here's my (untested) attempt to handle columns beyond "Z": from itertools import chain, count, imap, islice, product from string import ascii_uppercase def columnnames(): alpha = (ascii_uppercase,) return imap("".join, chain.from_iterable(product(*alpha*i) for i in count(1))) def cellnames(columns, rows): for row in xrange(1, rows+1): for column in islice(columnnames(), columns): yield column + str(row) if __name__ == "__main__": import sys print list(cellnames(*map(int, sys.argv[1:]))) I think the subject has come up before; goo^h^h^h the search engine of your choice is your friend. From kliateni at gmail.com Tue Aug 2 08:28:01 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:28:01 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37ED51.7010402@gmail.com> Thanks Paul, I never used string module. In fact, cellnames.split('') gives a syntax error w/ empty string. That's why I use the intermediate replace() which accept that. Cheers Karim On 08/02/2011 02:04 PM, Paul K?lle wrote: > Am 02.08.2011 13:45, schrieb Karim: >> >> Hello, >> >> I need a generator to create the cellname in a excell (using pyuno) >> document to assign value to >> the correct cell. The following code does this but do you have some >> optimizations >> on it, for instance to get the alphabetic chars instead of >> hard-coding it. > you can use: > import string > cellnames = string.ascii_uppercase > > not sure why you need the .replace().split() stuff... > > > def _xrange_cellnames(rows, cols): > cellnames = string.ascii_uppercase > for row in xrange(1, rows+1): > for char in cellnames[:rows]: > yield char + str(row) > > cheers > Paul > > >> >> Cheers >> karim >> >> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) >> [GCC 4.5.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def _xrange_cellnames(rows, cols): >> ... """Internal iterator function to compute excell table cellnames.""" >> ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >> ... for row in xrange(1, rows+1): >> ... for char in cellnames.replace('', ' ').split()[:cols]: >> ... yield char + str(row) >> ... >> >>> list( _xrange_cellnames(rows=3,cols=4)) >> ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] >> >> > > From kliateni at gmail.com Tue Aug 2 08:33:32 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:33:32 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37EE9C.4090701@gmail.com> Thanks Chris! It seems I am blind I should have seen it... In fact I started with the need (imaginary) to use enumerate() to get some indices but ended in a more simple code. Indeed, your's is simpler. For the double chars extension I will see if I need it in the future. Cheers Karim On 08/02/2011 02:07 PM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 12:45 PM, Karim wrote: >> ... for char in cellnames.replace('', ' ').split()[:cols]: > for char in cellnames[:cols]: > > Strings are iterable over their characters. Alternatively, you could > use chr and ord, but it's probably cleaner and simpler to have the > string there. It also automatically and implicitly caps your columns > at 26. On the other hand, if you want to support more than 26 columns, > you may want to make your own generator function to yield 'A', 'B',... > 'Z', 'AA', 'AB', etc. > > ChrisA From alain at dpt-info.u-strasbg.fr Tue Aug 2 08:45:46 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 02 Aug 2011 14:45:46 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> writes: > On 08/01/2011 06:06 PM, Steven D'Aprano wrote: >> Does your definition of "fixed" mean "gives wrong results for n>= 4 "? > Well, I don't know if you're trolling or just dumb: Steven is right, and you look dumb. >>> fibo(4) 3.0000000000000004 Even though the math is correct, your program is wrong. It doesn't even produce integers. And it will fail with overflow for big values. -- Alain. From kliateni at gmail.com Tue Aug 2 08:47:14 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:47:14 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37F1D2.2090505@gmail.com> On 08/02/2011 02:27 PM, Peter Otten wrote: > Karim wrote: > >> I need a generator to create the cellname in a excell (using pyuno) >> document to assign value to the correct cell. > Isn't there a way to use a (row, column) tuple directly? If so I'd prefer > that. Also, there used to be an alternative format to address a spreadsheet > cell with something like "R1C2". > In fact, in pyuno I get the following code: values = ( (22.5,21.5,121.5), (5615.3,615.3,-615.3), (-2315.7,315.7,415.7) ) table.getCellByName("A2").setValue(22.5) table.getCellByName("B2").setValue(5615.3) table.getCellByName("C2").setValue(-2315.7) Indeed the values tuple is formated like (row, column). I want to write simply and get cellname ondemand via an iterator function like that: values = ( (22.5,21.5,121.5), (5615.3,615.3,-615.3), (-2315.7,315.7,415.7) ) it = _xrange_cellnames(rows=len(value), cols=len(values[0])) table.getCellByName(it.next()).setValue(22.5) table.getCellByName(it.next()).setValue(5615.3) table.getCellByName(it.next()).setValue(-2315.7) >> The following code does this but do you have some >> optimizations >> on it, for instance to get the alphabetic chars instead of hard-coding it. >> >> Cheers >> karim >> >> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) >> [GCC 4.5.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def _xrange_cellnames(rows, cols): >> ... """Internal iterator function to compute excell table >> cellnames.""" >> ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >> ... for row in xrange(1, rows+1): >> ... for char in cellnames.replace('', ' ').split()[:cols]: > That is interesting ;) But for maximum clarity use > > for char in cellnames[:cols]: > > instead. Yes I am blind ;o) I did not see simplification. Simple is better than complicate... >> ... yield char + str(row) >> ... >> >>> list( _xrange_cellnames(rows=3,cols=4)) >> ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > Here's my (untested) attempt to handle columns beyond "Z": > > from itertools import chain, count, imap, islice, product > from string import ascii_uppercase > > def columnnames(): > alpha = (ascii_uppercase,) > return imap("".join, chain.from_iterable(product(*alpha*i) for i in > count(1))) > > def cellnames(columns, rows): > for row in xrange(1, rows+1): > for column in islice(columnnames(), columns): > yield column + str(row) > > > if __name__ == "__main__": > import sys > print list(cellnames(*map(int, sys.argv[1:]))) > > I think the subject has come up before; goo^h^h^h the search engine of your > choice is your friend. I will study this one and itertools modules, many thanks. Cheers Karim From kliateni at gmail.com Tue Aug 2 08:53:38 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:53:38 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> <4E37EF35.2080403@gmail.com> Message-ID: <4E37F352.1090208@gmail.com> Thanks Martin, This is the generator expression version. I can use both function generator or generator expression version correction. Cheers Karim On 08/02/2011 02:47 PM, Martin Gracik wrote: > def get_cellnames2(rows, cols): > rows = range(1, rows + 1) > cols = string.ascii_uppercase[:cols] > return ('%s%s' % (col, row) for row in rows for col in cols) From Shambhu.Rajak at kpitcummins.com Tue Aug 2 09:02:43 2011 From: Shambhu.Rajak at kpitcummins.com (Shambhu Rajak) Date: Tue, 2 Aug 2011 13:02:43 +0000 Subject: Require information on python API for Subversion related work Message-ID: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> Hi , I need an api that can be used to do following operations on Subversion repository tool: 1. Create branch 2. Check out 3. Check in 4. Merge Regards, Shambhu -------------- next part -------------- An HTML attachment was scrubbed... URL: From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 09:16:59 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 09:16:59 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Message-ID: On 08/02/2011 08:45 AM, Alain Ketterlin wrote: > produce integers. And it will fail with overflow for big values. If it would make you feel better I can use decimal. Also, perhaps I can name my function billy_fibo(n), which is defined as billy_fibo(n) +error(n) = fibo(n), where error(n) can be made arbitrarily small. This runs in constant time rather than linear (memoized) or exponential (fully recursive) at the cost of a minutia of accuracy. I find this tradeoff acceptable. -- Bill From __peter__ at web.de Tue Aug 2 09:59:32 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 15:59:32 +0200 Subject: Please code review. References: <4E37E34B.5080707@gmail.com> <4E37F1D2.2090505@gmail.com> Message-ID: Karim wrote: > values = ( (22.5,21.5,121.5), > (5615.3,615.3,-615.3), > (-2315.7,315.7,415.7) ) > > it = _xrange_cellnames(rows=len(value), cols=len(values[0])) > > table.getCellByName(it.next()).setValue(22.5) > table.getCellByName(it.next()).setValue(5615.3) > table.getCellByName(it.next()).setValue(-2315.7) Some googling suggests that there exists a getCellByPosition() method. With that the above would become (untested): for x, column in enumerate(values): for y, value in enumerate(column): table.getCellByPosition(x, y).setValue(value) From steve+comp.lang.python at pearwood.info Tue Aug 2 10:15:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 00:15:45 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e380692$0$29970$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > On 08/02/2011 08:45 AM, Alain Ketterlin wrote: >> produce integers. And it will fail with overflow for big values. > > If it would make you feel better I can use decimal. > > Also, perhaps I can name my function billy_fibo(n), which is defined as > billy_fibo(n) +error(n) = fibo(n), where error(n) can be made > arbitrarily small. So you say, but I don't believe it. Given fibo, the function you provided earlier, the error increases with N: >>> fibo(82) - fib(82) # fib returns the accurate Fibonacci number 160.0 >>> fibo(182) - fib(182) 2.92786721937918e+23 Hardly "arbitrarily small". Your function also overflows for N = 1475: >>> fibo(1475) Traceback (most recent call last): File "", line 1, in File "", line 3, in fibo OverflowError: (34, 'Numerical result out of range') The correct value only has 307 digits, so it's not that large a number for integer math. I won't show them all, but it starts and ends like this: 8077637632...87040886025 > This runs in constant time rather than linear > (memoized) A good memoisation scheme will run in constant time (amortised). > or exponential (fully recursive) Good heavens no. Only the most naive recursive algorithm is exponential. Good ones (note plural) are linear. Combine that with memoisation, and you have amortised constant time. > at the cost of a minutia of accuracy. I'm reminded of a time my wife was travelling across the US with her band's roadies. At some point crossing the miles and miles of highway through the desert, she pointed out that they were lost and nowhere even close to the city where they were supposed to be playing. The driver answered, "Who cares, we're making great time!" (True story.) > I find this tradeoff acceptable. Given that Fibonacci numbers are mostly of interest to number theorists, who care about the *actual* Fibonacci numbers and not almost-but-not-quite Fibonacci numbers, I'm having a lot of difficulty imagining what sort of application you have in mind that could legitimately make that trade-off. -- Steven From kliateni at gmail.com Tue Aug 2 10:19:05 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 16:19:05 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> <4E37F1D2.2090505@gmail.com> Message-ID: <4E380759.2020709@gmail.com> On 08/02/2011 03:59 PM, Peter Otten wrote: > Karim wrote: > >> values = ( (22.5,21.5,121.5), >> (5615.3,615.3,-615.3), >> (-2315.7,315.7,415.7) ) >> >> it = _xrange_cellnames(rows=len(value), cols=len(values[0])) >> >> table.getCellByName(it.next()).setValue(22.5) >> table.getCellByName(it.next()).setValue(5615.3) >> table.getCellByName(it.next()).setValue(-2315.7) > Some googling suggests that there exists a getCellByPosition() method. With > that the above would become (untested): > > for x, column in enumerate(values): > for y, value in enumerate(column): > table.getCellByPosition(x, y).setValue(value) Thanks for the tip I will check com.sun.star.text.TextTable API. Regards Karim From ndbecker2 at gmail.com Tue Aug 2 10:19:20 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 02 Aug 2011 10:19:20 -0400 Subject: 'Use-Once' Variables and Linear Objects Message-ID: I thought this was an interesting article http://www.pipeline.com/~hbaker1/Use1Var.html From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 10:40:06 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 10:40:06 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> <4e380692$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/02/2011 10:15 AM, Steven D'Aprano wrote: > So you say, but I don't believe it. Given fibo, the function you provided > earlier, the error increases with N: > >>>> fibo(82) - fib(82) # fib returns the accurate Fibonacci number > 160.0 >>>> fibo(182) - fib(182) > 2.92786721937918e+23 > > Hardly "arbitrarily small". Perhaps the individual number is big, but compare that to: (fibo(n) - fib(n)) / fib(n) The number is still quite close to the actual answer. > Your function also overflows for N = 1475: > >>>> fibo(1475) > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in fibo > OverflowError: (34, 'Numerical result out of range') > > > The correct value only has 307 digits, so it's not that large a number for > integer math. I won't show them all, but it starts and ends like this: > > 8077637632...87040886025 Yes, I mentioned possibly using the decimal class, which I suppose does lose the constant access time depending on how its implemented. > A good memoisation scheme will run in constant time (amortised). Amortized perhaps, but this assumes the call happening a number of times. Also, this requires linear memory to store previous values. > Good heavens no. Only the most naive recursive algorithm is exponential. > Good ones (note plural) are linear. Combine that with memoisation, and you > have amortised constant time. > Not all recursive functions can be memoized (or they can but for practically no benefit). What I was getting at was that a closed form expression of a recurrence might be significantly faster at an acceptable loss in accuracy. For an example, see the Ackermann function. > Given that Fibonacci numbers are mostly of interest to number theorists, who > care about the *actual* Fibonacci numbers and not almost-but-not-quite > Fibonacci numbers, I'm having a lot of difficulty imagining what sort of > application you have in mind that could legitimately make that trade-off. I was trying to show that there is an alternate method of calculation. Accuracy losses are really a problem with the underlying machinery rather than the high level code. If the recursive form of fib() were written in c, the integers would have overflown a long while ago compared to float. One other note, Fibonacci numbers grow exponentially fast (with respect to the number of bits), and python's integer multiplication takes exponential time (karatsuba rather than fft). If we are going to discuss the behavior of python's numeric types, then lets talk about how slow python will become for the nth Fibonacci integer and how much space it will take compared to the floating point short concise and almost as close form. -- Bill From cartercc at gmail.com Tue Aug 2 10:41:06 2011 From: cartercc at gmail.com (ccc31807) Date: Tue, 2 Aug 2011 07:41:06 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> On Jul 31, 2:38?pm, gavino wrote: > facebook is php > > myspace is microsoft > > aol was tcl and aolserver c embedding tcl interp > > priceline is lisp > > reddit is python was lisp orig > > amazon was perl > > livejournal was perl Most of these are tech companies. Tech companies are very important, but so are other kinds of companies. What do manufacturing companies use, like Ford and Toyota, energy companies like BP and Exxon, pharmaceutical companies, consumer product companies, and so on? What about the big retailers, Sears, WalMart, Target, etc.? CC. From steve+comp.lang.python at pearwood.info Tue Aug 2 10:45:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 00:45:34 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> harrismh777 wrote: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. xrange does not return an iterator. It returns a lazy iterable object, which is not the same thing. In Python, "iterator" is not merely a generic term for something which can be iterated over. An iterator is an object which obeys the iterator protocol, which depends on at least two properties: * the object must have a next() method, which returns values until the iterator is exhausted, and then raises StopIteration; (In Python 3, the method is __next__.) * and the object must have an __iter__() method which returns itself. (Also, "non-broken" iterators will continue to raise StopIteration once they do so once. That is, they can't be reset or repeated.) xrange objects fail on both accounts. (Likewise for range objects in Python 3.) [...] > These are coded with range(). The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. I find these results surprising, at least for numbers as small as 8128, and suspect your timing code is inaccurate. (But don't make the mistake of doing what I did, which was to attempt to produce range(290000000) in Python 2. After multiple *hours* of swapping, I was finally able to kill the Python process and get control of my PC again. Sigh.) I would expect that, in general, Python 3.1 or 3.2 is slightly slower than Python 2.6 or 2.7. (If you're using Python 3.0, stop now!) But in Python 2, I wouldn't expect orders of magnitude difference in range and xrange. Using the function perf(N) you gave, and a modified copy perfx(N) which simply replaces xrange for range, I get these timings in Python2.6: >>> from timeit import Timer >>> t1 = Timer('perf(10000)', 'from __main__ import perf') >>> t2 = Timer('perfx(10000)', 'from __main__ import perfx') >>> min(t1.repeat(number=1000, repeat=5)) 3.0614659786224365 >>> min(t2.repeat(number=1000, repeat=5)) 2.8787298202514648 A small difference, but not an order of magnitude. In Python 3.1, I get this: >>> min(t1.repeat(number=1000, repeat=5)) 3.4577009677886963 > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? Oh indubitably. I doubt it will need a PEP. Python 3.x is still quite young, and the focus is on improving unicode support, but performance improvements will usually be welcome. However, at some point I would expect adding hand-crafted optimizations to CPython will cease to be worthwhile. Guido is already talking about CPython becoming the reference implementation, and PyPy the production implementation because it's faster. PyPy's optimizing compiler is already about twice as fast as CPython, and for at least one specially crafted example, faster than C: http://morepypy.blogspot.com/2011/02/pypy-faster-than-c-on-carefully-crafted.html -- Steven From mail at timgolden.me.uk Tue Aug 2 10:46:32 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 02 Aug 2011 15:46:32 +0100 Subject: Require information on python API for Subversion related work In-Reply-To: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> References: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> Message-ID: <4E380DC8.5020008@timgolden.me.uk> On 02/08/2011 14:02, Shambhu Rajak wrote: > I need an api that can be used to do following operations on Subversion > repository tool: > > 1.Create branch > > 2.Check out > > 3.Check in > > 4.Merge http://pysvn.tigris.org/ (which is, by the way, the first Google hit for "Python Subversion bindings") TJG From hansmeetschool at gmail.com Tue Aug 2 11:30:04 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Tue, 2 Aug 2011 08:30:04 -0700 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: you shouldn't have anything to worry about SIGTERM if you send out a SIGCHLD On Tue, Aug 2, 2011 at 3:44 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:36 AM, Andrea Di Mario > wrote: > > If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or > not? > > What you would do is create two processes. Set up your signal > handlers, then fork; in the parent, just watch for the child's death - > in the child, do all your work. When the parent receives SIGCHLD, it > can ascertain the cause of death. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Aug 2 11:38:26 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Aug 2011 11:38:26 -0400 Subject: [ANN] IPython 0.11 is officially out In-Reply-To: References: Message-ID: On 8/1/11 8:54 AM, Thorsten Kampe wrote: > The documentation[1] says "If you are upgrading to version 0.11 of > IPython, you will need to migrate your old ipythonrc or ipy_user_conf.py > configuration files to the new system. Read on for information on how to > do this." Unfortunately there is no more mentioning of "migration", so > the developers' approach seems to be: "read all about the new > configuration system and see if you can somehow duplicate your old > ipythonrc settings. Good luck!". Or you can ask nicely on ipython-user, and we can help you migrate your old ipythonrc. http://mail.scipy.org/mailman/listinfo/ipython-user You can basically start with the ipython_config.py that is generated the first time and edit it. It is fully commented and demonstrates every configurable option with the defaults commented out. You just uncomment the appropriate lines and put in your values. You are right that the HOWTO migrate documentation is missing. It's an oversight that you can help remedy. -- 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 thinke365 at gmail.com Tue Aug 2 11:52:42 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 2 Aug 2011 23:52:42 +0800 Subject: python import error, what's wrong? Message-ID: I am using pydev plugin in eclipse, all things works just as well but now i have confronted with a confusing problem, that is i can import a module write by myself successfully, but when i try to run this program, error just shows up, what's wrong? the directory structure is as follows: src org.test A.py org.lab B.py contents of A seems like: class A ... contents of B seems like: // I try to run B.py, python import error just appears, why? from org.test.A import A a = A() From rantingrick at gmail.com Tue Aug 2 12:03:19 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 2 Aug 2011 09:03:19 -0700 (PDT) Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> <877h6xzgpm.fsf@mithlond.arda> Message-ID: On Aug 1, 3:19?am, Teemu Likonen wrote: > * 2011-07-30T10:57:29+10:00 * Steven D'Aprano wrote: > > > Teemu Likonen wrote: > >> Pathnames and the separator for pathname components should be > >> abstracted away, to a pathname object. > > > Been there, done that, floundered on the inability of people to work > > out the details. > > >http://www.python.org/dev/peps/pep-0355/ > > I'm very much a Lisp person and obviously got the idea of pathname > objects from Common Lisp. Lazily I'm also learning Python too but at the > moment I can't comment on the details of that PEP. Yet, generally I > think that's the way to improve pathnames, not the "rantinrick's". This thread was intended to expose another PyWart and get the community juices flowing. os.path is broken and cannot be repaired because os.path was an improper API to begin with. The only way to solve this problem is to introduce a new Path object. A new Path object is the answer. Some have said "been there, done that" with a sarcastic and defeatist point of view. I say we need to re-visit the proposal of PEP-0355 and hash out something quickly. We also need to realize that one day or another this Path object is going to become reality and the longer we drag our feet getting it implemented the more painful the transition is going to be. I feel Python community is in an awkward teenage stage at this point not really sure of it's self or direction. Living only for today with no ability to project the future and wasting too much time arguing over minutiae. We need a collective wake-up-call in the form of a slap on the face. We need to start making the hard choices necessary to clean up this library. Python3000 was only the beginning! ONLY THE BEGINNING! From rosuav at gmail.com Tue Aug 2 12:06:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:06:21 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 3:45 PM, Steven D'Aprano wrote: > (But don't make the mistake of doing what I did, which was to attempt to > produce range(290000000) in Python 2. After multiple *hours* of swapping, I > was finally able to kill the Python process and get control of my PC again. > Sigh.) > That is sad. (And, I am only slightly ashamed to admit it, quite funny.) But on the other hand, quite impressive that it didn't bomb anywhere! Whenever I'm about to do something really dangerous, I like to first open an SSH session from another computer - bash running inside there can usually kill any process fairly efficiently, without need for UI interaction. Failing that, good ol' Ctrl-Alt-F1 to get to a console is usually the next best, but sometimes logging in requires a lot of resources. This is actually one place where I'm really glad Python doesn't do much with multiple threads (for instance, it won't gc on another thread). A dual core CPU keeps everything happy! ChrisA From rosuav at gmail.com Tue Aug 2 12:20:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:20:07 +0100 Subject: python import error, what's wrong? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 4:52 PM, smith jack wrote: > from org.test.A import A This is going to look for org/test/A.py but not for org.test/A.py - are you able to rename your directories to not have dots? ChrisA From thinke365 at gmail.com Tue Aug 2 12:20:48 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 00:20:48 +0800 Subject: How to define repeated string when using the re module? Message-ID: if it's for a single character, this should be very easy, such as c{m,n} the occurrence of c is between m and n, if i want to define the occurrence of (.*?) how should make it done? ((.*?)){1,3} seems not work, any method to define repeat string using python regex? From rosuav at gmail.com Tue Aug 2 12:36:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:36:57 +0100 Subject: PyWart: os.path needs immediate attention! In-Reply-To: References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> <877h6xzgpm.fsf@mithlond.arda> Message-ID: On Tue, Aug 2, 2011 at 5:03 PM, rantingrick wrote: > This thread was intended to expose another PyWart and get the > community juices flowing. os.path is broken and cannot be repaired > because os.path was an improper API to begin with. The only way to > solve this problem is to introduce a new Path object. > > A new Path object is the answer. http://xkcd.com/927/ > I feel Python community is in an awkward teenage stage at this point > not really sure of it's self or direction. Living only for today with > no ability to project the future and wasting too much time arguing > over minutiae. We need a collective wake-up-call in the form of a slap > on the face. We need to start making the hard choices necessary to > clean up this library. > > Python3000 was only the beginning! ONLY THE BEGINNING! Some of us have reached the level of maturity necessary to understand that stability is valuable. Also to notice when requirements internally conflict - how are we going to develop the One Perfect API without spending a lot of time arguing minutiae? One thing I have learned in life is that mature products have their warts for a reason, and that reason is usually compatibility. That's not necessarily a good thing, but nor is it necessarily bad. For instance, the Python source code is managed by automake. We could save ourselves a LOT of trouble by simply moving to the future - a future in which Linux is the only operating system we bother with, that 64-bit hardware and 64-bit OSes are everything, and so on. Why bother supporting the past? But that "past" is actually a huge part of the world today, too. Large-scale adoption is an incredibly valuable thing, and you are narrowing your adoption potential considerably if you do not support these things. As an example, have you ever noticed how horribly useless and skeletal the Python documentation is? Neither have I. It's used by so many people that it gets eyeballs, and therefore time, to fix up its failings. Compare with Pike, a much more obscure language (syntactically similar to C, but under the covers quite similar to Python); scroll down this list of constants from its Stdio module: http://pike.ida.liu.se/generated/manual/modref/ex/predef_3A_3A/Stdio.html A good number of them simply say FIXME, and even those that _are_ documented have only brief explanations. For quite a few things, you need to go direct to the language's source code. (Do a docs search for FIXME and you'll find that this is not an isolated case.) That doesn't happen with Python, largely a consequence (if somewhat indirectly) of its being so widely used. Sure you can make your life easier. But is it really better? Chris Angelico From rosuav at gmail.com Tue Aug 2 12:55:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:55:30 +0100 Subject: Early binding as an option Message-ID: As I understand it, Python exclusively late-binds names; when you define a function, nothing is ever pre-bound. This allows a huge amount of flexibility (letting you "reach into" someone else's function and change its behaviour), but it's flexibility that most programs use seldom if at all. First off: Is there any way to request/cause some names to be bound early? and secondly, should there be? Argument against: Late binding is a Good Thing, and having some things bound early would be confusing. Argument in favour: Efficiency is also a Good Thing, and with staples like 'len', it's unlikely anyone will want to change them - yet the interpreter still has to do a namespace lookup every time. I would want the end programmer to have the ultimate power here (not the module designer). Something along the lines of: This global name will never change, so don't bother looking it up every time. As an example of this difference, Pike uses early binding for some things; when I did the perfect numbers testing in the other thread (discussion thread, not thread of execution!), Pike performed significantly better; I believe this is in part due to the formal declarations of variables, and the consequential simplification of local code, although since there are no globals being looked up here, there's little to be gained from those. Is this the realm of JIT compilation, or can it be done in regular CPython? Chris Angelico From drsalists at gmail.com Tue Aug 2 13:07:44 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 10:07:44 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Tue, Aug 2, 2011 at 3:25 AM, Alistair Miles wrote: > Hi Dan, > > Thanks for the reply. > > On Mon, Aug 1, 2011 at 5:45 PM, Dan Stromberg wrote: > > > > Python 2.x, or Python 3.x? > > Currently Python 2.x. > So it sounds like you may want to move this code to 3.x in the future. > > What are the types of your sort keys? > > Both numbers and strings. > > > If you're on 3.x and the key you need reversed is numeric, you can negate > > the key. > > I did wonder about that. Would that not be doable also in Python 2.7, > using sorted(key=...)? > Yes, probably, though in 2.x it's easy to just use __cmp__. > > If you're on 2.x, you can use an object with a __cmp__ method to compare > > objects however you require. > > OK, right. > > Looking at the HowTo/Sorting again [1] and the bit about cmp_to_key, > could you also achieve the same effect by returning a key with custom > implementations of rich comparison functions? > Yes, I believe so,. though then you're back to a bit slower sorting. > > You probably should timsort the chunks (which is the standard > list_.sort() - > > it's a very good in-memory sort), and then merge them afterward using the > > merge step of merge sort. > > Yes, that's what I understood by the activestate recipe [2]. > > So I guess my question boils down to, how do you do the merge step for > a complex sort? (Assuming each chunk had been completely sorted > first.) > Open one file for each sorted list on disk. Save these files in a file_list, indexed by an integer (of course, since this is a list) - doing this means you have a mapping from an integer to a file. Read the first value from each such file. Note that one of these values will become the least value in the result list - the least value in the result file has to be the least value from one of the sorted sublists. Fill some datastructure (list, heap, treap, etc.) with tuples (value_from_sorted_list1, index_into_file_dict1), (value_from_sorted_list2, index_into_file_dict2), etc. Then pull out the least value from the list/heap/treap, and add it to the result file, and read another value from the _same_ file (which you can get back from your file_list) you got back and add a replacement tuple to your list/heap/treap. In this way, each step of the way, when merging n files, your list/heap/treap always has n values - until you reach the end of one or more of your sorted files. Then you always have less than n. When you hit EOF on some file, you just don't add anything back for that file. Resist the temptation to remove it from your file_list - that'll mess up the file indexes in the list/heap/treap. Continue as long as you have an open file. We're using a tuple instead of a class, because comparing tuples tends to be pretty fast. We're using file indexes instead of files, because I don't want to think about what happens when you compare two files with the < operator. :) Maybe the answer is also to construct a key with custom implementation > of rich comparisons? > Could be related. > Now I'm also wondering about the best way to sort each chunk. The > examples in [1] of complex sorts suggest the best way to do it is to > first sort by the secondary key, then sort by the primary key, relying > on the stability of the sort to get the desired outcome. But would it > not be better to call sorted() once, supplying a custom key function? > Function calls in CPython are expensive, so if you can sort (twice) using a key (decorate, sort, undecorate), that's probably a performance win. It's kind of a Software Engineering lose though, so using a class with one or more comparison methods can be a benefit too. > (As an aside, at the end of the section in [1] on Sort Stability and > Complex sorts, it says "The Timsort algorithm used in Python does > multiple sorts efficiently because it can take advantage of any > ordering already present in a dataset." - I get that that's true, but > I don't see how that's relevant to this strategy for doing complex > sorts. I.e., if you sort first by the secondary key, you don't get any > ordering that's helpful when you subsequently sort by the primary key. > ...?) > Agreed. Sounds irrelevant. > (Sorry, another side question, I'm guessing reading a chunk of data > into a list and using Timsort, i.e., calling list.sort() or > sorted(mylist), is quicker than using bisect to keep the chunk sorted > as you build it?) > Oh yeah. The bisection itself is just O(logn), but inserting into the correct place afterward is O(n). So unless n is tiny, you're better off with a heap or treap or red-black tree. It's the difference between an overall O(nlogn) algorithm and an O(n^2) algorithm - for large n, it's a big difference. > > heapq's not unreasonable for the merging, but I think it's more common to > > use a short list. > > Do you mean a regular Python list, and calling min()? > Yes. Depending on how many lists you wish to merge at a time. Note that in terms of file I/O, it may be faster to open as many file descriptors as you can and use a logn datastructure for the merges. But recall that you don't get infinite file descriptors, so there's a benefit to being able to do them m at a time, for some reasonable m. Merge sort is commonly written with m=2 for simplicity. > I have a bunch of Python sorts at > > http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find > your > > need is specialized (EG, 3.x sorting by a secondary key that's a string, > in > > reverse), you could adapt one of these to do what you need. > > Thanks. Re 3.x sorting by a secondary key that's a string, in reverse, > which one were you thinking of in particular? > timsort is great for in-memory sorting, but the version that comes with CPython is faster than the Cython version at the URL. But there's a merge sort at the URL that you could glance at for just the merge step. But if you find you need some code you can adapt to specific needs, the timsort at the URL is probably a good option. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Aug 2 13:15:16 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Aug 2011 18:15:16 +0100 Subject: How to define repeated string when using the re module? In-Reply-To: References: Message-ID: <4E3830A4.5010103@mrabarnett.plus.com> On 02/08/2011 17:20, smith jack wrote: > if it's for a single character, this should be very easy, such as > c{m,n} the occurrence of c is between m and n, > > if i want to define the occurrence of (.*?) how should make it > done? ((.*?)){1,3} seems not work, any method to define repeat > string using python regex? Why do you think it's not working? From t at jollybox.de Tue Aug 2 13:18:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 19:18:20 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E38315C.1000102@jollybox.de> On 02/08/11 18:55, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. > > First off: Is there any way to request/cause some names to be bound > early? and secondly, should there be? > > Argument against: Late binding is a Good Thing, and having some things > bound early would be confusing. Also, simplicity is a good thing, and Pytho name binding and scoping is very simple. > > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. > > I would want the end programmer to have the ultimate power here (not > the module designer). Something along the lines of: This global name > will never change, so don't bother looking it up every time. What you can do, as a module author, is bind builtins/globals as default function arguments, making them local variables. def uses_len (arg0, len=len): # you could probably write a decorator that strips away this kind of # "builtin" argument As the module user, there's no way AFAIK. However, is this really useful? I suppose it would be possible to introduce a kind of "constant globals" namespace that a JIT compiler could then use to optimise, but how much would this help? If the content of this namespace is unknown at the time the module is compiled (and it would be), then only a JIT compiler could use the information - which doesn't mean it couldn't improve performance significantly in some cases. More importantly, how can the module user know which globals should be declared constant? Only the module author can know which names are looked up often enough for optimisation to make sense, or even which names are looked up at all. I think this effect can only, and best, be achieved in Python by binding relevant globals as locals in the module, and documenting which these are for the benefit of users who might want to change builtins, and would have to do it before importing the module. Thomas > > As an example of this difference, Pike uses early binding for some > things; when I did the perfect numbers testing in the other thread > (discussion thread, not thread of execution!), Pike performed > significantly better; I believe this is in part due to the formal > declarations of variables, and the consequential simplification of > local code, although since there are no globals being looked up here, > there's little to be gained from those. > > Is this the realm of JIT compilation, or can it be done in regular CPython? > > Chris Angelico From clp2 at rebertia.com Tue Aug 2 13:22:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 10:22:28 -0700 Subject: How to define repeated string when using the re module? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:20 AM, smith jack wrote: > if it's for a single character, this should be very easy, such as > c{m,n} ? the occurrence of c is between m and n, > > if i want to define the occurrence of (.*?) ?how should make it > done? ?((.*?)){1,3} ?seems not work, any method to define repeat > string using python regex? Don't parse HTML using regexes; use an HTML parser! http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags Here's a survey of Python HTML parsing libraries: http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Tue Aug 2 13:30:31 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 10:30:31 -0700 Subject: 'Use-Once' Variables and Linear Objects In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 7:19 AM, Neal Becker wrote: > I thought this was an interesting article > > http://www.pipeline.com/~hbaker1/Use1Var.html See also: http://en.wikipedia.org/wiki/Uniqueness_type Cheers, Chris From rosuav at gmail.com Tue Aug 2 13:42:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 18:42:01 +0100 Subject: Early binding as an option In-Reply-To: <4E38315C.1000102@jollybox.de> References: <4E38315C.1000102@jollybox.de> Message-ID: On Tue, Aug 2, 2011 at 6:18 PM, Thomas Jollans wrote: > I suppose it would be possible to introduce a kind of "constant > globals" namespace that a JIT compiler could then use to optimise, but > how much would this help? Surely it must help a lot; looking up names is string operations. If "len" could be replaced with "@10794928" where 10794928 is the actual address of the len object, then it'd be doing no work that isn't normally done, and would go straight to the object and call it. But I don't really know how to go about profiling this to be sure. Any ideas? Chris Angelico From thinke365 at gmail.com Tue Aug 2 14:02:09 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 02:02:09 +0800 Subject: how to sort a hash list without generating a new object? Message-ID: the source code is as follows x={} x['a'] = 11 x['c'] = 19 x['b'] = 13 print x tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by default, if i want to have a descending order, what should i do? # after sorted is called, a list will be generated, and the hash list x is not changed at all, how to convert x to a sorted hash list without generating a new object? print tmp print x From clp2 at rebertia.com Tue Aug 2 14:03:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 11:03:24 -0700 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:55 AM, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. > > First off: Is there any way to request/cause some names to be bound > early? Nope. Even if you "freeze" a variable's value via a closure, I don't believe it gets particularly optimized. > As an example of this difference, Pike uses early binding for some > things; when I did the perfect numbers testing in the other thread > (discussion thread, not thread of execution!), Pike performed > significantly better; I believe this is in part due to the formal > declarations of variables, and the consequential simplification of > local code, although since there are no globals being looked up here, > there's little to be gained from those. "in part". There are very likely additional factors at work here. Also, have you looked at Cython? I would guess that it can bypass a lot of the late binding. > Is this the realm of JIT compilation, or can it be done in regular CPython? Smart enough JITers can infer that late binding is not being exploited for certain variables and thus optimize them accordingly. Look how fast some of the JavaScript VMs are, despite JavaScript also being highly dynamic. The CPython devs are reluctant to accept the increased complexity and size of a JIT engine (see Unladen Swallow). Anything else would probably involve a similarly unpalatable level of complexity or require changing Python-the-language. I'm pretty sure optional early binding has been proposed in the past; try trawling the list archives. Cheers, Chris From t at jollybox.de Tue Aug 2 14:10:15 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 20:10:15 +0200 Subject: Early binding as an option In-Reply-To: References: <4E38315C.1000102@jollybox.de> Message-ID: <4E383D87.3060705@jollybox.de> On 02/08/11 19:42, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 6:18 PM, Thomas Jollans wrote: >> I suppose it would be possible to introduce a kind of "constant >> globals" namespace that a JIT compiler could then use to optimise, but >> how much would this help? > > Surely it must help a lot; looking up names is string operations. If > "len" could be replaced with "@10794928" where 10794928 is the actual > address of the len object, then it'd be doing no work that isn't > normally done, and would go straight to the object and call it. > > But I don't really know how to go about profiling this to be sure. Any ideas? Well, you could run a direct comparison of one function where len is global, and an identitical function where len is local (which does not do a dict lookup, am I right?) Of course the global dict lookup takes time, but I doubt that many modules look up the same name often enough for it to actually be significant. I don't really know enough about either profiling or the CPython interpreter, but I assume there's some function that's called to look up globals; you could profile the Python interpreter (don't ask me with which tool) and see how much time that function uses. Thomas From t at jollybox.de Tue Aug 2 14:12:49 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 20:12:49 +0200 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: <4E383E21.8020201@jollybox.de> On 02/08/11 20:02, smith jack wrote: > the source code is as follows > > x={} > x['a'] = 11 > x['c'] = 19 > x['b'] = 13 > print x > > tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by > default, if i want to have a descending order, what should i do? > # after sorted is called, a list will be generated, and the hash list > x is not changed at all, how to convert x to a sorted hash list > without generating a new object? > print tmp > print x Python dictionaries are never ordered. Perhaps the collections.OrderedDict class can do what you're looking for. http://docs.python.org/py3k/library/collections.html#collections.OrderedDict From dwblas at gmail.com Tue Aug 2 14:53:01 2011 From: dwblas at gmail.com (David) Date: Tue, 2 Aug 2011 11:53:01 -0700 (PDT) Subject: Spam References: Message-ID: <0df2e806-59f9-4d16-ad74-6a09bf03916d@g3g2000prf.googlegroups.com> If you click the "more options" link, there is an option in the sub- menu to report a post as spam. You can also forward it along with the offending e-mail address to spam at uce.gov From info at egenix.com Tue Aug 2 15:02:15 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 02 Aug 2011 21:02:15 +0200 Subject: ANN: eGenix mx Base Distribution 3.2.1 (mxDateTime, mxTextTools, etc.) Message-ID: <4E3849B7.8050907@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.2.1 for Python 2.4 - 2.7 Open Source Python extensions providing important and useful services for Python programmers. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.1-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Easy to use Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.1 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. The new patch-level version includes a few important fixes: * Fixed a segfault in mxDateTime. * Fixed a possible buffer overflow in the mxDebugPrintf() function. * Fixed a problem in mxSetup mx_autoconf: Python.h was not found by some tests. If you are upgrading from eGenix mx Base 3.1.x, please also see the eGenix mx Base Distribution 3.2.0 release notes for details on what has changed and which new features are available: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on all other Python platforms, such as Solaris, AIX, HP-UX, etc. To simplify installation in Zope/Plone and other egg-based systems, we have also precompiled egg distributions for all platforms. These are available on our own PyPI-style index server for easy and automatic download. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler or the Python development packages to be installed. For a 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, Aug 02 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: 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 alain at dpt-info.u-strasbg.fr Tue Aug 2 15:02:31 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 02 Aug 2011 21:02:31 +0200 Subject: Early binding as an option References: Message-ID: <87oc07wsag.fsf@dpt-info.u-strasbg.fr> Chris Angelico writes: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. I agree with you on your last remark, but unfortunately it's part of the language. Therefore, there *are* programs that rely on the ability to rebind 'let' and others. Changing this would require changing the language, basically turning some builtins into keywords. (BTW, the dynamic binding also has implications for security.) [...] > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. Yes, and it can't do common subexpression elimination, code hoisting, etc. Basically, nothing can be optimized, and the interpreter has to execute bytecode that exactly represents source code. > I would want the end programmer to have the ultimate power here (not > the module designer). Something along the lines of: This global name > will never change, so don't bother looking it up every time. Maybe some module could provide specialized, "use-at-your-own-risk" versions of some functions/operators. An example is '+' which can mean so many things that any use of it probably spends more time finding the right version than actually doing the work. The problem with such pre-bound identifiers is that anybody with performance problems would start peppering his/her code with things like plus_float_float(x,y), leading to unreadable code, to all kinds of strange errors, etc. Nobody really wants this probably. [...] > Is this the realm of JIT compilation, or can it be done in regular > CPython? No, it's a matter of language definition. A JIT can't do much here (actually jitting is almost orthogonal to that question), at least it couldn't do much better than CPython. It just has to go through all the lookups. IIRC, unladden-swallow has tried the JIT route, using LLVM as the backend. It seems they gave up. -- Alain. From tlikonen at iki.fi Tue Aug 2 15:12:26 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 02 Aug 2011 22:12:26 +0300 Subject: Early binding as an option References: Message-ID: <871ux3ljad.fsf@mithlond.arda> * 2011-08-02T11:03:24-07:00 * Chris Rebert wrote: > Smart enough JITers can infer that late binding is not being exploited > for certain variables and thus optimize them accordingly. Look how > fast some of the JavaScript VMs are, despite JavaScript also being > highly dynamic. Or Common Lisp. It has "packages" (namespaces for symbols). All the standard symbols are in the COMMON-LISP (CL) package which is locked and can't be modified. When the Lisp reader is parsing the source code character stream it knows which package symbols belong to. So, for example, at compile time there is the information that symbol + refers to the standard CL:+ add function. There's no need to be smart. The CL package is static and set to stone but programmer is free to control symbols in other packages. For example, in some other package programmer can import all symbols from the standard CL package except shadow the CL:+ symbol. Then she can write her own extended version of + function (which possibly falls back to CL:+ in some situations). The dynamic effect with symbols is achieved through namespace tricks and yet the compiler can always trust the symbols of the CL package. I'm too much a beginner to tell if similar symbol concept is applicable to Python. From thinke365 at gmail.com Tue Aug 2 15:28:14 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 03:28:14 +0800 Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? Message-ID: There are so many choice to do the same thing, so is there any special advantage Django brings to user? From redcat at catfolks.net Tue Aug 2 15:37:32 2011 From: redcat at catfolks.net (Redcat) Date: 2 Aug 2011 19:37:32 GMT Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? References: Message-ID: <99r1vrFrc1U1@mid.individual.net> On Wed, 03 Aug 2011 03:28:14 +0800, smith jack wrote: > There are so many choice to do the same thing, so is there any special > advantage Django brings to user? The ability to code in Python instead of Java is the biggest one to me. From tjreedy at udel.edu Tue Aug 2 16:23:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Aug 2011 16:23:21 -0400 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 8/2/2011 12:55 PM, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. By 'pre-bound' you presumably mean bound at definition time rather than call time. Default arg objects *are* pre-computed and pre-bound to internal slots at definition time. > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. Three approaches to machine efficiency. 1. Better algorithm: Python's people efficiency makes this easier than in most other languages. 2. Hand-optimize the code that actually chew up time (as revealed by profiler). This often means removing repeated expressions *and* global names from inner loops. _len = len for line in somefile: n = _len(line) *might* give a worthwhile speedup in a function if not too much else happends in the loop. But the CPython global name lookup code (in C) has been thoroughly examined and optimized as best as several developers could think of. 3. Convert critical code to native language (or C). The idea of 'early binding' comes up periodically but I do not remember many concrete proposals. -- Terry Jan Reedy From gelonida at gmail.com Tue Aug 2 17:39:39 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:39:39 +0200 Subject: m2crypto https, xmlrpc, keep_alive Message-ID: Hi, Just started playing with m2cryptos xmlrpc The code I'm is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mynethod2(2) What I wondered is following. Will each RPC call go through all the ssl negotiation with certificate verification, etc? If yes, is there something like the concept of a keep_alive connection, that would avoid this overhead? If yes. What would I have to change in my above code. Thanks in advance for some ideas From tim at johnsons-web.com Tue Aug 2 17:47:55 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 2 Aug 2011 13:47:55 -0800 Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? In-Reply-To: References: Message-ID: <20110802214755.GE14664@johnsons-web.com> * smith jack [110802 11:37]: > There are so many choice to do the same thing, so is there any special > advantage Django brings to user? Django is a python framework, J2EE is a java platform (my apologies if I use 'framework' incorrectly). Our customers want PHP,perl or python, not java. The definition for LAMP given at http://en.wikipedia.org/wiki/LAMP_(software_bundle) - for what it is worth includes python and defines LAMP as sort of generic (as I read it). Thus django *could* be considered a LAMP bundle, perhaps. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From gelonida at gmail.com Tue Aug 2 17:53:03 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:53:03 +0200 Subject: m2crypto https, xmlrpc, and cookies Message-ID: Hi, Just started playing with m2cryptos xmlrpc The code I'm using is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mynethod2(2) What I wondered is following: When using my web browser certain cookies are sent with the request. Is there any way to change my above code such, that cookies would be collected and sent? Thanks in advance for any pointers. From gelonida at gmail.com Tue Aug 2 17:59:39 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:59:39 +0200 Subject: m2crypto https, xmlrpc and ignore server name mismatch Message-ID: Hi, Just started playing with m2crypto's xmlrpc The code I'm using is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mymethod2(2) What I wondered is following: For testing I would like to ignore the fact, that the hostname in the request is different from the hostname in the server certificate. On the other hand I would like to verify that the server name from the server's certidicate matches a certain criteria. What would be the code to do this. import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context def check_func(server_certificate): hostname = get_hostname_from_cert() return hostname.endswith('.mydomain.com') ctx = Context() # modify context # add code to ignore server name mismatch # add code to call check_func. accept request only if it returns True svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mymethod2(2) Thanks in advance for any pointers. From rosuav at gmail.com Tue Aug 2 18:08:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 23:08:48 +0100 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy wrote: > On 8/2/2011 12:55 PM, Chris Angelico wrote: >> >> As I understand it, Python exclusively late-binds names; when you >> define a function, nothing is ever pre-bound. > > By 'pre-bound' you presumably mean bound at definition time rather than call > time. Default arg objects *are* pre-computed and pre-bound to internal slots > at definition time. Of course; that's a different issue altogether. No, I'm talking about the way a tight loop will involve repeated lookups for the same name. Unfortunately, there is no way - by definition - to guarantee that a binding won't change. Even in the example of getting the lengths of lines in a file, it's entirely possible for __len__ to rebind the global name "len" - so you can't rely on the repeated callings of len() to be calling the same function. But who WOULD do that? It's somewhat ridiculous to consider, and there's a huge amount of code out there that does these repeated calls and does not do stupid rebindings in the middle. So Python permits crazy behaviour at the cost of the performance of normal behaviour. With the local-variable-snapshot technique ("len = len"), can anything be optimized, since the parser can guarantee that nothing ever reassigns to it? If not, perhaps this would be a place where something might be implemented: @const(len,max) # maybe this def maxline(f): @const len,max # or this n = 0 for line in somefile: n = max(n,len(line)) return n Some notation like this could tell the interpreter, "I don't expect 'len' or 'max' to be rebound during the execution of this function. You're free to produce wrong results if either is." So... Would this potentially produce wrong results? Would it be of any use, or would its benefit be only valued in times when the whole function needs to be redone in C? Chris Angelico From gelonida at gmail.com Tue Aug 2 18:21:03 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:21:03 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 08/03/2011 12:08 AM, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > > @const(len,max) # maybe this > def maxline(f): > @const len,max # or this > n = 0 > for line in somefile: > n = max(n,len(line)) > return n > > Some notation like this could tell the interpreter, "I don't expect > 'len' or 'max' to be rebound during the execution of this function. > You're free to produce wrong results if either is." > > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? > > Chris Angelico I think the idea of having pragmas / directives to tell the interpreter that certain symbols could be bound early is intersting and might help optimizing some inner loops without having to explicitely assign to local vars. On the other hand: It might be interesting, that the early binding would just take place when python is invoked with -O Thus you could still do a lot of debug / tracing magic during development and only production code would do the late binding. From rosuav at gmail.com Tue Aug 2 18:26:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 23:26:01 +0100 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: > On the other hand: It might be interesting, that the early binding would > just take place when python is invoked with -O > This could be an excellent safety catch, but on the other hand, it might destroy all value of the feature - once again, it would be optimizing in the sole case where the code is probably better rewritten in C. Or would this be a sort of "half-way house" - this is where we need more performance, let's spend two minutes tweaking it in Python rather than dropping to C - to get some of the performance gains? ChrisA From gelonida at gmail.com Tue Aug 2 18:54:11 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:54:11 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E388013.7070506@gmail.com> On 08/03/2011 12:26 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: >> On the other hand: It might be interesting, that the early binding would >> just take place when python is invoked with -O >> > > This could be an excellent safety catch, but on the other hand, it > might destroy all value of the feature - once again, it would be > optimizing in the sole case where the code is probably better > rewritten in C. > > Or would this be a sort of "half-way house" - this is where we need > more performance, let's spend two minutes tweaking it in Python rather > than dropping to C - to get some of the performance gains? Not really sure. I would guess, that really tight inner loops should be rewritten with Cython (never tried it though) or in C if performance is really that critical. On the other hand it could be nice to get a certain performance increase with some pragmas without rendering the code completely unreadable. I have loads of places in my code, where name lookups were required only at compile time or at the first time when code is executed. For every consecutive call a cached object-reference could be used. From gelonida at gmail.com Tue Aug 2 18:54:24 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:54:24 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 08/03/2011 12:26 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: >> On the other hand: It might be interesting, that the early binding would >> just take place when python is invoked with -O >> > > This could be an excellent safety catch, but on the other hand, it > might destroy all value of the feature - once again, it would be > optimizing in the sole case where the code is probably better > rewritten in C. > > Or would this be a sort of "half-way house" - this is where we need > more performance, let's spend two minutes tweaking it in Python rather > than dropping to C - to get some of the performance gains? Not really sure. I would guess, that really tight inner loops should be rewritten with Cython (never tried it though) or in C if performance is really that critical. On the other hand it could be nice to get a certain performance increase with some pragmas without rendering the code completely unreadable. I have loads of places in my code, where name lookups were required only at compile time or at the first time when code is executed. For every consecutive call a cached object-reference could be used. From xahlee at gmail.com Tue Aug 2 19:15:13 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Aug 2011 16:15:13 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: <9e715ab4-d5c7-4269-95b3-5d8e705998de@c8g2000prn.googlegroups.com> On Jul 31, 11:38 am, gavino wrote: > On Jul 13, 1:04 pm, ccc31807 wrote: > > > > > > > > > > > On Jul 12, 7:54 am, Xah Lee wrote: > > > > maybe this will be of interest. > > > > ?What Programing Language Are the Largest Website Written In??http://xahlee.org/comp/website_lang_popularity.html > > > About five years ago, I did some pretty extensive research, and > > concluded that the biggest sites were written serverside with JSP. > > Obviously, this wouldn't include The Biggest site, but if you were a > > big, multinational corporation, or listed on the NYSE, you used JSP > > for your web programming. > > > I doubt very seriously PHP is used for the biggest sites -- I'd still > > guess JSP, or maybe a MS technology (not VB), but it's only a guess. > > > CC. > > facebook is php > > myspace is microsoft > > aol was tcl and aolserver c embedding tcl interp > > priceline is lisp > > reddit is python was lisp orig > > amazon was perl > > livejournal was perl thanks Kevin. Rarely seen you useful. :) Xah From 1248283536 at qq.com Tue Aug 2 20:21:53 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 3 Aug 2011 08:21:53 +0800 Subject: pygtk Message-ID: please see my attachment ,which widget the region1,region2 is? how to make it?? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: re2 Type: application/octet-stream Size: 26111 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Tue Aug 2 20:52:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 10:52:38 +1000 Subject: Spam References: <0df2e806-59f9-4d16-ad74-6a09bf03916d@g3g2000prf.googlegroups.com> Message-ID: <4e389bd7$0$29996$c3e8da3$5496439d@news.astraweb.com> David wrote: > If you click the "more options" link, there is an option in the sub- > menu to report a post as spam. You can also forward it along with the > offending e-mail address to spam at uce.gov What "more options" link? Are you referring to a specific program? If so, which? Remember, people are reading this via email: Thunderbird, Outlook, Outlook Express, Gmail, Yahoo Mail, Kmail, mutt, and hundreds of other programs; also via Usenet, again with multiple programs; on the web, via Google Groups or any of a dozen or so different websites. They don't all have a "more options" link. -- Steven From clp2 at rebertia.com Tue Aug 2 20:53:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 17:53:26 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:02 AM, smith jack wrote: > the source code is as follows > > x={} > x['a'] = 11 > x['c'] = 19 > x['b'] = 13 > print x > > tmp = sorted(x.items(), key = lambda x:x[0]) ? ?# ?increase order by > default, if i want to have a descending order, what should i do? Pass reverse=True. Read the find documentation for sorted(). tmp = sorted(x.items(), key=lambda x:x[0], reverse=True) > # after sorted is called, a list will be generated, and the hash list It's not a hash list (http://en.wikipedia.org/wiki/Hash_list ), it's a hash table. In Python, we call them dictionaries or dicts. > x is not changed at all, how to convert x to a sorted hash list > without generating a new object? There is no such thing as a sorted hash table (unless you're using an exotic variant). Why do you care whether it generates a new object or not? If you /really/ need a sorted mapping datatype, google for "sorteddict" (which is quite distinct from OrderedDict). Or look for a binary search tree or skip list implementation of some sort; but these aren't commonly used in Python, so it may be hard to find a good one. Cheers, Chris -- http://rebertia.com From gc1223 at gmail.com Tue Aug 2 21:45:15 2011 From: gc1223 at gmail.com (gc) Date: Tue, 2 Aug 2011 18:45:15 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? Message-ID: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Hi everyone! Longtime lurker, hardly an expert, but I've been using Python for various projects since 2007 and love it. I'm looking for either (A) suggestions on how to do a very common operation elegantly and Pythonically, or (B) input on whether my proposal is PEP-able, assuming there's no answer to A. (The proposal is sort of like the inverse of PEP 3132; I don't think it has been proposed before, sorry if I missed it.) Anyway, I frequently need to initialize several variables to the same value, as I'm sure many do. Sometimes the value is a constant, often zero; sometimes it's more particular, such as defaultdict(list). I use dict() below. Target lists using comma separation are great, but they don't work very well for this task. What I want is something like a,b,c,d,e = *dict() where * in this context means something like "assign separately to all." I'm not sure that * would the best sugar for this, but the normal meaning of * doesn't seem as if it would ever be valid in this case, and it somehow feels right (to me, anyway). Statements fitting the form above would get expanded during parsing to a sequence of separate assignments (a = dict(); b = dict(); c = dict() and so forth.) That's all there is to it. Compared to the patterns below, it's svelte, less copy-paste-y (so it removes an opportunity for inconsistency, where I remember to change a-d to defaultdict(list) but forget with e), and it doesn't require me to keep count of the number of variables I'm initializing. This would update section 6.2 of the language reference and require a small grammar expansion. But: Is there already a good way to do this that I just don't know? Below, I compare four obvious patterns, three of which are correct but annoying and one of which is incorrect in a way which used to surprise me when I was starting out. # Option 1 (separate lines) # Verbose and annoying, particularly when the varnames are long and of irregular length a = dict() b = dict() c = dict() d = dict() e = dict() # Option 2 (one line) # More concise but still pretty annoying, and hard to read (alternates variables and assignments) a = dict(); b = dict(); c = dict(); d = dict(); e = dict() # Option 3 (multiple target list: this seems the most Pythonic, and is normally what I use) # Concise, separates variables from assignments, but somewhat annoying; have to change individually and track numbers on both sides. a,b,c,d,e = dict(),dict(),dict(),dict(),dict() # Option 4 (iterable multiplication) # Looks better, and if the dict() should be something else, you only have to change it once, but the extra brackets are ugly and you still have to keep count of the targets... a,b,c,d,e = [dict()] * 5 # and it will bite you... >>> a[1] = 1 >>> b {1: 1} >>> id(a) == id(b) True # Gotcha! # Other forms of 4 also have this behavior: a,b,c,d,e = ({},) * 5 >>> a[1] = 1 >>> b {1: 1} Alternatively, is there a version of iterable multiplication that creates new objects rather than just copying the reference? That would solve part of the problem, though it would still look clunky and you'd still have to keep count. Any thoughts? Thanks! From drsalists at gmail.com Tue Aug 2 21:59:59 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 18:59:59 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E37CDCF.7060501@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it is possible to hard link directories ? > That is pretty true. I've heard of hardlinked directories on Solaris, but that's kind of an exception to the general rule. > > So presumably I would need to do a mkdir for each sub-directory > > encountered? > > Or is there an easier way to hardlink everything in a directory > > structure?. > > > > The requirement is for hard links, not symbolic links > > > > Yes, you have to mkdir everything. However, there is an easier way: > > subprocess.Popen(['cp','-Rl','target','link']) > > This is assuming that you're only supporting Unices with a working cp > program, but as you're using hard links, that's quite a safe bet, I > should think. > A little more portable way: $ cd from; find . -print | cpio -pdlv ../to cpio: ./b linked to ../to/./b ../to/./b cpio: ./a linked to ../to/./a ../to/./a cpio: ./c linked to ../to/./c ../to/./c ../to/./d cpio: ./d/1 linked to ../to/./d/1 ../to/./d/1 cpio: ./d/2 linked to ../to/./d/2 ../to/./d/2 cpio: ./d/3 linked to ../to/./d/3 ../to/./d/3 0 blocks However, you could do it without a shell command (IOW in pure python) using os.path.walk(). -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 2 22:09:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 03:09:34 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 2:45 AM, gc wrote: > Anyway, I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. If it's an immutable value (such as a constant integer), you can use syntax similar to C's chained assignment: a=b=c=0 If you do this with dict(), though, it'll assign the same dictionary to each of them - not much use. > # Option 3 (multiple target list: this seems the most Pythonic, and is > normally what I use) > # Concise, separates variables from assignments, but somewhat > annoying; have to change individually and track numbers on both sides. > > a,b,c,d,e = dict(),dict(),dict(),dict(),dict() I think this is probably the best option, although I would be inclined to use dictionary-literal syntax: a,b,c,d,e = {},{},{},{},{} It might be possible to do something weird with map(), but I think it'll end up cleaner to do it this way. Chris Angelico From steve+comp.lang.python at pearwood.info Tue Aug 2 22:15:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 12:15:44 +1000 Subject: with statement and context managers Message-ID: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> I'm not greatly experienced with context managers and the with statement, so I would like to check my logic. Somebody (doesn't matter who, or where) stated that they frequently use this idiom: spam = MyContextManager(*args) for ham in my_iter: with spam: # do stuff but to me that looks badly wrong. Surely the spam context manager object will exit after the first iteration, and always raise an exception on the second? But I don't quite understand context managers enough to be sure. I've tested it with two examples: # Simple example using built-in file context manager. >>> spam = open('aaa') >>> for ham in range(5): ... with spam: ... print ham ... 0 Traceback (most recent call last): File "", line 2, in ValueError: I/O operation on closed file # Slightly more complex example. >>> from contextlib import closing >>> import urllib >>> spam = closing(urllib.urlopen('http://www.python.org')) >>> for ham in range(5): ... with spam as page: ... print ham, sum(len(line) for line in page) ... 0 18486 1 Traceback (most recent call last): File "", line 3, in File "", line 3, in File "/usr/local/lib/python2.7/socket.py", line 528, in next line = self.readline() File "/usr/local/lib/python2.7/socket.py", line 424, in readline recv = self._sock.recv AttributeError: 'NoneType' object has no attribute 'recv' Am I right to expect that the above idiom cannot work? If not, what sort of context managers do work as shown? -- Steven From drsalists at gmail.com Tue Aug 2 22:20:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 19:20:19 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > On Tue, Aug 2, 2011 at 11:02 AM, smith jack wrote: > > the source code is as follows > > > > x={} > > x['a'] = 11 > > x['c'] = 19 > > x['b'] = 13 > > print x > > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which is quite distinct from OrderedDict). > Or look for a binary search tree or skip list implementation of some > sort; but these aren't commonly used in Python, so it may be hard to > find a good one. > I've found a need for such a thing a couple of times. Anyway, here are some other possibilities: http://stromberg.dnsalias.org/~dstromberg/treap/ http://pypi.python.org/pypi/bintrees/0.3.0 The treap code is considered by its author (me) production-quality, has an extensive test suite, and is known to work on CPython 2.x, CPython 3.x, PyPy and Jython. The CPython's can optionally be sped up with a Cython variant of the same code (autogenerated from a single source file using m4), and while I test on all 4 regularly, lately I mostly run it in production using the pure python version on PyPy. EG: $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import treap >>> t = treap.treap() >>> import random >>> for i in xrange(10): ... t[random.random()] = random.random() ... >>> print list(t.items()) [(0.049542221325585611, 0.60627903220498502), (0.26787423324282511, 0.95374362416785075), (0.45599886628328978, 0.57612454878587427), (0.46375501394309371, 0.28130836755784228), (0.54144253493651362, 0.47941229743653202), (0.54584770558330997, 0.49062231291462766), (0.5592476615748635, 0.39138521009523863), (0.73976131715214732, 0.99783565376628391), (0.7638117918732078, 0.55600393733208187), (0.88094790991949967, 0.90033960217787801)] >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jackdied at gmail.com Tue Aug 2 22:28:15 2011 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 2 Aug 2011 22:28:15 -0400 Subject: with statement and context managers In-Reply-To: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 10:15 PM, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > ? ?with spam: > ? ? ? ? # do stuff > [snip] > # Simple example using built-in file context manager. > >>>> spam = open('aaa') >>>> for ham in range(5): > ... ? ? with spam: > ... ? ? ? ? ? ? print ham > ... > 0 > Traceback (most recent call last): > ?File "", line 2, in > ValueError: I/O operation on closed file file_context = lambda: open('aaa') for i in range(3): with file_context(): print "hello" .. but if the context is short it is clearer and time saving to _not_ alias it. If the context is sufficiently complicated then it is worth it to make the complex code into a first class context manager - contextlib.contextmanager makes this very easy and extremely readable. -Jack From rmorgan466 at gmail.com Tue Aug 2 23:03:29 2011 From: rmorgan466 at gmail.com (Rita) Date: Tue, 2 Aug 2011 23:03:29 -0400 Subject: code generation Message-ID: Hello, This isn't much of a python question but a general algorithm question. I plan to input the following string and I would like to generate something like this. input: a->(b,c)->d output: parent a, child b c parent b c child d Are there any libraries or tools which will help me evaluate items like this better? I am mostly looking for syntax and sanity checking. Any thoughts? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue Aug 2 23:48:24 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 20:48:24 -0700 Subject: code generation In-Reply-To: References: Message-ID: Perhaps: http://code.google.com/p/python-graph/ On Tue, Aug 2, 2011 at 8:03 PM, Rita wrote: > Hello, > > This isn't much of a python question but a general algorithm question. > > I plan to input the following string and I would like to generate something > like this. > > input: a->(b,c)->d > output: > parent a, child b c > parent b c child d > > Are there any libraries or tools which will help me evaluate items like > this better? I am mostly looking for syntax and sanity checking. > > Any thoughts? > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Wed Aug 3 00:22:42 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Aug 2011 05:22:42 +0100 Subject: with statement and context managers References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Aug 2011 12:15:44 +1000, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > with spam: > # do stuff > > > but to me that looks badly wrong. Surely the spam context manager object > will exit after the first iteration, and always raise an exception on the > second? But I don't quite understand context managers enough to be sure. It depends upon the implementation of MyContextManager. If it's implemented using the contextlib.contextmanager decorator, then you're correct: you can only use it once. OTOH, if you implement your own class with __enter__ and __exit__ methods, you can use the same context manager object multiple times. From kushal.kumaran+python at gmail.com Wed Aug 3 02:32:07 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 3 Aug 2011 12:02:07 +0530 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: > > On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: >> >> On 02/08/11 11:32, loial wrote: >> > I am trying to hardlink all files in a directory structure using >> > os.link. >> > >> > However I do not think it is possible to hard link directories ? > > That is pretty true.? I've heard of hardlinked directories on Solaris, but > that's kind of an exception to the general rule. > In APUE, Richard Stevens says only root could do this, if it is supported by the system at all. In a footnote, he additionally mentions he screwed up his filesystem by creating a loop of hardlinked directories while writing that section of the book. I suppose it is a good thing systems don't allow that now. -- regards, kushal From wuwei23 at gmail.com Wed Aug 3 02:52:33 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Aug 2011 23:52:33 -0700 (PDT) Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> Message-ID: <7034abec-975d-4ed6-9cb7-7cc54ff4ef7b@s21g2000pre.googlegroups.com> Andrew Berg wrote: > He hasn't replied to his last two troll threads, though. It does seem > odd to write a wall of text and then not respond to replies. To be fair, > though, most replies either mock him or point out that he's a troll. :D His recent rants do seem a lot more Xah-Lee-like; a huge nonsensical diatribe that badly applies logic to try and mask its emotive agenda. A lot of the same "great mind struggling against the tyranny of idiots" subtext too. Not so much swearing though. From nobody at nowhere.com Wed Aug 3 03:04:59 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Aug 2011 08:04:59 +0100 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > However I do not think it is possible to hard link directories ? Modern Unices disallow hard links to directories, as it makes the directory "tree" not a tree, so anything which performs a recursive walk must explicitly check for cycles to avoid infnite recursion. Older systems which allowed hard links to directories required root privilege to do so. From ulrich.eckhardt at dominolaser.com Wed Aug 3 03:14:59 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 03 Aug 2011 09:14:59 +0200 Subject: python import error, what's wrong? References: Message-ID: smith jack wrote: > I am using pydev plugin in eclipse, all things works just as well > but now i have confronted with a confusing problem, that is i can > import a module write by myself successfully, but when i try to run > this program, > error just shows up, what's wrong? > > the directory structure is as follows: > > src > org.test > A.py > org.lab > B.py Python uses a dot as separator between different parts of nested structures, like e.g. the directories during import. I guess your directory naming conflicts with that. Try this structure instead: src org test A.py lab B.py or maybe src org_test A.py org_lab B.py > contents of A seems like: > class A > ... > > contents of B seems like: // I try to run B.py, > python import error just appears, why? "just appears" is not a sufficient discription of an error. I'd suggest reading Eric S. Raymond's excellent essay on "Asking Smart Questions", it will avoid such mistakes. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ben+python at benfinney.id.au Wed Aug 3 03:45:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Aug 2011 17:45:40 +1000 Subject: python import error, what's wrong? References: Message-ID: <871ux3kkez.fsf@benfinney.id.au> Ulrich Eckhardt writes: > > the directory structure is as follows: > > > > src > > org.test > > A.py > > org.lab > > B.py > > Python uses a dot as separator between different parts of nested > structures, like e.g. the directories during import. More generally, the name of a module must be a valid Python identifier. Hence, the module-name part of a directory or of a filename must also be a valid Python identifier. The ?.? (U+002E FULL STOP) character is not valid in an identifier. -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?? ?_Pinky and The Brain_ | Ben Finney From steve+comp.lang.python at pearwood.info Wed Aug 3 04:25:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 18:25:51 +1000 Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> gc wrote: > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() a, b, c, d, e = [dict() for i in range(5)] Unfortunately there is no way of doing so without counting the assignment targets. While slightly ugly, it doesn't seem ugly enough to justify the extra complexity of special syntax for such a special case. -- Steven From greg.ewing at canterbury.ac.nz Wed Aug 3 04:29:19 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Aug 2011 20:29:19 +1200 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <99sf72Fo87U1@mid.individual.net> gc wrote: > Alternatively, is there a version of iterable multiplication that > creates new objects rather than just copying the reference? You can use a list comprehension: a, b, c, d, e = [dict() for i in xrange(5)] or a generator expression: a, b, c, d, e = (dict() for i in xrange(5)) -- Greg From katriel at katriel.co.uk Wed Aug 3 04:36:19 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Wed, 3 Aug 2011 09:36:19 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > gc wrote: > > > Target lists using comma separation are great, but they don't work > > very well for this task. What I want is something like > > > > a,b,c,d,e = *dict() > > a, b, c, d, e = [dict() for i in range(5)] > I think this is good code -- if you want five different dicts, then you should call dict five times. Otherwise Python will magically call your expression more than once, which isn't very nice. And what if your datatype constructor has side-effects? Katriel -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrinalini at edss.co.in Wed Aug 3 04:58:48 2011 From: mrinalini at edss.co.in (mrinalini at edss.co.in) Date: Wed, 03 Aug 2011 14:28:48 +0530 Subject: Dynamically linking python into my vc project - help required Message-ID: <6cafe6745022b37909647db99073fc87@edss.co.in> Hi, I am trying to embed python into my MFC application. I have done this before by statically linking to the python lib. But I want to change this now. The idea is to take the information from the registry for the installed version of python on the target machine. Then load python using loadlibrary call and use the functions from python using pointers to functions returned by GetProcAddress . For example - hModPython = AfxLoadLibrary("Python23.dll"); pFnPyRun_SimpleString *pFunction = NULL; pFnPy_Initialize *pPy_Initialize = NULL; pFunction = (pFnPyRun_SimpleString *)::GetProcAddress(hModPython, "PyRun_SimpleString"); pPy_Initialize = (pFnPy_Initialize *)::GetProcAddress(hModPython, "Py_Initialize"); try { pPy_Initialize(); if ( pFunction ) { (*pFunction)("import sys"); // call the code } else { AfxMessageBox("unable to access function from python23.dll.", MB_ICONSTOP|MB_OK); } } catch(...) { } And then I want to execute a python script through my MFC application - HANDLE hFile = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwSize = GetFileSize(hFile, NULL); DWORD dwRead; char *s = new char[dwSize +1]; ReadFile(hFile, s, dwSize, &dwRead, NULL); s[dwSize] = '\0'; CString wholefile(s); wholefile.Remove('\r'); wholefile+="\n"; CloseHandle(hFile); pFnPy_CompileString *pFPy_CompileString = (pFnPy_CompileString *)::GetProcAddress(hModPython, "Py_CompileString"); CString fl(file); PyObject* pCodeObject = pFPy_CompileString(wholefile.GetBuffer(0), fl.GetBuffer(0), Py_file_input); if (pCodeObject != NULL) { pFnPyEval_EvalCode *pFPyEval_EvalCode = (pFnPyEval_EvalCode *)::GetProcAddress(hModPython, "PyEval_EvalCode"); PyObject* pObject = pFPyEval_EvalCode((PyCodeObject*)pCodeObject, m_Dictionary, m_Dictionary); } I am facing two problems here , though I want to link to python dynamically I am required to include python.h for my code to compile the following declaration. PyObject* pCodeObject I tried copying some of the python definitions including PyObject into a header in my mfc app. Then it complies fine. but Py_CompileString call fails. so finally I am unable to run script from my MFC application by linking to python dynamically. How can this be done ? Please help. Is there a different approach to linking to python dynamically. Please could you write to me ? Thanks in advance, Mrinalini From rosuav at gmail.com Wed Aug 3 04:58:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 09:58:53 +0100 Subject: Early binding as an option In-Reply-To: References: <4E38315C.1000102@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 5:46 AM, Dennis Lee Bieber wrote: > ? ? ? ?Horrors... That looks like some MUF code I've seen (I never had a > MUF flag on my old characters, so had no privilege to write in MUF -- > MPI was available to all, and even it had some links to MUF operations > using similar magic numbers). > Hehe. I didn't mean that it should be thus in the source code, but that some simple notation would tell the interpreter that it can make that translation in memory - at the tokenization stage, or perhaps when the function is invoked. The idea is that the interpreter can skip one step - the step of taking the name "len", looking it up, and finding the object that it represents. It can do that part of the work once, and patch in the function's address somewhere as a special token - right into the tokenized source code. Parenthesis: Reading the Wikipedia article on MUF shows that it has a number of similarities to what I do today in coding my MUD - I have an extremely rudimentary editor interface (smart editing is done on the client), submit my code to the server, compile it, and invoke it - and it's governed by permissions bits. However, I use a rather better language than MUF :) ChrisA From stefan_ml at behnel.de Wed Aug 3 05:33:21 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 11:33:21 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: Chris Angelico, 03.08.2011 00:08: > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? Note that, in most cases, you do not need to "redo the whole function in C". You can just use Cython to compile it, thus leaving it in Python syntax and keeping up Python semantics, unless you decide to explicitly divert from them in favour of optimisations. Stefan From gelonida at gmail.com Wed Aug 3 05:40:48 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 11:40:48 +0200 Subject: Text to image with same results on any platform Message-ID: Hi, >From within a django application I'd like create a small image file (e.g. .png) which just contains some text. I wondered what library would be appropriate and would yield the same result independent of the OS (assuming the versions of the python libraries are the same) Images should be pixel identical independent on the platform on which the image is created. I made some attempts with PIL (Image / ImageFont / ImageDraw), but have difficulties getting the same font under Linux and windows. # ------------------------code starts here import Image import ImageFont import ImageDraw # Here I don't know how to get the same font file # for all platforms # Perhaps there is a tiny trick that I overlooked. font_file = get_font_file_name() # Is truetype a good choice for portable fonts? font = ImageFont.truetype(font_file, 20) img = Image.new("RGB", (800, 600), "#FFFFFF") draw = ImageDraw.Draw(image) draw.text( (100, 100), font=font, fill="#00FF00") # ---------------------------- end of code I could also install any other library (matplotlib??) if it were capable of creating consistent images independent on the platform. Thanks in advance for any suggestions. From t at jollybox.de Wed Aug 3 05:47:31 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 11:47:31 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: <4E391933.6070603@jollybox.de> On 03/08/11 03:59, Dan Stromberg wrote: > > On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans > wrote: > > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it is possible to hard link directories ? > > > That is pretty true. I've heard of hardlinked directories on Solaris, > but that's kind of an exception to the general rule. > > > > So presumably I would need to do a mkdir for each sub-directory > > encountered? > > Or is there an easier way to hardlink everything in a directory > > structure?. > > > > The requirement is for hard links, not symbolic links > > > > Yes, you have to mkdir everything. However, there is an easier way: > > subprocess.Popen(['cp','-Rl','target','link']) > > This is assuming that you're only supporting Unices with a working cp > program, but as you're using hard links, that's quite a safe bet, I > should think. > > > A little more portable way: > > $ cd from; find . -print | cpio -pdlv ../to > cpio: ./b linked to ../to/./b > ../to/./b > cpio: ./a linked to ../to/./a > ../to/./a > cpio: ./c linked to ../to/./c > ../to/./c > ../to/./d > cpio: ./d/1 linked to ../to/./d/1 > ../to/./d/1 > cpio: ./d/2 linked to ../to/./d/2 > ../to/./d/2 > cpio: ./d/3 linked to ../to/./d/3 > ../to/./d/3 > 0 blocks > > However, you could do it without a shell command (IOW in pure python) > using os.path.walk(). Is it more portable? I don't actually have cpio installed on this system. Which implementations of cp don't implement -R and -l? Of course, the best way is probably implementing this in Python, either with os.path.walk, or with a monkey-patched shutil.copytree, as Peter suggested. Thomas From gelonida at gmail.com Wed Aug 3 05:52:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 11:52:46 +0200 Subject: PyWart: os.path needs immediate attention! In-Reply-To: References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <1311971809-sup-1144@2d2a55d49a8018d83ffdd9e06d> Message-ID: On 07/29/2011 11:43 PM, Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:44 AM, Corey Richardson wrote: >> Excerpts from rantingrick's message of Fri Jul 29 13:22:04 -0400 2011: >>> * New path module will ONLY support one path sep! >> >> People who use windows are used to \ being their pathsep. If you show >> them a path that looks like C:/whatever/the/path in an app, they are >> going to think you are nuts. It isn't up to us to decide what anyone >> uses as a path separator. They use \ natively, so should we. If at >> any point Windows as an OS starts using /'s, and not support, actually >> uses (in Windows Explorer as default (or whatever the filebrowser's >> name is)), it would be great to switch over. > > Just tested this: You can type c:/foldername into the box at the top > of a folder in Explorer, and it works. It will translate it to > c:\foldername though. > > We are not here to talk solely to OSes. We are here primarily to talk > to users. If you want to display a path to the user, it's best to do > so in the way they're accustomed to - so on Windows, display > backslashes. > >>> - normcase --> path = path.lower() >> >> Not quite, here are a few implementations of normcase (pulled from 2.7) >> >> # NT >> return s.replace("/", "\\").lower() >> >> # Mac (Correct in this case) >> return path.lower() >> >> # POSIX >> return s >> >> But I can't think of where I would ever use that. Isn't case important on >> Windows? > well normcase might help to find out, whether two filenames are the same. under unix 'myfile' and 'myFile' would be different under windows they would refer to the same file. normcase (perhaps to be combined with normpath) can tel you this. From t at jollybox.de Wed Aug 3 06:00:05 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 12:00:05 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E391C25.9070702@jollybox.de> On 03/08/11 00:08, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > [...] Yes, it can. The parser can know when it is reassigned to just by looking at the one function, and even if it didn't, or if it were reassigned, it wouldn't make much of a difference because the interpreter would still only have to fetch one of a set of locals known at compile time, which can be (is? I'm not sure) as simple as an array lookup: two pointers being dereferences instead of one. Chris Rebert raises a very important point though: Python dynamic namespaces make optimising variable lookup comparatively difficult, but not impossible: good JavaScript JITs are smart enough, so a good Python JIT could be as well. Thomas From steve+comp.lang.python at pearwood.info Wed Aug 3 06:16:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 20:16:46 +1000 Subject: Early binding as an option References: Message-ID: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy wrote: >> On 8/2/2011 12:55 PM, Chris Angelico wrote: >>> >>> As I understand it, Python exclusively late-binds names; when you >>> define a function, nothing is ever pre-bound. >> >> By 'pre-bound' you presumably mean bound at definition time rather than >> call time. Default arg objects *are* pre-computed and pre-bound to >> internal slots at definition time. > > Of course; that's a different issue altogether. No, I'm talking about > the way a tight loop will involve repeated lookups for the same name. It's not really a different issue. The "standard" approach for performing early binding in Python is by binding a global name to a local name at function definition time. In CPython at least, local lookups are faster than globals: locals are stored in a fixed array, and the function knows the numeric offset of each variable. Non-locals have to search multiple namespaces (globals + built-ins), using a hash table. That's fast, but locals are faster. (Aside: this is why locals() is not generally writable: the dict is a copy of that internal array. You can write to the dict, but the changes don't propagate back to the actual local table of the function.) So a good way to speed up name lookups is to turn a global into a local, and one common way to do that is to do it when the function is defined. For example, you will see this in the random module: def randrange(self, start, stop=None, step=1, int=int, default=None, maxwidth=1< Unfortunately, there is no way - by definition - to guarantee that a > binding won't change. Even in the example of getting the lengths of > lines in a file, it's entirely possible for __len__ to rebind the > global name "len" - so you can't rely on the repeated callings of > len() to be calling the same function. > > But who WOULD do that? It's somewhat ridiculous to consider, and > there's a huge amount of code out there that does these repeated calls > and does not do stupid rebindings in the middle. So Python permits > crazy behaviour at the cost of the performance of normal behaviour. This is a common criticism of Python, and the truth be told, it is right: Python makes crazy monkey-patching that we're told not to do easy, at the expense of allowing the compiler to optimise really common things. But, are you *sure* that name lookups are *really* the bottleneck? Name lookups are pretty fast. If you want them faster, turn them into a local variable. It's not clear to me that syntax, or a pragma directive, or some other form of magic, is better than an explicit assignment: def func(x): _len = len # bind at function call time for i in x: _len(i) # lookups of _len will be faster than len The argument that Python would be faster if it did early binding is not a given. For trivial code that doesn't do much, I dare say it might shave off a significant percentage, but trivial code is already pretty fast. Who cares if you speed up a trivial operation? In non-trivial code that does real work, it's not obvious that early binding will result in meaningful time savings. ("Yay, my code now runs in 17.1 milliseconds instead of 17.2!") The onus is on the person proposing this change to prove that the benefit is worth the extra complexity. Knowing what we know now, I'm not sure whether Guido would have kept the late binding semantics for Python, or privileged builtins in some fashion. I suspect that he wouldn't have changed a thing, but if he did, I suspect he'd be more concerned about accidental shadowing of builtins than about optimizations. E.g. people say list = [1,2,3], and then later try to call list(something). Or maybe that's just me :) Guido is generally very, very suspicious about proposed optimisations. They tend to increase the code's complexity by far more than they increase its speed. (E.g. an order of magnitude more complex to get 10% speed increase.) And they often subtly break the semantics of the code. E.g. if you do floating point maths, optimizing compilers that assume that x + y - x equals y are BROKEN. > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? Very likely. But the optimization happens at runtime, not at compile time. Default values for parameters are stored as an attribute of the function at definition time. So if you have this: def f(x, len=len): return len(x) then f gets a publicly accessible attribute func_defaults: >>> f.func_defaults (,) Even if you re-bind len, that doesn't change the binding here, and the *local* variable len will be assigned that value when f is called. Here's a practical example: >>> def test(len=len): ... while True: ... yield len ... >>> >>> it = test() >>> next(it) >>> len = None # rebind the global len >>> next(it) >>> test.func_defaults = (None, ) >>> next(it) But note that now as I've replaced the default value, the next time I call test() I'll get len=None. [...] > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? You really would need to demonstrate that the bottleneck in useful code (as opposed to toy examples) was the name lookups. -- Steven From rosuav at gmail.com Wed Aug 3 07:04:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 12:04:50 +0100 Subject: Early binding as an option In-Reply-To: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 11:16 AM, Steven D'Aprano wrote: > Chris Angelico wrote: >> Of course; that's a different issue altogether. No, I'm talking about >> the way a tight loop will involve repeated lookups for the same name. > > It's not really a different issue. The "standard" approach for performing > early binding in Python is by binding a global name to a local name at > function definition time. Thanks for the detailed response! My concept was that this wouldn't affect the dynamism significantly, and that if the function's caller wanted to change the definition of 'len', s/he could still do so; the "snapshotting" would occur as the function begins executing. This would make things rather safer, as there's a limited window during which this could affect things. > In CPython at least, local lookups are faster > than globals: locals are stored in a fixed array, and the function knows > the numeric offset of each variable. Ah! I was not aware of this, and thought that locals were a dictionary too. Of course, it makes a lot of sense. In that case, the classic "grab it as a local" isn't just loading down the locals dictionary with more names and thus slower lookups. > ? ? ? ?Do not supply the 'int', 'default', and 'maxwidth' arguments. > ? ? ? ?""" I love the way Python doesn't stop you from doing stupid things. This is an invitation to do something... hmm. >>> random.randrange(5,10,1,int=lambda x: (print(x),int(x))[1]) > But, are you *sure* that name lookups are *really* the bottleneck? Name > lookups are pretty fast. If you want them faster, turn them into a local > variable. It's not clear to me that syntax, or a pragma directive, or some > other form of magic, is better than an explicit assignment: No, I'm not sure. Unfortunately I have no convenient way to compare; all I can do is compare with a completely different language, which is of course NEVER going to be fair. The only actual data I have on the subject is the perfect-numbers search the other day; Pike managed the same task in a fraction of the time that Python spent on it. Pike has a single integer type that quietly switches from small to large at 2**32, with a noticeable performance change. This is the same as Python 2, but could explain some of the Python 3 penalty. There's only two obvious possibilities (there may be others, of course): firstly, that the actual name lookup is expensive; and secondly, that Pike is able to optimize integer arithmetic by knowing that the value in question is an int, and it will never be anything else. Since I was under the impression that local variables were stored in a hash table, I concluded that the first option was reasonably likely, and tried to get more data. >> So... Would this potentially produce wrong results? Would it be of any >> use, or would its benefit be only valued in times when the whole >> function needs to be redone in C? > > You really would need to demonstrate that the bottleneck in useful code (as > opposed to toy examples) was the name lookups. And especially, prove that the same can't be done with local variables. So which is the better idiom? def func(x): _len = len # bind at function call time for i in x: _len(i) # lookups of _len will be faster than len or: def func(x): len = len # localize len for i in x: len(i) # use it exactly as you otherwise would In other words, is it "Explicit is better than implicit" or "Simple is better than complex"? Since this does absolutely exactly the same thing as the original, I'd be inclined to go with the second form; a single line at the top of the function, with an explanatory comment perhaps, and the rest of the code is unaware of the optimization. But this has the potential to be insanely confusing if anything goes wrong, because down in the body of the function there's no clue that anything was changed. Unfortunately I can't offer any real-world use cases or examples. This is purely a thought experiment at the moment. Chris Angelico From python.list at tim.thechases.com Wed Aug 3 07:15:46 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Aug 2011 06:15:46 -0500 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E392DE2.7080006@tim.thechases.com> On 08/03/2011 03:25 AM, Steven D'Aprano wrote: > gc wrote: > >> Target lists using comma separation are great, but they don't work >> very well for this task. What I want is something like >> >> a,b,c,d,e = *dict() > > > a, b, c, d, e = [dict() for i in range(5)] > > Unfortunately there is no way of doing so without counting the assignment > targets. While slightly ugly, it doesn't seem ugly enough to justify the > extra complexity of special syntax for such a special case. I understand that in Py3k (and perhaps back-ported into later 2.x series?) one can do something like a, b, c, d, e, *junk = (dict() for _ in range(9999)) to prevent the need to count. However, I was disappointed with all the generator-ification of things in Py3k, that this "and the rest" syntax slurps up the entire generator, rather than just assigning the iterator. That would much more tidily be written as a,b,c,d,e, *more_dict_generator = (dict() for _ in itertools.count()) (itertools.count() happening to be a infinite generator). I can see the need to slurp if you have things afterward: a,b,c, *junk ,d,e = iterator(...) but when the "and the rest" is the last one, it would make sense not to force a slurp. -tkc From python.list at tim.thechases.com Wed Aug 3 07:25:34 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Aug 2011 06:25:34 -0500 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E39302E.9090602@tim.thechases.com> On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: > On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: >> a, b, c, d, e = [dict() for i in range(5)] > > I think this is good code -- if you want five different dicts, > then you should call dict five times. Otherwise Python will > magically call your expression more than once, which isn't > very nice. And what if your datatype constructor has > side-effects? If the side-effects are correct behavior (perhaps opening files, network connections, or even updating a class variable) then constructor side-effects are just doing what they're supposed to. E.g. something I use somewhat regularly in my code[*]: a,b,c,d = (file('file%i.txt', 'w') for i in range(4)) If the side-effects aren't performing the correct behavior, fix the constructor. :) -tkc [*] okay, it's more like (features, adjustments, internet, ) = (file(fname) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) or even (features, adjustments, internet, ) = ( set( line.strip().upper() for line in file(fname) if line.strip() ) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) to load various set() data from text-files. From stefan_ml at behnel.de Wed Aug 3 08:21:23 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 14:21:23 +0200 Subject: Early binding as an option In-Reply-To: <4E391C25.9070702@jollybox.de> References: <4E391C25.9070702@jollybox.de> Message-ID: Thomas Jollans, 03.08.2011 12:00: > JavaScript JITs are smart enough, so a good Python > JIT could be as well. Why "could"? There's PyPy if you need it. Stefan From eudes.elie at gmail.com Wed Aug 3 08:39:51 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Wed, 3 Aug 2011 05:39:51 -0700 (PDT) Subject: timeout issue with modules dbus & gobject Message-ID: Hi, Here is a sample code that reproduces the issue : [code] import logging import unittest import signal import gobject import dbus from functools import wraps from dbus.mainloop.glib import DBusGMainLoop class TimeoutException(Exception): pass def timeout(timeout_time=1800): """ decorator function catching the argument """ def timeout_function(func): """ decorator function """ @wraps(func) def _timeout_function(self): """ create a signal handler set the timeout with the argument given while calling the decorator @timeout call the function catch a timeout exception if necessary """ def timeout_handler(signum, frame): print 'Timeout (%s sec) reached' % str(timeout_time) raise TimeoutException() old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(timeout_time) # triger alarm in timeout_time seconds try: retval = func(self) finally: signal.signal(signal.SIGALRM, old_handler) signal.alarm(0) return retval return _timeout_function return timeout_function class Test_loopRun_And_Timeout(unittest.TestCase): def __init__(self,*args,**kwargs): super(Test_loopRun_And_Timeout, self).__init__(*args,**kwargs) dbus_loop = DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus(private=True,mainloop=dbus_loop) self.loop = gobject.MainLoop() logging.basicConfig() self.__logger = logging.getLogger("Tests.%s" % self.__class__.__name__) self.__logger.setLevel(logging.DEBUG) def setUp(self): ''' in this part, mediarouter can not be created Setup are all launch in // So if 50 tests are run in this class, 50 mediarouters are created ''' pass def tearDown(self): ''' ''' @timeout(5) def test_001(self): ''' ''' self.__logger.info('[CHECKPOINT] test_001') try: self.__logger.info('entering a waiting loop') self.loop.run() self.__logger.info('dummy log, should not appear') self.fail() except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') except : self.__logger.exception('Unexpected error') self.fail() @timeout(5) def test_002(self): ''' ''' def loop_quit(loop): loop.quit() return False self.__logger.info('[CHECKPOINT] test_002') try: self.__logger.info('entering a waiting loop') gobject.timeout_add(1000, loop_quit, self.loop) self.loop.run() self.__logger.info('exiting the loop') except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') self.fail() except : self.__logger.exception('Unexpected error') self.fail() [/code] If I start a unittest campaign like this : [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_002')) suite.addTest(Test_loopRun_And_Timeout('test_001')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] the result give me 2 tests OK Now If I launch this [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_001')) suite.addTest(Test_loopRun_And_Timeout('test_002')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] 1 OK (test_001) 1 Fail (test_002 goes on timeout) And if I am using more than 3 Testcases, the code is going to run in infinite loop (Ctrl+C or timeout decorator does not work, only a kill works) Is there an issue using the 'timeout' decorator with the loop.run() ? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Aug 3 08:42:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 03 Aug 2011 14:42:57 +0200 Subject: with statement and context managers In-Reply-To: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 03.08.2011 04:15 schrieb Steven D'Aprano: > I'm not greatly experienced with context managers and the with > statement, so I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently > use this idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > with spam: > # do stuff > > > but to me that looks badly wrong. Surely the spam context manager > object will exit after the first iteration, and always raise an > exception on the second? But I don't quite understand context > managers enough to be sure. Depends on the implementation. As already stated, a contextlib.contextmanager will only run once. But it is easy to turn it into a persistent one - which internally initializes as often as needed. class PersistentCM(object): def __init__(self, target): self.target = target self.current = [] def __enter__(self): cm = self.target() cm.__enter__() self.current.append(cm) def __exit__(self, *e): return self.current.pop(-1).__exit__(*e) (untested) This would allow for a CM to be used multiple times. It internally generates a new one on every __enter__() call and disposes of it on every __exit__(). As __enter__() and __exit__() are supposed to be used symmetrical, it should(!) work this way. Many CMs don't allow your shown use, though, partly due to obvious reasons: * The ...ing named ones do the action they are named after in the __exit__() part and do nothing in the __enter__() part. (E.g. closing.) * The ...ed named ones do the named action in __enter__() and undo it in __exit__(). They may or may not work multiple times. For example, take threading.Lock et al., which you can have locked several times. >>>> spam = open('aaa') >>>> for ham in range(5): > ... with spam: > ... print ham > ... > 0 > Traceback (most recent call last): > File "", line 2, in > ValueError: I/O operation on closed file To be honest, this one I don't understand as well. __exit__() closes the file spam, but even before "print ham" can be executed for a second time, there is a check if the file is still open. What does __enter__() do here? Just check if it is closed, or is it more? Nevertheless, it makes sense. > # Slightly more complex example. > >>>> from contextlib import closing >>>> import urllib >>>> spam = closing(urllib.urlopen('http://www.python.org')) >>>> for ham in range(5): > ... with spam as page: > ... print ham, sum(len(line) for line in page) > ... > 0 18486 > 1 > Traceback (most recent call last): > File "", line 3, in > File "", line 3, in > File "/usr/local/lib/python2.7/socket.py", line 528, in next > line = self.readline() > File "/usr/local/lib/python2.7/socket.py", line 424, in readline > recv = self._sock.recv > AttributeError: 'NoneType' object has no attribute 'recv' Here the above said applies: after closing happens in __exit__() and _sock gets set to None, the object is not usable any longer. > Am I right to expect that the above idiom cannot work? If not, what sort of > context managers do work as shown? As said, take threading.Lock as an example: they can be acquire()d and release()d as often as you want, and these actions happen in __enter__() and __exit__(), respectively. HTH, Thomas From phlip2005 at gmail.com Wed Aug 3 09:13:24 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 06:13:24 -0700 (PDT) Subject: attach cString to memoryview? Message-ID: <4232b39e-e07c-4e12-92e3-1e7b035422a6@a2g2000prf.googlegroups.com> HypoNt; My ulterior motive is the perfect command spawner: def call_4(cmd): import cStringIO # memoryview type # New in version 2.7. v = memoryview('abcefg') q = cStringIO.StringIO() p = Popen(cmd, shell=True, stdout=q, bufsize=4096) def check_me(): # consider: examine p or v here return q.read() return check_me # check_it = call_4('ls') # check_it() assert 'fabfile.py' in call_4('ls')() # Look, ma! No self.! The Subject line problem refers to how to get rid of this: AttributeError: 'cStringIO.StringO' object has no attribute 'fileno' To give it one, plug in a memoryview, right? Pencils down in 15 minutes, okay? Go! While I'm googling up a more mundane (and less performant) solution with a normal file... Distractingly yrs- -- Phlip http://bit.ly/ZeekLand From jayronsoares at gmail.com Wed Aug 3 09:26:26 2011 From: jayronsoares at gmail.com (Jayron Soares) Date: Wed, 3 Aug 2011 10:26:26 -0300 Subject: parsing in python Message-ID: Hi folks, I've created a simple method to grab files texts from directory by words random, however I figure out that I need extract the content inside of each file, in fact I believe I have to create a parsing, nonetheless I don't know how to create a parser. Please some could share some tips to do it? Cheers Jayron here is the code: # -*- conding: utf-8 -*- from subprocess import Popen, PIPE pesquisa = raw_input(" Digite a pesquisa de interesse: ") def Pesquisar(pesquisa): p = Popen(["search", pesquisa],stdout=PIPE) resultado = p.communicate()[0] return resultado print Pesquisar(pesquisa) -- *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* http://bucolick.tumblr.com http://artecultural.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 3 09:41:55 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 15:41:55 +0200 Subject: attach cString to memoryview? References: <4232b39e-e07c-4e12-92e3-1e7b035422a6@a2g2000prf.googlegroups.com> Message-ID: Phlip wrote: > q = cStringIO.StringIO() > p = Popen(cmd, shell=True, stdout=q, bufsize=4096) > The Subject line problem refers to how to get rid of this: > > AttributeError: 'cStringIO.StringO' object > has no attribute 'fileno' What's wrong with subprocess.PIPE? >>> import subprocess as sp >>> p = sp.Popen(["ls", "/usr/lib/python2.6"], stdout=sp.PIPE) >>> print p.communicate()[0] From invalid at invalid.invalid Wed Aug 3 10:22:57 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Aug 2011 14:22:57 +0000 (UTC) Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On 2011-08-03, Kushal Kumaran wrote: > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: >> >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: >>> >>> On 02/08/11 11:32, loial wrote: >>> > I am trying to hardlink all files in a directory structure using >>> > os.link. >>> > >>> > However I do not think it is possible to hard link directories ? >> >> That is pretty true.?? I've heard of hardlinked directories on Solaris, but >> that's kind of an exception to the general rule. > > In APUE, Richard Stevens says only root could do this, Yep, in early versions of Solaris root could hard-link directories. I did it once, and it's not something one did a second time. fsck couldn't deal with it and pretty much fell over. IIRC, the only way to recover was to clear several inodes manually and then let fsck salvage things. > if it is supported by the system at all. In a footnote, he > additionally mentions he screwed up his filesystem by creating a loop > of hardlinked directories while writing that section of the book. That sounds about right. > I suppose it is a good thing systems don't allow that now. It wouldn't be a problem, except there are some important places in Unix where it is assume that filesystems are trees. Hard linking directories causes that assumption to be false. -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From t at jollybox.de Wed Aug 3 11:08:48 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 17:08:48 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: <4E396480.3060108@jollybox.de> On 03/08/11 16:22, Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: >> I suppose it is a good thing systems don't allow that now. > > It wouldn't be a problem, except there are some important places in > Unix where it is assume that filesystems are trees. Hard linking > directories causes that assumption to be false. > It is generally assumed that ".." is clearly defined, i.e. that every directory has a parent. With hard linked directories, this would break down. From phlip2005 at gmail.com Wed Aug 3 11:29:08 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 08:29:08 -0700 (PDT) Subject: Snippet: The leanest Popen wrapper Message-ID: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Groupies: This is either a code snippet, if you like it, or a request for a critique, if you don't. I want to call a command and then treat the communication with that command as an object. And I want to do it as application-specifically as possible. Anyone could think of a way to productize this: def command(*cmdz): process = Popen( flatten(cmdz), shell= True, stdout= subprocess.PIPE, stderr= subprocess.PIPE, bufsize= 4096 ) def line(): return process.stdout.readline().rstrip() def s(): while True: l = line() if not l: break yield l line.s = s return line That leads to some syntactic sugar. For example, one truly demented way to stream in an entire block and then treat it as one big string is this: print '\n'.join(command('ls').s()) The point of the command() complex is the ability to start a long command and then fetch out individual lines from it: line = command('find', '../..') print 'lines' print line() print line() print line() print 'all' print list(line.s()) If you need different pipe abilities, such as stdin, you can trivially add them to the contents of command() (it's not productized on purpose). So I can take the line() functor and, for example, pin it to a View object, or put it in another thread now, right? -- Phlip http://bit.ly/ZeekLand From t4rtine at gmail.com Wed Aug 3 11:37:21 2011 From: t4rtine at gmail.com (julien godin) Date: Wed, 3 Aug 2011 17:37:21 +0200 Subject: python distributed computing Message-ID: Hello the list, I have a, let say 'special' , request. I would like to make a very specific type of distributed computing. Let me explain myself : I have a HUUUUUGE(everything is relative) amount of data coming from UDP/514 ( good old syslog), and one process alone could not handle them ( it's full of regex, comparison and counting. all this at about 100K lines of data per seconds and each line is about 1500o long. I tried to handle it on one process, 100% core time in htop. ) So i said to myself : why not distribute the computing ? I looked for a good library that could do the distribution/process management job for me (http://wiki.python.org/moin/ParallelProcessing). What i found was not really usable by me ( distributed processing with a lot of processing but almost no process communication wich is the opposite of the thing i would like to do: distribute the events in real time so it is processed in real time.). My question is : is their any library or API or anything that is able to do that ? Sincerly Julien PS: This is my first time posting on any mailing list, my explanation/syntax could look a little bite, messy. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 3 11:51:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 16:51:20 +0100 Subject: python distributed computing In-Reply-To: References: Message-ID: On Wed, Aug 3, 2011 at 4:37 PM, julien godin wrote: > I have a HUUUUUGE(everything is relative) amount of data coming from UDP/514 > ( good old syslog), and one process alone could not handle them ( it's > full?of regex, comparison and counting. all this at about 100K lines of data > per seconds and each line is about 1500o long. I tried to handle it on one > process, 100% core time in htop. ) > So i said to myself : why not distribute the computing ? You could brute-force it by forking out to multiple computers, but that would entail network traffic, which might defeat the purpose. If you have a multi-core CPU or multi-CPU computer, a better option would be to look into the multiprocessing module for some simple ways to divide the work between cores/CPUs. Otherwise, there's a few things to try. First and most important thing: Optimize your algorithms! Can you do less work and still get the same result? For instance, can you replace the regex with two or three simpler string methods? Profile your code to find out where most of the time is being spent, and see if you can recode those parts. Second: Try PyPy or Cython for higher-performance Python code. And third, if you still can't get the performance you need, consider changing languages. Python isn't the best language for fast execution - it's good for fast coding. Rewrite some or all of your code in C, Pike, COBOL, raw assembly language... okay, maybe not those last two! Since you profiled your code up in step 1, you'll know which parts are the best candidates for C code. I think there are quite a few options better than forking across computers; although distributed computing IS a lot of fun. Chris Angelico From missive at hotmail.com Wed Aug 3 12:02:04 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 20:32:04 +0430 Subject: parsing function parameters Message-ID: I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) def pdict(f, pstr): ??? '''given a function object and a string with the function parameters, ??? return a dictionary of {parameter name: default value or None, ...} ??? I don't really need the actual default values, just knowing that ??? they exist or having their string representations would be fine. ??? def foo(x, y, z=50): ??????? pass ??? ps = 'x, y, z=50' ??? pdict(foo, ps) ??? {'x': None, 'y': None, 'z': 50} ??? OR: {'x': '', 'y': '', 'z': '50'} ??? OR: {'x': False, 'y': False, 'z': True} ??? Note that the parameter list can be arbitrarily complex ??????? (as long as it is legal python) ??? def bar(m, n=(1, 2, 3), o? =? ('n=5', 'or anything legal')): ??????? pass ??? pps = 'm, n=(1, 2, 3), o? =? ('n=5', 'or anything legal')' ??? pdict(bar, pps) ??? {'m': None, 'n': '(1, 2, 3)', 'o': "('n=5', 'or anything legal')"} ??? ''' ??? prs = f.func_code.co_varnames ??? rxl = [r'(\s*%s\s*=(?=(?:\s*\S+))\s*\S+)\s*'%pr for pr in prs] ??? rx = ','.join(rxl) ??? print rx ??? import re ??? re.match(rx, pstr).groups() This regex works in limited situations, namely when every parameter has a default value, but I can't figure out how to also make it match a parameter that has no default. I am open to any solution, though I am reluctant to pull in any more external libraries just for this one little enhancement. I have it working by just splitting the pstr on comma, except of course that it fails when the default value contains a comma (a tuple or list, for instance). Any assistance or ideas appreciated. From coolaj86 at gmail.com Wed Aug 3 12:08:14 2011 From: coolaj86 at gmail.com (AJ ONeal) Date: Wed, 3 Aug 2011 10:08:14 -0600 Subject: [job] multiple openings for CS, CE, EE, IT majors / graduates Message-ID: I know of some job openings. Contact me off list for more details. The positions are full-time (or at least 30hrs / week) paid internships that should lead to a full-time salaried position in near future. If a *mix of any* of the bullet points below *describes you* or *someone you know*, please ask me some questions, send me a resume, and I'll get you in touch with some great people who need you! *All great candidates* - have taken their education into their own hands to some degree - learn quickly - have beyond-the-classroom experience / personal projects - know how to leverage tools and people in their circle (forums, interest groups, friends) to find answers to questions - are familiar with *nix and know their way around with find, grep, vim (or emacs) *Event-driven Application Developer* - could write a basic evented messaging queueing and retrieval service in about a week - can solve fizzbuzz in less than an hour - has written a simple chat server - knows the difference between a markup language and an object notation - is familiar with one of node.js, python / twisted, ruby / eventmachine, go, erlang - has used a web framework of some sort - has used C and written a queue of some sort - enjoys regex - has a good understanding of http and general networking concepts - has used wireshark to examine http and tcp traffic - has written a native mobile app (iOS, Android) *Gadget Engineer* - could build a rechargeable battery-powered usb hub in about a week - could reverse engineer a cheap usb hub from e-bay in about a day - could build a pringles cantenna in about a day - has used C and written a queue of some sort - can write object-oriented C (as if it were a programming language) - has played with Arduino, Bug, Beagle, Panda, or some other sort of project board - Envies those who own a Fluke multimeter (or owns one) *HTML5 Web App Developer* - could write a basic client-side timesheet application in about a week - has a good handle on JavaScript - knows how to use CSS selectors - knows the difference between a markup language and an object notation - knows the difference (or relationship) between HTML and the DOM - can solve fizzbuzz in less than an hour - has written a simple chat server - can draw a graph on canvas - enjoys regex - has worked with APIs such as Google Apps, facebook, twitter, etc - has a good understanding of http and general networking concepts - has used wireshark or firebug to examine http traffic - has written a native mobile app (iOS, Android) *Linux Techie++* - could set up a VPS with nginx, gitosis, git pull hooks, and reverse-proxied apps in about a week - has built a kernel - has built an out-of-tree kernel module - can use bash almost as if were a programming language (but has the good sense not to) - can write object-oriented C (as if it were a programming language) - enjoys regex - has used C and written a queue of some sort - has used wireshark to examine traffic - is familiar with one of node.js, python / twisted, ruby / eventmachine, go, erlang AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 12:18:15 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:18:15 -0700 Subject: parsing in python In-Reply-To: References: Message-ID: To just split lines into words, you could probably just use a regex. If you need to match things, like quotes or brackets or parens, pyparsing is pretty nice. On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by words > random, however I figure out that I need extract the content inside of each > file, in fact I believe I have to create a parsing, nonetheless I don't > know how to create a parser. > Please some could share some tips to do it? > Cheers > Jayron > here is the code: > > # -*- conding: utf-8 -*- > > > from subprocess import Popen, PIPE > > pesquisa = raw_input(" Digite a pesquisa de interesse: ") > > def Pesquisar(pesquisa): > p = Popen(["search", pesquisa],stdout=PIPE) > resultado = p.communicate()[0] > return resultado > > > print Pesquisar(pesquisa) > > > > > -- > *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* > > http://bucolick.tumblr.com > http://artecultural.wordpress.com/ > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 3 12:21:22 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 18:21:22 +0200 Subject: Snippet: The leanest Popen wrapper References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Phlip wrote: > Groupies: I smell a slight misperception of the audience you are addressing ;) > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) Protect your environment, don't let stderr pollute the nearby river ;) > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() At that point l may be empty because you have read the output completely or because there was an empty line that you rstripped to look like the end of file. > if not l: break > yield l > > line.s = s > > return line I think you are overdoing that closure/function factory thing a bit... Seriously, you should reread the subprocess documentation to learn how to avoid deadlocks. From abhishek11005 at iiitd.ac.in Wed Aug 3 12:22:26 2011 From: abhishek11005 at iiitd.ac.in (Abhishek Jain) Date: Wed, 3 Aug 2011 21:52:26 +0530 Subject: Equality check Message-ID: How to check equality of two nos. in python -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Aug 3 12:23:08 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 18:23:08 +0200 Subject: parsing function parameters In-Reply-To: References: Message-ID: Lee Harr, 03.08.2011 18:02: > I am trying to get some information about a function > before (and without) calling it. > > Here is what I have so far. I chose to go with a > regular expression, so now I have 2 problems :o) Can't you just use runtime introspection? Take a look at the inspect module. Stefan From drsalists at gmail.com Wed Aug 3 12:29:24 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:29:24 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E391933.6070603@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans wrote: > Is it more portable? I don't actually have cpio installed on this > system. Interesting. Of course, it's probably readily available to you. What *ix are you seeing that doesn't include cpio by default? > Which implementations of cp don't implement -R and -l? Probably most of them, except GNU and newer BSD. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 12:31:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:31:08 -0700 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 12:04 AM, Nobody wrote: > On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > > > However I do not think it is possible to hard link directories ? > > Modern Unices disallow hard links to directories, as it makes the > directory "tree" not a tree, so anything which performs a recursive walk > must explicitly check for cycles to avoid infnite recursion. > > Older systems which allowed hard links to directories required root > privilege to do so. > > Actually, I recently heard about a system with multiple Solaris Containers set up, that were sharing their /usr via directory hardlinks. The question came up: How does one back up such a system? But ufsdump worked. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stutzbach at google.com Wed Aug 3 12:33:17 2011 From: stutzbach at google.com (Daniel Stutzbach) Date: Wed, 3 Aug 2011 09:33:17 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which is quite distinct from OrderedDict). > Or look for a binary search tree or skip list implementation of some > sort; but these aren't commonly used in Python, so it may be hard to > find a good one. > The blist package (I'm the author) provides a list-like type that has O(log n) insertions and deletions. It provides a sorteddict type that uses the blist type under-the-hood. blist's "sorteddict" supports the "key" parameter (which works like list.sort's key parameter), which the original poster could use to maintain the keys in reverse order. http://pypi.python.org/pypi/blist/ There's no overhead to learn how to use the new types. A blist works exactly like a list but with different performance characteristics, and a sorteddict works just like a dict but keeps the keys sorted. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Aug 3 12:39:12 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 18:39:12 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: <4E3979B0.3080402@jollybox.de> On 03/08/11 17:29, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) > > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() > if not l: break This will ignore everything after a blank line. Intended? It may be better not to use readline(), but to use the fact that it's an iterable, and use next(process.stdout) to get each line. (and deal with StopIteration accordingly -- or not) > yield l > > line.s = s > > return line > > That leads to some syntactic sugar. For example, one truly demented > way to stream in an entire block and then treat it as one big string > is this: > > print '\n'.join(command('ls').s()) > > The point of the command() complex is the ability to start a long > command and then fetch out individual lines from it: > > line = command('find', '../..') > > print 'lines' > print line() > print line() > print line() > > print 'all' > print list(line.s()) > > If you need different pipe abilities, such as stdin, you can trivially > add them to the contents of command() (it's not productized on > purpose). > > So I can take the line() functor and, for example, pin it to a View > object, or put it in another thread now, right? > > -- > Phlip > http://bit.ly/ZeekLand From t at jollybox.de Wed Aug 3 12:44:04 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 18:44:04 +0200 Subject: Equality check In-Reply-To: References: Message-ID: <4E397AD4.2010908@jollybox.de> On 03/08/11 18:22, Abhishek Jain wrote: > How to check equality of two nos. in python > > http://docs.python.org/py3k/reference/expressions.html#not-in http://docs.python.org/py3k/tutorial/index.html From __peter__ at web.de Wed Aug 3 12:51:27 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 18:51:27 +0200 Subject: parsing function parameters References: Message-ID: Lee Harr wrote: > I am trying to get some information about a function > before (and without) calling it. If you allow for the function arguments to be evaluated it's easy (requires Python 2.7): >>> import inspect >>> def get_args(*args, **kw): ... return args, kw ... >>> argstr = "1, 2, z=42" >>> def f(a, b, x=1, y=2, z=3): ... pass ... >>> args, kw = eval("get_args(%s)" % argstr) >>> inspect.getcallargs(f, *args, **kw) {'a': 1, 'x': 1, 'b': 2, 'z': 42, 'y': 2} From jayronsoares at gmail.com Wed Aug 3 13:05:36 2011 From: jayronsoares at gmail.com (Jayron Soares) Date: Wed, 3 Aug 2011 14:05:36 -0300 Subject: parsing in python In-Reply-To: References: Message-ID: Hi Dan, Thank you a lot =) Cheers Jayron 2011/8/3 Dan Stromberg > > To just split lines into words, you could probably just use a regex. > > If you need to match things, like quotes or brackets or parens, pyparsing > is pretty nice. > > On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > >> Hi folks, >> >> I've created a simple method to grab files texts from directory by words >> random, however I figure out that I need extract the content inside of each >> file, in fact I believe I have to create a parsing, nonetheless I don't >> know how to create a parser. >> Please some could share some tips to do it? >> Cheers >> Jayron >> here is the code: >> >> # -*- conding: utf-8 -*- >> >> >> from subprocess import Popen, PIPE >> >> pesquisa = raw_input(" Digite a pesquisa de interesse: ") >> >> def Pesquisar(pesquisa): >> p = Popen(["search", pesquisa],stdout=PIPE) >> resultado = p.communicate()[0] >> return resultado >> >> >> print Pesquisar(pesquisa) >> >> >> >> >> -- >> *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* >> >> http://bucolick.tumblr.com >> http://artecultural.wordpress.com/ >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* http://bucolick.tumblr.com http://artecultural.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Aug 3 13:27:41 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Aug 2011 10:27:41 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 8:29 AM, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > ? ?process = Popen( flatten(cmdz), flatten() being defined as...? > ? ? ? ? ? ? ? ? ? ? shell= True, I would strongly encourage you to avoid shell=True. You really don't want to have to worry about doing proper shell escaping yourself. > ? ? ? ? ? ? ? ? ? ? stdout= subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? stderr= subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? bufsize= 4096 ) Cheers, Chris From missive at hotmail.com Wed Aug 3 14:00:03 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 22:30:03 +0430 Subject: parsing function parameters In-Reply-To: <1312388985.25995.11.camel@tim-laptop> References: , <1312388985.25995.11.camel@tim-laptop> Message-ID: >> I am trying to get some information about a function >> before (and without) calling it. > how about def pdict(f): ??? parameter_defaults = {} ??? defaults = f.func_defaults ??? defaultcount = len(defaults) ??? argcount = f.func_code.co_argcount ??? for i in xrange(f.func_code.co_argcount): ??????? name = f.func_code.co_varnames[i] ??????? value = None ??????? if i >= argcount - defaultcount: ??????????? value = defaults[i - (argcount - defaultcount)] ??????? parameter_defaults[name] = value ??? return parameter_defaults > No need for the string parameters. > > Tim That's it! I saw the func_defaults, but could not see how to make them match up with the co_varnames. I forgot that keyword args must follow the positional args (duh). I think this is going to work perfectly. Thanks to all for the suggestions! From phlip2005 at gmail.com Wed Aug 3 14:04:53 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 11:04:53 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: > flatten() being defined as...? Python Cookbook recipe 4.6 def flatten(sequence): # CONSIDER: Reconcile with utils... for item in sequence: if isinstance(item, (list, tuple)): for subitem in flatten(list(item)): yield subitem else: yield item >> ? ? ? ? ? ? ? ? ? ? shell= True, > I would strongly encourage you to avoid shell=True. You really don't > want to have to worry about doing proper shell escaping yourself. Tx for helping me avoid reading up on it. I just copied it in. I keep getting "fab not found" etc. when running 'fab command' thru it. So then I ditch to os.system(). The long-term solution would be 'bash', '-c', 'yack yack yack' if you want truly shelly things! -- ? Phlip ? http://c2.com/cgi/wiki?ZeekLand From missive at hotmail.com Wed Aug 3 14:33:21 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 23:03:21 +0430 Subject: parsing function parameters Message-ID: Needed to make one change... for functions with no default args: def pdict(f): ??? parameter_defaults = {} ??? defaults = f.func_defaults ??? if defaults is not None: ??????? defaultcount = len(defaults) ??? else: ??????? defaultcount = 0 ??? argcount = f.func_code.co_argcount ??? for i in xrange(f.func_code.co_argcount): ??????? name = f.func_code.co_varnames[i] ??????? value = None ??????? if i >= argcount - defaultcount: ??????????? value = defaults[i - (argcount - defaultcount)] ??????? parameter_defaults[name] = value ??? return parameter_defaults From t at jollybox.de Wed Aug 3 14:49:22 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 20:49:22 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> Message-ID: <4E399832.3090009@jollybox.de> On 03/08/11 18:29, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans > wrote: > > Is it more portable? I don't actually have cpio installed on this > system. > > > Interesting. Of course, it's probably readily available to you. What > *ix are you seeing that doesn't include cpio by default? Arch Linux - the base install is quite minimal. I just discovered that I have a program called bsdcpio which is used by mkinitcpio (and possibly other system scripts); no need for the GNU cpio. Curious. > > > Which implementations of cp don't implement -R and -l? > > > Probably most of them, except GNU and newer BSD. Okay. While GNU libc manuals usually document how portable functions are in detail, that's not true for the GNU coreutils manuals. Thomas From davea at ieee.org Wed Aug 3 15:15:56 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 03 Aug 2011 15:15:56 -0400 Subject: Equality check In-Reply-To: References: Message-ID: <4E399E6C.9000408@ieee.org> On 01/-10/-28163 02:59 PM, Abhishek Jain wrote: > How to check equality of two nos. in python > Python doesn't have numbers, it has various numeric data types. If all you're concerned with are int types, then just use the obvous: if a == b: dosomething.... If one or both might be floats, you have to deal with the likelihood that one or both may have quantization error, either caused by computational approximations, precision limitations, or conversion back and forth between string and internal binary representation. If one is in Decimal, you have to mostly deal with the first two. If one is complex, ... DaveA From steve+comp.lang.python at pearwood.info Wed Aug 3 15:51:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 05:51:16 +1000 Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: >> In CPython at least, local lookups are faster >> than globals: locals are stored in a fixed array, and the function knows >> the numeric offset of each variable. > > Ah! I was not aware of this, and thought that locals were a dictionary > too. Of course, it makes a lot of sense. In that case, the classic > "grab it as a local" isn't just loading down the locals dictionary > with more names and thus slower lookups. Er, not quite. Hash tables don't get slower as you add more items in them. The difference is between: (1) Search for "name" in globals dict; (2) If not found, search for "name" in builtins dict; (both searches being O(1) constant time to a first approximation) versus: (1) Look in slot 5 in the function table of local variables Name lookups involve hashing the string, then jumping to that position in a hash table, then checking the name equals the key actually found. On average, that requires constant time regardless of how many keys are in the hash table (although the hash calculation and the equality tests might depend on the length of the name). So the whole thing is predictably fast. But not quite as fast as a simple jump to an offset to a table. In theory, if you can arrange matters so that the dict is full of keys which all hash the same, then performance will fall to O(N) instead of O(1), but that would be *very* hard to do by accident. (A malicious coder might find a way to fill your globals with a whole lot of three-letter variables that happen to hash equal to that of "len", but then a malicious coder has better ways of making your life miserable than slowing down name lookups.) >> But, are you *sure* that name lookups are *really* the bottleneck? Name >> lookups are pretty fast. If you want them faster, turn them into a local >> variable. It's not clear to me that syntax, or a pragma directive, or >> some other form of magic, is better than an explicit assignment: > > No, I'm not sure. Unfortunately I have no convenient way to compare; Have you tried using the profiler? > all I can do is compare with a completely different language, which is > of course NEVER going to be fair. The only actual data I have on the > subject is the perfect-numbers search the other day; Pike managed the > same task in a fraction of the time that Python spent on it. Pike has > a single integer type that quietly switches from small to large at > 2**32, with a noticeable performance change. This is the same as > Python 2, but could explain some of the Python 3 penalty. There's only > two obvious possibilities (there may be others, of course): firstly, > that the actual name lookup is expensive; I wouldn't imagine that's a big factor, but I could be wrong. > and secondly, that Pike is > able to optimize integer arithmetic by knowing that the value in > question is an int, and it will never be anything else. Much more likely. Or that Pike's programming model is simpler and therefore code is faster, or it has a smarter compiler... there could be many, many different reasons. Or you cheated and used a slightly different algorithm in Pike :) [...] > So which is the better idiom? > > def func(x): > _len = len # bind at function call time > for i in x: > _len(i) # lookups of _len will be faster than len That's the standard way of doing, er, early binding as late as possible :) To do early binding as early as possible: def func(x, len=len): # binds at function definition time for i in x: len(i) > or: > > def func(x): > len = len # localize len > for i in x: > len(i) # use it exactly as you otherwise would That can't work. The problem is that because len is assigned to in the body of the function, the Python compiler treats it as a local variable. So the line len=len is interpreted as len = len, which doesn't yet exist. There's no way of saying len = len in the body of the function. So you must either: (1) use a different name: length = len (2) use a fully-qualified name: import builtins; len = builtins.len (3) do the assignment as a default parameter, which has slightly different binding rules: def func(x, len=len) (4) manual lookup: len = builtins.__dict__['len'] # untested I don't recommend that last one, unless you're deliberately trying to write obfuscated code :) -- Steven From nad at acm.org Wed Aug 3 15:57:23 2011 From: nad at acm.org (Ned Deily) Date: Wed, 03 Aug 2011 12:57:23 -0700 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: In article , Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: > > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: > >> > >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > >>> > >>> On 02/08/11 11:32, loial wrote: > >>> > I am trying to hardlink all files in a directory structure using > >>> > os.link. > >>> > > >>> > However I do not think it is possible to hard link directories ? > >> > >> That is pretty true.?? I've heard of hardlinked directories on Solaris, but > >> that's kind of an exception to the general rule. > > > > In APUE, Richard Stevens says only root could do this, > > Yep, in early versions of Solaris root could hard-link directories. > I did it once, and it's not something one did a second time. fsck > couldn't deal with it and pretty much fell over. IIRC, the only way > to recover was to clear several inodes manually and then let fsck > salvage things. > > > if it is supported by the system at all. In a footnote, he > > additionally mentions he screwed up his filesystem by creating a loop > > of hardlinked directories while writing that section of the book. > > That sounds about right. > > > I suppose it is a good thing systems don't allow that now. > > It wouldn't be a problem, except there are some important places in > Unix where it is assume that filesystems are trees. Hard linking > directories causes that assumption to be false. FWIW, Apple implemented directory hard links for HFS+ file systems in Mac OS X 10.5 specifically to make the Time Machine incremental backup system work efficiently. The hard directory links are, of course, not meant to be used by the casual user. The section "Directory Hard Links" in this blog entry from Amit Singh explains what restrictions are enforced on directory hard links to prevent cycles: http://osxbook.com/blog/2008/11/09/hfsdebug-40-and-new-hfs-features/ -- Ned Deily, nad at acm.org From alain at dpt-info.u-strasbg.fr Wed Aug 3 16:16:27 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 03 Aug 2011 22:16:27 +0200 Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fwliw8ro.fsf@dpt-info.u-strasbg.fr> Chris Angelico writes: [...] > The only actual data I have on the subject is the perfect-numbers > search the other day; Pike managed the same task in a fraction of the > time that Python spent on it. Pike has a single integer type that > quietly switches from small to large at 2**32, with a noticeable > performance change. This is the same as Python 2, but could explain > some of the Python 3 penalty. There's only two obvious possibilities > (there may be others, of course): firstly, that the actual name lookup > is expensive; and secondly, that Pike is able to optimize integer > arithmetic by knowing that the value in question is an int, and it > will never be anything else. Pike is (at least partly) statically typed. Most of the lookups are solved at compile time, and have therefore zero overhead at run-time. So your second possibility is the good one, but probably not because of arithmetic optims, rather because of all the lookups Pike doesn't perform dynamically. -- Alain. From tjreedy at udel.edu Wed Aug 3 16:20:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Aug 2011 16:20:22 -0400 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On 8/3/2011 11:29 AM, Phlip wrote: > This is either a code snippet, if you like it, or a request for a > critique, if you don't. A learning exercise but pretty useless otherwise. As others pointed out, immediately stripping off \n is a bug relative to *your* function description. Also, you yourself then give an example of joining with \n. But that does not restore the final \n. The rest duplicates the iteration ability of the .stdout file object. For repeated execution of code like process.stdout.readline() you can once create a 'packetized' bound method object like so cmdline = process.stdout.readline and then, without repeating the attribute lookups, repeatedly call cmdline() . -- Terry Jan Reedy From drsalists at gmail.com Wed Aug 3 17:25:41 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 14:25:41 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E399832.3090009@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans wrote: > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsdcpio which is used by mkinitcpio (and possibly > other system scripts); no need for the GNU cpio. Curious. > I guess that makes some sense. If you want to really strip down an install, removing cpio is a good candidate since it duplicates what's in tar, and tar is more popular - especially for interactive use. > Which implementations of cp don't implement -R and -l? > > > Probably most of them, except GNU and newer BSD. Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a reimplementation, not the original. cpio's been around since PWB/Unix, which sits between 6th Edition Unix and 7th Edition. It should be in just about everything, unless a vendor/distributor got pretty zealous about cutting duplicate utilities. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astley.lejasper at gmail.com Wed Aug 3 17:46:04 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Wed, 3 Aug 2011 14:46:04 -0700 (PDT) Subject: Inconsistent SMTP/Gmail connection drop Message-ID: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> I have a laptop that wakes up and then runs a script that collects info and sends an email with a spreadsheet (zipped and about 350KB) report to a number of people. However, every time I get the following error: File "/usr/lib/python2.7/smtplib.py", line 343, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") - When I check the laptop and manually run the function that sends the email and report, it works fine. I have never been able to replicate the error when doing it manually. - It can't be a problem with Gmail at that time in the morning or my connection, because the script also sends me a copy of the log file straight after, and that works. - The same code has been working for years, it just that I have recently rebuilt the machine so now it is using Python 2.7. I have also change the references to use absolute file references, rather than relative. I also have changed the code to run as root. - I've checked the smtp debug report and everything seems ok. I just never get the confirmation code (250) to say that it's completed. - Even stranger ... it ran ok once. But I didn't change a thing and the next day it wouldn't work. The only thing I can think of is that when the file is transferred to the reports directory, it somehow isn't been released quickly enough and perhaps this is tripping up SMTP. But ... this is a bit of a guess given I've tried to exhaust all the other options. Any ideas? From t at jollybox.de Wed Aug 3 17:54:03 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 23:54:03 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> Message-ID: <4E39C37B.4030503@jollybox.de> On 03/08/11 23:25, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans > wrote: > > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsdcpio which is used by mkinitcpio (and possibly > other system scripts); no need for the GNU cpio. Curious. > > > I guess that makes some sense. If you want to really strip down an > install, removing cpio is a good candidate since it duplicates what's in > tar, and tar is more popular - especially for interactive use. > >> Which implementations of cp don't implement -R and -l? >> >> >> Probably most of them, except GNU and newer BSD. > > Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. > > > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a > reimplementation, not the original. Indeed. But cp is in the coreutils, and that was what we were talking about. As for GNU cpio, that's simply what /usr/bin/cpio, if present, is expected to be on a GNU/Linux system. > > cpio's been around since PWB/Unix, which sits between 6th Edition Unix > and 7th Edition. It should be in just about everything, unless a > vendor/distributor got pretty zealous about cutting duplicate utilities. > From dstanek at dstanek.com Wed Aug 3 18:17:27 2011 From: dstanek at dstanek.com (David Stanek) Date: Wed, 3 Aug 2011 18:17:27 -0400 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper wrote: > > Any ideas? > Is it possible that the first email is sent before the network connection has been properly established? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek www: http://dstanek.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 3 18:24:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 23:24:09 +0100 Subject: Early binding as an option In-Reply-To: <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 8:51 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Ah! I was not aware of this, and thought that locals were a dictionary >> too. Of course, it makes a lot of sense. In that case, the classic >> "grab it as a local" isn't just loading down the locals dictionary >> with more names and thus slower lookups. > > Er, not quite. Hash tables don't get slower as you add more items in them. Whoops, sloppy English there. The locals dictionary isn't slower because it gets more stuffed in it (well, maybe a dict will slow down if you stuff a few million things in it vs having five, but not with this scale), but that it's slower than alternatives. >> No, I'm not sure. Unfortunately I have no convenient way to compare; > > Have you tried using the profiler? I can profile the code the way it is. I can't profile the code the way it isn't, with static lookups. I could compare global vs local, but not global/local vs no lookup at all. >> and secondly, that Pike is >> able to optimize integer arithmetic by knowing that the value in >> question is an int, and it will never be anything else. > > Much more likely. Pike separates variables from their values, just as Python does. I've actually stuffed strings into variables that are supposed to be int only, and things work fine (a bit confusing for the human though!). But you're right that it's probably simplifying other lookups, not the actual variable name. I think the same consideration applies; if you know exactly what you're working with, if you assume that x.__add__ is not going to change, then you can optimize. > Or you cheated and used a slightly different algorithm in Pike :) Heh. No, I kept the algorithm exactly the same. I'll post the code if you like :) >> def func(x): >> ? ?len = len ?# localize len >> ? ?for i in x: >> ? ? ? ?len(i) ?# use it exactly as you otherwise would > > That can't work. The problem is that because len is assigned to in the body > of the function, the Python compiler treats it as a local variable. So the > line len=len is interpreted as len = len, which doesn't yet > exist. There's no way of saying len = len in the body of the > function. Duh. Forgot that. Without convenient syntax like "len = ::len" to do this, it's not advisable. > (4) manual lookup: len = builtins.__dict__['len'] ?# untested > > I don't recommend that last one, unless you're deliberately trying to write > obfuscated code :) For that reason! Although using builtins in this way isn't a good idea - there's no reason to do early binding late if you just bind to the same thing that early binding early would have done. And globals()["len"] doesn't work either, because builtins aren't globals... blargh, there's really no simple way to do this. It's a good thing I don't *need* to do anything like this, because it's not the syntactically simple optimization that I thought it would be! ChrisA From astley.lejasper at gmail.com Wed Aug 3 18:26:34 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 00:26:34 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Not sure how I'd test or determine that. I've set smtp debug to true and the output looks all good. I suppose I could try sending an email before the report is sent, as well as the email that is sent after it. On Thu, Aug 4, 2011 at 12:17 AM, David Stanek wrote: > On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper > wrote: >> >> Any ideas? >> > > Is it possible that the first email is sent before the network connection > has been properly established? > > -- > David > blog: http://www.traceback.org > twitter: http://twitter.com/dstanek > www: http://dstanek.com > From rosuav at gmail.com Wed Aug 3 19:57:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 00:57:47 +0100 Subject: Equality check In-Reply-To: <4E399E6C.9000408@ieee.org> References: <4E399E6C.9000408@ieee.org> Message-ID: On Wed, Aug 3, 2011 at 8:15 PM, Dave Angel wrote: > If one is complex, ... The situation is complex enough without bringing complex numbers into it! OP, I recommend reading this page and then re-asking your question: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA From drsalists at gmail.com Wed Aug 3 20:34:04 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 17:34:04 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E39C37B.4030503@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> <4E39C37B.4030503@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 2:54 PM, Thomas Jollans wrote: > > On 03/08/11 23:25, Dan Stromberg wrote: > > > Interesting. Of course, it's probably readily available to you. > What > > > *ix are you seeing that doesn't include cpio by default? > > > > Arch Linux - the base install is quite minimal. > Hmmmm... So we're probably not talking about portability to Android... Because it's too minimal, too different? >> Which implementations of cp don't implement -R and -l? >> >> >> Probably most of them, except GNU and newer BSD. > > Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. You don't really need it in the coreutils doc. I'd feel very safe assuming that 98+% of all *ix's (not counting Android) either have cpio installed by default, or can easily get it via their native package manager. The same isn't true of a cp with new features. > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a > reimplementation, not the original. Indeed. But cp is in the coreutils, and that was what we were talking about. > Sorry. Maybe you should describe what you believe we -are- talking about, then? I guess I missed that. I thought it was portability. > As for GNU cpio, that's simply what /usr/bin/cpio, if present, is > expected to be on a GNU/Linux system. > Well, yes, but: 1) GNU/Linux is important 2) GNU/Linux isn't the end all and be all (I wrote:) > cpio's been around since PWB/Unix, which sits between 6th Edition Unix > and 7th Edition. It should be in just about everything, unless a > vendor/distributor got pretty zealous about cutting duplicate utilities. I guess this is boiling down to "A pure python solution might be better, since some folks don't like to use their package managers" Also, a pure python solution should work on windows - these shell commands don't unless you have one of the many ports of *ix tools to windows installed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 21:02:26 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 18:02:26 -0700 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Some things to consider: 1) You might see if there's something about the size of the message - is it bigger after collecting data all night? Is google disconnecting after a maximum amount of data is transferred? 2) You might try sending a tiny test message at the beginning, just to yourself, and seeing if that has the problem 3) You might try running your script under a system call tracer: http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html- and inspecting the list of syscalls and their return codes near when the process terminates 4) I get disconnects from gmail once in a while too, especially when downloading a large list of new message headers; I've been just coding around it by making my code idempotent and otherwise restartable. This seems to happen with both 2.x and 3.x, so I assume it's not really related to the Python version, but I suppose I should try it on PyPy or Jython someday. Note that the error message in 3.x was better than in 2.x. HTH On Wed, Aug 3, 2011 at 2:46 PM, Astley Le Jasper wrote: > I have a laptop that wakes up and then runs a script that collects > info and sends an email with a spreadsheet (zipped and about 350KB) > report to a number of people. However, every time I get the following > error: > > > File "/usr/lib/python2.7/smtplib.py", line 343, in getreply > raise SMTPServerDisconnected("Connection unexpectedly closed") > > > - When I check the laptop and manually run the function that sends the > email and report, it works fine. I have never been able to replicate > the error when doing it manually. > - It can't be a problem with Gmail at that time in the morning or my > connection, because the script also sends me a copy of the log file > straight after, and that works. > - The same code has been working for years, it just that I have > recently rebuilt the machine so now it is using Python 2.7. I have > also change the references to use absolute file references, rather > than relative. I also have changed the code to run as root. > - I've checked the smtp debug report and everything seems ok. I just > never get the confirmation code (250) to say that it's completed. > - Even stranger ... it ran ok once. But I didn't change a thing and > the next day it wouldn't work. > > The only thing I can think of is that when the file is transferred to > the reports directory, it somehow isn't been released quickly enough > and perhaps this is tripping up SMTP. But ... this is a bit of a guess > given I've tried to exhaust all the other options. > > Any ideas? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From myeates at jpl.nasa.gov Wed Aug 3 21:19:25 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Wed, 3 Aug 2011 18:19:25 -0700 Subject: making my extensions work together Message-ID: This isn't exactly a Python question but maybe someone here has run into this. I have 2 extensions and they both access a function in a (static) library. The function maintains state information using a static variable. This doesn't work. When one of my extensions changes the variable value, the other extension does not see the change. Would it work if I made my library dynamic? This is on Windows XP compiling with MSVC 2008. -Mathew From steve+comp.lang.python at pearwood.info Wed Aug 3 23:01:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 13:01:50 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> harrismh777 wrote: > def perf(n): > sum = 0 > for i in range(1, n): > if n % i == 0: > sum += i > return sum == n A more effective way to speed that up is with a better algorithm: def isperfect(n): if n < 2: return False total = 1 for i in range(2, int(n**0.5)+1): a, b = divmod(n, i) if b == 0: total += a+i return total == n For n=33550336 it loops about 5791 times instead of 33550335, reducing the amount of work done by about 99.98%. isperfect is fast enough to exhaustively test every number up to a low limit: testing every number between 0 and 8128 inclusive took about 0.38 second in total on my PC. That's an average of 0.05 millisecond per number tested. Unfortunately, it doesn't scale. isperfect(33550336) takes about 4.4 ms, and isperfect(8589869056) about 84 ms. However, it is still (barely) feasible to exhaustively test every number up to a much higher range. I extrapolate that the time needed to check every value between 0 and 33550336 would take about 30 hours. If you're wondering why exhaustive testing is so expensive, it's because the test code simply calls isperfect(n) for each n. The number of iterations in each call to isperfect is approximately sqrt(n), so the total in any exhaustive test is approximately sum(x**0.5 for x in range(upperlimit)), which gets rather large. -- Steven From steve at holdenweb.com Wed Aug 3 23:14:44 2011 From: steve at holdenweb.com (Steve Holden) Date: Wed, 3 Aug 2011 20:14:44 -0700 Subject: Community Involvement Message-ID: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> [Ccs appreciated] After some three years labor I (@holdenweb) at last find myself approaching the completion of the Python Certificate Series with O'Reilly School of Technology (@OReillySchool). At OSCON last week the team fell to talking about the final assignment (although the Certificate is not a certification, students only progress by answering real quiz questions, not the usual multiple-choice task). Success also requires that they complete a project at the end of each (of the ~60) lesson(s). We would ideally like the last project to to be something that demonstrates at least some minimal involvement with the Python community. Something like "get a Python answer upvoted on StackOverflow", for example, or getting a question answered on c.l.p. At the same time it shouldn't be anything that places a burden on the community (otherwise the hundredth student would be abused and the thousandth murdered). So I wondered if anyone had any good ideas. regards Steve -- Steve Holden steve at holdenweb.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Wed Aug 3 23:22:30 2011 From: gordon at panix.com (John Gordon) Date: Thu, 4 Aug 2011 03:22:30 +0000 (UTC) Subject: making my extensions work together References: Message-ID: In "Mathew" writes: > This isn't exactly a Python question but maybe someone here has run into > this. > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. I'm not sure what you mean by "extension", but it might not be relevant. Are these extensions, whatever they may be, part of the same program? Or are they separate? > This doesn't work. When one of my extensions changes the variable value, the > other extension does not see the change. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From chrisallick at gmail.com Wed Aug 3 23:41:09 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:41:09 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: <3c8e8fd8-5d52-44e7-a0d4-c48b5d2ae22a@en1g2000vbb.googlegroups.com> On Aug 1, 11:39?am, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Catch a Kill: def signal_handler(signal, frame): print "Received exit command." #server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) Find and Kill A Process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process. From chrisallick at gmail.com Wed Aug 3 23:46:14 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:46:14 -0700 (PDT) Subject: HID Device Drivers for OS X Message-ID: <6f1f2143-662f-4949-93f3-779934a2d47c@en1g2000vbb.googlegroups.com> Hi, I spent almost all day trying to figure out how to capture a click from this button: http://www.dreamcheeky.com/big-red-button I tried libusb, PyUSB, HIDAPI and probably a couple other things. No luck. My understanding is that libusb won't allow me to get at the interface and the example I found using PyUSB to read a magnetic card reader errors with a segmentation fault in the libusb library. Can anyone point me in the right direction? I looked the OS X I/O Kit at developer.apple.com, but it seems really confusing and over kill. I have the vendor ID and product ID, it seems like it would be really simple to read when the button is clicked. Any thoughts? From chrisallick at gmail.com Wed Aug 3 23:47:20 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:47:20 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: <978bcdc2-308c-48d4-8879-8dc9da7d7592@x10g2000vbl.googlegroups.com> On Aug 1, 5:56?am, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > Could you suggest me if there's a way to do this? > > Thanks, regards. > > -- > Andrea Di Mario This will catch Ctrl+C and a Kill PID request: # Add SIGINT handler for killing the threads def signal_handler(signal, frame): print "Received exit command." server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) And this will find an destroy a process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process." From lists.jkstephens at gmail.com Thu Aug 4 00:05:55 2011 From: lists.jkstephens at gmail.com (John L. Stephens) Date: Thu, 04 Aug 2011 00:05:55 -0400 Subject: parsing in python In-Reply-To: References: Message-ID: <4E3A1AA3.8060209@gmail.com> Depending on what you want to do, you might try looking at the pyparsing module. I have used it to successfully parse sentences looking for keywords and structures. On 8/3/2011 9:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by > words random, however I figure out that I need extract the content > inside of each file, in fact I believe I have to create a parsing, > nonetheless I don't know how to create a parser. > Please some could share some tips to do it? > Cheers > Jayron > here is the code: > > # -*- conding: utf-8 -*- > > > from subprocess import Popen, PIPE > > pesquisa = raw_input(" Digite a pesquisa de interesse: ") > > def Pesquisar(pesquisa): > p = Popen(["search", pesquisa],stdout=PIPE) > resultado = p.communicate()[0] > return resultado > > > print Pesquisar(pesquisa) > > > > > -- > /" A Vida ? arte do Saber...Quem quiser saber tem que *Estudar*!"/ > > http://bucolick.tumblr.com > http://artecultural.wordpress.com/ > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dannwong at cisco.com Thu Aug 4 00:06:19 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 3 Aug 2011 23:06:19 -0500 Subject: python module to determine if a machine is idle/free In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Hi all, I have 5 server machines that are using to process information. I would like to write a quick server python script that determines which of the machines are not in use. Any recommendations on which python module I should use to detect if a machine is not performing idle (ex. Some specific task is not running)? -------------- next part -------------- An HTML attachment was scrubbed... URL: From cgelinek at radlogic.com.au Thu Aug 4 00:25:37 2011 From: cgelinek at radlogic.com.au (Christian Gelinek) Date: Thu, 4 Aug 2011 13:55:37 +0930 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? Message-ID: <001201cc525e$8f834510$ae89cf30$@com.au> Hi all, I have a problem running some python program using version 2.6.4 (or version 2.7.2, I tried both) from the Win7 command line - it never finishes due to an infinite loop. The thing is, when I run the same program through Cygwin which uses Python version 2.6.5, it exits the loop at some point. I came to try this after I realised that in some of the sources (it is a rather big program using many source files, most of them being created by others from a Linux environment), the indentation is mixed tabs/spaces where the assumed tab size is 8 spaces. Reading on the Python website, a tab size of 8 is default anyway, so I would have assumed it should work... does that mean that one tab equals 2 indents?!? I myself never use tabs to indent Python code but let my editor do a tab-to-4-spaces conversion when I press . I find it at least confusing to read that Python expects a tab size of 8 but at the same time uses 4 spaces for one indent level. Or maybe I am completely on the wron track here? Any ideas on how to get the thing to run under (real) Windows, hopefully without having to edit existing sources of people who left our company ages ago? From clp2 at rebertia.com Thu Aug 4 00:38:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Aug 2011 21:38:34 -0700 Subject: python module to determine if a machine is idle/free In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 9:06 PM, Danny Wong (dannwong) wrote: > Hi all, > > ??????????????? I have 5 server machines that are using to process > information. I would like to write a quick server python script that > determines which of the machines are not in use. Any recommendations on > which python module I should use to detect if a machine is not performing > idle (ex. Some specific task is not running)? Yes, psutil: http://code.google.com/p/psutil/ os.getloadavg() may or may not also be useful to you: http://docs.python.org/library/os.html#os.getloadavg Cheers, Chris From thorsten at thorstenkampe.de Thu Aug 4 01:18:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 4 Aug 2011 07:18:50 +0200 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? References: Message-ID: * Christian Gelinek (Thu, 4 Aug 2011 13:55:37 +0930) > Any ideas on how to get the thing to run under (real) Windows, > hopefully without having to edit existing sources of people who left > our company ages ago? python -t "Issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. Issue an error when the option is given twice." Thorsten From stefan_ml at behnel.de Thu Aug 4 02:00:37 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Aug 2011 08:00:37 +0200 Subject: making my extensions work together In-Reply-To: References: Message-ID: Mathew, 04.08.2011 03:19: > This isn't exactly a Python question but maybe someone here has run into > this. > > I have 2 extensions With "extensions", I assume you mean extension modules for the CPython runtime that are written in C? It would help if you were more specific in your problem description. > and they both access a function in a (static) library. It would help if you mentioned the names of the modules (or packages) and of the external library. > The function maintains state information using a static variable. That's bad design, but it happens. > This doesn't work. When one of my extensions changes the variable value, the > other extension does not see the change. Are the two modules linked in any way or are they just arbitrary modules that happen to be installed at the same time, trying to use the same external C library? If the former, consider letting them communicate with each other by making one depend on the other. If you control the source code, you may also consider wrapping the library only once and reusing that from the two modules. Or, just move the configuration part into a separate module and have both depend on that. Or, try to dump the dependency on the static variable. If the latter, then, well, it depends on several environmental factors that you left out in your question. > Would it work if I made my library dynamic? That's usually a good idea, but it's unlikely to help in this specific case. > This is on Windows XP compiling with MSVC 2008. Others will know more here. Stefan From k.sahithi2862 at gmail.com Thu Aug 4 02:46:05 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 3 Aug 2011 23:46:05 -0700 (PDT) Subject: SOUTH ACTRESS HOT PHOTOS Message-ID: <22f206b4-68e5-483f-94a6-77108dad9110@y19g2000pre.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From rosuav at gmail.com Thu Aug 4 02:59:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 07:59:07 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano wrote: > ? ? ? ?a, b = divmod(n, i) > ? ? ? ?if b == 0: > ? ? ? ? ? ?total += a+i > Wouldn't this fail on squares? It happens to give correct results as far as I've checked; no square up to 10,000 is called perfect, and there are no perfect squares in that range, but I think it's technically using an incorrect intermediate result. ChrisA From clp2 at rebertia.com Thu Aug 4 03:08:29 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 00:08:29 -0700 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? In-Reply-To: <001201cc525e$8f834510$ae89cf30$@com.au> References: <001201cc525e$8f834510$ae89cf30$@com.au> Message-ID: On Wed, Aug 3, 2011 at 9:25 PM, Christian Gelinek wrote: > Hi all, > > I have a problem running some python program using version 2.6.4 (or version > 2.7.2, I tried both) from the Win7 command line - it never finishes due to > an infinite loop. The thing is, when I run the same program through Cygwin > which uses Python version 2.6.5, it exits the loop at some point. > > I came to try this after I realised that in some of the sources (it is a > rather big program using many source files, most of them being created by > others from a Linux environment), the indentation is mixed tabs/spaces where > the assumed tab size is 8 spaces. That's just plain evil. > Reading on the Python website, a tab size of 8 is default anyway, so I would > have assumed it should work... does that mean that one tab equals 2 > indents?!? I myself never use tabs to indent Python code but let my editor > do a tab-to-4-spaces conversion when I press . > > I find it at least confusing to read that Python expects a tab size of 8 but > at the same time uses 4 spaces for one indent level. Or maybe I am > completely on the wron track here? 4-space indents are /recommended/ by PEP 8, but the interpreter does not require or prefer that style. What the interpreter does when parsing indentation is rather more complicated; see http://docs.python.org/reference/lexical_analysis.html#indentation You might wanna look at tabnanny: http://docs.python.org/library/tabnanny.html Cheers, Chris From rosuav at gmail.com Thu Aug 4 03:08:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 08:08:59 +0100 Subject: making my extensions work together In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. If your extensions are DLLs and they're both linking to the same static library, you should have two independent copies of that library - which would mean they don't interfere with one another. That's why the other extension doesn't see the change, and normally this is the correct and desired behaviour. Having the two be aware of each other is potentially very messy. As Stefan suggested, making one depend on the other would be a lot simpler. Alternatively, there may be ways to have the two extensions share data through Python itself. What are you looking to accomplish? ChrisA From ericsnowcurrently at gmail.com Thu Aug 4 03:49:39 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 4 Aug 2011 01:49:39 -0600 Subject: finding the object corresponding to a stack frame Message-ID: For any given stack frame, the corresponding code object is derived most immediately from either a module [definition], a class definition, or function definition. I want to be able to determine the specific module, class, or function object for any arbitrary code/frame object. For modules it is pretty straightforward. For classes, the object doesn't exist yet, but I can work around that. Lastly, for functions it is not nearly as simple as I had hoped. If the function is defined in the global namespace then the solution is relatively trivial, using the inspect module: def get_context(): frame = inspect.currentframe().f_back if frame.f_code.co_name == "": return sys.modules[frame.f_locals["__name__"]] return frame.f_globals.get(frame.f_code.co_name) def f(): context = get_context() f() However, under other conditions it is not so easy: - the function is nested inside another, - the code object is shared between multiple functions, - the function is accessed as an attribute of some other object and thus is not bound by its name in the easy search namespaces (like globals), - others? I'm trying to see if there is a way to work through these issues. It would be great if objects knew under which object each was defined, but that is a bigger question for another time. Right now I would just settle for a frame object knowing the object for which it is running, particularly for functions. However, judging by similar questions found while researching this, I'm not holding my breath. Any ideas? -eric From astley.lejasper at gmail.com Thu Aug 4 03:54:26 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 09:54:26 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Thanks for those suggestions. I tried something last night before I got your ideas. 1. I added a line to send a copy of the report just to me, 2 lines before the line where it emails the report to all the recipients. 2. I also added a timer.sleep(5) pause just before the line that emails the reports to all the recipients. So the order was: a) Send the full report just to me .... FAILED. b) Pause for 5 seconds. c) Send the full report to all 4 recipients ... WORKED. d) Send the log file just to me ... WORKED. So ... what looks like may be happening is that something might still be locking the file. In which case i'll try again without the test email to me. And/or perhaps send a test email without the attachment before the main report to see if that gets through, to see if the connection with gmail is actually really connected. See also below... > 1) You might see if there's something about the size of the message - is it > bigger after collecting data all night?? Is google disconnecting after a > maximum amount of data is transferred? I don't think so. The test message I mentioned above got through and the attachment was identical (320kb or abouts) > 2) You might try sending a tiny test message at the beginning, just to > yourself, and seeing if that has the problem As above. > 3) You might try running your script under a system call tracer: > http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html > - and inspecting the list of syscalls and their return codes near when the > process terminates Ouch. Looks complicated! ;-) > 4) I get disconnects from gmail once in a while too, especially when > downloading a large list of new message headers; I've been just coding > around it by making my code idempotent and otherwise restartable.? This > seems to happen with both 2.x and 3.x, so I assume it's not really related > to the Python version, but I suppose I should try it on PyPy or Jython > someday.? Note that the error message in 3.x was better than in 2.x. I was thinking that perhaps I could put a loop in that tests if the email goes through, and if not, pauses for a few seconds and then tries again. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 04:10:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 10:10:48 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 03.08.2011 19:27 schrieb Chris Rebert: >> shell= True, > > I would strongly encourage you to avoid shell=True. ACK, but not because it is hard, but because it is unnecessary and unelegant at this point. > You really don't want to have to worry about doing proper shell escaping yourself. That's nothing to really worry about - just doing def shellquote(*strs): return " ".join([ "'"+st.replace("'","'\\''")+"'" for st in strs ]) would do perfectly: shellquote('echo', "'", '"', " ", "\n") If you emit a command line over ssh, for example, you don't have another simple choice. There are only worries if there is a shell which better shouldn't be named like this. As you generally cannot know what ugly things the user of your program does, it is better to avoid the additional shell layer. So generally agree to what you say, but it is not the proper shell escaping one should worry about (it is so simple that one cannot call it "worry"), but the type of shell one talks with. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 04:24:08 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 10:24:08 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 03.08.2011 17:29 schrieb Phlip: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. Well, at first, I cannot see the real point about it... > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) > > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() > if not l: break > yield l > > line.s = s > > return line I find it quite ugly. You get a function object with an attached generator (which has a strange and non-verbose name and) which might stop too early due to an empty line. Plus, you have no real control over the communication; you have no access to stdin or stderr. The latter might produce a lock if the process writes out too much on stderr. Plus, you have no access to the exit code of the program. And you lose information about if the stream ends with any combination of whitespace. > That leads to some syntactic sugar. For example, one truly demented > way to stream in an entire block and then treat it as one big string > is this: > > print '\n'.join(command('ls').s()) What would work as well via print Popen( ['ls'], stdout= subprocess.PIPE).stdout.read() or print Popen( ['ls'], stdout= subprocess.PIPE).communicate()[0] > The point of the command() complex is the ability to start a long > command and then fetch out individual lines from it: > > line = command('find', '../..') sp = Popen( ['find', '../..'], stdout= subprocess.PIPE).stdout.read() line = sp.stdout.readline # if you want so: line = lambda: sp.stdout.readline().rstrip() - which # might lose information as well... > print 'lines' > print line() > print line() > print line() > > print 'all' > print list(line.s()) print list(iter(line, '')) Thomas From clp2 at rebertia.com Thu Aug 4 04:42:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 01:42:34 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On Thu, Aug 4, 2011 at 1:10 AM, Thomas Rachel wrote: > Am 03.08.2011 19:27 schrieb Chris Rebert: > >>> ? ? ? ? ? ? ? ? ? ? shell= True, >> >> I would strongly encourage you to avoid shell=True. > > ACK, but not because it is hard, but because it is unnecessary and unelegant > at this point. > >> You really don't want to have to worry about doing proper shell escaping >> yourself. > > That's nothing to really worry about - just doing > > def shellquote(*strs): > ? ? ? ?return " ".join([ > ? ? ? ? ? ? ? ?"'"+st.replace("'","'\\''")+"'" > ? ? ? ? ? ? ? ?for st in strs > ? ? ? ?]) > > would do perfectly: shellquote('echo', "'", '"', " ", "\n") I was considering the more general case where one of the strings may have come from user input. You then need to also escape $looks_like_a_var, `some_command`, and way more other such stuff that your simple function doesn't cover. Even if the user is trusted, not escaping such things can still lead to bizarre unintended output/results. If the commands are completely static, then yes, I agree that lack of necessity then becomes the main argument against shell=True. Cheers, Chris -- http://rebertia.com From astley.lejasper at gmail.com Thu Aug 4 05:24:01 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 11:24:01 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Just to add a little bit to the mix, I have started having these problems since I rebuilt my machine (Xubuntu 11) and I changed the disc formats to ext4 without even thinking about it ... I was wondering if maybe that had something to do with it? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 05:25:51 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 11:25:51 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 04.08.2011 10:42 schrieb Chris Rebert: > I was considering the more general case where one of the strings may > have come from user input. You then need to also escape > $looks_like_a_var, `some_command`, and way more other such stuff that > your simple function doesn't cover. Even these things are harmless when included in ''s. $ echo '`rm -rf .`' '$RANDOM' `rm -rf .` $RANDOM Thomas From 1248283536 at qq.com Thu Aug 4 05:39:53 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 4 Aug 2011 17:39:53 +0800 Subject: ImportError: No module named PyQt4.QtGui Message-ID: i have installed such things: sudo apt-get install libqt4-dev sudo apt-get install g++ automake sudo apt-get install qt4-dev-tools qt4-designer qt4-doc sudo apt-get install libqt4-opengl-dev sudo apt-get install libqt4-sql-mysql libqt4-sql-odbc libqt4-sql-psql libqt4-sql-sqlite libqt4-sql-sqlite2 when i finished,input >>>from PyQt4.QtCore import * Traceback (most recent call last): File "", line 1, in ImportError: No module named PyQt4.QtCore would you mind to tell me how to solve it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Thu Aug 4 05:56:06 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 04 Aug 2011 11:56:06 +0200 Subject: ImportError: No module named PyQt4.QtGui In-Reply-To: References: Message-ID: <4E3A6CB6.30804@jollybox.de> On 04/08/11 11:39, ???? wrote: > i have installed such things: > > sudo apt-get install libqt4-dev > sudo apt-get install g++ automake > sudo apt-get install qt4-dev-tools qt4-designer qt4-doc > sudo apt-get install libqt4-opengl-dev > sudo apt-get install libqt4-sql-mysql libqt4-sql-odbc libqt4-sql-psql > libqt4-sql-sqlite libqt4-sql-sqlite2 > > when i finished,input >>>>from PyQt4.QtCore import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named PyQt4.QtCore > > would you mind to tell me how to solve it? > > http://lmgtfy.com/?q=debian+pyqt4 You haven't actually installed the python-qt4 bindings yet. All you installed is the C++ library. From steve+comp.lang.python at pearwood.info Thu Aug 4 05:56:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 19:56:41 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3a6cda$0$29995$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano > wrote: >> a, b = divmod(n, i) >> if b == 0: >> total += a+i >> > > Wouldn't this fail on squares? It happens to give correct results as > far as I've checked; no square up to 10,000 is called perfect, and > there are no perfect squares in that range, but I think it's > technically using an incorrect intermediate result. Yes, you're correct -- it counts sqrt(n) twice as a factor if n is a perfect square. The obvious fix is to change the increment to: total += a if a==i else a+i I don't believe it actually makes a difference for perfect numbers, but it's worth getting right. -- Steven From gelonida at gmail.com Thu Aug 4 06:04:27 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 04 Aug 2011 12:04:27 +0200 Subject: PIL question. having exactly same font on multiple platforms Message-ID: I posted already a question, but perhaps the subject line wasn't clear. Subject line was "Text to image with same results on any platform" >From within a django application I'd like create a small image file (e.g. .png) which just contains some text. I wondered what library would be appropriate and would yield the same result independent of the OS (assuming the versions of the python libraries are the same) Images should be pixel identical independent on the platform on which the image is created. I made some attempts with PIL (Image / ImageFont / ImageDraw), but have difficulties getting the same font under Linux and windows. # ------------------------code starts here import Image import ImageFont import ImageDraw # Here I don't know how to get the same font file # for all platforms # Perhaps there is a tiny trick that I overlooked. font_file = get_font_file_name() # Is truetype a good choice for portable fonts? font = ImageFont.truetype(font_file, 20) img = Image.new("RGB", (800, 600), "#FFFFFF") draw = ImageDraw.Draw(image) draw.text( (100, 100), font=font, fill="#00FF00") # ---------------------------- end of code I could also install any other library (matplotlib??) if it were capable of creating consistent images independent on the platform. Thanks in advance for any suggestions. From t at jollybox.de Thu Aug 4 06:32:00 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 04 Aug 2011 12:32:00 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: References: Message-ID: <4E3A7520.3030609@jollybox.de> On 04/08/11 12:04, Gelonida N wrote: > I posted already a question, but perhaps the subject line wasn't clear. > > > Subject line was "Text to image with same results on any platform" > Oh, your original message was perfectly clear, and if I knew the answer, I might have responded. Anyway, into thought. > >>From within a django application > I'd like create a small image file (e.g. .png) > which just contains some text. > > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. > > I made some attempts with PIL (Image / ImageFont / ImageDraw), > but have difficulties getting the same font under Linux and windows. Perhaps PIL uses a different font rendering library on each platform? You could try to get around this by using http://code.google.com/p/freetype-py/ directly. It's also possible that different hinting settings on the different systems are playing a role somehow, somewhere. Perhaps you can tell freetype precisely what to do, I'm not sure. If you want exactly the same bitmap on different platforms, you could just scrap truetype alltogether, and use bitmaps directly, individually taking the characters you need from a resource file. (you know, one bitmap with all the characters at known coordinates - or a load of small bitmaps) Why do you need the images to be identical to the pixel anyway? Surely, if it's about comparing the text, you would just compare the strings? And if it's only for displaying the text, then why bother with details like that as long as it looks good? - Thomas From steve+comp.lang.python at pearwood.info Thu Aug 4 08:37:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 22:37:27 +1000 Subject: PIL question. having exactly same font on multiple platforms References: Message-ID: <4e3a9288$0$29980$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. Short answer: you can't. Long answer: you might, if you can find identical fonts (not just fonts with the same name, but genuinely identical) for each platform, and find some way of telling each platform's font rendering software to use identical algorithms (e.g. kerning, hinting, scaling, sub-pixel rendering), and adjust for any other differences between platforms (e.g. font sizes on Windows tend to be larger than on Mac or Linux). And when I say "you might", I mean it is theoretically possibly, but practically speaking, you can't. Even longer answer: you can, if you ignore the platform font renderer, and use your own custom renderer; this is what (apparently) a number of Linux/Unix applications like Abiword and xpdf do (with varying levels of success). You still need to find identical fonts for each platform. Possibly the simplest way to do this is to stick to old-fashioned bitmapped fonts in fixed sizes, instead of Postscript or TrueType fonts -- assuming you don't mind your application's output looking like it was produced on a Macintosh in 1984. More information here: https://freddie.witherden.org/pages/font-rasterisation/ http://www.joelonsoftware.com/items/2007/06/12.html http://www.codinghorror.com/blog/2007/06/whats-wrong-with-apples-font-rendering.html http://jujusoft.com/?page_id=25 -- Steven From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Thu Aug 4 08:43:35 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Thu, 04 Aug 2011 08:43:35 -0400 Subject: PyWhich Message-ID: Hey c.l.p., I wrote a little python script that finds the file that a python module came from. Does anyone see anything wrong with this script? #!/usr/bin/python import sys if __name__ == '__main__': if len(sys.argv) > 1: try: m = __import__(sys.argv[1]) sys.stdout.write(m.__file__ + '\n') sys.stdout.flush() sys.exit(0) except ImportError: sys.stderr.write("No such module '%s'\n" % sys.argv[1]) sys.stderr.flush() sys.exit(1) else: sys.stderr.write("Usage: pywhich \n") sys.stderr.flush() sys.exit(0) -- Bill From myeates at jpl.nasa.gov Thu Aug 4 09:48:11 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 4 Aug 2011 06:48:11 -0700 Subject: making my extensions work together References: Message-ID: more info. I have a large 3rd party library with a function that looks like this void dumbfunc() { static int statevar=0; ++statevar; if (startvar ==3) printf("I have been called 3 times\n"); } and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make calls to dumbfunc. In creating the extensions, I linked to the 3rd party library. The behavior I want to see is >foo.dumbfunc() >goo.dumbfunc() >goo.dumbfunc() I have been called 3 times "Chris Angelico" wrote in message news:mailman.1880.1312441742.1164.python-list at python.org... > On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: >> I have 2 extensions and they both access a function in a (static) >> library. >> The function maintains state information using a static variable. > > If your extensions are DLLs and they're both linking to the same > static library, you should have two independent copies of that library > - which would mean they don't interfere with one another. That's why > the other extension doesn't see the change, and normally this is the > correct and desired behaviour. > > Having the two be aware of each other is potentially very messy. As > Stefan suggested, making one depend on the other would be a lot > simpler. Alternatively, there may be ways to have the two extensions > share data through Python itself. What are you looking to accomplish? > > ChrisA From benjamin.d.garrett at lmco.com Thu Aug 4 10:01:01 2011 From: benjamin.d.garrett at lmco.com (Garrett, Benjamin D) Date: Thu, 04 Aug 2011 10:01:01 -0400 Subject: python glibc issue Message-ID: Hi, I am running into a problem with Python 2.6 and SuSe 11 SP1. The error message looks just like this one: https://bugzilla.redhat.com/show_bug.cgi?id=556584 That link implies the fix is to upgrade to > glibc-2.11.90. But for this particular hardware, it would be difficult to upgrade the core operating system's glibc as novell hasn't blessed a version of glibc > 2.11.1. Also, using an upgraded dynamic/shared version of glibc seems to produce incompatibilities with core operating systems commands. So, is it possible to build python against a static version of glibc? I've tried installing a static glibc 2.12 on a different machine, then configuring python with 'configure -disable-shared --with-libc=/usr/lib64/libc_nonshared.a'. python builds but an ldd still seems to think the resulting executable depends on libc.so.6. I've tried google but found nothing concrete. Any other suggestions or comments would be greatly appreciated. Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From myeates at jpl.nasa.gov Thu Aug 4 10:04:39 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 4 Aug 2011 07:04:39 -0700 Subject: making my extensions work together References: Message-ID: okay. It worked to make my 3'rd party library dynamic. Hopefully this will help someone else in the future. "Mathew" wrote in message news:j1cs2t$j2f$1 at news.jpl.nasa.gov... > This isn't exactly a Python question but maybe someone here has run into > this. > > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. > > This doesn't work. When one of my extensions changes the variable value, > the other extension does not see the change. > > Would it work if I made my library dynamic? > > This is on Windows XP compiling with MSVC 2008. > > -Mathew > From katriel at katriel.co.uk Thu Aug 4 10:18:38 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Thu, 4 Aug 2011 15:18:38 +0100 Subject: making my extensions work together In-Reply-To: References: Message-ID: Wrap your 3rd party library with a Python interface module, and run all calls from foo and goo through your interface. On Thu, Aug 4, 2011 at 2:48 PM, Mathew wrote: > more info. I have a large 3rd party library with a function that looks > like > this > void dumbfunc() { > static int statevar=0; > ++statevar; > if (startvar ==3) printf("I have been called 3 times\n"); > } > > and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make > calls to dumbfunc. In creating the extensions, I linked to the 3rd party > library. > > The behavior I want to see is > >foo.dumbfunc() > >goo.dumbfunc() > >goo.dumbfunc() > I have been called 3 times > > > "Chris Angelico" wrote in message > news:mailman.1880.1312441742.1164.python-list at python.org... > > On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: > >> I have 2 extensions and they both access a function in a (static) > >> library. > >> The function maintains state information using a static variable. > > > > If your extensions are DLLs and they're both linking to the same > > static library, you should have two independent copies of that library > > - which would mean they don't interfere with one another. That's why > > the other extension doesn't see the change, and normally this is the > > correct and desired behaviour. > > > > Having the two be aware of each other is potentially very messy. As > > Stefan suggested, making one depend on the other would be a lot > > simpler. Alternatively, there may be ways to have the two extensions > > share data through Python itself. What are you looking to accomplish? > > > > ChrisA > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpjday at crashcourse.ca Thu Aug 4 11:28:09 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 4 Aug 2011 11:28:09 -0400 (EDT) Subject: error compiling python, and "plat-linux2" versus "plat-linux3" Message-ID: i may have asked about this once upon a time but i'm still fighting with it so i'll throw myself on the mercy of the list and ask again. (and if there's a better forum for this question, let me know.) i'm using the development environment wind river linux 4.2 (hereafter just "WRL") to configure and build an entire embedded system, and that build is failing when it comes to compile python-2.6.2. i *think* i have an idea what the general problem is, but i need help to narrow it down. here's the tail end of the build process: ===== begin snippet ===== Checking for unpackaged file(s): /home/rpjday/WindRiver/projects/42/glibc_std/host-cross/bin/../lib64/rpm/check-files /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2 error: Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen RPM build errors: File not found: /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2/usr/lib64/python2.6/plat-linux2 Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:2661: *** [python.install] Error 1 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:3017: *** [python.buildlogger] Error 2 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/Makefile.common.epilogue:37: *** [all] Error 2 GNUmakefile:55: *** [all] Error 2 #0 all at /home/rpjday/WindRiver/projects/42/glibc_std/build/GNUmakefile:55 remake[2]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std/build' Command-line arguments: "all" Makefile:831: *** [all-recursive] Error 1 #0 all-recursive at /home/rpjday/WindRiver/projects/42/glibc_std/Makefile:831 remake[1]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std' Command-line arguments: "all-recursive" make: *** [all] Error 2 ===== end snippet ===== note the references to "plat-linux3" above -- i think that's what's killing me as i'm doing all this on a ubuntu 11.04 system with my own hand-rolled 3.x kernel and i think there's a step in the python build process that can't handle a running kernel with version "3.*". this is my suspicion as i've already found another location in the WRL build that clearly never imagined it would be run on a 3.x kernel (it recognized only "2.x" kernels as a hardcoded value.) another reason i think it's something like this is if i run just the prep step -- that is, untar the python-2.6.2 tarball and apply the WRL patches -- here's what i get in the resulting directory: $ grep -r plat-linux2 * Doc/install/index.rst: ['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2', Doc/install/index.rst:'/www/python/lib/pythonX.Y/plat-linux2', ...]``. Misc/RPM/python-2.6.spec:%{__prefix}/%{libdirname}/python%{libvers}/plat-linux2 Misc/HISTORY: * Lib/plat-sunos5/CDIO.py, Lib/plat-linux2/CDROM.py: Misc/HISTORY:e.g. lib-tk, lib-stdwin, plat-win, plat-linux2, plat-sunos5, dos-8x3. $ as you can see, it's all *hardcoded* references to "plat-linux2" so it's a mystery as to where the references to "plat-linux3" are coming from during the build process, which is why i suspect the reason i gave above -- that nothing took into account that this build would be done on a 3.x kernel. can anyone shed light on this? can anyone else *try* this on a system with a 3.x kernel and let me know what they get? i'm about to just hack the source and change that to "plat-linux3" to see what happens, but it would be nice to do something more intelligent. thanks. rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From shilparani9030 at gmail.com Thu Aug 4 12:30:20 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Thu, 4 Aug 2011 09:30:20 -0700 (PDT) Subject: ADULT HOT PICS Message-ID: <707e8c3e-f337-430c-9597-876599f8db8b@f17g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html MAHESH BABU WORKING STILLS IN DHOOKUDU http://princemaheshfanz.blogspot.com/2011/08/dookudu-working-stills.html NAMRATHA IN NATIONAL BREAST FEEDING http://princemaheshfanz.blogspot.com/2011/08/namrata-shirodkar-at-national-breast.html From ethan at stoneleaf.us Thu Aug 4 13:04:48 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 10:04:48 -0700 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: <4E3AD130.6070704@stoneleaf.us> Steve Holden wrote: > We would ideally like the last project to to be something that > demonstrates at least some minimal involvement with the Python > community. Something like "get a Python answer upvoted on > StackOverflow", for example, or getting a question answered on c.l.p. At > the same time it shouldn't be anything that places a burden on the > community (otherwise the hundredth student would be abused and the > thousandth murdered). The problem I see with either of those is making the student's academic standing dependent on the actions of strangers. Having said that... Posting a question to c.l.py is fine if you have a real question, but if you don't... Of the two, I like the StackOverflow option better -- but keep in mind that at this moment, about 6,600 unanswered Python questions remain. (I've made it to page 23 of 132 over the last week.) Getting an answer upvoted can be pretty hit-and-miss. Perhaps the thing to do is have a wide range of options, any one of which will satisfy the requirement -- some will have questions to post, others may have a bug to file or, even better, a patch for a bug, others can go the StackOverflow route, someone may have a module to put on PyPI, etc., etc. Hope this helps! ~Ethan~ From sparkytwobillion at gmail.com Thu Aug 4 13:19:36 2011 From: sparkytwobillion at gmail.com (sparky gmail) Date: Thu, 04 Aug 2011 10:19:36 -0700 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: <4E3AD4A8.8020607@gmail.com> On 8/3/2011 8:14 PM, Steve Holden wrote: > [Ccs appreciated] > > After some three years labor I (@holdenweb) at last find myself > approaching the completion of the Python Certificate Series with > O'Reilly School of Technology (@OReillySchool). > > At OSCON last week the team fell to talking about the final assignment > (although the Certificate is not a certification, students only > progress by answering real quiz questions, not the usual > multiple-choice task). Success also requires that they complete a > project at the end of each (of the ~60) lesson(s). > > We would ideally like the last project to to be something that > demonstrates at least some minimal involvement with the Python > community. Something like "get a Python answer upvoted on > StackOverflow", for example, or getting a question answered on c.l.p. > At the same time it shouldn't be anything that places a burden on the > community (otherwise the hundredth student would be abused and the > thousandth murdered). > > So I wondered if anyone had any good ideas. > > regards > Steve > -- > Steve Holden > steve at holdenweb.com > > > Just a thought. What about contributing code or documentation to an established project? I dislike the idea of getting an answer up voted. First of all, for people trying to do it honestly you are putting their completion into the hands of strangers, secondly, it would be very easy to cheat by having someone else, or themselves with a puppet account, up vote the answer. There are a metric grip of established projects that could use a little help with documentation, code examples, etc. I think this is a better route to community participation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Aug 4 13:22:43 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 10:22:43 -0700 Subject: PyWhich In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 5:43 AM, Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module came > from. ?Does anyone see anything wrong with this script? > > > #!/usr/bin/python > > import sys > if __name__ == '__main__': > ? ?if len(sys.argv) > 1: > ? ? ? ?try: > ? ? ? ? ? ?m = __import__(sys.argv[1]) > ? ? ? ? ? ?sys.stdout.write(m.__file__ + '\n') > ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ?sys.exit(0) > ? ? ? ?except ImportError: > ? ? ? ? ? ?sys.stderr.write("No such module '%s'\n" % sys.argv[1]) > ? ? ? ? ? ?sys.stderr.flush() > ? ? ? ? ? ?sys.exit(1) > ? ?else: > ? ? ? ?sys.stderr.write("Usage: pywhich \n") > ? ? ? ?sys.stderr.flush() > ? ? ? ?sys.exit(0) Nothing wrong per se, but the flush()es seem unnecessary, and why do stdout.write() when you can just print()? Cheers, Chris -- I can't not think of the pitchman when I read your posts... http://rebertia.com From python.list at tim.thechases.com Thu Aug 4 14:24:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Aug 2011 13:24:13 -0500 Subject: PyWhich In-Reply-To: References: Message-ID: <4E3AE3CD.6020906@tim.thechases.com> On 08/04/2011 07:43 AM, Billy Mays wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module > came from. Does anyone see anything wrong with this script? > > #!/usr/bin/python > > import sys > if __name__ == '__main__': > if len(sys.argv)> 1: > try: > m = __import__(sys.argv[1]) > sys.stdout.write(m.__file__ + '\n') For a quick script in a controlled environment, not bad. In a hostile environment, I'd be nervous about running arbitrary module code triggered by the import. Even if non-malicious, some imports (like PyCrypto) may have some initialization lag which would be nice to avoid. I think I'd make use of imp.find_module to write it something like this (untested) from sys import argv, stderr import imp type_map = { imp.PY_SOURCE: "Source file", imp.PY_COMPILED: "Compiled code object", imp.C_EXTENSION: "Dynamically loadabld shared library", imp.PKG_DIRECTORY: "Package directory", imp.C_BUILTIN: "Built-in", imp.PY_FROZEN: "Frozen module", } if __name__ == '__main__': if len(argv) > 1: for modname in argv[1:]: try: fp, pth, desc = imp.find_module(modname) (suffix, mode, type_) = desc if fp is not None: fp.close() print("%s\t[%s]" % ( pth, type_map.get(type_, "UNKNOWN") )) except ImportError: stderr.write("No such module '%s'\n" % modname) else: stderr.write("Usage: pywhich [...]\n") I don't know a good way to tap into other import hooks (such as the zipfile import) to augment that type_map dictionary. -tkc From nephish at gmail.com Thu Aug 4 14:26:23 2011 From: nephish at gmail.com (nephish) Date: Thu, 4 Aug 2011 11:26:23 -0700 (PDT) Subject: problem with bcd and a number Message-ID: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both bytes are BCD-encoded, with the LSB containing digits zX and MSB containing digits xy. The system speed is then xyz%, where 100% means maximum speed and would be given by bytes 00(LSB) 10(MSB)." that is a quote from the documentation. Anyway, i am able to parse out the two bytes i need, but don't know where to go from there. thanks for any tips on this. From nephish at gmail.com Thu Aug 4 14:31:22 2011 From: nephish at gmail.com (nephish) Date: Thu, 4 Aug 2011 11:31:22 -0700 (PDT) Subject: problem with bcd and a number Message-ID: Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both bytes are BCD-encoded, with the LSB containing digits zX and MSB containing digits xy. The system speed is then xyz%, where 100% means maximum speed and would be given by bytes 00(LSB) 10(MSB)." that is a quote from the documentation. Anyway, i am able to parse out the two bytes i need, but don't know where to go from there. thanks for any tips on this. From gelonida at gmail.com Thu Aug 4 14:54:47 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 04 Aug 2011 20:54:47 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4E3A7520.3030609@jollybox.de> References: <4E3A7520.3030609@jollybox.de> Message-ID: On 08/04/2011 12:32 PM, Thomas Jollans wrote: > On 04/08/11 12:04, Gelonida N wrote: Thanks for your answer. >> >From within a django application >> I'd like create a small image file (e.g. .png) >> which just contains some text. >> >> I wondered what library would be appropriate and would yield the same >> result independent of the OS (assuming the versions of the python >> libraries are the same) >> Images should be pixel identical independent on the platform on which >> the image is created. >> >> I made some attempts with PIL (Image / ImageFont / ImageDraw), >> but have difficulties getting the same font under Linux and windows. > > Perhaps PIL uses a different font rendering library on each platform? > You could try to get around this by using > http://code.google.com/p/freetype-py/ directly. It's also possible that > different hinting settings on the different systems are playing a role > somehow, somewhere. Perhaps you can tell freetype precisely what to do, > I'm not sure. The reason why I want the images to look identical is very simple. Though the final web server will run on a linux server, I use sometimes windows for development or as test server. For automated tests I would have liked pixel identical images. this allows calculating the md5sum of images to know whether a regression in the image layout occured. Well I can live without it. The second (more import issue) is, that the images should look the same whether created on a Windows or Linux host. I didn't know that PIL delegated font rendering to the underlying OS, but thought it contains its own rendering. Here the problem is not if a few pixels are different, but currently I even don't know how to choose a font, and make sure it exists on both platforms. I also don't know how I can write portable python code, that will find a given font on windows and on linux independent of the exact font location. > > If you want exactly the same bitmap on different platforms, you could > just scrap truetype alltogether, and use bitmaps directly, individually > taking the characters you need from a resource file. (you know, one > bitmap with all the characters at known coordinates - or a load of small > bitmaps) A resource file or a bitmapped font packaged with my application might be a solution. I just had to learn where to get one from or how to create one without any copyright issues > > Why do you need the images to be identical to the pixel anyway? Surely, > if it's about comparing the text, you would just compare the strings? > And if it's only for displaying the text, then why bother with details > like that as long as it looks good? I hope I clarified a little what I was looking for. It's not necessarily pixel true, but it should not be too visible whether the image was rendered on a windows or linux PC From davea at ieee.org Thu Aug 4 15:28:58 2011 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Aug 2011 15:28:58 -0400 Subject: problem with bcd and a number In-Reply-To: References: Message-ID: <4E3AF2FA.7000207@ieee.org> On 01/-10/-28163 02:59 PM, nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. > Your problem is simply to extract the two nibbles from a byte. Then you can use trivial arithmetic to combine the nibbles. Error checking is another matter. First you need to specify whether this is Python 2.x or Python 3.x. In this message I'll assume 2.7 >>> val = "\x47" >>> print val G >>> print ord(val) 71 >>> print ord(val)/16 4 >>> print ord(val)%16 7 >>> DaveA From irmen.NOSPAM at xs4all.nl Thu Aug 4 15:30:59 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Aug 2011 21:30:59 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: References: <4E3A7520.3030609@jollybox.de> Message-ID: <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> On 4-8-2011 20:54, Gelonida N wrote: > The reason why I want the images to look identical is very simple. > Though the final web server will run on a linux server, I use sometimes > windows for development or as test server. > > For automated tests I would have liked pixel identical images. > this allows calculating the md5sum of images to know whether > a regression in the image layout occured. Well I can live without it. Then don't run your automated tests on the dev server but deploy your stuff to a separate test server first, that runs the same software as production. And run the tests there. > The second (more import issue) is, that the images should look the same > whether created on a Windows or Linux host. > > I didn't know that PIL delegated font rendering to the underlying OS, > but thought it contains its own rendering. I'm pretty sure it does have that indeed; it links with the freetype library. Are you sure you're not just seeing differences because of differences in the typeface itself? A courier.ttf on one system can look very different from a ms-courier-new.ttf on another... > Here the problem is not if a few pixels are different, but currently I > even don't know how to choose a font, and make sure it exists on both > platforms. I also don't know how I can write portable python code, that > will find a given font on windows and on linux independent of the exact > font location. I once made a module that uses PIL to draw captcha images. It uses one of the free truetype font files that I just place next to the code. I downloaded the ttf files from http://www.fontgirl.com/ but there are dozens of free font sites. Just be sure to check the license terms of the the typeface files. As far as I know, I did not see any difference in output on windows, linux and mac os x as long as the code used the same ttf file and PIL versions. (but I'll double check now and see if I remember this correctly). Irmen From ch at radamanthys.de Thu Aug 4 15:31:19 2011 From: ch at radamanthys.de (Christoph Hansen) Date: Thu, 04 Aug 2011 21:31:19 +0200 Subject: problem with bcd and a number In-Reply-To: References: Message-ID: nephish schrieb: > thanks for any tips on this. I'll try. In BCD a (decimal) digit is stored in a halfbyte (or a 'nibble'). So, in a byte you can store two decimal digits. For instance 42 would be nibble1 nibble2 0100 0010 4 2 >>> c=0b01000010 >>> c 66 >>> c >> 4 # first nibble 4 >>> c & 0b1111 # second nibble 2 So, a speed of 57% should be LSB= 0111 0000 MSB= 0000 0101 From python at mrabarnett.plus.com Thu Aug 4 15:35:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Aug 2011 20:35:18 +0100 Subject: problem with bcd and a number In-Reply-To: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <4E3AF476.9050502@mrabarnett.plus.com> On 04/08/2011 19:26, nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. The value is MSB * 100 + (LSB >> 4) * 10 + (LSB & 0xF) From ethan at stoneleaf.us Thu Aug 4 15:44:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 12:44:41 -0700 Subject: problem with bcd and a number In-Reply-To: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <4E3AF6A9.3090004@stoneleaf.us> nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. As I recall, when you cut a byte in half you get two nibbles. You need to translate your nibbles into numbers, then multiply and add -- something like this: 8<--- bcd.py ---------------------------------------------------------- def bcd_to_int(msb, lsb): """msb has two decimal digits, lsb has one e.g. msb has xy=10, lsb has zX = 00, actual number (xyz) is 100""" ones = lsb >> 4 tens = msb & 0x0f hundreds = msb >> 4 if ones > 9 or tens > 9 or hundreds > 9: raise ValueError( "invalid BCD digits in %02x %02x" % (msb, lsb) ) tens *= 10 hundreds *= 100 answer = hundreds + tens + ones return answer if __name__ == '__main__': import unittest class Test_BCD(unittest.TestCase): def test_valid(self): msb = 0x09 lsb = 0x34 # 4 will be discarded as garbage self.assertEqual(bcd_to_int(msb, lsb), 93) def test_invalid(self): msb = 0x1a lsb = 0x10 self.assertRaises(ValueError, bcd_to_int, msb, lsb) unittest.main() 8<--------------------------------------------------------------------- Hope this helps. ~Ethan~ From nospam at torek.net Thu Aug 4 15:49:44 2011 From: nospam at torek.net (Chris Torek) Date: 4 Aug 2011 19:49:44 GMT Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: >Chris Angelico wrote: [snippage] >> def func(x): >> len = len # localize len >> for i in x: >> len(i) # use it exactly as you otherwise would In article <4e39a6b5$0$29973$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >That can't work. The problem is that because len is assigned to in the body >of the function, the Python compiler treats it as a local variable. So the >line len=len is interpreted as len = len, which doesn't yet >exist. There's no way of saying len = len in the body of the >function. > >So you must either: > >(1) use a different name: length = len > >(2) use a fully-qualified name: import builtins; len = builtins.len (This is my preferred form, given what one has now, if one is going to do this in the function body. Of course in 2.x it is spelled __builtin__.len instead...) >(3) do the assignment as a default parameter, which has slightly different >binding rules: def func(x, len=len) > >(4) manual lookup: len = builtins.__dict__['len'] # untested > > >I don't recommend that last one, unless you're deliberately trying to write >obfuscated code :) If Python *were* to have some kind of "tie this symbol down now" operation / keyword / whatever, one could write: def func(x): snap len # here the new keyword is "snap" for i in x: ... len(i) ... # use it exactly as you otherwise would Of course there is no *need* for any new syntax with the other construction: def func(x, len=len) # snapshots "len" at def() time for i in x: ... len(i) ... but if one were to add it, it might look like: def func(x, snap len): The advantage (?) of something like a snap or snapshot or whatever keyword / magic-function / whatever is that you can apply it to more than just function names, e.g.: def func(arg): # for this example, assume that arg needs to have the # following attributes: snap arg.kloniblatt, arg.frinkle, arg.tippy ... Here, in the "..." section, a compiler (whether byte-code, or JIT, or whatever -- JIT makes the most sense in this case) could grab the attributes, looking up their types and any associated stuff it wants to, and then assume that for the rest of that function's execution, those are not allowed to change. (But other arg.whatever items are, here. If you want to bind *everything*, perhaps "snap arg" or "snap arg.*" -- see below.) Even a traditional (CPython) byte-code compiler could do something sort of clever here, by making those attributes "read-only" to whatever extent the snapshot operation is defined as fixing the binding (e.g., does it recurse into sub-attributes? does it bind only the name-and-type, or does it bind name-and-type-and-value, or name-and-type-and-function-address-if-function, or ... -- all of which has to be pinned down before any such suggestion is taken too seriously :-) ). -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ch at radamanthys.de Thu Aug 4 15:52:45 2011 From: ch at radamanthys.de (Christoph Hansen) Date: Thu, 04 Aug 2011 21:52:45 +0200 Subject: problem with bcd and a number In-Reply-To: References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: MRAB schrieb: > The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) i would say (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) but who knows From ethan at stoneleaf.us Thu Aug 4 16:14:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 13:14:18 -0700 Subject: problem with bcd and a number In-Reply-To: <4E3AF476.9050502@mrabarnett.plus.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> <4E3AF476.9050502@mrabarnett.plus.com> Message-ID: <4E3AFD9A.6060403@stoneleaf.us> MRAB wrote: > On 04/08/2011 19:26, nephish wrote: >> Hey all, >> >> I have been trying to get my head around how to do something, but i am >> missing how to pull it off. >> I am reading a packet from a radio over a serial port. >> >> i have " two bytes containing the value i need. The first byte is the >> LSB, second is MSB. Both bytes are BCD-encoded, with the LSB >> containing digits zX and MSB containing digits xy. The system speed >> is then xyz%, where 100% means maximum speed and would be given by >> bytes 00(LSB) 10(MSB)." >> >> that is a quote from the documentation. >> Anyway, i am able to parse out the two bytes i need, but don't know >> where to go from there. >> >> thanks for any tips on this. > > The value is MSB * 100 + (LSB >> 4) * 10 + (LSB & 0xF) Not according to the docs -- msb has two digits, lsb has one and garbage. ~Ethan~ From irmen.NOSPAM at xs4all.nl Thu Aug 4 16:24:54 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Aug 2011 22:24:54 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> References: <4E3A7520.3030609@jollybox.de> <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> On 4-8-2011 21:30, Irmen de Jong wrote: > As far as I know, I did not see any difference in output on windows, linux and mac os x > as long as the code used the same ttf file and PIL versions. (but I'll double check now > and see if I remember this correctly). To follow up on myself, I've just tested it with the same ttf file on windows, os x and linux. (made an image in font size 40 with 'The quick brown fox....' as text line) The resulting image files were byte-identical between os x and linux but the windows ones were slightly different (just by a few bytes). The text in the image itself looked identical though to the ones from the other systems (I couldn't see any difference by looking at it) so I presume the difference is in the image compression or file header metadata. PIL's font rendering seems to produce identical results across platforms and if you see a difference it must be caused by a difference in typeface file (or perhaps a different PIL/freetype version on the platform). Irmen From rhodri at wildebst.demon.co.uk Thu Aug 4 17:31:47 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 04 Aug 2011 22:31:47 +0100 Subject: Community Involvement References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Thu, 04 Aug 2011 18:04:48 +0100, Ethan Furman wrote: > Of the two, I like the StackOverflow option better -- but keep in mind > that at this moment, about 6,600 unanswered Python questions remain. > (I've made it to page 23 of 132 over the last week.) Getting an answer > upvoted can be pretty hit-and-miss. The other thing that may affect this is that anything posted to SE is subject to the Creative Commons license. This may be an issue for academic purposes, I don't know. (It's certainly an issue when you come across J*ff!) -- Rhodri James *-* Wildebeest Herder to the Masses From nobody at nowhere.com Thu Aug 4 17:35:02 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Aug 2011 22:35:02 +0100 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? References: Message-ID: On Thu, 04 Aug 2011 13:55:37 +0930, Christian Gelinek wrote: > I find it at least confusing to read that Python expects a tab size of 8 but > at the same time uses 4 spaces for one indent level. Or maybe I am > completely on the wron track here? 4-column indents are a convention, not a rule. You can use however many columns you like, and you don't even need to be consistent about it; you can use 2 columns for one "block" and 4 columns for another. Python only cares about "indented more than the previous line" and "indented to a depth matching an outer level of the code". 8-column tab stops are a rule, due to it being such a long-standing convention that some software and hardware has 8-column tab stops hardwired (and anything which allows tab stops to be configured normally defaults to 8 columns). > Any ideas on how to get the thing to run under (real) Windows, hopefully > without having to edit existing sources of people who left our company ages > ago? The only time you'll have problems is if you copy-and-paste code which was written using a mix of tabs and spaces and which assumed a different tab width. If code only ever uses tabs, the tab width doesn't matter. If code uses a mix of tabs and spaces and it actually works, it's correct according to Python's 8-column tab stops, even if that's not how the programmer's editor was set up. Also, copying blocks of code which start and end at the top-level (i.e. without indentation) will work regardless. Where it fails is if you copy indented code from e.g. a file which used a mix of spaces and 4-column tabs into a file which uses 8-column tabs. If you have existing code which uses a mix of tabs and spaces where tabs aren't 8 columns (or you aren't sure that they're 8 columns), your best bet is to reformat the code to avoid using tabs (on Unix: "pr -t -e", or "pr -t -e4" for 4-column tabs). From ericsnowcurrently at gmail.com Thu Aug 4 17:42:22 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 4 Aug 2011 15:42:22 -0600 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Wed, Aug 3, 2011 at 9:14 PM, Steve Holden wrote: > [Ccs appreciated] > After some three years labor I (@holdenweb) at last find myself approaching > the completion of the Python Certificate Series with O'Reilly School of > Technology (@OReillySchool). > At OSCON last week the team fell to talking about the final assignment > (although the Certificate is not a certification, students only progress by > answering real quiz questions, not the usual multiple-choice task). Success > also requires that they complete a project at the end of each (of the ~60) > lesson(s). > We would ideally like the last project to to be something that demonstrates > at least some minimal involvement with the Python community. Something like > "get a Python answer upvoted on StackOverflow", for example, or getting a > question answered on c.l.p. At the same time it shouldn't be anything that > places a burden on the community (otherwise the hundredth student would be > abused and the thousandth murdered). > So I wondered if anyone had any good ideas. While not as "community" as the mailing lists, perhaps they could post a recipe to the activestate. -eric > regards > ?Steve > -- > Steve Holden > steve at holdenweb.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From drsalists at gmail.com Thu Aug 4 19:24:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 4 Aug 2011 16:24:13 -0700 Subject: PyWhich In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 10:22 AM, Chris Rebert wrote: > > > #!/usr/bin/python > > > > import sys > > if __name__ == '__main__': > > if len(sys.argv) > 1: > > try: > > m = __import__(sys.argv[1]) > > sys.stdout.write(m.__file__ + '\n') > > sys.stdout.flush() > > sys.exit(0) > > except ImportError: > > sys.stderr.write("No such module '%s'\n" % sys.argv[1]) > > sys.stderr.flush() > > sys.exit(1) > > else: > > sys.stderr.write("Usage: pywhich \n") > > sys.stderr.flush() > > sys.exit(0) > > Nothing wrong per se, but the flush()es seem unnecessary, and why do > stdout.write() when you can just print()? > The flushes are unnecessary, but sys.stdout.write has an advantage over print: sys.stdout.write works pretty much the same in both 2.x and 3.x; print doesn't. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peterirbizon at gmail.com Thu Aug 4 19:26:59 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Fri, 5 Aug 2011 01:26:59 +0200 Subject: HSeparator() in gtk.layour Message-ID: hello, how can I add hseparator to gtk.layout? I tried hseparator = gtk.HSeparator() self.layout.put(hseparator, 50, 195) but it does not work :/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Thu Aug 4 19:37:04 2011 From: gelonida at gmail.com (Gelonida N) Date: Fri, 05 Aug 2011 01:37:04 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> References: <4E3A7520.3030609@jollybox.de> <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> Message-ID: Thanks again to everybody, Your answers helped me to understand better. My pragmatic solution is now to package my program with an open source .ttf font, which will be used on both platforms. On 08/04/2011 10:24 PM, Irmen de Jong wrote: > On 4-8-2011 21:30, Irmen de Jong wrote: > >> As far as I know, I did not see any difference in output on windows, linux and mac os x >> as long as the code used the same ttf file and PIL versions. (but I'll double check now >> and see if I remember this correctly). > > To follow up on myself, I've just tested it with the same ttf file on windows, os x and > linux. (made an image in font size 40 with 'The quick brown fox....' as text line) The > resulting image files were byte-identical between os x and linux but the windows ones > were slightly different (just by a few bytes). The text in the image itself looked > identical though to the ones from the other systems (I couldn't see any difference by > looking at it) so I presume the difference is in the image compression or file header > metadata. > > PIL's font rendering seems to produce identical results across platforms and if you see > a difference it must be caused by a difference in typeface file (or perhaps a different > PIL/freetype version on the platform). > What I finally did was following: I copied a ttf font whoose copyright seems to be permissive ('Vera.ttf') from my linux machine to my windows host. I wrote following script: import Image import ImageFont, ImageDraw import ImageChops im = Image.new( "RGB", (250,60) , "#000000" ) draw = ImageDraw.Draw(im) font = ImageFont.truetype("Vera.ttf", 40) draw.text((5, 5), "Hello world", font=font) im.save("img.png") im = Image.open('img.png') iml = Image.open('img_other.png') diff = ImageChops.difference(im, iml) diff.save('diff.png') and ran it on one machine then I copied the generated file img.png to my other platform and renamed it to img_other.png then I ran my script there and displayed diff.png What I see (but I do not have the same version of PIL on both machines) is, that the images are different, though the difference as rather local and not too huge. So copying an open source ttf font to my windows machine creates fonts, which are from an optical aspect similair enough. I will still check whether the imgaes are identical if using the same font file and the same PIL version. THis should clarify whether the OS is involved in rendering the images or not. If really wanted to run automated tests verifying the image result I could still do it by saving the md5sums for both platforms and veryfing whether the result is identical to one of them. From gelonida at gmail.com Thu Aug 4 19:56:26 2011 From: gelonida at gmail.com (Gelonida N) Date: Fri, 05 Aug 2011 01:56:26 +0200 Subject: Text to image with same results on any platform In-Reply-To: References: Message-ID: Just FYI. Thread continued in thread with the subject line 'PIL question. having exactly same font on multiple platforms' I'm currently not pixel true, but images are sufficiently similiar. On 08/03/2011 11:40 AM, Gelonida N wrote: > Hi, > > >>From within a django application > I'd like create a small image file (e.g. .png) > which just contains some text. > > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. > > I made some attempts with PIL (Image / ImageFont / ImageDraw), > but have difficulties getting the same font under Linux and windows. > > From shawn at skrite.net Thu Aug 4 20:15:46 2011 From: shawn at skrite.net (shawn bright) Date: Thu, 4 Aug 2011 19:15:46 -0500 Subject: problem with bcd and a number In-Reply-To: <4E3AF2FA.7000207@ieee.org> References: <4E3AF2FA.7000207@ieee.org> Message-ID: Thanks for your help on this, gents. Got it working now. shawn On Thu, Aug 4, 2011 at 2:28 PM, Dave Angel wrote: > nibbles from a byte -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Aug 4 20:34:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 10:34:56 +1000 Subject: PyWhich References: Message-ID: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module > came from. Does anyone see anything wrong with this script? Yes -- the most screamingly obvious question has to be, why are you writing directly to sys.stdout instead of just using print? > #!/usr/bin/python I believe the recommended, platform independent hash-bang line is #!/usr/bin/which python > import sys > if __name__ == '__main__': > if len(sys.argv) > 1: > try: > m = __import__(sys.argv[1]) The major risk here is whether or not you trust the module enough to import it and run arbitrary code. The alternative would be a lot more work: you would have to duplicate the logic of the import statement, search the PYTHONPATH, look for packages, inside zip files, etc. > sys.stdout.write(m.__file__ + '\n') Built-in modules don't have a __file__ attribute. The most obvious example: >>> import builtins # spelled __builtin__ in Python 2.x >>> builtins.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' Also, __file__ is not always entirely honest. In Python 3, module.__file__ may report a .py file when it is actually loaded from a .pyc file, even if the .py file doesn't exist. So if you care about the distinction between .py, .pyc, .pyo etc. files, looking at __file__ alone will be inadequate. > except ImportError: > sys.stderr.write("No such module '%s'\n" % sys.argv[1]) That's not a given -- it may be that the module exists, but importing fails for some other reason. I would recommend not catching ImportError at all, and just let the standard Python error handling print the traceback. Especially for a tool aimed at programmers (who else would be interested in PyWhich?), hiding useful diagnostic errors and replacing them with a generic, and potentially wrong, message, is very bad. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 4 20:40:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 10:40:08 +1000 Subject: with statement and context managers References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3b3be9$0$29989$c3e8da3$5496439d@news.astraweb.com> Thomas Rachel wrote: > Am 03.08.2011 04:15 schrieb Steven D'Aprano: [...] > > but to me that looks badly wrong. Surely the spam context manager > > object will exit after the first iteration, and always raise an > > exception on the second? But I don't quite understand context > > managers enough to be sure. > > Depends on the implementation. As already stated, a > contextlib.contextmanager will only run once. But it is easy to turn it > into a persistent one - which internally initializes as often as needed. Thanks, that's exactly the sort of information I was after. Thank you to everyone who answered. -- Steven From drsalists at gmail.com Thu Aug 4 20:40:51 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 4 Aug 2011 17:40:51 -0700 Subject: problem with bcd and a number In-Reply-To: References: <4E3AF2FA.7000207@ieee.org> Message-ID: It sounds like you have what you need, but here's an amusing way of dealing with a BCD byte: >>> print int(hex(0x72).replace('0x', '')) 72 On Thu, Aug 4, 2011 at 5:15 PM, shawn bright wrote: > Thanks for your help on this, gents. Got it working now. > shawn > > On Thu, Aug 4, 2011 at 2:28 PM, Dave Angel wrote: > >> nibbles from a byte > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Aug 4 21:04:15 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Aug 2011 20:04:15 -0500 Subject: PyWhich In-Reply-To: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E3B418F.3050906@tim.thechases.com> On 08/04/2011 07:34 PM, Steven D'Aprano wrote: > Billy Mays wrote: >> #!/usr/bin/python > > I believe the recommended, platform independent hash-bang line is > > #!/usr/bin/which python I think you mean #!/usr/bin/env python -tkc From tjreedy at udel.edu Thu Aug 4 21:21:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Aug 2011 21:21:09 -0400 Subject: error compiling python, and "plat-linux2" versus "plat-linux3" In-Reply-To: References: Message-ID: There has been some discussion about what to do with 'linux3'. See http://bugs.python.org/issue12326 for example. -- Terry Jan Reedy From steve at holdenweb.com Thu Aug 4 21:46:28 2011 From: steve at holdenweb.com (Steve Holden) Date: Thu, 4 Aug 2011 21:46:28 -0400 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: Haven't had much Cc input so far, but this one is definitely worth following up on. Thanks! regards Steve On Aug 4, 2011, at 5:42 PM, Eric Snow wrote: > On Wed, Aug 3, 2011 at 9:14 PM, Steve Holden wrote: >> [Ccs appreciated] >> After some three years labor I (@holdenweb) at last find myself approaching >> the completion of the Python Certificate Series with O'Reilly School of >> Technology (@OReillySchool). >> At OSCON last week the team fell to talking about the final assignment >> (although the Certificate is not a certification, students only progress by >> answering real quiz questions, not the usual multiple-choice task). Success >> also requires that they complete a project at the end of each (of the ~60) >> lesson(s). >> We would ideally like the last project to to be something that demonstrates >> at least some minimal involvement with the Python community. Something like >> "get a Python answer upvoted on StackOverflow", for example, or getting a >> question answered on c.l.p. At the same time it shouldn't be anything that >> places a burden on the community (otherwise the hundredth student would be >> abused and the thousandth murdered). >> So I wondered if anyone had any good ideas. > > While not as "community" as the mailing lists, perhaps they could post > a recipe to the activestate. > > -eric > >> regards >> Steve >> -- >> Steve Holden >> steve at holdenweb.com >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> -- Steve Holden steve at holdenweb.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 4 22:03:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 03:03:39 +0100 Subject: PyWhich In-Reply-To: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano wrote: > Especially for a tool aimed at programmers (who else would be interested in > PyWhich?) The use that first springs to my mind is debugging import paths etc. If you have multiple pythons installed and aren't sure that they're finding the right modules, you could fire up PyWhich on an innocuous module like math or sys, and see if it's loading it from the right path. People doing this might not necessarily be programmers, they might be sysadmins; but you're right that it's most likely this will be used by competent Python programmers. ChrisA From jdriselvato at gmail.com Thu Aug 4 23:25:33 2011 From: jdriselvato at gmail.com (John Riselvato) Date: Thu, 4 Aug 2011 23:25:33 -0400 Subject: JSON Strict Mode Message-ID: I am working on a license verification script. I am rather new to the concept and to JSON files in general. This is what my pseudocode looks like: licenses = meta['license'] > for x in licenses: > if licenses[x]['terms'] is not valid opensource license > if in strict mode > raise nonfree exception > > How would i go about checking if its in "strick mode" and what does "raise nonfree exception" mean? -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Aug 5 02:19:44 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 23:19:44 -0700 Subject: JSON Strict Mode In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 8:25 PM, John Riselvato wrote: > I am working on a license?verification?script. I am rather new to the > concept and to JSON files in general. Based on your questions, reading a programming tutorial might be a good idea. Here's one that uses Python and that I've heard praise for: http://openbookproject.net/thinkcs/python/english3e/ The official tutorial is also worth reading: http://docs.python.org/dev/tutorial/ Once you understand Python's basic datatypes, JSON is a breeze; they are extremely similar. > This is what my pseudocode looks like: >> >> licenses = meta['license'] >> for x in licenses: >> if licenses[x]['terms'] is not valid opensource license I would probably instead write that as: for license_name, license in licenses.items(): if not is_open_source(license['terms']): # rest same as before >> if in strict mode >> raise nonfree exception > > How would i go about checking if its in "strict mode" You would have a boolean* variable somewhere indicating whether or not the program is in strict mode. Its value would presumably be set based on user input, or a configuration file, or whatever is applicable to your program; e.g.: strict = True strict = False config = parse_configuration_file() if config.strict: # whatever > and what does "raise nonfree exception" mean? I regret that the Wikipedia article on the topic of exceptions isn't too approachable. So, I'll instead refer you to the relevant section of the Python tutorial: http://docs.python.org/dev/tutorial/errors.html#errors-and-exceptions (Disclaimer: The following is oversimplified and somewhat Python-specific.) In a nutshell, an exception is type of object** used to indicate that a program has encountered an error; it contains details about the error and its cause. When a program encounters an error, it stores information about the error into a new exception object and then "raises" (using, in Python, the "raise" statement) this object so that the program can properly react to the error. By virtue of the "raise", normal execution of the program stops, and control is transferred to another part of the program which previously registered itself as being capable of handling the kind of error in question. The code in that part of the program then examines the exception object that was raised and takes appropriate action to deal with the error. If no part of the program registered itself as capable of handling the kind of error in question, a detailed error message is output and the program exits. In your specific example, the non-pseudo-code would look something like: # a declaration somewhere: class NonFreeLicenseError(ValueError): """License is not free according to the Open Source Definition.""" # ... back in the part of your code corresponding to your pseudocode: if strict: raise NonFreeLicenseError("The '%s' license is nonfree and thus impermissible." % x) As written, I have NonFreeLicenseError as a kind of ValueError. This may or may not be appropriate depending on your program; a list of built-in types of exceptions can be found at http://docs.python.org/dev/library/exceptions.html#bltin-exceptions Cheers, Chris -- http://rebertia.com * http://en.wikipedia.org/wiki/Boolean_data_type ** http://en.wikipedia.org/wiki/Object_%28computer_science%29 From ericsnowcurrently at gmail.com Fri Aug 5 03:20:24 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 01:20:24 -0600 Subject: Observations on the three pillars of Python execution Message-ID: In Python, three types of objects have special syntax and mechanics for their instantiation, during which a code object is generated: modules, classes, and functions. Each has its own role to play and the differences between them mostly reflect that. Here are some observations (based on default behavior): Object creation relative to code object creation: (M) before (C) after (F) after Object creation relative to code object execution: (M) before (C) after (F) before Object available during code object execution: (M) no (C) no (F) no Code object destiny: (M) executed once at definition time, then discarded (C) executed once at definition time, then discarded (F) not executed at definition time, stored on the function object for execution with each __call__() invocation. Execution locals is available during code object execution: (M) as globals() (C) as locals() (F) as locals() Object namespace is execution locals of code object: (M) yes (C) more or less (F) completely distinct Unique syntax: (M) 'import' statement (C) 'class' statement (F) 'def' statement Mechanism triggered by respective syntax: (M) import machinery (import.c/importlib) (C) internal, but partially exposed via metaclasses and the __build_class__ builtin (F) internal, nothing exposed Override capability: (M) complete capability through builtin __import__ and PEP 302 import hooks (C) partial capability, before code object execution through metaclass __prepare__() and after through __build_class__() and metaclass __call__(), __new__(), and __init__() (F) no capability Post instantiation modification capability: (M) yes (C) yes (F) mostly (some attributes are read-only) Mechanism to instantiate outside of respective unique syntax: (M) imp.new_module(), types.ModuleType(), type()() (C) type() (F) types.FunctionType(), type(f)() Type extensibility: (M) Not relative to 'import' syntax (by default) (C) Complete (F) No Name available during definition execution: (M) as __name__ (C) only through metaclass __prepare__() (F) through inspect.currentframe().f_code.co_name Name available on object as __name__: (M) yes (C) yes (F) yes Corrections, additions, and comment are welcome. -eric From t at jollybox.de Fri Aug 5 04:22:42 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 05 Aug 2011 10:22:42 +0200 Subject: Observations on the three pillars of Python execution In-Reply-To: References: Message-ID: <4E3BA852.9020604@jollybox.de> On 05/08/11 09:20, Eric Snow wrote: > Object available during code object execution: > (M) no > (C) no > (F) no (F) yes. cf. recursion. From silverinteract at gmail.com Fri Aug 5 05:29:07 2011 From: silverinteract at gmail.com (Silver Interactive) Date: Fri, 5 Aug 2011 14:59:07 +0530 Subject: Python - C api related - Concurrent Script Execution Message-ID: Dear All, I have developed a C++ server application which handles requests coming in from my web server. The server application is capable of handling multiple users at a time. Each user has a session object. Each user also has some variables associated with it. These variables are maintained in the c++ side as python dictionaries as they will be processed by executing scripts by the function PyRun_SimpleString() with each request. What i realised half-way through the implementation is that I will probably not be able to execute python scripts in parallel from the c++ end. Is this thinking correct? One user makes a request and the c++ code calls the python script which has to fetch information from a remote server (takes some seconds), but I cannot have other users script execution wait till this first script returns. Am i missing a point here. Please let me know if there is a way out of this as I am stuck big time. Do let me know if you require any more information. Help will be appreciated. Thanks!!! Regards Diana -------------- next part -------------- An HTML attachment was scrubbed... URL: From heniser at yahoo.com Fri Aug 5 07:29:06 2011 From: heniser at yahoo.com (Ryan) Date: Fri, 5 Aug 2011 04:29:06 -0700 (PDT) Subject: __set__ method is not called for class attribute access Message-ID: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> In the context of descriptors, the __set__ method is not called for class attribute access. __set__ is only called to set the attribute on an instance instance of the owner class to a new value, value. WHY? Is there some other mechanism for accomplishing this outcome. This subtle difference from __get__cost me some time to track down. Might think about pointing that out the documentation. class RevealAccess(object): """A data descriptor that sets and returns values normally and prints a message logging their access. """ def __init__(self, initval=None, name='var'): self.val = initval self.name = name def __get__(self, obj, objtype): print 'Retrieving', self.name return self.val def __set__(self, obj, val): print 'Updating' , self.name self.val = val class MyClass(object): x = RevealAccess(10, 'var "x"') y = 5 print MyClass.x MyClass.x = 20 print MyClass.x MyClass.x = 30 print MyClass.x Retrieving var "x" 10 20 30 I am at a lost on how to intercept class attribute sets. Can anyone help :-/ Ryan From rosuav at gmail.com Fri Aug 5 07:40:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 12:40:24 +0100 Subject: Recursive functions (was Re: Observations on the three pillars of Python execution) Message-ID: On Fri, Aug 5, 2011 at 9:22 AM, Thomas Jollans wrote: > On 05/08/11 09:20, Eric Snow wrote: >> Object available during code object execution: >> (M) no >> (C) no >> (F) no > (F) yes. > > cf. recursion. Is it? As I understand it, a Python function is not able to reference "itself" but must reference its own name. This means that assigning that function to something else stops it being recursive: ##### >>> def foo(x): print(x) if x>3: foo(x-1) >>> foo(5) 5 4 3 >>> bar=foo >>> bar(5) 5 4 3 >>> def foo(x): print("Foo",x) if x>3: foo(x-1) >>> foo(5) Foo 5 Foo 4 Foo 3 >>> bar(5) 5 Foo 4 Foo 3 ##### bar() is not a recursive function, even though foo() was and is. I've just played around with a decorator, though; this appears to work: >>> def recursive(f): l=list(f.__defaults__) l[-1]=f f.__defaults__=tuple(l) return f >>> @recursive def quux(x,quux=None): print("Quux",x) if x>3: quux(x-1) >>> foo=quux >>> def quux(x): print("Stopping.") >>> quux(5) Stopping. >>> foo(5) Quux 5 Quux 4 Quux 3 Effectively, the decorator binds the function's own self to its last default parameter, thus holding a cyclic reference (unlikely to be an issue - people won't be creating and destroying functions frequently, so GC issues shouldn't arise). The last parameter doesn't have to have the name of the function; this works with lambdas: >>> recursive(lambda x,_=None: print("Lambda",x) or (x>3 and _(x-1) or None))(5) Lambda 5 Lambda 4 Lambda 3 Yes, this is a pretty stupid example. But is this sort of decorator useful? It's not like people regularly want recursive lambdas. Chris Angelico From __peter__ at web.de Fri Aug 5 08:10:52 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 14:10:52 +0200 Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? Is there some other mechanism for > accomplishing this outcome. This subtle difference from __get__cost me > some time to track down. Might think about pointing that out the > documentation. > > > class RevealAccess(object): > """A data descriptor that sets and returns values > normally and prints a message logging their access. > """ > > def __init__(self, initval=None, name='var'): > self.val = initval > self.name = name > > def __get__(self, obj, objtype): > print 'Retrieving', self.name > return self.val > > def __set__(self, obj, val): > print 'Updating' , self.name > self.val = val > > class MyClass(object): > x = RevealAccess(10, 'var "x"') > y = 5 > > print MyClass.x > MyClass.x = 20 > print MyClass.x > MyClass.x = 30 > print MyClass.x > > Retrieving var "x" > 10 > 20 > 30 > > I am at a lost on how to intercept class attribute sets. Can anyone > help :-/ A class is just an instance of its metaclass, so you could move the descriptor into the metaclass to see the expected behaviour in the class: >>> class A: ... class __metaclass__(type): ... x = RevealAccess(10, 'var "x"') ... >>> A.x = 42 Updating var "x" >>> A.x Retrieving var "x" 42 However: >>> A().x Traceback (most recent call last): File "", line 1, in AttributeError: 'A' object has no attribute 'x' So you'd need two descriptors if you want to intercept variable access on both the instance and class level. From Johnny.Venter at zoho.com Fri Aug 5 08:15:53 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Fri, 5 Aug 2011 08:15:53 -0400 Subject: Sockets: Receiving C Struct Message-ID: New to python and would like to test network/sockets with it. I am having a problem where I have setup the following: import socket, sys, struct HOST = '1.1.1.1' PORT = 153 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) data = struct.unpack('!I',s.recv(4))[0] s.close() print data What I would like to do is take the input from the server, and store it in an array. The type of data is int. Can someone help? Thanks, Johnny -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 841 bytes Desc: This is a digitally signed message part URL: From duncan.booth at invalid.invalid Fri Aug 5 08:16:09 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Aug 2011 12:16:09 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? Is there some other mechanism for > accomplishing this outcome. This subtle difference from __get__cost me > some time to track down. Might think about pointing that out the > documentation. > > > class RevealAccess(object): > """A data descriptor that sets and returns values > normally and prints a message logging their access. > """ > > def __init__(self, initval=None, name='var'): > self.val = initval > self.name = name > > def __get__(self, obj, objtype): > print 'Retrieving', self.name > return self.val > > def __set__(self, obj, val): > print 'Updating' , self.name > self.val = val > > class MyClass(object): > x = RevealAccess(10, 'var "x"') > y = 5 > > print MyClass.x > MyClass.x = 20 > print MyClass.x > MyClass.x = 30 > print MyClass.x > > Retrieving var "x" > 10 > 20 > 30 > > I am at a lost on how to intercept class attribute sets. Can anyone > help :-/ The descriptor protocol only works when a value is being accessed or set on an instance and there is no instance attribute of that name so the value is fetched from the underlying class. Classes are instances too, so you may get some of what you want from: class MyMeta(type): x = RevealAccess(10, 'var "x"') class MyClass(object): __metaclass__ = MyMeta y = 5 >>> MyClass.x = 20 Updating var "x" >>> MyClass.x Retrieving var "x" 20 However note that if you do this you can access "x" only directly on the class not on an instance of the class: >>> MyClass().x Traceback (most recent call last): File "", line 1, in MyClass().x AttributeError: 'MyClass' object has no attribute 'x' -- Duncan Booth http://kupuguy.blogspot.com From eliben at gmail.com Fri Aug 5 08:16:37 2011 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 5 Aug 2011 15:16:37 +0300 Subject: stopping a thread with _Thread__stop Message-ID: This recipe: http://code.activestate.com/recipes/576780-timeout-for-nearly-any-callable/ Claims that a Python thread can be stopped by executing the private method "Thread._Thread__stop". I don't think this is true, since _Thread__stop doesn't really stop or kill the thread. In conformance to theory, the "timelimited" method this recipe defines leaves a thread running in the background if the function it's given is long-running (or infinite). Is there something I'm missing? Eli From __peter__ at web.de Fri Aug 5 09:00:37 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 15:00:37 +0200 Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Duncan Booth wrote: > The descriptor protocol only works when a value is being accessed or set > on an instance and there is no instance attribute of that name so the > value is fetched from the underlying class. Unlike normal class attributes a descriptor is not shaded by an instance attribute: >>> class A(object): ... def set_x(self, value): self.__dict__["x"] = value/2.0 ... def get_x(self): return self.__dict__["x"] * 2.0 ... x = property(get_x, set_x) ... >>> a = A() >>> a.x = 42 >>> a.__dict__["x"] 21.0 >>> a.x 42.0 >>> A.x = "something completely different" >>> a.x 21.0 From Johnny.Venter at zoho.com Fri Aug 5 09:05:30 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Fri, 5 Aug 2011 09:05:30 -0400 Subject: Fwd: Sockets: Receiving C Struct References: Message-ID: I was not sure if this message was sent before my membership was accepted. Please disregard if it's a duplicate. Thanks Begin forwarded message: > From: Johnny Venter > Date: August 5, 2011 8:15:53 AM EDT > To: python-list at python.org > Subject: Sockets: Receiving C Struct > > New to python and would like to test network/sockets with it. > > I am having a problem where I have setup the following: > > import socket, sys, struct > > HOST = '1.1.1.1' > PORT = 153 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) > > data = struct.unpack('!I',s.recv(4))[0] > > s.close() > > print data > > > What I would like to do is take the input from the server, and store it in an array. The type of data is int. > > Can someone help? > > > Thanks, Johnny > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 841 bytes Desc: This is a digitally signed message part URL: From steve+comp.lang.python at pearwood.info Fri Aug 5 09:51:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 23:51:16 +1000 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Tim Chase wrote: > On 08/04/2011 07:34 PM, Steven D'Aprano wrote: >> Billy Mays wrote: >>> #!/usr/bin/python >> >> I believe the recommended, platform independent hash-bang line is >> >> #!/usr/bin/which python > > I think you mean > > #!/usr/bin/env python Doh! I *always* conflate env and which. Thank you for the correction. -- Steven From mail at timgolden.me.uk Fri Aug 5 10:03:18 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 05 Aug 2011 15:03:18 +0100 Subject: PyWhich In-Reply-To: <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E3BF826.3010107@timgolden.me.uk> On 05/08/2011 14:51, Steven D'Aprano wrote: > Tim Chase wrote: > >> On 08/04/2011 07:34 PM, Steven D'Aprano wrote: >>> Billy Mays wrote: >>>> #!/usr/bin/python >>> >>> I believe the recommended, platform independent hash-bang line is >>> >>> #!/usr/bin/which python >> >> I think you mean >> >> #!/usr/bin/env python > > > Doh! I *always* conflate env and which. Thank you for the correction. And there I was thinking you were making a sly and ironic point about using a utility to find something on the path in order to run a utility which finds something on the path... TJG From nka_99 at yahoo.com Fri Aug 5 10:18:07 2011 From: nka_99 at yahoo.com (Naresh Agrawal) Date: Fri, 5 Aug 2011 07:18:07 -0700 (PDT) Subject: Hi Message-ID: <1312553887.65658.YahooMailClassic@web65714.mail.ac4.yahoo.com> Looking for a Python Developer with ????????? Database (Oracle or SQL server ) ? MUST have Capital Market Experience? - Fixed Income Market / Trading Systems? ? ????????? Java/.Net as the base development expertise Please let me know if any one is interested to work Location is NY Thanks Nick nka_99 at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Fri Aug 5 10:33:58 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 14:33:58 +0000 (UTC) Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4e3bf554$0$29976$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > Doh! I *always* conflate env and which. Thank you for the correction. Way to say "conflate"! :-) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Fri Aug 5 10:36:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:36:16 +1000 Subject: Observations on the three pillars of Python execution References: Message-ID: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > In Python, three types of objects have special syntax and mechanics > for their instantiation, during which a code object is generated: > modules, classes, and functions. I believe you are labouring under a misapprehension. Modules and classes don't generate code objects. The simplest possible module just has a name: >>> import sys >>> module = type(sys) >>> module("name") Or if you prefer to do it the "normal" way by importing from source code, the simplest source code of all is just an empty file. A module is an object with a __dict__, a __name__, and a __docstring__ which defaults to None. That's it. No code objects, unless you populate the __dict__ with functions, but it is the *functions* that have the code objects, not the module itself. The module is just a container. Classes are similar. The simplest class: class K: pass or if you prefer: >>> type('K', (), {}) Again, no code objects unless you populate the dict with functions (which get turned into methods). Again, the class object is just a container. A more complex container than modules, with a richer set of inherited behaviour, but still just a container. The signature for creating a function is very different: help(type(lambda: None)) => class function(object) | function(code, globals[, name[, argdefs[, closure]]]) | | Create a function object from a code object and a dictionary. | The optional name string overrides the name from the code object. | The optional argdefs tuple specifies the default argument values. | The optional closure tuple supplies the bindings for free variables. The simplest function I can think of: >>> co = compile('pass', '', 'single') >>> f = type(lambda: None)(co, {}) Even simpler than def f(): pass Can you see why? If you inspect a function object, you will see that it always has a code object, even if the code object does nothing but return None: >>> import dis >>> dis.dis(f.func_code) 1 0 LOAD_CONST 0 (None) 3 RETURN_VALUE There may be some other obscure built-in type that includes code objects, but I can't imagine what it would be. I feel confident in saying that functions, and functions alone, contain code. Even methods are just wrappers around functions. Even built-in functions like len don't contain code! (Or at least, their code isn't accessible from Python.) Which makes sense, if you think about it: their code is part of the Python virtual machine, not the object. -- Steven From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Fri Aug 5 10:43:49 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Fri, 05 Aug 2011 10:43:49 -0400 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/04/2011 10:03 PM, Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano > wrote: >> Especially for a tool aimed at programmers (who else would be interested in >> PyWhich?) > > The use that first springs to my mind is debugging import paths etc. > If you have multiple pythons installed and aren't sure that they're > finding the right modules, you could fire up PyWhich on an innocuous > module like math or sys, and see if it's loading it from the right > path. People doing this might not necessarily be programmers, they > might be sysadmins; but you're right that it's most likely this will > be used by competent Python programmers. > > ChrisA I am trying to do debugging. I have had some trouble with multiple python installs with virtualenv, and I was trying to see where given modules came from. I knew about the code execution, but I couldn't think of a clean way to just find out the location rather than load it. The reason I used stdout was because I was going to be using it in a tool chain where the stdout might need to be formatted for another program to read in. Thats also why I was catching ImportError since a later version of this script might need to do something special with it. This is also useful to see if python is really using the module you think it is. -- Bill From steve+comp.lang.python at pearwood.info Fri Aug 5 10:44:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:44:20 +1000 Subject: Recursive functions (was Re: Observations on the three pillars of Python execution) References: Message-ID: <4e3c01c5$0$29981$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Aug 5, 2011 at 9:22 AM, Thomas Jollans wrote: >> On 05/08/11 09:20, Eric Snow wrote: >>> Object available during code object execution: >>> (M) no >>> (C) no >>> (F) no >> (F) yes. >> >> cf. recursion. > > Is it? As I understand it, a Python function is not able to reference > "itself" but must reference its own name. That is correct. Recursion in Python is implemented simply by name lookup. > This means that assigning > that function to something else stops it being recursive: An easier way to demonstrate the process: >>> def f(x): ... print x ... if x > 0: f(x-1) ... >>> f(3) 3 2 1 0 >>> g = f >>> del f >>> g(3) 3 Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'f' is not defined -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 10:56:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:56:14 +1000 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3c048e$0$29994$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > The reason I used stdout was because I was going to be using it in a > tool chain where the stdout might need to be formatted for another > program to read in. print writes to sys.stdout unless you tell it different. >>> import sys >>> import StringIO >>> capture = StringIO.StringIO() >>> sys.stdout = capture >>> print "spam" >>> sys.stdout = sys.__stdout__ # Restore the real file. >>> capture.getvalue() 'spam\n' Syntax for printing elsewhere is ugly as sin in Python 2, but it works: >>> print >>sys.stderr, "spam" spam >>> print >>capture, "ham" >>> capture.getvalue() 'spam\nham\n' > Thats also why I was catching ImportError since a > later version of this script might need to do something special with it. Well you better also catch SyntaxError, because a later version of your script might need to do something special with it too :) Also RuntimeError, ValueError, TypeError... *wink* -- Steven From drsalists at gmail.com Fri Aug 5 11:09:09 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 08:09:09 -0700 Subject: Sockets: Receiving C Struct In-Reply-To: References: Message-ID: First, s.recv(4) is not guaranteed to always return 4 bytes. It could return 0, 1, 2, 3, or 4, wtih 4 being the most likely. To deal with this, I tend to use http://stromberg.dnsalias.org/~dstromberg/bufsock.html - but I suspect that Twisted has a way of dealing with it too. Then, to put your data into a list, just create an empty list with [] and use list_.append(integer). Or was there more to your question, like perhaps a traceback you haven't shared with us? On Fri, Aug 5, 2011 at 6:05 AM, Johnny Venter wrote: > I was not sure if this message was sent before my membership was accepted. > > Please disregard if it's a duplicate. > > Thanks > > Begin forwarded message: > > *From: *Johnny Venter > *Date: *August 5, 2011 8:15:53 AM EDT > *To: *python-list at python.org > *Subject: **Sockets: Receiving C Struct* > > New to python and would like to test network/sockets with it. > > I am having a problem where I have setup the following: > > import socket, sys, struct > > HOST = '1.1.1.1' > PORT = 153 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) > > data = struct.unpack('!I',s.recv(4))[0] > > s.close() > > print data > > > What I would like to do is take the input from the server, and store it in > an array. The type of data is int. > > Can someone help? > > > Thanks, Johnny > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From k.sahithi2862 at gmail.com Fri Aug 5 11:12:04 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 5 Aug 2011 08:12:04 -0700 (PDT) Subject: EXCLUSIVE HOT PHOTOS & VIDEOS Message-ID: <1d284fca-fd21-434a-be05-4bdd4366b958@e20g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html MAHESH BABU WORKING STILLS IN DHOOKUDU http://princemaheshfanz.blogspot.com/2011/08/dookudu-working-stills.html NAMRATHA IN NATIONAL BREAST FEEDING http://princemaheshfanz.blogspot.com/2011/08/namrata-shirodkar-at-national-breast.html From 1248283536 at qq.com Fri Aug 5 11:21:05 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 5 Aug 2011 23:21:05 +0800 Subject: scrape text from web Message-ID: python-list at python.org: hi ,everyone, i want to scrap something from http://search.dangdang.com/search_pub.php?key=python my code is : import urllib import lxml.html down='http://search.dangdang.com/search_pub.php?key=python' file=urllib.urlopen(down).read() root=lxml.html.fromstring(file) tnodes = root.xpath("//div[@class='listitem detail']//li[@class='maintitle']//a") for i,x in enumerate(tnodes): print i," ",x.get('name'),x.get('href'),x.get('onclick'),x.text,"\n" the output is : 0 p_name http://product.dangdang.com/product.aspx?product_id=20872365&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20872365_1_22591_p','','',''); None 1 p_name http://product.dangdang.com/product.aspx?product_id=20255354&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20255354_2_12605_p','','',''); None 2 p_name http://product.dangdang.com/product.aspx?product_id=20836565&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20836565_3_2361_p','','',''); None 3 p_name http://product.dangdang.com/product.aspx?product_id=21004615&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21004615_4_3387_p','','',''); None 4 p_name http://product.dangdang.com/product.aspx?product_id=21063086&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21063086_5_18815_p','','',''); None 5 pr_name http://product.dangdang.com/product.aspx?product_id=20678461&ref=search-1-pub s('click','python','01.54.04.03,01.54.06.18','','86_1_25','','','20678461_6_3967_p','','','RECO'); None 6 pr_name http://product.dangdang.com/product.aspx?product_id=20650363&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','20650363_7_62_p','','','RECO'); ????????????(?????)(?1CD)(????CD-ROM)( 7 pr_name http://product.dangdang.com/product.aspx?product_id=20767932&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','20767932_8_4475_p','','','RECO'); Binary Hacks??????100? 8 p_name http://product.dangdang.com/product.aspx?product_id=20596189&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20596189_9_639_p','','',''); None 9 p_name http://product.dangdang.com/product.aspx?product_id=20947680&ref=search-1-pub s('click','python','01.54.24.00,01.54.06.18','','86_1_25','','','20947680_10_7295_p','','',''); None 10 p_name http://product.dangdang.com/product.aspx?product_id=21050368&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','21050368_11_7039_p','','',''); None 11 p_name http://product.dangdang.com/product.aspx?product_id=20667966&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20667966_12_383_p','','',''); None 12 p_name http://product.dangdang.com/product.aspx?product_id=21022493&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21022493_13_5183_p','','',''); None 13 pr_name http://product.dangdang.com/product.aspx?product_id=479654&ref=search-1-pub s('click','python','01.54.06.08,01.54.06.18','','86_1_25','','','479654_14_2095_p','','','RECO'); Perl????????? 14 pr_name http://product.dangdang.com/product.aspx?product_id=20999855&ref=search-1-pub s('click','python','01.54.10.00','','86_1_25','','','20999855_15_6715_p','','','RECO'); ??????????????????? 15 pr_name http://product.dangdang.com/product.aspx?product_id=20696203&ref=search-1-pub s('click','python','01.54.06.08','','86_1_25','','','20696203_16_31615_p','','','RECO'); Perl??????????????Learning Perl,5/e) 16 p_name http://product.dangdang.com/product.aspx?product_id=20670643&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20670643_17_24_p','','',''); ??? 17 p_name http://product.dangdang.com/product.aspx?product_id=20362210&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20362210_18_32_p','','',''); ?? 18 p_name http://product.dangdang.com/product.aspx?product_id=9053236&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','9053236_19_4_p','','',''); ?? 19 p_name http://product.dangdang.com/product.aspx?product_id=20850780&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20850780_20_1055_p','','',''); None 20 pr_name http://product.dangdang.com/product.aspx?product_id=20449068&ref=search-1-pub s('click','python','01.54.06.08','','86_1_25','','','20449068_21_38_p','','','RECO'); ??Perl 21 p_name http://product.dangdang.com/product.aspx?product_id=21127816&ref=search-1-pub s('click','python','01.54.24.00,01.54.06.18','','86_1_25','','','21127816_22_12545_p','','',''); None 22 p_name http://product.dangdang.com/product.aspx?product_id=21107633&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21107633_23_19245_p','','',''); Hadoop??????2??????? 23 None http://bang.dangdang.com/product_redirect.php?product_id=9317290 None None 24 p_name http://product.dangdang.com/product.aspx?product_id=9317290&ref=search-1-pub s('click','python','01.54.06.06,01.49.01.11,01.54.26.00','','86_1_25','','','9317290_24_81727_p','','',''); Java??????4?? 25 p_name http://product.dangdang.com/product.aspx?product_id=20773186&ref=search-1-pub s('click','python','01.54.06.17','','86_1_25','','','20773186_25_80479_p','','',''); Android?????? the problem is x.text ,for example: 1. Python ????(?2?) what i want to get is "Python ????(?2?)",the output is None 2: ??? Python what i want to get is "???python",the output is ??? would you mind to tell me how to revise my code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 5 11:32:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 16:32:03 +0100 Subject: problem with bcd and a number In-Reply-To: References: <4E3AF2FA.7000207@ieee.org> Message-ID: On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: >>>> print int(hex(0x72).replace('0x', '')) > 72 Or simpler: int(hex(0x72)[2:]) Although if you have it as a string, you need to ord() the string. It's probably better to just do the bitwise operations though. ChrisA From __peter__ at web.de Fri Aug 5 11:52:38 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 17:52:38 +0200 Subject: problem with bcd and a number References: <4E3AF2FA.7000207@ieee.org> Message-ID: Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: >>>>> print int(hex(0x72).replace('0x', '')) >> 72 > > Or simpler: int(hex(0x72)[2:]) > > Although if you have it as a string, you need to ord() the string. Or use str.encode(): >>> int("\x72".encode("hex")) 72 >>> int("\x12\x34\x56".encode("hex")) 123456 > It's probably better to just do the bitwise operations though. From ppearson at nowhere.invalid Fri Aug 5 12:01:48 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 5 Aug 2011 16:01:48 GMT Subject: problem with bcd and a number References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <9a2ifcF1k7U1@mid.individual.net> On Thu, 04 Aug 2011 21:52:45 +0200, Christoph Hansen wrote: > MRAB schrieb: > >> The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) > > i would say > > (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) > > but who knows I concur. I think the documentation is trying to say that the low-order nibble of the LSB is garbage. -- To email me, substitute nowhere->spamcop, invalid->net. From gruszczy at gmail.com Fri Aug 5 12:14:14 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Fri, 5 Aug 2011 18:14:14 +0200 Subject: ANN: geany-pyflakes 1.0 Message-ID: Hello everyone, I have just published a small plugin for Geany IDE that adds Pyflakes error detection to the editor. If there are people using Geany for Python development I would be very grateful for opinions and suggestions. The plugin can be found here: http://code.google.com/p/geany-pyflakes/ -- Filip Gruszczy?ski From ericsnowcurrently at gmail.com Fri Aug 5 12:46:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 10:46:02 -0600 Subject: Observations on the three pillars of Python execution In-Reply-To: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano wrote: > Eric Snow wrote: > >> In Python, three types of objects have special syntax and mechanics >> for their instantiation, during which a code object is generated: >> modules, classes, and functions. > > I believe you are labouring under a misapprehension. Modules and classes > don't generate code objects. Sorry for any confusion. I was talking specifically about the their instantiation through their respective special syntax. During that process a code object is generated for each. For classes and modules the code object is executed and then discarded. I covered this explicitly in one of the observations. > > The simplest possible module just has a name: > >>>> import sys >>>> module = type(sys) >>>> module("name") > > > Or if you prefer to do it the "normal" way by importing from source code, > the simplest source code of all is just an empty file. > > A module is an object with a __dict__, a __name__, and a __docstring__ which > defaults to None. That's it. No code objects, unless you populate the > __dict__ with functions, but it is the *functions* that have the code > objects, not the module itself. The module is just a container. > > Classes are similar. The simplest class: > > class K: > ? ?pass > > or if you prefer: > >>>> type('K', (), {}) > > > > Again, no code objects unless you populate the dict with functions (which > get turned into methods). Again, the class object is just a container. A > more complex container than modules, with a richer set of inherited > behaviour, but still just a container. > > The signature for creating a function is very different: > > help(type(lambda: None)) => > > class function(object) > ?| ?function(code, globals[, name[, argdefs[, closure]]]) > ?| > ?| ?Create a function object from a code object and a dictionary. > ?| ?The optional name string overrides the name from the code object. > ?| ?The optional argdefs tuple specifies the default argument values. > ?| ?The optional closure tuple supplies the bindings for free variables. > > > The simplest function I can think of: > >>>> co = compile('pass', '', 'single') >>>> f = type(lambda: None)(co, {}) > > Even simpler than > > def f(): > ? ?pass > > Can you see why? > > If you inspect a function object, you will see that it always has a code > object, even if the code object does nothing but return None: > >>>> import dis >>>> dis.dis(f.func_code) > ?1 ? ? ? ? ? 0 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?3 RETURN_VALUE > > > There may be some other obscure built-in type that includes code objects, > but I can't imagine what it would be. I feel confident in saying that > functions, and functions alone, contain code. Even methods are just > wrappers around functions. Even built-in functions like len don't contain > code! (Or at least, their code isn't accessible from Python.) Which makes > sense, if you think about it: their code is part of the Python virtual > machine, not the object. Agreed that [non-builtin] functions are the only objects that have a code object attribute. However, they are not the only objects for which a code object is generated and executed. I've always found your frequent responses very insightful and thoughtful, Steven, and I appreciate that. In this case I can only imagine that my opening statement was unclear enough that you did not continue to read the rest, where the context of my point was more clear (I hope :). Regardless, thanks for taking a look. -eric > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From emile at fenx.com Fri Aug 5 13:15:37 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 10:15:37 -0700 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: On 8/5/2011 9:14 AM Filip Gruszczy?ski said... > Hello everyone, > > I have just published a small plugin for Geany IDE that adds Pyflakes > error detection to the editor. If there are people using Geany for > Python development I would be very grateful for opinions and > suggestions. > > The plugin can be found here: http://code.google.com/p/geany-pyflakes/ > fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and should either be gizzped or simply named geany-pyflakes-1.0.tar. However, after activating the plugin, asking geany for a new file breaks geany and it rudely closes so I'm unable to actually do anything with it. Emile From steve+comp.lang.python at pearwood.info Fri Aug 5 13:29:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 03:29:13 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano > wrote: >> Eric Snow wrote: >> >>> In Python, three types of objects have special syntax and mechanics >>> for their instantiation, during which a code object is generated: >>> modules, classes, and functions. >> >> I believe you are labouring under a misapprehension. Modules and classes >> don't generate code objects. > > Sorry for any confusion. I was talking specifically about the their > instantiation through their respective special syntax. During that > process a code object is generated for each. Do you believe that this process of generating a code object and throwing it away is a part of the Python language specification, which any compiler must do in order to call itself "Python", or a mere implementation detail? Is this documented somewhere? If it is not documented, what makes you think that it happens at all? You are writing as if it were self-evidently true, but I don't believe it is self-evident at all. I think you need to demonstrate the truth of two of those three pillars, not just take them for granted. > For classes and modules > the code object is executed and then discarded. I covered this > explicitly in one of the observations. I think your definition of "explicitly" and mine differ here. > Agreed that [non-builtin] functions are the only objects that have a > code object attribute. However, they are not the only objects for > which a code object is generated and executed. Are you talking about the fact that importing a module, class statements and function statements all involve executing a block of code? How does that differ from executing any other fragment of code? Modules are special, of course, because they can get compiled to byte-code, but I trust you're not talking about .pyc files. -- Steven From fred.sells at adventistcare.org Fri Aug 5 13:31:03 2011 From: fred.sells at adventistcare.org (Sells, Fred) Date: Fri, 5 Aug 2011 13:31:03 -0400 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: After the completion of most training courses, the students are not yet ready to make a meaningful contribution to the community. Yet your goal of getting them involved in the community is worthwhile. I would think learning to use the community as a resource to solve a problem that is not based on the standard modules would be a good one. I liked the recipe suggestion as well, but I think you would need to post a list of items to choose and remove the item when the recipe has been posted. Otherwise you could get a gazillion examples of sorting a dictionary... Just my 2 cents FWIW Fred Sells -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 5 13:51:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 18:51:51 +0100 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Fri, Aug 5, 2011 at 6:31 PM, Sells, Fred wrote: > After the completion of most training courses, the students are not yet > ready to make a meaningful contribution to the community. That's quite possibly true, but they may very well be in a position to recognize a documentation error/omission and assist, or alternatively, to triage some bugs. There are plenty of OSS projects that could do with a hand there; does it have to be Python specifically? Python's docs are pretty good, but I'm sure there will always be value in people spending time on http://bugs.python.org/ and seeing if they can reproduce the bugs. ChrisA From tundra at tundraware.com Fri Aug 5 13:53:19 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 12:53:19 -0500 Subject: Table Driven GUI Definition? Message-ID: I have a task where I want to create pretty simple one page visual interfaces (Graphical or Text, but it needs to run across Windows, Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more than option checklists and text fields. Conceptually something like: Please Select Your Installation Options: Windows Compatibility Services _ Linux Compatibility Services _ TRS-DOS Compatibility Services _ What Is Your email Address: _______________________ What I'm looking for is a way to describe such forms in a text file that can then be fed into a tool to generate the necessary pyGUI, Tkinter, (or whatever) code. The idea is that it should be simple to generate a basic interface like this and have it only record the user's input. Thereafter, the python code would act on the basis of those selection without any further connection to the GUI. An added bonus would be a similar kind of thing for generating web interfaces to do this. This might actually be a better model because then I only have to worry about a single presentation environment. Ideas anyone? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From geoffwright240 at gmail.com Fri Aug 5 14:07:54 2011 From: geoffwright240 at gmail.com (Geoff Wright) Date: Fri, 5 Aug 2011 14:07:54 -0400 Subject: Question about encoding, I need a clue ... Message-ID: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Hi, I use Mac OSX for development but deploy on a Linux server. (Platform details provided below). When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. Specifically, calendar.month_name[8] returns a ? (question mark) on the Linux server whereas it displays properly on the Mac OSX system. However, if I take the result from calendar.month_name[8] and run it through the following function .... unicode(calendar.month_name[8],"latin1") ... then the u circumflex displays correctly on the Linux server but does not display correctly on my Mac. Of course, I could work around this problem with a relatively simple if statement but these issues are going to show up all over my application so even a simple if statement will start to get cumbersome. I guess what it boils down to is that I would like to get a better handle on what is going on so that I will know how best to work through future encoding issues. Thanks in advance for any advice. Here are the specifics of my problem. On my Mac: Python 2.6.7 (r267:88850, Jul 30 2011, 23:46:53) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >>> import locale >>> locale.setlocale(locale.LC_ALL,'fr_CA') 'fr_CA' >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> import calendar >>> calendar.month_name[8] 'ao\xc3\xbbt' >>> print calendar.month_name[8] ao?t >>> print unicode(calendar.month_name[8],"latin1") ao??t On the linux server: uname -a Linux alhena 2.6.32.8-grsec-2.1.14-modsign-xeon-64 #2 SMP Sat Mar 13 00:42:43 PST 2010 x86_64 GNU/Linux Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40) [GCC 4.3.2] on linux2 >>> import locale,sys,calendar >>> locale.setlocale(locale.LC_ALL,'fr_CA') 'fr_CA' >>> sys.getdefaultencoding() 'ascii' >>> calendar.month_name[8] 'ao\xfbt' >>> print calendar.month_name[8] ao?t >>> print unicode(calendar.month_name[8],"latin1") ao?t From mwilson at the-wire.com Fri Aug 5 14:22:11 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 05 Aug 2011 14:22:11 -0400 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There may be some other obscure built-in type that includes code objects, > but I can't imagine what it would be. I feel confident in saying that > functions, and functions alone, contain code. Even methods are just > wrappers around functions. Even built-in functions like len don't contain > code! (Or at least, their code isn't accessible from Python.) Which makes > sense, if you think about it: their code is part of the Python virtual > machine, not the object. Interesting question. Iterators seem to have code objects: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = [1, 2, 3] >>> b = (x for x in a) >>> dir(b) ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'close', 'gi_code', 'gi_frame', 'gi_running', 'next', 'send', 'throw'] >>> for name in dir(b): ... print name, type (getattr (b, name)) ... __class__ __delattr__ __doc__ __format__ __getattribute__ __hash__ __init__ __iter__ __name__ __new__ __reduce__ __reduce_ex__ __repr__ __setattr__ __sizeof__ __str__ __subclasshook__ close gi_code gi_frame gi_running next send throw in the form of the gi_code attribute. No idea what it's for, although no reason to believe it shouldn't be there. (Very interesting demo you gave of primitive object creation. I' awed.) Mel. From gervaz at gmail.com Fri Aug 5 14:52:23 2011 From: gervaz at gmail.com (gervaz) Date: Fri, 5 Aug 2011 11:52:23 -0700 (PDT) Subject: Get the name of a function Message-ID: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Hi all, is there a way to retrive the function name like with self.__class__.__name__? Using self.__dict__.__name__ I've got >>> def test(): ... print(self.__dict__.__name__) ... >>> test But I really just want the function name, so 'test' Any help? Thanks, Mattia From gruszczy at gmail.com Fri Aug 5 14:58:43 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Fri, 5 Aug 2011 20:58:43 +0200 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: > fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and > should either be gizzped or simply named geany-pyflakes-1.0.tar. > > However, after activating the plugin, asking geany for a new file breaks > geany and it rudely closes so I'm unable to actually do anything with it. I have posted a gzipped version with a fix. Would you care to take a look? -- Filip Gruszczy?ski From irmen at -NOSPAM-xs4all.nl Fri Aug 5 15:05:18 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 05 Aug 2011 21:05:18 +0200 Subject: Table Driven GUI Definition? In-Reply-To: References: Message-ID: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> On 05-08-11 19:53, Tim Daneliuk wrote: > I have a task where I want to create pretty simple one page visual > interfaces (Graphical or Text, but it needs to run across Windows, > Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more > than option checklists and text fields. Conceptually something like: > > Please Select Your Installation Options: > > Windows Compatibility Services _ > Linux Compatibility Services _ > TRS-DOS Compatibility Services _ > > What Is Your email Address: _______________________ > > What I'm looking for is a way to describe such forms in a text > file that can then be fed into a tool to generate the necessary > pyGUI, Tkinter, (or whatever) code. The idea is that it should > be simple to generate a basic interface like this and have it > only record the user's input. Thereafter, the python code > would act on the basis of those selection without any further > connection to the GUI. > > An added bonus would be a similar kind of thing for generating > web interfaces to do this. This might actually be a better model > because then I only have to worry about a single presentation > environment. > > Ideas anyone? Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. Wouldn't that work? Irmen From ms419 at freezone.co.uk Fri Aug 5 15:37:21 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Fri, 05 Aug 2011 12:37:21 -0700 Subject: Replace all references to one object with references to other Message-ID: <1312573041.6831.7.camel@selene> I have two objects, and I want to replace all references to the first object - everywhere - with references to the second object. What can I try? From tundra at tundraware.com Fri Aug 5 16:10:06 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 15:10:06 -0500 Subject: Table Driven GUI Definition? In-Reply-To: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: On 8/5/2011 2:05 PM, Irmen de Jong said this: > On 05-08-11 19:53, Tim Daneliuk wrote: >> I have a task where I want to create pretty simple one page visual >> interfaces (Graphical or Text, but it needs to run across Windows, >> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >> than option checklists and text fields. Conceptually something like: >> >> Please Select Your Installation Options: >> >> Windows Compatibility Services _ >> Linux Compatibility Services _ >> TRS-DOS Compatibility Services _ >> >> What Is Your email Address: _______________________ >> >> What I'm looking for is a way to describe such forms in a text >> file that can then be fed into a tool to generate the necessary >> pyGUI, Tkinter, (or whatever) code. The idea is that it should >> be simple to generate a basic interface like this and have it >> only record the user's input. Thereafter, the python code >> would act on the basis of those selection without any further >> connection to the GUI. >> >> An added bonus would be a similar kind of thing for generating >> web interfaces to do this. This might actually be a better model >> because then I only have to worry about a single presentation >> environment. >> >> Ideas anyone? > > Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... > > You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. > > Wouldn't that work? > > > Irmen Yup, although I'd probably use a central apache instance. But I'm still curious ... is there a way to do this with a full GUI tool on a thick client? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From emile at fenx.com Fri Aug 5 16:14:31 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:14:31 -0700 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: On 8/5/2011 11:58 AM Filip Gruszczy?ski said... >> fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and >> should either be gizzped or simply named geany-pyflakes-1.0.tar. >> >> However, after activating the plugin, asking geany for a new file breaks >> geany and it rudely closes so I'm unable to actually do anything with it. > > I have posted a gzipped version with a fix. Would you care to take a look? > OK - it no longer crashes, but it doesn't appear to do anything. Is there something further I need to do to configure it? The Pyflakes tab does appear in the message window and I've created a new testpyflakes.py with code similar to your example. Also, just FYI, the plugin manager now shows the version as 1.0.1 while the tar file name indicates 1.0.2. Emile From emile at fenx.com Fri Aug 5 16:16:54 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:16:54 -0700 Subject: Table Driven GUI Definition? In-Reply-To: References: Message-ID: On 8/5/2011 10:53 AM Tim Daneliuk said... > I have a task where I want to create pretty simple one page visual > interfaces (Graphical or Text, but it needs to run across Windows, > Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more > than option checklists and text fields. I'm not happened across an automated tool exactly, but I'd look into pyjamas or pygui. Emile From emile at fenx.com Fri Aug 5 16:18:05 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:18:05 -0700 Subject: Replace all references to one object with references to other In-Reply-To: <1312573041.6831.7.camel@selene> References: <1312573041.6831.7.camel@selene> Message-ID: On 8/5/2011 12:37 PM Jack Bates said... > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? Start with a proxy to your first and have it swap in to the second? EMile From emile at fenx.com Fri Aug 5 16:19:30 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:19:30 -0700 Subject: Get the name of a function In-Reply-To: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On 8/5/2011 11:52 AM gervaz said... > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? yes, but not reliably: Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def test():pass ... >>> test.__name__ 'test' >>> b=test >>> b.__name__ 'test' >>> Emile From kwatford at gmail.com Fri Aug 5 16:25:17 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 5 Aug 2011 16:25:17 -0400 Subject: Replace all references to one object with references to other In-Reply-To: <1312573041.6831.7.camel@selene> References: <1312573041.6831.7.camel@selene> Message-ID: On Fri, Aug 5, 2011 at 3:37 PM, Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? If using PyPy instead of CPython is an option, the "thunk" object space's "become" function can apparently do this: http://doc.pypy.org/en/latest/objspace-proxies.html#the-thunk-object-space In CPython, this might be a tad difficult. At the C level, a reference to a python object is just a pointer to it. You could iterate through the entire address space looking for values that equal a particular pointer, but changing them would be dangerous, since memory isn't labeled by type - you can't tell if the memory is a pointer to your object or an important part of some other data structure. If you could narrow down what you want to accomplish, this might be easier. For instance, if all you need is to replace module-level references to the object, that can be done. From philip at semanchuk.com Fri Aug 5 16:42:30 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Aug 2011 16:42:30 -0400 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > On 8/5/2011 2:05 PM, Irmen de Jong said this: >> On 05-08-11 19:53, Tim Daneliuk wrote: >>> I have a task where I want to create pretty simple one page visual >>> interfaces (Graphical or Text, but it needs to run across Windows, >>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>> than option checklists and text fields. Conceptually something like: >>> >>> Please Select Your Installation Options: >>> >>> Windows Compatibility Services _ >>> Linux Compatibility Services _ >>> TRS-DOS Compatibility Services _ >>> >>> What Is Your email Address: _______________________ >>> >>> What I'm looking for is a way to describe such forms in a text >>> file that can then be fed into a tool to generate the necessary >>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>> be simple to generate a basic interface like this and have it >>> only record the user's input. Thereafter, the python code >>> would act on the basis of those selection without any further >>> connection to the GUI. >>> >>> An added bonus would be a similar kind of thing for generating >>> web interfaces to do this. This might actually be a better model >>> because then I only have to worry about a single presentation >>> environment. >>> >>> Ideas anyone? Hi Tim This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? Cheers Philip >> >> Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... >> >> You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. >> >> Wouldn't that work? >> >> >> Irmen > > Yup, although I'd probably use a central apache instance. But > I'm still curious ... is there a way to do this with a full > GUI tool on a thick client? > > > -- > ------------------------------------------------------------------------ > Tim Daneliuk > tundra at tundraware.com > -- > http://mail.python.org/mailman/listinfo/python-list From gordon at panix.com Fri Aug 5 16:52:15 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 20:52:15 +0000 (UTC) Subject: Replace all references to one object with references to other References: Message-ID: In Jack Bates writes: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? The simplest answer to your question is to assign object2 to object1 at the very beginning of your code, but that is a very naive solution and can easily fail based on lots of factors. What's your context: A single source file? Many source files? A live application with persistent data? What are your two objects? Do they provide an identical interface? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gordon at panix.com Fri Aug 5 16:54:20 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 20:54:20 +0000 (UTC) Subject: Replace all references to one object with references to other References: Message-ID: In John Gordon writes: > In Jack Bates writes: > > I have two objects, and I want to replace all references to the first > > object - everywhere - with references to the second object. What can I > > try? > The simplest answer to your question is to assign object2 to object1 I think I have that backwards, but the intent should be clear: object1 = object2 # many references to object1 follow, which will now reference object2 -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Fri Aug 5 16:55:54 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Aug 2011 16:55:54 -0400 Subject: Observations on the three pillars of Python execution In-Reply-To: <4E3BA852.9020604@jollybox.de> References: <4E3BA852.9020604@jollybox.de> Message-ID: On 8/5/2011 4:22 AM, Thomas Jollans wrote: > On 05/08/11 09:20, Eric Snow wrote: >> Object available during code object execution: >> (M) no >> (C) no >> (F) no > (F) yes. > > cf. recursion. Recursion only happens through runtime name resolution, not through direct access to the function or code object from within the code. -- Terry Jan Reedy From clp2 at rebertia.com Fri Aug 5 17:12:40 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 14:12:40 -0700 Subject: Question about encoding, I need a clue ... In-Reply-To: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> References: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Message-ID: On Fri, Aug 5, 2011 at 11:07 AM, Geoff Wright wrote: > Hi, > > I use Mac OSX for development but deploy on a Linux server. ?(Platform details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. ASCII can't represent a circumflex anyway, and I think the "default encoding" is distinct from the locale-set encoding, so I don't think the default encoding matters here. >?Specifically, calendar.month_name[8] returns a ? (question mark) on the Linux server whereas it displays properly on the Mac OSX system. ?However, if I take the result from calendar.month_name[8] and run it through the following function .... unicode(calendar.month_name[8],"latin1") ... then the u circumflex displays correctly on the Linux server but does not display correctly on my Mac. > > Of course, I could work around this problem with a relatively simple if statement but these issues are going to show up all over my application so even a simple if statement will start to get cumbersome. > > I guess what it boils down to is that I would like to get a better handle on what is going on so that I will know how best to work through future encoding issues. ?Thanks in advance for any advice. > > Here are the specifics of my problem. > > On my Mac: > > Python 2.6.7 (r267:88850, Jul 30 2011, 23:46:53) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >>>> calendar.month_name[8] > 'ao\xc3\xbbt' >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao??t > > On the linux server: > > uname -a > Linux alhena 2.6.32.8-grsec-2.1.14-modsign-xeon-64 #2 SMP Sat Mar 13 00:42:43 PST 2010 x86_64 GNU/Linux > > Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40) > [GCC 4.3.2] on linux2 >>>> calendar.month_name[8] > 'ao\xfbt' >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao?t Some quick experimentation seems to indicate that your month names are Latin-1-encoded on Linux and UTF-8-encoded on Mac. Perhaps try using a locale that specifies a specific encoding? e.g. fr_CA.UTF-8 Cheers, Chris -- http://rebertia.com From santoso.wijaya at gmail.com Fri Aug 5 17:13:44 2011 From: santoso.wijaya at gmail.com (Santoso Wijaya) Date: Fri, 5 Aug 2011 14:13:44 -0700 Subject: ctypes LoadLibrary search path Message-ID: Hi, Can anyone enlighten me to the search path mechanism in ctypes' LoadLibrary? I have a DLL that resides elsewhere that is not in any default search path. I tried adding the path to `sys.path` before attempting to load said DLL but I still get "WindowsError: [Error 126] The specified module could not be found." Thanks, ~/santa -------------- next part -------------- An HTML attachment was scrubbed... URL: From santoso.wijaya at gmail.com Fri Aug 5 17:18:04 2011 From: santoso.wijaya at gmail.com (Santoso Wijaya) Date: Fri, 5 Aug 2011 14:18:04 -0700 Subject: ctypes LoadLibrary search path In-Reply-To: References: Message-ID: Nevermind. I figured it out (d'oh!). I had to append to `os.environ['PATH']`, not `sys.path`! ~/santa On Fri, Aug 5, 2011 at 2:13 PM, Santoso Wijaya wrote: > Hi, > > Can anyone enlighten me to the search path mechanism in ctypes' > LoadLibrary? I have a DLL that resides elsewhere that is not in any default > search path. I tried adding the path to `sys.path` before attempting to load > said DLL but I still get "WindowsError: [Error 126] The specified module > could not be found." > > Thanks, > > ~/santa > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Aug 5 17:19:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 14:19:21 -0700 Subject: Get the name of a function In-Reply-To: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On Fri, Aug 5, 2011 at 11:52 AM, gervaz wrote: > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? > > Using self.__dict__.__name__ I've got > >>>> def test(): > ... ? ? print(self.__dict__.__name__) > ... Er, where did `self` magically come from? >>>> test > > > But I really just want the function name, so 'test' > > Any help? Courtesy of the "Observations on the three pillars of Python execution" thread: from inspect import currentframe def foobar(): my_name = currentframe().f_code.co_name print(my_name) I would recommend against a function knowing its own name though, unless it's for debugging or necessary metaprogramming purposes. Cheers, Chris From invalid at invalid.invalid Fri Aug 5 18:05:45 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Aug 2011 22:05:45 +0000 (UTC) Subject: Get the name of a function References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On 2011-08-05, gervaz wrote: > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? Not really. There may not be any such thing as "the function name". A function may have zero names, it may have a dozen names. It may have names but only in namespaces that aren't accessible. This question comes up at least once a month, so look back through the group for threads about finding an object's name, finding a parameter's name, etc. Here's a nice article on introspection, but what it talks about as a "function name" probably isn't what you're interested in: http://www.ibm.com/developerworks/library/l-pyint/index.html Here's a stack-overflow question similar to yours: http://stackoverflow.com/questions/1538342/how-can-i-get-the-name-of-an-object-in-python -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From tundra at tundraware.com Fri Aug 5 18:20:16 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 17:20:16 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E3C6CA0.2000706@tundraware.com> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > >> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>> I have a task where I want to create pretty simple one page visual >>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>> than option checklists and text fields. Conceptually something like: >>>> >>>> Please Select Your Installation Options: >>>> >>>> Windows Compatibility Services _ >>>> Linux Compatibility Services _ >>>> TRS-DOS Compatibility Services _ >>>> >>>> What Is Your email Address: _______________________ >>>> >>>> What I'm looking for is a way to describe such forms in a text >>>> file that can then be fed into a tool to generate the necessary >>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>> be simple to generate a basic interface like this and have it >>>> only record the user's input. Thereafter, the python code >>>> would act on the basis of those selection without any further >>>> connection to the GUI. >>>> >>>> An added bonus would be a similar kind of thing for generating >>>> web interfaces to do this. This might actually be a better model >>>> because then I only have to worry about a single presentation >>>> environment. >>>> >>>> Ideas anyone? > > Hi Tim > This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? > > Cheers > Philip > I want to take a text definition file that looks something this: Title "Please Select Your Installation Options:" Checkbox "Windows Compatibility Services" Checkbox "Linux Compatibility Services" Checkbox "TRS-DOS Compatibility Services" Inputbox "What Is Your email Address:" And have that aut-generate the GUI interface described above for the selected GUI toolkit and/or an equivalent HTML page. I know I can write a program to do this, but it seems that someone else may have already solved this problem. Appearance isn't terribly important. I want a "Quick-And-Dirty" configuration manager interface (for configuring new operating system VMs). The reason that I want a simple text file definition is to make it easy to add new options to the display as they become available. For example, suppose it becomes possible to work with a new OS, then all I'd have to do is add the following to the text definition file, and regenerate the interface: Checkbox "MVS Compatibility Services" The idea is to not have to touch the code base as the options of the GUI evolve, but rather to modify the data file that describes it. In some sense, this is a variation of HTML templating except I want to do it (potentially) with a thick client GUI. From tundra at tundraware.com Fri Aug 5 18:20:16 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 17:20:16 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E3C6CA0.2000706@tundraware.com> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > >> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>> I have a task where I want to create pretty simple one page visual >>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>> than option checklists and text fields. Conceptually something like: >>>> >>>> Please Select Your Installation Options: >>>> >>>> Windows Compatibility Services _ >>>> Linux Compatibility Services _ >>>> TRS-DOS Compatibility Services _ >>>> >>>> What Is Your email Address: _______________________ >>>> >>>> What I'm looking for is a way to describe such forms in a text >>>> file that can then be fed into a tool to generate the necessary >>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>> be simple to generate a basic interface like this and have it >>>> only record the user's input. Thereafter, the python code >>>> would act on the basis of those selection without any further >>>> connection to the GUI. >>>> >>>> An added bonus would be a similar kind of thing for generating >>>> web interfaces to do this. This might actually be a better model >>>> because then I only have to worry about a single presentation >>>> environment. >>>> >>>> Ideas anyone? > > Hi Tim > This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? > > Cheers > Philip > I want to take a text definition file that looks something this: Title "Please Select Your Installation Options:" Checkbox "Windows Compatibility Services" Checkbox "Linux Compatibility Services" Checkbox "TRS-DOS Compatibility Services" Inputbox "What Is Your email Address:" And have that aut-generate the GUI interface described above for the selected GUI toolkit and/or an equivalent HTML page. I know I can write a program to do this, but it seems that someone else may have already solved this problem. Appearance isn't terribly important. I want a "Quick-And-Dirty" configuration manager interface (for configuring new operating system VMs). The reason that I want a simple text file definition is to make it easy to add new options to the display as they become available. For example, suppose it becomes possible to work with a new OS, then all I'd have to do is add the following to the text definition file, and regenerate the interface: Checkbox "MVS Compatibility Services" The idea is to not have to touch the code base as the options of the GUI evolve, but rather to modify the data file that describes it. In some sense, this is a variation of HTML templating except I want to do it (potentially) with a thick client GUI. From ericsnowcurrently at gmail.com Fri Aug 5 18:21:47 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 16:21:47 -0600 Subject: Observations on the three pillars of Python execution In-Reply-To: <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano wrote: > Eric Snow wrote: > >> On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano >> wrote: >>> Eric Snow wrote: >>> >>>> In Python, three types of objects have special syntax and mechanics >>>> for their instantiation, during which a code object is generated: >>>> modules, classes, and functions. >>> >>> I believe you are labouring under a misapprehension. Modules and classes >>> don't generate code objects. >> >> Sorry for any confusion. ?I was talking specifically about the their >> instantiation through their respective special syntax. ?During that >> process a code object is generated for each. > > > Do you believe that this process of generating a code object and throwing it > away is a part of the Python language specification, which any compiler > must do in order to call itself "Python", or a mere implementation detail? That's a great point which I hadn't considered. Honestly, I only used my experience with CPython in making these observations. After reviewing the language reference I see that I missed out on a bunch of nomenclature that would have made things more clear, and I got a few points wrong, which you pointed out. :) Regarding code objects and classes, your are right. The language reference indicates the following: "The class?s suite is then executed in a new execution frame...When the class?s suite finishes execution, its execution frame is discarded but its local namespace is saved." [1] So the use of code objects for execution is an implementation detail. Instead of "code object" I should have referred to the code executed in the execution frame or just to the frame. Incidently, I had not realized that the builtin __build_class__() is also an implementation detail[3]. For modules, the language reference doesn't say anything about how execution is accomplished, which only matters when execution is involved in the creation of the module object. It does refer to importlib as a reference implementation[4]. The order-of-operations observations I made are based on that reference implementation. > > Is this documented somewhere? If it is not documented, what makes you think > that it happens at all? You are writing as if it were self-evidently true, > but I don't believe it is self-evident at all. I think you need to > demonstrate the truth of two of those three pillars, not just take them for > granted. > > >> For classes and modules >> the code object is executed and then discarded. ?I covered this >> explicitly in one of the observations. > > I think your definition of "explicitly" and mine differ here. > > >> Agreed that [non-builtin] functions are the only objects that have a >> code object attribute. ?However, they are not the only objects for >> which a code object is generated and executed. > > Are you talking about the fact that importing a module, class statements and > function statements all involve executing a block of code? > > How does that differ from executing any other fragment of code? The difference is that modules, classes, and functions (really the function body) are code blocks tied to syntax that results in module, type, and function objects. There are other code blocks but none of them have a unique syntax, much less one that results in an object of the corresponding type[5]. This is relevant for trying to find the object that corresponds to an execution frame, which is what led me to my original post and drove the direction of the observations I made. Anyway, I appreciate the feedback! I'm going to have to revisit my observations with the language definition in hand. You've been really insightful, as usual. -eric [1] http://docs.python.org/dev/reference/compound_stmts.html#class-definitions [2] http://docs.python.org/dev/reference/datamodel.html#metaclasses [3] http://mail.python.org/pipermail/python-3000/2007-March/006338.html [4] http://docs.python.org/dev/reference/simple_stmts.html#the-import-statement [5] http://docs.python.org/dev/reference/executionmodel.html#naming > > Modules are special, of course, because they can get compiled to byte-code, > but I trust you're not talking about .pyc files. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From gruszczy at gmail.com Fri Aug 5 18:31:15 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sat, 6 Aug 2011 00:31:15 +0200 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: > OK - it no longer crashes, but it doesn't appear to do anything. ?Is there > something further I need to do to configure it? ?The Pyflakes tab does > appear in the message window and I've created a new testpyflakes.py with > code similar to your example. OK, so there must be something wrong. Do you have pyflakes installed? Where are they installed? > Also, just FYI, the plugin manager now shows the version as 1.0.1 while the > tar file name indicates 1.0.2. Yeah, I should make a configure file with version and use it in c code, to never make that mistake again, but I really, really don't wanto to touch autotools again. -- Filip Gruszczy?ski From philip at semanchuk.com Fri Aug 5 18:51:36 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Aug 2011 18:51:36 -0400 Subject: Table Driven GUI Definition? In-Reply-To: <4E3C6CA0.2000706@tundraware.com> References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> <4E3C6CA0.2000706@tundraware.com> Message-ID: <0B122ABE-F0A0-4F11-938F-5698FBADF7FB@semanchuk.com> On Aug 5, 2011, at 6:20 PM, Tim Daneliuk wrote: > On 8/5/2011 3:42 PM, Philip Semanchuk wrote: >> >> On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: >> >>> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>>> I have a task where I want to create pretty simple one page visual >>>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>>> than option checklists and text fields. Conceptually something like: >>>>> >>>>> Please Select Your Installation Options: >>>>> >>>>> Windows Compatibility Services _ >>>>> Linux Compatibility Services _ >>>>> TRS-DOS Compatibility Services _ >>>>> >>>>> What Is Your email Address: _______________________ >>>>> >>>>> What I'm looking for is a way to describe such forms in a text >>>>> file that can then be fed into a tool to generate the necessary >>>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>>> be simple to generate a basic interface like this and have it >>>>> only record the user's input. Thereafter, the python code >>>>> would act on the basis of those selection without any further >>>>> connection to the GUI. >>>>> >>>>> An added bonus would be a similar kind of thing for generating >>>>> web interfaces to do this. This might actually be a better model >>>>> because then I only have to worry about a single presentation >>>>> environment. >>>>> >>>>> Ideas anyone? >> >> Hi Tim >> This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? >> >> Cheers >> Philip >> > > I want to take a text definition file that looks something this: > > Title "Please Select Your Installation Options:" > > > Checkbox "Windows Compatibility Services" > Checkbox "Linux Compatibility Services" > Checkbox "TRS-DOS Compatibility Services" > > Inputbox "What Is Your email Address:" > > > And have that aut-generate the GUI interface described above for the > selected GUI toolkit and/or an equivalent HTML page. > > I know I can write a program to do this, but it seems that someone else > may have already solved this problem. Oh, I see. I didn't realize you were looking for a most canned solution. I agree that it's a problem that's been solved many times. I've used Mako before as an HTML templating engine, but ISTR that it points out that it's agnostic to what it's templating. In other words, it only cares about what's between the Mako escape tags, it doesn't care if the surrounding text is HTML or XML or Python or whatever. So you could have a Mako template that consists mostly of Python code that builds a wxPython window (if wxPython is your cup of tea) and then some Mako commands in the middle that reads your text definition file and adds checkboxes, textboxes, etc. as appropriate. It's not a canned solution, but it does allow you to separate the boilerplate stuff from the variants. Hope this helps Philip From vlastimil.brom at gmail.com Fri Aug 5 19:52:30 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 6 Aug 2011 01:52:30 +0200 Subject: Question about encoding, I need a clue ... In-Reply-To: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> References: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Message-ID: 2011/8/5 Geoff Wright : > Hi, > > I use Mac OSX for development but deploy on a Linux server. ?(Platform details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. ?... > > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I believe, sys.getdefaultencoding() isn't relevant here; you could try to determine the locale encoding via locale.getlocale() - it should return a tuple with language code and the encoding name http://docs.python.org/library/locale.html#locale.getlocale I suppose, you get the respective encodings on both of your different systems. I somehow can't find the Canadian locale on my OS (win XP, Czech), but hopefully the results are equivalent with French, I checked: cf Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import locale >>> import calendar >>> locale.setlocale(locale.LC_ALL,'French') 'French_France.1252' >>> locale.getlocale() ('fr_FR', 'cp1252') >>> calendar.month_name[8] 'ao\xfbt' >>> print calendar.month_name[8] ao?t >>> unicode(calendar.month_name[8], locale.getlocale()[1]) u'ao\xfbt' >>> print unicode(calendar.month_name[8], locale.getlocale()[1]) ao?t >>> ==== The above are the results in Idle and wx pyshell, i.e. unicode-enabled shells; on non-unicode cmd shell in windows I get: >>> print calendar.month_name[8] aout and even: >>> print unicode(calendar.month_name[8], locale.getlocale()[1]) Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\encodings\cp852.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\xfb' in position 2 : character maps to >>> hth, vbr From tundra at tundraware.com Fri Aug 5 19:57:51 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 18:57:51 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> <4E3C6CA0.2000706@tundraware.com> Message-ID: On 8/5/2011 5:51 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 6:20 PM, Tim Daneliuk wrote: > >> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: >>> >>> On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: >>> >>>> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>>>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>>>> I have a task where I want to create pretty simple one page visual >>>>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>>>> than option checklists and text fields. Conceptually something like: >>>>>> >>>>>> Please Select Your Installation Options: >>>>>> >>>>>> Windows Compatibility Services _ >>>>>> Linux Compatibility Services _ >>>>>> TRS-DOS Compatibility Services _ >>>>>> >>>>>> What Is Your email Address: _______________________ >>>>>> >>>>>> What I'm looking for is a way to describe such forms in a text >>>>>> file that can then be fed into a tool to generate the necessary >>>>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>>>> be simple to generate a basic interface like this and have it >>>>>> only record the user's input. Thereafter, the python code >>>>>> would act on the basis of those selection without any further >>>>>> connection to the GUI. >>>>>> >>>>>> An added bonus would be a similar kind of thing for generating >>>>>> web interfaces to do this. This might actually be a better model >>>>>> because then I only have to worry about a single presentation >>>>>> environment. >>>>>> >>>>>> Ideas anyone? >>> >>> Hi Tim >>> This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? >>> >>> Cheers >>> Philip >>> >> >> I want to take a text definition file that looks something this: >> >> Title "Please Select Your Installation Options:" >> >> >> Checkbox "Windows Compatibility Services" >> Checkbox "Linux Compatibility Services" >> Checkbox "TRS-DOS Compatibility Services" >> >> Inputbox "What Is Your email Address:" >> >> >> And have that aut-generate the GUI interface described above for the >> selected GUI toolkit and/or an equivalent HTML page. >> >> I know I can write a program to do this, but it seems that someone else >> may have already solved this problem. > > Oh, I see. I didn't realize you were looking for a most canned solution. I agree that it's a problem that's been solved many times. > > I've used Mako before as an HTML templating engine, but ISTR that it points out that it's agnostic to what it's templating. In other words, it only cares about what's between the Mako escape tags, it doesn't care if the surrounding text is HTML or XML or Python or whatever. > > So you could have a Mako template that consists mostly of Python code that builds a wxPython window (if wxPython is your cup of tea) and then some Mako commands in the middle that reads your text definition file and adds checkboxes, textboxes, etc. as appropriate. It's not a canned solution, but it does allow you to separate the boilerplate stuff from the variants. > > Hope this helps > Philip > Something like this is more what I had in mind (but this seems to not be actively supported????): http://pythoncard.sourceforge.net/documentation.html From steve+comp.lang.python at pearwood.info Fri Aug 5 20:57:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 10:57:41 +1000 Subject: Replace all references to one object with references to other References: Message-ID: <4e3c9186$0$29977$c3e8da3$5496439d@news.astraweb.com> Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? Another way of solving your *actual* problem. "Replace all references to object1 with object2 instead" is a means to an end, not the end itself. What are you trying to solve? Focus on *that* problem, not your supposed solution, because "replace all..." is doomed to fail. There is no "master list" of objects available to you. All you have is one or more namespaces containing objects. Many of those objects themselves will contain other objects, and so on. All you can do is walk through each namespace in turn, recursively into each object, searching for the object you want to replace. But that may not help you, because there's no guarantee that having found it you can replace it safely, *or at all*. While Python does allow code to reach deeply into the internals of a wide range of objects -- very little is truly private in Python -- do you *really* want to be taking responsibility for safely replacing objects from within arbitrary other objects? If so, Python gives you the tools to shoot yourself in the foot, although it won't necessarily be easy, or pretty, or fast. So, tell us what your real problem is, the end towards which you think "replace all..." is the solution, and we'll see if we can help. -- Steven From bigblueswope at gmail.com Fri Aug 5 21:29:01 2011 From: bigblueswope at gmail.com (BJ Swope) Date: Fri, 5 Aug 2011 21:29:01 -0400 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: The best tool to debug this is tcpdump. Running a packet capture whilst sending the mail will most likely shed the most light on the subject. -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Fri Aug 5 21:31:02 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 5 Aug 2011 18:31:02 -0700 (PDT) Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Aug 1, 5:33?pm, aliman wrote: > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. I would consider using memory mapping the file and sorting it inline. Sorting a binary file of bytes with NumPy is as easy as this: import numpy as np f = np.memmap(filename, mode='rwb', dtype=np.uint8) f.sort(kind='quicksort') del f (You can define dtype for any C data type or struct.) If the file is really big, use 64-bit Python. With memory mapping you don't have to worry about processing the file in chunks, because the operating systems will take care of those details. I am not sure how to achieve this (inline file sort) with standard library mmap and timsort, so I'll leave that out. Sturla From steve+comp.lang.python at pearwood.info Fri Aug 5 22:01:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 12:01:51 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3ca090$0$30003$c3e8da3$5496439d@news.astraweb.com> Mel wrote: > Steven D'Aprano wrote: > >> There may be some other obscure built-in type that includes code objects, >> but I can't imagine what it would be. I feel confident in saying that >> functions, and functions alone, contain code. Even methods are just >> wrappers around functions. Even built-in functions like len don't contain >> code! (Or at least, their code isn't accessible from Python.) Which makes >> sense, if you think about it: their code is part of the Python virtual >> machine, not the object. > > Interesting question. Iterators seem to have code objects: [...] Generators. But nice catch, thank you! Iterators are *any* object which obeys the iterator protocol, that is, have a next() method and an __iter__() method which behave in the expected way. Iterators are a duck-type. Generators, whether created from a generator expression or a generator function, are an actual type. >>> type(x for x in (1,2)) -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 22:05:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 12:05:01 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3ca14e$0$30003$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano > wrote: [...] >> Do you believe that this process of generating a code object and throwing >> it away is a part of the Python language specification, which any >> compiler must do in order to call itself "Python", or a mere >> implementation detail? > > That's a great point which I hadn't considered. Honestly, I only used > my experience with CPython in making these observations. After > reviewing the language reference I see that I missed out on a bunch of > nomenclature that would have made things more clear, and I got a few > points wrong, which you pointed out. :) > > Regarding code objects and classes, your are right. The language > reference indicates the following: > > "The class?s suite is then executed in a new execution frame...When > the class?s suite finishes execution, its execution frame is discarded > but its local namespace is saved." [1] It turns out that in CPython 2.5 at least, I'm strictly wrong and you got it right, at least for classes: >>> code = compile("""class K: pass""", '', 'exec') >>> dis.dis(code) 1 0 LOAD_CONST 0 ('K') 3 LOAD_CONST 3 (()) 6 LOAD_CONST 1 () 9 MAKE_FUNCTION 0 12 CALL_FUNCTION 0 15 BUILD_CLASS 16 STORE_NAME 0 (K) 19 LOAD_CONST 2 (None) 22 RETURN_VALUE So a code object is compiled, turned into a function, executed, the results turned into a class, and the code object and function thrown away. Is this an implementation detail? I would say so. The semantics of Python the language are different from the details of it's virtual machine. Surely we would be allowed to call something Python if it executed the body of the class statement *without* creating a code object first? The important part is *execute the body of the class statement*, not building the code object. The later is merely a means to an end. > So the use of code objects for execution is an implementation detail. > Instead of "code object" I should have referred to the code executed > in the execution frame or just to the frame. Unless you really intend to talk about implementation details, I think you should keep the discussion as high-level as possible. I'd talk about executing blocks of code, and not even mention execution frames unless you need to understand the role of frames during execution. -- Steven From roy at panix.com Fri Aug 5 22:54:05 2011 From: roy at panix.com (Roy Smith) Date: Fri, 05 Aug 2011 22:54:05 -0400 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Wow. I was going to suggest using the unix command-line sort utility via popen() or subprocess. My arguments were that it's written in C, has 30 years of optimizing in it, etc, etc, etc. It almost certainly has to be faster than anything you could do in Python. Then I tried the experiment. I generated a file of 1 million random integers in the range 0 to 5000. I wrote a little sorting program: numbers = [int(line) for line in open('numbers')] numbers.sort() for i in numbers: print i and ran it on my MacBook Pro (8 Gig, 2 x 2.4 GHz cores), Python 2.6.1. $ time ./sort.py > py-sort real 0m2.706s user 0m2.491s sys 0m0.057s and did the same with the unix utility: $ time sort -n numbers > cli-sort real 0m5.123s user 0m4.745s sys 0m0.063s Python took just about half the time. Certainly knocked my socks off. Hard to believe, actually. From drsalists at gmail.com Fri Aug 5 23:08:05 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 20:08:05 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Yup. Timsort is described as "supernatural", and I'm inclined to believe it. On Fri, Aug 5, 2011 at 7:54 PM, Roy Smith wrote: > Wow. > > Python took just about half the time. Certainly knocked my socks off. > Hard to believe, actually. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 5 23:10:36 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 20:10:36 -0700 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Well, a sniffer is one of many, and one worth mentioning. Though I'd recommend wireshark over tcpdump, pretty much any day. http://stromberg.dnsalias.org/~dstromberg/Problem-solving-on-unix-linux-systems.html On Fri, Aug 5, 2011 at 6:29 PM, BJ Swope wrote: > The best tool to debug this is tcpdump. > > Running a packet capture whilst sending the mail will most likely shed the > most light on the subject. > > > -- > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 5 23:12:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 13:12:02 +1000 Subject: Question about encoding, I need a clue ... References: Message-ID: <4e3cb103$0$29984$c3e8da3$5496439d@news.astraweb.com> Geoff Wright wrote: > Hi, > > I use Mac OSX for development but deploy on a Linux server. (Platform > details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex > consistently across the two machines even though the default encoding is > set to "ascii" on both machines. As somebody else already pointed out, ? (u circumflex) is not an ASCII character, so why would you expect to be able to use it with the ASCII encoding? Essential reading: http://www.joelonsoftware.com/articles/Unicode.html Drop everything and go read that! Using Python 2.x, so-called strings are byte strings, which complicates matters greatly. The month name you get: 'ao\xc3\xbbt' is a string of five bytes with hex values: x61 x6f xc3 xbb x74 Depending on how your terminal is set up, that MAY be interpreted as the characters a o ? t but you could end up with anything: >>> print s ao?t (In theory, even the a, o and t could change, but I haven't found any terminal settings *that* wacky.) > Specifically, calendar.month_name[8] > returns a ? (question mark) on the Linux server whereas it displays > properly on the Mac OSX system. That could mean either: (1) the terminal on the Linux server is set to a different default encoding from that on the Mac; or (2) the two terminals have the same encoding, but the font used on the Linux server doesn't include the right glyph to display ?. Of the two, I expect (1) is more likely. The solution is to avoid relying on lucky accidents of the terminal encoding, and deal with this the right way. The right way is nearly always to use UTF-8 everywhere you can, not Latin 1. Make sure your terminal is set to use UTF-8 as well (I believe this is the default for Mac OS's terminal app, but I have no idea about the many different Linux terminals). Then: >>> bytes = 'ao\xc3\xbbt' # From calendar.month_name[8] >>> s = bytes.decode('utf-8') # Like unicode(bytes, 'utf-8') >>> s u'ao\xfbt' >>> print s ao?t Provided your Linux server terminal also is set to use UTF-8, this should just work. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 23:30:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 13:30:33 +1000 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: <4e3cb55a$0$29985$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Wow. > > I was going to suggest using the unix command-line sort utility via > popen() or subprocess. My arguments were that it's written in C, has 30 > years of optimizing in it, etc, etc, etc. It almost certainly has to be > faster than anything you could do in Python. > > Then I tried the experiment. I generated a file of 1 million random > integers in the range 0 to 5000. I wrote a little sorting program: [...] > Python took just about half the time. Certainly knocked my socks off. > Hard to believe, actually. One million integers isn't very big. If each integer can fit in four-byte long, that's less than 4MB. That's almost small enough to fit in your CPU's cache, with room left over for the first few chapters of "War And Peace" *wink* So you're comparing Python's timsort, which is Awesome with a capital AWE but only works on data that fits in memory, versus something which can also work on files too big to fit into memory. Try generating a twenty gigabyte file of data, and sort that. Actually, don't, because just *reading it in* to Python will probably fail, and very possibly lock your PC up for the duration. Unix sort does an external R-Way merge sort: if you have more data than memory, it slices the data up into a bunch of smaller pieces, each of which will fit in memory, sorts each one to a temporary file, then merges the lot. It does a lot more work on such big files, because it *takes* a lot more work. For something as small as one million numbers, chances are the Unix sort falls back on a heapsort or a quicksort, which will be pretty fast, but it ain't no timsort. So yes, Python's timsort is awesome, but so is Unix's sort, just in different ways. -- Steven From clp2 at rebertia.com Sat Aug 6 00:45:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 21:45:21 -0700 Subject: JSON Strict Mode In-Reply-To: References: Message-ID: > On Fri, Aug 5, 2011 at 2:19 AM, Chris Rebert wrote: >> On Thu, Aug 4, 2011 at 8:25 PM, John Riselvato >> wrote: >> > I am working on a license?verification?script. I am rather new to the >> > concept and to JSON files in general. >> > This is what my pseudocode looks like: >> >> >> >> licenses = meta['license'] >> >> for x in licenses: >> >> ? ? if licenses[x]['terms'] is not valid opensource license >> >> I would probably instead write that as: >> >> for license_name, license in licenses.items(): >> ? ?if not is_open_source(license['terms']): >> # rest same as before >> >> >> ? ? ? ? if in strict mode >> >> ? ? ? ? ? ? raise nonfree exception >> > >> > How would i go about checking if its in "strict mode" >> > and what does "raise nonfree exception" mean? >> In your specific example, the non-pseudo-code would look something like: >> >> # a declaration somewhere: >> class NonFreeLicenseError(ValueError): >> ? ?"""License is not free according to the Open Source Definition.""" >> >> # ... back in the part of your code corresponding to your pseudocode: >> if strict: >> ? ?raise NonFreeLicenseError("The '%s' license is nonfree and thus >> impermissible." % x) >> >> As written, I have NonFreeLicenseError as a kind of ValueError. This >> may or may not be appropriate depending on your program; a list of >> built-in types of exceptions can be found at >> http://docs.python.org/dev/library/exceptions.html#bltin-exceptions On Fri, Aug 5, 2011 at 3:44 PM, John Riselvato wrote: > Thanks for this mate.I took what you said and made this. >>> >>> ? ? ? ? licenseCheck = Syn.policy.metafile.LICENSE_CLEAN >>> ? ? ? ? licenses = meta['license'] >>> ? ? ? ? for i in licenses: >>> ? ? ? ? ? ? ? ? if licenses[i]['terms'] in licenseCheck == False: More conventionally written: if licenses[i]['terms'] not in licenseCheck: For that matter, I would rename `licenseCheck` to something clearer like `acceptableLicenses`. >>> ? ? ? ? ? ? ? ? ? ? ? ? try: >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise Exception(licenses[i]['terms']) >>> ? ? ? ? ? ? ? ? ? ? ? ? except Exception as inst: >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? errors = errors + 1 >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Syn.log.l(Syn.log.CRITICAL, "Doesn't meet >>> License requirement!!!") >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Syn.log.l(Syn.log.CRITICAL, "License %s >>> is **NOT** marked as clean!!" % license[i]['terms']) It's pretty pointless to catch the exception right after you raise it like this. Exceptions are intended to communicate the error to the caller, which you're not doing here, so they may not be necessary. Also, one typically raises a more specific exception than just Exception, which is the most general and vague exception possible; see my prior post for an example of using a custom exception class. > the licenseCheck main infromation you need to know is: >>> >>> LICENSE_CLEAN = [ >>> "GPL", >>> "GPL-1", >>> "GPL-2", >>> "GPL-3", >>> "X11", >>> "MIT", >>> "PSFL-2" >>> ] If you have a recent version of Python, I'd recommend using a set instead: LICENSE_CLEAN = set([ "GPL", "GPL-1", # etc... ]) This is more conceptually accurate and should be faster too. > The JSON file information is set up practically like this: >> >> "license" : { >> "*" : { >> "terms" : "GPL-3", >> "author" : "Joe Shmo, et. al" >> } >> } >> >> Is what i programmed close to what I was trying to explain? More or less. If "*" is the only entry in "license", then the for-loop is unnecessary and you can just use reference licenses['*']['terms'] (and similar) directly; one would need a specification of the your data format (or at least more examples) to be sure. And your use of exceptions doesn't really match the pseudocode, although your underlying logic is entirely reasonable, even moreso if you were to not use exceptions. Cheers, Chris -- http://rebertia.com From devraj at gmail.com Sat Aug 6 01:49:38 2011 From: devraj at gmail.com (Devraj) Date: Fri, 5 Aug 2011 22:49:38 -0700 (PDT) Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function Message-ID: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Hi all, I am trying to simply my Web application handlers, by using Python decorators. Essentially I want to use decorators to abstract code that checks for authenticated sessions and the other that checks to see if the cache provider (Memcache in this instance) has a suitable response. Consider this method definition with the decorators: @auth.login_required @cache.clear def post(self, facility_type_id = None): auth.login_required checks to see if the user is logged in, otherwise returns an appropriate error message, or executes the original function. cache.clear would check to to see if the cache has a particular key and drop that, before it executes the calling method. Both auth.login_required and cache.clear would want to eventually execute the calling method (post). >From what I've read both, doing what I am doing now would execute the calling method (post) twice. My question, how do I chain decorators that end up executing the calling method, but ensure that it's only called once. Appreciate any pointers and thanks for your time. From nobody at nowhere.com Sat Aug 6 01:59:41 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Aug 2011 06:59:41 +0100 Subject: Question about encoding, I need a clue ... References: Message-ID: On Fri, 05 Aug 2011 14:07:54 -0400, Geoff Wright wrote: > I guess what it boils down to is that I would like to get a better handle > on what is going on so that I will know how best to work through future > encoding issues. Thanks in advance for any advice. > > Here are the specifics of my problem. > > On my Mac: >>>> sys.getdefaultencoding() > 'ascii' sys.getdefaultencoding() is a red herring. It's almost always 'ascii', and isn't affected by the locale (and cannot be changed outside of the site.py file). >>>> import calendar >>>> calendar.month_name[8] > 'ao\xc3\xbbt' This is the "repr()" of 'ao?t' in UTF-8. >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao??t This is what you get if you decode the UTF-8 representation of 'ao?t' using ISO-8859-1 (aka ISO-Latin-1). > On the linux server: >>>> calendar.month_name[8] > 'ao\xfbt' This is the "repr()" of 'ao?t' in ISO-8859-1. Conclusion: the Mac's "fr_CA" locale uses UTF-8, the Linux system uses ISO-8859-1 (there may or may not be a distinct "fr_CA.utf8" locale which uses UTF-8). The difference between the two /isn't/ responsible for your problem; your problem is almost certainly due to a mismatch between the encoding used by the terminal and the locale's encoding. If you get a "?" on the Linux system, it's likely that the terminal (or emulator) is configured to use something other than ISO-8859-1 (e.g. UTF-8 or ASCII). For a GUI-based emulator (xterm, etc), you need to consult the documentation for the specific program. For the Linux console, refer to the setfont(8) manual page. In this situation, there probably isn't much point in converting to and from Unicode. You can't perform the encoding step (Unicode -> whatever) without knowing the terminal's encoding. It *should* be the same as the locale's encoding, in which case converting to and from Unicode is an identity transformation (i.e. you get out exactly what you put in). If it isn't the same as the locale's encoding, well ... good luck trying to figure out what it is. From eaglebalti at gmail.com Sat Aug 6 02:24:53 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 5 Aug 2011 23:24:53 -0700 (PDT) Subject: Hello My Sweet Friends. Message-ID: Hello Friends.How are you all? Please visit the following link to watch what you want http://watchonlineindianmovies.blogspot.com/ http://hotfemaletennisplayershotphotos.blogspot.com/ http://kaitrinakaifhotpicshotvideosmovies.blogspot.com/ http://onlinehindimoviesfreewatch4u.blogspot.com/ From skippy.hammond at gmail.com Sat Aug 6 02:55:28 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 06 Aug 2011 16:55:28 +1000 Subject: Dynamically linking python into my vc project - help required In-Reply-To: <6cafe6745022b37909647db99073fc87@edss.co.in> References: <6cafe6745022b37909647db99073fc87@edss.co.in> Message-ID: <4E3CE560.30604@gmail.com> On 3/08/2011 6:58 PM, mrinalini at edss.co.in wrote: > Hi, > > I am trying to embed python into my MFC application. I have done this > before by statically linking to the python lib. But I want to change > this now. > The idea is to take the information from the registry for the installed > version of python on the target machine. Then load python using > loadlibrary call and use the functions from python using pointers to > functions returned by GetProcAddress . ... > PyObject* pObject = pFPyEval_EvalCode((PyCodeObject*)pCodeObject, > m_Dictionary, m_Dictionary); > } > > > I am facing two problems here , though I want to link to python > dynamically I am required to include python.h for my code to compile the > following declaration. > > PyObject* pCodeObject You can probably just define pFPyEval_EvalCode as taking a PyObject * (but I'm not sure where you are getting a declaration of PyObject * from) > I tried copying some of the python definitions including PyObject into a > header in my mfc app. Then it complies fine. but Py_CompileString call > fails. so finally I am unable to run script from my MFC application by > linking to python dynamically. Are you sure you have the calling convention correct on those function pointer decls? > How can this be done ? Please help. Is there a different approach to > linking to python dynamically. Please could you write to me ? py2exe takes the same basic approach as you and might be worth copying its declarations for the function pointers? Mark From eliben at gmail.com Sat Aug 6 03:34:48 2011 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 6 Aug 2011 10:34:48 +0300 Subject: Calling super() in __init__ of a metaclass Message-ID: Consider this standard metaclass definition: class MyMetaclass(type): def __init__(cls, name, bases, dct): super(MyMetaclass, cls).__init__(name, bases, dct) # do meta-stuff class Foo(object): __metaclass__ = MyMetaclass The call "super(MyMetaclass, cls)" should returns the parent of MyMetaclass here. But the 'cls' passed into this __init__ is *not* MyMetaclass, but rather the created class - i.e. Foo. So how does "super" get to the parent of MyMetaclass using this information? The documentation of "super" says: If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods). Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass of MyMetaclass, so this doesn't help. Eli From thinke365 at gmail.com Sat Aug 6 03:38:35 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 15:38:35 +0800 Subject: can virtualenv run without the main installation? Message-ID: At first i have a python environment, after using virtualenv test command, a new environment named test is created, in that directory have some of the executable commands such as python.exe, so can i program without the main installation of python? From rafadurancastaneda at gmail.com Sat Aug 6 03:49:30 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sat, 06 Aug 2011 09:49:30 +0200 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: <4E3CF20A.5000400@gmail.com> You don't need doing something special, each decorator returns a new function that and only the result function formed by all decorators will be run. Consider this: def clear_cache(func): def decorator(*args, **kwargs): print "cache cleared" return func(*args, **kwargs) return decorator def login(func): def decorator(*args, **kwargs): print "login" return func(*args, **kwargs) return decorator @login @clear_cache def post(msg= "POST", *args): print msg return args result = post("POST", "something") print result The output will be: login cache cleared POST ('something',) On 06/08/11 07:49, Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > > From what I've read both, doing what I am doing now would execute the > calling method (post) twice. > > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. > > Appreciate any pointers and thanks for your time. From clp2 at rebertia.com Sat Aug 6 03:49:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Aug 2011 00:49:59 -0700 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: On Fri, Aug 5, 2011 at 10:49 PM, Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > >From what I've read both, doing what I am doing now would execute the > calling method (post) twice. That's incorrect unless the decorators you're using are weird. > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. That's how it works normally; decorators stack (and order is therefore important). With normal wrapping decorators, only the first decorator gets access to the original function and is able to call it. Subsequent decorators only get access to the already-wrapped function. Example: def decorator_A(func): def decorated(*args, **kwds): print "In decorator A" return func(*args, **kwds) return decorated def decorator_B(func): def decorated(*args, **kwds): print "In decorator B" return func(*args, **kwds) return decorated @decorator_B @decorator_A def myfunc(arg): print "hello", arg >>> myfunc('bob') In decorator B In decorator A hello bob Notice that myfunc() only got executed once. Cheers, Chris -- http://rebertia.com From thinke365 at gmail.com Sat Aug 6 03:51:41 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 15:51:41 +0800 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: env create by virtualenv will refer to the main env, how did it find the main env, is there any configuration files, if yes, where is it? 2011/8/6 smith jack : > At first i have a python environment, after using virtualenv test > command, a new environment named test is created, in that directory > have some of the executable commands > such as python.exe, so can i program without the main installation of python? > From __peter__ at web.de Sat Aug 6 03:59:00 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Aug 2011 09:59 +0200 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > From what I've read both, doing what I am doing now would execute the > calling method (post) twice. > > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. You typically don't need to do anything special for the above to work: >>> def v(f): ... print "decorator v, wrapping", f.__name__, "into a" ... def a(*args, **kw): ... print "calling", f.__name__, "from a" ... return f(*args, **kw) ... return a ... >>> def w(f): ... print "decorator w, wrapping", f.__name__, "into b" ... def b(*args, **kw): ... print "calling", f.__name__, "from b" ... return f(*args, **kw) ... return b ... >>> @v ... @w ... def f(s): ... print s ... decorator w, wrapping f into b decorator v, wrapping b into a >>> f("hello") calling b from a calling f from b hello The output shows that w wraps f into b, but v then doesn't get to see the original f, it wraps b into a. Put another way @v @w def f(): ... is the same as def f(): ... f = v(w(f)) and calling f() now is equivalent to calling a() which may or may not invoke b() which may or may not invoke the original f(). Translated into your example: def post(self, facility_type_id = None): ... post = auth.login_required(cache.clear(post)) The cache should only be cleared after a successful login, and the original post() will only be invoked after a successful login and with a cleared cache. From clp2 at rebertia.com Sat Aug 6 04:04:30 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Aug 2011 01:04:30 -0700 Subject: Calling super() in __init__ of a metaclass In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 12:34 AM, Eli Bendersky wrote: > Consider this standard metaclass definition: > > class MyMetaclass(type): > ? ?def __init__(cls, name, bases, dct): > ? ? ? ?super(MyMetaclass, cls).__init__(name, bases, dct) > ? ? ? ?# do meta-stuff > > class Foo(object): > ? ?__metaclass__ = MyMetaclass > > The call "super(MyMetaclass, cls)" should returns the parent of > MyMetaclass here. But the 'cls' passed into this __init__ is *not* > MyMetaclass, but rather the created class - i.e. Foo. ...which is an instance of the first argument to super(), which is how super is typically invoked. Remember: a class is an instance of its metaclass. Perhaps if you rename `cls` to `self` and then re-read your snippet, you'll have a flash of sudden understanding. Calling the parameter `cls` is merely convention. > So how does > "super" get to the parent of MyMetaclass using this information? The > documentation of "super" says: > > ? ?If the second argument is a type, issubclass(type2, type) must be > true (this is useful for classmethods). > > Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass > of MyMetaclass, so this doesn't help. The typical form of super(), mentioned earlier in the documentation, is being used here: super(type, obj) -> bound super object; requires isinstance(obj, type) `type` here is the metaclass, `obj` here is the class. By definition, a class is an *instance* of its metaclass, so the precondition is satisfied. Cheers, Chris -- http://rebertia.com From __peter__ at web.de Sat Aug 6 04:11:49 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Aug 2011 10:11:49 +0200 Subject: Calling super() in __init__ of a metaclass References: Message-ID: Eli Bendersky wrote: > Consider this standard metaclass definition: > > class MyMetaclass(type): > def __init__(cls, name, bases, dct): > super(MyMetaclass, cls).__init__(name, bases, dct) > # do meta-stuff > > class Foo(object): > __metaclass__ = MyMetaclass > > The call "super(MyMetaclass, cls)" should returns the parent of > MyMetaclass here. But the 'cls' passed into this __init__ is *not* > MyMetaclass, but rather the created class - i.e. Foo. So how does > "super" get to the parent of MyMetaclass using this information? The > documentation of "super" says: > > If the second argument is a type, issubclass(type2, type) must be > true (this is useful for classmethods). > > Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass > of MyMetaclass, so this doesn't help. Don't let yourself get confused by the name 'cls' for what is normally called 'self'. Foo is an instance of MyMetaclass, so the situation is exactly the same as in class A(object): def __init__(self, ...) super(A, self).__init__(...) I don't know how exactly super() is implemented, but to go from an instance to its class you can use type(instance) or instance.__class__. From eliben at gmail.com Sat Aug 6 04:18:28 2011 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 6 Aug 2011 11:18:28 +0300 Subject: Calling super() in __init__ of a metaclass In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:04, Chris Rebert wrote: > On Sat, Aug 6, 2011 at 12:34 AM, Eli Bendersky wrote: >> Consider this standard metaclass definition: >> >> class MyMetaclass(type): >> ? ?def __init__(cls, name, bases, dct): >> ? ? ? ?super(MyMetaclass, cls).__init__(name, bases, dct) >> ? ? ? ?# do meta-stuff >> >> class Foo(object): >> ? ?__metaclass__ = MyMetaclass >> >> The call "super(MyMetaclass, cls)" should returns the parent of >> MyMetaclass here. But the 'cls' passed into this __init__ is *not* >> MyMetaclass, but rather the created class - i.e. Foo. > > ...which is an instance of the first argument to super(), which is how > super is typically invoked. Remember: a class is an instance of its > metaclass. > > Perhaps if you rename `cls` to `self` and then re-read your snippet, > you'll have a flash of sudden understanding. Calling the parameter > `cls` is merely convention. > >> So how does >> "super" get to the parent of MyMetaclass using this information? The >> documentation of "super" says: >> >> ? ?If the second argument is a type, issubclass(type2, type) must be >> true (this is useful for classmethods). >> >> Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass >> of MyMetaclass, so this doesn't help. > > The typical form of super(), mentioned earlier in the documentation, > is being used here: > > ? ?super(type, obj) -> bound super object; requires isinstance(obj, type) > > `type` here is the metaclass, `obj` here is the class. By definition, > a class is an *instance* of its metaclass, so the precondition is > satisfied. Thanks, Chris. This clarifies things. Eli From 1248283536 at qq.com Sat Aug 6 04:27:15 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sat, 6 Aug 2011 16:27:15 +0800 Subject: install editra Message-ID: sudo python /opt/Editra-0.6.58/setup.py install Traceback (most recent call last): File "/opt/Editra-0.6.58/setup.py", line 639, in DoSourcePackage() File "/opt/Editra-0.6.58/setup.py", line 498, in DoSourcePackage DATA = GenerateSrcPackageFiles() File "/opt/Editra-0.6.58/setup.py", line 190, in GenerateSrcPackageFiles for loc_dir in os.listdir("locale"): OSError: [Errno 2] No such file or directory: 'locale' how to solve it?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 05:17:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 19:17:57 +1000 Subject: install editra References: Message-ID: <4e3d06c6$0$29997$c3e8da3$5496439d@news.astraweb.com> ???? wrote: > sudo python /opt/Editra-0.6.58/setup.py install > Traceback (most recent call last): > File "/opt/Editra-0.6.58/setup.py", line 639, in > DoSourcePackage() > File "/opt/Editra-0.6.58/setup.py", line 498, in DoSourcePackage > DATA = GenerateSrcPackageFiles() > File "/opt/Editra-0.6.58/setup.py", line 190, in GenerateSrcPackageFiles > for loc_dir in os.listdir("locale"): > OSError: [Errno 2] No such file or directory: 'locale' > > how to solve it?? Try: cd /opt/Editra-0.6.58/ sudo python setup.py install and if that doesn't work, try asking on an Editra mailing list. -- Steven From thinke365 at gmail.com Sat Aug 6 06:20:30 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 18:20:30 +0800 Subject: How to make the program support communication behind NAT device? Message-ID: The subnet behind my router is 192.168.1.0/24, my pc ip is 192.168.1.9, the server written with python is hosted on 192.168.1.3 on port 1033, i can connect to this server from my pc But cannot connect to this server when outside of this subnet? why? I have made port translate on router, that is 10.10.9.2:1033 to 192.168.1.3:1033 what's wrong? From vipul.iiith at gmail.com Sat Aug 6 06:35:34 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 16:05:34 +0530 Subject: Segmentation Fault on exit Message-ID: Hi, I have wrapped a library from C++ to Python using SWIG. But when I import it in Python, I am able to work fine with it, but it gives a segmentation fault while exiting. Following is the log: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pyossim >>> * Do some stuff * >>> exit() Segmentation fault vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ Kindly help. Thanks and Regards, Vipul Raheja From rosuav at gmail.com Sat Aug 6 07:02:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 12:02:03 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: The most likely cause of this is that you DECREF'd an object when you shouldn't have, or failed to INCREF one when you should have. Check over your object usage; if you can narrow down the "Do some stuff" bit to the one function call that causes the crash, it'll help you figure out where the error is. Hope that helps! Chris Angelico From vipul.iiith at gmail.com Sat Aug 6 07:16:35 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 16:46:35 +0530 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: Hi Chris, Thanks for the reply. However, the error occurs even if I don't do anything, that is, even if I simply import the library and exit() after that. I created a file a.py whose contents were the following: import pyossim exit() Upon execution, the log was as follows: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python a.py Segmentation fault Following was the gdb log: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ gdb `which python` GNU gdb (GDB) 7.2-ubuntu Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /usr/bin/python...(no debugging symbols found)...done. (gdb) run a.py Starting program: /usr/bin/python a.py [Thread debugging using libthread_db enabled] Program received signal SIGSEGV, Segmentation fault. 0x00000029 in ?? () (gdb) bt #0 0x00000029 in ?? () #1 0x0171de9f in OpenThreads::Mutex::~Mutex() () from /usr/lib/libOpenThreads.so.13 #2 0x0035369e in ?? () from /lib/libc.so.6 #3 0x0035370f in exit () from /lib/libc.so.6 #4 0x080fc854 in ?? () #5 0x080fcdf5 in ?? () #6 0x080fdc9b in PyRun_SimpleFileExFlags () #7 0x0805b6d3 in Py_Main () #8 0x0805a8ab in main () (gdb) Regards, Vipul Raheja On Sat, Aug 6, 2011 at 4:32 PM, Chris Angelico wrote: > On Sat, Aug 6, 2011 at 11:35 AM, Vipul Raheja > wrote: > > Hi, > > > > I have wrapped a library from C++ to Python using SWIG. But when I > > import it in Python, I am able to work fine with it, but it gives a > > segmentation fault while exiting. Following is the log: > > The most likely cause of this is that you DECREF'd an object when you > shouldn't have, or failed to INCREF one when you should have. Check > over your object usage; if you can narrow down the "Do some stuff" bit > to the one function call that causes the crash, it'll help you figure > out where the error is. > > Hope that helps! > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 6 07:23:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 12:23:33 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 12:16 PM, Vipul Raheja wrote: > Hi Chris, > Thanks for the reply. > However, the error occurs even if I don't do anything, that is, even if I > simply import the library and exit() after that. > I created a file a.py whose contents were the following: > import pyossim > exit() In that case, it may be in your initialization/cleanup code. Check to see if you return Py_None without increffing it, or keep a reference to something you don't own and decref it on exit. ChrisA From python.list at tim.thechases.com Sat Aug 6 08:19:27 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Aug 2011 07:19:27 -0500 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: <4E3D314F.5050809@tim.thechases.com> On 08/06/2011 02:49 AM, Chris Rebert wrote: > On Fri, Aug 5, 2011 at 10:49 PM, Devraj wrote: >> My question, how do I chain decorators that end up executing the >> calling method, but ensure that it's only called once. > > That's how it works normally; decorators stack (and order is therefore > important). With normal wrapping decorators, only the first decorator > gets access to the original function and is able to call it. I'd clarify "first decorator" here as the one closest to the decorated function which is actually the *last* one in the list of decorators, but first-to-decorate. In Chris's example below, decorator_A is the only one that calls myfunc(). > Subsequent decorators only get access to the already-wrapped function. > > Example: > > def decorator_A(func): > def decorated(*args, **kwds): > print "In decorator A" > return func(*args, **kwds) > return decorated > > def decorator_B(func): > def decorated(*args, **kwds): > print "In decorator B" > return func(*args, **kwds) > return decorated > > @decorator_B > @decorator_A > def myfunc(arg): > print "hello", arg > >>>> myfunc('bob') > In decorator B > In decorator A > hello bob > > > Notice that myfunc() only got executed once. -tkc From rosuav at gmail.com Sat Aug 6 08:22:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 13:22:35 +0100 Subject: How to make the program support communication behind NAT device? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:20 AM, smith jack wrote: > The subnet behind my router is 192.168.1.0/24, my pc ip is 192.168.1.9, > the server written with python is hosted on 192.168.1.3 on port 1033, > i can connect to this server from my pc > > But cannot connect to this server when outside of this subnet? why? > > I have made port translate on router, that is 10.10.9.2:1033 to 192.168.1.3:1033 This is a networking question, not a Python question. You'll probably get better results on a forum focused on networking. Your router's address, 10.10.9.2, is another RFC 1918 address, just like 192.168.1.3. Are you attempting to connect from elsewhere on the 10.* network, or elsewhere on the internet? If the latter, you probably have to deal with a second level of NAT. The easiest way to test: Can you talk to (eg ping) the router, 10.10.9.2, from the computer that's unable to reach your server? If not, there's your problem. Chris Angelico From vipul.iiith at gmail.com Sat Aug 6 09:34:47 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 19:04:47 +0530 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: Hi, I did look out for the problem's solution but have been struggling with it ever since. I also asked around on IRC too but haven't quite progressed towards the solution. Here is the link to the swig-generated .cxx file which we need to look into for the answers. Could you please have a look at it and help? It'll be really great. Here's the link: www.geofemengineering.it/data/master_wrap.cxx Thanks and Regards, Vipul Raheja On Sat, Aug 6, 2011 at 4:53 PM, Chris Angelico wrote: > On Sat, Aug 6, 2011 at 12:16 PM, Vipul Raheja > wrote: > > Hi Chris, > > Thanks for the reply. > > However, the error occurs even if I don't do anything, that is, even if I > > simply import the library and exit() after that. > > I created a file a.py whose contents were the following: > > import pyossim > > exit() > > In that case, it may be in your initialization/cleanup code. Check to > see if you return Py_None without increffing it, or keep a reference > to something you don't own and decref it on exit. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat Aug 6 12:49:23 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 6 Aug 2011 09:49:23 -0700 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: I have little reason to doubt that it's related to referencing counting, but: http://stromberg.dnsalias.org/~dstromberg/checking-early.html On Sat, Aug 6, 2011 at 3:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pyossim > >>> > * Do some stuff * > >>> exit() > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ > > Kindly help. > > Thanks and Regards, > Vipul Raheja > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 6 12:52:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 17:52:01 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 2:34 PM, Vipul Raheja wrote: > Here's the link:?www.geofemengineering.it/data/master_wrap.cxx > Thanks and Regards, > Vipul Raheja Ugh. Unfortunately that file is somewhat lengthy... I hate to say "tl;dr" to people, but... is there any way to simplify that down? Perhaps the best way to proceed would be to make a completely empty SWIG-Python module, with absolutely none of the actual interface code, just initializing itself and cleaning up. If that doesn't crash, add code back in until it crashes on exit again. Alternatively, you may be able to get good results by compiling a debug build of Python, with reference tracking. I've never done that myself, but others on this list will be able to advise. ChrisA From thinke365 at gmail.com Sat Aug 6 13:07:00 2011 From: thinke365 at gmail.com (smith jack) Date: Sun, 7 Aug 2011 01:07:00 +0800 Subject: how to separate a list into two lists? Message-ID: if a list L is composed with tuple consists of two elements, that is L = [(a1, b1), (a2, b2) ... (an, bn)] is there any simple way to divide this list into two separate lists , such that L1 = [a1, a2... an] L2=[b1,b2 ... bn] i do not want to use loop, any methods to make this done? From rosuav at gmail.com Sat Aug 6 13:14:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 18:14:16 +0100 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? One easy way is to use list comprehensions. Technically that'll involve a loop, but the loop is handled efficiently under the hood. L1 = [x[0] for x in L] L2 = [x[1] for x in L] Another way would be to construct a dictionary from your list of tuples and then use the keys() and values() of that dictionary to form your lists (use collections.OrderedDict if the order matters). But I think the list comps are the best way. ChrisA From gherron at islandtraining.com Sat Aug 6 13:15:25 2011 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 06 Aug 2011 10:15:25 -0700 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D76AD.5010608@islandtraining.com> On 08/06/2011 10:07 AM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? List comprehension: L1 = [item[0] for item in L] L2 = [item[1] for item in L] which *is* still a loop. (You are going to have to write *really* arcane code to have no loop.) Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From kabie2011 at gmail.com Sat Aug 6 13:23:53 2011 From: kabie2011 at gmail.com (Kabie) Date: Sun, 7 Aug 2011 01:23:53 +0800 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: No. L1, L2 = zip(*L) 2011/8/7 Chris Angelico > On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: > > if a list L is composed with tuple consists of two elements, that is > > L = [(a1, b1), (a2, b2) ... (an, bn)] > > > > is there any simple way to divide this list into two separate lists , > such that > > L1 = [a1, a2... an] > > L2=[b1,b2 ... bn] > > > > i do not want to use loop, any methods to make this done? > > One easy way is to use list comprehensions. Technically that'll > involve a loop, but the loop is handled efficiently under the hood. > > L1 = [x[0] for x in L] > L2 = [x[1] for x in L] > > Another way would be to construct a dictionary from your list of > tuples and then use the keys() and values() of that dictionary to form > your lists (use collections.OrderedDict if the order matters). But I > think the list comps are the best way. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Sat Aug 6 13:24:10 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 06 Aug 2011 10:24:10 -0700 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On 8/6/2011 10:07 AM smith jack said... > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > >>> L = [('a1', 'b1'), ('a2', 'b2'),('an', 'bn')] >>> zip(*L) [('a1', 'a2', 'an'), ('b1', 'b2', 'bn')] Emile From schesis at gmail.com Sat Aug 6 13:30:49 2011 From: schesis at gmail.com (Zero Piraeus) Date: Sat, 6 Aug 2011 13:30:49 -0400 Subject: Fwd: how to separate a list into two lists? In-Reply-To: References: Message-ID: : > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] How about this? >>> L = [("a1", "b1"), ("a2", "b2"), ("an", "bn")] >>> L1, L2 = zip(*L) >>> L1 ('a1', 'a2', 'an') >>> L2 ('b1', 'b2', 'bn') http://docs.python.org/library/functions.html#zip ?-[]z. From sturlamolden at yahoo.no Sat Aug 6 13:53:12 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 6 Aug 2011 10:53:12 -0700 (PDT) Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Aug 1, 5:33?pm, aliman wrote: > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. Or just memory map the file (mmap.mmap) and do an inline .sort() on the bytearray (Python 3.2). With Python 2.7, use e.g. numpy.memmap instead. If the file is large, use 64-bit Python. You don't have to process the file in chunks as the operating system will take care of those details. Sturla From john2james at gmail.com Sat Aug 6 14:04:07 2011 From: john2james at gmail.com (John S James) Date: Sat, 6 Aug 2011 14:04:07 -0400 Subject: Problem installing 3.2.1 on a Linux server Message-ID: My ISP (Bluehost) does not yet support Python version 3, but gave me shell access (no sudo) so that I can install Python 3 myself on my server account (running Apache). So I uploaded the standard Python.org installation package (Python 3.2.1 for Linux) and followed instructions, starting with ./configure. These instructions had worked for me before, to install Python3 on a Linux netbook. But on the server, ./configure starts fine, but later stops with an error. Here is the section of the output where the error occurred: *checking for build directories... done* *configure: creating ./config.status* *config.status: creating Makefile.pre* *config.status: creating Modules/Setup.config* *config.status: error: cannot find input file: `Misc/python.pc.in'* Then the ./configure step stopped. Needless to say, the next step, Make, did not work because there was no Makefile. Others have received the same message, in different contexts. But I haven't found a solution. Two action items: * For the Python community, it would help to fix this problem in the standard Python distribution, if possible. People do want to run Python3 on more servers. I could help by testing the fix to see if the Python3 install now works. * Meanwhile I'd appreciate any advice on a temporary fix (such as changing the configure file, or where to find a package that I could install on the server before installing Python3). All I need for now is the most basic installation, to support CGI and Web forms. John -- John S. James www.RepliCounts.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From only at fleshwound.org Sat Aug 6 14:13:20 2011 From: only at fleshwound.org (bud) Date: 06 Aug 2011 18:13:20 GMT Subject: how to separate a list into two lists? References: Message-ID: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is L = > [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , > such that L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? (x,y) = [ [z[i] for z in L] for i in range(len(L[0]))] x : ['a1', 'a2', 'an'] y : ['b1', 'b2', 'bn'] From only at fleshwound.org Sat Aug 6 14:21:40 2011 From: only at fleshwound.org (bud) Date: 06 Aug 2011 18:21:40 GMT Subject: how to separate a list into two lists? References: Message-ID: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> On Sat, 06 Aug 2011 10:24:10 -0700, Emile van Sebille wrote: > On 8/6/2011 10:07 AM smith jack said... >> if a list L is composed with tuple consists of two elements, that is L >> = [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> > >>> L = [('a1', 'b1'), ('a2', 'b2'),('an', 'bn')] zip(*L) > [('a1', 'a2', 'an'), ('b1', 'b2', 'bn')] > Nice. :) I forgot about zip, still learning Python myself. I'll have to check up on the *L - is that a reference? I know in Perl, you can assign the lhs to a list, below works because there are exactly 2 items on the rhs. Does Python have a catchall, or an ignore the rest? Example, if L was a tuple that had 3 or more items, the below lhs would fail. Is this possible in Python? (X,Y) = zip(*L) X : ('a1', 'a2', 'an') Y : ('b1', 'b2', 'bn') From rosuav at gmail.com Sat Aug 6 14:35:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 19:35:53 +0100 Subject: how to separate a list into two lists? In-Reply-To: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> References: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: On Sat, Aug 6, 2011 at 7:21 PM, bud wrote: > Nice. :) ?I forgot about zip, still learning Python myself. > > I'll have to check up on the *L - is that a reference? > I It expands the list into the arguments. It's the parallel to: def func(*args): which collapses the args into a list. ChrisA From gelonida at gmail.com Sat Aug 6 15:50:40 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:50:40 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: On 08/06/2011 09:38 AM, smith jack wrote: > At first i have a python environment, after using virtualenv test > command, a new environment named test is created, in that directory > have some of the executable commands > such as python.exe, so can i program without the main installation of python? At least under linux virtualenv uses symbolic links. So the answer is simple. virtualenv need the pyton installation it was derived from. only modules, that you will install under virtualenv will be installed in the virtualenv directories. From gelonida at gmail.com Sat Aug 6 15:52:36 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:52:36 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: <4E3D9B84.7080604@gmail.com> On 08/06/2011 09:51 AM, smith jack wrote: > env create by virtualenv will refer to the main env, how did it find > the main env, is there any configuration files, if yes, where is it? > > 2011/8/6 smith jack : >> At first i have a python environment, after using virtualenv test >> command, a new environment named test is created, in that directory >> have some of the executable commands >> such as python.exe, so can i program without the main installation of python? >> Under linux the first lien of virtualenv is #!/usr/bin/python Thus it will be run by python installed under /usr/bin/python From gelonida at gmail.com Sat Aug 6 15:52:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:52:46 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: On 08/06/2011 09:51 AM, smith jack wrote: > env create by virtualenv will refer to the main env, how did it find > the main env, is there any configuration files, if yes, where is it? > > 2011/8/6 smith jack : >> At first i have a python environment, after using virtualenv test >> command, a new environment named test is created, in that directory >> have some of the executable commands >> such as python.exe, so can i program without the main installation of python? >> Under linux the first lien of virtualenv is #!/usr/bin/python Thus it will be run by python installed under /usr/bin/python From gelonida at gmail.com Sat Aug 6 16:00:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 22:00:46 +0200 Subject: how to separate a list into two lists? In-Reply-To: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: On 08/06/2011 08:13 PM, bud wrote: > On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote: > >> if a list L is composed with tuple consists of two elements, that is L = >> [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> i do not want to use loop, any methods to make this done? > > > (x,y) = [ [z[i] for z in L] for i in range(len(L[0]))] > > x > : ['a1', 'a2', 'an'] > > y > : ['b1', 'b2', 'bn'] > > Asuming you are not an alias of Jack Smith and assuming you did not see Jack's thread asking the same question: x,y = unzip(*L) From jjposner at codicesoftware.com Sat Aug 6 16:06:04 2011 From: jjposner at codicesoftware.com (John Posner) Date: Sat, 06 Aug 2011 16:06:04 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D9EAC.4090100@codicesoftware.com> On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? > The official Python documentation [1] notes that "zip() in conjunction with the * operator can be used to unzip a list". Ex: >>> L = [ (1,'a'), (2,'b'), (3,'c'), (4,'d') ] >>> zip(*L) [(1, 2, 3, 4), ('a', 'b', 'c', 'd')] HTH, John [1] http://docs.python.org/library/functions.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Sat Aug 6 16:06:41 2011 From: jjposner at optimum.net (John Posner) Date: Sat, 06 Aug 2011 16:06:41 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D9ED1.2070500@optimum.net> On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? > The official Python documentation [1] notes that "zip() in conjunction with the * operator can be used to unzip a list". Ex: >>> L = [ (1,'a'), (2,'b'), (3,'c'), (4,'d') ] >>> zip(*L) [(1, 2, 3, 4), ('a', 'b', 'c', 'd')] HTH, John [1] http://docs.python.org/library/functions.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahan_noor at hotmail.com Sat Aug 6 16:38:35 2011 From: aahan_noor at hotmail.com (aahan noor) Date: Sun, 7 Aug 2011 02:38:35 +0600 Subject: help In-Reply-To: References: Message-ID: Hi all: i am new to python. i am working with lm-sensors to monitor the cpu fan speed, temperature and voltages. i have to use python code to get integer value of cpu temperature from lm sensors. please help me how i do that i shall be gratefullAahan -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Sat Aug 6 16:53:42 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 6 Aug 2011 16:53:42 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 1:23 PM, Kabie wrote: > No. > L1, L2 = zip(*L) Not quite. That makes L1 & L2 tuples. L1, L2 = zip(*L) L1 = list(L1) L2 = list(L2) ??? From kw at codebykevin.com Sat Aug 6 17:33:13 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 06 Aug 2011 17:33:13 -0400 Subject: DDE vs. COM for Python Windows apps Message-ID: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> I'm developing a Windows version of a Mac/Python app and I'd like to add a scripting interface to it. On the Mac I do this via Apple Events--this is an Apple technology that allows applications to drive other applications and query them for data using a message-passing interface. Each application defines a suite of commands and/or data objects that it will invoke, depending on which Apple Event is passed to it; these commands and data objects are most commonly documented in an AppleScript API dictionary, though there are other ways to send Apple Events as well. On Windows, I've found two separate mechanisms that seem to offer what I'm looking for: Dynamic Data Exchange (DDE) and Component Object Model (COM). As I understand it, DDE allows data transfer and command-automation between applications via a lightweight message-passing interface. COM seems to offer similar functionality, with a much more complex learning curve. The main complaint I've seen about DDE is that it is very old. The main complaint I've seen about COM is that it is very complex and very brittle. Based on my research, it seems that DDE might be sufficient for my needs--I want other applications to be able to send commands to my application and have data returned to them. But I'd like to have a better understanding of the merits of each. Can someone summarize the advantages that COM might have over DDE, in a Pythonic context? --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From nad at acm.org Sat Aug 6 18:09:39 2011 From: nad at acm.org (Ned Deily) Date: Sat, 06 Aug 2011 15:09:39 -0700 Subject: Problem installing 3.2.1 on a Linux server References: Message-ID: In article , John S James wrote: > My ISP (Bluehost) does not yet support Python version 3, but gave me shell > access (no sudo) so that I can install Python 3 myself on my server account > (running Apache). So I uploaded the standard Python.org installation package > (Python 3.2.1 for Linux) and followed instructions, starting with > ./configure. These instructions had worked for me before, to install Python3 > on a Linux netbook. > > But on the server, ./configure starts fine, but later stops with an error. > Here is the section of the output where the error occurred: > *checking for build directories... done* > *configure: creating ./config.status* > *config.status: creating Makefile.pre* > *config.status: creating Modules/Setup.config* > *config.status: error: cannot find input file: `Misc/python.pc.in'* > > Then the ./configure step stopped. Needless to say, the next step, Make, did > not work because there was no Makefile. Works for me on a current Debian system. Are you downloading the source from python.org? Did you verify that the file is created by tar? $ curl -O http://www.python.org/ftp/python/3.2.1/Python-3.2.1.tgz $ tar xzf Python-3.2.1.tgz $ cd ./Python-3.2.1/ $ ls -l Misc/python.pc.in -rw-r----- 1 nad nad 293 Jul 8 23:58 Misc/python.pc.in $ ./configure [...] configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating Misc/python.pc config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating Makefile If you are still having problems, chances are you have an out-of-date or incomplete version of GNU autotools which contains the macros and tools that are used by the ./configure script. On my system: $ autoconf --version autoconf (GNU Autoconf) 2.68 -- Ned Deily, nad at acm.org From drsalists at gmail.com Sat Aug 6 18:42:03 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 6 Aug 2011 15:42:03 -0700 Subject: help In-Reply-To: References: Message-ID: I'll be a lot easier for you to get help, if you take a shot at it yourself first, then post a link to what you have here, along with any error messages you may be getting. On Sat, Aug 6, 2011 at 1:38 PM, aahan noor wrote: > > Hi all: > i am new to python. i am working with lm-sensors to monitor the cpu fan speed, temperature and voltages. i have to use python code to get integer value of cpu temperature from lm sensors. please help me how i do that > i shall be gratefull > > Aahan > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 20:07:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:07:23 +1000 Subject: how to separate a list into two lists? References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > Asuming you [Bud] are not an alias of Jack Smith and assuming you did > not see Jack's thread asking the same question: That's a strange thing to say when Bud *answered* Jack's question. > x,y = unzip(*L) What's unzip? It doesn't exist in any version of Python between 1.5 and 3.3 that I have. -- Steven From rosuav at gmail.com Sat Aug 6 20:08:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 01:08:41 +0100 Subject: DDE vs. COM for Python Windows apps In-Reply-To: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> References: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> Message-ID: On Sat, Aug 6, 2011 at 10:33 PM, Kevin Walzer wrote: > The main complaint I've seen about DDE is that it is very old. I can't speak about COM, as I have not used it to any great extent, but DDE has a number of things going for it. Firstly though, "old" does not need to be a criticism. How many network administrators use ping(1) on a daily basis? Yet that utility was written in the early 1980s - in computing terms, that's pretty old. DDE is implemented as window messages. This means it works with anything that has a window; it might not be easy to send DDE requests from a console application, and it would be quite tricky to receive them in a console. It also means that the system can hang until the request is dealt with. However, it is extremely simple and easy. There are other options. The best thing to do would be to set down your actual requirements, and then see what technology best fits them. For instance: * Do you need programs running on other computers to be able to send/receive messages, or just on the local computer (ie, do you need network support)? * Do you need asynchronous requests/responses? * Do you need to support multiple simultaneous requests? * Conversely, must you explicitly forbid requests when another app is using the API? * Do you need to move significant amounts of data around, or could it all be done with simple 32-bit integers? If you need networking, far and away the best option is TCP sockets. But your post suggests that something light-weight is what you're after. If you don't care about return values, or alternatively if you can return an instant response, it might be easiest to simply use window messages. You pass in a message number and two parameter integers, and you get back a returned integer. That's enough for a lot of things, but you have to be able to return very quickly. You may wish to google for 'Windows IPC'; there's quite a few options available. Deciding which one is best for your situation is partly art and partly science... and partly faith in the future. I recommend choosing the one that looks like the coolest and most fun to play with; that way, even if the project fails, it's not been a complete waste. ChrisA From steve+comp.lang.python at pearwood.info Sat Aug 6 20:13:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:13:02 +1000 Subject: how to separate a list into two lists? References: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3dd88f$0$29994$c3e8da3$5496439d@news.astraweb.com> bud wrote: > I'll have to check up on the *L - is that a reference? No, as Chris already answered, unary * is used for packing and unpacking positional arguments to functions; unary ** is similarly used for collecting keyword arguments. > I know in Perl, you can assign the lhs to a list, > below works because there are exactly 2 items on the rhs. > Does Python have a catchall, or an ignore the rest? Yes. In Python 3, you can do this: >>> a, b, *t, c = (1, 2, 3, 4, 5, 6, 7, 8, 9) >>> t [3, 4, 5, 6, 7, 8] (but not in Python 2) -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 6 20:27:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:27:24 +1000 Subject: how to separate a list into two lists? References: Message-ID: <4e3ddbed$0$29994$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: >> if a list L is composed with tuple consists of two elements, that is >> L = [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> i do not want to use loop, any methods to make this done? > > One easy way is to use list comprehensions. Technically that'll > involve a loop, but the loop is handled efficiently under the hood. > > L1 = [x[0] for x in L] > L2 = [x[1] for x in L] I hardly think that's "under the hood". It's right there: for x in L. How much more explicitly a loop do you want? To the original poster, Jack: if you don't loop over the list, how do you expect to operate on each and every item? Whether you write: L1, L2 = [], [] for a,b in L: L1.append(a) L2.append(b) or L1, L2 = zip(*L) or L1 = [x[0] for x in L] L2 = [x[1] for x in L] you are still looping over the list. In the second case, the one-liner using zip, you loop *twice*: once to unpack L into separate arguments, the second time to zip them up. And the result you end up with are tuples, not lists, so if you need lists, you have to loop *again*, over each tuple, converting them to lists. Here's one way to do that while keeping it a one-liner: L1, L2 = map(list, zip(*L)) If L is small, it really doesn't matter what you do, they will all be more or less as efficient. Write whatever you feel looks best. But if L is huge, then the difference between a four-liner that iterates over the list once, and one-liner that iterates over it four times, may be considerable. -- Steven From timr at probo.com Sat Aug 6 20:58:30 2011 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Aug 2011 17:58:30 -0700 Subject: how to separate a list into two lists? References: Message-ID: smith jack wrote: > >if a list L is composed with tuple consists of two elements, that is >L = [(a1, b1), (a2, b2) ... (an, bn)] > >is there any simple way to divide this list into two separate lists , such that >L1 = [a1, a2... an] >L2=[b1,b2 ... bn] > >i do not want to use loop, any methods to make this done? There will always be a loop. It might not be written with a "for" statement, but there will always be a loop. L1 = [k[0] for k in L] L2 = [k[1] for k in L] I did momentarily consider the following slimy solution: L1 = dict(L).keys() L2 = dict(L).values() but that reorders the tuples. They still correspond, but in a different order. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Sat Aug 6 21:05:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 02:05:14 +0100 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts wrote: > I did momentarily consider the following slimy solution: > ?L1 = dict(L).keys() > ?L2 = dict(L).values() > but that reorders the tuples. ?They still correspond, but in a different > order. > Which can be overcome with collections.OrderedDict. But what's dict(L) going to do? It's going to loop over L, more than once in fact. I guess the real question is: Why do you wish to avoid a loop? ChrisA From bmanchester at azteknetworks.com Sat Aug 6 21:32:19 2011 From: bmanchester at azteknetworks.com (Bart Manchester) Date: Sat, 6 Aug 2011 20:32:19 -0500 Subject: help with DLL or path issue trying to use cx_Freeze Message-ID: Im trying to use the most basic of cx_Freeze in a dos window and I receive the following error (see below). I suspect I have some kind of path issue, but am at a loss as to how to proceed. I am trying to execute this in the Scripts directory and have both the cxfreeze bat and also the .py file there. C:\Python32\Scripts>cxfreeze general-tl1-work.py Traceback (most recent call last): File "C:\Python32\Scripts\cxfreeze", line 5, in main() File "C:\Python32\lib\site-packages\cx_Freeze\main.py", line 187, in main silent = options.silent) File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 84, in __init_ _ for n in self._GetDefaultBinPathExcludes() + binPathExcludes] File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 205, in _GetDe faultBinPathExcludes import cx_Freeze.util ImportError: DLL load failed: %1 is not a valid Win32 application. C:\Python32\Scripts> -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 21:35:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 11:35:23 +1000 Subject: how to separate a list into two lists? References: Message-ID: <4e3debdb$0$29972$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts wrote: >> I did momentarily consider the following slimy solution: >> L1 = dict(L).keys() >> L2 = dict(L).values() >> but that reorders the tuples. ?They still correspond, but in a different >> order. >> > > Which can be overcome with collections.OrderedDict. But what's dict(L) > going to do? It's going to loop over L, more than once in fact. > > I guess the real question is: Why do you wish to avoid a loop? I think what the Original Poster actually meant was he wanted to avoid *writing out an explicit loop*. That is, he wants a one-liner, so he doesn't have to think about the details of iterating over the list. When we write: a = sum(a_sequence) aren't we doing the same thing really? -- Steven From ericsnowcurrently at gmail.com Sat Aug 6 23:06:51 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 6 Aug 2011 21:06:51 -0600 Subject: how to dynamically generate __name__ for an object? Message-ID: Thought I knew how to provide a dynamic __name__ on instances of a class. My first try was to use a non-data descriptor: # module base.py class _NameProxy(object): def __init__(self, oldname): self.oldname = oldname def __get__(self, obj, cls): if obj is None: return self.oldname if "__name__" not in obj.__dict__: return str(obj.__context__) return obj.__name__ class _BaseMeta(type): def __init__(cls, name, bases, namespace): cls.__name__ = _NameProxy(name) class Base(object): __metaclass__ = _BaseMeta $ python _base.py Traceback (most recent call last): ... File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ cls.__name__ = _NameProxy(name) TypeError: Error when calling the metaclass bases can only assign string to Base.__name__, not '_NameProxy' Needless to say I was surprised. After looking in typeobject.c, I believe that __name__ must be a string where classes are concerned[1]. So if I want all my instances to have a __name__ attribute, and for it to be dynamically provided if it isn't set on the instance, what are my options? Or maybe I did something wrong and it should work as I expected? -eric [1] http://hg.python.org/cpython/file/default/Objects/typeobject.c#l244 From steve+comp.lang.python at pearwood.info Sun Aug 7 00:47:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 14:47:42 +1000 Subject: how to dynamically generate __name__ for an object? References: Message-ID: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > Thought I knew how to provide a dynamic __name__ on instances of a > class. My first try was to use a non-data descriptor: Perhaps you should explain what you are trying to do. If you want to give instances their own name, why not just give them an instance attribute "name"? Double-leading-and-trailing-underscore attributes are reserved for Python, and have special semantics. -- Steven From no.email at nospam.invalid Sun Aug 7 01:29:44 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Aug 2011 22:29:44 -0700 Subject: how to separate a list into two lists? References: Message-ID: <7xd3ghokl3.fsf@ruckus.brouhaha.com> smith jack writes: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? That is called unzipping and there is a sneaky idiom for it: L1,L2 = zip(*L) Your homework assignment is figuring out how that works ;-). From zak.mc.kraken at libero.it Sun Aug 7 01:54:08 2011 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 07 Aug 2011 07:54:08 +0200 Subject: how to separate a list into two lists? References: Message-ID: David Robinow wrote: > On Sat, Aug 6, 2011 at 1:23 PM, Kabie wrote: >> No. >> L1, L2 = zip(*L) > > Not quite. That makes L1 & L2 tuples. > > L1, L2 = zip(*L) > L1 = list(L1) > L2 = list(L2) > ??? L1, L2 = map(list, zip(*L)) -- By ZeD From ericsnowcurrently at gmail.com Sun Aug 7 04:05:46 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sun, 7 Aug 2011 02:05:46 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 6, 2011 at 10:47 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> Thought I knew how to provide a dynamic __name__ on instances of a >> class. ?My first try was to use a non-data descriptor: > > Perhaps you should explain what you are trying to do. If you want to give > instances their own name, why not just give them an instance > attribute "name"? Double-leading-and-trailing-underscore attributes are > reserved for Python, and have special semantics. Again useful information failed to make it from my head to the keyboard. :) Currently I am looking at objects, regardless of their types, and keying off their name. If it is a module, class, or function object, the name should be stored in __name__ already. If it is an instance of the Base class I demonstrated, I would like to maintain that convention. However, you may have a good point. In other code I can simply check for the name attribute I choose for my objects and also check for __name__. I suppose I just liked the idea of having a single attribute to check. -eric > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From sharanya9030 at gmail.com Sun Aug 7 06:53:59 2011 From: sharanya9030 at gmail.com (sharu) Date: Sun, 7 Aug 2011 03:53:59 -0700 (PDT) Subject: HOT ACTRESS PHOTOS AND VIDEOS Message-ID: <68274dc1-370c-46f6-bd9b-fbe9f8f6b4ef@d8g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From lukius at gmail.com Sun Aug 7 08:56:16 2011 From: lukius at gmail.com (Lucio Santi) Date: Sun, 7 Aug 2011 09:56:16 -0300 Subject: PEP 372 -- Adding an ordered directory to collections In-Reply-To: <8ad2ea1e-e336-4236-81c3-7a4959050696@e53g2000hsa.googlegroups.com> References: <5c6cdecc-624f-4e1f-b4d5-88656e182d02@a1g2000hsb.googlegroups.com> <1ea1731d-9de9-4e73-9c08-e9f5572b9fd6@t54g2000hsg.googlegroups.com> <1a8797c6-a165-49b1-82de-94a6054cf856@z16g2000prn.googlegroups.com> <8ad2ea1e-e336-4236-81c3-7a4959050696@e53g2000hsa.googlegroups.com> Message-ID: Hi all, I'm a first-time writer here, so excuse me if I say something inappropriate or such. Last week, I was reviewing some Python 2.7 modules when I came across the OrderedDict data structure. After seeing its official implementation and also after reading through the corresponding PEP, I figured out another way of implementing it. As I recently saw here, the idea is similar to the one proposed by bearophile, but nevertheless I think it is more efficient since there is no need to perform lookups multiple times. The idea is to embed the doubly-linked list of items in the dictionary itself, and extend the values inserted by providing a node as a 4-tuple . Of course, references to the first and last nodes must be kept too, in addition to the dictionary. After implementing this approach, I experimented a little bit and compared both versions (i.e., the official one that uses an extra dictionary and mine) by measuring the running times of some basic operations. I verified that it indeed outperforms the existing implementation. I made up a recipe with the code and several comments, including more details about the experimentation mentioned above: http://code.activestate.com/recipes/577826-yet-another-ordered-dictionary/ Comments will be surely appreciated! Lucio -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Sun Aug 7 11:35:00 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 8 Aug 2011 01:35:00 +1000 Subject: Restricted attribute writing Message-ID: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is a modulo remainder. I need to be able to write to it like a normal list, but want to ensure it is only possible to do so without changing that format. Below is a what I eventually came up with; a container class called OrderElement for the inner lists, and subclass of list called Order for the main attribute, which is a property of the main class, simplified below as SeqSim. It works, but seems like a hell of a lot of code for a simple idea. I'm interested in ideas for simpler solutions, and general advice on how to do this kind of thing in a straightforward way. class OrderElement(): """Container class which can only hold two integers the first of which is a modulo of the 'length' arg""" def __init__(self, lis, length): self.__data = [None, None] self.__length=length self[:] = lis def __setitem__(self, index, item): if isinstance(index, slice): inds = range(*index.indices(2)) for k, v in enumerate(item): self[inds[k]] = v elif isinstance(item, int): if index == 0: item %= self.__length self.__data[index] = item else: raise TypeError("OrderElement takes two integers") def __getitem__(self, index): return self.__data[index] class Order(list): """Can only contain OrderElements""" def __init__(self, lis, length): self.__length = length self[:] = lis def __setitem__(self, index, item): if isinstance(index, slice): item = [i if isinstance(i, OrderElement) else OrderElement(i, self.__length) for i in item] elif not isinstance(item, OrderElement): item = OrderElement(item, self.__length) list.__setitem__(self, index, item) def __getitem__(self, index): """Ensure slices are of the same class""" if isinstance(index, slice): return self.__class__(list.__getitem__(self, index), self.__length) return list.__getitem__(self, index) class SeqSim(): """Just the relevant bits of the main class""" def __init__(self, lis, length): self.__order = Order(lis, length) self.length = length @property def order(self): return self.__order @order.setter def order(self, lis): if not isinstance(lis, Order): lis = Order(lis, self.length) self.__order = lis -- John O'Hagan From roy at panix.com Sun Aug 7 12:07:46 2011 From: roy at panix.com (Roy Smith) Date: Sun, 07 Aug 2011 12:07:46 -0400 Subject: Restricted attribute writing References: Message-ID: In article , John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such > that they retain the characteristics the class requires. Sounds like you're trying to do http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad thing. But, I think a more pythonic way to implement this would be to verify behaviors, not types. I would start by writing a assert_invarient() method which validates the object. I'm guessing all you really need is that you can index [0] and [1] and get ints, so test for that. Something like: def assert_invarient(self): try: assert isinstance(data[0], int) assert isinstance(data[1], int) except: raise ValueError Then, call this from inside your __init__(), __setitem__(), etc. From steve+comp.lang.python at pearwood.info Sun Aug 7 12:31:03 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 02:31:03 +1000 Subject: Restricted attribute writing References: Message-ID: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > John O'Hagan wrote: > >> I'm looking for good ways to ensure that attributes are only writable >> such that they retain the characteristics the class requires. > > Sounds like you're trying to do > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad > thing. But, I think a more pythonic way to implement this would be to > verify behaviors, not types. > > I would start by writing a assert_invarient() method which validates the > object. I'm guessing all you really need is that you can index [0] and > [1] and get ints, so test for that. Something like: > > def assert_invarient(self): > try: > assert isinstance(data[0], int) > assert isinstance(data[1], int) > except: > raise ValueError Don't do that. assert is for testing program logic, not verifying data. The problem with assert is that the user can turn all assertions off, simply by launching Python with the -O switch. Your verification code then becomes: def assert_invarient(self): try: pass except: raise ValueError which is useless. When should you use an assertion? If you've ever written code like this: if condition: do_something() else: # This should never happen. But you know what they say: code that # can't happen, does! raise RuntimeError('condition unexpectedly false') that's a prime candidate for turning into an assertion: assert condition, 'condition unexpectedly false' do_something() -- Steven From rafadurancastaneda at gmail.com Sun Aug 7 12:53:11 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 7 Aug 2011 18:53:11 +0200 Subject: Restricted attribute writing In-Reply-To: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: I think you might use a tuple instead of a list for OrderElement, that would make much easier your code: class OrderElement(tuple): def __new__(cls, x, y): if not isinstance(x, int) or not isinstance(y, int): raise TypeError("Order element must receives two integers") return tuple.__new__(cls, (x, y)) class Order(list): def __setitem__(self, item): assert isinstance(item, OrderElement) super(Order, self).__setitem__(item) I didn't check your module condition since it isn't quite clear to me, but you could add a second condition two Order class. 2011/8/7 Steven D'Aprano > Roy Smith wrote: > > > In article , > > John O'Hagan wrote: > > > >> I'm looking for good ways to ensure that attributes are only writable > >> such that they retain the characteristics the class requires. > > > > Sounds like you're trying to do > > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad > > thing. But, I think a more pythonic way to implement this would be to > > verify behaviors, not types. > > > > I would start by writing a assert_invarient() method which validates the > > object. I'm guessing all you really need is that you can index [0] and > > [1] and get ints, so test for that. Something like: > > > > def assert_invarient(self): > > try: > > assert isinstance(data[0], int) > > assert isinstance(data[1], int) > > except: > > raise ValueError > > Don't do that. assert is for testing program logic, not verifying data. The > problem with assert is that the user can turn all assertions off, simply by > launching Python with the -O switch. Your verification code then becomes: > > def assert_invarient(self): > try: > pass > except: > raise ValueError > > which is useless. > > When should you use an assertion? If you've ever written code like this: > > if condition: > do_something() > else: > # This should never happen. But you know what they say: code that > # can't happen, does! > raise RuntimeError('condition unexpectedly false') > > > that's a prime candidate for turning into an assertion: > > > assert condition, 'condition unexpectedly false' > do_something() > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafadurancastaneda at gmail.com Sun Aug 7 12:56:04 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 7 Aug 2011 18:56:04 +0200 Subject: Restricted attribute writing In-Reply-To: References: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: The assert on Order should be an if ... raise, like OrderElement, sorry for the mistake and repost El 7 de agosto de 2011 18:53, Rafael Dur?n Casta?eda < rafadurancastaneda at gmail.com> escribi?: > I think you might use a tuple instead of a list for OrderElement, that > would make much easier your code: > > class > OrderElement(tuple): > > def __new__(cls, x, y): > if not isinstance(x, int) or not isinstance(y, int): > raise TypeError("Order element must receives two > integers") > > return tuple.__new__(cls, (x, y)) > > > class Order(list): > def __setitem__(self, item): > assert isinstance(item, OrderElement) > super(Order, self).__setitem__(item) > > > I didn't check your module condition since it isn't quite clear to me, but > you could add a second condition two Order class. > > > 2011/8/7 Steven D'Aprano > >> Roy Smith wrote: >> >> > In article , >> > John O'Hagan wrote: >> > >> >> I'm looking for good ways to ensure that attributes are only writable >> >> such that they retain the characteristics the class requires. >> > >> > Sounds like you're trying to do >> > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad >> > thing. But, I think a more pythonic way to implement this would be to >> > verify behaviors, not types. >> > >> > I would start by writing a assert_invarient() method which validates the >> > object. I'm guessing all you really need is that you can index [0] and >> > [1] and get ints, so test for that. Something like: >> > >> > def assert_invarient(self): >> > try: >> > assert isinstance(data[0], int) >> > assert isinstance(data[1], int) >> > except: >> > raise ValueError >> >> Don't do that. assert is for testing program logic, not verifying data. >> The >> problem with assert is that the user can turn all assertions off, simply >> by >> launching Python with the -O switch. Your verification code then becomes: >> >> def assert_invarient(self): >> try: >> pass >> except: >> raise ValueError >> >> which is useless. >> >> When should you use an assertion? If you've ever written code like this: >> >> if condition: >> do_something() >> else: >> # This should never happen. But you know what they say: code that >> # can't happen, does! >> raise RuntimeError('condition unexpectedly false') >> >> >> that's a prime candidate for turning into an assertion: >> >> >> assert condition, 'condition unexpectedly false' >> do_something() >> >> >> >> -- >> Steven >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From redmumba at gmail.com Sun Aug 7 13:04:57 2011 From: redmumba at gmail.com (Redmumba) Date: Sun, 7 Aug 2011 13:04:57 -0400 Subject: PyPI Situation? Message-ID: I've been running into a lot of issues with the PyPI architecture, and I'm aware that there's some work going on behind the scenes, especially with making PyPI accessible from the a cloud-like architecture. However, I setup a Python mirror (using the pep381client) for our company, and the issue is--as always--with external packages, which usually makes the mirror useless (lxml is famously slow!). Has there been any work on improving the repository architecture, i.e., storing metadata, resolving dependencies prior to download? And is there anyway to get involved? Or should I look into creating my own and proposing a PEP? I don't want to create "yet another PyPI" if I can avoid it, so I'd prefer to contribute to an existing one if there's one available... Thanks, Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Aug 7 13:07:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 03:07:30 +1000 Subject: Restricted attribute writing References: Message-ID: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such > that they retain the characteristics the class requires. That's what properties are for. > My particular case is a class attribute which is initialised as a list of > lists of two integers, the first of which is a modulo remainder. I need to > be able to write to it like a normal list, but want to ensure it is only > possible to do so without changing that format. Then you have two problems to solve. First, you need a special type of list that only holds exactly two integers. Your main class can't control what happens inside the list, so you need the list to validate itself. Secondly, you should use a property in your main class to ensure that the attribute you want to be a special list-of-two-ints can't (easily) be changed to something else. > Below is a what I eventually came up with; a container class called > OrderElement for the inner lists, and subclass of list called Order for > the main attribute, which is a property of the main class, simplified > below as SeqSim. It works, but seems like a hell of a lot of code for a > simple idea. And why should this be surprising? It might be a simple *idea*, but the concrete execution of that idea is anything but simple. "Hey, let's fly to Mars!" is a simple idea too. Nevertheless, it does appear that your solution below is overly complicated. Two helper classes just to have a thing that holds two ints... does it have to be a list? Seems that if you're limited to exactly two items, a list is pretty useless, since you can't insert, append, pop or delete items. I'd take this approach instead: # Untested. class ThingWithTwoIntegers(object): def __init__(self, a, b): self.a = a self.b = b def __getitem__(self, index): # Slicing not supported, because I'm lazy. if index < 0: index += 2 if index == 0: return self.a elif index == 1: return self.b else: raise IndexError def __setitem__(self, index, value): # Slicing not supported, because I'm lazy. if index < 0: index += 2 if index == 0: self.a = value elif index == 1: self.b = value else: raise IndexError def _geta(self): return self._a def _seta(self, value): if isinstance(value, (int, long)): # drop long if using Python 3 self._a = value else: raise TypeError('expected an int but got %s' % type(value)) a = property(_geta, _seta) # and the same for b: _getb, _setb, making the obvious changes There's a little bit of code duplication there, but it's 3am here and I'm tired and besides, if I do all your work what would you do? *wink* This gives you an object that holds two integers. You can access them either by attribute name, "a" and "b", or by index, 0 and 1: instance = ThingWithTwoIntegers(23, 42) instance[0] => 23 instance.b => 42 Obviously this isn't a full blown list, but if you don't need all the list-like behaviour (sorting, inserting, deleting items, etc.) why support it? -- Steven From gelonida at gmail.com Sun Aug 7 13:11:32 2011 From: gelonida at gmail.com (Gelonida N) Date: Sun, 07 Aug 2011 19:11:32 +0200 Subject: how to separate a list into two lists? In-Reply-To: <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/07/2011 02:07 AM, Steven D'Aprano wrote: > Gelonida N wrote: > >> Asuming you [Bud] are not an alias of Jack Smith and assuming you did >> not see Jack's thread asking the same question: > > That's a strange thing to say when Bud *answered* Jack's question. > > >> x,y = unzip(*L) > > What's unzip? It doesn't exist in any version of Python between 1.5 and 3.3 > that I have. > Arg typo: I meant of course zip > > From jhaberman at gmail.com Sun Aug 7 14:11:37 2011 From: jhaberman at gmail.com (Josh Haberman) Date: Sun, 7 Aug 2011 11:11:37 -0700 (PDT) Subject: import hooks (PEP 302) broken in Python >=2.5? Message-ID: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> When reading about import hooks, I came across a blog entry comment that says: One additional thing to note about ihooks is that it's somewhat seriously broken on Python 2.5 and newer and there seems to be little or no interest in fixing it. It's probably worth *always* avoiding when writing new code. --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 Does anyone know what this is referring to? Should I be wary of relying on import hooks? Josh From rosuav at gmail.com Sun Aug 7 14:21:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 19:21:15 +0100 Subject: Restricted attribute writing In-Reply-To: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 7, 2011 at 6:07 PM, Steven D'Aprano wrote: > class ThingWithTwoIntegers(object): > I'm not a lisp expert, but this might well be called a cons cell. Or a "pair". ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 7 14:41:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 04:41:20 +1000 Subject: import hooks (PEP 302) broken in Python >=2.5? References: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> Message-ID: <4e3edc51$0$29998$c3e8da3$5496439d@news.astraweb.com> Josh Haberman wrote: > When reading about import hooks, I came across a blog entry comment > that says: > > One additional thing to note about ihooks is that it's > somewhat seriously broken on Python 2.5 and newer and there > seems to be little or no interest in fixing it. It's > probably worth *always* avoiding when writing new code. > > --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 > > Does anyone know what this is referring to? Should I be wary of > relying on import hooks? Are you using import hooks? What version(s) of Python are you using? Depending on whether you are asking out of curiosity, or because you have code that uses import hooks and you're about to migrate from Python 2.3 to 3.1, the answers may be different. -- Steven From bmanchester at azteknetworks.com Sun Aug 7 14:54:07 2011 From: bmanchester at azteknetworks.com (Bart Manchester) Date: Sun, 7 Aug 2011 13:54:07 -0500 Subject: help with DLL or path issue trying to use cx_Freeze Message-ID: I suspect this may have gone out before I was a member, and thus potentially not be received - apologies if this did go out please ignore this second attempt if it did. --------------- Im trying to use the most basic of cx_Freeze in a dos window and I receive the following error (see below). I suspect I have some kind of path issue, but am at a loss as to how to proceed. I am trying to execute this in the Scripts directory and have both the cxfreeze bat and also the .py file there. C:\Python32\Scripts>cxfreeze general-tl1-work.py Traceback (most recent call last): File "C:\Python32\Scripts\cxfreeze", line 5, in main() File "C:\Python32\lib\site-packages\cx_Freeze\main.py", line 187, in main silent = options.silent) File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 84, in __init_ _ for n in self._GetDefaultBinPathExcludes() + binPathExcludes] File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 205, in _GetDe faultBinPathExcludes import cx_Freeze.util ImportError: DLL load failed: %1 is not a valid Win32 application. C:\Python32\Scripts> -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Sun Aug 7 16:52:48 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Aug 2011 20:52:48 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > Duncan Booth wrote: > >> The descriptor protocol only works when a value is being accessed or set >> on an instance and there is no instance attribute of that name so the >> value is fetched from the underlying class. > > Unlike normal class attributes a descriptor is not shaded by an instance > attribute: > >>>> class A(object): > ... def set_x(self, value): self.__dict__["x"] = value/2.0 > ... def get_x(self): return self.__dict__["x"] * 2.0 > ... x = property(get_x, set_x) > ... >>>> a = A() >>>> a.x = 42 >>>> a.__dict__["x"] > 21.0 >>>> a.x > 42.0 >>>> A.x = "something completely different" >>>> a.x > 21.0 > True, and in fact that's why your suggestion of using two descriptors, one at each level works. Thanks for pointing out my mistake. -- Duncan Booth http://kupuguy.blogspot.com From nad at acm.org Sun Aug 7 18:01:52 2011 From: nad at acm.org (Ned Deily) Date: Sun, 07 Aug 2011 15:01:52 -0700 Subject: PyPI Situation? References: Message-ID: In article , Redmumba wrote: > I've been running into a lot of issues with the PyPI architecture, and I'm > aware that there's some work going on behind the scenes, especially with > making PyPI accessible from the a cloud-like architecture. PyPI is discussed on the Python Catalog SIG mailing list. You should take a look at the archives there and jump into the discussions: http://mail.python.org/mailman/listinfo/catalog-sig and mirrored in various formats here: http://dir.gmane.org/gmane.comp.python.catalog -- Ned Deily, nad at acm.org From ryan at rfk.id.au Sun Aug 7 18:03:22 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 08 Aug 2011 08:03:22 +1000 Subject: import hooks (PEP 302) broken in Python >=2.5? In-Reply-To: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> References: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> Message-ID: <1312754602.2068.1.camel@rambutan> On Sun, 2011-08-07 at 11:11 -0700, Josh Haberman wrote: > When reading about import hooks, I came across a blog entry comment > that says: > > One additional thing to note about ihooks is that it's > somewhat seriously broken on Python 2.5 and newer and there > seems to be little or no interest in fixing it. It's > probably worth *always* avoiding when writing new code. > > --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 > > Does anyone know what this is referring to? Should I be wary of > relying on import hooks? I believe that comment is referring specifically to "ihooks" the stdlib module, not "import hooks" the general concept as defined in PEP302. The former pre-dates the later. I use custom PEP302 loaders all the time and they work fine in at least 2.6, 2.7 and 3.2. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From jdoe at usenetlove.invalid Sun Aug 7 20:04:55 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 08 Aug 2011 00:04:55 GMT Subject: Wait for a keypress before continuing? Message-ID: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> My program does not need a prompt, it just needs to wait for any key to be pressed before it continues. This is in Windows. char=0 while not char: char=msvcrt.getch() That doesn't delay anything here. while 1: char=msvcrt.getch() break That appears to put my program into an endless loop. while msvcrt.kbhit(): sleep(4) msvcrt.getch() msvcrt.getch() How can that not delay anything and then instantly get past the getch()? char=0 while msvcrt.kbhit(): sleep(4) msvcrt.getch() while not char: char=msvcrt.getch() That doesn't delay anything. Something seriously wrong with my system? Thanks. From jura.grozni at gmail.com Sun Aug 7 20:26:01 2011 From: jura.grozni at gmail.com (azrael) Date: Sun, 7 Aug 2011 17:26:01 -0700 (PDT) Subject: WxPython and TK Message-ID: Today I found a quote from Guido. wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. -- Guido van Rossum OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. From steve+comp.lang.python at pearwood.info Sun Aug 7 20:27:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 10:27:59 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> John Doe wrote: > My program does not need a prompt, it just needs to wait for any > key to be pressed before it continues. This is in Windows. > > char=0 > while not char: > char=msvcrt.getch() > > That doesn't delay anything here. Works perfectly for me. You don't need the while loop, since getch blocks until a key is pressed. Rather than making arbitrary changes to the code, try printing char after the loop exits and see what it contains. That may give you a hint as to what is going on. Also, are you using an IDE? If so, it could very well be interfering with the keyboard buffer, for its own purposes. E.g. in IDLE 2.6.2, if I call getch it *immediately* returns without blocking: >>> msvcrt.getch() '\xff' -- Steven From thinke365 at gmail.com Sun Aug 7 20:45:23 2011 From: thinke365 at gmail.com (smith jack) Date: Mon, 8 Aug 2011 08:45:23 +0800 Subject: module import error, what's wrong? Message-ID: from common.URLTool import URLTool tool = URLTool() Traceback (most recent call last): File "E:\workspace\url\test.py", line 7, in ? from common.URLTool import URLTool ImportError: No module named common.URLTool URLTools is a class write by myself, it works well ,but cannot be imported in the other package, what's wrong? From gelonida at gmail.com Sun Aug 7 21:00:10 2011 From: gelonida at gmail.com (Gelonida N) Date: Mon, 08 Aug 2011 03:00:10 +0200 Subject: module import error, what's wrong? In-Reply-To: References: Message-ID: On 08/08/2011 02:45 AM, smith jack wrote: > from common.URLTool import URLTool could it be that you meant from common import URLTool As I don't know the module 'common' I am just guessing > tool = URLTool() > > Traceback (most recent call last): > File "E:\workspace\url\test.py", line 7, in ? > from common.URLTool import URLTool > ImportError: No module named common.URLTool > > URLTools is a class write by myself, it works well ,but cannot be > imported in the other package, what's wrong? From jdoe at usenetlove.invalid Sun Aug 7 22:44:41 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 08 Aug 2011 02:44:41 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> Steven D'Aprano wrote: > Also, are you using an IDE? If so, it could very well be > interfering with the keyboard buffer I really don't know how to answer your question. I am using Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon Naturally Speaking, Natlink, and Dragonfly might all be part of the process. Must be my system. I will post the solution if it comes up. From ian.g.kelly at gmail.com Mon Aug 8 00:29:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 7 Aug 2011 22:29:24 -0600 Subject: WxPython and TK In-Reply-To: References: Message-ID: On Sun, Aug 7, 2011 at 6:26 PM, azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. > -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). > > If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. That may be the only reason Tkinter was originally added to the standard library rather than wxPython, but there are plenty of reasons against changing it now. Even ignoring for the moment the fact that wxPython *still* doesn't work with Python 3 (2.5 years now since the initial release of Python 3.0), here is a nice, recent summary of some of the issues involved: http://mail.python.org/pipermail/python-list/2011-January/1264955.html Cheers, Ian From research at johnohagan.com Mon Aug 8 00:59:23 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 8 Aug 2011 14:59:23 +1000 Subject: Restricted attribute writing In-Reply-To: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110808145923.44fb85ec158393f36557f41c@johnohagan.com> On Mon, 08 Aug 2011 03:07:30 +1000 Steven D'Aprano wrote: > John O'Hagan wrote: > > > I'm looking for good ways to ensure that attributes are only writable such > > that they retain the characteristics the class requires. > > That's what properties are for. > > > My particular case is a class attribute which is initialised as a list of > > lists of two integers, the first of which is a modulo remainder. I need to > > be able to write to it like a normal list, but want to ensure it is only > > possible to do so without changing that format. > > Then you have two problems to solve. > > First, you need a special type of list that only holds exactly two integers. > Your main class can't control what happens inside the list, so you need the > list to validate itself. > > Secondly, you should use a property in your main class to ensure that the > attribute you want to be a special list-of-two-ints can't (easily) be > changed to something else. > Although experience shows you're usually right :) , I thought I had three problems, the third being what I perhaps wasn't clear enough about: that the two-integer containers live in a list which should only contain the two-integer things, but aside from that should be able to do all the other list operations on it. AFAIK making this attribute a property only protects it from incorrect assignment, but not from unwanted appends etc. That's what the other helper class Order is meant for, it subclasses list, and overrides __setitem__ to ensure every item is an OrderElement, and __getitem__ to ensure slices are the same class. I've also since realised it must override append, insert and extend. I think I need all this to ensure the required behaviour, including: s = SeqSim([[15, 2]], 12) s.order[0][1] = 100 s.order[0][1:] = [100] s.order += [[22, 11]] s.order *= 2 s.order[2] = [[15, 8]] s.order[1:5:2]) = [[1, 1],[2, 2]] s.order.extend([[1, 1],[2, 2]]) s.order.insert(2, [2, 29]) s.order.append([26, 24]) s.order.extend(s.order[1:3]) s.order = [[99, 99],[100, 100]] import random random.shuffle(s.order) etc [...] > I'd take this approach instead: > > # Untested. > class ThingWithTwoIntegers(object): > def __init__(self, a, b): > self.a = a > self.b = b > def __getitem__(self, index): > # Slicing not supported, because I'm lazy. > if index < 0: index += 2 > if index == 0: return self.a > elif index == 1: return self.b > else: raise IndexError > def __setitem__(self, index, value): > # Slicing not supported, because I'm lazy. > if index < 0: index += 2 > if index == 0: self.a = value > elif index == 1: self.b = value > else: raise IndexError > def _geta(self): > return self._a > def _seta(self, value): > if isinstance(value, (int, long)): # drop long if using Python 3 > self._a = value > else: > raise TypeError('expected an int but got %s' % type(value)) > a = property(_geta, _seta) > # and the same for b: _getb, _setb, making the obvious changes > [...] > Obviously this isn't a full blown list, but if you don't need all the > list-like behaviour (sorting, inserting, deleting items, etc.) why support > it? > Thanks for this, I can see that the __data attribute I was using was unnecessary and I've redone the OrderElement class accordingly, although I do want slicing and don't need dot-notation access: class OrderElement(): def __init__(self, length, a, b): self.__length=length self.__a = a self.__b = b self[:] = a, b def __setitem__(self, index, item): if isinstance(index, slice): for k, i in zip(range(*index.indices(2)), item): self[k] = i elif isinstance(item, int) and index in (0, 1): if index == 0: self.__a = item % self.__length elif index == 1: self.__b = item else: raise TypeError("OrderElement takes two integers") def __getitem__(self, index): if isinstance(index, slice): return [self[i] for i in range(*index.indices(2))] if index == 0: return self.__a if index == 1: return self.__b raise IndexError As for the rest, I take your point that a simple idea need not be simple to implement, and I'm starting to think my solution may be about as complicated as it needs to be. Regards, John From greg.ewing at canterbury.ac.nz Mon Aug 8 02:06:48 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 08 Aug 2011 18:06:48 +1200 Subject: WxPython and TK In-Reply-To: References: Message-ID: <9a9cnrFumuU1@mid.individual.net> azrael wrote: > If I would have gotten a dollar for every time I talked to someone in a company > about why they dont use python for their products and I was served the answer > "Well it kind of sucks in GUI development", I would be a millionaire. Even assuming that Python + wxPython sucks less than Python + Tkinter (which is a matter of opinion), putting wxPython in the standard library would change very little. Anyone who wants to is already free to use wxPython now. -- Greg From prakash.stack at gmail.com Mon Aug 8 02:11:51 2011 From: prakash.stack at gmail.com (prakash jp) Date: Mon, 8 Aug 2011 11:41:51 +0530 Subject: how to invoke a bat file on a remote machine Message-ID: Hi all, Want to know how to invoke a bat file on a remote machine. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Aug 8 02:37:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 16:37:15 +1000 Subject: WxPython and TK References: Message-ID: <4e3f841e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Mon, 8 Aug 2011 10:26 am azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a > number of constraints. The only reason wxPython isn't the standard Python > GUI toolkit is that Tkinter was there first. -- Guido van Rossum I'd like to see the context for this quote, because I don't think it is correct. Even if Guido did say it :) Other reasons contributing to why wxPython is not in the standard library: - Differences in the licence. I understand the wxWidgets licence is more restrictive than the Python licence. - Size: wxPython is much larger than Tkinter. By one account, adding wxPython would triple the size of the standard library. - Tcl/Tk is likely to already be installed on most Linux systems, wxWidgets may not be. - Stability: at least a few years ago, it was quite easy to get wxPython to seg fault. - Pythonicity: Tkinter code is much closer to Pythonic style of code than wxPython code, which is stylistically closer to C++. - Release schedules: this is likely to be the fatal sticking block. To be part of the standard library, wxPython would have to keep to Python's release schedule. If wxPython had been in the standard library, it would have been tied to Python's relatively sedate schedule, and would not have been able to keep up with wxWidgets. > OK, now. Isn't it maybe time to throw out TK once and for all? Python is > missing one of the most important aspects of todays IT industry. GUI > development native library (I mean a serious one). Python is not missing any such thing. It has a plethora of GUI libraries: wxPython Tkinter Pyjamas Dabo PyGTK PythonCard etc. See http://wiki.python.org/moin/GuiProgramming > If I would have gotten a dollar for every time I talked to someone in a > company about why they dont use python for their products and I was served > the answer "Well it kind of sucks in GUI development", I would be a > millionaire. What, these millions of companies don't have internet? http://www.wxpython.org/download.php#stable -- Steven From joepie at linux.nl Mon Aug 8 02:46:29 2011 From: joepie at linux.nl (ln4) Date: Mon, 08 Aug 2011 08:46:29 +0200 Subject: WxPython and TK References: Message-ID: azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a > number of constraints. The only reason wxPython isn't the standard Python > GUI toolkit is that Tkinter was there first. -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is > missing one of the most important aspects of todays IT industry. GUI > development native library (I mean a serious one). > > If I would have gotten a dollar for every time I talked to someone in a > company about why they dont use python for their products and I was served > the answer "Well it kind of sucks in GUI development", I would be a > millionaire. This quote from guido is perhaps from many, many years ago. I don't like wxpython so much. There is a much better solution available: using PyQt. Qt libraries are cross platform too, mature code and very fast. Including lots of tools for development without typing all the graphics code. Taco From ulrich.eckhardt at dominolaser.com Mon Aug 8 02:56:30 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 08 Aug 2011 08:56:30 +0200 Subject: Segmentation Fault on exit References: Message-ID: <1ed4h8-eo4.ln1@satorlaser.homedns.org> Vipul Raheja wrote: > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. 1. Use a debugger Run python with "gdb python", import the module and exit. The debugger should then show you where the segmentation fault occurs, even though that code isn't necessarily the code that is at fault itself. 2. Reduce the size of your module Remove code from the module. The most drastic variant is to strip anything and only leave an empty init function. If that still causes troubles, I'd suspect something in the environment or in the way you build the module. 3. Make sure the environment works Try compiling and running the SWIG examples or any other SWIG code. Does it work? What are the differences to your code? 4. Post your code If everything fails, you could try to reduce your module to the bare minimum and post that here. Make sure you really remove anything that's not necessary. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From xrgtn at yandex.ru Mon Aug 8 03:07:25 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Mon, 8 Aug 2011 10:07:25 +0300 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <20110808070725.GA3741@ux380n.ckee> Hello, On Tue, Aug 02, 2011 at 02:32:54AM -0700, loial wrote: > This works fine for files, but the directory > also contains sub- directories (which themselves > contain files and sub-directories). However I > do not think it is possible to hard link > directories ? On some Unices it is, as I heard. But in general, it's not always possible to even hardlink to an ordinary file: 1) across filesystem boundary 2) on GRSEC system, if you don't own the original file -- WBR, xrgtn From gelonida at gmail.com Mon Aug 8 03:41:05 2011 From: gelonida at gmail.com (Gelonida N) Date: Mon, 08 Aug 2011 09:41:05 +0200 Subject: Wait for a keypress before continuing? In-Reply-To: <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> Message-ID: On 08/08/2011 04:44 AM, John Doe wrote: > Steven D'Aprano wrote: > >> Also, are you using an IDE? If so, it could very well be >> interfering with the keyboard buffer > > I really don't know how to answer your question. I am using > Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon > Naturally Speaking, Natlink, and Dragonfly might all be part of > the process. > > Must be my system. I will post the solution if it comes up. Main question is whether your script is exectued in a console window (like cmd.exe) or from within a graphical library without console. you yould try to start cmd.exe and call your python script directly from there. if this doesn't work, then try just a simple test script containing nothing else than the code to wait for a keypress. Simple test script (working fine for me) import msvcrt print "before" msvcrt.getch() print "after" From python at bdurham.com Mon Aug 8 06:10:25 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 08 Aug 2011 06:10:25 -0400 Subject: WxPython and TK In-Reply-To: References: Message-ID: <1312798225.16266.2160672425@webmail.messagingengine.com> Azrael, > Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). Check out enhancements to Tk like Ttk included in Python 2.7 and 3.1 and above. http://www.tkdocs.com/tutorial/styles.html Tk/Ttk is a much lighter weight GUI than wxPython and allows for commercial quality, cross-platform GUI development. Malcolm From blivori at gmail.com Mon Aug 8 06:23:35 2011 From: blivori at gmail.com (blivori) Date: Mon, 8 Aug 2011 03:23:35 -0700 (PDT) Subject: PyPDF Processing Errors (ValueError: invalid literal for int() with base 16: '\x00\x00') Message-ID: <76d482a9-c8aa-497c-977f-b44c64a4c5fd@z17g2000vbp.googlegroups.com> I am trying to create a Python script using the PyPDF Module. What the script does it take the 'Root' folder, merges all the PDFs in it and outputs the merged PDF in an 'Output' folder and renames it to 'Root.pdf' (the folder which containes the split PDFs). What it does then is do the same with the sub-directories, giving the final output a name equal to the sub-directories. I'm stuck when coming to process the sub-directories, giving me an error code related to some hex values. (it seems that it is getting a null value which is not in hex) Please not that this happens only with certain PDF files. All of them are non-corrupted PDFs and can be opened with any PDFViewer. This is the error I get: Traceback (most recent call last): File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 76, in files_recursively(path) File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 74, in files_recursively os.path.walk(path, process_file, ()) File "C:\Python27\lib\ntpath.py", line 263, in walk walk(name, func, arg) File "C:\Python27\lib\ntpath.py", line 259, in walk func(arg, top, names) File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 38, in process_file pdf = PdfFileReader(file( filename, "rb")) File "C:\Python27\lib\site-packages\pyPdf\pdf? line 374, in __init__ self.read(stream) File "C:\Python27\lib\site-packages\pyPdf\pdf? line 775, in read newTrailer = readObject(stream, self) File "C:\Python27\lib\site-packages\pyPdf\gen? line 67, in readObject return DictionaryObject.readFromStream(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 531, in readFromStream value = readObject(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 58, in readObject return ArrayObject.readFromStream(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 153, in readFromStream arr.append(readObject(stream, pdf)) File "C:\Python27\lib\site-packages\pyPdf\gen? line 69, in readObject return readHexStringFromStream(stream) File "C:\Python27\lib\site-packages\pyPdf\gen? line 276, in readHexStringFromStream txt += chr(int(x, base=16)) ValueError: invalid literal for int() with base 16: '\x00\x00' From nickle at gmail.com Mon Aug 8 08:37:34 2011 From: nickle at gmail.com (Nick) Date: Mon, 8 Aug 2011 05:37:34 -0700 (PDT) Subject: Docstrings and class Attributes Message-ID: Is it possible to put a doc string on a class attribute? Something like this class Test (object): '''classx''' fred = 10 '''attribute''' print Test.__doc__ print Test.fred.__doc__ This code produces this output classx int(x[, base]) -> integer Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. If base is zero, the proper base is guessed based on the string content. If the argument is outside the integer range a long object will be returned instead. =========== So the class doc string is return, but no doc string for the attribute. From phd at phdru.name Mon Aug 8 09:17:40 2011 From: phd at phdru.name (Oleg Broytman) Date: Mon, 8 Aug 2011 17:17:40 +0400 Subject: SQLObject 1.1.2 Message-ID: <20110808131740.GC24811@iskra.aviel.ru> Hello! I'm pleased to announce version 1.1.2, a bugfix release of branch 1.1 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.1.2 News and changes: http://sqlobject.org/News.html What's New ========== Features & Interface -------------------- * A bug was fixed in SelectResults slicing that prevented to slice a slice (my_results[:20][1:5]). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From mephisto_9000 at hotmail.com Mon Aug 8 11:17:07 2011 From: mephisto_9000 at hotmail.com (Francis Labarre) Date: Mon, 8 Aug 2011 11:17:07 -0400 Subject: Embedded python console and FILE* in python 3.2 Message-ID: Hello everyone, I'm currently trying to port some embedded code from python 2.7 to python 3.2. The current code replicate the basic behavior of the python interpreter in anMFC application. When a command is entered in our embedded interpreter, we write it to a FILE* then transform this FILE* into a Python file with the apifunction PyFile_FromFile and assign it to python's stdin. We also assign anotherFILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to executethe statement as the python interpreter normally would. Finally, we can easily retrievethe result of the execution from the output FILE*. This is currently the only approach we have found that allows us to retrieve the result of executing a statement exactly as the interpreter would. The problem is that the implementation of files has changed in python 3 and the functionPyFile_FromFile has been removed. Does anyone knows a way to achieve the same thing as this function either trough the io moduleor the python/C api? Or could there be a better approach to what we are trying to achieve? Keep in mind that we need to obtain the result of any statement, i.e. : If the command is "2+2" the result should be "4", if the command is "1/0" the result should be Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero Thank you, F.L. -------------- next part -------------- An HTML attachment was scrubbed... URL: From katriel at katriel.co.uk Mon Aug 8 11:31:20 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Mon, 8 Aug 2011 16:31:20 +0100 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: Is the `code` module (http://docs.python.org/library/code.html) an insufficiently exact copy of an interpreter for you? On Mon, Aug 8, 2011 at 4:17 PM, Francis Labarre wrote: > Hello everyone, > > I'm currently trying to port some embedded code from python 2.7 to python > 3.2. > > The current code replicate the basic behavior of the python interpreter in > an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to > execute > the statement as the python interpreter normally would. Finally, we > can easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 and > the function > PyFile_FromFile has been removed. > > Does anyone knows a way to achieve the same thing as this function either > trough the io module > or the python/C api? Or could there be a better approach to what we are > trying to achieve? > > Keep in mind that we need to obtain the result of any statement, i.e. : > > If the command is "2+2" the result should be "4", if the command is "1/0" > the result should be > > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero > > > Thank you, > > F.L. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 8 11:31:38 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 17:31:38 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: <4E40015A.3060401@jollybox.de> On 08/08/11 17:17, Francis Labarre wrote: > Hello everyone, > > I'm currently trying to port some embedded code from python 2.7 to > python 3.2. > > The current code replicate the basic behavior of the python interpreter > in an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne > to execute > the statement as the python interpreter normally would. Finally, we > can easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 > and the function > PyFile_FromFile has been removed. > > Does anyone knows a way to achieve the same thing as this function > either trough the io module > or the python/C api? Or could there be a better approach to what we are > trying to achieve? > > Keep in mind that we need to obtain the result of any statement, i.e. : > > If the command is "2+2" the result should be "4", if the command is > "1/0" the result should be > > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero > > > Thank you, > > F.L. > > I assume you could simply use PyFile_FromFd? The more elegant solution might be to create custom Python file-like objects for std{in,out,err} that communicate directly with your application. Thomas From philip at semanchuk.com Mon Aug 8 11:49:44 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 8 Aug 2011 11:49:44 -0400 Subject: WxPython and TK In-Reply-To: References: Message-ID: On Aug 7, 2011, at 8:26 PM, azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. > -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). I don't see how removing TK from the standard library helps to fill the native GUI development library void that you see in Python. I guess you're promoting wxPython as the library to fill that void. Getting rid of TK is one argument, adding wxPython is different argument. Are you advocating one, the other, or both? > If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. And if I had a dollar for every "Let's replace TK with XYZ" post, I'd also be a millionaire. I don't object to your argument; criticism of standard library is how it advances. But you're going to have to come up with a better argument than a 5+ year old quote from Guido and an exaggerated claim about why people don't use Python. The "best Python GUI library" conversation is repeated on this list at least once every few months. If the subject really interests you, I recommend that you read the archives and see some of the arguments for and against various GUI toolkits. Cheers Philip From tdldev at gmail.com Mon Aug 8 12:08:35 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 8 Aug 2011 12:08:35 -0400 Subject: smtp Message-ID: I'm working on learning various aspects of Py coding, and happened to review the smtplib docs this morning. I entered the sample code from http://www.python.org/doc//current/library/smtplib.html import smtplib def prompt(prompt): return raw_input(prompt).strip() fromaddr = prompt("From: ")toaddrs = prompt("To: ").split()print "Enter message, end with ^D (Unix) or ^Z (Windows):" # Add the From: and To: headers at the start!msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs)))while 1: try: line = raw_input() except EOFError: break if not line: break msg = msg + line print "Message length is " + repr(len(msg)) server = smtplib.SMTP('localhost')server.set_debuglevel(1)server.sendmail(fromaddr, toaddrs, msg)server.quit() and it returns - "TypeError" with no other information... It appears to be generated from the line msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs))) But I'm not sure why... Any input is appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 8 12:26:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 17:26:18 +0100 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 5:08 PM, Verde Denim wrote: > and it returns - > "TypeError" with no other information... > It appears to be generated from the line > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs))) > > But I'm not sure why... > I transcribed pieces manually from your code into Python 2.4.5 and didn't get an error. What did you enter at the From: and To: prompts? As a side point: Does anyone else feel that it's potentially confusing to have a function whose parameter has the same name as the function itself? This is straight from the example. ChrisA From ericsnowcurrently at gmail.com Mon Aug 8 12:41:09 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Mon, 8 Aug 2011 10:41:09 -0600 Subject: Docstrings and class Attributes In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: > Is it possible to put a doc string on a class attribute? Something > like this You can put a docstring on a property (which is a function): class Test(object): @property def fred(self): "attribute" return 10 Python syntax supports implicitly building docstrings only for modules, class definitions, and function definitions. -eric > > class Test (object): > ? ?'''classx''' > > ? ?fred = 10 > ? ?'''attribute''' > > print Test.__doc__ > print Test.fred.__doc__ > > This code produces this output > > classx > int(x[, base]) -> integer > > Convert a string or number to an integer, if possible. ?A floating > point > argument will be truncated towards zero (this does not include a > string > representation of a floating point number!) ?When converting a string, > use > the optional base. ?It is an error to supply a base when converting a > non-string. ?If base is zero, the proper base is guessed based on the > string content. ?If the argument is outside the integer range a > long object will be returned instead. > > =========== > > So the class doc string is return, but no doc string for the > attribute. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From tdldev at gmail.com Mon Aug 8 12:45:45 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 8 Aug 2011 12:45:45 -0400 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 12:26 PM, Chris Angelico wrote: > On Mon, Aug 8, 2011 at 5:08 PM, Verde Denim wrote: > > and it returns - > > "TypeError" with no other information... > > It appears to be generated from the line > > > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > > % (fromaddr, ", ".join(toaddrs))) > > > > But I'm not sure why... > > > > I transcribed pieces manually from your code into Python 2.4.5 and > didn't get an error. What did you enter at the From: and To: prompts? > > I'm running 2.6.5 on a debian base... It didn't seem to matter what is input - I tried using a single recipient as well as multiples (separated by comma). Output appears as - # python send_my_msg.py From: me at me.com To: you at you.com Enter Message, end with ^D: Traceback (most recent call last): File "send_my_msg.py", line 12, in % (fromaddr, ", ".join(toaddr))) TypeError > As a side point: Does anyone else feel that it's potentially confusing > to have a function whose parameter has the same name as the function > itself? This is straight from the example. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 8 13:07:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 18:07:50 +0100 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 5:45 PM, Verde Denim wrote: > I'm running 2.6.5 on a debian base... > It didn't seem to matter what is input - > I tried using a single recipient as well as multiples (separated by comma). Since the recipient list is divided using split(), you should separate multiple addresses with spaces. However, that won't cause your problem. I copied and pasted your exact code and tried it on three different versions. Obviously Python 3 didn't like it (print statements). Python 2.4.5 failed on importing _socket, so I assume there's a minimum version required. But 2.6.5 worked fine: From: foo at bar To: asdf at qwer Enter message, end with ^D (Unix) or ^Z (Windows): zxcvaasdf ssdfzxcv ^Z Message length is 49 Traceback (most recent call last): File "1test.py", line 24, in server = smtplib.SMTP('localhost') File "C:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "C:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "C:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "C:\Python26\lib\socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 10061] No connection could be made because the target machi ne actively refused it C:\> I don't have an SMTP server running on localhost, but the script worked fine. Can you quote a failing traceback please? It might be instructive. ChrisA From mephisto_9000 at hotmail.com Mon Aug 8 13:14:57 2011 From: mephisto_9000 at hotmail.com (F L) Date: Mon, 8 Aug 2011 13:14:57 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E40015A.3060401@jollybox.de> References: , <4E40015A.3060401@jollybox.de> Message-ID: > Is the `code` module (http://docs.python.org/library/code.html) an insufficiently exact copy of an interpreter for you? The problem isn't really to emulate the behavior of the interpreter as to obtain the result of the execution as a string in c++. The code module doesn't seem to help with this matter. > I assume you could simply use PyFile_FromFd? According to the documentation using PyFile_FromFd seems unadvised, but I'll give it a try. > The more elegant solution might be to create custom Python file-like> objects for std{in,out,err} that communicate directly with your application.I thought about this, but I need the console window to be non-modal and I'm afraid that replacing stdin witha custom file-like object would cause a blocking call. Executing python in a second thread would solve this problembut our application isn't multi-threaded and executing python in another thread causes errors. Maybe I could use a file-like object to communicate the results to my c++ application and use the code module to execute code only when the c++ application needs it. Thanks a lot for the tips, have a nice day. F.L. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Mon Aug 8 13:37:29 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 8 Aug 2011 12:37:29 -0500 Subject: PyCon US 2012 Survey - We need your input! Message-ID: Hi all, As we ramp up our efforts on PyCon US 2012, we wanted to gather some information from the community on what we can do best to serve you at the March 2012 conference in Santa Clara, CA. We've put together a survey about your experiences at past PyCons as well as what your interests are in the upcoming conference. We're interested in what speakers and topics you'd like to have at the tutorials, conference, and the poster sessions, as well as any input you have on what we can improve in other aspects of the event. If you have 5 minutes to spare, the survey is available at https://www.surveymonkey.com/s/pycon2012_launch_survey and results will be used to help us make PyCon 2012 the best conference yet. Thanks, The PyCon Organizers http://us.pycon.org/2012/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 8 13:44:23 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 19:44:23 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: , <4E40015A.3060401@jollybox.de> Message-ID: <4E402077.2020808@jollybox.de> On 08/08/11 19:14, F L wrote: >> Is the `code` module (http://docs.python.org/library/code.html) an > insufficiently exact copy of an interpreter for you? > > The problem isn't really to emulate the behavior of the interpreter as > to obtain the result of the execution as a string in c++. > The code module doesn't seem to help with this matter. > >> I assume you could simply use PyFile_FromFd? > > According to the documentation using PyFile_FromFd seems unadvised, but > I'll give it a try. > >> The more elegant solution might be to create custom Python file-like >> objects for std{in,out,err} that communicate directly with your application. > > I thought about this, but I need the console window to be non-modal and > I'm afraid that replacing stdin with > a custom file-like object would cause a blocking call. Executing python > in a second thread would solve this problem > but our application isn't multi-threaded and executing python in another > thread causes errors. If you use the same workflow as you do currently, it won't: 1. Feed input to your custom stdin object, which will buffer the code. 2. Call PyRun_IteractiveOne - it will read from your object, which will return the buffer contents. 3. The result is somehow handled by custom stdout and stderr objects. > > Maybe I could use a file-like object to communicate the results to my > c++ application and use the code > module to execute code only when the c++ application needs it. > From t at jollybox.de Mon Aug 8 13:52:14 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 19:52:14 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E402077.2020808@jollybox.de> References: , <4E40015A.3060401@jollybox.de> <4E402077.2020808@jollybox.de> Message-ID: <4E40224E.7080701@jollybox.de> On 08/08/11 19:44, Thomas Jollans wrote: > If you use the same workflow as you do currently, it won't: > > 1. Feed input to your custom stdin object, which will buffer the code. > 2. Call PyRun_IteractiveOne - it will read from your object, which will > return the buffer contents. > 3. The result is somehow handled by custom stdout and stderr objects. > Come to think of it, you might as well just use StringIO. From airween at gmail.com Mon Aug 8 14:06:18 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 8 Aug 2011 20:06:18 +0200 Subject: smtp In-Reply-To: References: Message-ID: <20110808180617.GA2544@arxnet.hu> hello, > > import smtplib > def prompt(prompt): > return raw_input(prompt).strip() > fromaddr = prompt("From: ")toaddrs = prompt("To: ").split()print > "Enter message, end with ^D (Unix) or ^Z (Windows):" > # Add the From: and To: headers at the start!msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs)))while 1: > try: > line = raw_input() > except EOFError: > break > if not line: > break > msg = msg + line > print "Message length is " + repr(len(msg)) > server = smtplib.SMTP('localhost')server.set_debuglevel(1)server.sendmail(fromaddr, > toaddrs, msg)server.quit() > > and it returns - > "TypeError" with no other information... > It appears to be generated from the line > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs))) > > But I'm not sure why... after I copied it to a script, I've got this result: From: airween at gmail.com To: airween at index.hu Enter message, end with ^D (Unix) or ^Z (Windows): Teszt Message length is 55 send: 'ehlo slave.myhost.hu\r\n' reply: '250-ns2.myhost.hu\r\n' reply: '250-PIPELINING\r\n' reply: '250-SIZE 10240000\r\n' reply: '250-VRFY\r\n' reply: '250-ETRN\r\n' reply: '250-STARTTLS\r\n' reply: '250-AUTH PLAIN LOGIN\r\n' reply: '250-AUTH=PLAIN LOGIN\r\n' reply: '250-ENHANCEDSTATUSCODES\r\n' reply: '250-8BITMIME\r\n' reply: '250 DSN\r\n' reply: retcode (250); Msg: ns2.myhost.hu PIPELINING SIZE 10240000 VRFY ETRN STARTTLS AUTH PLAIN LOGIN AUTH=PLAIN LOGIN ENHANCEDSTATUSCODES 8BITMIME DSN send: 'mail FROM: size=55\r\n' reply: '250 2.1.0 Ok\r\n' reply: retcode (250); Msg: 2.1.0 Ok send: 'rcpt TO:\r\n' reply: '250 2.1.5 Ok\r\n' reply: retcode (250); Msg: 2.1.5 Ok send: 'data\r\n' reply: '354 End data with .\r\n' reply: retcode (354); Msg: End data with . data: (354, 'End data with .') send: 'From: airween at gmail.com\r\nTo: airween at index.hu\r\n\r\nTeszt\r\n.\r\n' reply: '250 2.0.0 Ok: queued as 643F144002\r\n' reply: retcode (250); Msg: 2.0.0 Ok: queued as 643F144002 data: (250, '2.0.0 Ok: queued as 643F144002') send: 'quit\r\n' reply: '221 2.0.0 Bye\r\n' reply: retcode (221); Msg: 2.0.0 Bye And there is that mail in my inbox... Debian Lenny, Python 2.5.2 a. From mephisto_9000 at hotmail.com Mon Aug 8 14:06:48 2011 From: mephisto_9000 at hotmail.com (F L) Date: Mon, 8 Aug 2011 14:06:48 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E40224E.7080701@jollybox.de> References: , , <4E40015A.3060401@jollybox.de>, , <4E402077.2020808@jollybox.de>, <4E40224E.7080701@jollybox.de> Message-ID: > If you use the same workflow as you do currently, it won't You're right it shouldn't cause a blocking call. > Come to think of it, you might as well just use StringIO. Yes I could probably replace std{in, out, err} with stringIO objects and retrieve their contents throughthe api. I'll look into it, thank again. F.L. > Date: Mon, 8 Aug 2011 19:52:14 +0200 > From: t at jollybox.de > To: python-list at python.org > Subject: Re: Embedded python console and FILE* in python 3.2 > > On 08/08/11 19:44, Thomas Jollans wrote: > > > > > 1. Feed input to your custom stdin object, which will buffer the code. > > 2. Call PyRun_IteractiveOne - it will read from your object, which will > > return the buffer contents. > > 3. The result is somehow handled by custom stdout and stderr objects. > > > > Come to think of it, you might as well just use StringIO. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 8 14:17:38 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:17:38 -0400 Subject: Docstrings and class Attributes In-Reply-To: References: Message-ID: On 8/8/2011 8:37 AM, Nick wrote: > Is it possible to put a doc string on a class attribute? Class and function docstrings are generated from string expression statements at the beginning of a suite. > class Test (object): > '''classx''' > > fred = 10 > '''attribute''' This is two statements that have no particular connection with each other. > print Test.__doc__ > print Test.fred.__doc__ > > This code produces this output > > classx > int(x[, base]) -> integer ... If an instance does not have a requested attribute, it is looked up on its class (and superclasses). Since all classes are subclasses of object and that has a docstring, I guess everything will. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Aug 8 14:26:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 04:26:09 +1000 Subject: Docstrings and class Attributes References: Message-ID: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >> Is it possible to put a doc string on a class attribute? Something >> like this > > You can put a docstring on a property (which is a function): > > class Test(object): > @property > def fred(self): > "attribute" > return 10 Which, however, doesn't really help: >>> t = Test() >>> t.fred.__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' The problem is that t.fred returns an integer, so t.fred.__doc__ returns the docstring from the integer, not for the property. >>> t.__class__.fred.__doc__ 'attribute' -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 8 14:32:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 04:32:18 +1000 Subject: Docstrings and class Attributes References: Message-ID: <4e402bb4$0$29990$c3e8da3$5496439d@news.astraweb.com> Nick wrote: > Is it possible to put a doc string on a class attribute? Something > like this > > class Test (object): > '''classx''' > fred = 10 > '''attribute''' The short answer is, no. The longer answer is, maybe, if you can make Test.fred be some sort of object with a docstring: class MyInt(int): '''attribute''' class Test(object): '''classx''' fred = MyInt(10) >>> Test.fred.__doc__ 'attribute' But the hard part is ensuring that Test.fred doesn't get replaced: >>> Test.fred = 11 >>> Test.fred.__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number ...' Not impossible to solve, but an awful lot of trouble for very little benefit. Just put your documentation in the class, where people expect to find it: class Test(object): '''classx Test.fred is an attribute. ''' fred = 10 -- Steven From tjreedy at udel.edu Mon Aug 8 14:35:10 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:35:10 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: On 8/8/2011 11:17 AM, Francis Labarre wrote: > Hello everyone, > > I'm currentlytrying to port some embedded code from python 2.7 to python > 3.2. > > The current code replicate the basic behavior of the python interpreter > in an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne > to execute > the statement as the python interpreter normally would. Finally, we can > easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 > and the function > PyFile_FromFile has been removed. The source for the function is still available in 2.7. You might be able to adapt it to work in 3.x. IDLE imitates the interactive interpreter by running code in a separate non-console pythonw process. There have been issues with getting that to work right on Windows (see issue 12540), but it works well when it does. Depending on your use case, this might work for you too. Communication is through (wrapped) OS pipes, not normal Python file objects. -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 14:48:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:48:21 -0400 Subject: Docstrings and class Attributes In-Reply-To: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/8/2011 2:26 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >>> Is it possible to put a doc string on a class attribute? This really makes little sense. The purpose of docstrings is to give interactive help. The place to document data attributes of a class is in the class docstring. The value of an int is considered to be self-explanatory. >> You can put a docstring on a property (which is a function): >> >> class Test(object): >> @property >> def fred(self): >> "attribute" >> return 10 > > Which, however, doesn't really help: > >>>> t = Test() >>>> t.fred.__doc__ > 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' > > > The problem is that t.fred returns an integer, so t.fred.__doc__ returns the > docstring from the integer, not for the property. > >>>> t.__class__.fred.__doc__ > 'attribute' Which is to say, the descriptor protocol allows custom get, set, and delete methods, but not an attribute-specific getattribute method ;-). -- Terry Jan Reedy From ethan at stoneleaf.us Mon Aug 8 14:58:21 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 08 Aug 2011 11:58:21 -0700 Subject: Docstrings and class Attributes In-Reply-To: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4031CD.3070204@stoneleaf.us> Steven D'Aprano wrote: > Eric Snow wrote: > >> On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >>> Is it possible to put a doc string on a class attribute? Something >>> like this >> You can put a docstring on a property (which is a function): >> >> class Test(object): >> @property >> def fred(self): >> "attribute" >> return 10 > > Which, however, doesn't really help: > >--> t = Test() >--> t.fred.__doc__ > 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' > > > The problem is that t.fred returns an integer, so t.fred.__doc__ returns the > docstring from the integer, not for the property. > >--> t.__class__.fred.__doc__ > 'attribute' So if property docstrings are so hard to get to, what's the point in having them? ~Ethan~ From steve+comp.lang.python at pearwood.info Mon Aug 8 15:05:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 05:05:36 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > So if property docstrings are so hard to get to, what's the point in > having them? Hard to get, not impossible. But I have no idea really -- they don't seem very useful to me. -- Steven From tjreedy at udel.edu Mon Aug 8 15:06:06 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:06:06 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:26 PM, Chris Angelico wrote: > As a side point: Does anyone else feel that it's potentially confusing > to have a function whose parameter has the same name as the function > itself? This is straight from the example. Yes. I might change it someday when I can. -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 15:07:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:07:11 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:08 PM, Verde Denim wrote: > I'm working on learning various aspects of Py coding, and happened to > review the smtplib docs this morning. > I entered the sample code from > http://www.python.org/doc//current/library/smtplib.html When posting about error messages, please specify Python version used and copy *entire* traceback -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 15:11:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:11:36 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:45 PM, Verde Denim wrote: > I'm running 2.6.5 on a debian base... > It didn't seem to matter what is input - > I tried using a single recipient as well as multiples (separated by comma). > > Output appears as - > # python send_my_msg.py > From: me at me.com > To: you at you.com > Enter Message, end with ^D: > Traceback (most recent call last): > File "send_my_msg.py", line 12, in > % (fromaddr, ", ".join(toaddr))) > TypeError I am concerned about the lack of any message. It is close to being a bug. If this happens with current Python, 2.7.2 or 3.2.1, posting to the bug tracker a minimal example needed to get the above might result in a fix. -- Terry Jan Reedy From ckaynor at zindagigames.com Mon Aug 8 15:22:33 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 8 Aug 2011 12:22:33 -0700 Subject: Docstrings and class Attributes In-Reply-To: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: They are actually quite easy to get to. help() on both the class or instance produces the docstring, and __doc__ on the property as accessed from the class produces the docstring. >>> class Test(object): ... @property ... def fred(self): ... """*This is a docstring.*""" ... return 1 ... >>> help(Test) Help on class Test in module __main__: class Test(__builtin__.object) | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | fred | *This is a docstring.* >>> Test.fred.__doc__ '*This is a docstring*.' >>> t = Test() >>> t.fred.__doc__ 'int(x[, base]) -> integer\n\n...' >>> help(t) Help on Test in module __main__ object: class Test(__builtin__.object) | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | fred | *This is a docstring.* Chris On Mon, Aug 8, 2011 at 12:05 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Ethan Furman wrote: > > > So if property docstrings are so hard to get to, what's the point in > > having them? > > Hard to get, not impossible. But I have no idea really -- they don't seem > very useful to me. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Mon Aug 8 15:24:11 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Mon, 8 Aug 2011 13:24:11 -0600 Subject: Docstrings and class Attributes In-Reply-To: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 8, 2011 at 1:05 PM, Steven D'Aprano wrote: > Ethan Furman wrote: > >> So if property docstrings are so hard to get to, what's the point in >> having them? > > Hard to get, not impossible. But I have no idea really -- they don't seem > very useful to me. They do show up in help(), but not as some sort of data-attribute docstring. -eric > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From croepha at gmail.com Mon Aug 8 15:50:44 2011 From: croepha at gmail.com (Croepha) Date: Mon, 8 Aug 2011 14:50:44 -0500 Subject: Object Diffs Message-ID: Hello Python list: I am doing research into doing network based propagation of python objects. In order to maintain network efficiency. I wan't to just send the differences of python objects, I was wondering if there was/is any other research or development in this area? I was thinking that I could look at how pickle works an implement a diff system there, or I could actually create a pickle of the object and then use difflib to compare the flattened text... Ideas, or comments welcome Thanks, Dave Butler From rosuav at gmail.com Mon Aug 8 18:10:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 23:10:25 +0100 Subject: Object Diffs In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 8:50 PM, Croepha wrote: > I am doing research into doing network based propagation of python > objects. ?In order to maintain network efficiency. I wan't to just > send the differences of python objects You could send pickled versions of each of the object's attributes, rather than the whole object. Then simply have a notation for "same as before", and you are sending the delta of attributes. If your set of important attributes is stable, this could be quite efficient. OTOH, this won't help if your attributes are complex structures for which you want to send detailed diffs, that won't work. Another way would be to pickle the object, and then use any string diff utility to find the significant portions. I don't know whether pickle is guaranteed to be stable on dictionaries, though; you might get a lot of "diff noise". ChrisA From drsalists at gmail.com Mon Aug 8 20:11:39 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 8 Aug 2011 17:11:39 -0700 Subject: Object Diffs In-Reply-To: References: Message-ID: You probably need a recursive algorithm to be fully general, and yes, looking at pickle might be a good place to start. Note that pickle can't pickle everything, but it can handle most things. Also check out NX - not the CPU feature, but the (re)transmission compressing software (there are two different things with the name "NX"). NX is remarkably good at dealing with things like VNC sessions with virtual desktops, as long as you don't throw a movie at it - and it's more general than just doing VNC. Note that sometimes computing a diff and sending the differences may end up being slower than transmitting the whole object. You might also check out pyro and similar tools. On Mon, Aug 8, 2011 at 12:50 PM, Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... > > Ideas, or comments welcome > > Thanks, > Dave Butler > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 8 20:23:42 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 20:23:42 -0400 Subject: Object Diffs In-Reply-To: References: Message-ID: On 8/8/2011 3:50 PM, Croepha wrote: > Hello Python list: Hi > I am doing research into doing network based propagation of python > objects.In order to maintain network efficiency. I want to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... The problem cannot be tackled efficiently 'in general'. The important issue is to choose a representation that localizes differences in a particular application so that the diff is significantly smaller than just sending the changed version. Source code systems regard files as sequences of lines. That is ok for formatted source code, not so good for prose in paragraphs where a small change in one line may cause re-wrapping that changes 20 lines. Compressed representations that spread the effect of localized changes are also bad for local diffs. A representation that arbitrarily orders items (and re-orders items at will), is also bad for local diffs. I have no idea how stable and local pickles are, but I know they were not designed for diff-ing. Json or yaml representations might do better if applicable. -- Terry Jan Reedy From python at bdurham.com Mon Aug 8 20:31:03 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 08 Aug 2011 20:31:03 -0400 Subject: Object Diffs In-Reply-To: References: Message-ID: <1312849863.32603.2160966673@webmail.messagingengine.com> Croepha, You may find it simpler and sufficiently efficient to compress your objects in whatever format they exist (pickle, json, xml, etc) and send the compressed equivalents vs. trying to diff on side and reassemble on the other side. Malcolm From steve+comp.lang.python at pearwood.info Mon Aug 8 20:32:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 10:32:07 +1000 Subject: Object Diffs References: Message-ID: <4e408009$0$29998$c3e8da3$5496439d@news.astraweb.com> Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, Can you explain in more detail what you mean? Are there constraints on what the objects can be? If you have two objects: a = None b = (1, 2, "hello world", []) how would you describe the diff between a and b? If a and b are both numbers, the diff between them is just a-b, but this itself is a number and so transmitting it takes exactly as much memory as just sending b. Obviously if a and b are strings, the problem becomes trivial (just transmitted the string diff, which is a solved problem). > I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... The source code for pickle is available. See the pickle.py and pickletools.py files in your Python installation. Also, these resources may help: http://wiki.python.org/moin/DistributedProgramming http://wiki.python.org/moin/ParallelProcessing -- Steven From rosuav at gmail.com Mon Aug 8 20:34:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 01:34:56 +0100 Subject: Object Diffs In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 1:23 AM, Terry Reedy wrote: > I have no idea how stable and local pickles are, but I know they were not > designed for diff-ing. Json or yaml representations might do better if > applicable. > In terms of stability, you'd probably have to have a rule that dictionaries are sorted by their keys before being encoded. Currently I can think of only one spec that requires that, and that's the .torrent file definition (it's mandated so that the info hash is stable). It may be necessary to build your own encoder routine to enforce this; you could still use a standard format, which will mean that a standard decoder will work fine. Depending on what you're doing, though, it might well be easier to abandon the entire notion of pickling an object and sending it, and instead send higher-level conceptual data. I've always been a bit leery of systems that let you "send an object" from one computer to another, because they're so easily misused; instead of sending the data that's needed at the other end, an entire complex object is sent, and the far end extracts the data it wants. Not only does a ridiculous amount of unnecessary data get encoded, transmitted, and decoded, but sometimes it can have security implications (such as a certain multiplayer game that reveals to any player the identities of all other players, including their login email addresses and IP addresses). ChrisA From ben+python at benfinney.id.au Mon Aug 8 20:36:12 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Aug 2011 10:36:12 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vr3ju9v.fsf@benfinney.id.au> Ethan Furman writes: > So if property docstrings are so hard to get to, what's the point in > having them? Why would you expect there be a special point to them? Men, like all primates of any sex, have nipples. Properties, like any function in Python, have docstrings. They're an accident of the history that led to their implementation, and of the pre-existing parts that they're built from. There doesn't need to be a point to them (though they might be useful for reasons incidental for the reasons they exist). -- \ ?I filled my humidifier with wax. Now my room is all shiny.? | `\ ?Steven Wright | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Mon Aug 8 20:51:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 10:51:10 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> Message-ID: <4e40847f$0$29969$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Ethan Furman writes: > >> So if property docstrings are so hard to get to, what's the point in >> having them? > > Why would you expect there be a special point to them? > > Men, like all primates of any sex, have nipples. > > Properties, like any function in Python, have docstrings. > > They're an accident of the history that led to their implementation, and > of the pre-existing parts that they're built from. There doesn't need to > be a point to them (though they might be useful for reasons incidental > for the reasons they exist). But properties *aren't* functions, they are objects which obey the descriptor protocol. Perhaps you are thinking of the individual getter, setter and deleter parameters to property(). If so, then your comment is relevant as far as it goes to the docstrings on the individual getter/setter/deleter functions. But property() itself explicitly takes a docstring parameter. It is that docstring that seems of limited value, except that Eric Snow has pointed out that help(instance) will display property help strings. -- Steven From ben+python at benfinney.id.au Mon Aug 8 21:28:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Aug 2011 11:28:37 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <4e40847f$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871uwvjrui.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > They're an accident of the history that led to their implementation, > > and of the pre-existing parts that they're built from. There doesn't > > need to be a point to them (though they might be useful for reasons > > incidental for the reasons they exist). > > But property() itself explicitly takes a docstring parameter. It is > that docstring that seems of limited value, except that Eric Snow has > pointed out that help(instance) will display property help strings. I had forgotten that there is explicit support for adding a docstring to the property itself. That does raise the question of why :-/ Oh well, I like the analogy and will find a better place soon to force-fit it to a technical discussion :-) -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From ameetn at qualcomm.com Mon Aug 8 21:46:19 2011 From: ameetn at qualcomm.com (Nanda, Ameet) Date: Tue, 9 Aug 2011 01:46:19 +0000 Subject: Network shares in Windows Message-ID: Hi All, I was trying to access a network shared folder on a windows network. I couldn' t find of a good documentation online to do that. Are there any recommendations on how to do it in windows. So if my folder is shared as \\ameetn\Dropbox and when I am trying to open it up, it says I don't have privileges to open it every time I try doing that. >>> open("\\\\ameetn\\Dropbox") Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '\\\\ameetn\\Dropbox' Al though I try this from the administrator cmd, I still get the same error. Can anyone please recommend me a good way to do this. Thanks, Ameet -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Aug 8 21:53:30 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 09 Aug 2011 02:53:30 +0100 Subject: Network shares in Windows In-Reply-To: References: Message-ID: <4E40931A.9070902@mrabarnett.plus.com> On 09/08/2011 02:46, Nanda, Ameet wrote: > Hi All, > > I was trying to access a network shared folder on a windows network. I > couldn? t find of a good documentation online to do that. Are there any > recommendations on how to do it in windows. So if my folder is shared as > \\ameetn\Dropbox and when I am trying to open > it up, it says I don?t have privileges to open it every time I try doing > that. > > >>> open("\\\\ameetn\\Dropbox") > > Traceback (most recent call last): > > File "", line 1, in > > IOError: [Errno 13] Permission denied: '\\\\ameetn\\Dropbox' > > Al though I try this from the administrator cmd, I still get the same > error. Can anyone please recommend me a good way to do this. > \\ameetn\Dropbox is a folder. 'open' is for opening files. If \\ameetn\Dropbox\foo is the path to a file, then: f = open(r"\\ameetn\Dropbox\foo") will open it. From vijay.murthy at gmail.com Tue Aug 9 01:37:13 2011 From: vijay.murthy at gmail.com (Vijay Anantha Murthy) Date: Tue, 9 Aug 2011 00:37:13 -0500 Subject: Need help with Python to C code compiler Message-ID: Hi All, Is there any compiler which will help me convert my python code to proper C code? In my python code I am using the XML.dom.minidom module to parse an xml and process the results obtained by ElementsByTagName. I don't know of any such compiler which will help me convert this kind of python code to C code. My intention is to convert python code to a readable C code which can later be compile to an .exe file. Cython will not be of much use to me as it is in the end writing c extensions which will later be used in python. However, I wish to use this as a proper readable C code which can later be shared with users - the c source code as well as the exe along with its corresponding .py file. My main impediment here is writing out the C code manually myself, my C skills are quite poor and it would require a huge effort to sharpening my C skills before writing the code myself, I can not afford that luxury of time. I was surfing and came across shedskin, but that might not just support the xml minidom module for my purposes. Thanks, Vijay -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue Aug 9 02:09:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 8 Aug 2011 23:09:19 -0700 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: Shedskin is one option - if it doesn't have the modules you need, you could try finding pure python versions of them and translating them too, along with your own code. Cython is probably the one I hear the most about. On Mon, Aug 8, 2011 at 10:37 PM, Vijay Anantha Murthy < vijay.murthy at gmail.com> wrote: > Hi All, > > Is there any compiler which will help me convert my python code to proper C > code? > In my python code I am using the XML.dom.minidom module to parse an xml and > process the results obtained by ElementsByTagName. > I don't know of any such compiler which will help me convert this kind of > python code to C code. > > My intention is to convert python code to a readable C code which can later > be compile to an .exe file. > Cython will not be of much use to me as it is in the end writing c > extensions which will later be used in python. > However, I wish to use this as a proper readable C code which can later be > shared with users - the c source code as well as the exe along with its > corresponding > .py file. > > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. > > I was surfing and came across shedskin, but that might not just support the > xml minidom module for my purposes. > > Thanks, > Vijay > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Aug 9 02:22:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 16:22:42 +1000 Subject: PyPy installed on old Linux Message-ID: <4e40d234$0$30003$c3e8da3$5496439d@news.astraweb.com> Has anyone here had any experience installing PyPy on Fedora 7? -- Steven From stefan_ml at behnel.de Tue Aug 9 04:18:52 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Aug 2011 10:18:52 +0200 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: Vijay Anantha Murthy, 09.08.2011 07:37: > Is there any compiler which will help me convert my python code to proper C > code? > In my python code I am using the XML.dom.minidom module to parse an xml and > process the results obtained by ElementsByTagName. > I don't know of any such compiler which will help me convert this kind of > python code to C code. It will certainly help much more to migrate your code to ElementTree first. See the xml.etree.cElementTree package, and also the external lxml.etree package. MiniDOM is known to have severe performance problems, including a huge memory overhead. > My intention is to convert python code to a readable C code which can later > be compile to an .exe file. Have a look at py2exe then. > Cython will not be of much use to me as it is in the end writing c > extensions which will later be used in python. So? You can just bundle CPython with it. Cython can directly generate the necessary code for embedding the runtime. > However, I wish to use this as a proper readable C code which can later be > shared with users - the c source code as well as the exe along with its > corresponding .py file. Cython will mostly give you that. It may not produce the most obvious C code in some cases, because it is an optimising compiler, but it's readable (especially in the annotated HTML version), and it allows you to ship your C code with your .py file, thus avoiding a user dependency on Cython. > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. That perfectly hits one of the more important use cases Cython is made for. > I was surfing and came across shedskin, but that might not just support the > xml minidom module for my purposes. Shedskin produces very fast code and generates stand-alone modules. However, it's not meant to compile Python code at all, rather a statically typed subset of the language. That implies that most Python code won't compile unchanged with it. Cython is much closer to Python semantics and capable of compiling a huge amount of existing Python code. Plus, it generates fast code and provides a very straight forward path for optimising the compiled code. There are other compilers listed here, although none of them has actual advantages over Cython and Shedskin: http://wiki.python.org/moin/PythonImplementations#Compilers Stefan From rosuav at gmail.com Tue Aug 9 04:22:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 09:22:24 +0100 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 6:37 AM, Vijay Anantha Murthy wrote: > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. Writing code is a skill. You'll seldom get as readable code out of an automated conversion utility than you would get by having an expert hand-write the code; properly-rewritten code will look at the intent behind the code, not just the current code. I recommend either learning C, or accepting Cython or Shedskin. Chris Angelico From python at hope.cz Tue Aug 9 07:10:31 2011 From: python at hope.cz (Johny) Date: Tue, 9 Aug 2011 04:10:31 -0700 (PDT) Subject: How to solve this problem Message-ID: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> I have a client that is a part of a local network.This client has a local address( not public).Is there a way how I can connect to this client from outside world? What software must I install so that I can connect and control that client from outside? Thanks B From gb at como.it Tue Aug 9 07:12:02 2011 From: gb at como.it (gb at como.it) Date: Tue, 09 Aug 2011 13:12:02 +0200 Subject: WxPython and TK References: Message-ID: <86pqkeon3x.fsf@aiuole.stru.polimi.it> azrael writes: > OK, now. Isn't it maybe time to throw out TK once and for all? no, because Tk has a clear advantage over many other UI tolkits Tk _was designed_ and it was designed by very competent people [1] good luck with smurfs' hunting [2], ciao gb [1]: 1986-91 ACM's Grace Murray Hopper Awards 1986 William N. Joy, BSD Unix, Sun; 1987 John Ousterhout, Tcl/TK; 1988 Guy L. Steele, Scheme, Java; 1989 W. Daniel Hillis Thinking Machines; 1990 Richard Stallman Emacs, Gcc, FSF; 1991 Feng-hsiung Hsu Deep Blue; [2] http://www.smurf.com/smurf.php/www/who/en/azrael From katriel at katriel.co.uk Tue Aug 9 07:33:29 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Tue, 9 Aug 2011 12:33:29 +0100 Subject: How to solve this problem In-Reply-To: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: Unless you have the router configured to allow connections through to your local client, you will need the client to connect *outwards*, either to you or to an intermediate server. On Tue, Aug 9, 2011 at 12:10 PM, Johny wrote: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? > > Thanks > > B > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 9 07:33:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 12:33:35 +0100 Subject: How to solve this problem In-Reply-To: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: On Tue, Aug 9, 2011 at 12:10 PM, Johny wrote: > I have a client that ?is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? Presumably you are using NAT (Network Address Translation). You'll need to arrange for a port (or a set of ports) to be forwarded to that computer, which is done by configuring your NAT router. In a simple home network, this usually means logging in using the router's home page, such as http://192.168.0.1/ or http://192.168.1.1/ (it'll be the same as your default gateway); otherwise, talk to your network admin about it. The port or ports that you need to forward will depend on what you mean by "connect and control". For SSH, that's port 22; for VNC, port 5900. Other services are on other ports. By the way, this is a networking question, not a Python one. Chris Angelico From jana1972 at centrum.cz Tue Aug 9 07:46:34 2011 From: jana1972 at centrum.cz (jana1972 at centrum.cz) Date: Tue, 09 Aug 2011 13:46:34 +0200 Subject: How to solve this problem Message-ID: <4E413A3A.24482.5AD192@jana1972.centrum.cz> I have a client that is a part of a local network.This client has a local address( not public).Is there a way how I can connect to this client from outside world? What software must I install so that I can connect and control that client from outside? Thanks B From szager at gmail.com Tue Aug 9 08:47:33 2011 From: szager at gmail.com (Stefan Zager) Date: Tue, 9 Aug 2011 05:47:33 -0700 Subject: [Swig-user] Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 3:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyossim >>>> > * Do some stuff * >>>> exit() > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ I'm sorry, but that's not enough information to debug the problem. Please provide a minimal complete test case which demonstrates the problem. Thanks, Stefan From wafflesouffle at gmail.com Tue Aug 9 09:07:23 2011 From: wafflesouffle at gmail.com (WaffleSouffle) Date: Tue, 9 Aug 2011 06:07:23 -0700 (PDT) Subject: os.path.dirname(sys.argv[0]) always returns nothing References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> <99osqsFk1aU1@mid.individual.net> Message-ID: On Aug 2, 12:57?am, Gregory Ewing wrote: > Thijs Engels wrote: > > argv[0] returns the name of the current file (string), but no path > > information if I recall correct. > > It's the path that was used to specify the script by whatever > launched it, so it could be either absolute or relative to > the current directory. > > -- > Greg >From the docs there are a couple of special cases: "If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string." So if you're running in a python interpreter compiled into an executable which doesn't initialise argv, that's another case where things won't go as expected. That's probably not relevant in this case, but I've certainly been bitten by it in the past. From ulrich.eckhardt at dominolaser.com Tue Aug 9 10:26:01 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 09 Aug 2011 16:26:01 +0200 Subject: How to solve this problem References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: Johny wrote: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? How is that a Python problem? Ask your network admin to configure something like port forwarding. Also, take a look at Eric S. Raymond's essay on asking smart questions, there are at least three things detailed there which you are doing wrong and where you are standing in your own way. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From gordon at panix.com Tue Aug 9 10:26:13 2011 From: gordon at panix.com (John Gordon) Date: Tue, 9 Aug 2011 14:26:13 +0000 (UTC) Subject: How to solve this problem References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: In <81a681e7-0be1-4edc-9e27-b492e8b6371f at a17g2000yqk.googlegroups.com> Johny writes: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? When you say the client's address is "not public", what do you mean exactly? Can the client initiate connections to the outside network? Is the client behind a firewall? > What software must I install so that I can connect and control that > client from outside? Perhaps you should ask your network administrators. And what does this question have to do with python? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ethan at stoneleaf.us Tue Aug 9 12:34:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 09 Aug 2011 09:34:23 -0700 Subject: __all__ Message-ID: <4E41618F.5010105@stoneleaf.us> Greetings! Does anyone know/recall the original purpose of __all__? I had thought it was primarily to specify what would be imported when `from ... import *` was executed, such as for tk; today, it seems it is also used to specify the API for the module, and so the help() subsystem will only provide details for those items found in __all__. The issue I'm having with this is that there are roughly a dozen items I would like to make available via the `import *` mechanism in my dbf module, and another dozen that, while part of the public API, don't need to be available via an `import *`. History lessons, as well as ideas, welcomed! ~Ethan~ From steve+comp.lang.python at pearwood.info Tue Aug 9 12:57:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 02:57:40 +1000 Subject: __all__ References: Message-ID: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > Greetings! > > Does anyone know/recall the original purpose of __all__? To customise the names available for `from ... import *`: http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > I had thought it was primarily to specify what would be imported when > `from ... import *` was executed, such as for tk; Yes, that was the original use. If __all__ is not defined, Python will import everything that doesn't start with an underscore. > today, it seems it is > also used to specify the API for the module, and so the help() subsystem > will only provide details for those items found in __all__. The two meanings are assumed to be synonymous: names in the public API should be importable with *, and importable names should be in the public API. You can't specify "this can be imported with *, but isn't public" or "this is public, but not importable with *". http://docs.python.org/reference/simple_stmts.html#index-1090 Also, the behaviour of __all__ with packages may be slightly different: http://docs.python.org/tutorial/modules.html#index-1134 > The issue I'm having with this is that there are roughly a dozen items I > would like to make available via the `import *` mechanism in my dbf > module, and another dozen that, while part of the public API, don't need > to be available via an `import *`. You have to choose both, or neither, but you can't have just one. -- Steven From manuel.graune at koeln.de Tue Aug 9 12:59:09 2011 From: manuel.graune at koeln.de (Manuel Graune) Date: Tue, 09 Aug 2011 18:59:09 +0200 Subject: numpy/scipy: calculate definite integral of sampled data Message-ID: <87ty9qttb6.fsf@uriel.graune.org> Hi everyone, to calculate the definite integral of a function or an array of sampled data scipy provides (among others) the quad and trapz functions. So it is possible to compute e. g. the definite integral of cos(t) over some range by doing definite_integral= scipy.integrate.quad(cos,lower_limit,upper_limit) or definite_integral= scipy.integrate.trapz(some_array). Now, if I want to plot cos(t) and the integral of cos(t) from 0 to t in a graph, the necessary array can be calculated by: @numpy.vectorize def intfunc(fnc,upper_limit): return scipy.integrate.quad(fnc,0.0,upper_limit) definite_inegral= intfunc(cos,t) which seems (whithout knowing the actual code) a bit wasteful and slow but is relatively concise. Now for my question: scipy provides e. g. the trapz-function to calculate definite integral of a complete array of sampled data. However, I have no idea how to get achieve the same as above for sampled data (apart from manually iterating in a for-loop). Is there a function somewhere which delivers an array of the definite integrals for each of the data-points in an array? Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From chichimeco at gmail.com Tue Aug 9 13:02:25 2011 From: chichimeco at gmail.com (Antonio Vera) Date: Tue, 9 Aug 2011 10:02:25 -0700 (PDT) Subject: Passing every element of a list as argument to a function Message-ID: Hi!, I have a very simple syntax question. I want to evaluate a library function f receiving an arbitrary number of arguments (like itertools.product), on the elements of a list l. This means that I want to compute f(l[0],l[1],...,l[len(l)-1]). Is there any operation "op" such that f(op(l)) will give the sequence of elements of l as arguments to f? Thanks for your time. Best, Antonio From Tim.Arnold at sas.com Tue Aug 9 13:07:01 2011 From: Tim.Arnold at sas.com (Tim Arnold) Date: Tue, 09 Aug 2011 13:07:01 -0400 Subject: multiprocessing timing issue Message-ID: Hi, I'm having problems with an empty Queue using multiprocessing. The task: I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. I'm using multiprocessing to do the data-gathering simultaneously. Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. My problem is that sometimes the Queue is empty and I guess it's because the get_data() method takes a lot of time. I've used multiprocessing before, but never with a Queue like this. Any notes or suggestions are very welcome. The task starts off with: Reporter(chapters).report() thanks, --Tim Arnold from Queue import Empty from multiprocessing import Process, Queue def run_mp(objects,fn): q = Queue() procs = dict() for obj in objects: procs[obj['name']] = Process(target=fn, args=(obj,q)) procs[obj['name']].start() return q class Reporter(object): def __init__(self, chapters): self.chapters = chapters def report(self): q = run_mp(self.chapters, self.get_data) for i in range(len(self.chapters)): try: data = q.get(timeout=30) except Empty: print 'Report queue empty at %s' % (i) else: self.update_report(data) def get_data(self, chapter, q): data = expensive_calculations() q.put(data) def update_report(self, data): db connection, etc. From rosuav at gmail.com Tue Aug 9 13:29:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 18:29:16 +0100 Subject: Passing every element of a list as argument to a function In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 6:02 PM, Antonio Vera wrote: > Hi!, > I have a very simple syntax question. I want to evaluate a library > function f receiving an arbitrary number of arguments (like > itertools.product), on the elements of a list l. This means that I > want to compute f(l[0],l[1],...,l[len(l)-1]). > > Is there any operation "op" such that f(op(l)) will give the sequence > of elements of l as arguments to f? Yep! f(*l) Chris Angelico From irmen at -NOSPAM-xs4all.nl Tue Aug 9 13:57:30 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Tue, 09 Aug 2011 19:57:30 +0200 Subject: Object Diffs In-Reply-To: References: Message-ID: <4e41750a$0$23871$e4fe514c@news2.news.xs4all.nl> On 08-08-11 21:50, Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... > > Ideas, or comments welcome > No Python code, but you may want to have a look at the DeltaCompressor of the Kryo serializer (written for Java). http://code.google.com/p/kryo/ (disclaimer: I haven't used it, just read a little bit about it) Irmen From ramit.prasad at jpmorgan.com Tue Aug 9 16:11:58 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 9 Aug 2011 16:11:58 -0400 Subject: Passing every element of a list as argument to a function In-Reply-To: References: Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA772C069@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of Antonio Vera Sent: Tuesday, August 09, 2011 12:02 PM To: python-list at python.org Subject: Passing every element of a list as argument to a function Hi!, I have a very simple syntax question. I want to evaluate a library function f receiving an arbitrary number of arguments (like itertools.product), on the elements of a list l. This means that I want to compute f(l[0],l[1],...,l[len(l)-1]). Is there any operation "op" such that f(op(l)) will give the sequence of elements of l as arguments to f? Thanks for your time. Best, Antonio -- http://mail.python.org/mailman/listinfo/python-list op(*l) for a list (or positional arguments). If you are trying to pass named keyword arguments then you must pass it a dictionary { 'keywordName' : 'value' } Example: >>>def F(name=None): pass >>>F(**{'name':'boo'}) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ursusmaximus at gmail.com Tue Aug 9 17:17:43 2011 From: ursusmaximus at gmail.com (Ron) Date: Tue, 9 Aug 2011 14:17:43 -0700 (PDT) Subject: What's in a name? References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> <4E361F36.4030802@gmail.com> Message-ID: On Aug 1, 10:11?am, Andrew Berg wrote: > Hmm.... > How about Rainbow Video Encoder Wrapper (Rainbow View for short - RView > is taken, possibly multiple times)? > I added an arbitrary word to a generic name, and the result doesn't seem > to be taken by anything software-related. It wraps more than just video > encoders (in fact, x264 will likely be the only one it wraps until it's > matured quite a bit :P ), but I didn't want the name to get too long. > The module itself will likely be called just rainbow.py. > > -- > CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 > PGP/GPG Public Key ID: 0xF88E034060A78FCB Andrew How about SuperMux with a command line interface called Cyclops and a GUI fornt end called VisualMux From pwoolcoc at gmail.com Tue Aug 9 17:42:28 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Tue, 9 Aug 2011 17:42:28 -0400 Subject: __all__ In-Reply-To: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: The gurus will have to correct me if this is not an accepted practice, but I know some projects (Fabric is the one that comes to mind) will define a submodule specifically for the 'from blah import *' situation. The submodule would be called "api", or something like that, so you can do: 'from mymodule.api import *' to separate the items you want to include in your public api, while still keeping other names importable by 'import blah' On Aug 9, 2011 1:00 PM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Ethan Furman wrote: > >> Greetings! >> >> Does anyone know/recall the original purpose of __all__? > > To customise the names available for `from ... import *`: > > http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > > >> I had thought it was primarily to specify what would be imported when >> `from ... import *` was executed, such as for tk; > > Yes, that was the original use. If __all__ is not defined, Python will > import everything that doesn't start with an underscore. > > >> today, it seems it is >> also used to specify the API for the module, and so the help() subsystem >> will only provide details for those items found in __all__. > > The two meanings are assumed to be synonymous: names in the public API > should be importable with *, and importable names should be in the public > API. You can't specify "this can be imported with *, but isn't public" > or "this is public, but not importable with *". > > http://docs.python.org/reference/simple_stmts.html#index-1090 > > > Also, the behaviour of __all__ with packages may be slightly different: > > http://docs.python.org/tutorial/modules.html#index-1134 > > >> The issue I'm having with this is that there are roughly a dozen items I >> would like to make available via the `import *` mechanism in my dbf >> module, and another dozen that, while part of the public API, don't need >> to be available via an `import *`. > > You have to choose both, or neither, but you can't have just one. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Tue Aug 9 17:43:01 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 09 Aug 2011 23:43:01 +0200 Subject: just for fun: make a class (not its instances) iterable Message-ID: Hi, I am just curious. There is no real use case: If I have a class and I want that its instances are iterable I can just add a class metohod named __iter__() example: class MyClass(object): def __iter__(self): for val in range(10): yield val this allows me to do: myobj = MyClass() for val in myobj: print val Now I wondered whether there is any way to implement a class such, that I can write for val in MyClass: print val I know I can implement a classmethod (e.g myclassmethod() ) and write: for val in MyClass.myclassmethod(): print val but I wondered whether classed can be made iterable Thanks in advance for your answers. From ckaynor at zindagigames.com Tue Aug 9 17:51:31 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 9 Aug 2011 14:51:31 -0700 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: You can using metaclasses (untested): >>>class MyMetaClass(type): >>> def __iter__(self): >>> return [1, 2, 3, 4] >>>class MyClass(object): >>> __metaclass__ = MyMetaClass >>>for value in MyClass: >>> print value 1 2 3 4 Chris On Tue, Aug 9, 2011 at 2:43 PM, Gelonida N wrote: > Hi, > > I am just curious. There is no real use case: > > If I have a class and I want that its instances are iterable I can just > add a class metohod named __iter__() > > > example: > > class MyClass(object): > def __iter__(self): > for val in range(10): > yield val > > > this allows me to do: > myobj = MyClass() > for val in myobj: > print val > > > Now I wondered whether there is any way to implement a class such, that > I can write > > > for val in MyClass: > print val > > I know I can implement a classmethod (e.g myclassmethod() ) and write: > > for val in MyClass.myclassmethod(): > print val > > but I wondered whether classed can be made iterable > > Thanks in advance for your answers. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Aug 9 18:20:48 2011 From: nagle at animats.com (John Nagle) Date: Tue, 09 Aug 2011 15:20:48 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: <4e41b2cd$0$2138$742ec2ed@news.sonic.net> On 8/6/2011 10:53 AM, sturlamolden wrote: > On Aug 1, 5:33 pm, aliman wrote: > >> I've read the recipe at [1] and understand that the way to sort a >> large file is to break it into chunks, sort each chunk and write >> sorted chunks to disk, then use heapq.merge to combine the chunks as >> you read them. > > Or just memory map the file (mmap.mmap) and do an inline .sort() on > the bytearray (Python 3.2). With Python 2.7, use e.g. numpy.memmap > instead. If the file is large, use 64-bit Python. You don't have to > process the file in chunks as the operating system will take care of > those details. > > Sturla No, no, no. If the file is too big to fit in memory, trying to page it will just cause thrashing as the file pages in and out from disk. The UNIX sort program is probably good enough. There are better approaches, if you have many gigabytes to sort, (see Syncsort, which is a commercial product) but few people need them. John Nagle From bthate at gmail.com Tue Aug 9 19:48:26 2011 From: bthate at gmail.com (Bart Thate) Date: Tue, 9 Aug 2011 16:48:26 -0700 (PDT) Subject: ANNOUNCING GOZERBOT 0.9.3 BETA1 Message-ID: <9a528c8a-4be8-4d06-952a-92a98a6d1069@a27g2000yqc.googlegroups.com> Hi world and every living thing on it ! I just want to give a headsup to the fact that i released the first beta of GOZERBOT 0.9.3. This release brings in a lot of bug fixes, so please try it out ;] Download is at http://gozerbot.googlecode.com, please if you find problems with the bot file a ticket on http://code.google.com/p/gozerbot/issues/list. Otherwise email me at bthate at gmail.com or check channel #dunkbots on irc.freenode.net, thnx ! feedback is very much appreciated ;] I also want to say sorry to my korean brothers and sisters, i have no evil intend with GOZERBOT even if you might read that into my announcements, i'll give the reason for the name below .. it is taken from the dutch language. Peace ! GOZERBOT name origin ==================== 23:37 < dunker> !tr nl en 1) Bargoense kerel 2) Bink 3) Gast 4) Goser 5) Joch 6) Jongen 7) Ker 8) Kerel 9) Kerel (bargoens) 10) Knaap 11) Knakker 12) Knul 13) Man 14) Persoonsbenaming 15) Vent 23:37 < jsonbot> 1) Bargoens guy 2) Bink 3) Guest 4) Goser 5) Jochberg 6) Girl 7) Ker 8) Guy 9) Dude (slang) 10) Knaap 11) bloke 12) Lad 13) F 14) Name Person 15) Vent ?? 1) Bargoens ?? 2) ?? 3) ??? 4) Goser 5) Jochberg 6) ?? 7) ?? 8) ?? 9) ?? (? ?) 10) Knaap 11) ? 12) ?? 13) F 14) ?? ? 15) ?? About GOZERBOT: GOZERBOT is a channel bot that aids with conversation in irc channels and jabber conference rooms. its mainly used to send notifications (RSS, nagios, etc.) and to have custom commands made for the channel. More then just a channel bot GOZERBOT aims to provide a platform for the user to program his own bot and make it into something thats usefull. This is done with a plugin structure that makes it easy to program your own plugins. But GOZERBOT comes with some batteries included, there are now over 100 plugins already written and ready for use. From steve+comp.lang.python at pearwood.info Tue Aug 9 19:54:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 09:54:25 +1000 Subject: just for fun: make a class (not its instances) iterable References: Message-ID: <4e41c8b3$0$29993$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > Now I wondered whether there is any way to implement a class such, that > I can write > > > for val in MyClass: > print val One way to make an object iterable (there are others) is to add an __iter__ method to the object's class. Unlike in some languages, classes in Python are themselves objects, which means that classes themselves have a class, "type". The class of a class is called the metaclass. So to make the class object (the instance) iterable, use a metaclass. >>> class MetaIter(type): ... def __iter__(self): ... for name in 'abcd': ... yield getattr(self, name) ... >>> class MyClass(object): ... __metaclass__ = MetaIter ... # In Python 3, write as class MyClass(object, metaclass=MetaIter) ... a, b, c, d, = 42, 23, -99, "Surprise!" ... >>> >>> for obj in MyClass: ... print obj ... 42 23 -99 Surprise! -- Steven From tjreedy at udel.edu Tue Aug 9 20:11:29 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:11:29 -0400 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: On 8/9/2011 5:43 PM, Gelonida N wrote: > Now I wondered whether there is any way to implement a class such, that > I can write > > for val in MyClass: > print val And what are the items in a class that you expect that to produce? I am pretty sure you can already do for val in MyClass.__dict__ (or __dict__.items()) -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 9 20:13:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:13:16 -0400 Subject: numpy/scipy: calculate definite integral of sampled data In-Reply-To: <87ty9qttb6.fsf@uriel.graune.org> References: <87ty9qttb6.fsf@uriel.graune.org> Message-ID: numpy/scipy questions are best asked on the numpy/scipy user lists. -- Terry Jan Reedy From python.list at tim.thechases.com Tue Aug 9 20:29:30 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Aug 2011 19:29:30 -0500 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: <4E41D0EA.1070000@tim.thechases.com> On 08/09/2011 07:11 PM, Terry Reedy wrote: > On 8/9/2011 5:43 PM, Gelonida N wrote: >> Now I wondered whether there is any way to implement a class such, that >> I can write >> >> for val in MyClass: >> print val > > And what are the items in a class that you expect that to produce? I can see doing something like class MyClass: instances = [] def __init__(self, *args, **kwargs): self.instances.append(self) # ... a = MyClass(...) b = MyClass(...) for instance in MyClass: do_something(instance) I was curious/surprised to find that class MyClass: instances = [] @classmethod def __iter__(cls): for i in cls.instances: yield i def __init__(self): self.instances.append(self) didn't work as I expected since MyClass then has an __iter__ property that should know about the class. -tkc From tjreedy at udel.edu Tue Aug 9 20:42:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:42:41 -0400 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: <4E41D0EA.1070000@tim.thechases.com> References: <4E41D0EA.1070000@tim.thechases.com> Message-ID: On 8/9/2011 8:29 PM, Tim Chase wrote: > On 08/09/2011 07:11 PM, Terry Reedy wrote: >> On 8/9/2011 5:43 PM, Gelonida N wrote: >>> Now I wondered whether there is any way to implement a class such, that >>> I can write >>> >>> for val in MyClass: >>> print val >> >> And what are the items in a class that you expect that to produce? > > I can see doing something like > > class MyClass: > instances = [] > def __init__(self, *args, **kwargs): > self.instances.append(self) > # ... > > a = MyClass(...) > b = MyClass(...) > for instance in MyClass: for instance in MyClass.instances: > do_something(instance) > > I was curious/surprised to find that > > class MyClass: > instances = [] > @classmethod > def __iter__(cls): > for i in cls.instances: > yield i > def __init__(self): > self.instances.append(self) > > didn't work as I expected since MyClass then has an __iter__ property > that should know about the class. I strongly suspect that iter(ob) starts the lookup for __iter__ with type(ob). I would also expect for instance in MyClass.__iter__() to work, but that is a waste since instances is already iterable. -- Terry Jan Reedy From etay.rosenzweig at gmail.com Tue Aug 9 23:00:02 2011 From: etay.rosenzweig at gmail.com (Etay) Date: Tue, 9 Aug 2011 20:00:02 -0700 (PDT) Subject: input file format Message-ID: <309782ab-d8c8-4b60-bce3-15457c66a5fb@i15g2000vbk.googlegroups.com> Hi all, I am trying to write a Python script which will read the output file of a numerical model, and then copy some of that information into a new file in a new format. The output file of the numerical model is basically 54321 # number of points 1234 # number of time steps __a whole bunch of lines with info I don't need__ [TIMESTAMP] 001 1 10 10 2 10 11 3 11 11 etc... in the format: Point# X Y for all 54321 points [TIMESTAMP] 002 1 13 13 2 14 13 etc... for all 54321 points and so for each of the 1234 time steps I would like to be able to save the number of points and time steps, then move all the time stamped data into a new file, but it needs to be written there as [ Pt# Y X ]. Is there some simple way to skip over the lines I don't need, and then inform Python about the format of the lines with the data I do need within a loop? Thanks! Etay From steve+comp.lang.python at pearwood.info Tue Aug 9 23:48:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 13:48:04 +1000 Subject: input file format References: <309782ab-d8c8-4b60-bce3-15457c66a5fb@i15g2000vbk.googlegroups.com> Message-ID: <4e41ff77$0$29995$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Aug 2011 01:00 pm Etay wrote: > Is there some simple way to skip over the lines I don't need, and then > inform Python about the format of the lines with the data I do need > within a loop? Yes. It's called "programming" :) f = open('some file') for line in f: if some_condition(line): continue # skip the line process(line) f.close() some_condition can be anything you like. You just have to write the code to make it so. -- Steven From lanyjie at yahoo.com Wed Aug 10 00:42:36 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 9 Aug 2011 21:42:36 -0700 (PDT) Subject: allow line break at operators Message-ID: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Hi all, When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: #the old way x = 1+2+3+4+\ ????? 1+2+3+4 #the new way x = 1+2+3+4+ #line continues as it is clearly unfinished ????? 1+2+3+4 Of course, the dot operator is also included, which may facilitate method chaining: x = svg.append( 'circle' ). ????? r(2).cx(1).xy(1). ????? foreground('black').bkground('white') Thoughts? Yingjie From clp2 at rebertia.com Wed Aug 10 00:55:33 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 21:55:33 -0700 Subject: allow line break at operators In-Reply-To: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: On Tue, Aug 9, 2011 at 9:42 PM, Yingjie Lan wrote: > Hi all, > > When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: > > #the old way > > x = 1+2+3+4+\ > ????? 1+2+3+4 > > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > ????? 1+2+3+4 # the currently allowed way x = (1+2+3+4+ 1+2+3+4) # note the parentheses I think this is sufficient. > Of course, the dot operator is also included, which may facilitate method chaining: > > x = svg.append( 'circle' ). > ????? r(2).cx(1).xy(1). > ????? foreground('black').bkground('white') Python does not particularly endorse method chaining; it's why list.sort(), list.append(), and similar methods of built-in types return None rather than self. Also, I dislike this for the dot operator especially, as it can obscure whether a method call or a function call is taking place. Cheers, Chris -- http://rebertia.com From lanyjie at yahoo.com Wed Aug 10 02:05:56 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 9 Aug 2011 23:05:56 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: <1312956356.91952.YahooMailNeo@web121503.mail.ne1.yahoo.com> On Tue, Aug 9, 2011 at 9:42 PM, Yingjie Lan wrote: > Hi all, > > When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: > > #the old way > > x = 1+2+3+4+\ > ????? 1+2+3+4 > > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > ????? 1+2+3+4 :# the currently allowed way :x = (1+2+3+4+ :? ? 1+2+3+4) :# note the parentheses : :I think this is sufficient. That works, but not in the most natural way--the way people are customed to...why require a pair of parenthis when we can do without them? Also, the new way does not affect the old ways of doing things at all, it is fully backward compatible. So this just offers a new choice. > Of course, the dot operator is also included, which may facilitate method chaining: > > x = svg.append( 'circle' ). > ????? r(2).cx(1).xy(1). > ????? foreground('black').bkground('white') :Also, I dislike this for the dot operator especially, as it can :obscure whether a method call or a function call is taking place. Again, this only offers a new choice, and does not force anybody to do it this way. cheers, Yingjie From dannwong at cisco.com Wed Aug 10 02:38:56 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:38:56 -0500 Subject: subprocess.Popen and thread module In-Reply-To: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Hi All, I'm trying to execute some external commands from multiple database. I'm using threads and subprocess.Popen ( from docs, all the popen* functions are deprecated and I was told to use subprocess.Popen) to execute the external commands in parallel, but the commands seems to hang. My question is: Is subprocess.Popen thread safe? If not, what other module should I use to perform a system call? I also, want to log stdout and stderr to a file. Thanks. From clp2 at rebertia.com Wed Aug 10 02:47:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 23:47:04 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) wrote: > Hi All, > ? I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. What's your Popen() call look like? Cheers, Chris From dannwong at cisco.com Wed Aug 10 02:48:36 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:48:36 -0500 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Hi Chris, Here is the code, try: cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) status = cmd_output.wait() print "In load status is: %s" % status + "\n" except: print "Error Executing %s" % command + "\n" -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 09, 2011 11:47 PM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: subprocess.Popen and thread module On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) wrote: > Hi All, > ? I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. What's your Popen() call look like? Cheers, Chris From clp2 at rebertia.com Wed Aug 10 02:53:29 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 23:53:29 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: > On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) > wrote: >> Hi All, >> ? I'm trying to execute some external commands from multiple database. >> I'm using threads and subprocess.Popen ( from docs, all the popen* >> functions are deprecated and I was told to use subprocess.Popen) to >> execute the external commands in parallel, but the commands seems to >> hang. > > What's your Popen() call look like? On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) wrote: > ? ?try: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > ? ? ? ?status = cmd_output.wait() Er, did you read the warning about Popen.wait() in the docs? (emphasis added): """ Popen.wait() Wait for child process to terminate. Set and return returncode attribute. Warning: ***This will deadlock*** when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. """ ? http://docs.python.org/library/subprocess.html#subprocess.Popen.wait Cheers, Chris From dannwong at cisco.com Wed Aug 10 02:56:38 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:56:38 -0500 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: I did read that portion of the doc, then I change it to communicate and it still hangs. So I reverted back to "wait" while launching one thread to see if I could isolate the problem, but it still hangs regardless of using "wait" or "communicate". -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 09, 2011 11:53 PM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: subprocess.Popen and thread module > On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) > wrote: >> Hi All, >> ? I'm trying to execute some external commands from multiple database. >> I'm using threads and subprocess.Popen ( from docs, all the popen* >> functions are deprecated and I was told to use subprocess.Popen) to >> execute the external commands in parallel, but the commands seems to >> hang. > > What's your Popen() call look like? On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) wrote: > ? ?try: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > ? ? ? ?status = cmd_output.wait() Er, did you read the warning about Popen.wait() in the docs? (emphasis added): """ Popen.wait() Wait for child process to terminate. Set and return returncode attribute. Warning: ***This will deadlock*** when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. """ ? http://docs.python.org/library/subprocess.html#subprocess.Popen.wait Cheers, Chris From sungsuha at gmail.com Wed Aug 10 03:01:10 2011 From: sungsuha at gmail.com (Seung =?utf-8?b?U29vLA==?= Ha) Date: Wed, 10 Aug 2011 07:01:10 +0000 (UTC) Subject: Run clang static analyzer on Python 3.30a Message-ID: Hello, I just ran the clang static analyzer on Python. I'm very new to this, so please bear with me as a describe the exact steps I took. 1. hg clone of python 2. scan-build ./configure --with-pydebug 3. scan-build make -s -j4 4. scan-view /tmp/scan-build-2011-08-10-1/ It shows 6 bugs and the report page even has a friendly option to report the bug. I'm just starting to learn C and I cannot judge whether they are worth reporting. Should I? I am aware of the issue tracker and how to use it. What I'm curious is what information I should provide, considering the fact that my skills (for now) is limited to copy and paste. What should I do next? (my system Ubuntu 11.04 x86_64 on AMD Phenom II X4 955) Thanks. From clp2 at rebertia.com Wed Aug 10 03:36:18 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 00:36:18 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: > From: Chris Rebert >> On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) >> wrote: >>> Hi All, >>> ? I'm trying to execute some external commands from multiple database. >>> I'm using threads and subprocess.Popen ( from docs, all the popen* >>> functions are deprecated and I was told to use subprocess.Popen) to >>> execute the external commands in parallel, but the commands seems to >>> hang. >> >> What's your Popen() call look like? > > On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) > wrote: >> ? ?try: >> ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> ? ? ? ?status = cmd_output.wait() > > Er, did you read the warning about Popen.wait() in the docs? (emphasis added): On Tue, Aug 9, 2011 at 11:56 PM, Danny Wong (dannwong) wrote: > I did read that portion of the doc, then I change it to communicate and it still hangs. So I reverted back to "wait" while launching one thread to see if I could isolate the problem, but it still hangs regardless of using "wait" or "communicate". Since you want to log the output to a file, have you tried: logfile = open("path/to/file", 'r') proc = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=logfile, stderr=subprocess.STDOUT) status = proc.wait() or similar? Cheers, Chris -- Damn Outlook/Exchange and its "On Behalf Of"! http://rebertia.com From steve+comp.lang.python at pearwood.info Wed Aug 10 04:32:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 18:32:05 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Aug 2011 04:05 pm Yingjie Lan wrote: > :# the currently allowed way > :x = (1+2+3+4+ > :1+2+3+4) > :# note the parentheses > : > :I think this is sufficient. > > That works, but not in the most natural way--the way people are customed > to...why require a pair of parenthis when we can do without them? Because it is better to be explicit that the line is still open. An opening parenthesis or bracket that hasn't been closed is an explicit sign that the line is still open. An operator is not. > Also, > the new way does not affect the old ways of doing things at all, it is > fully backward compatible. So this just offers a new choice. You say that as if having more choices is always good. It isn't. More choices means more for people to learn, more complicated parser, more options to consider, and more likelihood that errors will fail to raise SyntaxError and instead go on to silently do the wrong thing. A new choice should only be accepted when there is a clear and obvious benefit, not merely because it will provide more choice. Python is a programming language, not an ice cream shop. >> Of course, the dot operator is also included, which may facilitate method >> chaining: >> >> x = svg.append( 'circle' ). >> r(2).cx(1).xy(1). >> foreground('black').bkground('white') If you are chaining six dots like that, you are in gross violation of the Law Of Demeter. That is poor code, and should be discouraged, not encouraged. > > :Also, I dislike this for the dot operator especially, as it can > :obscure whether a method call or a function call is taking place. > > Again, this only offers a new choice, and does not force anybody to do it > this way. But it does force people to read it, because some people will use it, and so others will have to suffer for their poor judgement. -- Steven From rosuav at gmail.com Wed Aug 10 04:39:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 09:39:55 +0100 Subject: allow line break at operators In-Reply-To: <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 9:32 AM, Steven D'Aprano wrote: >>> Of course, the dot operator is also included, which may facilitate method >>> chaining: >>> >>> x = svg.append( 'circle' ). >>> r(2).cx(1).xy(1). >>> foreground('black').bkground('white') > > If you are chaining six dots like that, you are in gross violation of the > Law Of Demeter. That is poor code, and should be discouraged, not > encouraged. I would only accept that this is poor code IF there is a viable alternative, such as: x = svg.append(circle(r=2,cx=1,xy=1,foreground='black',bkground='white')) This would, imho, be a more Pythonic way to do it. But if this isn't available, and if the methods already return self, then I see nothing wrong with chaining. It's a handy way of getting additional mileage out of lambdas and list comps when writing one-liners. :) (Cue long thread about whether or not one-liners are Pythonic.) Chris Angelico From ranganayakirangs at gmail.com Wed Aug 10 05:10:29 2011 From: ranganayakirangs at gmail.com (ranganayaki rangs) Date: Wed, 10 Aug 2011 02:10:29 -0700 (PDT) Subject: http://123maza.com/65/share858/ Message-ID: http://123maza.com/65/share858/ From t at jollybox.de Wed Aug 10 05:38:46 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 10 Aug 2011 11:38:46 +0200 Subject: Restricted attribute writing In-Reply-To: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: <4E4251A6.7050407@jollybox.de> On 07/08/11 17:35, John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. > > My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is a modulo remainder. I need to be able to write to it like a normal list, but want to ensure it is only possible to do so without changing that format. > > Below is a what I eventually came up with; a container class called OrderElement for the inner lists, and subclass of list called Order for the main attribute, which is a property of the main class, simplified below as SeqSim. It works, but seems like a hell of a lot of code for a simple idea. I'm interested in ideas for simpler solutions, and general advice on how to do this kind of thing in a straightforward way. What I think you're looking for is properties: http://docs.python.org/py3k/library/functions.html#property So: with a property, channel getting and setting through functions that can check the value for validity. Secondly, use tuples instead of lists where possible: they're not mutable, which makes controlling their value a lot easier. If your attribute is a list that users may append elements to, consider adding an addelement(tpl) method to your class that checks the value and appends it to the list. Lastly, consider the option of not checking vigorously at all at that point: If the value is invalid, it will raise an exception later, when it is used. Depending on what you're doing, this might be all the checking you need. If you're going to serialise the data, or if you want to use the property setter to check user input directly, that's probably not a strong option. Thomas > > > class OrderElement(): > """Container class which can only hold two integers > the first of which is a modulo of the 'length' arg""" > def __init__(self, lis, length): > self.__data = [None, None] > self.__length=length > self[:] = lis > > def __setitem__(self, index, item): > if isinstance(index, slice): > inds = range(*index.indices(2)) > for k, v in enumerate(item): > self[inds[k]] = v > elif isinstance(item, int): > if index == 0: > item %= self.__length > self.__data[index] = item > else: > raise TypeError("OrderElement takes two integers") > > def __getitem__(self, index): > return self.__data[index] > > > class Order(list): > """Can only contain OrderElements""" > def __init__(self, lis, length): > self.__length = length > self[:] = lis > > def __setitem__(self, index, item): > if isinstance(index, slice): > item = [i if isinstance(i, OrderElement) > else OrderElement(i, self.__length) > for i in item] > elif not isinstance(item, OrderElement): > item = OrderElement(item, self.__length) > list.__setitem__(self, index, item) > > def __getitem__(self, index): > """Ensure slices are of the same class""" > if isinstance(index, slice): > return self.__class__(list.__getitem__(self, index), > self.__length) > return list.__getitem__(self, index) > > > class SeqSim(): > """Just the relevant bits of the main class""" > def __init__(self, lis, length): > self.__order = Order(lis, length) > self.length = length > > @property > def order(self): > return self.__order > > @order.setter > def order(self, lis): > if not isinstance(lis, Order): > lis = Order(lis, self.length) > self.__order = lis > From dan at tombstonezero.net Wed Aug 10 05:56:20 2011 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 10 Aug 2011 09:56:20 +0000 (UTC) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 10 Aug 2011 18:32:05 +1000, Steven D'Aprano wrote: > Python is a programming language, not an ice cream shop. +1 QOTW How about a cheese shop? In terms of easier to read, I find code easier to read when the operators are at the beginnings of the lines (PEP 8 notwithstanding): x = (someobject.somemethod(object3, thing) + longfunctionname(object2) + otherfunction(value1, value2, value3)) I can see the "+" signs a lot easier there than at the end of some line, where it might be buried between two longer lines: x = (someobject.somemethod(object3, thing) + longfunctionname(object2) + otherfunction(value1, value2, value3)) -- Dan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Aug 10 06:09:52 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 10 Aug 2011 12:09:52 +0200 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Am 10.08.2011 08:38 schrieb Danny Wong (dannwong): > Hi All, > I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. > My question is: > Is subprocess.Popen thread safe? Do you really need threads here? As you just run those external commands (as far as I understand), it might be enough to start the commands, hold their object, read them out (maybe part for part) and then wait(). Thomas From rosuav at gmail.com Wed Aug 10 06:26:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 11:26:10 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers wrote: > In terms of easier to read, I find code easier to read when the operators > are at the beginnings of the lines (PEP 8 notwithstanding): > > ? ?x = (someobject.somemethod(object3, thing) > ? ? ? ? + longfunctionname(object2) > ? ? ? ? + otherfunction(value1, value2, value3)) > Without the parentheses, this is legal but (probably) useless; it applies the unary + operator to the return value of those functions. Putting the + at the end of the previous line at least prevents that, since most unary operators bind to the operand on the right; but there's still the potential for ambiguity. When line breaks are significant, they cannot be randomly inserted inside expressions. ChrisA From przemolicc at poczta.fm Wed Aug 10 07:17:54 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Wed, 10 Aug 2011 13:17:54 +0200 Subject: String concatenation - which is the fastest way ? Message-ID: <20110810111754.GD5045@host.pgf.com.pl> Hello, I'd like to write a python (2.6/2.7) script which connects to database, fetches hundreds of thousands of rows, concat them (basically: create XML) and then put the result into another table. Do I have any choice regarding string concatenation in Python from the performance point of view ? Since the number of rows is big I'd like to use the fastest possible library (if there is any choice). Can you recommend me something ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f2a0a From no at nowhere.net.no Wed Aug 10 07:26:38 2011 From: no at nowhere.net.no (TheSaint) Date: Wed, 10 Aug 2011 19:26:38 +0800 Subject: allow line break at operators References: Message-ID: Yingjie Lan wrote: > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > 1+2+3+4 > Genrally I prefer this way. > Of course, the dot operator is also included, which may facilitate method > chaining: > > x = svg.append( 'circle' ). Dot-ended is to tiny thing that might cause oversights. *If* it'll be used as a secondary option I think it doesn't matter, otherwise *if* use as a compulsory writing mode I'd say it is pretty mistake prone. From duncan.booth at invalid.invalid Wed Aug 10 08:25:21 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2011 12:25:21 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. No, in some other languages it might be legal, but this is Python. without the parentheses it is a syntax error. -- Duncan Booth http://kupuguy.blogspot.com From k.sahithi2862 at gmail.com Wed Aug 10 08:25:56 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 10 Aug 2011 05:25:56 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: <4ca9c8fe-867c-471a-9c95-d883ecece545@y19g2000pre.googlegroups.com> HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html LATEST HOT TAPSEE KISSING STILLS http://southactresstou.blogspot.com/2011/06/tapsee.html KAJAL AGARWAL ROMANTIC STILLS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html TAMANNA BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/05/tamanna.html ANUSHKA SHETTY HOT SAREE STILLS http://southactresstou.blogspot.com/2011/06/anushka-shetty.html SNEHA RARE PHOTOS http://southactresstou.blogspot.com/2011/05/sneha.html NAMITHA HOT NAVEL SHOW http://southactresstou.blogspot.com/2011/05/namitha.html ILIYANA HOT WALLPAPERS http://southactresstou.blogspot.com/2011/05/iliyana.html PRIYAMANI LATEST SPICY PHOTOS http://southactresstou.blogspot.com/2011/05/priyamani.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From rosuav at gmail.com Wed Aug 10 08:32:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 13:32:06 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810111754.GD5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 12:17 PM, wrote: > Hello, > > I'd like to write a python (2.6/2.7) script which connects to database, fetches > hundreds of thousands of rows, concat them (basically: create XML) > and then put the result into another table. Do I have any choice > regarding string concatenation in Python from the performance point of view ? > Since the number of rows is big I'd like to use the fastest possible library > (if there is any choice). Can you recommend me something ? First off, I have no idea why you would want to create an XML dump of hundreds of thousands of rows, only to store it in another table. However, if that is your intention, list joining is about as efficient as you're going to get in Python: lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries xml=""+"".join(lst)+"" This sets xml to 'asdfqwerzxcv' which may or may not be what you're after. ChrisA From rosuav at gmail.com Wed Aug 10 08:42:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 13:42:30 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 1:25 PM, Duncan Booth wrote: > Chris Angelico wrote: > >> On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers >> wrote: >>> In terms of easier to read, I find code easier to read when the >>> operators are at the beginnings of the lines (PEP 8 notwithstanding): >>> >>> ? ?x = (someobject.somemethod(object3, thing) >>> ? ? ? ? + longfunctionname(object2) >>> ? ? ? ? + otherfunction(value1, value2, value3)) >>> >> >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. > > No, in some other languages it might be legal, but this is Python. > without the parentheses it is a syntax error. It would be parsed as three separate statements. The only reason it would be a syntax error would be because of the indentation, which is not what I'd call reliable; it happens to catch this case, because assignment doesn't allow subsequent lines to be indented, but nothing forces continuation lines to be indented. x = (5 +4) x = 5 +4 What we have is a strangeness that can arise when a programmer ignores something that is often insignificant; spare parentheses usually don't matter. Another potential danger is the similarity with tuple creation: x = (someobject.somemethod(object3, thing) ? ? + longfunctionname(object2) ? ? + otherfunction(value1, value2, value3),) This is a tuple with one element. Not too bad with the + operator, but imagine if everything's done with method chaining on . which results in the , being nearly indistinguishable. Not an insurmountable problem, but a potential risk. ChrisA From peterirbizon at gmail.com Wed Aug 10 08:42:31 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Wed, 10 Aug 2011 14:42:31 +0200 Subject: gtk STOCK_SAVE text in another language Message-ID: hello, I have slovak win but I would like to have english captions on pygtk STOCK_SAVE buttons. How can I set this? thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From doomsdaymine at gmail.com Wed Aug 10 08:44:25 2011 From: doomsdaymine at gmail.com (mike turner) Date: Wed, 10 Aug 2011 08:44:25 -0400 Subject: I need help/information on Freeze.py Message-ID: Hello all, How do you use freeze.py to freeze an application? I have an application built with pylons and I want to make it into a portable executable, is that possible? Thanks for the help. - mikey -------------- next part -------------- An HTML attachment was scrubbed... URL: From lanyjie at yahoo.com Wed Aug 10 08:58:24 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 05:58:24 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. :No, in some other languages it might be legal, but this is Python. :without the parentheses it is a syntax error. This discussion leads me to this question: Is it possible for python to allow free splitting of single-line statements without the backslashes, if we impose that expressions can only be split when it is not yet a finished expression? Note: splitting before closing parenthis, brace, or bracket can be viewed as special case of this more general rule. Yingjie From spsing07 at gmail.com Wed Aug 10 09:09:00 2011 From: spsing07 at gmail.com (spsing sing) Date: Wed, 10 Aug 2011 06:09:00 -0700 (PDT) Subject: hai go in mee t Message-ID: www.oneadds.info From lanyjie at yahoo.com Wed Aug 10 09:19:37 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 06:19:37 -0700 (PDT) Subject: allow line break at operators In-Reply-To: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. If ';' are employed (required), truely free line-splitting should be OK, the operators may appear at the beginnings of the lines as you wish. Yingjie From przemolicc at poczta.fm Wed Aug 10 09:31:46 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Wed, 10 Aug 2011 15:31:46 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> Message-ID: <20110810133146.GE5045@host.pgf.com.pl> On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 12:17 PM, wrote: > > Hello, > > > > I'd like to write a python (2.6/2.7) script which connects to database, fetches > > hundreds of thousands of rows, concat them (basically: create XML) > > and then put the result into another table. Do I have any choice > > regarding string concatenation in Python from the performance point of view ? > > Since the number of rows is big I'd like to use the fastest possible library > > (if there is any choice). Can you recommend me something ? > > First off, I have no idea why you would want to create an XML dump of > hundreds of thousands of rows, only to store it in another table. > However, if that is your intention, list joining is about as efficient > as you're going to get in Python: > > lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries > xml=""+"".join(lst)+"" > > This sets xml to 'asdfqwerzxcv' which > may or may not be what you're after. Chris, since this process (XML building) is running now inside database (using native SQL commands) and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which will concat subset of the whole table (and then merge all of them at the end). Basically: - fetch all rows from the database (up to 1 million): what is recommended data type ? - spawn X python processes each one: - concat its own subset - merge the result from all the subprocesses This task is running on a server which has many but slow cores and I am trying to divide this task into many subtasks. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From gandalf at shopzeus.com Wed Aug 10 09:42:55 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 10 Aug 2011 15:42:55 +0200 Subject: SocketServer expceion after upgrading to 2.7 Message-ID: <4E428ADF.5020806@shopzeus.com> Exception happened during processing of request from ('80.99.165.122', 56069) Traceback (most recent call last): File "/usr/local/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "/usr/local/lib/python2.7/SocketServer.py", line 311, in process_request self.shutdown_request(request) File "/usr/local/lib/python2.7/SocketServer.py", line 459, in shutdown_request request.shutdown(socket.SHUT_WR) TypeError: shutdown() takes exactly 0 arguments (1 given) I get this error with a program, after upgrading to python 2.7. I'm using a program that is based on SocketServer and SimpleXMLRPCDispatcher. Any idea how to fix this? Thanks, Laszlo From claird271 at gmail.com Wed Aug 10 10:04:10 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 10 Aug 2011 07:04:10 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 10) Message-ID: <6bd9df46-2baf-448a-b51f-be726c55d4bb@t5g2000yqj.googlegroups.com> QOTW: "If an elegant solution doesn't occur to me right away, then I first compose the most obvious solution I can think of. Finally, I refactor it until elegance is either achieved or imagined." - Neil Cerutti, 2011-07-28 What is the real purpose of __all__? http://old.nabble.com/__all__-td32227593.html __set__ does not appear to work for class attributes: http://groups.google.com/group/comp.lang.python/t/72a346299a7eacf5/ Talking of class attributes: how to set up a docstring for them? http://old.nabble.com/Docstrings-and-class-Attributes-td32218039.html Using zip to separate a list of pairs into two lists: http://groups.google.com/group/comp.lang.python/t/98008a2c63b002fa/ Detecting object differences in order to propagate the changes over a network: http://old.nabble.com/Object-Diffs-ts32221405.html modules, classes, and functions: all appear to be different ways to execute a block of code; similarities and differences http://groups.google.com/group/comp.lang.python/t/79bc8b7d5267338a/ Replace all references to one object with another, is it possible? http://groups.google.com/group/comp.lang.python/t/32b67545254bdf37/ Ensure certain attributes, even if writable and modifiable, maintain certain invariants: http://groups.google.com/group/comp.lang.python/t/d23a48c858b2cb75/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From claird271 at gmail.com Wed Aug 10 10:04:11 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 10 Aug 2011 07:04:11 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 10) Message-ID: <008bd519-baa0-4f4f-95fd-f2035f2425c0@y8g2000vba.googlegroups.com> QOTW: "If an elegant solution doesn't occur to me right away, then I first compose the most obvious solution I can think of. Finally, I refactor it until elegance is either achieved or imagined." - Neil Cerutti, 2011-07-28 What is the real purpose of __all__? http://old.nabble.com/__all__-td32227593.html __set__ does not appear to work for class attributes: http://groups.google.com/group/comp.lang.python/t/72a346299a7eacf5/ Talking of class attributes: how to set up a docstring for them? http://old.nabble.com/Docstrings-and-class-Attributes-td32218039.html Using zip to separate a list of pairs into two lists: http://groups.google.com/group/comp.lang.python/t/98008a2c63b002fa/ Detecting object differences in order to propagate the changes over a network: http://old.nabble.com/Object-Diffs-ts32221405.html modules, classes, and functions: all appear to be different ways to execute a block of code; similarities and differences http://groups.google.com/group/comp.lang.python/t/79bc8b7d5267338a/ Replace all references to one object with another, is it possible? http://groups.google.com/group/comp.lang.python/t/32b67545254bdf37/ Ensure certain attributes, even if writable and modifiable, maintain certain invariants: http://groups.google.com/group/comp.lang.python/t/d23a48c858b2cb75/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From vacorama at gmail.com Wed Aug 10 10:18:46 2011 From: vacorama at gmail.com (ron) Date: Wed, 10 Aug 2011 07:18:46 -0700 (PDT) Subject: Segmentation Fault on exit References: Message-ID: <38f2d76e-057f-4d62-9012-e09c18639de9@t7g2000vbv.googlegroups.com> On Aug 6, 6:35?am, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import pyossim > > * Do some stuff * > >>> exit() > > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ > > Kindly help. > > Thanks and Regards, > Vipul Raheja Check out Valgrind. It's easy to set up, runs like gdb, but keeps track and flags any offending memory use at the c level. Then just need to find the calling python code. From peterirbizon at gmail.com Wed Aug 10 10:22:32 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Wed, 10 Aug 2011 16:22:32 +0200 Subject: problem with GTK language Message-ID: Hello, I have strange problem with gtk language in pygtk. When I run .py file it shows all gtk labels in my default windows language (slovak). But when I compile it with py2exe and run exe file all labels are in english. Why this happens? How can I define on program startup which language to use? I would like to choose between english and slovak. I tryed to set locals in my application but no luck. What am I doing wrong? thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at gmail.com Wed Aug 10 10:33:09 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:33:09 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> On Aug 5, 12:29?pm, Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? It's an unfortunate asymmetry in the descriptor protocol. You can write "class descriptors" with behaviour on get, but not on set. As others point out, metaclasses are an ugly way round this (particularly given that *basically* a class can only have one metaclass - so if you're inheriting from a class that already has a custom metaclass you can't use this technique). Michael Foord -- http://voidspace.org.uk/ From fuzzyman at gmail.com Wed Aug 10 10:36:20 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:36:20 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: <33a59af5-bdf9-4f37-8801-9f9ad1a778b7@w11g2000vbp.googlegroups.com> On Aug 5, 1:16?pm, Duncan Booth wrote: > Ryan wrote: > > In the context of descriptors, the __set__ method is not called for > > class attribute access. __set__ is only > > called to set the attribute on an instance instance of the owner class > > to a new value, value. WHY? Is there some other mechanism for > > accomplishing this outcome. This subtle difference from __get__cost me > > some time to track down. Might think about pointing that out the > > documentation. > > > class RevealAccess(object): > > ? ? """A data descriptor that sets and returns values > > ? ? ? ?normally and prints a message logging their access. > > ? ? """ > > > ? ? def __init__(self, initval=None, name='var'): > > ? ? ? ? self.val = initval > > ? ? ? ? self.name = name > > > ? ? def __get__(self, obj, objtype): > > ? ? ? ? print 'Retrieving', self.name > > ? ? ? ? return self.val > > > ? ? def __set__(self, obj, val): > > ? ? ? ? print 'Updating' , self.name > > ? ? ? ? self.val = val > > > class MyClass(object): > > ? ? x = RevealAccess(10, 'var "x"') > > ? ? y = 5 > > > print MyClass.x > > MyClass.x = 20 > > print MyClass.x > > MyClass.x = 30 > > print MyClass.x > > > Retrieving var "x" > > 10 > > 20 > > 30 > > > I am at a lost on how to intercept class attribute sets. Can anyone > > help :-/ > > The descriptor protocol only works when a value is being accessed or set > on an instance and there is no instance attribute of that name so the > value is fetched from the underlying class. > That's not true. Properties, for example, can be got or set even when they shadow an instance attribute. You're (probably) thinking of __getattr__ which isn't invoked when an instance attribute exists. Also, the descriptor protocol *is* invoked for getting an attribute from a class - but not when setting a class attribute. An unfortunate asymmetry. It just wasn't considered as a use case when the descriptor protocol was implemented. Michael -- http://voidspace.org.uk/ From steve+comp.lang.python at pearwood.info Wed Aug 10 10:36:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:36:59 +1000 Subject: String concatenation - which is the fastest way ? References: Message-ID: <4e42978c$0$29993$c3e8da3$5496439d@news.astraweb.com> przemolicc at poczta.fm wrote: > Hello, > > I'd like to write a python (2.6/2.7) script which connects to database, > fetches hundreds of thousands of rows, concat them (basically: create XML) > and then put the result into another table. Do I have any choice > regarding string concatenation in Python from the performance point of > view ? Since the number of rows is big I'd like to use the fastest > possible library (if there is any choice). Can you recommend me something > ? For fast string concatenation, you should use the string.join method: substrings = ['a', 'bb', 'ccc', 'dddd'] body = ''.join(substrings) Using string addition in a loop, like this: # Don't do this! body = '' for sub in substrings: body += sub risks being *extremely* slow for large numbers of substrings. (To be technical, string addition can O(N**2), while ''.join is O(N).) This depends on many factors, including the operating system's memory management, and the Python version and implementation, so repeated addition may be fast on one machine and slow on another. Better to always use join, which is consistently fast. You should limit string addition to small numbers of substrings: result = head + body + tail # This is okay. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 10 10:37:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:37:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the operators >> are at the beginnings of the lines (PEP 8 notwithstanding): >> >> x = (someobject.somemethod(object3, thing) >> + longfunctionname(object2) >> + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. > Putting the + at the end of the previous line at least prevents that, > since most unary operators bind to the operand on the right; Not so: >>> x = (42 + - ... 100) >>> >>> x -58 -- Steven From rosuav at gmail.com Wed Aug 10 10:38:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:38:16 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810133146.GE5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 2:31 PM, wrote: > - fetch all rows from the database (up to 1 million): what is recommended data type ? > - spawn X python processes each one: > ? ?- concat its own subset > - merge the result from all the subprocesses > What you're writing is, fundamentally, glue between your SQL engine and your SQL engine. Look up what you get from your query and work with that. Which SQL library are you suing? Python may and may not be the best tool for this job. Chris Angelico From rosuav at gmail.com Wed Aug 10 10:38:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:38:42 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 3:38 PM, Chris Angelico wrote: > Which SQL library are you suing? And this is why I should proof-read BEFORE, not AFTER, sending. Which SQL library are you *using*? ChrisA From steve+comp.lang.python at pearwood.info Wed Aug 10 10:44:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:44:20 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e429945$0$29993$c3e8da3$5496439d@news.astraweb.com> Dan Sommers wrote: > In terms of easier to read, I find code easier to read when the operators > are at the beginnings of the lines (PEP 8 notwithstanding): > > x = (someobject.somemethod(object3, thing) > + longfunctionname(object2) > + otherfunction(value1, value2, value3)) Agreed. -- Steven From rosuav at gmail.com Wed Aug 10 10:45:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:45:43 +0100 Subject: allow line break at operators In-Reply-To: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 1:58 PM, Yingjie Lan wrote: > Is it possible for python to allow free splitting of single-line statements > without the backslashes, if we impose that expressions can only be split > when it is not yet a finished expression? The trouble is that in a lot of cases, the next statement after an unfinished expression could conceivably be a continuation of it. If this were permitted, it would have to also require that the continuation lines be indented, to avoid the problem described above. It'd still have the potential to mis-diagnose errors, though. ChrisA From fuzzyman at gmail.com Wed Aug 10 10:48:55 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:48:55 -0700 (PDT) Subject: how to dynamically generate __name__ for an object? References: Message-ID: On Aug 7, 4:06?am, Eric Snow wrote: > Thought I knew how to provide a dynamic __name__ on instances of a > class. ?My first try was to use a non-data descriptor: > > # module base.py > > class _NameProxy(object): > ? ? def __init__(self, oldname): > ? ? ? ? self.oldname = oldname > ? ? def __get__(self, obj, cls): > ? ? ? ? if obj is None: > ? ? ? ? ? ? return self.oldname > ? ? ? ? if "__name__" not in obj.__dict__: > ? ? ? ? ? ? return str(obj.__context__) > ? ? ? ? return obj.__name__ > > class _BaseMeta(type): > ? ? def __init__(cls, name, bases, namespace): > ? ? ? ? cls.__name__ = _NameProxy(name) > > class Base(object): > ? ? __metaclass__ = _BaseMeta > > $ python _base.py > Traceback (most recent call last): > ? ... > ? File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ > ? ? cls.__name__ = _NameProxy(name) > TypeError: Error when calling the metaclass bases > ? ? can only assign string to Base.__name__, not '_NameProxy' > > Needless to say I was surprised. ?After looking in typeobject.c, I > believe that __name__ must be a string where classes are concerned[1]. > ?So if I want all my instances to have a __name__ attribute, and for > it to be dynamically provided if it isn't set on the instance, what > are my options? ?Or maybe I did something wrong and it should work as > I expected? > __name__ can be a descriptor, so you just need to write a descriptor that can be fetched from classes as well as instances. Here's an example with a property (instance only): >>> class Foo(object): ... @property ... def __name__(self): ... return 'bar' ... >>> Foo().__name__ 'bar' Michael -- http://voidspace.org.uk/ From rosuav at gmail.com Wed Aug 10 11:13:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 16:13:42 +0100 Subject: allow line break at operators In-Reply-To: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 3:37 PM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operators bind to the operand on the right; > > Not so: > >>>> x = (42 + - > ... ? ? 100) >>>> >>>> x > -58 Your unary - is binding to the operand to its right, in this case the 100. (I think I have left and right correct; being in theatre has a tendency to make you forget which is which.) Your + is binary, operating on 42 and the result of applying unary - to 100, which is -100. My point about binding can be illustrated by inventing an operator @. Let's say that a at b is the atan2 of a and b, and x@ is x factorial (I can't imagine what deranged mind would do something like this, apart from my own). y = 5 @ # 120, as per factorial x = 5 @ 2 # 1.19 or so, as per atan2 foo(123) # Calls foo() and discards its return value z = 5 @ foo(123) Is that last example one statement or two? But this situation shouldn't ever occur in Python, because all its unary operators (not, -, +, ~) bind to the operand to their right (I don't think there's any I've missed, are there?). It does mean, however, that a leading operator is not unambiguous. Without the surrounding parentheses and/or otherwise-unexpected indentation, an expression beginning with a + could conceivably be applying the unary plus operator to the rest of the expression, rather than implying that it's continuing the previous line. Chris Angelico From ian.g.kelly at gmail.com Wed Aug 10 11:16:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Aug 2011 09:16:58 -0600 Subject: allow line break at operators In-Reply-To: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operators bind to the operand on the right; > > Not so: > >>>> x = (42 + - > ... ? ? 100) >>>> >>>> x > -58 That is still binding to the operand on the "right" (i.e., the sequentially later). And it still does not cause the problem that Chris was talking about, since without the parentheses that would be a syntax error. So I guess I'm not certain what exactly it is that you're trying to demonstrate here. From ian.g.kelly at gmail.com Wed Aug 10 11:25:08 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Aug 2011 09:25:08 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: References: Message-ID: On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > __name__ can be a descriptor, so you just need to write a descriptor > that can be fetched from classes as well as instances. > > Here's an example with a property (instance only): > >>>> class Foo(object): > ... ? @property > ... ? def __name__(self): > ... ? ? return 'bar' > ... >>>> Foo().__name__ > 'bar' But: >>> Foo.__name__ 'Foo' >>> repr(Foo()) '<__main__.Foo object at 0x00CAFFD0>' >>> Foo.__dict__['__name__'] It seems that Foo.__name__ and Foo.__dict__['__name__'] are not the same thing, and Python itself only uses the former. From duncan.booth at invalid.invalid Wed Aug 10 11:35:11 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2011 15:35:11 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <33a59af5-bdf9-4f37-8801-9f9ad1a778b7@w11g2000vbp.googlegroups.com> Message-ID: Fuzzyman wrote: >> The descriptor protocol only works when a value is being accessed or set >> on an instance and there is no instance attribute of that name so the >> value is fetched from the underlying class. >> > > That's not true. Properties, for example, can be got or set even when > they shadow an instance attribute. You're (probably) thinking of > __getattr__ which isn't invoked when an instance attribute exists. Yes, Peter Otten already corrected me on that point last Friday and I posted thanking him on Sunday. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Wed Aug 10 11:56:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 16:56:45 +0100 Subject: allow line break at operators In-Reply-To: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 2:19 PM, Yingjie Lan wrote: > If ';' are employed (required), truely free line-splitting should be OK, > the operators may appear at the beginnings of the lines as you wish. > And if we require {} then truly free indentation should be OK too! But it wouldn't be Python any more. ChrisA From funthyme at gmail.com Wed Aug 10 12:06:02 2011 From: funthyme at gmail.com (John Pinner) Date: Wed, 10 Aug 2011 09:06:02 -0700 (PDT) Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> Message-ID: <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> On Aug 9, 1:36?am, Ben Finney wrote: > Ethan Furman writes: > > So if property docstrings are so hard to get to, what's the point in > > having them? > > Why would you expect there be a special point to them? > > Men, like all primates of any sex, have nipples. > > Properties, like any function in Python, have docstrings. So are you saying that men's nipples are pointless? You could be correct, except in cold weather maybe. John -- > > They're an accident of the history that led to their implementation, and > of the pre-existing parts that they're built from. There doesn't need to > be a point to them (though they might be useful for reasons incidental > for the reasons they exist). > > -- > ?\ ? ? ? ??I filled my humidifier with wax. Now my room is all shiny.? | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??Steven Wright | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney From stefan_ml at behnel.de Wed Aug 10 12:20:10 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Aug 2011 18:20:10 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810133146.GE5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: przemolicc at poczta.fm, 10.08.2011 15:31: > On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: >> On Wed, Aug 10, 2011 at 12:17 PM, wrote: >>> I'd like to write a python (2.6/2.7) script which connects to database, fetches >>> hundreds of thousands of rows, concat them (basically: create XML) >>> and then put the result into another table. Do I have any choice >>> regarding string concatenation in Python from the performance point of view ? >>> Since the number of rows is big I'd like to use the fastest possible library >>> (if there is any choice). Can you recommend me something ? >> >> First off, I have no idea why you would want to create an XML dump of >> hundreds of thousands of rows, only to store it in another table. >> However, if that is your intention, list joining is about as efficient >> as you're going to get in Python: >> >> lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries >> xml=""+"".join(lst)+"" >> >> This sets xml to 'asdfqwerzxcv' which >> may or may not be what you're after. > > since this process (XML building) is running now inside database (using native SQL commands) > and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which > will concat subset of the whole table (and then merge all of them at the end). > Basically: > - fetch all rows from the database (up to 1 million): what is recommended data type ? > - spawn X python processes each one: > - concat its own subset > - merge the result from all the subprocesses > > This task is running on a server which has many but slow cores and I am trying to divide this task > into many subtasks. Makes sense to me. Note that the really good DBMSes (namely, PostgreSQL) come with built-in Python support. You still didn't provide enough information to make me understand why you need XML in between one database and another (or the same?), but if you go that route, you can just read data through multiple connections in multiple threads (or processes), have each build up one (or more) XML entries, and then push those into a queue. Then another thread (or more than one) can read from that queue and write the XML items into a file (or another database) as they come in. If your data has a considerable size, I wouldn't use string concatenation or joining at all (note that it requires 2x the memory during concatenation), but rather write it into a file, or even just process the data on the fly, i.e. write it back into the target table right away. Reading a file back in after the fact is much more resource friendly than keeping huge amounts of data in memory. And disk speed is usually not a problem when streaming data from disk into a database. It may also be worth considering to write out literal SQL insert statements instead of XML. Most databases have a decent bulk upload tool. Stefan From ericsnowcurrently at gmail.com Wed Aug 10 12:27:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 10:27:20 -0600 Subject: __set__ method is not called for class attribute access In-Reply-To: <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> Message-ID: On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman wrote: > On Aug 5, 12:29?pm, Ryan wrote: >> In the context of descriptors, the __set__ method is not called for >> class attribute access. __set__ is only >> called to set the attribute on an instance instance of the owner class >> to a new value, value. WHY? > > It's an unfortunate asymmetry in the descriptor protocol. You can > write "class descriptors" with behaviour on get, but not on set. > > As others point out, metaclasses are an ugly way round this > (particularly given that *basically* a class can only have one > metaclass - so if you're inheriting from a class that already has a > custom metaclass you can't use this technique). Keep in mind that you can still do something like this: class XMeta(Base.__class__): "Customize here" class X(Base, metaclass=XMeta): "Do your stuff." They you would put your descriptor hacking in XMeta and still take advantage of the original metaclass. -eric > > Michael Foord > -- > http://voidspace.org.uk/ > -- > http://mail.python.org/mailman/listinfo/python-list > From fuzzyman at gmail.com Wed Aug 10 12:38:07 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 09:38:07 -0700 (PDT) Subject: how to dynamically generate __name__ for an object? References: Message-ID: <1419d2bf-d71a-4f85-afc1-215274bd4b9a@w11g2000vbp.googlegroups.com> On Aug 10, 4:25?pm, Ian Kelly wrote: > On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > > __name__ can be a descriptor, so you just need to write a descriptor > > that can be fetched from classes as well as instances. > > > Here's an example with a property (instance only): > > >>>> class Foo(object): > > ... ? @property > > ... ? def __name__(self): > > ... ? ? return 'bar' > > ... > >>>> Foo().__name__ > > 'bar' > > But: > > >>> Foo.__name__ > 'Foo' That's why I said "you just need to _write_ a descriptor that can be fetched from classes as well as instances". The example with property was to show that it *could* be a descriptor. You can write descriptors with custom behaviour when fetched from a class. However it turns out that you're right and I'm wrong; __name__ is special: >>> class descriptor(object): ... def __get__(*args): ... return 'bar' ... >>> class Foo(object): ... __name__ = descriptor() ... >>> Foo.__name__ 'Foo' >>> Foo().__name__ 'bar' >>> class Foo(object): ... name = descriptor() ... >>> Foo.name 'bar' As Eric points out in his original slot, types have their __name__ slot filled in with a string in typeobject.c All the best, Michael -- http://voidspace.org.uk/ From fuzzyman at gmail.com Wed Aug 10 12:40:03 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 09:40:03 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> Message-ID: On Aug 10, 5:27?pm, Eric Snow wrote: > On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman wrote: > > On Aug 5, 12:29?pm, Ryan wrote: > >> In the context of descriptors, the __set__ method is not called for > >> class attribute access. __set__ is only > >> called to set the attribute on an instance instance of the owner class > >> to a new value, value. WHY? > > > It's an unfortunate asymmetry in the descriptor protocol. You can > > write "class descriptors" with behaviour on get, but not on set. > > > As others point out, metaclasses are an ugly way round this > > (particularly given that *basically* a class can only have one > > metaclass - so if you're inheriting from a class that already has a > > custom metaclass you can't use this technique). > > Keep in mind that you can still do something like this: > > class XMeta(Base.__class__): > ? ? "Customize here" > > class X(Base, metaclass=XMeta): > ? ? "Do your stuff." > > They you would put your descriptor hacking in XMeta and still take > advantage of the original metaclass. Yeah, the way round the "more than one metaclass problem" is to have your new metaclass inherit from the first one. That's not a general purpose solution though. Michael -- http://voidspace.org.uk/ From ericsnowcurrently at gmail.com Wed Aug 10 12:54:54 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 10:54:54 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: References: Message-ID: On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > On Aug 7, 4:06?am, Eric Snow wrote: >> Thought I knew how to provide a dynamic __name__ on instances of a >> class. ?My first try was to use a non-data descriptor: >> >> # module base.py >> >> class _NameProxy(object): >> ? ? def __init__(self, oldname): >> ? ? ? ? self.oldname = oldname >> ? ? def __get__(self, obj, cls): >> ? ? ? ? if obj is None: >> ? ? ? ? ? ? return self.oldname >> ? ? ? ? if "__name__" not in obj.__dict__: >> ? ? ? ? ? ? return str(obj.__context__) >> ? ? ? ? return obj.__name__ >> >> class _BaseMeta(type): >> ? ? def __init__(cls, name, bases, namespace): >> ? ? ? ? cls.__name__ = _NameProxy(name) >> >> class Base(object): >> ? ? __metaclass__ = _BaseMeta >> >> $ python _base.py >> Traceback (most recent call last): >> ? ... >> ? File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ >> ? ? cls.__name__ = _NameProxy(name) >> TypeError: Error when calling the metaclass bases >> ? ? can only assign string to Base.__name__, not '_NameProxy' >> >> Needless to say I was surprised. ?After looking in typeobject.c, I >> believe that __name__ must be a string where classes are concerned[1]. >> ?So if I want all my instances to have a __name__ attribute, and for >> it to be dynamically provided if it isn't set on the instance, what >> are my options? ?Or maybe I did something wrong and it should work as >> I expected? >> > > __name__ can be a descriptor, so you just need to write a descriptor > that can be fetched from classes as well as instances. > > Here's an example with a property (instance only): > >>>> class Foo(object): > ... ? @property > ... ? def __name__(self): > ... ? ? return 'bar' > ... >>>> Foo().__name__ > 'bar' Thanks! Your example is exactly what I didn't try in the first place, but should have. I was thinking of __name__ on a class as a simple data attribute. My original worry was that by adding a descriptor for __name__ on my class, I would overwrite the name of the class, hence the elaborate descriptor. However, for type objects (classes) __name__ is a data descriptor and the actual name isn't stored in __name__. I was staring that right in the face (the link I provided is for the setter method of the __name__ "property" for type objects). I guess it was a "forest for the trees" moment. Because of attribute lookup in Python, "Base.__name__" uses the equivalent of "Base.__class__.__name__.__get__(..., Base, Base.__class__)". Anyway, thanks for making me see how dumb I am! -eric > > Michael > -- > http://voidspace.org.uk/ > -- > http://mail.python.org/mailman/listinfo/python-list > From usenet-nospam at seebs.net Wed Aug 10 13:55:20 2011 From: usenet-nospam at seebs.net (Seebs) Date: 10 Aug 2011 17:55:20 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: On 2011-08-10, Chris Angelico wrote: > And if we require {} then truly free indentation should be OK too! But > it wouldn't be Python any more. Would it really not be Python at all? I've seen bits of code in preprocessing-based "Python with {}" type things, and they still look like Python to me, only they favor explicit over implicit a little more strongly. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From irmen at -NOSPAM-xs4all.nl Wed Aug 10 14:26:36 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 10 Aug 2011 20:26:36 +0200 Subject: SocketServer expceion after upgrading to 2.7 In-Reply-To: References: Message-ID: <4e42cd5c$0$23837$e4fe514c@news2.news.xs4all.nl> On 10-08-11 15:42, Laszlo Nagy wrote: > Exception happened during processing of request from ('80.99.165.122', > 56069) > Traceback (most recent call last): > File "/usr/local/lib/python2.7/SocketServer.py", line 284, in > _handle_request_noblock > self.process_request(request, client_address) > File "/usr/local/lib/python2.7/SocketServer.py", line 311, in > process_request > self.shutdown_request(request) > File "/usr/local/lib/python2.7/SocketServer.py", line 459, in > shutdown_request > request.shutdown(socket.SHUT_WR) > TypeError: shutdown() takes exactly 0 arguments (1 given) > > > I get this error with a program, after upgrading to python 2.7. I'm > using a program that is based on SocketServer and SimpleXMLRPCDispatcher. > > Any idea how to fix this? Strange, I expected at least one or two more stack frames in the traceback you posted (from within the socket.py module). What platform are you on? What python version? What does this print on your system: >>> import socket >>> s=socket.socket() >>> s.shutdown(socket.SHUT_WR) Irmen From tdsimpson at gmail.com Wed Aug 10 14:55:27 2011 From: tdsimpson at gmail.com (MrPink) Date: Wed, 10 Aug 2011 11:55:27 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... Message-ID: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> I need a little nudge into the right direction with this problem. As an exercise for me to learn about Python, I am trying to determine the best way to search a list of "lottery drawings" for a match with a lottery ticket. Possible numbers for a drawing are: 5 whiteballs (wb): 1-55 1 blackball (bb): 1-49 example: wb1, wb2, wb3, wb4, wb5, bb Example list of lottery drawings: date,wb,wb,wb,wb,wb,bb 4/1/2011,5,1,45,23,27,27 5/1/2011,15,23,8,48,22,32 6/1/2011,33,49,21,16,34,1 7/1/2011,9,3,13,22,45,41 8/1/2011,54,1,24,39,35,18 ... Typically a lottery ticket can have multiple combinations for the ticket to be a winner. For example: 2 wb, 1 bb 3 wb 3 wb, 1 bb 4 wb 4 wb, 1 bb 5 wb 5 wb, 1 bb (jackpot winner) An object oriented solution might be to create a list of "Drawing" objects and then loop through the list to find a match for the ticket object. For example: if oDrawing[x] == ticket then "Do XYZ" Or I could just perform this task with procedures and loops and skip the object solution idea. Do Python developers have a preference? Would it be worth the overhead to initialize a list of drawing objects to search through? There is no database back-end, so no SQL, etc. I hope all that makes sense. Thanks for you help. From ameet.nanda at gmail.com Wed Aug 10 15:52:17 2011 From: ameet.nanda at gmail.com (Ameet Nanda) Date: Wed, 10 Aug 2011 12:52:17 -0700 Subject: Directions on accessing shared folder in windows network Message-ID: Hi, Can anyone point me to a way to access windows shared folders from the network using a python script. I tried accessing using open, which is mentioned to work perfectly on the web, but it gives me following errors >>>open(NW_PATH) it gives me a permission denied error as follows: >>> open("\\\\ameetn\\DropBox\\") Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: '\\\\ameetn\\' >>> open("\\\\ameetn\\DropBox") Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '\\\\ameetn\\DropBox' I am running Python 2.6 on Windows 7 platform. Thanks in advance, Ameet -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Aug 10 16:14:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Aug 2011 21:14:05 +0100 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: <4E42E68D.70900@mrabarnett.plus.com> On 10/08/2011 20:52, Ameet Nanda wrote: > Hi, > > Can anyone point me to a way to access windows shared folders from the > network using a python script. I tried accessing using open, which is > mentioned to work perfectly on the web, but it gives me following errors > > >>>open(NW_PATH) > > it gives me a permission denied error as follows: > > >>> open("\\\\ameetn\\DropBox\\") > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: '\\\\ameetn\\' > > >>> open("\\\\ameetn\\DropBox") > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied: '\\\\ameetn\\DropBox' > > I am running Python 2.6 on Windows 7 platform. > "ameetn" is the name of the machine and "DropBox" is the name of a shared folder on that machine. The answer hasn't changed. 'open' is for opening _files_. Give 'open' the path to a _file_. From lists at cheimes.de Wed Aug 10 16:43:05 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Aug 2011 22:43:05 +0200 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: Am 10.08.2011 21:52, schrieb Ameet Nanda: > Hi, > > Can anyone point me to a way to access windows shared folders from the > network using a python script. I tried accessing using open, which is > mentioned to work perfectly on the web, but it gives me following errors The open() function wraps the fopen() function, which doesn't support UNC, just local paths. You have to mount the network share first (assign a drive letter). Christian From ben+python at benfinney.id.au Wed Aug 10 17:51:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 07:51:32 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <87fwl9hr4r.fsf@benfinney.id.au> Seebs writes: > On 2011-08-10, Chris Angelico wrote: > > And if we require {} then truly free indentation should be OK too! > > But it wouldn't be Python any more. > > Would it really not be Python at all? See the Python interpreter's response to ?from __future__ import braces?. > I've seen bits of code in preprocessing-based "Python with {}" type > things, and they still look like Python to me, only they favor > explicit over implicit a little more strongly. They introduce unnecessary ambiguity: the indentation-as-structure and braces-as-structure can then disagree. In which case either the Python interpreter must guess the programmer's intent (very un-Pythonic), or it throws an error and the programmer must do busy-work to keep braces and indentation in agreement (also un-Pythonic). The ambiguity is resolved by having exactly one of indentation or braces determining structure: Python uses indentation. In which case, braces are pointless for indicating block structure. -- \ ?Without cultural sanction, most or all of our religious | `\ beliefs and rituals would fall into the domain of mental | _o__) disturbance.? ?John F. Schumaker | Ben Finney From rosuav at gmail.com Wed Aug 10 18:42:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 23:42:06 +0100 Subject: allow line break at operators In-Reply-To: <87fwl9hr4r.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On Wed, Aug 10, 2011 at 10:51 PM, Ben Finney wrote: > Seebs writes: >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor >> explicit over implicit a little more strongly. > > They introduce unnecessary ambiguity: the indentation-as-structure and > braces-as-structure can then disagree. > > The ambiguity is resolved by having exactly one of indentation or braces > determining structure: Python uses indentation. In which case, braces > are pointless for indicating block structure. That's why it wouldn't be Python. It would have to use the braces and not the indentation. ChrisA PS. I mistakenly sent this to a Gilbert & Sullivan group first. Oddly enough, opera-goers are not used to discussing the relative merits of braces vs indentation in code. From gelonida at gmail.com Wed Aug 10 18:44:48 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 00:44:48 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) Message-ID: Hi, I'd like to install psyco on my windows host I'm using python 2.6.4 (32 bit version) I installed easy_intall and pip easy_install psyco and pip install psyco fail both with the message error: Setup script exited with error: Unable to find vcvarsall.bat I read, that this means I shoul dinstall a C-compiler I also read, that I should NOT Micrusoft Visual C++ Express 2010 (which is unfortunately exactly the version, which I installed for some other activity. So my question: - If I install visual Studio 2008 addtiojnally to visualstudia 2010, will easy_install find this compiler? - I read about the alternative of using MingW instead of Visual Studio Express 2008. What could influence my choice of Compiler? Thanks for any suggestions From python.list at tim.thechases.com Wed Aug 10 19:26:24 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Aug 2011 18:26:24 -0500 Subject: Python & Sullivan In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4E4313A0.5070401@tim.thechases.com> On 08/10/2011 05:42 PM, Chris Angelico wrote: > PS. I mistakenly sent this to a Gilbert& Sullivan group > first. Oddly enough, opera-goers are not used to discussing > the relative merits of braces vs indentation in code. It's only fair turnabout: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html -tkc From steve+comp.lang.python at pearwood.info Wed Aug 10 19:32:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 09:32:12 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> Ian Kelly wrote: > On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano > wrote: >>> Without the parentheses, this is legal but (probably) useless; it >>> applies the unary + operator to the return value of those functions. >>> Putting the + at the end of the previous line at least prevents that, >>> since most unary operators bind to the operand on the right; >> >> Not so: >> >>>>> x = (42 + - >> ... ? ? 100) >>>>> >>>>> x >> -58 > > That is still binding to the operand on the "right" (i.e., the > sequentially later). And it still does not cause the problem that > Chris was talking about, since without the parentheses that would be a > syntax error. So I guess I'm not certain what exactly it is that > you're trying to demonstrate here. Chris stated that putting the unary + at the end of the line prevents "that", that being applying the unary + operator to the value on the right. But that is not the case -- unary prefix operators in Python can be separated from their operands by whitespace, including newlines. (Python doesn't have any unary postfix operators.) -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 10 19:37:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 09:37:06 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> Message-ID: <4e431623$0$29967$c3e8da3$5496439d@news.astraweb.com> John Pinner wrote: > On Aug 9, 1:36?am, Ben Finney wrote: >> Ethan Furman writes: >> > So if property docstrings are so hard to get to, what's the point in >> > having them? >> >> Why would you expect there be a special point to them? >> >> Men, like all primates of any sex, have nipples. >> >> Properties, like any function in Python, have docstrings. > > So are you saying that men's nipples are pointless? > > You could be correct, except in cold weather maybe. Groan. However, off-topic but interesting, there is at least one species of bat where the males are known to routinely lactate and feed baby bats. http://en.wikipedia.org/wiki/Male_lactation So just because a feature is an accident of history, doesn't mean that a use can't be found for it. -- Steven From jackhatterly at hotmail.com Wed Aug 10 19:39:30 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Wed, 10 Aug 2011 23:39:30 +0000 Subject: Cookie Problem Message-ID: Hi; I'm trying to get this cookie code to work but it doesn't set the properties I want set (expires, path, comment, etc.). When I delete the cookie and run the script it duly creates a cookie. However, when I reload the page none of the morsels have values associated with them. I also do not see values when I look for them in my FireFox CookieCuller. I pretty much copied this code from an online tutorial so I'm wondering where the problem is. #!/usr/bin/env python import string import os import datetime, Cookie, random import time ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = str(time.time()) print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') # The first time the page is run there will be no cookies if not cookie_string: print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = str(time.time()) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/var/www/html/my_site/' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 else: # Run the page twice to retrieve the cookie print '

The returned cookie string was "' + cookie_string + '"

' # cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1], '.', '')[:-1] # load() parses the cookie string cookie.load(cookie_string) # Use the value attribute of the cookie to get it lastvisit = float(cookie['lastvisit'].value) for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' print '' TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 10 19:54:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 00:54:38 +0100 Subject: Python & Sullivan In-Reply-To: <4E4313A0.5070401@tim.thechases.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4E4313A0.5070401@tim.thechases.com> Message-ID: On Thu, Aug 11, 2011 at 12:26 AM, Tim Chase wrote: > On 08/10/2011 05:42 PM, Chris Angelico wrote: >> >> PS. I mistakenly sent this to a Gilbert& ?Sullivan group >> first. Oddly enough, opera-goers are not used to discussing >> the relative merits of braces vs indentation in code. > > It's only fair turnabout: > > http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html Yes, I know about that one. My problem is that I snap off quick responses to both lists, and sometimes type "sav" instead of "py" or vice versa. Usually I catch it before hitting Send, though!! On MUDs, we call that a mischannel. I've now mischanneled both directions. :| ChrisA From rosuav at gmail.com Wed Aug 10 19:55:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 00:55:36 +0100 Subject: allow line break at operators In-Reply-To: <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 11, 2011 at 12:32 AM, Steven D'Aprano wrote: > Chris stated that putting the unary + at the end of the line > prevents "that", that being applying the unary + operator to the value on > the right. But that is not the case -- unary prefix operators in Python can > be separated from their operands by whitespace, including newlines. > Right, I forgot that. It certainly would not be normal to do it that way, though. ChrisA From rdmoores at gmail.com Wed Aug 10 19:57:34 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Wed, 10 Aug 2011 16:57:34 -0700 Subject: Puzzled about the output of my demo of a proof of The Euler Series Message-ID: I saw an interesting proof of the limit of The Euler Series on math.stackexchange.com at . Scroll down to Hans Lundmark's post. I thought I'd try to see this "pinching down" on the limit of pi**2/6. See my attempt, and output for n = 150 at . What puzzles me is that upper_bound_partial_sum (lines 39 and 60) is always smaller than the limit. It should be greater than the limit, right? If not, no pinching between upper_bound_partial_sum and lower_bound_partial_sum. I've checked and double-checked the computation, but can't figure out what's wrong. Thanks, Dick Moores From steve+comp.lang.python at pearwood.info Wed Aug 10 20:32:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 10:32:34 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-10, Chris Angelico wrote: >> And if we require {} then truly free indentation should be OK too! But >> it wouldn't be Python any more. > > Would it really not be Python at all? Of course it wouldn't be. Every function, class, if, while, for, try...except block etc. in existing Python code would be illegal if {} were required. This would be an order of magnitude bigger change than going from Python 2 to 3, where the biggest syntax change is that print is no longer a statement. Even more so if ; were to become required, as suggested by the Original Poster. > I've seen bits of code in preprocessing-based "Python with {}" type > things, and they still look like Python to me, only they favor explicit > over implicit a little more strongly. "Looks like" Python does not equal "is Python". Cobra looks like Python, as do Boo, Groovy and Ruby, or OCaml with "twt" turned on ("the whitespace thing"). The similarities are especially strong for Boo and Cobra, but there is no doubt that they are different languages. In general, languages that aim to look like executable pseudo-code will converge on a similar look, because executable pseudo-code tends to be based on natural language (usually English) and mathematics syntax. -- Steven From ericsnowcurrently at gmail.com Wed Aug 10 20:38:17 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 18:38:17 -0600 Subject: code object differences between 2.7 and 3.3a Message-ID: Specifically, I am wondering why there is a difference for co_names. Here is a function that exercises the different code object pieces[1]: def g(y=5): a = 7 def f(x, w=y, z=4, *args, **kwargs): b = a c = global_x return f f1 = g() Here are the results for 2.7: >>> for name in dir(f1.func_code): print("%s -> %s" % (name, getattr(f1.func_code, name))) ... co_argcount -> 3 co_cellvars -> () co_code -> }t}dS co_consts -> (None,) co_filename -> co_firstlineno -> 3 co_flags -> 15 co_freevars -> ('a',) co_lnotab -> co_name -> f co_names -> ('a', 'b', 'global_x', 'c') co_nlocals -> 7 co_stacksize -> 1 co_varnames -> ('x', 'w', 'z', 'args', 'kwargs', 'c', 'b') And for 3.3: >>> for name in dir(f1.__code__): print("%s -> %s" % (name, getattr(f1.__code__, name))) ... co_argcount -> 3 co_cellvars -> () co_code -> b'\x88\x00\x00}\x05\x00t\x00\x00}\x06\x00d\x00\x00S' co_consts -> (None,) co_filename -> co_firstlineno -> 3 co_flags -> 31 co_freevars -> ('a',) co_kwonlyargcount -> 0 co_lnotab -> b'\x00\x01\x06\x01' co_name -> f co_names -> ('global_x',) co_nlocals -> 7 co_stacksize -> 1 co_varnames -> ('x', 'w', 'z', 'args', 'kwargs', 'b', 'c') While there are several differences, the one I care about is co_name. For 2.7 it's what I would expect. However, for 3.3 it's not[2][3]. It is actually nicer for my application this way, but I want to verify the situation before I get me hopes up. :) Before I go email-list-diving or digging through PyEval_EvalCodeEx, I wanted to see if anyone has any insight about this change in co_names. Thanks! -eric [1] yes, 3.x also supports keyword-only arguments. I tried this on 3.3 with extra kw-only arguments and it was the same outcome. [2] The documentation for the inspect module gives an incomplete listing of the code object attributes: The description of co_names there ("tuple of names of local variables") seems inconsistent with what I am seeing. It's probably just that I am misinterpreting that list or the doc needs an update. [3] My guess is that co_names was seen as bloated and the superfluous items removed, leaving only the un-closed free variables; co_freevars is the closed free variables. To get the same tuple as the 2.7 version, you could compose it from co_freevars, co_names, and the end of co_varnames. From rosuav at gmail.com Wed Aug 10 20:47:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 01:47:49 +0100 Subject: allow line break at operators In-Reply-To: <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 11, 2011 at 1:32 AM, Steven D'Aprano wrote: >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor explicit >> over implicit a little more strongly. > > "Looks like" Python does not equal "is Python". Cobra looks like Python, as > do Boo, Groovy and Ruby, or OCaml with "twt" turned on ("the whitespace > thing"). The similarities are especially strong for Boo and Cobra, but > there is no doubt that they are different languages. > > In general, languages that aim to look like executable pseudo-code will > converge on a similar look, because executable pseudo-code tends to be > based on natural language (usually English) and mathematics syntax. "Looks like" is a poor indication of anything much; "feels like" is a bit vague, but may be more useful. If you can manipulate objects and references to objects, if you can use Python's rich object set and standard library, if you can use Python-like features using reasonably readable syntax, then it feels like Python. Little things don't matter (eg whether 'print' is a keyword or a function). Big things do (eg having to explicitly deallocate objects). Lots of languages "look like" C. Some of them function like C (eg C++), and most definitely "feel like" C. Others don't. ChrisA From ben+python at benfinney.id.au Wed Aug 10 20:57:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 10:57:37 +1000 Subject: Python & Sullivan References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <871uwsix32.fsf@benfinney.id.au> Tim Chase writes: > On 08/10/2011 05:42 PM, Chris Angelico wrote: > > PS. I mistakenly sent this to a Gilbert& Sullivan group > > first. Oddly enough, opera-goers are not used to discussing > > the relative merits of braces vs indentation in code. > > It's only fair turnabout: > > http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html Also of interest: Do a web search for ?debian dueling banjos?. Or read about the phenomenon at . -- \ ?The restriction of knowledge to an elite group destroys the | `\ spirit of society and leads to its intellectual | _o__) impoverishment.? ?Albert Einstein | Ben Finney From ben+python at benfinney.id.au Wed Aug 10 20:59:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 10:59:19 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> <4e431623$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrekhifs.fsf@benfinney.id.au> Steven D'Aprano writes: > So just because a feature is an accident of history, doesn't mean that > a use can't be found for it. Which I explicitly noted in my message. I suppose it's inevitable for the nuances of one's utterances to be forgotten as the discussion progresses, but darn if it ain't annoying. -- \ ?Not using Microsoft products is like being a non-smoker 40 or | `\ 50 years ago: You can choose not to smoke, yourself, but it's | _o__) hard to avoid second-hand smoke.? ?Michael Tiemann | Ben Finney From jianbao.tao at gmail.com Wed Aug 10 21:24:53 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 18:24:53 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings Message-ID: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Greetings, folks, I am using python 2.7.2. Here is something I got: >>> a = 'popular' >>> i = a.find('o') >>> j = a.find('a') >>> a[i:j] 'opul' Well, I expected a[i:j] to be 'opula', and can't think of any reason why this is not happening. So, can anybody help me out about this? Thank you very much. Jim From rosuav at gmail.com Wed Aug 10 21:46:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 02:46:23 +0100 Subject: Cookie Problem In-Reply-To: References: Message-ID: On Thu, Aug 11, 2011 at 12:39 AM, Jack Hatterly wrote: > ??? cookie['lastvisit'] = str(time.time()) > ??? cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 > ??? cookie['lastvisit']['path'] = '/var/www/html/my_site/' > ??? cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' > ??? cookie['lastvisit']['domain'] = '.www.my_site.com' > ??? cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 > ??? cookie['lastvisit']['secure'] = '' > ??? cookie['lastvisit']['version'] = 1 Some of these values look wrong. Your 'path' ought to be as the browser sees it, and your 'domain' ditto; the only way that these would make sense is if you're setting this cookie on a page such as: http://foo.www.my_site.com/var/www/html/my_site/blah/blah and you want to also see the cookie on the page: http://bar.www.my_site.com/var/www/html/my_site/asdf/qwer Otherwise, I would recommend omitting those elements and allowing the defaults through. ChrisA From python at mrabarnett.plus.com Wed Aug 10 21:48:35 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 02:48:35 +0100 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Message-ID: <4E4334F3.5000005@mrabarnett.plus.com> On 11/08/2011 02:24, Jim wrote: > Greetings, folks, > > I am using python 2.7.2. Here is something I got: >>>> a = 'popular' >>>> i = a.find('o') >>>> j = a.find('a') >>>> a[i:j] > 'opul' > > Well, I expected a[i:j] to be 'opula', and can't think of any reason > why this is not happening. So, can anybody help me out about this? > Thank you very much. > Python uses half-open ranges, which means that the start position is inclusive and the end position is exclusive. This means that a[i:j] returns the string starting at position i and extending upto, but excluding, position j. The reason that Python uses half-open ranges is that experience (with the language Mesa) has shown that it results in fewer programming errors that the alternatives. From rosuav at gmail.com Wed Aug 10 22:14:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 03:14:30 +0100 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <4E4334F3.5000005@mrabarnett.plus.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4E4334F3.5000005@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 2:48 AM, MRAB wrote: > Python uses half-open ranges, which means that the start position is > inclusive and the end position is exclusive. > Or if you prefer: Python identifies positions between characters, rather than characters. And I agree that it's better than the alternative - in fact, I wish other systems could work the same way (eg Bible references). If you think about position 0 being the very beginning of the string, and position len(s) being the very end, then you slice the string from position to position and take the characters between. When you index the string for a particular character, you aim at a position and take the character after it. Chris Angelico From ryan at rfk.id.au Wed Aug 10 22:17:48 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 11 Aug 2011 02:17:48 -0000 Subject: PyCon Australia 2011: Registration Closing Soon! Message-ID: <20110811021748.15825.55916@pyglet.org> Hi Everyone, Registrations for PyCon Australia 2011 are closing soon! The conference is just over a week away, so we need final numbers in the next few days. If you're planning to attend, please register now! PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Registration Closing Soon 2. Coffee 3. Hosting Panel 4. More Sponsors Announced Please pass this message on to those you feel may be interested. Registration Closing Soon ========================= Full Registrations for the conference will be closing on: Monday 15th August: Full Registrations close That's only five days away, so register now to be sure you don't miss out. By request, we will still allow latecomers to register until just before the conference. However, since it's after the deadline for catering and printing, you won't be entitled to a T-shirt or a seat at the conference dinner: Thursday 18th August: Last-Minute Registrations close Please note that we will *not* accept registrations at the door. So don't delay, register now at: http://pycon-au.org/reg Coffee ====== Thanks to gold sponsors Arclight, we will be able to provide one of the most requested additions to this year's conference: Coffee! Yes, Arclight have generously agreed to provide a free coffee cart for the duration of the conference. And there was much rejoicing. Hosting Panel ============= Saturday evening will feature an informal panel discussion with several hosting providers. Come and hear from our hosting panel about why their services are right for hosting your next Python project! Each group will give a quick 5 minute spiel, to be followed by a casual drink before the conference dinner. This event is happening in a private area at Mr B's pub, across the street from the SMC. As this is a licensed venue anyone under 18 will have to be accompanied by a parent or guardian. More Sponsors Announced ======================= We are delighted to confirm that the Django Software Foundation and Ninefold have joined as Silver sponsors. In addition, Arclight have upgraded to Gold Sponsorship, Anchor have agreed to sponsor video production, and GitHub will be sponsoring internet access. Thanks once again to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Gold: Arclight Video: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Bitbucket by Atlassian Silver: Microsoft Silver: Django Software Foundation Silver: Ninefold Internet: GitHub Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details From missive at hotmail.com Wed Aug 10 22:39:53 2011 From: missive at hotmail.com (Lee Harr) Date: Thu, 11 Aug 2011 07:09:53 +0430 Subject: [ANNC] pynguin-0.11 python turtle graphics application Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues to expand basic functionality and ??? explores more user-friendly options in the interface. Pynguin is tested with Python 2.7.1 and PyQt 4.8.3 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.11: ??? Session ??????? - all settings now moved in to menus and settings dialogs ??? Pynguin API ??????? - added .label() method to have a label attached to a pynguin ??????????? - also accessible as .name attribute ??????? - added .speed() method to change speed from user code ??????? - viewcoords() now returns integers by default ??????????? - pass floats=True to get the float values instead ??????? - added .track() and .notrack() methods for user code ??? Canvas ??????? - added support for custom avatars ??????????? - both svg and bitmap images supported ??????? - fixed motion when drawing slow circles with pen up ??????? - don't draw circles when pen is up and speed is instant ??????? - expand canvas when resizing window ??? Integrated Editor ??????? - added "Test / Run all" button ??????? - improved handling of external .py files ??? Integrated Console ??????? - now gives correct call syntax when using test/run on classes ??? Examples ??????? - make examples use new viewcoords() API ??????? - fixed multi.pyn scatter example ??????? - make multi.pyn follow examples work with existing pynguins ??????? - demonstrate labels in multi.pyn follow example ??????? - fix penup() in oo.pyn ZZ example ??????? - add centered circle in oo.pyn ZZ example ??? General ??????? - fixed examples getting gzipped in .deb distribution file ??????? - added a way to dump contents of .pyn from command line From lanyjie at yahoo.com Wed Aug 10 22:52:55 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 19:52:55 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> :And if we require {} then truly free indentation should be OK too! But :it wouldn't be Python any more. Of course, but not the case with ';'. Currently ';' is optional in Python, But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. So the decision is: shall we change ';' from optional to mandatory to allow free line splitting? Yingjie From steve+comp.lang.python at pearwood.info Wed Aug 10 22:56:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 12:56:43 +1000 Subject: Bizarre behavior of the 'find' method of strings References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Message-ID: <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Aug 2011 11:24 am Jim wrote: > Greetings, folks, > > I am using python 2.7.2. Here is something I got: >>>> a = 'popular' >>>> i = a.find('o') >>>> j = a.find('a') >>>> a[i:j] > 'opul' > > Well, I expected a[i:j] to be 'opula', and can't think of any reason why > this is not happening. So, can anybody help me out about this? Thank you > very much. Your subject line says: Bizarre behavior of the 'find' method of strings What makes you think this is a problem with the find method? As a programmer, you should be able to isolate where the problem *actually* occurs: >>> a = 'popular' >>> a.find('o') 1 >>> a.find('a') 5 So there is no problem with the find method: it correctly finds the index (starting at zero, not one) of the first (going left-to-right) matching substring. Now, if you take a slice, you get an unexpected (to you) result: >>> a[1:5] 'opul' It doesn't matter where the 1 and 5 come from. The slice can't tell that they were the output of find, or how they were generated: >>> a[1000-999:20/4] 'opul' Now that you have isolated the actual problem, you can ask a better question: "Why does slicing not work the way I expect?" Answer: because Python uses half-open slices, where the end parameter is not included. The reason for that is that experience with other languages shows that it leads to fewer "off-by-one" errors. See also: http://mail.python.org/pipermail/tutor/2010-December/080592.html http://en.wikipedia.org/wiki/Off-by-one_error -- Steven From lanyjie at yahoo.com Wed Aug 10 22:58:22 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 19:58:22 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: <1313031502.48609.YahooMailNeo@web121515.mail.ne1.yahoo.com> On Wed, Aug 10, 2011 at 1:58 PM, Yingjie Lan wrote: > Is it possible for python to allow free splitting of single-line statements > without the backslashes, if we impose that expressions can only be split > when it is not yet a finished expression? :The trouble is that in a lot of cases, the next statement after an :unfinished expression could conceivably be a continuation of it. If :this were permitted, it would have to also require that the :continuation lines be indented, to avoid the problem described above. :It'd still have the potential to mis-diagnose errors, though. Indentation is a good idea to reduce the likelihood of such troubles. and also produce code that is easier to read. Yingjie From miki.tebeka at gmail.com Wed Aug 10 23:24:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:24:53 -0700 (PDT) Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: You can download the sources tarball and when building specify the compiler. See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw From miki.tebeka at gmail.com Wed Aug 10 23:24:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:24:53 -0700 (PDT) Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: You can download the sources tarball and when building specify the compiler. See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw From miki.tebeka at gmail.com Wed Aug 10 23:35:54 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:35:54 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: Python built in types are enough for this problem IMO. You can use sets of tuples to specify ticket and drawings and then just do set intersection. Say the drawing is set([(5, 'wb'), (1, 'wb'), (45, 'wb'), (23, 'wb'), (27, 'wb')]) (keeping black ball out). The you can create a score function: Side note: I might used a namedtuple to have drawing.whites, drawing.black. def score(ticket_whites, ticket_black, drawing_whites, drawing_black): num_whites = ticket_whites & drawing_whites black_matching = ticket_black == drawing_black return { (2, True) : 1, (3, False) : 2, (3, True) : 3, (4, False) : 4, (4, True) : 5, (5, False) : 6, (5, True) : 10 }[(num_whites, black_matching)] From philip at semanchuk.com Wed Aug 10 23:36:52 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 10 Aug 2011 23:36:52 -0400 Subject: multiprocessing timing issue In-Reply-To: References: Message-ID: On Aug 9, 2011, at 1:07 PM, Tim Arnold wrote: > Hi, I'm having problems with an empty Queue using multiprocessing. > > The task: > I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. > I'm using multiprocessing to do the data-gathering simultaneously. > > Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. > > My problem is that sometimes the Queue is empty and I guess it's > because the get_data() method takes a lot of time. > > I've used multiprocessing before, but never with a Queue like this. > Any notes or suggestions are very welcome. Hi Tim, THis might be a dumb question, but...why is it a problem if the queue is empty? It sounds like you figured out already that get_data() sometimes takes longer than your timeout. So either increase your timeout or learn to live with the fact that the queue is sometimes empty. I don't mean to be rude, I just don't understand the problem. Cheers Philip From clp2 at rebertia.com Wed Aug 10 23:49:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 20:49:49 -0700 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 7:56 PM, Steven D'Aprano wrote: > On Thu, 11 Aug 2011 11:24 am Jim wrote: > >> Greetings, folks, >> >> I am using python 2.7.2. Here is something I got: >>>>> a = 'popular' >>>>> i = a.find('o') >>>>> j = a.find('a') >>>>> a[i:j] >> 'opul' >> >> Well, I expected a[i:j] to be 'opula', and can't think of any reason why >> this is not happening. So, can anybody help me out about this? Thank you >> very much. > "Why does slicing not work the way I expect?" > > Answer: because Python uses half-open slices, where the end parameter is not > included. The reason for that is that experience with other languages shows > that it leads to fewer "off-by-one" errors. > > See also: > > http://mail.python.org/pipermail/tutor/2010-December/080592.html > http://en.wikipedia.org/wiki/Off-by-one_error And further: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html Cheers, Chris From drsalists at gmail.com Thu Aug 11 00:03:28 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 10 Aug 2011 21:03:28 -0700 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: FWIW, a few months ago I was working on a database application on Windows, and I benchmarked the psyco-enhanced version consistently running slower than the non-psyco version. The same code on Linux was faster with psyco though. If you need performance, and you aren't constrained by module availability, you probably should use PyPy instead. On Wed, Aug 10, 2011 at 3:44 PM, Gelonida N wrote: > Hi, > > I'd like to install psyco on my windows host > > > I'm using python 2.6.4 (32 bit version) > > I installed easy_intall and pip > > easy_install psyco > and > pip install psyco fail both with the message > error: Setup script exited with error: Unable to find vcvarsall.bat > > > I read, that this means I shoul dinstall a C-compiler > I also read, that I should NOT Micrusoft Visual C++ Express 2010 > (which is unfortunately exactly the version, which I installed for some > other activity. > > > So my question: > > - If I install visual Studio 2008 addtiojnally to visualstudia 2010, > will easy_install find this compiler? > - I read about the alternative of using MingW instead of Visual Studio > Express 2008. > > What could influence my choice of Compiler? > > Thanks for any suggestions > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Aug 11 00:16:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 21:16:54 -0700 Subject: allow line break at operators In-Reply-To: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, I think of it more as that Python deigns to permit semicolons. > But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? Hell no, considering that the sizable majority of lines *aren't* split, which makes those semicolons completely redundant to their accompanying newlines. We'd be practicing poor Huffman coding by optimizing for the *un*common case. It would also add punctuational noise to what is otherwise an amazingly clean and readable syntax. Accidental semicolon omission is (IMO) the most irritating source of syntax (and, inadvertently, sometimes other more serious) errors in curly-braced programming languages. Such a core syntax feature is not going to be changed lightly (or likely ever). Cheers, Chris From steve+comp.lang.python at pearwood.info Thu Aug 11 00:18:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 14:18:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in > magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? Why on earth would you want to break backwards compatibility of millions of Python scripts and programs, and require extra, unnecessary line-noise on every single line of Python code, just so that you can occasionally avoid a writing a pair of parentheses? This will never happen. Forget it. Python is more likely to get static types than compulsory semi-colons. -- Steven From jianbao.tao at gmail.com Thu Aug 11 00:29:01 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 21:29:01 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for all you guys. Now I got it. To Steven, I was in a little rush when I put this post. But you are right. It's not the find method's problem. From jianbao.tao at gmail.com Thu Aug 11 00:29:01 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 21:29:01 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for all you guys. Now I got it. To Steven, I was in a little rush when I put this post. But you are right. It's not the find method's problem. From fd0man at gmail.com Thu Aug 11 00:51:52 2011 From: fd0man at gmail.com (Michael Trausch) Date: Thu, 11 Aug 2011 00:51:52 -0400 Subject: allow line break at operators In-Reply-To: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: Perhaps it could be made an optional thing to enable; for example, some languages by default do dynamic typing, but with an option contained as the first statement of the file can enforce static typing. On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? > > Yingjie > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Thu Aug 11 00:59:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 04:59:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Seebs wrote: >> On 2011-08-10, Chris Angelico wrote: >>> And if we require {} then truly free indentation should be OK too! But >>> it wouldn't be Python any more. >> Would it really not be Python at all? > Of course it wouldn't be. Every function, class, if, while, for, > try...except block etc. in existing Python code would be illegal if {} were > required. So? Since there has never been an indentation-related problem in the history of human endeavors, automatically adding the braces would be completely trivial. How much of the language *specification* would change? > In general, languages that aim to look like executable pseudo-code will > converge on a similar look, because executable pseudo-code tends to be > based on natural language (usually English) and mathematics syntax. This is an interesting point. I guess I meant "look like" in a more abstract sense; the basic idea of what it's like to read the code, and what you have to keep in mind while doing so. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 00:59:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 04:59:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On 2011-08-10, Ben Finney wrote: > Seebs writes: >> On 2011-08-10, Chris Angelico wrote: >> > And if we require {} then truly free indentation should be OK too! >> > But it wouldn't be Python any more. >> Would it really not be Python at all? > See the Python interpreter's response to ???from __future__ import braces???. I'm aware of that. I have seen all the counterarguments, and what I've mostly become convinced of is this: 1. Indentation as flow control was a bad idea. 2. People are subconsciously aware of this. 3. There is a HUGE degree of emotional investment in defending it. The responses I have seen on this issue are highly emotional, full of insults, full of blame-throwing, and utterly contrary to the basic engineering spirit I usually see in programming communities. In other languages, and even in Python on any issue but this one, I regularly see people acknowledge shortcomings and explain either why they think the tradeoffs are good, or why they are willing to put up with it anyway. The characteristic vehemence and hostility this issue produces are the surest sign of people who have a desperate need not to acknowledge the elephant in the room. >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor >> explicit over implicit a little more strongly. > They introduce unnecessary ambiguity: the indentation-as-structure and > braces-as-structure can then disagree. Yes, they can. > In which case either the Python interpreter must guess the programmer's > intent (very un-Pythonic), or it throws an error and the programmer must > do busy-work to keep braces and indentation in agreement (also > un-Pythonic). The obvious answer would be: * Braces win because they are explicit rather than implicit. * Everyone would use things configured to throw a warning or error. The thing is... This whole argument rests on the assumption that if there are no braces, there is only one set of things, but if you have braces, there are two. This is untrue. If there are no braces, there are two things describing flow control; indentation and programmer intent. With braces, there's three. The most common misalignment is between the code as interpreted by the computer and the programmer's intent. Neither system prevents this, but that's where all the real hassle comes from. My expectation would be that the only times braces and indentation would be "ambiguous" would be cases where the indentation got screwed up. In these cases, I would MUCH prefer to get a fatal error than to have things run in a way entirely unrelated to the intent I had when I wrote the code. > The ambiguity is resolved by having exactly one of indentation or braces > determining structure: Python uses indentation. In which case, braces > are pointless for indicating block structure. I don't think so, any more than I think parentheses which happen to align with the existing precendence rules are pointless. In the real world, we are confronted constantly with tools which work perfectly with every programming language but Python or very old FORTRAN, but which mangle Python code sporadically and inexplicably. Mail servers chew up whitespace like there's no tomorrow. Web pages find innovative new explanations for why those leading spaces don't need to be displayed. I like Python a lot in some ways, but I am really sick of the insistance that this godawful wart is the sublime epitome of all perfection, never to be improved on. It was a really interesting experiment. As sometimes happens, the experiment discovered things that no one could have reasonably anticipated without running the experiment. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Thu Aug 11 01:07:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 22:07:42 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: > On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? On Wed, Aug 10, 2011 at 9:51 PM, Michael Trausch wrote: > Perhaps it could be made an optional thing to enable; for example, some > languages by default do dynamic typing, but with an option contained as the > first statement of the file can enforce static typing. I am intrigued. What languages(s) have the feature you refer to? Cheers, Chris From fd0man at gmail.com Thu Aug 11 01:17:37 2011 From: fd0man at gmail.com (Michael Trausch) Date: Thu, 11 Aug 2011 01:17:37 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: VB (classic; .NET versions no longer have it) had an "option explicit" where you had to define each variable explicitly, otherwise by default you created variables simply by assigning to them. They did it that way to enable backwards compatibility for those who wanted the old style. Most people wound up using "option explicit" and it is now the default (and afaik only, but I don't use vb.net so I cannot say that for sure) way of doing things. Somthing like an "option" keyword (which would only be a keyword until the first executable statement, e.g., would have to be before even imports) could enable things like "semicolon" or "explicit", or whatever really, and only affect those who opt in. If no code is ever seen using the option, it can even be removed. Wouldn't be a bad way to test changes that would impact the syntax of the language, actually... On Aug 11, 2011 1:07 AM, "Chris Rebert" wrote: >> On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: >>> :And if we require {} then truly free indentation should be OK too! But >>> >>> :it wouldn't be Python any more. >>> >>> Of course, but not the case with ';'. Currently ';' is optional in Python, >>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>> magnitude. >>> >>> So the decision is: shall we change ';' from optional to mandatory >>> to allow free line splitting? > > On Wed, Aug 10, 2011 at 9:51 PM, Michael Trausch wrote: >> Perhaps it could be made an optional thing to enable; for example, some >> languages by default do dynamic typing, but with an option contained as the >> first statement of the file can enforce static typing. > > I am intrigued. What languages(s) have the feature you refer to? > > Cheers, > Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Aug 11 01:26:35 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 10 Aug 2011 22:26:35 -0700 Subject: multiprocessing timing issue References: Message-ID: Tim Arnold wrote: > >The task: >I have a bunch of chapters that I want to gather data on individually >and then update a report database with the results. >I'm using multiprocessing to do the data-gathering simultaneously. > >Each chapter report gets put on a Queue in their separate processes. >Then each report gets picked off the queue and the report database is >updated with the results. > >My problem is that sometimes the Queue is empty and I guess it's >because the get_data() method takes a lot of time. > >I've used multiprocessing before, but never with a Queue like this. >Any notes or suggestions are very welcome. The obvious implication is that your timeout is simply not long enough for your common cases. If you know how many chapters to expect, why have a timeout at all? Why not just wait forever? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From casevh at gmail.com Thu Aug 11 01:44:47 2011 From: casevh at gmail.com (casevh) Date: Wed, 10 Aug 2011 22:44:47 -0700 (PDT) Subject: Puzzled about the output of my demo of a proof of The Euler Series References: Message-ID: On Aug 10, 4:57?pm, "Richard D. Moores" wrote: > I saw an interesting proof of the limit of The Euler Series on > math.stackexchange.com at > . > Scroll down to Hans Lundmark's post. > > I thought I'd try to see this "pinching down" on the limit of pi**2/6. > See my attempt, and output for n = 150 at > . What puzzles me is that > upper_bound_partial_sum (lines 39 and 60) is always smaller than the > limit. It should be greater than the limit, right? If not, no pinching > between upper_bound_partial_sum and lower_bound_partial_sum. > > I've checked and double-checked the computation, but can't figure out > what's wrong. > > Thanks, > > Dick Moores The math is correct. The proof only asserts that sum(1/k^2) is between the upper and lower partial sums. The upper and lower partial sums both converge to pi^2/6 from below and since the sum(1/k^2) is between the two partial sums, it must also converge to pi^2/6. Try calculating sum(1/k^2) for k in range(1, 2**n) and compare that with the upper and lower sums. I verified it with several values up to n=20. casevh From ben+python at benfinney.id.au Thu Aug 11 01:56:47 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 15:56:47 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <87obzwh4o0.fsf@benfinney.id.au> Seebs writes: > On 2011-08-10, Ben Finney wrote: > > Seebs writes: > >> On 2011-08-10, Chris Angelico wrote: > >> > And if we require {} then truly free indentation should be OK too! > >> > But it wouldn't be Python any more. > > >> Would it really not be Python at all? > > > See the Python interpreter's response to ???from __future__ import braces???. > > I'm aware of that. I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. > 2. People are subconsciously aware of this. What evidence do you have of these? The latter, especially, seems to be mere opinion unfounded in any measurement. > 3. There is a HUGE degree of emotional investment in defending it. That same observation is consistent with: * Indentation as block syntax is an excellent idea. * Python programmers are quite consciously aware of this. So I don't see a reason to prefer your inference over mine. > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing Again, I don't know where you've been observing that, but it's not what I've seen. > I like Python a lot in some ways, but I am really sick of the > insistance that this godawful wart is the sublime epitome of all > perfection, never to be improved on. It was a really interesting > experiment. As sometimes happens, the experiment discovered things > that no one could have reasonably anticipated without running the > experiment. You're welcome to attempt to demonstrate the superiority of some other Python-with-braces, but it will (a) be un-Pythonic, and (b) be unlikely to gain the efforts of people who don't think what you're addressing is a problem. Since that latter set of people includes most Python programmers who have reacted negatively to the proposal, you may want to re-think whether your effort is worthwhile. Meanwhile, we'll continue being productive with Python's indentation-as-structure. -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson, 1813-08-13 | Ben Finney From przemolicc at poczta.fm Thu Aug 11 02:30:08 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 08:30:08 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: <20110811063007.GA4990@host.pgf.com.pl> On Wed, Aug 10, 2011 at 03:38:42PM +0100, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 3:38 PM, Chris Angelico wrote: > > Which SQL library are you suing? > > And this is why I should proof-read BEFORE, not AFTER, sending. > > Which SQL library are you *using*? cx_oracle Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From przemolicc at poczta.fm Thu Aug 11 02:40:30 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 08:40:30 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: <20110811064030.GB4990@host.pgf.com.pl> On Wed, Aug 10, 2011 at 06:20:10PM +0200, Stefan Behnel wrote: > przemolicc at poczta.fm, 10.08.2011 15:31: >> On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: >>> On Wed, Aug 10, 2011 at 12:17 PM, wrote: >>>> I'd like to write a python (2.6/2.7) script which connects to database, fetches >>>> hundreds of thousands of rows, concat them (basically: create XML) >>>> and then put the result into another table. Do I have any choice >>>> regarding string concatenation in Python from the performance point of view ? >>>> Since the number of rows is big I'd like to use the fastest possible library >>>> (if there is any choice). Can you recommend me something ? >>> >>> First off, I have no idea why you would want to create an XML dump of >>> hundreds of thousands of rows, only to store it in another table. >>> However, if that is your intention, list joining is about as efficient >>> as you're going to get in Python: >>> >>> lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries >>> xml=""+"".join(lst)+"" >>> >>> This sets xml to 'asdfqwerzxcv' which >>> may or may not be what you're after. >> >> since this process (XML building) is running now inside database (using native SQL commands) >> and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which >> will concat subset of the whole table (and then merge all of them at the end). >> Basically: >> - fetch all rows from the database (up to 1 million): what is recommended data type ? >> - spawn X python processes each one: >> - concat its own subset >> - merge the result from all the subprocesses >> >> This task is running on a server which has many but slow cores and I am trying to divide this task >> into many subtasks. > > Makes sense to me. Note that the really good DBMSes (namely, PostgreSQL) > come with built-in Python support. The data are in Oracle so I have to use cx_oracle. > You still didn't provide enough information to make me understand why you > need XML in between one database and another (or the same?), but if you > go that route, you can just read data through multiple connections in > multiple threads (or processes), have each build up one (or more) XML > entries, and then push those into a queue. Then another thread (or more > than one) can read from that queue and write the XML items into a file > (or another database) as they come in. I am not a database developer so I don't want to change the whole process of data flow between applications in my company. Another process is reading this XML from particular Oracle table so I have to put the final XML there. > If your data has a considerable size, I wouldn't use string concatenation > or joining at all (note that it requires 2x the memory during > concatenation), but rather write it into a file, or even just process the > data on the fly, i.e. write it back into the target table right away. > Reading a file back in after the fact is much more resource friendly than > keeping huge amounts of data in memory. And disk speed is usually not a > problem when streaming data from disk into a database. This server has 256 GB of RAM so memory is not a problem. Also the select which fetches the data is sorted. That is why I have to carefully divide into subtasks and then merge it in correct order. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Dom marzen - kup lub wynajmij taniej niz myslisz! Szukaj >> http://linkint.pl/f2a0d From lanyjie at yahoo.com Thu Aug 11 03:01:28 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:01:28 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <1313046088.54814.YahooMailNeo@web121513.mail.ne1.yahoo.com> ________________________________ From: Michael Trausch To: Yingjie Lan Cc: Chris Angelico ; "python-list at python.org" Sent: Thursday, August 11, 2011 12:51 PM Subject: Re: allow line break at operators > Perhaps it could be made an optional thing to enable; for example, some languages by default do dynamic typing, but with an option contained as the first statement of the file can enforce static typing. That is a brilliant idea! Python code can specify encoding in the beginning, we might use another similar line to opt in for that kind of language features. Once in that ';'-required mode, the trouble of typing a ';' at end of almost every line can be easily avoided by a smart editor: 1) when a single 'Return' key is hit, and the line is not ending in ':' or ';' (white spaces and comments discarded), automatically append a ';' to the end of the line. 2) to continue the line to the next line, hit "Shift+Enter", then no ';' will be appended to the line. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From paddy3118 at googlemail.com Thu Aug 11 03:19:34 2011 From: paddy3118 at googlemail.com (Paddy) Date: Thu, 11 Aug 2011 00:19:34 -0700 (PDT) Subject: Python 3.X: nonlocal support in eval/exec? Message-ID: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> We can access nonlocal variables in a function, but if we were to eval/ exec the function we cannot set up a nested stack of evironment dicts. We are limited to just two: global and local. How about eval/exec take a new env argument that is a nested dictionary whose outer level corresponds to locals, and which has a __up__ value which is the next outer level environment dict. The outermost level of the nested dictionary would correspond to the global level? I haven't given much thought to my suggested solution - I just didn't want to leave a possible solution out. The major point is that there seems to be no support for nonlocal in eval/exec (unless, trivially, nonlocal==global). - Paddy. From lanyjie at yahoo.com Thu Aug 11 03:24:24 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:24:24 -0700 (PDT) Subject: allow line break at operators In-Reply-To: <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> ________________________________ From: Steven D'Aprano To: python-list at python.org Sent: Thursday, August 11, 2011 12:18 PM Subject: Re: allow line break at operators On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in > magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? :Why on earth would you want to break backwards compatibility of millions of :Python scripts and programs, and require extra, unnecessary line-noise on :every single line of Python code, just so that you can occasionally avoid a :writing a pair of parentheses? I think allowing free line splitting (without parentheses -- that's artifitial and requires the coder to serve the machine rather than the other way around) with proper indentation will produce truely ergonomic code layout (well, assuming you also like properly indented code). And this can be done almost hassle-free for the coder. The compatibility problem can be solved by something like a preprocessor indicator to opt in this new language feature, or, if we are determined to favor this new feature, all old code can be easily converted. The worst case is that the coder has to opt in. The trouble of adding a ';' to most of the lines can also be avoided by a smart editor (see my other reply). Python serves the coder, not the other way around. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu Aug 11 03:40:52 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Aug 2011 08:40:52 +0100 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: <4E438784.6020804@timgolden.me.uk> On 10/08/2011 21:43, Christian Heimes wrote: > Am 10.08.2011 21:52, schrieb Ameet Nanda: >> Hi, >> >> Can anyone point me to a way to access windows shared folders from the >> network using a python script. I tried accessing using open, which is >> mentioned to work perfectly on the web, but it gives me following errors > > The open() function wraps the fopen() function, which doesn't support > UNC, just local paths. You have to mount the network share first (assign > a drive letter). Christian, with respect: what are you talking about? print open (r"\\localhost\c$\python27\python.exe").read (100) The OP's problem is that he's trying to call open () on the share itself, not on a file within it. TJG From tjreedy at udel.edu Thu Aug 11 03:48:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2011 03:48:28 -0400 Subject: Python 3.X: nonlocal support in eval/exec? In-Reply-To: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> References: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> Message-ID: On 8/11/2011 3:19 AM, Paddy wrote: > We can access nonlocal variables in a function, but if we were to eval/ > exec the function we cannot set up a nested stack of evironment dicts. > We are limited to just two: global and local. Right. That was and is Python's execution model. Note that when you exec code, including a function call, the locals passed is the local context in which the code is executed. It is not the locals of any particular function called by the exec-ed code. If you exec a function that is a closure, the closure or non-local objects come with the function. A 'stack of dicts' has nothing to do with how function and nested funcs operate. -- Terry Jan Reedy From clp2 at rebertia.com Thu Aug 11 03:50:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Aug 2011 00:50:26 -0700 Subject: allow line break at operators In-Reply-To: <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Thu, Aug 11, 2011 at 12:24 AM, Yingjie Lan wrote: > From: Steven D'Aprano > On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > :Why on earth would you want to break backwards compatibility of millions of > :Python scripts and programs, and require extra, unnecessary line-noise on > :every single line of Python code, just so that you can occasionally avoid a > :writing a pair of parentheses? > > I think allowing free line splitting (without parentheses -- that's > artifitial and > requires the coder to serve the machine rather than the other way around) > with proper indentation will produce truely ergonomic code layout (well, > assuming you also like properly indented code). > > And this can be done almost hassle-free for the coder. > The trouble of adding a ';' to most of the lines can also be > avoided by a smart editor (see my other reply). The trouble of dealing with long lines can be avoided by a smart editor. It's called line wrap. Cheers, Chris From lanyjie at yahoo.com Thu Aug 11 03:53:55 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:53:55 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> ________________________________ From: Chris Rebert To: Yingjie Lan Cc: "python-list at python.org" Sent: Thursday, August 11, 2011 3:50 PM Subject: Re: allow line break at operators On Thu, Aug 11, 2011 at 12:24 AM, Yingjie Lan wrote: > From: Steven D'Aprano > On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > :Why on earth would you want to break backwards compatibility of millions of > :Python scripts and programs, and require extra, unnecessary line-noise on > :every single line of Python code, just so that you can occasionally avoid a > :writing a pair of parentheses? > > I think allowing free line splitting (without parentheses -- that's > artifitial and > requires the coder to serve the machine rather than the other way around) > with proper indentation will produce truely ergonomic code layout (well, > assuming you also like properly indented code). > > And this can be done almost hassle-free for the coder. > The trouble of adding a ';' to most of the lines can also be > avoided by a smart editor (see my other reply). :The trouble of dealing with long lines can be avoided by a smart :editor. It's called line wrap. Yeah, usually they just wrap it pretty arbitrarily, and you don't have any control, isn't it? Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From anacrolix at gmail.com Thu Aug 11 03:55:02 2011 From: anacrolix at gmail.com (Matt Joiner) Date: Thu, 11 Aug 2011 17:55:02 +1000 Subject: shouldn't ctypes cast as it does in C? Message-ID: http://www.mememaker.net/images/public/201108110739296015.jpg From nobody at nowhere.com Thu Aug 11 04:15:13 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Aug 2011 09:15:13 +0100 Subject: subprocess.Popen and thread module References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Danny Wong (dannwong) wrote: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', > '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) >? ? ? ?status = cmd_output.wait() If you redirect stdout and/or stderr to a pipe, you must wait for EOF before calling wait(), otherwise you risk deadlock (the process blocks waiting for Python to read data from the pipe while Python is blocked waiting for the process to terminate). And if you redirect both stdout and stderr to pipes, you must either use multiple threads or non-blocking I/O, otherwise you risk deadlock (the process blocks waiting for Python to read data from one of the pipes while Python is blocked waiting for the process to write to the other pipe). I suggest looking at the .communicate() method of the Popen class. From rosuav at gmail.com Thu Aug 11 04:24:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 09:24:04 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Thu, Aug 11, 2011 at 6:17 AM, Michael Trausch wrote: > Somthing like an "option" keyword (which would only be a keyword until the > first executable statement, e.g., would have to be before even imports) > could enable things like "semicolon" or "explicit", or whatever really, and > only affect those who opt in. If no code is ever seen using the option, it > can even be removed. Wouldn't be a bad way to test changes that would impact > the syntax of the language, actually... Python already has a syntax like this: from __future__ import statictyping Although I'm not sure how you'd go about implementing it plausibly. It'd be a fairly backward-incompatible change; what would happen to the modules you import? Either you would have to have a duplicate set (one that uses statictyping and one that doesn't), or you'd have to have statictyping somehow work on a per-module basis. As far as I know, most of the other future statements are per-module (with the possible exception of barry_as_FLUFL, which until today I was not aware of). Would static typing then apply only to module-level variables and function-local variables, with the values in lists/tuples/dicts/objects/etc/etc/etc still being dynamically typed? I think it'd be easier to fork Python and give it a new name. ChrisA From gelonida at gmail.com Thu Aug 11 04:59:40 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 10:59:40 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv Message-ID: Hi, Short version ============== I have a system with ipython installed by my Ubuntu distribution I created a virtualenv with > virtualenv ~/myenv I installed ipython > pip install ipython --upgrade When using ipython I notice, that it does import the modules from my default python setup and not from my virtualenv. Why? What could I have done differently? Long version =================== I created a virtualenv with virtualenv ~/myenv THis inherits my machines site packages. The reason I'm not using virutalenv --no-site-packages ~/myenv is that I would like to use some of the site packages, in particular some, that I don't want to compile due to huge package dependencies. Small problem is, that if I run ipython in a virtualenv it will still call /usr/bin/ipython and if I check the modules, that I import I seem to import the modules of my default environment and not the ones of my virtualenv. So I decided I will install my own version of ipython in my virtualenv The output if pip install ipython is a little confusing. > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 As I am a normal user and I don't have permissions to overwrite /usr/lib I decided to just give it a try and hope it will install in my virtualenv path and not in /usr/lib/... After running > pip install ipython --upgrade I have my own version of ipython. However when calling and using it I notice it still imports the modules from my default python and not from my virtualenv? Why does ipython ignore the virtualenv's settings? I know there are workarounds, but I wondered why it doesn't work out of the box. From gelonida at gmail.com Thu Aug 11 05:29:54 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 11:29:54 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: On 08/11/2011 06:03 AM, Dan Stromberg wrote: Hi Dan, > FWIW, a few months ago I was working on a database application on > Windows, and I benchmarked the psyco-enhanced version consistently > running slower than the non-psyco version. The same code on Linux was > faster with psyco though. Good to know. I wanted to make the test myself though. There's one / two modules where I would expect an increase in performance. The rest of the application will rather definitely not benefit from psyco. Also one thing, that I wanted to try is to not use psyco for the application itself, but just for running py2exe a little faster. > > If you need performance, and you aren't constrained by module > availability, you probably should use PyPy instead. Well many module depenencies. :-( and also a lot of old legacy code, which will probably not survive PyPy (files not being closed explicitely for example) From bex.lewis at gmail.com Thu Aug 11 05:39:06 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Thu, 11 Aug 2011 02:39:06 -0700 (PDT) Subject: ipython installed in virtualenv seems not to use virtualenv References: Message-ID: Hi, are you doing a pip install from within your virtualenv (sourcing the virtualenv and THEN installing ipython)? Becky Lewis On Aug 11, 9:59?am, Gelonida N wrote: > Hi, > > Short version > ============== > I have a system with ipython installed by my Ubuntu distribution > I created a virtualenv with> virtualenv ~/myenv > I installed ipython > > pip install ipython --upgrade > > When using ipython I notice, that it does import the modules from my > default python setup and not from ?my virtualenv. > > Why? > What could I have done differently? > > Long version > =================== > > I created a ?virtualenv with > > virtualenv ~/myenv > > THis inherits my machines site packages. > The reason I'm not using > > virutalenv --no-site-packages ~/myenv > > is that I would like to use some of the site packages, > in particular some, that I don't want to compile due to huge package > dependencies. > > Small problem is, that if I run ipython in a virtualenv > it will still call /usr/bin/ipython > > and if I check the modules, that I import I seem to import the modules > of my default environment and not the ones of my virtualenv. > > So I decided I will install my own version of ipython in my virtualenv > > The output if pip install ipython is a little confusing. > > > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 > > As I am a normal user and I don't have permissions to overwrite /usr/lib > I decided to just give it a try and hope it will install in my > virtualenv path and not in /usr/lib/... > > After running > > > pip install ipython --upgrade > > I have my own version of ipython. > > However when calling and using it I notice it still imports the modules > from my default python and not from my virtualenv? > > Why does ipython ignore the virtualenv's settings? > > I know there are workarounds, but I wondered why it doesn't work out of > the box. From gelonida at gmail.com Thu Aug 11 06:04:54 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 12:04:54 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv In-Reply-To: References: Message-ID: On 08/11/2011 11:39 AM, becky_lewis wrote: > Hi, > > are you doing a pip install from within your virtualenv (sourcing the > virtualenv and THEN installing ipython)? > Yes this is what I was doing. My default ipython without virtualenv is now: $ ipython -V 0.10 Within my virualenv it is now: $ ipython --version 0.11 which ipython indicates also, that is well placed in my virtual env's tree I forced a reinstall of the library, that was found by my virtualenv python, but was NOT found by my virtualenv ipython. and now everything works fine. This is weird. But I'm glad it's working now. Tried to reproduce the issue on another (rather similiar machine), but couldn't > Becky Lewis > > > On Aug 11, 9:59 am, Gelonida N wrote: >> Hi, >> >> Short version >> ============== >> I have a system with ipython installed by my Ubuntu distribution >> I created a virtualenv with> virtualenv ~/myenv >> I installed ipython >>> pip install ipython --upgrade >> >> When using ipython I notice, that it does import the modules from my >> default python setup and not from my virtualenv. >> >> Why? >> What could I have done differently? >> >> Long version >> =================== >> >> I created a virtualenv with >> >> virtualenv ~/myenv >> >> THis inherits my machines site packages. >> The reason I'm not using >> >> virutalenv --no-site-packages ~/myenv >> >> is that I would like to use some of the site packages, >> in particular some, that I don't want to compile due to huge package >> dependencies. >> >> Small problem is, that if I run ipython in a virtualenv >> it will still call /usr/bin/ipython >> >> and if I check the modules, that I import I seem to import the modules >> of my default environment and not the ones of my virtualenv. >> >> So I decided I will install my own version of ipython in my virtualenv >> >> The output if pip install ipython is a little confusing. >> >>> Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 >> >> As I am a normal user and I don't have permissions to overwrite /usr/lib >> I decided to just give it a try and hope it will install in my >> virtualenv path and not in /usr/lib/... >> >> After running >> >>> pip install ipython --upgrade >> >> I have my own version of ipython. >> >> However when calling and using it I notice it still imports the modules >> from my default python and not from my virtualenv? >> >> Why does ipython ignore the virtualenv's settings? >> >> I know there are workarounds, but I wondered why it doesn't work out of >> the box. > From zak.mc.kraken at libero.it Thu Aug 11 06:21:42 2011 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Thu, 11 Aug 2011 12:21:42 +0200 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: Yingjie Lan wrote: > :The trouble of dealing with long lines can be avoided by a smart > :editor. It's called line wrap. > > Yeah, usually they just wrap it pretty arbitrarily, > and you don't have any control, isn't it? umm... besides "notepad" pretty much any other serious "programmer editor" program try to do its best to deal with line wrap: the minimal I found is the wrapped line is "indented" at the same level of the flow, but I found editors where you can specify what to do (generally something like "indent the wrapped part 2 levels" or something like that) -- By ZeD From bex.lewis at gmail.com Thu Aug 11 06:28:35 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Thu, 11 Aug 2011 03:28:35 -0700 (PDT) Subject: ipython installed in virtualenv seems not to use virtualenv References: Message-ID: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> Just to add ... I ran through creating a virtualenv in the same manner as you: $ virtualenv SomeEnv $ source SomeEnv/bin/activate (SomeEnv)$ which pip /home/user/virtual/SomeEnv/bin/pip (SomeEnv)$ pip install ipython Requirement already satisfied (use --upgrade to upgrade): ipython in / usr/local/lib/python2.6/dist-packages Cleaning up... (SomeEnv)$ pip install ipython --upgrade ... pip installs ipython ... (SomeEnv)$ which ipython /home/user/virtual/SomeEnv/bin/ipython (SomeEnv)$ ipython Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) Type "copyright", "credits" or "license" for more information. IPython 0.11 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import os In [2]: os.__file__ Out[2]: '/home/user/virtual/SomeEnv/lib/python2.6/os.pyc' In [3]: import dbus In [4]: dbus.__file__ Out[4]: '/usr/lib/pymodules/python2.6/dbus/__init__.pyc' ipython is using the virtualenv when it can find them and the system wide packages when they are not in the virtualenv. Hope that helps you track down the problem :/ On Aug 11, 9:59?am, Gelonida N wrote: > Hi, > > Short version > ============== > I have a system with ipython installed by my Ubuntu distribution > I created a virtualenv with> virtualenv ~/myenv > I installed ipython > > pip install ipython --upgrade > > When using ipython I notice, that it does import the modules from my > default python setup and not from ?my virtualenv. > > Why? > What could I have done differently? > > Long version > =================== > > I created a ?virtualenv with > > virtualenv ~/myenv > > THis inherits my machines site packages. > The reason I'm not using > > virutalenv --no-site-packages ~/myenv > > is that I would like to use some of the site packages, > in particular some, that I don't want to compile due to huge package > dependencies. > > Small problem is, that if I run ipython in a virtualenv > it will still call /usr/bin/ipython > > and if I check the modules, that I import I seem to import the modules > of my default environment and not the ones of my virtualenv. > > So I decided I will install my own version of ipython in my virtualenv > > The output if pip install ipython is a little confusing. > > > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 > > As I am a normal user and I don't have permissions to overwrite /usr/lib > I decided to just give it a try and hope it will install in my > virtualenv path and not in /usr/lib/... > > After running > > > pip install ipython --upgrade > > I have my own version of ipython. > > However when calling and using it I notice it still imports the modules > from my default python and not from my virtualenv? > > Why does ipython ignore the virtualenv's settings? > > I know there are workarounds, but I wondered why it doesn't work out of > the box. From lanyjie at yahoo.com Thu Aug 11 06:59:06 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 03:59:06 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: <1313060346.15270.YahooMailNeo@web121517.mail.ne1.yahoo.com> > :The trouble of dealing with long lines can be avoided by a smart > :editor. It's called line wrap. > > Yeah, usually they just wrap it pretty arbitrarily, > and you don't have any control, isn't it? :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to do its best to deal with line wrap: the minimal I found is :the wrapped line is "indented" at the same level of the flow, but I found :editors where you can specify what to do (generally something like "indent :the wrapped part 2 levels" or something like that) Thanks for sharing that, which I am not quite aware of . BTW, do you think things like eclipse, emacs and vim also has such kind of functionality? Best of all, would certainly like to have IDLE have it, as I am teaching Python and would like to get them to start with a simple environment. Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 11 06:59:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 11:59:31 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811064030.GB4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 7:40 AM, wrote: > I am not a database developer so I don't want to change the whole process > of data flow between applications in my company. Another process is > reading this XML from particular Oracle table so I have to put the final XML there. I think you may be looking at a submission to http://www.thedailywtf.com/ soon. You seem to be working in a rather weird dataflow. :( Under the circumstances, you're probably going to want to go with the original ''.join() option. > This server has 256 GB of RAM so memory is not a problem. > Also the select which fetches the data is sorted. That is why I have to > carefully divide into subtasks and then merge it in correct order. There's no guarantee that all of that 256GB is available to you, of course. What may be the easiest way is to do the select in a single process, then partition it and use the Python multiprocessing module to split the job into several parts. Then you need only concatenate the handful of strings. You'll need to do some serious profiling, though, to ascertain where the bottleneck really is. Is it actually slow doing the concatenation, or is it taking more time reading/writing the disk? Is it actually all just taking time due to RAM usage? Proper string concatenation doesn't need a huge amount of CPU. ChrisA From gelonida at gmail.com Thu Aug 11 07:01:25 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 13:01:25 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: On 08/11/2011 05:24 AM, Miki Tebeka wrote: > You can download the sources tarball and when building specify the compiler. > See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw Your answer put me on the right track. This works: - downloading mingw - downloading and extracting the tarfile the tar file - python setup.py build --compiler=mingw32 - python setup.py install In order to directly use pip / easy_install I created the file %USERPROFILE%\pydistutils.cfg with following two contents: [build] compiler=mingw32 and added mingw to my search path. now in can directly type pip install psyco Thanks again From gelonida at gmail.com Thu Aug 11 07:06:25 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 13:06:25 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv In-Reply-To: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> References: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> Message-ID: On 08/11/2011 12:28 PM, becky_lewis wrote: > Just to add ... > > I ran through creating a virtualenv in the same manner as you: > > > ipython is using the virtualenv when it can find them and the system > wide packages when they are not in the virtualenv. Hope that helps you > track down the problem :/ > > Thanks once more. I guess something in my virtualenv was broken. I can't reproduce the issue anymore since I forced a reinstall of one of y packages and now things work as I would have expected them to work. Happy that thins work now. Unhappy, that I did not understand why they went wrong before. From lanyjie at yahoo.com Thu Aug 11 07:12:35 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 04:12:35 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: <1313061155.82601.YahooMailNeo@web121502.mail.ne1.yahoo.com> ________________________________ From: Vito 'ZeD' De Tullio :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to do its best to deal with line wrap: the minimal I found is :the wrapped line is "indented" at the same level of the flow, but I found :editors where you can specify what to do (generally something like "indent :the wrapped part 2 levels" or something like that) Well, even if one editor can do perfect line wrapping, breaking the line at places perfectly pleasing to the eye (put aside the fact that sometimes the line breaking could be based on the meaning of the code), it is unlikely to be cross-editor consistent. Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From przemolicc at poczta.fm Thu Aug 11 07:52:55 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 13:52:55 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: <20110811115255.GC4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 7:40 AM, wrote: > > I am not a database developer so I don't want to change the whole process > > of data flow between applications in my company. Another process is > > reading this XML from particular Oracle table so I have to put the final XML there. > > I think you may be looking at a submission to > http://www.thedailywtf.com/ soon. You seem to be working in a rather > weird dataflow. :( Under the circumstances, you're probably going to > want to go with the original ''.join() option. > > > This server has 256 GB of RAM so memory is not a problem. > > Also the select which fetches the data is sorted. That is why I have to > > carefully divide into subtasks and then merge it in correct order. > > There's no guarantee that all of that 256GB is available to you, of course. I am the admin of this server - the memory is available for us :-) > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. This is the way I am going to use. > You'll need to do some serious profiling, though, to ascertain where > the bottleneck really is. Is it actually slow doing the concatenation, > or is it taking more time reading/writing the disk? Is it actually all > just taking time due to RAM usage? Proper string concatenation doesn't > need a huge amount of CPU. I did my homework :-) - the CPU working on concatenation is a bottleneck. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Dziesiatki tysiecy ofert domow i mieszkan! Ogladaj >> http://linkint.pl/f2a0c From rosuav at gmail.com Thu Aug 11 07:58:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 12:58:36 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811115255.GC4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811115255.GC4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 12:52 PM, wrote: > On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: >> There's no guarantee that all of that 256GB is available to you, of course. > > I am the admin of this server - the memory is available for us :-) Hehe. I mean to any particular application; obviously you're way WAY beyond the 4GB limit of a 32-bit app, though there may be other limits; the main consideration here is contention - whatever Oracle itself is using, your concatenation app can't. >> You'll need to do some serious profiling, though, to ascertain where >> the bottleneck really is. Is it actually slow doing the concatenation, >> or is it taking more time reading/writing the disk? Is it actually all >> just taking time due to RAM usage? Proper string concatenation doesn't >> need a huge amount of CPU. > > I did my homework :-) - the CPU working on concatenation is a bottleneck. Glad you have! So many people don't. Looks like you have a plan there, then! ChrisA From stefan_ml at behnel.de Thu Aug 11 07:59:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Aug 2011 13:59:50 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: Chris Angelico, 11.08.2011 12:59: > On Thu, Aug 11, 2011 at 7:40 AM, wrote: >> I am not a database developer so I don't want to change the whole process >> of data flow between applications in my company. Another process is >> reading this XML from particular Oracle table so I have to put the final XML there. > > I think you may be looking at a submission to > http://www.thedailywtf.com/ soon. You seem to be working in a rather > weird dataflow. :( Under the circumstances, you're probably going to > want to go with the original ''.join() option. > >> This server has 256 GB of RAM so memory is not a problem. >> Also the select which fetches the data is sorted. That is why I have to >> carefully divide into subtasks and then merge it in correct order. > > There's no guarantee that all of that 256GB is available to you, of course. > > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. Or join them using an n-way merge. Stefan From jackhatterly at hotmail.com Thu Aug 11 08:28:50 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Thu, 11 Aug 2011 12:28:50 +0000 Subject: Cookie Problem In-Reply-To: References: , Message-ID: > Some of these values look wrong. Your 'path' ought to be as the > browser sees it, and your 'domain' ditto; ... > Otherwise, I would recommend omitting those elements and allowing the > defaults through. So I commented out those lines and now have this: #!/usr/bin/env python import string import os import datetime, Cookie, random import time ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = str(time.time()) print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') # The first time the page is run there will be no cookies if not cookie_string: print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = str(time.time()) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 # cookie['lastvisit']['path'] = '/var/www/html/my_site' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' # cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 else: # Run the page twice to retrieve the cookie print '

The returned cookie string was "' + cookie_string + '"

' # cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1], '.', '')[:-1] # load() parses the cookie string cookie.load(cookie_string) # Use the value attribute of the cookie to get it lastvisit = float(cookie['lastvisit'].value) for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' # for key, morsel in cookie.iteritems(): # print "key: %s\n" % key # print "morsel: %s\n\n" % morsel print '' and it does the same thing: namely, when I clear out the cookie, it creates a cookie but apparently not with the data I'm trying to push and when I refresh it displays all the keys without any morsel values. What do? TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Aug 11 08:29:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:29:29 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. I'm not aware of any language where indentation is used for flow control. Python is not one of those languages: it uses for, while, if, etc. for flow control, just like most other languages. It does however use indentation for grouping code into blocks -- a different concept. > 2. People are subconsciously aware of this. > 3. There is a HUGE degree of emotional investment in defending it. > > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing, and utterly contrary to the basic > engineering spirit So you say. You are free to hold whatever opinions you like, but have you considered that the reason people get emotional and angry when others insist that indentation as flow control should be discarded is because they actually believe that the "off-side rule" (as it is called) makes for a better language and a better coding experience? We're not defensive because we subconsciously know you're right, we're defensive because we consciously know you're wrong, have heard all the arguments a thousand times before, and are sick and tired of them. There are dozens, hundreds of brace languages, and 1-2 dozen using indentation, including Python. If braces are so important to you, go use one of those other languages, don't wreck the language we like by taking away one of the best features of the language. > I usually see in programming communities. In other languages, and even in > Python on any issue but this one, I regularly see people acknowledge > shortcomings and explain either why they think the tradeoffs are good, or > why they are willing to put up with it anyway. We're fully aware of the tradeoffs of significant indentation. We believe that brace languages get the trade-offs backwards: they optimise code for environments which mangle source code. 99.999% of code will never pass through a broken mail server that strips leading whitespace, or pasted into broken web forum software that mangles indentation, or go through any other broken tool that messes with indentation. Brace languages optimise for the 0.001% case, Python optimised the 99.999% case. Because people simply don't like it when their code's indentation doesn't match the actual semantics, people usually manually ensure that the two match, braces or no braces. Editors still have commands to indent and outdent blocks of code. There is no difference between (say) C or Pascal and Python in that regard. > * Braces win because they are explicit rather than implicit. There is nothing implicit about indentation. This false dichotomy between so-called explicit braces and allegedly implicit indentation gets thrown around all the time, but it is simply *wrong*. Indentation is not implicit. You (or your editor) has to add whitespace to the line, the parser has to see the whitespace, and an INDENT token is created for it. [...] > In the real world, we are confronted constantly with tools which work > perfectly with every programming language but Python or very old FORTRAN, And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any other languages with significant indentation. > but which mangle Python code sporadically and inexplicably. Mail servers > chew up whitespace like there's no tomorrow. Web pages find innovative > new explanations for why those leading spaces don't need to be displayed. No, most mail servers don't mangle whitespace in the body of the email, or in attachments. Some mail clients do, usually because they default to using HTML for text. So get a better mail client. Avoid pig-ignorant web forums that think that source code can be reflowed or that remove leading whitespace. Stop using Notepad, and use an editor that offers indent and outdent commands. If your mail server had a bug that deleted braces from emails, would you fix the bug, or would you insist that braces were a failed experiment and that C should stop using { } and start using BEGIN END like Pascal? -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 08:29:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:29:29 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. I'm not aware of any language where indentation is used for flow control. Python is not one of those languages: it uses for, while, if, etc. for flow control, just like most other languages. It does however use indentation for grouping code into blocks -- a different concept. > 2. People are subconsciously aware of this. > 3. There is a HUGE degree of emotional investment in defending it. > > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing, and utterly contrary to the basic > engineering spirit So you say. You are free to hold whatever opinions you like, but have you considered that the reason people get emotional and angry when others insist that indentation as flow control should be discarded is because they actually believe that the "off-side rule" (as it is called) makes for a better language and a better coding experience? We're not defensive because we subconsciously know you're right, we're defensive because we consciously know you're wrong, have heard all the arguments a thousand times before, and are sick and tired of them. There are dozens, hundreds of brace languages, and 1-2 dozen using indentation, including Python. If braces are so important to you, go use one of those other languages, don't wreck the language we like by taking away one of the best features of the language. > I usually see in programming communities. In other languages, and even in > Python on any issue but this one, I regularly see people acknowledge > shortcomings and explain either why they think the tradeoffs are good, or > why they are willing to put up with it anyway. We're fully aware of the tradeoffs of significant indentation. We believe that brace languages get the trade-offs backwards: they optimise code for environments which mangle source code. 99.999% of code will never pass through a broken mail server that strips leading whitespace, or pasted into broken web forum software that mangles indentation, or go through any other broken tool that messes with indentation. Brace languages optimise for the 0.001% case, Python optimised the 99.999% case. Because people simply don't like it when their code's indentation doesn't match the actual semantics, people usually manually ensure that the two match, braces or no braces. Editors still have commands to indent and outdent blocks of code. There is no difference between (say) C or Pascal and Python in that regard. > * Braces win because they are explicit rather than implicit. There is nothing implicit about indentation. This false dichotomy between so-called explicit braces and allegedly implicit indentation gets thrown around all the time, but it is simply *wrong*. Indentation is not implicit. You (or your editor) has to add whitespace to the line, the parser has to see the whitespace, and an INDENT token is created for it. [...] > In the real world, we are confronted constantly with tools which work > perfectly with every programming language but Python or very old FORTRAN, And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any other languages with significant indentation. > but which mangle Python code sporadically and inexplicably. Mail servers > chew up whitespace like there's no tomorrow. Web pages find innovative > new explanations for why those leading spaces don't need to be displayed. No, most mail servers don't mangle whitespace in the body of the email, or in attachments. Some mail clients do, usually because they default to using HTML for text. So get a better mail client. Avoid pig-ignorant web forums that think that source code can be reflowed or that remove leading whitespace. Stop using Notepad, and use an editor that offers indent and outdent commands. If your mail server had a bug that deleted braces from emails, would you fix the bug, or would you insist that braces were a failed experiment and that C should stop using { } and start using BEGIN END like Pascal? -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 08:40:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:40:27 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e43cdbc$0$29986$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: > indentation as flow control Gah! Of course, I meant indentation for blocks... after making the earlier point that indentation is *not* used for flow control, this was a particularly egregious error. How embarrassment. -- Steven From amitjaluf at gmail.com Thu Aug 11 08:56:27 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Thu, 11 Aug 2011 05:56:27 -0700 (PDT) Subject: indentation Message-ID: Hello Group, i just start python is it necessary indentation in python ? thanks in advance ... From python at mrabarnett.plus.com Thu Aug 11 09:03:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 14:03:22 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <4E43D31A.2070306@mrabarnett.plus.com> On 11/08/2011 05:16, Chris Rebert wrote: > On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan wrote: >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, > > I think of it more as that Python deigns to permit semicolons. > >> But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > Hell no, considering that the sizable majority of lines *aren't* > split, which makes those semicolons completely redundant to their > accompanying newlines. We'd be practicing poor Huffman coding by > optimizing for the *un*common case. It would also add punctuational > noise to what is otherwise an amazingly clean and readable syntax. > Accidental semicolon omission is (IMO) the most irritating source of > syntax (and, inadvertently, sometimes other more serious) errors in > curly-braced programming languages. > +1 > Such a core syntax feature is not going to be changed lightly (or likely ever). > I'm glad to hear that. :-) Although Python's use of indentation has its downside, we gain much more then we lose, IMHO. From python at mrabarnett.plus.com Thu Aug 11 09:15:33 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 14:15:33 +0100 Subject: indentation In-Reply-To: References: Message-ID: <4E43D5F5.7040303@mrabarnett.plus.com> On 11/08/2011 13:56, Amit Jaluf wrote: > Hello Group, > i just start python is it necessary indentation in python ? > Yes, indentation is part of the language. Even in programming languages where it isn't necessary, it's recommended because it makes the code easier to read. From tarmo.tapio at pp.inet.fi Thu Aug 11 09:18:39 2011 From: tarmo.tapio at pp.inet.fi (Tarmo Tapio) Date: Thu, 11 Aug 2011 16:18:39 +0300 Subject: python(x,y) Message-ID: <1E5E5A29601A441FAA2AC90CC27286B3@tarmoPC> I'm using scitools (Pythonxy). It plots the curve of the function (Figure window) but when I try to close Figure window I get the message 'Pythonw.exe do not answer'. My operation system is windows 7. This happened when I'm using Matplotlib for ploting. If I use gnuplot for plotting closing works ok. What is the problem? -------------- next part -------------- An HTML attachment was scrubbed... URL: From przemolicc at poczta.fm Thu Aug 11 09:46:13 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 15:46:13 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: <20110811134613.GE4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: > > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. This is the way I am going to use. But what is the best data type to hold so many rows and then operate on them ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zarabiasz 4 tys./miesiac? Damy wiecej! Sprawdz >> http://linkint.pl/f2a0f From rosuav at gmail.com Thu Aug 11 09:48:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 14:48:43 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811134613.GE4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 2:46 PM, wrote: > This is the way I am going to use. > But what is the best data type to hold so many rows and then operate on them ? > List of strings. Take it straight from your Oracle interface and work with it directly. ChrisA From amitjaluf at gmail.com Thu Aug 11 10:06:13 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Thu, 11 Aug 2011 07:06:13 -0700 (PDT) Subject: indentation References: Message-ID: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> On Aug 11, 8:15?am, MRAB wrote: > On 11/08/2011 13:56, Amit Jaluf wrote:> Hello Group, > > i just start python is it necessary indentation in python ? > > Yes, indentation is part of the language. > > Even in programming languages where it isn't necessary, it's > recommended because it makes the code easier to read. Thanks MRAB which book or tutorial i should for it(Python) i found "A Byte of Python " by Swaroop after that which tutorial(book) i have to read Please Suggest me ..... From paal.nilsen at gmail.com Thu Aug 11 10:15:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Thu, 11 Aug 2011 07:15:23 -0700 (PDT) Subject: indentation References: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> Message-ID: On 11 Aug, 16:06, Amit Jaluf wrote: > On Aug 11, 8:15?am, MRAB wrote: > > > On 11/08/2011 13:56, Amit Jaluf wrote:> Hello Group, > > > i just start python is it necessary indentation in python ? > > > Yes, indentation is part of the language. > > > Even in programming languages where it isn't necessary, it's > > recommended because it makes the code easier to read. > > Thanks MRAB > which book or tutorial i should for it(Python) > i found "A Byte of Python " by Swaroop > after that which tutorial(book) i have to read > Please Suggest me ..... http://www.python.org/dev/peps/pep-0008/ http://diveintopython.org/ http://learnpythonthehardway.org/ http://code.google.com/intl/no/edu/languages/google-python-class/introduction.html From anacrolix at gmail.com Thu Aug 11 10:28:04 2011 From: anacrolix at gmail.com (Matt Joiner) Date: Fri, 12 Aug 2011 00:28:04 +1000 Subject: [Python-ideas] allow line break at operators In-Reply-To: <4E43D2F2.1090004@mrabarnett.plus.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: +0.5 The "trailing \" workaround is nonobvious. Wrapping in () is noisy and already heavily used by other syntactical structures. Since a final ':' is needed anyway, i think this would be great. if a and b or c: do stuff() On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: > On 11/08/2011 05:16, Chris Rebert wrote: >> >> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>> >>> :And if we require {} then truly free indentation should be OK too! But >>> >>> :it wouldn't be Python any more. >>> >>> Of course, but not the case with ';'. Currently ';' is optional in >>> Python, >> >> I think of it more as that Python deigns to permit semicolons. >> >>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>> magnitude. >>> >>> So the decision is: shall we change ';' from optional to mandatory >>> to allow free line splitting? >> >> Hell no, considering that the sizable majority of lines *aren't* >> split, which makes those semicolons completely redundant to their >> accompanying newlines. We'd be practicing poor Huffman coding by >> optimizing for the *un*common case. It would also add punctuational >> noise to what is otherwise an amazingly clean and readable syntax. >> Accidental semicolon omission is (IMO) the most irritating source of >> syntax (and, inadvertently, sometimes other more serious) errors in >> curly-braced programming languages. >> > +1 >> >> Such a core syntax feature is not going to be changed lightly (or likely >> ever). >> > I'm glad to hear that. :-) > > Although Python's use of indentation has its downside, we gain much > more then we lose, IMHO. > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From przemolicc at poczta.fm Thu Aug 11 10:39:23 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 16:39:23 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110811143923.GG4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 2:46 PM, wrote: > > This is the way I am going to use. > > But what is the best data type to hold so many rows and then operate on them ? > > > > List of strings. Take it straight from your Oracle interface and work > with it directly. Can I use this list in the following way ? subprocess_1 - run on list between 1 and 10000 subprocess_2 - run on list between 10001 and 20000 subprocess_3 - run on list between 20001 and 30000 etc ... Sort of indexing ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zmyslowa bielizna? U nas ja znajdziesz! http://linkint.pl/f29fe From neilc at norwich.edu Thu Aug 11 10:40:21 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Aug 2011 14:40:21 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <9ai7ulFk97U2@mid.individual.net> On 2011-08-10, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:51 PM, Ben Finney wrote: >> Seebs writes: >>> I've seen bits of code in preprocessing-based "Python with {}" type >>> things, and they still look like Python to me, only they favor >>> explicit over implicit a little more strongly. >> >> They introduce unnecessary ambiguity: the indentation-as-structure and >> braces-as-structure can then disagree. >> >> The ambiguity is resolved by having exactly one of indentation or braces >> determining structure: Python uses indentation. In which case, braces >> are pointless for indicating block structure. > > That's why it wouldn't be Python. It would have to use the braces and > not the indentation. > > ChrisA > PS. I mistakenly sent this to a Gilbert & Sullivan group first. Oddly > enough, opera-goers are not used to discussing the relative merits of > braces vs indentation in code. Had I not become a lover of semantic indentation, Wisely wielding willing whitespace in a wondrous preparation, I could buttress blocks with braces, a la Kernighan and Ritchie, (Other styles, just as valid, make me terri-bul-ly twitchy), What I noticed was the whitespace hasn't shifted one iota, With the braces superfluous in my wc -m quota, When delineating code-blocks, with my keys a-clitter-clatter, I prefer semantic whitespace 'cause the braces shouldn't matter. No, the braces shouldn't matter, (Matter, matter, matter, matter) No, the braces shouldn't matter, (Matter, matter, matter, matter) When delineating code-clocks, with my keys a-clitter-clatter, I prefer semantic whitespace 'cause the braces shouldn't matter. -- Neil Cerutti From ulrich.eckhardt at dominolaser.com Thu Aug 11 10:44:13 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 11 Aug 2011 16:44:13 +0200 Subject: indentation References: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> Message-ID: <8u5dh8-mnk.ln1@satorlaser.homedns.org> Amit Jaluf wrote: > which book or tutorial i should for it(Python) > i found "A Byte of Python " by Swaroop > after that which tutorial(book) i have to read You can read lots of book reviews online. That said, have you checked http://www.python.org? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From aspineux at gmail.com Thu Aug 11 11:07:09 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 11 Aug 2011 08:07:09 -0700 (PDT) Subject: generate and send mail with python: tutorial Message-ID: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Hi I have written a tutorial about how to generate and send emails with python. You can find it here http://blog.magiksys.net/generate-and-send-mail-with-python-tutorial And here is the content. Enjoy. This article follows two other articles (1, 2) about how to parse emails in Python. These articles describe very well mail usages and rules and can be helpful for non Python developer too. The goal here is to generate a valid email including internationalized content, attachments and even inline images, and send it to a SMTP server. The procedure can be achieved in 3 steps : compose the body of the email. compose the header of the email. send the email to a SMTP server At the end you will find the sources. The first rule to keep in mind all the time, is that emails are 7bits only, they can contains us-ascii characters only ! A lot of RFCs define rules to encode non us-ascii characters when they are required: RFC2047 to encode headers, RFC2045 for encoding body using the MIME format or RFC2231 for MIME parameters like the attachment filename. The mail header The header is composed of lines having a name and a value. RFC2047 let you use quoted or binary encoding to encode non us-ascii characters in it. For example: Subject: Courrier ?lectronique en Fran?ais become using the quoted format Subject: =?iso-8859-1?q?Courrier_=E8lectronique_en_Fran=E7ais?= or using the binary one. Subject: =?iso-8859-1?b?Q291cnJpZXIg6GxlY3Ryb25pcXVlIGVuIEZyYW7nYWlz?= Here the quoted format is readable and shorter. Python email.header.Header object generates user friendly header by choosing the quoted format when the encoding shares characters with us-ascii, and the binary one for encoding like the Chinese big5 that requires the encoding of all characters. >>> str(Header(u'Courrier \xe8lectronique en Fran\xe7ais', 'iso-8859-1')) '=?iso-8859-1?q?Courrier_=E8lectronique_en_Fran=E7ais?=' Header values have different types (text, date, address, ...) that all require different encoding rules. For example, in an address like : Sender: Alain Spineux The email part has to be in us-ascii and cannot be encoded. The name part cannot contains some special characters without quoting : []\()<>@,:;". We can easily understand why "<>" are in the list, others have all their own story. For example, the use of the "Dr." prefix requires to quote the name because of the '.': Sender: "Dr. Alain Spineux" For a name with non us-ascii characters like (look at the "?" in Ala?n), the name must be encoded. Sender: Dr. Al?an Spineux must be written : Sender: =?iso-8859-1?q?Dr=2E_Ala=EFn_Spineux?= Notice that the '.' in the prefix is replaced by "=2E", because Header preventively encode all non alpha or digit characters to match the most restrictive header rules. The Python function email.utils.formataddr() quotes the special characters but don't encode non us-ascii characters. On the other hand, email.header.Header can encode non us-ascii characters but ignore all specials rule about address encoding. Let see how both work: >>> email.Utils.formataddr(('Alain Spineux', 'alain.spineux at gmail.com')) 'Alain Spineux ' This is a valid header value for a To: field >>> str(Header('Dr. Alain Spineux ')) 'Dr. Alain Spineux ' Here the '.' should be escaped like these 13 characters: []\()<>@,:;". >>> email.Utils.formataddr(('"Alain" Spineux', 'alain.spineux at gmail.com')) '"\\"Alain\\" Spineux" ' Here '"' is escaped using '\', this is fine. >>> email.Utils.formataddr((u'Ala\xefn Spineux', 'alain.spineux at gmail.com')) u'Ala\xefn Spineux ' formataddr() don't handle non us-ascii string, this must be done by Header object >>> str(Header(email.Utils.formataddr((u'Ala\xefn Spineux', 'alain.spineux at gmail.com')))) '=?utf-8?q?Ala=C3=AFn_Spineux_=3Calain=2Espineux=40gmail=2Ecom=3E?=' This is not valid because the address is also encoded and an old or some recent MUA will't handle this. The good form here is : =?utf-8?q?Ala=C3=AFn_Spineux?= ' Function format_addresses(addresses, header_name=None, charset=None) handle carefully the encoding of the addresses. >>> str(format_addresses([ (u'Ala\xefn Spineux', 'alain.spineux at gmail.com'), ('John', 'John at smith.com'), ], 'to', 'iso-8859-1')) '=?iso-8859-1?q?Ala=EFn_Spineux?= ,\n John ' Bytes and unicode string can be mixed. Addresses must always be us- ascii. Byte string must be encoded using charset or be us-ascii. Unicode strings that cannot be encoded using charset will be encoded using utf-8 automatically by Header. For dates, use the email.utils.formatdate() this way. >>> email.utils.formatdate(time.time(), localtime=True) 'Wed, 10 Aug 2011 16:46:30 +0200' The mail body Depending of your need : text and/or html version of the message related inline images attached files the structure of the MIME email may vary, but the general one is as follow: multipart/mixed | +-- multipart/related | | | +-- multipart/alternative | | | | | +-- text/plain | | +-- text/html | | | +-- image/gif | +-- application/msword Un-needed parts will be removed by function gen_mail(text, html=None, attachments=[], relateds=[]) regarding your parameters. >>> print gen_mail(text=(u'Bonne journ\xe8e', 'iso-8859-1'), \ html=None, \ attachments=[ (u'Text attach \xe8'.encode('iso-8859-1'), 'text', 'plain', 'filename.txt', 'iso-8859-1'), ] ) >From nobody Thu Aug 11 08:05:14 2011 Content-Type: multipart/mixed; boundary="===============0992984520==" MIME-Version: 1.0 --===============0992984520== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Bonne journ=E8e --===============0992984520== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="filename.txt" Text attach=E8 --===============0992984520==-- text and html are tuple of the form (content, encoding). Items of the attachments list can be tuples of the form (content, maintype, subtype, filename, charset) or can be MIME object inheriting from MIMEBase. If maintype is 'text', charset must match the encoding of the content, or if content is unicode, charset will be used to encode it. For other value of maintype, charset is not used. relateds is similar to attachments but content is related to the message in HTML to allow embedding of images or other contents. filename is replaced by content_id that must match the cid: references inside the HTML message. Attachments can have non us-ascii filename, but this is badly supported by some MUA and then discouraged. Anyway, if you want to use non us-ascii filename, RFC2231 need the encoding but also the language. Replace filename, by a tuple of the form (encoding, language, filename), for example, use ('iso-8859-1', 'fr', u'r \xe9pertoir.png'.encode('iso-8859-1')) instead of 'filename.txt'. The attached source code provide more samples. Look carefully in it how I encode or not the unicode string and content before to use them. Send your email The Python smtplib library handles SSL, STARTLS, and authentication, all you need to connect to any SMTP server. The library also reports all errors carefully. The send_mail(smtp_host, sender, recipients, subject, msg, default_charset, cc=[], bcc=[], smtp_port=25, smtp_mode='normal', smtp_login=None, smtp_password=None, message_id_string=None) function first fill in the header about sender and recipients using format_addresses() function, and send the email to the SMTP using the protocols and credentials you have choose with smtp_* variables. sender is a tuples and recipients, cc, bcc are list of tuple of the form [ (name, address), .. ] like expected by format_addresses(). default_charset will be used as default encoding when generating the email (to encode unicode string), and as default encoding for byte string. subject is the subject of the email. msg is a MIME object like returned by gen_mail(). smtp_mode can be 'normal', 'ssl' or 'tls'. For example if you want to use your GMAIL account to send your emails, use this setup: smtp_host='smtp.gmail.com' smtp_port=587 smtp_mode='tls' smtp_login='your.address at gmail.com' smtp_password='yourpassword' sender=('Your Name', smtp_login) Most of the time you will just need to specify smtp_host Source #!/bin/env/python # # sendmail.py # (c) Alain Spineux # http://blog.magiksys.net/sending-email-using-python-tutorial # Released under GPL # import os, sys import time import base64 import smtplib import email import email.header import email.utils import email.mime import email.mime.base import email.mime.text import email.mime.image import email.mime.multipart def format_addresses(addresses, header_name=None, charset=None): """This is an extension of email.utils.formataddr. Function expect a list of addresses [ ('name', 'name at domain'), ...]. The len(header_name) is used to limit first line length. The function mix the use Header(), formataddr() and check for 'us-ascii' string to have valid and friendly 'address' header. If one 'name' is not unicode string, then it must encoded using 'charset', Header will use 'charset' to decode it. Unicode string will be encoded following the "Header" rules : ( try first using ascii, then 'charset', then 'uft8') 'name at address' is supposed to be pure us-ascii, it can be unicode string or not (but cannot contains non us-ascii) In short Header() ignore syntax rules about 'address' field, and formataddr() ignore encoding of non us-ascci chars. """ header=email.header.Header(charset=charset, header_name=header_name) for i, (name, addr) in enumerate(addresses): if i!=0: # add separator between addresses header.append(',', charset='us-ascii') # check if address name is a unicode or byte string in "pure" us-ascii try: if isinstance(name, unicode): # convert name in byte string name=name.encode('us-ascii') else: # check id byte string contains only us-ascii chars name.decode('us-ascii') except UnicodeError: # Header will use "RFC2047" to encode the address name # if name is byte string, charset will be used to decode it first header.append(name) # here us-ascii must be used and not default 'charset' header.append('<%s>' % (addr,), charset='us-ascii') else: # name is a us-ascii byte string, i can use formataddr formated_addr=email.utils.formataddr((name, addr)) # us-ascii must be used and not default 'charset' header.append(formated_addr, charset='us-ascii') return header def gen_mail(text, html=None, attachments=[], relateds=[]): """generate the core of the email message. text=(encoded_content, encoding) html=(encoded_content, encoding) attachments=[(data, maintype, subtype, filename, charset), ..] if maintype is 'text', data lmust be encoded using charset filename can be us-ascii or (charset, lang, encoded_filename) where encoded_filename is encoded into charset, lang can be empty but usually the language related to the charset. relateds=[(data, maintype, subtype, content_id, charset), ..] idem attachment above, but content_id is related to the "CID" reference in the html version of the message. """ main=text_part=html_part=None if text: content, charset=text main=text_part=email.mime.text.MIMEText(content, 'plain', charset) if html: content, charset=html main=html_part=email.mime.text.MIMEText(content, 'html', charset) if not text_part and not html_part: main=text_part=email.mime.text.MIMEText('', 'plain', 'us- ascii') elif text_part and html_part: # need to create a multipart/alternative to include text and html version main=email.mime.multipart.MIMEMultipart('alternative', None, [text_part, html_part]) if relateds: related=email.mime.multipart.MIMEMultipart('related') related.attach(main) for part in relateds: if not isinstance(part, email.mime.base.MIMEBase): data, maintype, subtype, content_id, charset=part if (maintype=='text'): part=email.mime.text.MIMEText(data, subtype, charset) else: part=email.mime.base.MIMEBase(maintype, subtype) part.set_payload(data) email.Encoders.encode_base64(part) part.add_header('Content-ID', '<'+content_id+'>') part.add_header('Content-Disposition', 'inline') related.attach(part) main=related if attachments: mixed=email.mime.multipart.MIMEMultipart('mixed') mixed.attach(main) for part in attachments: if not isinstance(part, email.mime.base.MIMEBase): data, maintype, subtype, filename, charset=part if (maintype=='text'): part=email.mime.text.MIMEText(data, subtype, charset) else: part=email.mime.base.MIMEBase(maintype, subtype) part.set_payload(data) email.Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment', filename=filename) mixed.attach(part) main=mixed return main def send_mail(smtp_host, sender, recipients, subject, msg, default_charset, cc=[], bcc=[], smtp_port=25, smtp_mode='normal', smtp_login=None, smtp_password=None, message_id_string=None): """ """ mail_from=sender[1] rcpt_to=map(lambda x:x[1], recipients) rcpt_to.extend(map(lambda x:x[1], cc)) rcpt_to.extend(map(lambda x:x[1], bcc)) msg['From'] = format_addresses([ sender, ], header_name='from', charset=default_charset) msg['To'] = format_addresses(recipients, header_name='to', charset=default_charset) msg['Cc'] = format_addresses(cc, header_name='cc', charset=default_charset) msg['Subject'] = email.header.Header(subject, default_charset) utc_from_epoch=time.time() msg['Date'] = email.utils.formatdate(utc_from_epoch, localtime=True) msg['Messsage-Id'] =email.utils.make_msgid(message_id_string) # Send the message errmsg='' failed_addresses=[] try: if smtp_mode=='ssl': smtp=smtplib.SMTP_SSL(smtp_host, smtp_port) else: smtp=smtplib.SMTP(smtp_host, smtp_port) if smtp_mode=='tls': smtp.starttls() if smtp_login and smtp_password: # login and password must be encoded # because HMAC used in CRAM_MD5 require non unicode string smtp.login(smtp_login.encode('utf-8'), smtp_password.encode('utf-8')) ret=smtp.sendmail(mail_from, rcpt_to, msg.as_string()) smtp.quit() except (socket.error, ), e: errmsg='server %s:%s not responding: %s' % (smtp_host, smtp_port, e) except smtplib.SMTPAuthenticationError, e: errmsg='authentication error: %s' % (e, ) except smtplib.SMTPRecipientsRefused, e: # code, errmsg=e.recipients[recipient_addr] errmsg='recipients refused: '+', '.join(e.recipients.keys()) except smtplib.SMTPSenderRefused, e: # e.sender, e.smtp_code, e.smtp_error errmsg='sender refused: %s' % (e.sender, ) except smtplib.SMTPDataError, e: errmsg='SMTP protocol mismatch: %s' % (e, ) except smtplib.SMTPHeloError, e: errmsg="server didn't reply properly to the HELO greeting: %s" % (e, ) except smtplib.SMTPException, e: errmsg='SMTP error: %s' % (e, ) except Exception, e: errmsg=str(e) else: if ret: failed_addresses=ret.keys() errmsg='recipients refused: '+', '.join(failed_addresses) return msg, errmsg, failed_addresses And how to use it : smtp_host='max' smtp_port=25 if False: smtp_host='smtp.gmail.com' smtp_port='587' smtp_login='your.addresse at gmail.com' smtp_passwd='your.password' sender=(u'Ala\xefn Spineux', 'alain.spineux at gmail.com') sender=(u'Alain Spineux', u'alain.spineux at gmail.com') root_addr='root at max.asxnet.loc' recipients=[ ('Alain Spineux', root_addr), # (u'Alain Spineux', root_addr), # ('Dr. Alain Spneux', root_addr), # (u'Dr. Alain Spneux', root_addr), # (u'Dr. Ala\xefn Spineux', root_addr), # (u'Dr. Ala\xefn Spineux', root_addr), # ('us_ascii_name_with_a_space_some_where_in_the_middle to_allow_python_Header._split()_to_split_according_RFC2822', root_addr), # (u'This-is-a-very-long-unicode-name-with-one-non-ascii- char-\xf4-to-force-Header()-to-use-RFC2047-encoding-and-split-in-multi- line', root_addr), # ('this_line_is_too_long_and_dont_have_any_white_space_to_allow_Header._split()_to_split_according_RFC2822', root_addr), # ('Alain Spineux', root_addr), ] smile_png=base64.b64decode( """iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOBAMAAADtZjDiAAAAMFBMVEUQEAhaUjlaWlp7e3uMezGU hDGcnJy1lCnGvVretTnn5+/3pSn33mP355T39+// 75SdwkyMAAAACXBIWXMAAA7EAAAOxAGVKw4b AAAAB3RJTUUH2wcJDxEjgefAiQAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9u ABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJ dEVYdFNvZnR3YXJlAF1w/ zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDA G+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/ AAAABnRFWHRUaXRsZQCo 7tInAAAAaElEQVR4nGNYsXv3zt27TzHcPup6XDBmDsOeBvYzLTynGfacuHfm/ x8gfS7tbtobEM3w n2E9kP5n9N/oPZA+//7PP5D8GSCYA6RPzjlzEkSfmTlz +xkgffbkzDlAuvsMWAHDmt0g0AUAmyNE wLAIvcgAAAAASUVORK5CYII= """) angry_gif=base64.b64decode( """R0lGODlhDgAOALMAAAwMCYAAAACAAKaCIwAAgIAAgACAgPbTfoR/YP8AAAD/AAAA// rMUf8A/wD/ //Tw5CH5BAAAAAAALAAAAAAOAA4AgwwMCYAAAACAAKaCIwAAgIAAgACAgPbTfoR/ YP8AAAD/AAAA //rMUf8A/wD///Tw5AQ28B1Gqz3S6jop2sxnAYNGaghAHirQUZh6sEDGPQgy5/b9UI +eZkAkghhG ZPLIbMKcDMwLhIkAADs= """) pingu_png=base64.b64decode( """iVBORw0KGgoAAAANSUhEUgAAABoAAAATBAMAAAB8awA1AAAAMFBMVEUQGCE5OUJKa3tSUlJSrdZj xu9rWjl7e4SljDGlnHutnFK9vbXGxsbWrTHW1tbv7+88a/ HUAAAACXBIWXMAAA7EAAAOxAGVKw4b AAAAB3RJTUUH2wgJDw8mp5ycCAAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9u ABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJ dEVYdFNvZnR3YXJlAF1w/ zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDA G+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/ AAAABnRFWHRUaXRsZQCo 7tInAAAA0klEQVR4nE2OsYrCUBBFJ42woOhuq43f4IfYmD5fsO2yWNhbCFZ21ovgFyQYG1FISCxt Xi8k3KnFx8xOTON0Z86d4ZKKiNowM5QEUD6FU9uCSWwpYThrSQuj2fjLso2DqB9OBqqvJFiVllHa usJedty1NFe2brRbs7ny5aIP8dSXukmyUABQ0CR9AU9d1IOO1EZgjg7n+XEBpOQP0E/ rUz2Rlw09 Amte7bdVSs/s7py5i1vFRsnFuW+gdysSu4vzv9vm57faJuY0ywFhAFmupO/zDzDcxlhVE/ gbAAAA AElFTkSuQmCC """) text_utf8="""This is the the text part. With a related picture: cid:smile.png and related document: cid:related.txt Bonne journ\xc3\xa9ee. """ utext=u"""This is the the text part. With a related picture: cid:smile.png and related document: cid:related.txt Bonne journ\xe9e. """ data_text=u'Text en Fran\xe7ais' related_text=u'Document relatif en Fran\xe7ais' html=""" This is the html part with a related picture: and related document: here
Bonne journée. """ relateds=[ (smile_png, 'image', 'png', 'smile.png', None), (related_text.encode('iso-8859-1'), 'text', 'plain', 'related.txt', 'iso-8859-1'), ] pingu_att=email.mime.image.MIMEImage(pingu_png, 'png') pingu_att.add_header('Content-Disposition', 'attachment', filename=('iso-8859-1', 'fr', u'ping\xfc.png'.encode('iso-8859-1'))) pingu_att2=email.mime.image.MIMEImage(pingu_png, 'png') pingu_att2.add_header('Content-Disposition', 'attachment', filename='pingu.png') attachments=[ (angry_gif, 'image', 'gif', ('iso-8859-1', 'fr', u'\xe4ngry.gif'.encode('iso-8859-1')), None), (angry_gif, 'image', 'gif', 'angry.gif', None), (data_text.encode('iso-8859-1'), 'text', 'plain', 'document.txt', 'iso-8859-1'), pingu_att, pingu_att2] mail=gen_mail((utext.encode('iso-8859-1'), 'iso-8859-1'), (html, 'us- ascii'), attachments, relateds) msg, errmsg, failed_addresses=send_mail(smtp_host, \ sender, \ recipients, \ u'My Subject', \ mail, \ default_charset='iso-8859-1', cc=[('Gama', root_addr), ], bcc=[('Colombus', root_addr), ], smtp_port=smtp_port, ) print msg print errmsg print failed_addresses From jkbbwr at gmail.com Thu Aug 11 11:42:38 2011 From: jkbbwr at gmail.com (Jakob Bowyer) Date: Thu, 11 Aug 2011 16:42:38 +0100 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: -1 This idea seems like it would remove the true readability of python. Personally it would create more confusion than it would remove. On Thu, Aug 11, 2011 at 3:28 PM, Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. Since a final > ':' is needed anyway, i think this would be great. > > if a > ?and b > ?or c: > ?do stuff() > > On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: >> On 11/08/2011 05:16, Chris Rebert wrote: >>> >>> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>>> >>>> :And if we require {} then truly free indentation should be OK too! But >>>> >>>> :it wouldn't be Python any more. >>>> >>>> Of course, but not the case with ';'. Currently ';' is optional in >>>> Python, >>> >>> I think of it more as that Python deigns to permit semicolons. >>> >>>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>>> magnitude. >>>> >>>> So the decision is: shall we change ';' from optional to mandatory >>>> to allow free line splitting? >>> >>> Hell no, considering that the sizable majority of lines *aren't* >>> split, which makes those semicolons completely redundant to their >>> accompanying newlines. We'd be practicing poor Huffman coding by >>> optimizing for the *un*common case. It would also add punctuational >>> noise to what is otherwise an amazingly clean and readable syntax. >>> Accidental semicolon omission is (IMO) the most irritating source of >>> syntax (and, inadvertently, sometimes other more serious) errors in >>> curly-braced programming languages. >>> >> +1 >>> >>> Such a core syntax feature is not going to be changed lightly (or likely >>> ever). >>> >> I'm glad to hear that. :-) >> >> Although Python's use of indentation has its downside, we gain much >> more then we lose, IMHO. >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> http://mail.python.org/mailman/listinfo/python-ideas >> > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From Tim.Arnold at sas.com Thu Aug 11 12:58:00 2011 From: Tim.Arnold at sas.com (Tim Arnold) Date: Thu, 11 Aug 2011 12:58:00 -0400 Subject: multiprocessing timing issue In-Reply-To: References: Message-ID: On 8/10/2011 11:36 PM, Philip Semanchuk wrote: > > On Aug 9, 2011, at 1:07 PM, Tim Arnold wrote: > >> Hi, I'm having problems with an empty Queue using multiprocessing. >> >> The task: >> I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. >> I'm using multiprocessing to do the data-gathering simultaneously. >> >> Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. >> >> My problem is that sometimes the Queue is empty and I guess it's >> because the get_data() method takes a lot of time. >> >> I've used multiprocessing before, but never with a Queue like this. >> Any notes or suggestions are very welcome. > > > Hi Tim, > THis might be a dumb question, but...why is it a problem if the queue is empty? It sounds like you figured out already that get_data() sometimes takes longer than your timeout. So either increase your timeout or learn to live with the fact that the queue is sometimes empty. I don't mean to be rude, I just don't understand the problem. > > Cheers > Philip > Hi Philip, Not a dumb or rude question at all, thanks for thinking about it. When the queue is empty the report cannot be updated, so that's why I was concerned--I couldn't figure out how to block. Now that's dumb! From your response and Tim Roberts too, I see that it's possible to block until the data comes back. I just should never have put that timeout in there. I must have assumed it would not block with no timeout given. Wrong.... From the docs on q.get(): If optional args 'block' is true and 'timeout' is None (the default), block if necessary until an item is available. If 'timeout' is a positive number, it blocks at most 'timeout' seconds and raises the Empty exception if no item was available within that time. Otherwise ('block' is false), return an item if one is immediately available, else raise the Empty exception ('timeout' is ignored in that case). thanks, --Tim Arnold From pydanny at gmail.com Thu Aug 11 13:04:24 2011 From: pydanny at gmail.com (Daniel Greenfeld) Date: Thu, 11 Aug 2011 10:04:24 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Something like this already exists: a = 0 b = 1 if (True == True and False == False and a + 1 == b and b - 1 == a): print 'meh' So I've got no idea what this proposal is about except for the dropping of readability of Python. -1 Daniel Greenfeld On Thu, Aug 11, 2011 at 8:42 AM, Jakob Bowyer wrote: > -1 This idea seems like it would remove the true readability of > python. Personally it would create more confusion than it would > remove. > > On Thu, Aug 11, 2011 at 3:28 PM, Matt Joiner wrote: >> +0.5 >> >> The "trailing \" workaround is nonobvious. Wrapping in () is noisy and >> already heavily used by other syntactical structures. Since a final >> ':' is needed anyway, i think this would be great. >> >> if a >> ?and b >> ?or c: >> ?do stuff() >> >> On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: >>> On 11/08/2011 05:16, Chris Rebert wrote: >>>> >>>> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>>>> >>>>> :And if we require {} then truly free indentation should be OK too! But >>>>> >>>>> :it wouldn't be Python any more. >>>>> >>>>> Of course, but not the case with ';'. Currently ';' is optional in >>>>> Python, >>>> >>>> I think of it more as that Python deigns to permit semicolons. >>>> >>>>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>>>> magnitude. >>>>> >>>>> So the decision is: shall we change ';' from optional to mandatory >>>>> to allow free line splitting? >>>> >>>> Hell no, considering that the sizable majority of lines *aren't* >>>> split, which makes those semicolons completely redundant to their >>>> accompanying newlines. We'd be practicing poor Huffman coding by >>>> optimizing for the *un*common case. It would also add punctuational >>>> noise to what is otherwise an amazingly clean and readable syntax. >>>> Accidental semicolon omission is (IMO) the most irritating source of >>>> syntax (and, inadvertently, sometimes other more serious) errors in >>>> curly-braced programming languages. >>>> >>> +1 >>>> >>>> Such a core syntax feature is not going to be changed lightly (or likely >>>> ever). >>>> >>> I'm glad to hear that. :-) >>> >>> Although Python's use of indentation has its downside, we gain much >>> more then we lose, IMHO. >>> _______________________________________________ >>> Python-ideas mailing list >>> Python-ideas at python.org >>> http://mail.python.org/mailman/listinfo/python-ideas >>> >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> http://mail.python.org/mailman/listinfo/python-ideas >> > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From nad at acm.org Thu Aug 11 13:26:44 2011 From: nad at acm.org (Ned Deily) Date: Thu, 11 Aug 2011 10:26:44 -0700 Subject: code object differences between 2.7 and 3.3a References: Message-ID: In article , Eric Snow wrote: > Specifically, I am wondering why there is a difference for co_names. This is not an answer to your question but, as a metapoint, in my experience it is usually faster and often more reliable to try to answer questions like this yourself using the tools that the Python project provides: - clone a copy of the hg repository and update to the branch of interest - become familiar with the code layout (the developers guide can help with this (http://docs.python.org/devguide/) - use "hg annotate" to see what lines were changed by what rev sets and by whom - use "hg log -v " to browse the history entries for the file - look up the tracker issues referenced in those history entries and follow the discussions there The Python project has an effective process for code development and one that emphasizes good documentation of changes and additions. For instance, as part of the transition earlier this year from Subversion to Mercurial, great care was taken to preserve as much of the existing source history as possible going far back into the time machine. It's to your advantage to take advantage of these sources of history. -- Ned Deily, nad at acm.org From paul at colomiets.name Thu Aug 11 15:17:08 2011 From: paul at colomiets.name (Paul Colomiets) Date: Thu, 11 Aug 2011 22:17:08 +0300 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Hi Matt, On Thu, Aug 11, 2011 at 5:28 PM, Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. Since a final > ':' is needed anyway, i think this would be great. > > if a > ?and b > ?or c: > ?do stuff() > If you really think so, try writing some coffeescript (remember to obey 79 chars limit). Coffeescript is amasing, but it lacks strictness of python. So you really don't know how to break line, and it really takes time to figure out right way each time you need it. -- Paul From jeanpierreda at gmail.com Thu Aug 11 15:24:34 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 15:24:34 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Javascript also lets you break lines. For example, this does what you want: return 1 + 5 Whereas this does not return 1 + 5 Of course, Python would have no such problem, because you could make both cases unambiguous due to the indent. Devin On Thu, Aug 11, 2011 at 3:17 PM, Paul Colomiets wrote: > Hi Matt, > > On Thu, Aug 11, 2011 at 5:28 PM, Matt Joiner wrote: > > +0.5 > > > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > > already heavily used by other syntactical structures. Since a final > > ':' is needed anyway, i think this would be great. > > > > if a > > and b > > or c: > > do stuff() > > > If you really think so, try writing some coffeescript (remember to > obey 79 chars limit). Coffeescript is amasing, but it lacks > strictness of python. So you really don't know how to break line, > and it really takes time to figure out right way each time you need > it. > > -- > Paul > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paddy3118 at googlemail.com Thu Aug 11 16:31:45 2011 From: paddy3118 at googlemail.com (Paddy) Date: Thu, 11 Aug 2011 13:31:45 -0700 (PDT) Subject: Python 3.X: nonlocal support in eval/exec? References: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> Message-ID: <996e6195-1550-4149-ba5c-5f43eceebbad@fv14g2000vbb.googlegroups.com> On Aug 11, 8:48?am, Terry Reedy wrote: > On 8/11/2011 3:19 AM, Paddy wrote: > > > We can access nonlocal variables in a function, but if we were to eval/ > > exec the function we cannot set up a nested stack of evironment dicts. > > We are limited to just two: global and local. > > Right. That was and is Python's execution model. > Note that when you exec code, including a function call, the locals > passed is the local context in which the code is executed. It is not the > locals of any particular function called by the exec-ed code. > > If you exec a function that is a closure, the closure or non-local > objects come with the function. A 'stack of dicts' has nothing to do > with how function and nested funcs operate. > > -- > Terry Jan Reedy Thanks Terry. From bruce at leapyear.org Thu Aug 11 16:45:58 2011 From: bruce at leapyear.org (Bruce Leban) Date: Thu, 11 Aug 2011 13:45:58 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 12:24 PM, Devin Jeanpierre wrote: > Javascript also lets you break lines. For example, this does what you want: > > return 1 > + 5 > > Whereas this does not > > return > 1 + 5 > > Of course, Python would have no such problem, because you could make both > cases unambiguous due to the indent. > > Devin > > > Note that this is already valid and is not a continuation line: return 1 +5 Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. Now allowing line breaks *after* operators would be unambiguous and would not require new indentation rules. When a line ends with an operator, it's clearly incomplete (so no fear the reader will think the statement has ended unlike the above case) and it's a syntax error today: return 1 + 5 x = y > 0 and y < 10 This code is not valid today without parens or \ regardless of indentation. I'm +0 on this. I'd use it but does it really add enough convenience? --- Bruce Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Thu Aug 11 17:06:59 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 17:06:59 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: > Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. Eek no. If I was suggesting anything, it would have been a third form of continuation: collapsing subsequent extra-indented lines. This is never ambiguous. (This could be done in such a way as to permit comments, namely, by doing it to the tokenstream rather than to the actual text) Devin On Thu, Aug 11, 2011 at 4:45 PM, Bruce Leban wrote: > > On Thu, Aug 11, 2011 at 12:24 PM, Devin Jeanpierre wrote: >> >> Javascript also lets you break lines. For example, this does what you want: >> >> ??? return 1 >> ??????? + 5 >> >> Whereas this does not >> >> ??? return >> ??????? 1 + 5 >> >> Of course, Python would have no such problem, because you could make both cases unambiguous due to the indent. >> >> Devin >> > Note that this is already valid and is not a continuation line: > > return 1 > +5 > > Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. > Now allowing line breaks *after* operators would be unambiguous and would not require new indentation rules. When a line ends with an operator, it's clearly incomplete (so no fear the reader will think the statement has ended unlike the above case) and it's a syntax error today: > > return 1 + > ? ? 5 > x = y > 0 and > ? ?y < 10 > > This code is not valid today without parens or \ regardless of indentation. I'm +0 on this. I'd use it but does it really add enough convenience? > --- Bruce > Follow me:?http://www.twitter.com/Vroo?http://www.vroospeak.com From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: On 2011-08-11, Ben Finney wrote: > What evidence do you have of these? The latter, especially, seems to be > mere opinion unfounded in any measurement. Well, on new collection of data, I'm less convinced. The basic rule is: Engineers are nearly always aware of tradeoffs. If I suddenly encounter something where many engineers perceive a tradeoff, and a few deny that there is any tradeoff at all, that usually means that the latter category are not actually doing the engineering thing. > Again, I don't know where you've been observing that, but it's not what > I've seen. I've seen it some here, and in other Python discussion threads. I've also seen counterexamples, though, more now that I brought it up. > You're welcome to attempt to demonstrate the superiority of some other > Python-with-braces, but it will (a) be un-Pythonic, and (b) be unlikely > to gain the efforts of people who don't think what you're addressing is > a problem. I have noticed a tendency for "Pythonic" to produce fierce debates in which there is absolutely nothing measurable to point to. I'm not sold on it. I guess the thing is this: I am pretty sure Python is a pretty nice language. However, the indentation thing has screwed me a few times. Furthermore, I know people who like Python a great deal and acknowledge, without much difficulty, that the indentation thing has caused problems or incompatibilities for them. So when I see people deny that it is at all a problem, or that there are any possible shortcomings to it, I infer that they have some compelling reason to deny the existence of a thing which is reliably and easily observed. See, that's the thing. If you want to tell me that there are problems with braces, I'll *agree*. I am aware of those problems. I don't feel a need to deny that they exist. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Seebs wrote: >> I have seen all the counterarguments, and what I've >> mostly become convinced of is this: >> 1. Indentation as flow control was a bad idea. > I'm not aware of any language where indentation is used for flow control. > Python is not one of those languages: it uses for, while, if, etc. for flow > control, just like most other languages. It does however use indentation > for grouping code into blocks -- a different concept. Agh! Point granted. Presumably you knew what I meant, but you're right that I said it wrong. > You are free to hold whatever opinions you like, but have you considered > that the reason people get emotional and angry when others insist that > indentation as flow control should be discarded is because they actually > believe that the "off-side rule" (as it is called) makes for a better > language and a better coding experience? Yes. And when I talk to people who are *able to admit that there exist problems*, and who argue that the benefits outweigh them, I believe that they are probably making a good point. It's the people who insist that there are no problems that worry me. > There are dozens, hundreds of brace languages, and 1-2 dozen using > indentation, including Python. If braces are so important to you, go use > one of those other languages, don't wreck the language we like by taking > away one of the best features of the language. If I had a choice, believe me, I'd do just that. > We're fully aware of the tradeoffs of significant indentation. You are. A couple of other people I've talked to are. Many others are not. > We believe > that brace languages get the trade-offs backwards: they optimise code for > environments which mangle source code. 99.999% of code will never pass > through a broken mail server that strips leading whitespace, or pasted into > broken web forum software that mangles indentation, or go through any other > broken tool that messes with indentation. Brace languages optimise for the > 0.001% case, Python optimised the 99.999% case. This is a really interesting analysis. My experience, though, puts it more at about 99% and 1%. And the thing is... > Because people simply don't like it when their code's indentation doesn't > match the actual semantics, people usually manually ensure that the two > match, braces or no braces. Editors still have commands to indent and > outdent blocks of code. There is no difference between (say) C or Pascal > and Python in that regard. Yes, there very much is. You can't outdent "a block" in Python unless it is already correctly indented. The underlying thing I've noticed is: Braces have problems more often, but the problems are *always* 100% machine-fixable and therefore trivial. It takes milliseconds to get a program fixed so it looks like what it means. Indentation has problems less often, but the problems are *never* machine-fixable. It takes minutes or hours to figure out what was supposed to be there. > There is nothing implicit about indentation. This false dichotomy between > so-called explicit braces and allegedly implicit indentation gets thrown > around all the time, but it is simply *wrong*. Indentation is not implicit. Hmm. Maybe "implicit" isn't quite the right word, but... The end of an indented block is not a thing, it's the lack-of-a-thing. foo bar How many unindents are there between "foo" and "bar"? If you can't answer this from looking between "foo" and "bar", but must instead look at previous lines and *INFER* the number of unindents, then it seems to me that there is something implicit going on here. > And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, > Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any > other languages with significant indentation. Point made. > No, most mail servers don't mangle whitespace in the body of the email, or > in attachments. Most don't, that's true. Part of my frustration comes from a 6-month period during which most of my email was sent through a mail server which, for reasons no one was able to determine, was dutifully converting any plain text it received into HTML, and stripping "irrelevant" spaces along the way. :) > Some mail clients do, usually because they default to using > HTML for text. So get a better mail client. I have tried occasionally. Mine does not default to use HTML, but it does sometimes mangle lines. Unfortunately, it's the closest to having other funcitonality I want I've ever seen. > Avoid pig-ignorant web forums > that think that source code can be reflowed or that remove leading > whitespace. Stop using Notepad, and use an editor that offers indent and > outdent commands. I'm not using Notepad. And actually, it's the indent/outdent that bit me worst, so far. :) > If your mail server had a bug that deleted braces from emails, would you fix > the bug, or would you insist that braces were a failed experiment and that > C should stop using { } and start using BEGIN END like Pascal? If *only one program* deleted braces, sure. If "braces get deleted" were pretty much a daily occurrence among people I know (not everyone gets hit every day, but someone gets hit just about every day), and had been for the last 20+ years, I might feel differently. But I think a lot of this just comes down to the underlying human thing: People don't like being dismissed. When people come here and say that, for whatever reason, they are in an environment in which the whitespace thing is a problem, they get insulted and told that all their tools, which they may have been using without any trouble for twenty years, are defective and should be completely thrown out. Heck, arguably I should consider "Stop using Notepad" to be pretty insulting. And at the same time, I think the people who like the indentation policy are probably pretty sick of seeing it bashed. So there's a tendency for gradual escalation, and of course, each new person who comes here is coming here with a thing which is new *to them*, but old *to you*. So CLP jumps all over people who say that this is a problem for them, tells them they're wrong, tells them they're stupid, tells them that their work environment isn't *good enough* for them to be worthy of using Python. And tells them to leave. Well, seriously. If I could, I would. If it were up to me, I'd talk to the people who'd picked Python for some stuff I have to work for, point out the hostility of the Python community to newcomers whose workflows don't happen to have been preemptively built entirely around Python's design decisions, and suggest that maybe we use another language. Heck, since I've been encouraged so much to do so, I think I will. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e43cdbc$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Steven D'Aprano wrote: >> indentation as flow control > Gah! Of course, I meant indentation for blocks... after making the earlier > point that indentation is *not* used for flow control, this was a > particularly egregious error. > How embarrassment. My fault, I probably hypnotized you with my bad word choice. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From bruce at leapyear.org Thu Aug 11 17:21:53 2011 From: bruce at leapyear.org (Bruce Leban) Date: Thu, 11 Aug 2011 14:21:53 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 2:06 PM, Devin Jeanpierre wrote: > > Eek no. If I was suggesting anything, it would have been a third form > of continuation: collapsing subsequent extra-indented lines. This is > never ambiguous. (This could be done in such a way as to permit > comments, namely, by doing it to the tokenstream rather than to the > actual text) So if I miss-indent this a = b (x, y) = z instead of getting "unexpected indent" I get "SyntaxError: can't assign to function call". I'm sure someone can come up with two valid statements that have a different meaning when spliced together. --- Bruce Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Thu Aug 11 17:29:36 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 17:29:36 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: a = b, c = d is a pair of such statements. Howeverm indentation errors have been extremely rare in my experience, so I'm not really compelled to think it's harmful. Especially since 3.x outlaws mixing tabs and spaces. I don't love it, but I guess I prefer it to throwing parentheses and especially \ everywhere. Parentheses can be awkward and don't quite work everywhere the way one might want, and \ has that trailing space ugliness. Devin On Thu, Aug 11, 2011 at 5:21 PM, Bruce Leban wrote: > > On Thu, Aug 11, 2011 at 2:06 PM, Devin Jeanpierre > wrote: >> >> Eek no. If I was suggesting anything, it would have been a third form >> of continuation: collapsing subsequent extra-indented lines. This is >> never ambiguous. (This could be done in such a way as to permit >> comments, namely, by doing it to the tokenstream rather than to the >> actual text) > > So if I miss-indent this > a = b > ? (x, y) = z > > instead of getting "unexpected indent" I get "SyntaxError: can't assign to > function call". I'm sure someone can come up with two valid statements that > have a different meaning when spliced together. > --- Bruce > Follow me:?http://www.twitter.com/Vroo?http://www.vroospeak.com > > > From sigmundv at gmail.com Thu Aug 11 17:38:32 2011 From: sigmundv at gmail.com (SigmundV) Date: Thu, 11 Aug 2011 14:38:32 -0700 (PDT) Subject: String concatenation - which is the fastest way ? References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: When I saw the headline I thought "oh no, not string concatenation again... we have had scores of these thread before...", but this is a rather interesting problem. The OP says he's not a database developer, but why is he then fiddling with internal database operations? Wouldn't it be better to go back to the database developers and have them look into parallel processing. I'm sure that Oracle databases can do parallel processing by now... Sigmund From jimjjewett at gmail.com Thu Aug 11 17:39:01 2011 From: jimjjewett at gmail.com (Jim Jewett) Date: Thu, 11 Aug 2011 17:39:01 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 5:29 PM, Devin Jeanpierre wrote: > Howeverm indentation errors have been extremely rare in my experience, > so I'm not really compelled to think it's harmful. Especially since > 3.x outlaws mixing tabs and spaces. I normally get them when starting with code from somewhere else (which might well mixed tabs and spaces, or worse, if emailed or posted to the web) or when cutting and pasting at an interactive prompt. -jJ From jeanpierreda at gmail.com Thu Aug 11 18:29:37 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 18:29:37 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Well the tabs&spaces issue is no longer an issue as far as I understand it (such a change to indent semantics could only go into 3.x), and cutting and pasting to the interpreter is obvious anyway just visually, regardless of the specific error message. The other issue sounds reasonable. Code that has indentation stripped or mangled due to the transition medium would be even harder to recompose. Devin On Thu, Aug 11, 2011 at 5:39 PM, Jim Jewett wrote: > On Thu, Aug 11, 2011 at 5:29 PM, Devin Jeanpierre > wrote: >> Howeverm indentation errors have been extremely rare in my experience, >> so I'm not really compelled to think it's harmful. Especially since >> 3.x outlaws mixing tabs and spaces. > > I normally get them when starting with code from somewhere else (which > might well mixed tabs and spaces, or worse, if emailed or posted to > the web) or when cutting and pasting at an interactive prompt. > > -jJ > From ppv.grps at gmail.com Thu Aug 11 18:43:06 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 15:43:06 -0700 (PDT) Subject: TypeError: 'module' object is not callable Message-ID: I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: x = Univariate(a) # a is a list that is expected by the Univariate class python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a print dir(Univariate) it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. What gives? Thanks in advance. ====================== FreeBSD 7.2 machine with python version 2.5.6 From ethan at stoneleaf.us Thu Aug 11 18:43:39 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Aug 2011 15:43:39 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E445B1B.2010802@stoneleaf.us> Seebs wrote: >> We're fully aware of the tradeoffs of significant indentation. > > You are. A couple of other people I've talked to are. Many others > are not. The times that whitespace indentation has bitten me, it was still not difficult to fix -- I just had to look and see which line(s) should/should not be where they were. >> Because people simply don't like it when their code's indentation doesn't >> match the actual semantics, people usually manually ensure that the two >> match, braces or no braces. Editors still have commands to indent and >> outdent blocks of code. There is no difference between (say) C or Pascal >> and Python in that regard. > > Yes, there very much is. > > You can't outdent "a block" in Python unless it is already correctly > indented. I fix the block, then move it as I need to. > The underlying thing I've noticed is: > > Braces have problems more often, but the problems are *always* 100% > machine-fixable and therefore trivial. It takes milliseconds to get > a program fixed so it looks like what it means. Not so. If the braces do not match /intent/ (which is the problem I care most about) then it cannot be fixed by machine. > Indentation has problems less often, but the problems are *never* > machine-fixable. It takes minutes or hours to figure out what was > supposed to be there. I can see where a messed-up mail server could cause hours of grief. Not having experienced that, but only cases where I, myself, accidently changed indentation when I should have, it's not been a big deal to fix; I'm willing to live with not having the machine reformat my source code from incorrect to correct. ... > Well, seriously. If I could, I would. If it were up to me, I'd talk to the > people who'd picked Python for some stuff I have to work for, point out the > hostility of the Python community to newcomers whose workflows don't happen > to have been preemptively built entirely around Python's design decisions, > and suggest that maybe we use another language. Heck, since I've been > encouraged so much to do so, I think I will. Your choice, obviously -- seems a shame to me, though, to give up on Python because of one or two ouchy areas on c.l.py. By and large it's a very helpful and courteous community. ~Ethan~ From iamforufriends at gmail.com Thu Aug 11 19:35:15 2011 From: iamforufriends at gmail.com (kate for free dating) Date: Thu, 11 Aug 2011 16:35:15 -0700 (PDT) Subject: Its eazy to make girl friend and here... just add here with female profile... u willget hot girls for free....try it once... if probelem with ur original make, jsut make mail id and try it... http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas Message-ID: Its eazy to make girl friend and here... just add here with female profile... u willget hot girls for free....try it once... if probelem with ur original make, jsut make mail id and try it... http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 From gordon at panix.com Thu Aug 11 19:39:21 2011 From: gordon at panix.com (John Gordon) Date: Thu, 11 Aug 2011 23:39:21 +0000 (UTC) Subject: TypeError: 'module' object is not callable References: Message-ID: In Forafo San writes: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > x = Univariate(a) # a is a list that is expected by the Univariate class > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a It's difficult to diagnose this problem when you haven't shown us the code for Univariate. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Thu Aug 11 19:58:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 00:58:30 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: On Thu, Aug 11, 2011 at 10:19 PM, Seebs wrote: > I am pretty sure Python is a pretty nice language. ?However, the indentation > thing has screwed me a few times. ?Furthermore, I know people who like Python > a great deal and acknowledge, without much difficulty, that the indentation > thing has caused problems or incompatibilities for them. > Indentation-is-syntax is a feature of Python, and one that's not likely to change. Some programmers do not like indentation to be syntax, and a lot of them are not likely to change their views. There's a solution to this dilemma; it's called "using another language". Python is just one of many excellent languages in the world today. Even if you exclude non-free languages and non-free compilers/interpreters, you still have a wealth of options. Check Wikipedia, find one in a category that interests you, download a development environment, and give it a shot! It would surprise me *greatly* if the regular posters on this list were not all familiar with several languages other than Python, including at least one bracey language. The arguments do not come from ignorance but from knowledge. Incidentally, I will happily argue the benefits of Python's significant whitespace, even though I disagree with it; there are quite a few. (Is the fact that it discourages massive one-liners considered to be a benefit?) Of course, sometimes choosing another language is a luxury you can't afford. But in those situations, usually you're slotting into someone else's code Manual of Style too, so you might be required to write C code with three-space indents and a blank line before every open brace, for all we know. Doesn't matter that you're in a whitespace-insignificant language; you are in a whitespace-significant *environment*, and that's what matters. Chris Angelico From drobinow at gmail.com Thu Aug 11 20:15:39 2011 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Aug 2011 20:15:39 -0400 Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: On Thu, Aug 11, 2011 at 6:43 PM, Forafo San wrote: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to >import that class into a *.py file. However when I try to instantiate an object with that class like: What makes you think you're able to import that class? > x = Univariate(a) ? ? ? ? ? ? # a is a list that is expected by the Univariate class > > python raises the TypeError: 'module' object is not callable. ?If I embed the code of the Univariate >class in my *.py file, there is no problem. ?Also, when the class is imported and I do a > > print dir(Univariate) > > it does not print all the methods that are in the class, while if the class code appears in my *.py >file, all the methods are available and a list with the correct methods are printed. It appears that you are importing the "module" Univariate from the file Univariate.py If you want to instantiate the "class" Univariate contained in the "module" Univariate, try x = Univariate.Univariate(a) In the future, please try to include more of your code. From python at mrabarnett.plus.com Thu Aug 11 20:22:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 01:22:20 +0100 Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <4E44723C.6090804@mrabarnett.plus.com> On 11/08/2011 23:43, Forafo San wrote: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > x = Univariate(a) # a is a list that is expected by the Univariate class > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > print dir(Univariate) > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > What gives? > I think you mat be confusing the class with the module. When you write: import Univariate you're importing the module. If the module is called "Univariate" and the class within the module is called "Univariate" then you should either write: import Univariate x = Univariate.Univariate(a) # the class Univariate in the module Univariate or: from Univariate import Univariate x = Univariate(a) Incidentally, it's recommended that module names use lowercase, so that would be: import univariate x = univariate.Univariate(a) or: from univariate import Univariate From ppv.grps at gmail.com Thu Aug 11 20:56:34 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 17:56:34 -0700 (PDT) Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > On 11/08/2011 23:43, Forafo San wrote: > > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > > > x = Univariate(a) # a is a list that is expected by the Univariate class > > > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > > > print dir(Univariate) > > > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > > > What gives? > > > I think you mat be confusing the class with the module. > > When you write: > > import Univariate > > you're importing the module. > > If the module is called "Univariate" and the class within the module is > called "Univariate" then you should either write: > > import Univariate > x = Univariate.Univariate(a) # the class Univariate in the module > Univariate > > or: > > from Univariate import Univariate > x = Univariate(a) > > Incidentally, it's recommended that module names use lowercase, so that > would be: > > import univariate > x = univariate.Univariate(a) > > or: > > from univariate import Univariate Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again. From ppv.grps at gmail.com Thu Aug 11 20:56:34 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 17:56:34 -0700 (PDT) Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > On 11/08/2011 23:43, Forafo San wrote: > > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > > > x = Univariate(a) # a is a list that is expected by the Univariate class > > > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > > > print dir(Univariate) > > > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > > > What gives? > > > I think you mat be confusing the class with the module. > > When you write: > > import Univariate > > you're importing the module. > > If the module is called "Univariate" and the class within the module is > called "Univariate" then you should either write: > > import Univariate > x = Univariate.Univariate(a) # the class Univariate in the module > Univariate > > or: > > from Univariate import Univariate > x = Univariate(a) > > Incidentally, it's recommended that module names use lowercase, so that > would be: > > import univariate > x = univariate.Univariate(a) > > or: > > from univariate import Univariate Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again. From steve+comp.lang.python at pearwood.info Thu Aug 11 21:40:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 11:40:00 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > Incidentally, I will happily argue the > benefits of Python's significant whitespace, even though I disagree > with it; there are quite a few. Please be careful about conflating significant indentation with significant whitespace. Many languages have significant whitespace: foo bar is rarely the same thing as foobar but is the same as foo bar Python is no different. The only exception I can think of is *very* early Fortran, and that rightly is considered a mistake. Fortran 77 used to treat whitespace as always optional, so that in Python terms this: forxinrange(42) would be parsed as this: for x in range(42) See also: http://weblog.hotales.org/cgi-bin/weblog/nb.cgi/view/python/2005/02/19/1 http://c2.com/cgi/wiki?SyntacticallySignificantWhitespaceConsideredHarmful > (Is the fact that it discourages > massive one-liners considered to be a benefit?) Hell yes! -- Steven From jason.swails at gmail.com Thu Aug 11 21:47:57 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 11 Aug 2011 21:47:57 -0400 Subject: TypeError: 'module' object is not callable In-Reply-To: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> References: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> Message-ID: On Thu, Aug 11, 2011 at 8:56 PM, Forafo San wrote: > > Thank you all for your replies. When I do a > > from Univariate import Univariate > > the TypeError disappears and everything is fine. Clearly this was an error > that a newbie such as myself is likely to make because of little experience > with Python. However, this isn't something I'm likely to forget. > > I will also adopt the style recommendations. Thanks, again. > -- > http://mail.python.org/mailman/listinfo/python-list > As a beginner, I found that it was useful to note how these 2 approaches differ. In the first approach: import Univariate a = Univariate.Univariate(foo) what you're doing is loading everything in Univariate in a separate namespace (the Univariate namespace). The other approach: from Univariate import Univariate a = Univariate(foo) what you're doing is loading *just* Univariate into your top level namespace. It's important to note this difference because it has potentially critical implications as far as clobbering existing functions that happen to have the same name (if you're loading into your top level namespace with, for instance, "from mymodule import *") versus keeping everything in a separate namespace so stuff doesn't get overwritten. This is more applicable to scripts/programs you write that import a number of different modules, all of whom may contain objects with the same name. All the best, Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From goldtech at worldpost.com Thu Aug 11 22:03:36 2011 From: goldtech at worldpost.com (goldtech) Date: Thu, 11 Aug 2011 19:03:36 -0700 (PDT) Subject: Processing a large string Message-ID: Hi, Say I have a very big string with a pattern like: akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... I want to split the sting into separate parts on the "3" and process each part separately. I might run into memory limitations if I use "split" and get a big array(?) I wondered if there's a way I could read (stream?) the string from start to finish and read what's delimited by the "3" into a variable, process the smaller string variable then append/build a new string with the processed data? Would I loop it and read it char by char till a "3"...? Or? Thanks. From python at mrabarnett.plus.com Thu Aug 11 22:15:58 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 03:15:58 +0100 Subject: Processing a large string In-Reply-To: References: Message-ID: <4E448CDE.1060704@mrabarnett.plus.com> On 12/08/2011 03:03, goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > You could write a generator like this: def split(string, sep): pos = 0 try: while True: next_pos = string.index(sep, pos) yield string[pos : next_pos] pos = next_pos + 1 except ValueError: yield string[pos : ] string = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..." for part in split(string, "3"): print(part) From steve+comp.lang.python at pearwood.info Thu Aug 11 22:30:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 12:30:57 +1000 Subject: Processing a large string References: Message-ID: <4e449062$0$29975$c3e8da3$5496439d@news.astraweb.com> goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... Define "big". What seems big to you is probably not big to your computer. > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? You could, but unless there are a lot of 3s, it will probably be slow. If the 3s are far apart, it will be better to do this: # untested def split(source): start = 0 i = source.find("3") while i >= 0: yield source[start:i] start = i+1 i = source.find("3", start) That should give you the pieces of the string one at a time, as efficiently as possible. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 22:32:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 12:32:41 +1000 Subject: [Python-ideas] allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: <4e4490c9$0$29975$c3e8da3$5496439d@news.astraweb.com> Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. "Noisy"? Compare: # Best viewed with a fixed-width font if a if (a and b and b or c: or c): do stuff() do stuff() That is not my idea of "noise". The brackets have a clear and obvious meaning: they group the condition. > Since a final > ':' is needed anyway, i think this would be great. A final : is not needed for arbitrary expressions. flag = (a and b or c) -- Steven From mokurai at earthtreasury.org Thu Aug 11 22:43:22 2011 From: mokurai at earthtreasury.org (mokurai at earthtreasury.org) Date: Thu, 11 Aug 2011 22:43:22 -0400 Subject: [Edu-sig] [ANNC] pynguin-0.11 python turtle graphics application In-Reply-To: References: Message-ID: <9ff5475b55bcbc63b6b25e58a713bffe.squirrel@emailmg.ipage.com> The purely graphical Python version of turtle Graphics is Turtle Art/Turtle Blocks in the Sugar education software. http://activities.sugarlabs.org/en-US/sugar/addon/4027 You are welcome to adapt the tutorials at http:wiki.sugarlabs.org/go/Activities/TurtleArt/Tutorials to Pynguin or any other version of Turtle Art. On Wed, August 10, 2011 10:39 pm, Lee Harr wrote: > > Pynguin is a python-based turtle graphics application. > ??? It combines an editor, interactive interpreter, and > ??? graphics display area. > > It is meant to be an easy environment for introducing > ??? some programming concepts to beginning programmers. > > > http://pynguin.googlecode.com/ > > > This release continues to expand basic functionality and > ??? explores more user-friendly options in the interface. > > > Pynguin is tested with Python 2.7.1 and PyQt 4.8.3 and > ??? will use Pygments syntax highlighting if available. > > Pynguin is released under GPLv3. > > > Changes in pynguin-0.11: > ??? Session > ??????? - all settings now moved in to menus and settings dialogs > > ??? Pynguin API > ??????? - added .label() method to have a label attached to a pynguin > ??????????? - also accessible as .name attribute > ??????? - added .speed() method to change speed from user code > ??????? - viewcoords() now returns integers by default > ??????????? - pass floats=True to get the float values instead > ??????? - added .track() and .notrack() methods for user code > > ??? Canvas > ??????? - added support for custom avatars > ??????????? - both svg and bitmap images supported > ??????? - fixed motion when drawing slow circles with pen up > ??????? - don't draw circles when pen is up and speed is instant > ??????? - expand canvas when resizing window > > ??? Integrated Editor > ??????? - added "Test / Run all" button > ??????? - improved handling of external .py files > > ??? Integrated Console > ??????? - now gives correct call syntax when using test/run on classes > > ??? Examples > ??????? - make examples use new viewcoords() API > ??????? - fixed multi.pyn scatter example > ??????? - make multi.pyn follow examples work with existing pynguins > ??????? - demonstrate labels in multi.pyn follow example > ??????? - fix penup() in oo.pyn ZZ example > ??????? - add centered circle in oo.pyn ZZ example > > ??? General > ??????? - fixed examples getting gzipped in .deb distribution file > ??????? - added a way to dump contents of .pyn from command line > > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://wiki.sugarlabs.org/go/Replacing_Textbooks From nobody at nowhere.com Fri Aug 12 00:11:40 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Aug 2011 05:11:40 +0100 Subject: Processing a large string References: Message-ID: On Thu, 11 Aug 2011 19:03:36 -0700, goldtech wrote: > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? Use the .find() or .index() methods to find the next occurrence of a character. Building a large string by concatenation is inefficient, as each append will copy the original string. If you must have the result as a single string, using cStringIO would be preferable. But you'd be better off if you can work with a list of strings. From usenet-nospam at seebs.net Fri Aug 12 02:34:00 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 06:34:00 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: Before I get to the rest of this: Thinking it through, I've been unreasonable and grumpy here, and I'm trying to figure this out a bit more. A general observation: There's no real data here, so far as I can tell. There is no pair of languages which are exactly identical except for whether they use whitespace or some kind of brace/bracket/thing to indicate blocks, such that we can compare results between them. Humans are *notoriously* unreliable at evaluating the ease with which they do things, how long it takes them, how many mistakes they're making, and so on... So really, this is probably in large part a matter of taste or preference. On 2011-08-11, Ethan Furman wrote: > The times that whitespace indentation has bitten me, it was still not > difficult to fix -- I just had to look and see which line(s) > should/should not be where they were. I've been thinking about this, and I just plain can't understand how this could, in general, be done. Given a bunch of lines of code with no indication of where the blocks were supposed to be, I can't figure how this could be "fixed" in a way that is not-difficult, at least in general. > Not so. If the braces do not match /intent/ (which is the problem I > care most about) then it cannot be fixed by machine. Question for y'all: Has anyone here ever ACTUALLY encountered a case where braces -- not indentation -- did not match intent in a C-like language? I'm talking only about cases where braces are *actually present*. I haven't. Now, I've only been using C for maybe 20-25 years, but in all that time, I have never, ever, not *once*, seen braces not match intent. I've seen indentation errors galore. I've seen nutjobs writing "}}}" on a line all by itself. I've seen people forget to add braces and do stuff like: else a(); b(); ... but I've never, ever, seen braces not match intent. It just hasn't ever happened in code I've seen. >> people who'd picked Python for some stuff I have to work for, point out the >> hostility of the Python community to newcomers whose workflows don't happen >> to have been preemptively built entirely around Python's design decisions, >> and suggest that maybe we use another language. Heck, since I've been >> encouraged so much to do so, I think I will. > Your choice, obviously -- seems a shame to me, though, to give up on > Python because of one or two ouchy areas on c.l.py. By and large it's a > very helpful and courteous community. I was thinking about this more, and I think the issue that's historically bugged me is this: Most of the people I know and talk to about programming languages regard preferences as a matter of personal taste. I've seen people say that they prefer the significant-indentation thing, and I've seen people say they dislike it. The Python community, as a whole, seems particularly dogmatic about the indentation thing. And coming here as someone who doesn't much like it, and has been bitten by it a few times... Imagine that I were taking care of a cat for the first time, and I came to a cat-owners newsgroup, and found the following: 1. Nearly everyone there hated dogs, utterly. 2. The people who hated dogs were snide and insulting about people who didn't hate dogs. ... oookay, then. So I post my question, about a cat peeing on a bed, and I get the following responses: 1. What kind of idiot are you to continue using a broken non-waterproof matress? You should be using a solid vinyl cover over your mattress to prevent it from geting cat pee. 2. Once you've had a cat for a while you'll find that overall cat pee is superior to a dry mattress. ... At this point, I'm not exactly going to feel like a welcome member of the community. :) Now, that analogy is a little extreme, perhaps, but... Programmers get attached to their editors. And having a bunch of people insist that it's crazy of me to use an editor which has worked perfectly for me in the other ten programming languages I use, with settings that are not merely tolerable but *mandatory* for at least one of them, is... well, it doesn't create the impression that people who don't happen to already have fallen in love with an editor that coexists well with the whitespace thing are welcome. And part of this really is personal taste. I *LIKE* having a matching outdent for everything. I like to look at code and see blah blah blah blah blah because then I know it's balanced. If one of them is missing, *something is wrong*. And I have to keep that instinct to stay functional in most of the other languages I know. I don't have the option of ceasing to use C, but if I used C and didn't watch for missing close-braces, I'd be pretty badly hosed. So I have this strong incentive to prefer an explicit thing that I can see. And in any event, I *do* prefer it. In other language communities, when I find things about the language troublesome, I usually find people offering suggestions for ways to improve things, or workarounds, or acknowledging that, yes, that can be annoying. But for some reason, in this one, that's apparently against a local taboo. So instead of acknowledging that it is conceivably possible for people to prefer different things, people say things like "oh, once you've done it a bit you'll realize how much better it is and then you'll love it". Condescending, smug, and, at least so far, *totally untrue* for me. I am also weirded out by the claim that a Python which used braces would no longer be Python in any way, shape, or form. If you were to make a C derivative which used indentation instead of braces (this should be trivial to do with a preprocessor), I can't imagine C programmers claiming it's "not C". Of course it's C; it has the C type system, the C operators, the C promotion rules, C linkage and scope and so on... That's C. It's just a C variant which tweaks the punctuation. If Python with braces wouldn't be Python at all, why on earth does the language even exist? If all you want is indentation-which-matters, it's super easy to write a preprocessor for ANY language to do that, and you could have every last positive feature, benefit, or valuable trait of Python by doing that to any other language. Unless, of course, there are *other* things that are significant about Python. In which case, a language which preserved all of those, but used braces, would still be a kind of Python after all. Long story short: I think the dismissiveness and hostility I've seen from people in the Python community towards people who, for *whatever* reason, find the indentation-flow-control thing annoying, is not really helping the Python community win converts. All the people yelling at me and insulting my choice of editors, and telling me I should control every mail server between me and anyone who will ever send me code, have done nothing at all to make me feel like this is a language community I'd like. Meanwhile, the Python users I've talked to elsewhere who have funny indentation war stories but say that over time they've gotten used to it and they like how the code looks have made it sound like the language might be sorta fun. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 03:09:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 08:09:03 +0100 Subject: allow line break at operators In-Reply-To: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 2:40 AM, Steven D'Aprano wrote: > Please be careful about conflating significant indentation with significant > whitespace. Many languages have significant whitespace: > > foo bar > > is rarely the same thing as > > foobar > > but is the same as > > foo ? ? ? ? ? bar > > Python is no different. > Of course. But most languages derived from C have a single lexer token "whitespace". That one token is significant, but these are all the same: foo bar foo bar foo bar foo/* this one wasn't originally the same*/bar Python handles differently source files that differ only in whitespace. It's not only indentation; newlines are whitespace too, and they're significant. In C-derived languages, it's only presence-or-absence. ChrisA From przemolicc at poczta.fm Fri Aug 12 03:10:42 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Fri, 12 Aug 2011 09:10:42 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110812071041.GA6027@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:38:32PM -0700, SigmundV wrote: > When I saw the headline I thought "oh no, not string concatenation > again... we have had scores of these thread before...", but this is a > rather interesting problem. The OP says he's not a database > developer, but why is he then fiddling with internal database > operations? Wouldn't it be better to go back to the database > developers and have them look into parallel processing. I'm sure that > Oracle databases can do parallel processing by now... :-) Good question but I try to explain what motivates me to do it. First reason (I think the most important :-) ) is that I want to learn something new - I am new to python (I am unix/storage sysadmin but with programming background so python was a natural choice for more complicated sysadmin tasks). Another reason is that our server (and I am responsible for it) has many, many but slow cores (as I had written before). It means that parallelization of operations is obvious - the developer is not keen to spent much time on it (she is busy) - and for me this is something new (among some boring daily tasks ... ;-) ) and fresh :-) Another intention is to get some more knowledge about parallelization: how to divide some task into subtasks, what is the most optimal way to do it, etc And the last reason is that I love performance tuning :-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zmyslowa bielizna? U nas ja znajdziesz! http://linkint.pl/f29fe From rosuav at gmail.com Fri Aug 12 03:20:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 08:20:04 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 7:34 AM, Seebs wrote: > If Python with braces wouldn't be Python at all, why on earth does the > language even exist? Every language has its philosophy. Python, as conceived by Guido van Rossum, is a language which (guys, correct me where I'm wrong please!): * Eschews unnecessary syntactic salt * Has "batteries included" * Has a clean and readable syntax To achieve this, Python: * Uses indentation and other whitespace as structural elements (rather than semicolons, braces, etc) * Has a large standard library and an enormous PyPI collection * Uses keywords (and, or, not, if/else) rather than symbols (&, |, !, ?:) for common tasks Etcetera. These are the philosophical decisions made by GvR and the Python community, and these define Python's syntax. If you go against these, you could make something that compiles down to Python's byte code; in fact, I'd say you could make something that produces a .pyc file and then hands it to the regular Python interpreter for execution. Is it Python? No, no more than NetREXX is Java just because it can make a .class file. It's a different language. Pike is very similar to Python in underlying structure. You can pass lists and dictionaries (called arrays and mappings) around as first-class objects, you can reference objects in multiple places, you can work with huge integers comfortably. But they're different in philosophy. Pike's purpose is primarily zero-downtime servers; I can (and do on a daily basis) update parts of the code of a running program, without disconnecting clients. Python doesn't do this, and to make Python do this would violate a lot of its simplicities and underlying referencings. It can be done without modifying the interpreter, but it's never been designed in. If you want that feature, you go to Pike; if you want Python's syntax, you go to Python. I hope I make myself clear, Josephine? ChrisA From paal.nilsen at gmail.com Fri Aug 12 03:21:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Fri, 12 Aug 2011 00:21:23 -0700 (PDT) Subject: generate and send mail with python: tutorial In-Reply-To: References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Friday, August 12, 2011 8:51:33 AM UTC+2, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > Is that really such a difficult task? > > Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > Wulfraed Dennis Lee Bieber AF6VN > wlf... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Nice story bro... From paal.nilsen at gmail.com Fri Aug 12 03:21:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Fri, 12 Aug 2011 00:21:23 -0700 (PDT) Subject: generate and send mail with python: tutorial In-Reply-To: References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Friday, August 12, 2011 8:51:33 AM UTC+2, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > Is that really such a difficult task? > > Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > Wulfraed Dennis Lee Bieber AF6VN > wlf... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Nice story bro... From przemolicc at poczta.fm Fri Aug 12 03:50:29 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Fri, 12 Aug 2011 09:50:29 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110812075029.GB6027@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 2:46 PM, wrote: > > This is the way I am going to use. > > But what is the best data type to hold so many rows and then operate on them ? > > > > List of strings. [...] Let's assume I have the whole list in the memory: Can I use this list in the following way ? subprocess_1 - run on list between 1 and 10000 subprocess_2 - run on list between 10001 and 20000 subprocess_3 - run on list between 20001 and 30000 etc ... Can I use sort of indexing on this list ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From __peter__ at web.de Fri Aug 12 04:39:38 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2011 10:39:38 +0200 Subject: Processing a large string References: Message-ID: goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? You can read the file in chunks: from functools import partial def read_chunks(instream, chunksize=None): if chunksize is None: chunksize = 2**20 return iter(partial(instream.read, chunksize), "") def split_file(instream, delimiter, chunksize=None): leftover = "" chunk = None for chunk in read_chunks(instream): chunk = leftover + chunk parts = chunk.split(delimiter) leftover = parts.pop() for part in parts: yield part if leftover or chunk is None or chunk.endswith(delimiter): yield leftover I hope I got the corner cases right. PS: This has come up before, but I couldn't find the relevant threads... From ben+python at benfinney.id.au Fri Aug 12 04:59:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 18:59:41 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: <87ipq3gg3m.fsf@benfinney.id.au> Seebs writes: > On 2011-08-11, Ben Finney wrote: > > You're welcome to attempt to demonstrate the superiority of some > > other Python-with-braces, but it will (a) be un-Pythonic, and (b) be > > unlikely to gain the efforts of people who don't think what you're > > addressing is a problem. > > I am pretty sure Python is a pretty nice language. However, the > indentation thing has screwed me a few times. Furthermore, I know > people who like Python a great deal and acknowledge, without much > difficulty, that the indentation thing has caused problems or > incompatibilities for them. Yes. It's caused problems for me too, so I'm not going to deny that. This is different from saying ?indentation as block structure? is a problem; that statement is what I disagree with, and what I think most respondents who disagree with you are objecting to. > So when I see people deny that it is at all a problem, or that there > are any possible shortcomings to it, I infer that they have some > compelling reason to deny the existence of a thing which is reliably > and easily observed. I don't see anyone making the denials you're referring to there. If I did, you would have my support in considering those denials mistaken. Likewise, ?end of line as end of statement? has caused me and many others problems. I'd go so far as to say that any Python programmer for whom that's not true has not done any significant Python programming. That doesn't make ?end of line as end of statement? a problem. If a language feature is beneficial in far greater proportion to the inconveniences of that feature, I'd say that feature *is not a problem* for users of that language. In Python, I maintain that's the case for ?end of line as end of statement?, and for ?indentation as block structure?. -- \ ?A computer once beat me at chess, but it was no match for me | `\ at kick boxing.? ?Emo Philips | _o__) | Ben Finney From rosuav at gmail.com Fri Aug 12 05:20:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 10:20:41 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811143923.GG4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 3:39 PM, wrote: > On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >> List of strings. Take it straight from your Oracle interface and work >> with it directly. > > Can I use this list in the following way ? > subprocess_1 - run on list between 1 and 10000 > subprocess_2 - run on list between 10001 and 20000 > subprocess_3 - run on list between 20001 and 30000 > etc > ... Yep! You use list slicing. Working with smaller numbers for an example: >>> ltrs=['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'] >>> ltrs[:10] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] >>> ltrs[10:20] ['k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'] >>> ltrs[20:] ['u', 'v', 'w', 'x', 'y', 'z'] (I actually created that list as "list(string.ascii_lowercase)" for what that's worth.) Slice operations are quite efficient. Chris Angelico From stefan_ml at behnel.de Fri Aug 12 05:25:06 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Aug 2011 11:25:06 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811143923.GG4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: przemolicc at poczta.fm, 11.08.2011 16:39: > On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >> On Thu, Aug 11, 2011 at 2:46 PM, wrote: >>> This is the way I am going to use. >>> But what is the best data type to hold so many rows and then operate on them ? >>> >> >> List of strings. Take it straight from your Oracle interface and work >> with it directly. > > Can I use this list in the following way ? > subprocess_1 - run on list between 1 and 10000 > subprocess_2 - run on list between 10001 and 20000 > subprocess_3 - run on list between 20001 and 30000 > etc > ... Sure. Just read the data as it comes in from the database and fill up a chunk, then hand that on to a process. You can also distribute it in smaller packets, just check what size gives the best throughput. Still, I'd give each work parcel a number and then reorder the results while collecting them, that allows you to vary the chunk size and the process size independently, without having to wait for a process that happens to take longer. Stefan From ben+python at benfinney.id.au Fri Aug 12 06:39:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 20:39:44 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d3gahq1b.fsf@benfinney.id.au> Seebs writes: > Question for y'all: > > Has anyone here ever ACTUALLY encountered a case where braces -- not > indentation -- did not match intent in a C-like language? I'm talking > only about cases where braces are *actually present*. What a strange limitation. Why are you not comparing apples with apples? The correct comparison would be ?getting the braces to match the intended structure? compared with ?getting the indentation to match the intended structure?. > The Python community, as a whole, seems particularly dogmatic about > the indentation thing. And coming here as someone who doesn't much > like it, and has been bitten by it a few times... As you say, the data is thin on the ground for this issue. Would you accept the charge that you're being just as dogmatic about the superiority of braces-as-block-syntax? If so, good for you; we're all equally dogmatic by your definition. Let's move on. If not, what makes your position less dogmatic than ours? -- \ ?We jealously reserve the right to be mistaken in our view of | `\ what exists, given that theories often change under pressure | _o__) from further investigation.? ?Thomas W. Clark, 2009 | Ben Finney From steve+comp.lang.python at pearwood.info Fri Aug 12 06:40:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 20:40:37 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> Message-ID: <4e450326$0$29970$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Likewise, ?end of line as end of statement? has caused me and many > others problems. I don't understand this. Can you give an example? Do you mean, "Sometimes I want more code in a single statement than will comfortably fit in a single line"? -- Steven From ayaskanta.swain at altair.com Fri Aug 12 06:41:04 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 12 Aug 2011 16:11:04 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> Hi, I have a requirement where I need to check the write permissions on a directory on Windows platform. I don't want to use the python function os.access( ), since it does not work correctly on Windows. It is giving incorrect results to me. Another option of actually creating a temporary file inside the folder & then deleting it to check whether the user has write permissions or not is causing performance issues. It is slowing down our application when we have to check the permissions on hundreds of folders. It also changes the last access time stamp of the folder. So is there any other way such as using Win32API or Win32 security modules to check the permissions? Please suggest. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayaskanta.swain at altair.com Fri Aug 12 06:43:48 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 12 Aug 2011 16:13:48 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606BC8B2C@blrex.prog.altair.com> Some additional information - I am using python 2.5.1 version & it cannot be upgraded now to a higher version. Thanks Ayaskant- ________________________________ From: Ayaskanta Swain Sent: Friday, August 12, 2011 4:11 PM To: 'python-list at python.org' Subject: How to Check Write Access of a Folder on Windows Hi, I have a requirement where I need to check the write permissions on a directory on Windows platform. I don't want to use the python function os.access( ), since it does not work correctly on Windows. It is giving incorrect results to me. Another option of actually creating a temporary file inside the folder & then deleting it to check whether the user has write permissions or not is causing performance issues. It is slowing down our application when we have to check the permissions on hundreds of folders. It also changes the last access time stamp of the folder. So is there any other way such as using Win32API or Win32 security modules to check the permissions? Please suggest. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Aug 12 06:52:44 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Aug 2011 11:52:44 +0100 Subject: How to Check Write Access of a Folder on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> Message-ID: <4E4505FC.1030405@timgolden.me.uk> On 12/08/2011 11:41, Ayaskanta Swain wrote: > Hi, > > I have a requirement where I need to check the write permissions on a > directory on Windows platform. I don?t want to use the python function > os.access( ), since it does not work correctly on Windows. It is giving > incorrect results to me. > > Another option of actually creating a temporary file inside the folder & > then deleting it to check whether the user has write permissions or not > is causing performance issues. It is slowing down our application when > we have to check the permissions on hundreds of folders. It also changes > the last access time stamp of the folder. > > So is there any other way such as using Win32API or Win32 security > modules to check the permissions? In general, yes. Depends how finnicky you want to get. I take it from your question that you're pretty much unfamiliar with the Windows Security APIs and structures? There's a quite a bit of information around on the subject, but have a look at this first which is at least Python-oriented: http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The trouble is that do what you want, you need to use the AccessCheck API (or emulate its functionality) and this isn't currently exposed by the pywin32 modules. You could run it up yourself with ctypes or by creating a quick extension for the purpose. Alternatively, as I say, you could emulate by scanning the ACLs/ACEs and trying to apply some suitable logic. Frankly, I'd have thought this was harder work :) Hope that helps TJG From rdmoores at gmail.com Fri Aug 12 06:52:47 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Fri, 12 Aug 2011 03:52:47 -0700 Subject: Puzzled about the output of my demo of a proof of The Euler Series Message-ID: For the first time in my 7 years of using Gmail, I accidentally deleted my original post and it's one reply by casevh. I found both in the list archive, and with this post both quote casevh's reply and answer it. Sorry about my screw up. On Aug 10, 4:57 pm, "Richard D. Moores" wrote: > I saw an interesting proof of the limit of The Euler Series on > math.stackexchange.com at > . > Scroll down to Hans Lundmark's post. > > I thought I'd try to see this "pinching down" on the limit of pi**2/6. > See my attempt, and output for n = 150 at > . What puzzles me is that > upper_bound_partial_sum (lines 39 and 60) is always smaller than the > limit. It should be greater than the limit, right? If not, no pinching > between upper_bound_partial_sum and lower_bound_partial_sum. > > I've checked and double-checked the computation, but can't figure out > what's wrong. > > Thanks, > > Dick Moores The math is correct. The proof only asserts that sum(1/k^2) is between the upper and lower partial sums. The upper and lower partial sums both converge to pi^2/6 from below and since the sum(1/k^2) is between the two partial sums, it must also converge to pi^2/6. Try calculating sum(1/k^2) for k in range(1, 2**n) and compare that with the upper and lower sums. I verified it with several values up to n=20. casevh ===================Dick Moores' reply=================== Thank you! I had missed the 2^n -1 on the top of the sigma (see my image of the inequality expression at . So I rewrote the script and now it does what I intended -- show the pinching down on sum(1/k^2) by the upper sums and the lower sums for successively larger n. See the new script at . Dick From gandalf at shopzeus.com Fri Aug 12 07:14:04 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Aug 2011 13:14:04 +0200 Subject: problem with GTK language In-Reply-To: References: Message-ID: <4E450AFC.1020408@shopzeus.com> On 2011-08-10 16:22, Peter Irbizon wrote: > Hello, > I have strange problem with gtk language in pygtk. When I run .py file > it shows all gtk labels in my default windows language (slovak). But > when I compile it with py2exe and run exe file all labels are in > english. Why this happens? How can I define on program startup which > language to use? I would like to choose between english and slovak. I > tryed to set locals in my application but no luck. What am I doing wrong? Do you have this in your main program? import locale locale.setlocale(locale.LC_ALL, '') From ben+python at benfinney.id.au Fri Aug 12 07:16:55 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 21:16:55 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> <4e450326$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vqyhobc.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > Likewise, ?end of line as end of statement? has caused me and many > > others problems. > > I don't understand this. Can you give an example? Many times I have split a line expecting that some bracketing syntax will cause the statement to continue across the split. I've been wrong, and the code either gave a SyntaxError or, worse, did something functional but unintended. That is a problem only because end-of-line (outside some bracketing syntax) ends a statement. My point is that I consider that problem to be at least on par in the severity of the problems caused by indentation-as-block-syntax. That is, very small compared with the great benefit of the clean and readable syntax that results. -- \ ?Not to be absolutely certain is, I think, one of the essential | `\ things in rationality.? ?Bertrand Russell | _o__) | Ben Finney From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Fri Aug 12 08:54:14 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Fri, 12 Aug 2011 14:54:14 +0200 Subject: allow line break at operators In-Reply-To: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 12.08.2011 03:40 schrieb Steven D'Aprano: > The only exception I can think of is *very* early Fortran, and that rightly > is considered a mistake. ATARI 800XL. Built-in BASIC, acknowledging every command with "READY". Going over it with the cursor results in "ERROR- 6", meaning "no READ without DATA"... same as "READ Y". Thomas, it was a long time ago... From neilc at norwich.edu Fri Aug 12 08:57:22 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Aug 2011 12:57:22 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9akm9iFgfcU1@mid.individual.net> On 2011-08-12, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Incidentally, I will happily argue the >> benefits of Python's significant whitespace, even though I disagree >> with it; there are quite a few. > > Please be careful about conflating significant indentation with significant > whitespace. Many languages have significant whitespace: > > foo bar > > is rarely the same thing as > > foobar > > but is the same as > > foo bar > > Python is no different. > > The only exception I can think of is *very* early Fortran, and > that rightly is considered a mistake. Early versions of Basic were like this, too. It was common to compress large C64 Basic programs by removing the spaces and substituting the command synonyms. -- Neil Cerutti From aspineux at gmail.com Fri Aug 12 08:59:40 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 05:59:40 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Aug 12, 8:51?am, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > ? ? ? ? Is that really such a difficult task? Yes it's difficult to make an _universal_ mail parser, able to handle mails from different MUA, using different charsets. Some emails that break RFC's requires at least some background to know which rules can be missed by some MUA ! Handle mail from a unique source or similar sources is easy. Using try and error method is fine for this kind of job, you don't even need to care if the email you're parsing match the RFC's or not. My "parser" functions have been tested over 20.000 mails from all around the world using some human and automated verifications ! Generating emails is not easy, when mixing internationalized addresses, subject and content. Integrating text, html, attachment and embedded images in one single email looks to me difficult enough to require some explanations. At least read carefully all my articles to get an idea about the difficulty, this is what I try to explain. Regards. > > ? ? ? ? Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from ?message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From k.sahithi2862 at gmail.com Fri Aug 12 09:31:57 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 12 Aug 2011 06:31:57 -0700 (PDT) Subject: ADULT FAVORATE BLOG Message-ID: <86838230-02ce-46b0-a3ee-f44742997b43@g39g2000pro.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From goldtech at worldpost.com Fri Aug 12 09:36:52 2011 From: goldtech at worldpost.com (goldtech) Date: Fri, 12 Aug 2011 06:36:52 -0700 (PDT) Subject: Processing a large string References: Message-ID: Thanks for all this info. From steve+comp.lang.python at pearwood.info Fri Aug 12 09:38:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 23:38:30 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> aspineux wrote: > Hi I have written a tutorial about how to generate and send emails > with python. [...] Thank you, that is an extremely detailed tutorial. -- Steven From 1248283536 at qq.com Fri Aug 12 10:18:52 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 12 Aug 2011 22:18:52 +0800 Subject: fork problem Message-ID: in the book ,A call to wait() suspends execution (i.e., waits) until a child process (any child process) has completed, terminating either normally or via a signal. wait() will then reap the child, releasing any resources. If the child has already completed, then wait() just performs the reaping procedure. here is my code import os print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() if ret == 0: os.system('ls') else: os.wait() print "i am runing,who am i? ",os.getpid() according to the word,the output may be: i am parent 8014 i am here 8014 i am here 8015 "omitted my file" i am runing,who am i? 8014 because 8015 is terminated by os.wait(). in fact the output is: i am parent 8014 i am here 8014 i am here 8015 "omitted my file" i am runing,who am i? 8015 i am runing,who am i? 8014 i want to know why ?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Fri Aug 12 10:30:57 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 07:30:57 -0700 (PDT) Subject: fork problem References: Message-ID: <9330c4f3-ae9a-4081-bc54-1460970f8d3f@h14g2000yqd.googlegroups.com> On Aug 12, 4:18 pm, "????" <1248283... at qq.com> wrote: > in the book ,A call to wait() suspends execution (i.e., waits) until a child process (any child process) has completed, terminating either normally or via a signal. wait() will then reap the child, releasing any resources. If the child has already completed, then wait() just performs the reaping procedure. > here is my code > import os > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > if ret == 0: > os.system('ls') > else: > os.wait() > print "i am runing,who am i? ",os.getpid() > > according to the word,the output may be: > i am parent 8014 > i am here 8014 > i am here 8015 > "omitted my file" > i am runing,who am i? 8014 > because 8015 is terminated by os.wait(). > > in fact the output is: > > i am parent 8014 > i am here 8014 > i am here 8015 > "omitted my file" > i am runing,who am i? 8015 > i am runing,who am i? 8014 > > i want to know why ?? To get what you want, use os.exec() instead of os.system() or add a os.exit() just after os.system() Regards From __peter__ at web.de Fri Aug 12 10:48:10 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2011 16:48:10 +0200 Subject: Processing a large string References: Message-ID: Peter Otten wrote: > goldtech wrote: >> Say I have a very big string with a pattern like: >> >> akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... >> >> I want to split the sting into separate parts on the "3" and process >> each part separately. I might run into memory limitations if I use >> "split" and get a big array(?) I wondered if there's a way I could >> read (stream?) the string from start to finish and read what's >> delimited by the "3" into a variable, process the smaller string >> variable then append/build a new string with the processed data? > PS: This has come up before, but I couldn't find the relevant threads... Alex Martelli a looong time ago: > from __future__ import generators > > def splitby(fileobj, splitter, bufsize=8192): > buf = '' > > while True: > try: > item, buf = buf.split(splitter, 1) > except ValueError: > more = fileobj.read(bufsize) > if not more: break > buf += more > else: > yield item + splitter > > if buf: > yield buf http://mail.python.org/pipermail/python-list/2002-September/770673.html From rantingrick at gmail.com Fri Aug 12 11:26:45 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 08:26:45 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> On Aug 12, 1:34?am, Seebs wrote: > > And part of this really is personal taste. ?I *LIKE* having a matching outdent > for everything. ?I like to look at code and see > ? ? ? ? blah > ? ? ? ? ? ? ? ? blah > ? ? ? ? ? ? ? ? ? ? ? ? blah > ? ? ? ? ? ? ? ? blah > ? ? ? ? blah > > because then I know it's balanced. ?If one of them is missing, *something is > wrong*. What is with you guys and this need to have your hand held to read code. Out-dents are noise and nothing more. When you're driving on a two lane highway that becomes one lane, would you forget to merge (OUTDENT) simply because the "merge sign" was missing? If you did then i would say you need to keep your eyes on the road (CODE) instead of looking for signs on the side of the road. In other words; you need to start acting like an intelligent agent instead of a zombie. > In other language communities, when I find things about the language > troublesome, I usually find people offering suggestions for ways to improve > things, or workarounds, or acknowledging that, yes, that can be annoying. > But for some reason, in this one, that's apparently against a local taboo. > So instead of acknowledging that it is conceivably possible for people to > prefer different things, people say things like "oh, once you've done it a > bit you'll realize how much better it is and then you'll love it". > Condescending, smug, and, at least so far, *totally untrue* for me. Well for indention there is no alternatives. There is either indent/ dendent, or suffer the syntax error. > I am also weirded out by the claim that a Python which used braces would no > longer be Python in any way, shape, or form. ?If you were to make a C > derivative which used indentation instead of braces (this should be trivial > to do with a preprocessor), I can't imagine C programmers claiming it's > "not C". ?Of course it's C; it has the C type system, the C operators, the > C promotion rules, C linkage and scope and so on... That's C. ?It's just a C > variant which tweaks the punctuation. Hmm, Python's exclusive use of indent/dedent for denoting blocks is rather unique in a world of braces (barring a few other less known languages). Removing that feature and replacing it with braces (or tags or whatever) would change the language significantly! Likewise allowing a directive like "use braces = True" would also be detrimental to our code bases. A language must always strive to remove ambiguities and multiplicity. Having more than one way to mark blocks is insanity. You never want to induce more overhead than necessary because such things are detrimental to work flow and language evolution. > If Python with braces wouldn't be Python at all, why on earth does the > language even exist? ?If all you want is indentation-which-matters, it's > super easy to write a preprocessor for ANY language to do that, and you could > have every last positive feature, benefit, or valuable trait of Python by > doing that to any other language. This statement leads me to believe you have very little experience with the Python language. Python has many wonderful attributes and design philosophies. Significant indentation is just ONE of many. > Unless, of course, there are *other* things that are significant > about Python. ?In which case, a language which preserved all of > those, but used braces, would still be a kind of Python after all. I don't understand this need for braces. You yearn so badly to be dominated by them. Is this a psychological disorder, a Helsinki syndrome that you cannot shake? There is life after braces my friend, and the future is bright! > Long story short: ?I think the dismissiveness and hostility I've seen from > people in the Python community towards people who, for *whatever* reason, > find the indentation-flow-control thing annoying, is not really helping the > Python community win converts. ? As much as we love people getting on board we are not about to sacrifice our strong beliefs in clean source code just so you and other hardwired C programmers will come along. Indentation is at the very heart of Pythons philosophy. A philosophy that breaks free from decades old language design build on the detrimental ideals of multi- stylism. Good languages do not care about your singularly instinctual emotion needs for bondage, no, they care about productivity and readability from a community perspective. PS: I will admit that a few of our community members can be rather acerbic at times. From paulo at matos-sorge.com Fri Aug 12 11:30:29 2011 From: paulo at matos-sorge.com (Paulo J. Matos) Date: Fri, 12 Aug 2011 16:30:29 +0100 Subject: Multiple process output Message-ID: Hi all, I am have a function which executes a command in the shell. The stdout and stderr of the command should be multipled to two strings for stdout and stderr respectively and stdout and stderr of the current process respectively. I have done like this: from subprocess import Popen, PIPE, STDOUT from select import select from os import read from sys import stdout, stderr def communicate(p): """ Multiplex the subprocess stdout/stderr to the process stdout/stderr and a tuple of strings """ output = [] errput = [] while True: (ready_to_read, _, _) = select([p.stdout, p.stderr], [], []) dataout = "" dataerr = "" if p.stdout in ready_to_read: dataout = read(p.stdout.fileno(), 1024) stdout.write(dataout) output.append(dataout) if p.stderr in ready_to_read: dataerr = read(p.stderr.fileno(), 1024) stderr.write(dataerr) errput.append(dataerr) if dataout == "" and dataerr == "": p.stdout.close() p.stderr.close() break return (''.join(output), ''.join(errput)) def exe(s, cwd=None, output_command=True): if output_command: print s p = Popen(s, stdin=None, stdout=PIPE, stderr=PIPE, shell=True, cwd=cwd) (output, err) = communicate(p) rc = p.wait() return (rc, output, err) Unfortunately, the program is _sometimes_ but not always getting stuck on the call to select. I don't really understand when this happens. Any suggestions to the above code so select doesn't block the function? Cheers, -- PMatos From rantingrick at gmail.com Fri Aug 12 11:33:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 08:33:07 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> On Aug 12, 2:20?am, Chris Angelico wrote: > Pike is very [snip] > Pike's purpose is [snip] > you go to Pike[snip] > > I hope I make myself clear, Josephine? The only thing that is clear to me is that you have a hidden agenda to incorporate pike's functionality into Python -- and this is not the first time! Chris, this incessant babbling about "pike this" and "pike that" is starting to get on my nerves. Why don't you go over to comp.lang.pike and gush to them about how wonderful the language is. PS: Although i give you brownie point for sucking up to GvR and the community at large before hinting about "Esox lucius" greatness. Nice! From jackhatterly at hotmail.com Fri Aug 12 11:55:33 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 15:55:33 +0000 Subject: Problem reading HTTP_COOKIE Message-ID: Hi; I'm trying to get cookies to work and I've traced my problem down to this reduced script: #! /usr/bin/python import string import os import datetime, Cookie, random import time import os def parse_cookie(): print 'Content-Type: text/html\n' print os.environ.get('HTTP_COOKIE') print '' print '' if __name__ == "__main__": parse_cookie() It prints "None". However, when I look in my browser's cookie jar, there is a cookie "www.my_site.com" where my_site is the site from which I am surfing the above script. What gives? TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From tfb at tfeb.org Fri Aug 12 11:58:50 2011 From: tfb at tfeb.org (Tim Bradshaw) Date: Fri, 12 Aug 2011 16:58:50 +0100 Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> Message-ID: On 2011-08-02 15:41:06 +0100, ccc31807 said: > > Most of these are tech companies. Tech companies are very important, > but so are other kinds of companies. What do manufacturing companies > use, like Ford and Toyota, energy companies like BP and Exxon, > pharmaceutical companies, consumer product companies, and so on? What > about the big retailers, Sears, WalMart, Target, etc.? A more important metric is how critical the web presence is to the company. For Amazon, say, it's pretty critical, so what they do is likely to be interesting: if their site is broken they're not making any money. For Toyota, say, well, an outage would probably be embarrassing, but it's not anything like as critical to them. Unfortunatly I suspect that with web stuff as with other stuff, the answer is that it entirely depends. I am endlessly horrified by the poor state of software that is really critical to large companies. From sigmundv at gmail.com Fri Aug 12 12:09:42 2011 From: sigmundv at gmail.com (SigmundV) Date: Fri, 12 Aug 2011 09:09:42 -0700 (PDT) Subject: String concatenation - which is the fastest way ? References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <4c2bbcd6-01a3-4a53-bd08-4a7bda5e4154@h15g2000yqa.googlegroups.com> On Aug 12, 8:10?am, przemol... at poczta.fm wrote: > Good question but I try to explain what motivates me to do it. > First reason (I think the most important :-) ) is that I want to learn > something new - I am new to python (I am unix/storage sysadmin but with programming > background so python was a natural choice for more complicated > sysadmin tasks). > Another reason is that our server (and I am responsible for it) has > many, many but slow cores (as I had written before). It means that > parallelization of operations is obvious - the developer is not keen > to spent much time on it (she is busy) - and for me this is something new > (among some boring daily tasks ... ;-) ) and fresh :-) > Another intention is to get some more knowledge about parallelization: > how to divide some task into subtasks, what is the most optimal way to do it, etc > And the last reason is that I love performance tuning :-) When you put it this way I better understand what you're after and why you do this. And I agree with all your points. Learning something new is a noble cause in itself. :) Sigmund From alec.taylor6 at gmail.com Fri Aug 12 12:26:58 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 13 Aug 2011 02:26:58 +1000 Subject: What Programing Language are the Largest Website Written In? In-Reply-To: References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> Message-ID: C++ (Wt xor CppCMS) WOOT! On Sat, Aug 13, 2011 at 1:58 AM, Tim Bradshaw wrote: > On 2011-08-02 15:41:06 +0100, ccc31807 said: > >> >> Most of these are tech companies. Tech companies are very important, >> but so are other kinds of companies. What do manufacturing companies >> use, like Ford and Toyota, energy companies like BP and Exxon, >> pharmaceutical companies, consumer product companies, and so on? What >> about the big retailers, Sears, WalMart, Target, etc.? > > A more important metric is how critical the web presence is to the company. > ?For Amazon, say, it's pretty critical, so what they do is likely to be > interesting: if their site is broken they're not making any money. ?For > Toyota, say, well, an outage would probably be embarrassing, but it's not > anything like as critical to them. > > Unfortunatly I suspect that with web stuff as with other stuff, the answer > is that it entirely depends. ?I am endlessly horrified by the poor state of > software that is really critical to large companies. > > -- > http://mail.python.org/mailman/listinfo/python-list > From usenet-nospam at seebs.net Fri Aug 12 12:33:11 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:11 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 7:34 AM, Seebs wrote: >> If Python with braces wouldn't be Python at all, why on earth does the >> language even exist? > Every language has its philosophy. Yes. > Etcetera. These are the philosophical decisions made by GvR and the > Python community, and these define Python's syntax. If you go against > these, you could make something that compiles down to Python's byte > code; in fact, I'd say you could make something that produces a .pyc > file and then hands it to the regular Python interpreter for > execution. Is it Python? No, no more than NetREXX is Java just because > it can make a .class file. It's a different language. I would argue that any pure syntactic-sugar change which can be done entirely by a naive preprocessor does not constitute a significant shift in the language itself. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Ben Finney wrote: > Seebs writes: >> I am pretty sure Python is a pretty nice language. However, the >> indentation thing has screwed me a few times. Furthermore, I know >> people who like Python a great deal and acknowledge, without much >> difficulty, that the indentation thing has caused problems or >> incompatibilities for them. > Yes. It's caused problems for me too, so I'm not going to deny that. > This is different from saying ???indentation as block structure??? is a > problem; that statement is what I disagree with, and what I think most > respondents who disagree with you are objecting to. See below; I think I agree with what I meant by it, and disagree with what you seem to interpret it as. Your interpretation makes as much sense as mine, so far as I can tell. > I don't see anyone making the denials you're referring to there. If I > did, you would have my support in considering those denials mistaken. I suspect, thinking about it more, that it's a communications problem. > Likewise, ???end of line as end of statement??? has caused me and many > others problems. I'd go so far as to say that any Python programmer for > whom that's not true has not done any significant Python programming. > That doesn't make ???end of line as end of statement??? a problem. True, although it does make it a thing which *has* at least one problem. > If a language feature is beneficial in far greater proportion to the > inconveniences of that feature, I'd say that feature *is not a problem* > for users of that language. I wouldn't. Lemme give a concrete example, from C, since that's the language I know best. There are sound technical reasons for which C lets you manipulate pointers. If you couldn't, it wouldn't be C, and you couldn't do the bulk of the stuff that makes C useful. But... Pointer manipulation leads to crashes. LOTS of crashes. I have never met a C programmer with over a day or two of experience who has not had a program crash due to some mishap involving a pointer. When people say that a language like, say, Java, is trying to solve the problems of C's pointer system, I think that's a reasonable thing to try to do. There are tradeoffs. But it would be, IMHO, silly to claim that there are no problems with pointers; there are just benefits which outweigh them *for the things the language is trying to do*. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Ben Finney wrote: > Seebs writes: >> Question for y'all: >> >> Has anyone here ever ACTUALLY encountered a case where braces -- not >> indentation -- did not match intent in a C-like language? I'm talking >> only about cases where braces are *actually present*. > What a strange limitation. Why are you not comparing apples with apples? I am trying to. I'm trying to compare C-like languages, with braces, to Python, with indentation. > The correct comparison would be ???getting the braces to match the > intended structure??? compared with ???getting the indentation to match the > intended structure???. Right. I have seen Python programs in which indentation, while it obviously matched what actually happened, did not match intent. It is (at least in principle) easier to debug because you can see that, but... I've seen people in C do stuff like: for (i = 0; i < N; ++i); a[i] = 0; This is clearly a case where indentation matches intent, but doesn't match functionality, because C allows indentation to not-match functionality; this is the famous problem Python is solving. However, I've never, ever, seen a problem like that *when people were using braces*. An apples-to-apples comparison between indentation and braces should be a comparison *to braces*, not to people who "cleverly" omit braces. (If you are looking for a debate on whether C's optional-braces are a good idea, I'm afraid you will have to look elsewhere; if it were up to me, I would totally approve a language change making them mandatory.) > As you say, the data is thin on the ground for this issue. Would you > accept the charge that you're being just as dogmatic about the > superiority of braces-as-block-syntax? I don't think so. > If not, what makes your position less dogmatic than ours? A couple of things. 1. I do assert that people who are happy with an editor and have been using it for twenty years ought to change their editor to accommodate a language which uses braces. 2. I will happily grant that braces, written legibly, cost you an extra line per block, and that this space cost can make it harder to see all the code at once. 3. I don't have a problem agreeing that there certainly appear to be people for whom the Python syntax is easier to read. I think #1 is the real point at which I think there's a dogmatism problem. Maybe editors shouldn't "helpfully" convert spaces to tabs, but that feature has been nearly entirely beneficial to me in everything else I've edited for a long time, and I don't *want* to learn a new editor just for one language. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: On 2011-08-12, rantingrick wrote: > What is with you guys and this need to have your hand held to read > code. Good question! Great to see that the helpful and welcoming community is living up to its reputation. My brain has quirks. Some people call them defects, some don't, but it really doesn't matter; there are things about which my brain is just plain unreliable and I rely moderately heavily on extra visual cues to reduce the frequency with which I get things wrong when skimming. > Out-dents are noise and nothing more. Not for me. > When you're driving on a > two lane highway that becomes one lane, would you forget to merge > (OUTDENT) simply because the "merge sign" was missing? No, because the *LANE BOUNDARIES* would move. > If you did then > i would say you need to keep your eyes on the road (CODE) instead of > looking for signs on the side of the road. In other words; you need to > start acting like an intelligent agent instead of a zombie. Interesting theory. I propose we extend it to expression processing in general. Instead of writing a = (x + y) * z let's just write a = (x + y * z It's obvious that no one would have needed to introduce parentheses here unless they wanted to bind the + more closely than the *, so the ) is just noise and not needed. > Hmm, Python's exclusive use of indent/dedent for denoting blocks is > rather unique in a world of braces (barring a few other less known > languages). Removing that feature and replacing it with braces (or > tags or whatever) would change the language significantly! It would, but unless that's the only distinctive trait of the language, I don't think it would make the language cease to be Python. > Likewise allowing a directive like "use braces = True" would also be > detrimental to our code bases. A language must always strive to remove > ambiguities and multiplicity. Having more than one way to mark blocks > is insanity. You never want to induce more overhead than necessary > because such things are detrimental to work flow and language > evolution. Agreed. > This statement leads me to believe you have very little experience > with the Python language. Python has many wonderful attributes and > design philosophies. Significant indentation is just ONE of many. It was a reductio-ad-absurdum. > I don't understand this need for braces. You yearn so badly to be > dominated by them. Is this a psychological disorder, a Helsinki > syndrome that you cannot shake? There is life after braces my friend, > and the future is bright! Man, you really love pushing them buttons, don't you? You don't understand a thing. Therefore... there is no such thing, anyone who experiences life differently from you needs to be insulted? > As much as we love people getting on board we are not about to > sacrifice our strong beliefs in clean source code just so you and > other hardwired C programmers will come along. But you will happily insult people and call them names in order to keep them from having anything to listen to? > PS: I will admit that a few of our community members can be rather > acerbic at times. Yeah. And the thing is... This can't possibly lead to convincing people of your position, so presumably the purpose is that you don't want anyone who didn't start out agreeing with you to ever come to agree with you? Why's that? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From no.email at please.post Fri Aug 12 13:02:38 2011 From: no.email at please.post (kj) Date: Fri, 12 Aug 2011 17:02:38 +0000 (UTC) Subject: Java is killing me! (AKA: Java for Pythonheads?) Message-ID: *Please* forgive me for asking a Java question in a Python forum. My only excuse for this no-no is that a Python forum is more likely than a Java one to have among its readers those who have had to deal with the same problems I'm wrestling with. Due to my job, I have to port some Python code to Java, and write tests for the ported code. (Yes, I've considered finding myself another job, but this is not an option in the immediate future.) What's giving me the hardest time is that the original Python code uses a lot of functions with optional arguments (as is natural to do in Python). As far as I can tell (admittedly I'm no Java expert, and have not programmed in it since 2001), to implement a Java method with n optional arguments, one needs at least 2**n method definitions. Even if all but one of these definitions are simple wrappers that call the one that does all the work, it's still a lot of code to wade through, for nothing. That's bad enough, but even worse is writing the unit tests for the resulting mountain of fluffCode. I find myself writing test classes whose constructors also require 2**n definitions, one for each form of the function to be tested... I ask myself, how does the journeyman Python programmer cope with such nonsense? For the sake of concreteness, consider the following run-of-the-mill Python function of 3 arguments (the first argument, xs, is expected to be either a float or a sequence of floats; the second and third arguments, an int and a float, are optional): def quant(xs, nlevels=MAXN, xlim=MAXX): if not hasattr(xs, '__iter__'): return spam((xs,), n, xlim)[0] if _bad_quant_args(xs, nlevels, xlim): raise TypeError("invalid arguments") retval = [] for x in xs: # ... # elaborate acrobatics that set y # ... retval.append(y) return retval My Java implementation of it already requires at least 8 method definitions, with signatures: short[] quant (float[], int , float) short[] quant (float[], int ) short[] quant (float[], float) short[] quant (float[] ) short quant (float , int , float) short quant (float , int ) short quant (float , float) short quant (float ) Actually, for additional reasons, too arcane to go into, I also need four more: short quant (Float , Integer, Float) short quant (Float , Integer ) short quant (Float , Float) short quant (Float ) Writing JUnit tests for these methods is literally driving me INSANE. Some advice on implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj From clp2 at rebertia.com Fri Aug 12 13:03:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Aug 2011 10:03:04 -0700 Subject: allow line break at operators In-Reply-To: <87d3gahq1b.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On Fri, Aug 12, 2011 at 3:39 AM, Ben Finney wrote: > Seebs writes: > >> Question for y'all: >> >> Has anyone here ever ACTUALLY encountered a case where braces -- not >> indentation -- did not match intent in a C-like language? ?I'm talking >> only about cases where braces are *actually present*. > > What a strange limitation. Why are you not comparing apples with apples? > > The correct comparison would be ?getting the braces to match the > intended structure? compared with ?getting the indentation to match the > intended structure?. One argument I've heard from braces fans is that sometimes they want their own structure, which does not match the actual block structure. Example: FILE* f = fopen(...); // do stuff with f // at this indent level fclose(f); // back to normal But really this is just working around other limitations in the language (i.e. lack of a with-statement equivalent). Cheers, Chris -- http://rebertia.com From nathan.alexander.rice at gmail.com Fri Aug 12 13:15:02 2011 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 12 Aug 2011 13:15:02 -0400 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: public FooClass(String requiredArgument1, Long requiredArgument2, map yourOptionalArgumentMap) { ... } From jgaynor at ncsa.uiuc.edu Fri Aug 12 13:24:27 2011 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Fri, 12 Aug 2011 12:24:27 -0500 (CDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: Message-ID: <922377184.2518.1313169867874.JavaMail.root@zimbra-1.ncsa.uiuc.edu> One Java-eque solution is to pass in an object that has the arguments and build the validity logic into that object. So you have public class LimitsAndLevels{ float[] whatever = null; float anotherOne = 0.0; // or maybe some other overloaded value public float[] getWhatever(){ isValid(); return whatever; } public boolean hasWhatever(){ isValid(); return whatever != null; } public void isValid(){ // Code to check validity // Probably throws an IllegalArgumentException if you need. // That exception extends RuntimeException, so no need to put in a throws list } } Then you pass this, e.g., public class HeavyLifter{ public int[] quant(LimitsAndLevels args){ // acrobatics. } } Hope this helps... Jeff ----- Original Message ----- From: "kj" To: python-list at python.org Sent: Friday, August 12, 2011 12:02:38 PM Subject: Java is killing me! (AKA: Java for Pythonheads?) *Please* forgive me for asking a Java question in a Python forum. My only excuse for this no-no is that a Python forum is more likely than a Java one to have among its readers those who have had to deal with the same problems I'm wrestling with. Due to my job, I have to port some Python code to Java, and write tests for the ported code. (Yes, I've considered finding myself another job, but this is not an option in the immediate future.) What's giving me the hardest time is that the original Python code uses a lot of functions with optional arguments (as is natural to do in Python). As far as I can tell (admittedly I'm no Java expert, and have not programmed in it since 2001), to implement a Java method with n optional arguments, one needs at least 2**n method definitions. Even if all but one of these definitions are simple wrappers that call the one that does all the work, it's still a lot of code to wade through, for nothing. That's bad enough, but even worse is writing the unit tests for the resulting mountain of fluffCode. I find myself writing test classes whose constructors also require 2**n definitions, one for each form of the function to be tested... I ask myself, how does the journeyman Python programmer cope with such nonsense? For the sake of concreteness, consider the following run-of-the-mill Python function of 3 arguments (the first argument, xs, is expected to be either a float or a sequence of floats; the second and third arguments, an int and a float, are optional): def quant(xs, nlevels=MAXN, xlim=MAXX): if not hasattr(xs, '__iter__'): return spam((xs,), n, xlim)[0] if _bad_quant_args(xs, nlevels, xlim): raise TypeError("invalid arguments") retval = [] for x in xs: # ... # elaborate acrobatics that set y # ... retval.append(y) return retval My Java implementation of it already requires at least 8 method definitions, with signatures: short[] quant (float[], int , float) short[] quant (float[], int ) short[] quant (float[], float) short[] quant (float[] ) short quant (float , int , float) short quant (float , int ) short quant (float , float) short quant (float ) Actually, for additional reasons, too arcane to go into, I also need four more: short quant (Float , Integer, Float) short quant (Float , Integer ) short quant (Float , Float) short quant (Float ) Writing JUnit tests for these methods is literally driving me INSANE. Some advice on implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Fri Aug 12 13:35:46 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 18:35:46 +0100 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: <4E456472.9040600@mrabarnett.plus.com> On 12/08/2011 18:02, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > [snip] I would declare: short[] quant (float[], int , float) short quant (Float , Integer, Float) and see how it goes. "float" and "int" should be boxed to "Float" and "Integer" automatically. If the second and third arguments are frequently the default, then I would also declare: short[] quant (float[]) short quant (Float ) From billy.earney at gmail.com Fri Aug 12 13:44:16 2011 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 12 Aug 2011 12:44:16 -0500 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: Look into jython. You might be able to run your python code, directly in java. :) http://www.jython.org/ On Fri, Aug 12, 2011 at 12:02 PM, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > > short[] quant (float[], int , float) > short[] quant (float[], int ) > short[] quant (float[], float) > short[] quant (float[] ) > > short quant (float , int , float) > short quant (float , int ) > short quant (float , float) > short quant (float ) > > Actually, for additional reasons, too arcane to go into, I also > need four more: > > short quant (Float , Integer, Float) > short quant (Float , Integer ) > short quant (Float , Float) > short quant (Float ) > > Writing JUnit tests for these methods is literally driving me > INSANE. > > Some advice on implementing and testing functions with optional > arguments in Java would be appreciated. > > TIA! > > kj > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Fri Aug 12 13:45:47 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 12 Aug 2011 19:45:47 +0200 Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: <87k4ai8qwk.fsf@dpt-info.u-strasbg.fr> kj writes: [...] > def quant(xs, nlevels=MAXN, xlim=MAXX): [...] > My Java implementation of it already requires at least 8 method > definitions, with signatures: (BTW, your approach won't work if several optionals have the same type.) [...] - use Integer, Float, etc. everywhere. The compiler will box primitive types as needed at call sites - re. default values (on positional params), use null to indicate a use of the default, or use ellipsis, or use class-provided static fields at call sites, or use a special class to represent all the optional parameters - re. named parameters with default, use a map, or change the call sites to remove them -- Alain. From rantingrick at gmail.com Fri Aug 12 13:57:57 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 10:57:57 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> On Aug 12, 11:33?am, Seebs wrote: > > My brain has quirks. ?Some people call them defects, some don't, but it > really doesn't matter; there are things about which my brain is just plain > unreliable and I rely moderately heavily on extra visual cues to reduce > the frequency with which I get things wrong when skimming. I think that really boils down to you refusing to open your eyes up to new ways of doing things. You are clutching the past and it is taking you down with it. Pry your lips from Ritchie's left teet and stop slurping that "brace" milk; because it is polluting your mind! > > When you're driving on a > > two lane highway that becomes one lane, would you forget to merge > > (OUTDENT) simply because the "merge sign" was missing? > > No, because the *LANE BOUNDARIES* would move. The "lane boundaries" will also move whilst reading code that uses the indent/dedent paradigm. Are you honestly telling me that you will skip over a four spaced dedent without seeing it however you can easily spot a single closing brace and instantly "know" which corresponding opener brace to which it referrers without looking, and counting, and wasting time? Sorry, i just don't believe you. > I propose we extend it to expression processing in general. ?Instead > of writing > ? ? ? ? a = (x + y) * z > let's just write > ? ? ? ? a = (x + y * z I'm glad you brought this up! How about this instead: a = x + y * z ...where the calculation is NOT subject to operator precedence? I always hated using parenthesis in mathematical calculations. All math should resolve in a linear fashion. 3+3*2 should always be 12 and NOT 9! > It's obvious that no one would have needed to introduce parentheses here > unless they wanted to bind the + more closely than the *, so the ) is > just noise and not needed. I would even go as far to use a special set of brackets for linear calculations before using only one, or playing the precedence game. > > As much as we love people getting on board we are not about to > > sacrifice our strong beliefs in clean source code just so you and > > other hardwired C programmers will come along. > > But you will happily insult people and call them names in order to > keep them from having anything to listen to? I am not trying to discredit you simply by disagreeing with you. I have offered facts as to why significant indention is far superior to braces and yet you continue to use the same emotionally charged babble in your defense. When you offer some real facts then i will give then just consideration, until then i will "try" to enlighten you of the merits of significant indentation. From aspineux at gmail.com Fri Aug 12 14:17:28 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 11:17:28 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> On Aug 12, 3:38?pm, Steven D'Aprano wrote: > aspineux wrote: > > Hi I have written a tutorial about how to generate and send emails > > with python. > > [...] > > Thank you, that is an extremely detailed tutorial. Thanks, It was my intention Alain > > -- > Steven From miki.tebeka at gmail.com Fri Aug 12 14:18:01 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 12 Aug 2011 11:18:01 -0700 (PDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: <04e60610-b887-49f9-940f-7b4b507ae466@glegroupsg2000goo.googlegroups.com> You can probably do that with varargs. From usenet-nospam at seebs.net Fri Aug 12 14:37:41 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 18:37:41 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Chris Rebert wrote: > One argument I've heard from braces fans is that sometimes they want > their own structure, which does not match the actual block structure. EWW! > Example: > > FILE* f = fopen(...); > // do stuff with f > // at this indent level > fclose(f); > // back to normal > > But really this is just working around other limitations in the > language (i.e. lack of a with-statement equivalent). That's horrid. FWIW, the C idiom is: { FILE *f = ... ... fclose(f); } It isn't used all that widely, but it is a lot less horrible than random indenting would be. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 15:52:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 20:52:13 +0100 Subject: allow line break at operators In-Reply-To: <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 4:33 PM, rantingrick wrote: > On Aug 12, 2:20?am, Chris Angelico wrote: > >> Pike is very [snip] >> Pike's purpose is [snip] >> you go to Pike[snip] >> >> I hope I make myself clear, Josephine? > > The only thing that is clear to me is that you have a hidden agenda to > incorporate pike's functionality into Python -- and this is not the > first time! > > Chris, this incessant babbling about "pike this" and "pike that" is > starting to get on my nerves. Why don't you go over to comp.lang.pike > and gush to them about how wonderful the language is. Yeah, it's something I've mentioned a few times. I think people have mentioned C on this list a few times, too; also lisp. Of course, since this is the Python mailing list (or newsgroup, depending where you read it), we aren't allowed to mention any other languages at all. Mea culpa. I'm not seeking to add Pike's functionality into Python. I want the two languages to be different, and I want the world to have different languages. Diversity and choice promote quality in ways that you don't seem to understand. Chris Angelico From rosuav at gmail.com Fri Aug 12 16:01:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:01:56 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On Fri, Aug 12, 2011 at 5:33 PM, Seebs wrote: > I've seen people in C do stuff like: > > ? ? ? ?for (i = 0; i < N; ++i); > ? ? ? ? ? ? ? ?a[i] = 0; > > This is clearly a case where indentation matches intent, but doesn't match > functionality, because C allows indentation to not-match functionality; this > is the famous problem Python is solving. > There's several solutions to this. One is linting utilities that detect unexpectedly-indented code, which is the concept that Python took to the logical extent of syntactic errors. Another is (again linting) to disallow a direct trailing semicolon; if you want an empty body, you put whitespace before the semicolon. But that wasn't your point, I realise :) ChrisA From rosuav at gmail.com Fri Aug 12 16:09:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:09:56 +0100 Subject: allow line break at operators In-Reply-To: <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 6:57 PM, rantingrick wrote: > I'm glad you brought this up! How about this instead: > > ? ?a = x + y * z > > ...where the calculation is NOT subject to operator precedence? I > always hated using parenthesis in mathematical calculations. All math > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > 9! Why is left-to-right inherently more logical than multiplication-before-addition? Why is it more logical than right-to-left? And why is changing people's expectations more logical than fulfilling them? Python uses the + and - symbols to mean addition and subtraction for good reason. Let's not alienate the mathematical mind by violating this rule. It would be far safer to go the other way and demand parentheses on everything. Incidentally, in the original expression, it would be slightly more sane to write it as: a = x + y) * z borrowing from the musical concept that a repeat sign with no corresponding begin-repeat means to repeat from the beginning. But both of these violate XKCD 859. From ethan at stoneleaf.us Fri Aug 12 16:15:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Aug 2011 13:15:52 -0700 Subject: __all__ In-Reply-To: References: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4589F8.5080404@stoneleaf.us> Paul Woolcock wrote: > The gurus will have to correct me if this is not an accepted practice, > but I know some projects (Fabric is the one that comes to mind) will > define a submodule specifically for the 'from blah import *' situation. > The submodule would be called "api", or something like that, so you can > do: 'from mymodule.api import *' to separate the items you want to > include in your public api, while still keeping other names importable > by 'import blah' Have I said lately how much I *love* Python? Programming is fun again! Thanks, Paul, that was the clue I needed. Had to do some thinking since dbf is back to a single module, and no longer a package... here's what I came up with: ------------------------------------------------------------- class fake_module(object): def __init__(self, name, *args): self.name = name self.__all__ = [] for func in args: name = func.__name__ self.__dict__[name] = func self.__all__.append(name) def register(self): sys.modules["%s.%s" % (__name__, self.name)] = self ------------------------------------------------------------- then in my module (towards the bottom since I have to have all my functions/classes written that I want to include) I can have fake_module('api', class1, class2, func1, exception1).register() Now somebody else who wants to include the classes, exceptions, etc, that make up the primary part of the dbf module can do from dbf.api import * but help(dbf) will continue to list all the other public utility stuff (defined in dbf.__all__) normally. Thanks to all! ~Ethan~ From ckaynor at zindagigames.com Fri Aug 12 16:24:35 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Aug 2011 13:24:35 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 1:09 PM, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 6:57 PM, rantingrick > wrote: > > I'm glad you brought this up! How about this instead: > > > > a = x + y * z > > > > ...where the calculation is NOT subject to operator precedence? I > > always hated using parenthesis in mathematical calculations. All math > > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > > 9! > > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. > Left-to-right is more logical because that is the choice made by the English language (which I will note, we are using right now). Also, ignoring operator precedence, left-to-right is the way math equations evaluate. See 4 / 2 * 3 - you get 6, not (2/3) and not (3/2). Now, I would not suggest changing the multiplication before addition rule, for the very reason you mention: in many cases, the established rule is expected, but that does not mean it is more logical. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 12 16:29:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:29:25 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 4:55 PM, Jack Hatterly wrote: > It prints "None". However, when I look in my browser's cookie jar, there is > a cookie "www.my_site.com" where my_site is the site from which I am surfing > the above script. What gives? > I assume that what you mean is that it prints "None" even after you hit F5 to reload the page, as the first run of the script will never have a cookie. Your script is now not actually setting any cookie. What cookie are you seeing in your browser? It may be something created and consumed by your framework, somewhere. ChrisA From ethan at stoneleaf.us Fri Aug 12 16:35:56 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Aug 2011 13:35:56 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4E458EAC.8000702@stoneleaf.us> Chris Angelico wrote: > Incidentally, in the original expression, it would be slightly more > sane to write it as: > > a = x + y) * z > > borrowing from the musical concept that a repeat sign with no > corresponding begin-repeat means to repeat from the beginning. But > both of these violate XKCD 859. Argh! ;) ~Ethan~ From rosuav at gmail.com Fri Aug 12 16:39:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:39:33 +0100 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 6:02 PM, kj wrote: > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > Firstly, figure out how many combinations of optional arguments actually make sense. Any that don't, don't support. That may well cut it down significantly. And then, if there are any that make sense but will be really rare (eg if you allow optional specification of a max and a min, and most times you'll use either both bounds or neither), you can save a few by having the "optional" argument specified with a sentinel meaning "default". It's ugly in a few places to justify simplicity in most. If you really need 100% flexibility, then the suggestions already posted will definitely be the best. ChrisA From tdsimpson at gmail.com Fri Aug 12 16:47:40 2011 From: tdsimpson at gmail.com (MrPink) Date: Fri, 12 Aug 2011 13:47:40 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: Boy, that was a lot more elegant that I would have thought. Though hard for a greenhorn like me to really understand how the assignment are working, etc. Anyway, what are these kind of statement call so that I can read up more on this? What Python feature are you using? num_whites = ticket_whites & drawing_whites black_matching = ticket_black == drawing_black Thanks, On Aug 10, 11:35?pm, Miki Tebeka wrote: > Python built in types are enough for this problem IMO. You can use sets of tuples to specify ticket and drawings and then just do set intersection. > > Say the drawing is set([(5, 'wb'), (1, 'wb'), (45, 'wb'), (23, 'wb'), (27, 'wb')]) (keeping black ball out). The you can create a score function: > > Side note: I might used a namedtuple to have drawing.whites, drawing.black. > > def score(ticket_whites, ticket_black, drawing_whites, drawing_black): > ? ? num_whites = ticket_whites & drawing_whites > ? ? black_matching = ticket_black == drawing_black > ? ? return { > ? ? ? ? (2, True) ?: 1, > ? ? ? ? (3, False) : 2, > ? ? ? ? (3, True) ?: 3, > ? ? ? ? (4, False) : 4, > ? ? ? ? (4, True) ?: 5, > ? ? ? ? (5, False) : 6, > ? ? ? ? (5, True) ?: 10 > ? ? }[(num_whites, black_matching)] From usenet-nospam at seebs.net Fri Aug 12 17:06:37 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:37 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-12, rantingrick wrote: > On Aug 12, 11:33?am, Seebs wrote: >> My brain has quirks. ?Some people call them defects, some don't, but it >> really doesn't matter; there are things about which my brain is just plain >> unreliable and I rely moderately heavily on extra visual cues to reduce >> the frequency with which I get things wrong when skimming. > I think that really boils down to you refusing to open your eyes up to > new ways of doing things. You think that, then? Okay. > You are clutching the past and it is taking > you down with it. I see. This is a brilliant new theory. I will further explore the notion that actually my brain is 100% normal with no limitations except that I have used languages with braces. Doubtless this will prove illuminating. >> No, because the *LANE BOUNDARIES* would move. > The "lane boundaries" will also move whilst reading code that uses the > indent/dedent paradigm. Are you honestly telling me that you will skip > over a four spaced dedent without seeing it however you can easily > spot a single closing brace and instantly "know" which corresponding > opener brace to which it referrers without looking, and counting, and > wasting time? Sorry, i just don't believe you. Nope, not telling you that. Here's my example: if foo: blah blah blah if bar: moreblah moreblah if quux: typingisboring typingisboring typingisboring moreblah moreblah if baz: somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah abitmoreblah It's not easy for me to be sure, looking at something roughly like that, what's being closed and what isn't. If I have braces, I can tell how many things are being closed. I like that. It makes me happy. >> I propose we extend it to expression processing in general. ?Instead >> of writing >> ? ? ? ? a = (x + y) * z >> let's just write >> ? ? ? ? a = (x + y * z > I'm glad you brought this up! How about this instead: > a = x + y * z > ...where the calculation is NOT subject to operator precedence? I > always hated using parenthesis in mathematical calculations. All math > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > 9! Doesn't matter. At some point, somewhere, it would become desireable to introduce precedence with (), at which point, it is quite possible that the trailing ) would be redundant, so why not omit it? > I am not trying to discredit you simply by disagreeing with you. No, but you're certainly being insulting. > I have offered facts as to why significant indention is far superior to > braces and yet you continue to use the same emotionally charged babble > in your defense. Facts: Pry your lips from Ritchie's left teet and stop slurping that "brace" milk; because it is polluting your mind! Emotionally charged babble: My brain has quirks. Some people call them defects, some don't, but it really doesn't matter; there are things about which my brain is just plain unreliable and I rely moderately heavily on extra visual cues to reduce the frequency with which I get things wrong when skimming. > When you offer some real facts then i will give then > just consideration, until then i will "try" to enlighten you of the > merits of significant indentation. Well played! -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 17:06:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:38 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-12, Chris Angelico wrote: > Why is left-to-right inherently more logical than > multiplication-before-addition? I'd say it's certainly "more Pythonic in a vacuum". Multiplication-before-addition, and all the related rules, require you to know a lot of special rules which are not visible in the code, and many of which have no real logical basis. Left-to-right is, if nothing else, the way the majority of us read. The problem is that since everyone's used precedence before, not using it violates the principle of least astonishment. ... Hmm. There is a thought; I think it may be useful to distinguish between "Pythonic" and "Pythonic in a vacuum". That is to say, there are things which would fit the basic philosophy of Python very well if previous programming languages and tools were not widespread, and there are other things which fit anyway. Using a simple left-to-right evaluation would probably be easier for people to understand, and more self-explanatory, *IF* there were no prior art. > Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Well, playing devil's advocate's advocate here... You could argue that switching from braces to indentation might be "changing" peoples' expectations, or might be fulfilling them, depending on the people. I think there's certainly cases where it is probably better to say "that expectation proves to make it impossible to build a clean language, so we're going to ask you to do things this way", and cases where it is probably better to say "that expectation is very deeply established, and doesn't really hurt the language, so we'll adapt to you". > Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. I wouldn't mind that. > Incidentally, in the original expression, it would be slightly more > sane to write it as: > > a = x + y) * z > > borrowing from the musical concept that a repeat sign with no > corresponding begin-repeat means to repeat from the beginning. But > both of these violate XKCD 859. Yes, yes they do. Huh. You know, that's why the outdents-without-symbols bug me; I have a thing with a colon on it introducing something, and then there's nothing ending it. I want that match so I can let the naive stack-depth-counter off somewhere in my brain do its thing without leaving me with a huge feeling of unclosed blocks. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 17:06:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:38 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 5:33 PM, Seebs wrote: >> I've seen people in C do stuff like: >> ? ? ? ?for (i = 0; i < N; ++i); >> ? ? ? ? ? ? ? ?a[i] = 0; >> This is clearly a case where indentation matches intent, but doesn't match >> functionality, because C allows indentation to not-match functionality; this >> is the famous problem Python is solving. > There's several solutions to this. One is linting utilities that > detect unexpectedly-indented code, which is the concept that Python > took to the logical extent of syntactic errors. Another is (again > linting) to disallow a direct trailing semicolon; if you want an empty > body, you put whitespace before the semicolon. > > But that wasn't your point, I realise :) I think it sort of is. My current preference would be that C-like languages would simply absolutely eliminate optional-braces. Then the whole category of errors would partially-go-away. You could still have code which didn't do what you meant, but it would be reliably easy to see what it did, and so on. But it's interesting to note that there are many ways to address this. Most of the C I've done has been in circumstances where misindented code was in fact a thing that would fail reviews. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ckaynor at zindagigames.com Fri Aug 12 17:11:35 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Aug 2011 14:11:35 -0700 Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 1:47 PM, MrPink wrote: > Boy, that was a lot more elegant that I would have thought. > Though hard for a greenhorn like me to really understand how the > assignment are working, etc. > > Anyway, what are these kind of statement call so that I can read up > more on this? > What Python feature are you using? > > num_whites = ticket_whites & drawing_whites > This is a set intersection, using the "bit-wise and" operator (&). It can also be written as either of: num_whites = (ticket_whites & drawing_whites) # Makes it a bit clearer that the "bit-wise and" operator runs before the "assignment" (=) operator. num_whites = ticket_whites.intersection(drawing_whites) # Calls the actual method rather than using the operator. A bit more verbose. > black_matching = ticket_black == drawing_black > This is just the result of an equality operator being assigned. It may be a bit clearer if you see it as: black_matching = (ticket_black == drawing_black) > > Thanks, > > For more details, you can look up sets (both the math kind and the specific Python implementation are relevant): http://docs.python.org/library/stdtypes.html#set http://en.wikipedia.org/wiki/Set_(mathematics) http://en.wikipedia.org/wiki/Set_theory Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Fri Aug 12 17:31:13 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 12 Aug 2011 14:31:13 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: It's the builtin "set", see http://docs.python.org/library/stdtypes.html#set-types-set-frozenset From jackhatterly at hotmail.com Fri Aug 12 17:55:36 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 21:55:36 +0000 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: , Message-ID: > Date: Fri, 12 Aug 2011 21:29:25 +0100 > Subject: Re: Problem reading HTTP_COOKIE > From: rosuav at gmail.com > To: python-list at python.org > > I assume that what you mean is that it prints "None" even after you > hit F5 to reload the page, as the first run of the script will never > have a cookie. > > Your script is now not actually setting any cookie. What cookie are > you seeing in your browser? It may be something created and consumed > by your framework, somewhere. But my script *is* setting a cookie. I just sent a stripped-down version of the script earlier. Here's the entire script: #! /usr/bin/python import string import os import datetime, Cookie, random import time import os def parse_cookie(): ourTime = str(time.time()) environ = os.environ cookie = environ.get('HTTP_COOKIE', '') if cookie == '': cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = random.randint(1,999999999999) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/var/www/html/my_site/clients/Millenium/' cookie['lastvisit']['comment'] = random.randint(1,999999999999) cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 c = Cookie.SimpleCookie() c.load(cookie) cookiedict = {} for key in c.keys(): cookiedict[key] = c.get(key).value print c print 'Content-Type: text/html\n' print '' print '' if __name__ == "__main__": parse_cookie() You see, every time when the cookie is read it comes back None which gets translated to '' and then the cookie is re-baked. *NOT* what I want!! I can see the cookie in my browser. TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 12 18:00:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 12 Aug 2011 15:00:08 -0700 Subject: Processing a large string In-Reply-To: References: Message-ID: This is the sort of thing I wrote bufsock for. Don't let the name fool you - although I originally wrote it for sockets, it's since been extended to work with files and file handles. http://stromberg.dnsalias.org/~dstromberg/bufsock.html It was recently modified to work on 2.x and 3.x. On Thu, Aug 11, 2011 at 7:03 PM, goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 12 18:03:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 13 Aug 2011 08:03:49 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-12, rantingrick wrote: >> What is with you guys and this need to have your hand held to read >> code. > > Good question! Great to see that the helpful and welcoming community > is living up to its reputation. Please don't feed the troll. Responding to Rick's standard obnoxious posts is like wrestling with a pig -- you get tired and filthy, you never accomplish anything useful, and after a while, you realise that the pig is enjoying it. Save yourself a lot of aggravation and kill-file him now. -- Steven From ben+python at benfinney.id.au Fri Aug 12 18:12:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 08:12:27 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <874o1mgtys.fsf@benfinney.id.au> Seebs writes: > On 2011-08-12, rantingrick wrote: > > What is with you guys and this need to have your hand held to read > > code. > > Good question! Great to see that the helpful and welcoming community > is living up to its reputation. Please be aware that the particular person to whom you're responding is decidedly not part of the helpful and welcoming community here. > Man, you really love pushing them buttons, don't you? > > You don't understand a thing. Therefore... there is no such thing, > anyone who experiences life differently from you needs to be insulted? If you're interested, check the forum's archives for a thorough history of what the helpful and welcoming community say about him. You'll find we pretty much agree with your assessment. -- \ ?Generally speaking, the errors in religion are dangerous; | `\ those in philosophy only ridiculous.? ?David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney From drsalists at gmail.com Fri Aug 12 18:12:29 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 12 Aug 2011 15:12:29 -0700 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: Check varargs (as another poster mentioned), and consider doing your unit tests in Jython. Some shops that don't want Python for production code are fine with Python for unit tests. However, if the reason for preferring java is type checking, you could perhaps get somewhere by suggesting pylint. On Fri, Aug 12, 2011 at 10:02 AM, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > > short[] quant (float[], int , float) > short[] quant (float[], int ) > short[] quant (float[], float) > short[] quant (float[] ) > > short quant (float , int , float) > short quant (float , int ) > short quant (float , float) > short quant (float ) > > Actually, for additional reasons, too arcane to go into, I also > need four more: > > short quant (Float , Integer, Float) > short quant (Float , Integer ) > short quant (Float , Float) > short quant (Float ) > > Writing JUnit tests for these methods is literally driving me > INSANE. > > Some advice on implementing and testing functions with optional > arguments in Java would be appreciated. > > TIA! > > kj > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Fri Aug 12 18:14:01 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 22:14:01 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Steven D'Aprano wrote: > Please don't feed the troll. Responding to Rick's standard obnoxious posts > is like wrestling with a pig -- you get tired and filthy, you never > accomplish anything useful, and after a while, you realise that the pig is > enjoying it. Save yourself a lot of aggravation and kill-file him now. You know... I think I just realized where a big part of my misperception of the Python community was. Which is that until todayish, I had not realized that he was regarded as a troll by the rest of the community. But now that a couple of people have told me this, I am a lot more comfortable referring to the Python community in general as "welcoming". I sometimes enjoy trying to extract information from people like that, but I will respect the preferences of the actually-helpful people and drop that line of inquiry. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 18:31:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:31:51 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: I think the best thing to do would be to look at the raw headers. If you can't do that in your framework, then try this: set the cookie, shut down your server, fire up a debugging HTTP server on the same port, and then refresh the page. If your browser is sending the cookie, you'll see it in the HTTP request; if not, you have a configuration issue. As I said earlier, setting the cookie with a path like that may mean that the browser won't send it. Chris Angelico From ben+python at benfinney.id.au Fri Aug 12 18:36:10 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 08:36:10 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y5yyfeat.fsf@benfinney.id.au> Seebs writes: > I sometimes enjoy trying to extract information from people like that, > but I will respect the preferences of the actually-helpful people and > drop that line of inquiry. :) Much appreciated, thank you :-) -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Fri Aug 12 18:39:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 13 Aug 2011 08:39:24 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > You know, that's why the outdents-without-symbols bug me; I have a > thing with a colon on it introducing something, and then there's nothing > ending it. But there is something ending it: a change in indentation level. Python's parser explicitly pushes INDENT and OUTDENT tokens into the stream. They're just a change of state in indentation level, which is much more easily seen without the need for counting braces. Python's parser may need to count tokens, but for the human reader merely needs to use its intuitive and highly accurate ability to notice when things line up. (Aside: this is why I dislike two-space indents. That's narrow enough to make the "does this line up" detector subject to too many false positives.) > I want that match so I can let the naive stack-depth-counter > off somewhere in my brain do its thing without leaving me with a huge > feeling of unclosed blocks. Yet another reason to consider brace languages harmful: they spoil the user's intuitive grasp of intuition as grouping. And it really is intuitive[1]: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html Historically, nearly all languages with braces pre-date the widespread adoption of tools that think they can mangle whitespace with impunity. (I would say that the reasons that the tools are broken is *because* programmers have trained themselves to think that whitespace doesn't matter -- ask most writers or artists and they would say *of course* whitespace matters. The separation between elements is important -- perhaps not quite as important as the elements themselves, but still important.) Explicit BEGIN/END tokens exist to make the job of the parser easier, not that of the programmer. But the human brain is a funny thing: you can train it to expect to do more work than is necessary, and it will complain when you make its job easier. [1] For some definition of intuition. -- Steven From rosuav at gmail.com Fri Aug 12 18:50:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:50:42 +0100 Subject: allow line break at operators In-Reply-To: <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 11:39 PM, Steven D'Aprano wrote: > ask most writers or artists and they would say *of course* > whitespace matters. You can write Perl code in the shape of a camel. Can you do that in Python? Okay. Open challenge to anyone. Write a Python script that outputs "Just another Python hacker" or some such message, and is shaped in some way appropriately. And no fair doing all the shaping in comments :) (Has it already been done?) ChrisA From jackhatterly at hotmail.com Fri Aug 12 18:53:16 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 22:53:16 +0000 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: , , , Message-ID: Chris, I finally got a script that works. Thanks for trying! Jack #!/usr/bin/env python import string import os import datetime, Cookie, random import time # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') if not cookie_string: ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = string.replace(ourTime, '.', '') print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The first time the page is run there will be no cookies print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = string.replace(ourTime, '.', '') else: # Run the page twice to retrieve the cookie cookie = Cookie.SimpleCookie() cookie['lastvisit'] = cookie_string cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/cgi-bin/' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 print 'Content-Type: text/html\n' print '

', cookie, '

' for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 12 18:55:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:55:57 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 11:53 PM, Jack Hatterly wrote: > cookie['lastvisit']['path'] = '/cgi-bin/' > Yep, that's looking a lot more useful! Glad it's working. ChrisA From ben+python at benfinney.id.au Fri Aug 12 19:19:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 09:19:59 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9mfc9s.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, Aug 12, 2011 at 11:39 PM, Steven D'Aprano > wrote: > > ask most writers or artists and they would say *of course* > > whitespace matters. > > You can write Perl code in the shape of a camel. Can you do that in > Python? I'm glad to be using a language where that sort of hard to-read code is not encouraged by the syntax. Art is wonderful, if you don't want to communicate clearly. I'll thank the people who write the programs in my life to save their artistic expression for areas where clear communication is optional. -- \ ?My business is to teach my aspirations to conform themselves | `\ to fact, not to try and make facts harmonise with my | _o__) aspirations.? ?Thomas Henry Huxley, 1860-09-23 | Ben Finney From python.list at tim.thechases.com Fri Aug 12 19:53:43 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Aug 2011 18:53:43 -0500 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E45BD07.90300@tim.thechases.com> On 08/12/2011 05:50 PM, Chris Angelico wrote: > You can write Perl code in the shape of a camel. Can you do that in Python? > > Okay. Open challenge to anyone. Write a Python script that outputs > "Just another Python hacker" or some such message, and is shaped in > some way appropriately. And no fair doing all the shaping in comments Okay, my entry: print("Just another Python hacker") That lovely one-line shape resembles a straight & narrow snake ;-) -tkc From tjreedy at udel.edu Fri Aug 12 20:15:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Aug 2011 20:15:40 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/12/2011 6:14 PM, Seebs wrote: I am responding to your whole line of posts. I have been indenting code neatly for at least 32 years whenever the language I used allowed it. Just over 14 years ago, when Python was an obscure little known or used languge, I adopted it *because* it dropped all the redundant bracket noise and looked to me like 'executable pseudocode', as I explained (with an unfortunate misspelling) in https://groups.google.com/group/comp.lang.python/msg/cc25701a283a3f68 Indentation is part of that. Python-with-brackets would, to me, be something different -- sure, derived from Python, but not the same. I do not need for you to adopt and use Python to validate my choice. If you like it fine, welcome. If not, have fun with something else. I said that over a decade when this same discussion took place, and I say it now. Different brains are different. I do not care which of us is in the majority in which population. As I and others also pointed out over a decade ago, anyone is free to add insignificant comment braces (but keep that private, please) or, more sensibly, commented dedents to help the reader keep track of indent level. for... for ... if ... for ... if ... [50 more lines of code] #end outer if [more code] -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 12 20:18:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Aug 2011 20:18:39 -0400 Subject: generate and send mail with python: tutorial In-Reply-To: <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> Message-ID: On 8/12/2011 2:17 PM, aspineux wrote: > On Aug 12, 3:38 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> aspineux wrote: >>> Hi I have written a tutorial about how to generate and send emails >>> with python. >> >> [...] >> >> Thank you, that is an extremely detailed tutorial. > > Thanks, It was my intention Have you considered contributing a HOW-TO? -- Terry Jan Reedy From usenet-nospam at seebs.net Fri Aug 12 20:39:32 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 00:39:32 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Steven D'Aprano wrote: > Seebs wrote: >> You know, that's why the outdents-without-symbols bug me; I have a >> thing with a colon on it introducing something, and then there's nothing >> ending it. > But there is something ending it: a change in indentation level. Hmm. Okay, here's what I'm not getting. Consider this: if foo: blah if bar: blah blah if baz: blah blah > Python's parser explicitly pushes INDENT and OUTDENT tokens into the stream. What's being pushed into the stream to indicate that the first outdent is two outdents and the second is one? I guess... The parser is explicitly pushing those tokens, but I can't *SEE* those tokens. If I am looking at the end of a really long thing, and I see: blah blah I only know what's happening if I have absolute confidence that the indentation is always by the same amount, etectera. > They're just a change of state in indentation level, which is much more > easily seen without the need for counting braces. Python's parser may need > to count tokens, but for the human reader merely needs to use its intuitive > and highly accurate ability to notice when things line up. Well, that's the thing. In a case like: if foo: if bar: blah blah I notice that *NOTHING* lines up with "if bar:". And that affects me about the way unmatched brackets do. > (Aside: this is why I dislike two-space indents. That's narrow enough to > make the "does this line up" detector subject to too many false positives.) Yeah. >> I want that match so I can let the naive stack-depth-counter >> off somewhere in my brain do its thing without leaving me with a huge >> feeling of unclosed blocks. > Yet another reason to consider brace languages harmful: they spoil the > user's intuitive grasp of intuition as grouping. I assume you mean "indentation as grouping". I'm... not sold on this. It's not that I don't see indentation as a kind of grouping. It's just that I really, really, want groups to have ends. Consider the hypothetical array syntax: a = [ 1, 2 b = [ 3, 4 This *bugs* me. It's perfectly legible, and if you define it that way, it's unambiguous and everything, but... It bugs me. I want beginnings to have an actual corresponding end. > But the human brain is a funny thing: you can train > it to expect to do more work than is necessary, and it will complain when > you make its job easier. Easier varies somewhat from person to person. I need a LOT of parity checks (speaking metaphorically) because my brain is fantastically prone to dropping bits. But I'm really fast. So a thing with lots of parity checks is much easier for me to actually *successfully* use than a thing which omits all that extra stuff. I was overjoyed when I saw that Ruby would let me write 1_048_576. I can read that with fewer errors than I can read 1048576. (And yes, I could also write "1<<20".) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Fri Aug 12 20:43:58 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 10:43:58 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> Message-ID: <87pqkaf8dt.fsf@benfinney.id.au> Terry Reedy writes: > >> aspineux wrote: > >>> Hi I have written a tutorial about how to generate and send emails > >>> with python. > Have you considered contributing a HOW-TO? I think Terry is referring to . I agree that this should be submitted to that collection, and maintained along with all the others. What is the process if the OP, or someone to whom the OP delegates authority, wants to do that? -- \ ?If you continue running Windows, your system may become | `\ unstable.? ?Microsoft, Windows 95 bluescreen error message | _o__) | Ben Finney From usenet-nospam at seebs.net Fri Aug 12 20:44:26 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 00:44:26 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-13, Terry Reedy wrote: > I have been indenting code neatly for at least 32 years whenever the > language I used allowed it. Just over 14 years ago, when Python was an > obscure little known or used languge, I adopted it *because* it dropped > all the redundant bracket noise and looked to me like 'executable > pseudocode', as I explained (with an unfortunate misspelling) in > https://groups.google.com/group/comp.lang.python/msg/cc25701a283a3f68 > Indentation is part of that. Python-with-brackets would, to me, be > something different -- sure, derived from Python, but not the same. Fair enough. > I do not need for you to adopt and use Python to validate my choice. If > you like it fine, welcome. If not, have fun with something else. If this were among my options, it's probably what I'd do. It is what I do for things where I get a choice of languages. FWIW, yes, I spec machines with ECC memory whenever I can. I am a big fan of "redundant" data that can detect likely errors. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Fri Aug 12 20:57:28 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 10:57:28 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k4aif7rb.fsf@benfinney.id.au> Seebs writes: > What's being pushed into the stream to indicate that the first outdent > is two outdents and the second is one? See for a comprehensive discussion of the lexing done on Python source. To examine the resulting code objects, see the ?dis? module in the standard library . -- \ ?[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 ben+python at benfinney.id.au Fri Aug 12 21:00:05 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 11:00:05 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> <87pqkaf8dt.fsf@benfinney.id.au> Message-ID: <87fwl6f7my.fsf@benfinney.id.au> Ben Finney writes: > What is the process if the OP, or someone to whom the OP delegates > authority, wants to [contribute their work to the Python > documentation]? The answer is partly at : If you?re interested in contributing to Python?s documentation [?] Send an e-mail to docs at python.org or open an issue on the tracker. One should, before doing so, follow the above document on the documentation style conventions for Python. -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From greg.ewing at canterbury.ac.nz Fri Aug 12 21:19:24 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Aug 2011 13:19:24 +1200 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <9am1ouFgklU1@mid.individual.net> Chris Angelico wrote: > But both of these violate XKCD 859. For the benefit of all those who just went off to read that strip, here's something to help you unwind: ) There, you can relax now. -- Greg From usenet-nospam at seebs.net Fri Aug 12 22:34:50 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 02:34:50 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <87k4aif7rb.fsf@benfinney.id.au> Message-ID: On 2011-08-13, Ben Finney wrote: > Seebs writes: >> What's being pushed into the stream to indicate that the first outdent >> is two outdents and the second is one? > See for a > comprehensive discussion of the lexing done on Python source. Interesting, thanks. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From kw at codebykevin.com Fri Aug 12 22:49:32 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 12 Aug 2011 22:49:32 -0400 Subject: os.system() on Windows in Tkinter app spawns console window Message-ID: I'm developing a Tkinter app for a Windows customer, and the app bundles several command-line tools (ported from Unix). I call out to these console tools from the Tkinter app via os.system(). However, in the frozen version of my app, when I call out to these tools, I get multiple console windows popping up. This is jarring to say the least. Is there any way to run the commands under the hood without the console/DOS windows popping up? --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From nagle at animats.com Sat Aug 13 00:30:28 2011 From: nagle at animats.com (John Nagle) Date: Fri, 12 Aug 2011 21:30:28 -0700 Subject: 'Use-Once' Variables and Linear Objects In-Reply-To: References: Message-ID: <4e45fe11$0$2139$742ec2ed@news.sonic.net> On 8/2/2011 7:19 AM, Neal Becker wrote: > I thought this was an interesting article > > http://www.pipeline.com/~hbaker1/Use1Var.html Single-use was something of a dead end in programming. Single assignment, where you can only set a variable when you create it, is more useful. Single assignment is comparable to functional programming, but without the deeply nested syntax. Functional programs are trees, while single-assignment programs are directed acyclic graphs. The difference is that you can fan-out results, while in a a functional language, you can only fan in. This fits well with Python, where you can write things like def fn(x) : (a, b, c) = fn1() return(fn2(a) + fn3(b)*c) "const" is often used in C and C++ to indicate single-assignment usage. But C/C++ doesn't have multiple return values, so the concept isn't as useful as it is in Python. Optimizing compilers usually recognize variable lifetimes, and so they create single-assignment variables internally when possible. This is a win for register and stack allocation, and for fine-grain parallelism on machines which support it. Since Python isn't very optimizable, this is mostly a curiosity. John Nagle From juliocesarrodriguezcruz at gmail.com Sat Aug 13 00:59:42 2011 From: juliocesarrodriguezcruz at gmail.com (Julio Cesar Rodriguez Cruz) Date: Sat, 13 Aug 2011 00:59:42 -0400 Subject: How to print non-printable chars?? Message-ID: Hi all, If I open an .exe file in any text editor I get lot of odd chars, what I want is to know how to output those chars if I have the hexadecimal code. I found out how to do the reverse process with the quopri module, i.e.: >>> import quopri >>> quopri.encodestring('??') '=F1=E8=18' >>> quopri.decodestring('=F1=E8=18') '\xf1\xe8\x18' but how to do the reverse? ...gived '\xf1\xe8\x18', print '??' any tips? thanks Julio Cesar From nobody at nowhere.com Sat Aug 13 01:15:25 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Aug 2011 06:15:25 +0100 Subject: os.system() on Windows in Tkinter app spawns console window References: Message-ID: On Fri, 12 Aug 2011 22:49:32 -0400, Kevin Walzer wrote: > I'm developing a Tkinter app for a Windows customer, and the app bundles > several command-line tools (ported from Unix). I call out to these > console tools from the Tkinter app via os.system(). However, in the > frozen version of my app, when I call out to these tools, I get multiple > console windows popping up. This is jarring to say the least. Is there > any way to run the commands under the hood without the console/DOS > windows popping up? Just a wild guess, but try explicitly redirecting the commands' stdin/stdout/stderr. You might also consider using subprocess.call() instead of os.system(). From nobody at nowhere.com Sat Aug 13 01:22:22 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Aug 2011 06:22:22 +0100 Subject: How to print non-printable chars?? References: Message-ID: On Sat, 13 Aug 2011 00:59:42 -0400, Julio Cesar Rodriguez Cruz wrote: > Hi all, > If I open an .exe file in any text editor I get lot of odd chars, > what I want is to know how to output those chars if I have the hexadecimal > code. I found out how to do the reverse process with the quopri module, > > i.e.: >>>> import quopri >>>> quopri.encodestring('??') > '=F1=E8=18' >>>> quopri.decodestring('=F1=E8=18') > '\xf1\xe8\x18' > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '??' print(quopri.decodestring('=F1=E8=18')) or: sys.stdout.write(quopri.decodestring('=F1=E8=18')) If you type an expression into the interactive Python interpreter, the result is converted to a string using repr(); for strings, this converts 8-bit characters to their hexadecimal escape sequences, so that the result only uses ASCII. OTOH, the print statement converts values to strings using str(); for strings, this is an identity operation (i.e. it returns the original string untouched). Similarly, the .write() method of file objects uses str(). From juliocesarrodriguezcruz at gmail.com Sat Aug 13 01:55:16 2011 From: juliocesarrodriguezcruz at gmail.com (Julio Cesar) Date: Fri, 12 Aug 2011 22:55:16 -0700 (PDT) Subject: How to print non-printable chars?? References: Message-ID: On Aug 13, 1:22?am, Nobody wrote: > On Sat, 13 Aug 2011 00:59:42 -0400, Julio Cesar Rodriguez Cruz wrote: > > > Hi all, > > If I open an .exe file in any text editor I get lot of odd chars, > > what I want is to know how to output those chars if I have the hexadecimal > > code. I found out how to do the reverse process with the quopri module, > > > i.e.: > >>>> import quopri > >>>> quopri.encodestring('?? ') > > '=F1=E8=18' > >>>> quopri.decodestring('=F1=E8=18') > > '\xf1\xe8\x18' > > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '?? ' > > ? ? ? ? print(quopri.decodestring('=F1=E8=18')) > or: > ? ? ? ? sys.stdout.write(quopri.decodestring('=F1=E8=18')) > > If you type an expression into the interactive Python interpreter, the > result is converted to a string using repr(); for strings, this converts > 8-bit characters to their hexadecimal escape sequences, so that the result > only uses ASCII. > > OTOH, the print statement converts values to strings using str(); for > strings, this is an identity operation (i.e. it returns the original > string untouched). Similarly, the .write() method of file objects uses str(). It just works!! thanks a lot and also for the explanations ;) Cheers Julio Cesar From 1248283536 at qq.com Sat Aug 13 05:09:55 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sat, 13 Aug 2011 17:09:55 +0800 Subject: thread and process Message-ID: please see my code: import os import threading print threading.currentThread() print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() print threading.currentThread() if ret == 0: print threading.currentThread() else: os.wait() print threading.currentThread() print "i am runing,who am i? ",os.getpid(),threading.currentThread() the output is: <_MainThread(MainThread, started -1216477504)> i am parent 13495 i am here 13495 <_MainThread(MainThread, started -1216477504)> i am here 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> it is so strange that two different processes use one mainthread!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Sat Aug 13 06:01:07 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 13 Aug 2011 03:01:07 -0700 (PDT) Subject: thread and process References: Message-ID: On Aug 13, 11:09 am, "????" <1248283... at qq.com> wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> > it is so strange that two different processes use one mainthread!! You should not mix thread and fork. Some hint : You put your "import threading" before your fork(), then data initialized by the import are the same in the two process then it display the same, this is like a=-1216477504 os.fork() print a second I thing -1216477504 has no meaning, this is not a system thread ID but just an ID generated by python I think they must be unique inside a process but not cross process. Then 2 process can have the same python thread ID. If you have to mix thread and fork try to find some hints from Internet. Something like don't fork a process that already has tread(), or try to keep all your threads inside the same process ... Regards From aspineux at gmail.com Sat Aug 13 06:22:44 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 13 Aug 2011 03:22:44 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> <87pqkaf8dt.fsf@benfinney.id.au> <87fwl6f7my.fsf@benfinney.id.au> Message-ID: <3d847984-d977-4409-8f12-8f2b7510f9bf@s20g2000yqc.googlegroups.com> On Aug 13, 3:00?am, Ben Finney wrote: > Ben Finney writes: > > What is the process if the OP, or someone to whom the OP delegates > > authority, wants to [contribute their work to the Python > > documentation]? > > The answer is partly at : > > ? ? If you?re interested in contributing to Python?s documentation [?] > ? ? Send an e-mail to d... at python.org or open an issue on the tracker. > > One should, before doing so, follow the above document on the > documentation style conventions for Python. I'm using python for long now, and just discovered these HowTo today :- ( I don't thing rewriting these articles into another format will improve the "message". I will not rewrite them. You are free to do it, just keep my name as the original author. I have no other original source than the HTML one you can have on my blog. I appreciate your interest for my work. I think to put all the sources together to create a library. I thing about the name of pyezmail for "python easy mail". Any comment ? Regards > > -- > ?\ ? ? ??Contentment is a pearl of great price, and whosoever procures | > ? `\ ? ? ? ?it at the expense of ten thousand desires makes a wise and | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?happy purchase.? ?J. Balguy | > Ben Finney From pavlovevidence at gmail.com Sat Aug 13 06:52:22 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 13 Aug 2011 03:52:22 -0700 (PDT) Subject: thread and process In-Reply-To: References: Message-ID: On Saturday, August 13, 2011 2:09:55 AM UTC-7, ???? wrote: > please see my code: > import os > import? threading > print? threading.currentThread()? > print "i am parent ",os.getpid() > ret? =? os.fork() > print? "i am here",os.getpid() > print? threading.currentThread() > if? ret? ==? 0: > ???????? print? threading.currentThread() > else: > ??????? os.wait() > ??????? print? threading.currentThread() > ??????? > ??????? > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent? 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i?? 13496 <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i?? 13495 <_MainThread(MainThread, started -1216477504)> > it is so strange that? two? different? processes? use one? mainthread!! They don't use one main thread; it's just that each process's main thread has the same name. Which makes sense: when you fork a process all the data in the process has to remain valid in both parent and child, so any pointers would have to have the same value (and the -1216477504 happens to be the value of that pointer cast to an int). Carl Banks From davea at dejaviewphoto.com Sat Aug 13 08:21:42 2011 From: davea at dejaviewphoto.com (Dave Angel) Date: Sat, 13 Aug 2011 08:21:42 -0400 Subject: thread and process In-Reply-To: References: Message-ID: <4E466C56.4070601@dejaviewphoto.com> On 01/-10/-28163 02:59 PM, ???? wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496<_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495<_MainThread(MainThread, started -1216477504)> > it is so strange that two different processes use one mainthread!! Why would you figure that it's the same thread? You're just looking at the ID of the thread object in each process, and ID's have no promise of being unique between different processes, nor between multiple runs of the same program. In CPython, the id is actually an address, and each process has its own address space. The addresses happen to be the same because the main thread was created before you forked. DaveA From rafalgulinski at gmail.com Sat Aug 13 09:17:16 2011 From: rafalgulinski at gmail.com (rav) Date: Sat, 13 Aug 2011 06:17:16 -0700 (PDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: On Aug 12, 1:35?pm, MRAB wrote: > On 12/08/2011 18:02, kj wrote: > > > > > > > > > > > *Please* forgive me for asking a Java question in a Python forum. > > My only excuse for this no-no is that a Python forum is more likely > > than a Java one to have among its readers those who have had to > > deal with the same problems I'm wrestling with. > > > Due to my job, I have to port some Python code to Java, and write > > tests for the ported code. ?(Yes, I've considered finding myself > > another job, but this is not an option in the immediate future.) > > > What's giving me the hardest time is that the original Python code > > uses a lot of functions with optional arguments (as is natural to > > do in Python). > > > As far as I can tell (admittedly I'm no Java expert, and have not > > programmed in it since 2001), to implement a Java method with n > > optional arguments, one needs at least 2**n method definitions. > > Even if all but one of these definitions are simple wrappers that > > call the one that does all the work, it's still a lot of code to > > wade through, for nothing. > > > That's bad enough, but even worse is writing the unit tests for > > the resulting mountain of fluffCode. ?I find myself writing test > > classes whose constructors also require 2**n definitions, one for > > each form of the function to be tested... > > > I ask myself, how does the journeyman Python programmer cope with > > such nonsense? > > > For the sake of concreteness, consider the following run-of-the-mill > > Python function of 3 arguments (the first argument, xs, is expected > > to be either a float or a sequence of floats; the second and third > > arguments, an int and a float, are optional): > > > ? ? def quant(xs, nlevels=MAXN, xlim=MAXX): > > ? ? ? ? ?if not hasattr(xs, '__iter__'): > > ? ? ? ? ? ? ?return spam((xs,), n, xlim)[0] > > > ? ? ? ? ?if _bad_quant_args(xs, nlevels, xlim): > > ? ? ? ? ? ? ?raise TypeError("invalid arguments") > > > ? ? ? ? ?retval = [] > > ? ? ? ? ?for x in xs: > > ? ? ? ? ? ? ?# ... > > ? ? ? ? ? ? ?# elaborate acrobatics that set y > > ? ? ? ? ? ? ?# ... > > ? ? ? ? ? ? ?retval.append(y) > > > ? ? ? ? ?return retval > > > My Java implementation of it already requires at least 8 method > > definitions, with signatures: > > [snip] > > I would declare: > > ? ? ? short[] quant (float[], int ? ?, float) > ? ? ? short ? quant (Float ?, Integer, Float) > > and see how it goes. > > "float" and "int" should be boxed to "Float" and "Integer" > automatically. > > If the second and third arguments are frequently the default, then I > would also declare: > > ? ? ? short[] quant (float[]) > ? ? ? short ? quant (Float ?) This seems to be a very good solution but I would replace basic types with wrappers short[] quant (float[], Integer, Float) short quant (Float , Integer, Float) When you implement those two methods (where you need to check if Integer, Float are not null) then you can define two more methods: short[] quant (float[]) { return quant (float[], null, null); } short quant (float) { return quant (float, null, null); } That gives you 2 methods for unit testing. From fab at slick.airforce-one.org Sat Aug 13 11:21:01 2011 From: fab at slick.airforce-one.org (fab at slick.airforce-one.org) Date: 13 Aug 2011 15:21:01 GMT Subject: Dialog boxes in curses Message-ID: <4e46965d$0$23647$426a74cc@news.free.fr> Hello. I've googled for hints but I didn't find anything, I hope it's not an RTFM question :^) I want to have dialog boxes (a message with Yes/No/Cancel options, possibly with keyboard accels) in python + curses. Does anyone have a pointer to docs about this? Thanks! -- F. Delente From irmen.NOSPAM at xs4all.nl Sat Aug 13 11:37:50 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 13 Aug 2011 17:37:50 +0200 Subject: Dialog boxes in curses In-Reply-To: <4e46965d$0$23647$426a74cc@news.free.fr> References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> On 13-8-2011 17:21, fab at slick.airforce-one.org wrote: > Hello. > > I've googled for hints but I didn't find anything, I hope it's not an > RTFM question :^) > > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. > > Does anyone have a pointer to docs about this? > > Thanks! > Have you considered using Urwid instead? http://excess.org/urwid/ Irmen From nicholas.cole at gmail.com Sat Aug 13 11:49:48 2011 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sat, 13 Aug 2011 16:49:48 +0100 Subject: Dialog boxes in curses In-Reply-To: <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> References: <4e46965d$0$23647$426a74cc@news.free.fr> <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sat, Aug 13, 2011 at 4:37 PM, Irmen de Jong wrote: > On 13-8-2011 17:21, fab at slick.airforce-one.org wrote: >> Hello. >> >> I've googled for hints but I didn't find anything, I hope it's not an >> RTFM question :^) >> >> I want to have dialog boxes (a message with Yes/No/Cancel options, >> possibly with keyboard accels) in python + curses. >> >> Does anyone have a pointer to docs about this? >> >> Thanks! Or have a look at code.google.com/p/npyscreen Nicholas From k.sahithi2862 at gmail.com Sat Aug 13 12:04:00 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 13 Aug 2011 09:04:00 -0700 (PDT) Subject: ADULT FAVORATE BLOG Message-ID: <99352756-32b7-4daf-94e4-2999f8f1114f@m4g2000pri.googlegroups.com> HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html NAYANTHARA HOT PHOTOS http://southactresstou.blogspot.com/2011/08/nayanthara.html LATEST HOT TAPSEE KISSING STILLS http://southactresstou.blogspot.com/2011/06/tapsee.html KAJAL AGARWAL ROMANTIC STILLS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html TAMANNA BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/05/tamanna.html ANUSHKA SHETTY HOT SAREE STILLS http://southactresstou.blogspot.com/2011/06/anushka-shetty.html SNEHA RARE PHOTOS http://southactresstou.blogspot.com/2011/05/sneha.html NAMITHA HOT NAVEL SHOW http://southactresstou.blogspot.com/2011/05/namitha.html ILIYANA HOT WALLPAPERS http://southactresstou.blogspot.com/2011/05/iliyana.html PRIYAMANI LATEST SPICY PHOTOS http://southactresstou.blogspot.com/2011/05/priyamani.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT SEXY PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From thorsten at thorstenkampe.de Sat Aug 13 13:43:13 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 13 Aug 2011 19:43:13 +0200 Subject: Dialog boxes in curses References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: * fab at slick.airforce-one.org (13 Aug 2011 15:21:01 GMT) > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. Use Python Dialog[1] which is basically a wrapper for dialog boxes around ncurses. Thorsten [1] http://pythondialog.sourceforge.net/ From fab at slick.airforce-one.org Sat Aug 13 14:38:57 2011 From: fab at slick.airforce-one.org (fab at slick.airforce-one.org) Date: 13 Aug 2011 18:38:57 GMT Subject: Dialog boxes in curses References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: <4e46c4c1$0$4541$426a34cc@news.free.fr> Thanks all for your suggestions, I'll look into them. See you. -- F. Delente From tdsimpson at gmail.com Sat Aug 13 15:14:14 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 12:14:14 -0700 (PDT) Subject: How do I convert String into Date object Message-ID: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Is this the correct way to convert a String into a Date? I only have dates and no time. import time, datetime oDate = time.strptime('07/27/2011', '%m/%d/%Y') print oDate Thanks, From tdsimpson at gmail.com Sat Aug 13 15:26:25 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 12:26:25 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> I have file of records delimited by spaces. I need to import the date string and convert them into date datatypes. '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' I just discovered that my oDate is not an object, but a structure and not a date datatype. I'm stumped. Is there a way to convert a string into a date datatype for comparisons, equality, etc? Thanks, On Aug 13, 3:14?pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, From nulla.epistola at web.de Sat Aug 13 16:05:33 2011 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 13 Aug 2011 22:05:33 +0200 Subject: How do I convert String into Date object In-Reply-To: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: Am 13.08.2011 21:26, schrieb MrPink: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > There is. Only not in one step, if you want a date and not a datetime instance: >>> import datetime >>> oDateTime = datetime.datetime.strptime('07/27/2011', '%m/%d/%Y') >>> oDateTime datetime.datetime(2011, 7, 27, 0, 0) >>> oDate = oDateTime.date() >>> oDate datetime.date(2011, 7, 27) >>> HTH Sibylle From clp2 at rebertia.com Sat Aug 13 16:09:13 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Aug 2011 13:09:13 -0700 Subject: How do I convert String into Date object In-Reply-To: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: On Sat, Aug 13, 2011 at 12:14 PM, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate from datetime import datetime the_date = datetime.strptime('07/27/2011', '%m/%d/%Y').date() Cheers, Chris From rafadurancastaneda at gmail.com Sat Aug 13 16:11:00 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sat, 13 Aug 2011 22:11:00 +0200 Subject: How do I convert String into Date object In-Reply-To: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: <4E46DA54.4050504@gmail.com> You can use datetime objects: >>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") >>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") >>> dt1 == dt2 False >>> dt1 > dt2 False >>> dt1 < dt2 True >>> dt1 - dt2 datetime.timedelta(-1) On 13/08/11 21:26, MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > > Thanks, > > On Aug 13, 3:14 pm, MrPink wrote: >> Is this the correct way to convert a String into a Date? >> I only have dates and no time. >> >> import time, datetime >> >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') >> print oDate >> >> Thanks, From tdsimpson at gmail.com Sat Aug 13 16:25:07 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 13:25:07 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: BTW, here is the Python version I'm using. Will this make a difference with the solutions you guys provided? Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Also, what editor do you guys use? There are so many to chose from. On Aug 13, 4:11?pm, Rafael Dur?n Casta?eda wrote: > You can use datetime objects: > > ?>>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") > ?>>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") > ?>>> dt1 == dt2 > False > ?>>> dt1 > dt2 > False > ?>>> dt1 < dt2 > True > ?>>> dt1 - dt2 > datetime.timedelta(-1) > > On 13/08/11 21:26, MrPink wrote: > > > > > > > > > I have file of records delimited by spaces. > > I need to import the date string and convert them into date datatypes. > > > '07/27/2011' 'Event 1 Description' > > '07/28/2011' 'Event 2 Description' > > '07/29/2011' 'Event 3 Description' > > > I just discovered that my oDate is not an object, but a structure and > > not a date datatype. > > I'm stumped. ?Is there a way to convert a string into a date datatype > > for comparisons, equality, etc? > > > Thanks, > > > On Aug 13, 3:14 pm, MrPink ?wrote: > >> Is this the correct way to convert a String into a Date? > >> I only have dates and no time. > > >> import time, datetime > > >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') > >> print oDate > > >> Thanks, From __peter__ at web.de Sat Aug 13 16:29:35 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Aug 2011 22:29:35 +0200 Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > > Thanks, > > On Aug 13, 3:14 pm, MrPink wrote: >> Is this the correct way to convert a String into a Date? >> I only have dates and no time. >> >> import time, datetime That looks like a fifty-percent chance to try the "wrong" module ;) >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') >> print oDate >>> import datetime as dt >>> d = dt.date.strptime("07/27/2011", "%m/%d/%Y") Traceback (most recent call last): File "", line 1, in AttributeError: type object 'datetime.date' has no attribute 'strptime' So you cannot construct a date from a date string either. One more time: >>> d = dt.datetime.strptime("07/27/2011", "%m/%d/%Y") >>> d datetime.datetime(2011, 7, 27, 0, 0) >>> d.date() datetime.date(2011, 7, 27) $ cat csv_dates.csv '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' $ cat csv_dates.py import datetime import csv def rows(instream): for row in csv.reader(instream, delimiter=" ", quotechar="'"): row[0] = datetime.datetime.strptime(row[0], '%m/%d/%Y').date() yield row if __name__ == "__main__": import sys filename = sys.argv[1] with open(filename, "rb") as instream: for row in rows(instream): print row $ python csv_dates.py csv_dates.csv [datetime.date(2011, 7, 27), 'Event 1 Description'] [datetime.date(2011, 7, 28), 'Event 2 Description'] [datetime.date(2011, 7, 29), 'Event 3 Description'] From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 13 17:39:26 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 13 Aug 2011 21:39:26 +0000 (UTC) Subject: Relative import from script with same name as package Message-ID: I'm using Python 2.6.5. I have a directory structure like this: thetest/ __init__.py thetest.py theother.py __init__.py is an empty file. theother.py contains a function foo(). The package is accessible from sys.path, so that if I open the interpreter and do "import thetest" or "from thetest import thetest" or "import thetest.thetest", it works fine. Inside thetest.py I have code like this: ### from __future__ import absolute_import if __name__ == "__main__" and __package__ is None: import thetest __package__ = "thetest" from .theother import foo ### Note that I need the "import thetest" line to avoid a "parent module not loaded" error, as described here: http://stackoverflow.com/questions/2943847/nightmare-with-relative- imports-how-does-pep-366-work If I run foo.py directly, I receive a traceback like this: Traceback (most recent call last): File "C:\...\thetest\thetest.py", line 4, in import thetest File "C:\...\thetest\thetest.py", line 11, in from .theother import foo ValueError: Attempted relative import in non-package It appears that Python is reading "import thetest" as importing thetest.py (the same file that is currently being run). When it tries to run that file a second time, the relative import fails. But why? That __future__ import is supposed to make absolute imports the default, so why is "import thetest" importing thetest.py instead of the package called thetest? The absolute import should make it look in sys.path first and not try to import from the script directory, right? If I change the outer directory name and change the code in thetest.py to match, it works fine. But I shouldn't have to do this. How can I get relative imports to work correctly when running a script whose filename is the same as that of the directory (and thus the package) in which it resides? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 13 19:55:38 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 13 Aug 2011 23:55:38 +0000 (UTC) Subject: Relative import from script with same name as package References: Message-ID: OKB (not okblacke) wrote: > But why? That __future__ import is supposed to make > absolute > imports the default, so why is "import thetest" importing > thetest.py instead of the package called thetest? The absolute > import should make it look in sys.path first and not try to import > from the script directory, right? > > If I change the outer directory name and change the code > in > thetest.py to match, it works fine. But I shouldn't have to do > this. How can I get relative imports to work correctly when > running a script whose filename is the same as that of the > directory (and thus the package) in which it resides? After a bit more googling I discovered the answer here: http://stackoverflow.com/questions/1959188/absolute-import-failing-in- subpackage-that-shadows-a-stdlib-package-name The deal is that sys.path by default has the empty string as the first element, which tells Python to look first in the directory of the script being executed. This is unfortunate, but can worked around this way: import sys sys.path = sys.path[1:] + [''] (That is, move the current directory to the end of the search path instead of the beginning.) -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From rosuav at gmail.com Sat Aug 13 20:07:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 01:07:40 +0100 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 12:55 AM, OKB (not okblacke) wrote: > sys.path = sys.path[1:] + [''] > > (That is, move the current directory to the end of the search path > instead of the beginning.) > Or, equivalently: sys.path.append(sys.path.pop(0)) ChrisA From roy at panix.com Sat Aug 13 20:49:06 2011 From: roy at panix.com (Roy Smith) Date: Sat, 13 Aug 2011 20:49:06 -0400 Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: In article <83822ecb-3643-42c6-a2bf-0187c07d351d at a10g2000yqn.googlegroups.com>, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. You have already received a number of good replies, but let me throw out one more idea. If you ever need to do something with dates and times which the standard datetime module can't handle, take a look at the excellent dateutil module by Gustavo Niemeyer (http://labix.org/python-dateutil). From rantingrick at gmail.com Sat Aug 13 21:25:56 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:25:56 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 12, 5:03?pm, Steven D'Aprano wrote: > Responding to Rick's standard {EDIT} posts > is like wrestling with a {EDIT} > [...] > Save yourself a lot of aggravation and kill-file him now. Kindly allow Walter E. Kurtz to shine some light on this situation: """ Pig after pig, cow after cow, village after village, army after army. And they call me an assassin. What do you call it when the assassins accuse the assassin? They lie.. they lie and we have to be merciful for those who lie. Those nabobs. I hate them. How I hate them...""" From rantingrick at gmail.com Sat Aug 13 21:50:55 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:50:55 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6696bd00-802c-4815-a4f0-b0c83a1babf0@l7g2000vbz.googlegroups.com> On Aug 12, 7:39?pm, Seebs wrote: > Well, that's the thing. > > In a case like: > > ? ? ? ? if foo: > ? ? ? ? ? ? ? ? if bar: > ? ? ? ? ? ? ? ? ? ? ? ? blah > ? ? ? ? blah > > I notice that *NOTHING* lines up with "if bar:". ?And that affects me > about the way unmatched brackets do. For me, i believe it was a grave mistake to allow "user defined indention" within a python module. Not only that, but allowing indentation to be inconsistent (within the same module) not only worse, it's insane! I could have "slightly" understood giving people a choice of how many indents to use however i cannot fathom the idiocy of allowing inconsistent indentation within the same module! Although GvR is no doubt a brilliant mind he keeps making the same mistakes over and over again in the name of muti-stylism. ?Ay, caramba! Not that i find it *impossible* to read inconsistent indentation mind you, but that i find it blasphemous to the name of consistency. Programming languages MUST be consistent. Python should allow one and only one obvious way to indent a block; whether it be by a single tab char or by four spaces i don't care! But for crikey's sake pick one of them and stick with it!!! From rantingrick at gmail.com Sat Aug 13 21:59:04 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:59:04 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <88b5a66f-3c8b-427e-b321-cde6d93b0483@a4g2000yqg.googlegroups.com> On Aug 12, 7:39?pm, Seebs wrote: > Consider the hypothetical array syntax: > > ? ? ? ? a = [ > ? ? ? ? ? ? 1, > ? ? ? ? ? ? 2 > ? ? ? ? b = [ > ? ? ? ? ? ? 3, > ? ? ? ? ? ? 4 > > This *bugs* me. ?It's perfectly legible, and if you define it that way, it's > unambiguous and everything, but... It bugs me. ?I want beginnings to have > an actual corresponding end. It "almost" seems as if you have a valid point here until you consider that conditionals and blocks are ridged structures that must be defined under a strict set of syntactical rules with keywords and indentation. Whereas the list, dict, set, and tuple absolutely MUST have an explicit beginning AND an explicit end due to their free-form nature. You could create some strict rules for defining "X-literals" and remove any need for start and end tags however i see no need to do so. From rantingrick at gmail.com Sat Aug 13 22:07:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 19:07:39 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 12, 7:39?pm, Seebs wrote: > I was overjoyed when I saw that Ruby would let me write 1_048_576. I'll have to admit that Ruby has a few very interesting ideas, this being one of them. We all know how impossible it can be to eyeball parse a very long number like this. Having the interpretor ignore underscores in a number was very wise indeed! However i really hate the fact that Ruby FORCES you to use OOP. I LOVE OOP, however there are times when you just don't need that level of machinery to solve a problem. A good example is when scripting an API. Most times all you need is a few module level procedures and some simple logic. Try that with Ruby, then try that with Python, you'll be switching to Python in no time! PS: And before any Matz lovers start complaining: Yes, i know you can do procedural programming with ruby HOWEVER it suffers many pitfall due to (1) Ruby's scoping issues and (2) Ruby's explicit module declaration (which is more indirect than the first). From rantingrick at gmail.com Sat Aug 13 22:18:29 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 19:18:29 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <8762eb2d-5578-4050-a762-6bf8b4dd1b3b@c29g2000yqd.googlegroups.com> On Aug 12, 4:06?pm, Seebs wrote: > On 2011-08-12, Chris Angelico wrote: > > > Why is left-to-right inherently more logical than > > multiplication-before-addition? > > I'd say it's certainly "more Pythonic in a vacuum". > Multiplication-before-addition, and all the related rules, require > you to know a lot of special rules which are not visible in the > code, and many of which have no real logical basis. ?Left-to-right > is, if nothing else, the way the majority of us read. > > The problem is that since everyone's used precedence before, not using > it violates the principle of least astonishment. And repeatedly propagating a foolish consistency is well, FOOLISH! This problem invades every aspect of technology. Who was the idiot that decided it was okay to close SOME html tag and NOT close others? Since HTML is made to be read by machines why the hell would someone knowingly induce disorder? Which then leads to needing more logic to parse? But even more insane is why HTML has been allowed to be so disorderly for so long. Where is the need to be consistent? I tell you how to solve this, you solve it with plagues. Plagues of syntax errors will teach the unrighteous the err of their ways. From gordon at panix.com Sat Aug 13 22:20:30 2011 From: gordon at panix.com (John Gordon) Date: Sun, 14 Aug 2011 02:20:30 +0000 (UTC) Subject: Data issues with Django and Apache Message-ID: I'm devleoping a website using the Django framework along with Apache, and I'm seeing some odd data issues. During the course of navigating through the website content, a user will cause the creation of some data records with a limited lifespan. These data records have a create_dt field which is automatically set to the time that they were created, and an expire_dt field which is equal to create_dt plus ten minutes. The problem is that I get conflicting results as to whether these temporary records have reached their expiration date, depending if I search for them via an Apache web call or if I do the search locally from a python shell. And to make it weirder, the conflicts go away if I stop and restart the Apache server, although any new records created after this point will still exhibit the issue. Are there any known "gotchas" when using Django with Apache? It almost seems like Apache is maintaining its own persistent session or something, and restarting Apache causes the session to be flushed. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tdsimpson at gmail.com Sun Aug 14 01:44:32 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 22:44:32 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: I found this solution. Python: Convert String Date to Date Object http://slaptijack.com/programming/python-convert-string-date-to-date-object/ On Aug 13, 3:14?pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, From rantingrick at gmail.com Sun Aug 14 01:57:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 22:57:46 -0700 (PDT) Subject: Ten rules to becoming a Python community member. Message-ID: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Follow these simply rules to become an accepted member of the Python community. ------------------------------------------------------------ 1. Bash rantingrick and Xah Lee every chance you get. 2. Bash people who bash rick or xah because their basing made rick's or xah's words pass through your spam filter. 3. Post links to xkcd as often as you can. Don't worry if they have been posted a thousand times, just post them because it equals "geek cool points". 4. When the chance presents itself, make snide comments about lisp and perl; but NEVER about Ruby! (even though Ruby is Perl's micro minion!). 5. Use fancy words like "tail recursion", just because you read about it on Guido's blog once (even if you have no idea what that means)! 6. Engage in heated and pointless discussions as to whether Python is "pass-by-reference" or "pass-by-value" even if you have no idea what the hell you are talking about. 7. Play devils advocate often e.g., If someone hates Tkinter: then argue how great Tkinter is regardless of how much you actually care, use, or know about the module. Likewise if someone likes Tkinter: then argue how terrible Tkinter is and how Python does not need any GUI library; again, regardless of how much you actually care, use, or know about the module. 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." more than ten times in a single post, you will get an invite to Guido's next birthday party; where you'll be forced to do shots whist walking the balcony railing wearing wooden shoes! 9. Never use the word "previously" or the phrase "in the past"; just dumb it down with "used to". 10. Finally, if you get caught using the word "that" incredibly excessively, just hope that nobody notices that that that you are really GvR in disguise. From steve+comp.lang.python at pearwood.info Sun Aug 14 03:10:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 14 Aug 2011 17:10:36 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I guess... The parser is explicitly pushing those tokens, but I can't > *SEE* those tokens. If I am looking at the end of a really long > thing, and I see: > > blah > blah > > I only know what's happening if I have absolute confidence that the > indentation is always by the same amount, etectera. I believe this is a dubious argument. With only two lines of code in isolation, understanding the indentation changes is the least of your worries. Adding block delimiters doesn't give you any significant help -- ESPECIALLY if the block delimiters don't align with the indentation! blah } blah } In isolation, you don't even know whether the above is syntactically valid, since you have no way of knowing that either end brace is closing an open brace or not. "Who would write such a horrible mis-aligned piece of code?" Good question. If you're going to have style-guides that prohibit writing code like the above, then what exactly do the braces give you? Yes, yes, if you paste the code into a web forum the indentation may disappear, and if your hard drive controller is faulty it may randomly overwrite blocks with data belonging to other files. We all agree that environments that destroy data are Bad. >> Yet another reason to consider brace languages harmful: they spoil the >> user's intuitive grasp of intuition as grouping. > > I assume you mean "indentation as grouping". Yes, sorry about that. > I'm... not sold on this. It's not that I don't see indentation as a kind > of grouping. It's just that I really, really, want groups to have ends. > > Consider the hypothetical array syntax: > > ????????a = [ > ???????? ? ?1, > ???????? ? ?2 > ????????b = [ > ???????? ? ?3, > ???????? ? ?4 > > This *bugs* me. It's perfectly legible, and if you define it that way, > it's > unambiguous and everything, but... It bugs me. I want beginnings to have > an actual corresponding end. Do you get worried by books if the last page doesn't include the phrase "The End"? These days, many movies include an extra clip following the credits. When the clip finishes, and the screen goes dark, how long do you sit waiting before you accept that the movie is over? *wink* The above example bugs me too, because it is too close to what I'm used to in Python. I see an open bracket, I wait for a close bracket. Perhaps this would be better: a = array 1, 2, b = array 3, 4, Not so bad now, I betcha. And you can nest arrays: c = array 5, 6, array 7, 8, 9, Now, I wouldn't actually recommend such a syntax for a programming language. (Maybe for a config file format?) It's too big and awkward for array literals in an expression. You can partly fix that by making the whitespace optional, allowing an array to be written on one line: a = array 1, 2 b = array 3, 4 but that screws up the ability to nest arrays. Also, what happens here? spam(a, b, array 5, 6) That's ambiguous -- does spam have three arguments or four? Again, easy enough to fix: spam(a; b; array 5; 6) # four args but you still can't nest arrays. This potential syntax doesn't feel like a unified whole, but like a bunch of unrelated fixes for problems. Sometimes a literal START and END delimiter is the right answer. Python's use of indentation to delimit blocks doesn't feel like that. Unlike arrays, you can't use blocks in an expression, and I think that's the factor which makes all the difference. Ruby folks may call the lack of block expressions a problem with Python, but even if they're right, I don't think it's a *big* problem. Either way, given the restriction that blocks are statements, not expressions, the lack of an overt block markers is not a problem for code (with the proviso that a rogue editor doesn't go making arbitrary changes to your source code). -- Steven From bahamutzero8825 at gmail.com Sun Aug 14 03:54:44 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 14 Aug 2011 02:54:44 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <4E477F44.1090107@gmail.com> On 2011.08.14 12:57 AM, rantingrick wrote: > Follow these simply rules to become an accepted member of the Python > community. Sounds good. You should consider submitting this as a PEP. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From usenet-nospam at seebs.net Sun Aug 14 04:07:03 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 08:07:03 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Steven D'Aprano wrote: > Seebs wrote: >> I guess... The parser is explicitly pushing those tokens, but I can't >> *SEE* those tokens. If I am looking at the end of a really long >> thing, and I see: >> >> blah >> blah >> >> I only know what's happening if I have absolute confidence that the >> indentation is always by the same amount, etectera. > I believe this is a dubious argument. With only two lines of code in > isolation, understanding the indentation changes is the least of your > worries. Adding block delimiters doesn't give you any significant help -- > ESPECIALLY if the block delimiters don't align with the indentation! > blah > } > blah > } Interesting. I am sort of getting to an insight into this, which I am not sure I can articulate. FWIW, I've had to debug C (well, C++) much worse than that (... long story, but rest assured, the lulz justified the effort of reading the transcendantly awful code). I could still do it. :) > In isolation, you don't even know whether the above is syntactically valid, > since you have no way of knowing that either end brace is closing an open > brace or not. Ahh, but the computer can tell me that. I don't have to see it. > "Who would write such a horrible mis-aligned piece of code?" Good question. > If you're going to have style-guides that prohibit writing code like the > above, then what exactly do the braces give you? I think what they give me is... basically a parity bit. It's easy for people to screw up code, such that the code written does not reflect intent. Braces give me a likely red flag -- if they are screwed up, I know that this is a good palce to start looking. If they're not, then all they're costing me is a little vertical space. > Yes, yes, if you paste the code into a web forum the indentation may > disappear, and if your hard drive controller is faulty it may randomly > overwrite blocks with data belonging to other files. We all agree that > environments that destroy data are Bad. "Destroy data" is a sort of fungible concept. I was reading a comic book recently and it contained a URL for a poem which had been parodied. The URL had been hand-lettered... in block capitals. The actual URL had exactly one upper case letter in it. Whoops. In general, I don't think all data-loss is identical in severity. Outside of Python and Makefiles, I don't use anything where whitespace damage of the sort of "losing or changing leading spaces" is usually significant, so I *normally* regard it as a trivial change. > Do you get worried by books if the last page doesn't include the phrase "The > End"? These days, many movies include an extra clip following the credits. > When the clip finishes, and the screen goes dark, how long do you sit > waiting before you accept that the movie is over? > *wink* It's an actual thing I have been bitten by, especially because I often really enjoy those clips, and I've seen a movie that had two. > The above example bugs me too, because it is too close to what I'm used to > in Python. I see an open bracket, I wait for a close bracket. Perhaps this > would be better: > a = array > 1, > 2, > b = array > 3, > 4, > Not so bad now, I betcha. Interesting! For me this triggers the same "WHERE IS THE END MARKER???" reflex. These bug me like unmatched brackets. > but you still can't nest arrays. This potential syntax doesn't feel like a > unified whole, but like a bunch of unrelated fixes for problems. Sometimes > a literal START and END delimiter is the right answer. I think so. > Python's use of indentation to delimit blocks doesn't feel like that. Unlike > arrays, you can't use blocks in an expression, and I think that's the > factor which makes all the difference. Ruby folks may call the lack of > block expressions a problem with Python, but even if they're right, I don't > think it's a *big* problem. I actually really *like* that Ruby and Lua let pretty much everything just be an expression. I was utterly dumbfounded when I found out that "print" in Python is a kind of statement, not a function or something comparable. (This seems to have changed recentlyish.) > Either way, given the restriction that blocks > are statements, not expressions, the lack of an overt block markers is not > a problem for code (with the proviso that a rogue editor doesn't go making > arbitrary changes to your source code). Yeah. I suspect that if I'd never used something with braces, I might not mind as much, but the kinds of errors I've had would probably still be issues. Say I try to indent or outdent something and I grab the wrong set of lines. It's certainly possible for this to result in valid code... And I have no cue as to what happened. Even if I get a warning, I can't necessarily tell what happened. To some extent, I think I like braces for the same reason I like to use ECC memory whenever hardware supports it, and I prefer hardware that supports it. Yes, they're only really useful to me when Something Goes Wrong (or to accommodate my fussy brain), but something goes wrong often enough that I derive a lot of benefit from that. Refactoring C or Ruby is easy for me. Refactoring Python is hard for me. I really do rely on visible markers to sanity-check the boundaries of what I'm indenting or outdenting. If I do something in my editor and end up with: foo.each do |bar| bar.do_a_thing do_something_with(bar) end next_thing something else I know immediately that it's wrong. If I do something in my editor and end up with: if foo: bar.do_a_thing do_something_with(bar) next_thing something else I can't immediately see that I hit the wrong number key when telling the editor how many lines to adjust. Typos happen. I rely heavily on things that let me catch them in as many ways as possible. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 04:07:04 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 08:07:04 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On 2011-08-14, rantingrick wrote: > Follow these simply rules to become an accepted member of the Python > community. > 1. Bash rantingrick and Xah Lee every chance you get. ... If I'd known you were in the same category as him, I wouldn't have needed to wait until now to know to plonk you. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Sun Aug 14 04:34:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 09:34:26 +0100 Subject: allow line break at operators In-Reply-To: <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano wrote: > Do you get worried by books if the last page doesn't include the phrase "The > End"? These days, many movies include an extra clip following the credits. > When the clip finishes, and the screen goes dark, how long do you sit > waiting before you accept that the movie is over? > > *wink* > You wait for the house lights to come up. That's your ending signal. As is often said in live theatre: "House lights, warmers, thank you gentlemen, going off cans!" It still has an end marker. On Sun, Aug 14, 2011 at 9:07 AM, Seebs wrote: > I actually really *like* that Ruby and Lua let pretty much everything just > be an expression. I was utterly dumbfounded when I found out that "print" > in Python is a kind of statement, not a function or something comparable. > (This seems to have changed recentlyish.) Yes. Not everything's an expression; a block of code is not an expression that returns a code object, and variable assignment is a statement. Some day, I'd like to play around with a language where everything's an expression and yet it doesn't look like LISP - just for the fun of it. It probably won't be any more useful for real world coding, but it'd be fun to tinker with. ChrisA From jabba.laci at gmail.com Sun Aug 14 04:41:12 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 14 Aug 2011 10:41:12 +0200 Subject: monitor mouse coordinates in real-time Message-ID: Hi, I wrote a simple GUI with pygtk to monitor mouse coordinates in real-time. It works but when I close the application, the thread doesn't stop and I can't figure out how to terminate it. Here is the current source: https://gist.github.com/1144708 (83 lines). Could you please help me out how to close the application correctly? Thanks, Laszlo From clp2 at rebertia.com Sun Aug 14 04:44:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 01:44:05 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 1:34 AM, Chris Angelico wrote: > Yes. Not everything's an expression; a block of code is not an > expression that returns a code object, and variable assignment is a > statement. Some day, I'd like to play around with a language where > everything's an expression and yet it doesn't look like LISP - just > for the fun of it. It probably won't be any more useful for real world > coding, but it'd be fun to tinker with. I've heard that Dylan is supposedly Lisp, sans parens. http://en.wikipedia.org/wiki/Dylan_(programming_language) Cheers, Chris From ben+python at benfinney.id.au Sun Aug 14 05:25:39 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Aug 2011 19:25:39 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9ke44s.fsf@benfinney.id.au> Seebs writes: > I was utterly dumbfounded when I found out that "print" in Python is a > kind of statement, not a function or something comparable. (This seems > to have changed recentlyish.) It has long been recognised as a wart, but it required waiting for an opportunity for breaking backward compatibility (the Python 2 ? 3 transition) to fix it. If you can't yet switch to Python 3, you can explicitly ask for ?print? as a function in Python 2.6 or later. More at . -- \ ?The generation of random numbers is too important to be left | `\ to chance.? ?Robert R. Coveyou | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Aug 14 05:27:55 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Aug 2011 19:27:55 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pqk8e410.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano > wrote: > > Do you get worried by books if the last page doesn't include the > > phrase "The End"? These days, many movies include an extra clip > > following the credits. When the clip finishes, and the screen goes > > dark, how long do you sit waiting before you accept that the movie > > is over? > You wait for the house lights to come up. That's your ending signal. You mean people still watch movies in theatres? The house lights need to be controlled by someone who knows when the movie's end signal should be sent. What is our ending signal if we're watching it from media in our home, and no-one in the house knows when the movie ends? -- \ ?The best way to get information on Usenet is not to ask a | `\ question, but to post the wrong information.? ?Aahz | _o__) | Ben Finney From tlikonen at iki.fi Sun Aug 14 05:46:50 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 14 Aug 2011 12:46:50 +0300 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87obzstjed.fsf@mithlond.arda> * 2011-08-14T09:34:26+01:00 * Chris Angelico wrote: > Some day, I'd like to play around with a language where everything's > an expression and yet it doesn't look like LISP - just for the fun of > it. It probably won't be any more useful for real world coding, but > it'd be fun to tinker with. Of course it's a useful feature. Basically you can put any Lisp code in the world in the place of a Lisp expression. (setf variable (handler-case (some-code) (foo-error () "value 1") (bar-error () "value 2"))) is something like variable = try: return some_code() except FooError: return "value 1" except BarError: return "value 2" Sure, it's not a necessary feature. All we need is the machine language, but other than that there are differences in how languages let programmers express themselves. The above example emphasizes that "'variable' is being assigned". The "how" part gets less weight. If we put the assignment inside the handler-case or try-except forms we get the same result technically but the variable assignment becomes more hidden and is repeated, possibly several times. I understand that Python philosophy does not value freedom of expression that much. It values a general Pythonic rule which must obeyed and is called "readability". Other languages give too little or too much freedom. :-) From oktaysafak at superonline.com Sun Aug 14 05:57:06 2011 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 14 Aug 2011 12:57:06 +0300 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: <4E479BF2.4040205@superonline.com> 14.08.2011 00:39, OKB (not okblacke) yazm??: > I'm using Python 2.6.5. I have a directory structure like this: > > thetest/ > __init__.py > thetest.py > theother.py > > __init__.py is an empty file. theother.py contains a function foo(). > The package is accessible from sys.path, so that if I open the > interpreter and do "import thetest" or "from thetest import thetest" or > "import thetest.thetest", it works fine. It should. > > Inside thetest.py I have code like this: > > ### > from __future__ import absolute_import > > if __name__ == "__main__" and __package__ is None: > import thetest > __package__ = "thetest" > > from .theother import foo > ### > ... > > If I run foo.py directly, I receive a traceback like this: > Wait! What's foo.py? I guess you mean thetest.py as you say "(the same file that is currently being run)" below. > Traceback (most recent call last): > File "C:\...\thetest\thetest.py", line 4, in > import thetest > File "C:\...\thetest\thetest.py", line 11, in > from .theother import foo > ValueError: Attempted relative import in non-package > > It appears that Python is reading "import thetest" as importing > thetest.py (the same file that is currently being run). When it tries > to run that file a second time, the relative import fails. > No, there is no such thing happening. Read the error message more carefully: the error happens when your code reaches the line "from .theother import foo", and it fails because you are trying to execute an "explicit" relative import statement (with leading dot notation) as introduced by PEP 328. What you see is perfectly expected behaviour as explained in detail in the PEP because the python interpreter can only make sense of that statement if that code is *imported* for use by code that resides *outside* the package. That error message is what you see when you try to *run* a package member module which uses explicit relative imports. Let me try to explain a bit further: You say that your package is accessible from sys.path. So let's say you fire up your interpreter and type import thetest.thetest Here the interpreter first imports the *package* thetest and then the module *thetest.py*, therefore it knows that the module is a member of the package. And when executing the code in the module thetest.py, it can make sense of the leading dot in "import .theother", it can see that the leading dot means the packege thetest and find the right module inside that package. But when you run thetest.py directly, the interpreter has no idea what the leading dot means because it has not imported any package beforehand. So it complains about that. > But why? That __future__ import is supposed to make absolute > imports the default, so why is "import thetest" importing thetest.py > instead of the package called thetest? This is not what is happening. > The absolute import should make > it look in sys.path first and not try to import from the script > directory, right? As I explained above, that's not the error but I think this sentence shows your misunderstanding of this relative imports issue. Never mind, I found the documentation very confusing at first and took me a great deal of effort to finally "get it". Let me share my "distilled wisdom" about this: - First of all, never perform your experiments about relative/absolute imports using IDLE! I guess IDLE has its own path manipulation that doesn't do *the right thing*. - "Absolute import" means importing from sys.path only. - "Relative import" means a "package member" module importing another "package member", using a not fully qualified name (i.e X.Y.a importing X.Y.b as import b, instead of using import X.Y.b). When Python saw (before PEP 328) "import b" or "from b import ..." *in a package member*, it first imported the local b if available. (This business of a package member importing another package member is called relative import, only) Since this had the same notation (syntax) with other (non package member) imports, intra-package imports were considered "ambiguous" when the module to be imported had the same name with a module reachable from sys.path: it was not immediately clear which one was meant for untrained eyes. Also, it had the potential of shadowing a stdlib module: in that case no clean method of getting at the stdlib module was available. - PEP 328 is about giving "relative imports" a new syntax so that this ambiguity no longer exists and the possibility of shadowing a stdlib module is removed altogether. The new syntax is called "*explicit* relative imports". The former method can thus be called "implicit relative imports" or "ambiguous relative imports" - BIG SOURCE OF CONFUSION: Relative imports (both implicit and explicit) is all about imports *inside* packages. When you have 2 scripts app.py and string.py sitting in a *non-package* folder (they are called top-level modules), that folder is always the first entry in sys.path when you run either of those modules directly, so "import string" in app.py will always import the string.py in that folder, not the stdlib one. (But not when you try with IDLE!) In this case, if you really want the standard module, you must manipulate sys.path before your import statement (or change the name of your local string.py). THE PEP (328) HAS NO EFFECT IN THAT CASE! - So, "relative imports" is not a concept introduced by PEP 328, it means "importing a package member from another member of that package" and it existed well before PEP 328. But its syntax was ambiguous so it was clarified by PEP 328 by giving it a special syntax (the leading dot notation). But that change introduced many small gotchas, including the one you are seeing: you can't directly run a package member module if you have used this new syntax (leading dot notation) in it. It works fine only when you import the package members for use by a module outside of that package. This of course brings difficulties with testing but it is another story. I think you will now find it much easier to get what PEP 328 is all about. Oktay From ethan at stoneleaf.us Sun Aug 14 06:51:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 14 Aug 2011 03:51:52 -0700 Subject: allow line break at operators In-Reply-To: <87pqk8e410.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87pqk8e410.fsf@benfinney.id.au> Message-ID: <4E47A8C8.4090602@stoneleaf.us> Ben Finney wrote: > Chris Angelico writes: > >> On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano >> wrote: > >>> Do you get worried by books if the last page doesn't include the >>> phrase "The End"? These days, many movies include an extra clip >>> following the credits. When the clip finishes, and the screen goes >>> dark, how long do you sit waiting before you accept that the movie >>> is over? > >> You wait for the house lights to come up. That's your ending signal. > > You mean people still watch movies in theatres? Yup! Not often, but it's fun once in a while. > The house lights need to be controlled by someone who knows when the > movie's end signal should be sent. What is our ending signal if we're > watching it from media in our home, and no-one in the house knows when > the movie ends? If it's a tape, it'll stop, or start rewinding; if it's a DVD it'll go back to the open page. :) ~Ethan~ From no at nowhere.net.no Sun Aug 14 06:54:54 2011 From: no at nowhere.net.no (TheSaint) Date: Sun, 14 Aug 2011 18:54:54 +0800 Subject: indentation References: Message-ID: Amit Jaluf wrote: > is it necessary indentation in python ? > Try without and report it From alister.ware at ntlworld.com Sun Aug 14 06:58:25 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 14 Aug 2011 10:58:25 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Sun, 14 Aug 2011 02:54:44 -0500, Andrew Berg wrote: > On 2011.08.14 12:57 AM, rantingrick wrote: >> Follow these simply rules to become an accepted member of the Python >> community. > Sounds good. You should consider submitting this as a PEP. That would mark the first constructive action from rantingnick ever Surely that would mark the end of the sentient universe? -- The deafening silence taught me not to ask a bunch of geeks for advice from their girlfriends From no at nowhere.net.no Sun Aug 14 07:00:05 2011 From: no at nowhere.net.no (TheSaint) Date: Sun, 14 Aug 2011 19:00:05 +0800 Subject: monitor mouse coordinates in real-time References: Message-ID: Jabba Laci wrote: > Could you please help me out how to close the application correctly? > I think you should put a flag into the code, which the parent might modify it, so it will tell the child process to quit. Then the flag should need to be read periodically to know whether is time to quit. From rosuav at gmail.com Sun Aug 14 07:59:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 12:59:55 +0100 Subject: allow line break at operators In-Reply-To: <87pqk8e410.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87pqk8e410.fsf@benfinney.id.au> Message-ID: On Sun, Aug 14, 2011 at 10:27 AM, Ben Finney wrote: > The house lights need to be controlled by someone who knows when the > movie's end signal should be sent. What is our ending signal if we're > watching it from media in our home, and no-one in the house knows when > the movie ends? > If you're watching it from your own media, you'll come to the end of the file/DVD/whatever and VLC will know. End-of-file is a well-known condition with well-defined semantics. :) And in the theatre, there's a definition of the end based on the origin of the material (the stage manager's script/music score, or something). Yep, there's always an end marker somewhere. But we are now hopelessly off topic, I think! ChrisA From rosuav at gmail.com Sun Aug 14 08:08:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:08:16 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 11:58 AM, Alister Ware wrote: > That would mark the first constructive action from rantingnick ever > > Surely that would mark the end of the sentient universe? Only if he actually did it. Many's the time people have called for him to write a PEP, or (better still) to write some actual code. Unless, as seems likely, Ranting Rick is not his real name, I do not know that he has ever done so. (What sort of mother names her son "Ranting Rick", anyway?) ChrisA From abhishekjain.cooldude.93 at gmail.com Sun Aug 14 08:36:45 2011 From: abhishekjain.cooldude.93 at gmail.com (Abhishek Jain) Date: Sun, 14 Aug 2011 18:06:45 +0530 Subject: question Message-ID: Hello all, I wrote a python program to find the 1000th prime no. The program isn't working as it should be. Please tell what the error is: ## this is to find the 1000th prime number number = 3 while number < 10000: ###initialize stuff counter = 1 ###initializing list to check primarity factor = [] while counter!=(number/2): if number % counter == 0: factor = factor + [counter] counter = counter + 1 if len(factor) > 1: break elif counter == 1000: print number, number+=1 The program is printing all the prime nos. from 1009 to 9973. Please respond fast and give me the correct code with only simple functions as i am a beginner to python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Aug 14 08:41:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:41:09 +0100 Subject: question In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain wrote: > Please respond fast Just to let you know, this isn't usually the best way to ask for help. You're mostly there with the correct way to ask questions; you've posted your code, said what it ought to do, and said what it's actually doing; but I recommend a bit of patience. Also a better subject line would help. I'll respond to your actual question in a little while, but just thought I'd "respond fast" to that part. Chris Angelico From rosuav at gmail.com Sun Aug 14 08:47:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:47:44 +0100 Subject: question In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain wrote: > ## this is to find the 1000th prime number > > number = 3 > while number < 10000: > ??? ###initialize stuff > ??? counter = 1 I think your main problem here, and you have several, is with this variable 'counter'. Have a really good think about what the counter is supposed to do, and ensure that it's really doing it. If, as I suspect, it's meant to be counting prime numbers such that you print the thousandth, then you want to set it once, outside the loop, and increment it only when you find a prime number. (Point to note: The first prime number is 2, not 3.) You asked for code. This looks like a homework assignment, so I won't actually do your work for you, for that would defeat the purpose. But think about every variable you use, what it ought to be doing, and what it's actually doing. Step through the program in your own head, and be sure you fully understand what it's doing. Chris Angelico From irmen.NOSPAM at xs4all.nl Sun Aug 14 09:21:39 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 14 Aug 2011 15:21:39 +0200 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> On 14-8-2011 7:57, rantingrick wrote: > 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." > more than ten times in a single post, you will get an invite to > Guido's next birthday party; where you'll be forced to do shots whist > walking the balcony railing wearing wooden shoes! I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills for extra credit? Greetings from a Dutchman! Irmen From ron at bumpker.com Sun Aug 14 09:23:45 2011 From: ron at bumpker.com (Ronald Reynolds) Date: Sun, 14 Aug 2011 06:23:45 -0700 (PDT) Subject: pythonw.exe Message-ID: <1313328225.44793.YahooMailClassic@web1103.biz.mail.sk1.yahoo.com> Dear Python Friends: in my python directory there is a python.exe file which I understand completely but there is also a pythonw.exe DOS seems to honor the pythonw command (No error message) but nothing happens. What is pythonw.exe? Also is there a way to invoke idle from the DOS prompt? I tried idle filename.py and just idle. Is there any .exe for idle? Sincerely, 'Ron "bumpker" Reynolds' From rosuav at gmail.com Sun Aug 14 09:46:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 14:46:06 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong wrote: > On 14-8-2011 7:57, rantingrick wrote: >> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." >> more than ten times in a single post, you will get an invite to >> Guido's next birthday party; where you'll be forced to do shots whist >> walking the balcony railing wearing wooden shoes! > > I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills > for extra credit? > > Greetings from a Dutchman! Is partial credit available for part-Dutch people, e.g. those with at least two grandparents from Holland? (Couldn't resist sticking an e.g. in there, even though I know it's just feeding the troll...) Irmen, you definitely get bonus points for a .nl domain. ChrisA From irmen.NOSPAM at xs4all.nl Sun Aug 14 09:50:54 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 14 Aug 2011 15:50:54 +0200 Subject: pythonw.exe In-Reply-To: References: Message-ID: <4e47d2c0$0$23857$e4fe514c@news2.news.xs4all.nl> On 14-8-2011 15:23, Ronald Reynolds wrote: > Dear Python Friends: > in my python directory there is a python.exe file which I understand completely but there is also a pythonw.exe DOS seems to honor the pythonw > command (No error message) but nothing happens. What is pythonw.exe? > Also is there a way to invoke idle from the DOS prompt? I tried idle filename.py and just idle. Is there any .exe for idle? > > Sincerely, 'Ron "bumpker" Reynolds' pythonw.exe is the same as python.exe but it doesn't open a console window, and launches python in the background. This allows you to easily run background programs or GUI programs in a nicer way (without a dummy console window popping up). Idle has no .exe as far as I know but you can start it like this: pythonw -m idlelib.idle You could create an alias or batch file called 'idle' that does this. Irmen From steve+comp.lang.python at pearwood.info Sun Aug 14 10:26:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 00:26:45 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > "Destroy data" is a sort of fungible concept. I was reading a comic book > recently and it contained a URL for a poem which had been parodied. The > URL had been hand-lettered... in block capitals. The actual URL had > exactly one upper case letter in it. > > Whoops. Er, most URLs are case insensitive, at least the most common ones, including HTTP and HTTPS. So I don't quite see why you think this was a Whoops. > In general, I don't think all data-loss is identical in severity. Outside > of Python and Makefiles, I don't use anything where whitespace damage of > the sort of "losing or changing leading spaces" is usually significant, > so I *normally* regard it as a trivial change. Ys, nd n rdnry nglsh txt, th lss ar chng af vwls cn olsu b e trvl chng. But try that with your source code :) > I actually really *like* that Ruby and Lua let pretty much everything just > be an expression. I was utterly dumbfounded when I found out that "print" > in Python is a kind of statement, not a function or something comparable. > (This seems to have changed recentlyish.) Yes, print as a statement was a mistake. But assignment as a statement, not so much. Assignment as an expression in languages that have it tends to be associated with frequent errors. The way I see it, if something operates by side-effect, then it has no business being treated as an expression. I'm not even happy with the usual convention of Python functions that return None, such as list.sort() -- in my opinion, languages should have procedures which don't return anything, and can only be used as a statement, similar to Pascal procedures. (I'm prepared to make an exception for purely functional languages.) > Say I try to indent or outdent something and I grab the wrong set of > lines. It's certainly possible for this to result in valid code... And I > have no > cue as to what happened. Even if I get a warning, I can't necessarily > tell what happened. Then don't do that. I'm not impressed by arguments based on "but if I do something stupid, like select text with my eyes closed and reindent it without looking, I expect the compiler to save my bacon". In my opinion, it's not the compiler's job to protect you from errors caused by sheer carelessness at the keyboard. In any case, while reindenting an arbitrary set of lines may *possibly* result in valid code that runs but does the wrong thing, the likelihood of that happening is remote enough that I'm not going to lose any sleep over it. There are real-world scenarios involving such semantic errors involving indentation, but they're pretty rare. I think that six weeks of not having to type { } or BEGIN END around code blocks has saved far more time and effort than such errors have cost me in my entire history of Python programming. > Refactoring C or Ruby is easy for me. Refactoring Python is hard for me. > I really do rely on visible markers to sanity-check the boundaries of what > I'm indenting or outdenting. If I do something in my editor and end up > with: > > foo.each do |bar| > bar.do_a_thing > do_something_with(bar) > end > next_thing > something else > > I know immediately that it's wrong. How? What makes you so certain that next_thing and something else are supposed to be inside the loop? They don't even refer to bar. Even if they did, it's not a foolproof sign, although it is a good hint. Unless I understand the intent of the code, how can I tell whether the END token is in the right place or not? And if I understand the intent of the code, then the END token is redundant. > If I do something in my editor and end up with: > if foo: > bar.do_a_thing > do_something_with(bar) > next_thing > something else > > I can't immediately see that I hit the wrong number key when telling > the editor how many lines to adjust. > > Typos happen. I rely heavily on things that let me catch them in as many > ways as possible. I call that a poor user interface design. If you have to count the number of lines before applying an edit, instead of selecting a range of text, then you should stop using a tool that is stuck with a UI from the early 1980s. Please don't take this as an insult, because it is not meant as one, but it seems to me from this discussion that you're a more careless coder than I am[1], and you want more insurance to protect you from your own mistakes. Braces give you that insurance. I'm not saying I've never mis-indented a block of code, surely I must have. But if I did, it was so trivial to fix, and done so rarely, I've forgotten all about it. Consequently I don't want to pay the cost of that insurance, as little as it is, because I don't get the benefit of it -- for me, it's just redundant information that I have to type and read that provides no real benefit. And that's why I love Python, because it doesn't make my pay for insurance I don't need. [1] For some definition of "careless". -- Steven From nobody at nowhere.com Sun Aug 14 10:30:25 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 14 Aug 2011 15:30:25 +0100 Subject: pythonw.exe References: Message-ID: On Sun, 14 Aug 2011 06:23:45 -0700, Ronald Reynolds wrote: > in my python directory there is a python.exe file which I understand > completely but there is also a pythonw.exe DOS seems to honor the pythonw > command (No error message) but nothing happens. What is pythonw.exe? Windows distinguishes between "console" and "GUI" executables. python.exe is a console executable, pythonw.exe is a GUI executable. One difference is that GUI executables don't have stdin/stdout/stderr, so you can't use pythonw.exe as an interactive interpreter. The main use for pythonw.exe is if you write a GUI program in Python (using e.g. TkInter, wxPython, etc) and you want it to be able to run it from an icon (desktop, start menu) without it opening a console window (running a console executable from an icon will open a console window). > Also > is there a way to invoke idle from the DOS prompt? I tried idle > filename.py and just idle. Is there any .exe for idle? "C:\Program Files (x86)\Python27\Lib\idlelib\idle.py" filename.py ... or similar, depending upon where Python is installed. BTW, unless you're using Windows 95/98/ME, you don't have a "DOS Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. From 1248283536 at qq.com Sun Aug 14 10:50:12 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sun, 14 Aug 2011 22:50:12 +0800 Subject: login with urllib2 Message-ID: please to see my code: import urllib import urllib2 url = 'http://hi.baidu.com/' values = {'username' : '******','password' : '******' } data = urllib.urlencode(values) req = urllib2.Request(url,data) response = urllib2.urlopen(req) the_page = response.read() i can't to login ,why?username and password are right. any word appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafadurancastaneda at gmail.com Sun Aug 14 11:03:14 2011 From: rafadurancastaneda at gmail.com (=?UTF-8?B?UmFmYWVsIER1csOhbiBDYXN0YcOxZWRh?=) Date: Sun, 14 Aug 2011 17:03:14 +0200 Subject: login with urllib2 In-Reply-To: References: Message-ID: <4E47E3B2.2040609@gmail.com> I'm not sure but you probably need using HTTPS handler, but without exact error code/message... On 14/08/11 16:50, ???? wrote: > please to see my code: > import urllib > import urllib2 > > url = 'http://hi.baidu.com/' > values = {'username' : '******','password' : '******' } > > data = urllib.urlencode(values) > req = urllib2.Request(url,data) > response = urllib2.urlopen(req) > the_page = response.read() > > i can't to login ,why?username and password are right. > any word appreciated. From clp2 at rebertia.com Sun Aug 14 11:07:37 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 08:07:37 -0700 Subject: login with urllib2 In-Reply-To: References: Message-ID: 2011/8/14 ???? <1248283536 at qq.com>: > please to see my code: > import urllib > import urllib2 > > url = 'http://hi.baidu.com/' > values = {'username' : '******','password' : '******' } > > data = urllib.urlencode(values) > req = urllib2.Request(url,data) > response = urllib2.urlopen(req) > the_page = response.read() > > i can't to login ,why?username and password? are? right. > any word? appreciated. Use the URL specified as the
's action, which in this case is https://passport.baidu.com/?login , rather than the URL of the login page itself. The fields aren't called "username" and "password"; read the page's HTML. You'll also see that there are a few hidden form fields that are probably required. Finally, even if you fix these problems, the site could possibly block Python based on its User-agent header. Cheers, Chris -- http://blog.rebertia.com From kw at codebykevin.com Sun Aug 14 11:23:03 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 14 Aug 2011 11:23:03 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: I'd like to post a detailed response, e.g. a point-by-point engagement with Rantingrick's list, but as I lack time, this will have to suffice: http://xkcd.com/386/ There! Can I get my community pin now? :-) -- Kevin Walzer Code by Kevin http://www.codebykevin.com From roy at panix.com Sun Aug 14 11:35:21 2011 From: roy at panix.com (Roy Smith) Date: Sun, 14 Aug 2011 11:35:21 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Er, most URLs are case insensitive, at least the most common ones, including > HTTP and HTTPS. So I don't quite see why you think this was a Whoops. URLs are most certainly not case insensitive. Parts of them may be (i.e. the scheme and host parts), but not the stuff after the hostname. From rosuav at gmail.com Sun Aug 14 11:39:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 16:39:53 +0100 Subject: allow line break at operators In-Reply-To: <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano wrote: > Yes, print as a statement was a mistake. But assignment as a statement, not > so much. Assignment as an expression in languages that have it tends to be > associated with frequent errors. > > The way I see it, if something operates by side-effect, then it has no > business being treated as an expression. Wikipedia (that well-known authority) lists among examples of side effects both "write data to a display or file" and "modify one of its arguments". This strongly implies that print() is a function that operates by side-effect, just as the assignment operator (in languages in which it is one) does. Treating "a=5" as an expression with the value 5 is no more relying on side effects than having "print('asdf')" an expression with the value None. I believe that print-as-a-function is a Good Thing, mainly because it can be used as an argument to such as map. Somewhat silly/trivial example: msgs=["Hello","World"] list(map(print,msgs)) I'm aware that assignment-as-an-expression has plenty of risks associated with it (the main one being the classic C issue of assignment inside a conditional - a feature that I use frequently myself, but which trips plenty of people up), which is a strong argument for its remaining a statement, but side effects isn't on its own. ChrisA From rosuav at gmail.com Sun Aug 14 11:52:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 16:52:05 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 3:30 PM, Nobody wrote: > BTW, unless you're using Windows 95/98/ME, you don't have a > "DOS Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. > I don't see this as any sloppier than referring to "opening a prompt" when you mean "opening up a windowed command interpreter". The command interpreter in NT+ uses an interface that derives from the original DOS command interpreter, and a lot of people consider it to be as primitive (not realising that it has a lot of features, eg tab completion, that are WAY better even than command+doskey); it's a lot closer to Unix's bash than to MS-DOS's command. (I do prefer bash, though.) ChrisA From martin at v.loewis.de Sun Aug 14 12:27:31 2011 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 14 Aug 2011 18:27:31 +0200 Subject: Python 3.2.2rc1 Message-ID: <4E47F773.4080604@v.loewis.de> On behalf of the Python development team, I'm happy to announce the first release candidate of the Python 3.2.2 maintenance release (3.2.2rc1). Python 3.2.2 fixes `a regression `_ in the ``urllib.request`` module that prevented opening many HTTP resources correctly with Python 3.2.1. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * a much improved ssl module with support for SSL contexts and certificate hostname matching * a sysconfig module to access configuration information * additions to the shutil module, among them archive file support * many enhancements to configparser, among them mapping protocol support * improvements to pdb, the Python debugger * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Martin v. L?wis (on behalf of the entire python-dev team and 3.2's contributors) From jabba.laci at gmail.com Sun Aug 14 12:39:39 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 14 Aug 2011 18:39:39 +0200 Subject: monitor mouse coordinates in real-time In-Reply-To: References: Message-ID: I'm trying something similar. In the thread there is a variable which is modified by the parent. However, the thread doesn't quit the infinite loop. If someone could provide a patch, that'd be really useful. Thanks, Laszlo On Sun, Aug 14, 2011 at 13:00, TheSaint wrote: > Jabba Laci wrote: > >> Could you please help me out how to close the application correctly? >> > I think you should put a flag into the code, which the parent might modify > it, so it will tell the child process to quit. > Then the flag should need to be read periodically to know whether is time to > quit. > > -- > http://mail.python.org/mailman/listinfo/python-list > From kw at codebykevin.com Sun Aug 14 13:15:51 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 14 Aug 2011 13:15:51 -0400 Subject: os.system() on Windows in Tkinter app spawns console window In-Reply-To: References: Message-ID: <414ef$4e48029f$4275d90a$19723@FUSE.NET> On 8/13/11 1:15 AM, Nobody wrote: > On Fri, 12 Aug 2011 22:49:32 -0400, Kevin Walzer wrote: > >> I'm developing a Tkinter app for a Windows customer, and the app bundles >> several command-line tools (ported from Unix). I call out to these >> console tools from the Tkinter app via os.system(). However, in the >> frozen version of my app, when I call out to these tools, I get multiple >> console windows popping up. This is jarring to say the least. Is there >> any way to run the commands under the hood without the console/DOS >> windows popping up? > > Just a wild guess, but try explicitly redirecting the commands' > stdin/stdout/stderr. You might also consider using subprocess.call() > instead of os.system(). > I've gotten the CLI commands to execute silently by setting the window flags for subprocess as discussed here: http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/ These flags are apparently undocumented, but this solution works perfectly. Perhaps the flags should be better documented. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrick at gmail.com Sun Aug 14 13:21:59 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 10:21:59 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> On Aug 14, 12:57?am, rantingrick wrote: > 9. Never use the word "previously" or the phrase "in the past"; just > dumb it down with "used to". I had forgot to mention one other usage of "used to": WRONG: "I used to not like indention but know i am very used to it" RIGHT: "Previously i lamented forced indentation but i have since grown quite accustomed to it" Also the usage of "supposed to" is rather foolish. WRONG: "We are supposed to write clean code but i am not used to that" RIGHT: "We are required to write clean code however i am not accustom to that way of thinking. Gawd, sometimes i feel like i'm watching an episode of squidbillies when i read the this list. From steve+comp.lang.python at pearwood.info Sun Aug 14 13:24:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 03:24:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4804e2$0$29995$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article <4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Er, most URLs are case insensitive, at least the most common ones, >> including HTTP and HTTPS. So I don't quite see why you think this was a >> Whoops. > > URLs are most certainly not case insensitive. Parts of them may be > (i.e. the scheme and host parts), but not the stuff after the hostname. I stand corrected. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 14 13:26:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 03:26:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e48055b$0$29995$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano > wrote: >> Yes, print as a statement was a mistake. But assignment as a statement, >> not so much. Assignment as an expression in languages that have it tends >> to be associated with frequent errors. >> >> The way I see it, if something operates by side-effect, then it has no >> business being treated as an expression. > > Wikipedia (that well-known authority) lists among examples of side > effects both "write data to a display or file" and "modify one of its > arguments". [...] Good point. I withdraw my statement about things that operate about side-effects. -- Steven From rosuav at gmail.com Sun Aug 14 13:38:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 18:38:08 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 6:21 PM, rantingrick wrote: > > WRONG: "We are supposed to write clean code but i am not used to that" > RIGHT: "We are required to write clean code however i am not accustom > to that way of thinking. > Since when are we required to write clean code? If I write unclean code (that's code with an undivided hoof, if you're Jewish), or if I don't write code at all, will I be kicked from the group? I think you need to start a blog, Rick. You'd be easier to ignore. ChrisA From daniel at roseman.org.uk Sun Aug 14 14:12:15 2011 From: daniel at roseman.org.uk (Daniel Roseman) Date: Sun, 14 Aug 2011 11:12:15 -0700 (PDT) Subject: Data issues with Django and Apache In-Reply-To: References: Message-ID: <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1@glegroupsg2000goo.googlegroups.com> On Sunday, 14 August 2011 03:20:30 UTC+1, John Gordon wrote: > I'm devleoping a website using the Django framework along with Apache, > and I'm seeing some odd data issues. > > During the course of navigating through the website content, a user > will cause the creation of some data records with a limited lifespan. > These data records have a create_dt field which is automatically set to > the time that they were created, and an expire_dt field which is equal > to create_dt plus ten minutes. > > The problem is that I get conflicting results as to whether these temporary > records have reached their expiration date, depending if I search for them > via an Apache web call or if I do the search locally from a python shell. > > And to make it weirder, the conflicts go away if I stop and restart the > Apache server, although any new records created after this point will still > exhibit the issue. > > Are there any known "gotchas" when using Django with Apache? It almost > seems like Apache is maintaining its own persistent session or something, > and restarting Apache causes the session to be flushed. > > -- > John Gordon A is for Amy, who fell down the stairs > gor... at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Well, without seeing any code, it's hard to tell. And Apache (with mod_wsgi) is the recommended deployment method, so you can't really say there are gotchas. My guess is that you have not understood that server processes - and this is true on the dev server as well as on Apache - are not the same as requests. That is, server processes are long-lasting, and one process may end up serving tens or hundreds of requests before being recycled. So, if you have any code that runs at process startup - such as default values in class definitions or at module level - it will persist for all requests served by that process. Like I say, though, it would really help if you showed the relevant code. -- DR. From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Aug 14 14:48:46 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 14 Aug 2011 18:48:46 +0000 (UTC) Subject: Relative import from script with same name as package References: Message-ID: =?UTF-8?B?T2t0YXkgxZ5hZmFr?= wrote: >> It appears that Python is reading "import thetest" as >> importing >> thetest.py (the same file that is currently being run). When it >> tries to run that file a second time, the relative import fails. >> > > No, there is no such thing happening. Read the error message more > carefully: the error happens when your code reaches the line "from > .theother import foo", and it fails because you are trying to > execute an "explicit" relative import statement (with leading dot > notation) as introduced by PEP 328. What you see is perfectly > expected behaviour as explained in detail in the PEP because the > python interpreter can only make sense of that statement if that > code is *imported* for use by code that resides *outside* the > package. That error message is what you see when you try to *run* a > package member module which uses explicit relative imports. Let me > try to explain a bit further: Yes, such a thing was happening. (I described the fix in an answer to my own post.) You should read PEP 366 to understand what I was talking about, and what the __package__ variable does. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From usenet-nospam at seebs.net Sun Aug 14 15:01:57 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:57 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Chris Angelico wrote: > Yes. Not everything's an expression; a block of code is not an > expression that returns a code object, and variable assignment is a > statement. Some day, I'd like to play around with a language where > everything's an expression and yet it doesn't look like LISP - just > for the fun of it. It probably won't be any more useful for real world > coding, but it'd be fun to tinker with. Ruby and Lua are both pretty close. I'm not an expert in either, but I can't think of anything I can write in Ruby which isn't an expression. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 15:01:57 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:57 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Steven D'Aprano wrote: > Seebs wrote: >> "Destroy data" is a sort of fungible concept. I was reading a comic book >> recently and it contained a URL for a poem which had been parodied. The >> URL had been hand-lettered... in block capitals. The actual URL had >> exactly one upper case letter in it. > Er, most URLs are case insensitive, at least the most common ones, including > HTTP and HTTPS. So I don't quite see why you think this was a Whoops. Sort of. Host names are case insensitive, so far as I can tell "always". Paths past that are distinctly NOT always case insensitive, and since the server in question happened to be doing what appear to be "straight path lookups", it mattered a great deal that you had to downcase all but one of the letters. (The obvious technique of downcasing them all failed.) > Ys, nd n rdnry nglsh txt, th lss ar chng af vwls cn olsu b e trvl chng. > But try that with your source code :) Eh, I'm a C programmer, what makes you think I had any vowels to begin with? > Yes, print as a statement was a mistake. But assignment as a statement, not > so much. Assignment as an expression in languages that have it tends to be > associated with frequent errors. It does. I'm not sure whether the errors are compensated for by the expressiveness. I *think* on the whole they are, but I am honestly not sure. I do like gcc's warning for assignment used as a truth value. > The way I see it, if something operates by side-effect, then it has no > business being treated as an expression. Interesting! I tend to really like the ability to chain methods, depending on context. I find the side-effect/expression mix pretty normal, so I'm used to it. >> Say I try to indent or outdent something and I grab the wrong set of >> lines. It's certainly possible for this to result in valid code... And I >> have no >> cue as to what happened. Even if I get a warning, I can't necessarily >> tell what happened. > Then don't do that. If not doing that were a realistic option for me, I'm guessing I'd have stopped making typos thirty years ago. > I'm not impressed by arguments based on "but if I do something stupid, like > select text with my eyes closed and reindent it without looking, I expect > the compiler to save my bacon". In my opinion, it's not the compiler's job > to protect you from errors caused by sheer carelessness at the keyboard. I don't know about "sheer carelessness". Typos happen. Typos are not something you can prevent from happening just by wanting it very much. > In any case, while reindenting an arbitrary set of lines may *possibly* > result in valid code that runs but does the wrong thing, the likelihood of > that happening is remote enough that I'm not going to lose any sleep over > it. Ahh, but what about the case where it results in invalid code? It's not necessarily obvious which lines need to be moved after that. >> foo.each do |bar| >> bar.do_a_thing >> do_something_with(bar) >> end >> next_thing >> something else >> I know immediately that it's wrong. > How? The "end" is misaligned. Therefore SOMETHING is wrong. I don't know what, but I can be confident that something went wrong. > Unless I understand the intent of the code, how can I tell whether the END > token is in the right place or not? And if I understand the intent of the > code, then the END token is redundant. The question is not whether it's on the right line. No amount of indenting or outdenting can ever break that. The question is whether I've gotten the indentation screwed up. >> If I do something in my editor and end up with: >> if foo: >> bar.do_a_thing >> do_something_with(bar) >> next_thing >> something else >> I can't immediately see that I hit the wrong number key when telling >> the editor how many lines to adjust. >> Typos happen. I rely heavily on things that let me catch them in as many >> ways as possible. > I call that a poor user interface design. If you have to count the number of > lines before applying an edit, instead of selecting a range of text, then > you should stop using a tool that is stuck with a UI from the early 1980s. You keep telling me to stop using this editor. I have not seen a suggested improvement. (Hint: GUI editors are not an improvement for my purposes, as I do about 99.5% of my editing on machines that aren't in the same state that I am. No, the GUI editor cannot offer enough improvement in anything to justify the cost of copying files back and forth constantly.) > Please don't take this as an insult, because it is not meant as one, but it > seems to me from this discussion that you're a more careless coder than I > am[1], and you want more insurance to protect you from your own mistakes. > Braces give you that insurance. I have really, really, bad ADHD. When I was a kid a firecracker blew up in my hand because I *forgot* I was holding it. I'm not exactly "careless" in the pejorative sense (I don't accept the implication that it's a character flaw, but I don't think you intended it either), but functionally, I will make DOZENS of tiny errors per hour, and yes, I rely on having insurance against them. I don't really get a vote in this; I can either have insurance against them, never program at all, or spend a whole bunch of time trying to figure out what happened. > And that's why I love Python, because it doesn't make my pay for insurance I > don't need. I think that's pretty much the thing. I regard the "cost" of the insurance as completely nugatory, and I can identify dozens of times when it's saved me hours of effort on debugging code, whether mine or someone else's. And in general, I am a HUGE fan of things that offer a bit of insurance against otherwise-minor errors. If something can make a potentially severe problem into a trivial problem, that's usually a big attraction to me. So I think there are a couple of big personal-style questions influencing this. 1. Preference for "insurance"-type syntax -- stuff that may not be useful most of the time but will occasionally prevent failures. 2. Likelihood of "minor" formatting errors either in your direct work or in your larger environment (say, people mailing you code, use of web forum software, etc.) 3. General preferences for how things are structured. I strongly prefer explicit matching markers, and by "explicit" I mean *actual symbols you can see*. The way in which I view indentation as non-explicit is as follows: if foo: if bar: baz quux if foo: baz quux The two-tab outdent is either one or two outdents. I can't point to a specific character and say "this is *one* outdent". So it's not explicit. I really don't see why people insist on calling it explicit; it seems utterly unambiguous to me that it's not. I think... I mean, the thing about design philosophy, when you have several design philosophy rules, is that NONE of the rules get followed all the time. I think it'd be much more effective to say that one of the other rules won in this case than to try to convince people that a variable number of tokens occurring with no difference at all in the character stream is "explicit". -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 15:01:58 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:58 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87obzstjed.fsf@mithlond.arda> Message-ID: On 2011-08-14, Teemu Likonen wrote: > I understand that Python philosophy does not value freedom of expression > that much. It values a general Pythonic rule which must obeyed and is > called "readability". Other languages give too little or too much > freedom. :-) There is an interesting tradeoff, there, because I tend to find stuff like "variable = {fancy if expression}" to be much *more* readable, since I immediately get the top-level information ("we're assigning variable") and then I can look for details if I care. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From python.list at tim.thechases.com Sun Aug 14 15:50:35 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Aug 2011 14:50:35 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4E48270B.3010106@tim.thechases.com> On 08/14/2011 12:38 PM, Chris Angelico wrote: > On Sun, Aug 14, 2011 at 6:21 PM, rantingrick wrote: >> >> WRONG: "We are supposed to write clean code but i am not used to that" >> RIGHT: "We are required to write clean code however i am not accustom >> to that way of thinking. > > Since when are we required to write clean code? If I write unclean > code (that's code with an undivided hoof, if you're Jewish), or if I > don't write code at all, will I be kicked from the group? Any time your code sends Spam or is a resource hog, it would be unclean by both Jewish and Muslim anti-porcine standards :) > I think you need to start a blog, Rick. > > You'd be easier to ignore. +1 QOTW -tkc From thorsten at thorstenkampe.de Sun Aug 14 15:59:06 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 14 Aug 2011 21:59:06 +0200 Subject: pythonw.exe References: Message-ID: * Chris Angelico (Sun, 14 Aug 2011 16:52:05 +0100) > On Sun, Aug 14, 2011 at 3:30 PM, Nobody wrote: > > BTW, unless you're using Windows 95/98/ME, you don't have a "DOS > > Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. > > I don't see this as any sloppier than referring to "opening a > prompt" when you mean "opening up a windowed command > interpreter". You're misunderstanding what people mean by "DOS prompt". They don't mean "this is the DOS command shell", they mean "this is DOS". Thorsten From harmar at member.fsf.org Sun Aug 14 16:11:07 2011 From: harmar at member.fsf.org (harrismh777) Date: Sun, 14 Aug 2011 15:11:07 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: Chris Angelico wrote: >> I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills >> > for extra credit? >> > >> > Greetings from a Dutchman! > Is partial credit available for part-Dutch people, e.g. those with at > least two grandparents from Holland? > ... do we get extra credit for having our own shoes... my pair are official (e.g. hand-carved in Holland, with little windmills wood-burned on the bow... ) ... mine also have lambs wool lining... don't know it that adds anything official, but they sure feel great! kind r'gards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From harmar at member.fsf.org Sun Aug 14 16:20:54 2011 From: harmar at member.fsf.org (harrismh777) Date: Sun, 14 Aug 2011 15:20:54 -0500 Subject: pythonw.exe In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > You're misunderstanding what people mean by "DOS prompt". They don't > mean "this is the DOS command shell", they mean "this is DOS". ... yup, ... was helping my little sis with her iMac over the phone from four states away and had her open a terminal for some magic... and it took her exactly 1.03 seconds to say, "Oh, the iMac has DOS installed in the utilities folder!" :-O ... blondes... :-} (she tries hard, and actually has been learning, so, we keep trying...) -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From rosuav at gmail.com Sun Aug 14 16:28:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 21:28:23 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 9:20 PM, harrismh777 wrote: > ... yup, ... was helping my little sis with her iMac over the phone from > four states away and had her open a terminal for some ?magic... and it took > her exactly 1.03 seconds to say, "Oh, the iMac has DOS installed in the > utilities folder!" ? :-O > > ... blondes... ? :-} Just to confuse things even further, it's not unlikely that a Mac or Linux or Windows computer will have DOSBox installed. Is *that* DOS? Technically no, but practically yes. ChrisA From davea at ieee.org Sun Aug 14 17:46:03 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Aug 2011 17:46:03 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E48421B.2080201@ieee.org> On 01/-10/-28163 02:59 PM, Roy Smith wrote: > In article<4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Er, most URLs are case insensitive, at least the most common ones, including >> HTTP and HTTPS. So I don't quite see why you think this was a Whoops. > URLs are most certainly not case insensitive. Parts of them may be > (i.e. the scheme and host parts), but not the stuff after the hostname. > The thing that confuses people is that not only is the part up to and through the domain name is case-insensitive, but that simple pages on Windows become case-insensitive for the remainder simply because Windows is such. And the same page hosted on Linux would be case sensitive, per specification. The thing I find annoying is a host that decides that if a URL is close to an existing URL, it'll fix one or two "typos." To me, it's either right, or it's not. Don't change www.mydomain.com/page105.html to www/mydomain.com/page102.html and pretend it's "close enough." DaveA From davea at ieee.org Sun Aug 14 18:01:15 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Aug 2011 18:01:15 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4E4845AB.9020107@ieee.org> On 01/-10/-28163 02:59 PM, rantingrick wrote: > On Aug 14, 12:57 am, rantingrick wrote: > >> 9. Never use the word "previously" or the phrase "in the past"; just >> dumb it down with "used to". > I had forgot to mention one other usage of "used to": > > WRONG: "I used to not like indention but know i am very used to it" > RIGHT: "Previously i lamented forced indentation but i have since > grown quite accustomed to it" > > Also the usage of "supposed to" is rather foolish. > > WRONG: "We are supposed to write clean code but i am not used to that" > RIGHT: "We are required to write clean code however i am not accustom > to that way of thinking. > > Gawd, sometimes i feel like i'm watching an episode of squidbillies > when i read the this list. > > > Interesting that when you complain about other's grammatical typos, you're so careless with your own. know -> now i -> I accustom -> accustomed the this -> this I'm inclined to ignore typos in emails except in the case where the intent is to abuse others. DaveA From usenet-nospam at seebs.net Sun Aug 14 18:27:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 22:27:12 GMT Subject: pythonw.exe References: Message-ID: On 2011-08-14, Chris Angelico wrote: > Just to confuse things even further, it's not unlikely that a Mac or > Linux or Windows computer will have DOSBox installed. Is *that* DOS? > Technically no, but practically yes. Depending on how you define "unlikely", I'd guess it is. Assume that "unlikely" means roughly the equivalent of "if I were optimizing, I'd use a compiler branch prediction hint at this point". :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From roy at panix.com Sun Aug 14 18:46:24 2011 From: roy at panix.com (Roy Smith) Date: Sun, 14 Aug 2011 18:46:24 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Dave Angel wrote: > > URLs are most certainly not case insensitive. Parts of them may be > > (i.e. the scheme and host parts), but not the stuff after the hostname. > > > The thing that confuses people is that not only is the part up to and > through the domain name is case-insensitive, but that simple pages on > Windows become case-insensitive for the remainder simply because Windows > is such. Sure. But it's only in the most trivial of situations that URLs map in any trivial way to file names. > And the same page hosted on Linux would be case sensitive, per > specification. Well, I certainly could write an HTTP server on Linux which treated routes in a case-insensitive way. For example, if I do a GET on http://en.wikipedia.org/wiki/hypertext, I get redirected to http://en.wikipedia.org/wiki/Hypertext. On the other hand, http://en.wikipedia.org/WIKI/Hypertext gets me a 404. It's entirely up to the server to do whatever makes sense for that application. > The thing I find annoying is a host that decides that if a URL is close > to an existing URL, it'll fix one or two "typos." To me, it's either > right, or it's not. Don't change www.mydomain.com/page105.html > to www/mydomain.com/page102.html and pretend it's "close enough." Hosts don't decide anything. Applications running on those hosts decide things. Without knowing the application, it's impossible to say if this is the right thing to do or not. For example, it's good practice that if a URL ever worked in the past, you should keep that URL working, even if it becomes "obsolete". You might want to silently return some other page, or redirect the user to some other URL. This keeps bookmarks, existing links, cached search results, etc, from going stale. To use the wikipedia example again, there are lots of redirect entries, for other (perhaps incorrect) spellings, and so forth. For example, http://en.wikipedia.org/w/index.php?title=Taboule&redirect=no From oktaysafak at superonline.com Sun Aug 14 18:56:35 2011 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Mon, 15 Aug 2011 01:56:35 +0300 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: <4E4852A3.6010003@superonline.com> 14.08.2011 21:48, OKB (not okblacke) yazm??: > =?UTF-8?B?T2t0YXkgxZ5hZmFr?= wrote: > >>> It appears that Python is reading "import thetest" as >>> importing >>> thetest.py (the same file that is currently being run). When it >>> tries to run that file a second time, the relative import fails. >>> >> >> No, there is no such thing happening. Read the error message more >> carefully: the error happens when your code reaches the line "from >> .theother import foo", and it fails because you are trying to >> execute an "explicit" relative import statement (with leading dot >> notation) as introduced by PEP 328. What you see is perfectly >> expected behaviour as explained in detail in the PEP because the >> python interpreter can only make sense of that statement if that >> code is *imported* for use by code that resides *outside* the >> package. That error message is what you see when you try to *run* a >> package member module which uses explicit relative imports. Let me >> try to explain a bit further: > > Yes, such a thing was happening. (I described the fix in an > answer to my own post.) You should read PEP 366 to understand what I > was talking about, and what the __package__ variable does. > Hmmm, I have overlooked the middle part of your code. Now I get what you mean. Yes that is happening, you are right and I have given the source of that behaviour in my previous post: > - BIG SOURCE OF CONFUSION: Relative imports (both implicit and explicit) is all about imports *inside* packages. When you have 2 scripts app.py and string.py sitting in a *non-package* folder (they are called top-level modules), that folder is always the first entry in sys.path when you run either of those modules directly, so "import string" in app.py will always import the string.py in that folder, not the stdlib one. (But not when you try with IDLE!) In this case, if you really want the standard module, you must manipulate sys.path before your import statement (or change the name of your local string.py). THE PEP (328) HAS NO EFFECT IN THAT CASE! In your case, you are not using the package by importing its members from code outside the package but you are running them directly. So, your files thetest.py and theother.py are now *top-level* modules for the interpreter, not package members. So as per PEP 366, you need to add that boilerplate to set the __package__ attribute. But the "from __future__ import absolute_import" statement has no effect on the "import thetest" statement when you run the file directly: then thetest.py is a top level module, and when the interpreter encounters the statement "import thetest" *it is already absolute import* (whether you issed the __future__ statement or not). It still is in Python 2.7. PEP 328 has no effect in this case. Remember that absolute import means importing from sys.path only. In this case, thetest.py's folder is always the first entry in sys.path so it tries to import itself first. You would also see the same behaviour if your "import thetest" statement was in theother.py, it would import thetest.py rather than the package. So as I have said before and quoted above, in this case you have to manipulate sys.path, which you have found out yourself. So what is this "absolute import" thing that is introduced by PEP 328 then? It is all about import statements in package members when they are imported from code outside the package. Before PEP 328, if theother.py contained an "import thetest" statement and if you fired up your interpreter and issued import thetest.theother that "import thetest" in theother.py would find thetest.py. It was considered to be a(n implicit) package-relative import. After PEP 328, if you add to the top of theother.py or issue at the interpreter from __future__ import absolute_import and then issue import thetest.theother the "import thetest" statement in theother.py will find the *package* thetest because sys.path is given priority over the package dir by the __future__ statement. So the PEP has effectively overthrown the convention of treating such imports as special. They are not treated as special anymore and receive the same treatment as other imports. This is one aspect of the PEP. The PEP also defines a new notation (leading dot) for those who want the sibling thetest.py, which is another aspect. But when you run the theother.py directly, the PEP and the __future__ statement has NO EFFECT. The "import thetest" statement in theother.py is not seen as intra package import by the interpreter so it is already absolute import (uses sys.path) So it finds thetest.py because it is in the same folder as theother.py, which is the first folder in sys.path. Many people are confused and think that this is relative import. It's not. It is already absolute import (from sys.path) and the PEP has nothing to do with it. Now we can answer your critical question: > But why? That __future__ import is supposed to make absolute > imports the default, so why is "import thetest" importing thetest.py > instead of the package called thetest? Bacause you are running it directly and the PEP and the __future__ statement does not apply here. I hope it is clear now. -- Oktay ?afak From jhsu802701 at gmail.com Sun Aug 14 18:56:58 2011 From: jhsu802701 at gmail.com (Jason Hsu) Date: Sun, 14 Aug 2011 15:56:58 -0700 (PDT) Subject: Commands for changing ownership of a file Message-ID: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> I have a script that I execute as root, but I need to change the ownership of the files created in the script to that of my username. In GNU Bash, the command is something like "chown myusername:users". What's the equivalent Python command? I know that there is a command that uses numbers for the username and group, but is there a command that would allow me to use "myusername" and "users" instead of numbers? From rosuav at gmail.com Sun Aug 14 18:57:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 23:57:18 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4845AB.9020107@ieee.org> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <4E4845AB.9020107@ieee.org> Message-ID: On Sun, Aug 14, 2011 at 11:01 PM, Dave Angel wrote: > I'm inclined to ignore typos in emails except in the case where the intent > is to abuse others. > +1 QOTW. It is, however, a well-known tradition that spelling/grammar flames should contain one spelling/grammer error. Oh, I just did it myself, didn't I. ChrisA From rosuav at gmail.com Sun Aug 14 19:02:46 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 00:02:46 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 11:46 PM, Roy Smith wrote: > In article , > ?Dave Angel wrote: > >> The thing that confuses people is that not only is the part up to and >> through the domain name is case-insensitive, but that simple pages on >> Windows become case-insensitive for the remainder simply because Windows >> is such. > > Sure. ?But it's only in the most trivial of situations that URLs map in > any trivial way to file names. And even then, it plays havoc with caches (both browser and proxy), which have no way of knowing that http://blah.com/Foo.html and http://blah.com/foo.html are the same document. (It's not hard to set up a Windows system to be case sensitive with URLs, or (even easier - at least with Apache) to have any request with uppercase letters to instantly redirect to the lower-cased version.) URLs are definitely case sensitive; any server that ChrisA From clp2 at rebertia.com Sun Aug 14 19:37:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 16:37:57 -0700 Subject: Commands for changing ownership of a file In-Reply-To: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> References: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 3:56 PM, Jason Hsu wrote: > I have a script that I execute as root, but I need to change the > ownership of the files created in the script to that of my username. > In GNU Bash, the command is something like "chown myusername:users". > What's the equivalent Python command? ?I know that there is a command > that uses numbers for the username and group, but is there a command > that would allow me to use "myusername" and "users" instead of numbers? Simply use the `pwd` and `grp` modules to lookup the uid and gid for the username and group-name respectively. Then use the id-based chown function(s) you already came across. http://docs.python.org/library/pwd.html#pwd.getpwnam http://docs.python.org/library/grp.html#grp.getgrnam Cheers, Chris From gordon at panix.com Sun Aug 14 19:43:07 2011 From: gordon at panix.com (John Gordon) Date: Sun, 14 Aug 2011 23:43:07 +0000 (UTC) Subject: Data issues with Django and Apache References: <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1@glegroupsg2000goo.googlegroups.com> Message-ID: In <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1 at glegroupsg2000goo.googlegroups.com> Daniel Roseman writes: > Like I say, though, it would really help if you showed the relevant code. I know. But trimming the code down to where it would be fit for posting is a moderately big job and I'm somewhat pressed for time. I was just hoping that someone would recognize the problem from the few symptoms I gave. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From 1248283536 at qq.com Sun Aug 14 20:09:52 2011 From: 1248283536 at qq.com (=?utf-8?B?5a6I5qCq5b6F5YWU?=) Date: Mon, 15 Aug 2011 08:09:52 +0800 Subject: same code to login,one is ok,another is not Message-ID: 1.http://www.renren.com/Login.do it is ok,my code: import cookielib, urllib2, urllib cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),] opener.addheaders=exheaders url_login = 'http://www.renren.com/Login.do' body = (('email',' '), ('password', ')) req1 = opener.open(url_login, urllib.urlencode(body)) file=open('/tmp/sample','w') file.write(req1.read()) file.close() 2.https://passport.baidu.com/?login can't login,my code: import cookielib, urllib2, urllib cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),] opener.addheaders=exheaders url_login = 'https://passport.baidu.com/?login' body =(('username',' '), ('password',' '),('pwd','1')) req1 = opener.open(url_login, urllib.urlencode(body)) file=open('/tmp/sample','w') file.write(req1.read()) file.close() what i get is: ??????????????? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Aug 14 20:49:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Aug 2011 20:49:25 -0400 Subject: pythonw.exe In-Reply-To: References: Message-ID: On 8/14/2011 10:30 AM, Nobody wrote: > The main use for pythonw.exe is if you write a GUI program in Python > (using e.g. TkInter, wxPython, etc) and you want it to be able to run it > from an icon (desktop, start menu) without it opening a console window > (running a console executable from an icon will open a console window). In particular, IDLE runs in a pythonw process and it executes user code in a separate pythonw process and usually uses a socket for the connection. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sun Aug 14 20:55:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 10:55:53 +1000 Subject: same code to login,one is ok,another is not References: Message-ID: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> ???? wrote: > 1.http://www.renren.com/Login.do > it is ok,my code: [...] > 2.https://passport.baidu.com/?login > can't login,my code: [...] Do you have a question, or are you just sharing the bad news? Websites may choose to respond to login attempts differently. Some may require cookies, some may not. Some may check the referrer, some may not. Some may look at the user agent, some may not. If the web developer of the site insists that you log in with a browser, or Internet Explorer, you have to fight to convince the web server to let you in. Many websites really try hard to prevent bots and scripts logging in. The closer you can imitate what a real human being in a browser does, the better the chances you can fool the server that you are a real human being using a browser and not a bot. (Since your script *is* a bot, you may also be in violation of the web site's terms of service.) Some web sites may even check how often you try to log in, or how fast. But what makes you think you can't log in? Given the response below, it looks to me that you did log in, and got a blank page with some javascript to redirect you to the real content page. (If you are a web developer and you do this, I hate you.) But I may be wrong -- I'm not an expert on these things. > > ??????????????? > > > > > > > > > > > > > -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 14 20:56:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 10:56:12 +1000 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4e486ead$0$29986$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > I think you need to start a blog, Rick. > > You'd be easier to ignore. And yet, here you are, engaging him in conversation and feeding him the attention he craves :( -- Steven From john2james at gmail.com Sun Aug 14 20:56:36 2011 From: john2james at gmail.com (John S James) Date: Sun, 14 Aug 2011 20:56:36 -0400 Subject: Problem installing 3.2.1 on a Linux server Message-ID: Thanks, your reply helped. The problem seems to be the autoconfig -- I was using version 2.59 instead of 2.68. However, the host will not let users install 2.68. So I'm sending them feedback, suggesting a number of reasons for supporting 3.2 for their server accounts, including: * Popularity of Python, TIOBE recognition; * Wide consensus that new Python programmers should learn version 3, unless they must maintain legacy software; * 3.2 will be around for at least another year before 3.3 is released; * Lack of 3.2 in low-cost hosts (3.1 is available) -- a competitive advantage; * 3.2 improves future library compatibility, vs. 3.1; * Installing 3.2 should not affect any existing customers, unless they choose to use it. We should explore why hosting services are resistant to supporting the current version of Python (plus an important older version, 2.7). Other supported versions could be deprecated -- and eventually removed by the ISPs, except for the few customers who choose to install it themselves. John S James www.replicounts.org ---------- Forwarded message ---------- From: Ned Deily To: python-list at python.org Date: Sat, 06 Aug 2011 15:09:39 -0700 Subject: Re: Problem installing 3.2.1 on a Linux server In article , John S James wrote: > My ISP (Bluehost) does not yet support Python version 3, but gave me shell > access (no sudo) so that I can install Python 3 myself on my server account > (running Apache). So I uploaded the standard Python.org installation package > (Python 3.2.1 for Linux) and followed instructions, starting with > ./configure. These instructions had worked for me before, to install Python3 > on a Linux netbook. > > But on the server, ./configure starts fine, but later stops with an error. > Here is the section of the output where the error occurred: > *checking for build directories... done* > *configure: creating ./config.status* > *config.status: creating Makefile.pre* > *config.status: creating Modules/Setup.config* > *config.status: error: cannot find input file: `Misc/python.pc.in'* > > Then the ./configure step stopped. Needless to say, the next step, Make, did > not work because there was no Makefile. Works for me on a current Debian system. Are you downloading the source from python.org? Did you verify that the file is created by tar? $ curl -O http://www.python.org/ftp/python/3.2.1/Python-3.2.1.tgz $ tar xzf Python-3.2.1.tgz $ cd ./Python-3.2.1/ $ ls -l Misc/python.pc.in -rw-r----- 1 nad nad 293 Jul 8 23:58 Misc/python.pc.in $ ./configure [...] configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating Misc/python.pc config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating Makefile If you are still having problems, chances are you have an out-of-date or incomplete version of GNU autotools which contains the macros and tools that are used by the ./configure script. On my system: $ autoconf --version autoconf (GNU Autoconf) 2.68 -- Ned Deily, nad at acm.org -- John S. James www.aidsnews.org www.RepliCounts.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Aug 14 21:35:42 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 18:35:42 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: On Aug 14, 5:01?pm, Dave Angel wrote: > Interesting that when you complain about other's grammatical typos, > you're so careless with your own. > > know -> now > i -> I > accustom -> accustomed > the this -> this > > I'm inclined to ignore typos in emails except in the case where the > intent is to abuse others. My intent is NOT to abuse, but to enlighten. And you need to look up the definition of typo because i am not complaining about typos. Typos are accidents. Even the best of us suffer from accidents. What i AM complaining about is the adoption of a collectively foolish consistency. "Used to" and "supposed to" is the verbiage of children and idiots. I am trying to break these people out of such foolish loops. You should be thanking me instead of trolling my posts. From rantingrick at gmail.com Sun Aug 14 21:40:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 18:40:50 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Aug 14, 7:56?pm, Steven D'Aprano wrote: > Chris Angelico wrote: > > I think you need to start a blog, Rick. > > You'd be easier to ignore. > > And yet, here you are, engaging him in conversation and feeding him the > attention he craves :( Yes, Steven loves rule # 2. Second only to the strawmen armies he has built. Kurtz: "What do you call it when the assassins accuse the assassin?" From steve+comp.lang.python at pearwood.info Sun Aug 14 21:54:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 11:54:45 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-14, Steven D'Aprano > wrote: >> The way I see it, if something operates by side-effect, then it has no >> business being treated as an expression. Which I later withdrew. > Interesting! I tend to really like the ability to chain methods, > depending > on context. I find the side-effect/expression mix pretty normal, so I'm > used to it. As a rule, chaining method calls risks violating the Law of Demeter. Just sayin'. >>> Say I try to indent or outdent something and I grab the wrong set of >>> lines. It's certainly possible for this to result in valid code... And I >>> have no >>> cue as to what happened. Even if I get a warning, I can't necessarily >>> tell what happened. > >> Then don't do that. > > If not doing that were a realistic option for me, I'm guessing I'd have > stopped making typos thirty years ago. I feel your pain. But not all typos are equivalent. There are typos in the content of the document you are editing, and command typos. There's nothing an editor can do to prevent the first -- how is the editor supposed to know that you meant "referrer" rather than "referer"? And because it didn't, now we're stuck with a %*$%@&! spelling error forever. But a good editor can minimise command typos. User interfaces matter. If your car required you to reach over your left shoulder and pull a lever in order to slow down, it would be a really bad design. It would join these interfaces: http://www.asktog.com/columns/027InterfacesThatKill.html http://www.useit.com/alertbox/20050411.html If your editor doesn't help you minimise bad commands, then your editor doesn't work for you, it works against you. >> I'm not impressed by arguments based on "but if I do something stupid, >> like select text with my eyes closed and reindent it without looking, I >> expect the compiler to save my bacon". In my opinion, it's not the >> compiler's job to protect you from errors caused by sheer carelessness at >> the keyboard. > > I don't know about "sheer carelessness". Typos happen. Typos are not > something you can prevent from happening just by wanting it very much. I sympathise, but don't care. That's your problem man, not Python's. Python has a design philosophy that doesn't match your needs precisely. Oh well, no language can be all things to all people. If you try, you get Perl, and you still fail, because your language doesn't meet the needs of people looking for something that isn't Perl *wink* I hope you can still be productive in Python, and it's not like anyone *wants* you to stop using Python and use another language, but you have to understand that Python wasn't designed for *your* needs precisely. That doesn't make indentation as syntax a bad choice. >> In any case, while reindenting an arbitrary set of lines may *possibly* >> result in valid code that runs but does the wrong thing, the likelihood >> of that happening is remote enough that I'm not going to lose any sleep >> over it. > > Ahh, but what about the case where it results in invalid code? It's not > necessarily obvious which lines need to be moved after that. Are you talking about code you've moved from somewhere else and need to reindent? Then if the code was working before, it will keep working if you have the same relative indentation. (At least indentation-wise. It may break due to other factors.) Revert your bad reindent and try again, more carefully this time. If you're making semantic changes to the code, not just a simple move, then surely you understand what changes you're making and not just randomly indenting and dedenting until it complies? Read the code and decide how to fix it. I get it that sometimes there will be code which is hard to follow and hard to edit. But if that's the case, you've got more maintenance problems than indentation, and indents are the least of your problems. >>> foo.each do |bar| >>> bar.do_a_thing >>> do_something_with(bar) >>> end >>> next_thing >>> something else > >>> I know immediately that it's wrong. > >> How? > > The "end" is misaligned. Therefore SOMETHING is wrong. I don't know > what, but I can be confident that something went wrong. Okay, now I'm confused... if indentation doesn't matter, how is the end misaligned? You could write this, and it would still work the same, yes? foo.each do |bar| bar.do_a_thing do_something_with(bar) end next_thing something else >> Unless I understand the intent of the code, how can I tell whether the >> END token is in the right place or not? And if I understand the intent of >> the code, then the END token is redundant. > > The question is not whether it's on the right line. No amount of > indenting or > outdenting can ever break that. The question is whether I've gotten the > indentation screwed up. But if indentation doesn't matter, you can't screw it up. Isn't that the whole point of this discussion? [...] > You keep telling me to stop using this editor. I have not seen a > suggested improvement. There's only one editor worth using. The standard Unix editor, ed. http://www.gnu.org/fun/jokes/ed.msg.html *wink* Your editor is not my problem. But if you're going to come here and tell us that Python is less than optimal because it doesn't solve the problems you have with your editor, the obvious answer is that it is not Python's responsibility to minimise the harm caused when you indent 7 lines instead of 8, and if your editor encourages you to make mistakes, perhaps you need another editor. I have no idea if that editor even exists. Perhaps you need to write it yourself. [...] > The two-tab outdent is either one or two outdents. I can't point to a > specific character and say "this is *one* outdent". So it's not explicit. "I can point to a specific character" is not what explicit means. The outdent is defined by a change of indentation level. You had 8 spaces, now you have 4. That delta is real. Just because the glyph for spaces is transparent doesn't make it less real, and just because the delta is -4 spaces also doesn't make it less real. To start a new block in C, I type { and then type } to end it. Explicit. To start a new block in Python, I type TAB, and then SHIFT-TAB to end it. This is also explicit. > I think... I mean, the thing > about design philosophy, when you have several design philosophy rules, is > that NONE of the rules get followed all the time. I think it'd be much > more effective to say that one of the other rules won in this case than to > try to convince people that a variable number of tokens occurring with no > difference at all in the character stream is "explicit". The character stream does have a difference. TAB TAB TAB foo is different from TAB foo That difference depends on the context, but is usually two dedents. -- Steven From michael.poeltl at univie.ac.at Sun Aug 14 21:58:48 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 15 Aug 2011 03:58:48 +0200 Subject: Commands for changing ownership of a file In-Reply-To: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> References: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> Message-ID: <20110815015848.GD25106@horus.cms.at> in python-3.2.1 I'm using os.system() again, from time to time maybe that's the one you were looking for? >>> os.system('chown user:group /tmp/f') 0 >>> os.system('ls -l /tmp/f') -rw-r--r-- 1 user group 0 Aug 15 03:52 /tmp/f and besides os.chown() (where you ned the uid and gid), you could also use subprocess.call() or subprocess.Popen() regards Michael * Jason Hsu [2011-08-15 01:15]: > I have a script that I execute as root, but I need to change the > ownership of the files created in the script to that of my username. > In GNU Bash, the command is something like "chown myusername:users". > What's the equivalent Python command? I know that there is a command > that uses numbers for the username and group, but is there a command > that would allow me to use "myusername" and "users" instead of numbers? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From clp2 at rebertia.com Sun Aug 14 22:10:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 19:10:42 -0700 Subject: allow line break at operators In-Reply-To: <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 6:54 PM, Steven D'Aprano wrote: > Seebs wrote: >> Interesting! ?I tend to really like the ability to chain methods, >> depending >> on context. ?I find the side-effect/expression mix pretty normal, so I'm >> used to it. > > As a rule, chaining method calls risks violating the Law of Demeter. Just > sayin'. Not in the specific case of fluent interfaces[1] though, which could have been what Seebach had in mind. Whether fluent interfaces are a good idea... Cheers, Chris -- [1] http://en.wikipedia.org/wiki/Fluent_interface From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <4e486ead$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: > And yet, here you are, engaging him in conversation and feeding him the > attention he craves :( Many cultures have a tradition of almsgiving. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: >> Interesting! I tend to really like the ability to chain methods, >> depending >> on context. I find the side-effect/expression mix pretty normal, so I'm >> used to it. > As a rule, chaining method calls risks violating the Law of Demeter. Just > sayin'. "Risks violating" isn't the same thing as "violates". > But a good editor can minimise command typos. User interfaces matter. If > your car required you to reach over your left shoulder and pull a lever in > order to slow down, it would be a really bad design. It would join these > interfaces: Yeah. > If your editor doesn't help you minimise bad commands, then your editor > doesn't work for you, it works against you. Life is full of tradeoffs. The editor does a lot of things which very much improve my performance, with costs which are usually pretty easily mitigated. >> I don't know about "sheer carelessness". Typos happen. Typos are not >> something you can prevent from happening just by wanting it very much. > I sympathise, but don't care. That's your problem man, not Python's. Debatable. There's a sort of fuzzy boundary between "clearly this is a defect in the product" (see interfaces that kill), and "clearly this is a defect in the user". In fact, one of the major areas of interesting UI research involves interfaces that accommodate things which are generally regarded as defects in the user. Think about colorblindness. Obviously, it's the user's problem, not the editor's, but an editor which picks colors which most colorblind people can't distinguish for something important is going to get castigated for it. > I hope you can still be productive in Python, and it's not like anyone > *wants* you to stop using Python and use another language, but you have to > understand that Python wasn't designed for *your* needs precisely. That > doesn't make indentation as syntax a bad choice. I think it depends a lot on the goals. So far as I can tell, the primary goal of the policy was to eliminate a class of errors. It... well, it does this in a strictly technical sense, in that every error which occurs is no longer of that class. It does not seem to me that it's done very much to turn the kinds of things which used to result in that class of errors into non-errors; rather, it's turned them into different errors. > Are you talking about code you've moved from somewhere else and need to > reindent? Then if the code was working before, it will keep working if you > have the same relative indentation. (At least indentation-wise. It may > break due to other factors.) Revert your bad reindent and try again, more > carefully this time. The point is... I can't *TELL* what the boundaries of the bad-reindent are. Because there's no unambiguous point at which I can say "oh, look, here is the line where the indentation starts being wrong", unless there's a syntax error... and even then, the syntax error might be before or after the actual bounds of the bad indent. With properly-braced code in a brace language, any mis-indent you do can be unambiguously identified -- you have a 100% guarantee that you know what the first and last misindented lines are. In Python, you can usually guess within a couple of the lines, more easily if you're familiar with the code. > If you're making semantic changes to the code, not just a simple move, then > surely you understand what changes you're making and not just randomly > indenting and dedenting until it complies? Read the code and decide how to > fix it. The case that has historically bitten me is that I move N lines of code, and then I try to adjust the indentation of those N lines, and... SOMETHING happens. Maybe someone somewhere introduced tabs and adding four leading spaces doesn't do anything. Maybe I mis-counted N. > I get it that sometimes there will be code which is hard to follow and hard > to edit. But if that's the case, you've got more maintenance problems than > indentation, and indents are the least of your problems. Not if the only reason that it's hard to follow is that the indentation is screwed up. >> The "end" is misaligned. Therefore SOMETHING is wrong. I don't know >> what, but I can be confident that something went wrong. > Okay, now I'm confused... if indentation doesn't matter, how is the end > misaligned? Indentation doesn't affect the *compiler*, but we know the rules for indentation. It's a parity bit. If the indentation and the begin/end don't agree, then I *know something is wrong*. And I know on exactly which line it becomes wrong. That turns out to save me a fair bit of time if I have to look at code and try to figure out what's wrong. >> The question is not whether it's on the right line. No amount of >> indenting or >> outdenting can ever break that. The question is whether I've gotten the >> indentation screwed up. > But if indentation doesn't matter, you can't screw it up. Isn't that the > whole point of this discussion? I think there is some confusion because the word "matter" has more than one meaning. Indentation does not control what the compiler does in, say, C or Ruby. It does matter to the *reader*. > There's only one editor worth using. The standard Unix editor, ed. Heh. > Your editor is not my problem. But if you're going to come here and tell us > that Python is less than optimal because it doesn't solve the problems you > have with your editor, But they're *not problems* -- unless I'm using Python. The rest of the time it's just the ordinary thing where sometimes when you're using a computer you typo, misclick, or whatever. Hmm. Lemme try an analogy. Imagine, if you will, an editor with the helpful trait that if you close a window it closes, bang, whether or not anything has been touched in it. Your argument here is roughly: But if you're going to come here and tell us that Hypothetical Edit is less than optimal because it doesn't solve the problems you have with your mouse, [...] Which is to say: Yes, I usually expect software to be designed to handle common problems gracefully. Whether this is "Python's problem" or not is really an incoherent question; all we can do is talk about what the effects are, and it's up to Guido or whoever else to decide whether they care. In terms of language adoption, it has certainly been a "problem" historically; there are many people who might have used Python but ended up not doing so because the indentation thing interacted badly with their other requirements. I tend not to care much about assigning "blame". I don't care whether a tool is correctly designed for someone who isn't me, or is incorrectly designed, because neither matters. All that matters is whether I can use it reasonably easily. With Python, the single barrier I've encountered to a pleasant and productive programming experience has been the indentation thing. Apart from that it's a language I'd basically get along with. But, for whatever reason, the net result is that programming in Python is a perpetual exercise in frustration for me. I still prefer it to a number of other languages, but it's always annoying; it's like using a stereo system that has a persistent high-pitched whine, but otherwise has very good sound. > "I can point to a specific character" is not what explicit means. No, but... An explicit thing is by definition a thing which is *NOT INFERRED*. If the same sequence of characters can be one or two tokens, depending on a sequence of characters twenty lines ago, that looks very much like something is being *inferred*. Information external to the sequence of characters currently being tokenized is being used to determine what tokens to recognize. >> I think... I mean, the thing >> about design philosophy, when you have several design philosophy rules, is >> that NONE of the rules get followed all the time. I think it'd be much >> more effective to say that one of the other rules won in this case than to >> try to convince people that a variable number of tokens occurring with no >> difference at all in the character stream is "explicit". > The character stream does have a difference. The character streams I was talking about don't. Character stream: tab tab tab "foo" newline tab "bar". This is, as you say, *usually* two dedents, but it could be one. Same exact stream of bytes, and yet the newline/tab may be either one or two dedents, or four if you're working on code where someone has been using four-space indents but someone happened to convert sets of eight spaces to tabs. > That difference depends on the context, My point exactly. Dedents are constructed from a combination of the current character stream and information about characters that could easily be hundreds of tokens back. That means that they are not explicit in the part of the character stream where they occur, but are implied by the combination of that stream of characters with the rest of the stream. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Chris Rebert wrote: > On Sun, Aug 14, 2011 at 6:54 PM, Steven D'Aprano > wrote: >> As a rule, chaining method calls risks violating the Law of Demeter. Just >> sayin'. > Not in the specific case of fluent interfaces[1] though, which could > have been what Seebach had in mind. They're the most obvious example, from my point of view. I tend to write stuff like foo.array_of_things.sort.map { block }.join(", ") I like this a lot more than array = foo.array_of_things sorted_array = array.sort() mapped_array = [block(x) for x in sorted_array] ", ".join(mapped_array) (I am still not used to Python's attachment of join to strings rather than to arrays. I don't really object to it, it's just not how I think about join operations.) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Mon Aug 15 00:40:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 00:40:51 -0400 Subject: Problem installing 3.2.1 on a Linux server In-Reply-To: References: Message-ID: On 8/14/2011 8:56 PM, John S James wrote: > Thanks, your reply helped. The problem seems to be the autoconfig -- I > was using version 2.59 instead of 2.68. However, the host will not let > users install 2.68. > > So I'm sending them feedback, suggesting a number of reasons for > supporting 3.2 for their server accounts, including: > > * Popularity of Python, TIOBE recognition; > * Wide consensus that new Python programmers should learn version 3, > unless they must maintain legacy software; > * 3.2 will be around for at least another year before 3.3 is released; > * Lack of 3.2 in low-cost hosts (3.1 is available) -- a competitive > advantage; > * 3.2 improves future library compatibility, vs. 3.1; A mountain of library improvement that could not go in 3.1. > * Installing 3.2 should not affect any existing customers, unless they > choose to use it. With 3.1 in security-fix only mode, the multiple fixes each day only go in 3.2 and 3.3. > We should explore why hosting services are resistant to supporting the > current version of Python (plus an important older version, 2.7). Other Seeing and occasionally participating in the development work to improve Python, such resistance makes me sad. Not their concern, of course, but depriving their customers is. > supported versions could be deprecated -- and eventually removed by the > ISPs, except for the few customers who choose to install it themselves. -- Terry Jan Reedy From christophechong at gmail.com Mon Aug 15 01:01:00 2011 From: christophechong at gmail.com (Christophe Chong) Date: Sun, 14 Aug 2011 22:01:00 -0700 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <9701DD3E-6E92-4EA6-A225-A37E0F9E1497@gmail.com> I can't tell which comments are sarcastic On Aug 14, 2011, at 18:35, rantingrick wrote: > On Aug 14, 5:01 pm, Dave Angel wrote: > >> Interesting that when you complain about other's grammatical typos, >> you're so careless with your own. >> >> know -> now >> i -> I >> accustom -> accustomed >> the this -> this >> >> I'm inclined to ignore typos in emails except in the case where the >> intent is to abuse others. > > My intent is NOT to abuse, but to enlighten. And you need to look up > the definition of typo because i am not complaining about typos. Typos > are accidents. Even the best of us suffer from accidents. > > What i AM complaining about is the adoption of a collectively foolish > consistency. "Used to" and "supposed to" is the verbiage of children > and idiots. I am trying to break these people out of such foolish > loops. You should be thanking me instead of trolling my posts. > -- > http://mail.python.org/mailman/listinfo/python-list From timr at probo.com Mon Aug 15 01:22:21 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 14 Aug 2011 22:22:21 -0700 Subject: allow line break at operators References: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > >The only exception I can think of is *very* early Fortran, and that rightly >is considered a mistake. Fortran 77 used to treat whitespace as always >optional, so that in Python terms this: > >forxinrange(42) > >would be parsed as this: > >for x in range(42) Absolutely true, and that led to one of the more famous computing screw-ups in the early space program. The author intended to write this: DO 10 I=1,8 which, in Fortran, begins a loop that will run 8 times ending at the statement labeled "10". In this case, the author mistakenly typed a period instead of a comma: DO 10 I=1.8 That, unfortunately, is a perfectly valid statement that assigns the value "1.8" to the floating point variable "DO10I", supposedly resulting in the loss of an unmanned launch vehicle... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From saraanderson24 at gmail.com Mon Aug 15 02:21:35 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Sun, 14 Aug 2011 23:21:35 -0700 (PDT) Subject: Watch World`s Most Funniest Videos Ever. Message-ID: <567a6bb2-e3ee-4378-8cee-82a6b8c0d052@v9g2000pri.googlegroups.com> See Worlds Most Beautiful Places Ever. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH VERY VERY VERY FUNNY VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From rafadurancastaneda at gmail.com Mon Aug 15 02:58:52 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Mon, 15 Aug 2011 08:58:52 +0200 Subject: same code to login,one is ok,another is not In-Reply-To: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: First one is using http and second one https, did you try an https handler? as I already pointed out to you in other thread with the same topic... Please don't spam the list, if you aren 't getting the answers you was looking for, wait for a while and then repost not just open threads until get the answer 2011/8/15 Steven D'Aprano > ???? wrote: > > > 1.http://www.renren.com/Login.do > > it is ok,my code: > [...] > > 2.https://passport.baidu.com/?login > > can't login,my code: > [...] > > Do you have a question, or are you just sharing the bad news? > > Websites may choose to respond to login attempts differently. Some may > require cookies, some may not. Some may check the referrer, some may not. > Some may look at the user agent, some may not. > > If the web developer of the site insists that you log in with a browser, or > Internet Explorer, you have to fight to convince the web server to let you > in. Many websites really try hard to prevent bots and scripts logging in. > The closer you can imitate what a real human being in a browser does, the > better the chances you can fool the server that you are a real human being > using a browser and not a bot. (Since your script *is* a bot, you may also > be in violation of the web site's terms of service.) > > Some web sites may even check how often you try to log in, or how fast. > > But what makes you think you can't log in? Given the response below, it > looks to me that you did log in, and got a blank page with some javascript > to redirect you to the real content page. (If you are a web developer and > you do this, I hate you.) But I may be wrong -- I'm not an expert on these > things. > > > > > > ??????????????? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 15 03:31:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 03:31:15 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/15/2011 12:28 AM, Seebs wrote: To repeat again: you are free to put in explicit dedent markers that will let you re-indent code should all indents be removed. -- Terry Jan Reedy From vipul.iiith at gmail.com Mon Aug 15 04:08:33 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Mon, 15 Aug 2011 13:38:33 +0530 Subject: Help needed with using SWIG wrapped code in Python Message-ID: Hi, I have wrapped a library from C++ to Python using SWIG. But I am facing problems while importing and using it in Python. $ python >>> import pyossimtest >>> import pyossim >>> a = ["Image1.png","Image2.png"] >>> b = pyossimtest.Info() >>> b.initialize(len(a),a) Traceback (most recent call last): File "", line 1, in File "pyossimtest.py", line 84, in initialize def initialize(self, *args): return _pyossimtest.Info_initialize(self, *args) TypeError: in method 'Info_initialize', argument 3 of type 'char *[]' What does this error message imply? I have already handled char** as a special case in swig using typemaps. Here is the code excerpt from the swig-generated .cxx file: SWIGINTERN PyObject *_wrap_Info_initialize(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; pyossimtest::Info *arg1 = (pyossimtest::Info *) 0 ; int arg2 ; char **arg3 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; bool result; if (!PyArg_ParseTuple(args,(char *)"OO:Info_initialize",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_pyossimtest__Info, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Info_initialize" "', argument " "1"" of type '" "pyossimtest::Info *""'"); } arg1 = reinterpret_cast< pyossimtest::Info * >(argp1); { int i; if (!PyList_Check(obj1)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); return NULL; } arg2 = PyList_Size(obj1); arg3 = (char **) malloc((arg2+1)*sizeof(char *)); for (i = 0; i < arg2; i++) { PyObject *s = PyList_GetItem(obj1,i); if (!PyString_Check(s)) { free(arg3); PyErr_SetString(PyExc_ValueError, "List items must be strings"); return NULL; } arg3[i] = PyString_AsString(s); } arg3[i] = 0; } { try { result = (bool)(arg1)->initialize(arg2,arg3); } catch (const std::exception& e) { SWIG_exception(SWIG_RuntimeError, e.what()); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); { if (arg3) free(arg3); } return resultobj; fail: { if (arg3) free(arg3); } return NULL; } Kindly help. Thanks and regards, Vipul Raheja -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 15 04:27:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 09:27:47 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 15, 2011 at 5:28 AM, Seebs wrote: > Character stream: ?tab tab tab "foo" newline tab "bar". ?This is, as you > say, *usually* two dedents, but it could be one. I see your point, though I cannot imagine anyone who would use "tab tab" as an indent level. But if you go from 16 spaces down to 8, it's possible that the script uses eight space indents, or four. On Mon, Aug 15, 2011 at 8:31 AM, Terry Reedy wrote: > To repeat again: you are free to put in explicit dedent markers that will > let you re-indent code should all indents be removed. > This would be a solution to the above, but it has the feeling of syntactic salt. (I don't believe that braces are, because they afford a different form of flexibility.) But sure, if you configure your editor to do it for you. I type: if (blah): It puts: if (blah): | # << if with the cursor at the | marker. I never really got used to editors doing this for me, though. It didn't feel right. I prefer an editor that deals with my indentation but lets me do the rest; when I hit enter, it autoindents to either the current indent level or one greater, depending on whether it "looks like" there ought to be an indent (which mainly happens when I put a loose { on a line). Similarly, when I put a } into the file, it removes an indent level automatically. Still, it wouldn't be hard to make an editor put those dedent comments in, if you want them. ChrisA From rosuav at gmail.com Mon Aug 15 04:32:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 09:32:28 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 3:14 AM, Dennis Lee Bieber wrote: > ? ? ? ?Depends... "DOS", to me, is just short for "Disk Operating > System"... I've source code (in a book) for K2FDOS, source code for > LS-DOS 6, and have used the AmigaDOS component of AmigaOS (granted -- > AmigaDOS technically was the part of the OS that gave access to the I/O > system, and included the command line interpreter...). > > ? ? ? ?"DOS" does not automatically mean "MicroSoft DOS"... I would say that DOS can, in a Windows context, mean either MS-DOS or a generic Disk Operating System. The latter sense is no more appropriate to the CLI than the former; in a modern OS, the part that truly "operates the disk" would be either the kernel or the hard disk driver, depending on your point of view, and neither of those has any sort of UI. > ? ? ? ?What most call "DOS" is, to me, merely a "command line interpreter" > (CLI). And that's really what we have. A shell. A CLI. A textual command parser (as opposed to a graphical action system which is what most GUIs are). It's more similar to a MUD than to an operating system - first space-separated word is a verb, everything else is modifiers. ChrisA From pwoolcoc at gmail.com Mon Aug 15 05:07:30 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Mon, 15 Aug 2011 05:07:30 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 14, 2011 3:24 PM, "Seebs" wrote: ... > > I'm not impressed by arguments based on "but if I do something stupid, like > > select text with my eyes closed and reindent it without looking, I expect > > the compiler to save my bacon". In my opinion, it's not the compiler's job > > to protect you from errors caused by sheer carelessness at the keyboard. > > I don't know about "sheer carelessness". Typos happen. Typos are not > something you can prevent from happening just by wanting it very much. > If you have valid code caused by improper indentation, shouldn't that be caught by a good set of unit tests? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Aug 15 05:33:28 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 11:33:28 +0200 Subject: surprising interaction between function scope and class namespace Message-ID: Hi, I just stumbled over this: >>> A = 1 >>> def foo(x): ... A = x ... class X: ... a = A ... return X ... >>> foo(2).a 2 >>> def foo(x): ... A = x ... class X: ... A = A ... return X ... >>> foo(2).A 1 Works that way in Py2.7 and Py3.3. I couldn't find any documentation on this, but my *guess* about the reasoning is that the second case contains an assignment to A inside of the class namespace, and assignments make a variable local to a scope, in this case, the function scope. Therefore, the A on the rhs is looked up in that scope as well. However, this is just a totally hand waving guess. Does anyone have a better explanation or know of a place where this specific behaviour is documented? Stefan From stefan_ml at behnel.de Mon Aug 15 05:50:58 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 11:50:58 +0200 Subject: surprising interaction between function scope and class namespace In-Reply-To: References: Message-ID: Stefan Behnel, 15.08.2011 11:33: > I just stumbled over this: > > >>> A = 1 > >>> def foo(x): > ... A = x > ... class X: > ... a = A > ... return X > ... > >>> foo(2).a > 2 > >>> def foo(x): > ... A = x > ... class X: > ... A = A > ... return X > ... > >>> foo(2).A > 1 > > Works that way in Py2.7 and Py3.3. > > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside of the > class namespace, and assignments make a variable local to a scope, in this > case, the function scope. Therefore, the A on the rhs is looked up in that > scope as well. However, this is just a totally hand waving guess. ... and an incorrect one, as it turns out. I think I misinterpreted the results the wrong way around. Still: > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? Stefan From stefan_ml at behnel.de Mon Aug 15 06:08:02 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 12:08:02 +0200 Subject: Help needed with using SWIG wrapped code in Python In-Reply-To: References: Message-ID: Vipul Raheja, 15.08.2011 10:08: > I have wrapped a library from C++ to Python using SWIG. But I am facing > problems while importing and using it in Python. > > $ python > >>> import pyossimtest > >>> import pyossim > >>> a = ["Image1.png","Image2.png"] > >>> b = pyossimtest.Info() > >>> b.initialize(len(a),a) > Traceback (most recent call last): > File "", line 1, in > File "pyossimtest.py", line 84, in initialize > def initialize(self, *args): return _pyossimtest.Info_initialize(self, > *args) > TypeError: in method 'Info_initialize', argument 3 of type 'char *[]' > > What does this error message imply? I have already handled char** as a > special case in swig using typemaps. I have little experience with SWIG, so I can't comment much on the problem at hand, but what I can do is to encourage you to use Cython instead. It's faster, easier to use and much more versatile for writing Python wrappers than SWIG. Basically, it provides you with the full power and flexibility of a programming language, whereas SWIG (like all automatic wrapper generators) is always limiting because it has its predefined ways of wrapping things, and if they don't fit, you're on your own fighting up-hill against it. Stefan From duncan.booth at invalid.invalid Mon Aug 15 06:18:03 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Aug 2011 10:18:03 GMT Subject: surprising interaction between function scope and class namespace References: Message-ID: Stefan Behnel wrote: > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside > of the class namespace, and assignments make a variable local to a > scope, in this case, the function scope. Therefore, the A on the rhs > is looked up in that scope as well. However, this is just a totally > hand waving guess. > > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? > If it was a function rather than a class then in the first case you look up the non-local variable as expected and in the second case you get an UnboundLocalError. The only difference with the class definition is that instead of UnboundLocalError the lookup falls back to the global scope. This happens because class definitions use LOAD_NAME/STORE_NAME instead of LOAD_FAST/STORE_FAST and LOAD_NAME looks first in local scope and then in global. I suspect that http://docs.python.org/reference/executionmodel.html#naming-and-binding should say something about this but it doesn't. -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Mon Aug 15 06:42:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Aug 2011 12:42:01 +0200 Subject: surprising interaction between function scope and class namespace References: Message-ID: Stefan Behnel wrote: > Hi, > > I just stumbled over this: > > >>> A = 1 > >>> def foo(x): > ... A = x > ... class X: > ... a = A > ... return X > ... > >>> foo(2).a > 2 > >>> def foo(x): > ... A = x > ... class X: > ... A = A > ... return X > ... > >>> foo(2).A > 1 That's subtle. > Works that way in Py2.7 and Py3.3. > > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside of > the class namespace, and assignments make a variable local to a scope, in > this case, the function scope. Therefore, the A on the rhs is looked up in > that scope as well. However, this is just a totally hand waving guess. > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? I think it's an implementation accident. Classes have a special opcode, LOAD_NAME, that allows for >>> x = 42 >>> class A: ... x = x ... >>> A.x 42 which would fail in a function >>> def f(): ... x = x ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced before assignment LOAD_NAME is pretty dumb, it looks into the local namespace and if that lookup fails falls back to the global namespace. Someone probably thought "I can do better", and reused the static name lookup for nested functions for names that occur only on the right-hand side of assignments in a class. Here's a slightly modified version of your demo: >>> x = "global" >>> def foo(): ... x = "local" ... class A: ... x = x ... return A ... >>> def bar(): ... x = "local" ... class A: ... y = x ... return A ... >>> foo().x 'global' >>> bar().y 'local' Now let's have a glimpse at the bytecode: >>> import dis >>> foo.func_code.co_consts (None, 'local', 'A', ", line 3>, ()) >>> dis.dis(foo.func_code.co_consts[3]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 4 6 LOAD_NAME 2 (x) 9 STORE_NAME 2 (x) 12 LOAD_LOCALS 13 RETURN_VALUE >>> bar.func_code.co_consts (None, 'local', 'A', ", line 3>, ()) >>> dis.dis(bar.func_code.co_consts[3]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 4 6 LOAD_DEREF 0 (x) 9 STORE_NAME 2 (y) 12 LOAD_LOCALS 13 RETURN_VALUE From python.list at tim.thechases.com Mon Aug 15 07:40:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Aug 2011 06:40:10 -0500 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E49059A.60701@tim.thechases.com> On 08/14/2011 11:28 PM, Seebs wrote: > I tend to write stuff like > > foo.array_of_things.sort.map { block }.join(", ") > > I like this a lot more than > array = foo.array_of_things > sorted_array = array.sort() > mapped_array = [block(x) for x in sorted_array] > ", ".join(mapped_array) If you like the one-liner, this is readily written as ", ".join(block(x) for x in sorted(foo.array_of_things)) Modulo your gripes about string.join(), this is about as succinct (and more readable, IMHO) as your initial example. I've got piles of these sorts of things in my ETL code. -tkc From neilc at norwich.edu Mon Aug 15 08:06:31 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Aug 2011 12:06:31 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: <9asge7Fsv9U6@mid.individual.net> On 2011-08-14, Chris Angelico wrote: > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong wrote: >> On 14-8-2011 7:57, rantingrick wrote: >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." >>> more than ten times in a single post, you will get an invite to >>> Guido's next birthday party; where you'll be forced to do shots whist >>> walking the balcony railing wearing wooden shoes! >> >> I lolled about this one, e.g. I laughed out loud. But where >> are the tulips and windmills for extra credit? >> >> Greetings from a Dutchman! No credit. E.g., i.e., exampla gratis, means, "for example." -- Neil Cerutti From paddy3118 at googlemail.com Mon Aug 15 08:46:39 2011 From: paddy3118 at googlemail.com (Paddy) Date: Mon, 15 Aug 2011 05:46:39 -0700 (PDT) Subject: Wot! No Python? (Dynamic Languages Conference 2011, Edinburgh). Message-ID: <602a5feb-9d6b-4f11-8ffe-5f563758fad2@v3g2000vbx.googlegroups.com> http://www.dynamiclanguages.co.uk/dlc2011/ From philip at semanchuk.com Mon Aug 15 08:51:47 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 08:51:47 -0400 Subject: Help needed with using SWIG wrapped code in Python In-Reply-To: References: Message-ID: <5A1D8DCE-2E3F-48AD-81EE-D2967AC2C61E@semanchuk.com> On Aug 15, 2011, at 4:08 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But I am facing > problems while importing and using it in Python. Hi Vipul, Did you try asking about this on the SWIG mailing list? bye Philip From jhibschman+usenet at gmail.com Mon Aug 15 09:27:10 2011 From: jhibschman+usenet at gmail.com (Johann Hibschman) Date: Mon, 15 Aug 2011 08:27:10 -0500 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: Chris Angelico writes: > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. I'm a clearly a fool for allowing myself to be drawn into this thread, but I've been playing a lot recently with the APL-derivative language J, which uses a right-to-left operator precendence rule. Pragmatically, this is because J defines roughly a bajillion operators, and it would be impossible to remember the precendence of them all, but it makes sense in its own way. If you read "3 * 10 + 7", using right-to-left, you get "three times something". Then you read more and you get "three times (ten plus something)." And finally, you get "3*(10+7)". The prefix gives the continuation for the rest of the calculation; no matter what you substitute for X in "3*X", you will always just evaluate X, then multply it by 3. Likewise, for "3*10+X", no matter what X is, you know you'll add 10 and multiply by 3. This took me a while to get used to, but it's definitely a nice property. Not much to do with python, but I do like the syntax enough that I've implemented my own toy evaluator for J-like expressions in python, to get around the verbosity of some bits of numpy. Regards, Johann From steve+comp.lang.python at pearwood.info Mon Aug 15 09:30:26 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 23:30:26 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I tend to write stuff like > > foo.array_of_things.sort.map { block }.join(", ") > > I like this a lot more than > array = foo.array_of_things > sorted_array = array.sort() > mapped_array = [block(x) for x in sorted_array] > ", ".join(mapped_array) If you insist on a one-liner for four separate operations, what's wrong with this? ", ".join([block(x) for x in sorted(foo.array_of_things)]) Or if you prefer map: ", ".join(map(block, sorted(foo.array_of_things)) I think I would be less skeptical about fluent interfaces if they were written more like Unix shell script pipelines instead of using attribute access notation: foo.array_of_things | sort | map block | join ", " -- Steven From roy at panix.com Mon Aug 15 09:41:33 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 09:41:33 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. Computer programming languages follow math conventions only in the most vague ways. For example, standard math usage dictates that addition is commutative. While this is true for adding integers, it's certainly not true for adding strings (in any language which supports string addition). Where to draw the line between math and programming languages is not an easy question. > It would be far safer to go the other way > and demand parentheses on everything. Demand, no, but sometimes it's a good idea. I've been writing computer programs for close to 40 years, and I still have no clue what most of the order of operations is. It's just not worth investing the brain cells to remember such trivia (especially since the details change from language to language). Beyond remembering the (apparently) universal rule that {*, /} bind tighter than {+, -}, I pretty much just punt on everything else and put in extra parens everywhere. It's not the most efficient way to write code, and probably doesn't even result in the prettiest code. But it sure does eliminate those face-palm moments at the end of a long debugging session when you realize that somebody got it wrong. From rosuav at gmail.com Mon Aug 15 10:16:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 15:16:55 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Mon, Aug 15, 2011 at 2:41 PM, Roy Smith wrote: > Demand, no, but sometimes it's a good idea. ?I've been writing computer > programs for close to 40 years, and I still have no clue what most of > the order of operations is. ?It's just not worth investing the brain > cells to remember such trivia (especially since the details change from > language to language). ?Beyond remembering the (apparently) universal > rule that {*, /} bind tighter than {+, -}, I pretty much just punt on > everything else and put in extra parens everywhere. > Understandable. I go the other way, though, and keep an operator precedence table for each language handy; often, what I'm after is not "which one binds more tightly", but "what's the symbol for modulo", which is also (usually) on that same table. Or: "Blasted PHP, which operators have precedence between || and or?" which is easy to forget. And you're right about the details changing from language to language, hence the operators table *for each language*. But most languages follow fairly sane rules, and tend to come up with pretty much the same ordering. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 15 10:28:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 00:28:23 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Computer programming languages follow math conventions only in the most > vague ways. ?For example, standard math usage dictates that addition is > commutative. ?While this is true for adding integers, it's certainly not > true for adding strings (in any language which supports string addition). Not quite true for maths either, at least in principle. I'm not aware of any number types where addition is non-commutative, but subtraction is noncommutative even for integers, and noncommutative multiplication is quite common (e.g. matrix multiplication). And of course, once you start using floating point numbers, you can't assume commutativity: >>> 0.1 + 0.7 + 0.3 == 0.3 + 0.7 + 0.1 False I'm reminded of this quote from John Baez: "The real numbers are the dependable breadwinner of the family, the complete ordered field we all rely on. The complex numbers are a slightly flashier but still respectable younger brother: not ordered, but algebraically complete. The quaternions, being noncommutative, are the eccentric cousin who is shunned at important family gatherings. But the octonions are the crazy old uncle nobody lets out of the attic: they are nonassociative." (And don't even ask about the sedenions...) -- Steven From rosuav at gmail.com Mon Aug 15 10:42:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 15:42:08 +0100 Subject: allow line break at operators In-Reply-To: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 15, 2011 at 3:28 PM, Steven D'Aprano wrote: > And of course, once you start using floating point numbers, you can't assume > commutativity: > >>>> 0.1 + 0.7 + 0.3 == 0.3 + 0.7 + 0.1 > False > This isn't because programming languages fail to follow mathematics; it's because floating point numbers do not represent real numbers. Python doesn't support substring removal using the subtraction operator, but I'd have to say that floats more closely parallel strings and other high level objects than they do mathematical reals. If Python treated __sub__(str,str) as str.replace(str,"") then: >>> "hello world" + "asdfqwer" - "d" "hello worlasfqwer" >>> "hello world" - "d" + "asdfqwer" "hello worlasdfqwer" Nobody would expect strings to behave mathematically with subtraction, because negatives don't make sense. Even sets don't quite work, although they're closer: >>> set("asdf")-set("test") {'a', 'd', 'f'} There's no way, in a set, to show a negative reference to 't' and 'e'. In theory you could do this with dictionaries or collections.Counter, but subtracting a Counter from a Counter doesn't produce negative numbers either. No, these constructs do not subtract algebraically, and I do not think it would be any improvement to the language if they did. ChrisA From artie.ziff at gmail.com Mon Aug 15 11:20:22 2011 From: artie.ziff at gmail.com (Artie Ziff) Date: Mon, 15 Aug 2011 08:20:22 -0700 Subject: string to unicode Message-ID: <4E493936.5030807@gmail.com> if I am using the standard csv library to read contents of a csv file which contains Unicode strings (short example: '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such as decode or encode to transform this string type into a python unicode type? Must I know the encoding (byte groupings) of the Unicode? Can I get this from the file? Perhaps I need to open the file with particular attributes? thanks! From awilliam at whitemice.org Mon Aug 15 11:29:43 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 15 Aug 2011 11:29:43 -0400 Subject: string to unicode In-Reply-To: <4E493936.5030807@gmail.com> References: <4E493936.5030807@gmail.com> Message-ID: <1313422183.3127.5.camel@linux-yu4c.site> On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: > if I am using the standard csv library to read contents of a csv file > which contains Unicode strings (short example: > '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such > as decode or encode to transform this string type into a python unicode > type? Must I know the encoding (byte groupings) of the Unicode? Can I > get this from the file? Perhaps I need to open the file with particular > attributes? Open the file with a codec and pass that file-like object to csv. codecs.open(filename, mode[, encoding[, errors[, buffering]]]) -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From rosuav at gmail.com Mon Aug 15 11:37:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 16:37:36 +0100 Subject: string to unicode In-Reply-To: <4E493936.5030807@gmail.com> References: <4E493936.5030807@gmail.com> Message-ID: On Mon, Aug 15, 2011 at 4:20 PM, Artie Ziff wrote: > if I am using the standard csv library to read contents of a csv file which > contains Unicode strings (short example: '\xe8\x9f\x92\xe8\x9b\x87'), how do > I use a python Unicode method such as decode or encode to transform this > string type into a python unicode type? Must I know the encoding (byte > groupings) of the Unicode? Can I get this from the file? Perhaps I need to > open the file with particular attributes? > Start here: http://www.joelonsoftware.com/articles/Unicode.html The CSV file, being stored on disk, cannot contain Unicode strings; it can only contain bytes. If you know the encoding (eg UTF-8, UCS-2, etc), then you can decode it using that. If you don't, your best bet is to ask the origin of the file; failing that, check the first few bytes - if it's "\xFF\xFE" or "\xFE\xFF" or "\xEF\xBB\xBF", then it's probably UTF-16LE, UTF-16BE, or UTF-8, respectively (those being the encodings of the BOM). There may be other clues, too, but normally it's best to get the encoding separately from the data rather than try to decode it from the data itself. Chris Angelico From dirk at xanthippe.ping.de Mon Aug 15 12:16:09 2011 From: dirk at xanthippe.ping.de (Dirk Olmes) Date: Mon, 15 Aug 2011 16:16:09 +0000 (UTC) Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: On Fri, 12 Aug 2011 17:02:38 +0000, kj wrote: > *Please* forgive me for asking a Java question in a Python forum. My > only excuse for this no-no is that a Python forum is more likely than a > Java one to have among its readers those who have had to deal with the > same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write tests > for the ported code. (Yes, I've considered finding myself another job, > but this is not an option in the immediate future.) Can't you sidestep the porting effort and try to run everything in Jython on the JVM? -dirk (Python lurker with Java experience) From lukius at gmail.com Mon Aug 15 12:18:35 2011 From: lukius at gmail.com (Lucio Santi) Date: Mon, 15 Aug 2011 13:18:35 -0300 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9asge7Fsv9U6@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti wrote: > On 2011-08-14, Chris Angelico wrote: > > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong > wrote: > >> On 14-8-2011 7:57, rantingrick wrote: > >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." > >>> more than ten times in a single post, you will get an invite to > >>> Guido's next birthday party; where you'll be forced to do shots whist > >>> walking the balcony railing wearing wooden shoes! > >> > >> I lolled about this one, e.g. I laughed out loud. But where > >> are the tulips and windmills for extra credit? > >> > >> Greetings from a Dutchman! > > No credit. E.g., i.e., exampla gratis, means, "for example." > The correct spelling is 'exempli gratia'. It's Latin. i.e., on the other hand, comes from 'id est' ('that is'). Latin too. Regards, Lucio -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Aug 15 12:32:07 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 16:32:07 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: > Seebs wrote: >> I tend to write stuff like >> >> foo.array_of_things.sort.map { block }.join(", ") >> >> I like this a lot more than >> array = foo.array_of_things >> sorted_array = array.sort() >> mapped_array = [block(x) for x in sorted_array] >> ", ".join(mapped_array) > If you insist on a one-liner for four separate operations, what's wrong with > this? > ", ".join([block(x) for x in sorted(foo.array_of_things)]) Nothing in particular; I was just contrasting two styles, not asserting that Python couldn't do that. In general, I don't like to do things that either involve making a lot of variables that are assigned to once and then read from once, or making a whole lot of x = foo(x) type assignments to one variable. It feels cluttered to me. > I think I would be less skeptical about fluent interfaces if they were > written more like Unix shell script pipelines instead of using attribute > access notation: > foo.array_of_things | sort | map block | join ", " Interesting! I think that's probably why I find them so comfortable; shell was one of the first languages I got serious about. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 12:32:07 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 16:32:07 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-15, Roy Smith wrote: > Demand, no, but sometimes it's a good idea. I've been writing computer > programs for close to 40 years, and I still have no clue what most of > the order of operations is. It's just not worth investing the brain > cells to remember such trivia (especially since the details change from > language to language). Beyond remembering the (apparently) universal > rule that {*, /} bind tighter than {+, -}, I pretty much just punt on > everything else and put in extra parens everywhere. > > It's not the most efficient way to write code, and probably doesn't even > result in the prettiest code. But it sure does eliminate those > face-palm moments at the end of a long debugging session when you > realize that somebody got it wrong. Wholehearted agreement. It is conceivable for me to misremember precedence. I am pretty reliable at recognizing which things are in which parens. So I use them even in obvious cases: foo + (3 * 4) Never regretted that. Yes, it's extra typing, a little, but it prevents a whole category of bugs. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From python at mrabarnett.plus.com Mon Aug 15 12:44:15 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Aug 2011 17:44:15 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: <4E494CDF.8040706@mrabarnett.plus.com> On 15/08/2011 17:18, Lucio Santi wrote: > > > On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti > wrote: > > On 2011-08-14, Chris Angelico > wrote: > > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong > > wrote: > >> On 14-8-2011 7:57, rantingrick wrote: > >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use > "e.g." > >>> more than ten times in a single post, you will get an invite to > >>> Guido's next birthday party; where you'll be forced to do shots > whist > >>> walking the balcony railing wearing wooden shoes! > >> > >> I lolled about this one, e.g. I laughed out loud. But where > >> are the tulips and windmills for extra credit? > >> > >> Greetings from a Dutchman! > > No credit. E.g., i.e., exampla gratis, means, "for example." > > > The correct spelling is 'exempli gratia'. It's Latin. > > i.e., on the other hand, comes from 'id est' ('that is'). Latin too. > I remember reading a book about polymorphism in programming. The author said it came from Latin. Nope. From neilc at norwich.edu Mon Aug 15 13:14:27 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Aug 2011 17:14:27 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: <9at2fjF20mU1@mid.individual.net> On 2011-08-15, MRAB wrote: > On 15/08/2011 17:18, Lucio Santi wrote: >> On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti > > wrote: >> >> On 2011-08-14, Chris Angelico > > wrote: >> > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong >> > wrote: >> >> On 14-8-2011 7:57, rantingrick wrote: >> >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use >> "e.g." >> >>> more than ten times in a single post, you will get an invite to >> >>> Guido's next birthday party; where you'll be forced to do shots >> whist >> >>> walking the balcony railing wearing wooden shoes! >> >> >> >> I lolled about this one, e.g. I laughed out loud. But where >> >> are the tulips and windmills for extra credit? >> >> >> >> Greetings from a Dutchman! >> >> No credit. E.g., i.e., exampla gratis, means, "for example." >> >> >> The correct spelling is 'exempli gratia'. It's Latin. Thanks for the correction. >> i.e., on the other hand, comes from 'id est' ('that is'). >> Latin too. > > I remember reading a book about polymorphism in programming. > The author said it came from Latin. Nope. Sounds more like Greek. -- Neil Cerutti From python at bdurham.com Mon Aug 15 13:51:07 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Aug 2011 13:51:07 -0400 Subject: Reusable ways to wrapping thread locking techniques Message-ID: <1313430667.15383.140258129883089@webmail.messagingengine.com> I'm reviewing a lot of code that has thread acquire and release locks scattered throughout the code base. Would a better technique be to use -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Aug 15 13:56:06 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Aug 2011 13:56:06 -0400 Subject: Reusable ways to wrapping thread locking techniques In-Reply-To: <1313430667.15383.140258129883089@webmail.messagingengine.com> References: <1313430667.15383.140258129883089@webmail.messagingengine.com> Message-ID: <1313430966.16911.140258129884193@webmail.messagingengine.com> Hit send too soon ... I'm reviewing a lot of code that has thread acquire and release locks scattered throughout the code base. Would a better technique be to use contextmanagers (for safe granular locking within a function) or decorators (function wide locks) to manage locks or am I making things too complicated? Am I reinventing the wheel by creating my own versions of above or are there off-the-shelf, debugged versions of above that one can use? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 15 14:29:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 14:29:40 -0400 Subject: string to unicode In-Reply-To: <1313422183.3127.5.camel@linux-yu4c.site> References: <4E493936.5030807@gmail.com> <1313422183.3127.5.camel@linux-yu4c.site> Message-ID: On 8/15/2011 11:29 AM, Adam Tauno Williams wrote: > On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: >> if I am using the standard csv library to read contents of a csv file >> which contains Unicode strings (short example: >> '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such >> as decode or encode to transform this string type into a python unicode >> type? Must I know the encoding (byte groupings) of the Unicode? Can I >> get this from the file? Perhaps I need to open the file with particular >> attributes? > > Open the file with a codec and pass that file-like object to csv. > > codecs.open(filename, mode[, encoding[, errors[, buffering]]]) > > In Python 3, just open with open(... encoding = 'xxx') -- Terry Jan Reedy From artur at ergashev.com Mon Aug 15 15:10:22 2011 From: artur at ergashev.com (Artur Ergashev) Date: Mon, 15 Aug 2011 12:10:22 -0700 (PDT) Subject: datetime.strptime w/ non-UTC and non-local TZs? Message-ID: <09311a25-deec-4357-b9de-26ddf70aa2cc@v3g2000vbx.googlegroups.com> I was hoping somebody give me some clarity on how datetime.strptime is supposed to work, I'm thinking this is a bug, but wanted to see if the community has any ideas before I submit a bug to the python tracker. For reference I am in the CDT timezone... >>> from datetime import datetime >>> date_utc = "Sun Jul 24 02:54:11 UTC 2011" >>> date_local = "Sun Jul 24 02:54:11 CDT 2011" >>> date_other = "Sun Jul 24 02:54:11 PDT 2011" >>> print datetime.strptime(date_utc, '%a %b %d %H:%M:%S %Z %Y') 2011-07-24 02:54:11 >>> print datetime.strptime(date_local, '%a %b %d %H:%M:%S %Z %Y') 2011-07-24 02:54:11 >>> print datetime.strptime(date_other, '%a %b %d %H:%M:%S %Z %Y') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/_strptime.py", line 325, in _strptime (data_string, format)) ValueError: time data 'Sun Jul 24 02:54:11 PDT 2011' does not match format '%a %b %d %H:%M:%S %Z %Y' The format is correct, and it can parse UTC (as mentioned in the documentation), and it can parse CDT (which is my current time zone), but using another timezone causes it to fail. Trying to parse the failing timezone on a computer set on that timezone works correctly. The documentation seems to indicate that parsing non-UTC TZs isn't guaranteed to work, but in that case the exception is non-clear (perhaps there's no elegant solution here). From PointedEars at web.de Mon Aug 15 15:37:18 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 15 Aug 2011 21:37:18 +0200 Subject: string to unicode References: <4E493936.5030807@gmail.com> Message-ID: <21539106.hDsTRIgEHo@PointedEars.de> Chris Angelico wrote: > On Mon, Aug 15, 2011 at 4:20 PM, Artie Ziff wrote: >> if I am using the standard csv library to read contents of a csv file >> which contains Unicode strings (short example: >> '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such as >> decode or encode to transform this string type into a python unicode >> type? Must I know the encoding (byte groupings) of the Unicode? Can I get >> this from the file? Perhaps I need to open the file with particular >> attributes? > > Start here: > > http://www.joelonsoftware.com/articles/Unicode.html > > The CSV file, being stored on disk, cannot contain Unicode strings; it > can only contain bytes. If you know the encoding (eg UTF-8, UCS-2, > etc), then you can decode it using that. If you don't, your best bet > is to ask the origin of the file; failing that, check the first few > bytes - if it's "\xFF\xFE" or "\xFE\xFF" or "\xEF\xBB\xBF", then it's > probably UTF-16LE, UTF-16BE, or UTF-8, respectively (those being the > encodings of the BOM). There may be other clues, too, but normally > it's best to get the encoding separately from the data rather than try > to decode it from the data itself. As this problem really is not a new one, there are several more ? if I may say so ? pythonic approaches: Improving Billy Mays' "matching brackets" checker, chardet worked for me (the test file was UTF-8-encoded). Watch for word-wrap: ----------------------------------------------------------------------- # encoding: utf-8 ''' Created on 2011-07-18 @author: Thomas 'PointedEars' Lahn , based on an idea of Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> in ''' import sys, os, chardet pairs = {u'}': u'{', u')': u'(', u']': u'[', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?'} valid = set(v for pair in pairs.items() for v in pair) if __name__ == '__main__': for dirpath, dirnames, filenames in os.walk(sys.argv[1]): for name in filenames: stack = [' '] file_path = os.path.join(dirpath, name) with open(file_path, 'rb') as f: reported = False lines = enumerate(f, 1) encoding = chardet.detect(''.join(map(lambda x: x[1], lines)))['encoding'] chars = ((c, line_no, col) for line_no, line in lines for col, c in enumerate(line.decode(encoding), 1) if c in valid) for c, line_no, col in chars: if c in pairs: if stack[-1] == pairs[c]: stack.pop() else: if not reported: first_bad = (c, line_no, col) reported = True else: stack.append(c) print '%s: %s' % (name, ("good" if len(stack) == 1 else "bad '%s' at %s:%s" % first_bad)) ----------------------------------------------------------------------- HTH -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rantingrick at gmail.com Mon Aug 15 17:21:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 14:21:24 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <779fe0b7-bb06-4bbe-8469-9b846f764a60@x2g2000yql.googlegroups.com> On Aug 15, 2:31?am, Terry Reedy wrote: > On 8/15/2011 12:28 AM, Seebs wrote: > > To repeat again: you are free to put in explicit dedent markers that > will let you re-indent code should all indents be removed. As Terry has been trying to say for a while now, use the following methods to quell your eye pain. ------------------------------------------------------------ Use pass statement: ------------------------------------------------------------ if foo: if bar: baz else: pass else: quux ------------------------------------------------------------ Use comments: ------------------------------------------------------------ if foo: if bar: baz #else bar (or endif or whatever you like) else: quux ------------------------------------------------------------ Use road signs: :-) ------------------------------------------------------------ # [Warning: Curves Ahead: Eyeball Parse limit 35 WPM!] if foo: # [Exit 266: "foo"] --> # [Right Curve Ahead: slow eyeball parsing to 15 WPM!] if bar: baz else: pass # <-- [Warning: Do not litter!] else: # [Exit 267: "Not Foo"] --> # [Right Curve Ahead: slow eyeball parsing to 15 WPM!] quux ... # [Eyeball Parse limit 55 WPM!] ... # [PSA: Friends don't let friends write asinine code] ... # [Next Rest Stop: NEVER!] ------------------------------------------------------------ Now you have the nice triangular shape that your eyes have been trained to recognize! I would suggest to use comments whenever possible. Of course there will be times when you cannot use a comment and must use an else clause. Now you have nothing to complain about :). From grickert at coldstorage.com Mon Aug 15 17:52:05 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Mon, 15 Aug 2011 17:52:05 -0400 Subject: Why no warnings when re-assigning builtin names? Message-ID: With surprising regularity, I see program postings (eg. on StackOverflow) from inexperienced Python users accidentally re-assigning built-in names. For example, they'll innocently call some variable, "list", and assign a list of items to it. ...and if they're _unlucky_ enough, their program may actually work (encouraging them to re-use this name in other programs). If they try to use an actual keyword, both the interpreter and compiler are helpful enough to give them a syntax error, but I think the builtins should be "pseudo-reserved", and a user should explicitly have to do something *extra* to not receive a warning. I'd suggest: "from __future__ import allow_reassigning_builtins", but I think this abuse of the __future__ module likely isn't welcome. I know that for testing purposes, this functionality is very convenient, and I'm not suggesting it be removed. In these cases, it would be trivial to just require something explicit, telling the interpreter that the programmer was aware they were assigning to a builtin name. The situation is slightly different for modules that come with Python. Most of us would cringe when seeing something like: `string = "Some string"`; but at least the user has to explicitly import the string module for this to actually cause issues (other than readability). What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? Regards, Gerrat -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Aug 15 18:13:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 18:13:02 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <82392F42-1136-46F5-ACD7-618D7E21781A@semanchuk.com> On Aug 15, 2011, at 5:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on > StackOverflow) from inexperienced Python users accidentally > re-assigning built-in names. > > > > For example, they'll innocently call some variable, "list", and assign a > list of items to it. > > ...and if they're _unlucky_ enough, their program may actually work > (encouraging them to re-use this name in other programs). Or they'll assign a class instance to 'object', only to cause weird errors later when they use it as a base class. I agree that this is a problem. The folks on my project who are new-ish to Python overwrite builtins fairly often. Since there's never been any consequence other than my my vague warnings that something bad might happen as a result, it's difficult for them to develop good habits in this regard. It doesn't help that Eclipse (their editor of choice) doesn't seem to provide a way of coloring builtins differently. (That's what I'm told, anyway. I don't use it.) > If they try to use an actual keyword, both the interpreter and compiler > are helpful enough to give them a syntax error, but I think the builtins > should be "pseudo-reserved", and a user should explicitly have to do > something *extra* to not receive a warning. Unfortunately you're suggesting a change to the language which could break existing code. I could see a use for "from __future__ import squawk_if_i_reassign_a_builtin" or something like that, but the current default behavior has to remain as it is. JMO, Philip From rosuav at gmail.com Mon Aug 15 18:15:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 23:15:01 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on StackOverflow) > from inexperienced Python users ?accidentally re-assigning built-in names. > > For example, they?ll innocently call some variable, ?list?, and assign a > list of items to it. It's actually masking, not reassigning. That may make it easier or harder to resolve the issue. If you want a future directive that deals with it, I'd do it the other way - from __future__ import mask_builtin_warning or something - so the default remains as it currently is. But this may be a better job for a linting script. ChrisA From usenet-nospam at seebs.net Mon Aug 15 18:33:30 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 22:33:30 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: On 2011-08-15, Ethan Furman wrote: > Gerrat Rickert wrote: >> What sayest the Python community about having an explicit warning >> against such un-pythonic behaviour (re-assigning builtin names)? > What makes you think this behavior is unpythonic? Python is not about > hand-holding. It seems like something which is sufficiently likely to be a mistake might deserve a warning -- especially since, so far as I can tell, there's never going to be a program which can't easily be written to avoid the problematic behavior. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Mon Aug 15 18:34:51 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 15 Aug 2011 15:34:51 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <4E499F0B.30900@stoneleaf.us> Gerrat Rickert wrote: > What sayest the Python community about having an explicit warning > against such un-pythonic behaviour (re-assigning builtin names)? What makes you think this behavior is unpythonic? Python is not about hand-holding. ~Ethan~ From benjamin.kaplan at case.edu Mon Aug 15 18:52:42 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Aug 2011 18:52:42 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Aug 15, 2011 5:56 PM, "Gerrat Rickert" wrote: > > With surprising regularity, I see program postings (eg. on StackOverflow) from inexperienced Python users accidentally re-assigning built-in names. > > > > For example, they?ll innocently call some variable, ?list?, and assign a list of items to it. > > ...and if they?re _unlucky_ enough, their program may actually work (encouraging them to re-use this name in other programs). > > > > If they try to use an actual keyword, both the interpreter and compiler are helpful enough to give them a syntax error, but I think the builtins should be ?pseudo-reserved?, and a user should explicitly have to do something *extra* ... > > > What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? > One of Python's greatest strength's in my opinion is that it strives for consistency. As much as possible, Python avoids differentiating between built-in objects (types or otherwise) and user-defined objects. I think it should stay that way. There are tools that can detect these errors and their use should be encouraged, but the Python interpreter shouldn't single out variables which are types that happen to be built-in from any other variable or any other type. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Aug 15 19:12:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 15 Aug 2011 16:12:07 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <4E49A7C7.5090701@stoneleaf.us> Seebs wrote: > On 2011-08-15, Ethan Furman wrote: >> Gerrat Rickert wrote: >>> What sayest the Python community about having an explicit warning >>> against such un-pythonic behaviour (re-assigning builtin names)? > >> What makes you think this behavior is unpythonic? Python is not about >> hand-holding. > > It seems like something which is sufficiently likely to be a mistake might > deserve a warning -- especially since, so far as I can tell, there's never > going to be a program which can't easily be written to avoid the problematic > behavior. "sufficiently likely" depends entirely on who is doing the coding. I use `open()` for opening my files, and so regularly use `file` as a name. It can also be very handy to mask a built-in when doing something even more fun and entertaining and I, for one, have zero desire to have Python start warning me about perfectly legitimate code. Programmers need to learn whichever language they are choosing to code in, and if extra help is needed beyond whatever is basic for that language, find (or write! ;) the third-party tool to help out. There are at least two linters for Python, and multiple IDEs that can help with these, and other, problems. (I don't much care for IDEs, but I am thinking of starting to use a linter, myself.) ~Ethan~ From dajo.mail at web.de Mon Aug 15 19:26:54 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 01:26:54 +0200 Subject: testing if a list contains a sublist Message-ID: <4E49AB3E.9000801@web.de> hi list, what is the best way to check if a given list (lets call it l1) is totally contained in a second list (l2)? for example: l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 my problem is the second example, which makes it impossible to work with sets insteads of lists. But something like set.issubset for lists would be nice. greatz Johannes From drsalists at gmail.com Mon Aug 15 19:32:53 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 15 Aug 2011 16:32:53 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 2:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on StackOverflow) > from inexperienced Python users accidentally re-assigning built-in names. > http://pypi.python.org/pypi/pylint checks for this and many other issues. I don't know if pyflakes or pychecker do. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Mon Aug 15 19:37:21 2011 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 16 Aug 2011 09:37:21 +1000 Subject: Reusable ways to wrapping thread locking techniques In-Reply-To: <1313430966.16911.140258129884193@webmail.messagingengine.com> References: <1313430966.16911.140258129884193@webmail.messagingengine.com> Message-ID: <20110815233720.GA30163@cskk.homeip.net> On 15Aug2011 13:56, python at bdurham.com wrote: | I'm reviewing a lot of code that has thread acquire and release | locks scattered throughout the code base. | | Would a better technique be to use contextmanagers (for safe | granular locking within a function) or decorators (function wide | locks) to manage locks or am I making things too complicated? No, you're on the money. | Am I reinventing the wheel by creating my own versions of above | or are there off-the-shelf, debugged versions of above that one | can use? I routinely have: some_lock = allocate_lock() ... with some_lock: code here! Doing the equivalent with decorators to make monitors seems perfectly reasonable to me too. Do it all with context managers if you can; they do reliable lock release even when an exception occurs, and don't clutter the code with distracting and hard to verify cleanup code. It's worth it just to make everything more readable. The fact that it makes the code smaller and easier to maintain and less bug prone is just sugar. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ My mind is like a blotter: Soaks it up, gets it backwards. From drsalists at gmail.com Mon Aug 15 19:38:51 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 15 Aug 2011 16:38:51 -0700 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: Check out collections.Counter if you have 2.7 or up. If you don't, google for multiset or bag types. On Mon, Aug 15, 2011 at 4:26 PM, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Aug 15 20:10:21 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 00:10:21 +0000 (UTC) Subject: Data issues with Django and Apache References: Message-ID: In John Gordon writes: > The problem is that I get conflicting results as to whether these temporary > records have reached their expiration date, depending if I search for them > via an Apache web call or if I do the search locally from a python shell. > And to make it weirder, the conflicts go away if I stop and restart the > Apache server, although any new records created after this point will still > exhibit the issue. The problem turned out to be a class variable that contained a time filter with the "current" time. But since it was a class variable, it was only evaluated once upon import and its idea of "now" was forever frozen at that moment, so it always compared as being less than any of the lock records that were passed in. I changed it to be a class method that constructs and returns a new time filter whenever it is called. Thanks for everyone's help! -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From roy at panix.com Mon Aug 15 20:30:53 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:30:53 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e492d08$0$30003$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I'm reminded of this quote from John Baez: > > "The real numbers are the dependable breadwinner of the family, the complete > ordered field we all rely on. The complex numbers are a slightly flashier > but still respectable younger brother: not ordered, but algebraically > complete. The quaternions, being noncommutative, are the eccentric cousin > who is shunned at important family gatherings. But the octonions are the > crazy old uncle nobody lets out of the attic: they are nonassociative." Wow, at first glance, I mis-parsed that name as "Joan Baez". Had me really confused for a moment. From roy at panix.com Mon Aug 15 20:34:03 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:34:03 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Or: "Blasted PHP, which > operators have precedence between || and or?" which is easy to forget. > > And you're right about the details changing from language to language, > hence the operators table *for each language*. But most languages > follow fairly sane rules How dare you use the words "PHP" and "sane" in two adjoining paragraphs! From rosuav at gmail.com Mon Aug 15 20:37:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 01:37:21 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Tue, Aug 16, 2011 at 1:34 AM, Roy Smith wrote: > In article , > ?Chris Angelico wrote: > >> Or: "Blasted PHP, which >> operators have precedence between || and or?" which is easy to forget. >> >> And you're right about the details changing from language to language, >> hence the operators table *for each language*. But most languages >> follow fairly sane rules > > How dare you use the words "PHP" and "sane" in two adjoining paragraphs! By separating them with the word "most". ChrisA From usenet-nospam at seebs.net Mon Aug 15 20:39:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 00:39:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-16, Roy Smith wrote: > In article <4e492d08$0$30003$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: >> I'm reminded of this quote from John Baez: >> "The real numbers are the dependable breadwinner of the family, the complete >> ordered field we all rely on. The complex numbers are a slightly flashier >> but still respectable younger brother: not ordered, but algebraically >> complete. The quaternions, being noncommutative, are the eccentric cousin >> who is shunned at important family gatherings. But the octonions are the >> crazy old uncle nobody lets out of the attic: they are nonassociative." > Wow, at first glance, I mis-parsed that name as "Joan Baez". Had me > really confused for a moment. Would it have been that much weirder than Hedy Lamarr? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From greg.ewing at canterbury.ac.nz Mon Aug 15 20:43:57 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:43:57 +1200 Subject: allow line break at operators In-Reply-To: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9atsqeF442U1@mid.individual.net> Steven D'Aprano wrote: > I'm reminded of this quote from John Baez: > > "...But the octonions are the > crazy old uncle nobody lets out of the attic: they are nonassociative." > > (And don't even ask about the sedenions...) Aren't they the ones that mutilate cattle and abduct people? -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 15 20:48:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:48:08 +1200 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <9att2bF710U1@mid.individual.net> rantingrick wrote: > "Used to" and "supposed to" is the verbiage of children > and idiots. So when we reach a certain age we're meant to abandon short, concise and idomatic ways of speaking, and substitute long words and phrases to make ourselves sound adult and educated? -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 15 20:52:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:52:06 +1200 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9at2fjF20mU1@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> Message-ID: <9att9mF710U2@mid.individual.net> I don't mind people using e.g. and i.e. as long as they use them *correctly*. Many times people use i.e. when they really mean e.g. -- Greg From roy at panix.com Mon Aug 15 20:53:13 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:53:13 -0400 Subject: testing if a list contains a sublist References: Message-ID: In article , Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes import re def sublist(l1, l2): s1 = ''.join(map(str, l1)) s2 = ''.join(map(str, l2)) return re.search(s1, s2) assert sublist([1,2], [1,2,3,4,5]) assert not sublist ([1,2,2], [1,2,3,4,5]) assert not sublist([1,2,3], [1,3,5,7]) (running and ducking) From roy at panix.com Mon Aug 15 20:57:16 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:57:16 -0400 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: In article <9att2bF710U1 at mid.individual.net>, Gregory Ewing wrote: > rantingrick wrote: > > "Used to" and "supposed to" is the verbiage of children > > and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Yup. From greg.ewing at canterbury.ac.nz Mon Aug 15 21:08:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 13:08:36 +1200 Subject: surprising interaction between function scope and class namespace In-Reply-To: References: Message-ID: <9atu8nFebsU1@mid.individual.net> Peter Otten wrote: > LOAD_NAME is pretty dumb, it looks into the local namespace and if that > lookup fails falls back to the global namespace. Someone probably thought "I > can do better", and reused the static name lookup for nested functions for > names that occur only on the right-hand side of assignments in a class. I doubt that it was a conscious decision -- it just falls out of the way the compiler looks up names in its symbol table. In case 1, the compiler finds the name 'a' in the function's local namespace and generates a LOAD_FAST opcode, because that's what it does for all function-local names. In case 2, it finds it in the local namespace of the class and generates LOAD_NAME, because that's what it does for all class-local names. The weirdness arises because classes make use of vestiges of the old two-namespace system, which bypasses lexical scoping at run time. -- Greg From rantingrick at gmail.com Mon Aug 15 21:12:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 18:12:53 -0700 (PDT) Subject: Why no warnings when re-assigning builtin names? References: Message-ID: <3ac58c4a-d9cf-454d-94cf-6575aec0912e@j1g2000yqn.googlegroups.com> On Aug 15, 5:13?pm, Philip Semanchuk wrote: > On Aug 15, 2011, at 5:52 PM, Gerrat Rickert wrote: > > > With surprising regularity, I see program postings (eg. on > > StackOverflow) from inexperienced Python users ?accidentally > > re-assigning built-in names. > > > For example, they'll innocently call some variable, "list", and assign a > > list of items to it. > > > ...and if they're _unlucky_ enough, their program may actually work > > (encouraging them to re-use this name in other programs). > > Or they'll assign a class instance to 'object', only to cause weird errors later when they use it as a base class. > > I agree that this is a problem. The folks on my project who are new-ish to Python overwrite builtins fairly often. Simple syntax hilighting can head off these issues with great ease. Heck, python even has a keyword module, and you get a list of built- ins from the dir() function! import keyword import __builtin__ PY_BUILTINS = [str(name) for name in dir(__builtin__) if not name.startswith('_')] PY_KEYWORDS = keyword.kwlist Also Python ships with IDLE (which is a simplistic IDE) and although i find it needs a bit of work to be what GvR initially dreamed, it works good enough to get you by. I always say, you must use the correct tool for the job, and syntax hilight is a "must have" to avoid these accidents. From chris at simplistix.co.uk Mon Aug 15 21:21:33 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 16 Aug 2011 02:21:33 +0100 Subject: TestFixtures 1.12.0 Released! Message-ID: <4E49C61D.7070909@simplistix.co.uk> Hi All, I'm happy to announce a new release of TestFixtures with the following changes: - OutputCapture has grown a `captured` property and can now be temporarily disabled using their`disable` method: http://packages.python.org/testfixtures/streams.html - Logging can now be captured only when it exceeds a specified logging level: http://packages.python.org/testfixtures/logging.html#only-capturing-specific-logging - The handling of timezones has been reworked in both `test_datetime` and `test_time`. This is not backwards compatible but is much more useful and correct: http://packages.python.org/testfixtures/datetime.html#timezones The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve+comp.lang.python at pearwood.info Mon Aug 15 21:32:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 11:32:09 +1000 Subject: Why no warnings when re-assigning builtin names? References: Message-ID: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert > wrote: >> With surprising regularity, I see program postings (eg. on StackOverflow) >> from inexperienced Python users ?accidentally re-assigning built-in >> names. >> >> For example, they?ll innocently call some variable, ?list?, and assign a >> list of items to it. > > It's actually masking, not reassigning. That may make it easier or > harder to resolve the issue. The usual term is "shadowing builtins", and it's a feature, not a bug :) > If you want a future directive that deals with it, I'd do it the other > way - from __future__ import mask_builtin_warning or something - so > the default remains as it currently is. But this may be a better job > for a linting script. Agreed. It's a style issue, nothing else. There's nothing worse about: def spam(list): pass compared to class thingy: pass def spam(thingy): pass Why should built-ins be treated as more sacred than your own objects? -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 15 21:53:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 11:53:42 +1000 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: <4e49cda7$0$30004$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 10:48 am Gregory Ewing wrote: > rantingrick wrote: >> "Used to" and "supposed to" is the verbiage of children >> and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Say what? "Used to" isn't idiom. It is grammatical English. Avoidance of "used to" is a hyper-correction done by people who don't know as much about English as they think, like "the grammar policeman let Johnny and I off with a warning", perhaps the most widespread hyper-correction in English. (If you take Johnny out of the picture, the policeman let I off with a warning... which is obviously wrong. Whether Johnny was there or not, the policeman let *me* off with a warning.) "Used to" is unexceptional English: http://www.englishpage.com/verbpage/usedto.html http://www.bbc.co.uk/worldservice/learningenglish/youmeus/quiznet/newquiz114.shtml http://www.englishclub.com/grammar/verbs-m_used-to-do.htm http://www.learnenglish.de/grammar/usedtotext2.htm Any-grammatical-errors-are-deliberate-ly y'rs, -- Steven From python at mrabarnett.plus.com Mon Aug 15 21:59:42 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 02:59:42 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9att9mF710U2@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: <4E49CF0E.3010706@mrabarnett.plus.com> On 16/08/2011 01:52, Gregory Ewing wrote: > I don't mind people using e.g. and i.e. as long > as they use them *correctly*. > > Many times people use i.e. when they really > mean e.g. > Can you give me an example? :-) From roy at panix.com Mon Aug 15 22:01:32 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 22:01:32 -0400 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: In article <9att9mF710U2 at mid.individual.net>, Gregory Ewing wrote: > I don't mind people using e.g. and i.e. as long > as they use them *correctly*. The only correct way to use i.e. is to use it to download a better browser. From steve+comp.lang.python at pearwood.info Mon Aug 15 22:12:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 12:12:18 +1000 Subject: testing if a list contains a sublist References: Message-ID: <4e49d510$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 09:26 am Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? This is not the most efficient algorithm, but for short lists it should be plenty fast enough: def contains(alist, sublist): if len(sublist) == 0 or len(sublist) > len(alist): return False start = 0 while True: try: p = alist.index(sublist[0], start) except ValueError: return False for i,x in enumerate(sublist): if alist[p+i] != x: start = p+1 break else: # for loop exits without break return True -- Steven From usenet-nospam at seebs.net Mon Aug 15 22:33:22 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 02:33:22 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: On 2011-08-16, Roy Smith wrote: > In article <9att9mF710U2 at mid.individual.net>, > Gregory Ewing wrote: > >> I don't mind people using e.g. and i.e. as long >> as they use them *correctly*. > > The only correct way to use i.e. is to use it to download a better > browser. Similarly: Boy, is there, e.g., on my face now! -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From philip at semanchuk.com Mon Aug 15 23:23:06 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 23:23:06 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > >> If you want a future directive that deals with it, I'd do it the other >> way - from __future__ import mask_builtin_warning or something - so >> the default remains as it currently is. But this may be a better job >> for a linting script. > > Agreed. It's a style issue, nothing else. There's nothing worse about: > > def spam(list): > pass > > compared to > > class thingy: pass > > def spam(thingy): > pass > > Why should built-ins be treated as more sacred than your own objects? Because built-ins are described in the official documentation as having a specific behavior, while my objects are not. Yes, it can be useful to replace some of the builtins with one's own implementation, and yes, doing so fits in with Python's "we're all consenting adults" philosophy. But replacing (shadowing, masking -- call it what you will) builtins is not everyday practice. On the contrary, as the OP Gerrat pointed out, it's most often done unwittingly by newcomers to the language who have no idea that they've done anything out of the ordinary or potentially confusing. If a language feature is most often invoked accidentally without knowledge of or regard for its potential negative consequences, then it might be worth making it easier to avoid those accidents. bye, Philip From tlikonen at iki.fi Tue Aug 16 00:04:24 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 16 Aug 2011 07:04:24 +0300 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9iovcn.fsf@mithlond.arda> * 2011-08-14T01:44:05-07:00 * Chris Rebert wrote: > I've heard that Dylan is supposedly Lisp, sans parens. > http://en.wikipedia.org/wiki/Dylan_(programming_language) It has copied/derived many features from Lisps but it's not a dialect of Lisp because of the syntax and its consequences. From wuwei23 at gmail.com Tue Aug 16 00:13:53 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Aug 2011 21:13:53 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Steven D'Aprano wrote: > I think I would be less skeptical about fluent interfaces if they were > written more like Unix shell script pipelines instead of using attribute > access notation: > > foo.array_of_things | sort | map block | join ", " I've seen at least one attempt to provide this in Python: http://dev-tricks.net/pipe-infix-syntax-for-python From snorble at hotmail.com Tue Aug 16 00:32:02 2011 From: snorble at hotmail.com (snorble) Date: Mon, 15 Aug 2011 21:32:02 -0700 (PDT) Subject: Windows service in production? Message-ID: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Anyone know of a Python application running as a Windows service in production? I'm planning a network monitoring application that runs as a service and reports back to the central server. Sort of a heartbeat type agent to assist with "this server is down, go check on it" type situations. If using Visual Studio and C# is the more reliable way, then I'll go that route. I love Python, but everything I read about Python services seems to have workarounds ahoy for various situations (or maybe that's just Windows services in general?). And there seem to be multiple layers of workarounds, since it takes py2exe (or similar) and there are numerous workarounds required there, depending on which libraries and functionality are being used. Overall, reading about Windows services in Python is not exactly a confidence inspiring experience. If I knew of a reference example of something reliably running in production, I'd feel better than copying and pasting some code from a guy's blog. From rantingrick at gmail.com Tue Aug 16 00:37:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 21:37:08 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Message-ID: On Aug 15, 11:13?pm, alex23 wrote: > Steven D'Aprano wrote: > > I think I would be less skeptical about fluent interfaces if they were > > written more like Unix shell script pipelines instead of using attribute > > access notation: > > > foo.array_of_things | sort | map block | join ", " > > I've seen at least one attempt to provide this in Python: If you want 100% OOP then use Ruby: rb> [3,100,-20].sort.join('<#>') -20<#>3<#>100 Ruby is great from this angle! The reading proceeds naturally from right to left. I have become accustomed to reading Python's nested function calls however it does feel much more natural in Ruby. Of course, there are architectural reasons why Python cannot do this linear syntactical processing which lends some paradigm-al niceties to the python programmer that are not available to the Ruby folks. From rantingrick at gmail.com Tue Aug 16 00:50:51 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 21:50:51 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> On Aug 15, 7:48?pm, Gregory Ewing wrote: > rantingrick wrote: > > "Used to" and "supposed to" is the verbiage of children > > and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Well that is the idea anyway. Not that we should be overly pedantic about it of course, however some words need to be cast off before we leave the "primary school playground" in the name of articulate communication. These specific phrases i have pointed out ("used to" and "supposed to") are a result of a mind choosing the easy way out instead of putting in the wee bit more effort required to express one's self in an articulate manner. Also these two phrases are quite prolifically used within his community (among others), from the BDFL on down. It's a slippery slope my friend. From steve+comp.lang.python at pearwood.info Tue Aug 16 01:15:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 15:15:01 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: > > On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: > >> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >> >>> If you want a future directive that deals with it, I'd do it the other >>> way - from __future__ import mask_builtin_warning or something - so >>> the default remains as it currently is. But this may be a better job >>> for a linting script. >> >> Agreed. It's a style issue, nothing else. There's nothing worse about: >> >> def spam(list): >> pass >> >> compared to >> >> class thingy: pass >> >> def spam(thingy): >> pass >> >> Why should built-ins be treated as more sacred than your own objects? > > Because built-ins are described in the official documentation as having a > specific behavior, while my objects are not. *My* objects certainly are, because I write documentation for my code. My docs are no less official than Python's docs. You can shadow anything. Sometimes shadowing is safe, sometimes it isn't. I don't see why we should necessarily fear safe shadowing of built-ins more than we fear unsafe shadowing of non-built-ins. (I'm not even convinced that making None a reserved word was the right decision.) A warning that is off by default won't help the people who need it, because they don't know enough to turn the warning on. A warning that is on by default will be helpful to the newbie programmer for the first week or so, and then will be nothing but an annoyance for the rest of their career. (For some definition of a week -- some people are slower learners than others.) > Yes, it can be useful to replace some of the builtins with one's own > implementation, and yes, doing so fits in with Python's "we're all > consenting adults" philosophy. But replacing (shadowing, masking -- call > it what you will) builtins is not everyday practice. On the contrary, as > the OP Gerrat pointed out, it's most often done unwittingly by newcomers > to the language who have no idea that they've done anything out of the > ordinary or potentially confusing. Protecting n00bs from their own errors is an admirable aim, but have you considered that warnings for something which may be harmless could do more harm than good? Beginners often lack the skill to distinguish between harmless warnings that can safely be ignored, and fatal errors that need to be fixed. Even "user friendly" warning or error messages tend to unnerve some beginner coders. There's not much we can do about outright errors, except to make sure that the error string is as useful as possible, but we can avoid overloading beginners with warnings they don't need to care about: WARNING WARNING WARNING WILL ROBINSON, DANGER DANGER DANGER: YOUR SISTER'S NAME 'PENNY' SHADOWS THE BRITISH CURRENCY, POTENTIAL AMBIGUITY ALERT DANGER DANGER DANGER! *wink* Depending on their personality, you may end up teaching them to ignore warnings, or a superstitious dread of anything that leads to a warning. Neither is a good outcome. > If a language feature is most often invoked accidentally without knowledge > of or regard for its potential negative consequences, then it might be > worth making it easier to avoid those accidents. Perhaps. But I'm not so sure it is worth the cost of extra code to detect shadowing and raise a warning. After all, the average coder probably never shadows anything, and for those that do, once they get bitten *once* they either never do it again or learn how to shadow safely. I don't see it as a problem. -- Steven From thinke365 at gmail.com Tue Aug 16 01:15:05 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 13:15:05 +0800 Subject: How to use python environment created using virtualenv? Message-ID: I have created a python environment using virtualenv, but when i want to import such environment to PyDev, error just appears, it tells there should be a Libs dir, but there is no Libs DIr in the virtual envronment created using virtualenv, what should i do if i want to use this virtual environment? From cbrown at cbrownsystems.com Tue Aug 16 02:13:55 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:13:55 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <5b08f0ef-6dd5-445b-8526-2870cb6a4d62@p19g2000yqa.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From cbrown at cbrownsystems.com Tue Aug 16 02:14:07 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:14:07 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <79ff0c63-d64e-4236-9839-eb56a329b8d0@e35g2000yqc.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From cbrown at cbrownsystems.com Tue Aug 16 02:14:14 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:14:14 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From wuwei23 at gmail.com Tue Aug 16 02:49:25 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Aug 2011 23:49:25 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Message-ID: <379fb990-c471-47d2-a349-edfe6bc94956@o11g2000yql.googlegroups.com> On Aug 16, 2:37?pm, rantingrick wrote: > The reading proceeds naturally from right to left. Well, "naturally" if you're coding in Hebrew or Japanese perhaps :) From gandalf at shopzeus.com Tue Aug 16 02:51:25 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 08:51:25 +0200 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A136D.2030207@shopzeus.com> >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. >> >> greatz Johannes Fastest, error-free and simplest solution is to use sets: >>> l1 = [1,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set([]) >>> set(l2)-set(l1) set([3, 4, 5]) >>> Although with big lists, this is not very memory efficient. But I must tell you, sometimes I use this method for lists with millions of integers, and it is very fast and reliable, and memory is not a concern for me, at least - some million integers will fit into a few MB of memory. Read the docs about set operators for creating union, symmetric difference etc. Best, Laszlo From dannwong at cisco.com Tue Aug 16 03:00:22 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 02:00:22 -0500 Subject: regular expression In-Reply-To: <4E499F0B.30900@stoneleaf.us> References: <4E499F0B.30900@stoneleaf.us> Message-ID: Hi All, If I get multiline standard output from a command. How can I retrieve this part of the string "(1006)" Example: #Committing... #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" # Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" # Outgoing: # Change sets: # (1006) *--@ # Changes: # ---c- /he-Group/o-PI/target/config/common-ngp/makefile From dannwong at cisco.com Tue Aug 16 03:03:50 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 02:03:50 -0500 Subject: subprocess.Popen question In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: Hi All, I'm executing a command which I want to capture the standard/stderr output into a file (which I have with the code below), but I also want the standard output to go into a variable so I can process the information for the next command. Any ideas? Thanks. CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, stderr=subprocess.STDOUT) From clp2 at rebertia.com Tue Aug 16 03:07:46 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 00:07:46 -0700 Subject: subprocess.Popen question In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: On Tue, Aug 16, 2011 at 12:03 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. Pipe it thru `tee`: http://en.wikipedia.org/wiki/Tee_%28command%29 Cheers, Chris From wuwei23 at gmail.com Tue Aug 16 03:07:53 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:07:53 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> Message-ID: rantingrick wrote: > These specific phrases i have pointed out ("used to" and "supposed > to") are a result of a mind choosing the easy way out instead of > putting in the wee bit more effort required to express one's self in > an articulate manner. Also these two phrases are quite prolifically > used within his community (among others), from the BDFL on down. All the way down indeed. Can you pick who said these? "There are noobs watching and we to provide code that can be used to teach!" "And just what *point* an i supposed to be "getting" Stephen?" "An end user should NEVER EVER have to write glue code so their "abstraction of choice" can be used to to script an API." (For bonus points: can you also spot who is bored at work today?) From wuwei23 at gmail.com Tue Aug 16 03:14:08 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:14:08 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> On Aug 16, 4:51?pm, Laszlo Nagy wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> ?l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> ?l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> ?l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) Error free? Consider this stated requirement: > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set() >>> set(l2)-set(l1) {3, 4, 5} So set([1,2]) == set([1,2,2]), despite [1,2,2] not being a sublist of the original. It also completely ignores list order, which would make [9,8,7] a sublist of [5,6,7,8,9]. From wuwei23 at gmail.com Tue Aug 16 03:19:20 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:19:20 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <51581f4b-f74b-4df1-ae76-a65064b5dc27@s2g2000vby.googlegroups.com> Laszlo Nagy wrote: > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) > ?>>> Error-free? Not given the stated requirements: > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set() >>> set(l2)-set(l1) {3, 4, 5} As you can see, using sets provides the exact same result for a non- contained sub-list as it does for your valid example. The list [1,2,2,2,2,2,2,2,2] is clearly not contained with [1,2,3], but your code would say it is. Similarly, [9,8,7] would appear to be a sub-list of [5,6,7,8,9], something I'd also considered to be false in this instance. (My apologies if this is a double-up, the original post hasn't appeared yet) From cbrown at cbrownsystems.com Tue Aug 16 03:24:24 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Tue, 16 Aug 2011 00:24:24 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <636abfaa-a36f-4a67-af7f-59c19beb924a@gz5g2000vbb.googlegroups.com> On Aug 15, 11:51?pm, Laszlo Nagy wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> ?l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> ?l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> ?l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) > ?>>> > This approach fails the OP's desires when >>> l1 = [1,2,2,] >>> l2 = [1,2,3,4,5] The OP explicitly desires 'l2 contains l1' to be false in that case. Cheers - Chas From clp2 at rebertia.com Tue Aug 16 03:26:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 00:26:21 -0700 Subject: regular expression In-Reply-To: References: <4E499F0B.30900@stoneleaf.us> Message-ID: On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?If I get multiline standard output from a command. How can I > retrieve this part of the string "(1006)" > Example: > > #Committing... > #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" > # ?Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" > # ? ?Outgoing: > # ? ? ?Change sets: > # ? ? ? ?(1006) ?*--@ ? > # ? ? ? ? ?Changes: > # ? ? ? ? ? ?---c- /he-Group/o-PI/target/config/common-ngp/makefile Assuming the #s aren't in the actual output: import re pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) print(pat.search(your_str).group(1)) Obviously can vary depending on how you want to go about defining the target string. Cheers, Chris P.S. If you reply, please remove my email addresses from the quotation due to "On Behalf Of" brokenness. -- Freakin' Outlook/Exchange, I'm telling ya... http://rebertia.com From __peter__ at web.de Tue Aug 16 03:44:13 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2011 09:44:13 +0200 Subject: testing if a list contains a sublist References: <4E49AB3E.9000801@web.de> Message-ID: Johannes wrote: > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer that assumes yes and another that assume no. From smainklh at gmail.com Tue Aug 16 03:45:56 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 09:45:56 +0200 Subject: Linux : create a user if not exists Message-ID: Hi all, I'm learning the python language and i'm trying to create a user if it is not found in the system. I figured it out by doing the following thing : >>> def finduser(user): ... for line in open('/etc/passwd'): ... if line.startswith(user): ... print user, "user exists" ... return True ... return False >>> if not finduser('myuser'): ... print "Creating user myuser" ... os.system('/usr/sbin/useradd myuser') But i think it's a dirty way to do so. Is there another way to manage users with python ? Thank you :) Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Aug 16 03:52:37 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Aug 2011 08:52:37 +0100 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <4E4A21C5.30306@timgolden.me.uk> On 16/08/2011 05:32, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. Don't know what it'll take to inspire you with confidence, but I have several Python services running here without a hitch. The longest have been running for about three years -- not without a stop, since they have to be restarted for reasons external to the service itself. There's no py2exe involved, just the pywin32 service wrappers. (The apps in question are also set up to run standalone for testing etc.). They're mostly around a helpdesk system: one app ingests email requests to the helpdesk; another post-processes call changes, currently to send out email alerts to interested parties; another triggers alarms on calls for various purposes, etc. I don't claim they're the most sophisticated pieces of code on Earth, but it doesn't sound like you're after anything spectacular either. TJG From gandalf at shopzeus.com Tue Aug 16 04:00:15 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 10:00:15 +0200 Subject: testing if a list contains a sublist In-Reply-To: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> References: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> Message-ID: <4E4A238F.7030003@shopzeus.com> > Error free? Consider this stated requirement: >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 If you look it the strict way, "containment" relation for lists is meant this way: l1 = [] l2 = [1,l1,2] # l2 CONTAINS l1 But you are right, I was wrong. So let's clarify what the OP wants! For example: l1 = [1,2,2,], l2 = [2,1,2,3,4,5] What is the relation between these two lists? Does l2 contain l1 or not? In other words, is this "containment" relation interpreted on multisets not considering the order of the items? > > It also completely ignores list order, which would make [9,8,7] a > sublist of [5,6,7,8,9]. Exactly. However, from the original post of Johannes it was not clear if the order of the elements counts or not. If It this is interpreted as a multiset relation, it would be easier to use collections.Counter. If the order of elements is important then he can start with a Boyer-Moore algorithm. Best, Laszlo From clp2 at rebertia.com Tue Aug 16 04:04:11 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 01:04:11 -0700 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: On Tue, Aug 16, 2011 at 12:45 AM, smain kahlouch wrote: > Hi all, > > I'm learning the python language and i'm trying to create a user if it is > not found in the system. > I figured it out by doing the following thing : > >>>> def finduser(user): > ...???? for line in open('/etc/passwd'): > ...???????????? if line.startswith(user): > ...???????????????????? print user, "user exists" > ...???????????????????? return True > ...???? return False > But i think it's a dirty way to do so. Is there another way to manage users > with python ? You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): http://docs.python.org/library/pwd.html#pwd.getpwnam Cheers, Chris From wuwei23 at gmail.com Tue Aug 16 04:08:33 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 01:08:33 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: snorble wrote: > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). What workarounds do you mean? Every example I've ever seen makes direct use of the Windows modules for Python. > And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. What about existing code recipes which were featured in the Python Cookbook? http://code.activestate.com/recipes/551780/ Not a hint of pyexe or weird hackery. From rosuav at gmail.com Tue Aug 16 04:16:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 09:16:51 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 2:32 AM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > >> It's actually masking, not reassigning. That may make it easier or >> harder to resolve the issue. > > The usual term is "shadowing builtins", and it's a feature, not a bug :) Sorry, shadowing. And yeah, that's why I said that "fixing" this "issue" was the domain of linting scripts. ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 16 04:19:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 18:19:43 +1000 Subject: testing if a list contains a sublist References: <4e49d510$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4a281f$0$29973$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 12:12 pm Steven D'Aprano wrote: > On Tue, 16 Aug 2011 09:26 am Johannes wrote: > >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > > This is not the most efficient algorithm, but for short lists it should be > plenty fast enough: Nope, sorry, that was buggy. Here's another version which should be accurate but may be slower. def search(source, target, start=0, end=None): """Naive search for target in source.""" m = len(source) n = len(target) if end is None: end = m if n == 0 or m < n: return None for i in range(start, end-n+1): if source[i:i+n] == target: return i return None -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 16 04:37:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 18:37:21 +1000 Subject: testing if a list contains a sublist References: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> Message-ID: <4e4a2c41$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote: > On Aug 15, 4:26?pm, Johannes wrote: >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. >> >> greatz Johannes > > My best guess: > > from collections import Counter There's no reason to think that the Original Poster wants a multiset based solution. He asked about lists and sublists. That's a standard term, like substring: "12" is a substring of "01234". "21" and "13" are not. [1, 2] is a sublist of [0, 1, 2, 3, 4]. [2, 1] and [1, 3] are not. Since lists are ordered, so are sublists. If the OP does want a solution that ignores order, then he needs to describe his problem better. -- Steven From dajo.mail at web.de Tue Aug 16 04:38:17 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 10:38:17 +0200 Subject: testing if a list contains a sublist In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: <4E4A2C79.90609@web.de> Am 16.08.2011 09:44, schrieb Peter Otten: > Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. > > Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer that > assumes yes and another that assume no. > yes it should be contained in the other one. I just work with sorted lists, so i did not think about this case. geatz Johannes From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 16 05:10:45 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 16 Aug 2011 11:10:45 +0200 Subject: subprocess.Popen question In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: Am 16.08.2011 09:03 schrieb Danny Wong (dannwong): > Hi All, > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. > > CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, > stderr=subprocess.STDOUT) This way it won't work - but if you do sp = subprocess.Popen(COMMAND, stdout=subprocess.PIPE, stderr=subprocess.PIPE) you can flexibly work with both of them. But then the two streams can become intermixed. After that, you would have to emulate the select() behaviour of communicate(), but act differently on them. If you get data on stdout, you capture and append to the file, for data on stderr you only append. Maybe this could work for you: def communicate2(self, input): """ input is readable, output is a generator which yields data """ read_set = [] write_set = [] stdout = None # Return stderr = None # Return # Translate newlines, if requested. We cannot let the file # object do the translation: It is based on stdio, which is # impossible to combine with select (unless forcing no # buffering). if self.universal_newlines and hasattr(file, 'newlines'): xlate=lambda s:self._translate_newlines(s) else: xlate=lambda s:s if self.stdin: # Flush stdio buffer. This might block, if the user has # been writing to .stdin in an uncontrolled fashion. self.stdin.flush() if self.stdout: read_set.append(self.stdout) stdout = [] if self.stderr: read_set.append(self.stderr) stderr = [] inpcrsr=0 # der ist neu... rest='' eofseen=False while read_set or write_set: rlist, wlist, xlist = select.select(read_set, write_set, []) if self.stdin in wlist: # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk # blocking. POSIX defines PIPE_BUF >= 512 #pipebuf=512 pipebuf=os.fpathconf(self.stdin.fileno(),'PC_PIPE_BUF') if not eofseen: buf=input.read(pipebuf-len(rest)) # else it stays '' if not buf: eofseen=True if rest or buf: bytes_written = os.write(self.stdin.fileno(), rest+buf) if bytes_written > len(rest): rest=buf[bytes_written-len(rest):] else: rest=rest[bytes_written:]+buf else: self.stdin.close() write_set.remove(self.stdin) if self.stdout in rlist: data = os.read(self.stdout.fileno(), 1024) if data == "": self.stdout.close() read_set.remove(self.stdout) #stdout.append(data) #yield stdout,data yield 1,xlate(data) if self.stderr in rlist: data = os.read(self.stderr.fileno(), 1024) if data == "": self.stderr.close() read_set.remove(self.stderr) #stderr.append(data) yield 2,xlate(data) self.wait() (Im not sure if it is to 100% correct.) This yields tuples (1, ) for stdout data and tuples (2, ) for stderr data. From thinke365 at gmail.com Tue Aug 16 05:15:28 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 17:15:28 +0800 Subject: Anyone here can do a comparation between Djang and RoR Message-ID: what is the advantage of Django over RoR:) From __peter__ at web.de Tue Aug 16 05:26:01 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2011 11:26:01 +0200 Subject: testing if a list contains a sublist References: <4E49AB3E.9000801@web.de> <4E4A2C79.90609@web.de> Message-ID: Johannes wrote: > Am 16.08.2011 09:44, schrieb Peter Otten: >> Johannes wrote: >> >>> what is the best way to check if a given list (lets call it l1) is >>> totally contained in a second list (l2)? >>> >>> for example: >>> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >>> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >>> >>> my problem is the second example, which makes it impossible to work with >>> sets insteads of lists. But something like set.issubset for lists would >>> be nice. >> >> Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer >> that assumes yes and another that assume no. >> > > yes it should be contained in the other one. I just work with sorted > lists, so i did not think about this case. > > geatz Johannes For "short" lists l1: >>> pairs = [ ... ([1,2], [1,2,3,4,5]), ... ([1,2,2,], [1,2,3,4,5]), ... ([1,2,3], [1,3,5,7])] >>> for l1, l2 in pairs: ... contained = all(l1.count(item) <= l2.count(item) for item in set(l1)) ... print l1, ["not in", "in"][contained], l2 ... [1, 2] in [1, 2, 3, 4, 5] [1, 2, 2] not in [1, 2, 3, 4, 5] [1, 2, 3] not in [1, 3, 5, 7] From przemolicc at poczta.fm Tue Aug 16 05:38:00 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Tue, 16 Aug 2011 11:38:00 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: <20110816093800.GB19052@host.pgf.com.pl> On Fri, Aug 12, 2011 at 11:25:06AM +0200, Stefan Behnel wrote: > przemolicc at poczta.fm, 11.08.2011 16:39: >> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >>> On Thu, Aug 11, 2011 at 2:46 PM, wrote: >>>> This is the way I am going to use. >>>> But what is the best data type to hold so many rows and then operate on them ? >>>> >>> >>> List of strings. Take it straight from your Oracle interface and work >>> with it directly. >> >> Can I use this list in the following way ? >> subprocess_1 - run on list between 1 and 10000 >> subprocess_2 - run on list between 10001 and 20000 >> subprocess_3 - run on list between 20001 and 30000 >> etc >> ... > > Sure. Just read the data as it comes in from the database and fill up a > chunk, then hand that on to a process. You can also distribute it in > smaller packets, just check what size gives the best throughput. Since the performance is critical I wanted to use multiprocessing module. But when I get all the source rows into one list of strings can I easly share it between X processes ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From cbrewster at gmail.com Tue Aug 16 06:03:51 2011 From: cbrewster at gmail.com (Christopher Brewster) Date: Tue, 16 Aug 2011 03:03:51 -0700 (PDT) Subject: Messed up Mac installation Message-ID: Are there instructions somewhere online as to how to sort out a messed up installation of Python on a Mac? I have a 2 month old Macbook running Snow Leopard, I installed Python 2.7.1 some time ago. Now when I run 'python' this is what it shows. But easy_install and pip are installing modules to the python2.6 (which shipped with the OS). If I run 'python2.6' then I have access to the modules installed with pip. Oh and weirdly if I tell pip to uninstall modules it says the module does not exist. For example: "/Library/Frameworks/Python.framework/ Versions/2.7/bin/pip run on Tue Aug 16 11:46:28 2011 Cannot uninstall requirement reportlab, not installed" So why is it installing to one place (the 2.6 library) and trying to uninstall elsewhere (the 2.7 library)? I know this has been discussed many times but I do not know how to track this down. Thanks for any pointers. Christopher From aspineux at gmail.com Tue Aug 16 06:33:36 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 03:33:36 -0700 (PDT) Subject: Messed up Mac installation References: Message-ID: <9429a0b0-b17a-4247-ae19-67dfbc5e8636@hl8g2000vbb.googlegroups.com> On Aug 16, 12:03?pm, Christopher Brewster wrote: > Are there instructions somewhere online as to how to sort out a messed > up installation of Python on a Mac? > I have a 2 month old Macbook running Snow Leopard, I installed Python > 2.7.1 some time ago. Now when I run 'python' this is what it shows. > But easy_install and pip are installing modules to the python2.6 > (which shipped with the OS). If I run 'python2.6' then I have access > to the modules installed with pip. pip and easy_install work on directory hierarchy of the running python. then the idea (just the idea, not read sample) python2.7 pip.py **** will install into python2.7 directories python2.7 easy_install.py **** will install into python2.7 directories python2.6 pip.py **** will install into python2.6 directories python2.6 easy_install.py **** will install into python2.6 directories For example (real this time) to install easy_install for your 2.7 wget http://peak.telecommunity.com/dist/ez_setup.py python2.7 ez_setup.py > > Oh and weirdly if I tell pip to uninstall modules it says the module > does not exist. For example: "/Library/Frameworks/Python.framework/ > Versions/2.7/bin/pip run on Tue Aug 16 11:46:28 2011 > Cannot uninstall requirement reportlab, not installed" Probably because you run installed pip from python2.7 directory, that certainly use python2.7 binary, and then pip uninstall from python2.7 directories > > So why is it installing to one place (the 2.6 library) and trying to > uninstall elsewhere (the 2.7 library)? Because you are no using the same pip/easy_install to install or uninstall (or at least the python binary is not the same) > > I know this has been discussed many times but I do not know how to > track this down. > Thanks for any pointers. > > Christopher From lynx.p9 at gmail.com Tue Aug 16 06:47:47 2011 From: lynx.p9 at gmail.com (Alex Po) Date: Tue, 16 Aug 2011 03:47:47 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: Many things already done in RoR if comparing it with Django. From lynx.p9 at gmail.com Tue Aug 16 06:47:47 2011 From: lynx.p9 at gmail.com (Alex Po) Date: Tue, 16 Aug 2011 03:47:47 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: Many things already done in RoR if comparing it with Django. From python.list at tim.thechases.com Tue Aug 16 07:11:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 06:11:13 -0500 Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: <4E4A5051.1020509@tim.thechases.com> On 08/16/2011 04:15 AM, smith jack wrote: > what is the advantage of Django over RoR:) *THE* advantage is that you get to program in Python instead of Ruby. :) -tkc From abhib.py at gmail.com Tue Aug 16 07:17:14 2011 From: abhib.py at gmail.com (Abhishek Bajpai) Date: Tue, 16 Aug 2011 04:17:14 -0700 (PDT) Subject: Application monitoring Message-ID: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> I need to monitor applications like apache, mysql etc there live status, errors etc on my LAN is there any tool or lib for this any help will be appreciated thanks in advance From nobody at nowhere.com Tue Aug 16 07:21:47 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 16 Aug 2011 12:21:47 +0100 Subject: testing if a list contains a sublist References: Message-ID: On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? "Best" is subjective. AFAIK, the theoretically-optimal algorithm is Boyer-Moore. But that would require a fair amount of code, and Python isn't a particularly fast language, so you're likely to get better results if you can delegate most of the leg-work to a native library (along the lines of Roy's suggestion of using regexps). From nitinpawar432 at gmail.com Tue Aug 16 07:25:30 2011 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 16 Aug 2011 16:55:30 +0530 Subject: Application monitoring In-Reply-To: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: We use nagios for such monitoring On Tue, Aug 16, 2011 at 4:47 PM, Abhishek Bajpai wrote: > I need to monitor applications like apache, mysql etc there live > status, errors etc on my LAN is there any tool or lib for this any > help will be appreciated thanks in advance > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Tue Aug 16 07:26:39 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 16 Aug 2011 12:26:39 +0100 Subject: subprocess.Popen question References: <4E49AB3E.9000801@web.de> Message-ID: On Tue, 16 Aug 2011 02:03:50 -0500, Danny Wong (dannwong) wrote: > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. > > CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, > stderr=subprocess.STDOUT) CMD_OUTPUT.wait() with open(PROJECT_LOGFILE,'r') as f: str = f.read() If you're going to be writing it to a file anyhow, reading that file is likely to be faster than the alternatives. From smainklh at gmail.com Tue Aug 16 07:30:11 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 13:30:11 +0200 Subject: Application monitoring In-Reply-To: References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: or shinken ( written in python :) ); Regards, Sam 2011/8/16 Nitin Pawar > We use nagios for such monitoring > > > On Tue, Aug 16, 2011 at 4:47 PM, Abhishek Bajpai wrote: > >> I need to monitor applications like apache, mysql etc there live >> status, errors etc on my LAN is there any tool or lib for this any >> help will be appreciated thanks in advance >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Nitin Pawar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.wray at det.nsw.edu.au Tue Aug 16 07:33:29 2011 From: paul.wray at det.nsw.edu.au (Paul Wray) Date: Tue, 16 Aug 2011 21:33:29 +1000 Subject: Idea for pure-python templates using AST. Message-ID: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Hello all Ive had what I think is a great idea for pure-python templates (I can almost hear the groans, bear with me...) For the impatient, proof of concept is at http://pastie.org/2379978 demonstrating simple substitution, balanced tags using context manager, subtemplates, and template inheritance. I'm posting here to get opinions on: * the merits of the idea, (or otherwise!) * whether there are any established/mature templating systems that use this approach, or whether its come up before, * ideas for improvements and advice on other aspects such as sandboxing * of course, to share the idea in case others want to use it Background: Ive been working on an application that recursively renders html/xml documents from heterogenoeus trees, with separate classes for each document component. First I built my own renderer but was dissatisfied with the repetitive code. Then looked at Mako and Jinja, and used Jinja but was still disatisfied, because I still needed a render method in each class to do preparation, and also the template which was centrally managed by the Jinja loader and environment. I found a way to call templates recursively via Jinja filters, but was not sure that it wouldnt blow up in my face, so I also had separate calls to render the children of each node, and then feed the value to the parent template. I kept thinking that there must be a way to get the brevity and clarity of declarative templates, plus the simplicity of pure python loops, tests and function calls. The idea: Python syntax allows a statement to be a bare literal or identifier. These have no effect on the program. So the function below is legal python: def myFunc(): 'a' x = 45 'b'; 'c'; x So is this (within the appropriate class context of course): def body(self, r): '

'; self.heading; '

' '
    ' for itm in self.items: '
  • '; itm; '
  • ' '
' The idea is simply to use python ASTs to transform this code so that it accumulates the values of the bare expressions. I think this give the best of both worlds - declarative syntax for the template literals, but in a pure python context, giving you all the power of python control statements, classes etc. For application contexts outside pure python code (ie user-created templates) , it would be simple to extend the technique to creating template functions from strings, and insert the resulting methods into a namespace for execution.) I think, given the technique is already working with the AST, that sandboxing should not be too hard either - advice on this aspect would be appreciated. Paul Wray From roy at panix.com Tue Aug 16 07:50:55 2011 From: roy at panix.com (Roy Smith) Date: Tue, 16 Aug 2011 07:50:55 -0400 Subject: regular expression References: <4E499F0B.30900@stoneleaf.us> Message-ID: In article , Chris Rebert wrote: > pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) First rule of regexes in Python is to always use raw strings, to eliminate the doubled backslashes: > pat = re.compile(r"^ *(\([^)]+\))", re.MULTILINE) Is easier to read. From thinke365 at gmail.com Tue Aug 16 08:17:12 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 20:17:12 +0800 Subject: How to install easy_install on windows ? Message-ID: it needs read registry, but the python i used is extracted from .zip, so there is no record in the registry, what should i do in order to install easy_install for my python environment? From alain at dpt-info.u-strasbg.fr Tue Aug 16 08:23:44 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 16 Aug 2011 14:23:44 +0200 Subject: testing if a list contains a sublist References: Message-ID: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Roy Smith writes: >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? [...] > import re > > def sublist(l1, l2): > s1 = ''.join(map(str, l1)) > s2 = ''.join(map(str, l2)) > return re.search(s1, s2) This is complete nonsense (try it on [12] and [1,2]). The original problem is "string searching" (where strings here are sequences of numbers instead of characters). See http://en.wikipedia.org/wiki/String_searching_algorithm for any algorithm (Rabin-Karp seems appropriate to me). -- Alain. From aspineux at gmail.com Tue Aug 16 08:32:18 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:32:18 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> On Aug 16, 1:33?pm, "Paul Wray" wrote: > Hello all > > Ive had what I think is a great idea for pure-python templates (I can almost > hear the groans, bear with me...) > > For the impatient, proof of concept is athttp://pastie.org/2379978 > demonstrating simple substitution, balanced tags using context manager, > subtemplates, ?and template inheritance. You code fail, see below for other comment Traceback (most recent call last): File "Download/pastie-2379978.rb", line 108, in make_template(template1) File "Download/pastie-2379978.rb", line 60, in make_template ast.fix_missing_locations(astFromSrc) File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations _fix(node, 1, 0) File "/usr/lib/python2.6/ast.py", line 132, in _fix _fix(child, lineno, col_offset) File "/usr/lib/python2.6/ast.py", line 132, in _fix _fix(child, lineno, col_offset) File "/usr/lib/python2.6/ast.py", line 121, in _fix if 'lineno' in node._attributes: AttributeError: 'arguments' object has no attribute '_attributes' > > I'm posting here to get opinions on: > * the merits of the idea, (or otherwise!) > * whether there are any established/mature templating systems that use this > approach, or whether its come up before, > * ideas for improvements and advice on other aspects such as sandboxing > * of course, to share the idea in case others want to use it This is very original ! First time I see it. I like it. But how to debug large template ? How to find/detect a missing ? This is very important. This is one big advantage of Genshi over Kid How to report the correct error at the correct line ? How to find/get nice editor to edit large template ? > > Background: Ive been working on an application that recursively renders > html/xml documents from heterogenoeus trees, with separate classes for each > document component. First I built my own renderer but was dissatisfied with > the repetitive code. Then looked at Mako and Jinja, and used Jinja but was > still disatisfied, because I still needed a render method in each class to > do preparation, and also the template which was centrally managed by the > Jinja loader and environment. I found a way to call templates recursively > via Jinja filters, but was not sure that it wouldnt blow up in my face, so I > also had separate calls to render the children of each node, and then feed > the value to the parent template. I kept thinking that there must be a way > to get the brevity and clarity of declarative templates, plus the simplicity > of pure python loops, tests and function calls. > > The idea: > Python syntax allows a statement to be a bare literal or identifier. These > have no effect on the program. > > So the function below is legal python: > > def myFunc(): > ? ? 'a' > ? ? x = 45 > ? ? 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > ? ? ? ? '

'; self.heading; '

' > ? ? ? ? '
    ' > ? ? ? ? for itm in self.items: > ? ? ? ? ? ? '
  • '; itm; '
  • ' > ? ? ? ? '
' > > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. You could call it PHP :-) > > I think this give the best of both worlds - declarative syntax for the > template literals, but in a pure python context, giving you all the power of > python control statements, classes etc. > > For application contexts outside pure python code (ie user-created > templates) , it would be simple to extend the technique to creating template > functions from strings, and insert the resulting methods into a namespace > for execution.) > > I think, given the technique is already working with the AST, that > sandboxing should not be too hard either - advice on this aspect would be > appreciated. Maybe a good idea. But still a lot of work to get the level of existing libraries. Maybe better if mixed with other tools like Genshi to create widget. Maybe next toscawidget could use such a technique. Thanks for sharing > > Paul Wray From ayaskant.swain at gmail.com Tue Aug 16 08:38:01 2011 From: ayaskant.swain at gmail.com (Ayaskant Swain) Date: Tue, 16 Aug 2011 18:08:01 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: Hi Tim, Thanks for your reply. It seems this issue is related to python bug - http://bugs.python.org/issue2528 But the patch code looks complex to me. I want to make changes only in my python script which will read an user given directory path & check it's write access. What is the use of posixmodule.c file? I also went through the link that you provided - http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The code section in this link has a line - sd = win32security.GetFileSecurity (FILENAME, win32security.DACL_SECURITY_INFORMATION) Can we retrieve any write access information from this sd object in the python script? Thanks Ayaskant- ------------------------------------------------------------------------------------------------------- On 12/08/2011 11:41, Ayaskanta Swain wrote: >* Hi,* >* * >* I have a requirement where I need to check the write permissions on a* >* directory on Windows platform. I don?t want to use the python function* >* os.access( ), since it does not work correctly on Windows. It is giving* >* incorrect results to me.* >* * >* Another option of actually creating a temporary file inside the folder &* >* then deleting it to check whether the user has write permissions or not* >* is causing performance issues. It is slowing down our application when* >* we have to check the permissions on hundreds of folders. It also changes* >* the last access time stamp of the folder.* >* * >* So is there any other way such as using Win32API or Win32 security* >* modules to check the permissions?* In general, yes. Depends how finicky you want to get. I take it from your question that you're pretty much unfamiliar with the Windows Security APIs and structures? There's a quite a bit of information around on the subject, but have a look at this first which is at least Python-oriented: http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The trouble is that do what you want, you need to use the AccessCheck API (or emulate its functionality) and this isn't currently exposed by the pywin32 modules. You could run it up yourself with ctypes or by creating a quick extension for the purpose. Alternatively, as I say, you could emulate by scanning the ACLs/ACEs and trying to apply some suitable logic. Frankly, I'd have thought this was harder work :) Hope that helps TJG -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Tue Aug 16 08:39:54 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:39:54 -0700 (PDT) Subject: How to install easy_install on windows ? References: Message-ID: <77f65ea2-3748-4dfa-af7c-498ebe2d3be8@f7g2000vba.googlegroups.com> On Aug 16, 2:17?pm, smith jack wrote: > it needs read registry, but the python i used is extracted from .zip, > so there is no record in the registry, Noone need it, Python dont use any registry key > what should i do in order to install easy_install for my python environment? get ez_setup.py from http://peak.telecommunity.com/dist/ez_setup.py in a command prompt run C:\Your Python Directory\python.exe C:\Your Download directory \ez_setup.py Then use C:\Your Python Directory\python.exe C:\Your Python Directory\I dont know where the easy_install script will be installed\easy_install.py install module_name to install a modul_name Regards From roy at panix.com Tue Aug 16 08:53:58 2011 From: roy at panix.com (Roy Smith) Date: Tue, 16 Aug 2011 08:53:58 -0400 Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Message-ID: In article <8739h18rzj.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Roy Smith writes: > > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > import re > > > > def sublist(l1, l2): > > s1 = ''.join(map(str, l1)) > > s2 = ''.join(map(str, l2)) > > return re.search(s1, s2) > > This is complete nonsense (try it on [12] and [1,2]). No, it's not complete nonsense, it works just fine for the limited data set the OP presented :-) Of course, you are correct that it only works for single-digit integers, hence my "running and ducking" comment. > The original problem is "string searching" (where strings here are > sequences of numbers instead of characters). See > > http://en.wikipedia.org/wiki/String_searching_algorithm > > for any algorithm (Rabin-Karp seems appropriate to me). Yes, of course this is fundamentally a string searching problem. The problem is that while Python comes with an excellent tool for doing these kinds of string searches, its domain is limited to, as you pointed out, character strings. However, for the limited data the OP presented, there is a trivial way to map the original data domain (single digit integers) into the domain the re library knows about (character strings). My answer may be a sucky general-purpose solution, but it's also a neat hack, and sometimes a neat hack is what you need. It also occurs to me that this hack could be expanded a bit to handle a much larger input domain. If you had sequences of arbitrary (but hashable) objects, you could map this into a unicode string where each "character" is the 32-bit hash of of the corresponding input object, then run the regex search on that. In theory, it should work. In practice, I can see a few potential problems: 1) You might have to carefully craft your hash function to avoid magic unicode values like null or BOM. No biggie there. 2) Hash collisions can lead to false positives, so you need to filter those out with a subsequent linear comparison step. Of course, this is true of any kind of hash lookup. No biggie there either. 3) While the re module is advertised to work on unicode data, I have no idea how efficient it is on arbitrary values. I wouldn't be too surprised if it's tuned for "mostly ascii utf-8" and performance suffers on completely random strings. If its first step is to transcode to utf-32 internally, I expect it would work just fine, but it would take some experimentation (or reading of the source code) to validate this assumption. From aspineux at gmail.com Tue Aug 16 08:55:54 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:55:54 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <77300e22-241d-4b85-9758-680ed8ebbfc7@z17g2000vbp.googlegroups.com> On Aug 16, 6:32?am, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. I don't use service for my own python applications, even standalone py2exe applications. I use the Windows taskscheduler that start it once and try every minute to start it again but is is running all the time, and the the scheduler does nothing and wait to see for the next minute. When the python program crash then the scheduler restart it in the minute. look here how I do with tcpproxyreflector: http://blog.magiksys.net/software/tcp-proxy-reflector#tcpr_service In My MKSBackup http://blog.magiksys.net/mksbackup-quick-overview I have a install() function that create the task in the scheduler for XP and Windows2008 And this code, use a 2 min interval print 'create task %s in scheduler' % (task_name, ) interval=raw_input_with_default('Enter interval in minutes', '>', str(interval_in_minutes)) cmd='"%s" -c "%s"' % (os.path.join(install_target, os.path.basename(sys.argv[0])), os.path.join(target, ini_file)) schtasks_cmd=[ 'SCHTASKS', '/Create', '/SC', 'MINUTE', '/MO', interval, '/TN', task_name, '/RU', os.getenv('USERNAME'), '/TR', cmd ] if sys.getwindowsversion()[0]>5: # under 2008 ? require HIGHEST privilege # schtasks_cmd.insert(2, 'HIGHEST') # schtasks_cmd.insert(2, '/RL') # under 2008, to force the system to ask for the password, set empty password i=schtasks_cmd.index('/RU')+2 schtasks_cmd.insert(i, '') schtasks_cmd.insert(i, '/RP') else: pass Mix all 3 source to get what you want. Services are probably fine too, but this is another story. > > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. Overall, reading about Windows > services in Python is not exactly a confidence inspiring experience. > If I knew of a reference example of something reliably running in > production, I'd feel better than copying and pasting some code from a > guy's blog. From miki.tebeka at gmail.com Tue Aug 16 09:32:21 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 16 Aug 2011 06:32:21 -0700 (PDT) Subject: Application monitoring In-Reply-To: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: http://www.nagios.org/ From jjposner at codicesoftware.com Tue Aug 16 09:57:37 2011 From: jjposner at codicesoftware.com (John Posner) Date: Tue, 16 Aug 2011 09:57:37 -0400 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A7751.7050906@codicesoftware.com> On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would require a fair amount of code, and Python > isn't a particularly fast language, so you're likely to get better results > if you can delegate most of the leg-work to a native library (along the > lines of Roy's suggestion of using regexps). > > How about using Python's core support for "==" on list objects: def contains(alist, slist): """ predicate: is *slist* a sublist of *alist*? """ alist_sz = len(alist) slist_sz = len(slist) # special cases if slist_sz == 0: return True # empty list *is* a sublist elif slist_sz == alist_sz and alist == slist: return True elif slist_sz > alist_sz: return False # standard case for i in range(alist_sz - slist_sz + 1): if slist == alist[i:i+slist_sz]: return True # fell through "for" loop: no match found return False -John From jjposner at optimum.net Tue Aug 16 09:57:57 2011 From: jjposner at optimum.net (John Posner) Date: Tue, 16 Aug 2011 09:57:57 -0400 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A7765.9010009@optimum.net> On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would require a fair amount of code, and Python > isn't a particularly fast language, so you're likely to get better results > if you can delegate most of the leg-work to a native library (along the > lines of Roy's suggestion of using regexps). > > How about using Python's core support for "==" on list objects: def contains(alist, slist): """ predicate: is *slist* a sublist of *alist*? """ alist_sz = len(alist) slist_sz = len(slist) # special cases if slist_sz == 0: return True # empty list *is* a sublist elif slist_sz == alist_sz and alist == slist: return True elif slist_sz > alist_sz: return False # standard case for i in range(alist_sz - slist_sz + 1): if slist == alist[i:i+slist_sz]: return True # fell through "for" loop: no match found return False -John From fabiofz at gmail.com Tue Aug 16 10:06:18 2011 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 16 Aug 2011 11:06:18 -0300 Subject: How to use python environment created using virtualenv? In-Reply-To: References: Message-ID: On Tue, Aug 16, 2011 at 2:15 AM, smith jack wrote: > I have created a python environment using virtualenv, but when i want > to import such environment to PyDev, error just appears, > it tells there should be a Libs dir, but there is no Libs DIr in the > virtual envronment created using virtualenv, what should i do if > i want to use this virtual environment? You have to use the Lib dir from the base python (the one you used to create your virtualenv) -- it needs that to have access to the base python library (i.e.: threading.py, etc). Cheers, Fabio From philip at semanchuk.com Tue Aug 16 10:13:36 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 10:13:36 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: > >> >> On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: >> >>> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >>> >>>> If you want a future directive that deals with it, I'd do it the other >>>> way - from __future__ import mask_builtin_warning or something - so >>>> the default remains as it currently is. But this may be a better job >>>> for a linting script. >>> >>> Agreed. It's a style issue, nothing else. There's nothing worse about: >>> >>> def spam(list): >>> pass >>> >>> compared to >>> >>> class thingy: pass >>> >>> def spam(thingy): >>> pass >>> >>> Why should built-ins be treated as more sacred than your own objects? >> >> Because built-ins are described in the official documentation as having a >> specific behavior, while my objects are not. > > *My* objects certainly are, because I write documentation for my code. My > docs are no less official than Python's docs. I'm sure they are no less official to you. But you are you, and then there's...everyone else. =) I (and I think most people) give far more credibility to the Python docs than to the documentation of an individual. That's not a reflection on you, it reflects the limits of one person's ability versus organizationally produced docs which are heavily used, discussed, and have been iteratively developed over many years. > Sometimes shadowing is safe, sometimes it isn't. "Sometimes X is safe and sometimes it isn't" can be said of many, many things, from taking a walk down the street to juggling with knives. But it has little to do with whether or not Python should issue a warning in the specific case we're talking about. > A warning that is off by default won't help the people who need it, because > they don't know enough to turn the warning on. I agree that it wouldn't help the people who need it most (absolute raw newcomers). But you're asserting that once one learned the incantation to enable the theoretical warning we're discussing, one would have graduated to a level where it's no longer useful. That's not the case. There's a lot of ground to cover between "newcomer who has learned about a particular warning" and "coder who regularly shadows builtins on purpose". I am an example. I know enough to turn the theoretical warning on, and I would if I could. I have never shadowed a builtin deliberately. I've done it accidentally plenty of times. There are 84 builtins in my version of Python and I don't have them all memorized. The fact that my editor colors them differently is the only thing I have to back up my leaky memory. Not all editors are so gracious. >> Yes, it can be useful to replace some of the builtins with one's own >> implementation, and yes, doing so fits in with Python's "we're all >> consenting adults" philosophy. But replacing (shadowing, masking -- call >> it what you will) builtins is not everyday practice. On the contrary, as >> the OP Gerrat pointed out, it's most often done unwittingly by newcomers >> to the language who have no idea that they've done anything out of the >> ordinary or potentially confusing. > > Protecting n00bs from their own errors is an admirable aim, but have you > considered that warnings for something which may be harmless could do more > harm than good? Isn't the whole point of a warning to highlight behavior that's not strictly wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble to me. I hope you know what you're doing". If we are to eschew warnings in cases where they might be highlighting something harmless, then we would have no warnings at all. Again, shadowing builtins is not everyday practice. I have been trying to remember if I've ever seen it done deliberately, and I can't remember a case. Now, a comment like that is an invitation for people come out of the woodwork with cases where they found it useful, and I would welcome some examples as I'm sure they'd be interesting. But I think it's safe to say that if you look at random samples of code, builtins are shadowed unintentionally hundreds of times for every time they're shadowed deliberately and usefully. >> If a language feature is most often invoked accidentally without knowledge >> of or regard for its potential negative consequences, then it might be >> worth making it easier to avoid those accidents. > > Perhaps. But I'm not so sure it is worth the cost of extra code to detect > shadowing and raise a warning. After all, the average coder probably never > shadows anything, One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. > and for those that do, once they get bitten *once* they > either never do it again or learn how to shadow safely. I have done it plenty of times, never been bitten (thankfully) and still do it by accident now and again. You can coerce any example to apply to an argument for or against such a warning, but I think the general case is that Python could reduce unintended consequences by warning when vars erase builtins. (<=== How many builtins did I use in that sentence?) Cheers Philip From lists at cheimes.de Tue Aug 16 10:14:33 2011 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Aug 2011 16:14:33 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: Am 16.08.2011 10:04, schrieb Chris Rebert: > You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): > http://docs.python.org/library/pwd.html#pwd.getpwnam You should replace it. /etc/passwd is not the only source for users. /etc/nsswitch.conf may list more user and group sources like nis/yp, LDAP and so on. Christian From thinke365 at gmail.com Tue Aug 16 10:23:46 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 22:23:46 +0800 Subject: Failed to create virtual environment when using --relocatable option, what's wrong? Message-ID: all things works well without --relocatable option, the error info when using --relocatable option is as follows : F:\PythonEnv\djangoEnv>virtualenv f:\PythonEnv\djangoEnv2 --relocatable PYTHONHOME is set. You *must* activate the virtualenv before using it The environment doesn't have a file f:\PythonEnv\djangoEnv2\Scripts\activate_thi s.py -- please re-run virtualenv on this environment to update it Traceback (most recent call last): File "E:\Tools\gov\tools\chrome_python\Scripts\virtualenv-script.py", line 7, in ? sys.exit( File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 802, in main make_environment_relocatable(home_dir) File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 1338, in make_environment_relocatable fixup_scripts(home_dir) File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 1357, in fixup_scripts for filename in os.listdir(bin_dir): WindowsError: [Errno 3] : 'f:\\PythonEnv\\djangoEnv2\\Scripts/*.*' From snorble at hotmail.com Tue Aug 16 10:46:31 2011 From: snorble at hotmail.com (snorble) Date: Tue, 16 Aug 2011 07:46:31 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> On Aug 16, 2:52?am, Tim Golden wrote: > On 16/08/2011 05:32, snorble wrote: > > > Anyone know of a Python application running as a Windows service in > > production? I'm planning a network monitoring application that runs as > > a service and reports back to the central server. Sort of a heartbeat > > type agent to assist with "this server is down, go check on it" type > > situations. > > Don't know what it'll take to inspire you with confidence, but I have > several Python services running here without a hitch. > The longest have been running for about three years -- not without > a stop, since they have to be restarted for reasons external to the > service itself. > > There's no py2exe involved, just the pywin32 service wrappers. (The > apps in question are also set up to run standalone for testing etc.). > They're mostly around a helpdesk system: one app ingests email requests > to the helpdesk; another post-processes call changes, currently to > send out email alerts to interested parties; another triggers alarms > on calls for various purposes, etc. > > I don't claim they're the most sophisticated pieces of code on Earth, > but it doesn't sound like you're after anything spectacular either. > > TJG Interesting. Normally I would use py2exe then do "myapp.exe -install" to install the app as a service. How do you handle installing the service? Also what does the service show under the properties, for the executable? "python.exe script.py" or something else? From thinke365 at gmail.com Tue Aug 16 10:50:23 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 22:50:23 +0800 Subject: why i cannot import djang? Message-ID: this package is already in the site-packages directory, but i cannot import it , it's really confusing ... From pruebauno at latinmail.com Tue Aug 16 10:53:48 2011 From: pruebauno at latinmail.com (nn) Date: Tue, 16 Aug 2011 07:53:48 -0700 (PDT) Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Message-ID: <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> On Aug 16, 8:23?am, Alain Ketterlin wrote: > Roy Smith writes: > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > > import re > > > def sublist(l1, l2): > > ? ? s1 = ''.join(map(str, l1)) > > ? ? s2 = ''.join(map(str, l2)) > > ? ? return re.search(s1, s2) > > This is complete nonsense (try it on [12] and [1,2]). > > The original problem is "string searching" (where strings here are > sequences of numbers instead of characters). See > > http://en.wikipedia.org/wiki/String_searching_algorithm > > for any algorithm (Rabin-Karp seems appropriate to me). > > -- Alain. That can be easily fixed: >>> def sublist(lst1, lst2): s1 = ','.join(map(str, lst1)) s2 = ','.join(map(str, lst2)) return False if s2.find(s1)==-1 else True >>> sublist([1,2],[1,2,3,4,5]) True >>> sublist([1,2,2],[1,2,3,4,5]) False >>> sublist([1,2,3],[1,3,5,7]) False >>> sublist([12],[1,2]) False >>> I don't know about best, but it works for the examples given. From smainklh at gmail.com Tue Aug 16 10:57:27 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 16:57:27 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: Ok than you. You're right but it doesn't help me : I replaced it : >>> def finduser(user): ... if pwd.getpwnam(user): ... print user, "user exists" ... return True ... return False ... >>> finduser('realuser') realuser user exists True >>> finduser('blabla') Traceback (most recent call last): File "", line 1, in ? File "", line 2, in finduser KeyError: 'getpwnam(): name not found: blabla' As you can see, i just want to look for a user and if it doesn't exist, an action is taken (create user). Maybe you have another way to do that check ? Thank you 2011/8/16 Christian Heimes > Am 16.08.2011 10:04, schrieb Chris Rebert: > > You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): > > http://docs.python.org/library/pwd.html#pwd.getpwnam > > You should replace it. /etc/passwd is not the only source for users. > /etc/nsswitch.conf may list more user and group sources like nis/yp, > LDAP and so on. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Aug 16 11:06:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 08:06:12 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> Message-ID: <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> On Aug 16, 2:07?am, alex23 wrote: > All the way down indeed. Can you pick who said these? Obviously your grep skills are superb however you need to brush up on those reading and comprehension skills a bit. > "There are noobs watching and we to provide code that can be used to > teach!" Yes i said this, however the use of "used to" is proper here. -1 > "And just what *point* an i supposed to be "getting" Stephen?" Yes i said this, and it "may" seem that you have me on this one however i believe that Stephen had said something like """you are "supposed to" blah, blah""" and i retorted with """oh, and just what *point* am i "supposed to" blah blah blah"""... although i DID forget to quote "supposed to", still it's a -1. > "An end user should NEVER EVER have to write glue code so their > "abstraction of choice" can be used to to script an API." Yes i said this, however AGAIN the use of "used to" is proper here. -1. sorry alex, better luck next time :(. Follows is some homework i have prepared for you so that you can understand the proper and improper usage of "used to". Incorrect past tense usage of "used to": """ I "used to" wear wooden shoes """ Incorrect description using "used to": """ I have become "used to" wearing wooden shoes """ Correct usage of "used to": """ Wooden shoes can be "used to" torture someone """ For our next assignment we'll be learning about the exploits of Jack and Jill. > (For bonus points: can you also spot who is bored at work today?) Trolling doesn't count as "work" unless you're being paid for it, however some people might consider you a pro by now! PS: Does anyone notice how Stephen has fallen off the face the earth? Where is Stephen i wonder? He was such a vocal nuisance and then he just disappeared. It seemed like he appeared as strangely as he disappeared. Well, he's probably where most sock puppets go when they have no further usage. From k.sahithi2862 at gmail.com Tue Aug 16 11:06:31 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 16 Aug 2011 08:06:31 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: <16538baf-6729-46d6-b4fc-7e9b58a006a0@s2g2000vby.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html KAJAL AGARWAL HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html From rosuav at gmail.com Tue Aug 16 11:12:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 16:12:44 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: On Tue, Aug 16, 2011 at 3:13 PM, Philip Semanchuk wrote: > I am an example. I know enough to turn the theoretical warning on, and I would if I could. I have never shadowed a builtin deliberately. I've done it accidentally plenty of times. There are 84 builtins in my version of Python and I don't have them all memorized. The fact that my editor colors them differently is the only thing I have to back up my leaky memory. Not all editors are so gracious. > Rather than "turn a warning on" you can "run your code through a linting script". There are several excellent ones. Add it to your makefile or test suite; then you get the testing done over _all_ of your code, instead of waiting until the moment when you actually execute it. > One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. > There are several types of shadowing: 1) Deliberate shadowing because you want to change the behavior of the name. Extremely rare. 2) Shadowing simply by using the name of an unusual builtin (like 'file') in a context where you never use it. Very common. 3) Unintentional shadowing where you create a variable, but then intend to use the builtin. This is the only one that's a problem. list = [...] is not a problem unless you later on use foo = list(map(...)) which is more common in Python 3 than Python 2, but fortunately, it'll throw a nice quick error - nobody's going to use list operations on the normal 'list' type, nor is anybody going to call an instance of list. Definitely a job for linting. ChrisA From gandalf at shopzeus.com Tue Aug 16 11:17:08 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 17:17:08 +0200 Subject: testing if a list contains a sublist In-Reply-To: <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <4E4A89F4.3090008@shopzeus.com> > That can be easily fixed: > >>>> def sublist(lst1, lst2): > s1 = ','.join(map(str, lst1)) > s2 = ','.join(map(str, lst2)) > return False if s2.find(s1)==-1 else True > > I don't know about best, but it works for the examples given. > For numbers, it will always work. But what about lst1 = [",",",,"] lst1 = [",",",",","] From dajo.mail at web.de Tue Aug 16 11:26:08 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 17:26:08 +0200 Subject: testing if a list contains a sublist In-Reply-To: <4E4A238F.7030003@shopzeus.com> References: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> <4E4A238F.7030003@shopzeus.com> Message-ID: <4E4A8C10.5090208@web.de> Am 16.08.2011 10:00, schrieb Laszlo Nagy: > >> Error free? Consider this stated requirement: >>> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > If you look it the strict way, "containment" relation for lists is meant > this way: > > > l1 = [] > l2 = [1,l1,2] # l2 CONTAINS l1 > > But you are right, I was wrong. So let's clarify what the OP wants! > > For example: > > l1 = [1,2,2,], l2 = [2,1,2,3,4,5] I dont care about this case, because all list are ordered for me. I've chosen the following solution > def _list_contained_in_list(l1,l2): > d1 = {} > d2 = {} > for i in l1: > if i in d1: > d1[i] += 1 > else: > d1[i] = 1 > for i in l2: > if i in d2: > d2[i] += 1 > else: > d2[i] = 1 > if not all([k in d2.keys() for k in d1.keys()]): > return false > return all([d1[i] <= d2[i] for i in d1]) greatz Johannes From philip at semanchuk.com Tue Aug 16 11:31:30 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 11:31:30 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> On Aug 16, 2011, at 11:12 AM, Chris Angelico wrote: > On Tue, Aug 16, 2011 at 3:13 PM, Philip Semanchuk wrote: > >> One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. >> > > There are several types of shadowing: > > 1) Deliberate shadowing because you want to change the behavior of the > name. Extremely rare. > 2) Shadowing simply by using the name of an unusual builtin (like > 'file') in a context where you never use it. Very common. > 3) Unintentional shadowing where you create a variable, but then > intend to use the builtin. This is the only one that's a problem. Yes, but before you get to #3 you have to go through #2. The way I see it, #2 is setting a trap, #3 is actually stepping in it. I don't want to do either. Neither do I like working with code that has set trap #2 for me. Cheers Philip From philip at semanchuk.com Tue Aug 16 11:38:57 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 11:38:57 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4A8F94.50706@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: > Philip Semanchuk wrote: >> On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: >>> Protecting n00bs from their own errors is an admirable aim, but have you >>> considered that warnings for something which may be harmless could do more >>> harm than good? >> Isn't the whole point of a warning to highlight behavior that's not strictly > > wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble > > to me. I hope you know what you're doing". If we are to eschew warnings in > > cases where they might be highlighting something harmless, then we would > > have no warnings at all. > > Sounds good to me. ;) Keep such things in the IDE's, and then those who desire such behavior can have it there. Do not clutter Python with such. You wink, yet you sound serious. What's with the mixed message? Do you honestly advocate removing all warnings from Python, or not? I sincerely would like to know what you think. >>> Perhaps. But I'm not so sure it is worth the cost of extra code to detect >>> shadowing and raise a warning. After all, the average coder probably never >>> shadows anything, >> One need look no further than the standard library to see a strong > > counterexample. grep through the Python source for " file =". I see dozens >> of examples of this builtin being used as a common variable name. I would > > call contributors to the standard library above-average coders, and we can > > see them unintentionally shadowing builtins many times. > > What makes you think it's unintentional? file makes a good variable name, and if you don't need it to actually open a file there's nothing wrong with using it yourself. "Unintentional" as in, "I'm using file as a variable name because it's handy" as opposed to intentional as in "Yes, I am deliberately changing the meaning of this builtin". >>> and for those that do, once they get bitten *once* they >>> either never do it again or learn how to shadow safely. >> I have done it plenty of times, never been bitten (thankfully) and still > > do it by accident now and again. > > Seems to me the real issue is somebody using a builtin, such as str or int, and that they somehow manage to do this without realizing, "wait a sec', that's one of my variables!" Yes > I don't see that as a problem that Python needs to solve. "need" is a strong word. Python will be fine regardless of whether this changes or not. I believe Python could be improved; that's all I'm arguing. Cheers Philip From alain at dpt-info.u-strasbg.fr Tue Aug 16 11:39:19 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 16 Aug 2011 17:39:19 +0200 Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <87vctx74d4.fsf@dpt-info.u-strasbg.fr> Laszlo Nagy writes: >>>>> def sublist(lst1, lst2): >> s1 = ','.join(map(str, lst1)) >> s2 = ','.join(map(str, lst2)) >> return False if s2.find(s1)==-1 else True >> >> I don't know about best, but it works for the examples given. >> > For numbers, it will always work. I'm not even sure: if str() is locale-sensitive, it may introduce commas in numbers (I don't know whether str() is locale-sensitive, the doc doesn't mention anything.) > But what about > > lst1 = [",",",,"] > lst1 = [",",",",","] Yes. It will also fail on nested lists, for fundamental reasons which are impossible to handle with regexps. (Tough I'm not sure the OP had nested lists in mind.) The "brute-force" algorithm given somewhere else in this thread is probably the way to go, unless the lists are really long, in which case one of the "string searching" algorithm should be used (I would be surprised noone has implemented Boyer-Moore or Karp-Rabin). -- Alain. From ethan at stoneleaf.us Tue Aug 16 11:41:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 08:41:08 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4A8F94.50706@stoneleaf.us> Philip Semanchuk wrote: > On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: >> Protecting n00bs from their own errors is an admirable aim, but have you >> considered that warnings for something which may be harmless could do more >> harm than good? > > Isn't the whole point of a warning to highlight behavior that's not strictly > wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble > to me. I hope you know what you're doing". If we are to eschew warnings in > cases where they might be highlighting something harmless, then we would > have no warnings at all. Sounds good to me. ;) Keep such things in the IDE's, and then those who desire such behavior can have it there. Do not clutter Python with such. >> Perhaps. But I'm not so sure it is worth the cost of extra code to detect >> shadowing and raise a warning. After all, the average coder probably never >> shadows anything, > > One need look no further than the standard library to see a strong > counterexample. grep through the Python source for " file =". I see dozens > of examples of this builtin being used as a common variable name. I would > call contributors to the standard library above-average coders, and we can > see them unintentionally shadowing builtins many times. What makes you think it's unintentional? file makes a good variable name, and if you don't need it to actually open a file there's nothing wrong with using it yourself. >> and for those that do, once they get bitten *once* they >> either never do it again or learn how to shadow safely. > > I have done it plenty of times, never been bitten (thankfully) and still > do it by accident now and again. Seems to me the real issue is somebody using a builtin, such as str or int, and that they somehow manage to do this without realizing, "wait a sec', that's one of my variables!" I don't see that as a problem that Python needs to solve. ~Ethan~ From rantingrick at gmail.com Tue Aug 16 11:44:28 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 08:44:28 -0700 (PDT) Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> On Aug 16, 9:13?am, Philip Semanchuk wrote: > "Sometimes X is safe and sometimes it isn't" can be said > of many, many things, from taking a walk down the street > to juggling with knives. But it has little to do with > whether or not Python should issue a warning in the > specific case we're talking about. I think any Python n00b should be writing code in n editor that is "safe for beginners" AND is also teaching tool. IDLE is probably the best thing a new Python programmer could use. It has syntax hilight, smart indention, call tips, code completion, a class browser, greping tools, and more! I do admit the tool is lacking in many areas (including code base) that would be atrocious to an experienced Pythonista, however, the tool is perfect for n00bs (and myself and other pythoinistas use it all the time!) > There's a lot of ground to cover between "newcomer who has > learned about a particular warning" and "coder who > regularly shadows builtins on purpose". One word: SYNTAX HILIGHT > I have never shadowed a builtin deliberately. I've done it > accidentally plenty of times. There are 84 builtins in my > version of Python and I don't have them all memorized. The > fact that my editor colors them differently is the only > thing I have to back up my leaky memory. Not all editors > are so gracious. So you have syntax hilight however you still shadow builtins? Oh dear, this problem is worse than i initially suspected! > You can coerce any example to apply to an argument for or > against such a warning, but I think the general case is > that Python could reduce unintended consequences by > warning when vars erase builtins. ?(<=== How many builtins > did I use in that sentence?) Well let's see: py> import keyword py> import __builtin__ py> PY_KWS = keyword.kwlist py> PY_BLT = dir(globals()['__builtins__']) py> s = """\ You can coerce any example to apply to an argument for or against such a warning, but I think the general case is that Python could reduce unintended consequences by warning when vars erase builtins. """ py> fmtstr = '{0} -> {1}' py> for word in s.split(' '): ... if word in PY_BLT: ... print fmtstr.format('builtin', word) ... elif word in PY_KWS: ... print fmtstr.format('KeyWord', word) ... builtin -> coerce builtin -> any builtin -> apply KeyWord -> for KeyWord -> or KeyWord -> is builtin -> reduce builtin -> vars From tjreedy at udel.edu Tue Aug 16 11:47:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 11:47:58 -0400 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: On 8/16/2011 7:33 AM, Paul Wray wrote: > Hello all > > Ive had what I think is a great idea for pure-python templates (I can > almost hear the groans, bear with me...) > > For the impatient, proof of concept is at http://pastie.org/2379978 > demonstrating simple substitution, balanced tags using context manager, > subtemplates, and template inheritance. > > I'm posting here to get opinions on: > * the merits of the idea, (or otherwise!) > * whether there are any established/mature templating systems that use > this approach, or whether its come up before, > * ideas for improvements and advice on other aspects such as sandboxing > * of course, to share the idea in case others want to use it > > Background: Ive been working on an application that recursively renders > html/xml documents from heterogenoeus trees, with separate classes for > each document component. First I built my own renderer but was > dissatisfied with the repetitive code. Then looked at Mako and Jinja, > and used Jinja but was still disatisfied, because I still needed a > render method in each class to do preparation, and also the template > which was centrally managed by the Jinja loader and environment. I found > a way to call templates recursively via Jinja filters, but was not sure > that it wouldnt blow up in my face, so I also had separate calls to > render the children of each node, and then feed the value to the parent > template. I kept thinking that there must be a way to get the brevity > and clarity of declarative templates, plus the simplicity of pure python > loops, tests and function calls. > > The idea: > Python syntax allows a statement to be a bare literal or identifier. > These have no effect on the program. More generally, Python has expression statements, with the result of the expression ignored. These are usually function calls with side-effects. "print('x')" has no effect on the program and the return value is usually ignored. > So the function below is legal python: > > def myFunc(): > 'a' > x = 45 > 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' > > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. Interesting idea, though I have no experience for comparison. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 16 11:52:13 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 11:52:13 -0400 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: On 8/16/2011 10:57 AM, smain kahlouch wrote: > Ok than you. You're right but it doesn't help me : > I replaced it : > > >>> def finduser(user): > ... if pwd.getpwnam(user): > ... print user, "user exists" > ... return True > ... return False > ... > >>> finduser('realuser') > realuser user exists > True > >>> finduser('blabla') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 2, in finduser > KeyError: 'getpwnam(): name not found: blabla' > > As you can see, i just want to look for a user and if it doesn't exist, > an action is taken (create user). Replace if/then with try/except control flow try: pwd.getpwnam(user) return True except KeyWordError: return False -- Terry Jan Reedy From alex.kapps at web.de Tue Aug 16 11:56:37 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 16 Aug 2011 17:56:37 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: <4E4A9335.4010700@web.de> On 16.08.2011 16:57, smain kahlouch wrote: > Ok than you. You're right but it doesn't help me : > I replaced it : > > >>> def finduser(user): > ... if pwd.getpwnam(user): > ... print user, "user exists" > ... return True > ... return False > ... > >>> finduser('realuser') > realuser user exists > True > >>> finduser('blabla') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 2, in finduser > KeyError: 'getpwnam(): name not found: blabla' Untested: def finduser(name): try: return pwd.getpwnam(name) except KeyError: return None if not finduser("myuser"): print "creating user..." else: print "user already exists" Has the advantage that finduser() returns the user details if needed. (BTW: Please don't top-post) From python.list at tim.thechases.com Tue Aug 16 12:10:46 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 11:10:46 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> Message-ID: <4E4A9686.2090909@tim.thechases.com> On 08/16/2011 10:31 AM, Philip Semanchuk wrote: > On Aug 16, 2011, at 11:12 AM, Chris Angelico wrote: >> There are several types of shadowing: >> >> 1) Deliberate shadowing because you want to change the behavior of the >> name. Extremely rare. >> 2) Shadowing simply by using the name of an unusual builtin (like >> 'file') in a context where you never use it. Very common. >> 3) Unintentional shadowing where you create a variable, but then >> intend to use the builtin. This is the only one that's a >> problem. > > Yes, but before you get to #3 you have to go through #2. The > way I see it, #2 is setting a trap, #3 is actually stepping > in it. I don't want to do either. Neither do I like working > with code that has set trap #2 for me. Chris succinctly described the times I've done shadowing. Fortunately, the shadowing done in #3 (which you appropriately describe as being a superset of #2) is fairly remedied with most editors...since it usually occurs when you have "oh, I accidentally shadowed builtin X", so you just do a global search-and-replace for all those places you shadowed X and rename it to something like "my_X" and proceed to use X as the builtin. The bigger issue I have is module shadowing which is trickier to catch and produces weird symptoms (i.e. cryptic errors). The most common one I see is creating a local module called "email.py" and then having issues when trying to use standard-library email calls which find your local email.py before they find the email.py file in the standard library. I actually wrote a tool to scan for duplicate modules in $PYTHONPATH (pretty dumb tool, could easily have broken on things like zipfile imports, DLLs, etc), but it made diagnosing the issue easier. -tkc From gordon at panix.com Tue Aug 16 12:12:09 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 16:12:09 +0000 (UTC) Subject: why i cannot import djang? References: Message-ID: In smith jack writes: > this package is already in the site-packages directory, but i cannot > import it , it's really confusing ... Is it in the site-packages directory for the particular version of python you're using? For example, my system has both python2.3 and python2.5 installed, and they both have their own site-packages directories: /usr/lib/python2.3/site-packages /usr/lib/python2.5/site-packages A package installed for only one version of python won't be importable if you're running a different python version. (If you don't know which version you're running, the version number should be displayed when you start up a python shell, like this: command prompt> python Python 2.3.4 (#1, Apr 15 2011, 17:38:51) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Tue Aug 16 12:14:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 17:14:24 +0100 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: On Tue, Aug 16, 2011 at 12:33 PM, Paul Wray wrote: > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. That'd be similar to what the interactive loop does. Are you aware, though, that docstrings are bare expressions? You may have a syntactic collision there. ChrisA From anand.ibmgsi at gmail.com Tue Aug 16 12:16:07 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 16 Aug 2011 21:46:07 +0530 Subject: Idea for pure-python templates using AST. In-Reply-To: <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> Message-ID: Hi all, I did it. Finally managed to port mysqltuner.pl to python. Was a real pain in the butt doing it from bottom up manually, without ever really learing perl syntax. But i finally got it done. Now i need help testing it. find it here. git at github.com:anandjeyahar/mysqlDbAdmin-python.git. Also i never really thought about design. Just blindly/mechanically, translated from perl to python. So criticize and let me know how i can improve this. Thanks and Regards, ============================================== Anand Jeyahar https://sites.google.com/site/anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ? ? ? ? ? ? ? ? ? ~Bruce Lee Love is a trade with lousy accounting policies. ? ? ? ? ? ? ? ?? ~Aang Jie On Tue, Aug 16, 2011 at 18:02, aspineux wrote: > On Aug 16, 1:33?pm, "Paul Wray" wrote: >> Hello all >> >> Ive had what I think is a great idea for pure-python templates (I can almost >> hear the groans, bear with me...) >> >> For the impatient, proof of concept is athttp://pastie.org/2379978 >> demonstrating simple substitution, balanced tags using context manager, >> subtemplates, ?and template inheritance. > > You code fail, see below for other comment > > Traceback (most recent call last): > ?File "Download/pastie-2379978.rb", line 108, in > ? ?make_template(template1) > ?File "Download/pastie-2379978.rb", line 60, in make_template > ? ?ast.fix_missing_locations(astFromSrc) > ?File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations > ? ?_fix(node, 1, 0) > ?File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ?_fix(child, lineno, col_offset) > ?File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ?_fix(child, lineno, col_offset) > ?File "/usr/lib/python2.6/ast.py", line 121, in _fix > ? ?if 'lineno' in node._attributes: > AttributeError: 'arguments' object has no attribute '_attributes' > > > > >> >> I'm posting here to get opinions on: >> * the merits of the idea, (or otherwise!) >> * whether there are any established/mature templating systems that use this >> approach, or whether its come up before, >> * ideas for improvements and advice on other aspects such as sandboxing >> * of course, to share the idea in case others want to use it > > This is very original ! First time I see it. I like it. > But how to debug large template ? > How to find/detect a missing ? > This is very important. This is one big advantage of Genshi over Kid > How to report the correct error at the correct line ? > How to find/get nice editor to edit large template ? > > >> >> Background: Ive been working on an application that recursively renders >> html/xml documents from heterogenoeus trees, with separate classes for each >> document component. First I built my own renderer but was dissatisfied with >> the repetitive code. Then looked at Mako and Jinja, and used Jinja but was >> still disatisfied, because I still needed a render method in each class to >> do preparation, and also the template which was centrally managed by the >> Jinja loader and environment. I found a way to call templates recursively >> via Jinja filters, but was not sure that it wouldnt blow up in my face, so I >> also had separate calls to render the children of each node, and then feed >> the value to the parent template. I kept thinking that there must be a way >> to get the brevity and clarity of declarative templates, plus the simplicity >> of pure python loops, tests and function calls. >> >> The idea: >> Python syntax allows a statement to be a bare literal or identifier. These >> have no effect on the program. >> >> So the function below is legal python: >> >> def myFunc(): >> ? ? 'a' >> ? ? x = 45 >> ? ? 'b'; 'c'; x >> >> So is this (within the appropriate class context of course): >> >> def body(self, r): >> ? ? ? ? '

'; self.heading; '

' >> ? ? ? ? '
    ' >> ? ? ? ? for itm in self.items: >> ? ? ? ? ? ? '
  • '; itm; '
  • ' >> ? ? ? ? '
' >> >> The idea is simply to use python ASTs to transform this code so that it >> accumulates the values of the bare expressions. > > You could call it PHP :-) > >> >> I think this give the best of both worlds - declarative syntax for the >> template literals, but in a pure python context, giving you all the power of >> python control statements, classes etc. >> >> For application contexts outside pure python code (ie user-created >> templates) , it would be simple to extend the technique to creating template >> functions from strings, and insert the resulting methods into a namespace >> for execution.) >> >> I think, given the technique is already working with the AST, that >> sandboxing should not be too hard either - advice on this aspect would be >> appreciated. > > > Maybe a good idea. > But still a lot of work to get the level of existing libraries. > > Maybe better if mixed with other tools like Genshi to create widget. > Maybe next toscawidget could use such a technique. > > > Thanks for sharing > >> >> Paul Wray > > -- > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Tue Aug 16 12:19:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 09:19:58 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: <4E4A98AE.1070708@stoneleaf.us> Philip Semanchuk wrote: > On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: >> Philip Semanchuk wrote: >>> If we are to eschew warnings in >>> cases where they might be highlighting something harmless, then we would >>> have no warnings at all. >> >> Sounds good to me. ;) Keep such things in the IDE's, and then those >> who desire such behavior can have it there. Do not clutter Python with >> such. > > You wink, yet you sound serious. The smiley is an attempt to not sound harsh. > What's with the mixed message? Do you honestly advocate removing all > warnings from Python, or not? I sincerely would like to know what you think. I think warnings should be reserved for language changes and such (like DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible programmer mistakes. >> What makes you think it's unintentional? file makes a good variable name... > > "Unintentional" as in, "I'm using file as a variable name because it's handy" > as opposed to intentional as in "Yes, I am deliberately changing the meaning > of this builtin". That's not what 'unintentional' means. Further, there's no way to tell whether it was or was not from the code alone. Unless it caused a bug, in which case I'd be willing to call it unintentional. ;) >> I don't see that as a problem that Python needs to solve. > > "need" is a strong word. Python will be fine regardless of whether this changes > or not. I believe Python could be improved; that's all I'm arguing. Python can be improved -- I don't see 'hand-holding' as an improvement. IDEs and lints can do this. ~Ethan~ From philip at semanchuk.com Tue Aug 16 12:32:52 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 12:32:52 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4A98AE.1070708@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> Message-ID: <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> On Aug 16, 2011, at 12:19 PM, Ethan Furman wrote: > Philip Semanchuk wrote: >> On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: >>> Philip Semanchuk wrote: >>>> If we are to eschew warnings in >>>> cases where they might be highlighting something harmless, then we would >>>> have no warnings at all. > >> >>> Sounds good to me. ;) Keep such things in the IDE's, and then those > >> who desire such behavior can have it there. Do not clutter Python with > >> such. >> You wink, yet you sound serious. > > The smiley is an attempt to not sound harsh. Thanks. It's hard to know on the Internet. >>> I don't see that as a problem that Python needs to solve. >> "need" is a strong word. Python will be fine regardless of whether this changes > > or not. I believe Python could be improved; that's all I'm arguing. > > Python can be improved -- I don't see 'hand-holding' as an improvement. IDEs and lints can do this. When you say "hand-holding", I hear a pejorative. That makes "I don't see 'hand-holding' as an improvement" a tautology. Have I misheard you? I think Python does lots of beneficial hand-holding. Garbage collection is a good example. $DIETY knows, people have been struggling with manual memory management in C and its ilk for a long time. Even though there are good tools to help, memory leaks still happen. Python increases our productivity by allowing us to forget about manual memory management altogether. I can do it with tools like valgrind, but Python's makes the point moot. Is that hand-holding? If so, I'm all for it. Cheers Philip From gennad.zlobin at gmail.com Tue Aug 16 12:36:03 2011 From: gennad.zlobin at gmail.com (Gennadiy Zlobin) Date: Tue, 16 Aug 2011 23:36:03 +0700 Subject: why i cannot import djang? In-Reply-To: References: Message-ID: import sys print sys.path # All directories where Python looks for packages - Gennadiy On Tue, Aug 16, 2011 at 11:12 PM, John Gordon wrote: > In smith jack < > thinke365 at gmail.com> writes: > > > this package is already in the site-packages directory, but i cannot > > import it , it's really confusing ... > > Is it in the site-packages directory for the particular version of > python you're using? > > For example, my system has both python2.3 and python2.5 installed, and > they both have their own site-packages directories: > > /usr/lib/python2.3/site-packages > /usr/lib/python2.5/site-packages > > A package installed for only one version of python won't be importable > if you're running a different python version. > > (If you don't know which version you're running, the version number > should be displayed when you start up a python shell, like this: > > command prompt> python > Python 2.3.4 (#1, Apr 15 2011, 17:38:51) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.ibmgsi at gmail.com Tue Aug 16 12:38:35 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 16 Aug 2011 22:08:35 +0530 Subject: python mysqltuner port Message-ID: Hi all, Sorry for the repeat post. Had posted earlier in between an irrelevant thread by accident. > Hi all, > ? I did it. Finally managed to port mysqltuner.pl to python. Was a > real pain in the butt doing it from bottom up manually, without ever > really learing perl syntax. But i finally got it done. Now i need help > testing it. find it here. > ?git at github.com:anandjeyahar/mysqlDbAdmin-python.git. > > Also i never really thought about design. Just blindly/mechanically, > translated from perl to python. So criticize and let me know how i can > improve this. > > Thanks and Regards, > ============================================== > Anand Jeyahar > https://sites.google.com/site/anandjeyahar > ============================================== > The man who is really serious, > with the urge to find out what truth is, > has no style at all. He lives only in what is. > ? ? ? ? ? ? ? ? ? ~Bruce Lee > > Love is a trade with lousy accounting policies. > ? ? ? ? ? ? ? ?? ~Aang Jie From python at mrabarnett.plus.com Tue Aug 16 12:41:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 17:41:55 +0100 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: <4E4A9DD3.3040908@mrabarnett.plus.com> On 16/08/2011 00:26, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > Here's my solution, using the Counter class: >>> from collections import Counter >>> >>> c1 = Counter([1,2]) >>> c2 = Counter([1,2,3,4,5]) >>> (c1 & c2) == c1 True >>> >>> c1 = Counter([1,2,2,]) >>> c2 = Counter([1,2,3,4,5]) >>> (c1 & c2) == c1 False >>> >>> c1 = Counter([1,2,3]) >>> c2 = Counter([1,3,5,7]) >>> (c1 & c2) == c1 False From ethan at stoneleaf.us Tue Aug 16 13:07:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:07:58 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> Message-ID: <4E4AA3EE.1070104@stoneleaf.us> Philip Semanchuk wrote: > I think Python does lots of beneficial hand-holding. Garbage collection > is a good example. $DIETY knows, people have been struggling with manual > memory management in C and its ilk for a long time. Even though there > are good tools to help, memory leaks still happen. Python increases our > productivity by allowing us to forget about manual memory management > altogether. I can do it with tools like valgrind, but Python's makes > the point moot. Is that hand-holding? If so, I'm all for it. Good point. There is an important difference, however, between offering warnings to newbie programmers (which is how this thread started), and memory management. ~Ethan~ From usenet-nospam at seebs.net Tue Aug 16 13:11:37 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:37 GMT Subject: Anyone here can do a comparation between Djang and RoR References: Message-ID: On 2011-08-16, smith jack wrote: > what is the advantage of Django over RoR:) This question is pretty much... I mean, you're not gonna get useful answers. They're based on such different languages that I think any comparison past that is likely going to be uninteresting to a programmer, and I'm not sure any non-programmers are going to use either. I will say, the things I most value in Rails are pretty much contrary to conventional Python design philosophy. Python's stress on explicit over implicit is probably in contradiction with the Rails philosophy of convention over configuration. So for instance, if all you want of a class that maps to a database table in Rails is that it map the fields in the database, the class body is empty because that's the default. If you want to tell it that the database column foo_id represents the id of the foo object with which this record is associated, and you want to call that .foo, you write: belongs_to :foo and the rest is all implicit. This is really handy sometimes, but it's not very Pythonic... Mostly, I think you'd probably be better off asking in a completely different kind of forum, but even then, you're going to get mostly language advocacy. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-16, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >>> Why should built-ins be treated as more sacred than your own objects? >> Because built-ins are described in the official documentation as having a >> specific behavior, while my objects are not. > *My* objects certainly are, because I write documentation for my code. My > docs are no less official than Python's docs. Sure they are. I can't get yours from python.org. > You can shadow anything. Sometimes shadowing is safe, sometimes it isn't. I > don't see why we should necessarily fear safe shadowing of built-ins more > than we fear unsafe shadowing of non-built-ins. I think largely because anyone coming to your code will have expectations about the built-ins. For non-built-ins, they'll have to look around the code to see what they do, but for built-ins, they come to the table with an otherwise-reasonable expectation that they already know what that word means. > A warning that is off by default won't help the people who need it, because > they don't know enough to turn the warning on. A warning that is on by > default will be helpful to the newbie programmer for the first week or so, > and then will be nothing but an annoyance for the rest of their career. Will it? I am pretty sure that I'd keep it on and fix anything that triggered it, because shadowing built-ins strikes me as Asking For Trouble. > Protecting n00bs from their own errors is an admirable aim, but have you > considered that warnings for something which may be harmless could do more > harm than good? I would distinguish between "may not be causing bugs" and "may be harmless". I think code which shadows a built-in has a pretty real risk of being harmful at some unspecified future point when some maintainer who hasn't memorized every last line of the code makes the totally reasonable assumption that basic language features are still working and available. > Perhaps. But I'm not so sure it is worth the cost of extra code to detect > shadowing and raise a warning. After all, the average coder probably never > shadows anything, and for those that do, once they get bitten *once* they > either never do it again or learn how to shadow safely. I don't see it as a > problem. I would guess that it happens moderately often entirely by accident. Not a Python example, but I recently had a heck of a time with some JavaScript I was trying to maintain. Couldn't get it to work on a slightly older Firefox, and the diagnostics from Firebug came across as basically illucid. Problem: I was declaring an array named 'history'. My thoughts would be: 1. It's hard to avoid shadowing anything unless you know the entire language and never forget things. 2. In particular, Python likes to use clear, obvious, names for things. Meaning that your choice of a clear, obvious, name for a similar thing could be the name of a thing in the language. 3. I am not sure at all that shadowing can be "safe" in code which will some day be maintained. The chances of someone coming along and trying to write clean, idiomatic, Python which happens to blow up interestingly because their code runs in an environment where part of the standard language has been shadowed strike me as Too High. MHO, but speaking only for myself, I'd want that warning on and I'd not consider it harmless. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: On 2011-08-16, Ethan Furman wrote: > What makes you think it's unintentional? Programming experience. People *often* do things unintentionally. > Seems to me the real issue is somebody using a builtin, such as str or > int, and that they somehow manage to do this without realizing, "wait a > sec', that's one of my variables!" I don't see that as a problem that > Python needs to solve. I think the word "my" prejudices the case. Imagine stepping into a large project that uses multiple frameworks and class libraries and so on. You know Python but you're new to the project. Under which circumstance will you have more problems? 1. There is not a single shadowed built-in in the entire project. 2. There are dozens of shadowed built-ins based on when the original programmer felt there wasn't going to be a need for a given built-in feature, or possibly just didn't know about it. Also, how easy or hard do you think it will be to debug those problems? What's your first response going to be if, on a screen which doesn't contain the word file at all, you try to use the file built-in and you get some cryptic error? Are you going to know to go looking for the shadow right away? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Ethan Furman wrote: > I think warnings should be reserved for language changes and such (like > DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible > programmer mistakes. I disagree, on the basis of the following: The quality of C code I have to deal with has increased dramatically as gcc's aggressive use of warnings has spread. > Python can be improved -- I don't see 'hand-holding' as an improvement. > IDEs and lints can do this. -W ignore -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From grickert at coldstorage.com Tue Aug 16 13:15:04 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Tue, 16 Aug 2011 13:15:04 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: ... > A warning that is off by default won't help the people who need it, > because > they don't know enough to turn the warning on. A warning that is on by > default will be helpful to the newbie programmer for the first week or > so, > and then will be nothing but an annoyance for the rest of their career. > I think that best practices would suggest that one shouldn't use variable names that shadow builtins (except in specific, special circumstances), so I don't really think this would be an annoyance at all. The number of *unwanted* warnings they'd get would be pretty close to zero. OTOH, in response to a question I asked on StackOverflow, someone posted a large list of times where this isn't followed in the std lib, so there seems to be a precedent for just using the builtin names for anything one feels like at the time. Thinking about it, what about if, by default, python was configured to emit warnings about this sort of thing, but a simple environment variable or config option would turn them off. That way, new users would get warnings when doing this sort of thing, and any experienced user that wanted the option of using these variables anywhere would just have a one-time thing to change when they installed python (or any time later). They'd turn these warnings off when they installed Python, and would never have to think about it again. New users (or experienced ones that prefer this) would be warned by default, and then could make the conscious decision to shadow the builtin names, instead of accidentally doing it. All the suggestions to just use a linter aren't helpful, since new users aren't likely to start with one & and they are the thrust of this discussion. From bahamutzero8825 at gmail.com Tue Aug 16 13:23:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 16 Aug 2011 12:23:55 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> Message-ID: <4E4AA7AB.5000908@gmail.com> On 2011.08.16 10:44 AM, rantingrick wrote: > One word: SYNTAX HILIGHT And I had thought your troll skills had disappeared. Good one. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From ethan at stoneleaf.us Tue Aug 16 13:43:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:43:12 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: <4E4AAC30.6010100@stoneleaf.us> Seebs wrote: > On 2011-08-16, Ethan Furman wrote: >> I think warnings should be reserved for language changes and such (like >> DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible >> programmer mistakes. > > I disagree, on the basis of the following: > > The quality of C code I have to deal with has increased dramatically as > gcc's aggressive use of warnings has spread. With gcc you pay the cost once, with Python you would pay it with every run. A linter would be more along the lines of 'pay it once'. ~Ethan~ From neilc at norwich.edu Tue Aug 16 13:45:15 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Aug 2011 17:45:15 GMT Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <9avolbFff6U1@mid.individual.net> On 2011-08-16, nn wrote: > That can be easily fixed: > >>>> def sublist(lst1, lst2): > s1 = ','.join(map(str, lst1)) > s2 = ','.join(map(str, lst2)) > return False if s2.find(s1)==-1 else True > >>>> sublist([1,2,3],[1,2,3,4,5]) > True >>>> sublist([1,2,2],[1,2,3,4,5]) > False >>>> sublist([1,2,3],[1,3,5,7]) > False >>>> sublist([12],[1,2]) > False >>>> String conversion is risky: >>> sublist(['1,2', '3,4'], [1, 2, 3, 4]) True Since we're bike-shedding, here's my entry. It's not clear to me if accepting iterables rather than lists is a win, but I thought, "Why not be general if the implementation is easy?" def is_subseq_of(x, y): r"""Return True if the elements in iterable x are found contiguously in iterable y. >>> is_subseq_of([], []) True >>> is_subseq_of([], [1, 2, 3]) True >>> is_subseq_of([1], [1, 2, 3]) True >>> is_subseq_of([1], []) False >>> is_subseq_of([4, 5], [1, 2, 3, 4, 5]) True >>> is_subseq_of([1, 2], [1, 3, 2]) False >>> is_subseq_of([2, 3], [1, 2, 3, 4]) True >>> is_subseq_of([1, 2, 2], [1, 2, 3, 4, 5]) False >>> is_subseq_of([1, 2], [1, 2]) True >>> is_subseq_of([1, 2, 3], [1, 2]) False >>> is_subseq_of(['1,2', '3,4'], [1, 2, 3, 4]) False """ x = tuple(x) ix = 0 lenx = len(x) if lenx == 0: return True for elem in y: if x[ix] == elem: ix += 1 else: ix = 0 if ix == lenx: return True return False if __name__ == '__main__': import doctest doctest.testmod() -- Neil Cerutti From smainklh at gmail.com Tue Aug 16 13:47:27 2011 From: smainklh at gmail.com (Smaine Kahlouch) Date: Tue, 16 Aug 2011 19:47:27 +0200 Subject: Linux : create a user if not exists In-Reply-To: <4E4A9335.4010700@web.de> References: <4E4A9335.4010700@web.de> Message-ID: <4E4AAD2F.2090502@gmail.com> Le 16/08/2011 17:56, Alexander Kapps a ?crit : > On 16.08.2011 16:57, smain kahlouch wrote: >> Ok than you. You're right but it doesn't help me : >> I replaced it : >> >> >>> def finduser(user): >> ... if pwd.getpwnam(user): >> ... print user, "user exists" >> ... return True >> ... return False >> ... >> >>> finduser('realuser') >> realuser user exists >> True >> >>> finduser('blabla') >> Traceback (most recent call last): >> File "", line 1, in ? >> File "", line 2, in finduser >> KeyError: 'getpwnam(): name not found: blabla' > > > Untested: > > def finduser(name): > try: > return pwd.getpwnam(name) > except KeyError: > return None > > if not finduser("myuser"): > print "creating user..." > else: > print "user already exists" > > > Has the advantage that finduser() returns the user details if needed. > > > (BTW: Please don't top-post) Ok Thank you all, that works perfectly :) See you soon, Sam From ethan at stoneleaf.us Tue Aug 16 13:48:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:48:19 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4AAD63.20901@stoneleaf.us> Seebs wrote: > On 2011-08-16, Ethan Furman wrote: >> What makes you think it's unintentional? > > Programming experience. > > People *often* do things unintentionally. > >> Seems to me the real issue is somebody using a builtin, such as str or >> int, and that they somehow manage to do this without realizing, "wait a >> sec', that's one of my variables!" I don't see that as a problem that >> Python needs to solve. > > I think the word "my" prejudices the case. But fits in well with the OP. > Imagine stepping into a large project that uses multiple frameworks and > class libraries and so on. You know Python but you're new to the project. > > Under which circumstance will you have more problems? > > 1. There is not a single shadowed built-in in the entire project. > 2. There are dozens of shadowed built-ins based on when the original > programmer felt there wasn't going to be a need for a given built-in > feature, or possibly just didn't know about it. My first course of action would be to learn what I'm patching before I patch it. Scope helps in the case of shadowing; lint helps to give warnings about that and other things as well. > Also, how easy or hard do you think it will be to debug those problems? > What's your first response going to be if, on a screen which doesn't > contain the word file at all, you try to use the file built-in and you > get some cryptic error? Are you going to know to go looking for the > shadow right away? I should have a pretty good clue from the traceback, and a couple prints or logs around the offending lines should give me the rest. ~Ethan~ From ramit.prasad at jpmorgan.com Tue Aug 16 13:51:52 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 13:51:52 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7A5EC4B@EMARC112VS01.exchad.jpmchase.net> >Incorrect past tense usage of "used to": > """ I "used to" wear wooden shoes """ >Incorrect description using "used to": > """ I have become "used to" wearing wooden shoes """ >Correct usage of "used to": > """ Wooden shoes can be "used to" torture someone """ Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. http://www.englishgrammarsecrets.com/usedto/menu.php http://www.englishpage.com/verbpage/usedto.html http://www.5minuteenglish.com/mar20.htm http://www.learnenglish.de/grammar/usedtotext.htm http://www.thefreedictionary.com/used+to http://www.englishclub.com/grammar/verbs-m_used-to-do.htm Ramit P.S. Please CC me on any reply. Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of rantingrick Sent: Tuesday, August 16, 2011 10:06 AM To: python-list at python.org Subject: Re: Ten rules to becoming a Python community member. On Aug 16, 2:07?am, alex23 wrote: > All the way down indeed. Can you pick who said these? Obviously your grep skills are superb however you need to brush up on those reading and comprehension skills a bit. > "There are noobs watching and we to provide code that can be used to > teach!" Yes i said this, however the use of "used to" is proper here. -1 > "And just what *point* an i supposed to be "getting" Stephen?" Yes i said this, and it "may" seem that you have me on this one however i believe that Stephen had said something like """you are "supposed to" blah, blah""" and i retorted with """oh, and just what *point* am i "supposed to" blah blah blah"""... although i DID forget to quote "supposed to", still it's a -1. > "An end user should NEVER EVER have to write glue code so their > "abstraction of choice" can be used to to script an API." Yes i said this, however AGAIN the use of "used to" is proper here. -1. sorry alex, better luck next time :(. Follows is some homework i have prepared for you so that you can understand the proper and improper usage of "used to". For our next assignment we'll be learning about the exploits of Jack and Jill. > (For bonus points: can you also spot who is bored at work today?) Trolling doesn't count as "work" unless you're being paid for it, however some people might consider you a pro by now! PS: Does anyone notice how Stephen has fallen off the face the earth? Where is Stephen i wonder? He was such a vocal nuisance and then he just disappeared. It seemed like he appeared as strangely as he disappeared. Well, he's probably where most sock puppets go when they have no further usage. -- http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Tue Aug 16 14:23:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 19:23:22 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4AAC30.6010100@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4AAC30.6010100@stoneleaf.us> Message-ID: On Tue, Aug 16, 2011 at 6:43 PM, Ethan Furman wrote: > Seebs wrote: >> >> On 2011-08-16, Ethan Furman wrote: >>> >>> I think warnings should be reserved for language changes and such (like >>> DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible >>> programmer mistakes. >> >> I disagree, on the basis of the following: >> >> The quality of C code I have to deal with has increased dramatically as >> gcc's aggressive use of warnings has spread. > > With gcc you pay the cost once, with Python you would pay it with every run. > ?A linter would be more along the lines of 'pay it once'. Agreed; in addition, it's spam. Spam at compile time isn't much of an issue; you type ./configure and make, and a billion messages scroll past you. Spam at run time? Everyone who USES the program has to deal with it, and in amongst the program's own output. I don't know how to have Python emit warnings that wouldn't cause these issues. The only thing I can think of is to have the interactive interpreter default to showing more warnings, which is far from perfect itself. As to 'file' specifically, my 3.2 doesn't seem to have it as a builtin. The return value from open() is _io.TextIOWrapper, so the whole issue of file=open(...) may have been completely dodged. ChrisA From emmanuelrousselle at gmail.com Tue Aug 16 14:32:35 2011 From: emmanuelrousselle at gmail.com (eroussel) Date: Tue, 16 Aug 2011 11:32:35 -0700 (PDT) Subject: Python 2.7.2 on AIX 6.1: Unable to compile with ctypes Message-ID: Hello, I'm trying to figure out the recipe to compile Python 2.7.2 on AIX 6.1 with the ctypes module. I'm using the xlc_r compiler V9.0. I am currently able to generate an interpreter that works, but lacks the ctypes module because of compilation errors. From looking at the newgroup posts and bugs.python.org, there seems to be an issue with Python, libffi and AIX. Is the ctypes modules simply unsupported on AIX? These are the compilation error messages I get: "/sapdepot/HP_to_IBM/t154133/build/Python-2.7.2/Modules/_ctypes/libffi/ src/powerpc/ffi.c", line 146.25: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/sapdepot/HP_to_IBM/t154133/build/Python-2.7.2/Modules/_ctypes/libffi/ src/powerpc/ffi.c", line 607.19: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 610.19: 1506-045 (S) Undeclared identifier FFI_LINUX64. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 674.23: 1506-045 (S) Undeclared identifier FFI_SYSV. "/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 908.10: 1506-045 (S) Undeclared identifier FFI_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 908.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 909.10: 1506-045 (S) Undeclared identifier FFI_GCC_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 909.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 910.10: 1506-045 (S) Undeclared identifier FFI_LINUX. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 910.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 911.10: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 911.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 1033.26: 1506-045 (S) Undeclared identifier FFI_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 1159.27: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. and then: Failed to build these modules: _ctypes From python.list at tim.thechases.com Tue Aug 16 14:34:53 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 13:34:53 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4AB84D.9080706@tim.thechases.com> On 08/16/2011 12:11 PM, Seebs wrote: > Under which circumstance will you have more problems? > > 1. There is not a single shadowed built-in in the entire project. > 2. There are dozens of shadowed built-ins based on when the original > programmer felt there wasn't going to be a need for a given built-in > feature, or possibly just didn't know about it. In practice, I've never hit such a snag. For #2, the only way it would impact me is if I did the ill-advised from shadowy import * which might tromp on things I care about. Otherwise, I'd just do something like from shadowy import list as shadowy_list, id as shadowy_id If I'm altering another person's ill-created module, I might consider doing a search for builtins and then just simply patching the module so that it renamed all the shadowing usages. Unless the author was being particularly obscure (using scope to impact where a builtin meant the builtin, and other scopes to shadow the builtins), most authors are pretty consistent in their shadowing (usually ignorant of the fact they're shadowing the builtin) which makes the search-n-replace an easy tweak. -tkc From martin.hellwig at butterfly.uk.com Tue Aug 16 14:37:49 2011 From: martin.hellwig at butterfly.uk.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 19:37:49 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <4E4AB8FD.9080406@gmail.com> On 16/08/2011 18:51, Prasad, Ramit wrote: >> Incorrect past tense usage of "used to": >> """ I "used to" wear wooden shoes """ > >> Incorrect description using "used to": >> """ I have become "used to" wearing wooden shoes """ > >> Correct usage of "used to": >> """ Wooden shoes can be "used to" torture someone """ > > Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. > Well admittedly English isn't my native language, But indeed all sentences seem correct to me. With the first sentence meaning: in the past I wore wooden shoes, but presently I do not. With the second sentence meaning: in the past I was not used to (i.e. uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am used to it (although not necessarily comfortable, but at least not uncomfortable). I actually can't figure out a way of saying those two sentences more concise or correct then it has been given. But then again I do recognize that these are quite 'Germanic'* ways of constructing sentences, as in freely mixing past, present and future to indicate that a certain description is restricted to a specific time frame. * For the lack of a better description, I am not a linguist, but I was born in Germany and I am often guilty of mixing times. Also RR, congratualation to another troll post that turned out quite interesting :-) -- mph From martin.hellwig at gmail.com Tue Aug 16 14:37:49 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 19:37:49 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <4E4AB8FD.9080406@gmail.com> On 16/08/2011 18:51, Prasad, Ramit wrote: >> Incorrect past tense usage of "used to": >> """ I "used to" wear wooden shoes """ > >> Incorrect description using "used to": >> """ I have become "used to" wearing wooden shoes """ > >> Correct usage of "used to": >> """ Wooden shoes can be "used to" torture someone """ > > Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. > Well admittedly English isn't my native language, But indeed all sentences seem correct to me. With the first sentence meaning: in the past I wore wooden shoes, but presently I do not. With the second sentence meaning: in the past I was not used to (i.e. uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am used to it (although not necessarily comfortable, but at least not uncomfortable). I actually can't figure out a way of saying those two sentences more concise or correct then it has been given. But then again I do recognize that these are quite 'Germanic'* ways of constructing sentences, as in freely mixing past, present and future to indicate that a certain description is restricted to a specific time frame. * For the lack of a better description, I am not a linguist, but I was born in Germany and I am often guilty of mixing times. Also RR, congratualation to another troll post that turned out quite interesting :-) -- mph From rosuav at gmail.com Tue Aug 16 14:42:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 19:42:12 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4AB8FD.9080406@gmail.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: On Tue, Aug 16, 2011 at 7:37 PM, Martin P. Hellwig wrote: > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am > used to it (although not necessarily comfortable, but at least not > uncomfortable). > This usage can also be seen in a more archaic form, such as this example from WS Gilbert's "The Yeomen of the Guard" (which, as it happens, I'm presently in rehearsal of): Lieutenant: "I see. I think that manner of thing would be somewhat irritating." Jack: "At first, sir, perhaps; but use is everything, and you would come in time to like it." We would be more inclined to say "You'd get used to it". I don't see that this usage (heh) should be considered in any way wrong. ChrisA From jdoe at usenetlove.invalid Tue Aug 16 14:42:52 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 18:42:52 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e4aba2c$0$944$c3e8da3$9f400e27@news.astraweb.com> def wait_for_keystroke(): char=0 while not char==0x1B: char=msvcrt.getch() That freezes the process. Am I using the right code for the escape key, or doing anything else wrong? Again, I know it could be my system. But I must find a way to do this from within Windows. I use a keyboard hook written in C++, maybe something from that would be useful, but maybe complex. Thanks. From jdoe at usenetlove.invalid Tue Aug 16 14:48:24 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 18:48:24 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4aba2c$0$944$c3e8da3$9f400e27@news.astraweb.com> Message-ID: <4e4abb78$0$944$c3e8da3$9f400e27@news.astraweb.com> > def wait_for_keystroke(): > char=0 > while not char==0x1B: > char=msvcrt.getch() I tried using while not char==chr(27): From usenet-nospam at seebs.net Tue Aug 16 14:56:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 18:56:08 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Ethan Furman wrote: > Seebs wrote: >> The quality of C code I have to deal with has increased dramatically as >> gcc's aggressive use of warnings has spread. > With gcc you pay the cost once, with Python you would pay it with every > run. A linter would be more along the lines of 'pay it once'. Huh! That is a really good point, which I had not considered. I still prefer to get warnings, but... Hmm. I wonder whether there's a way to mitigate the cost of these things by messing with -W settings, such that runtime that wants to be fast can omit the checks, but the default could still be to, well, prevent likely errors. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 14:56:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 11:56:08 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> <379fb990-c471-47d2-a349-edfe6bc94956@o11g2000yql.googlegroups.com> Message-ID: <39187eb1-c069-4fe7-b9fd-e8f25a4caa60@q1g2000vbj.googlegroups.com> On Aug 16, 1:49?am, alex23 wrote: > On Aug 16, 2:37?pm, rantingrick wrote: > > > The reading proceeds naturally from right to left. > > Well, "naturally" if you're coding in Hebrew or Japanese perhaps :) Yes :). I typo-ed that one. It was getting late when i sent that reply. I did consider posting an edit however i decided not to and instead, wait and see who would notice. The map feels much better too as a consequence: rb> [3,100,-20].map{|x| x.to_f} [3.0, 100.0, -20.0] And you can can induce some logic without a clunky lambda. rb>[3,100,-20].map{|x| if x > 99 then x.to_f else x end} [3.0, 100.0, -20.0] in Python you'd have to create a def for that (i know bad "specific" example but the need is there) It feels just like a Python list comprehension though: py> [float(x) for x in [3,100,-20]] Even though it reads in a non-linear way, you could argue that the most important part (float(x)). is front-and-center. Of course i like the compactness of python's map function: py> map(float, [3,100,-20]) But all too often the map function is insufficient AND you cannot use map in a chain! If only we could find a happy medium between Python and Ruby oh what a bliss that would be. We could cut off all of Pythons warts and destroy all of Rubys multiplicity and "singular paridigm-ness". * Forced indention (exactly one tab, and one tab only!) * No multiplicity! * Nice linear expressions! * Name spaces! * Implicit modules! * Only "truly heterogeneous" built-in functions allowed! * Enough freedom to be expressive, but not enough to allow sloppy- ness. From python at mrabarnett.plus.com Tue Aug 16 15:03:53 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 20:03:53 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4AB8FD.9080406@gmail.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: <4E4ABF19.30205@mrabarnett.plus.com> On 16/08/2011 19:37, Martin P. Hellwig wrote: > On 16/08/2011 18:51, Prasad, Ramit wrote: >>> Incorrect past tense usage of "used to": >>> """ I "used to" wear wooden shoes """ >> >>> Incorrect description using "used to": >>> """ I have become "used to" wearing wooden shoes """ >> >>> Correct usage of "used to": >>> """ Wooden shoes can be "used to" torture someone """ >> >> Double you tee eff? Maybe this is a cultural language difference, but >> I believe all of the above are correct. Well, I am not sure about the >> middle one but the other two are valid. >> > Well admittedly English isn't my native language, But indeed all > sentences seem correct to me. > English _is_ my native language, and I agree with you. > With the first sentence meaning: in the past I wore wooden shoes, but > presently I do not. > Correct. > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I > am used to it (although not necessarily comfortable, but at least not > uncomfortable). > Correct. > I actually can't figure out a way of saying those two sentences more > concise or correct then it has been given. > > But then again I do recognize that these are quite 'Germanic'* ways of > constructing sentences, as in freely mixing past, present and future to > indicate that a certain description is restricted to a specific time frame. > > > * For the lack of a better description, I am not a linguist, but I was > born in Germany and I am often guilty of mixing times. > > Also RR, congratualation to another troll post that turned out quite > interesting :-) > From dannwong at cisco.com Tue Aug 16 15:09:39 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 14:09:39 -0500 Subject: regular expression In-Reply-To: References: <4E499F0B.30900@stoneleaf.us> Message-ID: Thanks chris. I had similar code to what you provided. I included the "#" (it was a comment in my code) as part of the string when it shouldn't be as part of my test. As soon as you pointed it out that the #'s aren't supposed to be part of the output, I removed them and it worked. How dumb of me. Thanks again. -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 16, 2011 12:26 AM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: regular expression On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?If I get multiline standard output from a command. How can I > retrieve this part of the string "(1006)" > Example: > > #Committing... > #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" > # ?Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" > # ? ?Outgoing: > # ? ? ?Change sets: > # ? ? ? ?(1006) ?*--@ ? > # ? ? ? ? ?Changes: > # ? ? ? ? ? ?---c- /he-Group/o-PI/target/config/common-ngp/makefile Assuming the #s aren't in the actual output: import re pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) print(pat.search(your_str).group(1)) Obviously can vary depending on how you want to go about defining the target string. Cheers, Chris P.S. If you reply, please remove my email addresses from the quotation due to "On Behalf Of" brokenness. -- Freakin' Outlook/Exchange, I'm telling ya... http://rebertia.com From irmen at -NOSPAM-xs4all.nl Tue Aug 16 15:23:34 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Tue, 16 Aug 2011 21:23:34 +0200 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <4e4ac3b6$0$23867$e4fe514c@news2.news.xs4all.nl> On 16-08-11 13:33, Paul Wray wrote: > The idea: > Python syntax allows a statement to be a bare literal or identifier. > These have no effect on the program. > > So the function below is legal python: > > def myFunc(): > 'a' > x = 45 > 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' > Looks very similar to PTL what Quixote uses: http://www.quixote.ca/overview/paper.html (never used it though, and I doubt Quixote used ASTs) Irmen From ramit.prasad at jpmorgan.com Tue Aug 16 15:26:37 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 15:26:37 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> >1. Indentation as flow control was a bad idea. >2. People are subconsciously aware of this. >3. There is a HUGE degree of emotional investment in defending it. > >The responses I have seen on this issue are highly emotional, full of insults, >full of blame-throwing, and utterly contrary to the basic engineering spirit >I usually see in programming communities. In other languages, and even in >Python on any issue but this one, I regularly see people acknowledge >shortcomings and explain either why they think the tradeoffs are good, or why >they are willing to put up with it anyway. > >The characteristic vehemence and hostility this issue produces are the surest >sign of people who have a desperate need not to acknowledge the elephant in >the room. What exactly is the downside to indentation as flow control? I am a fairly new programmer to Python, but the more I use it, the more I think it has the Right idea (for me at least). I find braces in Java/c[#,++] to be less than helpful in comparison to how people rave over. It allows for free form code sure, but half the time I was using indentation to figure out where conditional branching/loops started and stopped anyway! I will admit it was super useful in helping Eclipse to reformat with a more "readable" indentation. The only difference is that now it forces me to make more readable code instead of allowing me the freedom to make hard to read code. I suppose as an American I should be insulted at the lack of freedom. Hell, I own Apple products; I must be getting indoctrinated into a lack of freedom. :-P I am not being vehement or hostile. At least I am attempting to be neither. I do not really feel emotionally invested in either because honestly, I will do whatever I have to for what I am trying to get done. If that requires me coding while only wearing hot pink or using braces I will do it. I am far more concerned with ease of coding, ability to do what I want, and occasionally (fairly rarely) if the running code will be "fast enough". I am not sure why people are so stuck on braces. I figured other people would be like me and tired of having to do things like figuring out where I missed an end brace. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From gc1223 at gmail.com Tue Aug 16 15:50:52 2011 From: gc1223 at gmail.com (gc) Date: Tue, 16 Aug 2011 12:50:52 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5d0d89b4-d026-40ba-b9f1-d72f1731b690@a31g2000vbt.googlegroups.com> Thanks for all the discussion on this. Very illuminating. Sorry for the long delay in responding--deadlines intervened. I will use the list comprehension syntax for the foreseeable future. Tim, I agree with you about the slurping in final position--it's actually quite surprising. As I'm sure you realized, that behavior makes your 'tidier' version: a,b,c,d,e, *more_dict_generator = (dict() for _ in itertools.count()) break with a MemoryError, which I don't think is the result that most people would expect. Stephen wrote: > While slightly ugly, it doesn't seem ugly enough to justify the > extra complexity of special syntax for such a special case. You're probably right (although for my coding this multiple assignment scenario is a pretty ordinary case.) Anyway, I'll shop the a,b,c = *dict() syntax over to python-ideas just to see what they say. Thanks again, everyone! Happy Python. On Aug 3, 7:25?am, Tim Chase wrote: > On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: > > > On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: > >> a, b, c, d, e = [dict() for i in range(5)] > > > I think this is good code -- if you want five different dicts, > > then you should call dict five times. Otherwise Python will > > magically call your expression more than once, which isn't > > very nice. And what if your datatype constructor has > > side-effects? > > If the side-effects are correct behavior (perhaps opening files, > network connections, or even updating a class variable) then > constructor side-effects are just doing what they're supposed to. > ? E.g. something I use somewhat regularly in my code[*]: > > ? a,b,c,d = (file('file%i.txt', 'w') for i in range(4)) > > If the side-effects aren't performing the correct behavior, fix > the constructor. :) > > -tkc > > [*] okay, it's more like > > (features, > ? adjustments, > ? internet, > ? ) = (file(fname) for fname in ( > ? ? 'features.txt', > ? ? 'adjustments.txt', > ? ? 'internet.txt' > ? ? ) > > or even > > (features, > ? adjustments, > ? internet, > ? ) = ( > ? ? set( > ? ? ? line.strip().upper() > ? ? ? for line > ? ? ? in file(fname) > ? ? ? if line.strip() > ? ? ? ) > ? ? for fname in ( > ? ? 'features.txt', > ? ? 'adjustments.txt', > ? ? 'internet.txt' > ? ? ) > > to load various set() data from text-files. From ramit.prasad at jpmorgan.com Tue Aug 16 15:51:31 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 15:51:31 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF6535@EMARC112VS01.exchad.jpmchase.net> >> PS: I will admit that a few of our community members can be rather >> acerbic at times. >Yeah. And the thing is... This can't possibly lead to convincing people of >your position, so presumably the purpose is that you don't want anyone who >didn't start out agreeing with you to ever come to agree with you? Why's >that? Rantingrick: Do answer his question, please. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Tue Aug 16 16:05:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 21:05:57 +0100 Subject: allow line break at operators In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Tue, Aug 16, 2011 at 8:26 PM, Prasad, Ramit wrote: > I am not sure why people are so stuck on braces. I figured other people would be like me and tired of having to do things like figuring out where I missed an end brace. > I'm one of the fans of braces, but search the list archives and you'll find plenty of arguments on both sides. I like braces because they allow me to separate the syntax from the layout; I can choose to indent things based on logical structure, even when that doesn't correspond to the compiler's notion of the structure. Here's an example from C++: struct _blah { int x; int y; char **z; //etc etc etc }; struct blah: public _blah { char padding[1024-sizeof(_blah)]; }; The inheritance isn't significant to the overall concept of the object (the idea was that it should have a size of exactly 1024, as this had to interface with some lower-level systems), but it's significant to the compiler's understanding of the object. The braces, therefore, follow the compiler's requirements, but the indentation follows the programmer's. (And yes, there were comments explaining things, and much better element names.) Another idiom I often use in C or C++ is the "conditional for loop": for (x=getfirst();x;x=getnext()) if (x%3) { blah blah } The equivalent in Python: for x in blah: if x%3: blah blah is not legal, and must be written with an extra indentation: for x in blah: if x%3: blah blah I'm sure I could sort something out with a filtering generator, but it seems ridiculous to write: def condition(gen,func): for elem in gen: if func(elem): yield elem for x in condition(blah,lambda x: x%3): blah blah There are very good reasons for Python's system, and I don't object to it *in Python*. But I do not see indentation-as-structure as the ultimate and perfect system, and I desire and intend to preserve the freedom to choose languages with different systems. Chris Angelico From rantingrick at gmail.com Tue Aug 16 16:13:10 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 13:13:10 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: On Aug 16, 1:37?pm, "Martin P. Hellwig" wrote: > Well admittedly English isn't my native language, But indeed all > sentences seem correct to me. > > With the first sentence meaning: in the past I wore wooden shoes, but > presently I do not. > > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I > am used to it (although not necessarily comfortable, but at least not > uncomfortable). > > I actually can't figure out a way of saying those two sentences more > concise or correct then it has been given. If conciseness is all you seek then perhaps you prefer the following? ORIGINAL: "I used to wear wooden shoes" CONCISE: "I wore wooden shoes" "I wore wood shoes" "I< Message-ID: <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> def wait_for_keystroke(): char=0 while not (char==chr(27) or char==chr(110)): char=msvcrt.getch() if char==0: return That freezes the process. That means char=msvcrt.getch() is getting something? Could it have something to do with the formatting of the character? From usenet-nospam at seebs.net Tue Aug 16 16:19:33 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 20:19:33 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On 2011-08-16, Prasad, Ramit wrote: >What exactly is the downside to indentation as flow control? I think a lot of it is personal taste or differences in how peoples' brains work. I don't want "free form code", I don't want to write stuff that isn't correctly indented. I want a visual cue I can match up with the start of a loop so I know for sure what I meant, and a way to recover code in the event of Something Going Wrong. >I am not sure why people are so stuck on braces. I figured other >people would be like me and tired of having to do things like >figuring out where I missed an end brace. For me, if I've made an error of that category, the options are: 1. In C, finding out where I missed an end brace, because the compiler warned me, so I go look for an outdent without a brace. 2. In Python, having no clue at all what's wrong or why the program isn't running, and having no cue I can look to to see where the error occurred. Basically, it's parity bits. I love me some parity bits. :) I also recognize that this is a matter of taste; there are sound reasons for other people to have different preferences. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From martin.hellwig at gmail.com Tue Aug 16 16:39:34 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 21:39:34 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: On 03/08/2011 02:45, gc wrote: > a,b,c,d,e = *dict() > > where * in this context means something like "assign separately to > all. > Any thoughts? Thanks! Well got a thought but I am afraid it is the opposite of helpful in the direct sense. So if you don't want to hear it skip it :-) Although I can not proficiently argument it, it has a certain code smell to it. In the sense that it could hint that there is a better more readable way of solving that particular problem (taking in account that the one letter labels are pure for demonstration purpose). I would love to see an example where you would need such a construct. -- mph From luismgz at gmail.com Tue Aug 16 17:02:51 2011 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 16 Aug 2011 14:02:51 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR References: Message-ID: <5a7e2900-5021-4a33-95f7-1e8262327970@l37g2000yqd.googlegroups.com> On Aug 16, 2:11?pm, Seebs wrote: > On 2011-08-16, smith jack wrote: > > > what is the advantage of Django over RoR:) > > This question is pretty much... I mean, you're not gonna get useful > answers. ?They're based on such different languages that I think any > comparison past that is likely going to be uninteresting to a programmer, > and I'm not sure any non-programmers are going to use either. > > I will say, the things I most value in Rails are pretty much contrary > to conventional Python design philosophy. ?Python's stress on explicit > over implicit is probably in contradiction with the Rails philosophy of > convention over configuration. > > So for instance, if all you want of a class that maps to a database table > in Rails is that it map the fields in the database, the class body is > empty because that's the default. ?If you want to tell it that the database > column foo_id represents the id of the foo object with which this record > is associated, and you want to call that .foo, you write: > ? ? ? ? belongs_to :foo > and the rest is all implicit. > > This is really handy sometimes, but it's not very Pythonic... > > Mostly, I think you'd probably be better off asking in a completely > different kind of forum, but even then, you're going to get mostly language > advocacy. > > -s > -- > Copyright 2011, all wrongs reversed. ?Peter Seebach / usenet-nos... at seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. Seebs answer is spot on. The advantages or disadvantages of both frameworks are subjective. It all comes down to each person's language of preference, since each framework reflects its language philosophy. From jdoe at usenetlove.invalid Tue Aug 16 17:43:54 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 21:43:54 GMT Subject: Determine what msvcrt.getch() is getting? Message-ID: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> Whatever msvcrt.getch() is returning here in Windows, it's not within the 1-255 number range. How can I determine what it is returning? I would like to see whatever it is getting. Thanks. From timr at probo.com Tue Aug 16 17:50:13 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 14:50:13 -0700 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> Message-ID: John Doe wrote: >def wait_for_keystroke(): > char=0 > while not (char==chr(27) or char==chr(110)): > char=msvcrt.getch() > if char==0: > return > >That freezes the process. That exact code works perfectly for me. The function returns as soon as I press the escape key. You are running this from a console process, and not a GUI process, right? >That means char=msvcrt.getch() is getting something? Did you ever think about inserting a debug statement to help you? print hex(ord(char)) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From monaghand.david at gmail.com Tue Aug 16 17:55:10 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Tue, 16 Aug 2011 22:55:10 +0100 Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick wrote: >If conciseness is all you seek then perhaps you prefer the following? > >ORIGINAL: "I used to wear wooden shoes" >CONCISE: "I wore wooden shoes" >ORIGINAL: "I have become used to wearing wooden shoes" >CONCISE: "I like wearing wooden shoes" >However as you can see much of the rich information is missing. Indeed. Neither of your two concise examples has the same meaning of the originals. >Good communication requires that we use clear and articulate words (and >phrases) that will re-create a similar thought (if not perfect clone of!) >in the mind of your listener[s]. Different phrasings of all but the most basic sentences often have subtle differences of meaning which native speakers intend and understand. 1984 has been and gone. Shame on you! DaveM From jdoe at usenetlove.invalid Tue Aug 16 17:59:32 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 21:59:32 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> Message-ID: <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Tim Roberts wrote: > John Doe wrote: > >>def wait_for_keystroke(): >> char=0 while not (char==chr(27) or char==chr(110)): >> char=msvcrt.getch() if char==0: >> return >> >>That freezes the process. > > That exact code works perfectly for me. The function returns as > soon as I press the escape key. You are running this from a > console process, and not a GUI process, right? No. I am running this from within Windows, all sorts of Windows. So... Does that mean I will need something complex like a keyboard hook? Or what? Thanks. -- > >>That means char=msvcrt.getch() is getting something? > > Did you ever think about inserting a debug statement to help you? > print hex(ord(char)) From rantingrick at gmail.com Tue Aug 16 19:12:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 16:12:53 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 4:55?pm, David Monaghan wrote: > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > > wrote: > >If conciseness is all you seek then perhaps you prefer the following? > > >ORIGINAL: "I used to wear wooden shoes" > >CONCISE: ?"I wore wooden shoes" > >ORIGINAL: "I have become used to wearing wooden shoes" > >CONCISE: ?"I like wearing wooden shoes" > >However as you can see much of the rich information is missing. > > Indeed. Neither of your two concise examples has the same meaning of the > originals. Really? Are you sure? ------------------------------------------------------------ ORIGINAL1: "I used to wear wooden shoes" ------------------------------------------------------------ CONCISE_1a: "I wore wooden shoes" the word "wore" is "past tense" and can be replaced with the "past tense" phrase of "used to wear" without changing any meaning whatsoever -- albeit the latter is childish! CONCISE_1b: "I wore wood shoes" Wooden = "object made of wood" = "flesh of a tree" Wood = "the flesh of a tree" Completely interchangeable! CONCISE_1c: "I< Different phrasings of all but the most basic sentences often have subtle > differences of meaning which native speakers intend and understand. 1984 has > been and gone. Shame on you! Guido himself admitted that hidden descriptors are real. The inception has begun! From gordon at panix.com Tue Aug 16 19:25:52 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 23:25:52 +0000 (UTC) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: In rantingrick writes: > ------------------------------------------------------------ > ORIGINAL1: "I used to wear wooden shoes" > ------------------------------------------------------------ > CONCISE_1a: "I wore wooden shoes" "wore" does not convey the same meaning as "used to wear." "wore" means you have worn them in the past. "used to wear" means you have worn them in the past AND don't intend to do so again. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Tue Aug 16 19:29:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 19:29:25 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > I think that best practices would suggest that one shouldn't use > variable > names that shadow builtins (except in specific, special circumstances), > so I don't really think this would be an annoyance at all. The number > of > *unwanted* warnings they'd get would be pretty close to zero. OTOH, in > response to a question I asked on StackOverflow, someone posted a large > list of times where this isn't followed in the std lib, so there seems > to be a precedent for just using the builtin names for anything > one feels like at the time. If you run across that again and email me the link, I will take a look and see if I think the issue should be raised on pydev. Of course, some modules *intentionally* define an open function, intended to be accessed as 'mod.open' and not as 'from mod import *; open'. Also, class/instance attributes can also reuse builtin names. But 'open = ' would be bad. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 16 19:32:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 19:32:36 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 8/16/2011 2:56 PM, Seebs wrote: > I wonder whether there's a way to mitigate the cost of these things by > messing with -W settings, such that runtime that wants to be fast can > omit the checks, but the default could still be to, well, prevent likely > errors. Warning messages have a cost even if suppressed. -- Terry Jan Reedy From monaghand.david at gmail.com Tue Aug 16 19:43:59 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Wed, 17 Aug 2011 00:43:59 +0100 Subject: Ten rules to becoming a Python community member. References: <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <37vl47hrcer8a6d7eoc8o2980ihaj7ci25@4ax.com> On Tue, 16 Aug 2011 16:12:53 -0700 (PDT), rantingrick wrote: >On Aug 16, 4:55?pm, David Monaghan wrote: >> On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick >> >> wrote: >> >If conciseness is all you seek then perhaps you prefer the following? >> >> >ORIGINAL: "I used to wear wooden shoes" >> >CONCISE: ?"I wore wooden shoes" >> >ORIGINAL: "I have become used to wearing wooden shoes" >> >CONCISE: ?"I like wearing wooden shoes" >> >However as you can see much of the rich information is missing. >> >> Indeed. Neither of your two concise examples has the same meaning of the >> originals. > >Really? Are you sure? Yes. > ORIGINAL1: "I used to wear wooden shoes" There's an implicit corollary to this sentence: "...but I don't any more", which is missing from your concise sentence: >CONCISE_1a: "I wore wooden shoes" > ORIGINAL_2: "I have become used to wearing wooden shoes" This carries the meaning, "I wasn't always comfortable/accustomed to wearing wooden shoes, but I am now". This is a totally different meaning from: >CONCISE_2a: "I like wearing wooden shoes" which refers only to the present and is much more positive. In fact, now I consider it, these examples are so clearly different that you can't be a native English speaker. Either that, or I've just fed a troll. Damn. DaveM From jdoe at usenetlove.invalid Tue Aug 16 19:46:48 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 23:46:48 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e4b0168$0$26208$c3e8da3$c14f6927@news.astraweb.com> Okay... Looks like I need pyHook. From usenet-nospam at seebs.net Tue Aug 16 19:49:23 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 23:49:23 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Terry Reedy wrote: > On 8/16/2011 2:56 PM, Seebs wrote: >> I wonder whether there's a way to mitigate the cost of these things by >> messing with -W settings, such that runtime that wants to be fast can >> omit the checks, but the default could still be to, well, prevent likely >> errors. > Warning messages have a cost even if suppressed. Yes, but is it a *significant* cost? My assumption is that the suppression would be of checking, not just of displaying messages. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 19:50:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 16:50:49 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 6:25?pm, John Gordon wrote: > In rantingrick writes: > > > ------------------------------------------------------------ > > ?ORIGINAL1: "I used to wear wooden shoes" > > ------------------------------------------------------------ > > CONCISE_1a: "I wore wooden shoes" > > "wore" does not convey the same meaning as "used to wear." > > "wore" means you have worn them in the past. > > "used to wear" means you have worn them in the past AND don't intend > to do so again. Actually that assertion is wrong. Take (in the extreme example) that you were (in the past) forced to wear a tutu. You did not like wearing the tutu but someone put a gun to your head, so you did it. Now. If later someone asks you "Have you ever been forced to wear anything you did not like?" and you replied "Yes, i wore a tutu [once]", there is no way anyone could extrapolate from that statement whether or not you would NEVER wear a tutu again. So the moral is: Just because something happened in the past does not mean it will happen in the future. The fact remains that "wore" and "used to wear" both compile down to the same "past tense" event HOWEVER neither have the capacity to predict future events. No one can predict the future. Not even YOU can predict whether or not you will wear a tutu again. You may say you would "never" wear a tutu again however you can NEVER be sure about that statement without a time machine, and lots of free time. From paulwray111111 at gmail.com Tue Aug 16 19:57:51 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 16:57:51 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> On Aug 17, 2:14?am, Chris Angelico wrote: > On Tue, Aug 16, 2011 at 12:33 PM, Paul Wray wrote: > > The idea is simply to use python ASTs to transform this code so that it > > accumulates the values of the bare expressions. > > That'd be similar to what the interactive loop does. Are you aware, > though, that docstrings are bare expressions? You may have a syntactic > collision there. > > ChrisA Thanks yes ama aware of docstrings but did not consider. They are easy to strip out though. From rosuav at gmail.com Tue Aug 16 20:02:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 01:02:34 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Wed, Aug 17, 2011 at 12:49 AM, Seebs wrote: > Yes, but is it a *significant* cost? ?My assumption is that the suppression > would be of checking, not just of displaying messages. > It mightn't be very significant, but there'd still be some cost. However, IMHO the greatest cost is the spamminess; forcing the user to deal with lines and lines of warnings is not a useful way to design a language. ChrisA From rosuav at gmail.com Tue Aug 16 20:03:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 01:03:34 +0100 Subject: Idea for pure-python templates using AST. In-Reply-To: <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 12:57 AM, Paul Wray wrote: > Thanks yes ama aware of docstrings but did not consider. > They are easy to strip out though. > Maybe. You'd have to take notice of what's a docstring and what's the first element to be outputted. Or alternatively, just forbid docstrings on those functions. ChrisA From malaclypse2 at gmail.com Tue Aug 16 20:06:45 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 16 Aug 2011 20:06:45 -0400 Subject: Determine what msvcrt.getch() is getting? In-Reply-To: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> References: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 5:43 PM, John Doe wrote: > Whatever msvcrt.getch() is returning here in Windows, it's not within > the 1-255 number range. How can I determine what it is returning? > > I would like to see whatever it is getting. Just print it. Like this: import msvcrt ch = msvcrt.getch() print (ch) for a bit more information, do this instead: import msvcrt ch = msvcrt.getch() print(type(ch), repr(ch), ord(ch)) -- Jerry From malaclypse2 at gmail.com Tue Aug 16 20:11:39 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 16 Aug 2011 20:11:39 -0400 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 5:59 PM, John Doe wrote: > No. I am running this from within Windows, all sorts of Windows. What does that mean? You seem very resistant to answering anyone's questions about your code. Is your code run from the command line, or does it have a GUI? If it has a GUI, what windowing toolkit are you using? If you have code that's not working, please, show us a short, run-able bit of sample code that demonstrates the problem you're experiencing. Describe the behavior you see, the behavior you expected instead, and the full text of any traceback you may be getting. -- Jerry From gc1223 at gmail.com Tue Aug 16 20:14:16 2011 From: gc1223 at gmail.com (gc) Date: Tue, 16 Aug 2011 17:14:16 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> On Aug 16, 4:39?pm, "Martin P. Hellwig" wrote: > On 03/08/2011 02:45, gc wrote: > > > > a,b,c,d,e = *dict() > > > where * in this context means something like "assign separately to > > all. > . . . it has a certain code smell to it. > I would love to see an example where you would need such a construct. Perfectly reasonable request! Maybe there aren't as many cases when multiple variables need to be initialized to the same value as I think there are. I'm a heavy user of collections, especially counters and defaultdicts. One frequent pattern involves boiling (typically) SQLite records down into Python data structures for further manipulation. (OK, arguably that has some code smell right there--but I often have to do very expensive analysis on large subsets with complex definitions which can be very expensive to pull, sometimes requiring table scans over tens of gigabytes. I *like* being able to use dicts or other structures as a way to cache and structure query results in ways amenable to analysis procedures, even if it doesn't impress Joe Celko.) defaultdict(list) is a very clean way to do this. I'll often have four or five of them collecting different subsets of a single SQL pull, as in: # PROPOSED SYNTAX: all_pets_by_pet_store, blue_dogs_by_pet_store, green_cats_by_pet_store, red_cats_and_birds_by_pet_store = *defautdict(list) # (Yes, indexes on color and kind would speed up this query, but the actual fields can be way quite complex and have much higher cardinality.) for pet_store, pet_kind, pet_color, pet_weight, pet_height in cur.execute("""SELECT s, k, c, w, h FROM SuperExpensivePetTable WHERE CostlyCriterionA(criterion_basis) IN("you", "get", "the", "idea")"""): all_pets_by_pet_store[pet_store].append(pet_weight, pet_height) if pet_color in ("Blue", "Cyan", "Dark Blue") and pet_kind in ("Dog", "Puppy"): blue_dogs_by_pet_store[pet_store].append(pet_weight, pet_height) #... and so forth all_pets_analysis = BootstrappedMarkovDecisionForestFromHell(all_pets_by_pet_store) blue_dogs_analysis = BootstrappedMarkovDecisionForestFromHell(blue_dogs_by_pet_store) red_cats_and_birds_analysis = BMDFFHPreyInteracton(red_cats_and_bird_by_pet_store) #... and so forth Point is, I'd like to be able to create such collections cleanly, and a,b,c = *defaultdict(list) seems as clean as it gets. Plus, when I realize I need six (or only three) it's annoying to need to change two redundant things (i.e. both the variable names and the count.) if tl_dr: break() Generally speaking, when you know you need several variables of the same (maybe complex) type, the proposed syntax lets the equals sign fully partition the variables question (how many variables do I need, and what are they called?) from the data structure question (what type should the variables be?) The other syntaxes (except Tim's generator- slurping one, which as Tim points out has its own issues) all spread the variables question across the equals sign, breaking the analogy with single assignment (where the form is Variable = DataStructure). If we're allowing multiple assignment, why can't we allow some form of Variable1, Variable2, Variable3 = DataStructure without reaching for list comprehensions, copy-pasting and/or keeping a side count of the variables? if much_tl_dr: break() Let me address one smell from my particular example, which may be the one you're noticing. If I needed fifty parallel collections I would not use separate variables; I've coded a ghastly defaultdefaultdict just for this purpose, which effectively permits what most people would express as defaultdict(defaultdict(list)) [not possible AFAIK with the existing defaultdict class]. But for reasons of explicitness and simplicity I try to avoid hash-tables of hash-tables (and higher iterations). I'm not trying to use dicts to inner-platform a fully hashed version of SQL, but to boil things down. Also bear in mind, reading the above, that I do a lot of script-type programming which is constantly being changed under severe time pressure (often as I'm sitting next to my clients), which needs to be as simple as possible, and which tech-savvy non-programmers need to understand. A lot of my value comes from quickly creating code which other people (usually research academics) can feel ownership over. Python is already a great language for this, and anything which makes the syntax cleaner and more expressive and which eliminates redundancy helps me do my job better. If I were coding big, stable applications where the defaultdicts were created in a header file and wouldn't be touched again for three years, I would care less about a more awkward initialization method. From philip at semanchuk.com Tue Aug 16 20:18:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 20:18:02 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> On Aug 16, 2011, at 7:29 PM, Terry Reedy wrote: > On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > >> I think that best practices would suggest that one shouldn't use >> variable >> names that shadow builtins (except in specific, special circumstances), >> so I don't really think this would be an annoyance at all. The number >> of >> *unwanted* warnings they'd get would be pretty close to zero. OTOH, in >> response to a question I asked on StackOverflow, someone posted a large >> list of times where this isn't followed in the std lib, so there seems >> to be a precedent for just using the builtin names for anything >> one feels like at the time. > > If you run across that again and email me the link, I will take a look and see if I think the issue should be raised on pydev. Of course, some modules *intentionally* define an open function, intended to be accessed as 'mod.open' and not as 'from mod import *; open'. Also, class/instance attributes can also reuse builtin names. But 'open = ' would be bad. Hi Terry, To generalize from your example, are you saying that there's a mild admonition against shadowing builtins with unrelated variable names in standard lib code? Here's an example from Python 3.2.1's argparse.py, lines 466-473. "open" is shadowed on the second line. # clean up separators for mutually exclusive groups open = r'[\[(]' close = r'[\])]' text = _re.sub(r'(%s) ' % open, r'\1', text) text = _re.sub(r' (%s)' % close, r'\1', text) text = _re.sub(r'%s *%s' % (open, close), r'', text) text = _re.sub(r'\(([^|]*)\)', r'\1', text) text = text.strip() Thanks Philip From ben+python at benfinney.id.au Tue Aug 16 20:26:29 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 17 Aug 2011 10:26:29 +1000 Subject: parameterized-testcase 0.2 References: Message-ID: <87bovodgsq.fsf@benfinney.id.au> Austin Bingham writes: > parameterized-testcase works with Python's standard unittest module to > provide a means to run TestCases with different "parameterizations". How is this different from what we already have in ?testscenarios? ? -- \ ?????????? | `\ (What is undesirable to you, do not do to others.) | _o__) ???? Confucius, 551 BCE ? 479 BCE | Ben Finney From timr at probo.com Tue Aug 16 20:32:12 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:32:12 -0700 Subject: string to unicode References: Message-ID: <1r2m47h2fsmoe1cd9tnng4rdlf3l8cf39m@4ax.com> Artie Ziff wrote: > >if I am using the standard csv library to read contents of a csv file >which contains Unicode strings (short example: >'\xe8\x9f\x92\xe8\x9b\x87'), You need to be rather precise when talking about this. That's not a "Unicode string" in Python terms. It's an 8-bit string. It might be UTF-8 encoding. If so, it maps to two Unicode code points, U+87D2 and U+86C7, which are both CJK ideograms. Is that what you expected? C:\Dev\videology\sw\viewer>python Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = '\xe8\x9f\x92\xe8\x9b\x87' >>> x.decode('utf8') u'\u87d2\u86c7' -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gordon at panix.com Tue Aug 16 20:33:56 2011 From: gordon at panix.com (John Gordon) Date: Wed, 17 Aug 2011 00:33:56 +0000 (UTC) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: In rantingrick writes: > > "wore" means you have worn them in the past. > > > > "used to wear" means you have worn them in the past AND don't intend > > to do so again. > Actually that assertion is wrong. > No one can predict the future. Not even YOU can predict whether or not Of course -- that's why the word "intend" was part of my answer. Did you overlook that crucial word? I stand by my assertion that the phrase "I used to do X" carries the meaning that you have done X in the past but DO NOT INTEND to do so in the future. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From timr at probo.com Tue Aug 16 20:39:39 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:39:39 -0700 Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: "Paul Wray" wrote: > >Ive had what I think is a great idea for pure-python templates (I can almost >hear the groans, bear with me...) >... >The idea: >Python syntax allows a statement to be a bare literal or identifier. These >have no effect on the program. >... >So is this (within the appropriate class context of course): > >def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' This is essentially how the original CherryPy version 1 web framework worked. In the end, I think it was decided that this represented too much of a mix of processing and presentation, and CherryPy 2 and 3 use a different scheme. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Aug 16 20:41:32 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:41:32 -0700 Subject: why i cannot import djang? References: Message-ID: <0f3m47dsv6amck9jl578a4ps7fbcg1nibm@4ax.com> smith jack wrote: > >this package is already in the site-packages directory, but i cannot >import it , it's really confusing ... The package is called "django". The name you put in the subject line is wrong. Does your code use the right spelling? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve+comp.lang.python at pearwood.info Tue Aug 16 20:58:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 10:58:41 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-16, Steven D'Aprano > wrote: >> On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >>>> Why should built-ins be treated as more sacred than your own objects? > >>> Because built-ins are described in the official documentation as having >>> a specific behavior, while my objects are not. > >> *My* objects certainly are, because I write documentation for my code. My >> docs are no less official than Python's docs. > > Sure they are. I can't get yours from python.org. And what makes that unofficial? python.org is not the sole arbiter of official documentation in the world. You can't get docs for Django or Scipy or NLTK from python.org either, but just try telling the authors of those libraries that their docs are somehow unofficial and see how far that gets you. [...] > I think code which shadows a built-in has a pretty real risk of being > harmful at some unspecified future point when some maintainer who hasn't > memorized every last line of the code makes the totally reasonable > assumption that basic language features are still working and available. Am I the only person who writes functions and methods any more? *wink* Modern languages, and by modern I mean most languages more than, oh, about fifty years old, provide ways to limit the scope of variables. You don't need to memorise "every last line of the code" to safely edit a function. def process(list, arg): spam(list) ham(arg) cheese(list, arg) The scope of parameter "list" is limited to within the function process itself. Inside, it shadows the built-in list. Outside, it doesn't do squat. [...] > My thoughts would be: > 1. It's hard to avoid shadowing anything unless you know the entire > language and never forget things. Define the "entire language". Does that include the names of all the plethora of exceptions? How about the standard library? For what it's worth, I don't care about memorising all the built-ins. I delegate that job to my editor, which has a syntax highlighter for Python. It never forgets built-ins. (In fact, sometimes this is a nuisance. When I'm editing Python 3 code, it still insists that apply and reduce are built-ins.) > 2. In particular, Python likes to use clear, obvious, names for things. > Meaning that your choice of a clear, obvious, name for a similar thing > could be the name of a thing in the language. Yes, and Python also encourages the use of scopes, so that the clear, obvious name for something in one scope does not clash with the clear, obvious, identical name for something completely different in another scope. > 3. I am not sure at all that shadowing can be "safe" in code which will > some day be maintained. Oh there's no doubt that shadowing *can* be unsafe. But then, very few things can't be abused. As I see it, there are (at least) four stages related to shadowing. (1) At first, you don't even know enough to be concerned by shadowing. You blithely call variables "list" and "str" without a care in the world... until something goes wrong. (2) Second stage, you know enough to realise that shadowing can be bad. You avoid shadowing everything. Your code is full of variables called "my_list" and "astr" and "some_tuple". You call your functions things like "izip" even though it is designed as a replacement for zip, because the caller might use from itertools import * and accidentally replace the built-in zip with my zip. You even avoid using "string" as a variable name because it might shadow the string module -- even though you haven't actually imported or used the string module in the last four years. (3) Eventually, you get frustrated writing doc strings like this: def function(astr, myint=0): """function(astr [, myint]) -> list Arguments: astr - string myint - integer Do something tool-like to a string and optional integer... """ and begin writing them like this: def function(astr, myint): """function(str [, int]) -> list Do something tool-like to a string and optional integer... """ (4) And then, after a while, you decide that perhaps shadowing is not always so bad. (It helps if the Effbot tells you off for objecting to shadowing in a two-line function.) At first, you limit yourself to using parameter names that shadow built-ins in small tool-like functions. Then when the world doesn't implode, you rethink the use of top-level function names like "izip" and realise that namespaces exist so that you don't need to care about shadowing functions you don't use, and if people call import * they have nobody to blame but themselves if things break. More-or-less-auto-biographically-ly y'rs, -- Steven From python.list at tim.thechases.com Tue Aug 16 21:02:19 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 20:02:19 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <4E4B131B.4040902@tim.thechases.com> On 08/16/2011 07:33 PM, John Gordon wrote: > I stand by my assertion that the phrase "I used to do X" carries the > meaning that you have done X in the past but DO NOT INTEND to do so > in the future. I'd tweak the meaning to be something like "I did X regularly in the past and I no longer do it regularly". E.g. "I used to drink a lot of cranberry juice"[*] connotes that I drank it regularly, but no longer drink it regularly, even though I might still drink it occasionally. But on the whole, I side with John far more than I side with RR on the issue. -tkc [*] seriously, in college I managed to put away over a gal/day. Ah, to be young again and have an unlimited cafeteria food-plan. From paulwray111111 at gmail.com Tue Aug 16 21:02:40 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 18:02:40 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <4e4ac3b6$0$23867$e4fe514c@news2.news.xs4all.nl> Message-ID: <5c8fcb5c-a1af-4847-88fb-2d9f2e0556b4@o9g2000vbo.googlegroups.com> On Aug 17, 5:23?am, Irmen de Jong wrote: > On 16-08-11 13:33, Paul Wray wrote: > > > > > > > > > > > The idea: > > Python syntax allows a statement to be a bare literal or identifier. > > These have no effect on the program. > > > So the function below is legal python: > > > def myFunc(): > > 'a' > > x = 45 > > 'b'; 'c'; x > > > So is this (within the appropriate class context of course): > > > def body(self, r): > > '

'; self.heading; '

' > > '
    ' > > for itm in self.items: > > '
  • '; itm; '
  • ' > > '
' > > Looks very similar to PTL what Quixote uses:http://www.quixote.ca/overview/paper.html > > (never used it though, and I doubt Quixote used ASTs) > > Irmen Thanks. Yes it looks much the same, and it does use AST. This from the ptl_compile.py module: """Compile a PTL template. First template function names are mangled, noting the template type. Next, the file is parsed into a parse tree. This tree is converted into a modified AST. It is during this state that the semantics are modified by adding extra nodes to the tree. Finally bytecode is generated using the compiler package. """ From ckaynor at zindagigames.com Tue Aug 16 21:09:42 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 16 Aug 2011 18:09:42 -0700 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4B131B.4040902@tim.thechases.com> References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> <4E4B131B.4040902@tim.thechases.com> Message-ID: On Tue, Aug 16, 2011 at 6:02 PM, Tim Chase wrote: > On 08/16/2011 07:33 PM, John Gordon wrote: >> >> I stand by my assertion that the phrase "I used to do X" carries the >> meaning that you have done X in the past but DO NOT INTEND to do so >> in the future. > > I'd tweak the meaning to be something like "I did X regularly in the past > and I no longer do it regularly". ?E.g. "I used to drink a lot of cranberry > juice"[*] connotes that I drank it regularly, but no longer drink it > regularly, even though I might still drink it occasionally. ?But on the > whole, I side with John far more than I side with RR on the issue. There is a difference between "I used to drink cranberry juice" and "I used to drink a lot of cranberry juice". The first says that you no longer drink it at all, while the latter has quantified the statement to say you may still drink it occasionally, but less than you used to. The key is that "a lot" quantifies "drink" in the second statement. > > -tkc > > > [*] seriously, in college I managed to put away over a gal/day. Ah, to be > young again and have an unlimited cafeteria food-plan. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From paulwray111111 at gmail.com Tue Aug 16 21:10:00 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 18:10:00 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> Message-ID: <58ed00f2-e5cb-4139-bf36-c4ffa975838c@a31g2000vbt.googlegroups.com> > You code fail, see below for other comment > > Traceback (most recent call last): > ? File "Download/pastie-2379978.rb", line 108, in > ? ? make_template(template1) > ? File "Download/pastie-2379978.rb", line 60, in make_template > ? ? ast.fix_missing_locations(astFromSrc) > ? File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations > ? ? _fix(node, 1, 0) > ? File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ? _fix(child, lineno, col_offset) > ? File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ? _fix(child, lineno, col_offset) > ? File "/usr/lib/python2.6/ast.py", line 121, in _fix > ? ? if 'lineno' in node._attributes: > AttributeError: 'arguments' object has no attribute '_attributes' > Sorry, should have specified Python 2.7. Also Pastie thinks its ruby code so the donwloaded file is confusingly ___.rb From steve+comp.lang.python at pearwood.info Tue Aug 16 21:14:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 11:14:41 +1000 Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> David Monaghan wrote: > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > wrote: > >>If conciseness is all you seek then perhaps you prefer the following? >> >>ORIGINAL: "I used to wear wooden shoes" >>CONCISE: "I wore wooden shoes" > >>ORIGINAL: "I have become used to wearing wooden shoes" >>CONCISE: "I like wearing wooden shoes" > >>However as you can see much of the rich information is missing. > > Indeed. Neither of your two concise examples has the same meaning of the > originals. The second one is considerably different. Consider: "I have become used to getting up at 3am to be flogged for an hour by my boss. Between the sleep deprivation and the scar tissue on my back, I hardly feel a thing any more." versus "I like getting up at 3am to be flogged for an hour by my boss. I get all tingly in my man-bits, if you know what I mean." The first case is more subtle. The implication of "I used to wear..." is that you did back in the past, but no longer do, while "I wore..." has no such implication. It merely says that in the past you did this, whether you still do or don't is irrelevant. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 16 21:29:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 11:29:30 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> Message-ID: <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> Philip Semanchuk wrote: > I think Python does lots of beneficial hand-holding. Garbage collection is > a good example. $DIETY knows, people have been struggling with manual > memory management in C and its ilk for a long time. Even though there are > good tools to help, memory leaks still happen. Python increases our > productivity by allowing us to forget about manual memory management > altogether. I can do it with tools like valgrind, but Python's makes the > point moot. Is that hand-holding? If so, I'm all for it. Hand-holding is not a well-defined term. According to Mel, garbage collectors would be hand-holding designed for soft nellies. http://www.cs.utah.edu/~elb/folklore/mel.html But Mel would probably make his own nails rather than buy them from the hardware store too. To some secret recipe involving rare metals that most people have never even heard of. And use a hammer forged from a single piece of meteor iron, shaped to fit his hand precisely. And it would be too heavy for mortals to lift. Of course the term "hand-holding" is a pejorative. The implication is that the person needing the hand-holding is like a child who needs somebody to hold their hand while they cross the road. Adults are supposed to know better (if only it were true in real life!). On the other hand, a real adult knows their limitations, and if you need a bit of hand-holding in a certain area of your life, so be it. Some errors aren't exactly a matter of inexperience and poor judgement, and so everyone can benefit from guard rails, seat belts and garbage collection. In that case, it isn't hand-holding, because there's no expectation that you should grow up from it. Even Donald Knuth probably would get benefit from a good garbage collector. I have no objection to lint tools. But separation of concerns should apply: the Python compiler should just compile what I tell it to, the linter should warn me if I'm running with scissors. -- Steven From usenet-nospam at seebs.net Tue Aug 16 21:35:29 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 01:35:29 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-17, Chris Angelico wrote: > On Wed, Aug 17, 2011 at 12:49 AM, Seebs wrote: >> Yes, but is it a *significant* cost? ?My assumption is that the suppression >> would be of checking, not just of displaying messages. > It mightn't be very significant, but there'd still be some cost. > However, IMHO the greatest cost is the spamminess; forcing the user to > deal with lines and lines of warnings is not a useful way to design a > language. Lines and lines? I'd say if it's to be allowed to shadow built-ins (and I'm not sure that's a good thing at all), you'd still be looking at one warning per shadowing, which shouldn't be too many. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 21:47:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 18:47:39 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 7:33?pm, John Gordon wrote: > In rantingrick writes: > > > > "wore" means you have worn them in the past. > > > > "used to wear" means you have worn them in the past AND don't intend > > > to do so again. > > Actually that assertion is wrong. > > No one can predict the future. Not even YOU can predict whether or not > > Of course -- that's why the word "intend" was part of my answer. ?Did you > overlook that crucial word? > > I stand by my assertion that the phrase "I used to do X" carries the > meaning that you have done X in the past but DO NOT INTEND to do so > in the future. Okay and i'm with you as long as you'll also agree that "i wore wooden shoes" carries the meaning that i've worn shoes in the past but gives no indication that i will wear shoes again. And if you agree with that (which is a fact BTW) then you must also agree that "i used to wear wear wooden shoes" also gives no guarantee that i won't wear them again. This point i have been trying to make all along is: Speaking with this verbiage leaves to much to be desired. To much meaning is specific *only* to the sender and prone to cause subtle errors upon receiving due to errors of the "lost-in-translation" kind. We must remove these ambiguities from our speech and from our code if we ever expect to evolve into a species capable of taking the next logical step in our evolution. That step will require massive amounts of coherent and articulate collaboration across many cultures. How do solve that problem you ask? By removing all cultures and joining the culture of Mankind. We know that knowledge is being spread far and wide and to every corner of this planet. No one will ever be robbed of an education because all the knowledge is being cataloged in the world wide library (WWW). A person living in a mud hut in Africa has the same access to the knowledge base as a professor working at a prestigious college. No more will the class structure be relevant because knowledge IS power. The playing fields are beginning to be leveled and the world is on course for a huge shake up soon. How soon this event will culminate into reality is yet to be known however i can assure you people that at our current rate, sadly it is going to be a very long time! The transition is not evolving as fast as it should be because we refuse to eradicate the enormous amounts of multiplicity that plague our knowledge bases. Language is one of the top offenders, which manifest itself over and over like a stupidity virus; and the worst part is that it shows no readily perceivable symptoms to the zombie masses! These "masses" of hosts continue on day after day infecting new people with this disease of multi-language-ism and as such entropy grows. Leaps are made but then setbacks are certain due to entropy. On and on we continue to be slung back and forth due to this elastic rubber band of stupidity. Some folks get emotional when i speak of these things. They confuse multiplicity with freedom. They fear the loss of their freedom to be lazy, slothful, and stupid. Yes you have a right to be these things if you want, but don't be expecting that your gene-pool will be part of the future because you will be bred out of existence! The future belongs to the intelligent agents capable of eradicating multiplicity and harnessing what mother nature could never harness with billions and billions of years built on innumerable random guesses... the future belongs to those with an IMAGINATION! An imagination is the most power tool we posses. With imagination we can drive evolution. Without imagination nothing you see or know would exist. We would be caught forever in the infinite loop of ape-ian stupidity and left to wither as just a blip on the evolutionary radar. With our imagination we can not only harness our world but also our universe (which is far more expansive than we have yet to realize). We can even harness evolution itself! We can transcend the flesh, and then, THEN... we shall take our rightful place as the gods! Maybe there is even an evolution of the gods of which replacements are created every trillion or so years. We are next in line to replace the aging gods that now control the known universe. To continue to deny that we are natures greatest creation would be tantamount to bitch slapping our very own mothers. Instead we should make her proud by being all that we can be and using our intelligence to utterly destroy her and IN EFFECT become something greater in the process than we ever where before. Progress "progresses" by the prodigy standing on the shoulders of the creators to reach that "next" higher cookie jar. The future is not saving the whales or the dolphins, or the endangered three toed alligator. Neither is the future "save the earth". The future is transcendence from the flesh into a new state of being. No form of matter how well we maintain this earth, one day the sun will consume it. Likewise one day the sun be consumed. Do not put your faiths and beliefs in matter, because matter is fluid -- here today and changed tomorrow. Instead, put your faith in knowledge, order, and finally the end goal of transcendence beyond the confines of flesh. Recently I was an unwilling party to this completely ridiculous TV show about how the human race would be an "X" number of years from now -- through-out the show "X" was incremented. These idiots (calling themselves scientist) imagined that we would still be flying space ships as the last stars in the universe burned out. All the while i am thinking to myself (and laughing) how completely moronic these guys are. Newsflash! If we do not make the transcendence in the next 1000 years we may never make it and therefor some other life form will have to take a shot some time in the distant future. But i can tell you one thing for sure. In 10,000 years we are NOT going to be flying around in spaceships. We will have transcended the physical flesh and harnessed pure energy which will in turn fuel our expanding singular intelligence. At that time the currently known universe will become the size of your backyard swimming pool. Nature is random, but true evolution is the harnessing of evolution to bring about order in the known universe. We were put into this universe to bring about order from the chaos (something random guesses can never accomplish) don't be an idiot and waste your life saving the dolphins and recycling. Yes, be kind to other people (and lower lifeforms), but realize that they are a means to an end. Singularity is the end. From tjreedy at udel.edu Tue Aug 16 22:10:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 22:10:30 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 8/16/2011 7:49 PM, Seebs wrote: > On 2011-08-16, Terry Reedy wrote: >> On 8/16/2011 2:56 PM, Seebs wrote: >>> I wonder whether there's a way to mitigate the cost of these things by >>> messing with -W settings, such that runtime that wants to be fast can >>> omit the checks, but the default could still be to, well, prevent likely >>> errors. > >> Warning messages have a cost even if suppressed. > > Yes, but is it a *significant* cost? My assumption is that the suppression > would be of checking, not just of displaying messages. The -W settings suppress display or printing of warnings, not their generation. import warnings if some_condition: warnings.warn(message, Warning) The test and warn call are made regardless of disposition. Filters determine what is done with each Warning subclass. The logging module can grab them too. -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Aug 16 22:11:36 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Aug 2011 03:11:36 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <4E4B2358.2030208@mrabarnett.plus.com> On 17/08/2011 01:14, gc wrote: > On Aug 16, 4:39 pm, "Martin P. Hellwig" > wrote: >> On 03/08/2011 02:45, gc wrote: >> >> >>> a,b,c,d,e = *dict() >> >>> where * in this context means something like "assign separately to >>> all. > >> . . . it has a certain code smell to it. >> I would love to see an example where you would need such a construct. > > Perfectly reasonable request! Maybe there aren't as many cases when > multiple variables need to be initialized to the same value as I think > there are. > [snip] As I see it, there are 2 issues: 1. Repeated evaluation of an expression: "dict()" would be evaluated as many times as necessary. In other words, it's an unlimited generator. 2. Lazy unpacking: unpacking normally continues until the source is exhausted, but here you want it to stop when the destination (the RHS) is satisfied. It just happens that in your use-case they are being used together. From tjreedy at udel.edu Tue Aug 16 22:15:03 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 22:15:03 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> Message-ID: On 8/16/2011 8:18 PM, Philip Semanchuk wrote: > Hi Terry, > To generalize from your example, are you saying that there's a mild admonition > against shadowing builtins with unrelated variable names in standard lib code? I would expect that there might be. I would have to check PEP8. > Here's an example from Python 3.2.1's argparse.py, lines 466-473. > "open" is shadowed on the second line. > > # clean up separators for mutually exclusive groups > open = r'[\[(]' > close = r'[\])]' > text = _re.sub(r'(%s) ' % open, r'\1', text) > text = _re.sub(r' (%s)' % close, r'\1', text) > text = _re.sub(r'%s *%s' % (open, close), r'', text) > text = _re.sub(r'\(([^|]*)\)', r'\1', text) > text = text.strip() -- Terry Jan Reedy From philip at semanchuk.com Tue Aug 16 22:16:49 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 22:16:49 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 16, 2011, at 9:29 PM, Steven D'Aprano wrote: > I have no objection to lint tools. But separation of concerns should apply: > the Python compiler should just compile what I tell it to, the linter > should warn me if I'm running with scissors. This point (also made by Ethan) I can agree with. I haven't looked through all the warnings the Python compiler emits, but it seems like it currently doesn't dispense advice (unlike, say, gcc). It only warns about changes in the language & standard library. In that context, asking it to warn about shadowing builtins would be an expansion of scope. bye, Philip From jason.swails at gmail.com Tue Aug 16 22:34:28 2011 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 16 Aug 2011 22:34:28 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 9:14 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > David Monaghan wrote: > > > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > > wrote: > > > >>If conciseness is all you seek then perhaps you prefer the following? > >> > >>ORIGINAL: "I used to wear wooden shoes" > >>CONCISE: "I wore wooden shoes" > > > >>ORIGINAL: "I have become used to wearing wooden shoes" > >>CONCISE: "I like wearing wooden shoes" > > > >>However as you can see much of the rich information is missing. > > > > Indeed. Neither of your two concise examples has the same meaning of the > > originals. > > The second one is considerably different. Consider: > > "I have become used to getting up at 3am to be flogged for an hour by my > boss. Between the sleep deprivation and the scar tissue on my back, I > hardly feel a thing any more." > > versus > > "I like getting up at 3am to be flogged for an hour by my boss. I get all > tingly in my man-bits, if you know what I mean." > > The first case is more subtle. The implication of "I used to wear..." is > that you did back in the past, but no longer do, while "I wore..." has no > such implication. It merely says that in the past you did this, whether you > still do or don't is irrelevant. > Meh. We can come up with examples all over the place to support any of our assertions. The context is what matters. In a newspaper article, you'd often prefer to use "The president wore shoes" to "The president used to wear shoes" because the extra words and space make a difference, and you want to be concise while letting people know what happened. In a public forum catering to native and non-native English speakers alike, common phrases like "used to" and "supposed to" are well known and understood. As such, I argue they are supposed to be used (to) often. In such circumstances as these, I say keep your language concise and simple, and your words will reach the most people (and the fewest killfiles, perhaps). As the wise man says, "It's not only quiet people that don't say much". (And here RR joins his silent majority). Peace, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Tue Aug 16 22:51:01 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 22:51:01 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> Message-ID: On Aug 16, 2011, at 10:15 PM, Terry Reedy wrote: > On 8/16/2011 8:18 PM, Philip Semanchuk wrote: > >> Hi Terry, >> To generalize from your example, are you saying that there's a mild admonition > > against shadowing builtins with unrelated variable names in standard lib code? > > I would expect that there might be. I would have to check PEP8. I was curious, so I checked. I didn't see anything specifically referring to builtins. This is as close as it gets: "If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus "print_" is better than "prnt". (Perhaps better is to avoid such clashes by using a synonym.)" bye Philip From usenet-nospam at seebs.net Tue Aug 16 23:17:23 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 03:17:23 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > Seebs wrote: >> On 2011-08-16, Steven D'Aprano >> wrote: >>> *My* objects certainly are, because I write documentation for my code. My >>> docs are no less official than Python's docs. >> Sure they are. I can't get yours from python.org. > And what makes that unofficial? > python.org is not the sole arbiter of official documentation in the world. But it is the sole arbiter of official *Python* documentation. If I am looking at code in Python, I reasonably expect the Python docs to be correct about that code. Incomplete, sure, but *correct*. >> I think code which shadows a built-in has a pretty real risk of being >> harmful at some unspecified future point when some maintainer who hasn't >> memorized every last line of the code makes the totally reasonable >> assumption that basic language features are still working and available. > Am I the only person who writes functions and methods any more? *wink* Yes. Everyone else converted to single giant blocks of code because they are easier to develop. :P > Modern languages, and by modern I mean most languages more than, oh, about > fifty years old, provide ways to limit the scope of variables. You don't > need to memorise "every last line of the code" to safely edit a function. Only the parts that are in scope, but... I seem to recall (and I'm pretty Python newbiesh, so I could be wrong) that Python classes create a scope in which bits of the class become visible, and some classes are sorta biggish. > def process(list, arg): > spam(list) > ham(arg) > cheese(list, arg) > The scope of parameter "list" is limited to within the function process > itself. Inside, it shadows the built-in list. Outside, it doesn't do squat. Yes. But what about the built-in spam? :) > Define the "entire language". Does that include the names of all the > plethora of exceptions? How about the standard library? I'd think "standard library" or close to it. > For what it's worth, I don't care about memorising all the built-ins. I > delegate that job to my editor, which has a syntax highlighter for Python. > It never forgets built-ins. (In fact, sometimes this is a nuisance. When > I'm editing Python 3 code, it still insists that apply and reduce are > built-ins.) Heh. I mostly don't use syntax highlighters; at best, they distract me, at worst, they distract me a lot. I also don't use one in English, although I am sure some people would love to have nouns in blue and punctuation in green. > Yes, and Python also encourages the use of scopes, so that the clear, > obvious name for something in one scope does not clash with the clear, > obvious, identical name for something completely different in another > scope. "Another" scope is normally a horizontal thing -- you're talking about a different scope such that you are *either* in this one *or* in that one. Built-ins are not in a scope you are never not in. > Oh there's no doubt that shadowing *can* be unsafe. But then, very few > things can't be abused. Yup. > As I see it, there are (at least) four stages related to shadowing. > (1) At first, you don't even know enough to be concerned by shadowing. You > blithely call variables "list" and "str" without a care in the world... > until something goes wrong. > (2) Second stage, you know enough to realise that shadowing can be bad. You > avoid shadowing everything. Your code is full of variables called "my_list" > and "astr" and "some_tuple". You call your functions things like "izip" > even though it is designed as a replacement for zip, because the caller > might use from itertools import * and accidentally replace the built-in zip > with my zip. > You even avoid using "string" as a variable name because it might shadow the > string module -- even though you haven't actually imported or used the > string module in the last four years. Heh. (I got advised by pylint not to grab something from it, but I no longer remember why; I seem to recall being totally unable to find a way to avoid that warning and still have the string processing I needed.) > (3) Eventually, you get frustrated writing doc strings like this: > > def function(astr, myint=0): > """function(astr [, myint]) -> list > > Arguments: > astr - string > myint - integer > > Do something tool-like to a string and optional integer... > """ > and begin writing them like this: > def function(astr, myint): > """function(str [, int]) -> list > > Do something tool-like to a string and optional integer... > """ That seems safe enough to me. :) > (4) And then, after a while, you decide that perhaps shadowing is not always > so bad. (It helps if the Effbot tells you off for objecting to shadowing in > a two-line function.) At first, you limit yourself to using parameter names > that shadow built-ins in small tool-like functions. Then when the world > doesn't implode, you rethink the use of top-level function names > like "izip" and realise that namespaces exist so that you don't need to > care about shadowing functions you don't use, and if people call import * > they have nobody to blame but themselves if things break. Hmm. See, I've never reached that, in Python or any other language. I figure it creates a new potential for confusion, and that I would rather avoid any ambiguity. I don't *like* ambiguity in code. So I don't shadow stuff that's part of the language, because doing that makes it possible for a line of code to have a clear and obvious meaning to someone who looks at that line out of context, and a *completely different* clear and obvious meaning to someone who looks at it with a bit more context. I don't like that! It means that someone reading my code can never, ever, assume that a standard language feature is actually itself and not a local shadow which does something different unless they go walking back up the scope chain checking. And that's a pretty big cost to attach to stuff that is, by design, basic and universally available. I might feel differently about names which were only visible after you imported some specific thing, but if we're talking built-ins that are always visible... Hmm. No, actually, even then, I just think it's Bad Mojo to overlap names that were taken by the language itself. If a name is in a different scope which I'm not in, I don't care about it, but if the name would already be in scope if I didn't declare it, then I am creating a nasty ambiguity if I use it. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From jdoe at usenetlove.invalid Tue Aug 16 23:52:35 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 03:52:35 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Jerry Hill wrote: > John Doe wrote: >> No. I am running this from within Windows, all sorts of >> Windows. > > What does that mean? You snipped the context, Benny. > You seem very resistant to answering anyone's questions about > your code. No one else has had a problem with my code, Benny, and you have not questioned my code. I laid it out, they tried it, and now we're getting on with it. > Is your code run from the command line, or does it have a GUI? Using "does your code have a GUI" produces zero search results. Maybe that works better in some other language. > If it has a GUI, what windowing toolkit are you using? I guess the answer is Dragonfly. Or maybe it's Komodo (the IDE), as previously stated. I have never been interested in making Windows, just making Windows dance. I do macroing. > If you have code that's not working, please, show us a short, > run-able bit of sample code that demonstrates the problem you're > experiencing. Benny... Apparently you have missed at least two other replies that said they tried some of the code I provided and it worked fine for them. As already stated, a hook is probably required. It's not a big surprise to me, but it's a lot more work. And now I am in the process of getting it done. I expect the results to be very pleasant, though. I'm going to have a system that does voice-activated scripting combined with a systemwide hook, all in one package. If I can get the hook properly installed, it should rock, and I'm ready to tackle it. -- > Describe the behavior you see, the behavior you expected > instead, and the full text of any traceback you may be getting. > > -- > Jerry > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail > Return-Path: > X-Original-To: python-list python.org > Delivered-To: python-list mail.python.org > X-Spam-Status: OK 0.054 > X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'sorts': 0.04; 'answering': 0.09; 'demonstrates': 0.09; '16,': 0.15; 'doe': 0.16; 'getting.': 0.16; 'subject:continuing': 0.16; 'wrote:': 0.16; 'header:In- Reply-To:1': 0.22; 'tue,': 0.23; 'pm,': 0.24; 'command': 0.24; 'aug': 0.24; 'traceback': 0.24; 'code': 0.25; 'code.': 0.26; 'bit': 0.28; 'problem': 0.28; 'message-id: mail.gmail.com': 0.29; 'toolkit': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'does': 0.32; 'to:addr:python-list': 0.33; 'describe': 0.34; 'see,': 0.34; 'short,': 0.34; 'running': 0.35; 'instead,': 0.37; 'run': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'your': 0.61; 'john': 0.62; 'full': 0.63; 'show': 0.67; 'received:209.85.215.174': 0.67; 'received:mail-ey0-f174.google.com': 0.67; 'resistant': 0.84; 'windowing': 0.84; 'working,': 0.93 > DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=09nEr3tlARCpTiOfhP1XOnteJhDd/baJpJhzNhp5UsI=; b=v9cmI/PvRfaLZhXxYs1bHlUOG+IaGEjPq0Xmx+WTkTOPc5YRFRNivsVO8wgKHaWXZm LhxtRbBJaAJuZlXNZ2rX2BxXaT8VJ6wnn2Z1gRv83Jqxi+jJ4zHcfExLPrLRzxLKZXOc oeVqZwTxJRX8VOytC17/RwVjznYcamlxZsG3Q= > MIME-Version: 1.0 > In-Reply-To: <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> > Date: Tue, 16 Aug 2011 20:11:39 -0400 > Subject: Re: Wait for a keypress before continuing? > From: Jerry Hill > To: python-list python.org > Content-Type: text/plain; charset=UTF-8 > X-BeenThere: python-list python.org > X-Mailman-Version: 2.1.12 > Precedence: list > List-Id: General discussion list for the Python programming language > List-Unsubscribe: , > List-Archive: > List-Post: > List-Help: > List-Subscribe: , > Newsgroups: comp.lang.python > Message-ID: > Lines: 13 > NNTP-Posting-Host: 2001:888:2000:d::a6 > X-Trace: 1313539907 news.xs4all.nl 23971 [2001:888:2000:d::a6]:45697 > X-Complaints-To: abuse xs4all.nl > From cbrown at cbrownsystems.com Wed Aug 17 00:13:20 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Tue, 16 Aug 2011 21:13:20 -0700 (PDT) Subject: testing if a list contains a sublist References: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> <4e4a2c41$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1f44baaf-37a6-40b6-994d-8141fe9f621c@t6g2000yqd.googlegroups.com> On Aug 16, 1:37?am, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote: > > > > > On Aug 15, 4:26?pm, Johannes wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > > My best guess: > > > from collections import Counter > > There's no reason to think that the Original Poster wants a multiset based > solution. He asked about lists and sublists. That's a standard term, like > substring: > > "12" is a substring of "01234". > "21" and "13" are not. > > [1, 2] is a sublist of [0, 1, 2, 3, 4]. > [2, 1] and [1, 3] are not. > > Since lists are ordered, so are sublists. > That's reasonable; although except in the subject, the OP never uses the term 'sublist'; instead using more ambiguous terms like 'contains', 'is totally contained', etc., with definition by limited example. So it was a bit of a guess on my part of what was wanted. > If the OP does want a solution that ignores order, then he needs to describe > his problem better. As it turns out, in another response the OP says he wants [2,1,2] to be 'contained' by [1,2,2]. But in any case he always has sorted lists, in which case, interestingly, the multiset approach and your more canonical sublist approach yield the same results. Cheers - Chas From usenet-nospam at seebs.net Wed Aug 17 01:06:24 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 05:06:24 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Message-ID: On 2011-08-17, John Doe wrote: > Using "does your code have a GUI" produces zero search results. > Maybe that works better in some other language. You shouldn't need a search engine to answer a question about your code. If you do, it suggests that perhaps one or more of the terms are unfamiliar to you? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From jdoe at usenetlove.invalid Wed Aug 17 01:49:32 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 05:49:32 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Message-ID: <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Seebs wrote: > John Doe wrote: >> Using "does your code have a GUI" produces zero search results. >> Maybe that works better in some other language. > > You shouldn't need a search engine to answer a question about > your code. Context is lost when you quote only one level. I was not answering a question about my code. I was pointing out the fact that my questioner's terminology is strange/corrupt. > If you do, it suggests that perhaps one or more of the terms are > unfamiliar to you? Yes, even the common term "command line" is foreign to me. I do some powerful stuff in Windows, without need for a command line. I realize it exists and that some people live by it, but it has been nearly useless to me. -- > > -s > -- > Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!news-out.readnews.com!transit3.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.megabitz.net!nnrp2-asbnva.megabitz.net!not-for-mail > Newsgroups: comp.lang.python > From: Seebs > Subject: Re: Wait for a keypress before continuing? > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df news.astraweb.com> > User-Agent: slrn/0.9.9p1 (Darwin) > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Message-ID: > Date: 17 Aug 2011 05:06:24 GMT > Lines: 14 > Organization: Megabitz - More USENET, Faster USENET > NNTP-Posting-Date: 17 Aug 2011 05:06:24 GMT > NNTP-Posting-Host: 93ee8380.news.megabitz.net > X-Trace: DXC=oHM8SW;d^:0L\jMDQ^7Q0;><6FU_Q:4m2^W\Y;gN2lO=:j84KQkNLA7b6g X-Complaints-To: abuse megabitz.net > From usenet-nospam at seebs.net Wed Aug 17 02:12:02 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 06:12:02 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: On 2011-08-17, John Doe wrote: > Context is lost when you quote only one level. Not significantly. > I was not answering a question about my code. I was pointing out > the fact that my questioner's terminology is strange/corrupt. Well, that's the thing. There was a question there, with perfectly valid terminology. >> If you do, it suggests that perhaps one or more of the terms are >> unfamiliar to you? > Yes, even the common term "command line" is foreign to me. I do > some powerful stuff in Windows, without need for a command line. So apparently you *do* know the term. Normally, to say that a term is foreign to you is to say that you have no idea what it means, not that you know what it means but don't use it. > I realize it exists and that some people live by it, but it has > been nearly useless to me. In which case, you're not using a command line, and are using a GUI, and the other poster's question is answered. The Google results you cite to are uninteresting and frankly irrelevant. If someone asks me whether the ornamental fish in my 55-gallon tank is a koi, that Google has no hits for "ornamental fish in your 55-gallon tank is a koi" does not mean that the terminology is "strange" or "corrupt". The terminology was fine. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 03:13:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:13:49 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 1:14 AM, gc wrote: > Perfectly reasonable request! Maybe there aren't as many cases when > multiple variables need to be initialized to the same value as I think > there are. > Minor clarification: You don't want to initialize them to the same value, which you can do already: a=b=c=d=e=dict() You want to initialize them each to a fresh evaluation of the same expression. What you're asking for is a syntax that writes an expression once, but evaluates it many times; I think it's going to work out something very similar to a list comprehension (as has been mentioned). ChrisA From rosuav at gmail.com Wed Aug 17 03:19:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:19:25 +0100 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 7:12 AM, Seebs wrote: >> Yes, even the common term "command line" is foreign to me. I do >> some powerful stuff in Windows, without need for a command line. > > So apparently you *do* know the term. ?Normally, to say that a term is > foreign to you is to say that you have no idea what it means, not that > you know what it means but don't use it. > Unless you're saying it for deliberate effect. Smith: "To whom do you pay rent?" Arcadian girl: "Rent? We do not know what it is to pay rent!" Smith: "Ah. They're Irish." They know full well what "rent" means, but don't truly comprehend the concept, as they've never done it. I would say that for many people, command lines are the same thing. For me, photo editing is like that. ChrisA From jdoe at usenetlove.invalid Wed Aug 17 03:23:44 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 07:23:44 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Seebs wrote: > John Doe wrote: >> Context is lost when you quote only one level. > > Not significantly. Whatever you say, Jeebs. >> I was not answering a question about my code. I was pointing >> out the fact that my questioner's terminology is >> strange/corrupt. > > Well, that's the thing. There was a question there, with > perfectly valid terminology. And I respect your opinion, Jeebs. >>> If you do, it suggests that perhaps one or more of the terms >>> are unfamiliar to you? > >> Yes, even the common term "command line" is foreign to me. I do >> some powerful stuff in Windows, without need for a command >> line. > > So apparently you *do* know the term. Not very well, obviously. > Normally, to say that a term is foreign to you is to say that > you have no idea what it means, Sounds like being a lexicographer is a fantasy of yours, Jeebs. > not that you know what it means but don't use it. But in fact I do not have a clear understanding of what it means, Jeebs, but I know that it's a common term. You are not a lexicographer, dude. >> I realize it exists and that some people live by it, but it has >> been nearly useless to me. > > In which case, you're not using a command line, and are using a > GUI, and the other poster's question is answered. That might have been clear to most normal people in my first reply to the first follow-up. "I am using Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon Naturally Speaking, Natlink, and Dragonfly might all be part of the process." The answer was pointless by the time the question was asked straightforward. Thanks to the prior replies, by then I had already figured out that I need a keyboard hook. The answer doesn't matter anymore. > The Google results you cite to are uninteresting and frankly > irrelevant. You have every right to an opinion, Fuckturd. > If someone asks me whether the ornamental fish in my 55-gallon > tank is a koi, that Google has no hits for "ornamental fish in > your 55-gallon tank is a koi" does not mean that the terminology > is "strange" or "corrupt". No wonder you don't quote relevant material, Jeebs. If anybody knew what you were comparing that expression to, you would look stupid. > The terminology was fine. Are you a master of terminology on wikishit, Jeebs? I think wikishit sucks. Wannabe lexicographers like you might be a reason. I've dealt with some real lexicographers, Jeebs, you aren't one. -- > > -s > -- > Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!newsfeeds.sol.net!post2.nntp.sol.net!posts.news.megabitz.net!nnrp3-asbnva.megabitz.net!not-for-mail > Newsgroups: comp.lang.python > From: Seebs > Subject: Re: Wait for a keypress before continuing? > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d news.astraweb.com> > User-Agent: slrn/0.9.9p1 (Darwin) > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Message-ID: > Date: 17 Aug 2011 06:12:02 GMT > Lines: 40 > Organization: Megabitz - More USENET, Faster USENET > NNTP-Posting-Date: 17 Aug 2011 06:12:02 GMT > NNTP-Posting-Host: 3c8d6a06.news.megabitz.net > X-Trace: DXC=BKlkN0:D\OSc::[BQideGP><6FU_Q:4mR^W\Y;gN2lO]C2e6efi]<9Z?jW6Mmc0=4W7d DE\31QYU2V739; X-Complaints-To: abuse megabitz.net > From rosuav at gmail.com Wed Aug 17 03:27:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:27:44 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Wed, Aug 17, 2011 at 2:35 AM, Seebs wrote: > On 2011-08-17, Chris Angelico wrote: >> It mightn't be very significant, but there'd still be some cost. >> However, IMHO the greatest cost is the spamminess; forcing the user to >> deal with lines and lines of warnings is not a useful way to design a >> language. > > Lines and lines? > > I'd say if it's to be allowed to shadow built-ins (and I'm not sure that's > a good thing at all), you'd still be looking at one warning per shadowing, > which shouldn't be too many. One warning per shadowing. Okay. def foo(list): """Foo's the list provided and returns True on success or False on failure.""" def bar(list): """Counts the number of bars in the list, assuming it to be made of music.""" if not foo(list): return You call foo() once and bar() twice. How many shadowings have there been? How many warnings do you get? A simple implementation would give five warnings for this case - once for each invocation that shadows a builtin. Another simple implementation would give two warnings, at the time that the def statements are executed; this is preferred, but it's still two warnings, and if you have a huge set of functions that do this, that can easily be "lines and lines" of warnings. Or should it set a flag and say "I've already warned this session about shadowing 'list', so suppress all others"? That seems confusing. ChrisA From rosuav at gmail.com Wed Aug 17 03:34:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:34:22 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 1:58 AM, Steven D'Aprano wrote: >> My thoughts would be: >> 1. ?It's hard to avoid shadowing anything unless you know the entire >> language and never forget things. > > Define the "entire language". Does that include the names of all the > plethora of exceptions? How about the standard library? The shadowing issue applies to the standard library as well as the builtins, so yes; to avoid shadowing *anything*, you would have to know the entire language. I posit that this is a practical impossibility, and that unexpected shadowing will always be possible (and won't always be prevented by syntax highlighting). Some day you'll discover that you can't use module X because you have a function called X, and you'll have to rename. ChrisA From peter.mosley at talk21.com Wed Aug 17 04:03:00 2011 From: peter.mosley at talk21.com (peter) Date: Wed, 17 Aug 2011 01:03:00 -0700 (PDT) Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Is there an equivalent to msvcrt for Linux users? I haven't found one, and have resorted to some very clumsy code which turns off keyboard excho then reads stdin. Seems such an obvious thing to want to do I am surprised there is not a standard library module for it. Or have I missed someting (wouldn't be the first time!) Peter From steve+comp.lang.python at pearwood.info Wed Aug 17 04:15:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 18:15:19 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Aug 2011 01:17 pm Seebs wrote: [...] > "Another" scope is normally a horizontal thing -- you're talking about > a different scope such that you are *either* in this one *or* in that > one. > > Built-ins are not in a scope you are never not in. That's technically incorrect. Built-ins are a scope you are never in, if by "in" you mean "code is executed in this scope". You have three scopes in general: Local Global Built-ins (There's also zero or more nonlocal scopes, between local and global, that applies to closures and nested functions, but never mind that.) Code is almost(?) always executed in the local scope. (eval and exec let you mess around with that, somewhat.) E.g. an assignment "x = 1" applies to the local namespace unless you explicitly declare it global. If you are in the top level of a module, the local namespace is also the global one, the global statement does nothing, and the assignment occurs in the global namespace. However, name lookup rules are such that while assignments are always local, unsuccessful lookups may fall through to global then built-in. See also: http://www.python.org/dev/peps/pep-0227/ The only way to put something into the built-in namespace is by using the fully-qualified name: >>> import builtins # Use __builtin__ in Python 2 >>> builtins.x = 1 # Kids! Don't try this at home! >>> >>> x 1 >>> del x # prove it isn't a global or local Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined So a top-level (global) assignment, say: def sum(list): ... *shadows* the built-ins sum and list, it doesn't replace them. It defines a local variable "list" and a global variable "sum", but it doesn't touch either built-in. They are still available via the fully qualified name builtins.sum and builtins.list. [...] >> (4) And then, after a while, you decide that perhaps shadowing is not >> always so bad. (It helps if the Effbot tells you off for objecting to >> shadowing in a two-line function.) At first, you limit yourself to using >> parameter names that shadow built-ins in small tool-like functions. Then >> when the world doesn't implode, you rethink the use of top-level function >> names like "izip" and realise that namespaces exist so that you don't >> need to care about shadowing functions you don't use, and if people call >> import * they have nobody to blame but themselves if things break. > > Hmm. See, I've never reached that, in Python or any other language. I > figure it creates a new potential for confusion, and that I would rather > avoid any ambiguity. I don't *like* ambiguity in code. Ah, well you see the thing is, this is Python. As soon as you call any function you don't control, you no longer know what your environment is with any certainty. For all you know, the harmless-looking function is monkey-patching builtins like there's no tomorrow. Speaking broadly, perhaps too broadly, we're incredibly proud of the ability to modify nearly everything at runtime. Fortunately, while we are proud of having that ability, actually *using* it is considered a mortal sin. We're not Ruby developers -- if you actually monkey-patch something, especially built-ins, you can expect to be taken outside and slapped around with a fish if you get caught. http://www.youtube.com/watch?v=IhJQp-q1Y1s > So I don't shadow stuff that's part of the language, because doing that > makes it possible for a line of code to have a clear and obvious meaning > to someone who looks at that line out of context, and a *completely > different* clear and obvious meaning to someone who looks at it with a bit > more > context. I don't like that! It means that someone reading my code can > never, ever, assume that a standard language feature is actually itself > and not a local shadow which does something different unless they go > walking back up the scope chain checking. And that's a pretty big cost > to attach to stuff that is, by design, basic and universally available. Sure. But they can't have that certainty regardless of whether you shadow something, because how do they know whether you've shadowed it or not? In theory, anything could be anything at any time, and you have no protection. In practice, I worry more about being eaten by genetically-engineered flying piranhas than about rogue monkey-patching code. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 17 04:28:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 18:28:14 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Aug 2011 05:23 pm John Doe wrote: > You have every right to an opinion, Fuckturd. I shouldn't need to say this to anyone over the age of four, but being obnoxious to people trying to help does not encourage others to answer your question. You don't win points for insulting people who are trying to solve your problems. -- Steven From gnarlodious at gmail.com Wed Aug 17 05:06:31 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:06:31 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables Message-ID: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get >>> name2 -> MiniFieldStorage('name2', 'Val2') when I need to assign the variable name2 the value Val2 This is Py3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:16:06 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:16:06 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables Message-ID: <07a5fd4b-00fb-4ac9-b3b3-9ae820deb132@p10g2000yqi.googlegroups.com> I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get >>> name2 -> MiniFieldStorage('name2', 'Val2') when I need to assign the variable name2 the value Val2 This is Py3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:19:22 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:19:22 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:20:27 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:20:27 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: <33d4abcb-e017-430a-a46a-d1669f053c54@a12g2000yqi.googlegroups.com> I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie From rosuav at gmail.com Wed Aug 17 05:25:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:25:03 +0100 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:06 AM, Gnarlodious wrote: > I get a construct like this: > > form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), > MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) > > when I need to assign the variable name2 the value Val2 You can probably do this with some kind of list comprehension, but I recommend against it, if this has come from a web form. You do NOT want end users having the power to set variables. Keep it in a separate object (such as 'form') such that you must always be explicit about fetching form data. PHP has learned the risks; here's a decent summary: http://www.php.net/manual/en/security.globals.php Chris Angelico From gc1223 at gmail.com Wed Aug 17 05:26:42 2011 From: gc1223 at gmail.com (gc) Date: Wed, 17 Aug 2011 02:26:42 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Aug 17, 3:13?am, Chris Angelico wrote: > Minor clarification: You don't want to initialize them to the same > value, which you can do already: > > a=b=c=d=e=dict() Right. Call the proposed syntax the "instantiate separately for each target" operator. (It can be precisely defined as a * on the RHS of a one-into-many assignment statement--i.e. an assignment statement with 1 object on the RHS and more than 1 on the LHS). It has only one very modest function, which is to unpack a, b, c, d, e = *dict() to a, b, c, d, e = dict(), dict(), dict(), dict(), dict() so that you have n separate objects instead of one. If you want the same object duplicated five times, you'd best use a=b=c=d=e=dict(). (I'd guess that 90% of the people who try the a=b=c version actually *want* separate objects and are surprised at what they get--I made that mistake a few times!--but changing either behavior would be a very bad idea. This proposed syntax would be the Right Way to get separate objects.) Maybe this is more visibly convenient with a complex class, like x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) where you need three separate objects but don't want to duplicate the class call (for obvious copy-paste reasons) and where bundling it in a list comprehension: x, y, z = [SuperComplexClass(param1, etc, ...) for _ in range(3)] layers gunk on top of something that's already complex. > I think it's going to work out something very similar to a > list comprehension (as has been mentioned). Right; kind of a self-limiting generator[1], although that sounds MUCH more complex than it needs to. It's really just sugar. Not that it this is a suggestion :) but it could easily be done with a pre- processor. It would also be perfectly amenable to automated code conversion (i.e. 3to2). On Aug 16, 10:11 pm, MRAB wrote: > 1. Repeated evaluation of an expression: "dict()" would be evaluated as > many times as necessary. In other words, it's an unlimited generator. > 2. Lazy unpacking: unpacking normally continues until the source is > exhausted, but here you want it to stop when the destination (the RHS) > is satisfied. Yes, this is a good way to think of it. (Although I think you meant to type LHS, right?) * in this context would tell Python to do both of these things at once: evaluate successively and unpack lazily to the destination. Although it's still fully (and more simply) explainable as sugar. [1] Self-limiting is the key here. As above, the only proposed methods which don't require manual tallying on the RHS are Tim's very creative a,b,c,d,e,*scrap = (dict() for _ in range(9999)), which in this case creates a list containing 9994 unnecessary dicts, or the purer but Python-crashing a,b,c,d,e,*scrap = (dict() for _ in itertools.count()). Tim's intuition, which I share, is that in both cases *scrap should, since it's in final position, actually become the generator-in-state-6, rather than slurping the rest into a list. One argument for this is that the present behavior is (surprisingly, counterintuitively) identical for list comprehensions and generator expressions. Changing the outer parens to brackets yields the same results. But that's a separate, more complex proposal which would need its own use cases. From rosuav at gmail.com Wed Aug 17 05:41:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:41:41 +0100 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:19 AM, Gnarlodious wrote: > import cgi, os > os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" > form=cgi.FieldStorage() > > form > > dict = {} > for key in form.keys(): dict[ key ] = form[ key ].value > You could probably use a list comp for this, but there's not a lot of difference. (By the way, you should be aware that you're shadowing the builtin 'dict' here. That's not a problem, but be aware.) dict.update(((key,form[key].value) for key in form)) That's a generator that returns a (key,value) tuple for each form element, which update() will happily use. But the last line: > locals().update(dict) is, IMHO, a very bad idea. Rename your dictionary to 'request' or 'data' or 'form' or something, and then reference form['name3'] instead; or, be explicit: name3=form['name3'] Incidentally, you seem to be working at the module level, where locals() is globals() (and I mean that literally - 'locals() is globals()' is True). You may not be able to do this with locals() in a function: http://docs.python.org/library/functions.html#locals Chris Angelico From rosuav at gmail.com Wed Aug 17 05:45:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:45:24 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:26 AM, gc wrote: > On Aug 17, 3:13?am, Chris Angelico wrote: > >> Minor clarification: You don't want to initialize them to the same >> value, which you can do already: >> >> a=b=c=d=e=dict() > > Right. Call the proposed syntax the "instantiate separately for each > target" operator. ?(It can be precisely defined as a * on the RHS of a > one-into-many assignment statement--i.e. an assignment statement with > 1 object on the RHS and more than 1 on the LHS). > Agreed, but there's no requirement for it to be instantiating something (although that will be common). "dict()" is an expression that you want to evaluate five (or however many) times. It might just as easily be some other function call; for instance: head1,head2,head3=file.readline() to read three lines from a file. Or it mightn't even be a function call per se. ChrisA From gc1223 at gmail.com Wed Aug 17 06:33:58 2011 From: gc1223 at gmail.com (gc) Date: Wed, 17 Aug 2011 03:33:58 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <2e4e9b97-df0e-4c1e-9f41-db2b475add21@d7g2000vbv.googlegroups.com> On Aug 17, 5:45?am, Chris Angelico wrote: (snip) > > Right. Call the proposed syntax the "instantiate separately for each > > target" operator. > (snip) > It might just > as easily be some other function call; for instance: > > head1,head2,head3=file.readline() Hm--that's interesting! OK, call it the "evaluate separately for each target" operator. Same benefits in this use case; if I realize that the file only has two header lines, I can just change head1, head2, head3 = *file.readline() to head1, head2 = *file.readline() without needing to keep a RHS like = [file.readline() for _ in range(3)] in lockstep with the number of variables I'm assigning. Presumably this syntax should be disallowed, as a grammatical matter, when there's a starred target (per PEP 3132/language reference 6.2). That is, head, *body, tail = *file.readline() is disallowed, since it is (by definition) simply sugar for head = file.readline() *body = file.readline() tail = file.readline() and *body = file.readline() is disallowed (see PEP 3132). (Here, of course, you'd just want head, *body, tail = file.readlines(), which is perfectly good code.) PS. Off-topic, but the *target syntax already gets into similar territory, since a, *b, c = itertools.count() crashes with a MemoryError--but what else could it do? Ruling out such infinite-assignment statements on a grammatical basis would require solving the halting problem through static analysis, which might be a bit inefficient :P From benjokal at gmail.com Wed Aug 17 06:37:26 2011 From: benjokal at gmail.com (Benji Ara.) Date: Wed, 17 Aug 2011 06:37:26 -0400 Subject: How to package a gui with py2exe Message-ID: Hello I wonder how you package a Tkinter gui with py2exe? Thanks Benji * * -------------- next part -------------- An HTML attachment was scrubbed... URL: From f.derainville at gmail.com Wed Aug 17 07:27:10 2011 From: f.derainville at gmail.com (fmder1) Date: Wed, 17 Aug 2011 04:27:10 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=A0=3A_Messed_up_Mac_installation?= In-Reply-To: References: Message-ID: Checkout Homebrew. It can install in a very easy and clean way different version of Python (as well as a lot of other stuff). It tried for a long time to keep my Mac clean and this is so far the best I found. From f.derainville at gmail.com Wed Aug 17 07:28:05 2011 From: f.derainville at gmail.com (fmder1) Date: Wed, 17 Aug 2011 04:28:05 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=A0=3A_Messed_up_Mac_installation?= In-Reply-To: References: Message-ID: <81ef6220-e536-499c-8e1c-944a6b0b3be7@glegroupsg2000goo.googlegroups.com> Forgot to include a link : https://github.com/mxcl/homebrew From mail at timgolden.me.uk Wed Aug 17 08:17:22 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Aug 2011 13:17:22 +0100 Subject: Windows service in production? In-Reply-To: <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> Message-ID: <4E4BB152.5020904@timgolden.me.uk> On 16/08/2011 15:46, snorble wrote: > Interesting. Normally I would use py2exe then do "myapp.exe -install" > to install the app as a service. How do you handle installing the > service? Also what does the service show under the properties, for the > executable? "python.exe script.py" or something else? To install, I simply invoke the Command-line handler which comes with the pywin32 service utils: if __name__ == '__main__': win32serviceutil.HandleCommandLine (Service) (I imagine that's what py2exe's doing for you behind the scenes). The executable shows as pythonservice.exe. The short and long display names can of course be whatever you like. TJG From nobody at nowhere.com Wed Aug 17 08:28:42 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Aug 2011 13:28:42 +0100 Subject: testing if a list contains a sublist References: Message-ID: On Tue, 16 Aug 2011 09:57:57 -0400, John Posner wrote: > How about using Python's core support for "==" on list objects: > for i in range(alist_sz - slist_sz + 1): > if slist == alist[i:i+slist_sz]: > return True This is bound to be asymptotically O(alist_sz * slist_sz), even if the constant factor is reduced by use of ==. Boyer-Moore and regexps are asymptotically O(alist_sz). However, the setup costs are much higher, so you might need alist_sz to be very large before they win out. From vlastimil.brom at gmail.com Wed Aug 17 08:44:07 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 17 Aug 2011 14:44:07 +0200 Subject: How to package a gui with py2exe In-Reply-To: References: Message-ID: 2011/8/17 Benji Ara. : > Hello > I wonder how you package a Tkinter gui with py2exe? > Thanks > Benji > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, check the necessary steps on the py2exe homepage http://www.py2exe.org/index.cgi/Tutorial in your setup script, you have to use something like the following for a gui app: setup(windows=["gui_hello.py"]) instead of console in the sample code setup(console=['hello.py']) For more details there are some dedicated pages on the project wiki: http://www.py2exe.org/index.cgi/FrontPage hth, vbr From nobody at nowhere.com Wed Aug 17 08:45:36 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Aug 2011 13:45:36 +0100 Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, 17 Aug 2011 02:06:31 -0700, Gnarlodious wrote: > I get a construct like this: > > form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), > MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) > > Now how would I assign every variable name* its value? Don't do this. It will allow the user to set any variable they wish, not just the ones you want them to, which is a major security flaw. PHP had this as a language feature (controlled by the register_globals directive), and it was rightly decried as a major security flaw. From duncan.booth at invalid.invalid Wed Aug 17 09:15:04 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Aug 2011 13:15:04 GMT Subject: How to install easy_install on windows ? References: <77f65ea2-3748-4dfa-af7c-498ebe2d3be8@f7g2000vba.googlegroups.com> Message-ID: aspineux wrote: > in a command prompt run > C:\Your Python Directory\python.exe C:\Your Download directory > \ez_setup.py > > Then use > > C:\Your Python Directory\python.exe C:\Your Python Directory\I dont > know where the easy_install script will be installed\easy_install.py > install module_name Or even just use: C:\Your Python Directory\scripts\easy_install install module_name as easy_install will also add a .exe to your Python's 'scripts' folder. -- Duncan Booth http://kupuguy.blogspot.com From ethan at stoneleaf.us Wed Aug 17 09:21:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 06:21:23 -0700 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4E4BC053.6050000@stoneleaf.us> Welcome to my killfile. *plonk* From grickert at coldstorage.com Wed Aug 17 09:30:14 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Wed, 17 Aug 2011 09:30:14 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com><4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On 8/16/2011 7:29 PM, Terry Reedy wrote: > > On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > > > I think that best practices would suggest that one shouldn't use > > variable > > names that shadow builtins (except in specific, special > circumstances), > > so I don't really think this would be an annoyance at all. The > number > > of > > *unwanted* warnings they'd get would be pretty close to zero. OTOH, > in > > response to a question I asked on StackOverflow, someone posted a > large > > list of times where this isn't followed in the std lib, so there > seems > > to be a precedent for just using the builtin names for anything > > one feels like at the time. > > If you run across that again and email me the link, I will take a look > and see if I think the issue should be raised on pydev. Of course, some > modules *intentionally* define an open function, intended to be > accessed > as 'mod.open' and not as 'from mod import *; open'. Also, > class/instance > attributes can also reuse builtin names. But 'open = ' > would > be bad. > > > -- > Terry Jan Reedy > See the accepted answer to this question: http://stackoverflow.com/questions/7079519/is-there-python-code-in-the-python-standard-library-that-uses-variable-names-that From ameretat.reith at gmail.com Wed Aug 17 10:11:21 2011 From: ameretat.reith at gmail.com (Ameretat Reith) Date: Wed, 17 Aug 2011 18:41:21 +0430 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: <2411612.e64O9QM6es@hades> On Se shanbe 25 Mordad 1390 01:26:54 Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes Hope best answer is found so far. for easy answer, i prefer to use Python `==' operator instead of inner loop. l=[1,2,3,4,5] s=[1,2,2] sc=len(s) for c in xrange(len(l)-sc+1): if l[c:sc+c] == s: print ( 'found at {0}'.format(c) ) break Since sub-lists memory will be garbage collected, there is no problem in memory usage, but in time needed for constructing new slice, there is. -- Amir Ghassemi Nasr (Reith) GPG ID: 371035B4 (http://46.4.214.112/~reith/reith.asc) GPG Fingerprint: 18E6 CF11 BE80 F541 DC68 B6AF 9373 DE72 3710 35B4 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 230 bytes Desc: This is a digitally signed message part. URL: From hansmu at xs4all.nl Wed Aug 17 10:16:23 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 17 Aug 2011 16:16:23 +0200 Subject: Wait for a keypress before continuing? In-Reply-To: <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> On 17/08/11 10:03:00, peter wrote: > Is there an equivalent to msvcrt for Linux users? I haven't found > one, and have resorted to some very clumsy code which turns off > keyboard excho then reads stdin. Seems such an obvious thing to want > to do I am surprised there is not a standard library module for it. Or > have I missed someting (wouldn't be the first time!) The quick and dirty way is to invoke stty(1) using os.system: import os def getpassword(prompt="Password: "): try: os.system("stty -echo") passwd = raw_input(prompt) finally: os.system("stty echo") return passwd Strictly speaking, os.system is deprecated and you should use the equivalent invocation of subprocess.call: import subprocess def getpassword(prompt="Password: "): try: subprocess.call(["stty", "-echo"]) passwd = raw_input(prompt) finally: subprocess.call(["stty", "echo"]) return passwd If you don't want to use an external process, use termios: import termios, sys def getpassword(prompt="Password: "): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ECHO # lflags try: termios.tcsetattr(fd, termios.TCSADRAIN, new) passwd = raw_input(prompt) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) return passwd These functions work on any Posix system (including Mac OSX), but not on Windows. Hope this helps, -- HansM From thinke365 at gmail.com Wed Aug 17 11:13:20 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 17 Aug 2011 23:13:20 +0800 Subject: Some warning appears when installing virtualenv, does it matters? Message-ID: the warning is just as follows E:\Tools>pip install virtualenv Downloading/unpacking virtualenv Downloading virtualenv-1.6.4.tar.gz (1.9Mb): 1.9Mb downloaded Running setup.py egg_info for package virtualenv warning: no previously-included files matching '*.*' found under directory ' docs\_templates' Installing collected packages: virtualenv Running setup.py install for virtualenv warning: no previously-included files matching '*.*' found under directory ' docs\_templates' Installing virtualenv-script.py script to E:\Tools\gov\tools\py_build\Script s Installing virtualenv.exe script to E:\Tools\gov\tools\py_build\Scripts Installing virtualenv.exe.manifest script to E:\Tools\gov\tools\py_build\Scr ipts Successfully installed virtualenv Cleaning up... From jabba.laci at gmail.com Wed Aug 17 11:20:52 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 17 Aug 2011 17:20:52 +0200 Subject: monitor mouse coordinates in real-time In-Reply-To: <6e7d17a8-d5aa-4755-9bd4-09c09bed5c03@o26g2000vbi.googlegroups.com> References: <6e7d17a8-d5aa-4755-9bd4-09c09bed5c03@o26g2000vbi.googlegroups.com> Message-ID: Hi, Thanks, the problem got solved. The updated version can be found at https://gist.github.com/1144708 in a comment below the original post. Solution: self.connect("destroy", self.quit) def quit(self, widget): self.mouseThread.kill() gtk.main_quit() It was not evident that quit() must be passed the argument "widget" too. Thanks, Laszlo On Wed, Aug 17, 2011 at 16:48, MrJean1 wrote: > Check that the app.quit method registered with atexit is called. ?E.g. > on Windows, that may not be the case. > > /JeAN > > > On Aug 14, 9:39?am, Jabba Laci wrote: >> I'm trying something similar. In the thread there is a variable which >> is modified by the parent. However, the thread doesn't quit the >> infinite loop. If someone could provide a patch, that'd be really >> useful. >> >> Thanks, >> >> Laszlo >> >> >> On Sun, Aug 14, 2011 at 13:00, TheSaint wrote: >> > Jabba Laci wrote: >> >> >> Could you please help me out how to close the application correctly? >> >> > I think you should put a flag into the code, which the parent might modify >> > it, so it will tell the child process to quit. >> > Then the flag should need to be read periodically to know whether is time to >> > quit. >> >> > -- >> >http://mail.python.org/mailman/listinfo/python-list > > From mail at timgolden.me.uk Wed Aug 17 11:47:49 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Aug 2011 16:47:49 +0100 Subject: How to Check Write Access of a Folder on Windows In-Reply-To: References: Message-ID: <4E4BE2A5.3010405@timgolden.me.uk> On 16/08/2011 13:38, Ayaskant Swain wrote: > Hi Tim, > > Thanks for your reply. It seems this issue is related to python bug > -http://bugs.python.org/issue2528 > But the patch code looks complex to me. I want to make changes only > in my python script which will read an user given directory path& > check it's write access. What is the use of posixmodule.c file? Well.. the changes to posixmodule.c, had they been accepted, would have meant that a call to os.access on Windows would have done the work to determine whether or not you truly had access. As it is, that issue has been "demoted" to a doc-and-deprecate bug. So you either need to do the same sequence of actions (more or less) or to simulate its effect. Certainly you can retrieve the ACEs in the DACL via the GetFileSecurity call, and you're then going to have to compare the effect of all the (possibly quite complex and inherited) ACEs on the logged-in user's ability to view the directory. The ACEs might refer directly to the user or (more likely) indirectly via groups, including builtins like "Domain Users" or "Administrators". So you'd have to work out whether your user was in one of those groups, possibly indirectly as groups can contain groups. Certainly all of this is do-able but it won't be trivial. I'm sorry I can't be more helpful but I haven't had a need for this functionality myself (even the patch to issue2528 was in response to someone else's need similar to yours). TJG From tjreedy at udel.edu Wed Aug 17 12:12:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2011 12:12:47 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: The issue behind this thread is that for immutable objects, binding to n copies has the same effect as n bindings to one object (so one does not really have to know which one is doing), whereas the two are different for mutable objects (so one does have to know). In short, identity matters for mutables but not for immutables. Python programmers must learn both this and the fact that Python does not make copies unless asked. Adding a special case exception to the latter to mask the former does not seem like a good idea. On 8/17/2011 5:26 AM, gc wrote: > It has only one very modest function, which is to unpack > > a, b, c, d, e = *dict() *expression has already been proposed to generally mean what it does in function calls -- unpack the iterator in place. funnylist = [1,2,*dict,99,100] # == [1,2]+list(dict)+[99,100] would interpolate the keys of the dict into the list. There is a tracker issue for this -- it would be a follow-on to the addition of *traget in assignments. In a real sense, "a,b = iterable" *already* means "a,b = *iterable". If *iterable had been in general use from the beginning, presume the latter is how we would write sequence unpacking for assignments. > a, b, c, d, e = dict(), dict(), dict(), dict(), dict() *expression will not be changed in meaning to magically re-evaluate an expression some multiple number of times according to code elsewhere. > so that you have n separate objects instead of one. If you want the > same object duplicated five times, you'd best use a=b=c=d=e=dict(). Not 'duplicated', but 'bound'. > (I'd guess that 90% of the people who try the a=b=c version actually > *want* separate objects and are surprised at what they get--I made > that mistake a few times! Guessing that 90% of people are like you is likely to be wrong. I think this use case (for more than 2 or 3 copies) is pretty rare for most people. Where many people do trip up is "array = [[0]*i]*j", expecting to get j copies of [0]*i rather than j bindings of one object. But then, they must have the same wrong idea that [0]*i makes i copies of 0. For immutable 0, the misunderstanding does not matter. For mutable [0]*i, it does. People *must* learn that sequence multiplication multiplies bindings, not (copies of) objects. Both multiple copy problems have the same solution: array = [[0]*i for _ in range(j)] a,b,c,d,e = [dict() for _ in range(5)] The fact that the number of assignment sources (possibly after implicit unpacking) and targets have to match, unless one uses *target, and that both sides need to be changed if one is, is true of all assignments, not just this rare case. >--but changing either behavior would be a > very bad idea. This proposed syntax would be the Right Way to get > separate objects.) It would be very Wrong as it already has a very different meaning. -- Terry Jan Reedy From clp2 at rebertia.com Wed Aug 17 12:23:01 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Aug 2011 09:23:01 -0700 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 2:19 AM, Gnarlodious wrote: > I should add that this does what I want, but something a little more > Pythonic? > > import cgi, os > os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" > form=cgi.FieldStorage() > > form > > dict = {} > for key in form.keys(): dict[ key ] = form[ key ].value > > dict > locals().update(dict) > name3 Try it within a function. It will fail epic-ly in CPython and most other implementations. Read the note in the locals() docs: http://docs.python.org/library/functions.html#locals Cheers, Chris From usenet-nospam at seebs.net Wed Aug 17 12:33:05 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:05 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > I shouldn't need to say this to anyone over the age of four, but being > obnoxious to people trying to help does not encourage others to answer your > question. You don't win points for insulting people who are trying to solve > your problems. The frustrating part, of course, is that the people who do this are doing it for reasons such that the explanation seems only proof that they are even more right than they had previously expected. Pathological narcissism is scary. If you ever find yourself going longer than usual without being wrong, start checking your work more carefully. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 2011-08-17, peter wrote: > Is there an equivalent to msvcrt for Linux users? I haven't found > one, and have resorted to some very clumsy code which turns off > keyboard excho then reads stdin. Seems such an obvious thing to want > to do I am surprised there is not a standard library module for it. Or > have I missed someting (wouldn't be the first time!) There's no direct equivalent to the whole of msvcrt. The Unixy way to do stuff like that on the command line is usually curses. But to make a long story short: Unix evolved in a setting where there was often not a user at *THE* console, and users were often on devices such that it made sense to have all the line editing happen on the remote end, with the remote end sending a completed line once the user was done with all that stuff like backspaces. Unix programs that do stuff like this for tty input do exist, of course, but for the most part, they use an entire API designed for creating such utilities, rather than one or two specialized functions. (Another part of the reason for this: The Unix solution scales nicely to the case where the five people using your program will be doing so on physically different hardware terminals which don't use the same escape sequences for cursor movement.) Usually when people omit something obvious from a design, it's because of other constraints or history to the design which make it less obvious. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-17, Chris Angelico wrote: > def foo(list): > """Foo's the list provided and returns True on success or False on > failure.""" > > def bar(list): > """Counts the number of bars in the list, assuming it to be made > of music.""" > if not foo(list): return > You call foo() once and bar() twice. How many shadowings have there > been? How many warnings do you get? I'd say two, one when def foo... is parsed, one when def bar... is parsed. > A simple implementation would give five warnings for this case - once > for each invocation that shadows a builtin. Another simple > implementation would give two warnings, at the time that the def > statements are executed; this is preferred, but it's still two > warnings, and if you have a huge set of functions that do this, that > can easily be "lines and lines" of warnings. Or should it set a flag > and say "I've already warned this session about shadowing 'list', so > suppress all others"? That seems confusing. I guess I don't object to multiple warnings if I do the same thing multiple times. I was just thinking in terms of a single parse-time warning for the actual point at which something is shadowed, rather than, say, a warning every time a name is hit during execution of statements and refers to a shadow. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > On Wed, 17 Aug 2011 01:17 pm Seebs wrote: > [...] >> "Another" scope is normally a horizontal thing -- you're talking about >> a different scope such that you are *either* in this one *or* in that >> one. >> Built-ins are not in a scope you are never not in. > That's technically incorrect. Built-ins are a scope you are never in, if > by "in" you mean "code is executed in this scope". No, by "in" I mean "lookups from your code will reach this scope if they don't find something sooner". >> Hmm. See, I've never reached that, in Python or any other language. I >> figure it creates a new potential for confusion, and that I would rather >> avoid any ambiguity. I don't *like* ambiguity in code. > Ah, well you see the thing is, this is Python. As soon as you call any > function you don't control, you no longer know what your environment is > with any certainty. For all you know, the harmless-looking function is > monkey-patching builtins like there's no tomorrow. Speaking broadly, > perhaps too broadly, we're incredibly proud of the ability to modify nearly > everything at runtime. Heh. > Fortunately, while we are proud of having that ability, actually *using* it > is considered a mortal sin. We're not Ruby developers -- if you actually > monkey-patch something, especially built-ins, you can expect to be taken > outside and slapped around with a fish if you get caught. Okay, so. Here's what I don't get. If it's such a bad thing, *why is it allowed*? Why are you proud of the ability to do something that you are never socially-allowed to do? I have mixed feelings about Ruby's general tolerance for monkey-patching, although I've seen it do some pretty awesome things, so I am somewhat inclined to accept that it may be worth it. But it's clearly a feature which is used intentionally. It sounds to me like Python is very proud of having a feature which no one would ever use. ... Why? > Sure. But they can't have that certainty regardless of whether you shadow > something, because how do they know whether you've shadowed it or not? Well, they could trust me. :) > In theory, anything could be anything at any time, and you have no > protection. In practice, I worry more about being eaten by > genetically-engineered flying piranhas than about rogue monkey-patching > code. I do too, if I know that people don't shadow built-ins. If I know that people are shadowing built-ins, then some of the time, when I'm editing other peoples' code, they HAVE effectively monkey-patched it. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Wed Aug 17 12:36:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 02:36:45 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e4bee1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Hans Mulder wrote: > Strictly speaking, os.system is deprecated and you should use > the equivalent invocation of subprocess.call: Strictly speaking, os.system is *not* deprecated in either Python 2.x or 3.x. Latest stable documentation for Python 2.7 and 3.2: http://docs.python.org/library/os.html#os.system http://docs.python.org/py3k/library/os.html#os.system And docs in development for 3.3 (unstable): http://docs.python.org/dev/library/os.html#os.system Deprecation means that there are active plans to remove the feature. There are no such plans to remove os.system. What the docs say is much milder: "The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function." Using subprocess may be recommended, but that is not the same as saying that os.system is deprecated. os.system will not be going away any time in the foreseeable future. -- Steven From python at mrabarnett.plus.com Wed Aug 17 12:55:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Aug 2011 17:55:51 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <4E4BF297.7040901@mrabarnett.plus.com> On 17/08/2011 10:26, gc wrote: > On Aug 17, 3:13 am, Chris Angelico wrote: > >> Minor clarification: You don't want to initialize them to the same >> value, which you can do already: >> >> a=b=c=d=e=dict() > > Right. Call the proposed syntax the "instantiate separately for each > target" operator. (It can be precisely defined as a * on the RHS of a > one-into-many assignment statement--i.e. an assignment statement with > 1 object on the RHS and more than 1 on the LHS). > I think that lazy unpacking is the more important issue because we can replace instantiation with copying: def copies(obj, count=None): if count is None: while True: yield obj.copy() else: for i in range(count): yield obj.copy() (Should it yield deep copies, or should there be a separate deep_copies function?) > It has only one very modest function, which is to unpack > > a, b, c, d, e = *dict() > > to > > a, b, c, d, e = dict(), dict(), dict(), dict(), dict() > This becomes: a, b, c, d, e = copies(dict(), 5) With lazy unpacking it would become: a, b, c, d, e = lazy copies(dict()) (Or whatever the syntax is.) > so that you have n separate objects instead of one. If you want the > same object duplicated five times, you'd best use a=b=c=d=e=dict(). > (I'd guess that 90% of the people who try the a=b=c version actually > *want* separate objects and are surprised at what they get--I made > that mistake a few times!--but changing either behavior would be a > very bad idea. This proposed syntax would be the Right Way to get > separate objects.) > > Maybe this is more visibly convenient with a complex class, like > > x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) > x, y, z = lazy copies(SuperComplexClass(param1, etc, ...)) [snip] From tjreedy at udel.edu Wed Aug 17 13:02:35 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2011 13:02:35 -0400 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 8/17/2011 12:33 PM, Seebs wrote: > On 2011-08-17, peter wrote: >> Is there an equivalent to msvcrt for Linux users? I haven't found >> one, and have resorted to some very clumsy code which turns off >> keyboard excho then reads stdin. Seems such an obvious thing to want >> to do I am surprised there is not a standard library module for it. Or >> have I missed someting (wouldn't be the first time!) > > There's no direct equivalent to the whole of msvcrt. The Unixy way to > do stuff like that on the command line is usually curses. But to make > a long story short: Unix evolved in a setting where there was often > not a user at *THE* console, and users were often on devices such that > it made sense to have all the line editing happen on the remote end, with > the remote end sending a completed line once the user was done with all > that stuff like backspaces. > > Unix programs that do stuff like this for tty input do exist, of course, > but for the most part, they use an entire API designed for creating such > utilities, rather than one or two specialized functions. (Another part > of the reason for this: The Unix solution scales nicely to the case where > the five people using your program will be doing so on physically > different hardware terminals which don't use the same escape sequences > for cursor movement.) The difference is between "Hit to continue" (which we can do in portable Python) versus "Hit any key to continue" (which we cannot, and which also leads to the joke about people searching for the 'any' key ;-). The equivalent contrast for GUIs is "Click OK to continue" versus "Click anywhere to continue" If having to click a specific area is okay for GUIs, having to hit a specific key for TUIs should be also. -- Terry Jan Reedy From usenet-nospam at seebs.net Wed Aug 17 13:05:31 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:05:31 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 2011-08-17, Terry Reedy wrote: > The difference is between "Hit to continue" (which we can do in > portable Python) versus "Hit any key to continue" (which we cannot, and > which also leads to the joke about people searching for the 'any' key > ;-). And more importantly, frustration and confusion when people pick control or shift. > The equivalent contrast for GUIs is "Click OK to continue" versus > "Click anywhere to continue" If having to click a specific area is okay > for GUIs, having to hit a specific key for TUIs should be also. In general I agree. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 13:25:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 18:25:12 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4E4BF297.7040901@mrabarnett.plus.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> <4E4BF297.7040901@mrabarnett.plus.com> Message-ID: On Wed, Aug 17, 2011 at 5:55 PM, MRAB wrote: > x, y, z = lazy copies(SuperComplexClass(param1, etc, ...)) > This assumes that you can construct it once and then copy it reliably, which may mean that the class implement copying correctly. It also wouldn't work with: a, b, c, d = *random.randint(1,20) which would roll 4d20 and get the results in separate variables. The OP's idea of separately evaluating the expression would; but to do it with copying would require a special "randint" object that functions exactly as an integer but, when copied, would re-randomize. Perhaps * is the wrong syntactic element to use. Maybe it needs a special assignment operator: a, b, c, d @= random.randint(1,20) which would evaluate its left operand as a tuple of lvalues, then evaluate its right operand once for each element in the left operand, and assign to each element in turn. (I've no idea what form of assignment operator would be suitable, but @= is currently illegal, so it ought to be safe at least for discussion purposes.) Chris Angelico From usenet-nospam at seebs.net Wed Aug 17 13:36:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:36:08 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Ethan Furman wrote: > Seebs wrote: >> On 2011-08-17, Steven D'Aprano wrote: >>> Ah, well you see the thing is, this is Python. As soon as you call any >>> function you don't control, you no longer know what your environment is >>> with any certainty. For all you know, the harmless-looking function is >>> monkey-patching builtins like there's no tomorrow. Speaking broadly, >>> perhaps too broadly, we're incredibly proud of the ability to modify nearly >>> everything at runtime. >>> Fortunately, while we are proud of having that ability, actually *using* it >>> is considered a mortal sin. We're not Ruby developers -- if you actually >>> monkey-patch something, especially built-ins, you can expect to be taken >>> outside and slapped around with a fish if you get caught. >> Here's what I don't get. >> If it's such a bad thing, *why is it allowed*? Why are you proud of the >> ability to do something that you are never socially-allowed to do? > Monkey-patching built-ins would be something along the lines of > import sys > sys.modules['__builtin__'].str = my_super_string > and is what stands you in jeopardy of being fish-slapped. ;) > Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. Oh, I know. I was just noticing that Steven's post is specifically talking about how Python users are proud of having the ability to monkey-patch. If monkey-patching like that is a mortal sin, leads to fish-slapping, and so on.. Why is it possible? Why not just reject such things as invalid code? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Wed Aug 17 13:36:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 10:36:12 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4BFC0C.80603@stoneleaf.us> Seebs wrote: > On 2011-08-17, Steven D'Aprano wrote: >> On Wed, 17 Aug 2011 01:17 pm Seebs wrote: >>> Hmm. See, I've never reached that, in Python or any other language. I >>> figure it creates a new potential for confusion, and that I would rather >>> avoid any ambiguity. I don't *like* ambiguity in code. > >> Ah, well you see the thing is, this is Python. As soon as you call any >> function you don't control, you no longer know what your environment is >> with any certainty. For all you know, the harmless-looking function is >> monkey-patching builtins like there's no tomorrow. Speaking broadly, >> perhaps too broadly, we're incredibly proud of the ability to modify nearly >> everything at runtime. > > Heh. > >> Fortunately, while we are proud of having that ability, actually *using* it >> is considered a mortal sin. We're not Ruby developers -- if you actually >> monkey-patch something, especially built-ins, you can expect to be taken >> outside and slapped around with a fish if you get caught. > > Okay, so. > > Here's what I don't get. > > If it's such a bad thing, *why is it allowed*? Why are you proud of the > ability to do something that you are never socially-allowed to do? Monkey-patching built-ins would be something along the lines of import sys sys.modules['__builtin__'].str = my_super_string and is what stands you in jeopardy of being fish-slapped. ;) Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. ~Ethan~ From ethan at stoneleaf.us Wed Aug 17 13:37:53 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 10:37:53 -0700 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4BFC71.8080506@stoneleaf.us> Seebs wrote: > Pathological narcissism is scary. If you ever find yourself going longer > than usual without being wrong, start checking your work more carefully. :) +1 QOTW From usenet-nospam at seebs.net Wed Aug 17 13:38:25 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:38:25 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Chris Angelico wrote: > On Wed, Aug 17, 2011 at 5:33 PM, Seebs wrote: >> If it's such a bad thing, *why is it allowed*? ?Why are you proud of the >> ability to do something that you are never socially-allowed to do? > Going back to my original three examples: I may have been unclear about jumping topics; that comment was about monkey-patching, not about shadowing. > I greatly prefer this to the alternative, which is another 133 > reserved words (based on Python 3.2 for Windows). You have a point there. I guess I'm just used to the assumption that the confusion caused by shadowing names outweighs the benefits of using them -- the world is rich with plausible names. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 13:42:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 18:42:26 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 5:33 PM, Seebs wrote: > If it's such a bad thing, *why is it allowed*? ?Why are you proud of the > ability to do something that you are never socially-allowed to do? > Going back to my original three examples: > 1) Deliberate shadowing because you want to change the behavior of the > name. Extremely rare. > 2) Shadowing simply by using the name of an unusual builtin (like > 'file') in a context where you never use it. Very common. > 3) Unintentional shadowing where you create a variable, but then > intend to use the builtin. This is the only one that's a problem. All three are allowed, but it's the first one that's considered unusual. The second one is simply that Python doesn't have a million and one reserved words. Yes, you probably don't want to use 'print' as a variable name, but shadowing it with an exact equivalent would be fine (eg to automatically date-stamp or log your output, without changing your code). And as described above, using list/str/id etc is not uncommon. I greatly prefer this to the alternative, which is another 133 reserved words (based on Python 3.2 for Windows). ChrisA From rosuav at gmail.com Wed Aug 17 14:02:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 19:02:23 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 6:38 PM, Seebs wrote: > I may have been unclear about jumping topics; that comment was about > monkey-patching, not about shadowing. > Ah, apologies. Monkey-patching is a way of using the middle of a stack of code without using what's below it. If everything is statically linked, then every function does exactly what it was written to do and no more; if it accepts a file object as an argument, you could give it some other file-like object, but that's all. However, if the function was written to use print() and you don't want it to print to the screen, what do you do? Obviously it's your responsibility to ensure that your replacement is 100% equivalent in the required functionality, but it's a great flexibility to simply change the meaning of "print"; the alternative is to copy and paste the code, make one change (or even no change at all, if your replacement print() is a global), and run that. As Ethan posted while I was typing this, you're allowed to do it, but you just need to have a good reason for it. I like to explain/justify myself in comments when these things crop up in my code. ChrisA From usenet-nospam at seebs.net Wed Aug 17 14:09:30 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 18:09:30 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Ethan Furman wrote: > Part of the fun of Python is experimentation. And how much fun is it to > be told over and over, "No, you can't do that"? Okay, I buy that. Actually, this sort of fits with my experience of how (sane) people do it in Ruby. And I'm really the wrong person to criticize people for monkey-patching: http://www.yoctoproject.org/projects/pseudo (In which I monkeypatch *the entire Unix filesystem API*. On Linux and OS X. For C programs.) I guess maybe my question shouldn't have been "why is it allowed", but "and why is it bad to use it?" It just seemed like "you should never do this, it's horrible" and "we're proud of being able to do this" were not entirely compatible. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Wed Aug 17 14:13:30 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 11:13:30 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4C04CA.4050505@stoneleaf.us> Seebs wrote: > On 2011-08-17, Ethan Furman wrote: >> Seebs wrote: >>> On 2011-08-17, Steven D'Aprano wrote: >>>> Ah, well you see the thing is, this is Python. As soon as you call any >>>> function you don't control, you no longer know what your environment is >>>> with any certainty. For all you know, the harmless-looking function is >>>> monkey-patching builtins like there's no tomorrow. Speaking broadly, >>>> perhaps too broadly, we're incredibly proud of the ability to modify nearly >>>> everything at runtime. > >>>> Fortunately, while we are proud of having that ability, actually *using* it >>>> is considered a mortal sin. We're not Ruby developers -- if you actually >>>> monkey-patch something, especially built-ins, you can expect to be taken >>>> outside and slapped around with a fish if you get caught. > >>> Here's what I don't get. > >>> If it's such a bad thing, *why is it allowed*? Why are you proud of the >>> ability to do something that you are never socially-allowed to do? > >> Monkey-patching built-ins would be something along the lines of > >> import sys >> sys.modules['__builtin__'].str = my_super_string > >> and is what stands you in jeopardy of being fish-slapped. ;) > >> Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. > > Oh, I know. I was just noticing that Steven's post is specifically talking > about how Python users are proud of having the ability to monkey-patch. > > If monkey-patching like that is a mortal sin, leads to fish-slapping, and > so on.. > > Why is it possible? Why not just reject such things as invalid code? Well, the mortal sin part is a bit of an exaggeration -- it's more like you'd better have a really darn good reason to do it. And it is absolutely one of my favorite parts about Python. If I want to inject a custom Path class into builtins so it's readily available, and then change os.listdir to return it instead of normal strings, I can. If my application is truly case-insensitive, I can make my own istr class and monkey-patch builtins so it's what is used. Can this blow-up in my face? Certainly. But I would rather have the option open to me instead of being told "No, I'm sorry, you can't do that because I (developers in question) didn't imagine a good use case for it". Part of the fun of Python is experimentation. And how much fun is it to be told over and over, "No, you can't do that"? As an example of something that could easily have been outlawed, but wasn't, check out http://stackoverflow.com/questions/7068340 ~Ethan~ From thinke365 at gmail.com Wed Aug 17 14:16:14 2011 From: thinke365 at gmail.com (smith jack) Date: Thu, 18 Aug 2011 02:16:14 +0800 Subject: How to build python using visual studio 2005? Message-ID: anybody here have build it correctly? how to make a msi file just as the official site did? is there any detailed tutorial online? From steve+comp.lang.python at pearwood.info Wed Aug 17 14:29:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 04:29:30 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > The difference is between "Hit to continue" (which we can do in > portable Python) versus "Hit any key to continue" (which we cannot, and > which also leads to the joke about people searching for the 'any' key > ;-). The equivalent contrast for GUIs is "Click OK to continue" versus > "Click anywhere to continue" If having to click a specific area is okay > for GUIs, having to hit a specific key for TUIs should be also. Poor analogy. A better analogy to a GUI would be comparing: What would you like to do? Select an option and then click OK: ( ) Cancel ( ) Print (x) Save [__OK__] versus: What would you like to do? [__Cancel__] [__Print__] [__Save__] Actually, a better analogy would be a GUI that made you do this: What would you like to do? Type the first letter of the option you prefer in the text field, then click the OK button: Options: Cancel | Print | Save My option: [ ............ ] [__OK__] (ASCII art best viewed with a fixed-width font.) Generally speaking, the second UI would be preferred. The raw_input/input UI is well-designed for entering plain text data. It is extremely poor as a command interface. Bringing it back to text interfaces, it would be useful to have a text interface such that commands can be executed using a single key press. You might want to detect and respond to (say) the arrow keys, or ESC, or P rather than P. Curses apps can do it, proof that even under Unix it is desirable. (Imagine how awkward it would be to use a TUI mail client or text editor where the only user input was from something like raw_input.) Unfortunately curses is quite heavyweight for a simple CLI script. I note also that even the Python interactive interpreter under Linux has an extremely limited detect-single-keypress capability: Ctrl-C generates a KeyboardInterrupt without needing to hit Enter, and Ctrl-D exits the interpreter. -- Steven From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Aug 17 15:13:36 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 17 Aug 2011 19:13:36 +0000 (UTC) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: gc wrote: > Maybe this is more visibly convenient with a complex class, like > > x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) > > where you need three separate objects but don't want to duplicate the > class call (for obvious copy-paste reasons) and where bundling it in a > list comprehension: > > x, y, z = [SuperComplexClass(param1, etc, ...) for _ in range(3)] > > layers gunk on top of something that's already complex. That just seems like an odd use case to me. I rarely find myself wanting to make exactly N copies of the same thing and assign them to explicit names. If I'm not making just one, it's usually because I'm making some sort of list or dict of them that will be accessed by index (not with names like "x", "y", and "z"), in which case a list comprehension is the right way to go. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From ethan at stoneleaf.us Wed Aug 17 15:52:29 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 12:52:29 -0700 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4E4C1BFD.4040500@stoneleaf.us> gc wrote: > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() This isn't going to happen. From all the discussion so far I think your best solution is a simple helper function (not tested): def repeat(count_, object_, *args, **kwargs): result = [] for _ in range(count_): result.append(object_(*args, **kwargs)) return result a, b, c, d, e = repeat(5, dict) These are each new objects, so depending on the function (like the random.rand_int example) the values may not be the same. Oh, and I put the trailing _ on count and object to minimize possible conflicts with keyword arguments. ~Ethan~ From schesis at gmail.com Wed Aug 17 16:07:55 2011 From: schesis at gmail.com (Zero Piraeus) Date: Wed, 17 Aug 2011 16:07:55 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: : Off on a tangent ... On 16 August 2011 20:14, gc wrote: > > Let me address one smell from my particular example, which may be the > one you're noticing. If I needed fifty parallel collections I would > not use separate variables; I've coded a ghastly defaultdefaultdict > just for this purpose, which effectively permits what most people > would express as defaultdict(defaultdict(list)) [not possible AFAIK > with the existing defaultdict class]. Dunno if it's better than your ghastly defaultdefaultdict, but this works: >>> from collections import defaultdict >>> ddd = defaultdict(lambda: defaultdict(list)) >>> ddd["foo"]["bar"].append("something") >>> ddd["foo"]["bar"] ['something'] >>> -[]z. From Yingjie.Lin at mssm.edu Wed Aug 17 16:22:48 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Wed, 17 Aug 2011 16:22:48 -0400 Subject: pairwise combination of two lists Message-ID: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Hi Python users, I have two lists: li1 = ['a', 'b'] li2 = ['1', '2'] and I wish to obtain a list like this li3 = ['a1', 'a2', 'b1', 'b2'] Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I am looking for. Thank you. - Yingjie From mwilson at the-wire.com Wed Aug 17 17:15:34 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Aug 2011 17:15:34 -0400 Subject: pairwise combination of two lists References: Message-ID: Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly > what I am looking for. This seems to do it : mwilson at tecumseth:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import itertools >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> map (lambda (x,y):x+y, list (itertools.product (li1, li2))) ['a1', 'a2', 'b1', 'b2'] Mel. From mwilson at the-wire.com Wed Aug 17 17:18:40 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Aug 2011 17:18:40 -0400 Subject: pairwise combination of two lists References: Message-ID: Mel wrote: > Yingjie Lin wrote: >> I have two lists: >> >> li1 = ['a', 'b'] >> li2 = ['1', '2'] >> >> and I wish to obtain a list like this >> >> li3 = ['a1', 'a2', 'b1', 'b2'] [ ... ] > This seems to do it : > > mwilson at tecumseth:~$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import itertools >>>> li1 = ['a', 'b'] >>>> li2 = ['1', '2'] >>>> map (lambda (x,y):x+y, list (itertools.product (li1, li2))) > ['a1', 'a2', 'b1', 'b2'] I have doubts about this in Python3, since tuple unpacking in a argument list isn't done there, and I don't think sum works on strings. Some other function can probably be made to work. Mel. From nad at acm.org Wed Aug 17 17:33:17 2011 From: nad at acm.org (Ned Deily) Date: Wed, 17 Aug 2011 14:33:17 -0700 Subject: pairwise combination of two lists References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: In article <98CC6556-11F3-4850-BD2B-30481B53042D at mssm.edu>, Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and > li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I > am looking for. >>> from itertools import product >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> li3 = list("".join(x) for x in product(li1, li2)) >>> li3 ['a1', 'a2', 'b1', 'b2'] -- Ned Deily, nad at acm.org From kevin.p.dwyer at gmail.com Wed Aug 17 17:33:34 2011 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Wed, 17 Aug 2011 22:33:34 +0100 Subject: pairwise combination of two lists References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly > what I am looking for. > > Thank you. > > > - Yingjie Hello Yingjie, This isn't exactly handy, but... >>> import itertools >>> a = ('a', 'b') >>> b = (1, 2) >>> [x + str(y) for (x, y) in itertools.product(*(a, b))] ['a1', 'a2', 'b1', 'b2'] Cheers, Kev From usenet at solar-empire.de Wed Aug 17 17:43:44 2011 From: usenet at solar-empire.de (Marc Christiansen) Date: Wed, 17 Aug 2011 23:43:44 +0200 Subject: pairwise combination of two lists References: Message-ID: Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. Depending on your needs, we can offer you three solutions: For our customers who want it all at once, but without any unneccessary waste, the list expression: [a + b for a, b in itertools.product(li1, li2)] or if you don't need the whole list at once (especially interesting for our customers with large lists), the generator expression (genexp): (a + b for a, b in itertools.product(li1, li2)) and if you don't like the throwaway genexp and want something more ecofriedly, we can present you a memory efficient, reusable solution, the generator: def combiner(li1, li2): for a, b in itertools.product(li1, li2): yield a + b ;) HTH, Marc From rosuav at gmail.com Wed Aug 17 18:10:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 23:10:38 +0100 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 7:29 PM, Steven D'Aprano wrote: > The raw_input/input UI is well-designed for entering plain text data. It is > extremely poor as a command interface. > > ... (Imagine how awkward it would be to use a TUI mail client or > text editor where the only user input was from something like raw_input.) I run a MUD and play several. MUDs by definition have only line-based input (if you use a raw TELNET client, you have character-based input, but most MUD clients send entire lines of text at once); yet it is possible to implement a reasonably-viable file editor. It's not difficult to become quite proficient with line-based editors, especially if you rig some client-side support (which I have done on two of the MUDs). Line-based input is excellent as a command interface, if commands consist of verbs and parameters. It's terrible for playing Tetris on. ChrisA From saruviel at hotmail.com Wed Aug 17 18:17:50 2011 From: saruviel at hotmail.com (saruviel) Date: Wed, 17 Aug 2011 15:17:50 -0700 (PDT) Subject: The Amazing Lucy Potter Message-ID: <306b0589-d2ab-4be4-8eda-9b66fd4827c9@y8g2000prd.googlegroups.com> Joanne Kathleen Rowling (aka J K Rowling) Fanfiction Website http://jkrowlingfanfiction.angelfire.com (See Also http://noahidebooks.angelfire.com for the ?Chronicles of the Children of Destiny?) Featuring the ?Lucy Potter? saga (& In time the rest of the ?Circle of Magic Series? ? see below) Lucy Potter conceived of and created by Daniel Thomas Andrew Daly NOTE: My niece, Georgia Bridges, who features in the Books as a character, actually does have a little scar on her forehead, running down the middle of it. When she was very young she banged her head on the washing machine here at 29 Merriman Crescent, and a little scar remains of the incident (it was actually glued together by the doctor, which is something they do these days). Anyway, I started, as a joke, calling her ?Lucy Potter? one day because of the little ?l? shaped scar ? the l stands for ?Lucy? in that sense. So, one day, in my room or somewhere in the house, inspiration comes over me and I figure I should write about Lucy Potter. So, sitting down at my computer, I start the story, and it has continued since then. I gradually found out about Harry Potter fanfiction, and the story features on both www.fanfiction.net as well as www.hpfanficarchive.com . But the full series of 7 books in the saga are intended to be featured solely on this website. Now, in my other saga about angels known as the ?Chronicles of the Children of Destiny? (http:// noahidebooks.angelfire.com) Lucy Potter has had all relevant Harry Potter trademarked names changed (so that I can hopefully publish the book) and is called ?Lucy Smith? in that saga, and ties right into the plot of the saga. The story ?Lucy Smith? is exactly the same story as the first two Lucy Potter books, with names changed. Lucy Potter ? Book One (Click Me) Lucy Potter and the Vengeance of Lucifer Book Two (Click Me) Lucy Potter and the Golden Sovereigns Book Three (Click Me) Lucy Potter and the Sprite of Chakola Book Four (Click Me) Lucy Potter and the Terran Dragonrider Book Five (Plot ? Chapter Breakdown) (Click Me) Lucy Potter and the Children of Haven (Basic Plot Idea) (Click Me) Lucy Potter and the Dark Lords of Evil (Basic Plot Idea) (Click Me) The Circle of Magic Series (Saga forthcoming over the next few decades) By Daniel Thomas Andrew Daly Harry Potter Harry Potter and Ron Weasely Harry Potter and Hermione Granger Harry Potter and Luna Lovegood Harry Potter and Albus Dumbledore Harry Potter and Severus Snape Harry Potter and Lord Voldemort Lucy Potter (Completed) Lucy Potter and the Vengeance of Lucifer (Completed) Lucy Potter and the Golden Sovereigns (Completed) Lucy Potter and the Sprite of Chakola (Completed) Lucy Potter and the Terran Dragonrider Lucy Potter and the Children of Haven Lucy Potter and the Dark Lords of Evil Luna Lovegood Luna Lovegood and the Splendid Unicorn Luna Lovegood and the Mirror of Forgetfulness Luna Lovegood and the Spell of the Ancients Luna Lovegood and the Curse of the Witch Queen Luna Lovegood and the Scroll of Daranok Luna Lovegood and the Key of Fantasy Jenny Potter Jenny Potter and the Dark Designs of Alexander Darvanius Jenny Potter and Lucifer Malfoy?s Wicked Sense of Humour Jenny Potter and the Most Malevolent Grimlock Jenny Potter and the Challenges of David Rothchild Jenny Potter and the Witticisms of Daniel Daly Jenny Potter and the Wisdom of Shelandragh May Draco Malfoy Draco Malfoy and the Family from Hell Draco Malfoy and his Bad Reputation Draco Malfoy and the Wicked Harlot Draco Malfoy and the Gypsy of Bad Luck Draco Malfoy and the Throne of Evil Draco Malfoy and the Final Redemption SUBMISSIONS I am very happy to take submissions from Other Harry Potter Fanfiction Writers and Place there writings on this website if they like. I am not necessarily seeking any other Harry Potter fanfiction per se, but Will be happy to include writers who would like their Work featured here. You can email me to discuss this at: noahidebooks at hotmail.com PS If you would like to write some ?Lucy Potter? fanfiction based On my own ?Lucy Potter? character, I would love to feature it. The 7 Harry Potter books by J K Rowling are meant to be ?Canon? For the Circle of Magic series also, but the series develops its own canon. In the ?Chronicles of the Children of Destiny? there is an alternative Storyline in which Lucy Potter is known as ?Lucy Smith?. That storyline has an extensive amount of material written in It about angels, featured at: http://noahidebooks.angelfire.com The Circle of Magic Series should be finished within 30 years at the Most (Hopefully) and possibly sooner. From sigmundv at gmail.com Wed Aug 17 18:48:55 2011 From: sigmundv at gmail.com (SigmundV) Date: Wed, 17 Aug 2011 15:48:55 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <57d73724-6120-4ff3-8b34-ba67e2b9de04@q3g2000yqi.googlegroups.com> Bloody hell! This is the most persistent troll I've seen to date. He expected to get a raging army of pythoners after him, but people are just laughing at him. This is a mailing list, not a novel, so colloquialisms are welcome. The language on a mailing list should be informal and not necessarily grammatically correct. Sigmund From luismgz at gmail.com Wed Aug 17 19:27:43 2011 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 17 Aug 2011 16:27:43 -0700 (PDT) Subject: pairwise combination of two lists References: Message-ID: <9ad7849a-021c-48c3-852a-1bbb41ee3179@x11g2000yqx.googlegroups.com> This is the easiest and most pythonic way (IMHO): >>>> l3 = [i+e for i in li1 for e in li2] >>>> l3 ['a1', 'a2', 'b1', 'b2'] Regards, Luis From thaddeushelg at gmail.com Wed Aug 17 19:32:51 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:32:51 -0700 (PDT) Subject: lesbian rape comics | preteen sex blog | russian lolita sex Message-ID: <0ad3549f-cd0a-4c6a-9112-1ce55896c4f4@a7g2000yqb.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Japanese_Widow_Rape.mpeg http://www.dizzyporn.com/2011-Aug/Underage_Uncensored_Xxx.avi http://www.dizzyporn.com/2011-Aug/Black_Patent_High_Heel_Insertion.wmv http://www.dizzyporn.com/2011-Aug/Underage_Lolitas_Fucking.mpeg http://www.dizzyporn.com/2011-Aug/Incest_Creampie_Cum_In_Her_Pussy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Sarah_Shine_Young_And_Anal_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Italian_Gangster_Rape.avi http://www.dizzyporn.com/2011-Aug/Bad_Tushy_Spanking.wmv http://www.dizzyporn.com/2011-Aug/Incest_Porno_Italian_XviD.AC3.avi http://www.erohide.com/Aug_2011/Virgin_Taiwan_Girl.avi http://www.dizzyporn.com/2011-Aug/Lesbian_Sedeuces_Young_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_Ripe_Melons_4_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Home_Video_Young_Teen_Sex_XviD.AC3.avi http://www.erohide.com/Aug_2011/Rachel_Roxx_Rape.mpeg http://www.erohide.com/Aug_2011/Young_Lolita_Bondage_EDTV_640x480.avi http://www.dizzyporn.com/2011-Aug/Girls_Rape_Other_Girl.mpeg bloody nipple discharge nuva ring free squirt fan club code underage drinking in the marine corps lolitas underground, lolitas all american rejects - dirty little secrets lick your own nipples lesbians licking each other out incest stories and pics anal mature squirt free dirty talking sluts dirty thoughts anime russian young jocks chinese schoolgirl rape dirty used panties 4 sale dirty d uss detroit drawings comics toons adult bondage spanking teenage daughters true underage sex stories girls bound in bathing suits bondage drambook little virgins 10 12 preteen web links incest x comics freaky sex bondage and machines bag bondage leather incest stories post ebony preteen top upskirt girls in hardcore bondage teen cunt lick wendy whoppers bondage cum dripping double penetrations underage naked lolita underage rape pictures preteen lolitas sex gang bloods symbols wet vaginal orgasm hair pussy licking man licks cunt to orgasm free mpeg blood clots legs symptoms incest mike and joan sweet sexy petite girls teen boys ass licking naked petite goddess forced to perform oral sex xxx extreme penetration forced mom sex free incest porn stories, free incest story fat lesbian bondage sexy moms and daughters dirty dancing havannah nights mp3 young hot sex hairy vaginas closeup mother son incest stories female adolescent incest fantasies beautiful young teen dirty things found in disney movies free personal male beastiality links japanese schoolgirl thumbs free little lolitas nude monster oral penetration asian japanese schoolgirl sex porn petite women monster cocks hot young asian girls young orgasm videos harry the dirty dog activities how to become underage porn star dont cha dirty bondage how to tie free underage porno dad fucks daughter while mom masturbates underage teen fuck From thaddeushelg at gmail.com Wed Aug 17 19:38:46 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:38:46 -0700 (PDT) Subject: porn young girls | young teen porno | all rape housewives Message-ID: http://www.dizzyporn.com/2011-Aug/Pee_Hole_Insertion.wmv http://www.dizzyporn.com/2011-Aug/Russian_Brother_Rape_Her_Own_Sister.avi http://www.dizzyporn.com/2011-Aug/Hentai_Schoolgirls_Forced_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Mother_Forced_Son_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Incest_Mom_Fuck_Her_Son_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_Amateur_Brunet_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Young_Teen_Masturbate_XviD.AC3.avi http://www.erohide.com/Aug_2011/Tracyd_In_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Brandy_Taylor_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Sarah_Young_Creampie_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Teen_Agi_Puncikova_Defloration_XviD.AC3.avi http://www.erohide.com/Aug_2011/Virgin_Taiwan_Girl.avi http://www.erohide.com/Aug_2011/Lolitas_Fingering_Pussy_800x600.wmv http://www.dizzyporn.com/2011-Aug/Double_Penetration_Big_Dick_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Fivesome_Double_Penetration_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Saline_Breast_Torture_Blu-RayRip.x264.avi amateur housewife bondage 3d incest cartoons free adult bondage stories redhead butthole licking old women licking tits naked dirty pics lolita art top sites 50 women bondage spanking fantasy nude underage galleries toddler incest stories fuck anal pussy virgin slut teen cum russian young sex porn passwords creampie lolita girls licking pussy clips illegal naked preteen pics young girl butt preteen models nudes japanese rope bondage tutorial horny young girls on web cam sarah young mpeg free incest videos father daughter young russian female pussy licking teens in hte shower virgin teen spankings ebony preteen xxx penetration & penis & vagina young women in shower girls masturbating until they squirt dirty mom son incest dirty girls having sex videos incest cum face visa young hot models dad and young daughter sex incest sisters and brothers schoolgirl fucks teacher daddies preteen girl illegal lolita underage hentai bondage story sites bondage in plastic raincoats missouri uniform law enforcement system newsletter hardcore illegal preteen pierced tongue lick dirty whore cum nude russian preteen lolita dual penetration during sex underage illegal little boy pics mans head in vagina wild teen virgins in car bondage tight pants young girls male ball torture hardcore bondage videos nc laws, what is incest deep penetration girl young horny lesbians free buddy icon of blood hound gang schoolgirl lesbian pussy slaves in bondage underage naked little boys, little underage boys naughty bondage hentai bondage in mississippi dirty cunt giving handjobs to old men adult female contortionist/self lick young teen gangbang betty page bondage photo lingerie daughter is fingering her pussy petite low rise scrub pants young girls photography young white female closeup good dirty insults From thaddeushelg at gmail.com Wed Aug 17 19:39:01 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:01 -0700 (PDT) Subject: naked virgin pussy | hot teen virgin | mature young xxx Message-ID: http://www.dizzyporn.com/2011-Aug/Indian_Rape_Sexs.mpeg http://www.erohide.com/Aug_2011/Hotel_Sleep_Rape.avi http://www.dizzyporn.com/2011-Aug/Indian_Real_Virgin_Hymen_Broken.avi http://www.erohide.com/Aug_2011/Virgin_Blood_Defloration.wmv http://www.erohide.com/Aug_2011/Young_Cheyenne_Silver_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Housewife_And_Young_Boy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Young_Pettite_Anal_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Pussy_Extreme_Insertion_PrivateRecords_07.avi http://www.dizzyporn.com/2011-Aug/Mature_Young_Lesbian_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Nutella_Virgin_Off.wmv http://www.dizzyporn.com/2011-Aug/My_Wife_An_Young_XviD.AC3.avi http://www.erohide.com/Aug_2011/Japan_Massage_Fuck_Forced_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Young_Boy_Magazine_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Old_Guy_Young_Gil_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_And_Busty_Lea_In_Public_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Celebrities_Incest_Sex_Scene_XviD.AC3.avi young fat girls ass dirty office girls incest with mom young asian cunt young latin girl mature petite blondes software penetration testing software dad daughter hardcore girl on girl anal penetration bondage gothic girls lolita lesbian incest lick the head photos of preteens wearing thongs lesbian lick fest lds young women activities can a virgin get pregnant young upskirt pussy thumbnails airforce military schools petite breasted women family sex incest.com father daughter incest fat matures fucking young guys bdsm torture stories outdoor ball gagged bondage big penis penetration mommy spanking son forum preteen model underage asian teen sex fat preteen girls bart simpson incest hairless schoolgirl pussy dirty porno movies queensland underage smoking laws dui underage drinking adult cam lolita chats free underage school girls petite blonde dildo young boy licking mature young teen pool party triple penetration debutante sluts 4 free pics young girls underage hand jobs methods of anal stimulation dad with daughter porn hilary duff gagged bondage preteen girls in bikinis incest daughter stories young boys in bondage young panty pee underage nude guys free young underage sex pictures amanda part 2 and incest cartoons illegal underage prelolitas preteen erotic art multi girl lick free dirty aly clips russian underage msn group bondage lesbian fist japanese virgin pissing extreme penetration slut japanese teen schoolgirls nude video of stacy keibler schoolgirl japan mother son incest do heterosexual men like anal penetration russian preteen lolita underpants insane dildo insertions petite brunette 001 tad lick pussy hardcore bondage free downloads lolita erotica stories cartoon preteen nude incest;; From thaddeushelg at gmail.com Wed Aug 17 19:39:11 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:11 -0700 (PDT) Subject: prison anal rape | virgin anal fucking | little lolitas sex Message-ID: http://www.erohide.com/Aug_2011/Old_And_Young_Creampie_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Margo_Sullivan_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Femdom_Handjob_Torture_Orgasm.wmv http://www.erohide.com/Aug_2011/Naked_Underage_Lolita.avi http://www.dizzyporn.com/2011-Aug/Bondage_Forced_Trailer.wmv http://www.dizzyporn.com/2011-Aug/Simulated_Rape_Porn.avi http://www.dizzyporn.com/2011-Aug/Young_Drunk_Club_Lesbians_XviD.AC3.avi http://www.erohide.com/Aug_2011/Hotel_Asian_Sleep_Rape.mpeg http://www.erohide.com/Aug_2011/Girl_Forced_To_Fuck_A_Dog_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Scarlett_Pain_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Very_Young_Creampie_XviD.AC3.avi http://www.erohide.com/Aug_2011/Erotic_Torture_Chamber_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Indian_Shy_Girl_Forced_DUAL.BDRip.XviD.AC.avi http://www.erohide.com/Aug_2011/Incest_Porno_Italian_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Guy_Rape_Guy.mpeg http://www.erohide.com/Aug_2011/Dominatrix_And_Rape.avi nude lolitas world underage hardcore porn pics mommy loves pussy porn triple penetration sadistic torture bdsm no pop up pics free, virgin ass porn japanese schoolgirl cunts bob dylan forever young young schoolgirl whores free petite softcore porn love hina schoolgirl preteen tiny tits ir creampie virgin mom son incest incest mom young nude preteen tiny bbs lolitas with tiny tits rape pictures blowjobs ball torture movies free lolita bondage pics daughter vaginal penetration pics i squirt alot pre lolita underage teen thumb lick her orgasm movie top kds lolita underground japan schoolgirl nude dirty wet stained panties chinese bondage fetish lolita video,lolita movie,lolita pic free mom son incest art tranny triple penetrations young women in thongs preteen girl cheerleader shaved pussy petite firm tits incest sex brother sister lick sexy teacher party gang rape hot and dirty need slave bangalore lick dirty dancing havana nights soundtrack lyrics ass to lick schoolgirls asian lingerie exploited young teens virgin asian fuck russian underage lolitas young fuck asian erotic force fantasy petite wives teens get fucked upskirt pussy squirt free young nude girls free pussy squirt pics underage girls giving blowjobs clips small lolita sex forced blowjob girls 'free pictures of preteen girls' soundtrack from dirty dancing communities accepting incest date rape video pictures of young models cassie young blowjobs little underage girls fuck big dick porn stories karen incest beastiality lolita sex chat asian forced sex bloodhound gang fox-trot uniform charlie kilo video voyeur upskirts spycams free rape movies free galleries of incest photos free daughter spanking clips young girl nudes size or penis for penetration From thaddeushelg at gmail.com Wed Aug 17 19:39:23 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:23 -0700 (PDT) Subject: gang rape fantasy | teen virgin blowjob | dads rape girls Message-ID: <33c14ee0-1c4b-4c7e-8887-75f0fec83e85@p19g2000yqa.googlegroups.com> http://www.erohide.com/Aug_2011/Vintage_Classics_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Bondage_Forced_Trailer.wmv http://www.dizzyporn.com/2011-Aug/Young_Brazil_Teen_Model.avi http://www.erohide.com/Aug_2011/Rape_Forced_Orgasm_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Hentai_Toon_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Young_Little_Girl_Slut_XviD.AC3.avi http://www.erohide.com/Aug_2011/Real_Incest_Son_Anal_Fuc_K_Mom_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Mature_Mom_Rape_Young_Boy.mpeg http://www.erohide.com/Aug_2011/Korean_Groped_Sex_Rape_In_Hospital.mpeg http://www.dizzyporn.com/2011-Aug/Sarah_Young_Pee_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Asian_Bus_Molestation_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Russian_And_Young_Boy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Korean_Virgin_Scandal.avi http://www.dizzyporn.com/2011-Aug/Young_Wife_Interracial_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Mom_Forced_To_Blow_Son_DUAL.BDRip.XviD.AC.avi http://www.erohide.com/Aug_2011/Severe_Tit_Torture.wmv lolita underage models hardcore sexual torture tiny titties schoolgirl thumbnail galleries real family incest stories virgin doctors visit pervert spanking 3d incest post bisexual wife sex younger woman tiny teen vagina la petite acadamy paypal bondage join bloodhound gang fire water burn xxx 3d incest cartoon squirting female ejaculating orgasms fat guys in bondage sims 2 gothic lolita downloads guide for incest free incest database young ladies pussy tight petite hot naked young male stars hot young big butt women ass lick mature young asian teen little cuties preteen bbs daddy put your tongue in my pussy dirty sock videos young innocent beauty schoolgirl gallery archives men rape men forced sex pantyhose bondage rape free young pussy russia blow job asian schoolgirl facial free video shy lolita gallery bdsm rape stories squirting female orgasms female ejaculation video doing the dirty thing illegal free porn dicipline and bondage videos incest life stories underage pre-teen girls nude lolita 4 free lolita preteen art nude satin and bondage fantasy simpsons incest sex pre teen incest dad underage daughter nude sex amateur sweet petite teen older women in bondage dad fucks daughter trailer clip she licks cock young girl peeing black lolita 15 sonic the hedgehog bondage porn password forums incest dirty talk adult videos nipples in bondage search engines incest small redhead schoolgirl teen sex fucked sucks incest underage drinking statistics 2005 electric tit torture dirty old women petites salopes chaudes how to squirt your cum free incest research photos very young chicks young candid panties free girl orgasim squirts father mother and daughter orgies free downloads extreme hardcore bondage From thaddeushelg at gmail.com Wed Aug 17 19:39:44 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:44 -0700 (PDT) Subject: iraqi torture video | young underage sex | tgp movies squirt Message-ID: <89ed1e37-4acc-4d25-81f9-8826078b951a@1g2000vbu.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Youjizz_Brutal_Rape_Xxx.avi http://www.erohide.com/Aug_2011/Sebastian_Young_Bottoms_XviD.AC3.avi http://www.erohide.com/Aug_2011/Forced_Orgasm_HDRip.XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Milf_And_Young_Boy_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Mom_Fucks_Son_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Severe_Tit_Torture.wmv http://www.erohide.com/Aug_2011/Real_Incest_Clips_Bro_Sis_Bj_XviD.AC3.avi http://www.erohide.com/Aug_2011/Hentai_Toon_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/ass-fucking-underage.mp4 http://www.erohide.com/Aug_2011/Sinnamon_Love_Forced_Orgasm_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/The_Spanking_Machine.wmv http://www.erohide.com/Aug_2011/Asian_Teen_Anal_Rape.avi http://www.erohide.com/Aug_2011/Caning_Spanking_German.wmv http://www.erohide.com/Aug_2011/Young_Virgin_Xvideo.avi http://www.dizzyporn.com/2011-Aug/Illegal_Young_Fuck_XviD.AC3.avi http://www.erohide.com/Aug_2011/Shemales_Fuck_Virgin_Girls_Only.wmv young sister nude dirty sexy maids little boys youngest naked pictures incest forum link incest movie trailers daughter fucking dad 3d ebony petite sex daddy daughter incest story toys in ass penetration preteen actress galleries virgin teen defloration free clips bloody sex fetish pussy licking blonde lesbians fuck preteen girls cunt licking movies sexy underage teen schoolgirls preteen sex free teen rape video free creampie licking lesbians lick clits sons and mothers incest stories buying incest videos preteen hidden bed room cams kinesiology toe lick petite blonde babe 001 petite latina masterbating pics and vids gang bang young mature triple penetration taylor rain sea squirt structures young sex models leather jacket short petite hentai schoolgirl galleries young naked footjobs hentai school girls lick pussy mature lesbians and young girls dad daughter xxx dirty british housewives female anal stimulation cum in daughter's panties lick big clit harry the dirty dog double penetration huge tits dirty honey sucking big cock licking petite pussy lolita russian porn free nude pics of fat underage raunchy girls pussy licking gallery pre-teen incest stories free amature porn videos samples petite angles free ebony penetration pics galleries lolita preteen art incest cartoons pre teen dirty jokes in shakespear sites that support incest porn state v. william collins incest double penetration sex clip family sex hardcore incest video soul survivor young jazzy young amateur sandy preteens gone wild teen squirting machines anal lick fest dog licking dick licking cheerleader pussy schoolgirls and oral sex homosex daddy dvd incest taboo samples incest sex fucking forced anal virgin underage nude lolitas From thaddeushelg at gmail.com Wed Aug 17 19:40:00 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:40:00 -0700 (PDT) Subject: young girl raped | free incest porno | incest art xxx Message-ID: <12a2ce83-d451-490d-9588-9553e6ea5b03@t5g2000yqj.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Young_And_Busty_Lea_In_Public_XviD.AC3.avi http://www.erohide.com/Aug_2011/Father_Daughter_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Rape_Of_A_Young_Girl.mpeg http://www.erohide.com/Aug_2011/Britney_Skye_And_Virgin.wmv http://www.erohide.com/Aug_2011/Japanese_Groped_Sex_Rape_In_Hospital.mpeg http://www.dizzyporn.com/2011-Aug/Hot_lolita_stripping.mpeg http://www.erohide.com/Aug_2011/Margo_Sullivan_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Cute_Blonde_Young_Hardcore_XviD.AC3.avi http://www.erohide.com/Aug_2011/Bath_Hardcore_Bondage_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Virgin_Amateur_First.wmv http://www.erohide.com/Aug_2011/Sky_Lopez_Double_Penetration_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Double_Anal_Penetration_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Dad_Forced_Sex_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Brother_Sister_Homemade_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Yong_Lolita_Sex.avi http://www.dizzyporn.com/2011-Aug/Brandy_Taylor_Bondage_Blu-RayRip.x264.avi young boys tgp forced cum control free lesbians licking pussy tiny young twinks young, sexy, petite amateur little lolita rape mature woman young preteen girl handjob virgin fuck videos dirty preteen porn pics of preteen swimsuit models free petite nudes double penetration teen gang bang 'naked lolitas preteen' moaning tiny teen virgins lick up your cum young shaved cocks dirty porn email flinstones professional bondage photography cum vagina movies petite amie nue petite asians fuck make a dirty martini daughter sucks dads cock tied breasts breast bondage bag bondage escape illegal group sex female bondage sex squirt from behind dad fucking daughterspussy penetration of a virgin preteen feet gallery daughter dad touch sex stories petite bathroom vanity cabinet preteen virtual reality russian defloration video feet torture techniques daughter sucking dad's cock torture techniques stories dirty batman yaoi blood gang symbols sick skinny african boy sex stories incest my little lolita pics tiny pussy virgins bbs preteens in tight panties underage pussies oral sex little lolita videos little russian lolita videos young ebony hoes getting fucked preteen russian modeling angels free site dirty aly sex plus size schoolgirl outfits little girl incest pic male bondage female domination teacher and young student sex cum out of vagina dirty girl cop action free xxx dirty porn gothic lolita dress ebony natasha bondage goth pussy licking french lick girls little sister brother incest free4 incest thumbs underage ukraine lolita nude young blondes bondage stories restrained mature daddy hairy sock lick movies From steve+comp.lang.python at pearwood.info Wed Aug 17 20:36:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 10:36:40 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4c5e99$0$29998$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-17, Steven D'Aprano > wrote: >> Fortunately, while we are proud of having that ability, actually *using* >> it is considered a mortal sin. We're not Ruby developers -- if you >> actually monkey-patch something, especially built-ins, you can expect to >> be taken outside and slapped around with a fish if you get caught. > > Okay, so. > > Here's what I don't get. > > If it's such a bad thing, *why is it allowed*? Why are you proud of the > ability to do something that you are never socially-allowed to do? Why does any language allow monkey-patching? Because: (1) it is a consequence of a clean language design that doesn't special case things unless absolutely necessary -- monkey-patching wasn't added to the language, it just emerged given the basic language design; (2) consequently it isn't some special technique, it is just a special name given to ordinary, humdrum, everyday things like name-binding within a namespace; (3) and yet it is a powerful and useful ability that lets you extend both the language and libraries (yours or third party) while still writing very clean code; (4) it's also pretty cool that you can do these things; and most importantly (5) all of the above. Even if we shouldn't (ab)use it in production, it is still greatly useful for quick and dirty scripts, testing, experimentation and debugging. And sometimes monkey-patches end up in production. For example, the standard library site.py file adds help() and quit() commands to builtins at startup. Or you might grab an instance of some third-party class, and dynamically adding a method or an attribute to it. Why bother sub-classing it? There's a scene in James Clavell's "Shogun" which is relevant. Toranaga, the Japanese warlord, discovers that the Englishman John Blackthorne has betrayed his rightful ruler. Blackthorne protests that there are mitigating circumstances. Toranaga says that there can never be any mitigating circumstances for disloyalty to one's liege-lord. Blackthorne replies that there is one: if you win. The same applies for monkey-patching and other dangerous techniques. There can be no excuse for doing something like that in production... unless it is better than the alternatives. [...] > It sounds to me like Python is very proud of having a feature which no > one would ever use. ... Why? Don't get me wrong, there are plenty of people who would give up Python's extreme dynamicism is a heartbeat, if it were up to them. It does play havoc with the ability to optimise Python code, and is one of the reasons why CPython isn't as fast as (say) Lua. But the PyPy people are well on the way to blunting that criticism, with a fast, effective JIT optimising compiler that will be fast in the common case and no worse off in the rare times that built-in functions have been shadowed or modified. (PyPy is already about twice as fast as CPython, and in a few carefully crafted examples faster than C code.) -- Steven From gherron at islandtraining.com Wed Aug 17 21:26:18 2011 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 17 Aug 2011 18:26:18 -0700 Subject: pairwise combination of two lists In-Reply-To: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: <4E4C6A3A.9000302@islandtraining.com> On 08/17/2011 01:22 PM, Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I am looking for. > > Thank you. > > > - Yingjie >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> print [a+b for a in li1 for b in li2] ['a1', 'a2', 'b1', 'b2'] Gary Herron From moravec at stolaf.edu Wed Aug 17 23:08:23 2011 From: moravec at stolaf.edu (Emily Anne Moravec) Date: Wed, 17 Aug 2011 20:08:23 -0700 (PDT) Subject: lists and for loops Message-ID: I want to add 5 to each element of a list by using a for loop. Why doesn't this work? numbers = [1, 2, 3, 4, 5] for n in numbers: n = n + 5 print numbers From wuwei23 at gmail.com Wed Aug 17 23:08:39 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:08:39 -0700 (PDT) Subject: Failed to create virtual environment when using --relocatable option, what's wrong? References: Message-ID: On Aug 17, 12:23?am, smith jack wrote: > The environment doesn't have a file f:\PythonEnv\djangoEnv2\Scripts\activate_thi > s.py -- please re-run virtualenv on this environment to update it Although the docs aren't very clear, --relocatable should be run on _existing_ virtualenvs. Don't think of it as an option for creating an environment, but rather one for preparing an existing environment for moving. More importantly, it _must_ be re-run in order to remain relocatable after any modules are installed. But most important of all, from the documentation: "Also this does not currently work on Windows." From wuwei23 at gmail.com Wed Aug 17 23:14:20 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:14:20 -0700 (PDT) Subject: How to use python environment created using virtualenv? References: Message-ID: <18642775-5c79-407f-8d42-4e74fd29801f@t30g2000prm.googlegroups.com> On Aug 16, 3:15?pm, smith jack wrote: > I have created a python environment using virtualenv, but when i want > to import such environment to PyDev, error just appears, > it tells there should be a Libs dir, but there is no Libs DIr in the > virtual envronment created using virtualenv, what should i do if > i want to use this virtual environment? It would help if you showed us _exactly_ what commands you're using for creating & activing your virtualenv, as well as how you're trying to use it in PyDev. Basically, you should be able to do this: X:\>virtualenv foo New python executable in foo\Scripts\python.exe Installing setuptools................done. Installing pip...................done. X:\>cd foo X:\foo>Scripts\activate.bat (foo) X:\foo> If this doesn't work for you, please paste exactly what you tried and the results you got. From wuwei23 at gmail.com Wed Aug 17 23:23:17 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:23:17 -0700 (PDT) Subject: lists and for loops References: Message-ID: On Aug 18, 1:08?pm, Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > ? ? ?n = n + 5 > print numbers As the for loop steps through numbers, it assigns each integer value to the label n. What n holds is a number, _not_ a reference to the number in the list. So when you reassign n to hold n+5, you're pointing n at a new number, not modifying the original number being referred to. So what you need is a reference to the position of the number in the list, so you can reassign the value that's held there. The common pattern is to use enumerate, which lets you step through a list giving you both an reference (index) & a value: numbers = [1, 2, 3, 4, 5] for i, n in enumerate(numbers): numbers[i] = n + 5 Here you're reassigning each list element to hold its old value plus 5. Hope this helps. From jacktradespublic at gmail.com Wed Aug 17 23:33:53 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Wed, 17 Aug 2011 22:33:53 -0500 Subject: lists and for loops In-Reply-To: References: Message-ID: > > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers > > The n variable in the for loop refers to each value in the list, not the reference to the slot that value is stored in. To update the numbers list you would want something like this: numbers = [1, 2, 3, 4, 5] for n in range(len(numbers)): numbers[n] += 5 print numbers Alternatively if you didn't need to update the numbers list you could make a new list like this: [n+5 for n in numbers] -- Jack Trades Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Wed Aug 17 23:52:10 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 20:52:10 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: <220b4dbe-cce9-4742-9b1f-441ddf9c05df@a13g2000yqd.googlegroups.com> On Aug 17, 3:25?am, Chris Angelico wrote: > You do NOT > want end users having the power to set variables. Thanks for the warning, I can see I will need to quarantine the form input. And update() is out of the question. -- Gnarlie http://Gnarlodious.com/ From chris at simplistix.co.uk Thu Aug 18 02:37:14 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 17 Aug 2011 23:37:14 -0700 Subject: MailingLogger 3.4.0 Released! Message-ID: <4E4CB31A.5090803@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with a configurable headers for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested This release has no functional changes but finally ships with a full new set of Sphinx docs: http://packages.python.org/mailinglogger/ For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From no.email at nospam.invalid Thu Aug 18 03:18:49 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Aug 2011 00:18:49 -0700 Subject: pairwise combination of two lists References: Message-ID: <7x1uwjdw6e.fsf@ruckus.brouhaha.com> Yingjie Lin writes: > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > li3 = ['a1', 'a2', 'b1', 'b2'] from itertools import * li3 = list(chain.from_iterable(izip(li1,li2))) From alain at dpt-info.u-strasbg.fr Thu Aug 18 03:30:43 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 09:30:43 +0200 Subject: pairwise combination of two lists References: Message-ID: <87r54j5g7w.fsf@dpt-info.u-strasbg.fr> Yingjie Lin writes: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. It's not difficult to write your own: def product(l1,l2): for x1 in l1: for x2 in l2: yield x1+x2 use it like: for p in product(l1,l2) ... The call to product() produces a generator, the cross product is never built in full, it should work on long lists. -- Alain. From peter.mosley at talk21.com Thu Aug 18 04:24:30 2011 From: peter.mosley at talk21.com (peter) Date: Thu, 18 Aug 2011 01:24:30 -0700 (PDT) Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4b383bcd-c58c-4e67-895a-d70fdf82f9c0@n35g2000yqf.googlegroups.com> On Aug 17, 3:16?pm, Hans Mulder wrote: > On 17/08/11 10:03:00, peter wrote: > > > Is there an equivalent to msvcrt for Linux users? ?I haven't found > > one, and have resorted to some very clumsy code which turns off > > keyboard excho then reads stdin. Seems such an obvious thing to want > > to do I am surprised there is not a standard library module for it. Or > > have I missed someting (wouldn't be the first time!) > > The quick and dirty way is to invoke stty(1) using os.system: > > import os > > def getpassword(prompt="Password: "): > ? ? ?try: > ? ? ? ? ?os.system("stty -echo") > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?os.system("stty echo") > ? ? ?return passwd > > Strictly speaking, os.system is deprecated and you should use > the equivalent invocation of subprocess.call: > > import subprocess > > def getpassword(prompt="Password: "): > ? ? ?try: > ? ? ? ? ?subprocess.call(["stty", "-echo"]) > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?subprocess.call(["stty", "echo"]) > ? ? ?return passwd > > If you don't want to use an external process, use termios: > > import termios, sys > > def getpassword(prompt="Password: "): > ? ? ?fd = sys.stdin.fileno() > ? ? ?old = termios.tcgetattr(fd) > ? ? ?new = termios.tcgetattr(fd) > ? ? ?new[3] = new[3] & ~termios.ECHO ? ? ? ? ?# lflags > ? ? ?try: > ? ? ? ? ?termios.tcsetattr(fd, termios.TCSADRAIN, new) > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?termios.tcsetattr(fd, termios.TCSADRAIN, old) > ? ? ?return passwd > > These functions work on any Posix system (including Mac OSX), > but not on Windows. > > Hope this helps, > > -- HansM This is very similar to my solution, which was to use stty turn off keyboard echo, then repeatedly read sys.stdin.read(1) until a unique keystroke had been defined. For example, the 'Insert' key seems to return a sequence of four codes, namely 27, 91, 50, 126. It works but has two disadvantages which I have managed to live with:- 1. As character 27 is used to signal the start of a 'special' key sequence, it cannot detect a single press of the Esc key. The workaround is to detect a double press instead. 2. Some keys seem to return different sets of codes depending on the circumstances. For example, F1 returns 27,91,91,65 from the command line, and 27,79,80 from a GUI window. I suspect there may be variations between flavours of Linux too. The solution is to detect all possibilities - so far I haven't found any overlaps. Not pretty, but as I said it works. I know now not to spend time looking further. Whilst there may be a historical reason for the current situation, it would be a great convenience for amateur coders like mayself if the gurus could devise a platform independent version of mscvrt. If anyone is interested in the code I can post it, but it's quite long as it comprises multiple if statements to cover each combination. Peter From funthyme at gmail.com Thu Aug 18 05:26:35 2011 From: funthyme at gmail.com (John Pinner) Date: Thu, 18 Aug 2011 02:26:35 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4d9df596-beaa-496c-ad04-0df8278c2599@q1g2000vbj.googlegroups.com> On Aug 3, 2:45?am, gc wrote: > Hi everyone! Longtime lurker, hardly an expert, but I've been using > Python for various projects since 2007 and love it. > > I'm looking for either (A) suggestions on how to do a very common > operation elegantly and Pythonically, or (B) input on whether my > proposal is PEP-able, assuming there's no answer to A. (The proposal > is sort of like the inverse of PEP 3132; I don't think it has been > proposed before, sorry if I missed it.) > > Anyway, I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. > > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() > > where * in this context means something like "assign separately to > all." I'm not sure that * would the best sugar for this, but the > normal meaning of * doesn't seem as if it would ever be valid in this > case, and it somehow feels right (to me, anyway). > > Statements fitting the form above would get expanded during parsing to > a sequence of separate assignments (a = dict(); b = dict(); c = dict() > and so forth.) That's all there is to it. Compared to the patterns > below, it's svelte, less copy-paste-y (so it removes an opportunity > for inconsistency, where I remember to change a-d to defaultdict(list) > but forget with e), and it doesn't require me to keep count of the > number of variables I'm initializing. > > This would update section 6.2 of the language reference and require a > small grammar expansion. > > But: Is there already a good way to do this that I just don't know? > Below, I compare four obvious patterns, three of which are correct but > annoying and one of which is incorrect in a way which used to surprise > me when I was starting out. > > # Option 1 (separate lines) > # Verbose and annoying, particularly when the varnames are long and of > irregular length > > a = dict() > b = dict() > c = dict() > d = dict() > e = dict() > > # Option 2 (one line) > # More concise but still pretty annoying, and hard to read (alternates > variables and assignments) > > a = dict(); b = dict(); c = dict(); d = dict(); e = dict() > > # Option 3 (multiple target list: this seems the most Pythonic, and is > normally what I use) > # Concise, separates variables from assignments, but somewhat > annoying; have to change individually and track numbers on both sides. > > a,b,c,d,e = dict(),dict(),dict(),dict(),dict() > > # Option 4 (iterable multiplication) > # Looks better, and if the dict() should be something else, you only > have to change it once, but the extra brackets are ugly and you still > have to keep count of the targets... > > a,b,c,d,e = [dict()] * 5 > > # and it will bite you... > > >>> a[1] = 1 > >>> b > {1: 1} > >>> id(a) == id(b) > > True > > # Gotcha! > > # Other forms of 4 also have this behavior: > > a,b,c,d,e = ({},) * 5>>> a[1] = 1 > >>> b > > {1: 1} > > Alternatively, is there a version of iterable multiplication that > creates new objects rather than just copying the reference? That would > solve part of the problem, though it would still look clunky and you'd > still have to keep count. > > Any thoughts? Thanks! I hesitate to put this forward, as it smells and is probably considered bad practice, but heh! for char in 'abcdefg' : globals()[ char ] = dict() does what you wanted. Best wishes, John -- From ramapraba2653 at gmail.com Thu Aug 18 07:42:39 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Thu, 18 Aug 2011 04:42:39 -0700 (PDT) Subject: WORLD BEST SEXY PICS Message-ID: v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html KAJAL AGARWAL HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html From eudes.elie at gmail.com Thu Aug 18 08:02:44 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Thu, 18 Aug 2011 05:02:44 -0700 (PDT) Subject: decorator issue with modules dbus & gobject Message-ID: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Hi, Here is a sample code that reproduces the issue : [code] import logging import unittest import signal import gobject import dbus from functools import wraps from dbus.mainloop.glib import DBusGMainLoop class TimeoutException(Exception): pass def timeout(timeout_time=1800): """ decorator function catching the argument """ def timeout_function(func): """ decorator function """ @wraps(func) def _timeout_function(self): """ create a signal handler set the timeout with the argument given while calling the decorator @timeout call the function catch a timeout exception if necessary """ def timeout_handler(signum, frame): print 'Timeout (%s sec) reached' % str(timeout_time) raise TimeoutException() old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(timeout_time) # triger alarm in timeout_time seconds try: retval = func(self) finally: signal.signal(signal.SIGALRM, old_handler) signal.alarm(0) return retval return _timeout_function return timeout_function class Test_loopRun_And_Timeout(unittest.TestCase): def __init__(self,*args,**kwargs): super(Test_loopRun_And_Timeout, self).__init__(*args,**kwargs) dbus_loop = DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus(private=True,mainloop=dbus_loop) self.loop = gobject.MainLoop() logging.basicConfig() self.__logger = logging.getLogger("Tests.%s" % self.__class__.__name__) self.__logger.setLevel(logging.DEBUG) def setUp(self): ''' in this part, mediarouter can not be created Setup are all launch in // So if 50 tests are run in this class, 50 mediarouters are created ''' pass def tearDown(self): ''' ''' @timeout(5) def test_001(self): ''' ''' self.__logger.info('[CHECKPOINT] test_001') try: self.__logger.info('entering a waiting loop') self.loop.run() self.__logger.info('dummy log, should not appear') self.fail() except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') except : self.__logger.exception('Unexpected error') self.fail() @timeout(5) def test_002(self): ''' ''' def loop_quit(loop): loop.quit() return False self.__logger.info('[CHECKPOINT] test_002') try: self.__logger.info('entering a waiting loop') gobject.timeout_add(1000, loop_quit, self.loop) self.loop.run() self.__logger.info('exiting the loop') except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') self.fail() except : self.__logger.exception('Unexpected error') self.fail() [/code] If I start a unittest campaign like this : [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_002')) suite.addTest(Test_loopRun_And_Timeout('test_001')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] the result give me 2 tests OK Now If I launch this [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_001')) suite.addTest(Test_loopRun_And_Timeout('test_002')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] 1 OK (test_001) 1 Fail (test_002 goes on timeout) And if I am using more than 3 Testcases, the code is going to run in infinite loop (Ctrl+C or timeout decorator does not work, only a kill works) Is there an issue using the 'timeout' decorator with the loop.run() ? From prahamark at gmail.com Thu Aug 18 08:22:45 2011 From: prahamark at gmail.com (Mark Niemczyk) Date: Thu, 18 Aug 2011 05:22:45 -0700 (PDT) Subject: lists and for loops In-Reply-To: References: Message-ID: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> Or, using list comprehension. >>> numbers = [1, 2, 3, 4, 5] >>> numbers = [n + 5 for n in numbers] >>> numbers [6, 7, 8, 9, 10] From python.list at tim.thechases.com Thu Aug 18 08:45:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Aug 2011 07:45:10 -0500 Subject: lists and for loops In-Reply-To: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> References: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> Message-ID: <4E4D0956.8090607@tim.thechases.com> On 08/18/2011 07:22 AM, Mark Niemczyk wrote: > Or, using list comprehension. > >>>> numbers = [1, 2, 3, 4, 5] >>>> numbers = [n + 5 for n in numbers] >>>> numbers > [6, 7, 8, 9, 10] Or, if you want it in-place: numbers[:] = [n+5 for n in numbers] which makes a difference if you have another reference to numbers: >>> numbers = [1,2,3,4,5] >>> digits = numbers >>> numbers = [n+5 for n in numbers] >>> numbers, digits ([6, 7, 8, 9, 10], [1, 2, 3, 4, 5]) >>> numbers = [1,2,3,4,5] >>> digits = numbers >>> numbers[:] = [n+5 for n in numbers] >>> numbers, digits ([6, 7, 8, 9, 10], [6, 7, 8, 9, 10]) -tkc From jasons at adventureaquarium.com Thu Aug 18 08:58:42 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 08:58:42 -0400 Subject: List spam Message-ID: I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? Jason ..?><((((?> From roy at panix.com Thu Aug 18 09:13:14 2011 From: roy at panix.com (Roy Smith) Date: Thu, 18 Aug 2011 09:13:14 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: In article <16ea4848-db0c-489a-968c-ca40700f5806 at m5g2000prh.googlegroups.com>, gc wrote: > I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. Keep in mind that when you do: a = dict() b = dict() you are NOT initializing a and b to the same value. You are initializing each of them to a different empty dictionary, which is very different from a = b = dict() I suspect you knew that, but it's worth mentioning. > # Option 1 (separate lines) > # Verbose and annoying, particularly when the varnames are long and of > irregular length > > a = dict() > b = dict() > c = dict() > d = dict() > e = dict() This seems the best to me. Simple, straight-forward, easy to understand. What could be bad? It may not be elegant, but if I could have a nickel for every hour I've wasted trying to understand elegant code, I'd be a rich man. I can understand the above code in an instant, even at 2 AM juiced up on sugar and caffeine. From mail at timgolden.me.uk Thu Aug 18 09:30:37 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Aug 2011 14:30:37 +0100 Subject: List spam In-Reply-To: References: Message-ID: <4E4D13FD.5050103@timgolden.me.uk> On 18/08/2011 13:58, Jason Staudenmayer wrote: > I really like this list as part of my learning tools but the amount > of spam that I've been getting from it is CRAZY. Doesn't anything get > scanned before it sent to the list? I haven't seen any significant quantity of spam on the list for ages. (The occasional one does get through although I can't remember the last). I always access it as a mailing list, and I seem to recall that the newsgroup feed isn't filtered the same way as the mailing list is. TJG From philip at semanchuk.com Thu Aug 18 09:39:05 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Aug 2011 09:39:05 -0400 Subject: List spam In-Reply-To: References: Message-ID: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? This has been discussed on the list a number of times before, so I'll refer you to the archives for details. Basically, the mailing list receives postings from Google Groups and vice versa. Most of the spam comes from Google Groups. If you add a mail filter that deletes anything with the "Organization" header set to "http://groups.google.com", you won't see much spam anymore. In my experience, you'll also miss a number of legitimate postings. HTH Philip From jasons at adventureaquarium.com Thu Aug 18 09:39:35 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 09:39:35 -0400 Subject: List spam In-Reply-To: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: > On 18/08/2011 13:58, Jason Staudenmayer wrote: > > I really like this list as part of my learning tools but the amount > > of spam that I've been getting from it is CRAZY. Doesn't > anything get > > scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. > (The occasional one does get through although I can't > remember the last). > > I always access it as a mailing list, and I seem to recall that > the newsgroup feed isn't filtered the same way as the mailing list is. I've been getting more and more. Upon checking the header info the last hop is from the list server. Here's part of the header: Received: from (HELO mail.python.org) (82.94.164.166) by mail2.adventureaquarium.com with SMTP; 17 Aug 2011 23:53:17 -0000 Received: from albatross.python.org (localhost [127.0.0.1]) by mail.python.org (Postfix) with ESMTP id 3RfS705P3czN9Y for ; Thu, 18 Aug 2011 01:53:16 +0200 (CEST) I can deal with normal spam but this stuff I've gotten is all about rape. Jason Adventure Aquarium is America's Most Touchable Aquarium! Featuring the ALL NEW Stingray Beach Club Where you can touch and hand feed the gentle stingrays To buy and print your tickets at home visit www.AdventureAquarium.com ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?><((((?>..?`?.><((((?> A Herschend Family Entertainment Company From jasons at adventureaquarium.com Thu Aug 18 09:41:52 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 09:41:52 -0400 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > > > I really like this list as part of my learning tools but > the amount of spam that I've been getting from it is CRAZY. > Doesn't anything get scanned before it sent to the list? > > This has been discussed on the list a number of times before, > so I'll refer you to the archives for details. > > Basically, the mailing list receives postings from Google > Groups and vice versa. Most of the spam comes from Google > Groups. If you add a mail filter that deletes anything with > the "Organization" header set to "http://groups.google.com", > you won't see much spam anymore. In my experience, you'll > also miss a number of legitimate postings. > Ahhh, that would explain all the google stuff in the headers. Thanks for the heads-up I'll look at changing my spamassassin scoring for those. Jason Adventure Aquarium is America's Most Touchable Aquarium! Featuring the ALL NEW Stingray Beach Club Where you can touch and hand feed the gentle stingrays To buy and print your tickets at home visit www.AdventureAquarium.com ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?><((((?>..?`?.><((((?> A Herschend Family Entertainment Company From aspineux at gmail.com Thu Aug 18 09:44:38 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 06:44:38 -0700 (PDT) Subject: extend class: include factories functions inside constructor Message-ID: Hi I have a closed class and 2 factories function class Data: def __init__(self): self.payload=None def data_from_string(payload): data=Data() data.payload=payload return data def data_from_file(f): data=Data() data.payload=f.read() return data And I want to extend the class, by first including the factories function inside the constructor, second add some method to the class. class MyData(Data): def __init__(self, arg): # I know this coke is not working, this is to show you # what I expect if isinstance(arg, file): self=data_from_file(arg) else: self=data_from_string(arg) return self def len(self): return len(self.payload) And how I want to use it >>> m=MyData('hello') >>> print m.len() 5 any idea ? Alain From gheskett at wdtv.com Thu Aug 18 09:55:59 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 09:55:59 -0400 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <201108180955.59577.gheskett@wdtv.com> On Thursday, August 18, 2011 09:51:04 AM Philip Semanchuk did opine: > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > > I really like this list as part of my learning tools but the amount of > > spam that I've been getting from it is CRAZY. Doesn't anything get > > scanned before it sent to the list? > > This has been discussed on the list a number of times before, so I'll > refer you to the archives for details. > > Basically, the mailing list receives postings from Google Groups and > vice versa. Most of the spam comes from Google Groups. If you add a > mail filter that deletes anything with the "Organization" header set to > "http://groups.google.com", you won't see much spam anymore. In my > experience, you'll also miss a number of legitimate postings. > > HTH > Philip I am about to do just that, block groups.google.com. AFAIAC, if someone wants to contribute to this mailing list, they can damned well join THIS list if they want their posts to be read by the subscribers to this list. Google is not too big to block as I just told them while fwding that last bit of boilerplate to them at groups-abuse AT google dot com. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Such a fine first dream! But they laughed at me; they said I had made it up. From ghodmode at ghodmode.com Thu Aug 18 10:11:48 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Thu, 18 Aug 2011 22:11:48 +0800 Subject: List spam In-Reply-To: References: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: On Thu, Aug 18, 2011 at 9:30 PM, Tim Golden wrote: > On 18/08/2011 13:58, Jason Staudenmayer wrote: >> >> I really like this list as part of my learning tools but the amount >> of spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. (The > occasional one does get through although I can't remember the last). Maybe your email client is filtering it out for you. ?This list gets A LOT of spam. ?I'm lurking on over 25 different mailing lists and most of them don't seem to get any spam. ?On the others, it's only occasional and the list admins are quick to pounce on it. ?Here, it's like the floodgates are wide open. > I always access it as a mailing list, and I seem to recall that > the newsgroup feed isn't filtered the same way as the mailing list is. The last time I brought up the topic, I offered to do the work of filtering and banning spammers. ?The consensus seemed to be that it wasn't possible because the newsgroup IS filtered the same way as the mailing list. > TJG -- Ghodmode http://www.ghodmode.com/blog From chris at gonnerman.org Thu Aug 18 10:30:54 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Thu, 18 Aug 2011 09:30:54 -0500 Subject: [Python] Re: Windows service in production? In-Reply-To: <4E4BB152.5020904@timgolden.me.uk> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> <4E4BB152.5020904@timgolden.me.uk> Message-ID: <4E4D221E.6000302@gonnerman.org> Chiming in late here, but I've been running a very simple Python service for some time now on a number of computers. It's my Raw Print Server, available at http://newcenturycomputers.net/projects/rawprintserver.html, and I have instructions on the page for installing the Windows service version. It's really quite simple to do in plain Python; the only reason to use py2exe is if you don't want to install a full Python interpreter on the computer. But since I generally do anyway, it doesn't matter to me. -- Chris. From rantingrick at gmail.com Thu Aug 18 10:34:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 18 Aug 2011 07:34:24 -0700 (PDT) Subject: List spam References: Message-ID: <71d3407f-e851-414e-8934-28326d138dfe@o9g2000vbo.googlegroups.com> On Aug 18, 8:39?am, "Jason Staudenmayer" wrote: > > [snip irony] > > Adventure Aquarium is America's Most Touchable Aquarium! > Featuring the ALL NEW Stingray Beach Club > Where you can touch and hand feed the gentle stingrays > > To buy and print your tickets at home visit ?www.AdventureAquarium.com > ? ? ? ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ..?><((((?>..?`?.><((((?> > > A Herschend Family Entertainment Company Don't you find it a bit ironic that you are complaining about spam but yet you are spamming this group with your link to buy tickets to a stingray petting zoo (which is in fact an oxymoron?) under the guise of spam bashing? Tip of the day: Create a website! PS: I do however find the recent "rape" spam atrocious! From ghodmode at ghodmode.com Thu Aug 18 10:37:37 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Thu, 18 Aug 2011 22:37:37 +0800 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk wrote: > > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > >> I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? > > This has been discussed on the list a number of times before, so I'll refer you to the archives for details. > > Basically, the mailing list receives postings from Google Groups and vice versa. Most of the spam comes from Google Groups. If you add a mail filter that deletes anything with the "Organization" header set to "http://groups.google.com", you won't see much spam anymore. In my experience, you'll also miss a number of legitimate postings. You are absolutely right, it has been brought up before. But I'm glad it's been brought up again. It's such a problem that it degrades the usefulness of the list and the community. Most of the mailing lists I'm on are managed using Google Groups and many of them are on mailman, like this list. I don't see spam on them, so I don't know what's going on here. It's not really filtering at all. Most lists only allow members to post and the admins are quick to boot offenders. For the most part, I'm just a lurker, so my suggestion shouldn't carry as much weight, but here it is anyway... Make an effort to curb the spam even if it means killing the newsgroup availability. Choose mailman or Google Groups, or another single solution. Make it members only, but allow anyone to register with an automated confirmation email and a CAPTCHA. Appoint a list admin who has a few minutes each day to scan subjects of emails for spammers and remove them from the members list. ... problem solved. Yes. I'm saying we should abandon those who only follow the list via newsgroups. Yes. I'm willing to do the work, but I'm not the right choice. > HTH > Philip -- Ghodmode http://www.ghodmode.com/blog From __peter__ at web.de Thu Aug 18 10:45:34 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Aug 2011 16:45:34 +0200 Subject: extend class: include factories functions inside constructor References: Message-ID: aspineux wrote: > Hi > I have a closed class and 2 factories function > > class Data: > def __init__(self): > self.payload=None > > def data_from_string(payload): > data=Data() > data.payload=payload > return data > > def data_from_file(f): > data=Data() > data.payload=f.read() > return data > > And I want to extend the class, by first including the factories > function inside the constructor, > second add some method to the class. > > class MyData(Data): > > def __init__(self, arg): > # I know this coke is not working, this is to show you > # what I expect > if isinstance(arg, file): > self=data_from_file(arg) > else: > self=data_from_string(arg) > return self > > def len(self): > return len(self.payload) > > And how I want to use it > >>>> m=MyData('hello') >>>> print m.len() > 5 > > any idea ? Assuming that Data is an oldstyle class you can either copy the Data instance's state class MyData(Data): def __init__(self, arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) self.__dict__.update(obj.__dict__) def __len__(self): return len(self.payload) or use another factory function and manually set the __class__: class MyData(Data): def __len__(self): return len(self.payload) def make_mydata(arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) obj.__class__ = MyData return obj If Data were a newstyle class you could move the hand-made polymorphism into the __new__() method: class MyData(Data): def __new__(class_, arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) obj.__class__ = class_ return obj def __init__(self, arg): pass def __len__(self): return len(self.payload) if __name__ == "__main__": m = MyData("hello") print len(m) Nothing of the above strikes me as pretty. Perhaps we could come up with a neater solution if you tell us more about your use-case... From alain at dpt-info.u-strasbg.fr Thu Aug 18 10:48:58 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 16:48:58 +0200 Subject: List spam References: Message-ID: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> "Jason Staudenmayer" writes: > I really like this list as part of my learning tools but the amount of > spam that I've been getting from it is CRAZY. Doesn't anything get > scanned before it sent to the list? I'm using nntp to read this newsgroup (through an academic server). No spam at all. -- Alain. From jenn.duerr at gmail.com Thu Aug 18 10:57:52 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 07:57:52 -0700 (PDT) Subject: How to convert a list of strings into a list of variables Message-ID: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> How would you convert a list of strings into a list of variables using the same name of the strings? So, ["red", "one", "maple"] into [red, one, maple] Thanks for any help! From alain at dpt-info.u-strasbg.fr Thu Aug 18 10:58:04 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 16:58:04 +0200 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Ghodmode writes: [...] > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. Or save work and find a public nntp server (or setup one, or ask your provider), and use a news reader to follow the list (even thunderbird can do this). No spam, no need to store messages on your machine, auto-purge after a configurable delay, etc. Problem solved. -- Alain. From aspineux at gmail.com Thu Aug 18 10:59:38 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 07:59:38 -0700 (PDT) Subject: extend class: include factories functions inside constructor References: Message-ID: <2b080d2c-62c0-4e69-8675-4da3bca5a6d3@a4g2000yqg.googlegroups.com> On Aug 18, 4:45?pm, Peter Otten <__pete... at web.de> wrote: > aspineux wrote: > > Hi > > I have a closed class and 2 factories function > > > class Data: > > ? def __init__(self): > > ? ? self.payload=None > > > def data_from_string(payload): > > ? data=Data() > > ? data.payload=payload > > ? return data > > > def data_from_file(f): > > ? data=Data() > > ? data.payload=f.read() > > ? return data > > > And I want to extend the class, by first including the factories > > function inside the constructor, > > second add some method to the class. > > > class MyData(Data): > > > ? def __init__(self, arg): > > ? ? # I know this coke is not working, this is to show you > > ? ? # what I expect > > ? ? if isinstance(arg, file): > > ? ? ? ? self=data_from_file(arg) > > ? ? else: > > ? ? ? ? self=data_from_string(arg) > > ? ? return self > > > ? def len(self): > > ? ? return len(self.payload) > > > And how I want to use it > > >>>> m=MyData('hello') > >>>> print m.len() > > 5 > > > any idea ? > > Assuming that Data is an oldstyle class you can either copy the Data > instance's state > > class MyData(Data): > ? ? def __init__(self, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? self.__dict__.update(obj.__dict__) > > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > or use another factory function and manually set the __class__: Exactly what I was looking for The magic is in self.__dict__.update(obj.__dict__) :-) > > class MyData(Data): > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > def make_mydata(arg): > ? ? if hasattr(arg, "read"): > ? ? ? ? factory = data_from_file > ? ? else: > ? ? ? ? factory = data_from_string > ? ? obj = factory(arg) > ? ? obj.__class__ = MyData > ? ? return obj > I don't want to replace 2 factories by one ! > If Data were a newstyle class you could move the hand-made polymorphism into > the __new__() method: > > class MyData(Data): > ? ? def __new__(class_, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? obj.__class__ = class_ > ? ? ? ? return obj > ? ? def __init__(self, arg): > ? ? ? ? pass > ? ? def __len__(self): > ? ? ? ? return len(self.payload) Very nice, I wahad no solution for newer style class. Thanks > > if __name__ == "__main__": > ? ? m = MyData("hello") > ? ? print len(m) > > Nothing of the above strikes me as pretty. Perhaps we could come up with a > neater solution if you tell us more about your use-case... From jasons at adventureaquarium.com Thu Aug 18 11:00:40 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 11:00:40 -0400 Subject: List spam In-Reply-To: <71d3407f-e851-414e-8934-28326d138dfe@o9g2000vbo.googlegroups.com> Message-ID: > On Aug 18, 8:39?am, "Jason Staudenmayer" > wrote: > > > > [snip irony] > > > > Adventure Aquarium is America's Most Touchable Aquarium! > > Featuring the ALL NEW Stingray Beach Club > > Where you can touch and hand feed the gentle stingrays > > > > To buy and print your tickets at home visit ? www.AdventureAquarium.com > ? ? ? ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ..?><((((?>..?`?.><((((?> > > A Herschend Family Entertainment Company >Don't you find it a bit ironic that you are complaining about spam but >yet you are spamming this group with your link to buy tickets to a >stingray petting zoo (which is in fact an oxymoron?) under the guise >of spam bashing? Tip of the day: Create a website! >PS: I do however find the recent "rape" spam atrocious! I do know it is ironic that I forgot to stop the footer for the one reply. It's not my choice to add it but I was able to find a way around that work policy for list emails. I'm a strong opponent of dropping any email with a stupid footer spam. Jason ..?><((((?> From ian.g.kelly at gmail.com Thu Aug 18 11:03:03 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Aug 2011 11:03:03 -0400 Subject: pairwise combination of two lists In-Reply-To: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: On Wed, Aug 17, 2011 at 4:22 PM, Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], ?not exactly what I am looking for. Use the "roundrobin" recipe from the itertools documentation. Cheers, Ian From ms419 at freezone.co.uk Thu Aug 18 11:08:20 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Thu, 18 Aug 2011 08:08:20 -0700 Subject: Measure the amount of memory used? Message-ID: <1313680100.25701.15.camel@selene> I wrote a content filter for Postfix with Python, https://github.com/jablko/cookie It should get started once, and hopefully run for a long time - so I'm interested in how it uses memory: 1) How does the amount of memory used change as it runs? 2) How does the amount of memory used change as I continue to hack on it, and change the code? My naive thought was that I'd periodically append to a file, the virtual memory size from /proc/[pid]/stat and a timestamp. From this a could make a graph of the amount of memory used as my content filter runs, and I could compare two graphs to get a clue whether this amount changed as I continue to hack - but some Googling quickly revealed that measuring memory is actually quite complicated? Neither the virtual memory size nor the "resident set size" accurately measure the amount of memory used by a process Has anyone else measured the memory used by a Python program? How did you do it? From aspineux at gmail.com Thu Aug 18 11:09:43 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 08:09:43 -0700 (PDT) Subject: extend class: include factories functions inside constructor References: Message-ID: <14658331-2278-4601-91a2-1d1a5e180074@q1g2000vbj.googlegroups.com> On Aug 18, 4:45?pm, Peter Otten <__pete... at web.de> wrote: > aspineux wrote: > > Hi > > I have a closed class and 2 factories function > > > class Data: > > ? def __init__(self): > > ? ? self.payload=None > > > def data_from_string(payload): > > ? data=Data() > > ? data.payload=payload > > ? return data > > > def data_from_file(f): > > ? data=Data() > > ? data.payload=f.read() > > ? return data > > > And I want to extend the class, by first including the factories > > function inside the constructor, > > second add some method to the class. > > > class MyData(Data): > > > ? def __init__(self, arg): > > ? ? # I know this coke is not working, this is to show you > > ? ? # what I expect > > ? ? if isinstance(arg, file): > > ? ? ? ? self=data_from_file(arg) > > ? ? else: > > ? ? ? ? self=data_from_string(arg) > > ? ? return self > > > ? def len(self): > > ? ? return len(self.payload) > > > And how I want to use it > > >>>> m=MyData('hello') > >>>> print m.len() > > 5 > > > any idea ? > > Assuming that Data is an oldstyle class you can either copy the Data > instance's state > > class MyData(Data): > ? ? def __init__(self, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? self.__dict__.update(obj.__dict__) > > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > or use another factory function and manually set the __class__: > > class MyData(Data): > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > def make_mydata(arg): > ? ? if hasattr(arg, "read"): > ? ? ? ? factory = data_from_file > ? ? else: > ? ? ? ? factory = data_from_string > ? ? obj = factory(arg) > ? ? obj.__class__ = MyData > ? ? return obj > > If Data were a newstyle class you could move the hand-made polymorphism into > the __new__() method: > > class MyData(Data): > ? ? def __new__(class_, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? obj.__class__ = class_ > ? ? ? ? return obj > ? ? def __init__(self, arg): > ? ? ? ? pass > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > if __name__ == "__main__": > ? ? m = MyData("hello") > ? ? print len(m) > > Nothing of the above strikes me as pretty. Perhaps we could come up with a > neater solution if you tell us more about your use-case... Ops, I clicked send before to finish my post. Thanks for your quick and very valuable answer. From drobinow at gmail.com Thu Aug 18 11:12:37 2011 From: drobinow at gmail.com (David Robinow) Date: Thu, 18 Aug 2011 11:12:37 -0400 Subject: How to convert a list of strings into a list of variables In-Reply-To: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] Why would you want to? From jenn.duerr at gmail.com Thu Aug 18 11:19:56 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 08:19:56 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> On Aug 18, 11:12?am, David Robinow wrote: > On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > > How would you convert a list of strings into a list of variables using > > the same name of the strings? > > > So, ["red", "one", "maple"] into [red, one, maple] > > ? Why would you want to? I am being passed the list of strings. I have variables set up already pointing to files. I need to loop through each variable in the list and do things to the files. The list of strings will change each time, include up to 22 of the same strings each time. From malaclypse2 at gmail.com Thu Aug 18 11:29:40 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 18 Aug 2011 11:29:40 -0400 Subject: How to convert a list of strings into a list of variables In-Reply-To: <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > I am being passed the list of strings. ?I have variables set up > already pointing to files. ?I need to loop through each variable in > the list and do things to the files. ?The list of strings will change > each time, include up to 22 of the same strings each time. If you have a mapping of strings to values, you should just go ahead and store them in a dictionary. Then the lookup becomes simple: def foo(list_of_strings): mapping = { "bar0": "/var/log/bar0.log", "bar1": "/usr/local/bar/bar1.txt", "bar2": "/home/joe/logs/bar2.log", } for item in list_of_strings: filename = mapping[item] do_something(filename) (Untested) -- Jerry From gordon at panix.com Thu Aug 18 11:39:56 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 15:39:56 +0000 (UTC) Subject: Measure the amount of memory used? References: Message-ID: In Jack Bates writes: > 1) How does the amount of memory used change as it runs? I've observed that the amount of memory consumed by a program will stay constant or increase; it never decreases. Or were you wanting to measure the rate of increase over time? > Has anyone else measured the memory used by a Python program? How did > you do it? I generally use 'top' to do this for any program. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From darcy at druid.net Thu Aug 18 11:51:53 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Aug 2011 11:51:53 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <20110818115153.6a37653b@dilbert> On Thu, 18 Aug 2011 22:37:37 +0800 Ghodmode wrote: > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. I'm not sure it would scale but I have a few lists that I protect by doing a few simple things. First, I make the list so that only members can post. I then set the list so that everyone is moderated by default. When someone posts a legitimate message I simply pass it and then unmoderate that user. It's not as onerous as it sounds. Very few people actually post and you only have to deal with those that do once. Mailman makes it pretty simple to manage too. -- 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 jenn.duerr at gmail.com Thu Aug 18 11:54:48 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 08:54:48 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> Message-ID: <17946eaa-2bc6-4c9b-8251-729072473988@w18g2000yqc.googlegroups.com> On Aug 18, 11:29?am, Jerry Hill wrote: > On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > > I am being passed the list of strings. ?I have variables set up > > already pointing to files. ?I need to loop through each variable in > > the list and do things to the files. ?The list of strings will change > > each time, include up to 22 of the same strings each time. > > If you have a mapping of strings to values, you should just go ahead > and store them in a dictionary. ?Then the lookup becomes simple: > > def foo(list_of_strings): > ? ? ? ? mapping = { > ? ? ? ? ? ? ? ? "bar0": "/var/log/bar0.log", > ? ? ? ? ? ? ? ? "bar1": "/usr/local/bar/bar1.txt", > ? ? ? ? ? ? ? ? "bar2": "/home/joe/logs/bar2.log", > ? ? ? ? } > ? ? ? ? for item in list_of_strings: > ? ? ? ? ? ? ? ? filename = mapping[item] > ? ? ? ? ? ? ? ? do_something(filename) > > (Untested) > > -- > Jerry Thanks, implemented something along those lines, and it worked! From navkirat.py at gmail.com Thu Aug 18 12:06:18 2011 From: navkirat.py at gmail.com (Navkirat Singh) Date: Thu, 18 Aug 2011 21:36:18 +0530 Subject: Sqlalchemy + Cherrypy Message-ID: Hi Guys, I am not sure if this is the right place to put this question. I am trying to figure out what the proper/clean way is to integrate cherrypy and sqlalchemy? I am currently trying to do this cherrypy 3 and sqlalchemy .7 in python 3.2 a) Cherrypy tools b) Integrate it directly into the app Any help will be really appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Thu Aug 18 12:08:24 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:08:24 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <201108181208.25029.gheskett@wdtv.com> On Thursday, August 18, 2011 12:08:00 PM Ghodmode did opine: > On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk wrote: > > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > >> I really like this list as part of my learning tools but the amount > >> of spam that I've been getting from it is CRAZY. Doesn't anything > >> get scanned before it sent to the list? > > > > This has been discussed on the list a number of times before, so I'll > > refer you to the archives for details. > > > > Basically, the mailing list receives postings from Google Groups and > > vice versa. Most of the spam comes from Google Groups. If you add a > > mail filter that deletes anything with the "Organization" header set > > to "http://groups.google.com", you won't see much spam anymore. In my > > experience, you'll also miss a number of legitimate postings. > > You are absolutely right, it has been brought up before. But I'm glad > it's been brought up again. It's such a problem that it degrades the > usefulness of the list and the community. > > Most of the mailing lists I'm on are managed using Google Groups and > many of them are on mailman, like this list. I don't see spam on > them, so I don't know what's going on here. > > It's not really filtering at all. Most lists only allow members to > post and the admins are quick to boot offenders. > > For the most part, I'm just a lurker, so my suggestion shouldn't carry > as much weight, but here it is anyway... > > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. > > ... problem solved. > > Yes. I'm saying we should abandon those who only follow the list via > newsgroups. > Yes. I'm willing to do the work, but I'm not the right choice. +100 (or whatever it takes) > > HTH > > Philip > > -- > Ghodmode > http://www.ghodmode.com/blog Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The state of innocence contains the germs of all future sin. -- Alexandre Arnoux, "Etudes et caprices" From gordon at panix.com Thu Aug 18 12:09:43 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 16:09:43 +0000 (UTC) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: In <2ab25f69-6017-42a6-a7ef-c71bc2ee8547 at l2g2000vbn.googlegroups.com> noydb writes: > How would you convert a list of strings into a list of variables using > the same name of the strings? > So, ["red", "one", "maple"] into [red, one, maple] > Thanks for any help! If the strings and the object names are exactly the same, you could use eval(). (Of course this assumes the objects already exist.) red = "this is the red object" one = 1 maple = "this is the maple object" list_of_strings = ["red", "one", "maple"] list_of_variables = [] for x in list_of_strings: list_of_variables.append(eval(x)) for y in list_of_variables: print y -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ghodmode at ghodmode.com Thu Aug 18 12:09:56 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Fri, 19 Aug 2011 00:09:56 +0800 Subject: List spam In-Reply-To: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: On Thu, Aug 18, 2011 at 10:58 PM, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. ?Choose mailman or Google Groups, or another single >> solution. ?Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. ?Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. > > Problem solved. Is that easier than just checking your email? I guess it's a matter of perspective... Newsgroups aren't inherently spam-free. They're filtered. At least that's the case with Gmane (http://gmane.org/spam.php). My own ISP doesn't provide a news server and, although there are many links for free open news servers, most of them don't seem to work. I did check, though. I found a free, open news server with comp.lang.python after 6 that didn't work. Unfortunately, the one I found is read-only. I'll have to do some more looking if I want to participate in the newsgroup. I set it up in Thunderbird. I waited for a few minutes while it loaded the available newsgroups, then filtered the list for comp.lang.python and subscribed. I noticed that, when clicking on a message, there is another delay while I wait for the content of the message to load. I was happy to see significantly less spam in the newsgroup than in the mailing list, but there was still more than I see in other mailing lists. For me, this is much more difficult, although I'm sure that this is a matter of perspective. Also, I have something that's tied to this computer. I can't read it on my laptop, my mobile device, or at a cyber-cafe. I have to sit in front of this computer if I want to read the newsgroup and, until I find another news server that isn't read-only, I can't even post messages. For me, I'll stick with email. > -- Alain. -- Ghodmode http://www.ghodmode.com/blog From gheskett at wdtv.com Thu Aug 18 12:14:13 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:14:13 -0400 Subject: List spam In-Reply-To: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181214.13370.gheskett@wdtv.com> On Thursday, August 18, 2011 12:08:38 PM Alain Ketterlin did opine: > "Jason Staudenmayer" writes: > > I really like this list as part of my learning tools but the amount of > > spam that I've been getting from it is CRAZY. Doesn't anything get > > scanned before it sent to the list? > > I'm using nntp to read this newsgroup (through an academic server). > No spam at all. > > -- Alain. Which I think re-enforces the conclusion I have reached, and that is that the most obnoxious spammer here is injecting his spam directly to a machine handling google's groups that is downstream of any filtering they claim to do. Short answer is to disconnect the the NNTP link and make this list into a REAL mailing list. Subscribers only, or get past a GOOD captcha. Spammers have stuff that can do the average captcha in a second or less, so choose the images wisely and randomize both the background and the text. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The state of innocence contains the germs of all future sin. -- Alexandre Arnoux, "Etudes et caprices" From gheskett at wdtv.com Thu Aug 18 12:15:59 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:15:59 -0400 Subject: List spam In-Reply-To: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181215.59072.gheskett@wdtv.com> On Thursday, August 18, 2011 12:14:39 PM Alain Ketterlin did opine: > Ghodmode writes: > > [...] > > > Make an effort to curb the spam even if it means killing the newsgroup > > availability. Choose mailman or Google Groups, or another single > > solution. Make it members only, but allow anyone to register with an > > automated confirmation email and a CAPTCHA. Appoint a list admin who > > has a few minutes each day to scan subjects of emails for spammers and > > remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. > > Problem solved. > > -- Alain. That is asking the user to take considerable effort and resources to do that. What is wrong with the mailing list only approach? Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The plot was designed in a light vein that somehow became varicose. -- David Lardner From gheskett at wdtv.com Thu Aug 18 12:20:36 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:20:36 -0400 Subject: List spam In-Reply-To: References: Message-ID: <201108181220.36337.gheskett@wdtv.com> On Thursday, August 18, 2011 12:16:50 PM Jason Staudenmayer did opine: [...] > I do know it is ironic that I forgot to stop the footer for the one > reply. It's not my choice to add it but I was able to find a way around > that work policy for list emails. I'm a strong opponent of dropping any > email with a stupid footer spam. > > Jason I'm a strong "proponent" of dropping any email with a stupid footer spam. There, I fixed it for you. ;-) Sorry, couldn't resist, Jason. At nearly 77, I am a firm believer that one can grow old without growing up. ;p) Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Renning's Maxim: Man is the highest animal. Man does the classifying. From nad at acm.org Thu Aug 18 12:37:14 2011 From: nad at acm.org (Ned Deily) Date: Thu, 18 Aug 2011 09:37:14 -0700 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: In article , Ghodmode wrote: > Newsgroups aren't inherently spam-free. They're filtered. At least > that's the case with Gmane (http://gmane.org/spam.php). > > My own ISP doesn't provide a news server and, although there are many > links for free open news servers, most of them don't seem to work. > > I did check, though. I found a free, open news server with > comp.lang.python after 6 that didn't work. Unfortunately, the one I > found is read-only. I'll have to do some more looking if I want to > participate in the newsgroup. I set it up in Thunderbird. I waited > for a few minutes while it loaded the available newsgroups, then > filtered the list for comp.lang.python and subscribed. I noticed > that, when clicking on a message, there is another delay while I wait > for the content of the message to load. > > I was happy to see significantly less spam in the newsgroup than in > the mailing list, but there was still more than I see in other mailing > lists. > > For me, this is much more difficult, although I'm sure that this is a > matter of perspective. Also, I have something that's tied to this > computer. I can't read it on my laptop, my mobile device, or at a > cyber-cafe. I have to sit in front of this computer if I want to read > the newsgroup and, until I find another news server that isn't > read-only, I can't even post messages. Confusingly, this "forum" is available via a number of channels. Here is a subset of them (there are more): 1. python-list mailing list http://mail.python.org/mailman/listinfo/python-list 2. comp.lang.python news:comp.lang.python (Usenet group via NNTP) 3. google groups 4. gmane (various formats) http://dir.gmane.org/gmane.comp.python.general a. gmane.comp.python.general (non-Usenet group via NNTP) b. web interfaces All of the above allow both reading and posting. gmane does spam filtering so, if you read and post through it, you will avoid most of the spam (a little bit gets through). The gmane nntp server (which is for gmane groups only, not regular Usenet groups) is free to use. http://gmane.org/about.php -- Ned Deily, nad at acm.org From ppearson at nowhere.invalid Thu Aug 18 12:43:20 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 16:43:20 GMT Subject: lists and for loops References: Message-ID: <9b4tp8FdrgU1@mid.individual.net> On Wed, 17 Aug 2011 20:08:23 -0700 (PDT), Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers Because integers are immutable. You cannot turn 1 into 6. Contrast this behavior with lists, which *are* mutable: >>> numbers = [[1],[2],[3],[4],[5]] >>> for n in numbers: ... n[0]= n[0] + 5 ... >>> numbers [[6], [7], [8], [9], [10]] For practical purposes, I'm sure you'll find other responders' excellent posts to be of more immediate use, but keeping mutability in mind helps. -- To email me, substitute nowhere->spamcop, invalid->net. From gordon at panix.com Thu Aug 18 12:51:05 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 16:51:05 +0000 (UTC) Subject: Word Perfect integration References: Message-ID: In Ethan Furman writes: > I have WordPerfect v13 which we are currently using for letter merges. > I would like to automate this with Python instead of learning the WP > Macro language. I suspect that learning how to integrate python with wordperfect will end up being much more work than learning wordperfect macros. Just my two cents. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From alain at dpt-info.u-strasbg.fr Thu Aug 18 12:58:53 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 18:58:53 +0200 Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <8762lu64he.fsf@dpt-info.u-strasbg.fr> gene heskett writes: >> Or save work and find a public nntp server (or setup one, or ask your >> provider), and use a news reader to follow the list (even thunderbird >> can do this). No spam, no need to store messages on your machine, >> auto-purge after a configurable delay, etc. > That is asking the user to take considerable effort and resources to do > that. What is wrong with the mailing list only approach? Nothing really. Regarding effort and resources, once you've found a NNTP server there's very little effort (probably less than subscribing to a mailing list). I have 4 lines in my .emacs. And this lets me browse dozens of groups (or thousands if I had time for this). It might not be easy to find a server which will let you post, but that's because a few years back many internet providers decided that nntp was too much traffic. I guess it would now be considered ridiculous compared to the average web-site. But I'd like to return the question. What's wrong with nntp? It looks like everybody agrees that nntp brings spam. I just wanted to say that's not true, I use nntp extensively and haven't seen spam for months (I'm talking about 15-20 groups, not comp.lang.python only). The real problem here seems to be google groups, which in some way forwards spam to the mailing-list. How this happens is beyond my understanding. But let's try to fix the real problem. -- Alain. From ethan at stoneleaf.us Thu Aug 18 13:00:54 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 10:00:54 -0700 Subject: Word Perfect integration Message-ID: <4E4D4546.1070203@stoneleaf.us> I have WordPerfect v13 which we are currently using for letter merges. I would like to automate this with Python instead of learning the WP Macro language. Does anyone have any pointers? ~Ethan~ From ppearson at nowhere.invalid Thu Aug 18 13:02:49 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 17:02:49 GMT Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <9b4utpFdrgU2@mid.individual.net> On Thu, 18 Aug 2011 16:58:04 +0200, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. Choose mailman or Google Groups, or another single >> solution. Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. Or pay for filtered NNTP service. I'm happy with news.individual.net: 10 euros per year, appears to be competently run, very little spam gets through (maybe like 1 message per heavily posted group per day), and they probably carry all the newsgroups you follow. I have no affiliation with them, except for being a customer who hopes they stay in business. -- To email me, substitute nowhere->spamcop, invalid->net. From ppearson at nowhere.invalid Thu Aug 18 13:10:30 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 17:10:30 GMT Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <9b4vc6FdrgU3@mid.individual.net> On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: [snip] > What is wrong with the mailing list only approach? In the mailing-list approach, how do I search for prior discussions on a subject? (I'm not particularly opposed to the mailing list, I'm just an NNTP follower worried about the uncertainties of change.) -- To email me, substitute nowhere->spamcop, invalid->net. From philip at semanchuk.com Thu Aug 18 13:21:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Aug 2011 13:21:02 -0400 Subject: List spam In-Reply-To: <9b4vc6FdrgU3@mid.individual.net> References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> <9b4vc6FdrgU3@mid.individual.net> Message-ID: On Aug 18, 2011, at 1:10 PM, Peter Pearson wrote: > On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: > [snip] >> What is wrong with the mailing list only approach? > > In the mailing-list approach, how do I search for prior discussions > on a subject? (I'm not particularly opposed to the mailing list, > I'm just an NNTP follower worried about the uncertainties of change.) I use a Google search like this: site:mail.python.org/pipermail/python-list/ banana Although that has its own issues, as not all messages seem to make it to that list (or they have the X-No-Archive bit set?) Cheers P From ghodmode at ghodmode.com Thu Aug 18 13:29:12 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Fri, 19 Aug 2011 01:29:12 +0800 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: On Fri, Aug 19, 2011 at 12:37 AM, Ned Deily wrote: > 4. gmane (various formats) > ? http://dir.gmane.org/gmane.comp.python.general > ? a. ?gmane.comp.python.general (non-Usenet group via NNTP) > All of the above allow both reading and posting. ?gmane does spam > filtering so, if you read and post through it, you will avoid most of > the spam (a little bit gets through). ?The gmane nntp server (which is > for gmane groups only, not regular Usenet groups) is free to use. Unfortunately, Gmane's version of this newsgroup (gmane.comp.python.general) has all of the offensive spam. I'm kinda surprised considering the detailed information that they put on their site about spam filtering. These are the ones I got to work: - textnews.news.cambrium.nl - mail.tsu.ru ... They're light on the spam, but they're read-only. Ironically, the Google Groups version (https://groups.google.com/forum/#!forum/comp.lang.python) has almost none of the spam, although I did see one message that said "This topic has been hidden because it was flagged for abuse". I can't join that Google Group, though. I guess that's because it's just a viewer for the newsgroup. > -- > ?Ned Deily, > ?nad at acm.org -- Ghodmode http://www.ghodmode.com/blog From rosuav at gmail.com Thu Aug 18 13:46:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Aug 2011 18:46:48 +0100 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode wrote: > Make an effort to curb the spam even if it means killing the newsgroup > availability. ?Choose mailman or Google Groups, or another single > solution. ?Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. ?Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. > Unfortunately spammers can create email addresses very quickly, and CAPTCHAs are inherently weak (even the best of them are easily cracked by the Chinese human "botnets"). However, I wouldn't be against a system of spam filtering with three levels: Not Spam, gets straight onto the list; Definite Spam, gets deleted; and Dubious, which gets dropped into a mod's basket. ChrisA From drsalists at gmail.com Thu Aug 18 13:48:36 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Aug 2011 10:48:36 -0700 Subject: Measure the amount of memory used? In-Reply-To: <1313680100.25701.15.camel@selene> References: <1313680100.25701.15.camel@selene> Message-ID: "A person with one watch knows what time it is. A person with two is never sure." You're probably best off just picking one or more measures that work for your purposes, and going with them. Don't concern yourself overmuch with finding "the" amount. Memory can actually contract on some modern systems, due to garbage collection and the relatively new ability of some malloc's to mmap away no-longer-needed pages. Going directly to /proc is fine, though it might be a little more common (and portable) to run ps and let it sift through /proc. But of course, running ps over and over is less efficient. On Thu, Aug 18, 2011 at 8:08 AM, Jack Bates wrote: > I wrote a content filter for Postfix with Python, > https://github.com/jablko/cookie > > It should get started once, and hopefully run for a long time - so I'm > interested in how it uses memory: > > 1) How does the amount of memory used change as it runs? > > 2) How does the amount of memory used change as I continue to hack on > it, and change the code? > > My naive thought was that I'd periodically append to a file, the virtual > memory size from /proc/[pid]/stat and a timestamp. From this a could > make a graph of the amount of memory used as my content filter runs, and > I could compare two graphs to get a clue whether this amount changed as > I continue to hack > > - but some Googling quickly revealed that measuring memory is actually > quite complicated? Neither the virtual memory size nor the "resident set > size" accurately measure the amount of memory used by a process > > Has anyone else measured the memory used by a Python program? How did > you do it? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 18 13:48:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Aug 2011 18:48:56 +0100 Subject: How to convert a list of strings into a list of variables In-Reply-To: References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: > for x in list_of_strings: > ? ?list_of_variables.append(eval(x)) > If this really is what you need, you can simplify it by using the globals() dictionary - it's a regular dictionary whose contents are all the global variables in your current module. Inside a function, use locals() instead. http://docs.python.org/library/functions.html#globals ChrisA From nobody at nowhere.com Thu Aug 18 13:58:41 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 18:58:41 +0100 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> <4b383bcd-c58c-4e67-895a-d70fdf82f9c0@n35g2000yqf.googlegroups.com> Message-ID: On Thu, 18 Aug 2011 01:24:30 -0700, peter wrote: > This is very similar to my solution, which was to use stty turn off > keyboard echo, then repeatedly read sys.stdin.read(1) until a unique > keystroke had been defined. For example, the 'Insert' key seems to > return a sequence of four codes, namely 27, 91, 50, 126. It works but > has two disadvantages which I have managed to live with:- > > 1. As character 27 is used to signal the start of a 'special' key > sequence, it cannot detect a single press of the Esc key. The > workaround is to detect a double press instead. > > 2. Some keys seem to return different sets of codes depending on the > circumstances. For example, F1 returns 27,91,91,65 from the command > line, and 27,79,80 from a GUI window. I suspect there may be > variations between flavours of Linux too. The solution is to detect > all possibilities - so far I haven't found any overlaps. Escape sequences vary between terminals. A given key may have different escape sequences on the Linux console, xterm, a vt220, etc. The termcap and terminfo databases exist for this purpose (terminfo is newer). Some escape sequences vary by "mode". E.g. the cursor keys typically produce different sequences depending upon whether the terminal is in "keypad" mode. The normal solution for distinguishing the escape key from an escape sequence is a timeout. Unfortunately, it needs to be quite long in order to reliably support network (ssh, telnet, etc) connections. > Not pretty, but as I said it works. I know now not to spend time > looking further. Whilst there may be a historical reason for the > current situation, it would be a great convenience for amateur coders > like mayself if the gurus could devise a platform independent version > of mscvrt. The platform-independent high-level terminal interface is called "curses". From alec.taylor6 at gmail.com Thu Aug 18 14:00:49 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 04:00:49 +1000 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: 5963 unread emails. Thanks python-list + other mailing-lists! My recommendation to you is to setup a different account for your mailing-lists. Alternatively setup some mail rules. On Fri, Aug 19, 2011 at 3:46 AM, Chris Angelico wrote: > On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode wrote: >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. ?Choose mailman or Google Groups, or another single >> solution. ?Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. ?Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. >> > > Unfortunately spammers can create email addresses very quickly, and > CAPTCHAs are inherently weak (even the best of them are easily cracked > by the Chinese human "botnets"). However, I wouldn't be against a > system of spam filtering with three levels: Not Spam, gets straight > onto the list; Definite Spam, gets deleted; and Dubious, which gets > dropped into a mod's basket. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From alec.taylor6 at gmail.com Thu Aug 18 14:02:13 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 04:02:13 +1000 Subject: Word Perfect integration In-Reply-To: References: Message-ID: wow, people still use WordPerfect? On Fri, Aug 19, 2011 at 2:51 AM, John Gordon wrote: > In Ethan Furman writes: > >> I have WordPerfect v13 which we are currently using for letter merges. >> I would like to automate this with Python instead of learning the WP >> Macro language. > > I suspect that learning how to integrate python with wordperfect will > end up being much more work than learning wordperfect macros. > > Just my two cents. > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gordon at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > From as at sci.fi Thu Aug 18 14:13:09 2011 From: as at sci.fi (Anssi Saari) Date: Thu, 18 Aug 2011 21:13:09 +0300 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: Ghodmode writes: > Newsgroups aren't inherently spam-free. They're filtered. At least > that's the case with Gmane (http://gmane.org/spam.php). > > My own ISP doesn't provide a news server and, although there are many > links for free open news servers, most of them don't seem to work. You know, Gmane allows access also via NNTP, including this list. Server news.gmane.org, group name gmane.comp.python.general. Haven't used it since I get this list via "normal" NNTP as comp.lang.python. My NNTP access is via a computer club for 8 euros per year. From gheskett at wdtv.com Thu Aug 18 14:25:42 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 14:25:42 -0400 Subject: List spam In-Reply-To: <8762lu64he.fsf@dpt-info.u-strasbg.fr> References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181425.42811.gheskett@wdtv.com> On Thursday, August 18, 2011 02:12:58 PM Alain Ketterlin did opine: > gene heskett writes: > >> Or save work and find a public nntp server (or setup one, or ask your > >> provider), and use a news reader to follow the list (even thunderbird > >> can do this). No spam, no need to store messages on your machine, > >> auto-purge after a configurable delay, etc. > > > > That is asking the user to take considerable effort and resources to > > do that. What is wrong with the mailing list only approach? > > Nothing really. > > Regarding effort and resources, once you've found a NNTP server there's > very little effort (probably less than subscribing to a mailing list). I > have 4 lines in my .emacs. And this lets me browse dozens of groups (or > thousands if I had time for this). It might not be easy to find a server > which will let you post, but that's because a few years back many > internet providers decided that nntp was too much traffic. I guess it > would now be considered ridiculous compared to the average web-site. > > But I'd like to return the question. What's wrong with nntp? The sheer volume of traffic eats 99% of an ISP's bandwidth. The last time I checked with one of the local ISP's that I quit using years ago because it was 30 miles away and was then long distance, giving me $300 phone bills, they said their server died (again, and that then traffic was such that a 300GB hard drive was being subject to a posting lifetime of 3 hours because it was filling the drive that quickly. At the time, they had 5 T1 circuits, and NNTP was eating 4 of them. To an ISP, that stuff is found on the ground behind the male of the bovine specie. No ISP I have access to a mail account on, except google, has the resources to maintain a full listing nnpt server. > It looks > like everybody agrees that nntp brings spam. I just wanted to say that's > not true, I use nntp extensively and haven't seen spam for months (I'm > talking about 15-20 groups, not comp.lang.python only). > > The real problem here seems to be google groups, which in some way > forwards spam to the mailing-list. How this happens is beyond my > understanding. But let's try to fix the real problem. I could just nuke them, but I suppose I'd then have to resubscribe to about 10 of my mailing lists through the server this msg comes from. That is gradually happening anyway because posting through a gmail account, you cannot turn off the dup deletions, so one never knows if ones post to a list got there until someone replies, you don't get an echo. I have even tried CCing this address as some have suggested, but that doesn't work either. gmail is NOT the huge thing it was touted to be, not by a hell of a long row of apple trees. > -- Alain. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) "It's not just a computer -- it's your ass." -- Cal Keegan From gheskett at wdtv.com Thu Aug 18 14:28:48 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 14:28:48 -0400 Subject: List spam In-Reply-To: <9b4vc6FdrgU3@mid.individual.net> References: <9b4vc6FdrgU3@mid.individual.net> Message-ID: <201108181428.48530.gheskett@wdtv.com> On Thursday, August 18, 2011 02:26:24 PM Peter Pearson did opine: > On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett > wrote: [snip] > > > What is wrong with the mailing list only approach? > > In the mailing-list approach, how do I search for prior discussions > on a subject? (I'm not particularly opposed to the mailing list, > I'm just an NNTP follower worried about the uncertainties of change.) If the message still exists in your local email corpus, kmail for one has no problems searching it. However, since my corpus is close to 10gigs because my inbox and one list are not expired, the rest of them are expired on a selectable schedule that only saves the last 2000 or so msgs. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Hoare's Law of Large Problems: Inside every large problem is a small problem struggling to get out. From drsalists at gmail.com Thu Aug 18 14:29:58 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Aug 2011 11:29:58 -0700 Subject: List spam In-Reply-To: References: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: On Thu, Aug 18, 2011 at 6:39 AM, Jason Staudenmayer < jasons at adventureaquarium.com> wrote: > > > On 18/08/2011 13:58, Jason Staudenmayer wrote: > > > I really like this list as part of my learning tools but the amount > > > of spam that I've been getting from it is CRAZY. Doesn't > > anything get > > > scanned before it sent to the list? > I can deal with normal spam but this stuff I've gotten is all about > rape. > Agreed, a few of the recent messages would've been far too many at a count of 1. What I do is forward the list to gmail. gmail has pretty decent spam filtering - normally. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Thu Aug 18 14:39:29 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 19:39:29 +0100 Subject: List spam References: Message-ID: On Thu, 18 Aug 2011 14:30:37 +0100, Tim Golden wrote: >> I really like this list as part of my learning tools but the amount of >> spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. (The > occasional one does get through although I can't remember the last). > > I always access it as a mailing list, and I seem to recall that the > newsgroup feed isn't filtered the same way as the mailing list is. That depends upon your news server. I see a small amount of spam for this group, but not enough that it concerns me. If the mailing list is getting spam from the newsgroup, the solution is to either find a cleaner feed or add a spam filter to the gateway. From nobody at nowhere.com Thu Aug 18 14:45:28 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 19:45:28 +0100 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, 18 Aug 2011 16:09:43 +0000, John Gordon wrote: >> How would you convert a list of strings into a list of variables using >> the same name of the strings? > >> So, ["red", "one", "maple"] into [red, one, maple] > > If the strings and the object names are exactly the same, you could use > eval(). Eval is overkill for variables; use globals() and/or locals(). But data which is supposed to be indexed by a variable key (i.e. a name which is determined at run-time) should normally be put into a dictionary. If access with fixed keys is far more common than variable keys, using an object (with getattr/setattr for variable keys) may be preferable. From ethan at stoneleaf.us Thu Aug 18 15:24:17 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 12:24:17 -0700 Subject: Word Perfect integration In-Reply-To: References: Message-ID: <4E4D66E1.1050206@stoneleaf.us> Alec Taylor wrote: > wow, people still use WordPerfect? Them's fightin' words right there! :) Yes, we still use Word Perfect, and will as long as it is available. The ability to see the codes in use (bold, margins, columns, etc) has so far been unequaled in anything else I have looked at. ~Ethan~ From ethan at stoneleaf.us Thu Aug 18 15:25:00 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 12:25:00 -0700 Subject: Word Perfect integration In-Reply-To: References: Message-ID: <4E4D670C.50206@stoneleaf.us> John Gordon wrote: > I suspect that learning how to integrate python with wordperfect will > end up being much more work than learning wordperfect macros. Possibly... but I enjoy coding in Python. :) ~Ethan~ From matze999 at gmail.com Thu Aug 18 15:49:54 2011 From: matze999 at gmail.com (Matt Funk) Date: Thu, 18 Aug 2011 13:49:54 -0600 Subject: Help with regular expression in python Message-ID: <201108181349.54727.matze999@gmail.com> Hi, i am sorry if this doesn't quite match the subject of the list. If someone takes offense please point me to where this question should go. Anyway, i have a problem using regular expressions. I would like to match the line: 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description The number of floats can vary (in this example there are 32). So what i thought i'd do is the following: instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) {32}' instance_linetype_pattern = re.compile(instance_linetype_pattern_str) Basically the expression in the first major set of paranthesis matches a scientific number format. The '{32}' is supposed to match the previous 32 times. However, it doesn't. I can't figure out why this does not work. I'd really like to understand it if someone can shed light on it. thanks matt From tjreedy at udel.edu Thu Aug 18 15:58:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 15:58:39 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: > I did check, though. I found a free, open news server with > comp.lang.python after 6 that didn't work. Unfortunately, the one I > found is read-only. I'll have to do some more looking if I want to > participate in the newsgroup. I set it up in Thunderbird. I read and post to this and other Python lists via news.gmane.org (free) with Thunderbird. It mirrors 1000s of technical mail lists, including 200+ with 'python'. I believe it therefore has less spam than c.l.p (ie, minus whatever gets filtered out by the pipermail at python.org). First post to any list requires a response to an email. Uptime is pretty good. -- Terry Jan Reedy From M.Komon at SiliconHill.cz Thu Aug 18 15:59:32 2011 From: M.Komon at SiliconHill.cz (=?UTF-8?B?TWFydGluIEtvbW/FiA==?=) Date: Thu, 18 Aug 2011 21:59:32 +0200 Subject: Help with regular expression in python In-Reply-To: <201108181349.54727.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> Message-ID: <4E4D6F24.8040501@SiliconHill.cz> You don't seem to account for the whitespace between the floats. Try > '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?\s+){32}' (just added \s+). Martin On 8/18/2011 9:49 PM, Matt Funk wrote: > Hi, > i am sorry if this doesn't quite match the subject of the list. If someone > takes offense please point me to where this question should go. Anyway, i have > a problem using regular expressions. I would like to match the line: > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 > 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 > 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 > 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) : some description > > The number of floats can vary (in this example there are 32). So what i thought > i'd do is the following: > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > Basically the expression in the first major set of paranthesis matches a > scientific number format. The '{32}' is supposed to match the previous 32 > times. However, it doesn't. I can't figure out why this does not work. I'd > really like to understand it if someone can shed light on it. > > thanks > matt From gordon at panix.com Thu Aug 18 16:00:09 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 20:00:09 +0000 (UTC) Subject: Help with regular expression in python References: Message-ID: In Matt Funk writes: > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) Does your regexp account for the space in between each float? I can't tell due to your post having a linebreak at a really inconvenient spot. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Thu Aug 18 16:07:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 16:07:16 -0400 Subject: List spam In-Reply-To: <201108181214.13370.gheskett@wdtv.com> References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> <201108181214.13370.gheskett@wdtv.com> Message-ID: On 8/18/2011 12:14 PM, gene heskett wrote: > into a REAL mailing list. Subscribers only, or get past a GOOD captcha. I just had an idea. Ask 'What is python? __________________" or "What can you do with a python?' with a free-form fill in the blank answer. Look for 'computer', 'program' or 'language' in the response. 'snake' fails the test. Or 'Enter a Python keyword (search the tutorial if you do not know any) ____' -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 18 16:19:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 16:19:33 -0400 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: On 8/18/2011 3:24 PM, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. Definitely. I did a book with WP and periodically went through with codes revealed to delete any junk and got the camera-ready copy I wanted. I have recently used OpenO modeled after MSO and occasionally get frustrated when I cannot see what it actually inserts, to explain why it does not behave as expected. That aside, if you are on Windows, check the list archives for 'office automation' or somesuch. If WP has the standard API, I believe the answer is to use the PythonWin extensions, included with the ActiveState Python distribution and available on SourceForge. There is a windows module includes in the stdlib, but I do not know if it has enough. -- Terry Jan Reedy From vriolk at gmail.com Thu Aug 18 16:44:51 2011 From: vriolk at gmail.com (coldpizza) Date: Thu, 18 Aug 2011 13:44:51 -0700 (PDT) Subject: How to print non-printable chars?? References: Message-ID: <6c15a4a4-02a9-4a04-bd3a-0cb88a96470f@v7g2000vbk.googlegroups.com> On Aug 13, 7:59?am, Julio Cesar Rodriguez Cruz wrote: > Hi all, > If I open an .exe file in any text editor I get lot of odd chars, > what I want is to know how to output those chars if I have the hexadecimal > code. I found out how to do the reverse process with the quopri module, > > i.e.:>>> import quopri > >>> quopri.encodestring('?? ') > '=F1=E8=18' > >>> quopri.decodestring('=F1=E8=18') > > '\xf1\xe8\x18' > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '?? ' > > any tips? > thanks > Julio Cesar In a web/html environment or in broken ascii-only consoles like the one on windows, I use the following hack: print your_unicode_string.encode('us-ascii','xmlcharrefreplace') This will print unicode chars using pure ASCII symbols which will display correctly in a web browser and are more readable in a console than unicode escapes. From brian.curtin at gmail.com Thu Aug 18 16:51:42 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Thu, 18 Aug 2011 15:51:42 -0500 Subject: How to build python using visual studio 2005? In-Reply-To: References: Message-ID: On Wed, Aug 17, 2011 at 13:16, smith jack wrote: > anybody here have build it correctly? > how to make a msi file just as the official site did? > is there any detailed tutorial online? We're currently shipping CPython built on VS 2008, but I do know of people building with 2005. How they do it, I'm not entirely sure, but all of the related files are available -- see the PC folder for previous versions of project and solution files. As for making the MSI, from a source checkout, the Tools/msi/msi.py script is how its generated, but there isn't currently any documentation or tutorial. What I'd do is start by running that script, then piece together what you're missing in order to get it working. You'll need a built Python including the third-party things like tkinter in order for it to work. I know it needs pywin32, but I can't remember anything else I needed off the top of my head, but I have gotten it to work before. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Thu Aug 18 17:19:42 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 17:19:42 -0400 Subject: List spam In-Reply-To: References: <201108181214.13370.gheskett@wdtv.com> Message-ID: <201108181719.42980.gheskett@wdtv.com> On Thursday, August 18, 2011 05:18:42 PM Terry Reedy did opine: > On 8/18/2011 12:14 PM, gene heskett wrote: > > into a REAL mailing list. Subscribers only, or get past a GOOD > > captcha. > > I just had an idea. Ask 'What is python? __________________" or "What > can you do with a python?' with a free-form fill in the blank answer. > Look for 'computer', 'program' or 'language' in the response. 'snake' > fails the test. > > Or 'Enter a Python keyword (search the tutorial if you do not know any) > ____' Sounds good, but now you've trained the spammer who is without a doubt watching this list. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) QOTD: "I may not be able to walk, but I drive from the sitting position." From vlastimil.brom at gmail.com Thu Aug 18 17:27:42 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 18 Aug 2011 23:27:42 +0200 Subject: Help with regular expression in python In-Reply-To: <201108181349.54727.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> Message-ID: 2011/8/18 Matt Funk : > Hi, > i am sorry if this doesn't quite match the subject of the list. If someone > takes offense please point me to where this question should go. Anyway, i have > a problem using regular expressions. I would like to match the line: > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 > 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 > 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 > 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) ? ? ? : ? ? ? some description > > The number of floats can vary (in this example there are 32). So what i thought > i'd do is the following: > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > Basically the expression in the first major set of paranthesis matches a > scientific number format. The '{32}' is supposed to match the previous 32 > times. However, it doesn't. I ?can't figure out why this does not work. I'd > really like to understand it if someone can shed light on it. > > thanks > matt > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, the already suggested handling of whitespace with \s+ etc. at the end of the parenthesised patern should help; furhtermore, if you are using this pattern in the python source, you should either double all backslashes or use a raw string for the pattern - with r prepended before the opening quotation mark: pattern_str = r"..." in order to handle backslashes literally and not as escape character. hth, vbr From sigmundv at gmail.com Thu Aug 18 17:51:13 2011 From: sigmundv at gmail.com (SigmundV) Date: Thu, 18 Aug 2011 14:51:13 -0700 (PDT) Subject: pairwise combination of two lists References: Message-ID: <0da423ac-abc1-468d-bca7-8a745eae812b@y4g2000vbx.googlegroups.com> On Aug 17, 9:22?pm, Yingjie Lin wrote: > I found zip() but it only gives [('a', '1'), ('b', '2')], ?not exactly what I am looking for. Yet, if you feed the zip into a list comprehension you get what you want: li3 = [''.join(l) for l in zip(li1,li2)] Sigmund From antonio.a.barbosa at gmail.com Thu Aug 18 18:05:24 2011 From: antonio.a.barbosa at gmail.com (AB) Date: Thu, 18 Aug 2011 15:05:24 -0700 (PDT) Subject: How to convert a list of strings into a list of variables In-Reply-To: References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <2d34b748-8bcd-4411-8f81-a3e55a0ded21@glegroupsg2000goo.googlegroups.com> Hi, If the ?variables? are named attributes you can use getattr. #---------------- class colors: red=1 green=2 blue=3 c=colors() a=['red','green','blue'] for v in a: print v,getattr(c,v) #----------- AB From ramit.prasad at jpmorgan.com Thu Aug 18 18:20:59 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 18 Aug 2011 18:20:59 -0400 Subject: List spam In-Reply-To: <201108181719.42980.gheskett@wdtv.com> References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7C3C5AA@EMARC112VS01.exchad.jpmchase.net> >> Or 'Enter a Python keyword (search the tutorial if you do not know any) >> ____' > >Sounds good, but now you've trained the spammer who is without a doubt >watching this list. Teach them Python before they can post, I like it! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ben+python at benfinney.id.au Thu Aug 18 18:26:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Aug 2011 08:26:54 +1000 Subject: List spam References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <87ippubbkh.fsf@benfinney.id.au> gene heskett writes: > Short answer is to disconnect the the NNTP link and make this list > into a REAL mailing list. Subscribers only, or get past a GOOD > captcha. Many of the more valuable contributors post via NNTP, which does not require mailing list subscription nor CAPTCHA. One of the compelling features of this forum is that newcomers to Python can post here without the hurdles you're describing. -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From matze999 at gmail.com Thu Aug 18 19:03:05 2011 From: matze999 at gmail.com (Matt Funk) Date: Thu, 18 Aug 2011 17:03:05 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> Message-ID: <201108181703.06278.matze999@gmail.com> Hi guys, thanks for the suggestions. I had tried the white space before as well (to no avail). So here is the expression i am using (based on suggestions), but still no success: instance_linetype_pattern_str =\ r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' instance_linetype_pattern = re.compile(instance_linetype_pattern_str) results = instance_linetype_pattern.findall(line) print "results: "; print results The match i get is: results: [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome description')] btw: The line to be matched (given below) is ONE line. There are no line breaks (even though my email client adds them). matt On Thursday, August 18, 2011, Vlastimil Brom wrote: > 2011/8/18 Matt Funk : > > Hi, > > i am sorry if this doesn't quite match the subject of the list. If > > someone takes offense please point me to where this question should go. > > Anyway, i have a problem using regular expressions. I would like to > > match the line: > > > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > > 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > > 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > > 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > > 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > > 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > > 2.150000e+01 2.199000e+01 : (instance: 0) : some description > > > > The number of floats can vary (in this example there are 32). So what i > > thought i'd do is the following: > > instance_linetype_pattern_str = > > '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) {32}' > > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > > Basically the expression in the first major set of paranthesis matches a > > scientific number format. The '{32}' is supposed to match the previous 32 > > times. However, it doesn't. I can't figure out why this does not work. > > I'd really like to understand it if someone can shed light on it. > > > > thanks > > matt > > -- > > http://mail.python.org/mailman/listinfo/python-list > > Hi, > the already suggested handling of whitespace with \s+ etc. at the end > of the parenthesised patern should help; > furhtermore, if you are using this pattern in the python source, you > should either double all backslashes or use a raw string for the > pattern - with r prepended before the opening quotation mark: > pattern_str = r"..." > in order to handle backslashes literally and not as escape character. > hth, > vbr From usenet-nospam at seebs.net Thu Aug 18 19:03:28 2011 From: usenet-nospam at seebs.net (Seebs) Date: 18 Aug 2011 23:03:28 GMT Subject: List spam References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: On 2011-08-18, Prasad, Ramit wrote: >>> Or 'Enter a Python keyword (search the tutorial if you do not know any) >>> ____' >> >>Sounds good, but now you've trained the spammer who is without a doubt >>watching this list. > > Teach them Python before they can post, I like it! I don't. If I want to get started in a language, I might well want to read about it a bit, and maybe ask questions like "what is a good book for me to start with?" If I have to know the language to do that, well... -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 18 19:03:29 2011 From: usenet-nospam at seebs.net (Seebs) Date: 18 Aug 2011 23:03:29 GMT Subject: Word Perfect integration References: Message-ID: On 2011-08-18, Ethan Furman wrote: > Yes, we still use Word Perfect, and will as long as it is available. > The ability to see the codes in use (bold, margins, columns, etc) has so > far been unequaled in anything else I have looked at. I have used other software that had this functionality, but not so much lately. (Although it appears that PageStream still does this, which is totally of relevance to someone, I'm sure.) But yeah, that was an AMAZING feature, and not having it is one of the reasons I'm so often unable to get things done in MS Word. Sadly, Corel dropped Mac and Linux support, and I don't do real work on Windows, so WP has been off my list for a long time now. :( -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rhodri at wildebst.demon.co.uk Thu Aug 18 19:18:13 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Aug 2011 00:18:13 +0100 Subject: List spam References: Message-ID: On Thu, 18 Aug 2011 16:00:40 +0100, Jason Staudenmayer wrote: > I'm a strong opponent of dropping any email with a > stupid footer spam. By contrast, an excessively large sig (particularly an excessively large sig without a proper separator) is something that's guaranteed to get on my wick, and usually indicates someone I don't want to bother listening to. Thank you for trimming it. I'm reading this as the comp.lang.python newsgroup, straight off an NNTP server, and to be honest I'm not getting the level of spam you are talking about. There's some, sure -- usually for Bollywood actress pictures -- but not enough to make me worry about Opera's relatively poor newsgroup filtering facilities. If you're getting as much as you say, it's being injected on the mail side of the gateway somehow. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Thu Aug 18 19:21:16 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Aug 2011 00:21:16 +0100 Subject: Word Perfect integration References: Message-ID: On Thu, 18 Aug 2011 20:24:17 +0100, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. I take it you haven't looked at TeX, then? :-) -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Thu Aug 18 19:31:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Aug 2011 00:31:32 +0100 Subject: List spam In-Reply-To: References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: On Fri, Aug 19, 2011 at 12:03 AM, Seebs wrote: > I don't. ?If I want to get started in a language, I might well want to > read about it a bit, and maybe ask questions like "what is a good book > for me to start with?" > > If I have to know the language to do that, well... > When I start with a language, I want two things: a compiler/interpreter, and online documentation. (A book would be equivalent to the latter, but I tend to prefer to read things online.) Asking questions comes later; first, I want to get a comprehension for the language's features. By the time I join a list like this, I want to be able to understand the answers I get. ChrisA From vincent at vincentdavis.net Thu Aug 18 19:53:35 2011 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 18 Aug 2011 17:53:35 -0600 Subject: Check email header for RFC 822 standard and match emails between imap servers. Message-ID: The sort story, I have been attempting to use the Google Migration assistant to migrate emails from one google account to another, about 80,000 emails. I have two problems. 1. Many emails that fail to transfer because of errors like "Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is invalid." See full error below. emails that. 2. I need to delete the emails from the old account that have been transferred. And the Two question are: 1: I am able to connect and get an email. But I am not clear how I would check that the header is valid or identify the problem. grl = imaplib.IMAP4_SSL('imap.gmail.com', 993) grl.login('name at domain.com', 'password') grl.fetch(17006, 'uid') # So now I have an email how do I check the header, I know how to view it but not check it for RFC 822. 2: Since I don't know which emails have been transferred I want to delete all the email that have. To be more correct I don't know which ones on the old account, when they are moved to the new account they get the label as transferred. How should I compare emails? The uid is different on each server so I think using the TO: FROM: and DATE: TIME: would work. How do I compare emails in this way? How to I get the TO: FROM: DATE: TIME: from one email to reach for the same email in the other account. Sample error from google migration app. 2011-08-16T16:47:47.141-06:00 808 E:Network ExchangeMigration!WinHttp::ExecuteHttpRequestIStreamResponse @ 696 ( gmetanias at domain.com )> Response: Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is invalid. 2011-08-16T16:47:47.141-06:00 808 E:Migration ExchangeMigration!EmailUploader::HandleStatus @ 462 (gmetanias at domain.com)> Permanent Message Failure, skipping the message!. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!IMAPMessageWrapper::GetMessageSentTime @ 154 ( gmetanias at domain.com )> Failed with 0x80004005, last successful line = 151. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!IMAPMessageWrapper::GetMessageReceivedTime @ 170 ( gmetanias at domain.com )> Failed with 0x80004001, last successful line = 168. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!GetMessageDescription @ 198 (gmetanias at domain.com)> Sent: 2011-08-16T22:47:47.000Z. Received: 2011-08-16T22:47:47.000Z. Size: 196114. Subject RE: ppt templates. -- Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From noonslists at gmail.com Thu Aug 18 21:02:52 2011 From: noonslists at gmail.com (Noon Silk) Date: Fri, 19 Aug 2011 11:02:52 +1000 Subject: nose + processes + xunit In-Reply-To: References: Message-ID: Has anyone had any trouble with this setup? I am in a situation where, the tests run fine when I don't include "--processes=N", however, when I *do* do that, they exit early? The reason I think they exit, is that I'm actually running a different executable, and I load it like so: retcode = subprocess.call(["start /wait myprog.exe"], shell=True) Now, note that this is on Windows 7; the "start /wait" does basically exactly what you think. *And indeed it operates correctly in a single process*, but when nose tries to run multi-process, it fails to block, and the test executes far sooner than it should. Indeed, Nose claims that it ran 0 tests, when it actually at least ran 1! So, I think the myprog.exe is sending some signal to kill it. It so happens that start has a "/B" ?parameter that may also help here, but actually it doesn't. The result is that I don't get any further output from the test (that is, the xunit xml isn't generated, and even the console doesn't report anything as having happened). Interested in thoughts ... -- Noon Silk Fancy a quantum lunch? http://groups.google.com/group/quantum-lunch?hl=en "Every morning when I wake up, I experience an exquisite joy ? the joy of being this signature." From steve+comp.lang.python at pearwood.info Thu Aug 18 21:42:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 11:42:24 +1000 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <4e4dbf81$0$30004$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: >> for x in list_of_strings: >> list_of_variables.append(eval(x)) >> > > If this really is what you need, you can simplify it by using the > globals() dictionary - it's a regular dictionary whose contents are > all the global variables in your current module. Inside a function, > use locals() instead. You can use locals outside of a function too, because it just returns globals(). Lookup of names in locals/globals is much safer than eval, particularly if there is any risk that the list of names comes from an untrusted or potentially hostile source. list_of_strings = ['red', 'blue', '__import__("os").system("echo I just p0wned your system")', 'green', 'yellow'] (The simplest way out of a billion to cause grief.) Code injection attacks are the first and second most common form of security vulnerability, ahead of even buffer overflows. Please don't add to the list. http://cwe.mitre.org/top25/?2011 (Oh, and if you think that protecting against code injection attacks while still using eval or exec is simple, please step away from the keyboard.) -- Steven From srehtvandy at gmail.com Thu Aug 18 21:44:58 2011 From: srehtvandy at gmail.com (luvspython) Date: Thu, 18 Aug 2011 18:44:58 -0700 (PDT) Subject: 'super' object has no attribute '__setitem__' Message-ID: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> I'm using Python 2.7 and the code below fails at the 'super' statement in the __setitem__ function in the HistoryKeeper class. The error is: 'super' object has no attribute '_setitem__' Can anyone please tell me why and how to fix it? (I've googled endlessly and I don't see the problem.) [The code will seem silly as it is, because it's pared down to show the example. The goal is that multiple classes, like the Vehicle class below, will inherit HistoryKeeper. History keeper overloads __setitem__ and will eventually keep a running history every time an attribute of any of the inheriting classes is changed.] Thanks in advance .... class HistoryKeeper(object): def __init__(self, args): for arg, value in args.items(): if arg != 'self': self.__setitem__(arg, value) def __setitem__(self, item, value): super(HistoryKeeper, self).__setitem__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): args = locals() super(Vehicle, self).__init__(args) if __name__ == "__main__": car = Vehicle('TAG123', 'FORD', 'Model A') print car.make From benjamin at python.org Thu Aug 18 22:05:34 2011 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 19 Aug 2011 02:05:34 +0000 (UTC) Subject: 'super' object has no attribute =?utf-8?b?J19fc2V0aXRlbV9fJw==?= References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: luvspython gmail.com> writes: > def __setitem__(self, item, value): > super(HistoryKeeper, self).__setitem__(item, value) object has no __setitem__. Are you looking for __setattr__? > > class Vehicle(HistoryKeeper): > def __init__(self, tag, make, model): > args = locals() This is hideous by the way. From mrjean1 at gmail.com Thu Aug 18 22:07:06 2011 From: mrjean1 at gmail.com (MrJean1) Date: Thu, 18 Aug 2011 19:07:06 -0700 (PDT) Subject: Measure the amount of memory used? References: Message-ID: <52d4c51b-e820-4676-9273-aeef1a5030e1@e20g2000prn.googlegroups.com> Take a look it this recipe (for Linux only): /Jean On Aug 18, 8:08?am, Jack Bates wrote: > I wrote a content filter for Postfix with Python,https://github.com/jablko/cookie > > It should get started once, and hopefully run for a long time - so I'm > interested in how it uses memory: > > ?1) How does the amount of memory used change as it runs? > > ?2) How does the amount of memory used change as I continue to hack on > it, and change the code? > > My naive thought was that I'd periodically append to a file, the virtual > memory size from /proc/[pid]/stat and a timestamp. From this a could > make a graph of the amount of memory used as my content filter runs, and > I could compare two graphs to get a clue whether this amount changed as > I continue to hack > > ?- but some Googling quickly revealed that measuring memory is actually > quite complicated? Neither the virtual memory size nor the "resident set > size" accurately measure the amount of memory used by a process > > Has anyone else measured the memory used by a Python program? How did > you do it? From ericsnowcurrently at gmail.com Thu Aug 18 22:07:12 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 18 Aug 2011 20:07:12 -0600 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 7:44 PM, luvspython wrote: > I'm using Python 2.7 and the code below fails at the 'super' statement > in the __setitem__ function in the HistoryKeeper class. ?The error is: > ? 'super' object has no attribute '_setitem__' > > Can anyone please tell me why and how to fix it? ? (I've googled > endlessly and I don't see the problem.) > > [The code will seem silly as it is, because it's pared down to show > the example. ?The goal is that multiple classes, like the Vehicle > class below, will inherit HistoryKeeper. ?History keeper overloads > __setitem__ and will eventually keep a running history every time an > attribute of any of the inheriting classes is changed.] > > Thanks in advance .... > > > class HistoryKeeper(object): > ? ?def __init__(self, args): > ? ? ? ?for arg, value in args.items(): > ? ? ? ? ? ?if arg != 'self': > ? ? ? ? ? ? ? ?self.__setitem__(arg, value) > > ? ?def __setitem__(self, item, value): > ? ? ? ?super(HistoryKeeper, self).__setitem__(item, value) > > > class Vehicle(HistoryKeeper): > ? ?def __init__(self, tag, make, model): > ? ? ? ?args = locals() > ? ? ? ?super(Vehicle, self).__init__(args) > > > if __name__ == "__main__": > ? ?car = Vehicle('TAG123', 'FORD', 'Model A') > ? ?print car.make Did you mean to use __setattr__ instead? object, the base class of HistoryKeeper, does not have a __setitem__ method, hence the AttributeError. super() is a proxy for the next class in the MRO, typically the base class of your class. Keep in mind that is equivalent to . However, is equivalent to . see: http://docs.python.org/reference/datamodel.html#object.__setattr__ http://docs.python.org/reference/datamodel.html#object.__setitem__ http://docs.python.org/library/functions.html#super -eric > -- > http://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Thu Aug 18 22:10:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 12:10:12 +1000 Subject: List spam References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> gene heskett wrote: >> But I'd like to return the question. What's wrong with nntp? > > The sheer volume of traffic eats 99% of an ISP's bandwidth. I doubt that very much, particularly if the ISP drops the binary newsgroups. My ISP, Internode, has provided nntp for many years. For a while a few years back they dropped binary newsgroups, but thay have brought them back. They wouldn't do that if there wasn't a clear demand for it, and if they didn't believe that on the balance, providing free Usenet access to customers didn't pay for itself. These days, many big ISPs complain about bittorrent using up their bandwidth. I call shenanigans. That's like my local bottle shop complaining that 99% of their sales comes from wine, and that stocking all that wine takes away valuable shelf space that could be used for imported Romanian beers and Chinese whiskey (no offense to anyone who likes Romanian beer or Chinese whiskey). It's a nonsense claim -- if your customers want to use the bandwidth they're paying for on bittorrent, or any other protocol, what difference does it make to you? It's not like you have to install a second Interweb tube just for bittorrent, or that bittorrent packets cost more than HTTP packets. Fer fecks sake, the ISP doesn't even have to run a bittorrent server! It's practically free money to the ISP, packets go in, packets go out, they don't have to do a bloody thing with them. Now, an ISP might not have the bandwidth to supply all the needs of their customers, that's a separate issue. But complaining that the problem is specifically because they use bittorrent, as if it would disappear if they changed to HTTP, is bogus. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 18 22:23:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 12:23:09 +1000 Subject: List spam References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e4dc90d$0$29983$c3e8da3$5496439d@news.astraweb.com> Alain Ketterlin wrote: > "Jason Staudenmayer" writes: > >> I really like this list as part of my learning tools but the amount of >> spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I'm using nntp to read this newsgroup (through an academic server). > No spam at all. I'm also using nntp (Usenet) and see very little spam. There was a flurry of about ten *extremely* obnoxious pr0n spams in a row, and the occasional odd one here or there, but generally I see hardly any. It is ironic that some people say that the solution to the spam problem is to move to Google Groups, because most of the spam comes *from* Google Groups. -- Steven From grrrrr at rrrrr.com Thu Aug 18 22:24:44 2011 From: grrrrr at rrrrr.com (Grummble) Date: Thu, 18 Aug 2011 22:24:44 -0400 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: On 08/16/2011 12:32 AM, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. > I modified something similar to: http://code.activestate.com/recipes/551780-win-services-helper/ and it was in production for several years without any issues. Specifically it processed orders generated by a customer's MRP system, delivered to us via LPR, then processed into a format our in house windows hosted picking/shipping system could digest. Availability was a *major* requirement, and it worked flawlessly. From gheskett at wdtv.com Thu Aug 18 22:35:30 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 22:35:30 -0400 Subject: List spam In-Reply-To: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201108182235.30272.gheskett@wdtv.com> On Thursday, August 18, 2011 10:23:49 PM Steven D'Aprano did opine: > gene heskett wrote: > >> But I'd like to return the question. What's wrong with nntp? > > > > The sheer volume of traffic eats 99% of an ISP's bandwidth. > > I doubt that very much, particularly if the ISP drops the binary > newsgroups. [...] > It's not like you have to install a second Interweb tube just for > bittorrent, or that bittorrent packets cost more than HTTP packets. Fer > fecks sake, the ISP doesn't even have to run a bittorrent server! It's > practically free money to the ISP, packets go in, packets go out, they > don't have to do a bloody thing with them. Except pay for the bandwidth to get the bytes into their system. > Now, an ISP might not have the bandwidth to supply all the needs of > their customers, that's a separate issue. Yes it is, which is why Hughs has a bandwidth limit cap they lift in the middle of the night when overall traffic is zilch. The bird(s) only have so much bandwidth and it costs tens of millions to 'lay another fiber' when its 22,300 miles up. OTOH, they have to pay for that bandwidth 24/7, so if they can move the relatively few high traffic folks usage to 3-5 AM, they can service more people watching old black and white John Holmes clips at 9-11pm. ;-) > But complaining that the > problem is specifically because they use bittorrent, as if it would > disappear if they changed to HTTP, is bogus. Agreed, that's 100% a red herring. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Q: How many mathematicians does it take to screw in a light bulb? A: One. He gives it to six Californians, thereby reducing the problem to the earlier joke. From sjbenner at gmail.com Thu Aug 18 23:00:55 2011 From: sjbenner at gmail.com (Josh Benner) Date: Thu, 18 Aug 2011 20:00:55 -0700 Subject: Help with regular expression in python In-Reply-To: <201108181703.06278.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> Message-ID: On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk wrote: > Hi guys, > > thanks for the suggestions. I had tried the white space before as well (to > no > avail). So here is the expression i am using (based on suggestions), but > still > no success: > > instance_linetype_pattern_str =\ > r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > results = instance_linetype_pattern.findall(line) > print "results: "; print results > > > The match i get is: > results: > [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome > description')] > > > btw: The line to be matched (given below) is ONE line. There are no line > breaks (even though my email client adds them). > > > matt > > > If a group matches multiple times, only the last match is accessible. The matches returned represent the inner groupings of the last match found. JB-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at gonnerman.org Thu Aug 18 23:45:50 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Thu, 18 Aug 2011 22:45:50 -0500 Subject: [Python] Re: Windows service in production? In-Reply-To: <4E4BB152.5020904@timgolden.me.uk> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> <4E4BB152.5020904@timgolden.me.uk> Message-ID: <4E4DDC6E.9010405@gonnerman.org> Chiming in late here, but I've been running a very simple Python service for some time now on a number of computers. It's my Raw Print Server, available at http://newcenturycomputers.net/projects/rawprintserver.html, and I have instructions on the page for installing the Windows service version. It's really quite simple to do in plain Python; the only reason to use py2exe is if you don't want to install a full Python interpreter on the computer. But since I generally do anyway, it doesn't matter to me. -- Chris. From tjreedy at udel.edu Fri Aug 19 00:03:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Aug 2011 00:03:52 -0400 Subject: List spam In-Reply-To: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/18/2011 10:10 PM, Steven D'Aprano wrote: > Now, an ISP might not have the bandwidth to supply all the needs of their > customers, that's a separate issue. But complaining that the problem is > specifically because they use bittorrent, as if it would disappear if they > changed to HTTP, is bogus. Or changed to getting their movies via NetFlix, for instance, as Comcast *is* complaining about. I believe their real complaint is that they are only paid to move bits, and not for originating them, even though they already get several times as much per month as NetFlix. -- Terry Jan Reedy From me+list/python at ixokai.io Fri Aug 19 01:00:30 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 18 Aug 2011 22:00:30 -0700 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <4E4DEDEE.5070805@ixokai.io> On 8/15/11 9:32 PM, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. > > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. Overall, reading about Windows > services in Python is not exactly a confidence inspiring experience. > If I knew of a reference example of something reliably running in > production, I'd feel better than copying and pasting some code from a > guy's blog. Belatedly: I run a few quite major windows services which are installed at various customer sites in production, and we have no issues with it being a windows service. I basically only ever ran into two problems: 1. The lack of a console. Your service flat out /does not have/ a console, which is a slightly weird state to be in: writing to sys.stdout will fail. A print statement left in can crash things up -- even if in third-party code. Now, once you realize this is there, its easy to "fix". I end up doing something like this very early on in processing: class FakeFile: def __init__(self, fp): self._fp = fp def write(self, data): try: self._fp.write(data) except: pass # repeat with flush() sys.stdout = FakeFile(sys.stdout) sys.stderr = FakeFile(sys.stderr) That way it'll run from a regular terminal fine and write out fine, but if any stray attempts to print are left in, things will pass through fine when its running as a service. 2. Importing modules with the same names as dlls in system32 can go awry. I don't know if this is still there, I last touched this part of our code a long, long, long time ago: but my service does some manual PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy to do. It worked fine, and was stable and once going, everything worked fine. Ultimately, I have since abandoned running things as a real service directly, and wrote a "Metaservice" application we use in our company instead. It runs as a service, and executes any random series of programs beneath it, creating JOB's for each so any subprocesses of they launch all get killed together cleanly, and handling dependencies via between them through various means, and stuff like that. I just got tired of dealing with windows stuff, so. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From adam.jorgensen.za at gmail.com Fri Aug 19 01:21:25 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Fri, 19 Aug 2011 07:21:25 +0200 Subject: Windows service in production? In-Reply-To: <4E4DEDEE.5070805@ixokai.io> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <4E4DEDEE.5070805@ixokai.io> Message-ID: Yeah, we run our Python App as a service under Windows. You can look at the open-souce part of our product using http://trac.sjsoft.com/browser If you look into the code you should be able to find some stuff to do with services. Specficially, look in trunk/j5/src/j5/OS/WinService.py On 19 August 2011 07:00, Stephen Hansen wrote: > On 8/15/11 9:32 PM, snorble wrote: > > Anyone know of a Python application running as a Windows service in > > production? I'm planning a network monitoring application that runs as > > a service and reports back to the central server. Sort of a heartbeat > > type agent to assist with "this server is down, go check on it" type > > situations. > > > > If using Visual Studio and C# is the more reliable way, then I'll go > > that route. I love Python, but everything I read about Python services > > seems to have workarounds ahoy for various situations (or maybe that's > > just Windows services in general?). And there seem to be multiple > > layers of workarounds, since it takes py2exe (or similar) and there > > are numerous workarounds required there, depending on which libraries > > and functionality are being used. Overall, reading about Windows > > services in Python is not exactly a confidence inspiring experience. > > If I knew of a reference example of something reliably running in > > production, I'd feel better than copying and pasting some code from a > > guy's blog. > > Belatedly: I run a few quite major windows services which are installed > at various customer sites in production, and we have no issues with it > being a windows service. > > I basically only ever ran into two problems: > > 1. The lack of a console. Your service flat out /does not have/ a > console, which is a slightly weird state to be in: writing to sys.stdout > will fail. A print statement left in can crash things up -- even if in > third-party code. > > Now, once you realize this is there, its easy to "fix". I end up > doing something like this very early on in processing: > > class FakeFile: > def __init__(self, fp): > self._fp = fp > def write(self, data): > try: > self._fp.write(data) > except: > pass > > # repeat with flush() > > sys.stdout = FakeFile(sys.stdout) > sys.stderr = FakeFile(sys.stderr) > > That way it'll run from a regular terminal fine and write out fine, > but if any stray attempts to print are left in, things will pass through > fine when its running as a service. > > 2. Importing modules with the same names as dlls in system32 can go > awry. I don't know if this is still there, I last touched this part of > our code a long, long, long time ago: but my service does some manual > PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy > to do. > > It worked fine, and was stable and once going, everything worked fine. > > Ultimately, I have since abandoned running things as a real service > directly, and wrote a "Metaservice" application we use in our company > instead. It runs as a service, and executes any random series of > programs beneath it, creating JOB's for each so any subprocesses of they > launch all get killed together cleanly, and handling dependencies via > between them through various means, and stuff like that. I just got > tired of dealing with windows stuff, so. :) > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adiksonline at gmail.com Fri Aug 19 03:39:54 2011 From: adiksonline at gmail.com (Kingsley Adio) Date: Fri, 19 Aug 2011 00:39:54 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <1f26ef99-857c-455e-ae5f-c3dd7c19a4d2@v9g2000pri.googlegroups.com> noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! red="a string" one="another string" maple="a file path" old=["red", "one", "maple"] newList=map(eval, old) From fetchinson at googlemail.com Fri Aug 19 04:17:01 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 19 Aug 2011 10:17:01 +0200 Subject: OT Message-ID: I'll be 59 in a couple of months. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From stefan_ml at behnel.de Fri Aug 19 04:29:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Aug 2011 10:29:50 +0200 Subject: OT In-Reply-To: References: Message-ID: Daniel Fetchinson, 19.08.2011 10:17: > I'll be 59 in a couple of months. That's actually more on topic for one of the alt.test newsgroups. Stefan From aspineux at gmail.com Fri Aug 19 05:11:07 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 19 Aug 2011 02:11:07 -0700 (PDT) Subject: Word Perfect integration References: Message-ID: On Aug 18, 7:00?pm, Ethan Furman wrote: > I have WordPerfect v13 which we are currently using for letter merges. > I would like to automate this with Python instead of learning the WP > Macro language. > > Does anyone have any pointers? > paper letter or eletronic mail merger ? What you need is : - 1. write a "template" in WP with tag like
- 2. make a database with the corresponding data - 3. replace tag by data from a database, and generate a new WP document - 4. print all these ducument. 1 & 2 are not programming related 3. Should not be impossible, look at the wp binary file if you can find and replace the tag 4. More difficult: can you start a print job from a command line ? or put all file in a directory, then start WP and ask him to print all file in this directory or create print job and put them in a queue and hope WP will process the queue. Regards > ~Ethan~ Alain From alec.taylor6 at gmail.com Fri Aug 19 05:11:18 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 19:11:18 +1000 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: :P Personally, I use LaTeX, which fits all my requirements. On Fri, Aug 19, 2011 at 5:24 AM, Ethan Furman wrote: > Alec Taylor wrote: >> >> wow, people still use WordPerfect? > > Them's fightin' words right there! ?:) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From pwoolcoc at gmail.com Fri Aug 19 06:14:11 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Fri, 19 Aug 2011 06:14:11 -0400 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: If you really want __setitem__ and not __setattr__, you should change the base class to 'dict'. Or 'import UserDict' and use that for the base class. On Aug 18, 2011 9:45 PM, "luvspython" wrote: > I'm using Python 2.7 and the code below fails at the 'super' statement > in the __setitem__ function in the HistoryKeeper class. The error is: > 'super' object has no attribute '_setitem__' > > Can anyone please tell me why and how to fix it? (I've googled > endlessly and I don't see the problem.) > > [The code will seem silly as it is, because it's pared down to show > the example. The goal is that multiple classes, like the Vehicle > class below, will inherit HistoryKeeper. History keeper overloads > __setitem__ and will eventually keep a running history every time an > attribute of any of the inheriting classes is changed.] > > Thanks in advance .... > > > class HistoryKeeper(object): > def __init__(self, args): > for arg, value in args.items(): > if arg != 'self': > self.__setitem__(arg, value) > > def __setitem__(self, item, value): > super(HistoryKeeper, self).__setitem__(item, value) > > > class Vehicle(HistoryKeeper): > def __init__(self, tag, make, model): > args = locals() > super(Vehicle, self).__init__(args) > > > if __name__ == "__main__": > car = Vehicle('TAG123', 'FORD', 'Model A') > print car.make > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Aug 19 08:57:54 2011 From: roy at panix.com (Roy Smith) Date: Fri, 19 Aug 2011 08:57:54 -0400 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: In article <2ab25f69-6017-42a6-a7ef-c71bc2ee8547 at l2g2000vbn.googlegroups.com>, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! I'm not sure what you're trying to do, but explore the dictionary returned by locals(). You can do something like: loc = locals() [loc["red"], loc["one"], loc["maple"]] From ekh.johan at gmail.com Fri Aug 19 09:00:38 2011 From: ekh.johan at gmail.com (Johan Ekh) Date: Fri, 19 Aug 2011 15:00:38 +0200 Subject: Execute script from ipython Message-ID: Hi all, I have a script "myscript.py" located in "/usr/local/bin" on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Best regards, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: From matze999 at gmail.com Fri Aug 19 10:09:16 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 08:09:16 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> Message-ID: <201108190809.17040.matze999@gmail.com> Hi Josh, thanks for the reply. I am no expert so please bear with me: I thought that the {32} was supposed to match the previous expression 32 times? So how can i have all matches accessible to me? matt On Thursday, August 18, 2011, Josh Benner wrote: > On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk wrote: > > Hi guys, > > > > thanks for the suggestions. I had tried the white space before as well > > (to no > > avail). So here is the expression i am using (based on suggestions), but > > still > > no success: > > > > instance_linetype_pattern_str =\ > > > > r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' > > > > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > > results = instance_linetype_pattern.findall(line) > > print "results: "; print results > > > > > > The match i get is: > > results: > > [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: > > 0)\t:\tsome description')] > > > > > > btw: The line to be matched (given below) is ONE line. There are no line > > breaks (even though my email client adds them). > > > > > > matt > > If a group matches multiple times, only the last match is accessible. The > matches returned represent the inner groupings of the last match found. > > JB-) From jenn.duerr at gmail.com Fri Aug 19 10:32:14 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 19 Aug 2011 07:32:14 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <89a096bb-4aaa-4d21-81e2-4beecc1784b9@ea4g2000vbb.googlegroups.com> Thanks to all for your responses! Good lessons. I implemented something like what Jerry Hill suggested (dictionary), which works well for my purposes. The list of strings that is being passed into this code is also provided by something I wrote so I do trust what is being sent. Might use what AB suggested down the line, as tool expands. Thanks! From jason at powerpull.net Fri Aug 19 10:41:49 2011 From: jason at powerpull.net (Jason Friedman) Date: Fri, 19 Aug 2011 14:41:49 +0000 Subject: Help with regular expression in python In-Reply-To: <201108190809.17040.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: > Hi Josh, > thanks for the reply. I am no expert so please bear with me: > I thought that the {32} was supposed to match the previous expression 32 > times? > > So how can i have all matches accessible to me? $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description' >>> import re >>> re.findall(r"\d\.\d+e\+\d+", data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From lzlu123 at gmail.com Fri Aug 19 11:00:21 2011 From: lzlu123 at gmail.com (lzlu123) Date: Fri, 19 Aug 2011 08:00:21 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell Message-ID: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> I have an instrument that has a RS232 type serial comm port and I need to connect to and control. I use Python 3.2 in Windows XP, plus pySerial module. I have a problem when I execute a script consisting of statements that open the comm port, configure it, write strings to and receive strings from it. Thoese strings aer either commands pertinent to the instrument (control) or responses from the instrument (response). When those statements are executed in a python interpreter interactively (at >>>), I get what I expect and the results are good and correct. However, when I execute the script, either being invoked within the interpreter or run file, I don?t get what I want. The statements in the script is the same as what I use in the interactive interpreter. Why do I get the strange behavior and how can I change the script to make it to behave like in interactive interpreter? ----------------------script----------------------- def read(comport): wrt_str=b'movt 3000'+b'\r\n' ret_str=comport.write(wrt_str) wrt_str=b'scan'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines() #########1 wrt_str=b'hllo'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines()#########2 ---------------------------------------------------------- The problem is with the lines above with #######. In interactive mode, there is about 1 second delay at #1, and 9 seonds delay at #2. I get correct responses there. However, if I execute the script above, there is no delay at all and I get incorrect results (garbage). I set the read timeout to 0 in comm port set up, as comport.timeout=0 So the comport should be in blocking mode if it waits for the end of line or end of file. I tried many things, like exec (execfile in 2.7), but at no avail. I have an update to the original post I made a few days ago. I think I know what the problem is and want to know if anyone has a solution: After putting "print" and "time.sleep(delay)" after every statement, I found when the script is running, it appears going around the pyserial statement, such as "comport.write(..)" or "comport.readlines(...)" while the pyserial command is executing (appearing as waiting and busying doing some thing, you know serial port is slow). So for example, when I exec all statements in a python interactive shell, I am not able to type and run a new statement if the previous one is not returned. Let's ay, if comport.readlines() is not returning, I can't type and run the next comport.write(...) statemtn. However, in a script that is running, if the comport.readlines() is busy reading, the next statement is running, if the next statement happens to be a comport.write() which will abort the reading. Is there any way to force the python script to behave like running exactly sequentially? From wxjmfauth at gmail.com Fri Aug 19 11:07:51 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 08:07:51 -0700 (PDT) Subject: How to print non-printable chars?? References: <6c15a4a4-02a9-4a04-bd3a-0cb88a96470f@v7g2000vbk.googlegroups.com> Message-ID: <1d1b4ed7-5a08-48fa-b512-62d42ec678ed@m38g2000vbn.googlegroups.com> On 18 ao?t, 22:44, coldpizza wrote: > > > ... > > In a web/html environment or in broken ascii-only consoles like the > one on windows ... C:\Users\Jean-Michel>echo 'Cet ?uf de L?titia co?te un ?uro' 'Cet ?uf de L?titia co?te un ?uro' C:\Users\Jean-Michel>c:\Python27\python Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print 'Cet ?uf de L?titia co?te un ?uro' Cet ?uf de L?titia co?te un ?uro >>> import sys >>> u = unicode('Cet ?uf de L?titia co?te un ?uro', sys.stdin.encoding) >>> print u.encode(sys.stdout.encoding) Cet ?uf de L?titia co?te un ?uro >>> C:\Users\Jean-Michel>c:\Python32\python Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print('Cet ?uf de L?titia co?te un ?uro') Cet ?uf de L?titia co?te un ?uro >>> PS Cet ?uf de L?titia co?te un ?uro -> This L?titia's egg costs one ?uro' PS2 "?" does not require special attention. PS3 To the original question: This not a *coding* issue, it is a character *representation* question. jmf From Yingjie.Lin at mssm.edu Fri Aug 19 11:08:14 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 11:08:14 -0400 Subject: HTML client sctript Message-ID: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically "uses" this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Thank you. - Yingjie From clp2 at rebertia.com Fri Aug 19 11:11:38 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 08:11:38 -0700 Subject: Execute script from ipython In-Reply-To: References: Message-ID: On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > Hi all, > I have a script "myscript.py" located in "/usr/local/bin" on my linux box. > I can execute it in ipython with > > run /usr/local/bin/myscript.py > > but not with > > run myscript.py > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > What should I do to correct this? Given that %run takes a filename and not a module name, I doubt PYTHONPATH matters. ipython's docs for %run don't seem to indicate that a search of any kind is performed. So, I'd say you have to either pass a valid absolute or relative path to myscript.py, or run myscript.py from bash instead of ipython. Changing your script's shebang line to ipython might also work (haven't tried it myself). Or you could try patching ipython's run() function to add this search feature you desire. Cheers, Chris -- http://rebertia.com From matze999 at gmail.com Fri Aug 19 11:20:16 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 09:20:16 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: <4E4E7F30.7010205@gmail.com> Hi, thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. anyway, thanks though matt On 8/19/2011 8:41 AM, Jason Friedman wrote: >> Hi Josh, >> thanks for the reply. I am no expert so please bear with me: >> I thought that the {32} was supposed to match the previous expression 32 >> times? >> >> So how can i have all matches accessible to me? > $ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> data > '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) : some > description' >>>> import re >>>> re.findall(r"\d\.\d+e\+\d+", data) > ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', > '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', > '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', > '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', > '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', > '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', > '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', > '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From ppv.grps at gmail.com Fri Aug 19 11:31:06 2011 From: ppv.grps at gmail.com (Forafo San) Date: Fri, 19 Aug 2011 08:31:06 -0700 (PDT) Subject: Replacement for the shelve module? Message-ID: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an "ls" did not make sense, etc.). Thanks in advance for your suggestions. From kwatford at gmail.com Fri Aug 19 11:49:38 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 19 Aug 2011 11:49:38 -0400 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Fri, Aug 19, 2011 at 11:31 AM, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: For what you're doing, I would give PyTables a try. From wxjmfauth at gmail.com Fri Aug 19 11:50:51 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 08:50:51 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: On 19 ao?t, 17:20, Matt Funk wrote: > Hi, > thanks for the suggestion. I guess i had found another way around the > problem as well. But i really wanted to match the line exactly and i > wanted to know why it doesn't work. That is less for the purpose of > getting the thing to work but more because it greatly annoys me off that > i can't figure out why it doesn't work. I.e. why the expression is not > matches {32} times. I just don't get it. > re is not always the right tool to be used. Without more precisions: >>> s = '2.201000e+01 2.150000e+01 2.150000e+01\ ... : (instance: 0) : some description' >>> s 2.201000e+01 2.150000e+01 2.150000e+01 : (instance: 0) : some description >>> s[:s.find(':')] 2.201000e+01 2.150000e+01 2.150000e+01 >>> s[:s.find(':')].split() ['2.201000e+01', '2.150000e+01', '2.150000e+01'] >>> >>> jmf From t at jollybox.de Fri Aug 19 11:54:29 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 19 Aug 2011 17:54:29 +0200 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: <4E4E8735.4090509@jollybox.de> On 19/08/11 17:31, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). > > Thanks in advance for your suggestions. Firstly, since when is shelve deprecated? Shouldn't there be a deprecation warning on http://docs.python.org/dev/library/shelve.html ? If you want to keep your current approach of having an object containing all the data for each symbol, you will have to think about how to serialise the data, as well as how to store the documents/objects individually. For the serialisation, you can use pickle (as shelve does) or JSON (probably better because it's easier to edit directly, and therefore easier to debug). To store these documents, you could use a huge pickle'd Python dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; this is what shelve uses), or simple the file system: one file per serialised object. Looking at your use case, however, I think what you really should use is a SQL database. SQLite is part of Python and will do the job nicely. Just use a single table with three columns: symbol, date, value. Thomas From alain at dpt-info.u-strasbg.fr Fri Aug 19 12:00:35 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Aug 2011 18:00:35 +0200 Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Matt Funk writes: > thanks for the suggestion. I guess i had found another way around the > problem as well. But i really wanted to match the line exactly and i > wanted to know why it doesn't work. That is less for the purpose of > getting the thing to work but more because it greatly annoys me off that > i can't figure out why it doesn't work. I.e. why the expression is not > matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times "a space followed by a number". Using Jason's regexp, you can build the regexp step by step: number = r"\d\.\d+e\+\d+" numbersequence = r"%s( %s){31}" % (number,number) There are better ways to build your regexp, but I think this one is convenient to answer your question. You still have to append what will match the end of the line. -- Alain. P/S: please do not top-post >> $ python >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) >> [GCC 4.4.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> data >> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 >> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 >> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 >> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 >> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 >> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 >> 2.150000e+01 2.199000e+01 : (instance: 0) : some >> description' >>>>> import re >>>>> re.findall(r"\d\.\d+e\+\d+", data) >> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', >> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', >> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', >> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', >> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', >> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', >> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', >> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From gordon at panix.com Fri Aug 19 12:02:27 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 16:02:27 +0000 (UTC) Subject: HTML client sctript References: Message-ID: In Yingjie Lin writes: > Hi Python users, > I am maintaining a website written with Python CGI scripts. To make > sure the website is working well, I would like to have a script which > automatically "uses" this website and checks it's output everyday. It > would be better if this script runs from the clients' side. > Could any one suggest any Python modules, articles, tutorials, ect. that > might be helpful? Mechanize seems like what you want. It's built on top of urllib2. http://wwwsearch.sourceforge.net/mechanize/ -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ppv.grps at gmail.com Fri Aug 19 12:21:48 2011 From: ppv.grps at gmail.com (Forafo San) Date: Fri, 19 Aug 2011 09:21:48 -0700 (PDT) Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Aug 19, 11:54?am, Thomas Jollans wrote: > On 19/08/11 17:31, Forafo San wrote: > > > > > > > > > > > Folks, > > What might be a good replacement for the shelve module, but one that > > can handle a few gigs of data. I'm doing some calculations on daily > > stock prices and the result is a nested list like: > > > [[date_1, floating result 1], > > ?[date_2, floating result 2], > > ... > > ?[date_n, floating result n]] > > > However, there are about 5,000 lists like that, one for each stock > > symbol. Using the shelve module I could easily save them to a file > > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > > data. But shelve is deprecated AND when a lot of data is written > > shelve was acting weird (refusing to write, filesizes reported with an > > "ls" did not make sense, etc.). > > > Thanks in advance for your suggestions. > > Firstly, since when is shelve deprecated? Shouldn't there be a > deprecation warning onhttp://docs.python.org/dev/library/shelve.html? > > If you want to keep your current approach of having an object containing > all the data for each symbol, you will have to think about how to > serialise the data, as well as how to store the documents/objects > individually. For the serialisation, you can use pickle (as shelve does) > or JSON (probably better because it's easier to edit directly, and > therefore easier to debug). > To store these documents, you could use a huge pickle'd Python > dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; > this is what shelve uses), or simple the file system: one file per > serialised object. > > Looking at your use case, however, I think what you really should use is > a SQL database. SQLite is part of Python and will do the job nicely. > Just use a single table with three columns: symbol, date, value. > > Thomas Sorry. There is no indication that shelve is deprecated. I was using it on a FreeBSD system and it turns out that the bsddb module is deprecated and confused it with the shelve module. Thanks Ken and Thomas for your suggestions -- I will play around with both and pick one. From clp2 at rebertia.com Fri Aug 19 12:45:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 09:45:59 -0700 Subject: HTML client sctript In-Reply-To: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> References: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> Message-ID: On Fri, Aug 19, 2011 at 8:08 AM, Yingjie Lin wrote: > Hi Python users, > > I am maintaining a website written with Python CGI scripts. To make sure the website is working well, > I would like to have a script which automatically "uses" this website and checks it's output everyday. It > would be better if this script runs from the clients' side. > > Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Selenium: http://seleniumhq.org/ Cheers, Chris From saraanderson24 at gmail.com Fri Aug 19 12:55:29 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Fri, 19 Aug 2011 09:55:29 -0700 (PDT) Subject: WATCH WORLD MOST HILARIOUS FUNNY VIDEOS EVER. Message-ID: See Worlds Most Beautiful Places Ever. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD MOST HILARIOUS FUNNY VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From fuentesej at gmail.com Fri Aug 19 13:15:20 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 10:15:20 -0700 (PDT) Subject: Help on PyQt4 QProcess Message-ID: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal "finished(int)" of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x="started":print(x)) # connect pro.connect(pro, SIGNAL("finished(int)"), lambda x="finished":print(x)) pro.start('python',['hello.py']) # star hello.py program (contain print("hello world!")) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) I'm using Python 3.2 and PyQt 4.8.4 under winxp 32bit. best regards, From miki.tebeka at gmail.com Fri Aug 19 13:15:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 19 Aug 2011 10:15:53 -0700 (PDT) Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: You might check one of many binary encoders (like Avro, Thrift ...). The other option is to use a database, sqlite3 is pretty fast (if you schema is fixed). Otherwise you can look at some NoSQL ones (like MongoDB). From matze999 at gmail.com Fri Aug 19 13:33:49 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 11:33:49 -0600 Subject: Help with regular expression in python In-Reply-To: <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108191133.50170.matze999@gmail.com> On Friday, August 19, 2011, Alain Ketterlin wrote: > Matt Funk writes: > > thanks for the suggestion. I guess i had found another way around the > > problem as well. But i really wanted to match the line exactly and i > > wanted to know why it doesn't work. That is less for the purpose of > > getting the thing to work but more because it greatly annoys me off that > > i can't figure out why it doesn't work. I.e. why the expression is not > > matches {32} times. I just don't get it. > > Because a line is not 32 times a number, it is a number followed by 31 > times "a space followed by a number". Using Jason's regexp, you can > build the regexp step by step: > > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}" % (number,number) That didn't work either. Using the (modified (where the (.+) matches the end of the line)) expression as: number = r"\d\.\d+e\+\d+" numbersequence = r"%s( %s){31}(.+)" % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. thanks for all the help matt > > There are better ways to build your regexp, but I think this one is > convenient to answer your question. You still have to append what will > match the end of the line. > > -- Alain. > > P/S: please do not top-post > > >> $ python > >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) > >> [GCC 4.4.3] on linux2 > >> Type "help", "copyright", "credits" or "license" for more information. > >> > >>>>> data > >> > >> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > >> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > >> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > >> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > >> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > >> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > >> 2.150000e+01 2.199000e+01 : (instance: 0) : some > >> description' > >> > >>>>> import re > >>>>> re.findall(r"\d\.\d+e\+\d+", data) > >> > >> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', > >> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', > >> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', > >> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', > >> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', > >> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', > >> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', > >> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From robert.kern at gmail.com Fri Aug 19 13:45:32 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Aug 2011 12:45:32 -0500 Subject: Replacement for the shelve module? In-Reply-To: References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On 8/19/11 10:49 AM, Ken Watford wrote: > On Fri, Aug 19, 2011 at 11:31 AM, Forafo San wrote: >> Folks, >> What might be a good replacement for the shelve module, but one that >> can handle a few gigs of data. I'm doing some calculations on daily >> stock prices and the result is a nested list like: > > For what you're doing, I would give PyTables a try. For a few gigs of stock price data, this is what I use. Much better than SQLite for that amount of data. -- 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 phil at riverbankcomputing.com Fri Aug 19 13:56:30 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Fri, 19 Aug 2011 18:56:30 +0100 Subject: Help on PyQt4 QProcess In-Reply-To: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Message-ID: On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes wrote: > Dear friends, > > I need execute an external program from a gui using PyQt4, to avoid > that hang the main thread, i must connect the signal "finished(int)" > of a QProcess to work properly. > > for example, why this program don't work? > > from PyQt4.QtCore import QProcess > pro = QProcess() # create QProcess object > pro.connect(pro, SIGNAL('started()'), lambda > x="started":print(x)) # connect > pro.connect(pro, SIGNAL("finished(int)"), lambda > x="finished":print(x)) > pro.start('python',['hello.py']) # star hello.py program > (contain print("hello world!")) > timeout = -1 > pro.waitForFinished(timeout) > print(pro.readAllStandardOutput().data()) > > output: > > started > 0 > b'hello world!\n' > > see that not emit the signal finished(int) Yes it is, and your lambda slot is printing "0" which is the return code of the process. Phil From sajjad.ahmad009 at gmail.com Fri Aug 19 14:38:34 2011 From: sajjad.ahmad009 at gmail.com (Sajjad Ahmad) Date: Fri, 19 Aug 2011 11:38:34 -0700 (PDT) Subject: Hot Girls are Looking for Sex Message-ID: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . From wxjmfauth at gmail.com Fri Aug 19 14:40:54 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 11:40:54 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> On 19 ao?t, 19:33, Matt Funk wrote: > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. > > Anyway, i think at this point i will go another route. Not sure where the > issues lies at this point. > Seen on this list: And always keep this in mind: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski, comp.lang.emacs I proposed a solution which seems to corresponds to your problem if it were better formulated... jmf From Yingjie.Lin at mssm.edu Fri Aug 19 15:09:12 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:09:12 -0400 Subject: try... except with unknown error types Message-ID: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Hi Python users, I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print "URL does not exist!" Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using "HTTPError" alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. - Yingjie From gordon at panix.com Fri Aug 19 15:14:54 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 19:14:54 +0000 (UTC) Subject: try... except with unknown error types References: Message-ID: In Yingjie Lin writes: > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > Though "urllib2.HTTPError" is the error type reported by Python, Python > doesn't recognize it as an error type name. I tried using "HTTPError" > alone too, but that's not recognized either. Have you imported urllib2 in your code? > Does anyone know what error type I should put after the except > statement? or even better: is there a way not to specify the error > types? Thank you. You can catch all exceptions by catching the base class Exception: try: some_method() except Exception, e: print "some error happened, here is the explanation:" print str(e) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From Yingjie.Lin at mssm.edu Fri Aug 19 15:15:04 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:15:04 -0400 Subject: HTML client sctript In-Reply-To: References: Message-ID: <326A894F-F639-4D51-A505-AE98A9DF9BC0@mssm.edu> Hi John and Chris, Thanks for the help. I looked at both and think that mechanize suits my needs better, since it simply needs a python script and doesn't depend on Firefox. Yingjie > From: John Gordon > Mechanize seems like what you want. It's built on top of urllib2.http://wwwsearch.sourceforge.net/mechanize/ > > From: Chris Rebert > Selenium:http://seleniumhq.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at gmail.com Fri Aug 19 15:22:35 2011 From: thudfoo at gmail.com (xDog Walker) Date: Fri, 19 Aug 2011 12:22:35 -0700 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <201108191222.35687.thudfoo@gmail.com> On Friday 2011 August 19 12:09, Yingjie Lin wrote: > Hi Python users, > > I have been using try...except statements in the situations where I can > expect a certain type of errors might occur. But sometimes I don't exactly > know the possible error types, or sometimes I just can't "spell" the error > types correctly. For example, > > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python > doesn't recognize it as an error type name. I tried using "HTTPError" alone > too, but that's not recognized either. > > Does anyone know what error type I should put after the except statement? > or even better: is there a way not to specify the error types? Thank you. You probably need to import urllib2 before you can use urllib2.HTTPError. Otherwise, you can try using the base class: except Exception, e: -- I have seen the future and I am not in it. From schesis at gmail.com Fri Aug 19 15:30:55 2011 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 19 Aug 2011 15:30:55 -0400 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: : On 19 August 2011 15:09, Yingjie Lin wrote: > > I have been using try...except statements in the situations where I can expect a certain type of errors might occur. > But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. > For example, > > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. > I tried using "HTTPError" alone too, but that's not recognized either. > > Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify > the error types? Thank you. You should always specify the error type, so that your error-handling code won't attempt to handle an error it didn't anticipate and cause even more problems. In this case, I think it's just that you haven't imported HTTPError into your namespace - if you do, it works: >>> from urllib2 import urlopen, HTTPError >>> try: ... response = urlopen("http://google.com/invalid") ... except HTTPError: ... print "URL does not exist!" ... URL does not exist! >>> Alternatively: >>> import urllib2 >>> try: ... response = urllib2.urlopen("http://google.com/invalid") ... except urllib2.HTTPError: ... print "URL does not exist!" ... URL does not exist! >>> A careful look at the difference between these two ought to make it clear what's going on. -[]z. From Yingjie.Lin at mssm.edu Fri Aug 19 15:35:56 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:35:56 -0400 Subject: try... except with unknown error types In-Reply-To: References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <5082D71A-8346-47E4-BD20-DC3A96D949E8@mssm.edu> Hi Zero, I see! This is very helpful. Thank you. - Yingjie On Aug 19, 2011, at 3:30 PM, Zero Piraeus wrote: > : > > On 19 August 2011 15:09, Yingjie Lin wrote: >> >> I have been using try...except statements in the situations where I can expect a certain type of errors might occur. >> But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. >> For example, >> >> try: >> response = urlopen(urljoin(uri1, uri2)) >> except urllib2.HTTPError: >> print "URL does not exist!" >> >> Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. >> I tried using "HTTPError" alone too, but that's not recognized either. >> >> Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify >> the error types? Thank you. > > You should always specify the error type, so that your error-handling > code won't attempt to handle an error it didn't anticipate and cause > even more problems. > > In this case, I think it's just that you haven't imported HTTPError > into your namespace - if you do, it works: > >>>> from urllib2 import urlopen, HTTPError >>>> try: > ... response = urlopen("http://google.com/invalid") > ... except HTTPError: > ... print "URL does not exist!" > ... > URL does not exist! >>>> > > Alternatively: > >>>> import urllib2 >>>> try: > ... response = urllib2.urlopen("http://google.com/invalid") > ... except urllib2.HTTPError: > ... print "URL does not exist!" > ... > URL does not exist! >>>> > > A careful look at the difference between these two ought to make it > clear what's going on. > > -[]z. From srehtvandy at gmail.com Fri Aug 19 15:37:08 2011 From: srehtvandy at gmail.com (Bob Vandy) Date: Fri, 19 Aug 2011 15:37:08 -0400 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: I'm pretty sure I'd actually read the first 2 links you point to, but the difference between __setattr__ and __setitem__ still never registered with me -- perhaps partly because even the discussion of __setattr__ discusses adding an entry to the "*dictionary* of instance attributes". *MANY* thanks for your help! On Thu, Aug 18, 2011 at 10:07 PM, Eric Snow wrote: > On Thu, Aug 18, 2011 at 7:44 PM, luvspython wrote: > > I'm using Python 2.7 and the code below fails at the 'super' statement > > in the __setitem__ function in the HistoryKeeper class. The error is: > > 'super' object has no attribute '_setitem__' > > > > Can anyone please tell me why and how to fix it? (I've googled > > endlessly and I don't see the problem.) > > > > [The code will seem silly as it is, because it's pared down to show > > the example. The goal is that multiple classes, like the Vehicle > > class below, will inherit HistoryKeeper. History keeper overloads > > __setitem__ and will eventually keep a running history every time an > > attribute of any of the inheriting classes is changed.] > > > > Thanks in advance .... > > > > > > class HistoryKeeper(object): > > def __init__(self, args): > > for arg, value in args.items(): > > if arg != 'self': > > self.__setitem__(arg, value) > > > > def __setitem__(self, item, value): > > super(HistoryKeeper, self).__setitem__(item, value) > > > > > > class Vehicle(HistoryKeeper): > > def __init__(self, tag, make, model): > > args = locals() > > super(Vehicle, self).__init__(args) > > > > > > if __name__ == "__main__": > > car = Vehicle('TAG123', 'FORD', 'Model A') > > print car.make > > Did you mean to use __setattr__ instead? object, the base class of > HistoryKeeper, does not have a __setitem__ method, hence the > AttributeError. super() is a proxy for the next class in the MRO, > typically the base class of your class. > > Keep in mind that is equivalent to > . However, > is equivalent to . > > see: > > http://docs.python.org/reference/datamodel.html#object.__setattr__ > http://docs.python.org/reference/datamodel.html#object.__setitem__ > http://docs.python.org/library/functions.html#super > > -eric > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Fri Aug 19 15:55:01 2011 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 19 Aug 2011 12:55:01 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> On 08/19/2011 11:33 AM, Matt Funk wrote: > On Friday, August 19, 2011, Alain Ketterlin wrote: >> Matt Funk writes: >> > thanks for the suggestion. I guess i had found another way around the >> > problem as well. But i really wanted to match the line exactly and i >> > wanted to know why it doesn't work. That is less for the purpose of >> > getting the thing to work but more because it greatly annoys me off that >> > i can't figure out why it doesn't work. I.e. why the expression is not >> > matches {32} times. I just don't get it. >> >> Because a line is not 32 times a number, it is a number followed by 31 >> times "a space followed by a number". Using Jason's regexp, you can >> build the regexp step by step: >> >> number = r"\d\.\d+e\+\d+" >> numbersequence = r"%s( %s){31}" % (number,number) > That didn't work either. Using the (modified (where the (.+) matches the end of > the line)) expression as: > > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}(.+)" % (number,number) > instance_linetype_pattern = re.compile(numbersequence) > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. The secret is buried very unobtrusively in the re docs, where it has caught me out in the past. Specifically in the docs for re.group(): "If a group is contained in a part of the pattern that matched multiple times, the last match is returned." In addition to the findall solution someone else posted, another thing you could do is to explicitly express the groups in your re: number = r"\d\.\d+e\+\d+" groups = (r"( %s)" % number)*31 numbersequence = r"%s%s(.+)" % (number,groups) ... results = match_object.group(range(1,33)) Or (what I would probably do), simply match the whole string of numbers and pull it apart later: number = r"\d\.\d+e\+\d+" numbersequence = r"(%s(?: %s){31})(.+)" % (number,number) results = (match_object.group(1)).split() [none of this code is tested but should be close enough to convey the general idea.] From fuentesej at gmail.com Fri Aug 19 15:55:40 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 12:55:40 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Message-ID: <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> On Aug 19, 1:56?pm, Phil Thompson wrote: > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > > > > > > > > > wrote: > > Dear friends, > > > I need execute an external program from a gui using PyQt4, to avoid > > that hang the main thread, i must connect the signal "finished(int)" > > of a QProcess to work properly. > > > for example, why this program don't work? > > > ? ?from PyQt4.QtCore import QProcess > > ? ?pro = QProcess() # create QProcess object > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > x="started":print(x)) ? ? ? ?# connect > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > x="finished":print(x)) > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > (contain print("hello world!")) > > ? ?timeout = -1 > > ? ?pro.waitForFinished(timeout) > > ? ?print(pro.readAllStandardOutput().data()) > > > output: > > > ? ?started > > ? ?0 > > ? ?b'hello world!\n' > > > see that not emit the signal finished(int) > > Yes it is, and your lambda slot is printing "0" which is the return code > of the process. > > Phil Ok, but the output should be: started b'hello world!\n' finished no?. thanks Phil From johnny.venter at zoho.com Fri Aug 19 16:02:18 2011 From: johnny.venter at zoho.com (johnny.venter) Date: Fri, 19 Aug 2011 13:02:18 -0700 Subject: Python Windows Extensions for Mac Message-ID: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. From pavlovevidence at gmail.com Fri Aug 19 16:11:58 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Aug 2011 13:11:58 -0700 (PDT) Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}(.+)" % (number,number) > instance_linetype_pattern = re.compile(numbersequence) > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. > > Anyway, i think at this point i will go another route. Not sure where the > issues lies at this point. I think the problem is that repeat counts don't actually repeat the groupings; they just repeat the matchings. Take this expression: r"(\w+\s*){2}" This will match exactly two words separated by whitespace. But the match result won't contain two groups; it'll only contain one group, and the value of that group will match only the very last thing repeated: Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m = re.match(r"(\w+\s*){2}","abc def") >>> m.group(1) 'def' So you see, the regular expression is doing what you think it is, but the way it forms groups is not. Just a little advice (I know you've found a different method, and that's good, this is for the general reader). The functions re.findall and re.finditer could have helped here, they find all the matches in a string and let you iterate through them. (findall returns the strings matched, and finditer returns the sequence of match objects.) You could have done something like this: row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] And regexp matching is often overkill for a particular problem; this may be of them. line.split() could have been sufficient: row = [ float(x) for x in line.split() ] Of course, these solutions don't account for the case where you have lines, some of which aren't 32 floating-point numbers. You need extra error handling for that, but you get the idea. Carl Banks From steve+comp.lang.python at pearwood.info Fri Aug 19 16:13:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:13:57 +1000 Subject: try... except with unknown error types References: Message-ID: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In Yingjie Lin > writes: > >> try: >> response = urlopen(urljoin(uri1, uri2)) >> except urllib2.HTTPError: >> print "URL does not exist!" > >> Though "urllib2.HTTPError" is the error type reported by Python, Python >> doesn't recognize it as an error type name. I tried using "HTTPError" >> alone too, but that's not recognized either. > > Have you imported urllib2 in your code? Good question. If Python "doesn't recognize it as an error type name", there is a reason for that. Exceptions are exactly the same as every other name: >>> foo.spam Traceback (most recent call last): File "", line 1, in NameError: name 'foo' is not defined >>> urllib2.HTTPError Traceback (most recent call last): File "", line 1, in NameError: name 'urllib2' is not defined >> Does anyone know what error type I should put after the except >> statement? or even better: is there a way not to specify the error >> types? Thank you. > > You can catch all exceptions by catching the base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. -- Steven From msarro at gmail.com Fri Aug 19 16:17:49 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 16:17:49 -0400 Subject: Hot Girls are Looking for Sex In-Reply-To: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: That's great - but do they program in python? On Fri, Aug 19, 2011 at 2:38 PM, Sajjad Ahmad wrote: > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > -- > http://mail.python.org/mailman/listinfo/python-list > From pavlovevidence at gmail.com Fri Aug 19 16:21:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Aug 2011 13:21:30 -0700 (PDT) Subject: Help on PyQt4 QProcess In-Reply-To: <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> Message-ID: <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > On Aug 19, 1:56?pm, Phil Thompson > wrote: > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > wrote: > > > Dear friends, > > > > > I need execute an external program from a gui using PyQt4, to avoid > > > that hang the main thread, i must connect the signal "finished(int)" > > > of a QProcess to work properly. > > > > > for example, why this program don't work? > > > > > ? ?from PyQt4.QtCore import QProcess > > > ? ?pro = QProcess() # create QProcess object > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > > x="started":print(x)) ? ? ? ?# connect > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > > x="finished":print(x)) > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > > (contain print("hello world!")) > > > ? ?timeout = -1 > > > ? ?pro.waitForFinished(timeout) > > > ? ?print(pro.readAllStandardOutput().data()) > > > > > output: > > > > > ? ?started > > > ? ?0 > > > ? ?b'hello world!\n' > > > > > see that not emit the signal finished(int) > > > > Yes it is, and your lambda slot is printing "0" which is the return code > > of the process. > > > > Phil > > Ok, but the output should be: > > started > b'hello world!\n' > finished > > no?. > > thanks Phil Two issues. First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. Anyway, to fix that, try this: pro.connect(pro, SIGNAL("finished(int)"), lambda v, x="finished":print(x)) Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of "finished". Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). Carl Banks From gordon at panix.com Fri Aug 19 16:24:38 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 20:24:38 +0000 (UTC) Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > > You can catch all exceptions by catching the base class Exception: > Except that is nearly always poor advice, because it catches too much: it > hides bugs in code, as well as things which should be caught. > You should always catch the absolute minimum you need to catch. I agree, but it did seem to be exactly what he was asking for. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From philip at semanchuk.com Fri Aug 19 16:25:44 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 19 Aug 2011 16:25:44 -0400 Subject: Hot Girls are Looking for Sex In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <5D3D75CC-76B5-436F-918E-E411075A17F1@semanchuk.com> On Aug 19, 2011, at 4:17 PM, Matty Sarro wrote: > That's great - but do they program in python? Please don't repost URLs sent by a spammer. Only Google truly knows how its algorithm works, but the general consensus is that the more times Google sees a link repeated, the more credibility the link is given. By reposting links, you help the spammer. From steve+comp.lang.python at pearwood.info Fri Aug 19 16:36:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:36:49 +1000 Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. You might save some memory by using tuples rather than lists: >>> sys.getsizeof(["01/01/2000", 123.456]) # On a 32-bit system. 40 >>> sys.getsizeof(("01/01/2000", 123.456)) 32 By the way, you know that you should never, ever use floats for currency, right? http://vladzloteanu.wordpress.com/2010/01/11/why-you-shouldnt-use-float-for-currency-floating-point-issues-explained-for-ruby-and-ror/ http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency > Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated It certainly is not. http://docs.python.org/library/shelve.html http://docs.python.org/py3k/library/shelve.html Not a word about it being deprecated in either Python 2.x or 3.x. > AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). I would like to see this replicated. If it is true, that's a bug in shelve, but I expect you're probably doing something wrong. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 19 16:43:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:43:13 +1000 Subject: Stop quoting spam [was Re: Hot Girls ...] References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Matty Sarro wrote: > That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your "joke" I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your "joke" was so worth it. Not. [spam deleted] -- Steven From python at mrabarnett.plus.com Fri Aug 19 16:43:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Aug 2011 21:43:55 +0100 Subject: Help with regular expression in python In-Reply-To: <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> Message-ID: <4E4ECB0B.9080806@mrabarnett.plus.com> On 19/08/2011 20:55, rurpy at yahoo.com wrote: > On 08/19/2011 11:33 AM, Matt Funk wrote: >> On Friday, August 19, 2011, Alain Ketterlin wrote: >>> Matt Funk writes: >>>> thanks for the suggestion. I guess i had found another way around the >>>> problem as well. But i really wanted to match the line exactly and i >>>> wanted to know why it doesn't work. That is less for the purpose of >>>> getting the thing to work but more because it greatly annoys me off that >>>> i can't figure out why it doesn't work. I.e. why the expression is not >>>> matches {32} times. I just don't get it. >>> >>> Because a line is not 32 times a number, it is a number followed by 31 >>> times "a space followed by a number". Using Jason's regexp, you can >>> build the regexp step by step: >>> >>> number = r"\d\.\d+e\+\d+" >>> numbersequence = r"%s( %s){31}" % (number,number) >> That didn't work either. Using the (modified (where the (.+) matches the end of >> the line)) expression as: >> >> number = r"\d\.\d+e\+\d+" >> numbersequence = r"%s( %s){31}(.+)" % (number,number) >> instance_linetype_pattern = re.compile(numbersequence) >> >> The results obtained are: >> results: >> [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] >> so this matches the last number plus the string at the end of the line, but no >> retaining the previous numbers. > > The secret is buried very unobtrusively in the re docs, > where it has caught me out in the past. Specifically > in the docs for re.group(): > > "If a group is contained in a part of the pattern that > matched multiple times, the last match is returned." > [snip] There's a regex implementation on PyPI: http://pypi.python.org/pypi/regex which does support capturing all of the matches of a group. From steve+comp.lang.python at pearwood.info Fri Aug 19 16:45:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:45:36 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4ecb70$0$29990$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In <4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano > writes: > >> > You can catch all exceptions by catching the base class Exception: > >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. > >> You should always catch the absolute minimum you need to catch. > > I agree, but it did seem to be exactly what he was asking for. Sure, but if we're giving advice to somebody who is clearly a beginner (doesn't even know how to deal with a simple NameError from failing to import a module), it is our responsibility to teach *good* habits, not to teach him to be a crap programmer. Even if you don't think it's the ethical thing to do, consider that someday you might be maintaining code written by the OP :) -- Steven From rodrick.brown at gmail.com Fri Aug 19 17:10:49 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 19 Aug 2011 17:10:49 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From rodrick.brown at gmail.com Fri Aug 19 17:10:49 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 19 Aug 2011 17:10:49 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From msarro at gmail.com Fri Aug 19 17:12:40 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 17:12:40 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It was a joke, no need to be a prick about it. If you're that offended then spend the cycles fixing the damn list so it stops having so much spam. You realize spam comes in almost constantly, right? Enough that multiple tines over the past weeks there have been no less than 3 threads about it. If php, red hat, and perl can manage it for their lists, why not python? Is that a statement about python programmers? God forbid I try to make a joke. Grow up. On Aug 19, 2011 4:46 PM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Aug 19 17:16:42 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 17:16:42 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: Glad someone has a sense of humor :) If one person smiled I consider it a success. Happy weekend! On Aug 19, 2011 5:12 PM, "Rodrick Brown" wrote: > It's not the end of the world calm down I thought it was quite funny for a friday joke! > > Sent from my iPhone > > On Aug 19, 2011, at 4:43 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > >> Matty Sarro wrote: >> >>> That's great - but do they program in python? >> >> Thanks for that, I didn't see the spam the first time, but thanks to >> your "joke" I saw it now! I really appreciate that, because I LOVE to have >> spam sent to me, including all the URLs. An extra bonus is that when the >> posting is archived on a couple of dozen websites, this will boost the >> spammer's Google rankings. >> >> Thanks heaps! Your "joke" was so worth it. >> >> Not. >> >> >> >> [spam deleted] >> >> >> -- >> Steven >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matze999 at gmail.com Fri Aug 19 17:21:58 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 15:21:58 -0600 Subject: Help with regular expression in python In-Reply-To: <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> References: <201108181349.54727.matze999@gmail.com> <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> Message-ID: <201108191521.58499.matze999@gmail.com> On Friday, August 19, 2011, jmfauth wrote: > On 19 ao?t, 19:33, Matt Funk wrote: > > The results obtained are: > > results: > > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > > so this matches the last number plus the string at the end of the line, > > but no retaining the previous numbers. > > > > Anyway, i think at this point i will go another route. Not sure where the > > issues lies at this point. > > Seen on this list: > > And always keep this in mind: > 'Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems.' > --Jamie Zawinski, comp.lang.emacs > > > I proposed a solution which seems to corresponds to your problem > if it were better formulated... Agreed, and i will probably take your proposed route or a similar one. However, i still won't know WHY it didn't work. I would really LIKE to know why, simply because it tickles me. matt > > jmf From mwilson at the-wire.com Fri Aug 19 17:22:42 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 19 Aug 2011 17:22:42 -0400 Subject: try... except with unknown error types References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: xDog Walker wrote: > On Friday 2011 August 19 12:09, Yingjie Lin wrote: [ ... ] >> Does anyone know what error type I should put after the except statement? >> or even better: is there a way not to specify the error types? Thank you. > > You probably need to import urllib2 before you can use urllib2.HTTPError. > > Otherwise, you can try using the base class: > > except Exception, e: There are maybe better base classes to use. Running the interpreter: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> help (urllib2.HTTPError) will show you class HTTPError(URLError, urllib.addinfourl) | Raised when HTTP error occurs, but also acts like non-error return | | Method resolution order: | HTTPError | URLError | exceptions.IOError | exceptions.EnvironmentError | exceptions.StandardError | exceptions.Exception | exceptions.BaseException > So catching any of urllib2.HTTPError, urllib2.URLError, IOError, EnvironmentError, or StandardError will detect the exception -- with increasing levels of generality. Mel. From fuentesej at gmail.com Fri Aug 19 17:32:12 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 14:32:12 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 19, 4:21?pm, Carl Banks wrote: > On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > > On Aug 19, 1:56?pm, Phil Thompson > > ?wrote: > > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > > wrote: > > > > Dear friends, > > > > > I need execute an external program from a gui using PyQt4, to avoid > > > > that hang the main thread, i must connect the signal "finished(int)" > > > > of a QProcess to work properly. > > > > > for example, why this program don't work? > > > > > ? ?from PyQt4.QtCore import QProcess > > > > ? ?pro = QProcess() # create QProcess object > > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > > > x="started":print(x)) ? ? ? ?# connect > > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > > > x="finished":print(x)) > > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > > > (contain print("hello world!")) > > > > ? ?timeout = -1 > > > > ? ?pro.waitForFinished(timeout) > > > > ? ?print(pro.readAllStandardOutput().data()) > > > > > output: > > > > > ? ?started > > > > ? ?0 > > > > ? ?b'hello world!\n' > > > > > see that not emit the signal finished(int) > > > > Yes it is, and your lambda slot is printing "0" which is the return code > > > of the process. > > > > Phil > > > Ok, but the output should be: > > > ? ? started > > ? ? b'hello world!\n' > > ? ? finished > > > no?. > > > thanks Phil > > Two issues. ?First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. ?Anyway, to fix that, try this: > > pro.connect(pro, SIGNAL("finished(int)"), lambda v, x="finished":print(x)) > > Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. ?If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of "finished". > > Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. ?You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). > > Carl Banks Thanks Carl, your intervention was very helpful for me, this solve my semantic error. I need to study more about signal/slots and process. From darcy at druid.net Fri Aug 19 17:35:32 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Aug 2011 17:35:32 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110819173532.21ac05a2@dilbert> On Fri, 19 Aug 2011 17:12:40 -0400 Matty Sarro wrote: > It was a joke, no need to be a prick about it. It was spam. You're the prick. If you think spam is funny it's because you aren't the one that has to spend your time dealing with the fallout. > If you're that offended then spend the cycles fixing the damn list so it Most of us have fixed it. We didn't see the spam until you repeated it. For whatever reason the original message was caught by our filters. You helped the spammer break through. I can assure you though that your attitude means that you won't be able to help them again. I can hear the plonking going on all over the net. Here's another one; *plonk* No point in replying. I won't hear it. Hope you don't have any important questions for the group. It just became more of a read-only list for you. > If php, red hat, and perl can manage it for their lists, why not python? Is > that a statement about python programmers? And that should get you blacklisted by anyone on the cusp. -- 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 Aug 19 17:40:52 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Aug 2011 17:40:52 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110819174052.5fdf7024@dilbert> On Fri, 19 Aug 2011 17:10:49 -0400 Rodrick Brown wrote: > It's not the end of the world calm down I thought it was quite funny for a friday joke! The first message might have been funny (if you are twelve) but the rest were annoying and insulting. -- 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 me+list/python at ixokai.io Fri Aug 19 17:47:04 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 19 Aug 2011 14:47:04 -0700 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <4E4ED9D8.2070809@ixokai.io> On 8/19/11 12:09 PM, Yingjie Lin wrote: > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. > I tried using "HTTPError" alone too, but that's not recognized either. Exceptions are objects like any other, and they are defined in specific places. Only the standard ones are available everywhere; things like IndexError and AttributeError. See the 'exceptions' module for the standard ones. Everything else, you have to 'grab' the object from where it lives -- in this case, in urllib2. > Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify > the error types? Thank you. You can use a "bare except", like so: try: ... except: ... But avoid it, if you can. Or at least, don't let it become habit-forming: for networking code and interaction with external things, I usually have a bare-except as a final fallback, after trying other more specific things-- but only as a last resort. FWIW, the error hierarchy of url fetching is more then a little bit annoying. My own _request object I end up using for one of our services catches, in order: try: ... except urllib2.HTTPError: except urllib2.URLError: except httplib.BadStatusLine: except httplib.HTTPException: except socket.timeout: except: With each case logging and handling the error in a bit of a different way. (Though most, eventually, resulting in the request being retried -- all in the name of a mandate that this particular bit of code must not, under any circumstances, not ultimately work. Even going so far as to start having hour long waits between retries until the other side is finally up :P) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From matze999 at gmail.com Fri Aug 19 17:55:53 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 15:55:53 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> Message-ID: <201108191555.53338.matze999@gmail.com> On Friday, August 19, 2011, Carl Banks wrote: > On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: > > number = r"\d\.\d+e\+\d+" > > numbersequence = r"%s( %s){31}(.+)" % (number,number) > > instance_linetype_pattern = re.compile(numbersequence) > > > > The results obtained are: > > results: > > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > > so this matches the last number plus the string at the end of the line, > > but no retaining the previous numbers. > > > > Anyway, i think at this point i will go another route. Not sure where the > > issues lies at this point. > > I think the problem is that repeat counts don't actually repeat the > groupings; they just repeat the matchings. Take this expression: > > r"(\w+\s*){2}" I see > > This will match exactly two words separated by whitespace. But the match > result won't contain two groups; it'll only contain one group, and the > value of that group will match only the very last thing repeated: > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import re > >>> m = re.match(r"(\w+\s*){2}","abc def") > >>> m.group(1) > > 'def' > > So you see, the regular expression is doing what you think it is, but the > way it forms groups is not. > > > Just a little advice (I know you've found a different method, and that's > good, this is for the general reader). > > The functions re.findall and re.finditer could have helped here, they find > all the matches in a string and let you iterate through them. (findall > returns the strings matched, and finditer returns the sequence of match > objects.) You could have done something like this: I did use findall but when i tried to match the everything (including the 'some description' part) it did not work. But i think the explanation you gave above matches this case and explains why it did not. > > row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] > > And regexp matching is often overkill for a particular problem; this may be > of them. line.split() could have been sufficient: > > row = [ float(x) for x in line.split() ] > > Of course, these solutions don't account for the case where you have lines, > some of which aren't 32 floating-point numbers. You need extra error > handling for that, but you get the idea. thanks matt > > > Carl Banks From robert.kern at gmail.com Fri Aug 19 18:24:15 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Aug 2011 17:24:15 -0500 Subject: Replacement for the shelve module? In-Reply-To: <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/19/11 3:36 PM, Steven D'Aprano wrote: > By the way, you know that you should never, ever use floats for currency, > right? That's just incorrect. You shouldn't use (binary) floats for many *accounting* purposes, but for many financial/econometric analyses, floats are de rigeur and work much better than decimals (either floating or fixed point). If you are collecting gigs of stock prices, you are much more likely to be doing the latter than the former. -- 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 aspineux at gmail.com Fri Aug 19 18:38:34 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 19 Aug 2011 15:38:34 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: <7849d9ff-f472-49c3-a1ce-0f618a301f06@e7g2000vbw.googlegroups.com> On Aug 19, 5:00?pm, lzlu123 wrote: > I have an instrument that has a RS232 type serial comm port and I need > to connect to and control. I use Python 3.2 in Windows XP, plus > pySerial module. I have a problem when I execute a script consisting > of statements that open the comm port, configure it, write strings to > and receive strings from it. Thoese strings aer either commands > pertinent to the instrument (control) or responses from the instrument > (response). > > When those statements are executed in a python interpreter > interactively (at >>>), I get what I expect and the results are good > and correct. However, when I execute the script, either being invoked > within the interpreter or run file, I don?t get what I want. The > statements in the script is the same as what I use in the interactive > interpreter. > > Why do I get the strange behavior and how can I change the script to > make it to behave like in interactive interpreter? > > ----------------------script----------------------- > def read(comport): > > ? ? wrt_str=b'movt 3000'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? wrt_str=b'scan'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? rsp_str=comport.readlines() #########1 You use readlines() with a s at the end ! * Note that when the serial port was opened with no timeout, that readline() * blocks until it sees a newline (or the specified size is reached) * and that readlines() would never return and therefore refuses to work * (it raises an exception in this case)! > > ? ? wrt_str=b'hllo'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? rsp_str=comport.readlines()#########2 > ---------------------------------------------------------- > > The problem is with the lines above with #######. In interactive mode, > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > correct responses there. However, if I execute the script above, there > is no delay at all and I get incorrect results (garbage). I set the > read timeout to 0 in comm port set up, as > > comport.timeout=0 > So the comport should be in blocking mode if it waits for the end of > line or end of file. Wrong : timeout = None: wait forever timeout = 0: non-blocking mode (return immediately on read) timeout = x: set timeout to x seconds (float allowed) > > I tried many things, like exec (execfile in 2.7), but at no avail. > > I have an update to the original post I made a few days ago. I think I > know what the problem is and want to know if anyone has a solution: > > After putting "print" and "time.sleep(delay)" after every statement, I > found when the script is running, it appears going around the pyserial > statement, such as "comport.write(..)" or "comport.readlines(...)" > while the pyserial command is executing (appearing as waiting and > busying doing some thing, you know serial port is slow). So for > example, when I exec all statements in a python interactive shell, I > am not able to type and run a new statement if the previous one is not > returned. Let's ay, if comport.readlines() is not returning, I can't > type and run the next comport.write(...) statemtn. However, in a > script that is running, if the comport.readlines() is busy reading, > the next statement is running, if the next statement happens to be a > comport.write() which will abort the reading. > > Is there any way to force the python script to behave like running > exactly sequentially? You have some new things to try From drsalists at gmail.com Fri Aug 19 19:21:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 19 Aug 2011 16:21:11 -0700 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Fri, Aug 19, 2011 at 8:31 AM, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). > I'd probably use a cachedb, though perhaps I'm biased since I wrote it: http://stromberg.dnsalias.org/~dstromberg/cachedb.html It'll allow you to specify functions for serializing and deserializing values (but not keys), and cache a user-specified number of values in virtual memory. IOW, once you instantiate the class, you pretty much get caching and seralizing/deserializing as freebies, without the details of same getting scattered throughout your code. It wraps something like gdbm. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Fri Aug 19 19:24:26 2011 From: marduk at letterboxes.org (Albert W. Hopkins) Date: Fri, 19 Aug 2011 19:24:26 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1313796267.11691.6.camel@localhost.localdomain> On Friday, August 19 at 17:12 (-0400), Matty Sarro said: > > If you're that offended then spend the cycles fixing the damn list so > it > stops having so much spam. You realize spam comes in almost > constantly, > right? Enough that multiple tines over the past weeks there have been > no > less than 3 threads about it. For me, the original post ended in my spam box, which means my filter is doing it's job, but when you re-post it, my filter did not regard it as spam. I actually wish it had. Therefore you are an enabler. > If php, red hat, and perl can manage it for their lists, why not > python? Is > that a statement about python programmers? > The python list is (also) a Usenet newsgroup. Usenet is distributed and therefore there is no central place to filter spam (each usenet host would have to have its own filter and what one considers spam another might consider ham)... anyway, that's neither here nor there. Having my own filter usually works. I'm not here to dis you, just to try to help you understand the how/why regarding the re-post and why your attitude about it might give the impression of apathy toward your peer community. From torriem at gmail.com Fri Aug 19 19:59:01 2011 From: torriem at gmail.com (Michael Torrie) Date: Fri, 19 Aug 2011 17:59:01 -0600 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: <4E4EF8C5.5060909@gmail.com> On 08/18/2011 01:24 PM, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. > The ability to see the codes in use (bold, margins, columns, etc) has so > far been unequaled in anything else I have looked at. It's too bad LaTeX is so complicated and LyX just never quite worked out for me. From steve+comp.lang.python at pearwood.info Fri Aug 19 21:38:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 11:38:13 +1000 Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> Robert Kern wrote: > On 8/19/11 3:36 PM, Steven D'Aprano wrote: > >> By the way, you know that you should never, ever use floats for currency, >> right? > > That's just incorrect. You shouldn't use (binary) floats for many > *accounting* purposes, but for many financial/econometric analyses, floats > are de rigeur and work much better than decimals (either floating or fixed > point). If you are collecting gigs of stock prices, you are much more > likely to be doing the latter than the former. That makes sense, and I stand corrected. -- Steven From wkxin at qq.com Fri Aug 19 21:59:33 2011 From: wkxin at qq.com (=?ISO-8859-1?B?d3VrZXhpbg==?=) Date: Sat, 20 Aug 2011 09:59:33 +0800 Subject: hello python Message-ID: from china ------------------ designed by wkxin at qq.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 19 22:10:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 12:10:29 +1000 Subject: testing if a list contains a sublist References: Message-ID: <4e4f1794$0$29990$c3e8da3$5496439d@news.astraweb.com> Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? [...] For anyone interested, here's a pair of functions that implement sub-sequence testing similar to str.find and str.rfind: http://code.activestate.com/recipes/577850-search-sequences-for-sub-sequence/ -- Steven From nospam at nospam.com Fri Aug 19 23:06:11 2011 From: nospam at nospam.com (Javier) Date: Sat, 20 Aug 2011 03:06:11 +0000 (UTC) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: Never used it, but I think you can try this: Pexpect - a Pure Python Expect-like module Pexpect is a pure Python Expect-like module. Pexpect makes Python... www.noah.org/python/pexpect/ lzlu123 wrote: > I have an instrument that has a RS232 type serial comm port and I need > to connect to and control. I use Python 3.2 in Windows XP, plus > pySerial module. I have a problem when I execute a script consisting > of statements that open the comm port, configure it, write strings to > and receive strings from it. Thoese strings aer either commands > pertinent to the instrument (control) or responses from the instrument > (response). > > When those statements are executed in a python interpreter > interactively (at >>>), I get what I expect and the results are good > and correct. However, when I execute the script, either being invoked > within the interpreter or run file, I don???t get what I want. The > statements in the script is the same as what I use in the interactive > interpreter. > > Why do I get the strange behavior and how can I change the script to > make it to behave like in interactive interpreter? > > ----------------------script----------------------- > def read(comport): > > wrt_str=b'movt 3000'+b'\r\n' > ret_str=comport.write(wrt_str) > > wrt_str=b'scan'+b'\r\n' > ret_str=comport.write(wrt_str) > > rsp_str=comport.readlines() #########1 > > wrt_str=b'hllo'+b'\r\n' > ret_str=comport.write(wrt_str) > > rsp_str=comport.readlines()#########2 > ---------------------------------------------------------- > > The problem is with the lines above with #######. In interactive mode, > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > correct responses there. However, if I execute the script above, there > is no delay at all and I get incorrect results (garbage). I set the > read timeout to 0 in comm port set up, as > > comport.timeout=0 > So the comport should be in blocking mode if it waits for the end of > line or end of file. > > I tried many things, like exec (execfile in 2.7), but at no avail. > > I have an update to the original post I made a few days ago. I think I > know what the problem is and want to know if anyone has a solution: > > After putting "print" and "time.sleep(delay)" after every statement, I > found when the script is running, it appears going around the pyserial > statement, such as "comport.write(..)" or "comport.readlines(...)" > while the pyserial command is executing (appearing as waiting and > busying doing some thing, you know serial port is slow). So for > example, when I exec all statements in a python interactive shell, I > am not able to type and run a new statement if the previous one is not > returned. Let's ay, if comport.readlines() is not returning, I can't > type and run the next comport.write(...) statemtn. However, in a > script that is running, if the comport.readlines() is busy reading, > the next statement is running, if the next statement happens to be a > comport.write() which will abort the reading. > > Is there any way to force the python script to behave like running > exactly sequentially? From nospam at nospam.com Fri Aug 19 23:17:33 2011 From: nospam at nospam.com (Javier) Date: Sat, 20 Aug 2011 03:17:33 +0000 (UTC) Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: You will lose a lot of people asking/answering interesting stuff, and maybe eventually the list will die. Me (like many people with little free time) seldom post in blogs/forums/mailing lists where I need to register. gene heskett wrote: > That is asking the user to take considerable effort and resources to do > that. What is wrong with the mailing list only approach? From adam.jorgensen.za at gmail.com Sat Aug 20 01:29:47 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Sat, 20 Aug 2011 07:29:47 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: You mean pywin32? They sure don't install on linux so that should give you a clue... On 19 August 2011 22:02, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be > installed on a Mac.THanks. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Aug 20 01:36:01 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 22:36:01 -0700 Subject: Python Windows Extensions for Mac In-Reply-To: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. Your request is nonsensical. pywin32 wraps the Windows API libraries. Mac OS X is not Windows; it does not implement the Windows API. Thus, there is nothing for pywin32 to wrap on a Mac. Square peg, round hole. Cheers, Chris From usenet-nospam at seebs.net Sat Aug 20 01:46:39 2011 From: usenet-nospam at seebs.net (Seebs) Date: 20 Aug 2011 05:46:39 GMT Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e4ecb70$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-19, Steven D'Aprano wrote: > Even if you don't think it's the ethical thing to do, consider that someday > you might be maintaining code written by the OP :) A common further conclusion people reach is "but then I will be able to get a job fixing it!" Trust me, this is NOT where you want to go. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Sat Aug 20 02:07:23 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Aug 2011 16:07:23 +1000 Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <87ei0gbopw.fsf@benfinney.id.au> Javier writes: > You will lose a lot of people asking/answering interesting stuff, and > maybe eventually the list will die. I don't think it would die, but the chances are greater that it would become insular and further disconnected from the Python community, and hence far less useful. > Me (like many people with little free time) seldom post in > blogs/forums/mailing lists where I need to register. +1 -- \ ?Ignorance more frequently begets confidence than does | `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney From gd.usenet at spamfence.net Sat Aug 20 03:55:53 2011 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sat, 20 Aug 2011 09:55:53 +0200 Subject: Python Windows Extensions for Mac References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: In article , Chris Rebert wrote: >On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter wrote: >> >> Hello, I am looking for the Python Windows Extensions to see if they can be >> installed on a Mac.THanks. > >Your request is nonsensical. That's not completely true. >pywin32 wraps the Windows API libraries. >Mac OS X is not Windows; it does not implement the Windows API. Thus, >there is nothing for pywin32 to wrap on a Mac. Again: Not completely true. One could run python under wine and get -- at least a part of -- the Windows API. >Square peg, round hole. wine might be the tool that makes the square peg round. Best regards, G?nther From alec.taylor6 at gmail.com Sat Aug 20 04:16:48 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 20 Aug 2011 18:16:48 +1000 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <1313796267.11691.6.camel@localhost.localdomain> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: On Sat, Aug 20, 2011 at 9:24 AM, Albert W. Hopkins wrote: > > > On Friday, August 19 at 17:12 (-0400), Matty Sarro said: > >> >> If you're that offended then spend the cycles fixing the damn list so >> it >> stops having so much spam. You realize spam comes in almost >> constantly, >> right? Enough that multiple tines over the past weeks there have been >> no >> less than 3 threads about it. > > For me, the original post ended in my spam box, which means my filter is > doing it's job, but when you re-post it, my filter did not regard it as > spam. ?I actually wish it had. ?Therefore you are an enabler. > > >> If php, red hat, and perl can manage it for their lists, why not >> python? Is >> that a statement about python programmers? >> > > The python list is (also) a Usenet newsgroup. ?Usenet is distributed and > therefore there is no central place to filter spam (each usenet host > would have to have its own filter and what one considers spam another > might consider ham)... anyway, that's neither here nor there. ?Having my > own filter usually works. > > I'm not here to dis you, just to try to help you understand the how/why > regarding the re-post and why your attitude about it might give the > impression of apathy toward your peer community. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I found said joke rather funny :P From debruinjj at gmail.com Sat Aug 20 04:25:18 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 01:25:18 -0700 (PDT) Subject: Compare tuples of different lenght Message-ID: Hi, I have a list of tuples: [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] I would like to compare all the tuples to each other and if one element if found two tuples the smallest tuples is removed from the list. example if tuple 1 and tuple 3 are compare it should find that a single element in each are the same and tuple 1 should be removed resulting in [(12,13),(2,3,4),(8,),(5,6),(7,8,9),] the same for tuple 4 and 6 resulting in [(12,13),(2,3,4),(5,6),(7,8,9),] is this possible as I am having no success. Thanks From phil at riverbankcomputing.com Sat Aug 20 04:36:02 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Sat, 20 Aug 2011 09:36:02 +0100 Subject: Help on PyQt4 QProcess In-Reply-To: References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: <574f70abfc6a2dc96a9bbdcb464f4c23@localhost> On Fri, 19 Aug 2011 14:32:12 -0700 (PDT), Edgar Fuentes wrote: > On Aug 19, 4:21?pm, Carl Banks wrote: >> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: >> > On Aug 19, 1:56?pm, Phil Thompson >> > ?wrote: >> > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes >> > > wrote: >> > > > Dear friends, >> >> > > > I need execute an external program from a gui using PyQt4, to avoid >> > > > that hang the main thread, i must connect the signal >> > > > "finished(int)" >> > > > of a QProcess to work properly. >> >> > > > for example, why this program don't work? >> >> > > > ? ?from PyQt4.QtCore import QProcess >> > > > ? ?pro = QProcess() # create QProcess object >> > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda >> > > > x="started":print(x)) ? ? ? ?# connect >> > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda >> > > > x="finished":print(x)) >> > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program >> > > > (contain print("hello world!")) >> > > > ? ?timeout = -1 >> > > > ? ?pro.waitForFinished(timeout) >> > > > ? ?print(pro.readAllStandardOutput().data()) >> >> > > > output: >> >> > > > ? ?started >> > > > ? ?0 >> > > > ? ?b'hello world!\n' >> >> > > > see that not emit the signal finished(int) >> >> > > Yes it is, and your lambda slot is printing "0" which is the return >> > > code >> > > of the process. >> >> > > Phil >> >> > Ok, but the output should be: >> >> > ? ? started >> > ? ? b'hello world!\n' >> > ? ? finished >> >> > no?. >> >> > thanks Phil >> >> Two issues. ?First of all, your slot for the finished function does not >> have the correct prototype, and it's accidentally not throwing an >> exception because of your unnecessary use of default arguments. ?Anyway, >> to fix that, try this: >> >> pro.connect(pro, SIGNAL("finished(int)"), lambda v, >> x="finished":print(x)) >> >> Notice that it adds an argument to the lambda (v) that accepts the int >> argument of the signal. ?If you don't have that argument there, the int >> argument goes into x, which is why Python prints 0 instead of "finished". >> >> Second, processess run asynchrously, and because of line-buffering, IO >> can output asynchronously, and so there's no guarantee what order output >> occurs. ?You might try calling the python subprocess with the '-u' switch >> to force unbuffered IO, which might be enough to force synchronous output >> (depending on how signal/slot and subprocess semantics are implemented). >> >> Carl Banks > > Thanks Carl, your intervention was very helpful for me, this solve my > semantic error. I need to study more about signal/slots and process. In which case you should look at the modern, Pythonic connection syntax rather than the old one... pro.started.connect(lambda: print("started")) pro.finished.connect(lambda: print("finished")) Phil From clp2 at rebertia.com Sat Aug 20 04:45:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Aug 2011 01:45:04 -0700 Subject: Compare tuples of different lenght In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. So, would [(5,6), (6,7,8)] become [(6,7,8)] ? If no, then I believe you're trying to solve the set covering problem: http://en.wikipedia.org/wiki/Set_cover_problem Cheers, Chris -- http://rebertia.com From debruinjj at gmail.com Sat Aug 20 04:54:56 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 01:54:56 -0700 (PDT) Subject: Compare tuples of different lenght References: Message-ID: <977c304f-98be-4772-9e6c-d3f4caf61a06@v7g2000vbk.googlegroups.com> On Aug 20, 10:45?am, Chris Rebert wrote: > On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > So, would [(5,6), (6,7,8)] become [(6,7,8)] ? > > If no, then I believe you're trying to solve the set covering problem:http://en.wikipedia.org/wiki/Set_cover_problem > > Cheers, > Chris > --http://rebertia.com [(5,6), (6,7,8)] would become [(6,7,8)]. Thanks for the response From debruinjj at gmail.com Sat Aug 20 05:00:42 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 02:00:42 -0700 (PDT) Subject: Compare tuples of different lenght References: Message-ID: On Aug 20, 10:45?am, Chris Rebert wrote: > On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > So, would [(5,6), (6,7,8)] become [(6,7,8)] ? > > If no, then I believe you're trying to solve the set covering problem:http://en.wikipedia.org/wiki/Set_cover_problem > > Cheers, > Chris > --http://rebertia.com [(5,6), (6,7,8)] will indeed become [(6,7,8)] Tanks!! From prakashnn30590 at gmail.com Sat Aug 20 05:06:46 2011 From: prakashnn30590 at gmail.com (prakash prakash) Date: Sat, 20 Aug 2011 02:06:46 -0700 (PDT) Subject: hi Message-ID: <276c9d69-00cc-43ce-b508-cac195642374@r40g2000prf.googlegroups.com> http://123maza.com/65/share551/ From hackingkk at gmail.com Sat Aug 20 05:46:08 2011 From: hackingkk at gmail.com (hackingKK) Date: Sat, 20 Aug 2011 15:16:08 +0530 Subject: Hot Girls are Looking for Sex In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <4E4F8260.2080606@gmail.com> Well, they might be indented in the right places but i don't know if loops, conditions, functions, if they all happen or not. :) Happy hacking. Krishnakant, On 20/08/11 01:47, Matty Sarro wrote: > That's great - but do they program in python? > > On Fri, Aug 19, 2011 at 2:38 PM, Sajjad Ahmad wrote: >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From kevin.misc.10 at gmail.com Sat Aug 20 05:52:27 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Sat, 20 Aug 2011 17:52:27 +0800 Subject: Python import search path Message-ID: Hi, This is the directory tree. project ??? sme ??? src ? ??? a.pth ? ??? sss.py ??? test ??? ttt.py I need to import sss.py in ttt.py. Found a few solution in python docs. A. sys.path.append B. add ***.pth file C. edit .../site-packages/site.py I found out that a.pth only works when in directory like /usr/lib/pythonX.Y/site-packages instead of in current directory. I think A is not so pretty, and I don't have root privilege to use B and C. So any both more elegant and practical solutions? Thanks. Kevin Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 20 06:17:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 20:17:39 +1000 Subject: Compare tuples of different lenght References: Message-ID: <4e4f89c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. It's not clear what you mean by "smallest" tuple. Is (8,) smaller than (7,8,9)? I'm going to guess you care only about the length of the tuple, and not the items themselves. Let's start with a couple of helper functions. def compare(t1, t2): 'Return -1 if t1 is "smaller" than t2, 0 if equal, and +1 if "bigger".' if len(t1) < len(t2): return -1 elif len(t1) > len(t2): return 1 else: return 0 def match_any_item(t1, t2): try: s1 = set(t1) s2 = set(t2) return bool(s1 & s2) except TypeError: # Can't convert to sets because at least one item is mutable. # Let's do this the slow(?) way. matched = [x for x in t1 if x in t2] return bool(matched) list_of_tuples = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] flags = [True]*len(list_of_tuples) for i,t1 in enumerate(list_of_tuples): for j in range(i+1, len(list_of_tuples)): t2 = list_of_tuples[j] if match_any_item(t1, t2): n = compare(t1, t2) if n == -1: # Flag t1 to be removed. flags[i] = False elif n == 1: # Flag t2 to be removed. flags[j] = False saved_tuples = [] for t,flag in zip(list_of_tuples, flags): if flag: saved_tuples.append(t) This gives: >>> saved_tuples [(12, 13), (2, 3, 4), (5, 6), (7, 8, 9)] which matches what you wanted: > [(12,13),(2,3,4),(5,6),(7,8,9),] -- Steven From k.sahithi2862 at gmail.com Sat Aug 20 06:42:22 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 20 Aug 2011 03:42:22 -0700 (PDT) Subject: LATEST HOT PICS Message-ID: <8ee6d028-2beb-4db5-b45c-e019c3d570b2@j14g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From debruinjj at gmail.com Sat Aug 20 06:47:29 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 03:47:29 -0700 (PDT) Subject: Compare tuples of different lenght References: <4e4f89c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0d10e8b5-d531-4488-8fa1-2fb306ce215d@e7g2000vbw.googlegroups.com> On Aug 20, 12:17?pm, Steven D'Aprano wrote: > Jurgens de Bruin wrote: > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > It's not clear what you mean by "smallest" tuple. Is (8,) smaller than > (7,8,9)? > > I'm going to guess you care only about the length of the tuple, and not the > items themselves. > > Let's start with a couple of helper functions. > > def compare(t1, t2): > ? ? 'Return -1 if t1 is "smaller" than t2, 0 if equal, and +1 if "bigger".' > ? ? if len(t1) < len(t2): return -1 > ? ? elif len(t1) > len(t2): return 1 > ? ? else: return 0 > > def match_any_item(t1, t2): > ? ? try: > ? ? ? ? s1 = set(t1) > ? ? ? ? s2 = set(t2) > ? ? ? ? return bool(s1 & s2) > ? ? except TypeError: > ? ? ? ? # Can't convert to sets because at least one item is mutable. > ? ? ? ? # Let's do this the slow(?) way. > ? ? ? ? matched = [x for x in t1 if x in t2] > ? ? ? ? return bool(matched) > > list_of_tuples = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > flags = [True]*len(list_of_tuples) > for i,t1 in enumerate(list_of_tuples): > ? ? for j in range(i+1, len(list_of_tuples)): > ? ? ? ? t2 = list_of_tuples[j] > ? ? ? ? if match_any_item(t1, t2): > ? ? ? ? ? ? n = compare(t1, t2) > ? ? ? ? ? ? if n == -1: > ? ? ? ? ? ? ? ? # Flag t1 to be removed. > ? ? ? ? ? ? ? ? flags[i] = False > ? ? ? ? ? ? elif n == 1: > ? ? ? ? ? ? ? ? # Flag t2 to be removed. > ? ? ? ? ? ? ? ? flags[j] = False > > saved_tuples = [] > for t,flag in zip(list_of_tuples, flags): > ? ? if flag: saved_tuples.append(t) > > This gives: > > >>> saved_tuples > > [(12, 13), (2, 3, 4), (5, 6), (7, 8, 9)] > > which matches what you wanted: > > > [(12,13),(2,3,4),(5,6),(7,8,9),] > > -- > Steven Thanks Steven. This works great!!! Appreciated very much!!! From __peter__ at web.de Sat Aug 20 07:56:18 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Aug 2011 13:56:18 +0200 Subject: Compare tuples of different lenght References: Message-ID: Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. > > example if tuple 1 and tuple 3 are compare it should find that a > single element in each are the same and tuple 1 should be removed > resulting in > > [(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > the same for tuple 4 and 6 resulting in > > [(12,13),(2,3,4),(5,6),(7,8,9),] > > is this possible as I am having no success. > > Thanks from collections import Counter, defaultdict from itertools import chain def process_counter(sample): c = Counter() d = defaultdict(list) for items in sample: c.update(items) d[len(items)].append(items) result = [] for cluster in sorted(d.values(), key=len): c.subtract(chain.from_iterable(cluster)) for items in cluster: if not any(c[item] for item in items): result.append(items) result.sort(key=sample.index) return result if __name__ == "__main__": for process in [process_counter]: print process.__name__ sample = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] wanted = [(12,13),(2,3,4),(5,6),(7,8,9),] assert process(sample) == wanted sample = [(5,6), (6,7,8)] wanted = [(6,7,8)] got = process(sample) assert got == wanted sample = wanted = [(5, 6), (6, 7)] assert process(sample) == wanted sample = [(1,), (1, 2), (2, 3, 4)] wanted = [(2, 3, 4)] assert process(sample) == wanted From drobinow at gmail.com Sat Aug 20 08:17:32 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 20 Aug 2011 08:17:32 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: On Sat, Aug 20, 2011 at 4:16 AM, Alec Taylor wrote: >> ... > I found said joke rather funny :P Perhaps, as a retired amateur comedian, my standards are too high, but I don't think adding a smilie to a stupid post suddenly turns it into a joke. Nevertheless, the quality of the attempt is not really the issue here. The would-be humorist did not need to quote the spam. Please, don't do it. From rosuav at gmail.com Sat Aug 20 08:25:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 13:25:39 +0100 Subject: Python import search path In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 10:52 AM, Kevin Zhang wrote: > Found a few solution in python docs. > A. sys.path.append > I think A is not so pretty, and I don't have root ?privilege?to use B and C. > So any both more elegant and practical solutions? If, as I understand from your directory tree, ttt.py is a tester for sss.py, then I'd say this is the right option. It's only going to be used in the special environment of testing, so it's okay to have a single line of code up the top that makes it convenient. Chris Angelico From darcy at druid.net Sat Aug 20 10:50:35 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Aug 2011 10:50:35 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: <20110820105035.4fa540b5@dilbert> On Sat, 20 Aug 2011 08:17:32 -0400 David Robinow wrote: > > I found said joke rather funny :P > Perhaps, as a retired amateur comedian, my standards are too high, How does one retire from amateur status? Do you suddenly start charging for telling jokes? :-) > but I don't think adding a smilie to a stupid post suddenly turns it > into a joke. Nevertheless, the quality of the attempt is not really > the issue here. The would-be humorist did not need to quote the spam. Well, exactly. I don't think that anyone made any comment about the quality of the joke when talking about the first posting. The only thing that people said was that he shouldn't have repeated the spam. Everyone, including the original poster, who defended the post did so on the grounds that it was funny. That's certainly debatable but no one was telling him not to post until he gets funnier. http://en.wikipedia.org/wiki/Straw_man Whether the post was funny or not is a judgment call. No one is saying not to post unfunny jokes because no one is the arbiter of what's funny. If you want to argue with the complainers, argue with their actual complaint. Tell us why it is OK to repeat spam with all the spammy URLS intact By the way, my joke above is hilarious. -- 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 Sat Aug 20 10:57:08 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Aug 2011 10:57:08 -0400 Subject: Really, stop repeating spam! (Was: Hot Girls...) In-Reply-To: <4E4F8260.2080606@gmail.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4E4F8260.2080606@gmail.com> Message-ID: <20110820105708.6d1d24b2@dilbert> On Sat, 20 Aug 2011 15:16:08 +0530 hackingKK wrote: > Well, they might be indented in the right places but i don't know if > loops, conditions, functions, if they all happen or not. > :) [Entire spam deleted AGAIN] Good grief! Haven't you seen all the followups to that posting you replied to? Are you two actually in cahoots with the spammer? Wait, I get it. The spammer, Matty and you are all on gmail. You are all the same person, aren't you? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Sat Aug 20 10:59:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 15:59:53 +0100 Subject: Really, stop repeating spam! (Was: Hot Girls...) In-Reply-To: <20110820105708.6d1d24b2@dilbert> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4E4F8260.2080606@gmail.com> <20110820105708.6d1d24b2@dilbert> Message-ID: On Sat, Aug 20, 2011 at 3:57 PM, D'Arcy J.M. Cain wrote: > Wait, I get it. ?The spammer, Matty and you are all on gmail. ?You are > all the same person, aren't you? > Gmail is all one person now? That would explain why I keep seeing things I agree with. I had no idea there were so many of me around! Wait, does that make me Agent Smith? ChrisA From research at johnohagan.com Sat Aug 20 11:03:05 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 21 Aug 2011 01:03:05 +1000 Subject: Compare tuples of different lenght In-Reply-To: References: Message-ID: <20110821010305.726f9d431500b679214762f5@johnohagan.com> On Sat, 20 Aug 2011 01:25:18 -0700 (PDT) Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. [...] This should work: def long_match(tuples): sorted_tuples = sorted(tuples, key=len) for n, t in enumerate(sorted_tuples): for s in sorted_tuples[n + 1:]: if len(s) > len(t) and any(i in s for i in t): tuples.remove(t) break return tuples Regards, John From sajmikins at gmail.com Sat Aug 20 12:06:38 2011 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 20 Aug 2011 09:06:38 -0700 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: On Mon, Aug 15, 2011 at 4:26 PM, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes > -- > http://mail.python.org/mailman/listinfo/python-list > Probably not the most efficient way, but I wanted to mention it: from difflib import SequenceMatcher def list_in(a, b): '''Is a completely contained in b?''' matcher = SequenceMatcher(a=a, b=b) m = matcher.find_longest_match(0, len(a), 0, len(b)) return m.size == len(a) Cheers, ~Simon From kw at codebykevin.com Sat Aug 20 13:39:20 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 20 Aug 2011 13:39:20 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: On 8/19/11 4:02 PM, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. > You can certainly try to install them via easy_install, I supposed, but it's doubtful they would do anything, as the Mac does not support win32 API calls any more than Windows supports Cocoa/Objective-C calls. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From mydevgroup at gmail.com Sat Aug 20 13:48:47 2011 From: mydevgroup at gmail.com (George) Date: Sat, 20 Aug 2011 18:48:47 +0100 Subject: List spam In-Reply-To: <87ei0gbopw.fsf@benfinney.id.au> Message-ID: I find python group is filled with spam mails, is there any way to filter these mails before sending it to the group. I can't see this situation with similar user group, such as the jsr. George. On 20/08/2011 07:07, "Ben Finney" wrote: > Javier writes: > You will lose a lot of people > asking/answering interesting stuff, and > maybe eventually the list will > die. I don't think it would die, but the chances are greater that it > would become insular and further disconnected from the Python community, > and hence far less useful. > Me (like many people with little free time) > seldom post in > blogs/forums/mailing lists where I need to register. +1 -- > \ ?Ignorance more frequently begets confidence than does | `\ > knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) > | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list From maxmoroz at gmail.com Sat Aug 20 14:20:47 2011 From: maxmoroz at gmail.com (Max Moroz) Date: Sat, 20 Aug 2011 11:20:47 -0700 Subject: extended slicing and negative stop value problem Message-ID: Would it be a good idea to change Python definition so that a[10, -1, -1] referred to the elements starting with position 10, going down to the beginning? This would require disabling the "negative stop value means counting from the end of the array" magic whenever the step value is negative. The reason for this idea is that many people (me including) try to use extended slices with negative step values, only to realize that they are messed up. For example, if your stop value is reduced in a loop from a positive number to -1, the behavior breaks whenever it hits -1. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 20 14:29:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 19:29:42 +0100 Subject: extended slicing and negative stop value problem In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > Would it be a good idea to change Python definition so that?a[10, -1, -1] > referred to the elements starting with position 10, going down to the > beginning? Well, first off I think it's a dangerous idea to change semantics of something like that. I can see your use case, but I think that what you want is covered by simply omitting the stop marker: >>> a="qwertyuiopasdfghjklzxcvbnm" >>> a[10:1:-1] 'apoiuytre' >>> a[10:0:-1] 'apoiuytrew' >>> a[10::-1] 'apoiuytrewq' If you're using a variable for the stop value, you just need to set it to an explicit None if it would fall negative: >>> a[10:None:-1] 'apoiuytrewq' Hope that helps! ChrisA From maxmoroz at gmail.com Sat Aug 20 14:52:20 2011 From: maxmoroz at gmail.com (Max) Date: Sat, 20 Aug 2011 11:52:20 -0700 (PDT) Subject: extended slicing and negative stop value problem References: Message-ID: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> On Aug 20, 11:29?am, Chris Angelico wrote: > If you're using a variable for the stop value, you just need to set it > to an explicit None if it would fall negative: > > >>> a[10:None:-1] > That doesn't work if it's set in a loop or if it's calculated as a formula. For example, this very simple code doesn't work because of the "-1 problem". # find the longest substring that reads the same left to right and right to left for substr_length in range(len(input),0,-1): for starting_pos in range(len(input)-substr_length+1): ending_pos = starting_pos + substr_length - 1 if input[starting_pos:ending_pos+1] == input[ending_pos : starting_pos-1 : -1]: print(input[starting_pos:ending_pos+1]) exit(0) Of course you can rewrite it, but it becomes quite ugly. (Not to mention, people who learn the language would not always know this, and will end up with a bug.) From no.email at nospam.invalid Sat Aug 20 15:18:25 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 20 Aug 2011 12:18:25 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xipprsxha.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> You can catch all exceptions by catching the base class Exception: > > Except that is nearly always poor advice, because it catches too much: it > hides bugs in code, as well as things which should be caught. > You should always catch the absolute minimum you need to catch. But there's no way to know what that minimum is. Python libraries throw all sorts of exceptions that their documentation doesn't mention. Java's checked exceptions are obnoxious but they do have their attractions. From rosuav at gmail.com Sat Aug 20 15:53:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 20:53:53 +0100 Subject: extended slicing and negative stop value problem In-Reply-To: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> References: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> Message-ID: On Sat, Aug 20, 2011 at 7:52 PM, Max wrote: > That doesn't work if it's set in a loop or if it's calculated as a > formula. For example, this very simple code doesn't work because of > the "-1 problem". > Right, which is what I meant by setting it to an explicit None: if input[starting_pos:ending_pos+1] == input[ending_pos : starting_pos-1 if starting_pos >= 0 else None : -1]: You're right that it starts to get ugly, though. Of course, there are other ways to find the longest palindromic substring in a string: # I wouldn't bother counting a one-character "palindrome" for substr_length in range(len(input),1,-1): for starting_pos in range(len(input)-substr_length+1): ending_pos = starting_pos + substr_length - 1 testme = input[starting_pos:ending_pos+1] if testme == testme[::-1]: print(testme) exit(0) That is, snip out the string and then reverse that snipped piece, rather than reverse-slicing from the original. This doesn't solve the issue of slicing backwards with variable halts, though. ChrisA From steve+comp.lang.python at pearwood.info Sat Aug 20 16:14:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 21 Aug 2011 06:14:37 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> Message-ID: <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> Paul Rubin wrote: > Steven D'Aprano writes: >>> You can catch all exceptions by catching the base class Exception: >> >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. >> You should always catch the absolute minimum you need to catch. > > But there's no way to know what that minimum is. Python libraries throw > all sorts of exceptions that their documentation doesn't mention. Yes, you're absolutely correct. But it's also irrelevant. Most of those exceptions should not be caught, even if you know what they are, because they represent either bugs that should be fixed, or bad data which should raise an exception. A bare except, or except Exception, is hardly ever the right approach. As for exceptions which should be caught, they should be dealt with on a case-by-case basis. There's no need to identify all those obscure exception-raising cases ahead of time. After all, unless you're writing software for a nuclear reactor, or an aeroplane's autopilot, chances are that *bugs don't really matter*. That is to say, if you release software with a hidden bug, the consequences generally aren't very important. (Depends on the nature of the software, and the bug, of course. Sometimes bugs are important. How's your test suite?) At some point, you will get a bug report, and then you will fix the bug. The fix may involve catching an extra exception, or avoiding generating the exception in the first place. Trying to predict ahead of time every possible exception that could be raised, and deal with them correctly (as opposed to just sweeping them under the carpet), is not only impossible but also usually unnecessary. It took me a long time to realise that the world won't end if I write a piece of software with a bug. Now I realise that software is never finished, there's always going to be a next version, so trying to make it perfect is a fool's errand. It's very liberating :) > Java's checked exceptions are obnoxious but they do have their > attractions. No doubt about it, the concept is attractive, but a few Java heavyweights now consider checked exceptions to be a mistake. http://www.mindview.net/Etc/Discussions/CheckedExceptions http://radio-weblogs.com/0122027/stories/2003/04/01/JavasCheckedExceptionsWereAMistake.html More here: http://www.ibm.com/developerworks/java/library/j-jtp05254/index.html -- Steven From nagle at animats.com Sat Aug 20 16:15:41 2011 From: nagle at animats.com (John Nagle) Date: Sat, 20 Aug 2011 13:15:41 -0700 Subject: try... except with unknown error types In-Reply-To: References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e501614$0$2161$742ec2ed@news.sonic.net> On 8/19/2011 1:24 PM, John Gordon wrote: > In<4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > >>> You can catch all exceptions by catching the base class Exception: > >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. > >> You should always catch the absolute minimum you need to catch. Right. When in doubt, catch EnvironmentError. That means something external to the program, at the OS or network level, has a problem. "Exception" covers errors which are program bugs, like references to undefined class members. John Nagle From steve+comp.lang.python at pearwood.info Sat Aug 20 16:40:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 21 Aug 2011 06:40:01 +1000 Subject: extended slicing and negative stop value problem References: Message-ID: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> Pardon me for breaking threading, but I don't have Max's original post. On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > Would it be a good idea to change Python definition so that a[10, -1, -1] I presume you mean slice notation a[10:-1:-1]. > referred to the elements starting with position 10, going down to the > beginning? No, almost certainly not. Such a change would break backwards compatibility, and so would only be allowed under very unusual circumstances: the current behaviour would have to be a major problem, or the new behaviour a huge benefit, or both, to make up for: (1) the extra work needed to change the behaviour (probably involving a "from __future__ import ..." feature for the first version or two); (2) breaking people's existing code; and (3) forcing people to learn the new behaviour and unlearn the old. Even if the old behaviour is "wrong", the work needed to fix it may be more than the benefit. If this was going to be "fixed", the time was probably about three years ago, when Python3 was just starting. Now such a change will probably need to wait for the hypothetical Python 4000. > This would require disabling the "negative stop value means counting from > the end of the array" magic whenever the step value is negative. Which will hurt people who expect the current behaviour: >>> a[8:-8:-1] [8, 7, 6, 5, 4, 3] > The reason for this idea is that many people (me including) try to use > extended slices with negative step values, only to realize that they are > messed up. For example, if your stop value is reduced in a loop from a > positive number to -1, the behavior breaks whenever it hits -1. Yes, negative step values are unintuitive, especially if the step is not -1. The solution is, "Don't do that then!". The usual advice is to do your slicing twice, reversing it the second time: a[0:11][::-1] # Instead of a[10:-1:-1], which looks like it should work, but doesn't. (or use the reversed() built-in instead of the second slice), or to write a helper function to adjust the indexes and get whatever behaviour you like. Hint: >>> a[10:-11:-1] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] -- Steven From johnny.venter at zoho.com Sat Aug 20 19:51:29 2011 From: johnny.venter at zoho.com (Johnny Venter) Date: Sat, 20 Aug 2011 19:51:29 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? I found dcerpc might be the way to go. On Aug 20, 2011, at 1:39 PM, Kevin Walzer wrote: > On 8/19/11 4:02 PM, johnny.venter wrote: >> >> Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. >> > > You can certainly try to install them via easy_install, I supposed, but it's doubtful they would do anything, as the Mac does not support win32 API calls any more than Windows supports Cocoa/Objective-C calls. > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Aug 20 19:57:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 00:57:21 +0100 Subject: Python Windows Extensions for Mac In-Reply-To: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: On Sun, Aug 21, 2011 at 12:51 AM, Johnny Venter wrote: > Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? > The concept doesn't have meaning on a non-Windows computer, so I am going to take the liberty of assuming that you really want to query them from a different computer - some kind of network query. If that's not the case, can you clarify exactly what your setup is? Chris Angelico From greg.ewing at canterbury.ac.nz Sat Aug 20 20:37:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 21 Aug 2011 12:37:34 +1200 Subject: Replacement for the shelve module? In-Reply-To: <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9bb2ahFgjbU1@mid.individual.net> > Robert Kern wrote: > >>That's just incorrect. You shouldn't use (binary) floats for many >>*accounting* purposes, but for many financial/econometric analyses, floats >>are de rigeur and work much better than decimals There's a certain accounting package I work with that *does* use floats -- binary ones -- for accounting purposes, and somehow manages to get away with it. Not something I would recommend trying at home, though. -- Greg From rosuav at gmail.com Sat Aug 20 20:54:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 01:54:29 +0100 Subject: Replacement for the shelve module? In-Reply-To: <9bb2ahFgjbU1@mid.individual.net> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> <9bb2ahFgjbU1@mid.individual.net> Message-ID: On Sun, Aug 21, 2011 at 1:37 AM, Gregory Ewing wrote: > There's a certain accounting package I work with that *does* > use floats -- binary ones -- for accounting purposes, and > somehow manages to get away with it. Not something I would > recommend trying at home, though. > Probably quite a few, actually. It's not a very visible problem so long as you always have plenty of "spare precision", and you round everything off to two decimals (or however many for your currency). Eventually you'll start seeing weird results that are a cent off, but you won't notice them often. And hey. You store $1.23 as 1.23, and it just works! It must be the right thing to do! Me, I store dollars-and-cents currency in cents. Always. But that's because I never need fractional cents. I'm not sure what the best way to handle fractional cents is, but I'm fairly confident that this isn't it: http://thedailywtf.com/Articles/Price-in-Nonsense.aspx ChrisA From johnny.venter at zoho.com Sun Aug 21 01:38:24 2011 From: johnny.venter at zoho.com (Johnny Venter) Date: Sun, 21 Aug 2011 01:38:24 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: From my mac, I want to use python to access and read objects from a remote Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? On Aug 20, 2011, at 7:57 PM, Chris Angelico wrote: > On Sun, Aug 21, 2011 at 12:51 AM, Johnny Venter wrote: >> Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? >> > > The concept doesn't have meaning on a non-Windows computer, so I am > going to take the liberty of assuming that you really want to query > them from a different computer - some kind of network query. If that's > not the case, can you clarify exactly what your setup is? > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Aug 21 03:30:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 08:30:07 +0100 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: > Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: > > From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? > Then the "use Python" part is relatively immaterial; what you need to know is: What network protocol are you using to "access and read objects"? Start by researching that; once you know the details (is it even TCP/IP-based?), you can look into whether Python has facilities for speaking that protocol. ChrisA From yasar11732 at gmail.com Sun Aug 21 04:09:50 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 21 Aug 2011 11:09:50 +0300 Subject: Optimizing Text Similarity Algorithm Message-ID: Hi, I originally posted this question on stackoverflow, you can find it here: http://stackoverflow.com/q/7133350/886669 I just want people check what I am doing and express their opinion about the thing I am doing is acceptable, or are there some expects of it that could change. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jefflovejapan at gmail.com Sun Aug 21 06:03:09 2011 From: jefflovejapan at gmail.com (jefflovejapan) Date: Sun, 21 Aug 2011 03:03:09 -0700 (PDT) Subject: Installing numpy on 2.7 (OS X 10.7) Message-ID: I'm following the instructions given here, but it isn't working. Specifically, I'm getting: Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory even though I completed the two downloads from github successfully. Any ideas why this wouldn't be working, or any ideas where I can look for better instructions? From alec.taylor6 at gmail.com Sun Aug 21 06:13:07 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 21 Aug 2011 20:13:07 +1000 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: Perhaps you'd be better off with something like RunDeck (Free, Open-Source, Cross-Platform, CopyLeft) for this kind of problem. On Sun, Aug 21, 2011 at 5:30 PM, Chris Angelico wrote: > On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: >> Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: >> >> From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? >> > > Then the "use Python" part is relatively immaterial; what you need to > know is: What network protocol are you using to "access and read > objects"? Start by researching that; once you know the details (is it > even TCP/IP-based?), you can look into whether Python has facilities > for speaking that protocol. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Sun Aug 21 09:39:36 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 21 Aug 2011 09:39:36 -0400 Subject: Installing numpy on 2.7 (OS X 10.7) In-Reply-To: References: Message-ID: On Sun, Aug 21, 2011 at 6:03 AM, jefflovejapan wrote: > I'm following the instructions given Installing_SciPy/Mac_OS_X">here, but it isn't working. > Specifically, I'm getting: > > Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ > Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such > file or directory > > even though I completed the two downloads from github successfully. > Any ideas why this wouldn't be working, or any ideas where I can look > for better instructions? > -- As the error says, it can't find the setup.py file. My guess would be you forgot to cd to the newly created directory. You have to "cd numpy" (or cd scipy if you're trying to install that) first to get into the directory with the install script. From irmen.NOSPAM at xs4all.nl Sun Aug 21 11:28:52 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 21 Aug 2011 17:28:52 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: <4e512435$0$23850$e4fe514c@news2.news.xs4all.nl> On 21-8-2011 1:51, Johnny Venter wrote: > Thank you all for the replies. I would like to query various Windows' objects and > resources from Mac and/or Linux such as Active Directory users, network shares, group > members, etc... What module or methods can I use with python to accomplish this? A way to approach this problem is installing Python + windows extensions on the actual windows machine(s) you want to query. Then create some form of a server process that does the windows specific stuff locally, and exposes an interface with the functions you want to provide to your remote machine(s). Talk with the server process using some form of platform independent IPC, for instance Pyro: http://pypi.python.org/pypi/Pyro4/ Be careful what methods you expose this way though (security issues!) Irmen From emile at fenx.com Sun Aug 21 12:31:19 2011 From: emile at fenx.com (Emile van Sebille) Date: Sun, 21 Aug 2011 09:31:19 -0700 Subject: decorator issue with modules dbus & gobject In-Reply-To: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> References: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Message-ID: On 8/18/2011 5:02 AM Makiavelik said... > Hi, > Here is a sample code that reproduces the issue : Not really 'sample' enough to allow others to investigate... ImportError: No module named gobject ImportError: No module named dbus ImportError: No module named dbus.mainloop.glib Try to eliminate the non-standard dependencies. I wanted to check the default value set in timeout but there's too much crap to clean up. Emile From laurent.payot at gmail.com Sun Aug 21 12:52:23 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 09:52:23 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") Message-ID: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Hi Folks, I was arguing with a guy who was sure that incrementing a variable i with "i += 1" is faster than "i = i + 1". I couldn't tell if he was right or wrong so I did a little benchmark with the very useful timeit module. Here are the results on my little Linux Eeepc Netbook (using Python 3.2): Computing, please wait... Results for 1000000 times "i = i + 1": 0.37591004371643066 0.3827171325683594 0.37238597869873047 0.37305116653442383 0.3725881576538086 0.37294602394104004 0.3712761402130127 0.37357497215270996 0.371567964553833 0.37359118461608887 Total 3.7396 seconds. Results for 1000000 times "i += 1": 0.3821070194244385 0.3802030086517334 0.3828878402709961 0.3823058605194092 0.3801591396331787 0.38340115547180176 0.3795340061187744 0.38153910636901855 0.3835160732269287 0.381864070892334 Total 3.8175 seconds. ==> "i = i + 1" is 2.08% faster than "i += 1". I did many tests and "i = i + 1" always seems to be around 2% faster than "i += 1". This is no surprise as the += notation seems to be a syntaxic sugar layer that has to be converted to i = i + 1 anyway. Am I wrong in my interpretation? Btw here's the trivial Python 3.2 script I made for this benchmark: import timeit r = 10 n = 1000000 s1 = "i = i + 1" s2 = "i += 1" t1 = timeit.Timer(stmt=s1, setup="i = 0") t2 = timeit.Timer(stmt=s2, setup="i = 0") print("Computing, please wait...") results1 = t1.repeat(repeat=r, number=n) results2 = t2.repeat(repeat=r, number=n) print('\nResults for {} times "{}":'.format(n, s1)) sum1 = 0 for result in results1: print(result) sum1 += result print("Total {:.5} seconds.".format(sum1)) print('\nResults for {} times "{}":'.format(n, s2)) sum2 = 0 for result in results2: print(result) sum2 += result print("Total {:.5} seconds.".format(sum2)) print('\n==> "{}" is {:.3}% faster than "{}".'.format(s1,(sum2 / sum1) * 100 - 100, s2)) Comments are welcome... From woooee at gmail.com Sun Aug 21 12:59:11 2011 From: woooee at gmail.com (woooee) Date: Sun, 21 Aug 2011 09:59:11 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> as the += notation seems to be a syntaxic sugar layer that has to be converted to i = i + 1 anyway. That has always been my understanding. The faster way is to append to a list as concatenating usually, requires the original string, accessing an intermediate block of memory, and the memory for the final string. x_list.append(value) to_string = "".join(x_list) From laurent.payot at gmail.com Sun Aug 21 13:03:14 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 10:03:14 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> Message-ID: Well I agree with you about string concatenation, but here I'm talking about integers incrementation... From irmen at -NOSPAM-xs4all.nl Sun Aug 21 13:14:19 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Sun, 21 Aug 2011 19:14:19 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> Message-ID: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> On 21-08-11 19:03, Laurent wrote: > Well I agree with you about string concatenation, but here I'm talking about integers incrementation... Seems the two forms are not 100% identical: >>> import dis >>> def f1(x): ... x=x+1 ... >>> def f2(x): ... x+=1 ... >>> >>> dis.dis(f1) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 STORE_FAST 0 (x) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 INPLACE_ADD 7 STORE_FAST 0 (x) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE >>> What the precise difference (semantics and speed) is between the BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source code or maybe someone knows it from memory :-) Irmen From maxmoroz at gmail.com Sun Aug 21 13:27:26 2011 From: maxmoroz at gmail.com (Max) Date: Sun, 21 Aug 2011 10:27:26 -0700 (PDT) Subject: extended slicing and negative stop value problem References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> On Aug 20, 1:40?pm, Steven D'Aprano wrote: > Pardon me for breaking threading, but I don't have Max's original post. Not sure why; I also can't see it! I'll copy it at the end just in case. > On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > > Would it be a good idea to change Python definition so that a[10, -1, -1] > > I presume you mean slice notation a[10:-1:-1]. > > > referred to the elements starting with position 10, going down to the > > beginning? > > If this was going to be "fixed", the time was probably > about three years ago, when Python3 was just starting. Now such a change > will probably need to wait for the hypothetical Python 4000. Yeah, I was surprised that it didn't bother anyone.. > The usual advice is to do your slicing twice, reversing it the second time: > > a[0:11][::-1] > # Instead of a[10:-1:-1], which looks like it should work, but doesn't. It works nicely, but it is 1.3 times slower in my code (I am surprised the interpreter doesn't optimize this). From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 13:27:38 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Sun, 21 Aug 2011 19:27:38 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> Message-ID: <1313947658.3424.3.camel@thegeorge> > What the precise difference (semantics and speed) is between the > BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source > code or maybe someone knows it from memory :-) > > Irmen > from Python/ceval.c: 1316 case BINARY_ADD: 1317 w = POP(); 1318 v = TOP(); 1319 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { 1320 /* INLINE: int + int */ 1321 register long a, b, i; 1322 a = PyInt_AS_LONG(v); 1323 b = PyInt_AS_LONG(w); 1324 /* cast to avoid undefined behaviour 1325 on overflow */ 1326 i = (long)((unsigned long)a + b); 1327 if ((i^a) < 0 && (i^b) < 0) 1328 goto slow_add; 1329 x = PyInt_FromLong(i); 1330 } 1331 else if (PyString_CheckExact(v) && 1332 PyString_CheckExact(w)) { 1333 x = string_concatenate(v, w, f, next_instr); 1334 /* string_concatenate consumed the ref to v */ 1335 goto skip_decref_vx; 1336 } 1337 else { 1338 slow_add: 1339 x = PyNumber_Add(v, w); 1340 } 1341 Py_DECREF(v); 1342 skip_decref_vx: 1343 Py_DECREF(w); 1344 SET_TOP(x); 1345 if (x != NULL) continue; 1346 break; 1532 case INPLACE_ADD: 1533 w = POP(); 1534 v = TOP(); 1535 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { 1536 /* INLINE: int + int */ 1537 register long a, b, i; 1538 a = PyInt_AS_LONG(v); 1539 b = PyInt_AS_LONG(w); 1540 i = a + b; 1541 if ((i^a) < 0 && (i^b) < 0) 1542 goto slow_iadd; 1543 x = PyInt_FromLong(i); 1544 } 1545 else if (PyString_CheckExact(v) && 1546 PyString_CheckExact(w)) { 1547 x = string_concatenate(v, w, f, next_instr); 1548 /* string_concatenate consumed the ref to v */ 1549 goto skip_decref_v; 1550 } 1551 else { 1552 slow_iadd: 1553 x = PyNumber_InPlaceAdd(v, w); 1554 } 1555 Py_DECREF(v); 1556 skip_decref_v: 1557 Py_DECREF(w); 1558 SET_TOP(x); 1559 if (x != NULL) continue; 1560 break; As for using Integers, the first case (line 1319 and 1535) are true and there is no difference in Code. However, Python uses a huge switch-case construct to execute it's opcodes and INPLACE_ADD cames after BINARY_ADD, hence the difference in speed. To be clear, this is nothing you should consider when writing fast code. Complexity wise they both are the same. From laurent.payot at gmail.com Sun Aug 21 13:48:48 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 10:48:48 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> Thanks for these explanations. So 2% speed difference just between "B..." and "I..." entries in a huge alphabetically-ordered switch case? Wow. Maybe there is some material for speed enhancement here... From hansmu at xs4all.nl Sun Aug 21 13:57:50 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 21 Aug 2011 19:57:50 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e51471e$0$23880$e4fe514c@news2.news.xs4all.nl> On 21/08/11 19:14:19, Irmen de Jong wrote: > What the precise difference (semantics and speed) is between the > BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source > code or maybe someone knows it from memory :-) There is a clear difference in semantics: BINARY_ADD always produces a new object, INPLACE_ADD may modify its left-hand operand in situ (if it's mutable). Integers are immutable, so for integers the semantics are the same, but for lists, for example, the two are different: >>> x = [2, 3, 5, 7] >>> y = [11, 13] >>> x+y [2, 3, 5, 7, 11, 13] >>> x [2, 3, 5, 7] # x still has its original value >>> x += y >>> x [2, 3, 5, 7, 11, 13] # x is now modified >>> For integers, I would not expect a measurable difference in speed. Hope this helps, -- HansM From laurent.payot at gmail.com Sun Aug 21 14:03:16 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 11:03:16 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> Message-ID: <8530af1c-f723-47d6-afa9-2a8d9d3b17b1@glegroupsg2000goo.googlegroups.com> Well 2% more time after 1 million iterations so you're right I won't consider it. From lists at cheimes.de Sun Aug 21 14:24:17 2011 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Aug 2011 20:24:17 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: Am 21.08.2011 19:27, schrieb Andreas L?scher: > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. I don't think that's the reason. Modern compiles turn a switch statement into a jump or branch table rather than a linear search like chained elif statements. Python 3.2 on Linux should also be compiled with computed gotos. Christian From no.email at nospam.invalid Sun Aug 21 14:26:51 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 21 Aug 2011 11:26:51 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xty9ahb84.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> But there's no way to know what that minimum is. Python libraries throw >> all sorts of exceptions that their documentation doesn't mention. > > Yes, you're absolutely correct. But it's also irrelevant. Most of those > exceptions should not be caught, even if you know what they are, because > they represent either bugs that should be fixed, or bad data which should > raise an exception. A bare except, or except Exception, is hardly ever the > right approach. I'm not sure what to do instead. The exceptions I'm currently dealing with happen when certain network operations go wrong (e.g. network or remote host is down, connection fails, etc.) The remedy in each case is to catch the exception, log the error, and try the operation again later. But there's no guaranteed-to-be-complete list in the Python docs of all the exceptions that can be thrown. A new and surprising mode of network failure can lead to an unhandled exception, unless you catch everything. The Erlang approach is tempting. Don't catch the exception at all--just let the process crash, and restart it. But that's a more heavyweight operation in Python. > After all, unless you're writing > software for a nuclear reactor, or an aeroplane's autopilot, chances are > that *bugs don't really matter*. That is to say, if you release software > with a hidden bug, the consequences generally aren't very important. It's a retail application that would cause some business disruption and a pissed off customer if the program went down. Also it's in an embedded box on a customer site. It's not in Antarctica or anything like that, but it's a few towns over, and someone would have to drive there (probably through heavy traffic) if something went wrong that power cycling the box couldn't fix. > It took me a long time to realise that the world won't end if I write a > piece of software with a bug. It's not the end of the world if I get run over a truck, but such an event would be of enough consequence to me personally that I find it worth going to some trouble to avoid it. From roy at panix.com Sun Aug 21 14:52:50 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 14:52:50 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: In article , Christian Heimes wrote: > Am 21.08.2011 19:27, schrieb Andreas L?scher: > > As for using Integers, the first case (line 1319 and 1535) are true and > > there is no difference in Code. However, Python uses a huge switch-case > > construct to execute it's opcodes and INPLACE_ADD cames after > > BINARY_ADD, hence the difference in speed. > > I don't think that's the reason. Modern compiles turn a switch statement > into a jump or branch table rather than a linear search like chained > elif statements. This is true even for very small values of "modern". I remember the Unix v6 C compiler (circa 1977) was able to do this. From rosuav at gmail.com Sun Aug 21 15:17:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 20:17:59 +0100 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 21, 2011 at 7:26 PM, Paul Rubin wrote: > I'm not sure what to do instead. ?The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) ?The remedy in each case is > to catch the exception, log the error, and try the operation again > later. ?But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. ?A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. > A new and surprising mode of network failure would be indicated by a new subclass of IOError or EnvironmentError. If you catch one of those, you should catch it. That's the benefit of hierarchical exceptions. ChrisA From ethan at stoneleaf.us Sun Aug 21 15:22:47 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 21 Aug 2011 12:22:47 -0700 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4E515B07.70303@stoneleaf.us> Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever the >> right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. In a case like this I can see catching everything so long as (which you say you are doing) you log the error somehow -- what's really frustrating is when the error is simply tossed with no record whatsoever... what a pain to debug! ~Ethan~ From tjreedy at udel.edu Sun Aug 21 15:39:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 15:39:53 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: On 8/21/2011 1:27 PM, Andreas L?scher wrote: >> What the precise difference (semantics and speed) is between the >> BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source >> code or maybe someone knows it from memory :-) >> >> Irmen >> > from Python/ceval.c: > > 1316 case BINARY_ADD: > 1317 w = POP(); > 1318 v = TOP(); > 1319 if (PyInt_CheckExact(v)&& PyInt_CheckExact(w)) { > 1320 /* INLINE: int + int */ > 1321 register long a, b, i; > 1322 a = PyInt_AS_LONG(v); > 1323 b = PyInt_AS_LONG(w); > 1324 /* cast to avoid undefined behaviour > 1325 on overflow */ > 1326 i = (long)((unsigned long)a + b); > 1327 if ((i^a)< 0&& (i^b)< 0) > 1328 goto slow_add; > 1329 x = PyInt_FromLong(i); > 1330 } > 1331 else if (PyString_CheckExact(v)&& > 1332 PyString_CheckExact(w)) { > 1333 x = string_concatenate(v, w, f, next_instr); > 1334 /* string_concatenate consumed the ref to v */ > 1335 goto skip_decref_vx; > 1336 } > 1337 else { > 1338 slow_add: > 1339 x = PyNumber_Add(v, w); > 1340 } > 1341 Py_DECREF(v); > 1342 skip_decref_vx: > 1343 Py_DECREF(w); > 1344 SET_TOP(x); > 1345 if (x != NULL) continue; > 1346 break; > > 1532 case INPLACE_ADD: > 1533 w = POP(); > 1534 v = TOP(); > 1535 if (PyInt_CheckExact(v)&& PyInt_CheckExact(w)) { > 1536 /* INLINE: int + int */ > 1537 register long a, b, i; > 1538 a = PyInt_AS_LONG(v); > 1539 b = PyInt_AS_LONG(w); > 1540 i = a + b; > 1541 if ((i^a)< 0&& (i^b)< 0) > 1542 goto slow_iadd; > 1543 x = PyInt_FromLong(i); > 1544 } > 1545 else if (PyString_CheckExact(v)&& > 1546 PyString_CheckExact(w)) { > 1547 x = string_concatenate(v, w, f, next_instr); > 1548 /* string_concatenate consumed the ref to v */ > 1549 goto skip_decref_v; > 1550 } > 1551 else { > 1552 slow_iadd: > 1553 x = PyNumber_InPlaceAdd(v, w); > 1554 } > 1555 Py_DECREF(v); > 1556 skip_decref_v: > 1557 Py_DECREF(w); > 1558 SET_TOP(x); > 1559 if (x != NULL) continue; > 1560 break; > > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. > > To be clear, this is nothing you should consider when writing fast code. > Complexity wise they both are the same. With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with floats (0.0 and 1.0), 6% -- Terry Jan Reedy From tjreedy at udel.edu Sun Aug 21 15:52:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 15:52:28 -0400 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: On 8/21/2011 2:26 PM, Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever the >> right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. I would expect that catching socket.error (or even IOError) should catch all of those. "exception socket.error A subclass of IOError, this exception is raised for socket-related errors. It is recommended that you inspect its errno attribute to discriminate between different kinds of errors." > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. -- Terry Jan Reedy From laurent.payot at gmail.com Sun Aug 21 15:53:04 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:53:04 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > floats (0.0 and 1.0), 6% For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. From laurent.payot at gmail.com Sun Aug 21 15:53:04 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:53:04 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > floats (0.0 and 1.0), 6% For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. From laurent.payot at gmail.com Sun Aug 21 15:55:00 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:55:00 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <01896ae1-1a6e-4458-b9a0-1a071f8ffbae@glegroupsg2000goo.googlegroups.com> Actually 6% between float themselves is just as not-understandable. From laurent.payot at gmail.com Sun Aug 21 15:55:00 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:55:00 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <01896ae1-1a6e-4458-b9a0-1a071f8ffbae@glegroupsg2000goo.googlegroups.com> Actually 6% between float themselves is just as not-understandable. From laurent.payot at gmail.com Sun Aug 21 16:04:24 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 13:04:24 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <3fa8a0a4-9321-4442-9133-ad44f7513486@glegroupsg2000goo.googlegroups.com> I did the test several times with floats on my machine and the difference is not as big as for integers: ==> "i = i + 1.0" is 0.732% faster than "i += 1.0". It seems normal as the float addition is supposed to be slower than integer addition, thus the syntaxic difference is comparatively less important. From nobody at nowhere.com Sun Aug 21 17:07:56 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 21 Aug 2011 22:07:56 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, 21 Aug 2011 09:52:23 -0700, Laurent wrote: > I did many tests and "i = i + 1" always seems to be around 2% faster > than "i += 1". This is no surprise as the += notation seems to be a > syntaxic sugar layer that has to be converted to i = i + 1 anyway. Am I > wrong in my interpretation? It depends. If the value on the left has an __iadd__ method, that will be called; the value will be updated in-place, so all references to that object will be affected: > import numpy as np > a = np.zeros(3) > b = a > a array([ 0., 0., 0.]) > b array([ 0., 0., 0.]) > a += 1 > a array([ 1., 1., 1.]) > b array([ 1., 1., 1.]) If the value on the left doesn't have an __iadd__ method, then addition is performed and the name is re-bound to the result: > a = a + 1 > a array([ 2., 2., 2.]) > b array([ 1., 1., 1.]) If you're writing code which could reasonably be expected to work with arbitrary "numeric" values, you should decide which to use according to whether in-place modification is appropriate rather than trivial performance differences. If a difference of a few percent is significant, Python is probably the wrong language in the first place. From roy at panix.com Sun Aug 21 17:14:30 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 17:14:30 -0400 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: In article <7xty9ahb84.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. I would do something like this: try: do_some_network_stuff() except IOError: do_normal_recovery() except Exception: call_home() do_some_other_recovery() You are right, in an embedded/unattended application, you don't want to ever crash. If you ever get an error that you don't understand, you have no choice but to do the best you can to recover. I would also generate some kind of alert back to home base to tell somebody to take a look at it and make sure things are fine. I would expect that the whole application is wrapped in some kind of watchdog timer which will do a hard reset of the entire system. From clp2 at rebertia.com Sun Aug 21 18:16:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Aug 2011 15:16:21 -0700 Subject: extended slicing and negative stop value problem In-Reply-To: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> Message-ID: On Sun, Aug 21, 2011 at 10:27 AM, Max wrote: > On Aug 20, 1:40?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: >> > Would it be a good idea to change Python definition so that a[10, -1, -1] >> >> I presume you mean slice notation a[10:-1:-1]. >> >> > referred to the elements starting with position 10, going down to the >> > beginning? >> The usual advice is to do your slicing twice, reversing it the second time: >> >> a[0:11][::-1] >> # Instead of a[10:-1:-1], which looks like it should work, but doesn't. > > It works nicely, but it is 1.3 times slower in my code (I am surprised > the interpreter doesn't optimize this). That would require CPython to assume certain slicing semantics for all types (which it can't) or to check for this very specific case at runtime (which would slow down all other [list] slicing operations). A smarter implementation such as PyPy could indeed theoretically optimize this case though. Cheers, Chris From iamforufriends at gmail.com Sun Aug 21 19:07:39 2011 From: iamforufriends at gmail.com (kate for free dating) Date: Sun, 21 Aug 2011 16:07:39 -0700 (PDT) Subject: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm Message-ID: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 19:17:14 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 01:17:14 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <1313968634.3135.14.camel@thegeorge> Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: > In article , > Christian Heimes wrote: > > > Am 21.08.2011 19:27, schrieb Andreas Lscher: > > > As for using Integers, the first case (line 1319 and 1535) are true and > > > there is no difference in Code. However, Python uses a huge switch-case > > > construct to execute it's opcodes and INPLACE_ADD cames after > > > BINARY_ADD, hence the difference in speed. > > > > I don't think that's the reason. Modern compiles turn a switch statement > > into a jump or branch table rather than a linear search like chained > > elif statements. > > This is true even for very small values of "modern". I remember the > Unix v6 C compiler (circa 1977) was able to do this. What is the difference in speed between a jump table that is searched from top to bottom in comparison to an ordinary if-then-elif...? The difference can only be in the search algorithm regarding the table. Without optimization (linear search) both are the same. If the compiler applies some magic the difference can be relevant (linear complexity for if-then-elif... and O(1) if you would use a dictionary). Hence the executed code for integers is the same, there must be a slower path to the code of BINARY_ADD than to INPLACE_ADD. How would such an jump table work to behave the same liek a switch-case-statement? Beware, that things like case PRINT_NEWLINE_TO: 1802 w = stream = POP(); 1803 /* fall through to PRINT_NEWLINE */ 1804 1805 case PRINT_NEWLINE: must be supported. Bye the way: First line of ceval.c since at least Version 2.4 1 2 /* Execute compiled code */ 3 4 /* XXX TO DO: 5 XXX speed up searching for keywords by using a dictionary 6 XXX document it! 7 */ :-) From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 19:25:34 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 01:25:34 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <1313969134.3135.21.camel@thegeorge> Am Sonntag, den 21.08.2011, 12:53 -0700 schrieb Laurent: > > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > > floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. It's not as bad as you think. The addition of two integers is a cheap task (in terms of computation power). If you have two way's to to it, every little think (jumps in the code etc. ) will have a larger impact on the execution time than on an expensive operation. But every improvement on your algorithm will easily result in a significant shorter execution time than replaceing a+=1 with a=a+1 will ever do. :-) From rosuav at gmail.com Sun Aug 21 19:37:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 00:37:45 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313968634.3135.14.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: 2011/8/22 Andreas L?scher : > How would such an jump table work to behave the same liek a > switch-case-statement? If your switch statement uses a simple integer enum with sequential values, then it can be done quite easily. Take this as an example: switch (argc) { case 0: printf("No args at all, this is weird\n"); break; case 1: printf("No args\n"); break; case 2: printf("Default for second arg\n"); case 3: printf("Two args\n"); break; default: printf("Too many args\n"); break; } I compiled this using Open Watcom C, looked at the disassembly, and hereby translate it into pseudocode (I'll email/post the full 80x86 disassembly if you like): 1) Check if argc > 3 (unsigned comparison), if so jump to default case. 2) Left shift argc two places, add a constant offset, fetch a pointer from there, and jump to it - that's the jump table. One JMP statement. 3) Code follows for each case. Incidentally, the Open Watcom compiler actually turned several of the cases into offset-load of the appropriate string pointer, and then a jump to the single call to printf. The fall-through from 'case 2' to 'case 3' works fine, although it means that 'case 2' has to be de-optimized from that one simplification. This type of optimization works best when the case values are sequential. (If I remove the 'case 0', the compiler decrements argc and proceeds to continue as above.) Otherwise, the jump table has to have a lot of copies of the "default" pointer. Chris Angelico From tjreedy at udel.edu Sun Aug 21 19:38:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 19:38:22 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313968634.3135.14.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: On 8/21/2011 7:17 PM, Andreas L?scher wrote: > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: >> In article, >> Christian Heimes wrote: >> >>> Am 21.08.2011 19:27, schrieb Andreas Lscher: >>>> As for using Integers, the first case (line 1319 and 1535) are true and >>>> there is no difference in Code. However, Python uses a huge switch-case >>>> construct to execute it's opcodes and INPLACE_ADD cames after >>>> BINARY_ADD, hence the difference in speed. >>> >>> I don't think that's the reason. Modern compiles turn a switch statement >>> into a jump or branch table rather than a linear search like chained >>> elif statements. >> >> This is true even for very small values of "modern". I remember the >> Unix v6 C compiler (circa 1977) was able to do this. > > What is the difference in speed between a jump table that is searched > from top to bottom in comparison to an ordinary if-then-elif...? The > difference can only be in the search algorithm regarding the table. > Without optimization (linear search) both are the same. If the compiler > applies some magic the difference can be relevant (linear complexity for > if-then-elif... and O(1) if you would use a dictionary). A jump or branch table is applicable when the case value values are all small ints, like bytes or less. For C, the table is simply an array of pointers (addressess, with entries for unused byte codes would be a void pointer). Hence, O(1) access. https://secure.wikimedia.org/wikipedia/en/wiki/Jump_table > Hence the executed code for integers is the same, there must be a slower > path to the code of BINARY_ADD than to INPLACE_ADD. > > How would such an jump table work to behave the same liek a > switch-case-statement? Beware, that things like > > case PRINT_NEWLINE_TO: > 1802 w = stream = POP(); > 1803 /* fall through to PRINT_NEWLINE */ add jump to address of the code for PRINT_NEWLINE > 1804 > 1805 case PRINT_NEWLINE: > > must be supported. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 21 19:41:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 00:41:43 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313969134.3135.21.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: 2011/8/22 Andreas L?scher : > But every improvement on your algorithm will easily result in a > significant shorter execution time than replaceing a+=1 with a=a+1 will > ever do. :-) > Agreed. If Python needed a faster alternative to "a=a+1", then I would recommend an "a.inc()" call or something; some way to avoid looking up the value of 1. (An equivalent to C's ++a operation, if you like.) But I think you'd be hard-pressed to find any situation where improving the speed of incrementing will be significant, that wouldn't be better served by algorithmic improvements (even just using "for a in range()") or dropping to C. ChrisA From laurent.payot at gmail.com Sun Aug 21 19:49:30 2011 From: laurent.payot at gmail.com (Laurent Payot) Date: Sun, 21 Aug 2011 16:49:30 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> I made Python my language of choice because of its readability and simpleness, and not because of its speed. But it's always good to know what is the fastest sometimes when you don't want to write a module in C. So I was just wondering if there was a difference. There is, of a few percent. Anyway I will keep on using the 2% slower "i += 1" because for me that's less prone to errors because you write the variable only once, and that's more important than speed. From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 20:00:38 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 02:00:38 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: <1313971238.3713.0.camel@thegeorge> Am Sonntag, den 21.08.2011, 19:38 -0400 schrieb Terry Reedy: > On 8/21/2011 7:17 PM, Andreas L?scher wrote: > > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: > >> In article, > >> Christian Heimes wrote: > >> > >>> Am 21.08.2011 19:27, schrieb Andreas Lscher: > >>>> As for using Integers, the first case (line 1319 and 1535) are true and > >>>> there is no difference in Code. However, Python uses a huge switch-case > >>>> construct to execute it's opcodes and INPLACE_ADD cames after > >>>> BINARY_ADD, hence the difference in speed. > >>> > >>> I don't think that's the reason. Modern compiles turn a switch statement > >>> into a jump or branch table rather than a linear search like chained > >>> elif statements. > >> > >> This is true even for very small values of "modern". I remember the > >> Unix v6 C compiler (circa 1977) was able to do this. > > > > What is the difference in speed between a jump table that is searched > > from top to bottom in comparison to an ordinary if-then-elif...? The > > difference can only be in the search algorithm regarding the table. > > Without optimization (linear search) both are the same. If the compiler > > applies some magic the difference can be relevant (linear complexity for > > if-then-elif... and O(1) if you would use a dictionary). > > A jump or branch table is applicable when the case value values are all > small ints, like bytes or less. For C, the table is simply an array of > pointers (addressess, with entries for unused byte codes would be a void > pointer). Hence, O(1) access. > https://secure.wikimedia.org/wikipedia/en/wiki/Jump_table > > > Hence the executed code for integers is the same, there must be a slower > > path to the code of BINARY_ADD than to INPLACE_ADD. > > > > How would such an jump table work to behave the same liek a > > switch-case-statement? Beware, that things like > > > > case PRINT_NEWLINE_TO: > > 1802 w = stream = POP(); > > 1803 /* fall through to PRINT_NEWLINE */ > > add jump to address of the code for PRINT_NEWLINE > > > 1804 > > 1805 case PRINT_NEWLINE: > > > > must be supported. > :-) too easy or too late thanks From steve+comp.lang.python at pearwood.info Sun Aug 21 20:25:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 10:25:40 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e51a205$0$29974$c3e8da3$5496439d@news.astraweb.com> Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever >> the right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. I was waiting for you to raise network errors :) Network errors are a particularly annoying case, because although rare and undocumented, they are legitimate errors that should be caught. I feel your pain. > The Erlang approach is tempting. Don't catch the exception at all--just > let the process crash, and restart it. But that's a more heavyweight > operation in Python. The Erland approach sounds good, but as I've never used it, I don't know how well it works in practice. >> After all, unless you're writing >> software for a nuclear reactor, or an aeroplane's autopilot, chances are >> that *bugs don't really matter*. That is to say, if you release software >> with a hidden bug, the consequences generally aren't very important. > > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. Customers are always pissed off when something goes wrong, but ask them to pay an extra $300 for a battery backup unit to the hardware RAID controller *they* insisted on against your advice, and they say no. But I'm not bitter... Customer gets pissed off. What's the consequences? Do they sue you? Leave? Are they locked into a five year contract and have to pay you even if they do leave? Do you have to fix the incident at no charge, or give them two hours free support? Are you competing with armour-plated mature software that never goes down, or is the field yours alone? How price sensitive are your customers? Will they pay an extra $100,000 for an extra 9 in the expected uptime? Without knowing the consequences to *you* of failure, I can't tell you where you should be spending your time: trying to predict errors ahead of time, or fixing them once they've been seen. This is a business problem, not a software problem. Don't misunderstand me, I'm not suggesting that you shouldn't try to avoid things going wrong. But it's a hard problem. Solving it is why they pay you the big bucks *cough*: http://www.joelonsoftware.com/items/2007/12/06.html and is the difference between version 0.4 of an application, and version 3.4. If you're trying to go straight to version 3.4 without putting the software through real-world testing, then your testing better be mean and tough. *Really* tough. http://www.codinghorror.com/blog/2011/04/working-with-the-chaos-monkey.html -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 21 20:30:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 10:30:37 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > A new and surprising mode of network failure would be indicated by a > new subclass of IOError or EnvironmentError. /s/would/should/ I don't see why you expect this, when *existing* network-related failures aren't: >>> import socket >>> issubclass(socket.error, EnvironmentError) False (Fortunately that specific example is fixed in Python 3.) Besides, there's a world of difference between "should be" and "are". -- Steven From tjreedy at udel.edu Sun Aug 21 20:35:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 20:35:32 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/21/2011 5:07 PM, Nobody wrote: > If the value on the left has an __iadd__ method, that will be called; Correct > the value will be updated in-place, Not necessarily correct. The target is rebound to the return from the __iadd__ method. Augmented *assignment* is always assignment. This trips up people who try t = (1, []) t[1] += [1,2] # which *does* extend the array, but raises TypeError: 'tuple' object does not support item assignment # instead of t[1].extend([1,2]) # which extends without raising an error *IF* (and only if) the target object is mutable, then the __iadd__ may optionally mutate the target object. But the rebinding takes place nonetheless. Numbers, the subject of this thread, are not mutable and are not 'updated in-place' class test: def __init__(self, n): self.n = n def __iadd__(self, other): return test(self.n + other.n) def __repr__(self): return repr(self.n) r = test(1) t = r t += r print(r, t) # 1,2 That said, there is normally no reason to write an __ixxx__ method unless instances are mutable and the operation can be and is done in place therein. So the class above is for illustrative purposes only. A saner example is the following, which treats test examples as mutable number containers rather than as immutable surrogates. class test: def __init__(self, n): self.n = n def __add__(self, other): return test(self.n + other.n) def __iadd__(self, other): n = self.n + other.n self.n = n return n def __repr__(self): return repr(self.n) r = test(1) t = r t += r print(r, t) # 2 2 The interpreter cannot enforce that 'x += a' have the same effect as 'x = x+a', but it would break normal expectations to make the two different. > so all references to that object will be affected: Only if the target object is mutable and is mutated by the optional augmented assignment __ixxx__ methods. > > import numpy as np > > a = np.zeros(3) Numpy arrays meet the qualification above. > If the value on the left doesn't have an __iadd__ method, then addition is > performed and the name is re-bound to the result: As is also done with the results of __ixxx__ methods. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 21 20:41:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 01:41:47 +0100 Subject: try... except with unknown error types In-Reply-To: <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 22, 2011 at 1:30 AM, Steven D'Aprano wrote: > /s/would/should/ > > I don't see why you expect this, when *existing* network-related failures > aren't Ehh, granted. Definitely a case of "should". But certainly, there won't be an infinite number of new exceptions invented; most of the runtime issues you'll have will fall into a fairly small number of exception types (either by subclassing or by parameters eg errno). ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 21 21:12:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 11:12:54 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Laurent wrote: > >> With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with >> floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. > I would never have thought an interpreter would have differences like this > in syntax for something as fundamental as adding 1. Why? Python integers are rich objects, not native ints. Adding 1 is a moderately heavyweight operation far more complicated than the same operation in C. n=n+1 and n+=1 call different methods and do different things, they are *not* just different syntax. Your intuition about what should and shouldn't take the same time should not be trusted. But really, we're talking about tiny differences in speed. Such trivial differences are at, or beyond, the limit of what can realistically be measured on a noisy PC running multiple processes (pretty much all PCs these days). Here are three runs of each on my computer: [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.508 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.587 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.251 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.226 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.494 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.53 usec per loop Look at the variation between runs! About 130% variation between the fastest and slowest for each expression. And there's no reason to think that the fastest results shown is as fast as it can get. The time is dominated by noise, not the addition. For what it's worth, if I try it with a more recent Python: [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.221 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.202 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.244 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.49 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.176 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.49 usec per loop I simply do not believe that we can justify making *any* claim about the relative speeds of n=n+1 and n+=1 other than "they are about the same". Any result you get, faster or slower, will depend more on chance than on any real or significant difference in the code. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 21 21:16:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 11:16:58 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: <4e51ae0a$0$29975$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > 2011/8/22 Andreas L?scher : >> But every improvement on your algorithm will easily result in a >> significant shorter execution time than replaceing a+=1 with a=a+1 will >> ever do. :-) >> > > Agreed. If Python needed a faster alternative to "a=a+1", then I would > recommend an "a.inc()" call or something; some way to avoid looking up > the value of 1. Keep in mind that ints in Python are objects, not memory locations, and can be shared. If you are hoping for an in-place increment, I invite you to consider the following code and try to predict what it would do: a = 42 b = a b.inc() print(a) -- Steven From jefflovejapan at gmail.com Sun Aug 21 21:27:33 2011 From: jefflovejapan at gmail.com (jefflovejapan) Date: Sun, 21 Aug 2011 18:27:33 -0700 (PDT) Subject: Installing numpy on 2.7 (OS X 10.7) References: Message-ID: <9f35a78c-6af9-4e47-be4d-aaa898ac4f03@p37g2000prp.googlegroups.com> On Aug 21, 10:39?pm, Benjamin Kaplan wrote: > On Sun, Aug 21, 2011 at 6:03 AM, jefflovejapan wrote: > > I'm following the instructions given > Installing_SciPy/Mac_OS_X">here, but it isn't working. > > Specifically, I'm getting: > > > Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ > > Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such > > file or directory > > > even though I completed the two downloads from github successfully. > > Any ideas why this wouldn't be working, or any ideas where I can look > > for better instructions? > > -- > > As the error says, it can't find the setup.py file. My guess would be > you forgot to cd to the newly created directory. You have to "cd > numpy" (or cd scipy if you're trying to install that) first to get > into the directory with the install script. Of course! Thanks a lot. From timr at probo.com Sun Aug 21 22:02:56 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Aug 2011 19:02:56 -0700 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: <2vd357poedkl0icmu8m1dsmfq6aalujnpq@4ax.com> John Doe wrote: > >Tim Roberts wrote: > >> That exact code works perfectly for me. The function returns as >> soon as I press the escape key. You are running this from a >> console process, and not a GUI process, right? > >No. I am running this from within Windows, all sorts of Windows. > >So... Does that mean I will need something complex like a keyboard >hook? Or what? I see that this conversation took a nasty turn while I was on vacation. msvcrt.getch works with consoles. If you have an application where stdin and stdout are connected to a real, live console window (which looks just like a command line window), then msvcrt.getch will work. If not, then you have to use the Windows APIs. GetKeyboardState and GetKeyState can tell you if a specific key is currently being pressed. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From lists at cheimes.de Sun Aug 21 22:04:08 2011 From: lists at cheimes.de (Christian Heimes) Date: Mon, 22 Aug 2011 04:04:08 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313969134.3135.21.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: Am 22.08.2011 01:25, schrieb Andreas L?scher: > It's not as bad as you think. The addition of two integers is a cheap > task (in terms of computation power). If you have two way's to to it, > every little think (jumps in the code etc. ) will have a larger impact > on the execution time than on an expensive operation. > > But every improvement on your algorithm will easily result in a > significant shorter execution time than replaceing a+=1 with a=a+1 will > ever do. :-) You can learn an important lesson here. Since Python is a high level language without a JIT (yet) integer operations are much slower than in C or other low level languages. In general it's not a problem for most people. However if your algorithm is speed bound to integer operations or has a tight inner for loop than you can gain a considerable amount of speedup with C code. Reference counting and Python object creation need several CPU cycles. Also a good algorithm and a modern C compiler can make use of SIMD instructions, too. If you ever feel the need to implement something fast e.g. an encryption algorithm then you'd better off with a C implementation. Cython is my favourite tool for the job. Christian From me+list/python at ixokai.io Sun Aug 21 22:08:22 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 19:08:22 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <4E51BA16.7090605@ixokai.io> On 8/21/11 12:53 PM, Laurent wrote: > >> With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with >> floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. Its, seriously, not even kind of a lot at all. Percentages without context are meaningless: its 4% slower, sure -- but that is 4% of an incredibly small probably constant-time amount of time. Picking "i += 1" over "i = i + 1" based on one being 4% slower is sorta kinda crazy. The difference in speed is probably related to churn and cache as much as anything else (its not as consistent on my machine, for example): or the ceval loop doing a few more case-tests between them as others have mentioned. All in all, if 4% of a nanomicrofraction of a chunk of time is that meaningful, you're probably best served not using Python. :) That said: my advice is always to avoid += like a plague. It is magic and impossible to predict without intimate knowledge of exactly what's on the left-side. i += 1 n += x Those two things look very similar, but they may do -completely- different things depending on just what "n" is. It may or may not do something that is like: n = n + x Or, it may do something that's more akin to n.extend(x) n = n Those aren't even kind of equivalent actions. And things get more complicated if 'n' is say, n[0] (especially if something goes wrong between the extend and the rebinding). Python's usually all explicit and pretty well-defined in how its basic syntax and behaviors operate, and you usually don't really have to know details about how a data-type works to predict exactly what it's doing: in fact, its often beneficial to not pay too much attention to such details, and just assume the data type will work approximately as you'd expect. That way people can slip something-something to you and wink and say of /course/ its a dict, darling. Try it, you'll like it, okay? This sorta thing is encouraged, but it kinda depends on trusting objects to behave a certain way and for things to be predictable in both how they work and how they fail. With "i = i + 1", I know that generally speaking, my "i" is being assigned a new object and that's that, no matter what type "i" is. (Okay: I do know that you could modify __add__ to do something underhanded here, tweaking internal state and then returning self. People going out of their way to behave unpredictably is not my objection: supposedly easy and straight-forward normal Python-fu being inherently unpredictable is). For example: I just /know/ that it doesn't matter who or what may have their own binding to that object before I go and increment it, they won't be affected and everything just will work fine. With augmented assignment, I can't be sure of that. Now, while I admit, you generally do have to keep track in your head of which of your data-types are mutable vs immutable and take care with sharing mutables, the fact that "n += x" is described and generally thought of as merely syntactical sugar for: n = n + x ... lets one easily think that this should be entirely safe, even with mutable objects, because if += were merely syntactical sugar, it would be. But its not! Because += is wiggly. It can do more then one entirely different kind of behavior. Anyways. I've been kinda annoyed at augmented assignment for years now :P -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From roy at panix.com Sun Aug 21 22:09:19 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 22:09:19 -0400 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a205$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e51a205$0$29974$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > http://www.codinghorror.com/blog/2011/04/working-with-the-chaos-monkey.html I *love* being the Chaos Monkey! A few jobs ago, I had already turned in my resignation and was a short-timer, counting down the days to when I was out of there. A new server had just come in and I was helping the guy who was going to replace me set it up. This was the first server we had gotten with RAID and redundant power supplies and I wanted to test them out. My accomplice was horrified, but technically I was still his boss, so I got to do what I wanted. I opened up the drive shelve and yanked out a drive. The console printed a nice neat warning about loss of media and kept chugging along, just like it should. Then I pulled out a second drive. Sure enough, the whole array failed, just like expected. Then, I decided to have a go at the redundant power supplies. We paid a lot of money for that, and I damn well was going to test them now, when there was no real risk. I grabbed the big handle on the front of one of the (hot swappable) power supplies and pulled. The whole thing went dark. Turns out there had been an configuration error and the second power supply had never been installed (just a faceplate that looked like a power supply). My buddy was pissed, but I figure I'd just done him a big favor. Better to find out about it now than when the supply failed at some critical juncture. From tjreedy at udel.edu Sun Aug 21 22:11:46 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 22:11:46 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: On 8/21/2011 7:41 PM, Chris Angelico wrote: > Agreed. If Python needed a faster alternative to "a=a+1", then I would > recommend an "a.inc()" call or something But looking up the method name, creating a bound method wrapper, and making the call would probably be slower than the syntax;-). -- Terry Jan Reedy From tjreedy at udel.edu Sun Aug 21 22:15:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 22:15:07 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/21/2011 7:49 PM, Laurent Payot wrote: > I made Python my language of choice because of its readability and > simpleness, and not because of its speed. But it's always good to > know what is the fastest sometimes when you don't want to write a > module in C. So I was just wondering if there was a difference. There > is, of a few percent. Anyway I will keep on using the 2% slower "i += > 1" because for me that's less prone to errors because you write the > variable only once, and that's more important than speed. For longer variable names, it is also easier and faster to read once one gets used to the idiom. number_of_chars += 1 # versus number_of_chars = number_of_chars + 1 Not repeating was a major reason for the addition. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Aug 22 00:01:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 14:01:55 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e51d4b3$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 10:41 am Chris Angelico wrote: > On Mon, Aug 22, 2011 at 1:30 AM, Steven D'Aprano > wrote: >> /s/would/should/ >> >> I don't see why you expect this, when *existing* network-related failures >> aren't > > Ehh, granted. Definitely a case of "should". But certainly, there > won't be an infinite number of new exceptions invented; most of the > runtime issues you'll have will fall into a fairly small number of > exception types (either by subclassing or by parameters eg errno). Er, you can't know that either. Except that all exceptions must be rooted at BaseException, there *can* be an infinite number of new exception types invented. Or functions could raise unexpected, but known, exceptions, whether built-in or not. Of course, the set of hypothetical exceptions that could theoretically be raised is much, much bigger than the set of exceptions which you can realistically expect to see, especially if you limit yourself to those that don't leave you wondering about the sanity of the developer ("WTF? Why is x+1 raising HTTPBadGatewayError?"). But still, as a general rule you should not be surprised to see any of: AttributeError TypeError ValueError (and likely others) The more important question is, if you get an exception, any exception, is that a bug in the function you are calling, a bug in your calling code (you supplied a bad argument), or an expected result that you should catch and work around? -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 22 00:14:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 14:14:32 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 12:08 pm Stephen Hansen wrote: > Picking "i += 1" over "i = i + 1" based on one being 4% slower is sorta > kinda crazy. The difference in speed is probably related to churn and > cache as much as anything else (its not as consistent on my machine, for > example): or the ceval loop doing a few more case-tests between them as > others have mentioned. All in all, if 4% of a nanomicrofraction of a > chunk of time is that meaningful, you're probably best served not using > Python. :) Agreed. But... > That said: my advice is always to avoid += like a plague. It is magic > and impossible to predict without intimate knowledge of exactly what's > on the left-side. > > i += 1 > n += x > > Those two things look very similar, but they may do -completely- > different things depending on just what "n" is. Technically, the *exact same criticism* can be applied to: n = n + x since either n or x could override __add__ or __radd__ and do anything it bloody well likes. Including in-place modification of *either* argument (where possible). [...] > With "i = i + 1", I know that generally speaking, my "i" is being > assigned a new object and that's that, no matter what type "i" is. > (Okay: I do know that you could modify __add__ to do something > underhanded here, tweaking internal state and then returning self. What makes you think that's underhanded? To my mind, __add__ modifying self as a side-effect is unusual, but apart from breaking the general rule of thumb to avoid side-effects, not particularly evil. (But I would accept this is a code smell.) > People going out of their way to behave unpredictably is not my > objection: supposedly easy and straight-forward normal Python-fu being > inherently unpredictable is). > > For example: I just /know/ that it doesn't matter who or what may have > their own binding to that object before I go and increment it, they > won't be affected and everything just will work fine. But you can't /know/ that at all, unless you know that the object isn't "underhanded" (however you define that!). And given some arbitrary object, how can you know that? -- Steven From casevh at gmail.com Mon Aug 22 00:14:37 2011 From: casevh at gmail.com (casevh) Date: Sun, 21 Aug 2011 21:14:37 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <1313947658.3424.3.camel@thegeorge> Message-ID: <320f5fed-e32d-43a3-846a-5f0ed584c9e5@y8g2000prd.googlegroups.com> On Aug 21, 10:27?am, Andreas L?scher wrote: > > from Python/ceval.c: > > 1316 ? ? ? ? ? ?case BINARY_ADD: > 1317 ? ? ? ? ? ? ? ?w = POP(); > 1318 ? ? ? ? ? ? ? ?v = TOP(); > 1319 ? ? ? ? ? ? ? ?if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { > 1320 ? ? ? ? ? ? ? ? ? ?/* INLINE: int + int */ > 1321 ? ? ? ? ? ? ? ? ? ?register long a, b, i; > 1322 ? ? ? ? ? ? ? ? ? ?a = PyInt_AS_LONG(v); > 1323 ? ? ? ? ? ? ? ? ? ?b = PyInt_AS_LONG(w); > 1324 ? ? ? ? ? ? ? ? ? ?/* cast to avoid undefined behaviour > 1325 ? ? ? ? ? ? ? ? ? ? ? on overflow */ > 1326 ? ? ? ? ? ? ? ? ? ?i = (long)((unsigned long)a + b); > 1327 ? ? ? ? ? ? ? ? ? ?if ((i^a) < 0 && (i^b) < 0) > 1328 ? ? ? ? ? ? ? ? ? ? ? ?goto slow_add; > 1329 ? ? ? ? ? ? ? ? ? ?x = PyInt_FromLong(i); > 1330 ? ? ? ? ? ? ? ?} > 1331 ? ? ? ? ? ? ? ?else if (PyString_CheckExact(v) && > 1332 ? ? ? ? ? ? ? ? ? ? ? ? PyString_CheckExact(w)) { > 1333 ? ? ? ? ? ? ? ? ? ?x = string_concatenate(v, w, f, next_instr); > 1334 ? ? ? ? ? ? ? ? ? ?/* string_concatenate consumed the ref to v */ > 1335 ? ? ? ? ? ? ? ? ? ?goto skip_decref_vx; > 1336 ? ? ? ? ? ? ? ?} > 1337 ? ? ? ? ? ? ? ?else { > 1338 ? ? ? ? ? ? ? ? ?slow_add: > 1339 ? ? ? ? ? ? ? ? ? ?x = PyNumber_Add(v, w); > 1340 ? ? ? ? ? ? ? ?} > 1341 ? ? ? ? ? ? ? ?Py_DECREF(v); > 1342 ? ? ? ? ? ? ?skip_decref_vx: > 1343 ? ? ? ? ? ? ? ?Py_DECREF(w); > 1344 ? ? ? ? ? ? ? ?SET_TOP(x); > 1345 ? ? ? ? ? ? ? ?if (x != NULL) continue; > 1346 ? ? ? ? ? ? ? ?break; > > 1532 ? ? ? ? ? ?case INPLACE_ADD: > 1533 ? ? ? ? ? ? ? ?w = POP(); > 1534 ? ? ? ? ? ? ? ?v = TOP(); > 1535 ? ? ? ? ? ? ? ?if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { > 1536 ? ? ? ? ? ? ? ? ? ?/* INLINE: int + int */ > 1537 ? ? ? ? ? ? ? ? ? ?register long a, b, i; > 1538 ? ? ? ? ? ? ? ? ? ?a = PyInt_AS_LONG(v); > 1539 ? ? ? ? ? ? ? ? ? ?b = PyInt_AS_LONG(w); > 1540 ? ? ? ? ? ? ? ? ? ?i = a + b; > 1541 ? ? ? ? ? ? ? ? ? ?if ((i^a) < 0 && (i^b) < 0) > 1542 ? ? ? ? ? ? ? ? ? ? ? ?goto slow_iadd; > 1543 ? ? ? ? ? ? ? ? ? ?x = PyInt_FromLong(i); > 1544 ? ? ? ? ? ? ? ?} > 1545 ? ? ? ? ? ? ? ?else if (PyString_CheckExact(v) && > 1546 ? ? ? ? ? ? ? ? ? ? ? ? PyString_CheckExact(w)) { > 1547 ? ? ? ? ? ? ? ? ? ?x = string_concatenate(v, w, f, next_instr); > 1548 ? ? ? ? ? ? ? ? ? ?/* string_concatenate consumed the ref to v */ > 1549 ? ? ? ? ? ? ? ? ? ?goto skip_decref_v; > 1550 ? ? ? ? ? ? ? ?} > 1551 ? ? ? ? ? ? ? ?else { > 1552 ? ? ? ? ? ? ? ? ?slow_iadd: > 1553 ? ? ? ? ? ? ? ? ? ?x = PyNumber_InPlaceAdd(v, w); > 1554 ? ? ? ? ? ? ? ?} > 1555 ? ? ? ? ? ? ? ?Py_DECREF(v); > 1556 ? ? ? ? ? ? ?skip_decref_v: > 1557 ? ? ? ? ? ? ? ?Py_DECREF(w); > 1558 ? ? ? ? ? ? ? ?SET_TOP(x); > 1559 ? ? ? ? ? ? ? ?if (x != NULL) continue; > 1560 ? ? ? ? ? ? ? ?break; > > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. That fragment of cevel.c is from a 2.x version. Python 2.x supports both a PyInt and PyLong type and the cevel loop optimized the PyInt case only. On my system, I could not measure a difference between binary and inplace addition. Python 3.x behaves differently: TARGET(BINARY_ADD) w = POP(); v = TOP(); if (PyUnicode_CheckExact(v) && PyUnicode_CheckExact(w)) { x = unicode_concatenate(v, w, f, next_instr); /* unicode_concatenate consumed the ref to v */ goto skip_decref_vx; } else { x = PyNumber_Add(v, w); } Py_DECREF(v); skip_decref_vx: Py_DECREF(w); SET_TOP(x); if (x != NULL) DISPATCH(); break; TARGET(INPLACE_ADD) w = POP(); v = TOP(); if (PyUnicode_CheckExact(v) && PyUnicode_CheckExact(w)) { x = unicode_concatenate(v, w, f, next_instr); /* unicode_concatenate consumed the ref to v */ goto skip_decref_v; } else { x = PyNumber_InPlaceAdd(v, w); } Py_DECREF(v); skip_decref_v: Py_DECREF(w); SET_TOP(x); if (x != NULL) DISPATCH(); break; cevel just calls PyNumber_Add or PyNumber_InPlaceAdd. If you look at the code for PyNumber_InPlaceAdd (in abstract.c), it calls an internal function binary_iop1 with pointers to nb_inplace_add and nb_add. binary_iop1 then checks if nb_inplace_add exists. The PyLong type does not implement nb_inplace_add so the check fails and binary_iop1 used nb_add. In recent version of gmpy and gmpy2, I implemented the nb_inplace_add function and performance (for the gmpy.mpz type) is much better for the in-place addition. For the adventuresome, gmpy2 implements a mutable integer type called xmpz. It isn't much faster until the values are so large that the memory copy times become significant. (Some old gmpy documentation implies that operations with mutable integers should be much faster. With agressive caching of deleted objects, the object creation overhead is very low. So the big win for mutable integers is reduced to avoiding memory copies.) casevh > > To be clear, this is nothing you should consider when writing fast code. > Complexity wise they both are the same. From jialiuonlineshoe02 at 163.com Mon Aug 22 00:19:47 2011 From: jialiuonlineshoe02 at 163.com (amy) Date: Sun, 21 Aug 2011 21:19:47 -0700 (PDT) Subject: paypal wholesale gucci (paypal payment)( http://www.24hour-buy.com/) Message-ID: paypal wholesale d&g shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale gucci shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale lv shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale NBA shoes (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale nike (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale adidas shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale gucci shoes (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale bape hoody (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale antick jeans (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale diesel jeans (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale artful dudger (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale bag(lv gucci coach chanel d&g dior ed fendi ) (paypal payment)(http://www.24hour-buy.com/) paypal wholesale clothing (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale lrg,jeans,hoody, (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale evisu jeans,hoody,shirt (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Prada (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Puma (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Sand (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Shox (paypal payment)( http://www.24hour-buy.com/) paypal wholesale soccer (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale gucci (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Versace (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale Women (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Y-3 (paypal payment)( http://www.24hour-buy.com/ ) From me+list/python at ixokai.io Mon Aug 22 00:37:16 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 21:37:16 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E51DCFC.60106@ixokai.io> On 8/21/11 9:14 PM, Steven D'Aprano wrote: >> That said: my advice is always to avoid += like a plague. It is magic >> and impossible to predict without intimate knowledge of exactly what's >> on the left-side. >> >> i += 1 >> n += x >> >> Those two things look very similar, but they may do -completely- >> different things depending on just what "n" is. > > Technically, the *exact same criticism* can be applied to: > > n = n + x > > since either n or x could override __add__ or __radd__ and do anything it > bloody well likes. Including in-place modification of *either* argument > (where possible). I know: I addressed that. :P See, you know I addressed that, because: > [...] >> With "i = i + 1", I know that generally speaking, my "i" is being >> assigned a new object and that's that, no matter what type "i" is. >> (Okay: I do know that you could modify __add__ to do something >> underhanded here, tweaking internal state and then returning self. > > What makes you think that's underhanded? You quoted me addressing that very fact, and responded! :) Its underhanded outside of narrow, well-defined situations such as ORM's and the like where they're doing interesting and novel things with the object model. Underhanded doesn't mean there's no reason one should ever do it, but its very much an unusual thing and objects that do things like that should NOT freely interact with general Python objects: very surprising behavior will result. > To my mind, __add__ modifying self as a side-effect is unusual, but apart > from breaking the general rule of thumb to avoid side-effects, not > particularly evil. (But I would accept this is a code smell.) I didn't really say its evil, just that its underhanded: that's like, sketchy, not evil. :) There's good reasons to do it on occasion, but if an object does something like that then that is a very special kind of object and when using it, you need to be very aware of its unusual semantics. Having objects like that is fine. However, for the /language/ to have unusual (and unpredictable, from something of a distance at least) semantics, rubs me very much the wrong way. >> People going out of their way to behave unpredictably is not my >> objection: supposedly easy and straight-forward normal Python-fu being >> inherently unpredictable is). >> >> For example: I just /know/ that it doesn't matter who or what may have >> their own binding to that object before I go and increment it, they >> won't be affected and everything just will work fine. > > But you can't /know/ that at all, unless you know that the object > isn't "underhanded" (however you define that!). And given some arbitrary > object, how can you know that? I CAN know it with sufficient certainty that I can rely on it, and if I get messed up on it-- its never happened yet-- then I can fire someone or get a new library, after staring at an odd traceback and scratching my head for a minute. Python has very soft rules, I know that. Objects /can/ do all kinds of crazy things. I'm okay with that. But I can rely on certain behaviors being consistent: the basic behavior of the language is very straight-forward. It has hooks where you can do lots of Special stuff, and if objects are Special, they're described as Special. ORM's have a lot of Special objects, for example. That's fine: when messing with ORM objects, I know I have to take care with the operators I use against them, because I know I'm not using a /usual/ Python object. SQLAlchemy for example. This is not a criticism of SQLAlchemy: having magic objects lets it construct SQL in ways that are vastly easier then if they stuck to more regularly behaving objects. But, += is Python itself adding an unpredictable behavior into the core language, with its own base types behaving The *exact same criticism* can NOT be applied to n = n + x Because my criticism isn't about one choosing to do crazy stuff with the object model. I've never advocated Python be strict about rules. But for Python, all by itself, with nothing but built-in and basic types, to have a situation where: a = a + b a += b ... does two very distinctly different actions, even if in many or even most circumstances the end-result is probably the same and probably fine, is my criticism. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Mon Aug 22 00:49:03 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 21:49:03 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4E51DCFC.60106@ixokai.io> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> <4E51DCFC.60106@ixokai.io> Message-ID: <4E51DFBF.6030800@ixokai.io> On 8/21/11 9:37 PM, Stephen Hansen wrote: > But, += is Python itself adding an unpredictable behavior into the core > language, with its own base types behaving ... very differently to fundamental, basic appearing operators. Editing fail on my part. Similarly: > But for Python, all by itself, with nothing but built-in and basic > types, to have a situation where: > > a = a + b > a += b ... would be clearer if the second example were "x += y". > ... does two very distinctly different actions, even if in many or > even most circumstances the end-result is probably the same and probably > fine, is my criticism. > -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From research at johnohagan.com Mon Aug 22 01:04:45 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 22 Aug 2011 15:04:45 +1000 Subject: Adding modified methods from another class without subclassing Message-ID: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> I have a class like this: class MySeq(): def __init__(self, *seq, c=12): self.__c = c self.__pc = sorted(set([i % __c for i in seq])) self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) #other calculated attributes @property def pitches(self): return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] #other methods The "pitches" attribute initially reconstructs the "seq" arguments but can be modified by writing to the "order" attribute. The "pitches" attribute represents the instances and as such I found myself adding a lot of methods like: def __getitem__(self, index): return self.pitches[index] def __len__(self): return len(self.pitches) def __iter__(self): return iter(self.pitches) def __repr__(self): return str(self.pitches) and so on, and calling a lot of list methods on the "pitches" attribute of MySeq instances elsewhere. I thought of making MySeq a subclass of list with "pitches" as its contents, but then I would have had to override a lot of methods case-by-case, for example to ensure that any alterations to "pitches" were reflected in the other calculated attributes. So I wrote this function which takes a method, modifies it to apply to an instance attribute, and takes care of any quirks: def listmeth_to_attribute(meth, attr): def new_meth(inst, *args): #ensure comparison operators work: args = [getattr(i, attr) if isinstance(i, inst.__class__) else i for i in args] reference = getattr(inst, attr) test = reference[:] result = meth(test, *args) #ensure instance is reinitialised #if attribute has been changed: if test != reference: inst.__init__(*test) #ensure slices are of same class if isinstance(result, meth.__objclass__): result = inst.__class__(*result) return result return new_meth and this decorator to apply this function to all the list methods and add them to MySeq: def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): """Overides = any methods in target to override from source""" def decorator(target_cls): for name, meth in vars(source_cls).items(): if name not in dir(target_cls) or name in overrides: setattr(target_cls, name, modfunc(meth, *modfunc_args)) return target_cls return decorator a kind of DIY single inheritance, used like this: @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') class MySeq(): ..... Now I can call list methods transparently on MySeq instances, like subclassing but without all the overriding. If this works it will simplify a lot of code in my project. But the fact that I haven't seen this approach before increases the likelihood it may not be a good idea. I can almost hear the screams of "No, don't do that!" or the sound of me slapping my forehead when someone says "Why don't you just...". So before I put it in, I'd appreciate any comments, warnings, criticisms, alternatives etc.. Regards, John From steve+comp.lang.python at pearwood.info Mon Aug 22 01:27:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 15:27:36 +1000 Subject: Adding modified methods from another class without subclassing References: Message-ID: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 03:04 pm John O'Hagan wrote: > The "pitches" attribute represents the instances and as such I found > myself adding a lot of methods like: > > def __getitem__(self, index): > return self.pitches[index] > > def __len__(self): > return len(self.pitches) Looks like a call for (semi-)automatic delegation! Try something like this: # Untested class MySeq(object): methods_to_delegate = ('__getitem__', '__len__', ...) pitches = ... # make sure pitches is defined def __getattr__(self, name): if name in self.__class__.methods_to_delegate: return getattr(self.pitches, name) return super(MySeq, object).__getattr__(self, name) # will likely raise AttributeError > But the fact that I haven't seen this approach before increases the > likelihood it may not be a good idea. I can almost hear the screams of > "No, don't do that!" The general technique is called delegation and is perfectly legitimate. http://c2.com/cgi/wiki?WhatIsDelegation http://en.wikipedia.org/wiki/Delegation_(programming) -- Steven From usenet-nospam at seebs.net Mon Aug 22 01:33:28 2011 From: usenet-nospam at seebs.net (Seebs) Date: 22 Aug 2011 05:33:28 GMT Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: On 2011-08-21, Andreas L?scher wrote: > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: >> In article , >> Christian Heimes wrote: >> > I don't think that's the reason. Modern compiles turn a switch statement >> > into a jump or branch table rather than a linear search like chained >> > elif statements. >> This is true even for very small values of "modern". I remember the >> Unix v6 C compiler (circa 1977) was able to do this. > What is the difference in speed between a jump table that is searched > from top to bottom A jump table isn't searched, it's jumped into. You don't look through the table for a matching element, you grab the Nth element of the table. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From saraanderson24 at gmail.com Mon Aug 22 01:41:54 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Sun, 21 Aug 2011 22:41:54 -0700 (PDT) Subject: WATCH WORLD`S MOST FUNNIEST PRANK VIDEOS EVER. Message-ID: WATCH WORLD`S MOST BEAUTIFUL PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S MOST HILARIOUS FUNNIEST VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From tomas at liden-privat.net Mon Aug 22 02:37:42 2011 From: tomas at liden-privat.net (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Sun, 21 Aug 2011 23:37:42 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() Message-ID: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> In what order are the addresses returned by socket.gethostbyname_ex()? We know that gethostbyname() is indeterministic but hope that gethostbyname_ex() has a specified order. Best regards, Tomas From eudes.elie at gmail.com Mon Aug 22 04:04:54 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Mon, 22 Aug 2011 01:04:54 -0700 (PDT) Subject: decorator issue with modules dbus & gobject References: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Message-ID: <3faf2fbf-120a-42c4-a4c3-29de89ae4a45@q1g2000vbj.googlegroups.com> On 21 ao?t, 18:31, Emile van Sebille wrote: > On 8/18/2011 5:02 AM Makiavelik said... > > > Hi, > > Here is a sample code that reproduces the issue : > > Not really 'sample' enough to allow others to investigate... > > ImportError: No module namedgobject > ImportError: No module nameddbus > ImportError: No module nameddbus.mainloop.glib > > Try to eliminate the non-standard dependencies. ?I wanted to check the > default value set in timeout but there's too much crap to clean up. > > Emile Yes that's right there is a dependency with both modules dbus and gobject (as mentionned in the subject of the thread). The fact is I am not able to quit the looping method of the gobject.Mainloop object without errors ... From steve+comp.lang.python at pearwood.info Mon Aug 22 04:15:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 18:15:52 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. Did you want a particular order, or just any deterministic order? Have you considered sorting the addresses yourself? -- Steven From przemolicc at poczta.fm Mon Aug 22 04:52:53 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 10:52:53 +0200 Subject: locale.format without trailing zeros Message-ID: <20110822085253.GA13228@host.pgf.com.pl> Hello, >>> import locale >>> locale.setlocale(locale.LC_ALL, "pl_PL") 'pl_PL' >>> i=0.20 >>> j=0.25 >>> locale.format('%f', i) '0,200000' >>> locale.format('%f', j) '0,250000' I need to print the numbers in the following format: '0,2' (i) '0,25' (j) So the last trailing zeros are not printed. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From tomas.liden.privat at gmail.com Mon Aug 22 05:06:30 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 02:06:30 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22 Aug, 10:15, Steven D'Aprano wrote: > On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: > > > In what order are the addresses returned by socket.gethostbyname_ex()? > > > We know that gethostbyname() is indeterministic but hope that > > gethostbyname_ex() has a specified order. > > Did you want a particular order, or just any deterministic order? > > Have you considered sorting the addresses yourself? > > -- > Steven In this particular case we have a host with several connections (LAN, WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare adapter but we wanted to get the LAN (or the "best" connection to our server). With gethostbyname_ex() the ordering seemed to become LAN, Wifi, etc and that's good for us. But we don't know if this holds on other platforms (we're running on Windows 7). A cross-platform deterministic order would be excellent for us. /Tomas From __peter__ at web.de Mon Aug 22 05:32:18 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 11:32:18 +0200 Subject: Adding modified methods from another class without subclassing References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> Message-ID: John O'Hagan wrote: > I have a class like this: > > class MySeq(): > def __init__(self, *seq, c=12): > self.__c = c > self.__pc = sorted(set([i % __c for i in seq])) > self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) > #other calculated attributes > > @property > def pitches(self): > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > > #other methods That makes me dizzy. Are there any maxims in the Zen of Python that this piece doesn't violate? > The "pitches" attribute initially reconstructs the "seq" arguments but can > be modified by writing to the "order" attribute. > > The "pitches" attribute represents the instances and as such I found > myself adding a lot of methods like: > > > def __getitem__(self, index): > return self.pitches[index] > > def __len__(self): > return len(self.pitches) > > def __iter__(self): > return iter(self.pitches) > > def __repr__(self): > return str(self.pitches) > > and so on, and calling a lot of list methods on the "pitches" attribute of > MySeq instances elsewhere. I thought of making MySeq a subclass of list > with "pitches" as its contents, but then I would have had to override a > lot of methods case-by-case, for example to ensure that any alterations to > "pitches" were reflected in the other calculated attributes. > > So I wrote this function which takes a method, modifies it to apply to an > instance attribute, and takes care of any quirks: > > def listmeth_to_attribute(meth, attr): > def new_meth(inst, *args): > #ensure comparison operators work: > args = [getattr(i, attr) if isinstance(i, inst.__class__) > else i for i in args] > reference = getattr(inst, attr) > test = reference[:] > result = meth(test, *args) > #ensure instance is reinitialised > #if attribute has been changed: > if test != reference: > inst.__init__(*test) > #ensure slices are of same class > if isinstance(result, meth.__objclass__): > result = inst.__class__(*result) > return result > return new_meth > > and this decorator to apply this function to all the list methods and add > them to MySeq: > > def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): > """Overides = any methods in target to override from source""" > def decorator(target_cls): > for name, meth in vars(source_cls).items(): > if name not in dir(target_cls) or name in overrides: > setattr(target_cls, name, modfunc(meth, *modfunc_args)) > return target_cls > return decorator > > a kind of DIY single inheritance, used like this: > > @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') > class MySeq(): > ..... > > Now I can call list methods transparently on MySeq instances, like > subclassing but without all the overriding. If this works it will simplify > a lot of code in my project. > > But the fact that I haven't seen this approach before increases the > likelihood it may not be a good idea. I can almost hear the screams of > "No, don't do that!" or the sound of me slapping my forehead when someone > says "Why don't you just...". So before I put it in, I'd appreciate any > comments, warnings, criticisms, alternatives etc.. In the standard library functools.total_ordering uses that technique and I find the implications hard to understand: http://bugs.python.org/issue10042 Your decorator looks even more complex; I'd only recommend using it if you're absolutely sure you're clever enough to debug it ;) From __peter__ at web.de Mon Aug 22 05:48:46 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 11:48:46 +0200 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm wrote: >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > 'pl_PL' >>>> i=0.20 >>>> j=0.25 >>>> locale.format('%f', i) > '0,200000' >>>> locale.format('%f', j) > '0,250000' > > I need to print the numbers in the following format: > '0,2' (i) > '0,25' (j) > So the last trailing zeros are not printed. >>> print locale.format("%g", 1.23) 1,23 >>> print locale.format("%g", 1.2345678) 1,23457 >>> print locale.format("%.10g", 1.2345678) 1,2345678 >>> print locale.format("%.15g", 0.1) 0,1 >>> print locale.format("%.17g", 0.1) 0,10000000000000001 From rdmoores at gmail.com Mon Aug 22 05:55:11 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Mon, 22 Aug 2011 02:55:11 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 21, 2011 at 18:12, Steven D'Aprano wrote: > But really, we're talking about tiny differences in speed. Such trivial > differences are at, or beyond, the limit of what can realistically be > measured on a noisy PC running multiple processes (pretty much all PCs > these days). Here are three runs of each on my computer: > > > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.508 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.587 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.251 usec per loop > > > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.226 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.494 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.53 usec per loop > > Look at the variation between runs! About 130% variation between the fastest > and slowest for each expression. And there's no reason to think that the > fastest results shown is as fast as it can get. The time is dominated by > noise, not the addition. > > > For what it's worth, if I try it with a more recent Python: > > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.221 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.202 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.244 usec per loop > > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.49 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.176 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.49 usec per loop > > > I simply do not believe that we can justify making *any* claim about the > relative speeds of n=n+1 and n+=1 other than "they are about the same". Any > result you get, faster or slower, will depend more on chance than on any > real or significant difference in the code. I couldn't resist giving it a try. Using Python 3.2.1 on a 64-bit Windows 7 machine with a 2.60 gigahertz AMD Athlon II X4 620 processor, I did 18 tests, alternating between n=n+1 and n+=1 (so 9 each). The fastest for n+=1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.0879 usec per loop The slowest for n+=1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.0902 usec per loop The fastest for n = n + 1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.0831 usec per loop The slowest for n = n + 1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.0842 usec per loop Coincidence? All the data are pasted at http://pastebin.com/jArPSe56 Dick Moores From amirouche.boubekki at gmail.com Mon Aug 22 06:02:00 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Mon, 22 Aug 2011 03:02:00 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ Message-ID: I'm learning a bit of python internals lately and I'm trying to figure out the relationship between type, objects, class, callables and __getattribute__ resolution. While understanding Python mechanics/concepts, I'm trying to figure how it translates in CPython. This post is Python centric. Questions about the implementation of this concepts might be the subject of a future post [1]. I will proceed this way: I will write statements about each subject. Don't hesitate to pick one and provide more information or better phrasing, or explaining why it's not true. Be aware that I'm considering only new-style class. A) type vs object ----------------- 1) object is the base object, it has no bases : len(object.__bases__) == 0 2) every object in python inherit object : any_object_except_object.__bases__[-1] is object 3) object's type is type : object.__class__ is type 4) type parent object is object : type.__bases__ == (object,) B) type vs metaclass -------------------- 1) type is the first metaclass ? 2) type is its own metaclass : type(type) is type ? 3) object's metaclass is type ? 4) other metaclasses *MUST* inherit type ? 5) type(any_object) == last_metaclass_..., which is, most of the time, type ? C) type vs class ---------------- 1) Type is the metaclass of most classes 2) The class statement:: class MyClass(object): attribute = 1 def method(self): pass translates to:: MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def method: pass }) 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates to:: type(MyClass).__call__(MyClass, *args, **kwargs) This is due to __getattribute__ algorithm (see E) 4) It's in type.__call__ that happens calls to __new__ and __init__ 5) 3) => classes are instance of type 6) Since type.__call__ is used to instantiate instance of instance of type (rephrased: __call__ is used to instantiate classes) where is the code which is executed when we write ``type(myobject)`` or ``type('MyClass', bases, attributes)`` __getattribute__ resolution algorithm (see E) tells me that it should be type.__call__ but type.__call__ is already used to class instatiation. C') class vs class instances aka. objects ----------------------------------------- 1) A class type is a metaclass : issubclass(type(MyClass), type), MyClass.__class__ == type(MyClass) 2) An object type is a class : most of the time isinstance(type(my_object), type) generally issubclass(type(type(my_object)), type) D) builtin types ---------------- 1) builtin types are their own metaclass ? 2) why function builtin type can not be subclassed ? 3) how does builtin function type relate to callable objects ? 4) int(1) is the same as int.__call__(1), since type(int) is type, shouldn't int(1) translates to type.__call__(int, 1) ? E) __getattribute__ ------------------- 1) ``my_object.attribute`` always translates to ``my_object.__getattribute__('attribute')`` 2) Is the following algorithm describing __getattribute__ correct [2], beware that I've added a comment: a) If attrname is a special (i.e. Python-provided) attribute for objectname, return it. # what does it mean to be Python-provided ? b ) Check objectname.__class__.__dict__ for attrname. If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case. c) Check objectname.__dict__ for attrname, and return if found. d) If it is a class and a descriptor exists in it or its bases, return the descriptor result. d) Check objectname.__class__.__dict__ for attrname. If it exists and is a non-data descriptor, return the descriptor result. If it exists, and is not a descriptor, just return it. If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2. Search all bases of objectname.__class__ for same case. e) Raise AttributeError Thanks in advance, Regards, Amirouche [1] or maybe you can point me to the right direction before I ask stupid questions. I'm a bit familiar with Jython code, which seems to be easier than PyPy and CPython to read even if there is some magic due to the fact that Jython use some JVM API that hides somewhat how it works. [2] this is a rewritten version of http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#attribute-search-summary From cs at zip.com.au Mon Aug 22 06:06:46 2011 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 22 Aug 2011 20:06:46 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: Message-ID: <20110822100646.GA24782@cskk.homeip.net> On 22Aug2011 02:06, Tomas Lid?n wrote: | On 22 Aug, 10:15, Steven D'Aprano wrote: | > On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: | > > In what order are the addresses returned by socket.gethostbyname_ex()? | > | > > We know that gethostbyname() is indeterministic but hope that | > > gethostbyname_ex() has a specified order. | > | > Did you want a particular order, or just any deterministic order? | > | > Have you considered sorting the addresses yourself? | | In this particular case we have a host with several connections (LAN, | WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare | adapter but we wanted to get the LAN (or the "best" connection to our | server). With gethostbyname_ex() the ordering seemed to become LAN, | Wifi, etc and that's good for us. But we don't know if this holds on | other platforms (we're running on Windows 7). | | A cross-platform deterministic order would be excellent for us. It would not surprise me if the order was related to the order a scan of the system interfaces yields information, and I would imagine that may be influenced by the order in which the interfaces were initialised. So getting the LAN first may merely be fortuitous. I wouldn't rely on it, especially if interfaces come and go. What if you queried your routing table instead? Usually there's just one default route, and hopefully it would be configured to use the "best" interface. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you give me six lines written by the most honest man, I will find something in them to hang him. - Cardinal Richilieu From rosuav at gmail.com Mon Aug 22 06:36:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 11:36:12 +0100 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: <20110822100646.GA24782@cskk.homeip.net> References: <20110822100646.GA24782@cskk.homeip.net> Message-ID: On Mon, Aug 22, 2011 at 11:06 AM, Cameron Simpson wrote: > What if you queried your routing table instead? Usually there's just one > default route, and hopefully it would be configured to use the "best" > interface. > I wouldn't necessarily trust even this, on Windows. I've lately had the most insane trouble getting my XP laptop to function properly as a proxy - LAN connection has the default gateway, wifi has only 192.168.* - and Windows kept on trying to send DNS queries out on the wireless connection, and then wondered why it didn't get a result. Explicit is better than implicit. Instead of using the order, have a config file that chooses the one(s) you want by name or IP address. Of course, if you're on Unix/Linux, you can use the interface name (eth0, eth1, etc) with a fair degree of reliability. ChrisA From as at sci.fi Mon Aug 22 06:59:54 2011 From: as at sci.fi (Anssi Saari) Date: Mon, 22 Aug 2011 13:59:54 +0300 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm writes: > Hello, > >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > 'pl_PL' >>>> i=0.20 >>>> j=0.25 >>>> locale.format('%f', i) > '0,200000' >>>> locale.format('%f', j) > '0,250000' > > I need to print the numbers in the following format: > '0,2' (i) > '0,25' (j) > So the last trailing zeros are not printed. That would be the %g conversion specifier. From przemolicc at poczta.fm Mon Aug 22 07:08:40 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 13:08:40 +0200 Subject: locale.format without trailing zeros In-Reply-To: References: Message-ID: <20110822110840.GB13228@host.pgf.com.pl> On Mon, Aug 22, 2011 at 11:48:46AM +0200, Peter Otten wrote: > przemolicc at poczta.fm wrote: > > >>>> import locale > >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > > 'pl_PL' > >>>> i=0.20 > >>>> j=0.25 > >>>> locale.format('%f', i) > > '0,200000' > >>>> locale.format('%f', j) > > '0,250000' > > > > I need to print the numbers in the following format: > > '0,2' (i) > > '0,25' (j) > > So the last trailing zeros are not printed. > > >>> print locale.format("%g", 1.23) > 1,23 > >>> print locale.format("%g", 1.2345678) > 1,23457 > >>> print locale.format("%.10g", 1.2345678) > 1,2345678 > >>> print locale.format("%.15g", 0.1) > 0,1 > >>> print locale.format("%.17g", 0.1) > 0,10000000000000001 Thank you very much :-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f2a0a From lighttn at googlemail.com Mon Aug 22 07:26:23 2011 From: lighttn at googlemail.com (Hyun-su) Date: Mon, 22 Aug 2011 04:26:23 -0700 (PDT) Subject: write() Message-ID: Hi, I have a file which is 3D data ([pixel_x, pixel_y, pixel_z]) I want to plot and write into other file as 1 dimension ([:, y_cut, z_cut]) How can I do it? From roy at panix.com Mon Aug 22 07:26:56 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 07:26:56 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: In article <356978ef-e9c1-48fd-bb87-849fe8e27a79 at p5g2000vbl.googlegroups.com>, Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. Why would you hope that? Or maybe a better question is, why would you expect that? In general, all name resolution calls return results in arbitrary order. In some cases, results are intentionally changed on every call (i.e. round-robin) in an attempt at load sharing. What kind of ordering were you hoping for? From ekh.johan at gmail.com Mon Aug 22 07:28:05 2011 From: ekh.johan at gmail.com (Johan Ekh) Date: Mon, 22 Aug 2011 13:28:05 +0200 Subject: Execute script from ipython In-Reply-To: References: Message-ID: Thanks Chris! I tried using "!" instead of "run". It works but with a significant performance penalty. Best regards, Johan On Fri, Aug 19, 2011 at 5:11 PM, Chris Rebert wrote: > On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > > Hi all, > > I have a script "myscript.py" located in "/usr/local/bin" on my linux > box. > > I can execute it in ipython with > > > > run /usr/local/bin/myscript.py > > > > but not with > > > > run myscript.py > > > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > > > What should I do to correct this? > > Given that %run takes a filename and not a module name, I doubt > PYTHONPATH matters. ipython's docs for %run don't seem to indicate > that a search of any kind is performed. So, I'd say you have to either > pass a valid absolute or relative path to myscript.py, or run > myscript.py from bash instead of ipython. > > Changing your script's shebang line to ipython might also work > (haven't tried it myself). Or you could try patching ipython's run() > function to add this search feature you desire. > > Cheers, > Chris > -- > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomas.liden.privat at gmail.com Mon Aug 22 07:29:38 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:29:38 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: Message-ID: On 22 Aug, 12:06, Cameron Simpson wrote: > > It would not surprise me if the order was related to the order a scan of > the system interfaces yields information, and I would imagine that may > be influenced by the order in which the interfaces were initialised. > > So getting the LAN first may merely be fortuitous. > I wouldn't rely on it, especially if interfaces come and go. > We did try to disable/enable the interfaces in different orders, but always got the same return order from gethostbyname_ex(). So it looked pretty stable (on that specific OS). There's been some testing on Linux as well, but since this should be used in a general cross platform tool we wanted to check the exact behaviour of the method. > What if you queried your routing table instead? Usually there's just one > default route, and hopefully it would be configured to use the "best" > interface. > Hmm... perhaps. How would you do that? /Tomas From przemolicc at poczta.fm Mon Aug 22 07:29:58 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 13:29:58 +0200 Subject: locale.format without trailing zeros In-Reply-To: References: Message-ID: <20110822112958.GC13228@host.pgf.com.pl> On Mon, Aug 22, 2011 at 11:48:46AM +0200, Peter Otten wrote: > przemolicc at poczta.fm wrote: > > >>>> import locale > >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > > 'pl_PL' > >>>> i=0.20 > >>>> j=0.25 > >>>> locale.format('%f', i) > > '0,200000' > >>>> locale.format('%f', j) > > '0,250000' > > > > I need to print the numbers in the following format: > > '0,2' (i) > > '0,25' (j) > > So the last trailing zeros are not printed. > > >>> print locale.format("%g", 1.23) > 1,23 > >>> print locale.format("%g", 1.2345678) > 1,23457 > >>> print locale.format("%.10g", 1.2345678) > 1,2345678 > >>> print locale.format("%.15g", 0.1) > 0,1 > >>> print locale.format("%.17g", 0.1) > 0,10000000000000001 How about this format: ',1' (the local zero is also not printed) (I know this is strange but I need compatibility with local requirements) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From tomas.liden.privat at gmail.com Mon Aug 22 07:32:48 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:32:48 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <20110822100646.GA24782@cskk.homeip.net> Message-ID: On 22 Aug, 12:36, Chris Angelico wrote: > > Explicit is better than implicit. Instead of using the order, have a > config file that chooses the one(s) you want by name or IP address. Of > course, if you're on Unix/Linux, you can use the interface name (eth0, > eth1, etc) with a fair degree of reliability. > The config file solution is not suitable, I think. This code should run in a general cross platform application (Texttest), and we do not want each user of that system to be forced to edit a config file.. /Tomas From roy at panix.com Mon Aug 22 07:37:31 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 07:37:31 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Tomas Lid?n wrote: > In this particular case we have a host with several connections (LAN, > WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare > adapter but we wanted to get the LAN (or the "best" connection to our > server). Figuring out which is the best connection is a decidedly non-trivial problem. You could try some heuristic like "pick the address which has the same network number as me". But, what if you're multi-homed as well, and the target has addresses on more than one of the networks you're connected to? Not to mention that even enumerating all of your own connections is non-trivial. > With gethostbyname_ex() the ordering seemed to become LAN, > Wifi, etc and that's good for us. But we don't know if this holds on > other platforms (we're running on Windows 7). You can't count on the ordering being anything in particular. It's a lost cause. You may think you can find patterns, and then write your application to depend on those, and you will eventually get burned. > A cross-platform deterministic order would be excellent for us. "A cross-platform deterministic X would be excellent" is a true statement for almost any value of X. Many people have wasted much of their lives trying to achieve that goal, for various Xs. From tomas.liden.privat at gmail.com Mon Aug 22 07:39:39 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:39:39 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> On 22 Aug, 13:26, Roy Smith wrote: > In article > <356978ef-e9c1-48fd-bb87-849fe8e27... at p5g2000vbl.googlegroups.com>, > ?Tomas Lid?n wrote: > > > In what order are the addresses returned by socket.gethostbyname_ex()? > > > We know that gethostbyname() is indeterministic but hope that > > gethostbyname_ex() has a specified order. > > Why would you hope that? ?Or maybe a better question is, why would you > expect that? ?In general, all name resolution calls return results in > arbitrary order. ?In some cases, results are intentionally changed on > every call (i.e. round-robin) in an attempt at load sharing. > > What kind of ordering were you hoping for? See previous posts. Basically I was asking about the contract for this method.. hoping that it is deterministic. Our testing indicated that the interfaces are returned in a specific order, but we want to know if this is really the case (on all platforms). /Tomas From steve+comp.lang.python at pearwood.info Mon Aug 22 07:57:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 21:57:31 +1000 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: Message-ID: <4e52442b$0$29975$c3e8da3$5496439d@news.astraweb.com> Amirouche B. wrote: > A) type vs object > ----------------- > > 1) object is the base object, it has no bases : len(object.__bases__) > == 0 Correct, but for reference, a more direct test is: object.__bases__ == () (no need for len). > 2) every object in python inherit object : > any_object_except_object.__bases__[-1] is object Excluding old-style objects, I believe you are correct. > 3) object's type is type : object.__class__ is type > 4) type parent object is object : type.__bases__ == (object,) The relationship between type and object is somewhat special, and needs to be bootstrapped by the CPython virtual machine. Arbitrary types (classes) inherit from object. That means the type is a subclass of object: >>> class K(object):pass ... >>> issubclass(K, object) True What's less obvious is that types are themselves objects, and therefore are instances of object: >>> isinstance(K, object) True Since classes are objects, they have a type, namely ``type``. This includes ``type`` itself: * type is an instance of object * object is an instance of type * type is a subclass of object * but object is NOT a subclass of type > B) type vs metaclass > -------------------- > > 1) type is the first metaclass ? Excluding old-style classes, yes, all custom classes (those you create with the class statement) have a default metaclass of type. > 2) type is its own metaclass : type(type) is type ? Yes. Another bit of bootstrapping that the compiler does. >>> type(type) is type True > 3) object's metaclass is type ? Yes. > 4) other metaclasses *MUST* inherit type ? No. Metaclasses can be anything that mimics type. >>> def meta(name, bases, dict): ... class X(object): ... pass ... return X ... >>> class K(object): ... __metaclass__ = meta ... a = 1 ... >>> >>> K They don't even need to return a type/class. Like decorators, they can return anything. >>> def meta(name, bases, dict): ... return "spam" ... >>> class K(object): ... __metaclass__ = meta ... >>> K 'spam' > 5) type(any_object) == last_metaclass_..., which is, most of the time, > type ? I'm not sure what you mean by "last_metaclass". But no. The type of an object is its class: type(42) => int type("spam") => str type(1.23) => float However, the type of a class is *usually* type. > C) type vs class > ---------------- > > 1) Type is the metaclass of most classes Yes. > 2) The class statement:: > > class MyClass(object): > attribute = 1 > > def method(self): > pass > > translates to:: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': > def method: pass }) Except that the syntax won't work, the idea is broadly correct. > 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates > to:: > > type(MyClass).__call__(MyClass, *args, **kwargs) Like any function call, MyClass(...) becomes type(MyClass).__call__(self, ...) with self=MyClass. Since type(MyClass) is usually ``type``, that gives: type.__call__(MyClass, ...) > This is due to __getattribute__ algorithm (see E) > > 4) It's in type.__call__ that happens calls to __new__ and __init__ If type were written in pure Python, it would probably look something like this: class Type(object): # ... # other methods # ... def __call__(cls, *args, **kwargs): instance = cls.__new__(cls, *args, **kwargs) if isinstance(instance, cls): instance.__init__(*args, **kwargs) return instance But see further on, for more complication. Note that __new__ is special-cased as a staticmethod, hence it needs the first argument to be passed directly. > 5) 3) => classes are instance of type > > 6) Since type.__call__ is used to instantiate instance of instance of > type > (rephrased: __call__ is used to instantiate classes) where is the > code which > is executed when we write ``type(myobject)`` or ``type('MyClass', > bases, attributes)`` You would need to check the C implementation of type, but if I were doing this in pure Python, I'd have something like this: class Type(object): def __call__(self, *args, **kwargs): if self is Type: if kwargs: raise TypeError('unexpected keyword arguments') # calling type(...) directly if len(args) == 1: # Single argument call, like type(x) return x.__class__ else: # Like type(name, bases, dict) name, bases, dict = *args cls = Type.__new__(Type, name, bases, dict) if isinstance(cls, Type): cls.__init__(name, bases, dict) else: # called from MyClass(...) # which becomes type(MyClass).__call__(MyClass, ...) # self here equals MyClass, which is an instance of type but # not type itself instance = self.__new__(self, *args, **kwargs) if isinstance(instance, self): instance.__init__(*args, **kwargs) return instance def __new__(cls, *args): # magic to actually create a new type object Note that this may not be how ``type`` actually does it. See the source code, and I hope you have better luck reading it than I did! http://hg.python.org/cpython/file/c8e73a89150e/Objects/typeobject.c -- Steven From roy at panix.com Mon Aug 22 08:14:10 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 08:14:10 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> Message-ID: In article <034ff4bf-e3e4-47ff-9a6c-195412431e73 at s20g2000yql.googlegroups.com>, Tomas Lid?n wrote: > Basically I was asking about the contract for this method.. hoping > that it is deterministic. The contract for socket.gethostbyname_ex() is described at http://docs.python.org/library/socket.html#socket.gethostbyname_ex. It says: "Translate a host name to IPv4 address format, extended interface. Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4 addresses for the same interface on the same host (often but not always a single address). gethostbyname_ex() does not support IPv6 name resolution, and getaddrinfo() should be used instead for IPv4/v6 dual stack support." That's it. It says nothing about ordering, so nothing about ordering should be inferred. > Our testing indicated that the interfaces are returned in a specific > order, but we want to know if this is really the case (on all > platforms). No, it is not. From paul at subsignal.org Mon Aug 22 08:18:14 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Mon, 22 Aug 2011 14:18:14 +0200 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 22.08.2011 13:37, schrieb Roy Smith: > In article > , > Tomas Lid?n wrote: >> A cross-platform deterministic order would be excellent for us. > > "A cross-platform deterministic X would be excellent" is a true > statement for almost any value of X. Many people have wasted much of > their lives trying to achieve that goal, for various Xs. So true..., QOTW +1 From tomas.liden.privat at gmail.com Mon Aug 22 08:33:25 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 05:33:25 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: OK - thank you all for your contributions. /T From __peter__ at web.de Mon Aug 22 08:53:41 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 14:53:41 +0200 Subject: Optimizing Text Similarity Algorithm References: Message-ID: Ya?ar Arabac? wrote: > I originally posted this question on stackoverflow, you can find it here: > http://stackoverflow.com/q/7133350/886669 > > I just want people check what I am doing and express their opinion about > the thing I am doing is acceptable, or are there some expects of it that > could change. You are using only word frequencies to calculate the similarity of the document pairs. You can calculate these frequencies before you enter the the expensive for documentA in ...: for documentB in ...: calculate_similarity(documentA, documentB) loops and therefore bring that portion of your could from O(n*n) to O(n). Here's is a sample where I applied that technique blindly to your code. I also had to remove the django dependency, so I've changed it to operate on text files. import sys import math import re from collections import Counter from itertools import combinations def get_words(text): # FIXME regex = re.compile("\W+", flags=re.UNICODE) return re.split(regex, text) def pairs(files): """Generate (title, wordlist) pairs. (filename is used as title) """ for filename in files: with open(filename) as f: text = f.read() yield filename, get_words(text) def process(pairs): triples = [] total = Counter() for title, words in pairs: c = Counter(words) total.update(c.iterkeys()) sigma = sum(math.log(freq, 1.6) for freq in c.itervalues()) triples.append((title, c, sigma)) for (title1, freq1, sum1), (title2, freq2, sum2) in combinations( triples, 2): upper_part = 0 for word in freq1 & freq2: adjusted1 = math.log(freq1[word], 1.6) adjusted2 = math.log(freq2[word], 1.6) upper_part += ( adjusted1 * adjusted2 * math.log(len(triples)/total[word])) lower_part = math.sqrt(sum1 * sum2) title1, title2 = sorted([title1, title2]) yield title1, title2, upper_part/lower_part def main(): files = sys.argv[1:] results = process(pairs(files)) results = sorted(results, key=lambda x: x[:2]) results.sort(key=lambda x: x[2], reverse=True) print "\n".join("%s and %s => %f" % xcv for xcv in results) if __name__ == "__main__": main() From ulrich.eckhardt at dominolaser.com Mon Aug 22 08:57:24 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Aug 2011 14:57:24 +0200 Subject: write() References: Message-ID: Hyun-su wrote: > I have a file which is 3D data ([pixel_x, pixel_y, pixel_z]) > > I want to plot and write into other file as 1 dimension ([:, y_cut, > z_cut]) > > How can I do it? I'd write a loop along these lines: with open(outputfile, 'w') as o: for pixel_x, pixel_y, pixel_z in input_data: o.write(...) If you want a better suggestion, I'd suggest that you provide more info. Also, and that is very important, you should indicate which efforts you already too. In particular, I'd suggest the introductory tutorial on Python (see http://docs.python.org) and E.S. Raymonds essay on smart questions (search the web for it). If you don't show effort, people will assume you are lazy and just need someone to do your homework for you. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Mon Aug 22 09:01:51 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 15:01:51 +0200 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm wrote: > How about this format: > ',1' > (the local zero is also not printed) > > (I know this is strange but I need compatibility with local requirements) I believe you have to do it yourself: >>> locale.format("%f", 0.123) '0,123000' >>> locale.format("%f", 0.123).strip("0") ',123' From neilc at norwich.edu Mon Aug 22 09:05:03 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Aug 2011 13:05:03 GMT Subject: Optimizing Text Similarity Algorithm References: Message-ID: <9bf2fvFer9U1@mid.individual.net> On 2011-08-22, Peter Otten <__peter__ at web.de> wrote: > Ya??ar Arabac?? wrote: >> I originally posted this question on stackoverflow, you can find it here: >> http://stackoverflow.com/q/7133350/886669 >> >> I just want people check what I am doing and express their opinion about >> the thing I am doing is acceptable, or are there some expects of it that >> could change. Perhaps check out difflib.SequenceMatcher.ratio to see if the library function is good enough. -- Neil Cerutti From johnny.venter at zoho.com Mon Aug 22 09:07:39 2011 From: johnny.venter at zoho.com (johnny.venter) Date: Mon, 22 Aug 2011 06:07:39 -0700 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> Chris, thank you for the information. Focusing on Active Directory, I reviewed the info at the following site: http://technet.microsoft.com/en-us/library/cc961766.aspx Based on this, I need to find a module that implements the LDAP APIs. By default, it does not appear that Python can speak this language, I am using version 2.6.1. The module I found is Python-LDAP (http://www.python-ldap.org/). Does anyone have experience using this? ---- On Sun, 21 Aug 2011 00:30:07 -0700 Chris Angelico wrote ---- >On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: >> Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: >> >> From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? >> > >Then the "use Python" part is relatively immaterial; what you need to >know is: What network protocol are you using to "access and read >objects"? Start by researching that; once you know the details (is it >even TCP/IP-based?), you can look into whether Python has facilities >for speaking that protocol. > >ChrisA >-- >http://mail.python.org/mailman/listinfo/python-list > From research at johnohagan.com Mon Aug 22 09:08:50 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 22 Aug 2011 23:08:50 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> On Mon, 22 Aug 2011 15:27:36 +1000 Steven D'Aprano wrote: > On Mon, 22 Aug 2011 03:04 pm John O'Hagan wrote: > > > The "pitches" attribute represents the instances and as such I found > > myself adding a lot of methods like: > > > > def __getitem__(self, index): > > return self.pitches[index] > > > > def __len__(self): > > return len(self.pitches) > > > Looks like a call for (semi-)automatic delegation! > > Try something like this: > > > # Untested > class MySeq(object): > methods_to_delegate = ('__getitem__', '__len__', ...) > pitches = ... # make sure pitches is defined > def __getattr__(self, name): > if name in self.__class__.methods_to_delegate: > return getattr(self.pitches, name) > return super(MySeq, object).__getattr__(self, name) > # will likely raise AttributeError Thanks, this looks promising. I didn't know about __getattr__ or delegation. This example doesn't seem to work as is for special methods beginning with "__" (e.g.: "TypeError: object of type 'MyList' has no len()"). It seems that __getattr__ is not called for special methods. Also, it doesn't immediately suggest to me a way of modifying method calls (maybe __setattr__?). But it's certainly a neater way to get methods to operate on the attribute. I'm looking into it, and delegation generally. However, I don't understand what the super call is doing. If the method isn't delegated, shouldn't it just fall back to getattr(self, name)? Thanks and regards, John From abacau10 at gmail.com Mon Aug 22 09:21:35 2011 From: abacau10 at gmail.com (aba ca) Date: Mon, 22 Aug 2011 16:21:35 +0300 Subject: To cmd.exe Message-ID: Hi all! How can I send to cmd.exe "netstat -an"? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Mon Aug 22 09:29:33 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Aug 2011 14:29:33 +0100 Subject: To cmd.exe In-Reply-To: References: Message-ID: <4E5259BD.1050206@timgolden.me.uk> On 22/08/2011 14:21, aba ca wrote: > How can I send to cmd.exe "netstat -an"? Look at the subprocess module, and especially the .check_output convenience function: http://docs.python.org/library/subprocess.html#subprocess.check_output TJG From vlastimil.brom at gmail.com Mon Aug 22 09:59:16 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 22 Aug 2011 15:59:16 +0200 Subject: Help with regular expression in python In-Reply-To: <201108191555.53338.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108191555.53338.matze999@gmail.com> Message-ID: Sorry, if I missed some further specification in the earlier thread or if the following is oversimplification of the original problem (using 3 numbers instead of 32), would something like the following work for your data? >>> import re >>> data = """2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description""" >>> for res in re.findall(r"(?m)^(?:(?:[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+))?\s+){3}(?:.+)$", data): print res ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description >>> i.e. all parentheses are non-capturing (?:...) and there are extra anchors for line begining and end ^...$ with the multiline flag set via (?m) Each result is one matching line in this sample (if you need to acces single numbers, you could process these matches further or use the new regex implementation mentioned earlier by mrab (its developer) with the new match method captures() - using an appropriate pattern with the needed groupings). regards, vbr From k.sahithi2862 at gmail.com Mon Aug 22 10:18:49 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Mon, 22 Aug 2011 07:18:49 -0700 (PDT) Subject: TAMIL SEXY HOT GIRLS Message-ID: <31fb13a0-911a-4546-97b0-5154c1e4e916@e34g2000prn.googlegroups.com> v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From research at johnohagan.com Mon Aug 22 10:20:09 2011 From: research at johnohagan.com (John O'Hagan) Date: Tue, 23 Aug 2011 00:20:09 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> Message-ID: <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> On Mon, 22 Aug 2011 11:32:18 +0200 Peter Otten <__peter__ at web.de> wrote: > John O'Hagan wrote: > > > I have a class like this: > > > > class MySeq(): > > def __init__(self, *seq, c=12): > > self.__c = c > > self.__pc = sorted(set([i % __c for i in seq])) > > self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) > > #other calculated attributes > > > > @property > > def pitches(self): > > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > > > > #other methods > > That makes me dizzy. Are there any maxims in the Zen of Python that this > piece doesn't violate? "Now is better than never"? I know it looks crazy to take something apart and put it back together, as in this simplified example, but it does have a meaningful use: reducing a series of musical notes to a unique irreducible form "__pc", ("prime form" in pitch-class set theory), but keeping track of the actual current manifestation of that form via the writeable "order" attribute. That's why "pitches" must be called with each reference, because it may change, unlike "__pc", which can only change if the instance is reinitialised. I am open to more elegant suggestions, of course. :) [...] > > > > So I wrote this function which takes a method, modifies it to apply to an > > instance attribute, and takes care of any quirks: > > > > def listmeth_to_attribute(meth, attr): > > def new_meth(inst, *args): > > #ensure comparison operators work: > > args = [getattr(i, attr) if isinstance(i, inst.__class__) > > else i for i in args] > > reference = getattr(inst, attr) > > test = reference[:] > > result = meth(test, *args) > > #ensure instance is reinitialised > > #if attribute has been changed: > > if test != reference: > > inst.__init__(*test) > > #ensure slices are of same class > > if isinstance(result, meth.__objclass__): > > result = inst.__class__(*result) > > return result > > return new_meth > > > > and this decorator to apply this function to all the list methods and add > > them to MySeq: > > > > def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): > > """Overides = any methods in target to override from source""" > > def decorator(target_cls): > > for name, meth in vars(source_cls).items(): > > if name not in dir(target_cls) or name in overrides: > > setattr(target_cls, name, modfunc(meth, *modfunc_args)) > > return target_cls > > return decorator > > > > a kind of DIY single inheritance, used like this: > > > > @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') > > class MySeq(): > > ..... [...] > > In the standard library functools.total_ordering uses that technique and I > find the implications hard to understand: > > http://bugs.python.org/issue10042 > > Your decorator looks even more complex; I'd only recommend using it if > you're absolutely sure you're clever enough to debug it ;) It looks to me like that total_ordering bug is a result of using comparison operators on objects which may not implement them; I'm pretty sure the listmeth_to_attribute function above can only allow comparing lists with lists or raising an exception. Although I must admit that this creates an unexpected bug/feature whereby lists and MySeqs can be successfully compared, so I take your point! Thanks for your reply, John From lzlu123 at gmail.com Mon Aug 22 10:31:55 2011 From: lzlu123 at gmail.com (lzlu123) Date: Mon, 22 Aug 2011 07:31:55 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> <7849d9ff-f472-49c3-a1ce-0f618a301f06@e7g2000vbw.googlegroups.com> Message-ID: <9ceeb1ea-f896-4e64-bad7-b544c329bc0a@k15g2000yqd.googlegroups.com> On Aug 19, 6:38?pm, aspineux wrote: > On Aug 19, 5:00?pm, lzlu123 wrote: > > > > > > > > > > > I have an instrument that has a RS232 type serial comm port and I need > > to connect to and control. I use Python 3.2 in Windows XP, plus > > pySerial module. I have a problem when I execute a script consisting > > of statements that open the comm port, configure it, write strings to > > and receive strings from it. Thoese strings aer either commands > > pertinent to the instrument (control) or responses from the instrument > > (response). > > > When those statements are executed in a python interpreter > > interactively (at >>>), I get what I expect and the results are good > > and correct. However, when I execute the script, either being invoked > > within the interpreter or run file, I don?t get what I want. The > > statements in the script is the same as what I use in the interactive > > interpreter. > > > Why do I get the strange behavior and how can I change the script to > > make it to behave like in interactive interpreter? > > > ----------------------script----------------------- > > def read(comport): > > > ? ? wrt_str=b'movt 3000'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? wrt_str=b'scan'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? rsp_str=comport.readlines() #########1 > > You use readlines() with a s at the end ! > > * Note that when the serial port was opened with no timeout, that > readline() > * blocks until it sees a newline (or the specified size is reached) > * and that readlines() would never return and therefore refuses to > work > * (it raises an exception in this case)! > > > > > > > > > > > > > ? ? wrt_str=b'hllo'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? rsp_str=comport.readlines()#########2 > > ---------------------------------------------------------- > > > The problem is with the lines above with #######. In interactive mode, > > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > > correct responses there. However, if I execute the script above, there > > is no delay at all and I get incorrect results (garbage). I set the > > read timeout to 0 in comm port set up, as > > > comport.timeout=0 > > So the comport should be in blocking mode if it waits for the end of > > line or end of file. > > Wrong : > > ? ? timeout = None: wait forever > ? ? timeout = 0: non-blocking mode (return immediately on read) > ? ? timeout = x: set timeout to x seconds (float allowed) > > > > > > > > > > > > > I tried many things, like exec (execfile in 2.7), but at no avail. > > > I have an update to the original post I made a few days ago. I think I > > know what the problem is and want to know if anyone has a solution: > > > After putting "print" and "time.sleep(delay)" after every statement, I > > found when the script is running, it appears going around the pyserial > > statement, such as "comport.write(..)" or "comport.readlines(...)" > > while the pyserial command is executing (appearing as waiting and > > busying doing some thing, you know serial port is slow). So for > > example, when I exec all statements in a python interactive shell, I > > am not able to type and run a new statement if the previous one is not > > returned. Let's ay, if comport.readlines() is not returning, I can't > > type and run the next comport.write(...) statemtn. However, in a > > script that is running, if the comport.readlines() is busy reading, > > the next statement is running, if the next statement happens to be a > > comport.write() which will abort the reading. > > > Is there any way to force the python script to behave like running > > exactly sequentially? > > You have some new things to try I tried to set the timeout to different values other than 0, but still got same result -- ruuning script directly behaves differently from executing statements in interactive shell. I even tried using read instead of readline(s). From lzlu123 at gmail.com Mon Aug 22 10:33:26 2011 From: lzlu123 at gmail.com (lzlu123) Date: Mon, 22 Aug 2011 07:33:26 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: <2f3f84da-6f21-48a6-9f2d-ba0c916dbdde@f41g2000yqh.googlegroups.com> On Aug 19, 11:06?pm, Javier wrote: > Never used it, but I think you can try this: > > Pexpect - a Pure Python Expect-like module > Pexpect is a pure Python Expect-like module. Pexpect makes Python...www.noah.org/python/pexpect/ > > > > > > > > lzlu123 wrote: > > I have an instrument that has a RS232 type serial comm port and I need > > to connect to and control. I use Python 3.2 in Windows XP, plus > > pySerial module. I have a problem when I execute a script consisting > > of statements that open the comm port, configure it, write strings to > > and receive strings from it. Thoese strings aer either commands > > pertinent to the instrument (control) or responses from the instrument > > (response). > > > When those statements are executed in a python interpreter > > interactively (at >>>), I get what I expect and the results are good > > and correct. However, when I execute the script, either being invoked > > within the interpreter or run file, I don???t get what I want. The > > statements in the script is the same as what I use in the interactive > > interpreter. > > > Why do I get the strange behavior and how can I change the script to > > make it to behave like in interactive interpreter? > > > ----------------------script----------------------- > > def read(comport): > > > ? ?wrt_str=b'movt 3000'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?wrt_str=b'scan'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?rsp_str=comport.readlines() #########1 > > > ? ?wrt_str=b'hllo'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?rsp_str=comport.readlines()#########2 > > ---------------------------------------------------------- > > > The problem is with the lines above with #######. In interactive mode, > > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > > correct responses there. However, if I execute the script above, there > > is no delay at all and I get incorrect results (garbage). I set the > > read timeout to 0 in comm port set up, as > > > comport.timeout=0 > > So the comport should be in blocking mode if it waits for the end of > > line or end of file. > > > I tried many things, like exec (execfile in 2.7), but at no avail. > > > I have an update to the original post I made a few days ago. I think I > > know what the problem is and want to know if anyone has a solution: > > > After putting "print" and "time.sleep(delay)" after every statement, I > > found when the script is running, it appears going around the pyserial > > statement, such as "comport.write(..)" or "comport.readlines(...)" > > while the pyserial command is executing (appearing as waiting and > > busying doing some thing, you know serial port is slow). So for > > example, when I exec all statements in a python interactive shell, I > > am not able to type and run a new statement if the previous one is not > > returned. Let's ay, if comport.readlines() is not returning, I can't > > type and run the next comport.write(...) statemtn. However, in a > > script that is running, if the comport.readlines() is busy reading, > > the next statement is running, if the next statement happens to be a > > comport.write() which will abort the reading. > > > Is there any way to force the python script to behave like running > > exactly sequentially? I am using Python 3.2 in Windows in which Pexpect appeared problematic. From gnarlodious at gmail.com Mon Aug 22 11:28:41 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Aug 2011 08:28:41 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables Message-ID: In my last post I learned of the necessity of filtering CGI input, so what I want to do is set a dict of allowable variable names: allowedVariables = {'eeny':None, 'meeny':None, 'miny':None, 'mo':None} # Set up a FieldStorage object: import cgi inputVariables = cgi.FieldStorage() for name, value in {"eeny" : "value1", "meeny" : "value2", "miny" : "value3", "mofo" : "value4"}.items(): inputVariables.list.append(cgi.MiniFieldStorage(name, value)) allowedVariables.update(((key, inputVariables[key].value) for key in inputVariables)) allowedVariables As you can see, the variable 'mofo' gets added to allowedVariables, which is normal behavior. Is there an easy way to limit updates to ONLY variables in the allowedVariables dict? And in addition, maybe return an error so the attacker can be blocked? -- Gnarlie From miki.tebeka at gmail.com Mon Aug 22 11:39:47 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 22 Aug 2011 08:39:47 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables In-Reply-To: References: Message-ID: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> > Is there an easy way to limit updates to > ONLY variables in the allowedVariables dict? allowedVariables = ['eeny', 'meeny', 'miny', 'mo'] form = cgi.FieldStorage() safe_input = dict((key, form.getvalue(key)) for key in allowedVariables) > And in addition, maybe return an error so the attacker can be blocked? You can check if there is a "non-allowed variable" and then return HTTP error. if set(form) - set(allowedVariables): print('Status: 406\n\n') raise SystemExit() HTH -- Miki Tebeka http://pythonwise.blogspot.com From me+list/python at ixokai.io Mon Aug 22 11:41:38 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 08:41:38 -0700 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ In-Reply-To: References: Message-ID: <4E5278B2.1050504@ixokai.io> On 8/22/11 3:02 AM, Amirouche B. wrote: > A) type vs object > ----------------- > > 1) object is the base object, it has no bases : len(object.__bases__) > == 0 > 2) every object in python inherit object : > any_object_except_object.__bases__[-1] is object Not exactly. Python has two somewhat different object models, "old style classes" and "new style classes", with slightly different behavior and internal structure. class Foo: pass is an "old-style class", dated back to Python's ancient past. This all relates to the fact that 'type' and 'class' used to be two pretty different things, where one was something you mostly did only in C, and one was something you did (mostly) only in Python. They are largely the same now. > 3) object's type is type : object.__class__ is type > 4) type parent object is object : type.__bases__ == (object,) Saying "type" and "parent" and the like for new-style classes is something of a misnomer. For "type" and "object", these things aren't constructed like this. What you have here is technically true if you go poke at it in the interpreter, but it doesn't really /mean/ anything because its not how these objects came to be and is circular and a bit confusing. These fundamental objects are created special. > B) type vs metaclass > -------------------- > > 1) type is the first metaclass ? Type is the basic, default "metaclass", yes. A metaclass is a callable that constructs class objects. > 2) type is its own metaclass : type(type) is type ? Only in a purely theoretical way. It doesn't actually mean anything; moreover, type(something) is NOT how you determine somethings metaclass. Its how you determine somethings type. The two concepts may be very distinct. Lots of things don't have metaclasses. > 3) object's metaclass is type ? Again, only theoretically. > 4) other metaclasses *MUST* inherit type ? Absolutely not. Any callable can be a metaclasss. Despite its name, it doesn't have to be itself a class or anything. Just something you can call with er, 3 (I forget exactly) arguments, and which returns a constructed class object. > 5) type(any_object) == last_metaclass_..., which is, most of the time, > type ? Not necessarily at all. In fact, there is no way I'm aware of to determine if a metaclass was involved in a classes construction unless said metaclass wants to provide such a mechanism. Metaclasses are kind of a hack. They are a way to hook into the class construction that's normally done and do something, anything you want, (even hijack the whole procedure and NOT construct a class at all, but play a song if you want) before its all finished. For example, this is a metaclass I've used: PageTypes = {} class _PageRegistration(type): def __new__(cls, name, bases, dct): klass = type.__new__(cls, name, bases, dct) typename = name[:-9].lower() if not typename: typename = None PageTypes[typename] = klass klass.Type = typename return klass class QueuePage(sc.SizedPanel): __metaclass__ = _PageRegistration Note, the fact that my _PageRegistration metaclass inherits is itself a class which inherits from type is just one convenient way to write metaclasses. It could as simply have been just a function. Metaclasses are somewhat poorly named in that they are really, "creation hooks". > C) type vs class > ---------------- > > 1) Type is the metaclass of most classes Yes and no. Yes, in that most classes are created using the default mechanism inside CPython. The class body is executed in a scope, the resulting dictionary is bound to a new class object, bases and the like are set, and such. No in that it really just, IIUC, skips the whole "metaclass" part of the process because this 'default mechanism' doesn't need to call out into other code to do its job. At least, I think-- May be wrong here, metaclasses are something of a dark voodoo and I'm not 100% entirely familiar with the internal workings of CPython. But functionally, a metaclass is the chunk of code responsible for the actual physical construction of the class object. > 2) The class statement:: > > class MyClass(object): > attribute = 1 > > def method(self): > pass > > translates to:: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': > def method: pass }) Translates to, I don't know about that. Is functionally equivalent, yes. It is more or less what happens. > 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates > to:: > > type(MyClass).__call__(MyClass, *args, **kwargs) > > This is due to __getattribute__ algorithm (see E) > 4) It's in type.__call__ that happens calls to __new__ and __init__ Again, "translates to" is suggesting "this is what happens when you do X", which I don't know if is strictly true. CPython inside may be optimizing this whole process. Especially when it comes to "magic methods", __x__ and the like -- CPython rarely uses __get*_ for those. It just calls the methods directly on the class object. What you're doing here is functionally equivalent to what CPython does, but it may take a more direct route to get there. CPython has the advantage of not being Python and having direct access to internals. > 5) 3) => classes are instance of type > > 6) Since type.__call__ is used to instantiate instance of instance of > type > (rephrased: __call__ is used to instantiate classes) where is the > code which > is executed when we write ``type(myobject)`` or ``type('MyClass', > bases, attributes)`` > __getattribute__ resolution algorithm (see E) tells me that it > should be type.__call__ > but type.__call__ is already used to class instatiation. Python callables can have more then one argument, and more then one behavior, and can choose to do more then one thing based on the number of arguments. They don't have overloading, but they can do it themselves. You've already proven that, and you already know that -- you're sorta over-complicating this :) You said: MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def method: pass }) Type.__call__ does both. > C') class vs class instances aka. objects > ----------------------------------------- > > 1) A class type is a metaclass : issubclass(type(MyClass), type), > MyClass.__class__ == type(MyClass) An old-style classe's type is classobj. A new-style class's type is type. It may or may not be a "metaclass". type(foo) is not defined as 'the metaclass of foo', but 'the type of foo'. It often is the same thing, since most of the time type(myclass) is "type" itself and "type" is the default "metaclass". But mixing up the two concepts isn't really very helpful. > 2) An object type is a class : most of the time > isinstance(type(my_object), type) > generally issubclass(type(type(my_object)), type) Generally. > D) builtin types > ---------------- > > 1) builtin types are their own metaclass ? Builtin types are constructed by the interpreter, and may or may not involve themselves with the class/type hierarchy. Even when they do, they may only do so partially. > 2) why function builtin type can not be subclassed ? Because functions are not classes. They're discrete things of their own. That a function object has a __class__ attribute is an example of a builtin partially involving itself in the class/type hierarchy, largely just for introspection purposes-- since functions are first-class citizens, you need to be able to pass it around and test to determine what one thing or another actually is. Now, functions ARE indeed PyObjects, the internal CPython representation of an object, of which all things are. But that's not really the same thing as ultimately inheriting from and involving itself in "object" and types/classes. > 3) how does builtin function type relate to callable objects ? It doesn't, really. > 4) int(1) is the same as int.__call__(1), since type(int) is type, > shouldn't int(1) > translates to type.__call__(int, 1) ? You're overly focused on __call__, for one thing. For another, no, I'm not sure why you think one should "translate" to another (again: just because you've got the basic relationship of the meta-parts of Python down pat, doesn't mean Python internals actually goes through all those actual steps when doing things). int(1) translates into: int.__call__(1) int_inst = int.__new__(1) More or less. Now, "int" is itself a "class" (type), so it was, itself, constructed by a call to type (well, "type"'s internal C version of itself, Py_TYPE). type, the metaclass or class-constructor version, is only called to create /classes/, at class-creation-time. After "int" itself exists, its no longer involved. int has its own __new__ that's used to construct actual instances of itself. type is now out of the picture. > > > E) __getattribute__ > ------------------- > > 1) ``my_object.attribute`` always translates to > ``my_object.__getattribute__('attribute')`` No. __getattribute__ is a mechanism to hook into the attribute fetching mechanism. (As is __getattr__). It is NOT always invoked. Especially in the case of __*__ attributes, which by and large bypass such hooks, as the CPython internals is calling those functions directly on the class instances themselves. > 2) Is the following algorithm describing __getattribute__ correct This is broadly incorrect because it implies that __getattribute__ is an internal protocol that Python uses for attribute-resolution, which is simply untrue. Its a method you may define on new style classes which, if present, is called when an attribute is requested from an object (but NOT in the case of __*__ methods, usually, which are obtained internally by a direct struct access, i.e., mytype->tp_new gets mytype.__new__). If no such attribute exists, it goes along to do its default attribute-resolution process, including the descriptor protocol and dict checking and the like. __getattribute__ is an optional hook that you can define which allows a Python class to /bypass/ the normal mechanism for normal (non-magic) attributes. If you're asking what the normal mechanism is, its broadly: - Check to see if the object's base-classes have a descriptor of the attributes name. If so, call that. - Check to see if the object's instance dict has an attribute of the name. If so, return that. - Check to see if the object's base-classes have an attribute of the name. More or less. I think. I'm probably leaving something out there. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Mon Aug 22 11:57:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 16:57:51 +0100 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ In-Reply-To: <4E5278B2.1050504@ixokai.io> References: <4E5278B2.1050504@ixokai.io> Message-ID: On Mon, Aug 22, 2011 at 4:41 PM, Stephen Hansen wrote: > Not exactly. Python has two somewhat different object models, "old style > classes" and "new style classes", with slightly different behavior and > internal structure. > > ? class Foo: pass > > is an "old-style class", dated back to Python's ancient past. This all > relates to the fact that 'type' and 'class' used to be two pretty > different things, where one was something you mostly did only in C, and > one was something you did (mostly) only in Python. They are largely the > same now. And "now" includes everything in Python 3, where a class implicitly derives from object if no other subclassing is given. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 22 12:09:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 02:09:50 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e527f4e$0$29996$c3e8da3$5496439d@news.astraweb.com> Tomas Lid?n wrote: > In this particular case we have a host with several connections (LAN, > WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare > adapter but we wanted to get the LAN (or the "best" connection to our > server). Define "best" connection. If I tell you that my server has the following 6 connections: Wifi1, LAN4, LAN1, LAN2, Wifi2, LAN5 which one is "best"? Once you have an algorithm for deciding which connection is "best" for everybody, then you can check whether gethostbyname_ex uses that algorithm, or some other one. -- Steven From bob at passcal.nmt.edu Mon Aug 22 12:35:20 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 10:35:20 -0600 Subject: Setting the time in Win7 Message-ID: <2011082210352016807-bob@passcalnmtedu> Permissions! We're running in an account as an administrator (the only account on the laptops) and the program just calls system(time xxxx) and system(date xxxx) after reading it from a connected GPS receiver. I've fiddled with everything I could find in the registry and with the secpol.msc program and there doesn't seem to be any reason that it can't set the time, but it can't. Any ideas? Thanks! Bob From emile at fenx.com Mon Aug 22 12:35:56 2011 From: emile at fenx.com (Emile van Sebille) Date: Mon, 22 Aug 2011 09:35:56 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/22/2011 2:55 AM Richard D. Moores said... > I couldn't resist giving it a try. Using Python 3.2.1 on a 64-bit > Windows 7 machine with a 2.60 gigahertz AMD Athlon II X4 620 > processor, I did 18 tests, alternating between n=n+1 and n+=1 (so 9 > each). > > The fastest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0879 usec per loop > > The slowest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0902 usec per loop > > The fastest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0831 usec per loop > > The slowest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0842 usec per loop > > Coincidence? > Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :) Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile> From emile at fenx.com Mon Aug 22 13:22:25 2011 From: emile at fenx.com (Emile van Sebille) Date: Mon, 22 Aug 2011 10:22:25 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/22/2011 9:35 AM Emile van Sebille said... > On 8/22/2011 2:55 AM Richard D. Moores said... >> Coincidence? >> > > Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :) > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.108 usec per loop > > C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.108 usec per loop Actually, it's more likely I hit a minimum resolution issue -- I ran it twenty more times and never got a different result. Emile From tjreedy at udel.edu Mon Aug 22 13:34:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2011 13:34:57 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> Message-ID: On 8/22/2011 7:39 AM, Tomas Lid?n wrote: > On 22 Aug, 13:26, Roy Smith wrote: >> In article >> <356978ef-e9c1-48fd-bb87-849fe8e27... at p5g2000vbl.googlegroups.com>, >> Tomas Lid?n wrote: >> >>> In what order are the addresses returned by socket.gethostbyname_ex()? >> >>> We know that gethostbyname() is indeterministic but hope that >>> gethostbyname_ex() has a specified order. >> >> Why would you hope that? Or maybe a better question is, why would you >> expect that? In general, all name resolution calls return results in >> arbitrary order. In some cases, results are intentionally changed on >> every call (i.e. round-robin) in an attempt at load sharing. >> >> What kind of ordering were you hoping for? > > See previous posts. > > Basically I was asking about the contract for this method.. The doc "Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4/v6 addresses for the same interface on the same host (most likely containing only a single address)." > hoping that it is deterministic. As far as I can see, that is not in the contract. > Our testing indicated that the interfaces are returned in a specific > order, but we want to know if this is really the case (on all > platforms). Even if it were so now, a patch could change things. -- Terry Jan Reedy From mail at timgolden.me.uk Mon Aug 22 13:41:45 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Aug 2011 18:41:45 +0100 Subject: Setting the time in Win7 In-Reply-To: <2011082210352016807-bob@passcalnmtedu> References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <4E5294D9.80408@timgolden.me.uk> If memory serves, you need to enable a specific privilege to set the time in Vista+. Just a moment... Have a look here: http://support.microsoft.com/kb/300022 and look for SeSystemtimePrivilege generally. Sorry; I'm a bit rushed at the moment. Feel free to post back if that isn't clear TJG On 22/08/2011 17:35, Bob Greschke wrote: > Permissions! > > We're running in an account as an administrator (the only account on the > laptops) and the program just calls system(time xxxx) and system(date > xxxx) after reading it from a connected GPS receiver. I've fiddled with > everything I could find in the registry and with the secpol.msc program > and there doesn't seem to be any reason that it can't set the time, but > it can't. Any ideas? > > Thanks! > > Bob > From fuentesej at gmail.com Mon Aug 22 13:43:54 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Mon, 22 Aug 2011 10:43:54 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 20, 4:36?am, Phil Thompson wrote: > On Fri, 19 Aug 2011 14:32:12 -0700 (PDT), Edgar Fuentes > > > > > > > > > > wrote: > > On Aug 19, 4:21?pm, Carl Banks wrote: > >> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > >> > On Aug 19, 1:56?pm, Phil Thompson > >> > ?wrote: > >> > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > >> > > wrote: > >> > > > Dear friends, > > >> > > > I need execute an external program from a gui using PyQt4, to > avoid > >> > > > that hang the main thread, i must connect the signal > >> > > > "finished(int)" > >> > > > of a QProcess to work properly. > > >> > > > for example, why this program don't work? > > >> > > > ? ?from PyQt4.QtCore import QProcess > >> > > > ? ?pro = QProcess() # create QProcess object > >> > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > >> > > > x="started":print(x)) ? ? ? ?# connect > >> > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > >> > > > x="finished":print(x)) > >> > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py > program > >> > > > (contain print("hello world!")) > >> > > > ? ?timeout = -1 > >> > > > ? ?pro.waitForFinished(timeout) > >> > > > ? ?print(pro.readAllStandardOutput().data()) > > >> > > > output: > > >> > > > ? ?started > >> > > > ? ?0 > >> > > > ? ?b'hello world!\n' > > >> > > > see that not emit the signal finished(int) > > >> > > Yes it is, and your lambda slot is printing "0" which is the return > >> > > code > >> > > of the process. > > >> > > Phil > > >> > Ok, but the output should be: > > >> > ? ? started > >> > ? ? b'hello world!\n' > >> > ? ? finished > > >> > no?. > > >> > thanks Phil > > >> Two issues. ?First of all, your slot for the finished function does not > >> have the correct prototype, and it's accidentally not throwing an > >> exception because of your unnecessary use of default arguments. > ?Anyway, > >> to fix that, try this: > > >> pro.connect(pro, SIGNAL("finished(int)"), lambda v, > >> x="finished":print(x)) > > >> Notice that it adds an argument to the lambda (v) that accepts the int > >> argument of the signal. ?If you don't have that argument there, the int > >> argument goes into x, which is why Python prints 0 instead of > "finished". > > >> Second, processess run asynchrously, and because of line-buffering, IO > >> can output asynchronously, and so there's no guarantee what order > output > >> occurs. ?You might try calling the python subprocess with the '-u' > switch > >> to force unbuffered IO, which might be enough to force synchronous > output > >> (depending on how signal/slot and subprocess semantics are > implemented). > > >> Carl Banks > > > Thanks Carl, your intervention was very helpful for me, this solve my > > semantic error. I need to study more about signal/slots and process. > > In which case you should look at the modern, Pythonic connection syntax > rather than the old one... > > ? ? pro.started.connect(lambda: print("started")) > ? ? pro.finished.connect(lambda: print("finished")) > > Phil Pythonic, great!, more straightforward. Thanks again Phil and Carl. best regards, Edgar Fuentes From smainklh at gmail.com Mon Aug 22 14:09:56 2011 From: smainklh at gmail.com (Smaine Kahlouch) Date: Mon, 22 Aug 2011 20:09:56 +0200 Subject: python apt help Message-ID: <4E529B74.8090706@gmail.com> Hi, I'm trying to use the apt_pkg module but it seems to me really hard and i didn't find samples for what i'm trying to do. Actually it should be simple : - Installing a package like 'aptitude install mypackage' - test if a package is already installed Thank you all for your help, Sam From __peter__ at web.de Mon Aug 22 14:38:30 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 20:38:30 +0200 Subject: Adding modified methods from another class without subclassing References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> Message-ID: John O'Hagan wrote: > On Mon, 22 Aug 2011 11:32:18 +0200 > Peter Otten <__peter__ at web.de> wrote: > >> John O'Hagan wrote: >> >> > I have a class like this: >> > >> > class MySeq(): >> > def __init__(self, *seq, c=12): >> > self.__c = c >> > self.__pc = sorted(set([i % __c for i in seq])) >> > self.order = ([[self.__pc.index(i % __c), i // __c] for i in >> > seq]) >> > #other calculated attributes >> > >> > @property >> > def pitches(self): >> > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] >> > >> > #other methods >> >> That makes me dizzy. Are there any maxims in the Zen of Python that this >> piece doesn't violate? > > "Now is better than never"? > > I know it looks crazy to take something apart and put it back together, as > in this *simplified* *example* emphasis mine ;) > , but it does have a meaningful use: reducing a > series of musical notes to a unique irreducible form "__pc", ("prime form" > in pitch-class set theory), but keeping track of the actual current > manifestation of that form via the writeable "order" attribute. That's why > "pitches" must be called with each reference, because it may change, > unlike "__pc", which can only change if the instance is reinitialised. > > I am open to more elegant suggestions, of course. :) > [...] Dunno. Maybe you could inherit from collections.(Mutable)Sequence and somewhat reduce the number of methods you'd have to implement. Or you introduce a Pitch (Python) class that knows about its pitch class, and put that into a normal list: >>> class Pitch(int): ... @property ... def pitch_class(self): ... return self % 12 ... def __repr__(self): ... return "Pitch(%s, pitch_class=%s)" % (self, self.pitch_class) ... >>> map(Pitch, [1,0,42]) [Pitch(1, pitch_class=1), Pitch(0, pitch_class=0), Pitch(42, pitch_class=6)] From bob at passcal.nmt.edu Mon Aug 22 14:46:04 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 12:46:04 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <2011082212460475249-bob@passcalnmtedu> Hi! Yup. I've been from one end of that article to the other with no luck. It must be something to do with the shell that the system() call creates not having permission to set the time, but I can't figure out how to get around it. Just using the GUI the account where the user is running the program from has permission to set the time. On 2011-08-22 11:41:45 -0600, Tim Golden said: > If memory serves, you need to enable a specific privilege to > set the time in Vista+. Just a moment... > > Have a look here: > > http://support.microsoft.com/kb/300022 > > and look for SeSystemtimePrivilege generally. Sorry; I'm > a bit rushed at the moment. Feel free to post back if > that isn't clear > > TJG > > On 22/08/2011 17:35, Bob Greschke wrote: >> Permissions! >> >> We're running in an account as an administrator (the only account on the >> laptops) and the program just calls system(time xxxx) and system(date >> xxxx) after reading it from a connected GPS receiver. I've fiddled with >> everything I could find in the registry and with the secpol.msc program >> and there doesn't seem to be any reason that it can't set the time, but >> it can't. Any ideas? >> >> Thanks! >> >> Bob From matthew.brett at gmail.com Mon Aug 22 14:51:13 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 11:51:13 -0700 (PDT) Subject: Error when deleting and reimporting subpackages Message-ID: Hi, I recently ran into this behavior: >>> import sys >>> import apkg.subpkg >>> del sys.modules['apkg'] >>> import apkg.subpkg as subpkg Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'subpkg' where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. Is this behavior expected? Best, Matthew From me+list/python at ixokai.io Mon Aug 22 15:06:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 12:06:44 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: <4E52A8C4.6080404@ixokai.io> On 8/22/11 11:51 AM, Matthew Brett wrote: > Hi, > > I recently ran into this behavior: > >>>> import sys >>>> import apkg.subpkg >>>> del sys.modules['apkg'] >>>> import apkg.subpkg as subpkg > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'subpkg' > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > Is this behavior expected? Yes. Doing an import of "apkg.subpkg" results in more then just "test1" being cached in sys.modules, and you're removing half of that so leaving Python in a weird state. You also want to del sys.modules["apkg.subpkg"], then you'll be able to re-import apkg.subpkg. I.e: Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import test1.test2 >>> del sys.modules['test1'] >>> del sys.modules['test1.test2'] >>> import test1.test2 as test2 >>> -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From nobody at nowhere.com Mon Aug 22 15:12:16 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 22 Aug 2011 20:12:16 +0100 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: On Sun, 21 Aug 2011 23:37:42 -0700, Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. It doesn't. In fact, the order of the IP addresses may have been deliberately randomised (by the resolver and/or DNS server) in order to provide a simple form of load balancing. From matthew.brett at gmail.com Mon Aug 22 15:14:50 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 12:14:50 -0700 (PDT) Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Monday, August 22, 2011 12:06:44 PM UTC-7, Stephen Hansen wrote: > On 8/22/11 11:51 AM, Matthew Brett wrote: > > Hi, > > > > I recently ran into this behavior: > > > >>>> import sys > >>>> import apkg.subpkg > >>>> del sys.modules['apkg'] > >>>> import apkg.subpkg as subpkg > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'module' object has no attribute 'subpkg' > > > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > > > Is this behavior expected? > > Yes. Doing an import of "apkg.subpkg" results in more then just "test1" > being cached in sys.modules, and you're removing half of that so leaving > Python in a weird state. > > You also want to del sys.modules["apkg.subpkg"], then you'll be able to > re-import apkg.subpkg. I.e: > > Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> import test1.test2 > >>> del sys.modules['test1'] > >>> del sys.modules['test1.test2'] > >>> import test1.test2 as test2 > >>> Yes, sorry, I should have mentioned that I explored these kind of variations. I think I see that there isn't an obvious way for del sys.modules['apkg'] to know to delete or modify 'apkg.subpkg', because sys.modules is just a dict. However, I could imagine the import machinery being able to recognize that 'apkg.subpkg' is broken, and re-import it without error. Is that reasonable? Best, Matthew From matthew.brett at gmail.com Mon Aug 22 15:14:50 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 12:14:50 -0700 (PDT) Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Monday, August 22, 2011 12:06:44 PM UTC-7, Stephen Hansen wrote: > On 8/22/11 11:51 AM, Matthew Brett wrote: > > Hi, > > > > I recently ran into this behavior: > > > >>>> import sys > >>>> import apkg.subpkg > >>>> del sys.modules['apkg'] > >>>> import apkg.subpkg as subpkg > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'module' object has no attribute 'subpkg' > > > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > > > Is this behavior expected? > > Yes. Doing an import of "apkg.subpkg" results in more then just "test1" > being cached in sys.modules, and you're removing half of that so leaving > Python in a weird state. > > You also want to del sys.modules["apkg.subpkg"], then you'll be able to > re-import apkg.subpkg. I.e: > > Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> import test1.test2 > >>> del sys.modules['test1'] > >>> del sys.modules['test1.test2'] > >>> import test1.test2 as test2 > >>> Yes, sorry, I should have mentioned that I explored these kind of variations. I think I see that there isn't an obvious way for del sys.modules['apkg'] to know to delete or modify 'apkg.subpkg', because sys.modules is just a dict. However, I could imagine the import machinery being able to recognize that 'apkg.subpkg' is broken, and re-import it without error. Is that reasonable? Best, Matthew From bob at passcal.nmt.edu Mon Aug 22 15:42:28 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 13:42:28 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <2011082213422850073-bob@passcalnmtedu> Several people have been hacking away on this computer we are testing on, so I'm not sure what settings -- other than all of them -- have been messed with, but popen("time ...") seems to work, but system("time ...") does not. I'm going to restore the machine to its original state and see what happens. Bob On 2011-08-22 11:41:45 -0600, Tim Golden said: > If memory serves, you need to enable a specific privilege to > set the time in Vista+. Just a moment... > > Have a look here: > > http://support.microsoft.com/kb/300022 > > and look for SeSystemtimePrivilege generally. Sorry; I'm > a bit rushed at the moment. Feel free to post back if > that isn't clear > > TJG > > On 22/08/2011 17:35, Bob Greschke wrote: >> Permissions! >> >> We're running in an account as an administrator (the only account on the >> laptops) and the program just calls system(time xxxx) and system(date >> xxxx) after reading it from a connected GPS receiver. I've fiddled with >> everything I could find in the registry and with the secpol.msc program >> and there doesn't seem to be any reason that it can't set the time, but >> it can't. Any ideas? >> >> Thanks! >> >> Bob From chris at simplistix.co.uk Mon Aug 22 17:36:54 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 22 Aug 2011 14:36:54 -0700 Subject: MailingLogger 3.4.0 Released! In-Reply-To: <4E4CB31A.5090803@simplistix.co.uk> References: <4E4CB31A.5090803@simplistix.co.uk> Message-ID: <4E52CBF6.30905@simplistix.co.uk> Heh, of course, I forgot the setuptools-git extension to make "include_package_data=True" work, so this release was pretty useless, other than the docs on packages.python.org/testfixtures ;-) Anyway, 3.4.1 has now been released which fixes this! cheers, Chris On 17/08/2011 23:37, Chris Withers wrote: > I'm pleased to announce a new release of Mailinglogger. > > Mailinglogger provides two handlers for the standard python > logging framework that enable log entries to be emailed either as the > entries are logged or as a summary at the end of the running process. > > The handlers have the following features: > > - customisable and dynamic subject lines for emails sent > > - emails sent with a configurable headers for easy filtering > > - flood protection to ensure the number of emails sent is not excessive > > - support for SMTP servers that require authentication > > - fully documented and tested > > This release has no functional changes but finally ships with a full new > set of Sphinx docs: > > http://packages.python.org/mailinglogger/ > > For more information, please see: > http://www.simplistix.co.uk/software/python/mailinglogger > or > http://pypi.python.org/pypi/mailinglogger > > cheers, > > Chris > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From me+list/python at ixokai.io Mon Aug 22 17:56:07 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 14:56:07 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Mon, Aug 22, 2011 at 12:14 PM, Matthew Brett wrote: > Yes, sorry, I should have mentioned that I explored these kind of > variations. > > I think I see that there isn't an obvious way for del sys.modules['apkg'] > to know to delete or modify 'apkg.subpkg', because sys.modules is just a > dict. > > However, I could imagine the import machinery being able to recognize that > 'apkg.subpkg' is broken, and re-import it without error. > Is that reasonable? > Not really, no. Despite the fact that you can sorta do it, and that there's this "reload" function, Python doesn't really support reloading of modules / code. If you want to do it, you basically have to go out and _do_ it yourself. If you muck about in sys.modules, you need to do so completely. Python and the import stuff won't really do anything to help you (though it won't go out of its way to hinder you, either). Something like: def remove_module(name): for mod in sys.modules.keys(): if mod == name or name.startswith(name + "."): del sys.modules[mod] Then remove_module("apkg") may work for you. (Code above not tested at all, not even kinda) --Ix -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Mon Aug 22 18:46:36 2011 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Aug 2011 08:46:36 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: Message-ID: <20110822224636.GA5704@cskk.homeip.net> On 22Aug2011 04:29, Tomas Lid?n wrote: | On 22 Aug, 12:06, Cameron Simpson wrote: | > It would not surprise me if the order was related to the order a scan of | > the system interfaces yields information, and I would imagine that may | > be influenced by the order in which the interfaces were initialised. | > | > So getting the LAN first may merely be fortuitous. | > I wouldn't rely on it, especially if interfaces come and go. | | We did try to disable/enable the interfaces in different orders, but | always got the same return order from gethostbyname_ex(). So it looked | pretty stable (on that specific OS). There's been some testing on | Linux as well, but since this should be used in a general cross | platform tool we wanted to check the exact behaviour of the method. | | > What if you queried your routing table instead? Usually there's just one | > default route, and hopefully it would be configured to use the "best" | > interface. | | Hmm... perhaps. How would you do that? On UNIX systems (and, I think, also Windows systems) you'd run the command: netstat -rn or use the "route" command. (This avoids using operating system calls directly - the command will know what to do itself.) I seem to recall that Windows has the netstat command as well (possibly because, IIRC, they pulled in the BSD UNIX IP stack for their first IP implementation). Anyway, by popening the netstat command you can pull the "default" (or "0.0.0.0") route from its output. Then see if the interface listed there corresponds to what you need to know. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Then again, it's probably really because your average Australian doesn't give a shit about anything that doesn't increase the price of beer. - Murray Chapman From tim at johnsons-web.com Mon Aug 22 19:47:04 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 22 Aug 2011 15:47:04 -0800 Subject: Thoughts about documentation for non-python resource files Message-ID: <20110822234704.GD12101@johnsons-web.com> I'm looking for comments and/or URLs to discussions on this topic. I use my own MVC system. A component of this system generates documentation from python docstrings. Of course this system also comprises many non-python filetypes : css, html, txt, js, xml etc. Views, which are txt or html files can be handled by my system's built-in relationships between controllers and views. For other non-python files which are not found directly to controllers, css, js, html, xml all support comments and documentation can be (and is) build into the comments. Before I proceded and 'roll my own' protocol for generating documentations for these above-mention filetypes, I'd like to know if there is any such protocols being used already. Example : A pythonic way to generate documentations on a javascript file as well as its functions, objects etc. Any comments welcome. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From Yingjie.Lin at mssm.edu Mon Aug 22 20:17:47 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Mon, 22 Aug 2011 20:17:47 -0400 Subject: Help on instance of closeable_response in module Mechanize Message-ID: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> Hi Python users, I have a question about the instance of closeable_response in module Mechanize. from mechanize import ParseResponse, urlopen url = "http://wwwsearch.sourceforge.net/mechanize/example.html" r = urlopen(url) forms = ParseResponse(r, backwards_compat=False) html_lines = r.read() If I call ParseResponse() before r.read(), then lforms would be a list containing one form instance, and html_lines would be an empty string. If I call r.read() first, then html_lines would be the HTML source code of the page, but forms would be an empty list. Therefore, I have to open the url twice, once for each function, like this: r = urlopen(url) forms = ParseResponse(r, backwards_compat=False) r = urlopen(url) html_lines = r.read() I believe this shouldn't be necessary. What is the proper way of doing it? Thank you. - Yingjie From crebert at ucsd.edu Mon Aug 22 20:27:18 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Mon, 22 Aug 2011 17:27:18 -0700 Subject: Help on instance of closeable_response in module Mechanize In-Reply-To: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> References: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> Message-ID: On Mon, Aug 22, 2011 at 5:17 PM, Yingjie Lin wrote: > Hi Python users, > > I have a question about the instance of closeable_response in module Mechanize. > > ? ? ? ?from mechanize import ParseResponse, urlopen > ? ? ? ?url = "http://wwwsearch.sourceforge.net/mechanize/example.html" > ? ? ? ?r = urlopen(url) > ? ? ? ?forms = ParseResponse(r, backwards_compat=False) > ? ? ? ?html_lines = r.read() > > If I call ParseResponse() before r.read(), then lforms would be a list containing one form > instance, and html_lines would be an empty string. If I call r.read() first, then html_lines > would be the HTML source code of the page, but forms would be an empty list. > > Therefore, I have to open the url twice, once for each function, like this: > > ? ? ? ?r = urlopen(url) > ? ? ? ?forms = ParseResponse(r, backwards_compat=False) > ? ? ? ?r = urlopen(url) > ? ? ? ?html_lines = r.read() > > I believe this shouldn't be necessary. What is the proper way of doing it? Thank you. Untested speculation: from StringIO import StringIO r = urlopen(url) html = r.read() s = StringIO(html) forms = ParseResponse(s, backwards_compat=False) Cheers, Chris From research at johnohagan.com Mon Aug 22 20:55:26 2011 From: research at johnohagan.com (John O'Hagan) Date: Tue, 23 Aug 2011 10:55:26 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> Message-ID: <20110823105526.3032630855f69a716738095f@johnohagan.com> On Mon, 22 Aug 2011 23:08:50 +1000 John O'Hagan wrote: > On Mon, 22 Aug 2011 15:27:36 +1000 > Steven D'Aprano wrote: [..] > > Looks like a call for (semi-)automatic delegation! > > > > Try something like this: > > > > > > # Untested > > class MySeq(object): > > methods_to_delegate = ('__getitem__', '__len__', ...) > > pitches = ... # make sure pitches is defined > > def __getattr__(self, name): > > if name in self.__class__.methods_to_delegate: > > return getattr(self.pitches, name) > > return super(MySeq, object).__getattr__(self, name) > > # will likely raise AttributeError > [..] > > However, I don't understand what the super call is doing. If the method isn't delegated, shouldn't it just fall back to getattr(self, name)? On reading the __getattr__ docs properly, I see that AttributeError is what should generally happen. > Thanks and regards, > > John > From steve+comp.lang.python at pearwood.info Mon Aug 22 23:26:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 13:26:30 +1000 Subject: Adding modified methods from another class without subclassing References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> Message-ID: <4e531de6$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Aug 2011 10:55 am John O'Hagan wrote: >> > # Untested >> > class MySeq(object): >> > methods_to_delegate = ('__getitem__', '__len__', ...) >> > pitches = ... ?# make sure pitches is defined >> > def __getattr__(self, name): >> > if name in self.__class__.methods_to_delegate: >> > return getattr(self.pitches, name) >> > return super(MySeq, object).__getattr__(self, name) >> > # will likely raise AttributeError >> > [..] >> >> However, I don't understand what the super call is doing. If the method >> isn't delegated, shouldn't it just fall back to getattr(self, name)? > > On reading the __getattr__ docs properly, I see that AttributeError is > what should generally happen. Which is what the call to super will accomplish, but if the behaviour ever changes (including the error message given), you won't have to change your class. -- Steven From gnarlodious at gmail.com Tue Aug 23 00:12:49 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Aug 2011 21:12:49 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables References: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> Message-ID: <857a0816-108a-4add-b71f-d41593d2e83a@n35g2000yqf.googlegroups.com> On Aug 22, 9:39?am, Miki Tebeka wrote: > HTH Yes it helps, thank you! -- Gnarlie http://Gnarlodious.com From nagle at animats.com Tue Aug 23 00:54:58 2011 From: nagle at animats.com (John Nagle) Date: Mon, 22 Aug 2011 21:54:58 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: <4e5332c7$0$2177$742ec2ed@news.sonic.net> On 8/22/2011 11:51 AM, Matthew Brett wrote: > Hi, > > I recently ran into this behavior: > >>>> import sys import apkg.subpkg del sys.modules['apkg'] import >>>> apkg.subpkg as subpkg > Traceback (most recent call last): File "", line 1, > in AttributeError: 'module' object has no attribute 'subpkg' > > where 'apkg' and 'subpkg' comprise empty __init__.py files to > simplify the example. > > It appears then, that importing a subpackage, then deleting the > containing package from sys.modules, orphans the subpackage in an > unfixable state. > > I ran into this because the nose testing framework does exactly this > kind of thing when loading test modules, causing some very confusing > errors and failures. > > Is this behavior expected? It's undefined behavior. You're dealing with CPython implementation semantics, not Python language semantics. John Nagle From 1248283536 at qq.com Tue Aug 23 01:10:10 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 23 Aug 2011 13:10:10 +0800 Subject: how to write the lambda expression in my tkinter ? Message-ID: from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(event,entries): for entry in entries: print 'Input => "%s"' % entry.get() # get text print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) # make a new row lab = Label(row, width=5, text=field) # add label, entry ent = Entry(row) row.pack(side=TOP, fill=X) # pack row on top lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) # grow horizontal entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', lambda event,entries=ents: fetch(event,entries)) Button(root, text='Fetch', command= lambda event:fetch(event,entries)).pack(side=LEFT) root.mainloop() when you run it ,press enter ,you can get the value in the entry;when you click the Button(Fetch),there is a wrong output ,i can't revise it,i know it is the 26 can't run ,how to fix it ? Button(root, text='Fetch', command= lambda event:fetch(event,entries)).pack(side=LEFT) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Aug 23 02:52:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Aug 2011 23:52:05 -0700 Subject: how to write the lambda expression in my tkinter ? In-Reply-To: References: Message-ID: 2011/8/22 ???? <1248283536 at qq.com>: > from?Tkinter?import?* > fields?=?'Name',?'Job',?'Pay' > > def?fetch(event,entries): > ???for?entry?in?entries: > ???????print?'Input?=>?"%s"'?%?entry.get()???????#?get?text > ???????print??event.widget > > > def?makeform(root,?fields): > ???entries?=?[] > ???for?field?in?fields: > ???????row?=?Frame(root)???????????????????????????#?make?a?new?row > ???????lab?=?Label(row,?width=5,?text=field)???????#?add?label,?entry > ???????ent?=?Entry(row) > ???????row.pack(side=TOP,?fill=X)??????????????????#?pack?row?on?top > ???????lab.pack(side=LEFT) > ???????ent.pack(side=RIGHT,?expand=YES,?fill=X)????#?grow?horizontal > ???????entries.append(ent) > ???return?entries > > if?__name__?==?'__main__': > ???root?=?Tk() > ???ents?=?makeform(root,?fields) > ???root.bind('',?lambda?event,entries=ents:?fetch(event,entries)) > ???Button(root,?text='Fetch',?command=?lambda?event:fetch(event,entries)).pack(side=LEFT) > ???root.mainloop() > > when you run it ,press enter ,you can get the value in the entry;when you > click the? Button(Fetch),there is a wrong output ,i can't revise it,i know > it is the? 26? can't run ,how to fix it ? > > Button(root,?text='Fetch',?command=?lambda?event:fetch(event,entries)).pack(side=LEFT) Problem 1: `entries` is undefined within the scope of the lambda; it's not a parameter of the lambda, nor is it defined in any outer scope that encloses the lambda. This will lead to a NameError. `ents` is / would be within scope however...(*wink*) Problem 2: Based on quick experimentation, Tkinter does not pass `command` any arguments, yet your lambda has 1 required argument (namely, `event`). This will cause a run-time error when the lambda is called. That should be enough to get you started. Cheers, Chris -- http://rebertia.com From no.email at nospam.invalid Tue Aug 23 03:21:45 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Aug 2011 00:21:45 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Chris Angelico writes: > Ehh, granted. Definitely a case of "should". But certainly, there > won't be an infinite number of new exceptions invented; Right, the number is finite, but the issue is that it's unknown. It's like never knowing whether you've fixed the last bug in a program. From steve+comp.lang.python at pearwood.info Tue Aug 23 03:25:22 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 17:25:22 +1000 Subject: Adding modified methods from another class without subclassing References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote: > On Mon, 22 Aug 2011 15:27:36 +1000 > Steven D'Aprano wrote: [...] >> # Untested >> class MySeq(object): >> methods_to_delegate = ('__getitem__', '__len__', ...) >> pitches = ... # make sure pitches is defined >> def __getattr__(self, name): >> if name in self.__class__.methods_to_delegate: >> return getattr(self.pitches, name) >> return super(MySeq, object).__getattr__(self, name) >> # will likely raise AttributeError > > Thanks, this looks promising. I didn't know about __getattr__ or > delegation. This example doesn't seem to work as is for special methods > beginning with "__" (e.g.: "TypeError: object of type 'MyList' has no > len()"). It seems that __getattr__ is not called for special methods. Ah yes, that would be a problem. This recipe may help. http://code.activestate.com/recipes/252151-generalized-delegates-and-proxies/ > Also, it doesn't immediately suggest to me a way of modifying method calls > (maybe __setattr__?). What do you mean, "modifying method calls"? __getattr__ doesn't know whether the method retrieved modifies the instance or not. That's irrelevant. __setattr__ is called when you say instance.attribute = value > But it's certainly a neater way to get methods to > operate on the attribute. I'm looking into it, and delegation generally. > > However, I don't understand what the super call is doing. If the method > isn't delegated, shouldn't it just fall back to getattr(self, name)? getattr(self, name) will just call self.__getattr__(name) again, which will call getattr, and so on... leading to RecursionError. -- Steven From rosuav at gmail.com Tue Aug 23 04:24:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 09:24:39 +0100 Subject: CGI input: Filter dict.update() unwanted variables In-Reply-To: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> References: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, Aug 22, 2011 at 4:39 PM, Miki Tebeka wrote: > You can check if there is a "non-allowed variable" and then return HTTP error. > if set(form) - set(allowedVariables): > ? ?print('Status: 406\n\n') > ? ?raise SystemExit() > I'd be disinclined to do this; ignore unrecognized query variables, but don't throw back an error. Sometimes it's convenient to let the browser send a "junk header" that the server will ignore - helps with integration with other systems. As long as you can be sure that the script won't do the wrong thing, it should be fine to have an extra bit of GET/POST data. ChrisA From rosuav at gmail.com Tue Aug 23 04:26:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 09:26:11 +0100 Subject: try... except with unknown error types In-Reply-To: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Aug 23, 2011 at 8:21 AM, Paul Rubin wrote: > Chris Angelico writes: >> Ehh, granted. Definitely a case of "should". But certainly, there >> won't be an infinite number of new exceptions invented; > > Right, the number is finite, but the issue is that it's unknown. ?It's > like never knowing whether you've fixed the last bug in a program. > Yeah. Oh, I know when I've fixed the last bug in a program. It's the day the program gets deleted. Until then? Nope. ChrisA From mail at timgolden.me.uk Tue Aug 23 04:26:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Aug 2011 09:26:38 +0100 Subject: Setting the time in Win7 In-Reply-To: <2011082213422850073-bob@passcalnmtedu> References: <2011082210352016807-bob@passcalnmtedu> <2011082213422850073-bob@passcalnmtedu> Message-ID: <4E53643E.7030307@timgolden.me.uk> On 22/08/2011 20:42, Bob Greschke wrote: > Several people have been hacking away on this computer we are testing > on, so I'm not sure what settings -- other than all of them -- have been > messed with, but popen("time ...") seems to work, but system("time ...") > does not. I'm going to restore the machine to its original state and see > what happens. Hoping that this helps: you can programatically set the system time from within Python by using the pywin32 modules, or ctypes if you prefer. The code below works for an already-elevated command prompt by enabling the SystemTime privilege and (crudely) moving the time forward by five minutes by way of showing what's happening before resetting it back. I've commented out the actual SetSystemTime calls just in case anyone cuts-and-pastes indjudiciously. Ideally you should disable the privilege afterwards but I've left that out so as not to clutter the example. import os, sys import win32api import win32security import ntsecuritycon hToken = win32security.OpenProcessToken ( win32api.GetCurrentProcess (), ntsecuritycon.MAXIMUM_ALLOWED ) time_privilege = win32security.LookupPrivilegeValue (None, win32security.SE_SYSTEMTIME_NAME) win32security.AdjustTokenPrivileges ( hToken, 0, [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)] ) current_time = win32api.GetSystemTime () print "Current time:", current_time new_time = list (current_time) new_time[5] += 5 ## print win32api.SetSystemTime (*new_time) print "Current time:", win32api.GetSystemTime () ## print win32api.SetSystemTime (*current_time) print "Current time:", win32api.GetSystemTime () TJG From steve+comp.lang.python at pearwood.info Tue Aug 23 04:33:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 18:33:06 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e5365c2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 04:26 am Paul Rubin wrote: > The Erlang approach is tempting. Don't catch the exception at all--just > let the process crash, and restart it. But that's a more heavyweight > operation in Python. You might be interested in this paper: http://usenix.org/events/hotos03/tech/full_papers/candea/candea.pdf -- Steven From gheskett at wdtv.com Tue Aug 23 04:43:18 2011 From: gheskett at wdtv.com (gene heskett) Date: Tue, 23 Aug 2011 04:43:18 -0400 Subject: try... except with unknown error types In-Reply-To: References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: <201108230443.19007.gheskett@wdtv.com> On Tuesday, August 23, 2011 04:42:04 AM Chris Angelico did opine: > On Tue, Aug 23, 2011 at 8:21 AM, Paul Rubin wrote: > > Chris Angelico writes: > >> Ehh, granted. Definitely a case of "should". But certainly, there > >> won't be an infinite number of new exceptions invented; > > > > Right, the number is finite, but the issue is that it's unknown. It's > > like never knowing whether you've fixed the last bug in a program. > > Yeah. Oh, I know when I've fixed the last bug in a program. It's the > day the program gets deleted. Until then? Nope. > > ChrisA OTOH, ChrisA, I have it on good authority that no program is ever finished, until someone shoots the programmer. :) Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Practice is the best of all instructors. -- Publilius From rosuav at gmail.com Tue Aug 23 05:07:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 10:07:28 +0100 Subject: try... except with unknown error types In-Reply-To: <201108230443.19007.gheskett@wdtv.com> References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> <201108230443.19007.gheskett@wdtv.com> Message-ID: On Tue, Aug 23, 2011 at 9:43 AM, gene heskett wrote: > OTOH, ChrisA, I have it on good authority that no program is ever finished, > until someone shoots the programmer. ?:) > Correct, although I've had projects that were killed by changes to requirements - such as my fantastic system for writing device drivers that leveraged DEBUG.EXE to translate assembly code into machine code, and a REXX script to handle jump labels and such. That project was quite thoroughly finished on the day that I met nasm :) But that's quite off-topic. ChrisA From wujackjp at gmail.com Tue Aug 23 05:48:00 2011 From: wujackjp at gmail.com (Jack) Date: Tue, 23 Aug 2011 02:48:00 -0700 (PDT) Subject: Why __slots__ slows down attribute access? Message-ID: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> People have illusion that it is faster to visit the attribute defined by __slots__ . http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be That is wrong. The following tests show it is slower. __slots__ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. It makes a little bit slower. So __slots__ just saves memory space by preventing creation of __dict__ and __weakref__ on each instance, while sacrifice performance and inheritance flexibility. http://groups.google.com/group/comp.lang.python/msg/6623e8b94b6d6934 D:\>d:\python-v3.1.2\python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.237 usec per loop D:\>d:\python-v3.1.2\python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5 inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.214 usec per loop D:\>d:\python-v2.6.4\python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.26 usec per loop D:\>d:\python-v2.6.4\python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.217 usec per loop From __peter__ at web.de Tue Aug 23 06:26:50 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Aug 2011 12:26:50 +0200 Subject: Why __slots__ slows down attribute access? References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ . > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. Not so fast. Here's what I get (python2.6.4, 64 bit): $ python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.324 usec per loop $ python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.393 usec per loop Now what? From johnjohn.tedro at gmail.com Tue Aug 23 06:57:05 2011 From: johnjohn.tedro at gmail.com (John-John Tedro) Date: Tue, 23 Aug 2011 12:57:05 +0200 Subject: Why __slots__ slows down attribute access? In-Reply-To: References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: On Tue, Aug 23, 2011 at 12:26 PM, Peter Otten <__peter__ at web.de> wrote: > Jack wrote: > > > People have illusion that it is faster to visit the attribute defined > > by __slots__ . > > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > > > That is wrong. The following tests show it is slower. > > Not so fast. Here's what I get (python2.6.4, 64 bit): > > $ python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s > "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.324 usec per loop > > $ python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; > inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.393 usec per loop > > Now what? > > -- > http://mail.python.org/mailman/listinfo/python-list > This is what I get on a 64 bit Linux 2.6.39 script: for v in 2.6 2.7 3.2; do python$v --version echo -n "(slots) = "; python$v -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7"; echo -n "(regular) = "; python$v -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7"; done output: Python 2.6.5 (slots) = 1000000 loops, best of 3: 0.219 usec per loop (regular) = 1000000 loops, best of 3: 0.231 usec per loop Python 2.7.2 (slots) = 1000000 loops, best of 3: 0.244 usec per loop (regular) = 1000000 loops, best of 3: 0.285 usec per loop Python 3.2 (slots) = 1000000 loops, best of 3: 0.193 usec per loop (regular) = 1000000 loops, best of 3: 0.224 usec per loop -- John-John Tedro -------------- next part -------------- An HTML attachment was scrubbed... URL: From askutt at gmail.com Tue Aug 23 07:26:10 2011 From: askutt at gmail.com (Adam Skutt) Date: Tue, 23 Aug 2011 04:26:10 -0700 (PDT) Subject: Why __slots__ slows down attribute access? References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: <920e68e2-58a6-4022-a333-7bd11f7295d7@h34g2000vbr.googlegroups.com> On Aug 23, 5:48?am, Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ .http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. No, they don't really show anything. The default clocks used by timeit lack the resolution to measure such things accurately; you're measuring various noise sources on your system. The range of 100 trials of 1million iterations on my system is 70.3 ms, which is 70ns when divided by a million, which is about the size of the difference you show. A 70ns average difference between iterations is trivially attributable to noise on a modern machine. Run enough trials or just wait for the moon to move a bit, and I wouldn't be terribly surprised if you got difference results. Rebooting your machine might be enough to do it. Adam > D:\>d:\python-v3.1.2\python ?-mtimeit -s "class A(object): __slots__ = > ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.237 usec per loop > > D:\>d:\python-v3.1.2\python ?-mtimeit -s "class A(object): pass" -s > "inst = A()" "inst.a=5 inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.214 usec per loop > > D:\>d:\python-v2.6.4\python ?-mtimeit -s "class A(object): __slots__ = > ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.26 usec per loop > > D:\>d:\python-v2.6.4\python ?-mtimeit -s "class A(object): pass" -s > "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.217 usec per loop From thinke365 at gmail.com Tue Aug 23 07:59:21 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 23 Aug 2011 19:59:21 +0800 Subject: is there any principle when writing python function Message-ID: i have heard that function invocation in python is expensive, but make lots of functions are a good design habit in many other languages, so is there any principle when writing python function? for example, how many lines should form a function? From __peter__ at web.de Tue Aug 23 08:20:50 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Aug 2011 14:20:50 +0200 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Five ;) From mwilson at the-wire.com Tue Aug 23 08:53:49 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 23 Aug 2011 08:53:49 -0400 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? It's hard to discuss in the abstract. A function should perform a recognizable step in solving the program's problem. If you prepared to write your program by describing each of several operations the program would have to perform, then you might go on to plan a function for each of the described operations. The high-level functions can then be analyzed, and will probably lead to functions of their own. Test-driven development encourages smaller functions that give you a better granularity of testing. Even so, the testable functions should each perform one meaningful step of a more general problem. > for example, how many lines should form a function? Maybe as few as one. def increase (x, a): return x+a is kind of stupid, but a more complicated line def expand_template (bitwidth, defs): '''Turn Run-Length-Encoded list into bits.''' return np.array (sum (([bit]*(count*bitwidth) for count, bit in defs), []), np.int8) is the epitome of intelligence. I wrote it myself. Even increase might be useful: def increase (x, a): return x + a * application_dependent_quantity `increase` has become a meaningful operation in the imaginary application we're discussing. For an upper bound, it's harder to say. If you read to the end of a function and can't remember how it started, or what it did in between, it's too big. If you're reading on your favourite screen, and the end and the beginning are more than one page-scroll apart, it might be too big. If it's too big, factoring it into sub-steps and making functions of some of those sub-steps is the fix. Mel. From roy at panix.com Tue Aug 23 08:55:19 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 08:55:19 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Enough lines to do what the function needs to do, but no more. Seriously, break up your program into functions based on logical groupings, and whatever makes your code easiest to understand. When you're all done, if your program is too slow, run it under the profiler. Use the profiling results to indicate which parts need improvement. It's very unlikely that function call overhead will be a significant issue. Don't worry about stuff like that unless the profiler shows its a bottleneck. Don't try to guess what's slow. My guesses are almost always wrong. Yours will be too. If your program runs fast enough as it is, don't even bother with the profiler. Be happy that you've got something useful and move on to the next thing you've got to do. From roy at panix.com Tue Aug 23 08:56:57 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 08:56:57 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > smith jack wrote: > > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example, how many lines should form a function? > > Five ;) Five is right out. From ulrich.eckhardt at dominolaser.com Tue Aug 23 09:00:47 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Aug 2011 15:00:47 +0200 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Don't compromise the design and clarity of your code just because you heard some rumors about performance. Also, for any performance question, please consult a profiler. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From yasar11732 at gmail.com Tue Aug 23 09:20:34 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Tue, 23 Aug 2011 16:20:34 +0300 Subject: Fwd: is there any principle when writing python function In-Reply-To: References: Message-ID: I accidentally sent below mail only to roy. Resending to groups. ---------- Y?nlendirilmi? ileti ---------- Kimden: Ya?ar Arabac? Tarih: 23 A?ustos 2011 16:19 Konu: Re: is there any principle when writing python function Kime: Roy Smith I don't see myself a good python programmer or anything, but just saying what I do. I create function for each of the biggest code blocks that is going to be executed more then once. 2011/8/23 Roy Smith > In article , Peter Otten <__peter__ at web.de> > wrote: > > > smith jack wrote: > > > > > i have heard that function invocation in python is expensive, but make > > > lots of functions are a good design habit in many other languages, so > > > is there any principle when writing python function? > > > for example, how many lines should form a function? > > > > Five ;) > > Five is right out. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://yasar.serveblog.net/ -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at tobiah.org Tue Aug 23 09:27:39 2011 From: toby at tobiah.org (Tobiah) Date: Tue, 23 Aug 2011 06:27:39 -0700 Subject: Hiding token information from users Message-ID: I am making QR codes that cell phone users scan in order to make use of an application. Part of the information is a token that needs to be passed on to the server, but I'd rather not allow a person examining the QR code to be able to see that plain bit of information. I'd like to scramble up the token so that the result: 1) takes up the same (near, or less) number of characters as the original token. 2) They key can be derived from the input, and vise versa. 3) The result is alphanumeric. 4) When one character changes in the source, many characters are likely to change in the result. So if my token is: mytoken2011 The result might be something like: xm23ffz4uuw Then mytoken2012 might yield something very different: d8ru3jdhvhd I was thinking of just stringing up all letters and numbers into a 'wheel' and doing an 18 char rotation on the chars in the token, but that fails #4. The secret is not like the key to Fort Knox. We would rather not have the plain token out there, as it's internal business information, but we don't have to protect the information at all costs. Just making it really inconvenient to extract is fine. Thanks, Tobiah From fzadrozny at appcelerator.com Tue Aug 23 09:36:23 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Tue, 23 Aug 2011 10:36:23 -0300 Subject: PyDev 2.2.2 Released Message-ID: Hi All, PyDev 2.2.2 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- **IPython / Interactive console** * IPython (0.10 or 0.11) is now used as the interactive console backend if PyDev can detect it in the PYTHONPATH. * While waiting for the output of a command, intermediary results are printed in the console. * ANSI color codes are supported in the interactive console. **Code Analysis** * Reporting variables that shadow builtins as warnings. * Fixed issue where __dict__ was not found. **Code completion** * Aliases have a better treatment (i.e.: unittest.assertEqual will show the proper type/parameters). * Improved support for analyzing function builtins where the return type is known (i.e.: open, str.split, etc). **Debugger** * When doing a remote debug session, if the files cannot be found in the local filesystem, PyDev will ask for files in the remote debugger. **Editor** * Files without extension that have a python shebang (e.g.: #!/usr/bin/python in the first line) are automatically opened with the PyDev editor (in the PyDev Package Explorer). **Django** * When the shell command is used in the django custom commands, PyDev no longer uses 100% cpu while it doesn't complete. **Others** * Fixed issue where the * operator was not properly formatted. * When the quick outline dialog is deactivated, it's closed. * Fixed heuristic for finding position for local import. * Fixed compare editor issue with Eclipse 3.2. * Fixed integration issue with latest PyLint. * Fixed deadlock issue on app engine manage window. * More options added to configure the automatic deletion of .pyc files (delete always, never delete, delete only on .py delete). What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From lists at cheimes.de Tue Aug 23 09:40:59 2011 From: lists at cheimes.de (Christian Heimes) Date: Tue, 23 Aug 2011 15:40:59 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> Message-ID: Am 22.08.2011 15:07, schrieb johnny.venter: > Chris, thank you for the information. Focusing on Active Directory, I reviewed the info at the following site: http://technet.microsoft.com/en-us/library/cc961766.aspx > > Based on this, I need to find a module that implements the LDAP APIs. By default, it does not appear that Python can speak this language, I am using version 2.6.1. The module I found is Python-LDAP (http://www.python-ldap.org/). > > Does anyone have experience using this? LDAP is a protocol, not a language. You are right, LDAP isn't part of the Python standard library. The python-ldap extensions works well with Active Directory. I've used it to write an authentication and authorisation layer for our application. A word of warning: LDAP isn't trivial and AD has its quirks, too. It's going to take you a while to understand its concepts. Christian From rvince99 at gmail.com Tue Aug 23 09:45:17 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 23 Aug 2011 06:45:17 -0700 (PDT) Subject: Directly executing from an egg Message-ID: I have created an egg file with one source file in it, hello.py (I just want to go through the entire uild/install/execute cycle using egg files). I create it fine, and now I want to execute the eg file directly (i.e. run it without unpacking or easy_install'ing it). So when I invoke it from the directory the egg is in with: python 'hello-1.0-py2.6.egg I get: can't find '__main__.py' in 'hello-1.0-py2.6.egg' How do I remedy this? I've looked through the docs but it seems ambiguous on this point to me. Below is the setup section from my setup.py which I used to create this egg. Thank you, RVince setup( name='hello', version='1.0', description='', author='', author_email='', install_requires=[ "SQLAlchemy>=0.4", "psycopg2", ], zip_safe=False, entry_points=""" [hello] hello = hello:hello_app """, ) From thinke365 at gmail.com Tue Aug 23 10:03:29 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 23 Aug 2011 22:03:29 +0800 Subject: why i cannot invoke python script using command line? Message-ID: but i can invoke it in eclipse, what's wrong? the script refered to another python script in eclipse project. f:\project\src\a.py f:\project\src\lib\b.py there is such lines in a.py from lib import b i can invoke a.py very well in eclipse but failed when using python f:\project\src\a.py, what's wrong? (the error msg shows a.py cannot find b.py) , what should i do in order to run a.py using command line? From Yingjie.Lin at mssm.edu Tue Aug 23 10:21:09 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Tue, 23 Aug 2011 10:21:09 -0400 Subject: Methods on file-like objects can only used once on one object? Message-ID: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> Hi Python users, I just realize that my post yesterday shouldn't be specifically for mechanize. It should be a general question for file-like objects. >>> f = open('my_file.txt') >>> print f.readlines() ( prints a list of strings >>> print f.readlines() [] There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: f.readlines() f.read() ... What should I do? Thank you. - Yingjie From gordon at panix.com Tue Aug 23 10:21:29 2011 From: gordon at panix.com (John Gordon) Date: Tue, 23 Aug 2011 14:21:29 +0000 (UTC) Subject: why i cannot invoke python script using command line? References: Message-ID: In smith jack writes: > but i can invoke it in eclipse, what's wrong? > the script refered to another python script in eclipse project. > f:\project\src\a.py > f:\project\src\lib\b.py > there is such lines in a.py > from lib import b > i can invoke a.py very well in eclipse > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? What is your PYTHONPATH environment variable setting? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Tue Aug 23 10:25:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 15:25:56 +0100 Subject: why i cannot invoke python script using command line? In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 3:03 PM, smith jack wrote: > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? > >From the sound of things, your working directory is not f:\project\src. I recommend you either: 1) Change to that directory first: cd f:\project\src python a.py Or 2) Add to your import path inside a.py: import sys sys.path.append(r"f:\project\src") Either method should solve the problem. Chris Angelico From ian.g.kelly at gmail.com Tue Aug 23 11:08:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Aug 2011 09:08:00 -0600 Subject: Hiding token information from users In-Reply-To: References: Message-ID: How many of these codes do you need, and do they only need to be decrypted at a central server? You might be able to just create random strings of whatever form you want and associate them with the tokens in a database. Then they will be completely opaque. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peterirbizon at gmail.com Tue Aug 23 11:08:30 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Tue, 23 Aug 2011 17:08:30 +0200 Subject: incorporate png/ico to exe and use it in application Message-ID: hello, I am zsing py2exe to compile exe files. I would like to incorporate png and icon file into exe and then use it during program run (to show it in about dialog and system tray). How can I do it? For example now I use self.staticon.set_from_file(os.path.join(module_path(), "icon.ico")) but I would like to prevent user from changeing this icon. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Aug 23 11:22:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:22:19 +1000 Subject: is there any principle when writing python function References: Message-ID: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> smith jack wrote: > i have heard that function invocation in python is expensive, It's expensive, but not *that* expensive. Compare: [steve at sylar ~]$ python3.2 -m timeit 'x = "abc".upper()' 1000000 loops, best of 3: 0.31 usec per loop [steve at sylar ~]$ python3.2 -m timeit -s 'def f(): return "abc".upper()' 'f()' 1000000 loops, best of 3: 0.53 usec per loop So the function call is nearly as expensive as this (very simple!) sample code. But in absolute terms, that's not very expensive at all. If we make the code more expensive: [steve at sylar ~]$ python3.2 -m timeit '("abc"*1000)[2:995].upper().lower()' 10000 loops, best of 3: 32.3 usec per loop [steve at sylar ~]$ python3.2 -m timeit -s 'def f(): return ("abc"*1000 [2:995].upper().lower()' 'f()' 10000 loops, best of 3: 33.9 usec per loop the function call overhead becomes trivial. Cases where function call overhead is significant are rare. Not vanishingly rare, but rare enough that you shouldn't worry about them. > but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? About as long as a piece of string. A more serious answer: it should be exactly as long as needed to do the smallest amount of work that makes up one action, and no longer or shorter. If you want to maximise the programmer's efficiency, a single function should be short enough to keep the whole thing in your short-term memory at once. This means it should consist of no more than seven, plus or minus two, chunks of code. A chunk may be a single line, or a few lines that together make up a unit, or if the lines are particularly complex, *less* than a line. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two http://www.codinghorror.com/blog/2006/08/the-magical-number-seven-plus-or-minus-two.html (Don't be put off by the use of the term "magical" -- there's nothing literally magical about this. It's just a side-effect of the way human cognition works.) Anything longer than 7?2 chunks, and you will find yourself having to scroll backwards and forwards through the function, swapping information into your short-term memory, in order to understand it. Even 7?2 is probably excessive: I find that I'm most comfortable with functions that perform 4?1 chunks of work. An example from one of my classes: def find(self, prefix): """Find the item that matches prefix.""" prefix = prefix.lower() # Chunk #1 menu = self._cleaned_menu # Chunk #2 for i,s in enumerate(menu, 1): # Chunk #3 if s.lower().startswith(prefix): return i return None # Chunk #4 So that's three one-line chunks and one three-line chunk. -- Steven From darnold992000 at yahoo.com Tue Aug 23 11:24:11 2011 From: darnold992000 at yahoo.com (darnold) Date: Tue, 23 Aug 2011 08:24:11 -0700 (PDT) Subject: Methods on file-like objects can only used once on one object? References: Message-ID: On Aug 23, 9:21?am, Yingjie Lin wrote: > Hi Python users, > > I just realize that my post yesterday shouldn't be specifically for mechanize. It should be a general question for file-like objects. > > >>> f = open('my_file.txt') > >>> print f.readlines() > > ? ? ? ? ( prints a list of strings>>> print f.readlines() > > [] > > There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: > > f.readlines() > f.read() > ... > > What should I do? Thank you. > > - Yingjie Each of those calls consumes the entire file, leaving the file pointer at end-of-file. to reset the file pointer back to the beginning of the file and enable re-reading, use f.seek(0) . From steve+comp.lang.python at pearwood.info Tue Aug 23 11:25:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:25:06 +1000 Subject: Methods on file-like objects can only used once on one object? References: Message-ID: <4e53c651$0$29996$c3e8da3$5496439d@news.astraweb.com> Yingjie Lin wrote: > Hi Python users, > > I just realize that my post yesterday shouldn't be specifically for > mechanize. It should be a general question for file-like objects. > >>>> f = open('my_file.txt') >>>> print f.readlines() > ( prints a list of strings >>>> print f.readlines() > [] Once you've read the file, the file pointer is now at the end of the file. To go back to the beginning of the file and read it again, you have to use the seek method: f.seek(0) But better is to not read the file twice: f = open('my_file.txt') lines = f.readlines() print lines print lines print lines print lines f.close() There's no need to read the lines again unless you expect that the file has changed. -- Steven From paul at subsignal.org Tue Aug 23 11:28:11 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Tue, 23 Aug 2011 17:28:11 +0200 Subject: Methods on file-like objects can only used once on one object? In-Reply-To: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> References: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> Message-ID: Am 23.08.2011 16:21, schrieb Yingjie Lin: > Hi Python users, [snip] > There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: > > f.readlines() > f.read() > ... > > What should I do? Thank you. use f.seek(0) between calls. The python documentation will educate you about the details. hth Paul From eric.lemings at gmail.com Tue Aug 23 11:29:58 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 08:29:58 -0700 (PDT) Subject: Windows No-Install Distribution? Message-ID: Hi, I would like to create/find a Python 3.x distribution that can be redeployed simply by copying a directory of required files; i.e. without the need for actually "installing" an MSI, modifying Windows registry entries, etc. First of all, will Python even work on Windows simply by copying files from one system to another? If so, does such a "no-install" distribution already exist? If not, what are the minimum set of Python 3.x files from a standard Windows Python installation required for proper/normal operation? Thanks, Eric. From redcat at streemit.net Tue Aug 23 11:31:48 2011 From: redcat at streemit.net (Redcat) Date: 23 Aug 2011 15:31:48 GMT Subject: Windows No-Install Distribution? References: Message-ID: <9bhvf4F5glU1@mid.individual.net> I haven't tried it myself yet, but might http://www.portablepython.com/ be what you're looking for? From steve+comp.lang.python at pearwood.info Tue Aug 23 11:34:26 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:34:26 +1000 Subject: why i cannot invoke python script using command line? References: Message-ID: <4e53c882$0$29986$c3e8da3$5496439d@news.astraweb.com> smith jack wrote: > but i can invoke it in eclipse, what's wrong? > the script refered to another python script in eclipse project. > > f:\project\src\a.py > f:\project\src\lib\b.py > > there is such lines in a.py > from lib import b > > i can invoke a.py very well in eclipse > > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? The import statement doesn't search the entire hard drive. It only searches the places in sys.path. You can modify sys.path either programmatically, or by adding things to the environment variable PYTHONPATH. Eclipse may be modifying the path so that it works in Eclipse. My recommendation is to either: (1) Use a flatter layout, like: f:\project\src\a.py f:\project\src\b.py and cd into f:\project\src\ before executing python a.py OR (2) learn how to use packages, and put a and b into a package; OR (3) Inside script a.py, add this to the start of the file: import os import sys import __main__ location = os.path.split(__main__.__file__)[0] location = os.path.join(location, 'lib') sys.path.append(location) -- Steven From toby at tobiah.org Tue Aug 23 11:35:51 2011 From: toby at tobiah.org (Tobiah) Date: Tue, 23 Aug 2011 08:35:51 -0700 Subject: Hiding token information from users In-Reply-To: References: Message-ID: <4E53C8D7.3040606@tobiah.org> On 08/23/2011 08:08 AM, Ian Kelly wrote: > How many of these codes do you need, and do they only need to be > decrypted at a central server? You might be able to just create random > strings of whatever form you want and associate them with the tokens in > a database. Then they will be completely opaque. > The tokens have a year portion that increments each year, and the base portion of the token will be created newly in accordance with new accounts that we take on. I really need some sort of algorithm that will let me take an unknown string and generate the encrypted bit on the fly. Thanks, Tobiah From invalid at invalid.invalid Tue Aug 23 11:35:56 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Aug 2011 15:35:56 +0000 (UTC) Subject: Methods on file-like objects can only used once on one object? References: <4e53c651$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-23, Steven D'Aprano wrote: > Yingjie Lin wrote: > >> Hi Python users, >> >> I just realize that my post yesterday shouldn't be specifically for >> mechanize. It should be a general question for file-like objects. >> >>>>> f = open('my_file.txt') >>>>> print f.readlines() >> ( prints a list of strings >>>>> print f.readlines() >> [] > > Once you've read the file, the file pointer is now at the end of the file. > To go back to the beginning of the file and read it again, you have to use > the seek method: > > f.seek(0) It's too bad Python doesn't support the f.rewind() spelling for that operation. Rewinding disk files always made me smile... -- Grant Edwards grant.b.edwards Yow! Did I say I was at a sardine? Or a bus??? gmail.com From bob at passcal.nmt.edu Tue Aug 23 11:49:34 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 23 Aug 2011 09:49:34 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> <2011082213422850073-bob@passcalnmtedu> Message-ID: <2011082309493416807-bob@passcalnmtedu> On 2011-08-23 02:26:38 -0600, Tim Golden said: > On 22/08/2011 20:42, Bob Greschke wrote: >> Several people have been hacking away on this computer we are testing >> on, so I'm not sure what settings -- other than all of them -- have been >> messed with, but popen("time ...") seems to work, but system("time ...") >> does not. I'm going to restore the machine to its original state and see >> what happens. > > Hoping that this helps: you can programatically set the system time > from within Python by using the pywin32 modules, or ctypes if you > prefer. The code below works for an already-elevated command prompt > by enabling the SystemTime privilege and (crudely) moving the time > forward by five minutes by way of showing what's happening before > resetting it back. > > I've commented out the actual SetSystemTime calls just in case anyone > cuts-and-pastes indjudiciously. Ideally you should disable the > privilege afterwards but I've left that out so as not to clutter > the example. > > > import os, sys > > import win32api > import win32security > import ntsecuritycon > > hToken = win32security.OpenProcessToken ( > win32api.GetCurrentProcess (), > ntsecuritycon.MAXIMUM_ALLOWED > ) > time_privilege = win32security.LookupPrivilegeValue (None, > win32security.SE_SYSTEMTIME_NAME) > win32security.AdjustTokenPrivileges ( > hToken, 0, > [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)] > ) > > current_time = win32api.GetSystemTime () > print "Current time:", current_time > new_time = list (current_time) > new_time[5] += 5 > ## print win32api.SetSystemTime (*new_time) > print "Current time:", win32api.GetSystemTime () > ## print win32api.SetSystemTime (*current_time) > print "Current time:", win32api.GetSystemTime () > > > > TJG Oooo. Now I can be dangerous. We kinda also solved the whole thing for us (just a few minutes ago) by checking the checkbutton "Run as administrator" in the Properties, Compatibility tab, for python.exe and pythonw.exe. The account is an Administrator, so it's OK for this. I thought there must be a way through pywin32, but I don't know much of anything about Windows API calls. I have a Windows Programming book collecting dust somewhere... Thanks! Bob From peterirbizon at gmail.com Tue Aug 23 11:52:36 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Tue, 23 Aug 2011 17:52:36 +0200 Subject: aboutdialog space between program name/version and logo Message-ID: Hello, please how can i set space between program name/version and logo in this code? thanks about = gtk.AboutDialog() about.set_program_name("name") about.set_version("0.0.1") about.set_logo(gtk.gdk.pixbuf_new_from_file("file.png")) -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Tue Aug 23 11:59:23 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 23 Aug 2011 10:59:23 -0500 Subject: Windows No-Install Distribution? In-Reply-To: References: Message-ID: <4E53CE5B.3040202@gmail.com> On 2011.08.23 10:29 AM, Eric Lemings wrote: > Hi, > > I would like to create/find a Python 3.x distribution that can be > redeployed simply by copying a directory of required files; i.e. > without the need for actually "installing" an MSI, modifying Windows > registry entries, etc. First of all, will Python even work on Windows > simply by copying files from one system to another? If so, does such > a "no-install" distribution already exist? If not, what are the > minimum set of Python 3.x files from a standard Windows Python > installation required for proper/normal operation? I unpacked the 32-bit version of CPython 3.2 from its installer into a folder and it seems to work. I haven't done any real testing, but it works for me (mainly I just need to have the files needed to build 32-bit frozen binaries with cx_Freeze). -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From rvince99 at gmail.com Tue Aug 23 12:14:06 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 23 Aug 2011 09:14:06 -0700 (PDT) Subject: Execute a method in a file in an egg Message-ID: Is there a way to do this from the command line? Thanks. From roy at panix.com Tue Aug 23 12:29:56 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 09:29:56 -0700 (PDT) Subject: truncating strings Message-ID: I want to log a string but only the first bunch of it, and add "..." to the end if it got truncated. This certainly works: log_message = message if len(log_message) >= 50: log_message = log_message[:50] + '...' logger.error("FAILED: '%s', '%s', %s, %s" % (log_message, route, params, e.code)) but it bugs me that there should be some cleaner way to do this. I'm fantasizing about something along the lines of: logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, route, params, e.code)) does anything like this exist? From k.sahithi2862 at gmail.com Tue Aug 23 12:36:06 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 23 Aug 2011 09:36:06 -0700 (PDT) Subject: TOLLY WOOD HOT GIRLS Message-ID: <39592601-48cc-44d5-b7a4-da44d4d9ae7c@n19g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From eric.lemings at gmail.com Tue Aug 23 12:46:43 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 09:46:43 -0700 (PDT) Subject: Windows No-Install Distribution? References: <9bhvf4F5glU1@mid.individual.net> Message-ID: <98dd0cad-1f08-4827-9569-0178696d0f8e@s7g2000yqk.googlegroups.com> On Aug 23, 9:31?am, Redcat wrote: > I haven't tried it myself yet, but mighthttp://www.portablepython.com/ > be what you're looking for? Almost except it contains additional Python packages that I'm not interested in. From usenet-nospam at seebs.net Tue Aug 23 12:53:40 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 16:53:40 GMT Subject: is there any principle when writing python function References: Message-ID: On 2011-08-23, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? Lots of them. None of them have to do with performance. > for example, how many lines should form a function? Between zero (which has to be written "pass") and a few hundred. Usually closer to the lower end of that range. Occasionally outside it. Which is to say: This is the wrong question. Let us give you the two laws of software optimization. Law #1: Don't do it. If you try to optimize stuff, you will waste a ton of time doing things that, it turns out, are unimportant. Law #2: (Experts only.) Don't do it yet. You don't know enough to "optimize" this yet. Write something that does what it is supposed to do and which you understand clearly. See how it looks. If it looks like it is running well enough, STOP. You are done. Now, if it is too slow, and you are running it on real data, NOW it is time to think about why it is slow. And the solution there is not to read abstract theories about your language, but to profile it -- actually time execution and find out where the time goes. I've been writing code, and making it faster, for some longish period of time. I have not yet ever in any language found cause to worry about function call overhead. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Tue Aug 23 12:55:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 02:55:11 +1000 Subject: Hiding token information from users References: Message-ID: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> Tobiah wrote: > I really need some sort of > algorithm that will let me take an unknown string and generate > the encrypted bit on the fly. Google broken for you? *wink* Seriously, there are about a bazillion algorithms for encrypting and obfuscating strings. Depending on your security requirements, that can be as simple as rot13 and as complex as blowfish (or even more so). If it helps, I have a module that implements a selection of classical (i.e. insecure) encryption algorithms: http://pypi.python.org/pypi/obfuscate Earlier, you said: > The secret is not like > the key to Fort Knox. ?We would rather not have the plain > token out there, as it's internal business information, > but we don't have to protect the information at all costs. > Just making it really inconvenient to extract is fine. I don't understand the point of this. What could your users do with the plain token that they shouldn't? I don't see why, if it's not worth encrypting properly, why it's worth obfuscating it at all. -- Steven From tobiah at teranews.com Tue Aug 23 13:00:33 2011 From: tobiah at teranews.com (Tobiah) Date: Tue, 23 Aug 2011 10:00:33 -0700 Subject: Hiding token information from users In-Reply-To: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/23/2011 09:55 AM, Steven D'Aprano wrote: > Tobiah wrote: > >> I really need some sort of >> algorithm that will let me take an unknown string and generate >> the encrypted bit on the fly. > > Google broken for you? *wink* I had some requirements in the OP that I could not find a solution for. > Seriously, there are about a bazillion algorithms for encrypting and > obfuscating strings. Depending on your security requirements, that can be > as simple as rot13 and as complex as blowfish (or even more so). > > If it helps, I have a module that implements a selection of classical (i.e. > insecure) encryption algorithms: > > http://pypi.python.org/pypi/obfuscate > > > Earlier, you said: > >> The secret is not like >> the key to Fort Knox. We would rather not have the plain >> token out there, as it's internal business information, >> but we don't have to protect the information at all costs. >> Just making it really inconvenient to extract is fine. > > I don't understand the point of this. What could your users do with the > plain token that they shouldn't? I don't see why, if it's not worth > encrypting properly, why it's worth obfuscating it at all. The token ends up translating into the name of a database on our server. With that information alone, it's difficult to imagine a serious vulnerability, yet we just thought it would be worth it to disguise the plain text. From rantingrick at gmail.com Tue Aug 23 13:02:41 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 23 Aug 2011 10:02:41 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> On Aug 23, 6:59?am, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Everyone here who is suggesting that function bodies should be confined to ANY length is an idiot. The length of a functions code block is inconsequential. Don't worry if it too small or too big. It's not the size that matters, it's the motion of the sources ocean! A good function can be one line, or a hundred lines. Always use comments to clarify code and NEVER EVER create more functions only for the sake of short function bodies, WHY, because all you do is move confusion OUT OF the function body and INTO the module/class body. """Energy can neither be created nor be destroyed: it can only be transformed from one state to another""" http://en.wikipedia.org/wiki/Conservation_of_energy https://sites.google.com/site/thefutureofpython/ From clp2 at rebertia.com Tue Aug 23 13:27:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 10:27:42 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 9:29 AM, Roy Smith wrote: > I want to log a string but only the first bunch of it, and add "..." > to the end if it got truncated. ?This certainly works: > > ? ? ? ? ?log_message = message > ? ? ? ? ?if len(log_message) >= 50: > ? ? ? ? ? ?log_message = log_message[:50] + '...' > ? ? ? ? ?logger.error("FAILED: '%s', '%s', %s, %s" % (log_message, > route, params, e.code)) > > but it bugs me that there should be some cleaner way to do this. ?I'm > fantasizing about something along the lines of: > > ? ? ? ? ?logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, > route, params, e.code)) > > does anything like this exist? You can specify a maximum width to truncate the string to, but I don't see any built-in way to add an elision indication (e.g. "..."). >>> "%.4s" % "spam and eggs" 'spam' >>> "{:.4s}".format("spam and eggs") 'spam' You could define something to wrap strings and override __format__() or similar, but that seems like overkill. Cheers, Chris -- http://rebertia.com From no.email at nospam.invalid Tue Aug 23 13:43:35 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Aug 2011 10:43:35 -0700 Subject: try... except with unknown error types References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: <7x62lo6n20.fsf@ruckus.brouhaha.com> gene heskett writes: > OTOH, ChrisA, I have it on good authority that no program is ever finished, > until someone shoots the programmer. :) The way I heard it was "software is never finished until the last user is dead". From ian.g.kelly at gmail.com Tue Aug 23 14:12:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Aug 2011 12:12:43 -0600 Subject: extended slicing and negative stop value problem In-Reply-To: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> Message-ID: On Aug 21, 2011 1:34 PM, "Max" wrote: > > a[0:11][::-1] > > # Instead of a[10:-1:-1], which looks like it should work, but doesn't. > > It works nicely, but it is 1.3 times slower in my code (I am surprised > the interpreter doesn't optimize this). Have you tried reverse()? I haven't timed it, but since it merely creates an iterator rather than a second copy, you may get better performance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Aug 23 14:19:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 14:19:15 -0400 Subject: is there any principle when writing python function In-Reply-To: References: Message-ID: On 8/23/2011 7:59 AM, smith jack wrote: > i have heard that function invocation in python is expensive, That comes into play when chosing between list2 = map(lambda x: 2*x, list1) # versus list2 = [2*x for x in list1] It also comes into play when choosing between looping with recursion (function calls) versus looping with iteration (while/for). In Python, the iteration is faster, while some functional languages omit looping syntax constructs and perhaps auto-translate some recursion to iteration. > but makelots of functions are a good design habit in many other languages, Same for Python, with the exceptions noted above of avoiding trivial one-use functions when there is an alternative. > is there any principle when writing python function? Same as usual. Functions define new words and create new abstractions than encapsulate a unit of computation. > for example, how many lines should form a function? 1 to many, as long as the 1 is more complex than 2*x, unless the trivial function is required for a callback. I doubt the stdlib has many defs longer than 100 lines. Try the following: complex enough that the function call overhead does not matter; simple enough to be understood as a unit. I just came up with the following hypothesis: the complexity of a function is related to the number of *different* functions used to define it: x = a*b + c/d - e**f is more complex (harder to understand) than x = a + b + c + d + e + f For this purpose, different statememts count as functions (and indeed, they translate to bytecode functions. So: for i in iterable: if f(i): print i is more complex than a = 1 b = 2 c = 3 d = 4 People can retain at most about 10 different things in short term memory. So perhaps 10 different 'functions' within a function, or at least a commented block, is enough. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 23 14:29:38 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 14:29:38 -0400 Subject: is there any principle when writing python function In-Reply-To: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/23/2011 11:22 AM, Steven D'Aprano wrote: > Even 7?2 is probably excessive: I find that I'm most comfortable with > functions that perform 4?1 chunks of work. An example from one of my > classes: > > def find(self, prefix): > """Find the item that matches prefix.""" > prefix = prefix.lower() # Chunk #1 > menu = self._cleaned_menu # Chunk #2 > for i,s in enumerate(menu, 1): # Chunk #3 > if s.lower().startswith(prefix): > return i > return None # Chunk #4 > > So that's three one-line chunks and one three-line chunk. In terms of different functions performed (see my previous post), I see attribute lookup assignment enumerate sequence unpacking for-looping if-conditioning lower startswith return That is 9, which is enough. -- Terry Jan Reedy From adrian.monkas at bqn.com.uy Tue Aug 23 15:00:26 2011 From: adrian.monkas at bqn.com.uy (=?ISO-8859-1?Q?Adri=E1n_Monkas?=) Date: Tue, 23 Aug 2011 16:00:26 -0300 Subject: reading and writing files Message-ID: Hi. I`ve been trying to copy a long text from one file to another but it always copied me just a small part. I would be glad if you can help me or explain which is my error. Thanks ---------------------------------------------------------------------------------- def runMenu(): print "\nMENU" print " 1) Copiar" print " 0) Exit" response = int( raw_input().strip() ) if response == 1: print "Copiar" try: print "Abro Archivo Origen" archivo=open("D:\Boot.txt","r") print "Name of the file: ", archivo.name print "Closed or not : ", archivo.closed print "Opening mode : ", archivo.mode print "--------ORIGEN-----------" print archivo.read() print "-------------------------" archivo.seek(0, 0) print "Abro Archivo Destino" archivo2=open("D:\Copia.txt","w+") print "Name of the file: ", archivo2.name print "Closed or not : ", archivo2.closed print "Opening mode : ", archivo2.mode archivo2.write(archivo.read()) archivo2.seek(0, 0) print "---------DESTINO---------" print archivo2.read() print "-------------------------" archivo.close() archivo2.close() except IOError: print ("I/O Error de Lectura") else: print "Lectura OK" elif response == 0: #device.close() print "Exit" return response def main(): print "main" while(1): if runMenu() == 0: break main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Tue Aug 23 15:52:34 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 23 Aug 2011 12:52:34 -0700 Subject: Windows No-Install Distribution? In-Reply-To: References: Message-ID: <4E540502.2020905@ixokai.io> On 8/23/11 8:29 AM, Eric Lemings wrote: > I would like to create/find a Python 3.x distribution that can be > redeployed simply by copying a directory of required files; i.e. Just take the default installer, install it, and then check the Python directory: does it have the python DLL? If not, go look into the system32 directory, grab it, drop it in the Python directory. (If you installed for all-users this will happen, Now copy/zip/whatever that Python directory to another machine where it was not installed. It'll work fine. You'll have to explicitly provide the path to the Python.exe of course; you can't just double-click on a .py or run 'python blah.py', but if your shortcuts/whatever all do C:\Where\You\Installed\Python.exe, everything should just work. We do that at work and never run into any trouble. (We actually provide a MSI but only for convenience of customers who want to auto-install via Group Policy). In most situations, Python's good at "finding itself", i.e. where the python.exe is actually located -- and it boostraps the location of everything else based on that. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From mzummo at gmail.com Tue Aug 23 15:53:45 2011 From: mzummo at gmail.com (Mathew) Date: Tue, 23 Aug 2011 12:53:45 -0700 (PDT) Subject: Looking for python/pyramid developers for a project Message-ID: <7176109a-b899-41ef-9932-ae7821872ffd@t5g2000yqj.googlegroups.com> Hello, My company an ISP is looking to build an administrative webapp dashboard for our underlying systems. We are looking to hire a developer(s) immediately. We would prefer the application be built on python with a popular framework such as pyramid. This position is a contract position paid hourly (35-45$ based on experience). Please email me if you are interested and attach any relevant past projects/ screenshots that were built on pyramid/python. email: mzummo at [gmail.com] skype " mzummo " From amirouche.boubekki at gmail.com Tue Aug 23 16:13:40 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Tue, 23 Aug 2011 13:13:40 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: <4e52442b$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <64707632-4eb6-493a-9c19-440df932e61c@d7g2000vbv.googlegroups.com> On Aug 22, 1:57 pm, Steven D'Aprano wrote: > The relationship between type and object is somewhat special, and needs to > be bootstrapped by the CPython virtual machine. Since you are talking about CPython, I'm wondering how it is bootstraped since you can easly reference PyType in PyObject that part is not hard. > > 2) type is its own metaclass : type(type) is type ? > > Yes. Another bit of bootstrapping that the compiler does. self reference is easy same as referencing PyType from PyObject and PyObject from PyType. > > 5) type(any_object) == last_metaclass_..., which is, most of the time, > > type ? > > I'm not sure what you mean by "last_metaclass". But no. The type of an > object is its class: see this code for example proove my point: class meta_a(type): def __new__(cls, *args, **kwargs): return type.__new__(cls, *args, **kwargs) # see (?) class meta_b(meta_a): def __new___(cls, *args, **kwargs): return meta_a.__new__(cls, *args, **kwargs) # same as above class ClassWithTypeMetaA(object): __metaclass__ = meta_a class ClassWithTypeMetaB(object): __metaclass__ = meta_b type(ClassWithTypeMetaA) == meta_a type(ClassWithTypeMetaB) == meta_b [?] super call doesn't work here, anyone can say why ? Regards, Amirouche From rantingrick at gmail.com Tue Aug 23 16:22:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 23 Aug 2011 13:22:46 -0700 (PDT) Subject: is there any principle when writing python function References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 23, 1:29?pm, Terry Reedy wrote: > In terms of different functions performed (see my previous post), I see > ? ?attribute lookup > ? ?assignment > ? ?enumerate > ? ?sequence unpacking > ? ?for-looping > ? ?if-conditioning > ? ?lower > ? ?startswith > ? ?return > That is 9, ?which is enough. attribute lookup -> inspection assignment -> ditto enumerate -> enumeration sequence unpacking -> parallel assignment for-looping -> cycling if-conditioning -> logic lower -> mutation (don't try to argue!) startswith -> boolean-logic return -> exiting (although all exits require an entrance!) omitted: documenting, referencing, -presumptuousness- pedantic-ly yours, rr ;-) From amirouche.boubekki at gmail.com Tue Aug 23 16:47:07 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Tue, 23 Aug 2011 13:47:07 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: Message-ID: On Aug 22, 5:41 pm, Stephen Hansen wrote: > > 3) object's type is type : object.__class__ is type > > 4) type parent object is object : type.__bases__ == (object,) > > Saying "type" and "parent" and the like for new-style classes is > something of a misnomer. For "type" and "object", these things aren't > constructed like this. > > What you have here is technically true if you go poke at it in the > interpreter, but it doesn't really /mean/ anything because its not how > these objects came to be and is circular and a bit confusing. These > fundamental objects are created special. The code snippet is here to illustrate how it is visible in the interpreter. But you are right. > > 2) type is its own metaclass : type(type) is type ? > > Only in a purely theoretical way. It doesn't actually mean anything; > moreover, type(something) is NOT how you determine somethings metaclass. > Its how you determine somethings type. see the answer to Steven D'Aprano. type(class_object) == a_meta_class_object > The two concepts may be very distinct. Lots of things don't have > metaclasses. All object in new style class have a metaclass at least type. > > 3) object's metaclass is type ? > > Again, only theoretically. and again the famous "bootstrapping" make it like type created object. >From the outside world of the Python implementation object looks like a type instance. > > 5) type(any_object) == last_metaclass_..., which is, most of the time, > > type ? > > Not necessarily at all. In fact, there is no way I'm aware of to > determine if a metaclass was involved in a classes construction unless > said metaclass wants to provide such a mechanism. > > Metaclasses are kind of a hack. They are a way to hook into the class > construction that's normally done and do something, anything you want, > (even hijack the whole procedure and NOT construct a class at all, but > play a song if you want) before its all finished. > > For example, this is a metaclass I've used: > > PageTypes = {} > > class _PageRegistration(type): > def __new__(cls, name, bases, dct): > klass = type.__new__(cls, name, bases, dct) > typename = name[:-9].lower() > if not typename: > typename = None > > PageTypes[typename] = klass > klass.Type = typename > > return klass > > class QueuePage(sc.SizedPanel): > __metaclass__ = _PageRegistration > > Note, the fact that my _PageRegistration metaclass inherits is itself a > class which inherits from type is just one convenient way to write > metaclasses. It could as simply have been just a function. > > Metaclasses are somewhat poorly named in that they are really, "creation > hooks". It the same issue in django, views are only function, until you need complex behavior and you want a "namespace" to put everything in it. IMO that's why class based views exists for complex cases. That said being able to declare a metaclass only as a functions is neat. > > C) type vs class > > ---------------- > > > 1) Type is the metaclass of most classes > > Yes and no. Yes, in that most classes are created using the default > mechanism inside CPython. The class body is executed in a scope, the > resulting dictionary is bound to a new class object, bases and the like > are set, and such. > > No in that it really just, IIUC, skips the whole "metaclass" part of the > process because this 'default mechanism' doesn't need to call out into > other code to do its job. At least, I think-- May be wrong here, > metaclasses are something of a dark voodoo and I'm not 100% entirely > familiar with the internal workings of CPython. > > But functionally, a metaclass is the chunk of code responsible for the > actual physical construction of the class object. For me it takes some variables, namely ``bases``, ``class_dict`` and ``configuration class_name`` and do something with it, probably creating a class_object which behaviour is parametred with the context. I did not know Python before new-style class, so probably for most people explainning that metaclasses are a creation hook is easier for them... > > 4) It's in type.__call__ that happens calls to __new__ and __init__ > > Again, "translates to" is suggesting "this is what happens when you do > X", which I don't know if is strictly true. CPython inside may be > optimizing this whole process. > Especially when it comes to "magic > methods", __x__ and the like -- CPython rarely uses __get*_ for those. > It just calls the methods directly on the class object. IIUC the code of Jython tells me what I've written. If the first part of the algorithm is "lookup for special methods" (what you seem to say) then we both agree that we agree, isn't it ? Moreover I'm not looking in this part to understand how CPython works internally, but how Python works. Since I'm most proeffencient in Python I translate it to Python. *Translates* means "it's a shortcut for". > > 5) 3) => classes are instance of type > > > 6) Since type.__call__ is used to instantiate instance of instance of > > type > > (rephrased: __call__ is used to instantiate classes) where is the > > code which > > is executed when we write ``type(myobject)`` or ``type('MyClass', > > bases, attributes)`` > > __getattribute__ resolution algorithm (see E) tells me that it > > should be type.__call__ > > but type.__call__ is already used to class instatiation. > > Python callables can have more then one argument, and more then one > behavior, and can choose to do more then one thing based on the number > of arguments. > > They don't have overloading, but they can do it themselves. > > You've already proven that, and you already know that -- you're sorta > over-complicating this :) > You said: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def > method: pass }) > > Type.__call__ does both. Actually I missed that :/ > > D) builtin types > > ---------------- > > > 1) builtin types are their own metaclass ? > > Builtin types are constructed by the interpreter, and may or may not > involve themselves with the class/type hierarchy. Even when they do, > they may only do so partially. That's the part I don't understand. How can they possibly work differently. They surrely make their bussiness in the infrastructure/algorithm already in place in type and object to but I cant spot the right piece of code that will explain it. > > 2) why function builtin type can not be subclassed ? > > Because functions are not classes. They're discrete things of their own. > That a function object has a __class__ attribute is an example of a > builtin partially involving itself in the class/type hierarchy, largely > just for introspection purposes-- since functions are first-class > citizens, you need to be able to pass it around and test to determine > what one thing or another actually is. > > Now, functions ARE indeed PyObjects, the internal CPython representation > of an object, of which all things are. But that's not really the same > thing as ultimately inheriting from and involving itself in "object" and > types/classes. Coming with general idea about what are builtin type would make it easier to understand function objects. What I can tell is that function objects behave like the instances of a class, and the class takes (at least) runnable code as arguments. > > E) __getattribute__ > > ------------------- > > > 1) ``my_object.attribute`` always translates to > > ``my_object.__getattribute__('attribute')`` > > No. __getattribute__ is a mechanism to hook into the attribute fetching > mechanism. (As is __getattr__). It is NOT always invoked. > > Especially in the case of __*__ attributes, which by and large bypass > such hooks, as the CPython internals is calling those functions directly > on the class instances themselves. see my answer in the other response From usenet-nospam at seebs.net Tue Aug 23 16:52:55 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 20:52:55 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Roy Smith wrote: > I want to log a string but only the first bunch of it, and add "..." > to the end if it got truncated. This certainly works: > logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, > route, params, e.code)) > does anything like this exist? %.50s -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From eric.lemings at gmail.com Tue Aug 23 17:56:21 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 14:56:21 -0700 (PDT) Subject: Windows No-Install Distribution? References: Message-ID: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> On Aug 23, 1:52?pm, Stephen Hansen wrote: > On 8/23/11 8:29 AM, Eric Lemings wrote: > > > I would like to create/find a Python 3.x distribution that can be > > redeployed simply by copying a directory of required files; i.e. > > Just take the default installer, install it, and then check the Python > directory: does it have the python DLL? If not, go look into the > system32 directory, grab it, drop it in the Python directory. (If you > installed for all-users this will happen, > > Now copy/zip/whatever that Python directory to another machine where it > was not installed. It'll work fine. > > You'll have to explicitly provide the path to the Python.exe of course; > you can't just double-click on a .py or run 'python blah.py', but if > your shortcuts/whatever all do C:\Where\You\Installed\Python.exe, > everything should just work. > > We do that at work and never run into any trouble. (We actually provide > a MSI but only for convenience of customers who want to auto-install via > Group Policy). > > In most situations, Python's good at "finding itself", i.e. where the > python.exe is actually located -- and it boostraps the location of > everything else based on that. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload Excellent start. Which files comprise the standard Python library? Only the files in the 'Lib' subdirectory or are more needed? From usenet-nospam at seebs.net Tue Aug 23 18:00:05 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 22:00:05 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Ethan Furman wrote: > Seebs wrote: >> On 2011-08-23, Roy Smith wrote: >>> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >>> route, params, e.code)) >>> does anything like this exist? >> %.50s > That's not working in 2.7 or 3.2. Huh. Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print "%.5s" % ("hello there, truncate me!") hello -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Tue Aug 23 18:02:30 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Aug 2011 15:02:30 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: <4E542376.5020408@stoneleaf.us> Seebs wrote: > On 2011-08-23, Roy Smith wrote: >> I want to log a string but only the first bunch of it, and add "..." >> to the end if it got truncated. This certainly works: > >> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >> route, params, e.code)) > >> does anything like this exist? > > %.50s That's not working in 2.7 or 3.2. ~Ethan~ From bumbker at yahoo.com Tue Aug 23 18:09:42 2011 From: bumbker at yahoo.com (Ronald Reynolds) Date: Tue, 23 Aug 2011 15:09:42 -0700 (PDT) Subject: upgrade python Message-ID: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> What is recommended for upgrading python for windows? Do I just install the new versionDo I edit my system path? Should I uninstall the old version. ?Right now I have 2.7 and3.1 ?and 3.2 ?and I keep editing my system path when I install a new version but I'm notsure that's the right way to go. ?Is there an upgrade way? I only found downloads at Python.org ?thx ? ? 'Ron "bumpker" Reynolds'? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Aug 23 19:05:30 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Aug 2011 09:05:30 +1000 Subject: Looking for python/pyramid developers for a project References: <7176109a-b899-41ef-9932-ae7821872ffd@t5g2000yqj.googlegroups.com> Message-ID: <878vqjwwxx.fsf@benfinney.id.au> Mathew writes: > We are looking to hire a developer(s) immediately. Please don't use this Python discussion for recruitment. Instead, please use the Python Jobs Board for that purpose . -- \ ?It's a good thing we have gravity or else when birds died | `\ they'd just stay right up there. Hunters would be all | _o__) confused.? ?Steven Wright | Ben Finney From tjreedy at udel.edu Tue Aug 23 19:18:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 19:18:50 -0400 Subject: upgrade python In-Reply-To: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> References: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> Message-ID: On 8/23/2011 6:09 PM, Ronald Reynolds wrote: > What is recommended for upgrading python for windows? Do I just install > the new version I put each version in its own Pythonxy directory, as the installer wants. x.y.z bug fix releases replace the previous x.y release. > Do I edit my system path? However, I put all versions in my own 'Programs' directory (not at top-level, not in Program Files. On my old machine, I added that one directory to PATH. Then I copied Pythonxy/python to pyxy in that directory. I will do the same on my new machine when I have need. But I mostly execute from an IDLE editor window, so PATH and command prompts are mostly irrelevant for me. > Should I uninstall the old version. If and only if you are sure you have no further use for it. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 23 19:28:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 19:28:47 -0400 Subject: Windows No-Install Distribution? In-Reply-To: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> References: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> Message-ID: On 8/23/2011 5:56 PM, Eric Lemings wrote: > On Aug 23, 1:52 pm, Stephen Hansen wrote: >> On 8/23/11 8:29 AM, Eric Lemings wrote: >> >>> I would like to create/find a Python 3.x distribution that can be >>> redeployed simply by copying a directory of required files; i.e. >> >> Just take the default installer, install it, except do a custom install and leave out what you do not want. (Tools? tcl/tk/idle?). You can leave out tests, but then you might want that, at least once, to test your no-install copy. >> and then check the Python >> directory: does it have the python DLL? If not, go look into the >> system32 directory, grab it, drop it in the Python directory. (If you >> installed for all-users this will happen, For Python3, python3.dll in in Python3y\DLLs even for all users install. I believe this is per MS recommendation. So just copy the entire python3y directory. > Which files comprise the standard Python library? Only the files in > the 'Lib' subdirectory That only has Python-coded modules. > or are more needed? C-coded modules are in /DLLs. I presume /libs is needed too but I do not really know, and I will not experiment. Just limit your install to what you want and copy everything. -- Terry Jan Reedy From ethan at stoneleaf.us Tue Aug 23 19:44:29 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Aug 2011 16:44:29 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: <4E543B5D.1090602@stoneleaf.us> Seebs wrote: > On 2011-08-23, Ethan Furman wrote: >> Seebs wrote: >>> On 2011-08-23, Roy Smith wrote: >>>> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >>>> route, params, e.code)) > >>>> does anything like this exist? > >>> %.50s > >> That's not working in 2.7 or 3.2. > > Huh. > > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> print "%.5s" % ("hello there, truncate me!") > hello Ah -- that's only part of it -- the OP wants '...' to print as well. :) ~Ethan~ From steve+comp.lang.python at pearwood.info Tue Aug 23 21:24:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 11:24:14 +1000 Subject: truncating strings References: Message-ID: <4e5452be$0$29984$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> print "%.5s" % ("hello there, truncate me!") > hello Well, whadda you know, I learned something new :) In any case, this doesn't solve the OP's problem, as he wants to truncate the input string, and append '...' if and only if it were truncated. The right solution is to wrap the functionality in a function. It's not hard, and is elegant. Not everything needs to be a built-in. # Untested. def truncate(s, maxwidth=50): if len(s) <= maxwidth: return s s = s[:maxwidth - 3] return s + '...' -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 23 21:44:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 11:44:14 +1000 Subject: is there any principle when writing python function References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e54576e$0$29980$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > On 8/23/2011 11:22 AM, Steven D'Aprano wrote: > >> Even 7?2 is probably excessive: I find that I'm most comfortable with >> functions that perform 4?1 chunks of work. An example from one of my >> classes: >> >> def find(self, prefix): >> """Find the item that matches prefix.""" >> prefix = prefix.lower() # Chunk #1 >> menu = self._cleaned_menu # Chunk #2 >> for i,s in enumerate(menu, 1): # Chunk #3 >> if s.lower().startswith(prefix): >> return i >> return None # Chunk #4 >> >> So that's three one-line chunks and one three-line chunk. > > In terms of different functions performed (see my previous post), I see > attribute lookup > assignment > enumerate > sequence unpacking > for-looping > if-conditioning > lower > startswith > return > That is 9, which is enough. I think we have broad agreement, but we're counting different things. Analogy: you're counting atoms, I'm grouping atoms into molecules and counting them. It's a little like phone numbers: it's not an accident that we normally group phone numbers into groups of 2-4 digits: 011 23 4567 8901 In general, people can more easily memorise four chunks of four digits (give or take) than one chunk of 13 digits: 0112345678901. -- Steven From user at example.net Tue Aug 23 22:46:11 2011 From: user at example.net (User) Date: Tue, 23 Aug 2011 22:46:11 -0400 Subject: Learning Python Message-ID: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Hello all, Does anyone have any good resources for learning Python? I know basic Java and basic Python (loops, data types, if-then statements, etc), but I want to delve into Python further. If anyone knows of any good books, video tutorials, etc it would be greatly appreciated. Thanks, User From Johnny.Venter at zoho.com Tue Aug 23 22:55:12 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Tue, 23 Aug 2011 22:55:12 -0400 Subject: Learning Python In-Reply-To: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <9A6239EC-9CDE-4D28-9C87-22AF4905AF32@zoho.com> http://greenteapress.com/thinkpython/ On Aug 23, 2011, at 10:46 PM, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic Java and basic Python (loops, data types, if-then statements, etc), but I want to delve into Python further. If anyone knows of any good books, video tutorials, etc it would be greatly appreciated. > Thanks, > User > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Aug 23 23:05:18 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Aug 2011 20:05:18 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: <47c4c2ac-a6ea-4575-ba4f-473ca8ba4c6e@x21g2000prd.googlegroups.com> rantingrick wrote: > Everyone here who is suggesting that function bodies should be > confined to ANY length is an idiot. Or, more likely, is the sort of coder who has worked with other coders in the past and understands the value of readable code. > Don't worry if it too small or too big. It's > not the size that matters, it's the motion of the sources ocean! If only you spent as much time actually thinking about what you're saying as trying to find 'clever' ways to say it... > Always use > comments to clarify code and NEVER EVER create more functions only for > the sake of short function bodies This is quite likely the worst advice you've ever given. I can only assume you've never had to refactor the sort of code you're advocating here. From wuwei23 at gmail.com Tue Aug 23 23:08:44 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Aug 2011 20:08:44 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: rantingrick wrote: > https://sites.google.com/site/thefutureofpython/ "Very soon I will be hashing out a specification for python 4000." AHAHAHAHAhahahahahahahAHAHAHAHahahahahaaaaaaa. So rich. Anyone willing to bet serious money we won't see this before 4000AD? "Heck even our leader seems as a captain too drunk with vanity to care; and our members like a ship lost at sea left to sport of every troll-ish wind!" Quite frankly, you're a condescending, arrogant blow-hard that this community would be better off without. "We must constantly strive to remove multiplicity from our systems; lest it consumes us!" s/multiplicity/rantingrick/ and I'm in full agreement. From davea at ieee.org Wed Aug 24 00:05:40 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Aug 2011 00:05:40 -0400 Subject: reading and writing files In-Reply-To: References: Message-ID: <4E547894.2020308@ieee.org> On 01/-10/-28163 02:59 PM, Adri?n Monkas wrote: > Hi. > I`ve been trying to copy a long text from one file to another but it always > copied me just a small part. > I would be glad if you can help me or explain which is my error. > Thanks > > ---------------------------------------------------------------------------------- > def runMenu(): > > print "\nMENU" > print " 1) Copiar" > print " 0) Exit" > > response = int( raw_input().strip() ) > > if response == 1: > print "Copiar" > try: > print "Abro Archivo Origen" > archivo=open("D:\Boot.txt","r") > print "Name of the file: ", archivo.name > print "Closed or not : ", archivo.closed > print "Opening mode : ", archivo.mode > > print "--------ORIGEN-----------" > print archivo.read() > print "-------------------------" > archivo.seek(0, 0) > > print "Abro Archivo Destino" > archivo2=open("D:\Copia.txt","w+") > print "Name of the file: ", archivo2.name > print "Closed or not : ", archivo2.closed > print "Opening mode : ", archivo2.mode > > > > archivo2.write(archivo.read()) > > archivo2.seek(0, 0) > print "---------DESTINO---------" > print archivo2.read() > print "-------------------------" > archivo.close() > archivo2.close() > > except IOError: > print ("I/O Error de Lectura") > else: > print "Lectura OK" > > elif response == 0: > #device.close() > print "Exit" > > return response > > def main(): > print "main" > while(1): > if runMenu() == 0: break > > main() > What's your goal? If it's to write a small program to copy a file, try using shutil library. It'll save you lots of trouble. It can handle files that are bigger than available memory, it can fix up timestamps, etc. If it's to learn Python, then you need to learn about writing debuggable code. Part of that is doing things once. So if you read() the entire contents of the file, keep it in a variable and use that variable to write() to the other file, and also to print to the screen. Then if something's wrong, you can be sure it's the same both places. Never do something like y.write(x.read()) till you're sure everything's working. That's a kind of optimization which doesn't save any execution time, and only a few keystrokes. And you'll waste those keystrokes changing the code a dozen times to find out why it isn't working. You don't make clear just what is "just a small part." In other words, what is truncated? Is it the ORIGEN printout, the DESTINO printout, or the actual file contents ? And is the file involved a gigabyte or two, or is it 500 bytes? Did it display part of the file correctly, or by "small part" did you mean zero bytes? Show the actual stack trace if you got an error, or the program output if not. And in general, when you're asking questions, please specify the Python version and OS version you're running. Clearly, the latter is some kind of Windows, since you're using the D: drive. And the Python version is 2.x for some value of x. But sometimes it'll matter. Your filenames are incorrect, since you use the backslash without escaping it. So the source file has a backspace in it. I'm amazed you don't get an error, since it's unlikely you have a file with that kind of name. When I run it, I get "Abro Archivo Origen". I'm astounded you don't. When making a literal string out of a Windows filename, either double the backslashes, or use R"xxx" for raw strings, or just use forward slashes. HTH. DaveA From steve+comp.lang.python at pearwood.info Wed Aug 24 00:10:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 14:10:49 +1000 Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4e5479ca$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Aug 2011 12:46 pm User wrote: > Hello all, > Does anyone have any good resources for learning Python? http://duckduckgo.com/?q=python+tutorial -- Steven From larry at hastings.org Wed Aug 24 00:15:07 2011 From: larry at hastings.org (Larry Hastings) Date: Tue, 23 Aug 2011 21:15:07 -0700 Subject: Announcing a new podcast: Radio Free Python Message-ID: <4E547ACB.4040301@hastings.org> Radio Free Python is a new monthly podcast focused on Python and its community. Episode 1 has just been released! It features a panel discussion with the PythonLabs team: * Barry Warsaw, * Fred Drake, * Guido van Rossum, * Roger Masse, * and Tim Peters. You can find it at http://www.radiofreepython.com/ as of this very minute. Enjoy! /larry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Wed Aug 24 00:21:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 24 Aug 2011 04:21:18 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Ethan Furman wrote: > Ah -- that's only part of it -- the OP wants '...' to print as well. :) Ohhhh. Hmm. That's harder. I can't think of a pretty way, so I think I'd probably write a "prettytrunc(string, len)" or something similar. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Wed Aug 24 00:43:41 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 21:43:41 -0700 Subject: reading and writing files In-Reply-To: <4E547894.2020308@ieee.org> References: <4E547894.2020308@ieee.org> Message-ID: On Tue, Aug 23, 2011 at 9:05 PM, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Adri?n Monkas wrote: >> ? ? ? ? ? ? print "Abro Archivo Origen" >> ? ? ? ? ? ? archivo=open("D:\Boot.txt","r") > Your filenames are incorrect, since you use the backslash without escaping > it. ?So the source file has a backspace in it. ?I'm amazed you don't get an > error, since it's unlikely you have a file with that kind of name. Backslash escape sequences only work for lowercase characters: >>> '\b' '\x08' >>> '\B' '\\B' But yeah, I don't endorse relying on this. Just use forward slashes instead of backslashes in paths; Windows accepts them just fine. Cheers, Chris -- http://rebertia.com From saraanderson24 at gmail.com Wed Aug 24 01:11:55 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Tue, 23 Aug 2011 22:11:55 -0700 (PDT) Subject: WATCH WORLD`S MOST BEAUTIFUL CITYSCAPE PLACES EVER. Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S MOST HILARIOUS FUNNIEST VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From muresanalex.contact at gmail.com Wed Aug 24 02:29:41 2011 From: muresanalex.contact at gmail.com (Muresan Alexandru Mihai) Date: Wed, 24 Aug 2011 09:29:41 +0300 Subject: reading and writing files In-Reply-To: References: Message-ID: If you need an int isn't better to use input() instead of raw_input() ? On Tue, Aug 23, 2011 at 10:00 PM, Adri?n Monkas wrote: > Hi. > I`ve been trying to copy a long text from one file to another but it always > copied me just a small part. > I would be glad if you can help me or explain which is my error. > Thanks > > > ---------------------------------------------------------------------------------- > def runMenu(): > > print "\nMENU" > print " 1) Copiar" > print " 0) Exit" > > response = int( raw_input().strip() ) > > if response == 1: > print "Copiar" > try: > print "Abro Archivo Origen" > archivo=open("D:\Boot.txt","r") > print "Name of the file: ", archivo.name > print "Closed or not : ", archivo.closed > print "Opening mode : ", archivo.mode > > print "--------ORIGEN-----------" > print archivo.read() > print "-------------------------" > archivo.seek(0, 0) > > print "Abro Archivo Destino" > archivo2=open("D:\Copia.txt","w+") > print "Name of the file: ", archivo2.name > print "Closed or not : ", archivo2.closed > print "Opening mode : ", archivo2.mode > > > > archivo2.write(archivo.read()) > > archivo2.seek(0, 0) > print "---------DESTINO---------" > print archivo2.read() > print "-------------------------" > archivo.close() > archivo2.close() > > except IOError: > print ("I/O Error de Lectura") > else: > print "Lectura OK" > > elif response == 0: > #device.close() > print "Exit" > > return response > > def main(): > print "main" > while(1): > if runMenu() == 0: break > > main() > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Muresan Alexandru Web Developer 0740782921 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Aug 24 02:38:12 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 23:38:12 -0700 Subject: reading and writing files In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 11:29 PM, Muresan Alexandru Mihai wrote: > If you need an int isn't better to use input() instead of raw_input() ? Absolutely not! input() does an eval(), which is very dangerous security-wise and can also lead to rather strange behavior. input() is so bad that it was removed in Python 3 (confusingly, raw_input() was also simultaneously renamed to input(); the point is, there's no longer an equivalent built-in function). Cheers, Chris From bex.lewis at gmail.com Wed Aug 24 04:53:19 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Wed, 24 Aug 2011 01:53:19 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: http://diveintopython.org/ is where you can get an online version of the dive into python book. I found it useful when learning python :) Becky Lewis On Aug 24, 3:46?am, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic > Java and basic Python (loops, data types, if-then statements, etc), but > I want to delve into Python further. If anyone knows of any good books, > video tutorials, etc it would be greatly appreciated. > Thanks, > User From muresanalex.contact at gmail.com Wed Aug 24 05:51:46 2011 From: muresanalex.contact at gmail.com (Muresan Alexandru Mihai) Date: Wed, 24 Aug 2011 12:51:46 +0300 Subject: Learning Python In-Reply-To: References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: http://www.youtube.com/watch?v=tKTZoB2Vjuk On Wed, Aug 24, 2011 at 11:53 AM, becky_lewis wrote: > http://diveintopython.org/ is where you can get an online version of > the dive into python book. I found it useful when learning python :) > > Becky Lewis > > On Aug 24, 3:46 am, User wrote: > > Hello all, > > Does anyone have any good resources for learning Python? I know basic > > Java and basic Python (loops, data types, if-then statements, etc), but > > I want to delve into Python further. If anyone knows of any good books, > > video tutorials, etc it would be greatly appreciated. > > Thanks, > > User > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Alexandru Muresan Web Developer -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Aug 24 06:04:45 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Aug 2011 07:04:45 -0300 Subject: Execute a method in a file in an egg References: Message-ID: En Tue, 23 Aug 2011 13:14:06 -0300, RVince escribi?: > Is there a way to do this from the command line? Thanks. Something like this? python -c "import the.module;the.module.someclass().method(arguments)" -- Gabriel Genellina From research at johnohagan.com Wed Aug 24 07:01:55 2011 From: research at johnohagan.com (John O'Hagan) Date: Wed, 24 Aug 2011 21:01:55 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> Message-ID: <20110824210155.fd069643aa9a4e66de3c6a9f@johnohagan.com> On Mon, 22 Aug 2011 20:38:30 +0200 Peter Otten <__peter__ at web.de> wrote: > John O'Hagan wrote: > > > On Mon, 22 Aug 2011 11:32:18 +0200 > > Peter Otten <__peter__ at web.de> wrote: > > > >> John O'Hagan wrote: > >> > >> > I have a class like this: > >> > > >> > class MySeq(): > >> > def __init__(self, *seq, c=12): > >> > self.__c = c > >> > self.__pc = sorted(set([i % __c for i in seq])) > >> > self.order = ([[self.__pc.index(i % __c), i // __c] for i in > >> > seq]) > >> > #other calculated attributes > >> > > >> > @property > >> > def pitches(self): > >> > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > >> > > >> > #other methods > >> > >> That makes me dizzy. Are there any maxims in the Zen of Python that this > >> piece doesn't violate? > > > > "Now is better than never"? > > > > I know it looks crazy to take something apart and put it back together, as > > in this *simplified* *example* > > emphasis mine ;) > > > , but it does have a meaningful use: reducing a > > series of musical notes to a unique irreducible form "__pc", ("prime form" > > in pitch-class set theory), but keeping track of the actual current > > manifestation of that form via the writeable "order" attribute. That's why > > "pitches" must be called with each reference, because it may change, > > unlike "__pc", which can only change if the instance is reinitialised. > > > > I am open to more elegant suggestions, of course. :) > > [...] > > Dunno. Maybe you could inherit from collections.(Mutable)Sequence and > somewhat reduce the number of methods you'd have to implement. > Or you introduce a Pitch (Python) class that knows about its pitch class, > and put that into a normal list: > > >>> class Pitch(int): > ... @property > ... def pitch_class(self): > ... return self % 12 > ... def __repr__(self): > ... return "Pitch(%s, pitch_class=%s)" % (self, > self.pitch_class) > ... > >>> map(Pitch, [1,0,42]) > [Pitch(1, pitch_class=1), Pitch(0, pitch_class=0), Pitch(42, pitch_class=6)] > That's a good starting point for a neater solution, but there's more I have to solve. For completeness, here's the un-simplified __init__ of the class (yes, it gets worse!): class MySeq(): def __init__(self, *sequence, octave=12): pcset = sorted(set([i % octave for i in sequence])) steps = ([pcset[i] - pcset[i - 1] for i in range(1, len(pcset))] + [octave - pcset[-1]]) rotations = [steps[n:] + steps[:n] for n in range(len(steps))] prime_steps = min([i for i in rotations if i[-1] == max(steps)]) self.__prime = [0] for step in prime_steps: self.__prime.append(step + prime[-1]) self.__offset = pcset[rotations.index(prime_steps)] self.__order = Order([[prime.index((i - offset) % octave), (i - self.__offset) // octave] for i in sequence]) self.__octave = octave The __prime attribute is the one all the internal methods refer to, and it's not so much a collection of pitch classes as an interval structure. Accordingly, I'll follow your tip and look into the collections ABCs, many of which look applicable, and go back to the drawing board. Thanks, John From research at johnohagan.com Wed Aug 24 07:09:28 2011 From: research at johnohagan.com (John O'Hagan) Date: Wed, 24 Aug 2011 21:09:28 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110824210928.8a79a37a577f395780aa1f75@johnohagan.com> On Tue, 23 Aug 2011 17:25:22 +1000 Steven D'Aprano wrote: > On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote: > > > On Mon, 22 Aug 2011 15:27:36 +1000 > > Steven D'Aprano wrote: > [...] > >> # Untested > >> class MySeq(object): > >> methods_to_delegate = ('__getitem__', '__len__', ...) > >> pitches = ... # make sure pitches is defined > >> def __getattr__(self, name): > >> if name in self.__class__.methods_to_delegate: > >> return getattr(self.pitches, name) > >> return super(MySeq, object).__getattr__(self, name) > >> # will likely raise AttributeError > > [...] > > > Also, it doesn't immediately suggest to me a way of modifying method calls > > (maybe __setattr__?). > > What do you mean, "modifying method calls"? That was a rather badly-worded reference to a function in my original post which modified the action of list methods in ways specific to the new class. As I said, I re-read the docs on __getattr__, and now __setattr__, and I get what they do now. Thanks for your pointers, I'll get back to work. Regards, John From adam.jorgensen.za at gmail.com Wed Aug 24 08:21:18 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 24 Aug 2011 14:21:18 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... Message-ID: Hi all, I'm experiencing a weird issue with closuring of parameters and some nested functions I have inside two functions that return decorators. I think it's best illustrated with the actual code: # This decorator doesn't work. For some reason python refuses to closure the *decode_args parameter into the scope of the nested decorate and decorate_with_rest_wrapper functions # Renaming *decode_args has no effect def rest_wrapper(*decode_args, **deco_kwargs): def decorate(func): argspec = getfullargspec(func) decode_args = [argspec.args.index(decode_arg) for decode_arg in decode_args] def decorate_with_rest_wrapper(func, *args, **kwargs): if decode_args: args = list(args) for index in decode_args: args[index] = json.loads(args[index], cls=deco_kwargs.get('json_decoder')) return Response.ResponseString(json.dumps(func(*args, **kwargs), cls=deco_kwargs.get('json_encoder'))) return decorator(decorate_with_rest_wrapper, func) return decorate # If I modify rest_wrapper slightly and use the parameters from rest_wrapper as default value args for decorate it works. Why? def rest_wrapper(*decode_args, **deco_kwargs): def decorate(func, decode_args=decode_args, deco_kwargs=deco_kwargs): argspec = getfullargspec(func) decode_args = [argspec.args.index(decode_arg) for decode_arg in decode_args] def decorate_with_rest_wrapper(func, *args, **kwargs): if decode_args: args = list(args) for index in decode_args: args[index] = json.loads(args[index], cls=deco_kwargs.get('json_decoder')) return Response.ResponseString(json.dumps(func(*args, **kwargs), cls=deco_kwargs.get('json_encoder'))) return decorator(decorate_with_rest_wrapper, func) return decorate # Similarly, this decorator doesn't work. For some reason python refuses to closure the sa_session_class_lambda parameter into the scope of the nested decorate and decorate_with_sqlalchemy functions # Renaming the sa_session_class_lambda parameter does not work and neither does changing the order of the args list. def with_sqlalchemy(sa_session_parameter_name='sa_session', sa_session_class_lambda=None): def decorate(func): argspec = getfullargspec(func) sa_session_parameter_index = argspec.args.index(sa_session_parameter_name) if sa_session_class_lambda is None: if argspec.args[0] == 'self': sa_session_class_lambda = lambda obj, *args, **kwargs: obj.get_sa_session_class() else: sa_session_class_lambda = lambda *args, **kwargs: Alchemy.get_sa_session_class() def decorate_with_alchemy(func, *args, **kwargs): if args[sa_session_parameter_index]: raise Exception('%s parameter is not empty!' % sa_session_parameter_name) try: sa_session_class = sa_session_class_lambda(*args, **kwargs) sa_session = sa_session_class() args = list(args) args[sa_session_parameter_index] = sa_session retval = func(*args, **kwargs) sa_session.commit() return retval except Exception, e: sa_session.rollback() raise e finally: sa_session.close() return decorator(decorate_with_alchemy, func) return decorate # Again, if I modify decorate and use the parameters from with_sqlalchemy as default value args in decorate it works fine. What gives? def with_sqlalchemy(sa_session_parameter_name='sa_session', sa_session_class_lambda=None): def decorate(func, sa_session_parameter_name=sa_session_parameter_name, sa_session_class_lambda=sa_session_class_lambda): argspec = getfullargspec(func) sa_session_parameter_index = argspec.args.index(sa_session_parameter_name) if sa_session_class_lambda is None: if argspec.args[0] == 'self': sa_session_class_lambda = lambda obj, *args, **kwargs: obj.get_sa_session_class() else: sa_session_class_lambda = lambda *args, **kwargs: Alchemy.get_sa_session_class() def decorate_with_alchemy(func, *args, **kwargs): if args[sa_session_parameter_index]: raise Exception('%s parameter is not empty!' % sa_session_parameter_name) try: sa_session_class = sa_session_class_lambda(*args, **kwargs) sa_session = sa_session_class() args = list(args) args[sa_session_parameter_index] = sa_session retval = func(*args, **kwargs) sa_session.commit() return retval except Exception, e: sa_session.rollback() raise e finally: sa_session.close() return decorator(decorate_with_alchemy, func) return decorate Does anyone have any idea why the problem parameters are not being captured? When I try to run the code using the broken versions of the two decorators python fails claiming that the problem variables are being referenced before they are defined... What's more interesting is that PyCharm seems to know this is going to happen as well because the code insight marks the problem versions as having unused parameters (Specifically, the *decode_args and sa_session_class_lambda parameters). Does anyone know why this is happening and if there is a nicer fix than the one illustrated above? Thanks Adam From sdouche at gmail.com Wed Aug 24 08:22:12 2011 From: sdouche at gmail.com (Sebastien Douche) Date: Wed, 24 Aug 2011 14:22:12 +0200 Subject: Execute a method in a file in an egg In-Reply-To: References: Message-ID: On Wed, Aug 24, 2011 at 12:04, Gabriel Genellina wrote: >> Is there a way to do this from the command line? Thanks. > > Something like this? > > python -c "import the.module;the.module.someclass().method(arguments)" Or with console_scripts option in setup.py. -- Sebastien Douche Twitter : @sdouche From __peter__ at web.de Wed Aug 24 09:29:58 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Aug 2011 15:29:58 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... References: Message-ID: Adam Jorgensen wrote: > Hi all, I'm experiencing a weird issue with closuring of parameters > and some nested functions I have inside two functions that > return decorators. I think it's best illustrated with the actual code: You should have made an effort to reduce its size > # This decorator doesn't work. For some reason python refuses to > closure the *decode_args parameter into the scope of the nested > decorate and decorate_with_rest_wrapper functions > # Renaming *decode_args has no effect > def rest_wrapper(*decode_args, **deco_kwargs): > def decorate(func): > argspec = getfullargspec(func) > decode_args = [argspec.args.index(decode_arg) for decode_arg > in decode_args] I didn't read the whole thing, but: >>> def f(a): ... def g(): ... a = a + 42 ... return a ... return g ... >>> f(1)() Traceback (most recent call last): File "", line 1, in File "", line 3, in g UnboundLocalError: local variable 'a' referenced before assignment Python treats variables as local if you assign a value to them anywhere in the function. The fix is easy, just use another name: >>> def f(a): ... def g(): ... b = a + 42 ... return b ... return g ... >>> f(1)() 43 In Python 3 you can also use the nonlocal statement. From python.list at tim.thechases.com Wed Aug 24 09:41:17 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 24 Aug 2011 08:41:17 -0500 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: <4E54FF7D.7000602@tim.thechases.com> On 08/23/2011 11:15 PM, Larry Hastings wrote: > Episode 1 has just been released! > > You can find it at http://www.radiofreepython.com/ as of this very minute. No Podcast/RSS feed...seriously? Downloaded manually and will listen later, but best left to podcatchers :) -tkc From adam.jorgensen.za at gmail.com Wed Aug 24 10:30:13 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 24 Aug 2011 16:30:13 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... In-Reply-To: References: Message-ID: Thanks :-) Sorry about the size, I wasn't sure what was relevant... On 24 August 2011 15:29, Peter Otten <__peter__ at web.de> wrote: > Adam Jorgensen wrote: > >> Hi all, I'm experiencing a weird issue with closuring of parameters >> and some nested functions I have inside two functions that >> return decorators. I think it's best illustrated with the actual code: > > You should have made an effort to reduce its size >> # This decorator doesn't work. For some reason python refuses to >> closure the *decode_args parameter into the scope of the nested >> decorate and decorate_with_rest_wrapper functions >> # Renaming *decode_args has no effect >> def rest_wrapper(*decode_args, **deco_kwargs): >> ? ? def decorate(func): >> ? ? ? ? argspec = getfullargspec(func) >> ? ? ? ? decode_args = [argspec.args.index(decode_arg) for decode_arg >> in decode_args] > > I didn't read the whole thing, but: > >>>> def f(a): > ... ? ? def g(): > ... ? ? ? ? ? ? a = a + 42 > ... ? ? ? ? ? ? return a > ... ? ? return g > ... >>>> f(1)() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in g > UnboundLocalError: local variable 'a' referenced before assignment > > Python treats variables as local if you assign a value to them anywhere in > the function. The fix is easy, just use another name: > >>>> def f(a): > ... ? ? def g(): > ... ? ? ? ? ? ? b = a + 42 > ... ? ? ? ? ? ? return b > ... ? ? return g > ... >>>> f(1)() > 43 > > In Python 3 you can also use the nonlocal statement. > > -- > http://mail.python.org/mailman/listinfo/python-list > From cjw at ncf.ca Wed Aug 24 10:36:54 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 24 Aug 2011 10:36:54 -0400 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: On 24-Aug-11 00:15 AM, Larry Hastings wrote: > > > Radio Free Python is a new monthly podcast focused on Python and its > community. > > Episode 1 has just been released! It features a panel discussion with > the PythonLabs team: > > * Barry Warsaw, > * Fred Drake, > * Guido van Rossum, > * Roger Masse, > * and Tim Peters. > > > You can find it at http://www.radiofreepython.com/ as of this very minute. > > Enjoy! > > > /larry/ > > +1 Colin W. From k.sahithi2862 at gmail.com Wed Aug 24 11:04:13 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 24 Aug 2011 08:04:13 -0700 (PDT) Subject: HOT ACTRESS & DOOKUDU MOVIE STILLS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From patentsvnc at gmail.com Wed Aug 24 11:53:58 2011 From: patentsvnc at gmail.com (Den) Date: Wed, 24 Aug 2011 08:53:58 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> On Aug 23, 7:46?pm, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic > Java and basic Python (loops, data types, if-then statements, etc), but > I want to delve into Python further. If anyone knows of any good books, > video tutorials, etc it would be greatly appreciated. > Thanks, > User Learning Python, and Programming in Python by Lutz. They worked for me. Den From kangshufan at hotmail.com Wed Aug 24 11:59:45 2011 From: kangshufan at hotmail.com (kangshufan at hotmail.com) Date: Wed, 24 Aug 2011 08:59:45 -0700 (PDT) Subject: there is a problem, holp someone could help me,thanks Message-ID: Hi everyone I just study python for a few time. Now I have a problem and I holp someone can help me. There is a piece of code: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) Could you explain how it works? Thanks for you help. Vince From kangshufan at hotmail.com Wed Aug 24 12:03:39 2011 From: kangshufan at hotmail.com (kangshufan at hotmail.com) Date: Wed, 24 Aug 2011 09:03:39 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> Message-ID: <770aff9e-0879-40f5-ac86-f5098b9fd764@b9g2000prd.googlegroups.com> Hi all could some one help me? there is a piece of code: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) Could some one explain it for me? I can't understand how it works. From gordon at panix.com Wed Aug 24 12:46:39 2011 From: gordon at panix.com (John Gordon) Date: Wed, 24 Aug 2011 16:46:39 +0000 (UTC) Subject: there is a problem, holp someone could help me,thanks References: Message-ID: In kangshufan at hotmail.com writes: > Hi everyone > I just study python for a few time. > Now I have a problem and I holp someone can help me. > There is a piece of code: > def fib(x): > if x==0 or x==1: return 1 > else: return fib(x-1) + fib(x-2) > Could you explain how it works? > Thanks for you help. > Vince When a function calls itself, as fib() does, it's called recursion. http://en.wikipedia.org/wiki/Recursion_(computer_science) Basically the fib() method keeps calling itself with smaller and smaller arguments until it gets 1 or 0. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nobody at nowhere.com Wed Aug 24 13:47:37 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Aug 2011 18:47:37 +0100 Subject: Hiding token information from users References: Message-ID: On Tue, 23 Aug 2011 06:27:39 -0700, Tobiah wrote: > I am making QR codes that cell phone users scan in order to make use of an > application. Part of the information is a token that needs to be passed > on to the server, but I'd rather not allow a person examining the QR code > to be able to see that plain bit of information. I'd like to scramble up > the token so that the result: Can you not just encrypt the data with a fixed secret key? A fixed key satisfies #2. #3 can almost be satisfied by using base-64, or can be entirely satisfied by using base-36 or base-62 (these are less efficient, but that doesn't matter for small amounts of data). #1 can be satisfied by compressing the text beforehand; this should almost exactly compensate for the expansion caused by #3. Any block cipher in CBC mode will satisfy #4 (it will even be satisfied in ECB mode if the compressed token is smaller than the cipher block size). From nathan.huang.python at gmail.com Wed Aug 24 13:50:46 2011 From: nathan.huang.python at gmail.com (nathan huang) Date: Thu, 25 Aug 2011 01:50:46 +0800 Subject: there is a problem, holp someone could help me,thanks In-Reply-To: References: Message-ID: hi John it's simple, let's make a little modification for the scipt: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) for i in range(10): print 'fib(%s): ' % i, fib(i) result: fib(0): 1 fib(1): 1 fib(2): 2 fib(3): 3 fib(4): 5 fib(5): 8 fib(6): 13 fib(7): 21 fib(8): 34 fib(9): 55 you see, when we put 0 or 1 into fib, we definitely get 1 individually, if we put 2 into fib(), inside script we get two fib() result plus 1 + 1. If we put 9 into fib(), we get plus of two results of fib(7) and fib(8), that is 21 + 34, so we get 55. hope it can give you a little help. On Thu, Aug 25, 2011 at 12:46 AM, John Gordon wrote: > In > kangshufan at hotmail.com writes: > > > Hi everyone > > > I just study python for a few time. > > Now I have a problem and I holp someone can help me. > > There is a piece of code: > > > def fib(x): > > if x==0 or x==1: return 1 > > else: return fib(x-1) + fib(x-2) > > > Could you explain how it works? > > Thanks for you help. > > > Vince > > When a function calls itself, as fib() does, it's called recursion. > > http://en.wikipedia.org/wiki/Recursion_(computer_science) > > Basically the fib() method keeps calling itself with smaller and smaller > arguments until it gets 1 or 0. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From iamforufriends at gmail.com Wed Aug 24 14:34:20 2011 From: iamforufriends at gmail.com (hot girl) Date: Wed, 24 Aug 2011 11:34:20 -0700 (PDT) Subject: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfri Message-ID: <84a2f2bb-99e7-40ab-8e79-4737b2388591@x14g2000prn.googlegroups.com> making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc From rantingrick at gmail.com Wed Aug 24 14:39:21 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Aug 2011 11:39:21 -0700 (PDT) Subject: there is a problem, holp someone could help me,thanks References: Message-ID: <4dd3838c-8d6b-4957-b7c8-7b8b4669d058@a31g2000vbt.googlegroups.com> On Aug 24, 10:59?am, kangshu... at hotmail.com wrote: > Now I have a problem and I holp someone can help me. > > def fib(x): > ? ? if x==0 or x==1: return 1 > ? ? else: return fib(x-1) + fib(x-2) This must be from "How not to program". Was this a personal pick or recommendation? From gordon at panix.com Wed Aug 24 14:46:19 2011 From: gordon at panix.com (John Gordon) Date: Wed, 24 Aug 2011 18:46:19 +0000 (UTC) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> <770aff9e-0879-40f5-ac86-f5098b9fd764@b9g2000prd.googlegroups.com> Message-ID: In <770aff9e-0879-40f5-ac86-f5098b9fd764 at b9g2000prd.googlegroups.com> kangshufan at hotmail.com writes: > Hi all > could some one help me=EF=BC=9F > there is a piece of code: > def fib(x): > if x=3D=3D0 or x=3D=3D1: return 1 > else: return fib(x-1) + fib(x-2) > Could some one explain it for me? I can't understand how it works. Reposting the exact same question doesn't help us answer it. Perhaps you could explain why the previous responses weren't helpful. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From motoom at xs4all.nl Wed Aug 24 15:52:41 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 24 Aug 2011 21:52:41 +0200 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: On Aug 24, 2011, at 06:15, Larry Hastings wrote: > Radio Free Python is a new monthly podcast focused on Python and its community. Excellent initiative! I love to listen to podcasts about Open Source software and Python, on my MP3 player, while I take long walks in the countryside. I hope you'll have the same stamina as FLOSS Weekly (http://en.wikipedia.org/wiki/Floss_weekly). In the past years there have been some Python podcast initiatives, but most of them didn't last very long. I guess it takes a substantial amount of energy and commitment to produce regular podcasts over a long period of time. Do you need any input/ideas/feedback ? Greetings, Michiel Overtoom http://www.michielovertoom.com -- "Learn to value yourself, which means: fight for your happiness." - Ayn Rand From bsagert at gmail.com Wed Aug 24 16:45:09 2011 From: bsagert at gmail.com (Bill) Date: Wed, 24 Aug 2011 13:45:09 -0700 (PDT) Subject: I think I found 2 undocumented string format codes. Message-ID: My google-fu has failed me in finding info on %h and %l string formatting codes. >>> '%h' %'hello' exceptions.ValueError: incomplete format >>> '%l' %'hello' exceptions.ValueError: incomplete format Does anyone know what doing a "complete format" means? From rantingrick at gmail.com Wed Aug 24 17:22:21 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Aug 2011 14:22:21 -0700 (PDT) Subject: I think I found 2 undocumented string format codes. References: Message-ID: On Aug 24, 3:45?pm, Bill wrote: > My google-fu has failed me in finding info on %h and %l string > formatting codes. Did it ever occur to you to peruse the docs? http://docs.python.org/library/stdtypes.html#string-formatting-operations Stop using the limited deprecated string interpolation and use the new string format method. http://docs.python.org/library/string.html#format-string-syntax From alex.kapps at web.de Wed Aug 24 17:32:56 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 24 Aug 2011 23:32:56 +0200 Subject: I think I found 2 undocumented string format codes. In-Reply-To: References: Message-ID: <4E556E08.5050308@web.de> On 24.08.2011 22:45, Bill wrote: > My google-fu has failed me in finding info on %h and %l string > formatting codes. > >>>> '%h' %'hello' > exceptions.ValueError: incomplete format > >>>> '%l' %'hello' > exceptions.ValueError: incomplete format > > Does anyone know what doing a "complete format" means? See http://docs.python.org/library/stdtypes.html#string-formatting-operations The formatting codes have been borrowed from the C function sprintf(), where l and h are length modifier for integers (%hi, %li, ...) The Python docs (link above) say: "A length modifier (h, l, or L) may be present, but is ignored as it is not necessary for Python ? so e.g. %ld is identical to %d." From tjreedy at udel.edu Wed Aug 24 17:50:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Aug 2011 17:50:21 -0400 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: <4E55721D.5090805@udel.edu> On 8/24/2011 12:15 AM, Larry Hastings wrote: > Radio Free Python is a new monthly podcast focused on Python and its > community. > > Episode 1 has just been released! It features a panel discussion with > the PythonLabs team: > > * Barry Warsaw, > * Fred Drake, > * Guido van Rossum, > * Roger Masse, > * and Tim Peters. > > You can find it at http://www.radiofreepython.com/ as of this very minute. What a treat. Thank you. Please announce the next one too. -- Terry Jan Reedy From davea at ieee.org Wed Aug 24 17:51:21 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Aug 2011 17:51:21 -0400 Subject: Unspecified problem sending serial data In-Reply-To: References: <4E547894.2020308@ieee.org> Message-ID: <4E557259.5060702@ieee.org> Former subject line: reading and writing files On 08/24/2011 01:05 PM, Adri?n Monkas wrote: > Hi. thanks for answering so soon. > What i want to do is send around 180KBytes via Serial port. First of all i > have been trying to read from a file this amount of information and copy to > another file. That was a succesful test. After that the second test was > reading from a file and then send the info via serial, but it failed. > I have configured the serial port in both side of the connection. > thanks > Adrian > > Don't top-post. Put your response after the text you're quoting. OK, so you solved the first problem. Did you learn anything from my post? You're again not describing your (new) problem, your environment, nor in this case giving a clue as to what you've tried. Descriptions like "it failed" are usually useless. In this case, I can't help, because I don't know anything about doing serial on the Amiga. In any case, i wouldn't, since you didn't post to the forum. You sent it as a private reply to me. If you're reading this as a mailing list, the remember to do a reply-all, or at least make sure to use Python-list at python.org I'll forward the message for you, bu it would have been better if you had posted it directly, with an appropriate subject line. DaveA From tahoemph at gmail.com Wed Aug 24 18:01:28 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Wed, 24 Aug 2011 15:01:28 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E55721D.5090805@udel.edu> References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> Message-ID: On Wed, Aug 24, 2011 at 2:50 PM, Terry Reedy wrote: [...] >> You can find it at http://www.radiofreepython.com/ as of this very minute. > > What a treat. Thank you. Please announce the next one too. No, please don't announce the next one. There should be a RSS feed. But please do announce the feed at regular intervals. Michael > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Wed Aug 24 18:41:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 24 Aug 2011 15:41:18 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> Message-ID: <4E557E0E.7050602@stoneleaf.us> Michael Hunter wrote: > On Wed, Aug 24, 2011 at 2:50 PM, Terry Reedy wrote: > [...] >>> You can find it at http://www.radiofreepython.com/ as of this very minute. >> >> What a treat. Thank you. Please announce the next one too. > > No, please don't announce the next one. There should be a RSS feed. > But please do announce the feed at regular intervals. You're kidding, right? Instead of an alert for each podcast release which says, "Hey, there's something there right now!" you would rather have an alert that says, "Hey, check out this RSS feed, which may have nothing on it for another three weeks until the next podcast is ready!" ?? I vote with Terry. ~Ethan~ From tahoemph at gmail.com Wed Aug 24 18:51:28 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Wed, 24 Aug 2011 15:51:28 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E557E0E.7050602@stoneleaf.us> References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> <4E557E0E.7050602@stoneleaf.us> Message-ID: On Wed, Aug 24, 2011 at 3:41 PM, Ethan Furman wrote: [...] >> No, please don't announce the next one. ?There should be a RSS feed. >> But please do announce the feed at regular intervals. Note, I didn't say announce the feed each release. In fact, I didn't even say announce the feed in this channel. > > You're kidding, right? ?Instead of an alert for each podcast release which > says, "Hey, there's something there right now!" you would rather have an > alert that says, "Hey, check out this RSS feed, which may have nothing on it > for another three weeks until the next podcast is ready!" ?? No, you use the RSS feed to notify interested parties that a new podcast is available. You advertise the feed in a general way to get new users. Those are different things. > > I vote with Terry. Not sure how either of you was thinking but I do think the podcast author should use RSS. Michael > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Wed Aug 24 19:25:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Aug 2011 09:25:34 +1000 Subject: Announcing a new podcast: Radio Free Python References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> <4E557E0E.7050602@stoneleaf.us> Message-ID: <874o16wfwx.fsf@benfinney.id.au> Michael Hunter writes: > No, you use the RSS feed to notify interested parties that a new > podcast is available. You advertise the feed in a general way to get > new users. Those are different things. +1, except please make it a standard Atom feed instead of (or in addition to) the messy RSS. -- \ ?Very few things happen at the right time, and the rest do not | `\ happen at all. The conscientious historian will correct these | _o__) defects.? ?Mark Twain, _A Horse's Tale_ | Ben Finney From redjohn367 at gmail.com Wed Aug 24 19:29:26 2011 From: redjohn367 at gmail.com (Red John) Date: Wed, 24 Aug 2011 16:29:26 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: > "We must constantly strive to remove multiplicity from our systems; > lest it consumes us!" > > s/multiplicity/rantingrick/ and I'm in full agreement. QFT From steve+comp.lang.python at pearwood.info Wed Aug 24 20:54:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 25 Aug 2011 10:54:55 +1000 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... References: Message-ID: <4e559d60$0$29989$c3e8da3$5496439d@news.astraweb.com> Adam Jorgensen wrote: > Thanks :-) Sorry about the size, I wasn't sure what was relevant... We prefer that you don't top-post here, because it makes it hard to see context when people reply. In general, people asking questions should always try to reduce the problem to the simplest code that will demonstrate the problem. This has two huge advantages: (1) We're all volunteers here, none of us are paid to solve your problems. The more work needed to answer a question that we might not care that much about, the less likely it is that you will get good answers. The easier you make it for us, the more likely you will get many good, prompt answers. (2) Even more important... the process of cutting out all the irrelevant details and reducing the code to the smallest possible example may reveal to you what the problem is. As the old proverb goes, "solve a coder's problem, and you've solved one problem... teach a coder how to solve his own problems, and you've solved them all" *wink* I can't begin to count how many times I've started writing up a post to ask a question, and in the process of reducing the example code to the smallest it can be, I've solved it myself. -- Steven From 1248283536 at qq.com Wed Aug 24 23:34:04 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 25 Aug 2011 11:34:04 +0800 Subject: event :use command to replace bind Message-ID: here is my code ,it can run ,i want to make it simpler, to change three sentences to one, xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) i write: Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) that is to change code1 into code2 ,when you click the button"fetch",the output is : TypeError: fetch() takes exactly 2 arguments (1 given) how to revise it? code1:(it's ok) from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(event, entries): for entry in entries: print 'Input => "%s"' % entry.get() print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) lab = Label(row, width=5, text=field) ent = Entry(row) row.pack(side=TOP, fill=X) lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', partial(fetch, entries=ents)) xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) root.mainloop() code2: from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(event, entries): for entry in entries: print 'Input => "%s"' % entry.get() print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) lab = Label(row, width=5, text=field) ent = Entry(row) row.pack(side=TOP, fill=X) lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', partial(fetch, entries=ents)) Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsgroups at jiripik.com Thu Aug 25 02:26:36 2011 From: newsgroups at jiripik.com (Jiri Pik) Date: Thu, 25 Aug 2011 08:26:36 +0200 Subject: PythonAPI4FinancialData - Python code for grabbing the entire universe of Finance Yahoo tickers Message-ID: <1586553507.20110825082636@jiripik.com> Hello Python-list, for personal finance study, i found it critical to have as complete universe of yahoo tickers as possible. In fact, this seems to be a common problem if you google it. Thus, I have created a simple Python code (to be expanded shortly for all required functionality) which grabs all the tickers from Yahoo. In case you're interested, https://github.com/jiripik/PythonAPI4FinancialData. -- Jiri Pik, jiri at jiripik.com Web: http://jiripik.com, LinkedIn: http://www.linkedin.com/in/jiripik, Twitter: http://twitter.com/@JiriPik From motoom at xs4all.nl Thu Aug 25 02:27:46 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 25 Aug 2011 08:27:46 +0200 Subject: Unspecified problem sending serial data In-Reply-To: <4E557259.5060702@ieee.org> References: <4E547894.2020308@ieee.org> <4E557259.5060702@ieee.org> Message-ID: On Aug 24, 2011, at 23:51, Dave Angel wrote: > On 08/24/2011 01:05 PM, Adri?n Monkas wrote: >> What I want to do is send around 180KBytes via Serial port. Also have a look at pySerial, http://pyserial.sourceforge.net/ Greetings, -- "If you don't know, the thing to do is not to get scared, but to learn." - Ayn Rand From steve+comp.lang.python at pearwood.info Thu Aug 25 03:13:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 25 Aug 2011 17:13:07 +1000 Subject: [OT-ish] Design principles: no bool arguments Message-ID: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> One design principle often mentioned here (with a certain degree of disagreement[1]) is the idea that as a general rule, you shouldn't write functions that take a bool argument to switch between two slightly different behaviours. This is a principle often championed by the BDFL, Guido van Rossum. Here's a Javascript-centric article which discusses the same idea, and gives it a name: the Boolean Trap. http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html No doubt there are counter arguments as well. The most obvious to me is if the flag=True and flag=False functions share a lot of code, it is poor practice to implement them as two functions with two copies of almost identical code. My solution to this is a technical violation of the "Avoid Boolean Trap" principle, but only in a private function: def spam_on(arg): _spam(arg, True) def spam_off(arg): _spam(arg, False) def _spam(arg, flag): do stuff if flag: a else: b more stuff [1] This is the Internet. There's *always* a certain amount of disagreement. -- Steven From maarten.sneep at knmi.nl Thu Aug 25 03:52:38 2011 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 25 Aug 2011 00:52:38 -0700 (PDT) Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> On Aug 25, 9:13?am, Steven D'Aprano wrote: > One design principle often mentioned here (with a certain degree of > disagreement[1]) is the idea that as a general rule, you shouldn't write > functions that take a bool argument to switch between two slightly > different behaviours. > > This is a principle often championed by the BDFL, Guido van Rossum. > > Here's a Javascript-centric article which discusses the same idea, and gives > it a name: the Boolean Trap. > > http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html > > No doubt there are counter arguments as well. The most obvious to me is if > the flag=True and flag=False functions share a lot of code, it is poor > practice to implement them as two functions with two copies of almost > identical code. A simple one: C and C-like languages only have arguments, not keyword- parameters. That alone makes a world of difference. Maarten From affdfsdfdsfsd at b.com Thu Aug 25 04:25:59 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 25 Aug 2011 08:25:59 GMT Subject: bash command, get stdErr Message-ID: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Hi all! i'ld like to execute via Python this simple bash command: sudo las las is intended to be a typo for "ls" the point is that i want to see in the terminal the stderr message (that is "sorry, try again" if i insert the wrong password or "sudo: las: command not found" otherwise) i can simply do it with subprocess.POpen() or subprocess.Call() but as far as i know i have two choice: 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) in this way i catch the stderr messages BUT they are not "printed" in the terminal 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) in this way i "print" the message in the terminal but i can retrieve they (the error messages) when the command is executed it's important for me to know if the user have inserted the wrong password or i've tryied to execute a wrong/unsupported command (for example yum install in a ubuntu environment, or a typo like "las") if i use stderr=subprocess.PIPE and the user insert a wrong password, he'll get a second request of insert password without the reason for doing it (because the error message isn't printed on the terminal). This is not a big problem, he will understand he haven't inserted the right password, and if he miss the password 3 times i'll pop-up a gtk alert windows to inform him of the problem. Still, it's not good to don't give feedback of the error to the user, so i'ld like to print the stderr on terminal AND get it after the command terminate to check the problem occurred (exit status is not enough). Is there a way to accomplish this? As usual sorry for my bad english MedeoTL From stefan_ml at behnel.de Thu Aug 25 04:29:41 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Aug 2011 10:29:41 +0200 Subject: Design principles: no bool arguments In-Reply-To: <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> Message-ID: Maarten, 25.08.2011 09:52: > On Aug 25, 9:13 am, Steven D'Aprano wrote: >> One design principle often mentioned here (with a certain degree of >> disagreement[1]) is the idea that as a general rule, you shouldn't write >> functions that take a bool argument to switch between two slightly >> different behaviours. >> >> This is a principle often championed by the BDFL, Guido van Rossum. >> >> Here's a Javascript-centric article which discusses the same idea, and gives >> it a name: the Boolean Trap. >> >> http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html >> >> No doubt there are counter arguments as well. The most obvious to me is if >> the flag=True and flag=False functions share a lot of code, it is poor >> practice to implement them as two functions with two copies of almost >> identical code. > > A simple one: C and C-like languages only have arguments, not keyword- > parameters. That alone makes a world of difference. Right. It's totally unreadable to find this in the code: data1.merge_with(data2, true); Requires you to either a) know the underlying signature by heart, or b) look it up before understanding the code. It's a lot harder to argue against this: data1.merge_with(data2, overwrite_duplicates=True) Stefan From clp2 at rebertia.com Thu Aug 25 04:52:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 01:52:25 -0700 Subject: bash command, get stdErr In-Reply-To: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: > Hi all! > i'ld like to execute via Python this simple bash command: > > sudo las > > las is intended to be a typo for "ls" > > the point is that i want to see in the terminal the stderr message (that > is "sorry, try again" if i insert the wrong password or "sudo: las: > command not found" otherwise) > > i can simply do it with subprocess.POpen() or subprocess.Call() but as > far as i know i have two choice: > 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) > > in this way i catch the stderr messages BUT they are not "printed" in the > terminal > > 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) > in this way i "print" the message in the terminal but i can retrieve they > (the error messages) when the command is executed > Still, it's not good to don't give > feedback of the error to the user, so i'ld like to print the stderr on > terminal AND get it after the command terminate to check the problem > occurred (exit status is not enough). Untested: from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, stderr=PIPE) tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) # Read from tee.stdout to get any error messages Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 Cheers, Chris -- http://rebertia.com From PointedEars at web.de Thu Aug 25 05:29:01 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 25 Aug 2011 11:29:01 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> Message-ID: <1660212.aK4W3vaeNJ@PointedEars.de> Stefan Behnel wrote: > Maarten, 25.08.2011 09:52: >> On Aug 25, 9:13 am, Steven D'Aprano wrote: >>> One design principle often mentioned here (with a certain degree of >>> disagreement[1]) is the idea that as a general rule, you shouldn't write >>> functions that take a bool argument to switch between two slightly >>> different behaviours. >>> >>> This is a principle often championed by the BDFL, Guido van Rossum. >>> >>> Here's a Javascript-centric article which discusses the same idea, and >>> gives it a name: the Boolean Trap. >>> >>> http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html >>> >>> No doubt there are counter arguments as well. The most obvious to me is >>> if the flag=True and flag=False functions share a lot of code, it is >>> poor practice to implement them as two functions with two copies of >>> almost identical code. >> >> A simple one: C and C-like languages only have arguments, not keyword- >> parameters. That alone makes a world of difference. The logic is flawed, for one because keyword arguments can be emulated. For example in C, you can (and would) OR-combine binary flag constants: open("foo", O_RDONLY); instead of open("foo", TRUE); (assuming the latter function existed). Other approaches can be found in C as well: fopen("foo", "r"); In ECMAScript implementations like JavaScript (which I count as C-like), you can define the API so that it accepts object references (as explained in the article): foo(bar, {baz: true}); instead of (or in addition to) foo(bar, true); (But this is a trade-off readability vs. runtime and memory efficiency, as each time the function is called an object needs to be created, if it is not cached, and an additional property access is necessary in the function/method. Python has much the same problem, see below.) And there can hardly be an argument that W3C DOM Level 3 Events init?Event() methods are *unnecessarily* FUBAR. Even OMG IDL supports constants (as showed by the HTMLElement interface of DOM Level 2 Core), and passing of object instances to methods. > Right. It's totally unreadable to find this in the code: > > data1.merge_with(data2, true); > > Requires you to either a) know the underlying signature by heart, or b) > look it up before understanding the code. > > It's a lot harder to argue against this: > > data1.merge_with(data2, overwrite_duplicates=True) Both variants work (even in Py3) if you only define class Data(object): def merge_with(self, bar, overwrite_duplicates): pass data1 = Data() data2 = Data() You have to define class Data(object): def merge_with(self, bar, **kwargs): # do something with kwargs['overwrite_duplicates'] pass data1 = Data() data2 = Data() so that data1.merge_with(data2, True); is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 given)"). IOW, this advantage of Python in readability is not only caused by API definition, but also by how the API is used. It might turn into a disadvantage if key lookups make the code expensive memory- and runtime wise. And you will still have to know the underlying signature to name the argument. Worse, with keyword arguments you *have to* look up the documentation (i. e., it needs to be well-documented as well) to know its name (as the compiler can only tell you "kwargs"). So no doubt there are advantages to keyword arguments, but there are disadvantages, too. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From moiurmohiuddin at gmail.com Thu Aug 25 06:40:31 2011 From: moiurmohiuddin at gmail.com (waner) Date: Thu, 25 Aug 2011 03:40:31 -0700 (PDT) Subject: world most interesting event is waiting Message-ID: <765c69bb-edf7-45cd-a614-711a39104e7d@y39g2000prd.googlegroups.com> This is really funny and useful for all ,to know the basic information of home equity. Learn More for details:http://usefulfitnesstips.com/ From anand.shashwat at gmail.com Thu Aug 25 07:07:50 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 16:37:50 +0530 Subject: PUT with proxy-support Message-ID: I want to make a PUT request. I need some headers of my own ( certificates etc ) and I need to mandatorily use a proxy. Also the url is of the form http://www.xyz.com/abc and I don't have permission to put data on http://www.xyz.com while I do have permission to put data on http://www.xyz.com/abc I tried httplib, httplib2, urllib2 with no avail. I managed to do this via command line curl: $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" Is there a way to do it in python apart from using command line curl in python. The machine is RHEL4 and is giving hard time installing pycurl. -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxc at me.com Thu Aug 25 07:18:33 2011 From: maxc at me.com (Max Countryman) Date: Thu, 25 Aug 2011 07:18:33 -0400 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> Check out the python Requests module: http://docs.python-requests.org/en/latest/index.html Sent from my iPhone On Aug 25, 2011, at 7:07, Shashwat Anand wrote: > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abc and I don't have permission to put data > on http://www.xyz.com while I do have permission to put data on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in python. > The machine is RHEL4 and is giving hard time installing pycurl. > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Thu Aug 25 07:18:49 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 25 Aug 2011 13:18:49 +0200 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <4E562F99.1000301@jollybox.de> On 25/08/11 13:07, Shashwat Anand wrote: > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to > mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abc and I don't have > permission to put data > on http://www.xyz.com while I do have permission to put data > on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. What did you try? What problems did you run into? I'm sure there is a way in Python, and chances are you were already close to finding it -- show us what you tried, what actually happened, including any error messages in full, and what you wanted to happen. Thomas > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt > -T test.txt -H "sw-version: > 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H > "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in > python. > The machine is RHEL4 and is giving hard time installing pycurl. > > > From anand.shashwat at gmail.com Thu Aug 25 07:47:07 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:17:07 +0530 Subject: PUT with proxy-support In-Reply-To: <4E562F99.1000301@jollybox.de> References: <4E562F99.1000301@jollybox.de> Message-ID: On Thu, Aug 25, 2011 at 4:48 PM, Thomas Jollans wrote: > On 25/08/11 13:07, Shashwat Anand wrote: > > I want to make a PUT request. > > I need some headers of my own ( certificates etc ) and I need to > > mandatorily use a proxy. > > Also the url is of the form http://www.xyz.com/abc and I don't have > > permission to put data > > on http://www.xyz.com while I do have permission to put data > > on http://www.xyz.com/abc > > > > I tried httplib, httplib2, urllib2 with no avail. > > What did you try? What problems did you run into? > > I'm sure there is a way in Python, and chances are you were already > close to finding it -- show us what you tried, what actually happened, > including any error messages in full, and what you wanted to happen. > > Thomas > Hi Thomas, so one of my tries was: import urllib import urllib2 import httplib import httplib2 url = 'http://alatheia.zenfs.com/testing/shashwat' body_content = 'CONTENT GOES HERE' proxy = 'ca-proxy.corp.xyz.com:3128' params = { 'x-sws-version' : '1.0', 'x-sws-access' : 'public', 'User-Agent' : 'CacheSystem', 'Cache-Control' : 'public', 'Content-Type' : 'text/plain', 'App-Auth' : 'v=1;a=client.alatheia.prod;h=10.16.19.23;t=1316594650;s=AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--', } httplib2.debuglevel=4 h = httplib2.Http(proxy_info = httplib2.ProxyInfo(3, ' ca-proxy.corp.xyz.com:3128', 3128)) resp, content = h.request(url, "PUT", body=body_content, headers = params) print resp print content Output: connect: (alatheia.zenfs.com, 80) Traceback (most recent call last): File "test.py", line 29, in resp, content = h.request(url, "PUT", body=body_content, headers = params) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1436, in request (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1188, in _request (response, content) = self._conn_request(conn, request_uri, method, body, headers) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1123, in _conn_request conn.connect() File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 786, in connect self.sock.connect(sa) File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 381, in connect self.__negotiatehttp(destpair[0], destpair[1]) File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 347, in __negotiatehttp raise HTTPError((statuscode, statusline[2])) httplib2.socks.HTTPError: (403, 'Tunnel or SSL Forbidden') The reason I can trace it is because, I can use PUT on http://alatheia.zenfs.com/testing/shashwat but not on http://alatheia.zenfs.com/ however host is resolved. Again port 80 is used even when I use specific port (3128, in this case). -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Aug 25 07:49:56 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:19:56 +0530 Subject: PUT with proxy-support In-Reply-To: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> References: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> Message-ID: On Thu, Aug 25, 2011 at 4:48 PM, Max Countryman wrote: > Check out the python Requests module: > http://docs.python-requests.org/en/latest/index.html > > Python request module is not documented very well IMHO. I tried to figure how to make PUT calls, how to add proxy, how to add certificates in headers. Did not managed to find all of it. Am not sure is supports REST calls with proxy support. > Sent from my iPhone > > On Aug 25, 2011, at 7:07, Shashwat Anand wrote: > > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to > mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abcand I don't have permission to put data > on http://www.xyz.com while I do have permission to > put data on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/ > xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in > python. > The machine is RHEL4 and is giving hard time installing pycurl. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Thu Aug 25 07:52:11 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 25 Aug 2011 13:52:11 +0200 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <4E56376B.1080603@shopzeus.com> > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt > -T test.txt -H "sw-version: > 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H > "Content-Type:text/plain" If you can do it with command line curl then probably you can do it with pycurl. http://pycurl.sourceforge.net/ Best, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Aug 25 08:02:17 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:32:17 +0530 Subject: PUT with proxy-support In-Reply-To: <4E56376B.1080603@shopzeus.com> References: <4E56376B.1080603@shopzeus.com> Message-ID: On Thu, Aug 25, 2011 at 5:22 PM, Laszlo Nagy wrote: > ** > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H > "sw-version: 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > If you can do it with command line curl then probably you can do it with > pycurl. > > http://pycurl.sourceforge.net/ > Yeah. I tried that. The system is RHEL 4. So it gave me this error : src/pycurl.c:42:20: Python.h: No such file or directory src/pycurl.c:43:22: pythread.h: No such file or directory src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile pycurl." src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to compile pycurl." Apparently we need python-devel package. Following http://fedoraproject.org/wiki/EPEL/FAQ#howtouse I added EPEL software repository. sh-3.00$ yum list | grep -i python-dev sh-3.00$ sudo yum -y install python-dev Password: Setting up Install Process Setting up repositories epel [1/1] epel 100% |=========================| 3.8 kB 00:00 Reading repository metadata in from local files b1f7bfef07466e9561644aba7 100% |=========================| 841 kB 00:06 epel : ################################################## 2583/2583 Added 2583 new packages, deleted 0 old in 4.51 seconds Parsing package install arguments No Match for argument: python-dev Nothing to do Turned out that python-curl is the required package which is already installed. Still no use. sh-3.00$ yum list | grep -i python-curl python-curl.x86_64 7.12.1-1.3.el4.rf installed sh-3.00$ python Python 2.6.4 (r264:75706, Nov 9 2009, 16:32:06) [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pycurl Traceback (most recent call last): File "", line 1, in ImportError: No module named pycurl >>> Tried installing via easy_install sh-3.00$ sudo easy_install pycurl Searching for pycurl Reading http://pypi.python.org/simple/pycurl/ Reading http://pycurl.sourceforge.net/ Reading http://pycurl.sourceforge.net/download/ Best match: pycurl 7.19.0 Downloading http://pycurl.sourceforge.net/download/pycurl-7.19.0.tar.gz Processing pycurl-7.19.0.tar.gz Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2ZCa8v/pycurl-7.19.0/egg-dist-tmp-DyHFls Using curl-config (libcurl 7.12.1) src/pycurl.c:42:20: Python.h: No such file or directory src/pycurl.c:43:22: pythread.h: No such file or directory src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile pycurl." src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to compile pycurl." [... Error Clipped] error: Setup script exited with error: command '/usr/bin/gcc' failed with exit status 1 > > Best, > > Laszlo > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrei.fokau at gmail.com Thu Aug 25 08:54:43 2011 From: andrei.fokau at gmail.com (Andrei) Date: Thu, 25 Aug 2011 05:54:43 -0700 (PDT) Subject: How to run a setup command with 'pip install'? Message-ID: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> Hello, I have a trouble installing the DMSL package with pip. The package doesn't have *.c files, which must be produced with Cython by 'pyhton setup.py build_ext' command. How do I run it with 'pip install'? Please see http://stackoverflow.com/questions/7189336/ for details. Regards, Andrei From boppanas at gmail.com Thu Aug 25 09:24:46 2011 From: boppanas at gmail.com (Sirisha) Date: Thu, 25 Aug 2011 06:24:46 -0700 (PDT) Subject: Immediate Requirement for a Data Warehouse Developer Message-ID: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> Position Profile ? Senior Data Warehouse Developer Location: Detroit, MI Contact: Please send resumes to resumes at rg-llc.com or call 313.254.4631 Purpose ? Assist with analysis, design, development and implementation of projects for the corporate data warehouse ? Partner with the DBA team and other data warehouse developers to achieve the best performance and efficiency possible for our internal business customers ? Act as the Subject Matter Expert in methods, best practices and standards related to data management, data movement, conceptual and physical database design, and data warehousing business intelligence technologies ? Basic Position Requirements: What do you need to qualify as a candidate for this position? ? You need to be organized, with an ability to multi-task and prioritize multiple requests ? You need to be able to demonstrate problem-solving skills and make quick decisions ? You need to be self-driven, motivated to help, and able to perform with minimal supervision in a team environment ? You need to be receptive to ongoing feedback aimed at improving the performance of you and your team Requirements: Experience and Education requirements. Required: ? Minimum of 5 years of data warehouse analysis, design and development experience ? Minimum of 10 years of overall Information Systems experience ? Practical expertise in full lifecycle database design, including 3NF and dimensional design concepts ? Proficiency in PL/SQL coding, troubleshooting, and performance tuning ? Experience with Oracle, preferably version 10/11 Preferred ? Experience in DW specific disciplines such as Data Quality and Cleansing, Data Governance, Metadata usage and management, and Master data management. ? Knowledge of ETL tools ? specifically Oracle Data Integrator Enterprise Edition ? Knowledge of Unix Scripting and job scheduling ? Bachelor?s degree Position Outcomes & Activities: You will be measured on your ability to perform the following activities effectively ? Gather requirements: You will need to meet with internal customers so you can provide analysis and solution design to meet their requirements. ? Provide time and cost estimates: You will be measured on your ability to estimate time and cost for architecture design and development on data warehouse projects ? Provide recommendations and Implement: As the Subject Matter Expert you will be expected to make recommendations on system and architecture changes to improve performance and efficiency and see these recommendation through to implementation ? Complete development: You will need to develop solutions using Oracle, PL/SQL, Oracle Data Integrator Enterprise Edition (ODIEE). Please send resumes to resumes at rg-llc.com or call 313.254.4631 From andrei.fokau at gmail.com Thu Aug 25 09:54:18 2011 From: andrei.fokau at gmail.com (Andrei) Date: Thu, 25 Aug 2011 06:54:18 -0700 (PDT) Subject: How to run a setup command with 'pip install'? In-Reply-To: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> References: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> Message-ID: <766f3c8b-364d-46aa-ba68-21aee38e38d8@glegroupsg2000goo.googlegroups.com> 'pip install pyrex' solved the problem (credit to @jezdez) From saraanderson24 at gmail.com Thu Aug 25 10:19:07 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Thu, 25 Aug 2011 07:19:07 -0700 (PDT) Subject: WATCH WORLD`S BEST BREAK DANCE PERFORMANCE. Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S BEST BREAK DANCE PERFORMANCE. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From ting at thsu.org Thu Aug 25 10:30:31 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 07:30:31 -0700 (PDT) Subject: Run time default arguments Message-ID: What is the most common way to handle default function arguments that are set at run time, rather than at compile time? The snippet below is the current technique that I've been using, but it seems inelegant. defaults = { 'debug' : false } def doSomething (debug = None): debug = debug if debug != None else defaults['debug'] # blah blah blah Basically, I want to define a set of common defaults at the module and/ or class level but let them be overridden via function arguments. The simpler, naive approach does not work, because the argument gets set at compile time, rather than at run time. That is: def doSomething(debug = defaults['debug']) ends up being compiled into: def doSomething(debug = false) which is not the behavior I want, as I want to evaluate the argument at run time. Any better suggestions? -- // T.Hsu From arnodel at gmail.com Thu Aug 25 10:31:08 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 15:31:08 +0100 Subject: Getting a module's code object Message-ID: Hi all, In Python 3, a function f's code object can be accessed via f.__code__. I'm interested in getting a module's code object, i.e. the code that is executed when the module is run. I don't think it's accessible via the module object itself (although I would be glad if somebody proved me wrong :). In the marshal module docs [1] it is mentioned that: """ The marshal module exists mainly to support reading and writing the ?pseudo-compiled? code for Python modules of .pyc files. """ So it seems that the module's code object is marshalled into the .pyc file - so there may be a way to unmarshal it - but I can't easily find information about how to do this. Is this a good lead, or is there another way to obtained a module's code object? Thanks -- Arnaud [1] http://docs.python.org/py3k/library/marshal.html From arnodel at gmail.com Thu Aug 25 10:35:05 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 07:35:05 -0700 (PDT) Subject: Run time default arguments References: Message-ID: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> On Aug 25, 3:30?pm, t... at thsu.org wrote: > What is the most common way to handle default function arguments that > are set at run time, rather than at compile time? The snippet below is > the current technique that I've been using, but it seems inelegant. > > defaults = { 'debug' : false } > def doSomething (debug = None): > ? ? debug = debug if debug != None else defaults['debug'] > ? ? # blah blah blah You're close to the usual idiom: def doSomething(debug=None): if debug is None: debug = defaults['debug'] ... Note the use of 'is' rather than '==' HTH -- Arnaud From python at mrabarnett.plus.com Thu Aug 25 10:50:24 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Aug 2011 15:50:24 +0100 Subject: Run time default arguments In-Reply-To: References: Message-ID: <4E566130.1050409@mrabarnett.plus.com> On 25/08/2011 15:30, ting at thsu.org wrote: > What is the most common way to handle default function arguments that > are set at run time, rather than at compile time? The snippet below is > the current technique that I've been using, but it seems inelegant. > > defaults = { 'debug' : false } > def doSomething (debug = None): > debug = debug if debug != None else defaults['debug'] > # blah blah blah > > Basically, I want to define a set of common defaults at the module and/ > or class level but let them be overridden via function arguments. The > simpler, naive approach does not work, because the argument gets set > at compile time, rather than at run time. That is: > def doSomething(debug = defaults['debug']) > ends up being compiled into: > def doSomething(debug = false) > which is not the behavior I want, as I want to evaluate the argument > at run time. > > Any better suggestions? > The recommended way is: def doSomething (debug = None): if debug is None: debug = defaults['debug'] It's more lines, but clearer. From philip at semanchuk.com Thu Aug 25 10:56:17 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 25 Aug 2011 10:56:17 -0400 Subject: Immediate Requirement for a Data Warehouse Developer In-Reply-To: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> References: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> Message-ID: <5EFBF134-A4B2-4B0A-BDC6-CB6D6B0F7BF2@semanchuk.com> On Aug 25, 2011, at 9:24 AM, Sirisha wrote: > Position Profile ? Senior Data Warehouse Developer As was mentioned on the list less than 24 hours ago, please don't post job listings to this mailing list. Use the Python jobs board instead: http://www.python.org/community/jobs/ From tjreedy at udel.edu Thu Aug 25 11:03:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Aug 2011 11:03:41 -0400 Subject: [OT-ish] Design principles: no bool arguments In-Reply-To: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/25/2011 3:13 AM, Steven D'Aprano wrote: > One design principle often mentioned here (with a certain degree of > disagreement[1]) is the idea that as a general rule, you shouldn't write > functions that take a bool argument to switch between two slightly > different behaviours. > > This is a principle often championed by the BDFL, Guido van Rossum. You missed the essential caveat to his rule. See below. > Here's a Javascript-centric article which discusses the same idea, and gives > it a name: the Boolean Trap. > > http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html This was mostly about defining parameters as positional-only (which Python does not have) versus keyword-optional or keyword only. In Python, callers always have the 'keyword = BOOL' option. > No doubt there are counter arguments as well. The most obvious to me is if > the flag=True and flag=False functions share a lot of code, it is poor > practice to implement them as two functions with two copies of almost > identical code. > > My solution to this is a technical violation of the "Avoid Boolean Trap" > principle, but only in a private function: > > def spam_on(arg): > _spam(arg, True) > > def spam_off(arg): > _spam(arg, False) > > def _spam(arg, flag): > do stuff > if flag: > a > else: > b > more stuff As I think one of the comments pointed out, this now means that if I the user need to compute whether to turn off or on, I now have to write if expr: spam_on(arg) elses: spam_off(arg) (or put this on 4 lines if you prefer ;-) instead of spam_switch(expr, arg) so moving the conditional out of the function *pushes it onto every user*. Note that naming the function 'switch' and putting the bool as the first param makes it pretty obvious that True=='on', and False=='off'. As I remember, Guido only recommendeds splitting if the boolean arg is (would be) always (nearly) passed as a constant True or False. Of course, I am not sure how one forsees that at the design stage, prior to field use. -- Terry Jan Reedy From __peter__ at web.de Thu Aug 25 11:07:33 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Aug 2011 17:07:33 +0200 Subject: Getting a module's code object References: Message-ID: Arnaud Delobelle wrote: > In Python 3, a function f's code object can be accessed via f.__code__. > > I'm interested in getting a module's code object, i.e. the code that > is executed when the module is run. I don't think it's accessible via > the module object itself (although I would be glad if somebody proved > me wrong :). In the marshal module docs [1] it is mentioned that: > > """ > The marshal module exists mainly to support reading and writing the > ?pseudo-compiled? code for Python modules of .pyc files. > """ > > So it seems that the module's code object is marshalled into the .pyc > file - so there may be a way to unmarshal it - but I can't easily find > information about how to do this. > > Is this a good lead, or is there another way to obtained a module's code > object? Taken from pkgutil.py: def read_code(stream): # This helper is needed in order for the PEP 302 emulation to # correctly handle compiled files import marshal magic = stream.read(4) if magic != imp.get_magic(): return None stream.read(4) # Skip timestamp return marshal.load(stream) Alternatively you can compile the source yourself: module = compile(source, filename, "exec") From arnodel at gmail.com Thu Aug 25 11:33:55 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 16:33:55 +0100 Subject: Getting a module's code object In-Reply-To: References: Message-ID: On 25 August 2011 16:07, Peter Otten <__peter__ at web.de> wrote: > Arnaud Delobelle wrote: > >> In Python 3, a function f's code object can be accessed via f.__code__. >> >> I'm interested in getting a module's code object, [...] > > Taken from pkgutil.py: > > def read_code(stream): > ? ?# This helper is needed in order for the PEP 302 emulation to > ? ?# correctly handle compiled files > ? ?import marshal > > ? ?magic = stream.read(4) > ? ?if magic != imp.get_magic(): > ? ? ? ?return None > > ? ?stream.read(4) # Skip timestamp > ? ?return marshal.load(stream) This works fine, thanks a lot! > Alternatively you can compile the source yourself: > > module = compile(source, filename, "exec") I don't necessarily have access to the source file. -- Arnaud From stefan_ml at behnel.de Thu Aug 25 13:01:22 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Aug 2011 19:01:22 +0200 Subject: Design principles: no bool arguments In-Reply-To: <1660212.aK4W3vaeNJ@PointedEars.de> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: Thomas 'PointedEars' Lahn, 25.08.2011 11:29: > Stefan Behnel wrote: >> It's totally unreadable to find this in the code: >> >> data1.merge_with(data2, true); >> >> Requires you to either a) know the underlying signature by heart, or b) >> look it up before understanding the code. >> >> It's a lot harder to argue against this: >> >> data1.merge_with(data2, overwrite_duplicates=True) >[...] > And you will still have to know the underlying signature to name the > argument. Worse, with keyword arguments you *have to* look up the > documentation (i. e., it needs to be well-documented as well) to know its > name (as the compiler can only tell you "kwargs"). Note that code is read more often than it gets written. Stefan From emortalwatts at gmail.com Thu Aug 25 14:43:24 2011 From: emortalwatts at gmail.com (Emory Watts) Date: Thu, 25 Aug 2011 14:43:24 -0400 Subject: Disable pop up menu that triggers upon pressing tab, Message-ID: Hello, I tried to find out how to do this on my own, but searching around turned up no results. And this is the only way I saw to get a question answered. I would like know how to disable the pop up predictions menu that appears when I press tab. I would much rather just be able to tab over, and I cannot figure out how to disable the menu. Thank you for your time. Emory -------------- next part -------------- An HTML attachment was scrubbed... URL: From claird271 at gmail.com Thu Aug 25 14:48:42 2011 From: claird271 at gmail.com (Cameron Laird) Date: Thu, 25 Aug 2011 11:48:42 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 25) Message-ID: [Original draft by Gabriel Genellina.] QOTW: "Python is a programming language, not an ice cream shop." - Steven D'Aprano, 2011-08-10, on providing the language with just "more choices" Comparing the relative speed of `i += 1` and `i = i + 1` http://groups.google.com/group/comp.lang.python/browse_thread/thread/db68a23685eb03a9/ Efficiently split and process a large string: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f9122961559e747b/ Fastest way to do string concatenation: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f65e05cd3a230290/ An unexpected interaction between function scope and class namespace: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9c4435d56fdec152/ The GIL, once again: http://mail.python.org/pipermail/python-dev/2011-August/112813.html Three language proposals: allow line breaks at operators (very long thread!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/a80ffc70aeea2116/ repeat the right hand side value of assignment statements, as needed: http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cf460dc9d6262d1/ issue warnings when builtin names are hidden: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1b2dd8552aabf033/ How to generate and send mails: a step by step tutorial http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0793c1007361398/ Best practices when dealing with unknown exceptions: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d8da925e6fa03ec6/ When using extended slicing, behavior of negative stop values is not fully intuitive: http://groups.google.com/group/comp.lang.python/browse_thread/thread/29193779abef5bfb/ It's not easy to check a folder for write access on Windows: http://groups.google.com/group/comp.lang.python/browse_thread/thread/122a47fce5571322/ Advice on how long a function should be: http://groups.google.com/group/comp.lang.python/browse_thread/thread/97076160ebf0f392/ It is relatively easy to confuse the import machinery and make import fail: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3199d1e000b135d/ Non-local variables and exec/eval: a clarification http://groups.google.com/group/comp.lang.python/browse_thread/thread/9f46a4b59f525f59/ An original idea: pure-python templates using the AST http://groups.google.com/group/comp.lang.python/browse_thread/thread/827f4345d4ad5672/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From PointedEars at web.de Thu Aug 25 16:10:06 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 25 Aug 2011 22:10:06 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: <9667176.GlLmdWzCzT@PointedEars.de> Stefan Behnel wrote: > Thomas 'PointedEars' Lahn, 25.08.2011 11:29: >> Stefan Behnel wrote: >>> It's totally unreadable to find this in the code: >>> >>> data1.merge_with(data2, true); >>> >>> Requires you to either a) know the underlying signature by heart, or b) >>> look it up before understanding the code. >>> >>> It's a lot harder to argue against this: >>> >>> data1.merge_with(data2, overwrite_duplicates=True) >>[...] >> And you will still have to know the underlying signature to name the >> argument. Worse, with keyword arguments you *have to* look up the >> documentation (i. e., it needs to be well-documented as well) to know its >> name (as the compiler can only tell you "kwargs"). > > Note that code is read more often than it gets written. It is not clear to me why you completely ignored the rest of my counter-argument. As it is, yours is a weak argument. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From clp2 at rebertia.com Thu Aug 25 16:34:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 13:34:24 -0700 Subject: Disable pop up menu that triggers upon pressing tab, In-Reply-To: References: Message-ID: On Thu, Aug 25, 2011 at 11:43 AM, Emory Watts wrote: > Hello, I tried to find out how to do this on my own, but searching around > turned up no results. And this is the only way I saw to get a question > answered. I would like know how to disable the pop up predictions menu that > appears when I press tab. I would much rather just be able to tab over, and > I cannot figure out how to disable the menu. Thank you for your time. Which of the myriad Python editors or interpreters is your question in regards to? Cheers, Chris From jenn.duerr at gmail.com Thu Aug 25 16:38:28 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 25 Aug 2011 13:38:28 -0700 (PDT) Subject: Adding a ranking based on two fields Message-ID: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> Hello All, Looking for some advice/ideas on how to implement a ranking to a 'scores' field I have. So this scores field has values ranging from 1.00-4. There is also a count field. I want to add a rank field such that all the records have a unique ranking, 1 through the number of records (thousands). The rank is based on the score first, the count second. So, a record with a score of 4 and a count of 385 is ranked higher than a record with a score of 4 and a count of 213 AND higher than record with a score of 3.25 with a count of 4640. My thought was to add the unique score values to a list and loop thru the list... sort records with score=listItem, add ranking... not quite sure how to do this! Any help would be much appreciated! From clp2 at rebertia.com Thu Aug 25 16:53:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 13:53:34 -0700 Subject: Adding a ranking based on two fields In-Reply-To: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> References: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> Message-ID: On Thu, Aug 25, 2011 at 1:38 PM, noydb wrote: > Hello All, > > Looking for some advice/ideas on how to implement a ranking to a > 'scores' field I have. ?So this scores field has values ranging from > 1.00-4. ?There is also a count field. ?I want to add a rank field such > that all the records have a unique ranking, 1 through the number of > records (thousands). ?The rank is based on the score first, the count > second. ?So, a record with a score of 4 and a count of 385 is ranked > higher than a record with a score of 4 and a count of 213 AND higher > than record with a score of 3.25 with a count of 4640. > > My thought was to add the unique score values to a list and loop thru > the list... sort records with score=listItem, add ranking... not quite > sure how to do this! things = getListOfYourThings() things.sort(reverse=True, key=lambda item: (item.score, item.count)) for i, thing in enumerate(things): thing.rank = i + 1 Cheers, Chris -- http://rebertia.com From ting at thsu.org Thu Aug 25 16:54:35 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 13:54:35 -0700 (PDT) Subject: Run time default arguments References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> Message-ID: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> On Aug 25, 10:35?am, Arnaud Delobelle wrote: > You're close to the usual idiom: > > def doSomething(debug=None): > ? ? if debug is None: > ? ? ? ? debug = defaults['debug'] > ? ? ... > > Note the use of 'is' rather than '==' > HTH Hmm, from what you are saying, it seems like there's no elegant way to handle run time defaults for function arguments, meaning that I should probably write a sql-esc coalesce function to keep my code cleaner. I take it that most people who run into this situation do this? def coalesce(*args): for a in args: if a is not None: return a return None def doSomething(debug=None): debug = coalesce(debug,defaults['debug']) # blah blah blah -- // T.Hsu From navkirat.py at gmail.com Thu Aug 25 17:09:21 2011 From: navkirat.py at gmail.com (Navkirat Singh) Date: Fri, 26 Aug 2011 02:39:21 +0530 Subject: How to handle application level errors Message-ID: Hi Guys, Not sure if this is the place to ask, but I am trying find out a way to handle application level errors from a global config. Any help would be really appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 25 19:30:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 09:30:59 +1000 Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 6:54 AM, wrote: > def doSomething(debug=None): > ?debug = coalesce(debug,defaults['debug']) > ?# blah blah blah > It won't work with a True/False flag, but if you can guarantee that all real options will evaluate as True, you can use a simpler notation: def doSomething(option=None): option=option or defaults['option'] You can't explicitly set option to False/0 with this, but it is a bit cleaner (IMO - some may disagree). ChrisA From ian.g.kelly at gmail.com Thu Aug 25 20:50:37 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 25 Aug 2011 18:50:37 -0600 Subject: Design principles: no bool arguments In-Reply-To: <1660212.aK4W3vaeNJ@PointedEars.de> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: On Thu, Aug 25, 2011 at 3:29 AM, Thomas 'PointedEars' Lahn wrote: > Both variants work (even in Py3) if you only define > > class Data(object): > ?def merge_with(self, bar, overwrite_duplicates): > ? ?pass > > data1 = Data() > data2 = Data() > > You have to define > > class Data(object): > ?def merge_with(self, bar, **kwargs): > ? ?# do something with kwargs['overwrite_duplicates'] > ? ?pass > > data1 = Data() > data2 = Data() > > so that > > data1.merge_with(data2, True); > > is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 > given)"). > > IOW, this advantage of Python in readability is not only caused by API > definition, but also by how the API is used. ?It might turn into a > disadvantage if key lookups make the code expensive memory- and runtime > wise. > > And you will still have to know the underlying signature to name the > argument. ?Worse, with keyword arguments you *have to* look up the > documentation (i. e., it needs to be well-documented as well) to know its > name (as the compiler can only tell you "kwargs"). Note though that Python 3 adds actual keyword-only arguments, which address all of your points: class Data: def merge_with(self, bar, *, overwrite_duplicates): pass >>> data1.merge_with(data2, True) TypeError: merge_with() takes exactly 2 positional arguments (3 given) >>> data1.merge_with(data2) TypeError: merge_with() needs keyword-only argument overwrite_duplicates >>> data1.merge_with(data2, overwrite_duplicates=True) >>> Of course, in Python 2 that definition would be a syntax error, so you can't really take advantage of it if you need compatibility. From roy at panix.com Thu Aug 25 21:56:31 2011 From: roy at panix.com (Roy Smith) Date: Thu, 25 Aug 2011 21:56:31 -0400 Subject: [OT-ish] Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e55f604$0$29973$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > [1] This is the Internet. There's *always* a certain amount of disagreement. No there's not. From chetan.harjani at gmail.com Thu Aug 25 23:31:16 2011 From: chetan.harjani at gmail.com (Chetan Harjani) Date: Fri, 26 Aug 2011 09:01:16 +0530 Subject: Learning python reading software source code Message-ID: Hello friends, I have learned the basic syntax of python through the book HOW TO THINK LIKE A COMPUTER SCIENTIST n by reading first 10-11 chapters of Apress-BEGINNING PROGRAMMING FROM NOVICE TO PROFESSIONAL. (btw it was really very boring) I am looking forward to learn further by understanding source code of applications built in python. I guess i will begin with reading the source code of MIRO http://www.getmiro.com/ . So I am looking for suggestions on how one can understand the code better. Any specific references I should look in as I stumble upon libraries n functions while reading or just the python official docs would be enough? thanking you -- Chetan H Harjani -------------- next part -------------- An HTML attachment was scrubbed... URL: From tahoemph at gmail.com Thu Aug 25 23:59:36 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Thu, 25 Aug 2011 20:59:36 -0700 Subject: Learning python reading software source code In-Reply-To: References: Message-ID: On Thu, Aug 25, 2011 at 8:31 PM, Chetan Harjani wrote: [read book, picked miro to read through] > So I am looking for suggestions on how one can understand the code better. > Any specific references I should look in as I stumble upon libraries n > functions while reading or just the python official docs would be enough? Mess the code up. Make changes to it. Alternate between writing code, often reading code, and occasionally reading books. The act of having to mod the code and debug those modifications will lead you through many documents. But the documents on their own shouldn't usu. be your guide. A note on reading books. A book or two can be useful for learning a language. But beyond that books about specific language have quickly diminishing returns. Instead read books about high order concepts (e.g. software engineering, algorithms, problem domain specifics). Michael From saraanderson24 at gmail.com Fri Aug 26 01:11:12 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Thu, 25 Aug 2011 22:11:12 -0700 (PDT) Subject: CNN Reports World`s First Pregnant Man Ever. (Watch it) Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ CNN Reports World`s First Pregnant Man Ever. (Watch it) http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From ting at thsu.org Fri Aug 26 01:20:29 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 22:20:29 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: On Aug 23, 7:59?am, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? My suggestion is to think how you would test the function, in order to get 100% code coverage. The parts of the function that are difficult to test, those are the parts that you want to pull out into their own separate function. For example, a block of code within a conditional statement, where the test condition cannot be passed in, is a prime example of a block of code that should be pulled out into a separate function. Obviously, there are times where this is not practical - exception handling comes to mind - but that should be your rule of thumb. If a block of code is hard to test, pull it out into it's own function, so that it's easier to test. -- // T.Hsu From joho.smithury at gmail.com Fri Aug 26 01:21:56 2011 From: joho.smithury at gmail.com (John Smithury) Date: Fri, 26 Aug 2011 13:21:56 +0800 Subject: How cai i encode url Message-ID: Hi pythons. following is my code # -*- coding: utf8 -*- import urllib2 import urllib url = "http://a.shanting.mobi/????/???/list" print url p1=u"????".encode('utf8') p2=u"???".encode('utf8') encodeurl = "http://a.shanting.mobi/"+p1+"/"+p2+"/"+"list" print encodeurl mp3file = urllib2.urlopen(encodeurl) output = open("list1", "wb") output.write(mp3file.read()) output.close ----------------------------------- but error following, why? what can i encode the url? Traceback (most recent call last): File "D:/readurl.py", line 11, in mp3file = urllib2.urlopen(encodeurl) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 398, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", line 511, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python27\lib\urllib2.py", line 436, in error return self._call_chain(*args) File "C:\Python27\lib\urllib2.py", line 370, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 519, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 404: Not Found -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Aug 26 01:50:48 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Aug 2011 07:50:48 +0200 Subject: How cai i encode url References: Message-ID: John Smithury wrote: > Hi pythons. > > following is my code > > # -*- coding: utf8 -*- > import urllib2 > import urllib > > url = "http://a.shanting.mobi/????/???/list" > print url > p1=u"????".encode('utf8') > p2=u"???".encode('utf8') > encodeurl = "http://a.shanting.mobi/"+p1+"/"+p2+"/"+"list" > print encodeurl > mp3file = urllib2.urlopen(encodeurl) > output = open("list1", "wb") > output.write(mp3file.read()) > output.close > > ----------------------------------- > but error following, why? what can i encode the url? The following seems to work: # -*- coding: utf-8 -*- import urllib2 url = u"http://a.shanting.mobi/????/???/list" encoded_url = urllib2.quote(url.encode("utf-8"), safe=":/") instream = urllib2.urlopen(encoded_url) with open("list1", "wb") as outstream: outstream.write(instream.read()) From k.sahithi2862 at gmail.com Fri Aug 26 02:32:39 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 25 Aug 2011 23:32:39 -0700 (PDT) Subject: NEW UPDATES Message-ID: <9b8cb42b-68b9-4322-9a52-9efe1bab8c5b@l8g2000prd.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From affdfsdfdsfsd at b.com Fri Aug 26 03:56:26 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 07:56:26 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: > On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >> Hi all! cut > Untested: > > from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, > stderr=PIPE) > tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) > # Read from tee.stdout to get any error messages > > Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 > > Cheers, > Chris mmm, it doesn't seem to work... any other hints guys? From clp2 at rebertia.com Fri Aug 26 04:20:02 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Aug 2011 01:20:02 -0700 Subject: bash command, get stdErr In-Reply-To: <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Message-ID: On Fri, Aug 26, 2011 at 12:56 AM, Tracubik wrote: > Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: >> On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >>> Hi all! > > cut > >> Untested: >> >> from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, >> stderr=PIPE) >> tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) >> # Read from tee.stdout to get any error messages >> >> Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 > > mmm, it doesn't seem to work... How so? Seems to work in an admittedly dirt simple test where I do tee.stdout.read(). You might need to fiddle with buffering settings depending on how you're processing the output. Cheers, Chris From affdfsdfdsfsd at b.com Fri Aug 26 04:26:32 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 08:26:32 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: <4e5758b8$0$44208$4fafbaef@reader1.news.tin.it> Il Thu, 25 Aug 2011 08:25:59 +0000, Tracubik ha scritto: > Hi all! > i'ld like to execute via Python this simple bash command: > > sudo las > > las is intended to be a typo for "ls" > > the point is that i want to see in the terminal the stderr message (that > is "sorry, try again" if i insert the wrong password or "sudo: las: > command not found" otherwise) > > i can simply do it with subprocess.POpen() or subprocess.Call() but as > far as i know i have two choice: > 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) > > in this way i catch the stderr messages BUT they are not "printed" in > the terminal > > 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) > in this way i "print" the message in the terminal but i can retrieve > they (the error messages) when the command is executed maybe i've solved it: sudo las 2>&1 | tee tmp.txt in this way i redirect stderr to stdout (the terminal) and i tee it in tmp.txt. The only problem is the output and error messages are joined togheter but i think i can deal with it. :-D MedeoTL From affdfsdfdsfsd at b.com Fri Aug 26 05:20:02 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 09:20:02 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Message-ID: <4e576542$0$44208$4fafbaef@reader1.news.tin.it> Il Fri, 26 Aug 2011 01:20:02 -0700, Chris Rebert ha scritto: > On Fri, Aug 26, 2011 at 12:56 AM, Tracubik wrote: >> Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: >>> On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >>>> Hi all! >> >> cut >> >>> Untested: >>> >>> from subprocess import Popen, PIPE sudo = Popen("sudo las", >>> shell=True, >>> stderr=PIPE) >>> tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) >>> # Read from tee.stdout to get any error messages >>> >>> Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 >> >> mmm, it doesn't seem to work... > > How so? Seems to work in an admittedly dirt simple test where I do > tee.stdout.read(). > You might need to fiddle with buffering settings depending on how you're > processing the output. oh, yeah! now it work thanks! don't really know why it wasn't working yesterday, i've retried today and it work very well :-D MedeoTL From gandalf at shopzeus.com Fri Aug 26 05:45:39 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Aug 2011 11:45:39 +0200 Subject: PUT with proxy-support In-Reply-To: References: <4E56376B.1080603@shopzeus.com> Message-ID: <4E576B43.3010501@shopzeus.com> Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2ZCa8v/pycurl-7.19.0/egg-dist-tmp-DyHFls > Using curl-config (libcurl 7.12.1) > src/pycurl.c:42:20: Python.h: No such file or directory > src/pycurl.c:43:22: pythread.h: No such file or directory > src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to > compile pycurl." > src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to > compile pycurl." > [... Error Clipped] > error: Setup script exited with error: command '/usr/bin/gcc' failed > with exit status 1 I'm not familiar with red hat. But looks like this is now a sysadmin problem. I could install pycurl under freebsd and ubuntu too. I have some code that might be able to PUT through a proxy for you. Please look at the attached file. You can setup a proxy this way: import MozzillaEmulator MozzillaEmulator.DEFAULT_PROXIES = { 'http':'http://user:password at proxy.host.com:3128', 'https':'http://user:password at proxy.host.com:3128', } And here is how you use it: dl = MozillaEmulator.MozillaEmulator() put_url = "http://some_url_to_put_to" headers = {'Content-Type':'application/xml;charset=UTF-8'} data = open("some_file","rb").read() response = dl.download(put_url,data,headers,put_method=True) If you don't set the put_method flag, then it will POST instead. (But in that case, post data must be a valid post data field fields and values.) If you don't give post_data then it will GET. The PUT method was tested without a proxy, and the GET and POST methods were tested with and without proxy. Actually I have tried to do PUT through a proxy, but it didn't work. But it was a restriction on the proxy side. (As far as I can recall, the error message came from the proxy server, something about unsupported request?). So it *might* work for you, with the right proxy server that supports PUT requests. Also be aware that this version uses urllib2. Although it can use https protocol, it doesn't check the server's certificate. Good luck, Laszlo -------------- next part -------------- A non-text attachment was scrubbed... Name: MozillaEmulator.py Type: text/x-python Size: 12093 bytes Desc: not available URL: From roy at panix.com Fri Aug 26 07:15:52 2011 From: roy at panix.com (Roy Smith) Date: Fri, 26 Aug 2011 07:15:52 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , ting at thsu.org wrote: > On Aug 23, 7:59?am, smith jack wrote: > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example, how many lines should form a function? > > My suggestion is to think how you would test the function, in order to > get 100% code coverage. I'm not convinced 100% code coverage is an achievable goal for any major project. I was once involved in a serious code coverage program. We had a large body of code (100's of KLOC of C++) which we were licensing to somebody else. The customer was insisting that we do code coverage testing and set a standard of something like 80% coverage. There was a dedicated team of about 4 people working on this for the better part of a year. They never came close to 80%. More like 60%, and that was after radical surgery to eliminate dead code and branches that couldn't be reached. The hard parts are testing the code that deals with unusual error conditions caused by interfaces to the external world. The problem is, it's just damn hard to simulate all the different kinds of errors that can occur. This was network intensive code. Every call that touches the network can fail in all sorts of ways that are near impossible to simulate. We also had lots of code that tried to deal with memory exhaustion. Again, that's hard to simulate. I'm not saying code coverage testing is a bad thing. Many of the issues I mention above could have been solved with additional abstraction layers, but that adds complexity of its own. Certainly, designing a body of code to be testable from the get-go is a far superior to trying to retrofit tests to an existing code base (which is what we were doing). > The parts of the function that are difficult > to test, those are the parts that you want to pull out into their own > separate function. > > For example, a block of code within a conditional statement, where the > test condition cannot be passed in, is a prime example of a block of > code that should be pulled out into a separate function. Maybe. In general, it's certainly true that a bunch of smallish functions, each of which performs exactly one job, is easier to work with than a huge ball of spaghetti code. On the other hand, interfaces are a common cause of bugs. When you pull a hunk of code out into its own function, you create a new interface. Sometimes that adds complexity (and bugs) of its own. > Obviously, there are times where this is not practical - exception > handling comes to mind - but that should be your rule of thumb. If a > block of code is hard to test, pull it out into it's own function, so > that it's easier to test. In general, that's good advice. You'll also usually find that code which is easy to test is also easy to understand and easy to modify. From jehugaleahsa at gmail.com Fri Aug 26 08:33:29 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 05:33:29 -0700 (PDT) Subject: Mastering Python... Best Resources? Message-ID: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> I know the Python syntax pretty well. I know a lot of the libraries and tools. When I see professional Python programmer's code, I am often blown away with the code. I realized that even though I know the language, I know nothing about using it effectively. I would like to start using Python more in my professional career. Where can I find resources that will take my skills to the next level? I would prefer to watch a streaming video series, if possible. I've read quite a few books about Python. They cover a lot of topics, but none of them covered common conventions or hacks. I mean, I got good at C++ reading books by Scott Meyers, who concentrated on common idioms, things to avoid, the proper way to do things, etc. Right now, I am at that point where I know how to do write just about anything in the language. However, I still have that hesitation I get when I'm just not sure what's the right way. From rosuav at gmail.com Fri Aug 26 08:44:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 22:44:28 +1000 Subject: Mastering Python... Best Resources? In-Reply-To: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 10:33 PM, Travis Parks wrote: > I know the Python syntax pretty well. I know a lot of the libraries > and tools. When I see professional Python programmer's code, I am > often blown away with the code. I realized that even though I know the > language, I know nothing about using it effectively. I would say that there are three aspects to using Python effectively: 1) Understanding the syntax, which you've mastered. 2) Understanding the philosophy 3) Knowing algorithms. The second is more or less what you're asking for, but the language-independent third may be more useful to you. This is correct Python syntax (#1), and decently Pythonic style (#2), but a hopelessly flawed algorithm (#3): def fib(x): return fib(x-1) + fib(x-2) if x>2 else 1 Or: def fib(x): if x<3: return 1 return fib(x-1) + fib(x-2) Both versions are clean and easy to read, but neither would be what I'd call brilliant code. You can get books on algorithms from all sorts of places, and with a very few exceptions, everything you learn with apply to Python and also to every other language you use. ChrisA From anand.shashwat at gmail.com Fri Aug 26 08:51:54 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Aug 2011 18:21:54 +0530 Subject: PUT with proxy-support In-Reply-To: <4E576B43.3010501@shopzeus.com> References: <4E56376B.1080603@shopzeus.com> <4E576B43.3010501@shopzeus.com> Message-ID: On Fri, Aug 26, 2011 at 3:15 PM, Laszlo Nagy wrote: > Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-2ZCa8v/**pycurl-7.19.0/egg-dist-tmp-**DyHFls > >> Using curl-config (libcurl 7.12.1) >> src/pycurl.c:42:20: Python.h: No such file or directory >> src/pycurl.c:43:22: pythread.h: No such file or directory >> src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile >> pycurl." >> src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to >> compile pycurl." >> [... Error Clipped] >> error: Setup script exited with error: command '/usr/bin/gcc' failed with >> exit status 1 >> > I'm not familiar with red hat. But looks like this is now a sysadmin > problem. I could install pycurl under freebsd and ubuntu too. > > I have some code that might be able to PUT through a proxy for you. Please > look at the attached file. > > You can setup a proxy this way: > > import MozzillaEmulator > MozzillaEmulator.DEFAULT_**PROXIES = { > 'http':'http://user:password@**proxy.host.com:3128 > ', > 'https':'http://user:password@**proxy.host.com:3128 > ', > } > > And here is how you use it: > > dl = MozillaEmulator.**MozillaEmulator() > put_url = "http://some_url_to_put_to" > headers = {'Content-Type':'application/**xml;charset=UTF-8'} > data = open("some_file","rb").read() > response = dl.download(put_url,data,**headers,put_method=True) > > If you don't set the put_method flag, then it will POST instead. (But in > that case, post data must be a valid post data field fields and values.) If > you don't give post_data then it will GET. The PUT method was tested without > a proxy, and the GET and POST methods were tested with and without proxy. > > Actually I have tried to do PUT through a proxy, but it didn't work. But it > was a restriction on the proxy side. (As far as I can recall, the error > message came from the proxy server, something about unsupported request?). > So it *might* work for you, with the right proxy server that supports PUT > requests. > > Also be aware that this version uses urllib2. Although it can use https > protocol, it doesn't check the server's certificate. > > > Mozilla Emulator works like a charm. Also managed to install pycurl and the same works too. Thanks. :) ~Shashwat -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Fri Aug 26 08:58:46 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 05:58:46 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 26, 8:44?am, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:33 PM, Travis Parks wrote: > > I know the Python syntax pretty well. I know a lot of the libraries > > and tools. When I see professional Python programmer's code, I am > > often blown away with the code. I realized that even though I know the > > language, I know nothing about using it effectively. > > I would say that there are three aspects to using Python effectively: > > 1) Understanding the syntax, which you've mastered. > 2) Understanding the philosophy > 3) Knowing algorithms. > > The second is more or less what you're asking for, but the > language-independent third may be more useful to you. This is correct > Python syntax (#1), and decently Pythonic style (#2), but a hopelessly > flawed algorithm (#3): > > def fib(x): > ? ? return fib(x-1) + fib(x-2) if x>2 else 1 > > Or: > > def fib(x): > ? ? if x<3: return 1 > ? ? return fib(x-1) + fib(x-2) > > Both versions are clean and easy to read, but neither would be what > I'd call brilliant code. > > You can get books on algorithms from all sorts of places, and with a > very few exceptions, everything you learn with apply to Python and > also to every other language you use. > > ChrisA > > Well, I think I am going more for #2. I know about things like data structures and algorithms... in your case memoization. Here is a good example of what I am talking about. Someone took the time to write quicksort in a single line of code: def qsortr(list): return [] if list==[] else qsortr([x for x in list[1:] if x < list[0]]) + [list[0]] + qsortr([x for x in list[1:] if x >= list[0]]) I would never even think to use list comprehensions and splicing like that. I would write this code the same way I'd write it in C++/C#. I'm aware that writing code like the above example is probably bad practice (and that the implementation here has some major inefficiencies), but it is the "mentality" that goes into it. I haven't gotten to the point where I can truly use the language features to my full advantage. I haven't seen enough "tricks" to be effective. I feel like there is so much of the language I am not utilizing because I'm still thinking in terms of a less powerful language. I was hoping to find a series that would familiarize me with how real Python programmers get things done. From chetan.harjani at gmail.com Fri Aug 26 09:06:38 2011 From: chetan.harjani at gmail.com (Chetan Harjani) Date: Fri, 26 Aug 2011 18:36:38 +0530 Subject: Learning python reading software source code In-Reply-To: References: Message-ID: Thanks Michael :) . I will keep your suggestions in mind. On Fri, Aug 26, 2011 at 9:01 AM, Chetan Harjani wrote: > Hello friends, > > I have learned the basic syntax of python through the book HOW TO THINK > LIKE A COMPUTER SCIENTIST n by reading first 10-11 chapters of > Apress-BEGINNING PROGRAMMING FROM NOVICE TO PROFESSIONAL. > (btw it was really very boring) > > I am looking forward to learn further by understanding source code of > applications built in python. I guess i will begin with reading the source > code of MIRO http://www.getmiro.com/ . > > So I am looking for suggestions on how one can understand the code better. > Any specific references I should look in as I stumble upon libraries n > functions while reading or just the python official docs would be enough? > > thanking you > -- > Chetan H Harjani > > > -- Chetan H Harjani -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Fri Aug 26 09:08:45 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Aug 2011 09:08:45 -0400 Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: Chris Angelico wrote: [ ... ] > You can get books on algorithms from all sorts of places, and with a > very few exceptions, everything you learn with apply to Python and > also to every other language you use. I liked _Programming Pearls_ by Jon Bentley. No reference to Python -- that would be the O.P.'s job. Mel. From rosuav at gmail.com Fri Aug 26 09:28:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 23:28:03 +1000 Subject: Mastering Python... Best Resources? In-Reply-To: References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks wrote: > I haven't gotten to the point where I can truly use the language > features to my full advantage. I haven't seen enough "tricks" to be > effective. I feel like there is so much of the language I am not > utilizing because I'm still thinking in terms of a less powerful > language. I was hoping to find a series that would familiarize me with > how real Python programmers get things done. > Ah! Then I recommend poking around with the standard library. No guarantees that it's ALL good code, but it probably will be. In any case, it sounds like you're well able to evaluate code in your own head and recognize the good from the ugly. In the source distribution (I'm looking at the latest straight from hg, but presumably it's the same everywhere), there's a whole lot of .py files in ./Lib - there's sure to be some good examples in there somewhere. ChrisA From dreyemi at gmail.com Fri Aug 26 09:44:21 2011 From: dreyemi at gmail.com (Kayode Odeyemi) Date: Fri, 26 Aug 2011 14:44:21 +0100 Subject: Mastering Python... Best Resources? In-Reply-To: References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 2:28 PM, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks > wrote: > > I haven't gotten to the point where I can truly use the language > > features to my full advantage. I haven't seen enough "tricks" to be > > effective. I feel like there is so much of the language I am not > > utilizing because I'm still thinking in terms of a less powerful > > language. I was hoping to find a series that would familiarize me with > > how real Python programmers get things done. > > > > Ah! Then I recommend poking around with the standard library. No > guarantees that it's ALL good code, but it probably will be. In any > case, it sounds like you're well able to evaluate code in your own > head and recognize the good from the ugly. > > In the source distribution (I'm looking at the latest straight from > hg, but presumably it's the same everywhere), there's a whole lot of > .py files in ./Lib - there's sure to be some good examples in there > somewhere. > > ChrisA > As a rule of thumb, I have learnt to always make the python source my best resource. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Odeyemi 'Kayode O. http://www.sinati.com. t: @charyorde -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Fri Aug 26 10:10:34 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 07:10:34 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: <81eba77b-00b7-43bd-b8e4-988812716a51@hr10g2000vbb.googlegroups.com> On Aug 26, 9:28?am, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks wrote: > > I haven't gotten to the point where I can truly use the language > > features to my full advantage. I haven't seen enough "tricks" to be > > effective. I feel like there is so much of the language I am not > > utilizing because I'm still thinking in terms of a less powerful > > language. I was hoping to find a series that would familiarize me with > > how real Python programmers get things done. > > Ah! Then I recommend poking around with the standard library. No > guarantees that it's ALL good code, but it probably will be. In any > case, it sounds like you're well able to evaluate code in your own > head and recognize the good from the ugly. > > In the source distribution (I'm looking at the latest straight from > hg, but presumably it's the same everywhere), there's a whole lot of > .py files in ./Lib - there's sure to be some good examples in there > somewhere. > > ChrisA > > I've been thinking about going through the docs on the main website. Cool thing is it has links to the actual lib files. I was checking out string.py yesterday. I was searching all over youtube for good videos of some type. Google has an intro course, but it didn't really do much for me. Microsoft has these series called 'Going Deep' that occasionally runs something super in-depth. The videos on C++ and the STL are really excellent. I was hoping someone had taken the time to create a similar series for Python. I can't help but remember my one professor in college, who really made pointers, bitwise arithmetic and low level OS operations make sense. He explained to us a lot about how the STL worked and showed us tons of C++/STL hacks. I probably learned more in the 2 years I had classes with him than I have in all the time I've programmed. To get that type of insight into another language, like Python, would be the ultimate gift for someone like me. Personally, I am tired of working in languages that don't strongly support functional paradigms. From dboland9 at fastmail.fm Fri Aug 26 10:18:10 2011 From: dboland9 at fastmail.fm (Dave Boland) Date: Fri, 26 Aug 2011 10:18:10 -0400 Subject: Python IDE/Eclipse Message-ID: I'm looking for a good IDE -- easy to setup, easy to use -- for Python. Any suggestions? I use Eclipse for other projects and have no problem with using it for Python, except that I can't get PyDev to install. It takes forever, then produces an error that makes no sense. An error occurred while installing the items session context was:(profile=PlatformProfile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). Cannot connect to keystore. This trust engine is read only. The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. Any suggestions on getting this to work? Thanks, Dave From tdldev at gmail.com Fri Aug 26 10:43:04 2011 From: tdldev at gmail.com (Verde Denim) Date: Fri, 26 Aug 2011 10:43:04 -0400 Subject: dpkg Message-ID: I downloaded cx_oracle for installation to Ubuntu 11.04 64bit this morning, and the alien and dpkg operations worked fine, but on testing the import, the error msg shows that the oracle client lib is missing. I found a thread that mentioned installing the oracle instant client on 11.04 to resolve this, and alien and dpkg worked fine. Yet, when I go into python (runing 2.7) and import cx_Oracle, I get "ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory. Looking for this with find / -name libclntsh.so.11.1 -print produces /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 I'm confused as to why Python doesn't see it... -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Aug 26 11:12:32 2011 From: roy at panix.com (Roy Smith) Date: Fri, 26 Aug 2011 11:12:32 -0400 Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: In article <2309ec4b-e9a3-4330-9983-1c621ac16163 at ea4g2000vbb.googlegroups.com>, Travis Parks wrote: > I know the Python syntax pretty well. I know a lot of the libraries > and tools. When I see professional Python programmer's code, I am > often blown away with the code. I realized that even though I know the > language, I know nothing about using it effectively. In a sense, I'm in the same boat as you. I've been using Python since before the 2.0 series, and I tend to think of the language in much the same way as I did back then. Which is to say I don't use the language, as it currently exists, as effectively as I might. Here's some things I suggest you look at: Iterators. This is such a powerful concept. When I started with the language, iterators largely meant the difference between range() and xrange(). Now we've got a whole ecosystem which has grown up around them (x + " comprehension" for x in {'list', 'dictionary', 'set'}), not to mention generators and generator expressions. And the itertools library. Decorators. Another powerful concept. We use these in our web servers for all sorts of cool things. Adding cacheing. Imposing prerequisites on route calls. I still don't think of using these immediately, but I do see the notational convenience they provide for many things. Context Managers. One of the (very few) things that I always found lacking in Python compared to C++ was deterministic object destruction. Context managers give you this. I'm still exploring all the neat things you can do with them. The full range of containers. I started with lists, tuples, and dictionaries. Now we've got sets, frozensets, named tuples, deques, Counters, defaultdicts (I love those), heaps, and I'm sure a few others I've missed. List and dicts are such well designed containers, you can do almost anything with just those two, but all the other new ones often make things quicker, simpler, and more obvious. The profiler. Most people obsess about performance early on and don't realize that most of their guesses about what's fast and what's slow are probably wrong. Learn to use the profiler and understand what it's telling you. Unittest. Testing is, in general, a neglected practice in most software development shops, and that's a shame. Python has some really good capabilities to support testing which you should get familiar with. Unittest is just one of them. There's also doctest, nose, and a bunch of other contributed modules. Look at them all, learn at least one of them well, and use it for everything you write. > I've read quite a few books about Python. They cover a lot of topics, > but none of them covered common conventions or hacks. I mean, I got > good at C++ reading books by Scott Meyers, who concentrated on common > idioms, things to avoid, the proper way to do things, etc. Ugh. The problem with Meyers's books is that they are needed in the first place. C++ is such a horribly complicated language, you really can't use it without making a serious study of it. There's too many gotchas that you MUST know to avoid disaster with even the most basic programs. Python isn't that way. You can learn a small, basic subset of the language and get a lot done. You may not be doing things the most effective way, but you're also not going to be looking at memory corruption because you didn't understand the details of object lifetimes or how type promotion, function overloading, and implicit temporary object construction all interact. From zcdziura at gmail.com Fri Aug 26 11:17:02 2011 From: zcdziura at gmail.com (Zach Dziura) Date: Fri, 26 Aug 2011 08:17:02 -0700 (PDT) Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: <35acafee-2e39-4734-a270-2294d69e6a55@glegroupsg2000goo.googlegroups.com> I've honestly always used either PyDev or IDLE. However, Python is pretty easy to usd without a big IDE slowing you down, so you could also use a developer's text editor like Notepad++ or gedit and still be good. From kwatford at gmail.com Fri Aug 26 11:17:58 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 26 Aug 2011 11:17:58 -0400 Subject: dpkg In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 10:43 AM, Verde Denim wrote: > Looking for this with find / -name libclntsh.so.11.1 -print produces > /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 > > I'm confused as to why Python doesn't see it... Try running "sudo ldconfig". From rantingrick at gmail.com Fri Aug 26 11:20:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 08:20:43 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> On Aug 26, 6:15?am, Roy Smith wrote: > Maybe. ?In general, it's certainly true that a bunch of smallish > functions, each of which performs exactly one job, is easier to work > with than a huge ball of spaghetti code. ? Obviously you need to google the definition of "spaghetti code". When you move code out of one function and create another function you are contributing to the "spaghetti-ness" of the code. Think of plate of spaghetti and how the noodles are all intertwined and without order. Likewise when you go to one function and have to follow the trial of one or more helper functions you are creating a twisting and unordered progression of code -- sniff-sniff, do you smell what i smell? Furthermore: If you are moving code out of one function to ONLY be called by that ONE function then you are a bad programmer and should have your editor taken away for six months. You should ONLY create more func/methods if those func/methods will be called from two or more places in the code. The very essence of func/meths is the fact that they are reusable. It might still be spaghetti under that definition (of which ALL OOP code actually is!) however it will be as elegant as spaghetti can be. > On the other hand, interfaces > are a common cause of bugs. ?When you pull a hunk of code out into its > own function, you create a new interface. ?Sometimes that adds > complexity (and bugs) of its own. Which is it? You cannot have it both ways. You're straddling the fence here like a dirty politician. Yes, this subject IS black and white! From tdldev at gmail.com Fri Aug 26 11:25:12 2011 From: tdldev at gmail.com (Verde Denim) Date: Fri, 26 Aug 2011 11:25:12 -0400 Subject: dpkg In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 11:17 AM, Ken Watford wrote: > On Fri, Aug 26, 2011 at 10:43 AM, Verde Denim wrote: > > Looking for this with find / -name libclntsh.so.11.1 -print produces > > /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 > > > > I'm confused as to why Python doesn't see it... > > Try running "sudo ldconfig". > That was the missing link - thanks! works fine now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From treleven.lloyd at gmail.com Fri Aug 26 11:35:30 2011 From: treleven.lloyd at gmail.com (lblake) Date: Fri, 26 Aug 2011 08:35:30 -0700 (PDT) Subject: Unit test failing please help Message-ID: Hi I am new to python I am at bit lost as to why my unit test is failing below is the code and the unit test: class Centipede(object): legs, stomach def __init__(self): def __str__(self): return ','.join(self.stomach) def __call__(self,*args): [self.stomach.append(arg) for arg in args] #self.stomach.append(args) def __repr__(self): return ','.join(self.legs) def __setattr__(self, key, value): print("setting %s to %s" % (key, repr(value))) if key in ([]): self.legs.append(key) super(Centipede, self).__setattr__(self, key,value) unit test code: import unittest from centipede import Centipede class TestBug(unittest.TestCase): def test_stomach(self): ralph = Centipede() ralph('chocolate') ralph('bbq') ralph('cookies') ralph('salad') self.assertEquals(ralph.__str__(), 'chocolate,bbq,cookies,salad') def test_legs(self): ralph = Centipede() ralph.friends = ['Steve', 'Daniel', 'Guido'] ralph.favorite_show = "Monty Python's Flying Circus" ralph.age = '31' self.assertEquals(ralph.__repr__(),'' ) if __name__ == "__main__": unittest.main() error message generated when running the test: AttributeError: 'Centipede' object has no attribute 'legs' AttributeError: 'Centipede' object has no attribute 'stomach' Any suggestions as to where I am going wrong? From mlindo at gmail.com Fri Aug 26 11:36:37 2011 From: mlindo at gmail.com (Moises Alberto Lindo Gutarra) Date: Fri, 26 Aug 2011 10:36:37 -0500 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: I like Aptana Studio http://www.aptana.com/products/studio3 2011/8/26 Dave Boland : > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any > suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, then > produces an error that makes no sense. > > An error occurred while installing the items > ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > ?Cannot connect to keystore. > ?This trust engine is read only. > ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > not found. > > > Any suggestions on getting this to work? > > Thanks, > Dave > -- > http://mail.python.org/mailman/listinfo/python-list > -- Atte. Mois?s Alberto Lindo Gutarra Asesor - Desarrollador Java / Open Source Linux Registered User #431131 - http://counter.li.org/ Cel: (511) 995081720 - Rpm: *548913 EMail: mlindo at gmail.com MSN: mlindo at tumisolutions.com From jehugaleahsa at gmail.com Fri Aug 26 11:36:54 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 08:36:54 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: <6087b517-23ef-4e86-948b-ea327eb19677@18g2000yqu.googlegroups.com> On Aug 26, 11:12?am, Roy Smith wrote: > In article > <2309ec4b-e9a3-4330-9983-1c621ac16... at ea4g2000vbb.googlegroups.com>, > ?Travis Parks wrote: > > > I know the Python syntax pretty well. I know a lot of the libraries > > and tools. When I see professional Python programmer's code, I am > > often blown away with the code. I realized that even though I know the > > language, I know nothing about using it effectively. > > In a sense, I'm in the same boat as you. ?I've been using Python since > before the 2.0 series, and I tend to think of the language in much the > same way as I did back then. ?Which is to say I don't use the language, > as it currently exists, as effectively as I might. > > Here's some things I suggest you look at: > > Iterators. ?This is such a powerful concept. ?When I started with the > language, iterators largely meant the difference between range() and > xrange(). ?Now we've got a whole ecosystem which has grown up around > them (x + " comprehension" for x in {'list', 'dictionary', 'set'}), not > to mention generators and generator expressions. ?And the itertools > library. > > Decorators. ?Another powerful concept. ?We use these in our web servers > for all sorts of cool things. ?Adding cacheing. ?Imposing prerequisites > on route calls. ?I still don't think of using these immediately, but I > do see the notational convenience they provide for many things. > > Context Managers. ?One of the (very few) things that I always found > lacking in Python compared to C++ was deterministic object destruction. ? > Context managers give you this. ?I'm still exploring all the neat things > you can do with them. > > The full range of containers. ?I started with lists, tuples, and > dictionaries. ?Now we've got sets, frozensets, named tuples, deques, > Counters, defaultdicts (I love those), heaps, and I'm sure a few others > I've missed. ?List and dicts are such well designed containers, you can > do almost anything with just those two, but all the other new ones often > make things quicker, simpler, and more obvious. > > The profiler. ?Most people obsess about performance early on and don't > realize that most of their guesses about what's fast and what's slow are > probably wrong. ?Learn to use the profiler and understand what it's > telling you. > > Unittest. ?Testing is, in general, a neglected practice in most software > development shops, and that's a shame. ?Python has some really good > capabilities to support testing which you should get familiar with. ? > Unittest is just one of them. ?There's also doctest, nose, and a bunch > of other contributed modules. ?Look at them all, learn at least one of > them well, and use it for everything you write. > > > I've read quite a few books about Python. They cover a lot of topics, > > but none of them covered common conventions or hacks. I mean, I got > > good at C++ reading books by Scott Meyers, who concentrated on common > > idioms, things to avoid, the proper way to do things, etc. > > Ugh. ?The problem with Meyers's books is that they are needed in the > first place. ?C++ is such a horribly complicated language, you really > can't use it without making a serious study of it. ?There's too many > gotchas that you MUST know to avoid disaster with even the most basic > programs. > > Python isn't that way. ?You can learn a small, basic subset of the > language and get a lot done. ?You may not be doing things the most > effective way, but you're also not going to be looking at memory > corruption because you didn't understand the details of object lifetimes > or how type promotion, function overloading, and implicit temporary > object construction all interact. > > Thanks for the input. I had been writing my Compass project (http://compass.codeplex.com) in Pythonese. I was planning on implementing a lot of the features of MS' LINQ in Python iterators, too. I am surprised that there aren't a ton of Python libraries for general purpose algorithms. "yield" is one of my favorite keywords. :-) I will take a look at decorators especially. I see them being used for properties and other coolness. I started playing with unittest the other day. unittest.main(exit=False) <-- took me a while to find I will look at the containers, too. I have been trying to push tuple syntax support in C# for years now. Named tuples are so useful. I agree that C++ is too complicated. Bjarne should have cared less about backward compatibility with C and fixed some of the issues with it. He should have also made some of the defaults more intuitive - like ctor initializers being reorganized to the same order as the backing fields... that'll getcha. Function argument order evaluation. Oh no! It might run .00001 seconds slower on a Sparc machine! I think anal programmers like me gravitate towards C++ because we like to show how smart we are by naming off some arbitrary fact. Sure, it doesn't make development any better, but it gives us something to waste memory with. I find myself getting super excited when I get to use words like 'readonly' in C# (Mwahahah! I used a keyword no one else uses!). What drives me nuts is that Bjarne defends his language to the death. It is nice to see Guido trying to fix things in Py3. From mateusz at loskot.net Fri Aug 26 11:40:13 2011 From: mateusz at loskot.net (Mateusz Loskot) Date: Fri, 26 Aug 2011 16:40:13 +0100 Subject: Why PyImport_ExecCodeModule takes char*? Message-ID: <4E57BE5D.3080306@loskot.net> Hi, I'm wondering, why PyImport_ExecCodeModule function takes char* instead of const char*? Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org Member of ACCU, http://accu.org From gordon at panix.com Fri Aug 26 11:40:40 2011 From: gordon at panix.com (John Gordon) Date: Fri, 26 Aug 2011 15:40:40 +0000 (UTC) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: In <7b47ca17-d3f1-4d91-91d1-98421e8708cd at ea4g2000vbb.googlegroups.com> rantingrick writes: > Furthermore: If you are moving code out of one function to ONLY be > called by that ONE function then you are a bad programmer and should > have your editor taken away for six months. You should ONLY create > more func/methods if those func/methods will be called from two or > more places in the code. The very essence of func/meths is the fact > that they are reusable. That's one very important aspect of functions, yes. But there's another: abstraction. If I'm writing a module that needs to fetch user details from an LDAP server, it might be worthwhile to put all of the LDAP-specific code in its own method, even if it's only used once. That way the main module can just contain a line like this: user_info = get_ldap_results("cn=john gordon,ou=people,dc=company,dc=com") The main module keeps a high level of abstraction instead of descending into dozens or even hundreds of lines of LDAP-specific code. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From eaglebalti at gmail.com Fri Aug 26 11:44:45 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 26 Aug 2011 08:44:45 -0700 (PDT) Subject: Hot Bollwood Actresses and Hot Football Players of Spain Soccer Team Message-ID: <187ef78f-ee84-481d-a72f-fc08243c4bdd@hr10g2000vbb.googlegroups.com> Hot Bollywood Actresses and Hot Football Players of Spain Nation Soccer Team. http://bollywoodactresseshotdresses.blogspot.com/ http://spainnationalfootballteamwallpapers.blogspot.com/ From benjamin.kaplan at case.edu Fri Aug 26 11:45:18 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Aug 2011 11:45:18 -0400 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: On Aug 26, 2011 11:39 AM, "Moises Alberto Lindo Gutarra" wrote: > > I like Aptana Studio > http://www.aptana.com/products/studio3 > FYI, Aptana is just a set of extensions for Eclipse. Aptana Studio is just Eclipse with all of the Aptana extensions (including PyDev) preinstalled. > 2011/8/26 Dave Boland : > > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. Any > > suggestions? > > > > I use Eclipse for other projects and have no problem with using it for > > Python, except that I can't get PyDev to install. It takes forever, then > > produces an error that makes no sense. > > > > An error occurred while installing the items > > session context was:(profile=PlatformProfile, > > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > > Cannot connect to keystore. > > This trust engine is read only. > > The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > > not found. > > > > > > Any suggestions on getting this to work? > > > > Thanks, > > Dave > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Atte. > Mois?s Alberto Lindo Gutarra > Asesor - Desarrollador Java / Open Source > Linux Registered User #431131 - http://counter.li.org/ > Cel: (511) 995081720 - Rpm: *548913 > EMail: mlindo at gmail.com > MSN: mlindo at tumisolutions.com > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tobiah at teranews.com Fri Aug 26 11:48:28 2011 From: tobiah at teranews.com (Tobiah) Date: Fri, 26 Aug 2011 08:48:28 -0700 Subject: is there any principle when writing python function In-Reply-To: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: > Furthermore: If you are moving code out of one function to ONLY be > called by that ONE function then you are a bad programmer and should > have your editor taken away for six months. You should ONLY create > more func/methods if those func/methods will be called from two or > more places in the code. The very essence of func/meths is the fact > that they are reusable. While I understand and agree with that basic tenet, I think that the capitalized 'ONLY' is too strong. I do split out code into function for readability, even when the function will only be called from the place from which I split it out. I don't think that this adds to the 'spaghetti' factor. It can make my life much easier when I go to debug my own code years later. In python, I use a small function to block out an idea as a sort of pseudo code, although it's valid python. Then I just define the supporting functions, and the task is done: def validate_registrants(): for dude in get_registrants(): id = get_id(dude) amount_paid = get_amount_paid(dude) amount_owed = get_amount_owed(dude) if amount_paid != amount_owed(): flag(dude) I get that this cries out for a 'dude' object, but I'm just making a point. When I go back to this code, I can very quickly see what the overall flow is, and jump to the problem area by function name. The above block might expand to a couple of hundred lines if I didn't split it out like this. From eaglebalti at gmail.com Fri Aug 26 11:51:47 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 26 Aug 2011 08:51:47 -0700 (PDT) Subject: Hot Bollwood Actresses and Hot Football Players of Spain Soccer Team Message-ID: <8cdcc8bd-0361-4609-94e2-9e21604e44f9@z18g2000yqb.googlegroups.com> Hot Bollywood Actresses and Hot Football Players of Spain Nation Soccer Team. http://bollywoodactresseshotdresses.blogspot.com/ http://spainnationalfootballteamwallpapers.blogspot.com/ From tim.wintle at teamrubber.com Fri Aug 26 11:52:43 2011 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 26 Aug 2011 16:52:43 +0100 Subject: Unit test failing please help In-Reply-To: References: Message-ID: <1314373963.9006.39.camel@tim-laptop> On Fri, 2011-08-26 at 08:35 -0700, lblake wrote: > Hi I am new to python I am at bit lost as to why my unit test is > failing below is the code and the unit test: > > class Centipede(object): > legs, stomach This doesn't do what you think it does. "legs, stomach" is a statement and is not defining any variables at all. Presumably you've also got variables named legs and stomach in the module's scope - as I'd expect to see a NameError : name 'legs' is not defined. (I'd also expect a SyntaxError from having an empty __init__ function body) You probably want do write something like this: class Centipede(object): def __init__(self): self.legs = [] self.stomach = [] From gordon at panix.com Fri Aug 26 11:58:05 2011 From: gordon at panix.com (John Gordon) Date: Fri, 26 Aug 2011 15:58:05 +0000 (UTC) Subject: Unit test failing please help References: Message-ID: In lblake writes: > Hi I am new to python I am at bit lost as to why my unit test is > failing below is the code and the unit test: > class Centipede(object): > legs, stomach You aren't assigning any values to "legs" or "stomach" here. From your later code, it seems like you intend these items to start out as empty lists. This code might work better: class Centipede(object): legs = [] stomach = [] (In fact, since you aren't *assigning* anything to legs or stomach but you're simply *referencing them*, this code should have been an error because those names do not yet exist.) > def __init__(self): This __init__() method does nothing at all. It doesn't even have a pass statement, which means it isn't legal python. Your code should have produced an error here. > def __setattr__(self, key, value): > print("setting %s to %s" % (key, repr(value))) > if key in ([]): > self.legs.append(key) > super(Centipede, self).__setattr__(self, key,value) How will this if statement ever be true? You're checking if 'key' is a member of an empty list. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From smackay at flagstonesoftware.com Fri Aug 26 12:00:48 2011 From: smackay at flagstonesoftware.com (smackay at flagstonesoftware.com) Date: Fri, 26 Aug 2011 17:00:48 +0100 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: <20110826170048.37748y08q3odsnjk@flagstonesoftware.com> You can get a lot done, if not everything, with a simple editor however for me an IDE is awesome for digging around in the django internals to see how it all works. I used PyDev initially then onto emacs but finally I settled on PyCharm - it's just like PyDev except that everything works. Stuart > I like Aptana Studio > http://www.aptana.com/products/studio3 > > 2011/8/26 Dave Boland : >> I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any >> suggestions? >> >> I use Eclipse for other projects and have no problem with using it for >> Python, except that I can't get PyDev to install. ?It takes forever, then >> produces an error that makes no sense. >> >> An error occurred while installing the items >> ?session context was:(profile=PlatformProfile, >> phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, >> operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, >> action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). >> ?Cannot connect to keystore. >> ?This trust engine is read only. >> ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was >> not found. >> >> >> Any suggestions on getting this to work? >> >> Thanks, >> Dave >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Atte. > Mois?s Alberto Lindo Gutarra > Asesor - Desarrollador Java / Open Source > Linux Registered User #431131 - http://counter.li.org/ > Cel: (511) 995081720 - Rpm: *548913 > EMail: mlindo at gmail.com > MSN: mlindo at tumisolutions.com > -- > http://mail.python.org/mailman/listinfo/python-list > From PointedEars at web.de Fri Aug 26 12:09:21 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 26 Aug 2011 18:09:21 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: <1391623.i9ryzFtX3L@PointedEars.de> Ian Kelly wrote: > Thomas 'PointedEars' Lahn wrote: >> Both variants work (even in Py3) if you only define [a named argument]. >> You have to define [a keyword argument, e.g. `kwargs']. >> >> so that >> >> data1.merge_with(data2, True); >> >> is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 >> given)"). >> >> IOW, this advantage of Python in readability is not only caused by API >> definition, but also by how the API is used. It might turn into a >> disadvantage if key lookups make the code expensive memory- and runtime >> wise. >> >> And you will still have to know the underlying signature to name the >> argument. Worse, with keyword arguments you *have to* look up the >> documentation (i. e., it needs to be well-documented as well) to know its >> name (as the compiler can only tell you "kwargs"). > > Note though that Python 3 adds actual keyword-only arguments, which > address all of your points: > > class Data: > def merge_with(self, bar, *, overwrite_duplicates): > pass > >>>> data1.merge_with(data2, True) > TypeError: merge_with() takes exactly 2 positional arguments (3 given) >>>> data1.merge_with(data2) > TypeError: merge_with() needs keyword-only argument overwrite_duplicates >>>> data1.merge_with(data2, overwrite_duplicates=True) >>>> That's good to know. Thanks. > Of course, in Python 2 that definition would be a syntax error, so you > can't really take advantage of it if you need compatibility. ACK. Regards, -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rosuav at gmail.com Fri Aug 26 12:10:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 02:10:34 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 1:48 AM, Tobiah wrote: > While I understand and agree with that basic tenet, I think > that the capitalized 'ONLY' is too strong. ?I do split out > code into function for readability, even when the function > will only be called from the place from which I split it out. > This can be good and can be bad. It's good when it aids readability; it's bad when you need to pass practically the entire locals() as function arguments and/or return values. I would split the function only when both halves (caller and callee) can be given short and useful names - if you can't explain what a block of code does in a few words, it's probably a poor choice for splitting out into a function. ChrisA From PointedEars at web.de Fri Aug 26 12:37:44 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 26 Aug 2011 18:37:44 +0200 Subject: Python IDE/Eclipse References: Message-ID: <4258793.v1tGDxx7uL@PointedEars.de> Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > Any suggestions? PyDev (currently 2.2.1.2011073123, from the Aptana Studio 3.0.4 Plugin; but I can see that 2.2.2 has been released). > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. It takes forever, > then produces an error that makes no sense. > > An error occurred while installing the items > session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > Cannot connect to keystore. > This trust engine is read only. > The artifact file for > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > > Any suggestions on getting this to work? Your Eclipse version is apparently a bit old (note the build/sign date of the requested CVS package). Although PyDev is documented to work with Eclipse 3.2 to 3.7, try a newer version (but make a backup of your workspace before). Indigo (3.7) was released on 2011-06-22 CE. The corresponding CVS package version is (perhaps with updates) 3.3.400.I20110510-0800. If you use PyDev from Aptana, you have to uninstall standalone PyDev first. I can still recommend using Aptana for Eclipse 3.7 on GNU/Linux, where it is running without problems so far. However, in Eclipse 3.7 on Windows 7, after the latest Aptana update (3.0.4), PDT collided in their Content-Type settings with Aptana PHP Editor, so I had to uninstall the Aptana plugin in order to get any PHP editor working again. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rantingrick at gmail.com Fri Aug 26 14:05:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 11:05:30 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 26, 10:40?am, John Gordon wrote: > In <7b47ca17-d3f1-4d91-91d1-98421e870... at ea4g2000vbb.googlegroups.com> rantingrick writes: > > > Furthermore: If you are moving code out of one function to ONLY be > > called by that ONE function then you are a bad programmer and should > > have your editor taken away for six months. You should ONLY create > > more func/methods if those func/methods will be called from two or > > more places in the code. The very essence of func/meths is the fact > > that they are reusable. > > That's one very important aspect of functions, yes. ?But there's another: > abstraction. > [...] > The main module keeps a high level of abstraction instead of descending > into dozens or even hundreds of lines of LDAP-specific code. Exactly. I am not arguing against creating intuitive and simplistically elegant interfaces. I mean, lists *could* have only one method called apply(process, *args, **kw) which takes an argument like ("append", "value") or ("index", 42) and has a long block of logic to handle the inputs however that would be a horrible interface. So in that respect i agree. We must weigh the entire interface from an empirical perspective. However i can be sure of one point: As you increase the number of methods you also increase the mental load required to understand that particular interface. An interface with a small number of methods will not suffer too terribly from one or two extra methods however at some point more methods just equals more confusion. It is a delicate balancing act that many programmers are not agile enough to juggle elegantly. Take for instance the interface for Grep, Search, and Replace dialogs in the idlelib which span two separate modules and have a mind numbing number of methods for such remedial things as creating buttons and entrys. All three dialogs look very similar and share many similarities. Now take a look at MY simple ONE module solution. It has JUST enough methods and NOT a single more! Yes the create widgets method is fairly long (weighing in at 80+ lines with comments!) however all of this code needs to be contained in ONE and ONLY one method. Heck if i wanted to get pendantic i could replace the five cb_*() methods with partials however MY interface is so intuitive there is no need. ############################################################ # START CODE ############################################################ class FindReplaceDialog(object): def __init__(self, textbox): [...] def create_widgets(self, type_): # Create toplevel dialog window. [...] # Create widgets belonging to both # search AND replace dialogs dialogs. [...] if type_ == 'replace': # Add widgets unique to replace # dialogs. [...] elif type_ == 'grep': # Add widgets unique to grep # dialogs. [...] # Load any initial values and states. [...] def show(self, type_='find'): self.create_widgets(type_) # Do any initial setup. def close(self, event=None): # destroy the dialog. def find_again(self, event=None): # Event callback bound to textbox. def find(self, target): # Search the buffer for target and # hilight if found. def replace(self, action='replace'): # Fetch the old and new strings and # mediate the work depending on the # action. [...] if action == 'replace+find': [...] elif action == 'replaceall': [...] def grep(): [...] def cb_grepbutton(self, event=None): self.grep(target.entry.get()) def cb_findbutton(self, event=None): self.find(target.entry.get()) def cb_replacebutton(self): self.replace(action='replace') def cb_replacefindbutton(self): self.replace(action='replace+find') def cb_replaceallbutton(self): self.replace(action='replaceall') ############################################################ # END CODE ############################################################ Now look at the three modules in idlelib (Grep Dialog, Search Dialog, and Replace Dialog) and ask yourself which is cleaner? Which is more intuiitve? Which is more professional? Which would you rather debug? *scholl-bell-rings* From steve+comp.lang.python at pearwood.info Fri Aug 26 14:16:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 04:16:30 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e57e2ff$0$29984$c3e8da3$5496439d@news.astraweb.com> Tobiah wrote: > >> Furthermore: If you are moving code out of one function to ONLY be >> called by that ONE function then you are a bad programmer and should >> have your editor taken away for six months. You should ONLY create >> more func/methods if those func/methods will be called from two or >> more places in the code. The very essence of func/meths is the fact >> that they are reusable. > > While I understand and agree with that basic tenet, I think > that the capitalized 'ONLY' is too strong. I do split out > code into function for readability, even when the function > will only be called from the place from which I split it out. In other words, you disagree. Which is good, because the text you quote is terrible advice, and it is ironic that the person you quote judges others as bad programmers when his advice is so bad. I can think of at least five reasons apart from re-use why it might be appropriate to pull out code into its own function or method even if it is used in one place only: (1) Extensibility. Just earlier today I turned one method into three: def select(self): response = input(self) if response: index = self.find(response) else: index = self.default return self.menuitems[index-1] turned into: def choose(self, response): if response: index = self.find(response) else: index = self.default return self.menuitems[index-1] def raw_select(self): return input(self) def select(self): return self.choose(self.raw_select()) I did this so that subclasses could override the behaviour of each component individually, even though the caller is not expected to call raw_select or choose directly. (I may even consider making them private.) (2) Testing. It is very difficult to reach into the middle of a function and test part of it. It is very difficult to get full test coverage of big monolithic blocks of code: to ensure you test each path through a big function, the number of test cases rises exponentially. By splitting it into functions, you can test each part in isolation, which requires much less work. (3) Fault isolation. If you have a 100 line function that fails on line 73, that failure may have been introduced way back in line 16. By splitting the function up into smaller functions, you can more easily isolate where the failure comes from, by checking for violated pre- and post-conditions. (4) Maintainability. It's just easier to document and reason about a function that does one thing, than one that tries to do everything. Which would you rather work with, individual functions for: buy_ingredients clean_kitchen_work_area wash_vegetables prepare_ingredients cook_main_course fold_serviettes make_desert serve_meal do_washing_up etc., or one massive function: prepare_and_serve_five_course_meal Even if each function is only called once, maintenance is simpler if the code is broken up into more easily understood pieces. (5) Machine efficiency. This can go either way. Code takes up memory too, and it may be easier for the compiler to work with 1000 small functions than 1 big function. I've actually seen somebody write a single function so big that Python couldn't import the module, because it ran out of memory trying to compile it! (This function was *huge* -- the source code was many megabytes in size.) I don't remember the details, but refactoring the source code into smaller functions fixed it. On the other hand, if you are tight for memory, 1 big function may have less overhead than 1000 small functions; and these days, with even entry level PCs often having a GB or more of memory, it is rare to come across a function so big that the size of code matters. Even a 10,000 line function is likely to be only a couple of hundred KB in size: >>> text = '\n'.join('print x+i' for i in range(1, 10001)) >>> code = compile(text, '', 'exec') >>> sys.getsizeof(code.co_code) # size in bytes 90028 So that's four really good reasons for splitting code into functions, and one borderline one, other than code re-use. There may be others. -- Steven From greymausg at mail.com Fri Aug 26 14:39:07 2011 From: greymausg at mail.com (greymaus) Date: 26 Aug 2011 18:39:07 GMT Subject: Record seperator Message-ID: Is there an equivelent for the AWK RS in Python? as in RS='\n\n' will seperate a file at two blank line intervals -- maus . . ... NO CARRIER From darcy at druid.net Fri Aug 26 15:02:21 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Aug 2011 15:02:21 -0400 Subject: Record seperator In-Reply-To: References: Message-ID: <20110826150221.7e8b2d5a@dilbert> On 26 Aug 2011 18:39:07 GMT greymaus wrote: > > Is there an equivelent for the AWK RS in Python? > > > as in RS='\n\n' > will seperate a file at two blank line intervals open("file.txt").read().split("\n\n") -- 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+comp.lang.python at pearwood.info Fri Aug 26 15:56:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 05:56:12 +1000 Subject: Catch and name an exception in Python 2.5 + Message-ID: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> In Python 3, you can catch an exception and bind it to a name with: try: ... except ValueError, KeyError as error: pass In Python 2.5, that is written: try: ... except (ValueError, KeyError), error: pass and the "as error" form gives a SyntaxError. Python 2.6 and 2.7 accept either form. Is there any way to catch an exception and bind it to a name which will work across all Python versions from 2.5 onwards? I'm pretty sure there isn't, but I thought I'd ask just in case. -- Steven From t at jollybox.de Fri Aug 26 16:36:21 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 26 Aug 2011 22:36:21 +0200 Subject: Catch and name an exception in Python 2.5 + In-Reply-To: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E5803C5.2080003@jollybox.de> On 26/08/11 21:56, Steven D'Aprano wrote: > In Python 3, you can catch an exception and bind it to a name with: > > try: > ... > except ValueError, KeyError as error: > pass > > In Python 2.5, that is written: > > try: > ... > except (ValueError, KeyError), error: > pass > > and the "as error" form gives a SyntaxError. > > Python 2.6 and 2.7 accept either form. > > Is there any way to catch an exception and bind it to a name which will work > across all Python versions from 2.5 onwards? > > I'm pretty sure there isn't, but I thought I'd ask just in case. It's not elegant, and I haven't actually tested this, but this should work: try: ... except (ValueError, KeyError): error = sys.exc_info()[2] -- Thomas From rosuav at gmail.com Fri Aug 26 17:45:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 07:45:53 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 4:05 AM, rantingrick wrote: > Now take a look at MY simple ONE module solution. It has JUST enough > methods and NOT a single more! I disagree - create_widgets() is completely unnecessary in the presence of show(), unless it's possible to show the dialog, hide it, and then re-show it without recreating the widgets. On Sat, Aug 27, 2011 at 4:16 AM, Steven D'Aprano wrote: > I can think of at least five reasons apart from re-use why it might be > appropriate to pull out code into its own function or method even if it is > used in one place only: I'm glad you say "might be", because your five reasons aren't always reasons for refactoring. I'll play devil's advocate for a moment, because discussion is both fun and informative: :) > (1) Extensibility. Just earlier today I turned one method into three: > I did this so that subclasses could override the behaviour of each component > individually, even though the caller is not expected to call raw_select or > choose directly. (I may even consider making them private.) Definitely, but it's no value if you make every tiny thing into your own function. Sometimes the best way to code is to use lower-level functionality directly (not wrapping input() inside raw_select() for instance), and letting someone monkey-patch if they want to change your code. A judgment call. > (2) Testing. It is very difficult to reach into the middle of a function and > test part of it. ... By splitting it > into functions, you can test each part in isolation, which requires much > less work. Yes, but 100% coverage isn't that big a deal. If the function does precisely one logical thing, then you don't _need_ to test parts in isolation - you can treat it as a black box and just ensure that it's doing the right thing under various circumstances. However, this ties in nicely with your next point... > (3) Fault isolation. If you have a 100 line function that fails on line 73, > that failure may have been introduced way back in line 16. By splitting the > function up into smaller functions, you can more easily isolate where the > failure comes from, by checking for violated pre- and post-conditions. ... and here's where #2 really shines. If you break your function in two, the natural thing to do is to test each half separately, with the correct preconditions, and examine its output. If your fault was on line 16, your test for that half of the function has a chance of detecting it. I don't have a Devil's Advocate put-down for this one, save the rather weak comment that it's possible to check pre- and post-conditions without refactoring. :) > (4) Maintainability. It's just easier to document and reason about a > function that does one thing, than one that tries to do everything. Which > would you rather work with, individual functions for: > ... omnomnom ... > Even if each function is only called once, maintenance is simpler if the > code is broken up into more easily understood pieces. Yes, as long as you do the job intelligently. Goes back to what I said about naming functions - in your kitchen example, every function has a self-documenting name, which means you've broken it out more-or-less correctly. (I'd still want to have prepare_and_serve_five_course_meal() of course, but it would be calling on all the others.) Breaking something out illogically doesn't help maintainability at all - in fact, it'll make it worse. "So this function does what, exactly? And if I need to add a line of code, ought I to do it here, or over there? Does anyone else actually call this function? MIGHT someone be reaching into my module and calling this function directly? I'd better keep it... ugh." > (5) Machine efficiency. This can go either way. And that's the very best thing to say about efficiency. Ever. In C, I can write static functions and let the compiler inline them; in Java, I tried to do the same thing, and found ridiculous overheads. Ended up making a monolith rather than go through Java's overhead. But if I'd changed what VM I was running it on, that might well have changed. Profile, profile, profile. > So that's four really good reasons for splitting code into functions, and > one borderline one, other than code re-use. There may be others. I'm sure there are. But let's face it: We're programming in PYTHON. Not C, not Erlang, not Pike, not PHP. Python. If this has been the right choice, then we should assume that efficiency isn't king, but readability and maintainability probably are; so the important considerations are not "will it take two extra nanoseconds to execute" but "can my successor understand what the code's doing" and "will he, if he edits my code, have a reasonable expectation that he's not breaking stuff". These are always important. ChrisA From arnodel at gmail.com Fri Aug 26 18:20:38 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 26 Aug 2011 23:20:38 +0100 Subject: The RAISE_VARARGS opcode in Python 3 Message-ID: Hi all, Here is an extract from the dis module doc [1] """ RAISE_VARARGS(argc) Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS. """ OTOH, looking at PEP 3109: """ In Python 3, the grammar for raise statements will change from [2] raise_stmt: 'raise' [test [',' test [',' test]]] to raise_stmt: 'raise' [test] """ So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python 3, whereas it could be up to 3 in Python 2. Can anyone confirm that this is the case? In this case, I guess the dis docs need to be updated. Thank you, Arnaud [1] http://docs.python.org/py3k/library/dis.html#opcode-RAISE_VARARGS [2] http://www.python.org/dev/peps/pep-3109/#grammar-changes From rantingrick at gmail.com Fri Aug 26 18:26:37 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 15:26:37 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <681242ae-33ed-4440-8918-c7e540e0bf8c@n35g2000yqf.googlegroups.com> On Aug 26, 4:45?pm, Chris Angelico wrote: > On Sat, Aug 27, 2011 at 4:05 AM, rantingrick wrote: > > Now take a look at MY simple ONE module solution. It has JUST enough > > methods and NOT a single more! > > I disagree - create_widgets() is completely unnecessary in the > presence of show(), Well since you cannot see the underlying code i won't be too harsh on you :), but yes, i can assure you that create widgets IS necessary for readability. show() calls "self.create_widgets()" then adds a special hit tag to the text widget and sets up a modal behavior of the dialog, it's only 5-7 lines of setup code but i think the separation is warranted. Could i have rolled all the create_widgets() code into the show() method? Of course, however i do see a good reason for separation here for the sake of readability. Although i must admit, had the interface been much larger i most assuredly would have rolled it together. > unless it's possible to show the dialog, hide it, > and then re-show it without recreating the widgets. Yes the instance lives on between session to save state. Also the "find_again" binding of the text widget calls the SearchReplaceDialog.find_again() method when {CONTROL+G} event fires. > I'm sure there are. But let's face it: We're programming in PYTHON. > Not C, not Erlang, not Pike, not PHP. Python. If this has been the > right choice, then we should assume that efficiency isn't king, but > readability and maintainability probably are; so the important > considerations are not "will it take two extra nanoseconds to > execute" but "can my successor understand what the code's doing" and > "will he, if he edits my code, have a reasonable expectation that > he's not breaking stuff". These are always important. Bravo! That has to be most lucid and intelligent statement from you to date. And i must say the warm fuzzies i got from imagining the defeat D'Aprano must have felt whist reading it left me with a nice feeling. How do like them apples, D'Aprano? :-) From rantingrick at gmail.com Fri Aug 26 18:37:11 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 15:37:11 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e57e2ff$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <69798bf3-ce54-48e0-b08d-f5897862e57c@b20g2000vbz.googlegroups.com> On Aug 26, 1:16?pm, Steven D'Aprano wrote: > (3) Fault isolation. If you have a 100 line function that fails on line 73, > that failure may have been introduced way back in line 16. By splitting the > function up into smaller functions, you can more easily isolate where the > failure comes from, by checking for violated pre- and post-conditions. What's wrong Steven, are track backs too complicated for you? ############################################################ # START DUMMY SCRIPT ############################################################ def very_long_function(): max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(object) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) # print 'blah' print 'blah' print 'blah-blah' very_long_function() ############################################################ # END DUMMY SCRIPT ############################################################ Traceback (most recent call last): File "C:/Python27/test33333.py", line 48, in very_long_function() File "C:/Python27/test33333.py", line 26, in very_long_function max(object) TypeError: 'type' object is not iterable Oh the humanity! From steve+comp.lang.python at pearwood.info Fri Aug 26 21:26:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 11:26:21 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sat, Aug 27, 2011 at 4:16 AM, Steven D'Aprano > wrote: >> I can think of at least five reasons apart from re-use why it might be >> appropriate to pull out code into its own function or method even if it >> is used in one place only: > > I'm glad you say "might be", because your five reasons aren't always > reasons for refactoring. I'll play devil's advocate for a moment, > because discussion is both fun and informative: :) Naturally :) I say "might be" because I mean it: these arguments have to be weighed up against the argument against breaking code out of functions. It's easy to imagine an extreme case where there are a billion *tiny* functions, each of which does one micro-operation: def f1(x): return x + 1 def f2(x): return 3*x def f3(x): return f2(f1(x)) # instead of 3*(x+1) ... If spaghetti code (GOTOs tangled all through the code with no structure) is bad, so is ravioli code (code bundled up into tiny parcels and then thrown together higgledy-piggledy). Both cases can lead to an unmaintainable mess. Nobody is arguing that "More Functions Is Always Good". Sensible coders understand that you should seek a happy medium and not introduce more functions just for the sake of having More! Functions!. But I'm not arguing with you, we're in agreement. One last comment though: [...] > Definitely, but it's no value if you make every tiny thing into your > own function. Sometimes the best way to code is to use lower-level > functionality directly (not wrapping input() inside raw_select() for > instance), and letting someone monkey-patch if they want to change > your code. A judgment call. I agree on the first part (don't split *everything* into functions) but I think that the monkey-patch idea is tricky and dangerous in practice. The first problem is, how do you know what needs to be monkey-patched? You may not have access to the source code to read, and it may not be as obvious as "oh, it gets input from the user, so it must be calling input()". Second, even if you know what to monkey-patch, it's really hard to isolate the modification to just the method you want. By their nature, monkey- patches apply globally to the module. And if you patch the builtins module, they apply *everywhere*. So while monkey-patching can work, it's tricky to get it right and it should be left as a last resort. -- Steven From rosuav at gmail.com Fri Aug 26 21:37:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 11:37:27 +1000 Subject: is there any principle when writing python function In-Reply-To: <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 27, 2011 at 11:26 AM, Steven D'Aprano wrote: > I say "might be" because I mean it: these arguments have to be weighed up > against the argument against breaking code out of functions. It's easy to > imagine an extreme case where there are a billion *tiny* functions, each of > which does one micro-operation: > > def f1(x): return x + 1 > def f2(x): return 3*x > def f3(x): return f2(f1(x)) ?# instead of 3*(x+1) This fails the "give it a decent name" test. Can you name these functions according to what they do, as opposed to how they do it? For instance: def add_flagfall(x): return x + 1 # add a $1 flagfall to the price def add_tax(x): return 3*x # this is seriously nasty tax def real_price(x): return add_tax(add_flagfall(x)) ?# instead of 3*(x+1) This would be acceptable, because each micro-operation has real meaning. I'd prefer to do it as constants rather than functions, but at least they're justifying their names. And you're absolutely right about monkey-patching. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 26 23:45:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 13:45:29 +1000 Subject: Catch and name an exception in Python 2.5 + References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> Thomas Jollans wrote: > On 26/08/11 21:56, Steven D'Aprano wrote: >> Is there any way to catch an exception and bind it to a name which will >> work across all Python versions from 2.5 onwards? >> >> I'm pretty sure there isn't, but I thought I'd ask just in case. > > It's not elegant, and I haven't actually tested this, but this should > work: > > try: > ... > except (ValueError, KeyError): > error = sys.exc_info()[2] Great! Thanks for that, except I think you want to use [1], not [2]. -- Steven From __peter__ at web.de Sat Aug 27 02:49:53 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Aug 2011 08:49:53 +0200 Subject: The RAISE_VARARGS opcode in Python 3 References: Message-ID: Arnaud Delobelle wrote: > Here is an extract from the dis module doc [1] > > """ > RAISE_VARARGS(argc) > Raises an exception. argc indicates the number of parameters to the > raise statement, ranging from 0 to 3. The handler will find the > traceback as TOS2, the parameter as TOS1, and the exception as TOS. > """ > > OTOH, looking at PEP 3109: > > """ > In Python 3, the grammar for raise statements will change from [2] > > raise_stmt: 'raise' [test [',' test [',' test]]] > to > > raise_stmt: 'raise' [test] > """ > > So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python > 3, whereas it could be up to 3 in Python 2. It can be up to 2 in Python 3, >>> help("raise") The ``raise`` statement *********************** raise_stmt ::= "raise" [expression ["from" expression]] ... confirmed by a quick look into ceval.c: TARGET(RAISE_VARARGS) v = w = NULL; switch (oparg) { case 2: v = POP(); /* cause */ case 1: w = POP(); /* exc */ case 0: /* Fallthrough */ why = do_raise(w, v); break; default: PyErr_SetString(PyExc_SystemError, "bad RAISE_VARARGS oparg"); why = WHY_EXCEPTION; break; } break; > Can anyone confirm that > this is the case? In this case, I guess the dis docs need to be > updated. Indeed. From shenbakrishna86 at gmail.com Sat Aug 27 02:56:42 2011 From: shenbakrishna86 at gmail.com (shenba valli) Date: Fri, 26 Aug 2011 23:56:42 -0700 (PDT) Subject: comp.lang.python is a high-volume Usenet open (not moderated) newsgroup for general discussions and questions about Python. You can also access it as a ... Message-ID: comp.lang.python ? Discussions ? + new post ? About this group ? Subscribe to this group. This is a Usenet group - learn more. View this group in the new Google ... http://123maza.com/65/purple505/ From arnodel at gmail.com Sat Aug 27 03:00:34 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 08:00:34 +0100 Subject: The RAISE_VARARGS opcode in Python 3 In-Reply-To: References: Message-ID: On 27 August 2011 07:49, Peter Otten <__peter__ at web.de> wrote: > Arnaud Delobelle wrote: > >> Here is an extract from the dis module doc [1] >> >> """ >> RAISE_VARARGS(argc) >> Raises an exception. argc indicates the number of parameters to the >> raise statement, ranging from 0 to 3. The handler will find the >> traceback as TOS2, the parameter as TOS1, and the exception as TOS. >> """ >> >> OTOH, looking at PEP 3109: >> >> """ >> In Python 3, the grammar for raise statements will change from [2] >> >> raise_stmt: 'raise' [test [',' test [',' test]]] >> to >> >> raise_stmt: 'raise' [test] >> """ >> >> So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python >> 3, whereas it could be up to 3 in Python 2. > > It can be up to 2 in Python 3, > >>>> help("raise") > The ``raise`` statement > *********************** > > ? raise_stmt ::= "raise" [expression ["from" expression]] > ... > > confirmed by a quick look into ceval.c: > > ? ? ? ?TARGET(RAISE_VARARGS) > ? ? ? ? ? ?v = w = NULL; > ? ? ? ? ? ?switch (oparg) { > ? ? ? ? ? ?case 2: > ? ? ? ? ? ? ? ?v = POP(); /* cause */ > ? ? ? ? ? ?case 1: > ? ? ? ? ? ? ? ?w = POP(); /* exc */ > ? ? ? ? ? ?case 0: /* Fallthrough */ > ? ? ? ? ? ? ? ?why = do_raise(w, v); > ? ? ? ? ? ? ? ?break; > ? ? ? ? ? ?default: > ? ? ? ? ? ? ? ?PyErr_SetString(PyExc_SystemError, > ? ? ? ? ? ? ? ? ? ? ? ? ? "bad RAISE_VARARGS oparg"); > ? ? ? ? ? ? ? ?why = WHY_EXCEPTION; > ? ? ? ? ? ? ? ?break; > ? ? ? ? ? ?} > ? ? ? ? ? ?break; Thanks again, Peter! I'm out of Python practice, and I've forgotten some things like help("keyword"). Also PEP 3109 does indeed mention the raise .. from .. syntax in an example at the end. -- Arnaud From arnodel at gmail.com Sat Aug 27 03:08:20 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 08:08:20 +0100 Subject: how to format long if conditions Message-ID: Hi all, I'm wondering what advice you have about formatting if statements with long conditions (I always format my code to <80 colums) Here's an example taken from something I'm writing at the moment and how I've formatted it: if (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) What would you do? -- Arnaud From steve+comp.lang.python at pearwood.info Sat Aug 27 03:24:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 17:24:12 +1000 Subject: how to format long if conditions References: Message-ID: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Arnaud Delobelle wrote: > Hi all, > > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to <80 colums) > > Here's an example taken from something I'm writing at the moment and > how I've formatted it: > > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > What would you do? I believe that PEP 8 now suggests something like this: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): ) py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) I consider that hideous and would prefer to write this: if (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) Or even this: tmp = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) ) if tmp: py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) But perhaps the best solution is to define a helper function: def is_next(left, right): """Returns True if right is the next PyCompare to left.""" return (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) # PEP 8 version left as an exercise. # later... if is_next(left, right): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) -- Steven From hansmu at xs4all.nl Sat Aug 27 03:50:36 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 09:50:36 +0200 Subject: how to format long if conditions In-Reply-To: References: Message-ID: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> On 27/08/11 09:08:20, Arnaud Delobelle wrote: > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to<80 colums) > > Here's an example taken from something I'm writing at the moment and > how I've formatted it: > > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > What would you do? I would break after the '(' and indent the condition once and put the '):' bit on a separate line, aligned with the 'if': if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) It may look ugly, but it's very clear where the condition part ends and the 'then' part begins. -- HansM From andrei.lisnic at gmail.com Sat Aug 27 04:34:03 2011 From: andrei.lisnic at gmail.com (UncleLaz) Date: Sat, 27 Aug 2011 01:34:03 -0700 (PDT) Subject: Python IDE/Eclipse References: Message-ID: On Aug 26, 5:18?pm, Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > ? Any suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, > then produces an error that makes no sense. > > An error occurred while installing the items > ? ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). > ? ?Cannot connect to keystore. > ? ?This trust engine is read only. > ? ?The artifact file for > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > Any suggestions on getting this to work? > > Thanks, > Dave I use Aptana Studio 3, it's pretty good and it's based on eclipse From steve+comp.lang.python at pearwood.info Sat Aug 27 05:05:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 19:05:25 +1000 Subject: how to format long if conditions References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> Hans Mulder wrote: [...] > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. Immediately after the colon, surely? -- Steven From t at jollybox.de Sat Aug 27 05:57:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Sat, 27 Aug 2011 11:57:58 +0200 Subject: Catch and name an exception in Python 2.5 + In-Reply-To: <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E58BFA6.7080203@jollybox.de> On 27/08/11 05:45, Steven D'Aprano wrote: > Thomas Jollans wrote: > >> On 26/08/11 21:56, Steven D'Aprano wrote: > >>> Is there any way to catch an exception and bind it to a name which will >>> work across all Python versions from 2.5 onwards? >>> >>> I'm pretty sure there isn't, but I thought I'd ask just in case. >> >> It's not elegant, and I haven't actually tested this, but this should >> work: >> >> try: >> ... >> except (ValueError, KeyError): >> error = sys.exc_info()[2] > > Great! Thanks for that, except I think you want to use [1], not [2]. Ah, yes. Of course. From arnodel at gmail.com Sat Aug 27 06:24:33 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 11:24:33 +0100 Subject: how to format long if conditions In-Reply-To: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27 August 2011 08:24, Steven D'Aprano wrote: > Arnaud Delobelle wrote: > >> Hi all, >> >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to <80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> ? ? ? ? if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> ? ? ? ? ? ? ? ? and left.complist[-1] is right.complist[0]): >> ? ? ? ? ? ? py_and = PyCompare(left.complist + right.complist[1:]) >> ? ? ? ? else: >> ? ? ? ? ? ? py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I believe that PEP 8 now suggests something like this: > > ? ? ? ?if ( > ? ? ? ? ? ? ? ?isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ? ? ?and left.complist[-1] is right.complist[0]): > ? ? ? ? ? ?) > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > I consider that hideous and would prefer to write this: > > > ? ? ? ?if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ?and left.complist[-1] is right.complist[0]): > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > Or even this: > > ? ? ? ?tmp = ( > ? ? ? ? ? ?isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ?and left.complist[-1] is right.complist[0]) > ? ? ? ? ? ?) > ? ? ? ?if tmp: > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > But perhaps the best solution is to define a helper function: > > def is_next(left, right): > ? ?"""Returns True if right is the next PyCompare to left.""" > ? ?return (isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ?and left.complist[-1] is right.complist[0]) > ? ?# PEP 8 version left as an exercise. > > > # later... > ? ? ? ?if is_next(left, right): > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > Thanks Steven and Hans for you suggestions. For this particular instance I've decided to go for a hybrid approach: * Add two methods to PyCompare: class PyCompare(PyExpr): ... def extends(self, other): if not isinstance(other, PyCompare): return False else: return self.complist[0] == other.complist[-1] def chain(self, other): return PyCompare(self.complist + other.complist[1:]) * Rewrite the if as: if isinstance(right, PyCompare) and right.extends(left): py_and = left.chain(right) else: py_and = PyBooleanAnd(left, right) The additional benefit is to hide the implementation details of PyCompare (I suppose this could illustrate the thread on when to create functions). -- Arnaud From hansmu at xs4all.nl Sat Aug 27 06:51:16 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 12:51:16 +0200 Subject: how to format long if conditions In-Reply-To: <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e58cc24$0$2409$e4fe514c@news2.news.xs4all.nl> On 27/08/11 11:05:25, Steven D'Aprano wrote: > Hans Mulder wrote: > > [...] >> It may look ugly, but it's very clear where the condition part ends >> and the 'then' part begins. > > Immediately after the colon, surely? On the next line, actually :-) The point is, that this layout makes it very clear that the colon isn't in its usual position (at the end of the line that starts with 'if') and it is clearly visible. With the layout Arnaud originally propose, finding the colon takes longer. (Arnaud has since posted a better approach, in which the colon is back in its usual position.) -- HansM From pavlovevidence at gmail.com Sat Aug 27 07:35:21 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 27 Aug 2011 04:35:21 -0700 (PDT) Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: On Thursday, August 25, 2011 1:54:35 PM UTC-7, ti... at thsu.org wrote: > On Aug 25, 10:35?am, Arnaud Delobelle wrote: > > You're close to the usual idiom: > > > > def doSomething(debug=None): > > ? ? if debug is None: > > ? ? ? ? debug = defaults['debug'] > > ? ? ... > > > > Note the use of 'is' rather than '==' > > HTH > > Hmm, from what you are saying, it seems like there's no elegant way to > handle run time defaults for function arguments, meaning that I should > probably write a sql-esc coalesce function to keep my code cleaner. I > take it that most people who run into this situation do this? I don't; it seems kind of superfluous when "if arg is not None: arg = whatever" is just as easy to type and more straightforward to read. I could see a function like coalesce being helpful if you have a list of several options to check, though. Also, SQL doesn't give you a lot of flexibility, so coalesce is a lot more needed there. But for simple arguments in Python, I'd recommend sticking with "if arg is not None: arg = whatever" Carl Banks From ben+python at benfinney.id.au Sat Aug 27 08:04:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Aug 2011 22:04:19 +1000 Subject: how to format long if conditions References: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874o13ukl8.fsf@benfinney.id.au> Steven D'Aprano writes: > I believe that PEP 8 now Specifically the ?Indentation? section contains:: When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line. > suggests something like this: > > if ( > isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > ) > py_and = PyCompare(left.complist + right.complist[1:] > else: > py_and = PyBooleanAnd(left, right) That gives a SyntaxError. I think you mean one of these possible PEP 8 compliant forms:: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) or maybe:: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) > I consider that hideous I think both of those (once modified to conform to both the Python syntax and the PEP 8 guidelines) look clear and readable. I mildy prefer the first for being a little more elegant, but the second is slightly better for maintainability and reducing diff noise. Either one makes me happy. > and would prefer to write this: > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:] > else: > py_and = PyBooleanAnd(left, right) That one keeps tripping me up because the indentation doesn't make clear where subordinate clauses begin and end. The (current) PEP 8 rules are much better for readability in my eyes. Having said that, I'm only a recent convert to the current PEP 8 style for indentation of condition clauses. It took several heated arguments with colleagues before I was able to admit the superiority of clear indentation :-) -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From kwa at kuwata-lab.com Sat Aug 27 08:37:45 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sat, 27 Aug 2011 21:37:45 +0900 Subject: [ANN] Oktest 0.9.0 released - a new-style testing library Message-ID: Hi, I released Oktest 0.9.0. http://pypi.python.org/pypi/Oktest/ http://packages.python.org/Oktest/ Oktest is a new-style testing library for Python. :: from oktest import ok, NG ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo' # same as assertEqual(s, 'foo') ok (s) != 'foo' # same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode)) NG (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int)) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) NG ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) See http://packages.python.org/Oktest/ for details. NOTICE!! Oktest is a young project and specification may change in the future. Main Enhancements ----------------- * New '@test' decorator provided. It is simple but very powerful. Using @test decorator, you can write test description in free text instead of test method. ex:: class FooTest(unittest.TestCase): def test_1_plus_1_should_be_2(self): # not cool... self.assertEqual(2, 1+1) @test("1 + 1 should be 2") # cool! easy to read & write! def _(self): self.assertEqual(2, 1+1) * Fixture injection support by '@test' decorator. Arguments of test method are regarded as fixture names and they are injected by @test decorator automatically. Instance methods or global functions which name is 'provide_xxxx' are regarded as fixture provider (or builder) for fixture 'xxxx'. ex:: class SosTest(unittest.TestCase): ## ## fixture providers. ## def provide_member1(self): return {"name": "Haruhi"} def provide_member2(self): return {"name": "Kyon"} ## ## fixture releaser (optional) ## def release_member1(self, value): assert value == {"name": "Haruhi"} ## ## testcase which requires 'member1' and 'member2' fixtures. ## @test("validate member's names") def _(self, member1, member2): assert member1["name"] == "Haruhi" assert member2["name"] == "Kyon" Dependencies between fixtures are resolved automatically. ex:: class BarTest(unittest.TestCase): ## ## for example: ## - Fixture 'a' depends on 'b' and 'c'. ## - Fixture 'c' depends on 'd'. ## def provide_a(b, c): return b + c + ["A"] def provide_b(): return ["B"] def provide_c(d): return d + ["C"] def provide_d(): reutrn ["D"] ## ## Dependencies between fixtures are solved automatically. ## @test("dependency test") def _(self, a): assert a == ["B", "D", "C", "A"] If loop exists in dependency then @test reports error. If you want to integrate with other fixture library, see the following example:: class MyFixtureManager(object): def __init__(self): self.values = { "x": 100, "y": 200 } def provide(self, name): return self.values[name] def release(self, name, value): pass oktest.fixure_manager = MyFixtureResolver() Other Enhancements and Changes ------------------------------ * Supports command-line interface to execute test scripts. * Reporting style is changed. * New assertion method ``ok(x).attr(name, value)`` to check attribute. * New assertion method ``ok(x).length(n)``. * New feature``ok().should`` helps you to check boolean method. * 'ok(str1) == str2' displays diff if text1 != text2, even when using with unittest module. * Assertion ``raises()`` supports regular expression to check error message. * Helper functions in oktest.dummy module are now available as decorator. * 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'. * ``oktest.run()`` is changed to return number of failures and errors of tests. * ``before_each()`` and ``after_each()`` are now non-supported. * (Experimental) New function ``NOT()`` provided which is same as ``NG()``. * (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests:: See CHANGES.txt for details. http://packages.python.org/Oktest/CHANGES.txt Have a nice testing life! -- regards, makoto kuwata From k.sahithi2862 at gmail.com Sat Aug 27 09:28:44 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 27 Aug 2011 06:28:44 -0700 (PDT) Subject: ADULT HOT PICS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From jason.swails at gmail.com Sat Aug 27 09:42:57 2011 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 27 Aug 2011 09:42:57 -0400 Subject: typing question Message-ID: Hello everyone, This is probably a basic question with an obvious answer, but I don't quite get why the type(foo).__name__ works differently for some class instances and not for others. If I have an "underived" class, any instance of that class is simply of type "instance". If I include an explicit base class, then its type __name__ is the name of the class. $ python Python 2.7.2 (default, Aug 26 2011, 22:35:24) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class MyClass: ... pass ... >>> foo = MyClass() >>> type(foo) >>> type(foo).__name__ 'instance' >>> class MyClass1(): ... pass ... >>> bar = MyClass1() >>> type(bar) >>> type(bar).__name__ 'instance' >>> class MyClass2(object): ... pass ... >>> foobar = MyClass2() >>> type(foobar) >>> type(foobar).__name__ 'MyClass2' I can't explain this behavior (since doesn't every class inherit from object by default? And if so, there should be no difference between any of my class definitions). I would prefer that every approach give me the name of the class (rather than the first 2 just return 'instance'). Why is this not the case? Also, is there any way to access the name of the of the class type foo or bar in the above example? Thanks! Jason P.S. I'll note that my "preferred" behavior is how python3.2 actually operates $ python3.2 Python 3.2.1 (default, Aug 26 2011, 23:20:19) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class MyClass: ... pass ... >>> foo = MyClass() >>> type(foo).__name__ 'MyClass' -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 27 09:46:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 23:46:14 +1000 Subject: typing question In-Reply-To: References: Message-ID: On Sat, Aug 27, 2011 at 11:42 PM, Jason Swails wrote: > I can't explain this behavior (since doesn't every class inherit from object > by default? And if so, there should be no difference between any of my class > definitions). That is true in Python 3, but not in Python 2. That's why your example works perfectly in version 3.2. Be explicit about deriving from object and your code should work fine in both versions. Chris Angelico From 1jason.whatford at gmail.com Sat Aug 27 09:55:28 2011 From: 1jason.whatford at gmail.com (J) Date: Sat, 27 Aug 2011 06:55:28 -0700 (PDT) Subject: UnicodeEncodeError -- 'character maps to ' Message-ID: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> Hi there, I'm attempting to print a dictionary entry of some twitter data to screen but every now and then I get the following error: (, UnicodeEncodeError('charmap', u'RT @ciaraluvsjb26: BIEBER FEVER \u2665', 32, 33, 'character maps to '), ) I have googled this but haven't really found any way to overcome the error. Any ideas? J From steve+comp.lang.python at pearwood.info Sat Aug 27 11:00:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 01:00:20 +1000 Subject: UnicodeEncodeError -- 'character maps to ' References: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> Message-ID: <4e590684$0$29972$c3e8da3$5496439d@news.astraweb.com> J wrote: > Hi there, > > I'm attempting to print a dictionary entry of some twitter data to screen > but every now and then I get the following error: > > (, UnicodeEncodeError('charmap', > u'RT @ciaraluvsjb26: BIEBER FEVER \u2665', 32, 33, 'character maps to > '), ) Showing the actual traceback will help far more than a raw exception tuple. > I have googled this but haven't really found any way to overcome the > error. Any ideas? I can only try to guess what you are doing, since you haven't shown either any code or a traceback, but I can imagine that you're probably trying to encode a Unicode string into bytes, but using the wrong encoding. I can almost replicate the error: the exception is the same, the message is not, although it is similar. >>> s = u'BIEBER FEVER \u2665' >>> print s # Printing Unicode is fine. BIEBER FEVER ? >>> s.encode() # but encoding defaults to ASCII Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u2665' in position 13: ordinal not in range(128) The right way is to specify an encoding that includes all the characters you need. Unless you have some reason to choose another encoding, the best thing to do is to just use UTF-8. >>> s.encode('utf-8') 'BIEBER FEVER \xe2\x99\xa5' -- Steven From cjw at ncf.ca Sat Aug 27 11:16:51 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 11:16:51 -0400 Subject: how to format long if conditions In-Reply-To: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E590A63.3060906@ncf.ca> On 27-Aug-11 03:50 AM, Hans Mulder wrote: > On 27/08/11 09:08:20, Arnaud Delobelle wrote: >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to<80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0]): >> py_and = PyCompare(left.complist + right.complist[1:]) >> else: >> py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I would break after the '(' and indent the condition once and > put the '):' bit on a separate line, aligned with the 'if': > > > if ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > ): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. > > -- HansM What about: cond= isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] py_and= PyCompare(left.complist + right.complist[1:])if cond else: py_and = PyBooleanAnd(left, right) Colin W. From cjw at ncf.ca Sat Aug 27 11:16:51 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 11:16:51 -0400 Subject: how to format long if conditions In-Reply-To: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E590A63.3060906@ncf.ca> On 27-Aug-11 03:50 AM, Hans Mulder wrote: > On 27/08/11 09:08:20, Arnaud Delobelle wrote: >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to<80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0]): >> py_and = PyCompare(left.complist + right.complist[1:]) >> else: >> py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I would break after the '(' and indent the condition once and > put the '):' bit on a separate line, aligned with the 'if': > > > if ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > ): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. > > -- HansM What about: cond= isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] py_and= PyCompare(left.complist + right.complist[1:])if cond else: py_and = PyBooleanAnd(left, right) Colin W. From hansmu at xs4all.nl Sat Aug 27 11:53:48 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 17:53:48 +0200 Subject: how to format long if conditions In-Reply-To: References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> On 27/08/11 17:16:51, Colin J. Williams wrote: > What about: > cond= isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > py_and= PyCompare(left.complist + right.complist[1:])if cond > else: py_and = PyBooleanAnd(left, right) > Colin W. That's a syntax error. You need to add parenthesis. How about: cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) -- HansM From roy at panix.com Sat Aug 27 12:39:02 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 12:39:02 -0400 Subject: how to format long if conditions References: Message-ID: In article , Arnaud Delobelle wrote: > Hi all, > > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to <80 colums) > [...] > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) To tie this into the ongoing, "When should I write a new function?" discussion, maybe the right thing here is to refactor all of that mess into its own function, so the code looks like: if _needs_compare(left, right): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) and then def _needs_compare(left, right): "Decide if we need to call PyCompare" return isinstance(left, PyCompare) and \ isinstance(right, PyCompare) and \ left.complist[-1] is right.complist[0] This seems easier to read/understand than what you've got now. It's an even bigger win if this will get called from multiple places. From roy at panix.com Sat Aug 27 12:41:36 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 12:41:36 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: Chris Angelico wrote: > the important > considerations are not "will it take two extra nanoseconds to execute" > but "can my successor understand what the code's doing" and "will he, > if he edits my code, have a reasonable expectation that he's not > breaking stuff". These are always important. Forget about your successor. Will *you* be able to figure out what you did 6 months from now? I can't tell you how many times I've looked at some piece of code, muttered, "Who wrote this crap?" and called up the checkin history only to discover that *I* wrote it :-) From Joshua.R.English at gmail.com Sat Aug 27 12:42:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 09:42:44 -0700 (PDT) Subject: Understanding .pth files Message-ID: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> I am developing a library for Python 2.7. I'm on Windows XP. I am also learning the "proper" way to do this (per PyPi) but not in a linear fashion: I've built a prototype for the library, created my setup script, and run the install to make sure I had that bit working properly. Now I'm continuing to develop the library alongside my examples and applications that use this library. The source is at c:\Dev\XmlDB. The installed package in in c:\Python27\lib\site-packages\xmldb\ According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder. (Otherwise I have my dev folder, but end up doing actual library development in the site-packages folder) So my C:\Python27\lib\site-packages\xmldb.pth file has one line: c:\dev\XmlDB\xmldb (I've tried the slashes the other way, too, but it doesn't seem to work). Is the only solution to delete the installed library and add the dev folder to my site.py file? Josh From Joshua.R.English at gmail.com Sat Aug 27 12:56:40 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 09:56:40 -0700 (PDT) Subject: Understanding .pth in site-packages Message-ID: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> (This may be a shortened double post) I have a development version of a library in c:\dev\XmlDB\xmldb After testing the setup script I also have c:\python27\lib\site-packages\xmldb Now I'm continuing to develop it and simultaneously building an application with it. I thought I could plug into my site-packages directory a file called xmldb.pth with: c:\dev\XmlDB\xmldb which should redirect import statements to the development version of the library. This doesn't seem to work. Is there a better way to redirect import statements without messing with the system path or the PYTHONPATH variable? Josh From rosuav at gmail.com Sat Aug 27 12:57:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 02:57:50 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:41 AM, Roy Smith wrote: > Forget about your successor. ?Will *you* be able to figure out what you > did 6 months from now? ?I can't tell you how many times I've looked at > some piece of code, muttered, "Who wrote this crap?" and called up the > checkin history only to discover that *I* wrote it :-) Heh. In that case, you were your own successor :) I always word it as a different person to dodge the "But I'll remember!" excuse, but you are absolutely right, and I've had that exact same experience myself. Fred comes up to me and says, "How do I use FooMatic?" Me: "I dunno, ask Joe." Fred: "But didn't you write it?" Me: "Yeah, that was years ago, I've forgotten. Ask Joe, he still uses the program." ChrisA From greymausg at mail.com Sat Aug 27 12:59:52 2011 From: greymausg at mail.com (greymaus) Date: 27 Aug 2011 16:59:52 GMT Subject: Record seperator References: Message-ID: On 2011-08-26, D'Arcy J.M. Cain wrote: > On 26 Aug 2011 18:39:07 GMT > greymaus wrote: >> >> Is there an equivelent for the AWK RS in Python? >> >> >> as in RS='\n\n' >> will seperate a file at two blank line intervals > > open("file.txt").read().split("\n\n") > Ta!.. bit awkard. :)))))) -- maus . . ... NO CARRIER From Ric at rdo Sat Aug 27 13:03:45 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 13:03:45 -0400 Subject: Arrange files according to a text file Message-ID: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Hello, What would be the best way to accomplish this task? I have many files in separate directories, each file name contain a persons name but never in the same spot. I need to find that name which is listed in a large text file in the following format. Last name, comma and First name. The last name could be duplicate. Adler, Jack Smith, John Smith, Sally Stone, Mark etc. The file names don't necessary follow any standard format. Smith, John - 02-15-75 - business files.doc Random Data - Adler Jack - expenses.xls More Data Mark Stone files list.doc etc I need some way to pull the name from the file name, find it in the text list and then create a directory based on the name on the list "Smith, John" and move all files named with the clients name into that directory. From philip at semanchuk.com Sat Aug 27 13:18:38 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 13:18:38 -0400 Subject: Understanding .pth in site-packages In-Reply-To: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <7C05C625-CD4F-453F-AC3B-BD28516AAF37@semanchuk.com> On Aug 27, 2011, at 12:56 PM, Josh English wrote: > (This may be a shortened double post) > > I have a development version of a library in c:\dev\XmlDB\xmldb > > After testing the setup script I also have c:\python27\lib\site-packages\xmldb > > Now I'm continuing to develop it and simultaneously building an application with it. > > I thought I could plug into my site-packages directory a file called xmldb.pth with: > > c:\dev\XmlDB\xmldb > > which should redirect import statements to the development version of the library. > > This doesn't seem to work. xmldb.pth should contain the directory that contains xmldb: c:\dev\XmlDB Examining sys.path at runtime probably would have helped you to debug the effect of your .pth file. On another note, I don't know if the behavior of 'import xmldb' is defined when xmldb is present both as a directory in site-pacakges and also as a .pth file. You're essentially giving Python two choices from where to import xmldb, and I don't know which Python will choose. It may be arbitrary. I've looked for some sort of statement on this topic in the documentation, but haven't come across it yet. > Is there a better way to redirect import statements without messing with the system path or the PYTHONPATH variable? Personally I have never used PYTHONPATH. Hope this helps Philip From python at mrabarnett.plus.com Sat Aug 27 13:22:58 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Aug 2011 18:22:58 +0100 Subject: Arrange files according to a text file In-Reply-To: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E5927F2.1010906@mrabarnett.plus.com> On 27/08/2011 18:03, Ric at rdo.python.org wrote: > Hello, > > What would be the best way to accomplish this task? > I have many files in separate directories, each file name > contain a persons name but never in the same spot. > I need to find that name which is listed in a large > text file in the following format. Last name, comma > and First name. The last name could be duplicate. > > Adler, Jack > Smith, John > Smith, Sally > Stone, Mark > etc. > > > The file names don't necessary follow any standard > format. > > Smith, John - 02-15-75 - business files.doc > Random Data - Adler Jack - expenses.xls > More Data Mark Stone files list.doc > etc > > I need some way to pull the name from the file name, find it in the > text list and then create a directory based on the name on the list > "Smith, John" and move all files named with the clients name into that > directory. I would get a name from the text file, eg. "Adler, Jack", and then identify all the files which contain "Adler, Jack" or "Adler Jack" or "Jack Adler" in the filename, also checking the surrounding characters to ensure that I don't split a name, eg. that "John" isn't part of "Johnson". From steve+comp.lang.python at pearwood.info Sat Aug 27 13:24:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 03:24:34 +1000 Subject: Record seperator References: Message-ID: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> greymaus wrote: > On 2011-08-26, D'Arcy J.M. Cain wrote: >> On 26 Aug 2011 18:39:07 GMT >> greymaus wrote: >>> >>> Is there an equivelent for the AWK RS in Python? >>> >>> >>> as in RS='\n\n' >>> will seperate a file at two blank line intervals >> >> open("file.txt").read().split("\n\n") >> > > > Ta!.. bit awkard. :)))))) Er, is that meant to be a pun? "Awk[w]ard", as in awk-ward? In any case, no, the Python line might be a handful of characters longer than the AWK equivalent, but it isn't awkward. It is logical and easy to understand. It's embarrassingly easy to describe what it does: open("file.txt") # opens the file .read() # reads the contents of the file .split("\n\n") # splits the text on double-newlines. The only tricky part is knowing that \n means newline, but anyone familiar with C, Perl, AWK etc. should know that. The Python code might be "long" (but only by the standards of AWK, which can be painfully concise), but it is simple, obvious and readable. A few extra characters is the price you pay for making your language readable. At the cost of a few extra key presses, you get something that you will be able to understand in 10 years time. AWK is a specialist text processing language. Python is a general scripting and programming language. They have different values: AWK values short, concise code, Python is willing to pay a little more in source code. -- Steven From emile at fenx.com Sat Aug 27 13:27:48 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 10:27:48 -0700 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On 8/27/2011 9:41 AM Roy Smith said... > Chris Angelico wrote: > >> the important >> considerations are not "will it take two extra nanoseconds to execute" >> but "can my successor understand what the code's doing" and "will he, >> if he edits my code, have a reasonable expectation that he's not >> breaking stuff". These are always important. > > Forget about your successor. Will *you* be able to figure out what you > did 6 months from now? I can't tell you how many times I've looked at > some piece of code, muttered, "Who wrote this crap?" and called up the > checkin history only to discover that *I* wrote it :-) When you consider that you're looking at the code six months later it's likely for one of three reasons: you have to fix a bug; you need to add features; or the code's only now getting used. So you then take the extra 20-30 minutes, tease the code apart, refactor as needed and end up with better more readable debugged code. I consider that the right time to do this type of cleanup. For all the crap I write that works well for six months before needing to be cleaned up, there's a whole lot more crap that never gets looked at again that I didn't clean up and never spent the extra 20-30 minutes considering how my future self might view what I wrote. I'm not suggesting that you shouldn't develop good coding habits that adhere to established standards and result in well structured readable code, only that if that ugly piece of code works that you move on. You can bullet proof it after you uncover the vulnerabilities. Code is first and foremost written to be executed. Emile From __peter__ at web.de Sat Aug 27 13:29:07 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Aug 2011 19:29:07 +0200 Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > I have a development version of a library in c:\dev\XmlDB\xmldb > > After testing the setup script I also have > c:\python27\lib\site-packages\xmldb > > Now I'm continuing to develop it and simultaneously building an > application with it. > > I thought I could plug into my site-packages directory a file called > xmldb.pth with: > > c:\dev\XmlDB\xmldb > > which should redirect import statements to the development version of the > library. > > This doesn't seem to work. You have to put the directory containing the package into the pth-file. That's probably c:\dev\XmlDB in your case. Also, Python will stop at the first matching module or package; if you keep c:\python27\lib\site-packages\xmldb that will shadow c:\dev\XmlDB\xmldb. %APPDATA%/Python/Python26/site-packages may be a good place for the pth-file (I'm not on Windows and too lazy to figure out where %APPDATA% actually is. The PEP http://www.python.org/dev/peps/pep-0370/ may help) From rosuav at gmail.com Sat Aug 27 13:31:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 03:31:19 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 3:27 AM, Emile van Sebille wrote: > Code is first and foremost written to be executed. > +1 QOTW. Yes, it'll be read, and most likely read several times, by humans, but ultimately its purpose is to be executed. And in the case of some code, the programmer needs the same treatment, but that's a different issue... ChrisA From clp2 at rebertia.com Sat Aug 27 13:35:14 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Aug 2011 10:35:14 -0700 Subject: typing question In-Reply-To: References: Message-ID: On Sat, Aug 27, 2011 at 6:42 AM, Jason Swails wrote: > Hello everyone, > > This is probably a basic question with an obvious answer, but I don't quite > get why the type(foo).__name__ works differently for some class instances > and not for others.? If I have an "underived" class, any instance of that > class is simply of type "instance".? If I include an explicit base class, > then its type __name__ is the name of the class. > > $ python > Python 2.7.2 (default, Aug 26 2011, 22:35:24) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> class MyClass: > ...???? pass > ... >>>> foo = MyClass() >>>> type(foo) > >>>> type(foo).__name__ > 'instance' >>>> class MyClass1(): > ...???? pass > ... >>>> bar = MyClass1() >>>> type(bar) > >>>> type(bar).__name__ > 'instance' >>>> class MyClass2(object): > ...???? pass > ... >>>> foobar = MyClass2() >>>> type(foobar) > >>>> type(foobar).__name__ > 'MyClass2' > > I can't explain this behavior (since doesn't every class inherit from object > by default? That's only true in Python 3.x. Python 2.7.2 (default, Jul 27 2011, 04:14:23) >>> class Foo: ... pass ... >>> Foo.__bases__ () >>> class Bar(object): ... pass ... >>> Bar.__bases__ (,) > And if so, there should be no difference between any of my class > definitions).? I would prefer that every approach give me the name of the > class (rather than the first 2 just return 'instance').? Why is this not the > case? Classes directly or indirectly inheriting from `object` are "new-style"; classes which don't are "old-style". The two kinds of classes have different semantics (including whether they have a .__name__, but that's minor relative to the other changes). Old-style classes are deprecated and were removed in Python 3. See http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes Cheers, Chris From roy at panix.com Sat Aug 27 13:45:31 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 13:45:31 -0400 Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n") # splits the text on double-newlines. The biggest problem with this code is that read() slurps the entire file into a string. That's fine for moderately sized files, but will fail (or at least be grossly inefficient) for very large files. It's always annoyed me a little that while it's easy to iterate over the lines of a file, it's more complicated to iterate over a file character by character. You could write your own generator to do that: for c in getchar(open("file.txt")): whatever def getchar(f): for line in f: for c in line: yield c but that's annoyingly verbose (and probably not hugely efficient). Of course, the next problem for the specific problem at hand is that even with an iterator over the characters of a file, split() only works on strings. It would be nice to have a version of split which took an iterable and returned an iterator over the split components. Maybe there is such a thing and I'm just missing it? From Joshua.R.English at gmail.com Sat Aug 27 13:57:01 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 10:57:01 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Philip, Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. Why the egg file, which doesn't list any paths, would interfere I do not know. But with those changes, the xmldb.pth file is being read. So I think the preferred search order is: 1. a folder in the site-packages directory 2. an Egg file (still unsure why) 3. A .pth file It's a strange juju that I haven't figured out yet. Thanks for the hint. Josh From Joshua.R.English at gmail.com Sat Aug 27 13:57:01 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 10:57:01 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Philip, Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. Why the egg file, which doesn't list any paths, would interfere I do not know. But with those changes, the xmldb.pth file is being read. So I think the preferred search order is: 1. a folder in the site-packages directory 2. an Egg file (still unsure why) 3. A .pth file It's a strange juju that I haven't figured out yet. Thanks for the hint. Josh From emile at fenx.com Sat Aug 27 14:06:22 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 11:06:22 -0700 Subject: Arrange files according to a text file In-Reply-To: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 10:03 AM Ric at rdo.python.org said... > Hello, > > What would be the best way to accomplish this task? I'd do something like: usernames = """Adler, Jack Smith, John Smith, Sally Stone, Mark""".split('\n') filenames = """Smith, John - 02-15-75 - business files.doc Random Data - Adler Jack - expenses.xls More Data Mark Stone files list.doc""".split('\n') from difflib import SequenceMatcher as SM def ignore(x): return x in ' ,.' for filename in filenames: ratios = [SM(ignore,filename,username).ratio() for username in usernames] best = max(ratios) owner = usernames[ratios.index(best)] print filename,":",owner Emile > I have many files in separate directories, each file name > contain a persons name but never in the same spot. > I need to find that name which is listed in a large > text file in the following format. Last name, comma > and First name. The last name could be duplicate. > > Adler, Jack > Smith, John > Smith, Sally > Stone, Mark > etc. > > > The file names don't necessary follow any standard > format. > > Smith, John - 02-15-75 - business files.doc > Random Data - Adler Jack - expenses.xls > More Data Mark Stone files list.doc > etc > > I need some way to pull the name from the file name, find it in the > text list and then create a directory based on the name on the list > "Smith, John" and move all files named with the clients name into that > directory. From philip at semanchuk.com Sat Aug 27 14:07:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 14:07:02 -0400 Subject: Understanding .pth in site-packages In-Reply-To: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 27, 2011, at 1:57 PM, Josh English wrote: > Philip, > > Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. > > I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. > > Why the egg file, which doesn't list any paths, would interfere I do not know. > > But with those changes, the xmldb.pth file is being read. > > So I think the preferred search order is: > > 1. a folder in the site-packages directory > 2. an Egg file (still unsure why) > 3. A .pth file That might be implementation-dependent or it might even come down to something as simple as the in which order the operating system returns files/directories when asked for a listing. In other words, unless you can find something in the documentation (or Python's import implementation) that confirms your preferred search order observation, I would not count on it working the same way with all systems, all Pythons, or even all directory names. Good luck Philip From cbrown at cbrownsystems.com Sat Aug 27 14:40:09 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Sat, 27 Aug 2011 11:40:09 -0700 (PDT) Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 27, 10:45?am, Roy Smith wrote: > In article <4e592852$0$29965$c3e8da3$54964... at news.astraweb.com>, > ?Steven D'Aprano wrote: > > > open("file.txt") ? # opens the file > > ?.read() ? ? ? ? ? # reads the contents of the file > > ?.split("\n\n") ? ?# splits the text on double-newlines. > > The biggest problem with this code is that read() slurps the entire file > into a string. ?That's fine for moderately sized files, but will fail > (or at least be grossly inefficient) for very large files. > > It's always annoyed me a little that while it's easy to iterate over the > lines of a file, it's more complicated to iterate over a file character > by character. ?You could write your own generator to do that: > > for c in getchar(open("file.txt")): > ? ?whatever > > def getchar(f): > ? ?for line in f: > ? ? ? for c in line: > ? ? ? ? ?yield c > > but that's annoyingly verbose (and probably not hugely efficient). read() takes an optional size parameter; so f.read(1) is another option... > > Of course, the next problem for the specific problem at hand is that > even with an iterator over the characters of a file, split() only works > on strings. ?It would be nice to have a version of split which took an > iterable and returned an iterator over the split components. ?Maybe > there is such a thing and I'm just missing it? I don't know if there is such a thing; but for the OP's problem you could read the file in chunks, e.g.: def readgroup(f, delim, buffsize=8192): tail='' while True: s = f.read(buffsize) if not s: yield tail break groups = (tail + s).split(delim) tail = groups[-1] for group in groups[:-1]: yield group for group in readgroup(open('file.txt'), '\n\n'): # do something Cheers - Chas From me+list/python at ixokai.io Sat Aug 27 14:48:03 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 11:48:03 -0700 Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: <4E593BE3.8080905@ixokai.io> On 8/25/11 1:54 PM, ting at thsu.org wrote: > On Aug 25, 10:35 am, Arnaud Delobelle wrote: >> You're close to the usual idiom: >> >> def doSomething(debug=None): >> if debug is None: >> debug = defaults['debug'] >> ... >> >> Note the use of 'is' rather than '==' >> HTH > > Hmm, from what you are saying, it seems like there's no elegant way to > handle run time defaults for function arguments, Well, elegance is in the eye of the beholder: and the above idiom is generally considered elegant in Python, more or less. (The global nature of 'defaults' being a question) > meaning that I should > probably write a sql-esc coalesce function to keep my code cleaner. I > take it that most people who run into this situation do this? > > def coalesce(*args): > for a in args: > if a is not None: > return a > return None > > def doSomething(debug=None): > debug = coalesce(debug,defaults['debug']) > # blah blah blah Er, I'd say that most people don't do that, no. I'd guess that most do something more along the lines of "if debug is None: debug = default" as Arnaud said. Its very common Pythonic code. In fact, I'm not quite sure what you think you're getting out of that coalesce function. "Return the first argument that is not None, or return None"? That's a kind of odd thing to do, I think. In Python at least. Why not just: debug = defaults.get("debug", None) (Strictly speaking, providing None to get is not needed, but I always feel odd leaving it off.) That's generally how I spell it when I need to do run time defaults. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From dbigbear at gmail.com Sat Aug 27 15:24:33 2011 From: dbigbear at gmail.com (Xiong Deng) Date: Sun, 28 Aug 2011 03:24:33 +0800 Subject: How can I solve a equation like solve a function containint expressions like sqrt(log(x) - 1) = 2 and exp((log(x) - 1.5)**2 - 3) = 5 In-Reply-To: References: Message-ID: HI, Hi, I am trying to solve an equation containing both exp, log, erfc, and they may be embedded into each other....But sympy cannot handle this, as shown below: >>> from sympy import solve, exp, log, pi >>>from sympy.mpmath import * >>>from sympy import Symbol >>>x=Symbol('x') >>>sigma = 4 >>>mu = 1.5 >>>solve(x * ((1.0 / sqrt(2 * pi) * x * sigma) * exp(-0.5 * (log(x) - mu)**2 / sigma**2)) + 0.5 * erfc((mu - log(x)) / (sigma * sqrt(2))) - 1, x) Traceback (most recent call last): File "", line 1, in File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/functions/functions.py", line 287, in log return ctx.ln(x) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp_python.py", line 984, in f x = ctx.convert(x) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp_python.py", line 662, in convert return ctx._convert_fallback(x, strings) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp.py", line 556, in _convert_fallback raise TypeError("cannot create mpf from " + repr(x)) TypeError: cannot create mpf from x But sqrt, log, exp, itself is OK, as shown as below: >>> solve((1.0 / sqrt(2 * pi) * x * sigma) - 1, x) [0.626657068657750] SO, How can I solve an equation containint expressions like sqrt(log(x) - 1)=0 or exp((log(x) - mu)**2 - 3) = 0??? If there are any other methods without Sympy, it is still OK. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 27 15:45:45 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 27 Aug 2011 19:45:45 +0000 (UTC) Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > Philip, > > Yes, the proper path should be c:\dev\XmlDB, which has the > setup.py, xmldb subfolder, the docs subfolder, and example > subfolder, and the other text files proscribed by the package > development folder. > > I could only get it to work, though, by renaming the xmldb folder > in the site-packages directory, and deleting the egg file created > in the site-packages directory. > > Why the egg file, which doesn't list any paths, would interfere I > do not know. > > But with those changes, the xmldb.pth file is being read. > > So I think the preferred search order is: > > 1. a folder in the site-packages directory > 2. an Egg file (still unsure why) > 3. A .pth file You say that the egg file was created by the setup script for the library. Are you sure that this script did not also create or modify a .pth file of its own, adding the egg to the path? .pth files do not "redirect" imports from site-packages; they add EXTRA directories to sys.path. Also note that this means the .pth file itself is not part of the search path; it's not like you shadow a package xyz by creating a .pth file xyz.pth "instead". A single .pth file can list multiple directories, and it's those directories that are added to the path. I'm not sure how your package is set up, but easy_install, for instance, creates an easy_install.pth file in site-packages. This file contains references to egg files (or, at least in my case, .egg directories created by unpacking the eggs) for each package installed with easy_install. As far as I'm aware, Python doesn't have special rules for putting egg files in the search path, so my guess is that it's something like that: the "setup script" is creating a .pth file (or modifying an existing .pth file) to add the egg to the path. Read http://docs.python.org/library/site.html for the description of how .PTH files work. I don't think there is a general way to globally "shadow" a package that exists in site-packages. However, according to the docs the .pth files are added in alphabetical order, so if it is indeed easy_install.pth that is adding your egg, you could hack around it by making a file with an alphabetically earlier name (e.g., a_xmldb.pth). -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From tjreedy at udel.edu Sat Aug 27 16:03:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:03:44 -0400 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/27/2011 1:45 PM, Roy Smith wrote: > In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> open("file.txt") # opens the file >> .read() # reads the contents of the file >> .split("\n\n") # splits the text on double-newlines. > > The biggest problem with this code is that read() slurps the entire file > into a string. That's fine for moderately sized files, but will fail > (or at least be grossly inefficient) for very large files. I read the above as separating the file into paragraphs, as indicated by blank lines. def paragraphs(file): para = [] for line in file: if line: para.append(line) else: yield para # or ''.join(para), as desired para = [] -- Terry Jan Reedy From rosuav at gmail.com Sat Aug 27 16:07:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 06:07:08 +1000 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 28, 2011 at 6:03 AM, Terry Reedy wrote: > ? ? ?yield para # or ''.join(para), as desired > Or possibly '\n'.join(para) if you want to keep the line breaks inside paragraphs. ChrisA From tjreedy at udel.edu Sat Aug 27 16:08:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:08:25 -0400 Subject: typing question In-Reply-To: References: Message-ID: On 8/27/2011 9:42 AM, Jason Swails wrote: > P.S. I'll note that my "preferred" behavior is how python3.2 actually > operates Python core developers agree. This is one of the reasons for breaking a bit from 2.x to make Python 3. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 27 16:14:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:14:15 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/27/2011 2:07 PM, Philip Semanchuk wrote: > > On Aug 27, 2011, at 1:57 PM, Josh English wrote: > >> Philip, >> >> Yes, the proper path should be c:\dev\XmlDB, which has the >> setup.py, xmldb subfolder, the docs subfolder, and example >> subfolder, and the other text files proscribed by the package >> development folder. >> >> I could only get it to work, though, by renaming the xmldb folder >> in the site-packages directory, and deleting the egg file created >> in the site-packages directory. >> >> Why the egg file, which doesn't list any paths, would interfere I >> do not know. >> >> But with those changes, the xmldb.pth file is being read. >> >> So I think the preferred search order is: >> >> 1. a folder in the site-packages directory 2. an Egg file (still >> unsure why) 3. A .pth file > > > That might be implementation-dependent or it might even come down to > something as simple as the in which order the operating system > returns files/directories when asked for a listing. Doc says first match, and I presume that includes first match within a directory. -- Terry Jan Reedy From Ric at rdo Sat Aug 27 16:15:44 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 16:15:44 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: Hello Emile , Thank you for the code below as I have not encountered SequenceMatcher before and would have to take a look at it closer. My question would it work for a text file list of names about 25k lines and a directory with say 100 files inside? Thank you once again. On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille wrote: >On 8/27/2011 10:03 AM Ric at rdo.python.org said... >> Hello, >> >> What would be the best way to accomplish this task? > >I'd do something like: > > >usernames = """Adler, Jack >Smith, John >Smith, Sally >Stone, Mark""".split('\n') > >filenames = """Smith, John - 02-15-75 - business files.doc >Random Data - Adler Jack - expenses.xls >More Data Mark Stone files list.doc""".split('\n') > >from difflib import SequenceMatcher as SM > > >def ignore(x): > return x in ' ,.' > > >for filename in filenames: > ratios = [SM(ignore,filename,username).ratio() for username in >usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner > > >Emile > > > >> I have many files in separate directories, each file name >> contain a persons name but never in the same spot. >> I need to find that name which is listed in a large >> text file in the following format. Last name, comma >> and First name. The last name could be duplicate. >> >> Adler, Jack >> Smith, John >> Smith, Sally >> Stone, Mark >> etc. >> >> >> The file names don't necessary follow any standard >> format. >> >> Smith, John - 02-15-75 - business files.doc >> Random Data - Adler Jack - expenses.xls >> More Data Mark Stone files list.doc >> etc >> >> I need some way to pull the name from the file name, find it in the >> text list and then create a directory based on the name on the list >> "Smith, John" and move all files named with the clients name into that >> directory. > From steve+comp.lang.python at pearwood.info Sat Aug 27 16:27:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 06:27:32 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 28, 2011 at 3:27 AM, Emile van Sebille wrote: >> Code is first and foremost written to be executed. >> > > +1 QOTW. Yes, it'll be read, and most likely read several times, by > humans, but ultimately its purpose is to be executed. You've never noticed the masses of code written in text books, blogs, web pages, discussion forums like this one, etc.? Real world code for production is usually messy and complicated and filled with data validation and error checking code. There's a lot of code without that, because it was written explicitly to be read by humans, and the fact that it may be executed as well is incidental. Some code is even written in pseudo-code that *cannot* be executed. It's clear to me that a non-trivial amount of code is specifically written to be consumed by other humans, not by machines. It seems to me that, broadly speaking, there are languages designed with execution of code as the primary purpose: Fortran, C, Lisp, Java, PL/I, APL, Forth, ... and there are languages designed with *writing* of code as the primary purpose: Perl, AWK, sed, bash, ... and then there are languages where *reading* is the primary purpose: Python, Ruby, Hypertalk, Inform 7, Pascal, AppleScript, ... and then there are languages where the torment of the damned is the primary purpose: INTERCAL, Oook, Brainf*ck, Whitespace, Malbolge, ... and then there are languages with few, or no, design principles to speak of, or as compromise languages that (deliberately or accidentally) straddle the other categories. It all depends on the motivation and values of the language designer, and the trade-offs the language makes. Which category any specific language may fall into may be a matter of degree, or a matter of opinion, or both. -- Steven From philip at semanchuk.com Sat Aug 27 16:28:27 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 16:28:27 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <21BF439E-678A-4B07-9F6D-0CF60945691E@semanchuk.com> On Aug 27, 2011, at 4:14 PM, Terry Reedy wrote: > On 8/27/2011 2:07 PM, Philip Semanchuk wrote: >> >> On Aug 27, 2011, at 1:57 PM, Josh English wrote: >> >>> Philip, >>> >>> Yes, the proper path should be c:\dev\XmlDB, which has the >>> setup.py, xmldb subfolder, the docs subfolder, and example >>> subfolder, and the other text files proscribed by the package >>> development folder. >>> >>> I could only get it to work, though, by renaming the xmldb folder >>> in the site-packages directory, and deleting the egg file created >>> in the site-packages directory. >>> >>> Why the egg file, which doesn't list any paths, would interfere I >>> do not know. >>> >>> But with those changes, the xmldb.pth file is being read. >>> >>> So I think the preferred search order is: >>> >>> 1. a folder in the site-packages directory 2. an Egg file (still >>> unsure why) 3. A .pth file >> >> >> That might be implementation-dependent or it might even come down to >> something as simple as the in which order the operating system >> returns files/directories when asked for a listing. > > Doc says first match, and I presume that includes first match within a directory. First match using which ordering? Do the docs clarify that? Thanks Philip From rosuav at gmail.com Sat Aug 27 16:38:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 06:38:31 +1000 Subject: is there any principle when writing python function In-Reply-To: <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 28, 2011 at 6:27 AM, Steven D'Aprano wrote: > You've never noticed the masses of code written in text books, blogs, web > pages, discussion forums like this one, etc.? > > Real world code for production is usually messy and complicated and filled > with data validation and error checking code. There's a lot of code without > that, because it was written explicitly to be read by humans, and the fact > that it may be executed as well is incidental. Some code is even written in > pseudo-code that *cannot* be executed. It's clear to me that a non-trivial > amount of code is specifically written to be consumed by other humans, not > by machines. Yes, I'm aware of the quantities of code that are primarily for human consumption. But in the original context, which was of editing code six months down the track, I still believe that such code is primarily for the machine. In that situation, there are times when it's not worth the hassle of writing beautiful code; you'd do better to just get that code generated and in operation. Same goes for lint tools and debuggers - sometimes, it's easier to just put the code into a live situation (or a perfect copy of) and see where it breaks, than to use a simulation/test harness. ChrisA From roy at panix.com Sat Aug 27 17:07:48 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 17:07:48 -0400 Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Terry Reedy wrote: > On 8/27/2011 1:45 PM, Roy Smith wrote: > > In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> open("file.txt") # opens the file > >> .read() # reads the contents of the file > >> .split("\n\n") # splits the text on double-newlines. > > > > The biggest problem with this code is that read() slurps the entire file > > into a string. That's fine for moderately sized files, but will fail > > (or at least be grossly inefficient) for very large files. > > I read the above as separating the file into paragraphs, as indicated by > blank lines. > > def paragraphs(file): > para = [] > for line in file: > if line: > para.append(line) > else: > yield para # or ''.join(para), as desired > para = [] Plus or minus the last paragraph in the file :-) From emile at fenx.com Sat Aug 27 17:08:17 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 14:08:17 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 1:15 PM Ric at rdo.python.org said... > > Hello Emile , > > Thank you for the code below as I have not encountered SequenceMatcher > before and would have to take a look at it closer. > > My question would it work for a text file list of names about 25k > lines and a directory with say 100 files inside? Sure. Emile > > Thank you once again. > > > On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille > wrote: > >> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>> Hello, >>> >>> What would be the best way to accomplish this task? >> >> I'd do something like: >> >> >> usernames = """Adler, Jack >> Smith, John >> Smith, Sally >> Stone, Mark""".split('\n') >> >> filenames = """Smith, John - 02-15-75 - business files.doc >> Random Data - Adler Jack - expenses.xls >> More Data Mark Stone files list.doc""".split('\n') >> >>from difflib import SequenceMatcher as SM >> >> >> def ignore(x): >> return x in ' ,.' >> >> >> for filename in filenames: >> ratios = [SM(ignore,filename,username).ratio() for username in >> usernames] >> best = max(ratios) >> owner = usernames[ratios.index(best)] >> print filename,":",owner >> >> >> Emile >> >> >> >>> I have many files in separate directories, each file name >>> contain a persons name but never in the same spot. >>> I need to find that name which is listed in a large >>> text file in the following format. Last name, comma >>> and First name. The last name could be duplicate. >>> >>> Adler, Jack >>> Smith, John >>> Smith, Sally >>> Stone, Mark >>> etc. >>> >>> >>> The file names don't necessary follow any standard >>> format. >>> >>> Smith, John - 02-15-75 - business files.doc >>> Random Data - Adler Jack - expenses.xls >>> More Data Mark Stone files list.doc >>> etc >>> >>> I need some way to pull the name from the file name, find it in the >>> text list and then create a directory based on the name on the list >>> "Smith, John" and move all files named with the clients name into that >>> directory. >> From roy at panix.com Sat Aug 27 17:09:51 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 17:09:51 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e595334$0$30000$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > and then there are languages with few, or no, design principles to speak of Oh, like PHP? From cjw at ncf.ca Sat Aug 27 17:25:10 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 17:25:10 -0400 Subject: how to format long if conditions In-Reply-To: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E5960B6.1070901@ncf.ca> On 27-Aug-11 11:53 AM, Hans Mulder wrote: > On 27/08/11 17:16:51, Colin J. Williams wrote: > >> What about: >> cond= isinstance(left, PyCompare) >> and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0] >> py_and= PyCompare(left.complist + right.complist[1:])if cond >> else: py_and = PyBooleanAnd(left, right) >> Colin W. > > That's a syntax error. You need to add parenthesis. > > How about: > > cond = ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > } > py_and = ( > PyCompare(left.complist + right.complist[1:]) > if cond > else PyBooleanAnd(left, right) > ) > > -- HansM I like your 11:53 message but suggest indenting the if cond as below to make it clearer that it, with the preceding line, is all one statement. Colin W. #!/usr/bin/env python z= 1 class PyCompare: complist = [True, False] def __init__(self): pass left= PyCompare right= PyCompare def isinstance(a, b): return True def PyBooleanAnd(a, b): return True def PyCompare(a): return False z=2 def try1(): ''' Hans Mulder suggestion 03:50 ''' if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) def try2(): ''' cjw response - corrected 11:56 ''' cond= (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) py_and= (PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right)) def try3(): ''' Hans Mulder 11:53 ''' cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ) # not } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) def main(): try1() try2() try3() if __name__ == '__main__': main() pass From cjw at ncf.ca Sat Aug 27 17:25:10 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 17:25:10 -0400 Subject: how to format long if conditions In-Reply-To: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E5960B6.1070901@ncf.ca> On 27-Aug-11 11:53 AM, Hans Mulder wrote: > On 27/08/11 17:16:51, Colin J. Williams wrote: > >> What about: >> cond= isinstance(left, PyCompare) >> and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0] >> py_and= PyCompare(left.complist + right.complist[1:])if cond >> else: py_and = PyBooleanAnd(left, right) >> Colin W. > > That's a syntax error. You need to add parenthesis. > > How about: > > cond = ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > } > py_and = ( > PyCompare(left.complist + right.complist[1:]) > if cond > else PyBooleanAnd(left, right) > ) > > -- HansM I like your 11:53 message but suggest indenting the if cond as below to make it clearer that it, with the preceding line, is all one statement. Colin W. #!/usr/bin/env python z= 1 class PyCompare: complist = [True, False] def __init__(self): pass left= PyCompare right= PyCompare def isinstance(a, b): return True def PyBooleanAnd(a, b): return True def PyCompare(a): return False z=2 def try1(): ''' Hans Mulder suggestion 03:50 ''' if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) def try2(): ''' cjw response - corrected 11:56 ''' cond= (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) py_and= (PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right)) def try3(): ''' Hans Mulder 11:53 ''' cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ) # not } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) def main(): try1() try2() try3() if __name__ == '__main__': main() pass From ben+python at benfinney.id.au Sat Aug 27 17:51:10 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Aug 2011 07:51:10 +1000 Subject: UnicodeEncodeError -- 'character maps to ' References: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> <4e590684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zkiuttf5.fsf@benfinney.id.au> Steven D'Aprano writes: > >>> s = u'BIEBER FEVER \u2665' > >>> print s # Printing Unicode is fine. > BIEBER FEVER ? You're a cruel man. Why do you hate me? -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson, 1813-08-13 | Ben Finney From ben+python at benfinney.id.au Sat Aug 27 17:57:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Aug 2011 07:57:48 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <87vctitt43.fsf@benfinney.id.au> Emile van Sebille writes: > Code is first and foremost written to be executed. ?1 QotW. I disagree, and have a counter-aphorism: ?Programs must be written for people to read, and only incidentally for machines to execute.? ?Abelson & Sussman, _Structure and Interpretation of Computer Programs_ Yes, the primary *function* of the code you write is for it to eventually execute. But the primary *audience* of the text you type into your buffer is not the computer, but the humans who will read it. That's what must be foremost in your mind while writing that text. -- \ ?If you can't beat them, arrange to have them beaten.? ?George | `\ Carlin | _o__) | Ben Finney From emile at fenx.com Sat Aug 27 18:21:06 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 15:21:06 -0700 Subject: is there any principle when writing python function In-Reply-To: <87vctitt43.fsf@benfinney.id.au> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: On 8/27/2011 2:57 PM Ben Finney said... > Emile van Sebille writes: > >> Code is first and foremost written to be executed. > > ?Programs must be written for people to read, and only incidentally for > machines to execute.? > ?Abelson& Sussman, _Structure and Interpretation of Computer Programs_ > That's certainly self-fulfilling -- code that doesn't execute will need to be read to be understood, and to be fixed so that it does run. Nobody cares about code not intended to be executed. Pretty it up as much as you have free time to do so to enlighten your intended audience. Code that runs from the offset may not ever again need to be read, so the only audience will ever be the processor. I find it much to easy to waste enormous amounts of time prettying up code that works. Pretty it up when it doesn't -- that's the code that needs the attention. Emile > Yes, the primary *function* of the code you write is for it to > eventually execute. But the primary *audience* of the text you type into > your buffer is not the computer, but the humans who will read it. That's > what must be foremost in your mind while writing that text. > From Joshua.R.English at gmail.com Sat Aug 27 18:39:24 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:39:24 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <47945742-a04c-4eda-aee3-a0026c04e360@glegroupsg2000goo.googlegroups.com> OKB, The setup.py script created the egg, but not the .pth file. I created that myself. Thank you for clarifying about how .pth works. I know "redirect imports" was the wrong phrase, but it worked in my head at the time. It appears, at least on my system, that Python will find site-packages/foo before it finds and reads site-packages/foo.pth. At least this solution gives me a way to develop my libraries outside of site-packages. Josh From Joshua.R.English at gmail.com Sat Aug 27 18:41:58 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:41:58 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? Josh From Joshua.R.English at gmail.com Sat Aug 27 18:41:58 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:41:58 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? Josh From Joshua.R.English at gmail.com Sat Aug 27 18:49:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:49:44 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) I would guess Python is using os.listdir. Why wouldn't it? From Joshua.R.English at gmail.com Sat Aug 27 18:49:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:49:44 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) I would guess Python is using os.listdir. Why wouldn't it? From rantingrick at gmail.com Sat Aug 27 19:01:47 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Aug 2011 16:01:47 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: <6930db73-816a-44a9-be1f-0915ced571a3@p10g2000yqi.googlegroups.com> On Aug 27, 5:21?pm, Emile van Sebille wrote: > On 8/27/2011 2:57 PM Ben Finney said... > > > Emile van Sebille ?writes: > > >> Code is first and foremost written to be executed. > > > ? ? ??Programs must be written for people to read, and only incidentally for > > ? ? ?machines to execute.? > > ? ? ??Abelson& ?Sussman, _Structure and Interpretation of Computer Programs_ > > That's certainly self-fulfilling -- code that doesn't execute will need > to be read to be understood, and to be fixed so that it does run. > Nobody cares about code not intended to be executed. ?Pretty it up as > much as you have free time to do so to enlighten your intended audience. > > Code that runs from the offset may not ever again need to be read, so > the only audience will ever be the processor. WRONG! Code may need to be extended someday no matter HOW well it executes today. Also, code need to be readable so the readers can learn from it. From roy at panix.com Sat Aug 27 19:09:41 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 19:09:41 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: In article , Emile van Sebille wrote: > code that doesn't execute will need to be read to be understood, and > to be fixed so that it does run. That is certainly true, but it's not the whole story. Even code that works perfectly today will need to be modified in the future. Business requirements change. Your code will need to be ported to a new OS. You'll need to make it work for 64-bit. Or i18n. Or y2k (well, don't need to worry about that one any more). Or with a different run-time library. A new complier. A different database. Regulatory changes will impose new requirements Or, your company will get bought and you'll need to interface with a whole new system. Code is never done. At least not until the project is dead. From Ric at rdo Sat Aug 27 19:18:54 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 19:18:54 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: Thank you so much. The code worked perfectly. This is what I tried using Emile code. The only time when it picked wrong name from the list was when the file was named like this. Data Mark Stone.doc How can I fix this? Hope I am not asking too much? import os from difflib import SequenceMatcher as SM path = r'D:\Files ' txt_names = [] with open(r'D:/python/log1.txt') as f: for txt_name in f.readlines(): txt_names.append(txt_name.strip()) def ignore(x): return x in ' ,.' for filename in os.listdir(path): ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in txt_names] best = max(ratios) owner = txt_names[ratios.index(best)] print filename,":",owner On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille wrote: >On 8/27/2011 1:15 PM Ric at rdo.python.org said... >> >> Hello Emile , >> >> Thank you for the code below as I have not encountered SequenceMatcher >> before and would have to take a look at it closer. >> >> My question would it work for a text file list of names about 25k >> lines and a directory with say 100 files inside? > >Sure. > >Emile > > >> >> Thank you once again. >> >> >> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >> wrote: >> >>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>> Hello, >>>> >>>> What would be the best way to accomplish this task? >>> >>> I'd do something like: >>> >>> >>> usernames = """Adler, Jack >>> Smith, John >>> Smith, Sally >>> Stone, Mark""".split('\n') >>> >>> filenames = """Smith, John - 02-15-75 - business files.doc >>> Random Data - Adler Jack - expenses.xls >>> More Data Mark Stone files list.doc""".split('\n') >>> >>>from difflib import SequenceMatcher as SM >>> >>> >>> def ignore(x): >>> return x in ' ,.' >>> >>> >>> for filename in filenames: >>> ratios = [SM(ignore,filename,username).ratio() for username in >>> usernames] >>> best = max(ratios) >>> owner = usernames[ratios.index(best)] >>> print filename,":",owner >>> >>> >>> Emile >>> >>> >>> >>>> I have many files in separate directories, each file name >>>> contain a persons name but never in the same spot. >>>> I need to find that name which is listed in a large >>>> text file in the following format. Last name, comma >>>> and First name. The last name could be duplicate. >>>> >>>> Adler, Jack >>>> Smith, John >>>> Smith, Sally >>>> Stone, Mark >>>> etc. >>>> >>>> >>>> The file names don't necessary follow any standard >>>> format. >>>> >>>> Smith, John - 02-15-75 - business files.doc >>>> Random Data - Adler Jack - expenses.xls >>>> More Data Mark Stone files list.doc >>>> etc >>>> >>>> I need some way to pull the name from the file name, find it in the >>>> text list and then create a directory based on the name on the list >>>> "Smith, John" and move all files named with the clients name into that >>>> directory. >>> > From me+list/python at ixokai.io Sat Aug 27 19:27:16 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:27:16 -0700 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: <4E597D54.5010605@ixokai.io> On 8/27/11 3:21 PM, Emile van Sebille wrote: > On 8/27/2011 2:57 PM Ben Finney said... >> Emile van Sebille writes: >> >>> Code is first and foremost written to be executed. >> > > >> ?Programs must be written for people to read, and only >> incidentally for >> machines to execute.? >> ?Abelson& Sussman, _Structure and Interpretation of Computer >> Programs_ >> > > That's certainly self-fulfilling -- code that doesn't execute will need > to be read to be understood, and to be fixed so that it does run. Nobody > cares about code not intended to be executed. Pretty it up as much as > you have free time to do so to enlighten your intended audience. Er, you're interpreting the quote... way overboard. No one's talking about code that isn't intended to be executed, I don't think; the quote includes, "and only incidentally for machines to execute." That's still the there, and its still important. It should just not be the prime concern while actually writing the code. The code has to actually do something. If not, obviously you'll have to change it. The Pythonic emphasis on doing readable, pretty code isn't JUST about making code that just looks good; its not merely an aesthetic that the community endorses. And although people often tout the very valid reason why readability counts-- that code is often read more then written, and that coming back to a chunk of code 6 months later and being able to understand fully what its doing is very important... that's not the only reason readability counts. Readable, pretty, elegantly crafted code is also far more likely to be *correct* code. However, this: > Code that runs from the offset may not ever again need to be read, so > the only audience will ever be the processor. > > I find it much to easy to waste enormous amounts of time prettying up > code that works. Pretty it up when it doesn't -- that's the code that > needs the attention. ... seems to me to be a rather significant self-fulfilling prophecy in its own right. The chances that the code does what its supposed to do, accurately, and without any bugs, goes down in my experience quite significantly the farther away from "pretty" it is. If you code some crazy, overly clever, poorly organized, messy chunk of something that /works/ -- that's fine and dandy. But unless you have some /seriously/ comprehensive test coverage then the chances that you can eyeball it and be sure it doesn't have some subtle bugs that will call you back to fix it later, is pretty low. In my experience. Its not that pretty code is bug-free, but code which is easily read and understood is vastly more likely to be functioning correctly and reliably. Also... it just does not take that much time to make "pretty code". It really doesn't. The entire idea that its hard, time-consuming, effort-draining or difficult to make code clean and "pretty" from the get-go is just wrong. You don't need to do a major "prettying up" stage after the fact. Sure, sometimes refactoring would greatly help a body of code as it evolves, but you can do that as it becomes beneficial for maintenance reasons and not just for pretty's sake. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Aug 27 19:31:15 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:31:15 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E597E43.6030702@ixokai.io> On 8/27/11 11:06 AM, Emile van Sebille wrote: > from difflib import SequenceMatcher as SM > > def ignore(x): > return x in ' ,.' > > for filename in filenames: > ratios = [SM(ignore,filename,username).ratio() for username in > usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner It amazes me that I can still find a surprising new tool in the stdlib after all these years. Neat. /pinboards -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Aug 27 19:44:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:44:44 -0700 Subject: Understanding .pth in site-packages In-Reply-To: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> Message-ID: <4E59816C.50403@ixokai.io> On 8/27/11 3:41 PM, Josh English wrote: > I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Sounds like your setup.py isn't actually including your source. > > Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? IIUC, its nominally very slightly faster to use an egg, because it can skip a lot of filesystem calls. But I've only heard that and can't completely confirm it (internal testing at my day job did not conclusively support this, but our environments are uniquely weird). But that speed boost (if even true) isn't really the point of eggs-as-files -- eggs are just easy to deal with as files is all. They don't prevent people from seeing the code*, they're just regular zip files and can be unzipped fine. I almost always install unzip my eggs on a developer machine, because I inevitably want to go poke inside and see what's actually going on. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * Although you can make an egg and then go and remove all the .PY files from it, and leave just the compiled .PYC files, and Python will load it fine. At the day job, that's what we do. But, you have to be aware that this ties the egg to a specific version of Python, and its not difficult for someone industrious to disassemble and/or decompile the PYC back to effectively equivalent PY files to edit away if they want. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From python at mrabarnett.plus.com Sat Aug 27 19:48:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Aug 2011 00:48:20 +0100 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E598244.2070400@mrabarnett.plus.com> On 28/08/2011 00:18, Ric at rdo.python.org wrote: > Thank you so much. The code worked perfectly. > > This is what I tried using Emile code. The only time when it picked > wrong name from the list was when the file was named like this. > > Data Mark Stone.doc > > How can I fix this? Hope I am not asking too much? > Have you tried the alternative word orders, "Mark Stone" as well as "Stone, Mark", picking whichever name has the best ratio for either? > > import os > from difflib import SequenceMatcher as SM > > path = r'D:\Files ' > txt_names = [] > > > with open(r'D:/python/log1.txt') as f: > for txt_name in f.readlines(): > txt_names.append(txt_name.strip()) > > def ignore(x): > return x in ' ,.' > > for filename in os.listdir(path): > ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in > txt_names] > best = max(ratios) > owner = txt_names[ratios.index(best)] > print filename,":",owner > > > > > > On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille > wrote: > >> On 8/27/2011 1:15 PM Ric at rdo.python.org said... >>> >>> Hello Emile , >>> >>> Thank you for the code below as I have not encountered SequenceMatcher >>> before and would have to take a look at it closer. >>> >>> My question would it work for a text file list of names about 25k >>> lines and a directory with say 100 files inside? >> >> Sure. >> >> Emile >> >> >>> >>> Thank you once again. >>> >>> >>> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >>> wrote: >>> >>>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>>> Hello, >>>>> >>>>> What would be the best way to accomplish this task? >>>> >>>> I'd do something like: >>>> >>>> >>>> usernames = """Adler, Jack >>>> Smith, John >>>> Smith, Sally >>>> Stone, Mark""".split('\n') >>>> >>>> filenames = """Smith, John - 02-15-75 - business files.doc >>>> Random Data - Adler Jack - expenses.xls >>>> More Data Mark Stone files list.doc""".split('\n') >>>> >>> >from difflib import SequenceMatcher as SM >>>> >>>> >>>> def ignore(x): >>>> return x in ' ,.' >>>> >>>> >>>> for filename in filenames: >>>> ratios = [SM(ignore,filename,username).ratio() for username in >>>> usernames] >>>> best = max(ratios) >>>> owner = usernames[ratios.index(best)] >>>> print filename,":",owner >>>> >>>> >>>> Emile >>>> >>>> >>>> >>>>> I have many files in separate directories, each file name >>>>> contain a persons name but never in the same spot. >>>>> I need to find that name which is listed in a large >>>>> text file in the following format. Last name, comma >>>>> and First name. The last name could be duplicate. >>>>> >>>>> Adler, Jack >>>>> Smith, John >>>>> Smith, Sally >>>>> Stone, Mark >>>>> etc. >>>>> >>>>> >>>>> The file names don't necessary follow any standard >>>>> format. >>>>> >>>>> Smith, John - 02-15-75 - business files.doc >>>>> Random Data - Adler Jack - expenses.xls >>>>> More Data Mark Stone files list.doc >>>>> etc >>>>> >>>>> I need some way to pull the name from the file name, find it in the >>>>> text list and then create a directory based on the name on the list >>>>> "Smith, John" and move all files named with the clients name into that >>>>> directory. >>>> >> From Ric at rdo Sat Aug 27 20:21:19 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 20:21:19 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On Sun, 28 Aug 2011 00:48:20 +0100, MRAB wrote: >On 28/08/2011 00:18, Ric at rdo.python.org wrote: >> Thank you so much. The code worked perfectly. >> >> This is what I tried using Emile code. The only time when it picked >> wrong name from the list was when the file was named like this. >> >> Data Mark Stone.doc >> >> How can I fix this? Hope I am not asking too much? >> >Have you tried the alternative word orders, "Mark Stone" as well as >"Stone, Mark", picking whichever name has the best ratio for either? >> Yes I tried and the result was the same. I will try to work out something. thank you. >> import os >> from difflib import SequenceMatcher as SM >> >> path = r'D:\Files ' >> txt_names = [] >> >> >> with open(r'D:/python/log1.txt') as f: >> for txt_name in f.readlines(): >> txt_names.append(txt_name.strip()) >> >> def ignore(x): >> return x in ' ,.' >> >> for filename in os.listdir(path): >> ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in >> txt_names] >> best = max(ratios) >> owner = txt_names[ratios.index(best)] >> print filename,":",owner >> >> >> >> >> >> On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille >> wrote: >> >>> On 8/27/2011 1:15 PM Ric at rdo.python.org said... >>>> >>>> Hello Emile , >>>> >>>> Thank you for the code below as I have not encountered SequenceMatcher >>>> before and would have to take a look at it closer. >>>> >>>> My question would it work for a text file list of names about 25k >>>> lines and a directory with say 100 files inside? >>> >>> Sure. >>> >>> Emile >>> >>> >>>> >>>> Thank you once again. >>>> >>>> >>>> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >>>> wrote: >>>> >>>>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>>>> Hello, >>>>>> >>>>>> What would be the best way to accomplish this task? >>>>> >>>>> I'd do something like: >>>>> >>>>> >>>>> usernames = """Adler, Jack >>>>> Smith, John >>>>> Smith, Sally >>>>> Stone, Mark""".split('\n') >>>>> >>>>> filenames = """Smith, John - 02-15-75 - business files.doc >>>>> Random Data - Adler Jack - expenses.xls >>>>> More Data Mark Stone files list.doc""".split('\n') >>>>> >>>> >from difflib import SequenceMatcher as SM >>>>> >>>>> >>>>> def ignore(x): >>>>> return x in ' ,.' >>>>> >>>>> >>>>> for filename in filenames: >>>>> ratios = [SM(ignore,filename,username).ratio() for username in >>>>> usernames] >>>>> best = max(ratios) >>>>> owner = usernames[ratios.index(best)] >>>>> print filename,":",owner >>>>> >>>>> >>>>> Emile >>>>> >>>>> >>>>> >>>>>> I have many files in separate directories, each file name >>>>>> contain a persons name but never in the same spot. >>>>>> I need to find that name which is listed in a large >>>>>> text file in the following format. Last name, comma >>>>>> and First name. The last name could be duplicate. >>>>>> >>>>>> Adler, Jack >>>>>> Smith, John >>>>>> Smith, Sally >>>>>> Stone, Mark >>>>>> etc. >>>>>> >>>>>> >>>>>> The file names don't necessary follow any standard >>>>>> format. >>>>>> >>>>>> Smith, John - 02-15-75 - business files.doc >>>>>> Random Data - Adler Jack - expenses.xls >>>>>> More Data Mark Stone files list.doc >>>>>> etc >>>>>> >>>>>> I need some way to pull the name from the file name, find it in the >>>>>> text list and then create a directory based on the name on the list >>>>>> "Smith, John" and move all files named with the clients name into that >>>>>> directory. >>>>> >>> From suresh.amritapuri at gmail.com Sat Aug 27 20:52:32 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Sat, 27 Aug 2011 17:52:32 -0700 (PDT) Subject: packaging a python application Message-ID: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> Hi I created a python application which consists of multiple python files and a configuration file. I am not sure, how can I distribute it. I read distutils2 documentation and a few blogs on python packaging. But I still have the following questions. 1. My package has a configuration file which has to be edited by the user. How do we achieve that? 2. Should the user directly edit the configuration file, or there would be an interface for doing it...?(I remember my sendmail installations in Debian/Ubuntu. It would ask a bunch of questions and the cfg file would be ready) I am just confused how to go about... thanks suresh From tjreedy at udel.edu Sat Aug 27 20:55:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 20:55:55 -0400 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/27/2011 5:07 PM, Roy Smith wrote: > In article, > Terry Reedy wrote: > >> On 8/27/2011 1:45 PM, Roy Smith wrote: >>> In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, >>> Steven D'Aprano wrote: >>> >>>> open("file.txt") # opens the file >>>> .read() # reads the contents of the file >>>> .split("\n\n") # splits the text on double-newlines. >>> >>> The biggest problem with this code is that read() slurps the entire file >>> into a string. That's fine for moderately sized files, but will fail >>> (or at least be grossly inefficient) for very large files. >> >> I read the above as separating the file into paragraphs, as indicated by >> blank lines. >> >> def paragraphs(file): >> para = [] >> for line in file: >> if line: >> para.append(line) >> else: >> yield para # or ''.join(para), as desired >> para = [] > > Plus or minus the last paragraph in the file :-) Or right, I forgot the last line, which is a repeat of the yield after the for loop finishes. -- Terry Jan Reedy From emile at fenx.com Sat Aug 27 21:10:07 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 18:10:07 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 4:18 PM Ric at rdo.python.org said... > Thank you so much. The code worked perfectly. > > This is what I tried using Emile code. The only time when it picked > wrong name from the list was when the file was named like this. > > Data Mark Stone.doc > > How can I fix this? Hope I am not asking too much? What name did it pick? I imagine if you're picking a name from a list of 25000 names that some subset of combinations may yield like ratios. But, if you double up on the file name side you may get closer: for filename in filenames: ratios = [SM(ignore,filename+filename,username).ratio() for username in usernames] best = max(ratios) owner = usernames[ratios.index(best)] print filename,":",owner ... on the other hand, if you've only got a 100 files to sort out, you should already be done. :) Emile From drsalists at gmail.com Sat Aug 27 21:19:05 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 27 Aug 2011 18:19:05 -0700 Subject: Record seperator In-Reply-To: References: Message-ID: http://stromberg.dnsalias.org/svn/bufsock/trunk does it. $ cat double-file daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh root:x:0:0:root:/root:/bin/bash lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh benchbox-dstromberg:~/src/home-svn/bufsock/trunk i686-pc-linux-gnu 8830 - above cmd done 2011 Sat Aug 27 06:19 PM $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import bufsock >>> file_ = open('double-file', 'rb') >>> bs = bufsock.bufsock(file_) >>> bs.readto('oo') 'daemon:x:1:1:daemon:/usr/sbin:/bin/sh\nbin:x:2:2:bin:/bin:/bin/sh\nsys:x:3:3:sys:/dev:/bin/sh\nsync:x:4:65534:sync:/bin:/bin/sync\ngames:x:5:60:games:/usr/games:/bin/sh\nman:x:6:12:man:/var/cache/man:/bin/sh\nroo' >>> bs.close() >>> Don't let the name fool you - it's not just for sockets anymore. On Fri, Aug 26, 2011 at 11:39 AM, greymaus wrote: > > Is there an equivelent for the AWK RS in Python? > > > as in RS='\n\n' > will seperate a file at two blank line intervals > > > -- > maus > . > . > ... NO CARRIER > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jphalip at gmail.com Sat Aug 27 21:59:10 2011 From: jphalip at gmail.com (Julien) Date: Sat, 27 Aug 2011 18:59:10 -0700 (PDT) Subject: Custom dict to prevent keys from being overridden Message-ID: Hi, With a simple dict, the following happens: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } >>> d {'a': 3, 'b': 2} ... i.e. the value for the 'a' key gets overridden. What I'd like to achieve is: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } Error: The key 'a' already exists. Is that possible, and if so, how? Many thanks! Kind regards, Julien From steve+comp.lang.python at pearwood.info Sat Aug 27 22:38:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 12:38:20 +1000 Subject: Custom dict to prevent keys from being overridden References: Message-ID: <4e59aa1c$0$29977$c3e8da3$5496439d@news.astraweb.com> Julien wrote: > What I'd like to achieve is: > >>>> d = { > ... 'a': 1, > ... 'b': 2, > ... 'a': 3 > ... } > Error: The key 'a' already exists. > > Is that possible, and if so, how? Not if the requirements including using built-in dicts { }. But if you are happy enough to use a custom class, like this: d = StrictDict(('a', 1), ('b', 2'), ('a', 3)) then yes. Just subclass dict and have it validate items as they are added. Something like: # Untested class StrictDict(dict): def __init__(self, items): for key, value in items: self[key] = value def __setitem__(self, key, value): if key in self: raise KeyError('key %r already exists' % key) super(StrictDict, self).__setitem__(key, value) should more or less do it. -- Steven From philip at semanchuk.com Sat Aug 27 23:01:11 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 23:01:11 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <32FE080C-4C17-435A-BB32-DAFE901BE944@semanchuk.com> On Aug 27, 2011, at 6:49 PM, Josh English wrote: > When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) That's one definition of "in order". =) > I would guess Python is using os.listdir. Why wouldn't it? If you mean that Python uses os.listdir() during import resolution, then yes I agree that's probable. And os.listdir() doesn't guarantee any consistent order. In fact, the documentation explicitly states that the list is returned in arbitrary order. Like a lot of things in Python, os.listdir() probably relies on the underlying C library which varies from system to system. (Case in point -- on my Mac, os.listdir() returns things in the same order as the 'ls' command, which is case-sensitive alphabetical, files & directories mixed -- different from Windows.) So if import relies on os.listdir(), then you're relying on arbitrary resolution when you have a .pth file that shadows a site-packages directory. Those rules will probably work consistently on your particular system, you're developing a habit around what is essentially an implementation quirk. Cheers Philip From research at johnohagan.com Sat Aug 27 23:45:05 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 13:45:05 +1000 Subject: Why do closures do this? Message-ID: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: funcs=[] for n in range(3): def f(): return n funcs.append(f) [i() for i in funcs] The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: def mkfnc(n): def fnc(): return n return fnc funcs=[] for n in range(3): funcs.append(mkfnc(n)) which seems roundabout, or take advantage of the "default values set at definition time" behaviour: funcs=[] for n in range(3): def f(n=n): return n funcs.append(f) which seems obscure, and a side-effect. My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? Regards, John From research at johnohagan.com Sun Aug 28 00:00:24 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 14:00:24 +1000 Subject: Get reference to parent class from subclass? Message-ID: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> class P(): pass class C(P): pass Can I get P from C? IOW, can I get a reference to the object P from the object C? This should be obvious one way or the other, but I haven't been able to find the answer. Regards, John From tjreedy at udel.edu Sun Aug 28 00:19:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 00:19:07 -0400 Subject: Why do closures do this? In-Reply-To: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: On 8/27/2011 11:45 PM, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: def f(): return n is a CONSTANT value. It is not a closure. Your code above is the same as def f(): return n funcs = [f,f,f] n = 2 [i() for i in funcs] > def mkfnc(n): > def fnc(): > return n > return fnc fnc is a closure and n in a nonlocal name. Since you only read it, no nonlocal declaration is needed. > funcs=[] > for n in range(3): > funcs.append(mkfnc(n)) > > which seems roundabout, or take advantage of the "default values set at definition time" behaviour: > > funcs=[] > for n in range(3): > def f(n=n): > return n > funcs.append(f) > > which seems obscure, and a side-effect. It was the standard idiom until nested functions were upgraded to enclose or capture the values of nonlocals. > My question is, is this an inescapable consequence of using closures, I cannot answer since I am not sure what you mean by 'this'. Closures are nested functions that access the locals of enclosing functions. To ensure that the access remains possible even after the enclosing function returns, the last value of such accessed names is preserved even after the enclosing function returns. (That is the tricky part.) -- Terry Jan Reedy From harmar at member.fsf.org Sun Aug 28 00:51:59 2011 From: harmar at member.fsf.org (harrismh777) Date: Sat, 27 Aug 2011 23:51:59 -0500 Subject: is there any principle when writing python function In-Reply-To: References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Once Abraham Lincoln was asked how long a man's legs should be. (Well, he was a tall man and had exceptionally long legs... his bed had to be specially made.) Old Abe said, "A man's legs ought to be long enough to reach from his body to the floor". One time the Austrian Emperor decided that one of Wolfgang Amadeus Mozart's masterpieces contained too many notes... when asked how many notes a masterpiece ought to contain it is reported that Mozart retorted, "I use precisely as many notes as the piece requires, not one note more, and not one note less". After starting the python interpreter import this: import this ... study carefully. If you're not Dutch, don't worry if some of it confuses you. ... apply liberally to your function praxis. kind regards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From research at johnohagan.com Sun Aug 28 01:03:13 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 15:03:13 +1000 Subject: Why do closures do this? In-Reply-To: References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: <20110828150313.fa3e35c121380fd8dbbcf2bd@johnohagan.com> On Sun, 28 Aug 2011 00:19:07 -0400 Terry Reedy wrote: > On 8/27/2011 11:45 PM, John O'Hagan wrote: > > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > > > funcs=[] > > for n in range(3): > > def f(): > > return n > > funcs.append(f) > > > > > > > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. [...] > > def f(): return n > is a CONSTANT value. It is not a closure. Quite right: I originally encountered this inside a function, but removed the enclosing function to show the issue in minimal form. > Your code above is the same as > def f(): return n > funcs = [f,f,f] > n = 2 > [i() for i in funcs] > Also right, but I still find this surprising. [...] > > > My question is, is this an inescapable consequence of using closures, > > I cannot answer since I am not sure what you mean by 'this'. Ah, but you are and you have: > Closures are nested functions that access the locals of enclosing > functions. To ensure that the access remains possible even after the > enclosing function returns, the last value of such accessed names is > preserved even after the enclosing function returns. (That is the tricky > part.) > Thanks, John From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Aug 28 01:20:23 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 28 Aug 2011 05:20:23 +0000 (UTC) Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <47945742-a04c-4eda-aee3-a0026c04e360@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > OKB, > > The setup.py script created the egg, but not the .pth file. I > created that myself. > > Thank you for clarifying about how .pth works. I know "redirect > imports" was the wrong phrase, but it worked in my head at the > time. It appears, at least on my system, that Python will find > site-packages/foo before it finds and reads site-packages/foo.pth. > > At least this solution gives me a way to develop my libraries > outside of site-packages. Well, I'm still not totally sure what your setup is, but assuming site-packages/foo is a directory containing an __init__.py (that is, it is a package), then yes, it will be found before an alternative package in a directory named with a .pth file. Note that I don't say it will be found before the .pth file, because, again, the finding of the package (when you do "import foo") happens much later than the processing of the .pth file. So it doesn't find site-packages/foo before it reads foo.pth; it just finds site-packages/foo before it finds the other foo that foo.pth was trying to point to. Let's say your .pth file specifies the directory /elsewhere. The .pth file is processed by site.py when the interpreter starts up, and at that time /elsewhere will be appended to sys.path. Later, when you do the import, it searches sys.path in order. site-packages itself will be earlier in sys.path than /elsewhere, so a package site-packages/foo will be found before /elsewhere/foo. The key here is that the .pth file is processed at interpreter-start time, but the search for foo doesn't take place until you actually execute "import foo". If you want to make your /elsewhere "jump the line" and go to the front, look at easy_install.pth, which seems to have some magic code at the end that moves its eggs ahead of site-packages in sys.path. I'm not sure how this works, though, and it seems like a risky proposition. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From Ric at rdo Sun Aug 28 01:24:48 2011 From: Ric at rdo (Ric at rdo) Date: Sun, 28 Aug 2011 01:24:48 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: No, it turned out to be my mistake. Your code was correct and I appreciate it very much. Thank you again On Sat, 27 Aug 2011 18:10:07 -0700, Emile van Sebille wrote: >On 8/27/2011 4:18 PM Ric at rdo.python.org said... >> Thank you so much. The code worked perfectly. >> >> This is what I tried using Emile code. The only time when it picked >> wrong name from the list was when the file was named like this. >> >> Data Mark Stone.doc >> >> How can I fix this? Hope I am not asking too much? > >What name did it pick? I imagine if you're picking a name from a list >of 25000 names that some subset of combinations may yield like ratios. > >But, if you double up on the file name side you may get closer: > >for filename in filenames: > ratios = [SM(ignore,filename+filename,username).ratio() for >username in usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner > >... on the other hand, if you've only got a 100 files to sort out, you >should already be done. > >:) > >Emile From flebber.crue at gmail.com Sun Aug 28 03:56:03 2011 From: flebber.crue at gmail.com (flebber) Date: Sun, 28 Aug 2011 00:56:03 -0700 (PDT) Subject: Python IDE/Eclipse References: Message-ID: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> On Aug 27, 6:34?pm, UncleLaz wrote: > On Aug 26, 5:18?pm, Dave Boland wrote: > > > > > > > > > > > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > > ? Any suggestions? > > > I use Eclipse for other projects and have no problem with using it for > > Python, except that I can't get PyDev to install. ?It takes forever, > > then produces an error that makes no sense. > > > An error occurred while installing the items > > ? ?session context was:(profile=PlatformProfile, > > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). > > ? ?Cannot connect to keystore. > > ? ?This trust engine is read only. > > ? ?The artifact file for > > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > > Any suggestions on getting this to work? > > > Thanks, > > Dave > > I use Aptana Studio 3, it's pretty good and it's based on eclipse Emacs with emacs-for-python makes the install and setup a breeze and emacs does a lot for you without much learning. http://gabrielelanaro.github.com/emacs-for-python/ geany is great I use it the most. http://www.geany.org/ Finally this is a fairly new project, but it could be pretty good. they are heavy in development of version 2. Ninja ide http://ninja-ide.org/ they provide packages for Debian/ubuntu fedora mandriva & windows and the developers are very helpful if you have any issues or questions jump on IRC for a chat. Sayth From mail at johnohagan.com Sun Aug 28 04:18:54 2011 From: mail at johnohagan.com (johnohagan) Date: Sun, 28 Aug 2011 18:18:54 +1000 Subject: Get reference to parent class from subclass? In-Reply-To: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> References: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> Message-ID: <20110828181854.6cf95fa850f0c7417cfc9d7a@johnohagan.com> On Sun, 28 Aug 2011 14:00:24 +1000 John O'Hagan wrote: > class P(): > pass > > class C(P): > pass > > Can I get P from C? > Never mind, it's __bases__ (not found in dir(C)) > > Regards, > > John From wxjmfauth at gmail.com Sun Aug 28 04:43:38 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 28 Aug 2011 01:43:38 -0700 (PDT) Subject: On re / regex replacement Message-ID: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> There is actually a discussion on the dev-list about the replacement of "re" by "regex". I'm not a regular expressions specialist, neither a regex user. However, there is in regex a point that is a little bit disturbing me. The regex module proposes a flag to select the "coding" (wrong word, just to be short): The global flags are: ASCII, LOCALE, NEW, REVERSE, UNICODE. If I can undestand the ASCII flag, ASCII being the "lingua franca" of almost all codings, I am more skeptical about the LOCALE/UNICODE flags. There is in my mind some kind of conflict here. What is 100% unicode compliant shoud be locale independent ("Unicode.org") and a locale depedency means a loss of unicode compliance. I'm fearing some potential problems here: Users or modules working in one mode, while some others are working in the other mode. Nothing technical here. It seems to me nobody has pointed this fact. jmf From greymausg at mail.com Sun Aug 28 06:03:13 2011 From: greymausg at mail.com (greymaus) Date: 28 Aug 2011 10:03:13 GMT Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-27, Steven D'Aprano wrote: > greymaus wrote: > >> On 2011-08-26, D'Arcy J.M. Cain wrote: >>> On 26 Aug 2011 18:39:07 GMT >>> greymaus wrote: >>>> >>>> Is there an equivelent for the AWK RS in Python? >>>> >>>> >>>> as in RS='\n\n' >>>> will seperate a file at two blank line intervals >>> >>> open("file.txt").read().split("\n\n") >>> >> >> >> Ta!.. bit awkard. :)))))) > > Er, is that meant to be a pun? "Awk[w]ard", as in awk-ward? Yup, mispelled it and realized th error :) > > In any case, no, the Python line might be a handful of characters longer > than the AWK equivalent, but it isn't awkward. It is logical and easy to > understand. It's embarrassingly easy to describe what it does: > > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n") # splits the text on double-newlines. > > The only tricky part is knowing that \n means newline, but anyone familiar > with C, Perl, AWK etc. should know that. > > The Python code might be "long" (but only by the standards of AWK, which can > be painfully concise), but it is simple, obvious and readable. A few extra > characters is the price you pay for making your language readable. At the > cost of a few extra key presses, you get something that you will be able to > understand in 10 years time. > > AWK is a specialist text processing language. Python is a general scripting > and programming language. They have different values: AWK values short, > concise code, Python is willing to pay a little more in source code. > > RS, and its Perl equivelent, which I forget, mean that you can read in full multiline records. (I am coming into Python via Perl from AWK, and trying to get a grip on the language and its idions) Thanks to All Oh, Awk is far more than a text processing language, may be old (like me!) but useful (ditto) -- maus . . ... NO CARRIER From ombdalen at gmail.com Sun Aug 28 06:19:54 2011 From: ombdalen at gmail.com (=?UTF-8?Q?Ole_Martin_Bj=C3=B8rndalen?=) Date: Sun, 28 Aug 2011 12:19:54 +0200 Subject: inpipe and outpipe (and other useful functions) Message-ID: Hi! Please excuse me if this i common knowledge, or if I've one again re-implemented something that turned out to be in the standard library, but I think I came up with something rather neat. I'm writing a lot of programs that call external programs, and as much as I love subproces.Popen, I do get tired of writing rather wordy things like: args = ['cmd', 'arg1', 'arg2', 'etc'] p = subprocess.Popen(args, stdin=subprocess.PIPE) for line in p: line = line.decode('latin1') do_something_with(line) Bleh. so last week I had enough, and I sat down and wrote a few functions. No I can do: from lib import inpipe for line in inpipe(args, encoding='latin1'): do_something_with(line) and from lib import outpipe with outpipe(args, addnl=True) as write: write('Python is awesome!') write('') Some code from a program I'm writing: args = ['metaflac', '--show-total-samples', '--show-sample-rate', file] for line in stripped(inpipe(args)): (name, value) = line.split('=') # ... process tag Now, that is a lot more readable than what I had before! The library has a lot of other things in it as well, and is available here: https://github.com/olemb/lib I love Python! -- Ole Martin, http://nerdly.info/ole/ From aspineux at gmail.com Sun Aug 28 07:45:58 2011 From: aspineux at gmail.com (aspineux) Date: Sun, 28 Aug 2011 04:45:58 -0700 (PDT) Subject: pyzmail-0.9.0: high level mail library to read, write and send emails easily Message-ID: Python easy mail library pyzmail is a high level mail library for Python. It provides functions and classes that help to read, compose and send emails. pyzmail exists because their is no reasons that handling mails with Python would be more difficult than with popular mail clients like Outlook or Thunderbird. pyzmail hide the difficulties of the MIME structure and MIME encoding/decoding. It also hide the problem of the internationalized header encoding/decoding. More here http://www.magiksys.net/pyzmail/ You can get a lot of usage samples from the inside API documentation : http://www.magiksys.net/pyzmail/api/index.html This library is the result of 3 articles I wrote about sending mail using python - Parsing email using Python part 1 of 2 : The Header http://blog.magiksys.net/parsing-email-using-python-header - Parsing email using Python part 2 of 2 : The content http://blog.magiksys.net/parsing-email-using-python-content - Generate and send mail with python: tutorial http://blog.magiksys.net/generate-and-send-mail-with-python-tutorial pyzmail also include a very nice "pyzsendmail" command line utility to send the most complex email from the command line. "pyzsendmail -h" for more I'm waiting for your feedback From alec.taylor6 at gmail.com Sun Aug 28 08:53:21 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 28 Aug 2011 22:53:21 +1000 Subject: Python IDE/Eclipse In-Reply-To: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> References: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> Message-ID: Editra On Sun, Aug 28, 2011 at 5:56 PM, flebber wrote: > On Aug 27, 6:34?pm, UncleLaz wrote: >> On Aug 26, 5:18?pm, Dave Boland wrote: >> >> >> >> >> >> >> >> >> >> > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. >> > ? Any suggestions? >> >> > I use Eclipse for other projects and have no problem with using it for >> > Python, except that I can't get PyDev to install. ?It takes forever, >> > then produces an error that makes no sense. >> >> > An error occurred while installing the items >> > ? ?session context was:(profile=PlatformProfile, >> > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, >> > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, >> > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). >> > ? ?Cannot connect to keystore. >> > ? ?This trust engine is read only. >> > ? ?The artifact file for >> > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. >> >> > Any suggestions on getting this to work? >> >> > Thanks, >> > Dave >> >> I use Aptana Studio 3, it's pretty good and it's based on eclipse > > Emacs with emacs-for-python makes the install and setup a breeze and > emacs does a lot for you without much learning. > http://gabrielelanaro.github.com/emacs-for-python/ > > geany is great I use it the most. > http://www.geany.org/ > > Finally this is a fairly new project, but it could be pretty good. > they are heavy in development of version 2. Ninja ide > http://ninja-ide.org/ > they provide packages for Debian/ubuntu fedora mandriva & windows and > the developers are very helpful if you have any issues or questions > jump on IRC for a chat. > > Sayth > -- > http://mail.python.org/mailman/listinfo/python-list > From k.sahithi2862 at gmail.com Sun Aug 28 09:39:02 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sun, 28 Aug 2011 06:39:02 -0700 (PDT) Subject: LATEST HOT PICS Message-ID: <78c81bb1-a264-4aaf-a471-5e1f608906d2@x14g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From vlastimil.brom at gmail.com Sun Aug 28 09:40:05 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 28 Aug 2011 15:40:05 +0200 Subject: On re / regex replacement In-Reply-To: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: 2011/8/28 jmfauth : > There is actually a discussion on the dev-list about the replacement > of "re" by "regex". >... > If I can undestand the ASCII flag, ASCII being the "lingua franca" of > almost all codings, I am more skeptical about the LOCALE/UNICODE > flags. > > There is in my mind some kind of conflict here. What is 100% unicode > compliant shoud be locale independent ("Unicode.org") and a locale > depedency means a loss of unicode compliance. > > I'm fearing some potential problems here: ?Users or modules working > in one mode, while some others are working in the other mode. > >... > jmf > > -- > http://mail.python.org/mailman/listinfo/python-list > As I understand it, regex was designed to be as much compatible with re as possible, sometimes even some problematic (in some interpretation) behaviour is retained as default and "corrected" via the NEW flag (e.g. zero-width split). Also the LOCALE flag seems to be considered as legacy feature and kept with the same behaviour like re; cf.: http://code.google.com/p/mrab-regex-hg/issues/detail?id=6&can=1 In my opinon, the LOCALE flag is not reliable (in a way I would imagine) in either re or regex. In the area of flags regex should work the same way like re or it just adds more possibilities (REVERSE for backwards search, ASCII as the complement for unicode, NEW to enable some incompatible additions or corrections, where the original behaviour could be relied on). The only (understandable) incompatibility I encounter in regex are the new features requiring special syntax, which would obviously raise errors in re or which would be matched literally instead. see http://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails#Additional_features for an overview of the additions. Personally I am very happy with regex, both with its features as well as with the support and maintenance by its developer; however I am mostly using it for manually entered patterns, and less for hardcoded operation. regards, Vlastimil Brom From t at jollybox.de Sun Aug 28 10:04:56 2011 From: t at jollybox.de (Thomas Jollans) Date: Sun, 28 Aug 2011 16:04:56 +0200 Subject: Why do closures do this? In-Reply-To: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: <4E5A4B08.2050405@jollybox.de> On 28/08/11 05:45, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: This does not do what you'd like it to do. But let's assume that, it did, that Python, when encountering a function definition inside a function, "froze" the values of nonlocal variables used in the new function, from the point of view of that function ? that *might* be more intuitive, at least in certain situations. However, what if you wanted a closure to access a nonlocal variable that changes - acting differently depending on what has since happened in the parent function. That may not be as common, but it is a perfectly plausible situation, and the hack required to support that behaviour in a Python that acts as you had expected it to, a surrogate namespace using a class, list, or dict, is infinitely more cryptic and ugly than the default-parametre hack. Thomas From amitjaluf at gmail.com Sun Aug 28 11:34:27 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Sun, 28 Aug 2011 08:34:27 -0700 (PDT) Subject: about if __name == '__main__': Message-ID: hello group i have one question about this if __name == '__main__': is it same as other languages like[c,c++] main function. because of i google and read faqs and also " http://docs.python.org/faq/programming#how-do-i-find-the-current-module-name" this and i am confused. thanks From tjreedy at udel.edu Sun Aug 28 12:26:18 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 12:26:18 -0400 Subject: Why do closures do this? In-Reply-To: <4E5A4B08.2050405@jollybox.de> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> <4E5A4B08.2050405@jollybox.de> Message-ID: On 8/28/2011 10:04 AM, Thomas Jollans wrote: > This does not do what you'd like it to do. But let's assume that, it > did, that Python, when encountering a function definition inside a > function, "froze" the values of nonlocal variables used in the new > function, from the point of view of that function ? that *might* be more > intuitive, at least in certain situations. However, what if you wanted a > closure to access a nonlocal variable that changes - acting differently > depending on what has since happened in the parent function. > > That may not be as common, but it is a perfectly plausible situation, > and the hack required to support that behaviour in a Python that acts as > you had expected it to, a surrogate namespace using a class, list, or > dict, is infinitely more cryptic and ugly than the default-parametre hack. Or, what if the nonlocal name is not even defined when the closure is. >>> def f(): def g(): print(a) a = 3 g() >>> f() 3 Note that global names also do not have to be defined when a function using them is compiled. The current situation is that nonlocal and global names are treated the same way. This makes normal and nested functions as much the same as possible. This is intentional. It would be extremely disconcerting if moving code that contains a def into or out of a wrapping function radically changed its behavior more than is absolutely necessary. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Aug 28 12:32:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 10:32:23 -0600 Subject: Understanding .pth files In-Reply-To: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> References: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 10:42 AM, Josh English wrote: > According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder. The name of the .pth file is not important. Python uses it to add locations to sys.path; it doesn't care what packages might be contained at those locations. > So my C:\Python27\lib\site-packages\xmldb.pth file has one line: > > c:\dev\XmlDB\xmldb The final xmldb is the actual package, yes? The directory in the .pth file should be one inside which Python can find packages, not a package itself. So the file should have just "c:\dev\XmlDB". Then when you do "import xmldb", Python will look inside the "c:\dev\XmlDB", find the xmldb package, and import it. > > (I've tried the slashes the other way, too, but it doesn't seem to work). > > Is the only solution to delete the installed library and add the dev folder to my site.py file? The preferred solution here is to use virtualenv to set up your development environment without having to modify the installed version in the system site-packages at all. HTH, Ian From ian.g.kelly at gmail.com Sun Aug 28 12:51:32 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 10:51:32 -0600 Subject: about if __name == '__main__': In-Reply-To: References: Message-ID: On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > hello group > > i have one question about this > > if __name == '__main__': First, it should be: if __name__ == '__main__': > is it same as other languages like[c,c++] ?main function. because of i > google and read faqs > and also " http://docs.python.org/faq/programming#how-do-i-find-the-current-module-name" > this and i am confused. No, that is not a main function. It's not even a function. When Python runs a script, it loads that script as a module, sets its name to be __main__, and then executes the entire module, starting from the top as normal. What that if statement defines is an ordinary branch that is only executed if the current module is the main module, as opposed to having been imported from some other module. Normally this will be at the end of the file so that all the definitions in the file will have already been executed. The usual idiom for this is: def main(argv): # parse arguments and begin program logic... pass if __name__ == '__main__': import sys main(sys.argv) This is also frequently used for unit testing of library modules, so that the module can be tested just by running it. # define library classes and functions here if __name__ == '__main__': # perform unit tests Cheers, Ian From yasar11732 at gmail.com Sun Aug 28 13:22:08 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 28 Aug 2011 20:22:08 +0300 Subject: A question about class as an iterator Message-ID: Hi, I got confused about classes as an iterator. I saw something like this: class foo(): __iter__(self): return self next(self): return something But then I saw a __next__ method on some code. So what is the deal, which one should I use and what is the difference? -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Aug 28 14:40:36 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Aug 2011 19:40:36 +0100 Subject: On re / regex replacement In-Reply-To: References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: <4E5A8BA4.4060200@mrabarnett.plus.com> On 28/08/2011 14:40, Vlastimil Brom wrote: > 2011/8/28 jmfauth: >> There is actually a discussion on the dev-list about the replacement >> of "re" by "regex". >> ... >> If I can undestand the ASCII flag, ASCII being the "lingua franca" of >> almost all codings, I am more skeptical about the LOCALE/UNICODE >> flags. >> >> There is in my mind some kind of conflict here. What is 100% unicode >> compliant shoud be locale independent ("Unicode.org") and a locale >> depedency means a loss of unicode compliance. >> >> I'm fearing some potential problems here: Users or modules working >> in one mode, while some others are working in the other mode. >> >> ... >> jmf >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > As I understand it, regex was designed to be as much compatible with > re as possible, sometimes even some problematic (in some > interpretation) behaviour is retained as default and "corrected" via > the NEW flag (e.g. zero-width split). Also the LOCALE flag seems to be > considered as legacy feature and kept with the same behaviour like re; > cf.: http://code.google.com/p/mrab-regex-hg/issues/detail?id=6&can=1 > In my opinon, the LOCALE flag is not reliable (in a way I would > imagine) in either re or regex. > In Python 2, re defaults to ASCII and you must use UNICODE for Unicode strings (the str type is a bytestring). In Python 3, re defaults to UNICODE and you must use ASCII for ASCII bytestrings (the str type is a Unicode string). The LOCALE flag is for locale-dependent 8-bit bytestrings. It uses the toupper and tolower functions of the underlying C library. The regex module tries to be drop-in compatible. It supports the LOCALE flag only because the re module has it. Even Perl has something similar. > In the area of flags regex should work the same way like re or it just > adds more possibilities (REVERSE for backwards search, ASCII as the > complement for unicode, NEW to enable some incompatible additions or > corrections, where the original behaviour could be relied on). > > The only (understandable) incompatibility I encounter in regex are the > new features requiring special syntax, which would obviously raise > errors in re or which would be matched literally instead. > see > http://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails#Additional_features > for an overview of the additions. > In the re module, unknown escape sequences are treated as literals, eg \K is treated as K. The regex module has more escape sequences, so that may break existing regexes, eg \X isn't treated as X, but matches a grapheme. Unknown escape sequences are still treated as literals, as in re. My view is that you shouldn't be relying on that behaviour. If it looks like an escape sequence, it may very well be one. It's like their use in strings literals for file paths on Windows. I would've preferred that a invalid escape sequence in a string literal raised an exception (either it's valid and has a meaning, or it's invalid/reserved for future use). It's a balancing act. Requiring the NEW flag for _any_ deviation from re would be very annoying. > Personally I am very happy with regex, both with its features as well > as with the support and maintenance by its developer; > however I am mostly using it for manually entered patterns, and less > for hardcoded operation. > And I'm very happy with your feedback. ;-) From woooee at gmail.com Sun Aug 28 14:56:40 2011 From: woooee at gmail.com (woooee) Date: Sun, 28 Aug 2011 11:56:40 -0700 (PDT) Subject: about if __name == '__main__': References: Message-ID: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Two main routines, __main__ and main(), is not the usual or the common way to do it. It is confusing and anyone looking at the end of the program for statements executed when the program is called will find an isolated call to main(), and then have to search the program for the statements that should have been at the bottom of the program. The only reason to use such a technique in Python is if you want to call the function if the program is run from the command line, and also call the same function if the program is imported from another. In which case, use a name that is descriptive, not "main". And be careful of anyone that gives you programming advice. Research these things for yourself. From paul.nospam at rudin.co.uk Sun Aug 28 15:18:11 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 28 Aug 2011 20:18:11 +0100 Subject: Processing a large string References: Message-ID: <87y5ydqr9o.fsf@no-fixed-abode.cable.virginmedia.net> goldtech writes: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > > Thanks. s = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn" for k, subs in itertools.groupby(s, lambda x: x=="3"): print ''.join(subs) what you actually do in the body of the loop depends on what you want to do with the bits. From yasar11732 at gmail.com Sun Aug 28 15:52:23 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 28 Aug 2011 22:52:23 +0300 Subject: Fwd: Processing a large string In-Reply-To: References: <87y5ydqr9o.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: ---------- Y?nlendirilmi? ileti ---------- Kimden: Ya?ar Arabac? Tarih: 28 A?ustos 2011 22:51 Konu: Re: Processing a large string Kime: Paul Rudin Are you getting Overflow error or memory error? If you don't know what those means: Overflow error occurs when your lists gets bigger than sys.maxsize in size. Memory error occurs, when your objects take too much memory that no more memory can be allocated for you. For example, if you have only one item in your list, and that item consumes all your memory, you will get memory error. On the other hand, if you put so much items to the list that list index hits the sys.maxsize value, you will get Overflow error. Answer to your questions depends on spesifics of your needs and current situation. If you can read whole of the string without getting memory error, you wont get memory error when you split the string into a list (at least in my theory), but you can still get Overflowerror (in 2.6 at least.). If your string is in a file or buffer, I would do something like, file__ = open("big-string.txt","r") output__ = open("outputfile","w") temp__ = "" def process_string(string_): return processed_string while 1: new_char = file.read(1) if new_char == "": break elif new_char == "3": output__.write(process_string(temp__)) temp__ = "" else: temp__ = temp__ + new_char 2011/8/28 Paul Rudin > goldtech writes: > > > Hi, > > > > Say I have a very big string with a pattern like: > > > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > > > I want to split the sting into separate parts on the "3" and process > > each part separately. I might run into memory limitations if I use > > "split" and get a big array(?) I wondered if there's a way I could > > read (stream?) the string from start to finish and read what's > > delimited by the "3" into a variable, process the smaller string > > variable then append/build a new string with the processed data? > > > > Would I loop it and read it char by char till a "3"...? Or? > > > > Thanks. > > s = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn" > for k, subs in itertools.groupby(s, lambda x: x=="3"): > print ''.join(subs) > > > what you actually do in the body of the loop depends on what you want to > do with the bits. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://yasar.serveblog.net/ -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sun Aug 28 17:16:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Aug 2011 14:16:30 -0700 (PDT) Subject: Why do closures do this? In-Reply-To: References: Message-ID: On Saturday, August 27, 2011 8:45:05 PM UTC-7, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: .... > My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? It is the preferred behavior for the following case. def foo(): def printlocals(): print a,b,c,d a = 1; b = 4; c = 5; d = 0.1 printlocals() a = 2 printlocals() When seeing a nested function, there are strong expectations by most people that it will behave this way (not to mention it's a lot more useful). It's only for the less common and much more advanced case of creating a closure in a loop that the other behavior would be preferred. Carl Banks From pavlovevidence at gmail.com Sun Aug 28 17:16:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Aug 2011 14:16:30 -0700 (PDT) Subject: Why do closures do this? In-Reply-To: References: Message-ID: On Saturday, August 27, 2011 8:45:05 PM UTC-7, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: .... > My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? It is the preferred behavior for the following case. def foo(): def printlocals(): print a,b,c,d a = 1; b = 4; c = 5; d = 0.1 printlocals() a = 2 printlocals() When seeing a nested function, there are strong expectations by most people that it will behave this way (not to mention it's a lot more useful). It's only for the less common and much more advanced case of creating a closure in a loop that the other behavior would be preferred. Carl Banks From jehugaleahsa at gmail.com Sun Aug 28 17:20:11 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Sun, 28 Aug 2011 14:20:11 -0700 (PDT) Subject: Checking Signature of Function Parameter Message-ID: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> I am trying to write an algorithms library in Python. Most of the functions will accept functions as parameters. For instance, there is a function called any: def any(source, predicate): for item in source: if predicate(item): return true; return false; There are some things I want to make sure of. 1) I want to make sure that source is iterable. 2) More importantly, I want to make sure that predicate is callable, accepting a thing, returning a bool. This is what I have so far: if source is None: raise ValueError("") if not isinstanceof(source, collections.iterable): raise TypeError("") if not callable(predicate): raise TypeError("") The idea here is to check for issues up front. In some of the algorithms, I will be using iterators, so bad arguments might not result in a runtime error until long after the calls are made. For instance, I might implement a filter method like this: def where(source, predicate): for item in source: if predicate(item): yield item Here, an error will be delayed until the first item is pulled from the source. Of course, I realize that functions don't really have return types. Good thing is that virtually everything evaluates to a boolean. I am more concerned with the number of parameters. Finally, can I use decorators to automatically perform these checks, instead of hogging the top of all my methods? From tjreedy at udel.edu Sun Aug 28 17:26:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 17:26:11 -0400 Subject: A question about class as an iterator In-Reply-To: References: Message-ID: On 8/28/2011 1:22 PM, Ya?ar Arabac? wrote: > I got confused about classes as an iterator. I saw something like this: > > class foo(): > __iter__(self): > return self > next(self): > return something 2.x > But then I saw a __next__ method on some code. 3.x This might work in 2.6 or .7, but I do not really know. The next() builting was introduced in 2.6 so that *users* could write item = next(someiter) and have that work in 2.6+ and in 3.x without change. > which one should I use? Depends on your Python version. I recommend you use 3.2 unless you have a reason or need to use something else. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 28 17:31:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 07:31:52 +1000 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > if source is None: raise ValueError("") > if not isinstanceof(source, collections.iterable): raise TypeError("") > if not callable(predicate): raise TypeError("") > Easier: Just ignore the possibilities of failure and carry on with your code. If the source isn't iterable, you'll get an error raised by the for loop. If the predicate's not callable, you'll get an error raised when you try to call it. The only consideration you might need to deal with is that the predicate's not callable, and only if you're worried that consuming something from your source would be a problem (which it won't be with the normal iterables - strings, lists, etc, etc). Otherwise, just let the exceptions be raised! ChrisA From tjreedy at udel.edu Sun Aug 28 17:35:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 17:35:24 -0400 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: On 8/28/2011 2:56 PM, woooee wrote: > Two main routines, __main__ and main(), '__main__' in not a routine, it is the name of the initial module. > is not the usual or the common > way to do it. It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and then have to search the program for > the statements that should have been at the bottom of the program. > The only reason to use such a technique in Python is if you want to > call the function if the program is run from the command line, and > also call the same function if the program is imported from another. > In which case, use a name that is descriptive, not "main". And be > careful of anyone that gives you programming advice. Research these > things for yourself. As far as I know, all the Lib/test/test_xxx.py file have a test_main function, so one can write (in IDLE, for instance) from test.test_xxx import test_main as f; f() and run that test. Very handy. -- Terry Jan Reedy From timr at probo.com Sun Aug 28 18:52:10 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Aug 2011 15:52:10 -0700 Subject: Why PyImport_ExecCodeModule takes char*? References: Message-ID: Mateusz Loskot wrote: > >I'm wondering, why PyImport_ExecCodeModule function takes char* >instead of const char*? My guess is "history". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ian.g.kelly at gmail.com Sun Aug 28 19:55:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 17:55:39 -0600 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 12:56 PM, woooee wrote: > Two main routines, __main__ and main(), is not the usual or the common > way to do it. ?It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and then have to search the program for > the statements that should have been at the bottom of the program. Not a problem if you write them one after another. Besides which, any decent editor will have a command to go directly from the function call to the function definition, so I really don't see this as a problem. > The only reason to use such a technique in Python is if you want to > call the function if the program is run from the command line, and > also call the same function if the program is imported from another. Or if your main "routine" has variables, and you don't particularly want them polluting the module's global namespace. > In which case, use a name that is descriptive, not "main". "main" is descriptive in that it clearly designates the entry point of the script to anybody accustomed to such terminology. But there is certainly no reason it needs to be "main", and in fact I only used that for the example. In an actual script I would use whatever seems appropriate. From cs at zip.com.au Sun Aug 28 19:59:43 2011 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 29 Aug 2011 09:59:43 +1000 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: <20110828235943.GA12678@cskk.homeip.net> On 28Aug2011 11:56, woooee wrote: | Two main routines, __main__ and main(), is not the usual or the common | way to do it. It is confusing and anyone looking at the end of the | program for statements executed when the program is called will find | an isolated call to main(), and then have to search the program for | the statements that should have been at the bottom of the program. Firstly, as Terry remarked, __main__ is a name, not a function. Secondly, "search the program for the statements that should have been at the bottom of the program" isn't how I see it. If I have a module I expect to be usable from the command line easily it looks like this: def main(argv): ... command line program logic ... return exit_code ... all the other module contents ... if __name__ == '__main__': import sys sys.exit(main(sys.argv)) That way the top level command line program logic is at the top of the file where it is easy to find, not buried in the middle or at the bottom. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Anarchy is not lack of order. Anarchy is lack of ORDERS. From srehtvandy at gmail.com Sun Aug 28 20:00:03 2011 From: srehtvandy at gmail.com (luvspython) Date: Sun, 28 Aug 2011 17:00:03 -0700 (PDT) Subject: Unpickle error -- "object has no attribute ...." Message-ID: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> I have an application that needs to keep a history of the values of several attributes of each of many instances of many classes. The history-keeping logic is in a helper class, HistoryKeeper, that's inherited by classes like Vehicle in the example below. Pickling an instance of Vehicle works, but unpickling fails with: "Vehicle object has no attribute '_orderedArgNames'" (_orderedArgNames is an attribute in HistoryKeeper that tells the attributes for which history must be kept.) During unpickling, the exception occurs at the 2nd line in the __getattribute__ method: if item not in object.__getattribute__(self, '_orderedArgNames'): FWIW, cPickle fails the same way. Below is a stripped-down example that fails in unpickling. Can anyone explain why it fails and what I can do to fix it? MANY thanks. ========================================================= import datetime, bisect from collections import OrderedDict # define a class which helps keep date-history of attribute settings in inheriting classes class HistoryKeeper(object): """ Class to maintain a dated history of attribute settings in inheriting classes. The initialization arguments are in an OrderedDict.""" def __init__(self, orderedArgs): super(HistoryKeeper, self).__setattr__('_orderedArgNames', orderedArgs.keys()) #remember the order of unnamed args for arg, value in orderedArgs.items(): if arg != 'self': self.Set(arg, value) """ Get the current value of an attribute, optionally returning its entire history.""" def __getattribute__(self, item, returnHistory=False): value = object.__getattribute__(self, item) if item not in object.__getattribute__(self, '_orderedArgNames'): return value # not an attribute for which we maintain a change history elif returnHistory: return value # return the entire history else: return value[-1][0] # return only the latest value """ Set an attribute by appending the new value and date to existing history of that attribute. Unless a setting-date is supplied, default to today. Set the value only if it's different than the chronological immediately preceding value.""" def __setattr__(self, item, value, date=None): # avoid history keeping if this item isn't among those declared to require it if item not in self._orderedArgNames: super(HistoryKeeper, self).__setattr__(item, value) else: if not date: date = datetime.date.today() # if this attribute has already been set, add this value to that history try: history = self.__getattribute__(item, returnHistory=True) # if a date was supplied, ensure the history remains in chronological order dates = [val[1] for val in history] index = bisect.bisect_right(dates, date) # insert this value into the history unless it doesn't change an existing setting if index == 0 or history[index-1][0] != value: history.insert(index, (value,date)) except: history = [(value, date)] super(HistoryKeeper, self).__setattr__(item, history) def Set(self, item, value): self.__setattr__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): argDict = OrderedDict([('tag',tag),('make',make), ('model',model)]) super(Vehicle, self).__init__(argDict) if __name__ == "__main__": car = Vehicle('TAG123', 'FORD', 'Model A') import pickle pFile = open('car.pk1', 'wb') pickle.dump(car, pFile, -1) pFile.close() print "car pickled OK" pFile = open('car.pk1', 'rb') community = pickle.load(pFile) pFile.close() From tjreedy at udel.edu Sun Aug 28 20:02:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 20:02:39 -0400 Subject: Why PyImport_ExecCodeModule takes char*? In-Reply-To: References: Message-ID: On 8/28/2011 6:52 PM, Tim Roberts wrote: > Mateusz Loskot wrote: >> >> I'm wondering, why PyImport_ExecCodeModule function takes char* >> instead of const char*? > > My guess is "history". I believe some const tags have been added over the last few years. Another factory than mere history for some things is portability across platforms and the main compilers. -- Terry Jan Reedy From jehugaleahsa at gmail.com Sun Aug 28 20:20:30 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Sun, 28 Aug 2011 17:20:30 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> On Aug 28, 5:31?pm, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > > if source is None: raise ValueError("") > > if not isinstanceof(source, collections.iterable): raise TypeError("") > > if not callable(predicate): raise TypeError("") > > Easier: Just ignore the possibilities of failure and carry on with > your code. If the source isn't iterable, you'll get an error raised by > the for loop. If the predicate's not callable, you'll get an error > raised when you try to call it. The only consideration you might need > to deal with is that the predicate's not callable, and only if you're > worried that consuming something from your source would be a problem > (which it won't be with the normal iterables - strings, lists, etc, > etc). Otherwise, just let the exceptions be raised! > > ChrisA I guess my concern is mostly with the delayed exceptions. It is hard to find the source of an error when it doesn't happen immediately. I am writing this library so all of the calls can be chained together (composed). If this nesting gets really deep, finding the source is hard to do, even with a good debugger. Maybe I should give up on it, like you said. I am still familiarizing myself with the paradigm. I want to make sure I am developing code that is consistent with the industry standards. From niklasro at gmail.com Sun Aug 28 20:26:41 2011 From: niklasro at gmail.com (Niklas Rosencrantz) Date: Sun, 28 Aug 2011 17:26:41 -0700 (PDT) Subject: Why I need the parameter when the call doesn't use it? Message-ID: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: ---- class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): def is_submitter_human(self): cResponse = captcha.submit( self.request.get('recaptcha_challenge_field').encode('utf-8'), self.request.get('recaptcha_response_field').encode('utf-8'), CAPTCHA_PRV_KEY, os.environ['REMOTE_ADDR']) return cResponse.is_valid def post(self, view): logging.debug('starting recaptcha check') isHuman = self.is_submitter_human()# here I don't pass a parameter logging.debug('recaptcha check isHuman:' +str(isHuman)) if not isHuman:#failed captcha and can try again #Reprint the form -- It seems unlike other programming languages where the number of arguments in the call are the same as the number of arguments in the function head and python requires me to add one parameter to the function head and I wonder if you call tell me something about the background why? What's the story of using these parameters that are called "self"? Thank you From rosuav at gmail.com Sun Aug 28 20:27:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 10:27:53 +1000 Subject: Checking Signature of Function Parameter In-Reply-To: <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 10:20 AM, Travis Parks wrote: > Maybe I should give up on it, like you said. I am still familiarizing > myself with the paradigm. I want to make sure I am developing code > that is consistent with the industry standards. > In Python, the industry standard is "easier to ask forgiveness than permission" - that is, let the exceptions happen. It's not worth the hassle of error-checking when the result of not checking an error is exactly the same thing. ChrisA From cnchenji at gmail.com Sun Aug 28 20:35:58 2011 From: cnchenji at gmail.com (Gee Chen) Date: Sun, 28 Aug 2011 17:35:58 -0700 (PDT) Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 Message-ID: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> ---------------------------------- the Python environment on my mac is: Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664) Copyright (C) 2007 Free Software Foundation, Inc. --------------------------------------------------------------------- I found the download adresses of scipy and numpy from official website 'www.scipy.org'. After downloading 2 latest released dmg files, i directly installed them with double-click the dmg files. Then, i opened Python interpreter in Terminal, and tested whether scipy & numpy work. The result is disappointed! when i inputed ' import scipy' & 'import numpy', the output is : >>> import scipy Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/scipy/_init_.py", line 78, in from numpy import show_config as show_numpy_config File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/_init_.py", line 137, in import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/add_newdocs.py", line 9, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/_init_.py", line 4, in from type_check import * File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/type_check.py", line 8, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/_init_.py", line 5, in import multiarray ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/numpy/core/multiarray.so: no matching architecture in universal wrapper >>> >>> import numpy Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/_init_.py", line 137, in import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/add_newdocs.py", line 9, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/_init_.py", line 4, in from type_check import * File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/type_check.py", line 8, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/_init_.py", line 5, in import multiarray ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/numpy/core/multiarray.so: no matching architecture in universal wrapper >>> Is there anybody can tell me where the error exists? From ian.g.kelly at gmail.com Sun Aug 28 20:40:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 18:40:22 -0600 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): > ? ?for item in source: > ? ? ? ?if predicate(item): > ? ? ? ? ? ?return true; > ? ?return false; Perhaps not the best name, since there is already a built-in called "any" that would be masked by this. Using the built-in, "any(source, predicate)" would be written as "any(predicate(x) for x in source)" > I guess my concern is mostly with the delayed exceptions. It is hard > to find the source of an error when it doesn't happen immediately. I > am writing this library so all of the calls can be chained together > (composed). If this nesting gets really deep, finding the source is > hard to do, even with a good debugger. Agreed that there are cases where it is useful to do this. But there is no delayed execution in the example you've given, so the exceptions will happen immediately (or at least, within the same stack frame). The stack traces will still come from the "any" function and will look basically the same as the stack traces you'll get from raising the exceptions by hand. HTH, Ian From clp2 at rebertia.com Sun Aug 28 21:14:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:14:27 -0700 Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 In-Reply-To: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> References: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 5:35 PM, Gee Chen wrote: > ---------------------------------- > the Python environment on my mac is: > > Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin For future reference, when on OS X, it's very helpful to include how you installed your Python, and whether it's 32-bit or 64-bit. > I found the download adresses of scipy and numpy from official website > 'www.scipy.org'. After downloading 2 latest released dmg files, i > directly installed them with double-click the dmg files. > > Then, i opened Python interpreter in Terminal, and tested whether > scipy & numpy work. The result is disappointed! > > when i inputed ' import scipy' & 'import numpy', the output is : > > >>>> import scipy > Traceback (most recent call last): > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > site-packages/numpy/core/_init_.py", line 5, in > import multiarray > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable > image found. Did find: > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- > packages/numpy/core/multiarray.so: no matching architecture in > universal wrapper > Is there anybody can tell me where the error exists? I believe you've installed 32-bit libraries for a 64-bit Python (or possibly vice-versa). It appears that NumPy & SciPy official releases are 32-bit-only. So, you can either use the alternate, unofficial 64-bit releases of those packages, or install a 32-bit Python (via Fink, MacPorts, a Python.org installer, etc.). A third option is to install the Enthought Python Distribution (http://www.enthought.com/products/epd.php ) or similar, which bundles Python together with SciPy, NumPy, and other libraries in a single install. Cheers, Chris -- http://rebertia.com From russ.paielli at gmail.com Sun Aug 28 21:15:56 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 18:15:56 -0700 (PDT) Subject: killing a script Message-ID: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> I have a Python (2.6.x) script on Linux that loops through many directories and does processing for each. That processing includes several "os.system" calls for each directory (some to other Python scripts, others to bash scripts). Occasionally something goes wrong, and the top-level script just keeps running with a stack dump for each case. When I see that, I want to just kill the whole thing and fix the bug. However, when I hit Control- C, it apparently just just kills whichever script happens to be running at that instant, and the top level script just moves to the next line and keeps running. If I hit Control-C repeatedly, I eventually get "lucky" and kill the top-level script. Is there a simple way to ensure that the first Control-C will kill the whole darn thing, i.e, the top-level script? Thanks. --Russ P. From clp2 at rebertia.com Sun Aug 28 21:21:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:21:57 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): > ? ?for item in source: > ? ? ? ?if predicate(item): > ? ? ? ? ? ?return true; > ? ?return false; > > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > I am more concerned with the number of parameters. That can be introspected using the `inspect` module: http://docs.python.org/library/inspect.html#inspect.getargspec > Finally, can I use decorators to automatically perform these checks, > instead of hogging the top of all my methods? Certainly. Although, as others have said, the cost-benefit ratio of adding code to perform such somewhat-redundant checks might make it not worth the trouble. Cheers, Chris From praveen.venkata at gmail.com Sun Aug 28 21:30:00 2011 From: praveen.venkata at gmail.com (Ven) Date: Sun, 28 Aug 2011 18:30:00 -0700 (PDT) Subject: Button Label change on EVT_BUTTON in wxpython!!! Message-ID: Some system info before proceeding further: Platform: Mac OS X 10.7.1 Python Version: ActiveState Python 2.7.1 wxPython Version: [url=http://downloads.sourceforge.net/wxpython/ wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/ url] I want the button label to be changed while performing a task So, here is what I did/want: self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) def OnRun(self,evt): self.run_button.SetLabel('Installing..') #call a function that does the installation task installation_task() #After task completion, set the button label back to "Install" self.run_button.SetLabel('Install') When I try doing this, it doesn't set the label to "Installing" while the task is being performed. Any suggestions how do I achieve this? From ben+python at benfinney.id.au Sun Aug 28 21:32:22 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 11:32:22 +1000 Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87mxett32x.fsf@benfinney.id.au> Niklas Rosencrantz writes: > I modularize code for a webapp and I want to know what python makes > that a need to define an argument called self? Because, when calling a method on an instance, the instance is a parameter to the call. That is, foo = Thribble() foo.bar("spam") is usually syntactic sugar for foo = Thribble() foo.__class__.bar(foo, "spam") and so the definition of that function on the Thribble class needs to accept both parameters. > Here's some code where I'm modularizing a recaptcha test to a function > and the I must add the parameter "self" to the function > is_submitter_human Yes, because the code of ?is_submitter_human? needs to know *which* instance has been passed. That instance is bound to the first parameter, which is conventionally named ?self?. > It seems unlike other programming languages where the number of > arguments in the call are the same as the number of arguments in the > function head and python requires me to add one parameter to the > function head and I wonder if you call tell me something about the > background why? I hope that explains. See also: -- \ ?Nullius in verba? (?Take no-one's word for it?) ?motto of the | `\ Royal Society, since 1663-06-30 | _o__) | Ben Finney From chris at gonnerman.org Sun Aug 28 21:42:32 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Sun, 28 Aug 2011 20:42:32 -0500 Subject: [Python] Why I need the parameter when the call doesn't use it? In-Reply-To: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <4E5AEE88.1000000@gonnerman.org> On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: > I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: > > ---- > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > def is_submitter_human(self): is_submitter_human() isn't a function, it's a method. Methods are always called with a reference to the class instance (i.e. the object) that the method belongs to; this reference is the first argument, and is conventionally called "self". Though I've hacked it out, your code sample includes calls to other methods of the object, by calling self.methodname(). Without the first parameter, how else would you do it? -- Chris. From clp2 at rebertia.com Sun Aug 28 21:52:03 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:52:03 -0700 Subject: Why I need the parameter when the call doesn't use it? In-Reply-To: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 5:26 PM, Niklas Rosencrantz wrote: > I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: > > ---- > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > ? ?def is_submitter_human(self): > ? ? ? ?cResponse = captcha.submit( ? ? ? ? ? ? ? ? ? ? self.request.get('recaptcha_challenge_field').encode('utf-8'), ? ? ? ? ? ? ? ? ? ? self.request.get('recaptcha_response_field').encode('utf-8'), > ? ? ? ? ? ? ? ? ? ? CAPTCHA_PRV_KEY, > ? ? ? ? ? ? ? ? ? ? os.environ['REMOTE_ADDR']) > ? ? ? ?return cResponse.is_valid > > ? ?def post(self, view): > ? ? ? ?logging.debug('starting recaptcha check') > ? ? ? ?isHuman = self.is_submitter_human()# here I don't pass a parameter > ? ? ? ?logging.debug('recaptcha check isHuman:' +str(isHuman)) > ? ? ? ?if not isHuman:#failed captcha and can try again > ? ? ? ? ? ?#Reprint the form > > -- > It seems unlike other programming languages where the number of arguments in the call are the same as the number of arguments in the function head and python requires me to add one parameter to the function head and I wonder if you call tell me something about the background why? > > What's the story of using these parameters that are called "self"? Some other languages name the analogous parameter "this" instead of "self", and basically declare it implicitly for you. In both cases, said variable is used to refer to the object that the current method is being called on (e.g. if `w` is a list and I do w.append(v), the list `w` is `self` in the context of the .append() method call). Since Python's object-orientation is slightly impure, you are required to declare `self` explicitly in the parameter list, unlike most other languages. Technically, you are free to name the parameter something else instead of "self"; naming it "self" is merely a convention. However, no matter its name, the first parameter to a method will always receive the current object as its argument value. So, given: x = Foo() Then: x.bar(y, z) is approximately equivalent to: Foo.bar(x, y, z) # perfectly legal working code So the number of arguments actually /does/ match the number of parameters; `x`/`self` is just passed implicitly via the semantics of the dot (".") operator. Cheers, Chris From python at mrabarnett.plus.com Sun Aug 28 21:52:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Aug 2011 02:52:22 +0100 Subject: killing a script In-Reply-To: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4E5AF0D6.3010901@mrabarnett.plus.com> On 29/08/2011 02:15, Russ P. wrote: > I have a Python (2.6.x) script on Linux that loops through many > directories and does processing for each. That processing includes > several "os.system" calls for each directory (some to other Python > scripts, others to bash scripts). > > Occasionally something goes wrong, and the top-level script just keeps > running with a stack dump for each case. When I see that, I want to > just kill the whole thing and fix the bug. However, when I hit Control- > C, it apparently just just kills whichever script happens to be > running at that instant, and the top level script just moves to the > next line and keeps running. If I hit Control-C repeatedly, I > eventually get "lucky" and kill the top-level script. Is there a > simple way to ensure that the first Control-C will kill the whole darn > thing, i.e, the top-level script? Thanks. > You could look at the return value of os.system, which may tell you the exit status of the process. From ben+python at benfinney.id.au Sun Aug 28 22:34:23 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 12:34:23 +1000 Subject: [Python] Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87fwklt07k.fsf@benfinney.id.au> Chris Gonnerman writes: > On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: > > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > > def is_submitter_human(self): > is_submitter_human() isn't a function, it's a method. No, that's not true and may lead to future confusion. Rather, it is a function *and* a method. Not all functions are methods, but all methods are functions. > Methods are always called with a reference to the class instance Also not true, but perhaps too subtle an issue to explore in this thread. > Though I've hacked it out, your code sample includes calls to other > methods of the object, by calling self.methodname(). Without the first > parameter, how else would you do it? Yes, that's exactly the reason. Thanks. -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From philip at semanchuk.com Sun Aug 28 22:34:49 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 28 Aug 2011 22:34:49 -0400 Subject: Button Label change on EVT_BUTTON in wxpython!!! In-Reply-To: References: Message-ID: <5C9EC16C-48EE-4BA3-A3E8-AB72D0271C7F@semanchuk.com> On Aug 28, 2011, at 9:30 PM, Ven wrote: > Some system info before proceeding further: > > Platform: Mac OS X 10.7.1 > Python Version: ActiveState Python 2.7.1 > wxPython Version: [url=http://downloads.sourceforge.net/wxpython/ > wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/ > url] > > I want the button label to be changed while performing a task > > So, here is what I did/want: > > self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') > self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) > > def OnRun(self,evt): > self.run_button.SetLabel('Installing..') > #call a function that does the installation task > installation_task() > #After task completion, set the button label back to "Install" > self.run_button.SetLabel('Install') > > When I try doing this, it doesn't set the label to "Installing" while > the task is being performed. Any suggestions how do I achieve this? Suggestion #1: After you set the label to "Installing...", try adding self.run_button.Refresh() and/or self.run_button.Update(). Suggestion #2: Ask wxPython questions on the wxPython mailing list. Good luck Philip From russ.paielli at gmail.com Sun Aug 28 22:41:25 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 19:41:25 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 6:52?pm, MRAB wrote: > On 29/08/2011 02:15, Russ P. wrote:> I have a Python (2.6.x) script on Linux that loops through many > > directories and does processing for each. That processing includes > > several "os.system" calls for each directory (some to other Python > > scripts, others to bash scripts). > > > Occasionally something goes wrong, and the top-level script just keeps > > running with a stack dump for each case. When I see that, I want to > > just kill the whole thing and fix the bug. However, when I hit Control- > > C, it apparently just just kills whichever script happens to be > > running at that instant, and the top level script just moves to the > > next line and keeps running. If I hit Control-C repeatedly, I > > eventually get "lucky" and kill the top-level script. Is there a > > simple way to ensure that the first Control-C will kill the whole darn > > thing, i.e, the top-level script? Thanks. > > You could look at the return value of os.system, which may tell you the > exit status of the process. Thanks for the suggestion. Yeah, I guess I could do that, but it seems that there should be a simpler way to just kill the "whole enchilada." Hitting Control-C over and over is a bit like whacking moles. --Russ P. From rosuav at gmail.com Sun Aug 28 22:51:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 12:51:13 +1000 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > On Aug 28, 6:52?pm, MRAB wrote: >> You could look at the return value of os.system, which may tell you the >> exit status of the process. > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. I believe the idea of this suggestion is for the outer script to notice that the inner script terminated via Ctrl-C, and would then immediately choose to terminate itself - thus avoiding the whack-a-mole effect. ChrisA From no.email at nospam.invalid Sun Aug 28 22:53:02 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Aug 2011 19:53:02 -0700 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <7xr545vshd.fsf@ruckus.brouhaha.com> "Russ P." writes: > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. Hit Ctrl-Z, which stops execution of the subprogram but doesn't kill it. Then kill both the subprogram and the control program from a terminal window. From kwa at kuwata-lab.com Sun Aug 28 23:07:16 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 29 Aug 2011 12:07:16 +0900 Subject: [ANN] Oktest 0.9.0 released - a new-style testing library In-Reply-To: References: Message-ID: I published presentation slide about Oktest. If you have interested in testing, check it out. http://www.slideshare.net/kwatch/oktest-a-new-style-testing-library-for-python -- regards, makoto kuwata On Sat, Aug 27, 2011 at 9:37 PM, Makoto Kuwata wrote: > Hi, > > I released Oktest 0.9.0. > http://pypi.python.org/pypi/Oktest/ > http://packages.python.org/Oktest/ > > Oktest is a new-style testing library for Python. > :: > > ? ?from oktest import ok, NG > ? ?ok (x) > 0 ? ? ? ? ? ? ? ? # same as assert_(x > 0) > ? ?ok (s) == 'foo' ? ? ? ? ? ?# same as assertEqual(s, 'foo') > ? ?ok (s) != 'foo' ? ? ? ? ? ?# same as assertNotEqual(s, 'foo') > ? ?ok (f).raises(ValueError) ?# same as assertRaises(ValueError, f) > ? ?ok (u'foo').is_a(unicode) ?# same as assert_(isinstance(u'foo', unicode)) > ? ?NG (u'foo').is_a(int) ? ? ?# same as assert_(not isinstance(u'foo', int)) > ? ?ok ('A.txt').is_file() ? ? # same as assert_(os.path.isfile('A.txt')) > ? ?NG ('A.txt').is_dir() ? ? ?# same as assert_(not os.path.isdir('A.txt')) > > See http://packages.python.org/Oktest/ for details. > > NOTICE!! Oktest is a young project and specification may change in the future. > > > Main Enhancements > ----------------- > > * New '@test' decorator provided. It is simple but very powerful. > ?Using @test decorator, you can write test description in free text > ?instead of test method. > ?ex:: > > ? ?class FooTest(unittest.TestCase): > > ? ? ? ?def test_1_plus_1_should_be_2(self): ?# not cool... > ? ? ? ? ? ?self.assertEqual(2, 1+1) > > ? ? ? ?@test("1 + 1 should be 2") ? ?# cool! easy to read & write! > ? ? ? ?def _(self): > ? ? ? ? ? ?self.assertEqual(2, 1+1) > > * Fixture injection support by '@test' decorator. > ?Arguments of test method are regarded as fixture names and > ?they are injected by @test decorator automatically. > ?Instance methods or global functions which name is 'provide_xxxx' are > ?regarded as fixture provider (or builder) for fixture 'xxxx'. > ?ex:: > > ? ?class SosTest(unittest.TestCase): > > ? ? ? ?## > ? ? ? ?## fixture providers. > ? ? ? ?## > ? ? ? ?def provide_member1(self): > ? ? ? ? ? ?return {"name": "Haruhi"} > > ? ? ? ?def provide_member2(self): > ? ? ? ? ? ?return {"name": "Kyon"} > > ? ? ? ?## > ? ? ? ?## fixture releaser (optional) > ? ? ? ?## > ? ? ? ?def release_member1(self, value): > ? ? ? ? ? ?assert value == {"name": "Haruhi"} > > ? ? ? ?## > ? ? ? ?## testcase which requires 'member1' and 'member2' fixtures. > ? ? ? ?## > ? ? ? ?@test("validate member's names") > ? ? ? ?def _(self, member1, member2): > ? ? ? ? ? ?assert member1["name"] == "Haruhi" > ? ? ? ? ? ?assert member2["name"] == "Kyon" > > ?Dependencies between fixtures are resolved automatically. > ?ex:: > > ? ?class BarTest(unittest.TestCase): > > ? ? ? ?## > ? ? ? ?## for example: > ? ? ? ?## - Fixture 'a' depends on 'b' and 'c'. > ? ? ? ?## - Fixture 'c' depends on 'd'. > ? ? ? ?## > ? ? ? ?def provide_a(b, c): ?return b + c + ["A"] > ? ? ? ?def provide_b(): ? ? ?return ["B"] > ? ? ? ?def provide_c(d): ? ? return d + ["C"] > ? ? ? ?def provide_d(): ? ? ?reutrn ["D"] > > ? ? ? ?## > ? ? ? ?## Dependencies between fixtures are solved automatically. > ? ? ? ?## > ? ? ? ?@test("dependency test") > ? ? ? ?def _(self, a): > ? ? ? ? ? ?assert a == ["B", "D", "C", "A"] > > ?If loop exists in dependency then @test reports error. > > ?If you want to integrate with other fixture library, see the following > ?example:: > > ? ? ?class MyFixtureManager(object): > ? ? ? ? ?def __init__(self): > ? ? ? ? ? ? ?self.values = { "x": 100, "y": 200 } > ? ? ? ? ?def provide(self, name): > ? ? ? ? ? ? ?return self.values[name] > ? ? ? ? ?def release(self, name, value): > ? ? ? ? ? ? ?pass > > ? ? ?oktest.fixure_manager = MyFixtureResolver() > > > > Other Enhancements and Changes > ------------------------------ > > * Supports command-line interface to execute test scripts. > * Reporting style is changed. > * New assertion method ``ok(x).attr(name, value)`` to check attribute. > * New assertion method ``ok(x).length(n)``. > * New feature``ok().should`` helps you to check boolean method. > * 'ok(str1) == str2' displays diff if text1 != text2, even when using > ?with unittest module. > * Assertion ``raises()`` supports regular expression to check error message. > * Helper functions in oktest.dummy module are now available as decorator. > * 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'. > * ``oktest.run()`` is changed to return number of failures and errors of tests. > * ``before_each()`` and ``after_each()`` are now non-supported. > * (Experimental) New function ``NOT()`` provided which is same as ``NG()``. > * (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests:: > > See CHANGES.txt for details. > http://packages.python.org/Oktest/CHANGES.txt > > > Have a nice testing life! > > -- > regards, > makoto kuwata > From russ.paielli at gmail.com Sun Aug 28 23:08:25 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 20:08:25 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 7:51?pm, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > > On Aug 28, 6:52?pm, MRAB wrote: > >> You could look at the return value of os.system, which may tell you the > >> exit status of the process. > > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > > that there should be a simpler way to just kill the "whole enchilada." > > Hitting Control-C over and over is a bit like whacking moles. > > I believe the idea of this suggestion is for the outer script to > notice that the inner script terminated via Ctrl-C, and would then > immediately choose to terminate itself - thus avoiding the > whack-a-mole effect. > > ChrisA Yes, but if I am not mistaken, that will require me to put a line or two after each os.system call. That's almost like whack-a-mole at the code level rather than the Control-C level. OK, not a huge deal for one script, but I was hoping for something simpler. I was hoping I could put one line at the top of the script and be done with it. --Russ P. From clp2 at rebertia.com Sun Aug 28 23:16:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 20:16:17 -0700 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > On Aug 28, 7:51?pm, Chris Angelico wrote: >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: >> > On Aug 28, 6:52?pm, MRAB wrote: >> >> You could look at the return value of os.system, which may tell you the >> >> exit status of the process. >> >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems >> > that there should be a simpler way to just kill the "whole enchilada." >> > Hitting Control-C over and over is a bit like whacking moles. >> >> I believe the idea of this suggestion is for the outer script to >> notice that the inner script terminated via Ctrl-C, and would then >> immediately choose to terminate itself - thus avoiding the >> whack-a-mole effect. >> >> ChrisA > > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. Er, just write a wrapper for os.system(), e.g.: def mysystem(cmd): if os.system(cmd): sys.exit() Also, you may want to switch to using the `subprocess` module instead. Cheers, Chris From russ.paielli at gmail.com Sun Aug 28 23:22:10 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 20:22:10 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 8:16?pm, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > > On Aug 28, 7:51?pm, Chris Angelico wrote: > >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > >> > On Aug 28, 6:52?pm, MRAB wrote: > >> >> You could look at the return value of os.system, which may tell you the > >> >> exit status of the process. > > >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > >> > that there should be a simpler way to just kill the "whole enchilada." > >> > Hitting Control-C over and over is a bit like whacking moles. > > >> I believe the idea of this suggestion is for the outer script to > >> notice that the inner script terminated via Ctrl-C, and would then > >> immediately choose to terminate itself - thus avoiding the > >> whack-a-mole effect. > > >> ChrisA > > > Yes, but if I am not mistaken, that will require me to put a line or > > two after each os.system call. > > Er, just write a wrapper for os.system(), e.g.: > > def mysystem(cmd): > ? ? if os.system(cmd): > ? ? ? ? sys.exit() > > Also, you may want to switch to using the `subprocess` module instead. > > Cheers, > Chris Sounds like a good idea. I'll give it a try. Thanks. --Russ P. From gordon at panix.com Sun Aug 28 23:27:17 2011 From: gordon at panix.com (John Gordon) Date: Mon, 29 Aug 2011 03:27:17 +0000 (UTC) Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: In <66a3f64c-d35e-40c7-be69-ddf708e37ba7 at glegroupsg2000goo.googlegroups.com> Niklas Rosencrantz writes: > What's the story of using these parameters that are called "self"? "self" is a reference to the class object, and it allows the method to access other methods and variables within the class. For example, say you have this class: class MyClass(object): def method1(self, x): self.x = x self.say_hello() def say_hello(self): self.x = self.x + 1 print "hello" Without the "self" reference, method1 wouldn't be able to access instance variable x and it wouldn't be able to call say_hello(). If you have a method that doesn't need to access other variables or methods within the class, you can declare it with the @staticmethod decorator. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From amitjaluf at gmail.com Sun Aug 28 23:42:26 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Sun, 28 Aug 2011 20:42:26 -0700 (PDT) Subject: about if __name == '__main__': References: Message-ID: On Aug 28, 12:51?pm, Ian Kelly wrote: > On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > > hello group > > > i have one question about this > > > if __name == '__main__': sorry dear for this and thanks all of you for this................ From anand.ibmgsi at gmail.com Mon Aug 29 00:01:29 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Mon, 29 Aug 2011 09:31:29 +0530 Subject: packaging a python application In-Reply-To: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> References: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> Message-ID: Hi all, This is interesting. Do we have the distribute/setuptools equivalent of postinstall (with ncurses interface) from Debian? My limited foray into setuptools, indicate it doesn't have . Is it a planned feature either? i would like to contribute in that case. ============================================== Anand Jeyahar https://sites.google.com/site/ anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie On Sun, Aug 28, 2011 at 06:22, suresh wrote: > Hi > I created a python application which consists of multiple python files and > a configuration file. I am not sure, how can I distribute it. > > I read distutils2 documentation and a few blogs on python packaging. But I > still have the following questions. > > 1. My package has a configuration file which has to be edited by the user. > How do we achieve that? > > 2. Should the user directly edit the configuration file, or there would be > an interface for doing it...?(I remember my sendmail installations in > Debian/Ubuntu. It would ask a bunch of questions and the cfg file would be > ready) > > I am just confused how to go about... > > thanks > suresh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Aug 29 00:40:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Aug 2011 14:40:38 +1000 Subject: [Python] Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> <87fwklt07k.fsf@benfinney.id.au> Message-ID: <4e5b1847$0$30004$c3e8da3$5496439d@news.astraweb.com> On Mon, 29 Aug 2011 12:34 pm Ben Finney wrote: > Chris Gonnerman writes: > >> On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: >> > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): >> > def is_submitter_human(self): > >> is_submitter_human() isn't a function, it's a method. > > No, that's not true and may lead to future confusion. > > Rather, it is a function *and* a method. Not all functions are methods, > but all methods are functions. Wouldn't it be more accurate to say that methods *wrap* functions? >>> class C(object): ... def spam(self): ... pass ... >>> C().spam > >>> C().spam.im_func (At least for pure Python methods... those written in C, such as for the built-in types, don't.) >> Methods are always called with a reference to the class instance > > Also not true, but perhaps too subtle an issue to explore in this thread. But for the record, you have "normal" instance methods, class methods, static methods, and any other sort of method you can create using the descriptor protocol, such as this one: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ But as Ben hints at, this is getting into fairly advanced territory. -- Steven From samzielkeryner at gmail.com Mon Aug 29 00:49:34 2011 From: samzielkeryner at gmail.com (Sascha) Date: Sun, 28 Aug 2011 21:49:34 -0700 (PDT) Subject: Interact with SQL Database using Python 2.4 or lower Message-ID: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> Hello I have an website on an Australian webhost. I have designed my website to allow people to login & their login details are stored in an SQLite3 database. I interact with the SQLite3 database using pythons SQLite3 module(found only in python2.5 & up) My Problem: the webhost runs Python 2.4 so I cannot communicate with(query or modify) my SQLite3 database. The webhost will not allow me to install my own version of python or upload modules unless I upgrade to VPS. What do you think are my options to still be able to work/interface with my SQL database? Do you know of way to interact with a SQL database using python modules from Python 2.4 or earlier? Do you know of a python 2.4 module that will let me interact with an SQL database(can be MySQL, SQLite, etc.)? From me+list/python at ixokai.io Mon Aug 29 01:09:51 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:09:51 -0700 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> Message-ID: <4E5B1F1F.8070604@ixokai.io> On 8/28/11 9:49 PM, Sascha wrote: > My Problem: the webhost runs Python 2.4 so I cannot communicate > with(query or modify) my SQLite3 database. The webhost will not allow > me to install my own version of python or upload modules unless I > upgrade to VPS. Get a new webhost. Seriously. This is a seriously absurd requirement -- it goes past absurd into malicious incompetence, frankly. Not being able to upload your own modules? There has to be another option. Personally, I'm a major fan of Webfaction -- from price to plans to what's supported to actual effectiveness of their tech support. But I don't know if they have a warehouse in Australia, if their latency with any of their various data centers is suitable for you. Maybe, maybe not -- but there /has/ to be a better option then this site... Good hosts these days are not all that uncommon and are fairly competitive. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Mon Aug 29 01:23:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 15:23:53 +1000 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <4E5B1F1F.8070604@ixokai.io> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: On Mon, Aug 29, 2011 at 3:09 PM, Stephen Hansen wrote: > Get a new webhost. ... > > But I don't know if they have a warehouse in Australia, if their latency > with any of their various data centers is suitable for you. Maybe, maybe > not -- but there /has/ to be a better option then this site... Good > hosts these days are not all that uncommon and are fairly competitive. Having burnt my fingers with a couple of web hosts, and finally decided to host my own web site, I have one major piece of advice regarding this: Get a personal recommendation. Don't sign up with any hosting service unless you have advice from someone you trust who has used that service and been happy with it. I'm sure good hosts aren't uncommon, but nor are bad hosts, and it's easy to get caught up with a lot of hassles and outages. BTW, don't take the fact that I host my own site as a negative recommendation for every hosting company out there. My requirements are somewhat unusual - I want to host a MUD, not just a web site. Hosts that let you do THAT much are usually quite expensive :) ChrisA From me+list/python at ixokai.io Mon Aug 29 01:39:49 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:39:49 -0700 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: <4E5B2625.4080503@ixokai.io> On 8/28/11 10:23 PM, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 3:09 PM, Stephen Hansen > wrote: >> Get a new webhost. ... >> >> But I don't know if they have a warehouse in Australia, if their latency >> with any of their various data centers is suitable for you. Maybe, maybe >> not -- but there /has/ to be a better option then this site... Good >> hosts these days are not all that uncommon and are fairly competitive. > > Having burnt my fingers with a couple of web hosts, and finally > decided to host my own web site, I have one major piece of advice > regarding this: > > Get a personal recommendation. This is good advice, though with prices as they are in many cases -- provided you don't need to start out immediately solid and have some development wiggle-room -- its not a bad thing to experiment. Just don't get too tied to a certain host until you feel them out. Sending them emails with detailed questions before you sign up is a good thing, for example. Good hosts will respond with detailed, specific answers, from real people. Bad hosts will point you to a vague website or stock reply. Real people, reading your real questions, and answering with real answers is a major, major sign of the kind of company I want to do business with. (Bonus points if they respond to complex, technical and legal questions with specific answers within 24 hours -- bonus++ points if the non-legal questions usually get responses in 1, at absurd times even). > BTW, don't take the fact that I host my own site as a negative > recommendation for every hosting company out there. My requirements > are somewhat unusual - I want to host a MUD, not just a web site. > Hosts that let you do THAT much are usually quite expensive :) Hehe, I don't want to get overly advertising in my comments (so I'm so not including a referrer link anywhere), but amusingly enough, my first Webfaction account was signed up for the MUD reason. They officially don't give a rats ass what you run in the background, provided you're just not using more then your RAM allotment and that its not spiking the CPU to a point that affects the rest of the system. I have one account that runs a mud, one that does often semi-significant background processing regularly via cron jobs (which they mailed me about once when it got out of hand-- but they were entirely professional and nice about it, and I fixed it with some controls so it behaved in a more friendly way towards the rest of the system), and one for my personal site where I run an IRC bouncer on, and all is cool. (Why three accounts? One is paid for by a client, one half by me, one by me -- it was just easier, and no way it all would fit under a single plan) Anyways. I shall not further ramble as a satisfied-customer. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wxjmfauth at gmail.com Mon Aug 29 01:40:42 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 28 Aug 2011 22:40:42 -0700 (PDT) Subject: On re / regex replacement References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: <5651b3de-40ae-4fda-b7d2-b59d06bd1e97@o26g2000vbi.googlegroups.com> On 28 ao?t, 20:40, MRAB wrote: > ... > The regex module tries to be drop-in compatible. It supports the LOCALE > flag only because the re module has it. Even Perl has something similar. > ... Ok. That's quite logical. jmf From rosuav at gmail.com Mon Aug 29 01:52:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 15:52:51 +1000 Subject: Web hosting when you need to install your own modules (was Re: Interact with SQL Database using Python 2.4 or lower) Message-ID: On Mon, Aug 29, 2011 at 3:39 PM, Stephen Hansen wrote: > Just don't get too tied to a certain host until you feel them out. > Sending them emails with detailed questions before you sign up is a good > thing, for example. > That helps a lot, but the problems I had with my most recent pay-for web host were less obvious: * Outages that were scheduled, but not notified in a way that I had noticed (it was on their web site, but they didn't mail my registered other email address) * Fine print on their uptime policy that explicitly excluded scheduled outages, and considerably lengthier and more numerous scheduled outages than I would have normally considered reasonable * DNS record changes required a support ticket (this was shared web hosting, so I didn't have control over the BIND files - that's what they said, anyway) * Some sort of weird lack of internal communication that meant that they didn't ever close our account. I still, to this day, am getting emails from their server saying "Hey, you have some package-installed software that's out of date, you should log in and update it". I cannot log in as our account has been suspended for non-payment. I cannot close the account as it is suspended. They somehow didn't get the message four months before the suspension, following their policy strictly, requesting closure. So... yeah. Hopefully, this is a rare situation, but that's why I would look for a personal reference. ChrisA From me+list/python at ixokai.io Mon Aug 29 01:59:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:59:44 -0700 Subject: Web hosting when you need to install your own modules (was Re: Interact with SQL Database using Python 2.4 or lower) In-Reply-To: References: Message-ID: <4E5B2AD0.3050900@ixokai.io> On 8/28/11 10:52 PM, Chris Angelico wrote: > * DNS record changes required a support ticket (this was shared web > hosting, so I didn't have control over the BIND files - that's what > they said, anyway) Ouch: I never let a webhost near my domain names. I was burned somewhere around that a long time ago, and now always keep the jobs of managing my DNS record and hosting my sites /totally/ separate. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Mon Aug 29 02:15:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 16:15:34 +1000 Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87bov8u4jd.fsf@benfinney.id.au> John Gordon writes: > In <66a3f64c-d35e-40c7-be69-ddf708e37ba7 at glegroupsg2000goo.googlegroups.com> Niklas Rosencrantz writes: > > > What's the story of using these parameters that are called "self"? > > "self" is a reference to the class object, and it allows the method to > access other methods and variables within the class. No, ?self? (in an instance method, which is where it's normally used) is bound to the instance object. The class object is a different thing. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From nobody at nowhere.com Mon Aug 29 02:30:37 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Aug 2011 07:30:37 +0100 Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. The "callable" part is do-able, the rest isn't. The predicate may accept an arbitrary set of arguments via the "*args" and/or "**kwargs" syntax, and pass these on to some other function. Exactly *which* function may be the result of an arbitrarily complex expression. Or it may not even call another function, but just use the arbitrary set of arguments in an arbitrarily complex manner. IOW, determining in advance what will or won't work is actually impossible. From mimran774 at gmail.com Mon Aug 29 02:51:54 2011 From: mimran774 at gmail.com (mohammed imran) Date: Sun, 28 Aug 2011 23:51:54 -0700 (PDT) Subject: mohammedimran Message-ID: <3e075a70-5e60-43ce-9626-e608ffb63a3a@s35g2000prm.googlegroups.com> http://123maza.com/65/fun564/ From nobody at nowhere.com Mon Aug 29 02:52:46 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Aug 2011 07:52:46 +0100 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, 28 Aug 2011 18:15:56 -0700, Russ P. wrote: > Is there a > simple way to ensure that the first Control-C will kill the whole darn > thing, i.e, the top-level script? Thanks. You might try using subprocess.Popen() or subprocess.call() rather than os.system(). os.system() calls the platform's system() function. On Unix, this specifically ignores SIGINT and SIGQUIT for the duration of the call, ensuring that Ctrl-C and Ctrl-\ only affect the child process and not the parent. subprocess.Popen() doesn't perform any implicit signal handling; it's implemented in Python in terms of os.fork() and os.execvp[e](). It also has a better interface (i.e. you get to directly control the argument list passed to the child process, rather than having to construct a shell command and hope that you got the quoting/escaping correct). This may not suffice if any of the descendent processes are moved into their own process group, as signals generated by the tty driver are sent only to the foreground process group. However, this is unlikely to be an issue for simple non-interactive programs (e.g. standard Unix "commands"). From t at jollybox.de Mon Aug 29 03:49:26 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 29 Aug 2011 09:49:26 +0200 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4E5B4486.1080300@jollybox.de> On 2011-08-29 05:08, Russ P. wrote: > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. That's almost like whack-a-mole at the > code level rather than the Control-C level. OK, not a huge deal for > one script, but I was hoping for something simpler. I was hoping I > could put one line at the top of the script and be done with it. It's perfectly normal error-handling procedure. In Python, errors are usually handled by exceptions, but if you embed a system that doesn't support exceptions, e.g. external processes or a C library via ctypes, you will of course have to write a little more code in order to handle errors correctly. T From __peter__ at web.de Mon Aug 29 05:02:27 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Aug 2011 11:02:27 +0200 Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: luvspython wrote: > I have an application that needs to keep a history of the values of > several attributes of each of many instances of many classes. The > history-keeping logic is in a helper class, HistoryKeeper, that's > inherited by classes like Vehicle in the example below. > > Pickling an instance of Vehicle works, but unpickling fails with: > "Vehicle object has no attribute > '_orderedArgNames'" (_orderedArgNames is an attribute in > HistoryKeeper that tells the attributes for which history must be > kept.) > > During unpickling, the exception occurs at the 2nd line in the > __getattribute__ method: > if item not in object.__getattribute__(self, > '_orderedArgNames'): > > FWIW, cPickle fails the same way. > > Below is a stripped-down example that fails in unpickling. > > Can anyone explain why it fails and what I can do to fix it? By default unpickling an object does *not* invoke its __init__() method; instead it creates an instance and then updates the __dict__ attribute of that instance. You intercept attribute access with __getattribute__, so to get hold of __dict__ you need to know __dict__["_orderedArgNames"] first, i. e. you run into a bootstrap problem. To fix the error I'd try special-casing "__dict__" def __getattribute__(self, item, ...): if item == "__dict__": return super(HistoryKeeper, self).__getattribute__(item) ... or making _orderedArgNames a class attribute: class HistoryKeeper(object): def __init__(self, orderedArgs): for arg, value in orderedArgs.items(): if arg != 'self': self.Set(arg, value) ... class Vehicle(HistoryKeeper): _orderedArgNames = "tag", "make", "model" ... If that doesn't work out you can write your own __reduce_ex__() method to customise pickling, see http://docs.python.org/library/pickle.html#object.__reduce_ex__ By the way, docstrings belong below the def not above: def f(): """Explain f() here""" From sathish at solitontech.com Mon Aug 29 06:40:06 2011 From: sathish at solitontech.com (Sathish S) Date: Mon, 29 Aug 2011 16:10:06 +0530 Subject: Calling Script from Command line not working Message-ID: Hi Ppl, We created a DLL using cygwin and have written a class based python module for the same. We have created a sample script for the class based python module, that creates an object of the class and calls various methods in the class. This Test script works fine while I run it from IDLE. However when I run it from command prompt it either hangs or just returns without executing the functions. When it returns I do not get a error trace. When I tried to findout where exactly the issue is happening. the issue occurs when I try to call the *cygwin_dll_init* method of the cygwin1.dll . This cygwin1.dll is actualy a dependency to the DLL we have built. So we have to load this DLL and call this *cygwin_dll_init* method before loading my DLL. cyg = cdll.LoadLibrary("cygwin1.dll") cyg.*cygwin_dll_init() #hangs or returns here* *mydll=**cdll.LoadLibrary("my.dll") * *mydll.func1()* * * *I'm trying to understand what exactly is the difference, when we call it IDLE and when we call it from command prompt using the python command. I will have to get the script working from command prompt as well.* * * Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Aug 29 09:09:08 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 29 Aug 2011 09:09:08 -0400 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <4E5B1F1F.8070604@ixokai.io> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: <1314623348.23664.140258134885497@webmail.messagingengine.com> > Personally, I'm a major fan of Webfaction -- from price to plans to what's supported to actual effectiveness of their tech support. +1 Malcolm From ramapraba2653 at gmail.com Mon Aug 29 09:30:36 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Mon, 29 Aug 2011 06:30:36 -0700 (PDT) Subject: ONLY FOR HOT GUYS Message-ID: <5b263734-1b40-40bf-98ab-f97f9c026178@e34g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From steve+comp.lang.python at pearwood.info Mon Aug 29 09:56:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Aug 2011 23:56:16 +1000 Subject: A tale of yak shaving Message-ID: <4e5b9a81$0$29968$c3e8da3$5496439d@news.astraweb.com> This is not exactly fresh (it was written back in March), but it's the first time I saw it and I thought I'd share. Barry Warsaw, one of the lead Python developers, describes one of his most ... interesting ... debugging experiences. http://www.wefearchange.org/2011/03/charming-snakes-and-shaving-yaks.html [quote] Everyone who reported the problem said the TypeError was getting thrown on the for-statement line. The exception message indicated that Python was getting some object that it was trying to convert to an integer, but was failing. How could you possible get that exception when either making a copy of a list or iterating over that copy? Was the list corrupted? Was it not actually a list but some list-like object that was somehow returning non-integers for its min and max indexes? [end quote] -- Steven From jacktradespublic at gmail.com Mon Aug 29 10:41:51 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 09:41:51 -0500 Subject: Returning a value from exec or a better solution Message-ID: I'm writing a Scheme interpreter and I need to be able to create and return a Python function from a string. This is a port of another Scheme interpreter I wrote in Scheme. What I'm trying to do looked like this: (define (scheme-syntax expr) (hash-table-set! global-syntax (car expr) (eval (cadr expr)))) Where expr was of the form (symbol (lambda (exp) ...)). This added a new special form handler. I came up with a very ugly solution in Python: def add_special_form_handler(expr): exec(expr.cdr.car) special_forms[expr.car] = f Where expr.car = the symbol to be dispatched on and expr.cdr.car = a string of Python code defining a function that must be named f. I wanted to use an anonymous function here, but with the limitations of Python's lambda that would probably make things more complicated. Failing that I wanted to allow the user to manually return the function from the string, like this: a = exec(""" def double(x): return x * 2 double """) However it seems that exec does not return a value as it produces a SyntaxError whenever I try to assign it. Is there a better way to do this? -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Aug 29 10:52:40 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Aug 2011 14:52:40 GMT Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <9c1ndoFj9iU10@mid.individual.net> On 2011-08-26, Chris Angelico wrote: > On Sat, Aug 27, 2011 at 1:48 AM, Tobiah > wrote: >> While I understand and agree with that basic tenet, I think >> that the capitalized 'ONLY' is too strong. ?I do split out >> code into function for readability, even when the function >> will only be called from the place from which I split it out. > > This can be good and can be bad. It's good when it aids > readability; it's bad when you need to pass practically the > entire locals() as function arguments and/or return values. Even when lots of context is needed, defining the context with function calls is a big improvement over directly using names in a module's global namespace. Sometimes repeatedly reused context suggests that creating new classes of objects might be a good idea. > I would split the function only when both halves (caller and > callee) can be given short and useful names - if you can't > explain what a block of code does in a few words, it's probably > a poor choice for splitting out into a function. I agree, except for the implied unconditional preference for short names. I believe the length of a name should usually be proportional to the scope of the object it represents. In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil Cerutti, and in the global scope I have to use a meaningless unique identifier. Hopefully no Python namespace ever gets that big. -- Neil Cerutti From drsalists at gmail.com Mon Aug 29 11:14:43 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Aug 2011 08:14:43 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > You can check a lot of this stuff very inexpensively by using pylint, pychecker or pyflakes. I use pylint quite a bit. Along with many kinds of type errors (except almost anything can be legitimately used in a boolean context), it'll detect when you define an any(), hiding the builtin one. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cnchenji at gmail.com Mon Aug 29 11:32:30 2011 From: cnchenji at gmail.com (Gee Chen) Date: Mon, 29 Aug 2011 08:32:30 -0700 (PDT) Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 References: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> Message-ID: <7cfdd69e-fbea-47e7-8a88-8a977c4736df@b34g2000prf.googlegroups.com> On Aug 29, 9:14?am, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 5:35 PM, Gee Chen wrote: > > ---------------------------------- > > the Python environment on my mac is: > > > Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) > > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > > For future reference, when on OS X, it's very helpful to include how > you installed your Python, and whether it's 32-bit or 64-bit. > > > > > > > > > > > > > I found the download adresses of scipy and numpy from official website > > 'www.scipy.org'. After downloading 2 latest released dmg files, i > > directly installed them with double-click the dmg files. > > > Then, i opened Python interpreter in Terminal, and tested whether > > scipy & numpy work. The result is disappointed! > > > when i inputed ' import scipy' & 'import numpy', the output is : > > >>>> import scipy > > Traceback (most recent call last): > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > > site-packages/numpy/core/_init_.py", line 5, in > > import multiarray > > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > > lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable > > image found. Did find: > > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- > > packages/numpy/core/multiarray.so: no matching architecture in > > universal wrapper > > > Is there anybody can tell me where the error exists? > > I believe you've installed 32-bit libraries for a 64-bit Python (or > possibly vice-versa). It appears that NumPy & SciPy official releases > are 32-bit-only. So, you can either use the alternate, unofficial > 64-bit releases of those packages, or install a 32-bit Python (via > Fink, MacPorts, a Python.org installer, etc.). A third option is to > install the Enthought Python Distribution > (http://www.enthought.com/products/epd.php) or similar, which bundles > Python together with SciPy, NumPy, and other libraries in a single > install. > > Cheers, > Chris > --http://rebertia.com thanks for your help. the problem was solved.. From srehtvandy at gmail.com Mon Aug 29 12:22:52 2011 From: srehtvandy at gmail.com (luvspython) Date: Mon, 29 Aug 2011 09:22:52 -0700 (PDT) Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: On Aug 29, 5:02?am, Peter Otten <__pete... at web.de> wrote: > luvspython wrote: > > I have an application that needs to keep a history of the values of > > several attributes of each of many instances of many classes. ?The > > history-keeping logic is in a helper class, HistoryKeeper, that's > > inherited by classes like Vehicle in the example below. > > > Pickling an instance of Vehicle works, but unpickling fails with: > > ?"Vehicle object has no attribute > > '_orderedArgNames'" ? (_orderedArgNames is an attribute in > > HistoryKeeper that tells the attributes for which history must be > > kept.) > > > During unpickling, the exception occurs at the 2nd line in the > > __getattribute__ method: > > ? ? ? ? if item not in object.__getattribute__(self, > > '_orderedArgNames'): > > > FWIW, cPickle fails the same way. > > > Below is a stripped-down example that fails in unpickling. > > > Can anyone explain why it fails and what I can do to fix it? > > By default unpickling an object does *not* invoke its __init__() method; > instead it creates an instance and then updates the __dict__ attribute of > that instance. You intercept attribute access with __getattribute__, so to > get hold of __dict__ you need to know __dict__["_orderedArgNames"] first, i. > e. you run into a bootstrap problem. > > To fix the error I'd try special-casing "__dict__" > > def __getattribute__(self, item, ...): > ? ? if item == "__dict__": > ? ? ? ? return super(HistoryKeeper, self).__getattribute__(item) > ? ? ... > > or making _orderedArgNames a class attribute: > > class HistoryKeeper(object): > ? ? def __init__(self, orderedArgs): > ? ? ? ? for arg, value in orderedArgs.items(): > ? ? ? ? ? ? if arg != 'self': > ? ? ? ? ? ? ? ? self.Set(arg, value) > ? ? ... > > class Vehicle(HistoryKeeper): > ? ? _orderedArgNames = "tag", "make", "model" > ? ? ... > > If that doesn't work out you can write your own __reduce_ex__() method to > customise pickling, seehttp://docs.python.org/library/pickle.html#object.__reduce_ex__ > > By the way, docstrings belong below the def not above: > > def f(): > ? ? """Explain f() here"""- Hide quoted text - > > - Show quoted text - THANK YOU! Special-casing "__dict__" did the trick. Not sure I'd have ever figured that out, which leads to a different question: I can figure out most things, though perhaps very slowly and painfully, if I can trace through code. I use WingIDE (love it), but the execution of the C code is of course hidden, which helped stymie on this problem. Is there another tool y'all might use and you can suggest that deals with that problem and would have helped me with this case? Or is one's ability to figure out this sort of problem largely dependent on really understanding the system's internals? From jehugaleahsa at gmail.com Mon Aug 29 12:45:51 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Mon, 29 Aug 2011 09:45:51 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Aug 29, 2:30?am, Nobody wrote: > On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > > More importantly, I want to make sure that > > predicate is callable, accepting a thing, returning a bool. > > The "callable" part is do-able, the rest isn't. > > The predicate may accept an arbitrary set of arguments via the "*args" > and/or "**kwargs" syntax, and pass these on to some other function. > Exactly *which* function may be the result of an arbitrarily complex > expression. Or it may not even call another function, but just use the > arbitrary set of arguments in an arbitrarily complex manner. > > IOW, determining in advance what will or won't work is actually impossible. > > Thanks for everyone's input. I decided that I will put some basic checks up front, like "is it None", "is it Iterable" and "is it callable". Other than that, I am letting things slide. Asking for forgiveness is always easier anyway. Just so everyone knows, I am defining these methods inside a class called IterableExtender: class IterableExtender(collections.Iterable):... I wanted to allow for calls like this: extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == 0).first(lambda x: x % 7 == 0) It allows me to compose method calls similarly to LINQ in C#. I think this looks better than: first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, lambda x : x % 7 == 0))) Internally to the class, there are "private" static methods taking raw inputs and performing no checks. The public instance methods are responsible for checking input arguments and wrapping results. Eventually, I will start working on algorithms that work on MutableSequences, but for now I am just doing Iterables. This is turning out to be a great learning experience. From rtw at rtw.me.uk Mon Aug 29 13:30:53 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Mon, 29 Aug 2011 17:30:53 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOg=GtFGPmTB=1OJNvNRPdYUcxDoKN1WJQMOMv9gx0+fZA at mail.gmail.com in gmane.comp.python.general: > ... I wanted to allow the user to manually return the > function from the string, like this: > > a = exec(""" > def double(x): > return x * 2 > double > """) > > However it seems that exec does not return a value as it produces a > SyntaxError whenever I try to assign it. def test(): src = ( "def double(x):" " return x * 2" ) globals = {} exec( src, globals ) return globals[ "double" ] print( test() ) The a bove works on 2.7 (I tested it) on earlier versions you may need to use: exec src in globals Rob. From ian.g.kelly at gmail.com Mon Aug 29 13:42:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Aug 2011 11:42:51 -0600 Subject: Checking Signature of Function Parameter In-Reply-To: References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > I wanted to allow for calls like this: > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > 0).first(lambda x: x % 7 == 0) > > It allows me to compose method calls similarly to LINQ in C#. I think > this looks better than: > > first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, > lambda x : x % 7 == 0))) FWIW, I would be inclined to write that in Python like this: def first(iterable): try: return next(iter(iterable)) except StopIteration: raise ValueError("iterable was empty") squares = (x * x for x in range(0, 1000)) first(x for x in squares if x % 14 == 0) It does a bit too much to comfortably be a one-liner no matter which way you write it, so I split it into two. Cheers, Ian From rtw at rtw.me.uk Mon Aug 29 13:46:49 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Mon, 29 Aug 2011 17:46:49 +0000 (UTC) Subject: Button Label change on EVT_BUTTON in wxpython!!! References: Message-ID: Ven wrote in news:aa1212bb-35e5-4bf9-b8ad-7a3c083749c2 @x2g2000yql.googlegroups.com in gmane.comp.python.general: > So, here is what I did/want: > > self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') > self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) > > def OnRun(self,evt): > self.run_button.SetLabel('Installing..') > #call a function that does the installation task > installation_task() > #After task completion, set the button label back to "Install" > self.run_button.SetLabel('Install') > > When I try doing this, it doesn't set the label to "Installing" while > the task is being performed. Any suggestions how do I achieve this? > http://wiki.wxpython.org/CallAfter Using this your OnRun will become somthing like: def OnRun( self, evt ): def after(): installation_task() self.run_button.SetLabel('Install') self.run_button.SetLabel('Installing..') wx.Callafter( after ) However if installation_task takes a long time you will need to use threads, something like (untested): def OnRun( self, evt ): def after(): self.run_button.SetLabel('Install') def task(): installation_task() wx.Callafter( after ) self.run_button.SetLabel('Installing..') import threading threading.Thread( target = task ).start() Rob. From roy at panix.com Mon Aug 29 13:53:35 2011 From: roy at panix.com (Roy Smith) Date: Mon, 29 Aug 2011 10:53:35 -0700 (PDT) Subject: Help me understand this logging config Message-ID: I'm using django 1.3 and python 2.6. My logging config is: LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(asctime)s: %(name)s %(levelname)s % (funcName)s %(message)s' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose', }, }, 'loggers': { 'django.request': {'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'djfront': {'handlers': ['console'], 'propagate': True, }, 'djfront.view': {'level': 'INFO'}, 'djfront.auth': {'level': 'INFO'}, 'djfront.auth.user': {'level': 'INFO'}, 'djfront.api': {'level': 'WARN'}, } } In my code, I do: logger = logging.getLogger('djfront.auth.facebook') Since I haven't configured a 'djfront.auth.facebook' logger, it should inherit the 'djfront.auth' config, which means the logging level should be set to INFO. But, when I do: logger.debug('redirecting to "%s"' % url) it emits a message: 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init redirecting to [...] I'm confused. Why is the debug level message not getting filtered out? From jehugaleahsa at gmail.com Mon Aug 29 14:04:55 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Mon, 29 Aug 2011 11:04:55 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Aug 29, 1:42?pm, Ian Kelly wrote: > On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > > I wanted to allow for calls like this: > > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > > 0).first(lambda x: x % 7 == 0) > > > It allows me to compose method calls similarly to LINQ in C#. I think > > this looks better than: > > > first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, > > lambda x : x % 7 == 0))) > > FWIW, I would be inclined to write that in Python like this: > > def first(iterable): > ? ? try: > ? ? ? ? return next(iter(iterable)) > ? ? except StopIteration: > ? ? ? ? raise ValueError("iterable was empty") > > squares = (x * x for x in range(0, 1000)) > first(x for x in squares if x % 14 == 0) Python's comprehensions make the need for many of the methods I am writing unnecessary. Which probably explains why no ones really bothered to write one before. The only problem I have above is either the composition causes complex method calls first(where(map(range(..., it requires complex comprehensions or it requires breaking the code into steps. Even my approach has problems, such as the overhead of carrying an invisible wrapper around. > > It does a bit too much to comfortably be a one-liner no matter which > way you write it, so I split it into two. > > Cheers, > Ian > > Yeah. I have already seen a lot of better ways of writing my code based solely on your example. I didn't know about iter as a built-in function. I have been calling __iter__ directly. I also need to think more about whether methods like "where" and "map" are going to be beneficial. The good thing is that someone will be able to use my wrapper in any context where an Iterable can be used. It will allow someone to switch between styles on the fly. I'm still not convinced that this library is going to be very "pythony". I wrote a post a few days ago about how I know the syntax and libraries fairly well, but I don't have the "philosophy". I haven't seen a lot of tricks and I am never sure what is the "norm" in Python. I am sure if an experienced Python programmer looked at my code, they'd immediately know I was missing a few things. From rosuav at gmail.com Mon Aug 29 14:20:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 04:20:49 +1000 Subject: is there any principle when writing python function In-Reply-To: <9c1ndoFj9iU10@mid.individual.net> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> Message-ID: On Tue, Aug 30, 2011 at 12:52 AM, Neil Cerutti wrote: >> I would split the function only when both halves (caller and >> callee) can be given short and useful names - if you can't >> explain what a block of code does in a few words, it's probably >> a poor choice for splitting out into a function. > > I agree, except for the implied unconditional preference for > short names. I believe the length of a name should usually be > proportional to the scope of the object it represents. Oh,I definitely prefer short names to this: http://thedailywtf.com/Articles/Double-Line.aspx "Short" is a relative term. If the function's name is 20 characters long and meaningful, that's fine. > In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil > Cerutti, and in the global scope I have to use a meaningless > unique identifier. Hopefully no Python namespace ever gets that > big. Chorus? Does that imply that you sing? Neat :) What you have, I think, is a module named Cerutti, in which you have a class of which Neil is an instance. Inside method functions, you can be referenced by "self" (which is to code what pronouns are to English); outside of them, you are referred to as Neil; and outside the module, Cerutti.Neil is the cleanest way to reference you. But your name is still Neil, no matter how you're referenced. Chris Angelico whose name is sometimes Chris, sometimes Rosuav, and sometimes "Chris or Michael" by people who can't distinguish him from his brother From noreply at domain.invalid Mon Aug 29 14:21:48 2011 From: noreply at domain.invalid (William Gill) Date: Mon, 29 Aug 2011 14:21:48 -0400 Subject: Help parsing a text file Message-ID: I haven't done much with Python for a couple years, bouncing around between other languages and scripts as needs suggest, so I have some minor difficulty keeping Python functionality Python functionality in my head, but I can overcome that as the cobwebs clear. Though I do seem to keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard). I have a text file with XML like records that I need to parse. By XML like I mean records have proper opening and closing tags. but fields don't have closing tags (they rely on line ends). Not all fields appear in all records, but they do adhere to a defined sequence. My initial passes into Python have been very unfocused (a scatter gun of too many possible directions, yielding very messy results), so I'm asking for some suggestions, or algorithms (possibly even examples)that may help me focus. I'm not asking anyone to write my code, just to nudge me toward a more disciplined approach to a common task, and I promise to put in the effort to understand the underlying fundamentals. From rosuav at gmail.com Mon Aug 29 14:27:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 04:27:14 +1000 Subject: Unpickle error -- "object has no attribute ...." In-Reply-To: References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: On Tue, Aug 30, 2011 at 2:22 AM, luvspython wrote: > I can figure out most things, though perhaps very slowly and > painfully, if I can trace through code. ?I use WingIDE (love it), but > the execution > of the C code is of course hidden, which helped stymie on this > problem. ?Is there another tool y'all might use and you can suggest > that deals with that problem and would have helped me with this case? > Or is one's ability to figure out this sort of problem largely > dependent on really understanding the system's internals? In terms of debugging, it's hard to ignore the old favorite stand-by: If In Doubt, Print It Out. Pepper your code with console-output calls and manually trace your code using those. Every other debugging tool you'll ever use is a bonus on top of that; if you accustom yourself to IIDPIO debugging, you'll be able to solve problems in any environment. Python does have a number of other debugging tools, though. I'd recommend looking at pylint, for a start. It's not technically a debugger, but it may be of value. ChrisA From philip at semanchuk.com Mon Aug 29 14:31:13 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 29 Aug 2011 14:31:13 -0400 Subject: Help parsing a text file In-Reply-To: References: Message-ID: <3BC2BAF2-0293-4773-8FD7-40FA2614299D@semanchuk.com> On Aug 29, 2011, at 2:21 PM, William Gill wrote: > I haven't done much with Python for a couple years, bouncing around between other languages and scripts as needs suggest, so I have some minor difficulty keeping Python functionality Python functionality in my head, but I can overcome that as the cobwebs clear. Though I do seem to keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard). > > I have a text file with XML like records that I need to parse. By XML like I mean records have proper opening and closing tags. but fields don't have closing tags (they rely on line ends). Not all fields appear in all records, but they do adhere to a defined sequence. > > My initial passes into Python have been very unfocused (a scatter gun of too many possible directions, yielding very messy results), so I'm asking for some suggestions, or algorithms (possibly even examples)that may help me focus. > > I'm not asking anyone to write my code, just to nudge me toward a more disciplined approach to a common task, and I promise to put in the effort to understand the underlying fundamentals. If the syntax really is close to XML, would it be all that difficult to convert it to proper XML? Then you have nice libraries like ElementTree to use for parsing. Cheers Philip From neilc at norwich.edu Mon Aug 29 14:40:24 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Aug 2011 18:40:24 GMT Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> Message-ID: <9c24onF3ktU2@mid.individual.net> On 2011-08-29, Chris Angelico wrote: >> In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil >> Cerutti, and in the global scope I have to use a meaningless >> unique identifier. Hopefully no Python namespace ever gets that >> big. > > Chorus? Does that imply that you sing? Neat :) Wait... not all Python programmers sing? > What you have, I think, is a module named Cerutti, in which you > have a class of which Neil is an instance. Inside method > functions, you can be referenced by "self" (which is to code > what pronouns are to English); outside of them, you are > referred to as Neil; and outside the module, Cerutti.Neil is > the cleanest way to reference you. But your name is still Neil, > no matter how you're referenced. The problem with that scenario is that, in real life, there's more than one Cerutti.Neil, and they like to move around. ;) -- Neil Cerutti From nospam at domain.invalid Mon Aug 29 14:56:05 2011 From: nospam at domain.invalid (William Gill) Date: Mon, 29 Aug 2011 14:56:05 -0400 Subject: Help parsing a text file In-Reply-To: References: Message-ID: On 8/29/2011 2:31 PM, Philip Semanchuk wrote: > > If the syntax really is close to XML, would it be all that difficult to convert it to proper XML? Then you have nice libraries like ElementTree to use for parsing. > Possibly, but I would still need the same search algorithms to find the opening tag for the field, then find and replace the next line end with a matching closing tag. So it seems to me that the starting point is the same, and then it's my choice to either process the substrings myself or employ something like ElementTree. From rosuav at gmail.com Mon Aug 29 15:02:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 05:02:52 +1000 Subject: is there any principle when writing python function In-Reply-To: <9c24onF3ktU2@mid.individual.net> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> <9c24onF3ktU2@mid.individual.net> Message-ID: On Tue, Aug 30, 2011 at 4:40 AM, Neil Cerutti wrote: > Wait... not all Python programmers sing? I do, and there seems to be more than coincidental overlap between musos and coders. > The problem with that scenario is that, in real life, there's > more than one Cerutti.Neil, and they like to move around. ;) Yes indeed; which means that your Cerutti module is in a package: from norwich import Cerutti It's always possible to make a locally-unique identifier into a more globally unique one by prepending another tag to it. Alternatively, you need to be duck-typed: you're the Neil Cerutti who writes code, and if some other Neil Cerutti is asked to write code, he will throw an exception. That's probably the easiest way to deal with it - but I don't know of a way to implement it in a coded way. Maybe all names actually point to lists of objects, and whenever you try to do something with a name, the system goes through the elements of the list until one doesn't fail? Going back to the original question, the length of function name required for it to be "meaningful" is, obviously, a variable quantity. But I think it's still reasonable to use that as a rule of thumb for dividing functions - if you can sanely name both halves, without putting the entire code into the function name, then you have a case for refactoring. ChrisA From brunoandrade_13 at hotmail.com Mon Aug 29 15:10:22 2011 From: brunoandrade_13 at hotmail.com (Bruno Andrade) Date: Mon, 29 Aug 2011 16:10:22 -0300 Subject: =?iso-8859-1?Q?Institui=E7=F5?= =?iso-8859-1?Q?es_que_uti?= =?iso-8859-1?Q?lizam_Pyth?= =?iso-8859-1?Q?on.?= Message-ID: Ol?, boa tarde! Eu, estou entrando em contato com voc?s, pois eu gostaria de saber quais institui??es brasileiras usam regularmente Python para o desenvolvimento de suas atividades. Essas institui??es podem ser usu?rios de sistemas desenvolvidos usando a linguagem Python, ou podem ser institui??es que criam aplica??es para terceiros usando a linguagem Python. Acredito que talvez, voc?s contenham uma lista com essas institui??es que utilizam Python. Desde j? agrade?o a sua aten??o; Muito Obrigado; Att; Bruno Andrade. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Mon Aug 29 16:55:55 2011 From: jason.swails at gmail.com (Jason Swails) Date: Mon, 29 Aug 2011 16:55:55 -0400 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 10:41 PM, Russ P. wrote: > > > You could look at the return value of os.system, which may tell you the > > exit status of the process. > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. > Agreed. I had written a program that had a similar problem. As others have suggested, you need to either wrap os.system in another function that analyzes the return value of the call or use another approach in which the Python program itself sees the SIGINT (I ended up changing to subprocess.Popen classes since they are more customizable and SIGINT is captured by the Python program itself rather than the child process). Another thing you can consider doing is to define your scripts' behavior if it captures a SIGINT. (Untested) import signal, sys def sigint_handler(): sys.stdout.write('Caught an interruption signal!') sys.exit(1) signal.signal(signal.SIGINT, sigint_handler) **rest of your program** Of course, the SIGINT signal won't be caught if it isn't seen by the main Python process, so this still won't do anything if you use an unprotected/unwrapped os.system command. HTH, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 29 17:05:23 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 29 Aug 2011 23:05:23 +0200 Subject: Help parsing a text file In-Reply-To: References: Message-ID: <4E5BFF13.2070408@jollybox.de> On 29/08/11 20:21, William Gill wrote: > I haven't done much with Python for a couple years, bouncing around > between other languages and scripts as needs suggest, so I have some > minor difficulty keeping Python functionality Python functionality in my > head, but I can overcome that as the cobwebs clear. Though I do seem to > keep tripping over the same Py2 -> Py3 syntax changes (old habits die > hard). > > I have a text file with XML like records that I need to parse. By XML > like I mean records have proper opening and closing tags. but fields > don't have closing tags (they rely on line ends). Not all fields appear > in all records, but they do adhere to a defined sequence. > > My initial passes into Python have been very unfocused (a scatter gun of > too many possible directions, yielding very messy results), so I'm > asking for some suggestions, or algorithms (possibly even examples)that > may help me focus. > > I'm not asking anyone to write my code, just to nudge me toward a more > disciplined approach to a common task, and I promise to put in the > effort to understand the underlying fundamentals. A name that is often thrown around on this list for this kind of question is pyparsing. Now, I don't know anything about it myself, but it may be worth looking into. Otherwise, if you say it's similar to XML, you might want to take a cue from XML processing when it comes to dealing with the file. You could emulate the stream-based approach taken by SAX or eXpat - have methods that handle the different events that can occur - for XML this is "start tag", "end tag", "text node", "processing instruction", etc., in your case, it might be "start/end record", "field data", etc. That way, you could separate the code that keeps track of the current record, and how the data fits together to make an object structure, and the parsing code, that knows how to convert a line of data into something meaningful. Thomas From russ.paielli at gmail.com Mon Aug 29 17:26:20 2011 From: russ.paielli at gmail.com (Russ P.) Date: Mon, 29 Aug 2011 14:26:20 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <01954f13-f3b4-4be1-8038-e452b06b2c7b@fv14g2000vbb.googlegroups.com> On Aug 28, 8:16?pm, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > > On Aug 28, 7:51?pm, Chris Angelico wrote: > >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > >> > On Aug 28, 6:52?pm, MRAB wrote: > >> >> You could look at the return value of os.system, which may tell you the > >> >> exit status of the process. > > >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > >> > that there should be a simpler way to just kill the "whole enchilada." > >> > Hitting Control-C over and over is a bit like whacking moles. > > >> I believe the idea of this suggestion is for the outer script to > >> notice that the inner script terminated via Ctrl-C, and would then > >> immediately choose to terminate itself - thus avoiding the > >> whack-a-mole effect. > > >> ChrisA > > > Yes, but if I am not mistaken, that will require me to put a line or > > two after each os.system call. > > Er, just write a wrapper for os.system(), e.g.: > > def mysystem(cmd): > ? ? if os.system(cmd): > ? ? ? ? sys.exit() > > Also, you may want to switch to using the `subprocess` module instead. > > Cheers, > Chris I ended up with this: def systemx(cmd): if system(cmd): exit("\nERROR: " + cmd + " failed\n") This is good enough for my purposes in this case. Thanks for all the suggestions. --Russ P. From jacktradespublic at gmail.com Mon Aug 29 18:14:11 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 17:14:11 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Mon, Aug 29, 2011 at 12:30 PM, Rob Williscroft wrote: > Jack Trades wrote in > > ... I wanted to allow the user to manually return the > > function from the string, like this: > > > > a = exec(""" > > def double(x): > > return x * 2 > > double > > """) > > > > However it seems that exec does not return a value as it produces a > > SyntaxError whenever I try to assign it. > > def test(): > src = ( > "def double(x):" > " return x * 2" > ) > globals = {} > exec( src, globals ) > return globals[ "double" ] > > print( test() ) > I looked into doing it that way but it still requires that the user use a specific name for the function they are defining. The docs on exec say that an implementation may populate globals or locals with whatever they want so that also rules out doing a simple "for item in globals", as there may be more than just the one function in there (though I suppose I may be able to work around that). -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Aug 29 18:17:35 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 30 Aug 2011 08:17:35 +1000 Subject: For some value of =?utf-8?B?4oCcc2luZ+KAnQ==?= (was: is there any principle when writing python function) References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> <9c24onF3ktU2@mid.individual.net> Message-ID: <87ty8zsw00.fsf_-_@benfinney.id.au> Neil Cerutti writes: > On 2011-08-29, Chris Angelico wrote: > > Chorus? Does that imply that you sing? Neat :) > > Wait... not all Python programmers sing? All Python programmers sing. Some of them should not. -- \ ?To be is to do? ?Plato | `\ ?To do is to be? ?Aristotle | _o__) ?Do be do be do? ?Sinatra | Ben Finney From timothy.c.delaney at gmail.com Mon Aug 29 18:43:17 2011 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 30 Aug 2011 08:43:17 +1000 Subject: =?UTF-8?Q?Re=3A_Institui=C3=A7=C3=B5es_que_utilizam_Python=2E?= In-Reply-To: References: Message-ID: 2011/8/30 Bruno Andrade > Ol?, boa tarde! > > Eu, estou entrando em contato com voc?s, pois eu gostaria de saber quais > institui??es brasileiras usam regularmente Python para o desenvolvimento de > suas atividades. Essas institui??es podem ser usu?rios de sistemas > desenvolvidos usando a linguagem Python, ou podem ser institui??es que criam > aplica??es para terceiros usando a linguagem Python. Acredito que talvez, > voc?s contenham uma lista com essas institui??es que utilizam Python. > Pode come?ar com http://www.python.org.br/. Al?m disso, http://www.google.com.au/search?q=python+brasil. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Mon Aug 29 18:50:46 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 29 Aug 2011 23:50:46 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 29 August 2011 23:14, Jack Trades wrote: > On Mon, Aug 29, 2011 at 12:30 PM, Rob Williscroft wrote: >> >> Jack Trades wrote in >> > ... I wanted to allow the user to manually return the >> > function from the string, like this: >> > >> > a = exec(""" >> > def double(x): >> > ? return x * 2 >> > double >> > """) >> > >> > However it seems that exec does not return a value as it produces a >> > SyntaxError whenever I try to assign it. >> >> def test(): >> ?src = ( >> ? ? ?"def double(x):" >> ? ? ?" ?return x * 2" >> ? ?) >> ?globals ?= {} >> ?exec( src, globals ) >> ?return globals[ "double" ] >> >> print( test() ) > > I looked into doing it that way but it still requires that the user use a > specific name for the function they are defining.? The docs on exec say that > an implementation may populate globals or locals with whatever they want so > that also rules out doing a simple "for item in globals", as there may be > more than just the one function in there (though I suppose I may be able to > work around that). Hi Jack, Here is a possible solution for your problem (Python 3): >>> class CapturingDict(dict): ... def __setitem__(self, key, val): ... self.key, self.val = key, val ... dict.__setitem__(self, key, val) ... >>> c = CapturingDict() >>> exec("def myfunction(x): return 1", c) >>> c.key 'myfunction' >>> c.val HTH, -- Arnaud From arnodel at gmail.com Mon Aug 29 18:53:13 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 29 Aug 2011 23:53:13 +0100 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On 29 August 2011 04:08, Russ P. wrote: > On Aug 28, 7:51?pm, Chris Angelico wrote: >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: >> > On Aug 28, 6:52?pm, MRAB wrote: >> >> You could look at the return value of os.system, which may tell you the >> >> exit status of the process. >> >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems >> > that there should be a simpler way to just kill the "whole enchilada." >> > Hitting Control-C over and over is a bit like whacking moles. >> >> I believe the idea of this suggestion is for the outer script to >> notice that the inner script terminated via Ctrl-C, and would then >> immediately choose to terminate itself - thus avoiding the >> whack-a-mole effect. >> >> ChrisA > > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. That's almost like whack-a-mole at the > code level rather than the Control-C level. OK, not a huge deal for > one script, but I was hoping for something simpler. I was hoping I > could put one line at the top of the script and be done with it. Write a function! That's what they're for after all :) -- Arnaud From ethan at stoneleaf.us Mon Aug 29 19:36:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Aug 2011 16:36:12 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: <4E5C226C.7080801@stoneleaf.us> Travis Parks wrote: > I wrote a post a few days ago about how I know the syntax and > libraries fairly well, but I don't have the "philosophy". I haven't > seen a lot of tricks and I am never sure what is the "norm" in Python. > I am sure if an experienced Python programmer looked at my code, > they'd immediately know I was missing a few things. The best thing to do now is pick something and run with it. (Sounds like you have.) Expect to redesign and reimplement three or four times as you get a feel for what's pythonic. And have fun! ~Ethan~ From jacktradespublic at gmail.com Mon Aug 29 19:39:36 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 18:39:36 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Mon, Aug 29, 2011 at 5:50 PM, Arnaud Delobelle wrote: > > Hi Jack, > > Here is a possible solution for your problem (Python 3): > > > >>> class CapturingDict(dict): > ... def __setitem__(self, key, val): > ... self.key, self.val = key, val > ... dict.__setitem__(self, key, val) > ... > >>> c = CapturingDict() > >>> exec("def myfunction(x): return 1", c) > >>> c.key > 'myfunction' > >>> c.val > > > HTH, > > -- > Arnaud > That's brilliant and works flawlessly. Thank you very much! -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Aug 29 21:22:33 2011 From: usenet-nospam at seebs.net (Seebs) Date: 30 Aug 2011 01:22:33 GMT Subject: A tale of yak shaving References: <4e5b9a81$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-29, Steven D'Aprano wrote: > This is not exactly fresh (it was written back in March), but it's the first > time I saw it and I thought I'd share. Barry Warsaw, one of the lead Python > developers, describes one of his most ... interesting ... debugging > experiences. That is a truly excellent debugging story. I also like the term "yak shaving", and I suspect I'll be using that for future such endeavors. Of which there are a fair number in my line of work. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Tue Aug 30 00:13:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 30 Aug 2011 14:13:41 +1000 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: [...] >> Yes, but if I am not mistaken, that will require me to put a line or >> two after each os.system call. That's almost like whack-a-mole at the >> code level rather than the Control-C level. OK, not a huge deal for >> one script, but I was hoping for something simpler. I was hoping I >> could put one line at the top of the script and be done with it. > > Write a function! That's what they're for after all :) I'm not sure that this is actually as simple as that, especially using os.system. As I understand it, the scenario is this: The main script looks something like this: for x in whatever: os.system('something.py x') Each time through the loop, a new Python process is started. Each process runs in the foreground, capturing standard input, and so hitting Ctrl-C kills *that* process, not the main script. Unless, by chance, the Ctrl-C happens after the system call returns, but before the next one starts, it is completely invisible to the parent process (the main script). Wrapping os.system in a function does nothing to fix that. Possibly using the subprocess module may help. Otherwise, the only way around this I can think of is to ensure that the 'something.py' script (or scripts!) each return an error code for "User Cancelled": for x in whatever: result = os.system('something.py x') if result == 3: # User Cancelled break But if the 'something.py' scripts are arbitrary scripts, I don't think you have any easy way around it. Perhaps use threads, and have the main script ask the thread to kill the child process? Regardless, this is a hard problem, and it isn't possible to just have some magic switch at the top of your script to make it work. You actually have to do the work yourself. (But of course you can do the work inside a function, and re-use it elsewhere.) -- Steven From rtw at rtw.me.uk Tue Aug 30 03:28:41 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 07:28:41 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOh1+oE4g9Frjp3pucbHUtWcN34KK35a-Xs2YqkZH9X5=w at mail.gmail.com in gmane.comp.python.general: >> def test(): >> src = ( >> "def double(x):" >> " return x * 2" >> ) >> globals = {} >> exec( src, globals ) >> return globals[ "double" ] >> >> print( test() ) >> > > I looked into doing it that way but it still requires that the user > use a specific name for the function they are defining. The docs on > exec say that an implementation may populate globals or locals with > whatever they want so that also rules out doing a simple "for item in > globals", as there may be more than just the one function in there > (though I suppose I may be able to work around that). > > Why not just get the name from the user, or use a regular expression to extract the first (or last, maybe) definition from the source string. Rob. From rtw at rtw.me.uk Tue Aug 30 03:37:37 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 07:37:37 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOiOAge3uHrGSDTZ412GAg+CC- 6u8iGOyJ0Lnf3HnwUVzA at mail.gmail.com in gmane.comp.python.general: >> >>> class CapturingDict(dict): >> ... def __setitem__(self, key, val): >> ... self.key, self.val = key, val >> ... dict.__setitem__(self, key, val) >> ... >> >>> c = CapturingDict() >> >>> exec("def myfunction(x): return 1", c) >> >>> c.key >> 'myfunction' >> >>> c.val >> >> >> HTH, >> >> -- >> Arnaud >> > > That's brilliant and works flawlessly. Thank you very much! If an impementation (as you say up thread) can populate globals or locals with whatever they want, then how do you know that last item added was the function definition the user supplied ? Rob. From exhuma at gmail.com Tue Aug 30 04:53:17 2011 From: exhuma at gmail.com (Michel Albert) Date: Tue, 30 Aug 2011 01:53:17 -0700 (PDT) Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? Message-ID: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Hi, I use python oftentimes to write automation scripts on Linux servers. And there's a big pattern in my scripts: - I *always* use `logging` instead of `print` statements. - I *always* create two stream handlers. One for `sys.stdout` with level `INFO` and one for `sys.stderr` with level `WARN` Well, the levels may variate occasionally, but that's only the rare exception. The reason I do this is simple: Most automation tasks are run via cron. With this setup, I can redirect `stdout` to `/dev/null` and still receive e-mails if things go wrong. And having two handlers gives me more flexibility in my scripts. In one case, I used a different color for error messages for example as this script is run primarily from the shell and having errors stand out has proven to be a good thing. Unfortunately this setup makes `logging.basicConfig` pretty useless. However, I believe that this is something that more people could benefit from. I also believe, that it just "makes sense" to send warnings (and above) to `stderr`, the rest to `stdout`. So I was thinking: "Why does `logging.basicConfig` not behave that way". Naturally, I was thinking of writing a patch against the python codebase and submit it as a suggestion. But before doing so, I would like to hear your thoughts on this. Does it make sense to you too or am I on the wrong track? Are there any downsides I am missing? From __peter__ at web.de Tue Aug 30 05:24:44 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 11:24:44 +0200 Subject: Help me understand this logging config References: Message-ID: Roy Smith wrote: > I'm using django 1.3 and python 2.6. Isn't dictConfig() new in 2.7? It looks like that is what you are using... > My logging config is: > > > LOGGING = { > 'version': 1, > 'disable_existing_loggers': False, > 'formatters': { > 'verbose': { > 'format': '%(asctime)s: %(name)s %(levelname)s % > (funcName)s %(message)s' > } > }, > 'handlers': { > 'mail_admins': { > 'level': 'ERROR', > 'class': 'django.utils.log.AdminEmailHandler' > }, > 'console': { > 'level': 'DEBUG', > 'class': 'logging.StreamHandler', > 'formatter': 'verbose', > }, > }, > 'loggers': { > 'django.request': {'handlers': ['mail_admins'], > 'level': 'ERROR', > 'propagate': True, > }, > 'djfront': {'handlers': ['console'], > 'propagate': True, > }, > 'djfront.view': {'level': 'INFO'}, > 'djfront.auth': {'level': 'INFO'}, > 'djfront.auth.user': {'level': 'INFO'}, > 'djfront.api': {'level': 'WARN'}, > } > } > > In my code, I do: > > logger = logging.getLogger('djfront.auth.facebook') > > Since I haven't configured a 'djfront.auth.facebook' logger, it should > inherit the 'djfront.auth' config, which means the logging level > should be set to INFO. But, when I do: > > logger.debug('redirecting to "%s"' % url) > > it emits a message: > > 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init > redirecting to [...] > > I'm confused. Why is the debug level message not getting filtered > out? I tried your setup with the django-specific handler replaced by another StreamHandler $ cat tmp_logging.py import logging import logging.config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(asctime)s: %(name)s %(levelname)s %(funcName)s %(message)s' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'logging.StreamHandler' #'django.utils.log.AdminEmailHandler' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose', }, }, 'loggers': { 'django.request': {'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'djfront': {'handlers': ['console'], 'propagate': True, }, 'djfront.view': {'level': 'INFO'}, 'djfront.auth': {'level': 'INFO'}, 'djfront.auth.user': {'level': 'INFO'}, 'djfront.api': {'level': 'WARN'}, } } logging.config.dictConfig(LOGGING) logger = logging.getLogger('djfront.auth.facebook') logger.info("info-test") logger.debug("debug-test") and got what $ python2.7 tmp_logging.py 2011-08-30 11:18:33,160: djfront.auth.facebook INFO info-test $ which seems to be what you expected. So I'm confused, too... From __peter__ at web.de Tue Aug 30 05:45:53 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 11:45:53 +0200 Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? References: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Message-ID: Michel Albert wrote: > I use python oftentimes to write automation scripts on Linux servers. > And there's a big pattern in my scripts: > > - I *always* use `logging` instead of `print` statements. > - I *always* create two stream handlers. One for `sys.stdout` with > level `INFO` and one for `sys.stderr` with level `WARN` > > Well, the levels may variate occasionally, but that's only the rare > exception. How would a call to basicConfig() look like that produces this setup? From hansmu at xs4all.nl Tue Aug 30 06:40:26 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 30 Aug 2011 12:40:26 +0200 Subject: killing a script In-Reply-To: <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5cbe1a$0$2468$e4fe514c@news2.news.xs4all.nl> On 30/08/11 06:13:41, Steven D'Aprano wrote: > On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: > > [...] >>> Yes, but if I am not mistaken, that will require me to put a line or >>> two after each os.system call. That's almost like whack-a-mole at the >>> code level rather than the Control-C level. OK, not a huge deal for >>> one script, but I was hoping for something simpler. I was hoping I >>> could put one line at the top of the script and be done with it. >> >> Write a function! That's what they're for after all :) > > > I'm not sure that this is actually as simple as that, especially using > os.system. > > As I understand it, the scenario is this: > > The main script looks something like this: > > for x in whatever: > os.system('something.py x') > > Each time through the loop, a new Python process is started. Each process > runs in the foreground, capturing standard input, and so hitting Ctrl-C > kills *that* process, not the main script. Unless, by chance, the Ctrl-C > happens after the system call returns, but before the next one starts, it > is completely invisible to the parent process (the main script). Wrapping > os.system in a function does nothing to fix that. > > Possibly using the subprocess module may help. Using the subprocess module is likely to help, because unlike os.system, subprocess does not set control-C to 'ignore' in the parent process > Otherwise, the only way around this I can think of is to ensure that > the 'something.py' script (or scripts!) each return an error code for "User > Cancelled": > > for x in whatever: > result = os.system('something.py x') > if result == 3: # User Cancelled > break On my system, os.system returns 2 if the subprocess was killed by a control-C. The portable way is to use the constant SIGINT from the signal module. Not that os.system does not return 2 if the child ended by doing sys.exit(2); in that case, os.system in the parent returns 2<<8. > But if the 'something.py' scripts are arbitrary scripts, I don't think you > have any easy way around it. If the arbitrary script does not trap SIGINT, then os.system will return the number of the signal that kill the script, i.e. signal.SIGINT. If the script traps SIGINT and does some cleanup and then exits, the best you can hope for, is that in the error case, the script exits with a special value. And you have to remember the <<8 issue. > Perhaps use threads, and have the main script > ask the thread to kill the child process? How would that help? The problem is that the parent process ignores control-C while os.system is running (by design). If the parent uses threads, it still won't receive the signal, because signal state is global. > Regardless, this is a hard problem, and it isn't possible to just have some > magic switch at the top of your script to make it work. You actually have > to do the work yourself. You could monkey-patch the os module and replace os.system by (untested): def sub_system(command): pr = subprocess.Popen(command, shell=True) status = os.waitpid(pr.pid, 0)[1] return status That should have the same effect as os.system, except it does not ignore control-C. > (But of course you can do the work inside a function, and re-use it > elsewhere.) Even if you don't re-use it, you should still do it in a function, if only for readability. Hope this helps, -- HansM From anand.ibmgsi at gmail.com Tue Aug 30 07:31:42 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 30 Aug 2011 17:01:42 +0530 Subject: Help me understand this logging config In-Reply-To: References: Message-ID: Hi, I took a look at the logging source code. getLogger checks for existing loggers with the given name and if it doesn't creates one. def getLogger(self, name): """ Get a logger with the specified name (channel name), creating it if it doesn't yet exist. This name is a dot-separated hierarchical name, such as "a", "a.b", "a.b.c" or similar. If a PlaceHolder existed for the specified name [i.e. the logger didn't exist but a child of it did], replace it with the created logger and fix up the parent/child references which pointed to the placeholder to now point to the logger. """ rv = None _acquireLock() try: if name in self.loggerDict: rv = self.loggerDict[name] if isinstance(rv, PlaceHolder): ph = rv rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupChildren(ph, rv) self._fixupParents(rv) else: rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupParents(rv) finally: _releaseLock() return rv ============================================== Anand Jeyahar https://sites.google.com/site/ anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From wm at localhost.localdomain Tue Aug 30 07:50:42 2011 From: wm at localhost.localdomain (Waldek M.) Date: Tue, 30 Aug 2011 13:50:42 +0200 Subject: Help parsing a text file References: Message-ID: <1mpbiyq718zub.dlg@localhost.localdomain> On Mon, 29 Aug 2011 23:05:23 +0200, Thomas Jollans wrote: > A name that is often thrown around on this list for this kind of > question is pyparsing. Now, I don't know anything about it myself, but > it may be worth looking into. Definitely. I did use it and even though it's not perfect - it's very useful indeed. Due to it's nature it is not a demon of speed when parsing complex and big structures, so you might want to keep it in mind. But I whole-heartedly recommend it. Br. Waldek From exhuma at gmail.com Tue Aug 30 07:59:32 2011 From: exhuma at gmail.com (Michel Albert) Date: Tue, 30 Aug 2011 04:59:32 -0700 (PDT) Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? References: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 30, 11:45?am, Peter Otten <__pete... at web.de> wrote: > Michel Albert wrote: > > I use python oftentimes to write automation scripts on Linux servers. > > And there's a big pattern in my scripts: > > > - I *always* use `logging` instead of `print` statements. > > - I *always* create two stream handlers. One for `sys.stdout` with > > level `INFO` and one for `sys.stderr` with level `WARN` > > > Well, the levels may variate occasionally, but that's only the rare > > exception. > > How would a call to basicConfig() look like that produces this setup? I personally see this happen by default (i.e. no additional parameters). And in case the `stream` parameter is set, /then/ you would send all to that stream only. In my point of view, the call to `basicConfig` is either something used in only the most mundane usages of the logging package, or it's mainly used by people that have not yet grokked the logging package (correct me if I'm wrong). In both cases, I find it useful to redirect warnings and errors to `stderr` by default. However, this would also mean that existing code calling this method would result in different behavior. But only /slightly/ different. Meaning, you still see the output on the console as expected. But it gives you the possibility to use standard shell redirection in a way that "makes sense". From jacktradespublic at gmail.com Tue Aug 30 08:31:26 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Tue, 30 Aug 2011 07:31:26 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: > > That's brilliant and works flawlessly. Thank you very much! > > If an impementation (as you say up thread) can populate globals > or locals with whatever they want, then how do you know that last > item added was the function definition the user supplied ? > > Rob. > > -- > http://mail.python.org/mailman/listinfo/python-list > I spoke a bit too soon with the "works flawlessly" post. In addition to your issue, there is also the problem that supplying an empty environment does not allow the user to call necessary functions (like scheme_eval). Why not just get the name from the user > That's probably what I'll end up doing, something similar to: special_forms = {} def exec_func_def(symbol, def_string, name=None): exec(def_string) if name is None: special_forms[symbol] = f else: special_forms[symbol] = eval(name) It just feels kind of hackish to me, when what I really want to do here is eval an anonymous function. -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Tue Aug 30 08:39:26 2011 From: roy at panix.com (Roy Smith) Date: Tue, 30 Aug 2011 08:39:26 -0400 Subject: Help me understand this logging config References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Roy Smith wrote: > > > I'm using django 1.3 and python 2.6. > > Isn't dictConfig() new in 2.7? It looks like that is what you are using... Oh, my, it turns out that django includes: # This is a copy of the Python logging.config.dictconfig module, # reproduced with permission. It is provided here for backwards # compatibility for Python versions prior to 2.7. Comparing the django copy to lib/logging/config.py from Python 2.7.2, they're not identical. It's likely they grabbed something earlier in the 2.7 series. I'll check 2.7.0 and 2.7.1 to see. > I tried your setup with the django-specific handler replaced by another > StreamHandler > [...] > and got what > > $ python2.7 tmp_logging.py > 2011-08-30 11:18:33,160: djfront.auth.facebook INFO info-test > $ > > which seems to be what you expected. So I'm confused, too... I'll need to dig deeper. Not that I realize this may not be a Python issue per-se, I'll do some more experimentation and ask on the django mailing list. Thanks for your help. From __peter__ at web.de Tue Aug 30 10:21:27 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 16:21:27 +0200 Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: luvspython wrote: > THANK YOU! Special-casing "__dict__" did the trick. Not sure I'd > have ever figured that out, which leads to a different question: > > I can figure out most things, though perhaps very slowly and > painfully, if I can trace through code. I use WingIDE (love it), but > the execution > of the C code is of course hidden, which helped stymie on this > problem. Is there another tool y'all might use and you can suggest > that deals with that problem and would have helped me with this case? > Or is one's ability to figure out this sort of problem largely > dependent on really understanding the system's internals? I'm with Chris here, I make do with some understanding of Python and a generous amount of print statements. My other secret weapon is that I try to keep the complexity of my code low ;) As Python is yet another C program you can of course step through its code (debug build) with an appropriate debugger, but I've never done that. My guess is that you wouldn't have seen the forest for the trees. From phd at phdru.name Tue Aug 30 12:04:17 2011 From: phd at phdru.name (Oleg Broytman) Date: Tue, 30 Aug 2011 20:04:17 +0400 Subject: SQLObject 1.1.3 Message-ID: <20110830160417.GD19217@iskra.aviel.ru> Hello! I'm pleased to announce version 1.1.3, a bugfix release of branch 1.1 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.1.3 News and changes: http://sqlobject.org/News.html What's New ========== Features & Interface -------------------- * Fixed a bug with Postgres - add quotes in "SET client_encoding" query. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From k.sahithi2862 at gmail.com Tue Aug 30 12:25:36 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 30 Aug 2011 09:25:36 -0700 (PDT) Subject: 2011 HOT PICS Message-ID: <1855dc30-bb22-466d-8e62-17f83e3e03f8@c8g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS TAMANNA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/tamanna-hot.html PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From johanna.royer at gmail.com Tue Aug 30 12:41:32 2011 From: johanna.royer at gmail.com (Johanna) Date: Tue, 30 Aug 2011 18:41:32 +0200 Subject: can't create instance of pythoncom server Message-ID: Hi all, I am trying to consume a Pythoncom server from 3ds max. I need this to be able to call some mysql queries in python script from maxscript. I tried to follow the steps in this article. I created a small pythoncom server import sys, os def getWorkingDirectory() : return os.path.dirname(sys.argv[0]) sys.path.append('tubeBDD') from Database import Database import selectBDD as select db = Database() # A simple Python COM server. class PythonComUtilities: _public_methods_ = ['getProjects'] _reg_progid_ = 'PythonCom.Utilities' # Class ID must be new/unique for every server you create _reg_clsid_ = '{BAC62D37-EEDF-46B3-8DED-11E842225B0E}' def getProjects(self, string): # self.db = Database() projects = select.getProjects(db) proj = "" for p in projects: if proj == "": proj = p[0] else: proj = proj + "," + p[0] return proj if (__name__ == '__main__'): print 'Registering COM server...' import win32com.server.register as comReg comReg.UseCommandLine(PythonComUtilities) Then I try to call it in a maxscript (in a 3D soft): comObj = createOLEObject "PythonCom.Utilities" It gives me this error : -- Runtime error: createOLEObject: can't create instance PythonCom.Utilities Any idea what I'm doing wrong ? Or any idea of how I could test it other than in the 3D soft ? Cheers, Johanna -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Aug 30 14:19:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 11:19:52 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D29C8.8010206@stoneleaf.us> Jack Trades wrote: > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? Because the implementation will add things before the exec is processed. Then when the exec actually runs, any assignments, definitions, etc, from the user supplied string will be added. > I spoke a bit too soon with the "works flawlessly" post. In addition to > your issue, there is also the problem that supplying an empty > environment does not allow the user to call necessary functions (like > scheme_eval). So, just like an implementation, add the functions to the CapturingDict before the exec. One thing to keep in mind: the CapturingDict only remembers the *last* thing created/assigned... so if the user code has more than one def/class/name assignment, you won't have ready access to the first items, only that last one. ~Ethan~ From rtw at rtw.me.uk Tue Aug 30 15:28:52 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 19:28:52 +0000 (UTC) Subject: Returning a value from exec or a better solution References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: Ethan Furman wrote in news:4E5D29C8.8010206 at stoneleaf.us in gmane.comp.python.general: > Jack Trades wrote: >> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>> If an impementation (as you say up thread) can populate globals >>> or locals with whatever they want, then how do you know that last >>> item added was the function definition the user supplied ? > > Because the implementation will add things before the exec is processed. How do you know this ?, it isn't what the docs say. http://docs.python.org/reference/simple_stmts.html#the-exec-statement Rob. From fnautaNO at SPAMsolfon.nl Tue Aug 30 16:00:48 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Tue, 30 Aug 2011 22:00:48 +0200 Subject: Installing WebDAV server Message-ID: <9c4trjFcfmU1@mid.individual.net> Hi all, I am completely new to Python, but I'm confronted with a problem I can't solve. This is my question: I'm running a PC with XP Pro32, which acts as a file server/print server/FTP server and web server. The web server is facilitated by the Aprelium Abyss X2 server, and has Perl and PHP support on http and https. It all works fine. To do some research with some calender systems and to share the Outlook calendar I need a WebDAV server. After googling I found the Python WebDAV server. I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and PyXML-0.8.4. In the PyWebDAV README it says: Installation and setup of server can be as easy as follows: $ easy_install PyWebDAV $ davserver -D /tmp -n -J But of course it doesn't work like that. When I start up Python GUI I see the ">>>" prompt instead of the "$" prompt. But where do I place the two directories? And there is no easy_install script in the PyXML-0.8.4 directory, only a setup.py and ez_setup.py script. I guess the latter is the one to use. But how? How do I proceed next? Any help will be appreciated. Thanks in advance. With regards, Fokke Nauta From PointedEars at web.de Tue Aug 30 16:31:11 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 30 Aug 2011 22:31:11 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> Message-ID: <6545843.yvFAXZvWTv@PointedEars.de> Fokke Nauta wrote: > I'm running a PC with XP Pro32, [?] > To do some research with some calender systems and to share the Outlook > calendar I need a WebDAV server. After googling I found the Python WebDAV > server. > I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. > Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 > and PyXML-0.8.4. In the PyWebDAV README it says: > > Installation and setup of server can be as easy as follows: > > $ easy_install PyWebDAV > $ davserver -D /tmp -n -J > > But of course it doesn't work like that. When I start up Python GUI That is really not a *G*raphical User Interface, but the (text-based) Python shell. > I see the ">>>" prompt instead of the "$" prompt. "Doctor, my arm hurts when I move it." ? "Don't move it, then." The Python shell executes Python code. The above obviously is not Python code, but *system* shell commands. So let the *system* command shell execute them (as indicated by the `$' prompt, which is customary for a sh-based UNIX/Linux shell prompt). Since you use Windows XP, type `cmd' to get the command shell (if you knew MS-DOS, which I doubt, you are at home now). However, you appear to have found the *UNIX/Linux* README (and the corresponding version?) of that server: the second command is usually how you would run a program as daemon on Unices (run through an init script), while on Windows NT (like XP) you would have a setup program install a service for you (maybe to execute that command when the service is started). Look for the Windows version. > But where do I place the two directories? You do not; let easy_install place them in the correct packages directory (hence *easy* *install*). That is very likely what the setup.py and ez_setup.py scripts are for (spell "ez" in English). > And there is no easy_install script in the PyXML-0.8.4 > directory, only a setup.py and ez_setup.py script. I guess the latter is > the one to use. But how? RTFM. > How do I proceed next? Look for the Windows version. If there is none, get easy_install and use it as described. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From philip at semanchuk.com Tue Aug 30 16:34:48 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Aug 2011 16:34:48 -0400 Subject: Python Tools for Visual Studio - anyone using it? Message-ID: Hi all, I was reminded today (via Slashdot) of Python Tools for Visual Studio which was discussed on this list back in March (http://mail.python.org/pipermail/python-list/2011-March/1267662.html) and has reached version 1.0. Is anyone here using it? Care to share pros & cons? Here's the URL for those who haven't heard of it before: http://pytools.codeplex.com/ Thanks Philip From aww.dev at googlemail.com Tue Aug 30 16:42:29 2011 From: aww.dev at googlemail.com (Andreas) Date: Tue, 30 Aug 2011 22:42:29 +0200 Subject: Usage of PyDateTime_FromTimestamp Message-ID: Hi, I'm working on a c-extension of python and want to create an instance of python datetime object with a unix timestamp in c. On the documentation site ( http://docs.python.org/c-api/datetime.html ) I found the function PyDateTime_FromTimestamp() which returns a new reference based on an input parameter. The description is as follows: Create and return a new datetime.datetime object given an argument tuple suitable for passing to datetime.datetime.fromtimestamp(). I tried out to call the function with a PyFloat_Object but the function always returns NULL (even if I simply put in 0). Does somebody have an example how I have to call the function or can give a hint what kind of parameter tuple is required to get it work? Thanks! From ethan at stoneleaf.us Tue Aug 30 16:59:34 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 13:59:34 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: <4E5D4F36.1030209@stoneleaf.us> Rob Williscroft wrote: > Ethan Furman wrote in news:4E5D29C8.8010206 at stoneleaf.us in > gmane.comp.python.general: > >> Jack Trades wrote: >>> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>>> If an impementation (as you say up thread) can populate globals >>>> or locals with whatever they want, then how do you know that last >>>> item added was the function definition the user supplied ? >> Because the implementation will add things before the exec is processed. > > How do you know this ?, it isn't what the docs say. > > http://docs.python.org/reference/simple_stmts.html#the-exec-statement The docs don't say when, true -- so I don't know for sure that all additions happen before the exec since I haven't delved into the source code... Okay, just perused builtin_exec in bltinmodule.c, and I can say that cPython (somewhere in 3.2-3.3 land) only adds __builtins__ if not already there, and that it does it first. Which makes sense -- after all, what's the point of adding stuff to globals() *after* the code has been run? ~Ethan~ From arnodel at gmail.com Tue Aug 30 17:05:07 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 30 Aug 2011 22:05:07 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 30 August 2011 13:31, Jack Trades wrote: > > > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: > >> >> > That's brilliant and works flawlessly. ?Thank you very much! >> >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? That's not an issue. The last statement that is executed will be the "def" statement. >> Rob. > > I spoke a bit too soon with the "works flawlessly" post.? In addition to > your issue, there is also the problem that supplying an empty environment > does not allow the user to call necessary functions (like scheme_eval). You could simply prepend the function definition string with whatever imports are needed. -- Arnaud From fnautaNO at SPAMsolfon.nl Tue Aug 30 17:16:12 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Tue, 30 Aug 2011 23:16:12 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> Message-ID: <9c528rFi5aU1@mid.individual.net> "Thomas 'PointedEars' Lahn" wrote in message news:6545843.yvFAXZvWTv at PointedEars.de... > Fokke Nauta wrote: > >> I'm running a PC with XP Pro32, [.] >> To do some research with some calender systems and to share the Outlook >> calendar I need a WebDAV server. After googling I found the Python WebDAV >> server. >> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >> Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 >> and PyXML-0.8.4. In the PyWebDAV README it says: >> >> Installation and setup of server can be as easy as follows: >> >> $ easy_install PyWebDAV >> $ davserver -D /tmp -n -J >> >> But of course it doesn't work like that. When I start up Python GUI > > That is really not a *G*raphical User Interface, but the (text-based) > Python > shell. Yes, I noticed. But the application has the name of Python GUI. >> I see the ">>>" prompt instead of the "$" prompt. > > "Doctor, my arm hurts when I move it." - "Don't move it, then." I don't see the point here ... > The Python shell executes Python code. The above obviously is not Python > code, but *system* shell commands. So let the *system* command shell > execute them (as indicated by the `$' prompt, which is customary for a > sh-based UNIX/Linux shell prompt). I know. I worked with SCO Unix and various sorts of Linux. But never with Python, so I hadn't got a clue about the prompt. > Since you use Windows XP, type `cmd' to get the command shell (if you knew > MS-DOS, which I doubt, you are at home now). I know MSDOS. I even worked with CP/M > However, you appear to have > found the *UNIX/Linux* README (and the corresponding version?) of that > server: the second command is usually how you would run a program as > daemon > on Unices (run through an init script), while on Windows NT (like XP) you > would have a setup program install a service for you (maybe to execute > that > command when the service is started). Look for the Windows version. There is no other Windows version except the packages I mentioned, PyWebDAV and PyXML. The only Windows thing I got was the Python interpreter itself. >> But where do I place the two directories? > > You do not; let easy_install place them in the correct packages directory > (hence *easy* *install*). That is very likely what the setup.py and > ez_setup.py scripts are for (spell "ez" in English). > >> And there is no easy_install script in the PyXML-0.8.4 >> directory, only a setup.py and ez_setup.py script. I guess the latter is >> the one to use. But how? > > RTFM. Which fucking manual? >> How do I proceed next? > > Look for the Windows version. If there is none, get easy_install and use > it > as described. > Thanks for your quick reply. This means "Show over"? Fokke From ramit.prasad at jpmorgan.com Tue Aug 30 17:26:24 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 30 Aug 2011 17:26:24 -0400 Subject: Get reference to parent class from subclass? In-Reply-To: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> References: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F1628DD19@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of John O'Hagan Sent: Saturday, August 27, 2011 11:00 PM To: python-list at python.org Subject: Get reference to parent class from subclass? class P(): pass class C(P): pass Can I get P from C? IOW, can I get a reference to the object P from the object C? This should be obvious one way or the other, but I haven't been able to find the answer. Regards, John -- You should be able to access what you need via the super() built-in. I am not entirely sure what you are trying to do...but I think usage of super is probably better than trying to access the base classes manually. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jdriselvato at gmail.com Tue Aug 30 17:32:51 2011 From: jdriselvato at gmail.com (John Riselvato) Date: Tue, 30 Aug 2011 17:32:51 -0400 Subject: Access LDAP with Django Message-ID: Would Django be a good framework to use if i wanted to take directories of LDAP and make a list of users on a website? I have seen it done in php, but what about trying to manage this with django? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtw at rtw.me.uk Tue Aug 30 17:48:11 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 21:48:11 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Arnaud Delobelle wrote in news:CAJ6cK1YVi3NQgdZOUdhAESf133pUkdazM1PkSP=p6xFaYVOHYA at mail.gmail.com in gmane.comp.python.general: > On 30 August 2011 13:31, Jack Trades wrote: >> >> >> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> >>> >>> > That's brilliant and works flawlessly. ??Thank you very much! >>> >>> If an impementation (as you say up thread) can populate globals >>> or locals with whatever they want, then how do you know that last >>> item added was the function definition the user supplied ? > That's not an issue. The last statement that is executed will be the > "def" statement. You don't know that, an implementation may for example set __bultins__ to None, prior to returning, its not an unreasonable thing to do and the docs don't say they can't. Rob. From python at mrabarnett.plus.com Tue Aug 30 17:49:04 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Aug 2011 22:49:04 +0100 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: References: Message-ID: <4E5D5AD0.9070408@mrabarnett.plus.com> On 30/08/2011 21:42, Andreas wrote: > Hi, > > I'm working on a c-extension of python and want to create an instance of > python datetime object with a unix timestamp in c. > > On the documentation site ( http://docs.python.org/c-api/datetime.html ) > I found the function PyDateTime_FromTimestamp() which returns a new > reference based on an input parameter. > > The description is as follows: Create and return a new datetime.datetime > object given an argument tuple suitable for passing to > datetime.datetime.fromtimestamp(). > > I tried out to call the function with a PyFloat_Object but the function > always returns NULL (even if I simply put in 0). > > Does somebody have an example how I have to call the function or can > give a hint what kind of parameter tuple is required to get it work? > The key phrase is "argument tuple". The arguments passed to a Python call are always a tuple, not PyFloat_Object. You can build a tuple from the PyFloat_Object using: Py_BuildValue("(O)", float_object) The "(O)" says to build a tuple ("(...)") containing a single object ("O"). From ethan at stoneleaf.us Tue Aug 30 18:28:16 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 15:28:16 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D6400.90003@stoneleaf.us> Rob Williscroft wrote: > Arnaud Delobelle wrote: >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. Yet another excellent reason to have unit tests! ~Ethan~ From ethan at stoneleaf.us Tue Aug 30 18:31:42 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 15:31:42 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D64CE.3060303@stoneleaf.us> Rob Williscroft wrote: > Arnaud Delobelle wrote: > >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. Actually, I think it is unreasonable -- by modifying the globals or locals objects *after* the code has been exec'd, information is being removed about the environment the code ran in, making introspection (if nothing else) more difficult. Good reasons are required to make life difficult (at least with Python). ~Ethan~ From jacktradespublic at gmail.com Tue Aug 30 18:45:58 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Tue, 30 Aug 2011 17:45:58 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: <4E5D29C8.8010206@stoneleaf.us> References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: On Tue, Aug 30, 2011 at 1:19 PM, Ethan Furman wrote: > > I spoke a bit too soon with the "works flawlessly" post. In addition to >> your issue, there is also the problem that supplying an empty environment >> does not allow the user to call necessary functions (like scheme_eval). >> > > > So, just like an implementation, add the functions to the CapturingDict > before the exec. > > I will probably do that a bit down the road, that also allows exporting only the things that are absolutely necessary, which is a huge plus. Right now I'm trying to keep the code as simple as possible as this Scheme interpreter is being written as a tutorial in a similar fashion to "An Incremental Approach to Compiler Construction". I'll add a note about this method of implementation and link to this discussion. In the off chance anyone is interested, the series is hereand the github is here . It's still very much in draft form and will probably undergo a number of rewrites, but criticism is always welcome. -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabiofz at gmail.com Tue Aug 30 19:44:43 2011 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 30 Aug 2011 20:44:43 -0300 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 11:18 AM, Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any > suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, then > produces an error that makes no sense. > > An error occurred while installing the items > ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > ?Cannot connect to keystore. > ?This trust engine is read only. > ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > not found. > > > Any suggestions on getting this to work? In the install dialog, uncheck the 'contact all update sites during install to find required software'. Another option would be getting Aptana Studio 3, which has PyDev preinstalled (see: http://pydev.org/download.html ) Cheers, Fabio From PointedEars at web.de Tue Aug 30 20:00:33 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 31 Aug 2011 02:00:33 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> Message-ID: <4761603.ypaU67uLZW@PointedEars.de> Fokke Nauta wrote: > "Thomas 'PointedEars' Lahn" wrote in message > news:6545843.yvFAXZvWTv at PointedEars.de... It's attribution _line_, not attribution novel. Your quotes are hardly legible, too ? >> Fokke Nauta wrote: >>> I'm running a PC with XP Pro32, [.] >>> [?] In the PyWebDAV README it says: >>> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_install PyWebDAV >>> $ davserver -D /tmp -n -J >>> >>> But of course it doesn't work like that. When I start up Python GUI >> That is really not a *G*raphical User Interface, but the (text-based) >> Python shell. > > Yes, I noticed. But the application has the name of Python GUI. ACK. Admittedly I cannot remember having used Python on Windows (XP) except via Cygwin. >>> I see the ">>>" prompt instead of the "$" prompt. >> "Doctor, my arm hurts when I move it." - "Don't move it, then." > > I don't see the point here ... Do not run `python' or the "Python GUI", then. >> The Python shell executes Python code. The above obviously is not Python >> code, but *system* shell commands. So let the *system* command shell >> execute them (as indicated by the `$' prompt, which is customary for a >> sh-based UNIX/Linux shell prompt). > > I know. I worked with SCO Unix and various sorts of Linux. > But never with Python, so I hadn't got a clue about the prompt. Come on, with that experience you see a `$' and those commands and don't realize it is (ba)sh? >> Since you use Windows XP, type `cmd' to get the command shell (if you >> knew MS-DOS, which I doubt, you are at home now). > > I know MSDOS. I even worked with CP/M Good for you. >> However, you appear to have found the *UNIX/Linux* README (and the >> corresponding version?) of that server: the second command is usually how >> you would run a program as daemon on Unices (run through an init script), >> while on Windows NT (like XP) you would have a setup program install a >> service for you (maybe to execute that command when the service is >> started). Look for the Windows version. > > There is no other Windows version except the packages I mentioned, > PyWebDAV and PyXML. The only Windows thing I got was the Python > interpreter itself. Has it not occurred to you to STFW for "easy_install" first? >>> And there is no easy_install script in the PyXML-0.8.4 >>> directory, only a setup.py and ez_setup.py script. I guess the latter is >>> the one to use. But how? >> RTFM. > > Which fucking manual? That of the server, on Windows-related information. Or that of easy_install. Or Python. Whichever comes first. >>> How do I proceed next? >> Look for the Windows version. If there is none, get easy_install and use >> it as described. > > Thanks for your quick reply. > This means "Show over"? No, it means "Do your homework". -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From jehugaleahsa at gmail.com Tue Aug 30 21:43:21 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Tue, 30 Aug 2011 18:43:21 -0700 (PDT) Subject: Handling 2.7 and 3.0 Versions of Dict Message-ID: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> I am writing a simple algorithms library that I want to work for both Python 2.7 and 3.x. I am writing some functions like distinct, which work with dictionaries under the hood. The problem I ran into is that I am calling itervalues or values depending on which version of the language I am working in. Here is the code I wrote to overcome it: import sys def getDictValuesFoo(): if sys.version_info < (3,): return dict.itervalues else: return dict.values getValues = getDictValuesFoo() def distinct(iterable, keySelector = (lambda x: x)): lookup = {} for item in iterable: key = keySelector(item) if key not in lookup: lookup[key] = item return getValues(lookup) I was surprised to learn that getValues CANNOT be called as if it were a member of dict. I figured it was more efficient to determine what getValues was once rather than every time it was needed. First, how can I make the method getValues "private" _and_ so it only gets evaluated once? Secondly, will the body of the distinct method be evaluated immediately? How can I delay building the dict until the first value is requested? I noticed that hashing is a lot different in Python than it is in .NET languages. .NET supports custom "equality comparers" that can override a type's Equals and GetHashCode functions. This is nice when you can't change the class you are hashing. That is why I am using a key selector in my code, here. Is there a better way of overriding the default hashing of a type without actually modifying its definition? I figured a requesting a key was the easiest way. From tjreedy at udel.edu Tue Aug 30 23:33:37 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Aug 2011 23:33:37 -0400 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> Message-ID: On 8/30/2011 9:43 PM, Travis Parks wrote: > I am writing a simple algorithms library that I want to work for both > Python 2.7 and 3.x. I am writing some functions like distinct, which > work with dictionaries under the hood. The problem I ran into is that > I am calling itervalues or values depending on which version of the > language I am working in. Here is the code I wrote to overcome it: > > import sys > def getDictValuesFoo(): > if sys.version_info< (3,): > return dict.itervalues > else: > return dict.values One alternative is to use itervalues and have 2to3 translate for you. -- Terry Jan Reedy From aww.dev at googlemail.com Tue Aug 30 23:39:33 2011 From: aww.dev at googlemail.com (Andreas) Date: Wed, 31 Aug 2011 05:39:33 +0200 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: <4E5D5AD0.9070408@mrabarnett.plus.com> References: <4E5D5AD0.9070408@mrabarnett.plus.com> Message-ID: Am 30.08.2011 23:49, schrieb MRAB: > The key phrase is "argument tuple". The arguments passed to a Python > call are always a tuple, not PyFloat_Object. > > You can build a tuple from the PyFloat_Object using: > > Py_BuildValue("(O)", float_object) > > The "(O)" says to build a tuple ("(...)") containing a single object > ("O"). Thank you very much! That solved my problem. Here the full working example: static double doubleValue = 1314761451; PyObject *floatObj = NULL; PyObject *timeTuple = NULL; PyObject *dateTime = NULL; floatObj = PyFloat_FromDouble(doubleValue); timeTuple = Py_BuildValue("(O)", floatObj); dateTime = PyDateTime_FromTimestamp(timeTuple); From adam.jorgensen.za at gmail.com Wed Aug 31 00:53:26 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 31 Aug 2011 06:53:26 +0200 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: I recommend PyCharm. Best Python IDE ever :-) If you can't afford to pay for it in the long run, then PyDev is the next best bet. I would recommend downloading the most minimal Eclipse you can get (Usually the Eclipse RCP Runtime) and install the necessary plugins as you go. This prevents you from falling into the overloaded eclipse problem as quickly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 31 01:37:14 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 30 Aug 2011 22:37:14 -0700 Subject: Help parsing a text file References: Message-ID: William Gill wrote: > >My initial passes into Python have been very unfocused (a scatter gun of >too many possible directions, yielding very messy results), so I'm >asking for some suggestions, or algorithms (possibly even examples)that >may help me focus. > >I'm not asking anyone to write my code, just to nudge me toward a more >disciplined approach to a common task, and I promise to put in the >effort to understand the underlying fundamentals. Python includes "sgmllib", which was designed to parse SGML-based files, including both neat XML and slimy HTML, and "htmllib", which derives from it. I have used "htmllib" to parse HTML files where the tags were not properly closed. Perhaps you could start from "htmllib" and modify it to handle the quirks in your particular format. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From arnodel at gmail.com Wed Aug 31 02:35:45 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 31 Aug 2011 07:35:45 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 30 August 2011 22:48, Rob Williscroft wrote: > Arnaud Delobelle wrote in > news:CAJ6cK1YVi3NQgdZOUdhAESf133pUkdazM1PkSP=p6xFaYVOHYA at mail.gmail.com in > gmane.comp.python.general: > >> On 30 August 2011 13:31, Jack Trades wrote: >>> >>> >>> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>> >>>> >>>> > That's brilliant and works flawlessly. ??Thank you very much! >>>> >>>> If an impementation (as you say up thread) can populate globals >>>> or locals with whatever they want, then how do you know that last >>>> item added was the function definition the user supplied ? > >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. I haven't studied the docs but I'm certain that such an implementation would break a lot of code. -- Arnaud From paul at subsignal.org Wed Aug 31 04:52:45 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Wed, 31 Aug 2011 10:52:45 +0200 Subject: Installing WebDAV server In-Reply-To: <9c4trjFcfmU1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> Message-ID: Hi, Am 30.08.2011 22:00, schrieb Fokke Nauta: > Hi all, > > I am completely new to Python, but I'm confronted with a problem I can't > solve. Welcome to python. > This is my question: [snip] > I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. Now > I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and > PyXML-0.8.4. In the PyWebDAV README it says: > > Installation and setup of server can be as easy as follows: > > $ easy_install PyWebDAV > $ davserver -D /tmp -n -J > > But of course it doesn't work like that. When I start up Python GUI I see > the ">>>" prompt instead of the "$" prompt. But where do I place the two > directories? And there is no easy_install script in the PyXML-0.8.4 > directory, only a setup.py and ez_setup.py script. I guess the latter is the > one to use. But how? You dont install from "Python GUI", use normal cmd, navigate to the folder you downloaded PyXML and PyWebDAV and run "python setup.py install" (python.exe has to be in your PATH). Then you have to find the startup-script "davserver". Find your python installation directory and look into /Tools/Scripts, in my computer this is E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the site-packages folder i.e. E:\python27\Lib/site-packages. You might have to look for "davserver" there... hth Paul From fnautaNO at SPAMsolfon.nl Wed Aug 31 05:27:36 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 11:27:36 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de> Message-ID: <9c6d4cFa54U1@mid.individual.net> "Thomas 'PointedEars' Lahn" wrote in message news:4761603.ypaU67uLZW at PointedEars.de... > Fokke Nauta wrote: > >> "Thomas 'PointedEars' Lahn" wrote in message >> news:6545843.yvFAXZvWTv at PointedEars.de... > > It's attribution _line_, not attribution novel. Your quotes are hardly > legible, too ? > >>> Fokke Nauta wrote: >>>> I'm running a PC with XP Pro32, [.] >>>> [.] In the PyWebDAV README it says: >>>> >>>> Installation and setup of server can be as easy as follows: >>>> >>>> $ easy_install PyWebDAV >>>> $ davserver -D /tmp -n -J >>>> >>>> But of course it doesn't work like that. When I start up Python GUI >>> That is really not a *G*raphical User Interface, but the (text-based) >>> Python shell. >> >> Yes, I noticed. But the application has the name of Python GUI. > > ACK. Admittedly I cannot remember having used Python on Windows (XP) > except > via Cygwin. > >>>> I see the ">>>" prompt instead of the "$" prompt. >>> "Doctor, my arm hurts when I move it." - "Don't move it, then." >> >> I don't see the point here ... > > Do not run `python' or the "Python GUI", then. > >>> The Python shell executes Python code. The above obviously is not >>> Python >>> code, but *system* shell commands. So let the *system* command shell >>> execute them (as indicated by the `$' prompt, which is customary for a >>> sh-based UNIX/Linux shell prompt). >> >> I know. I worked with SCO Unix and various sorts of Linux. >> But never with Python, so I hadn't got a clue about the prompt. > > Come on, with that experience you see a `$' and those commands and don't > realize it is (ba)sh? Ofcourse I realized it was Unix/Linux. I already could tell that as the packages I downloaded were tar.gz files. So I unpacked them and expected to run a Python installer script from the Python command line. Hence my question "How do I do that", but perhaps I did not make myself clear enough. Tried to run the Python installer script from the DOS command line but that resulted in an error. As I have Cygwin running as well, I could try to install it there instead of in Windows. >>> Since you use Windows XP, type `cmd' to get the command shell (if you >>> knew MS-DOS, which I doubt, you are at home now). >> >> I know MSDOS. I even worked with CP/M > > Good for you. > >>> However, you appear to have found the *UNIX/Linux* README (and the >>> corresponding version?) of that server: the second command is usually >>> how >>> you would run a program as daemon on Unices (run through an init >>> script), >>> while on Windows NT (like XP) you would have a setup program install a >>> service for you (maybe to execute that command when the service is >>> started). Look for the Windows version. >> >> There is no other Windows version except the packages I mentioned, >> PyWebDAV and PyXML. The only Windows thing I got was the Python >> interpreter itself. > > Has it not occurred to you to STFW for "easy_install" first? What do you mean by STFW? I wasn't aware that easy_install was a utility. Downloaded and installed the Windows version and run easy_install pywebdav. It downloaded something, installed something and finished something. But, once again, don't know how to proceed. Otherwise I'll give it a try under Cygwin. >>>> And there is no easy_install script in the PyXML-0.8.4 >>>> directory, only a setup.py and ez_setup.py script. I guess the latter >>>> is >>>> the one to use. But how? >>> RTFM. >> >> Which fucking manual? > > That of the server, on Windows-related information. Or that of > easy_install. Or Python. Whichever comes first. It's my own server and I didn't write a manual for it. In the manual of Easy_install it says how to install packaged etc and I did sucessfully. There is no furter information as how to proceed. That's why I posted my question here. >>>> How do I proceed next? >>> Look for the Windows version. If there is none, get easy_install and >>> use >>> it as described. I did and it worked. What's next? Fokke From martin at v.loewis.de Wed Aug 31 05:55:39 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 31 Aug 2011 11:55:39 +0200 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> Message-ID: <4E5E051B.8060002@v.loewis.de> Am 31.08.2011 03:43, schrieb Travis Parks: > I am writing a simple algorithms library that I want to work for both > Python 2.7 and 3.x. I am writing some functions like distinct, which > work with dictionaries under the hood. The problem I ran into is that > I am calling itervalues or values depending on which version of the > language I am working in. Here is the code I wrote to overcome it: > > import sys > def getDictValuesFoo(): > if sys.version_info < (3,): > return dict.itervalues > else: > return dict.values > > getValues = getDictValuesFoo() > > def distinct(iterable, keySelector = (lambda x: x)): > lookup = {} > for item in iterable: > key = keySelector(item) > if key not in lookup: > lookup[key] = item > return getValues(lookup) > > I was surprised to learn that getValues CANNOT be called as if it were > a member of dict. I figured it was more efficient to determine what > getValues was once rather than every time it was needed. > > First, how can I make the method getValues "private" _and_ so it only > gets evaluated once? Not sure what "private" means here. Having the logic selected only once goes like this if sys.version_info < (3,): def getDictValues(dict): return dict.itervalues() else: def getDictValues(dict): return dict.values() > Secondly, will the body f the distinct method be > evaluated immediately? Yes. > How can I delay building the dict until the first value is requested? Make it a generator: def distinct(iterable, keySelector = (lambda x: x)): lookup = {} for item in iterable: key = keySelector(item) if key not in lookup: lookup[key] = item for v in getValues(lookup): yield v This delays *building* the dictionary until the *first* value is requested. I.e. it completes building the dictionary before the first value is returned. If you also want to interleave iteration over iterable with fetching distinct values, write it like that: def distinct(iterable, keySelector = (lambda x: x)): seen = {} for item in iterable: key = keySelector(item) if key not in seen: yield item seen[key] = item > I noticed that hashing is a lot different in Python than it is in .NET > languages. .NET supports custom "equality comparers" that can override > a type's Equals and GetHashCode functions. This is nice when you can't > change the class you are hashing. That is why I am using a key > selector in my code, here. Is there a better way of overriding the > default hashing of a type without actually modifying its definition? I > figured a requesting a key was the easiest way. You could provide a Key class that takes a hash function and a value function: class Key: def __init__(self, value, hash, eq): self.value, self.hash, self.eq = value, hash, eq def __hash__(self): return self.hash(self.value) def __eq__(self, other_key): return self.eq(self.value, other_key.value) This class would then be used instead of your keySelector. With that, you could change the dictionary to a set. Actually, you could already do so in the second generator version: def distinct(iterable, keySelector = (lambda x: x)): seen = set() for item in iterable: key = keySelector(item) if key not in seen: yield item seen.add(key) # item is not needed anymore HTH, Martin From yasar11732 at gmail.com Wed Aug 31 07:43:50 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 14:43:50 +0300 Subject: Subclassing str object Message-ID: H?, I originally posted my question to here: http://stackoverflow.com/q/7255655/886669 Could you people please look at it and enlighten me a little bit? I would appreciate an answer either from here or at stackoverflow. Thanks in advance. -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Wed Aug 31 07:48:42 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 31 Aug 2011 13:48:42 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6d4cFa54U1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de> <9c6d4cFa54U1@mid.individual.net> Message-ID: <4E5E1F9A.6010602@shopzeus.com> > What do you mean by STFW? Search The Fucking Web ? > I wasn't aware that easy_install was a utility. Downloaded and installed the > Windows version and run easy_install pywebdav. > It downloaded something, installed something and finished something. Then it's installed! > But, once again, don't know how to proceed. Is that so hard? I have never used pywebdav but the first page I hit through Google search is: http://code.google.com/p/pywebdav/ Where it says: > Installation and setup of server can be as easy as follows: > > $ easy_installPyWebDAV > $ davserver-D/tmp-n-J > Starting upPyWebDAV server(version0.9.2-dev) > >> ATTENTION: Authentication disabled! > >> Serving datafrom /tmp > >> Listening on localhost(8008) So you successfully ran easy_install. Then I guess you will have to look for a program named "davserver" and start it up. I suspect that searching for "davserver.*" under your site-packages dir or Python installation dir will do. L From chris at simplistix.co.uk Wed Aug 31 07:57:04 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Aug 2011 12:57:04 +0100 Subject: argparse: showing full help for subparsers Message-ID: <4E5E2190.6090006@simplistix.co.uk> Hi All, If I have subparsers set up and do: myscript.py --help I get the summary for each of the top-level commands, but to get the help for each sub-command I have to do: myscript.py subcommand --help Is there any way I can get "myscript.py --help" to show the help hierarchically, including all options for all subcommands? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From fnautaNO at SPAMsolfon.nl Wed Aug 31 08:18:00 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 14:18:00 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> Message-ID: <9c6n4oFsnbU1@mid.individual.net> "Paul K?lle" wrote in message news:mailman.595.1314780791.27778.python-list at python.org... > Hi, > > Am 30.08.2011 22:00, schrieb Fokke Nauta: >> Hi all, >> >> I am completely new to Python, but I'm confronted with a problem I can't >> solve. > Welcome to python. > >> This is my question: > [snip] > >> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >> Now >> I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and >> PyXML-0.8.4. In the PyWebDAV README it says: >> >> Installation and setup of server can be as easy as follows: >> >> $ easy_install PyWebDAV >> $ davserver -D /tmp -n -J >> >> But of course it doesn't work like that. When I start up Python GUI I see >> the ">>>" prompt instead of the "$" prompt. But where do I place the two >> directories? And there is no easy_install script in the PyXML-0.8.4 >> directory, only a setup.py and ez_setup.py script. I guess the latter is >> the >> one to use. But how? > You dont install from "Python GUI", use normal cmd, navigate to the folder > you downloaded PyXML and PyWebDAV and run "python setup.py install" > (python.exe has to be in your PATH). Then you have to find the > startup-script "davserver". Find your python installation directory and > look into /Tools/Scripts, in my computer this is > E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the > site-packages folder i.e. E:\python27\Lib/site-packages. You might have to > look for "davserver" there... > Thanks, Paul. I ran "python setup.py install" in both the PyXML and PyWebDAV directories. A lot of things happened and are added into those directories and I guess it will be OK. Next step, the startup-script "davserver". There is no script as such, also not in \python27\tools\scripts. I found 2 similar scripts: 1. server.py in D:\Python27\WebDAV\PyWebDAV\DAVServer 2. WebDAVServer.py in D:\Python27\WebDAV\PyWebDAV\DAV Which one is the one to use? I also configured config.ini in D:\Python27\WebDAV\PyWebDAV\DAVServer In this file it says: "# Auth Database Table, Must exists in database prior to firstrun dbtable=webDav # Create User Database Table and Insert system user" I created in MySQL a database called webDav. I can create a table called User, but how many fields? With regards, Fokke From steve+comp.lang.python at pearwood.info Wed Aug 31 08:33:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 31 Aug 2011 22:33:15 +1000 Subject: PC locks up with list operations Message-ID: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 script that tries to create a list that is insanely too big. In the first case, I (stupidly) did something like: mylist = [0]*12345678901234 After leaving the machine for THREE DAYS (!!!) I eventually was able to get to a console and kill the Python process. Amazingly, it never raised MemoryError in that time. The second time was a little less stupid, but not much: mylist = [] for x in itertools.combinations_with_replacement(some_big_list, 20): mylist.append(func(x)) After three hours, the desktop is still locked up. I'm waiting to see what happens in the morning before rebooting. Apart from "Then don't do that!", is there anything I can do to prevent this sort of thing in the future? Like instruct Python not to request more memory than my PC has? I am using Linux desktops; both incidents were with Python 2.5. Do newer versions of Python respond to this sort of situation more gracefully? -- Steven From fnautaNO at SPAMsolfon.nl Wed Aug 31 08:35:26 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 14:35:26 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> Message-ID: <9c6o4eF5h7U1@mid.individual.net> "Laszlo Nagy" wrote in message news:mailman.597.1314791334.27778.python-list at python.org... > >> What do you mean by STFW? > Search The Fucking Web ? OK, the modern version of RTFM. >> I wasn't aware that easy_install was a utility. Downloaded and installed >> the >> Windows version and run easy_install pywebdav. >> It downloaded something, installed something and finished something. > Then it's installed! >> But, once again, don't know how to proceed. > Is that so hard? I have never used pywebdav but the first page I hit > through Google search is: > > http://code.google.com/p/pywebdav/ I've been there. > Where it says: > >> Installation and setup of server can be as easy as follows: >> >> $ easy_installPyWebDAV >> $ davserver-D/tmp-n-J >> Starting upPyWebDAV server(version0.9.2-dev) >> >> ATTENTION: Authentication disabled! >> >> Serving datafrom /tmp >> >> Listening on localhost(8008) Yes, but that's Unix/Linux again. But I'm in Windows, without experience with Python. > So you successfully ran easy_install. Then I guess you will have to look > for a program named "davserver" and start it up. I suspect that searching > for "davserver.*" under your site-packages dir or Python installation dir > will do. > Fokke From chris at simplistix.co.uk Wed Aug 31 08:40:43 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Aug 2011 13:40:43 +0100 Subject: PC locks up with list operations In-Reply-To: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E5E2BCB.5090903@simplistix.co.uk> On 31/08/2011 13:33, Steven D'Aprano wrote: > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? Ironically, Windows does better here and dumps you out with a MemoryError before slowly recovering. Linux seems to fair badly when programs use more memory than physically available. Perhaps there's some per-process thing that can be used to limit things on Linux? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve+comp.lang.python at pearwood.info Wed Aug 31 08:47:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 31 Aug 2011 22:47:59 +1000 Subject: PC locks up with list operations References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> Chris Withers wrote: > On 31/08/2011 13:33, Steven D'Aprano wrote: >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a > MemoryError before slowly recovering. > > Linux seems to fair badly when programs use more memory than physically > available. Perhaps there's some per-process thing that can be used to > limit things on Linux? As far as I know, ulimit ("user limit") won't help. It can limit the amount of RAM available to a process, but that just makes the process start using virtual memory more quickly. It can also limit the amount of virtual memory used by the shell, but not of other processes. In other words, Linux will try really, really, really hard to give you the 84 gigabytes you've asked for on a 2 GB system, even if it means DOSing your system for a month. Of course, I would be very happy to learn I'm wrong. -- Steven From benjamin.kaplan at case.edu Wed Aug 31 08:49:24 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 31 Aug 2011 08:49:24 -0400 Subject: PC locks up with list operations In-Reply-To: <4E5E2BCB.5090903@simplistix.co.uk> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4E5E2BCB.5090903@simplistix.co.uk> Message-ID: On Wed, Aug 31, 2011 at 8:40 AM, Chris Withers wrote: > > On 31/08/2011 13:33, Steven D'Aprano wrote: >> >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a MemoryError before slowly recovering. > > Linux seems to fair badly when programs use more memory than physically available. Perhaps there's some per-process thing that can be used to limit things on Linux? > > cheers, > > Chris > > -- 32-bit or 64-bit Python? A 32-bit program will crash once memory hits 2GB. A 64-bit program will just keep consuming RAM until your computer starts thrashing. The problem isn't your program using more RAM than you have, just more RAM than you have free. Last time I faced a situation like this, I just decided it was better to stick to the 32-bit program and let it crash if it got too big. > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ?- http://www.simplistix.co.uk > -- > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Wed Aug 31 08:56:07 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Aug 2011 14:56:07 +0200 Subject: PC locks up with list operations References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345678901234 > > After leaving the machine for THREE DAYS (!!!) I eventually was able to > get to a console and kill the Python process. Amazingly, it never raised > MemoryError in that time. > > The second time was a little less stupid, but not much: > > mylist = [] > for x in itertools.combinations_with_replacement(some_big_list, 20): > mylist.append(func(x)) > > After three hours, the desktop is still locked up. I'm waiting to see what > happens in the morning before rebooting. > > Apart from "Then don't do that!", is there anything I can do to prevent > this sort of thing in the future? Like instruct Python not to request more > memory than my PC has? > > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? If you are starting these scripts from the shell, how about ulimit? $ ulimit -v 40000 $ python -c'print range(10**5)[-1]' 99999 $ python -c'print range(10**6)[-1]' Traceback (most recent call last): File "", line 1, in MemoryError $ From king6cong at gmail.com Wed Aug 31 09:35:11 2011 From: king6cong at gmail.com (king6cong at gmail.com) Date: Wed, 31 Aug 2011 21:35:11 +0800 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? Message-ID: hi, This is a question not specific to Python,but its related somehow,and I believe I can get some help from your fellow:) I am doing my work on a server service program on Linux that processes the packages sent to the socket it listens.Their is already a old such service listening on the port doing its job,and I can't stop the old server service, and I need to get the packages sent to the old server and send them to my new server service to make sure it works well .How can I get the package and resent them to my new service? Is there such a tool or is there some functionality that tools such as tcpdump already provides? Thanks:) -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Wed Aug 31 09:36:44 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 31 Aug 2011 15:36:44 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6o4eF5h7U1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> <9c6o4eF5h7U1@mid.individual.net> Message-ID: <4E5E38EC.4070303@shopzeus.com> >> Where it says: >> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_installPyWebDAV >>> $ davserver-D/tmp-n-J >>> Starting upPyWebDAV server(version0.9.2-dev) >>>>> ATTENTION: Authentication disabled! >>>>> Serving datafrom /tmp >>>>> Listening on localhost(8008) > Yes, but that's Unix/Linux again. > But I'm in Windows, without experience with Python. Not really... The "easy_install" command is the same on windows. Maybe the command prompt is different, but the command itself is the same. Same is true with the "davserver" command. If you can find a "davserver.exe" or "davserver.py" or "davserver.pyw" file under site-packages or tools/scripts, then that will be the program that you need to start up. No magic. L From spamtrap at arumes.com Wed Aug 31 10:06:43 2011 From: spamtrap at arumes.com (Robert Spanjaard) Date: Wed, 31 Aug 2011 16:06:43 +0200 Subject: PC locks up with list operations In-Reply-To: References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/31/2011 02:40 PM, Chris Withers wrote: > On 31/08/2011 13:33, Steven D'Aprano wrote: >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a > MemoryError before slowly recovering. I think it's a little premature to make such a statement based on a single user experience. I've used Linux for six years now, and it NEVER locked up, even when a program leaks memory like hell. I can't duplicate the OP's behaviour because my Python (2.6.5, 64 bit) does generate an instant MemoryError (which answers the question, ofcourse), but I've used a VLC version that had a nasty leak. My swap space is on a SSD, and VLC filled it completely in about 10 seconds. But then, VLC got killed automatically, and the system recovered gracefully. On a system with the swapspace on a regular HD, the same will happen, but it'll take more time. And while VLC is filling the swap space, the system does not lock up at all. You can still keep working, and (for example) fire up the process manager and kill VLC yourself. >>> mylist = [0]*12345678901234 Traceback (most recent call last): File "", line 1, in MemoryError -- Regards, Robert http://www.arumes.com From rodrick.brown at gmail.com Wed Aug 31 10:13:02 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 31 Aug 2011 10:13:02 -0400 Subject: PC locks up with list operations In-Reply-To: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <534EAA9D-B7CB-4A1A-A166-BA336EB42004@gmail.com> $ man limits.conf Sent from my iPhone On Aug 31, 2011, at 8:33 AM, Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345678901234 > > After leaving the machine for THREE DAYS (!!!) I eventually was able to get > to a console and kill the Python process. Amazingly, it never raised > MemoryError in that time. > > The second time was a little less stupid, but not much: > > mylist = [] > for x in itertools.combinations_with_replacement(some_big_list, 20): > mylist.append(func(x)) > > After three hours, the desktop is still locked up. I'm waiting to see what > happens in the morning before rebooting. > > Apart from "Then don't do that!", is there anything I can do to prevent this > sort of thing in the future? Like instruct Python not to request more > memory than my PC has? > > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From msarro at gmail.com Wed Aug 31 10:22:20 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 31 Aug 2011 10:22:20 -0400 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: Its possible using TCPDUMP and wireshark. however its a bit of a manual process (open the pcap in wireshark, select the correct tcp stream, and extract the file). I did this to show a vulnerability in how medical images were transmitted in a university hospital once :) Here are some guides, maybe it can serve as a jumping off point? http://packetlife.net/blog/2009/jul/13/quick-packet-capture-data-extraction/ http://wiki.wireshark.org/TCP_Reassembly There are some C# libraries specifically for this: http://www.codeproject.com/KB/IP/TcpRecon.aspx Not sure if anything exists explicitly for python though. -Matty On Wed, Aug 31, 2011 at 9:35 AM, king6cong at gmail.com wrote: > hi, > ? This is a question not specific to Python,but its related somehow,and I > believe I can get some help from your fellow:) > ? I am doing my work on a server service program on Linux that processes the > packages sent to the socket it listens.Their is already a old such service > listening on the port doing its job,and > I can't stop the old server service, and I need to get the packages sent to > the old server and send them to my new server service to make sure it works > well .How can I get the package and resent them to my new service? Is there > such a tool or is there some functionality that tools such as tcpdump > already provides? > Thanks:) > > -- > http://mail.python.org/mailman/listinfo/python-list > > From ian.g.kelly at gmail.com Wed Aug 31 10:25:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 08:25:43 -0600 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Wed, Aug 31, 2011 at 12:35 AM, Arnaud Delobelle wrote: >> You don't know that, an implementation may for example set __bultins__ >> to None, prior to returning, its not an unreasonable thing to do and >> the docs don't say they can't. > > I haven't studied the docs but I'm certain that such an implementation > would break a lot of code. For example: a = 42 exec "a += 1729" print(a) ...since print would no longer be available in the global namespace. Cheers, Ian From kgmerk at gmail.com Wed Aug 31 10:34:30 2011 From: kgmerk at gmail.com (merk) Date: Wed, 31 Aug 2011 07:34:30 -0700 (PDT) Subject: Creating python egg including pre-built libraries Message-ID: I have a set of complex libraries that I have wrapped with swig. I would like to create a python egg of the swig generated python files and the pre-built libraries. The libraries have a lot of dependencies and I don't want to force the user to get all the dependencies to try to build the libraries from source. I just want to distribute some python files and the libraries for a given platform. Does anyone have a recipe for doing something like this? Thanks, Karl From tgoodchild at gmail.com Wed Aug 31 10:35:36 2011 From: tgoodchild at gmail.com (T. Goodchild) Date: Wed, 31 Aug 2011 07:35:36 -0700 (PDT) Subject: Why do class methods always need 'self' as the first parameter? Message-ID: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> I?m new to Python, and I love it. The philosophy of the language (and of the community as a whole) is beautiful to me. But one of the things that bugs me is the requirement that all class methods have 'self' as their first parameter. On a gut level, to me this seems to be at odds with Python?s dedication to simplicity. For example, consider Python?s indent-sensitive syntax. Although other languages didn?t use indentation to specify scope, programmers always used indentation anyways. Making indentation took a common practice, made it a rule, and the result was a significantly improved signal-to-noise ratio in the readability of Python code. So why is 'self' necessary on class methods? It seems to me that the most common practice is that class methods *almost always* operate on the instance that called them. It would make more sense to me if this was assumed by default, and for "static" methods (methods that are part of a class, but never associated with a specific instance) to be labelled instead. Just curious about the rationale behind this part of the language. From invalid at invalid.invalid Wed Aug 31 10:36:16 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Aug 2011 14:36:16 +0000 (UTC) Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? References: Message-ID: On 2011-08-31, Matty Sarro wrote: > Its possible using TCPDUMP and wireshark. however its a bit of a > manual process (open the pcap in wireshark, select the correct tcp > stream, and extract the file). Presumably the OP knows the port IP address and port number on which the server is listening, so wouldn't it be simpler to just capture TCP traffic to/from that IP/port? Then you can play it back using tcprewrite, tcpreplay, et al. But, I don't see how that's going to work. The OP seems to want to capture a TCP session and then "replay it" so that the client from the session ends up talking to a different server during the replay. The chances of the new server starting up a connection with the same ACK sequence number is practially nil isn't it? >> ?? This is a question not specific to Python,but its related >> somehow,and I believe I can get some help from your fellow:) ?? I am >> doing my work on a server service program on Linux that processes the >> packages sent to the socket it listens.Their is already a old such >> service listening on the port doing its job,and I can't stop the old >> server service, and I need to get the packages sent to the old server >> and send them to my new server service to make sure it works well >> .How can I get the package and resent them to my new service? Is >> there such a tool or is there some functionality that tools such as >> tcpdump already provides? Thanks:) -- Grant Edwards grant.b.edwards Yow! ... this must be what at it's like to be a COLLEGE gmail.com GRADUATE!! From fnautaNO at SPAMsolfon.nl Wed Aug 31 10:37:00 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 16:37:00 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> <9c6o4eF5h7U1@mid.individual.net> Message-ID: <9c6v8dF1ngU1@mid.individual.net> "Laszlo Nagy" wrote in message news:mailman.603.1314797809.27778.python-list at python.org... > >>> Where it says: >>> >>>> Installation and setup of server can be as easy as follows: >>>> >>>> $ easy_installPyWebDAV >>>> $ davserver-D/tmp-n-J >>>> Starting upPyWebDAV server(version0.9.2-dev) >>>>>> ATTENTION: Authentication disabled! >>>>>> Serving datafrom /tmp >>>>>> Listening on localhost(8008) >> Yes, but that's Unix/Linux again. >> But I'm in Windows, without experience with Python. > Not really... The "easy_install" command is the same on windows. Maybe the > command prompt is different, but the command itself is the same. Same is > true with the "davserver" command. If you can find a "davserver.exe" or > "davserver.py" or "davserver.pyw" file under site-packages or > tools/scripts, then that will be the program that you need to start up. No > magic. > Actually, I installed easy_install setuptools for Windows (setuptools-0.6c11.win32-py2.7.exe). Running easy_install generated an error message: "Setuptools version 0.6c9 or greater has been installed. (Run "ez_setup.py -U setuptools" to reinstall or upgrade.)" I did, quite something happened but the same error message came back when retrying. So, I installed it another way, indicated by Paul K?lle: "navigate to the folder you downloaded PyXML and PyWebDAV and run "python setup.py install" (python.exe has to be in your PATH). " That worked fine, but: There is no davserver script or executable. Please read my response to Paul K?lle. Fokke From emile at fenx.com Wed Aug 31 10:54:20 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 07:54:20 -0700 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: On 8/31/2011 6:35 AM king6cong at gmail.com said... > hi, > This is a question not specific to Python,but its related somehow,and > I believe I can get some help from your fellow:) > I am doing my work on a server service program on Linux that > processes the packages sent to the socket it listens.Their is already a > old such service listening on the port doing its job,and > I can't stop the old server service, and I need to get the packages sent > to the old server and send them to my new server service to make sure it > works well .How can I get the package and resent them to my new service? > Is there such a tool or is there some functionality that tools such as > tcpdump already provides? I recently set up a standby spare fax server on a network that I also needed to test, and was able to tee the source transmissions to both systems. That may be an option, particularly as it sounds like you've written a consumer of info and are not replying and interacting with the source. Emile From gordon at panix.com Wed Aug 31 10:54:25 2011 From: gordon at panix.com (John Gordon) Date: Wed, 31 Aug 2011 14:54:25 +0000 (UTC) Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: In <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> "T. Goodchild" writes: > So why is 'self' necessary on class methods? It seems to me that the > most common practice is that class methods *almost always* operate on > the instance that called them. It would make more sense to me if this > was assumed by default, and for "static" methods (methods that are > part of a class, but never associated with a specific instance) to be > labelled instead. > Just curious about the rationale behind this part of the language. How would a method access instance variables without 'self'? They probably could have made 'self' a magical attribute that just appears out of thin air instead of being passed as an argument, like 'this' in C++. But would that really provide any benefit? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From emile at fenx.com Wed Aug 31 11:01:01 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 08:01:01 -0700 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: On 8/31/2011 7:35 AM T. Goodchild said... > Just curious about the rationale behind this part of the language. http://docs.python.org/faq/design.html From neilc at norwich.edu Wed Aug 31 11:05:41 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 31 Aug 2011 15:05:41 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <9c70u5FckrU2@mid.individual.net> On 2011-08-31, T. Goodchild wrote: > I?m new to Python, and I love it. The philosophy of the > language (and of the community as a whole) is beautiful to me. > > But one of the things that bugs me is the requirement that all > class methods have 'self' as their first parameter. On a gut > level, to me this seems to be at odds with Python?s dedication > to simplicity. Think it through carefully, and you'll probably agree with Python's design. But not necessarily. In any case, this is a very common complaint, so check out the Python FAQ. http://docs.python.org/faq/design.html#why-self -- Neil Cerutti "A politician is an arse upon which everyone has sat except a man." e. e. cummings From javier.collado at gmail.com Wed Aug 31 11:10:45 2011 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 31 Aug 2011 17:10:45 +0200 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: Hello, 2011/8/31 T. Goodchild : > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter. ?On a gut level, to me > this seems to be at odds with Python?s dedication to simplicity. I think the answer to this question is part of the zen of python: <> http://www.python.org/dev/peps/pep-0020/ Regards, Javier From king6cong at gmail.com Wed Aug 31 11:37:23 2011 From: king6cong at gmail.com (king6cong at gmail.com) Date: Wed, 31 Aug 2011 23:37:23 +0800 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: In fact,UDP is enough for me,I heared that tcpdump and netcat can store and resend the udp packages to get the replay effect,but I don't know how, or is there some better way? I am working on a Linux server and only some basic terminal tools are available :) 2011/8/31 Emile van Sebille > On 8/31/2011 6:35 AM king6cong at gmail.com said... > > hi, >> This is a question not specific to Python,but its related somehow,and >> I believe I can get some help from your fellow:) >> I am doing my work on a server service program on Linux that >> processes the packages sent to the socket it listens.Their is already a >> old such service listening on the port doing its job,and >> I can't stop the old server service, and I need to get the packages sent >> to the old server and send them to my new server service to make sure it >> works well .How can I get the package and resent them to my new service? >> Is there such a tool or is there some functionality that tools such as >> tcpdump already provides? >> > > I recently set up a standby spare fax server on a network that I also > needed to test, and was able to tee the source transmissions to both > systems. That may be an option, particularly as it sounds like you've > written a consumer of info and are not replying and interacting with the > source. > > Emile > > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 31 11:41:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 01:41:27 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> T. Goodchild wrote: > So why is 'self' necessary on class methods? I assume you are talking about the declaration in the method signature: def method(self, args): ... rather than why methods have to be called using self.method. If not, there's already a FAQ for that second question: http://docs.python.org/faq/design.html#why-self > It seems to me that the > most common practice is that class methods *almost always* operate on > the instance that called them. By the way, what you're calling "class methods" are actually *instance* methods, because they receive the instance "self" as the first parameter. Python does have class methods, which receive the class, not the instance, as the first parameter. These are usually written something like this: class K(object): @classmethod def spam(cls, args): print cls # always prints "class K", never the instance Just like self, the name cls is a convention only. Class methods are usually used for alternate constructors. There are also static methods, which don't receive any special first argument, plus any other sort of method you can invent, by creating descriptors... but that's getting into fairly advanced territory. They're generally specialised, and don't see much use. As you can see, the terminology is not exactly the same as Java. > It would make more sense to me if this > was assumed by default, ... Well here's the thing. Python methods are wrappers around function objects. The method wrapper knows which instance is involved (because of the descriptor magic which I alluded to above), but the function doesn't and can't. Or at least not without horrible run-time hacks. By treating "self" as an ordinary parameter which needs to be declared, you can do cool stuff like bound and unbound methods: f = "instance".upper # this is a bound method g = str.upper # this is an unbound method The bound method f already has the instance "self" filled in, so to speak. So you can now just call it, and it will work: f() => returns "INSTANCE" The unbound method still needs the instance supplied. This makes it perfect for code like this: for instance in ("hello", "world"): print g(instance) especially if you don't know what g will be until run-time. (E.g. will it be str.upper, str.lower, str.title?) Because methods require that first argument to be given explicitly, unbound methods are practically ordinary functions. They're so like functions that in Python 3, they're done away with altogether, and the unwrapped function object will be returned instead. You can also do nifty stuff like dynamic method injections: >>> def func(a, b): ... print(a, b) ... >>> class K(object): ... pass ... >>> K.func = func # dynamically inject a method >>> instance = K() >>> instance.func(23) (<__main__.K object at 0xb7f0a4cc>, 23) and it all just works. You can even inject a method onto the instance, although it takes a bit more effort to make that work. All this is possible without nasty hacks because self is treated as just an ordinary parameter of functions. Otherwise, the compiler would need to know whether the function was being called from inside a method wrapper or not, and change the function signature appropriately, and that just gets too ugly and messy for words. So for the cost of having to declare self as an argument, we get: * instant visual recognition of what's intended as a method ("the first argument is called self") and what isn't * a nicely consistent treatment of function signatures at all times * clean semantics for the local variable namespace * the same mechanism (with minor adjustments) can be used for class and static methods * bound and unbound methods semantics plus as a bonus, plenty of ongoing arguments about whether or not having to explicitly list "self" as a parameter is a good thing or not, thus keeping people busy arguing on mailing lists instead of coding -- Steven From k.sahithi2862 at gmail.com Wed Aug 31 11:41:57 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 31 Aug 2011 08:41:57 -0700 (PDT) Subject: HOT ACTRESS PHOTOS AND VIDEOS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS TAMANNA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/tamanna-hot.html PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From ian.g.kelly at gmail.com Wed Aug 31 11:44:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 09:44:47 -0600 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <4E5E051B.8060002@v.loewis.de> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> Message-ID: On Wed, Aug 31, 2011 at 3:55 AM, Martin v. Loewis wrote: > if sys.version_info < (3,): > def getDictValues(dict): > return dict.itervalues() > else: > def getDictValues(dict): > return dict.values() The extra level of function call indirection is unnecessary here. Better to write it as: if sys.version_info < (3,): getDictValues = dict.itervalues else: getDictValues = dict.values (which is basically what the OP was doing in the first place). >> I noticed that hashing is a lot different in Python than it is in .NET >> languages. .NET supports custom "equality comparers" that can override >> a type's Equals and GetHashCode functions. This is nice when you can't >> change the class you are hashing. That is why I am using a key >> selector in my code, here. Is there a better way of overriding the >> default hashing of a type without actually modifying its definition? I >> figured a requesting a key was the easiest way. > > You could provide a Key class that takes a hash function and a value > function: > > class Key: > ?def __init__(self, value, hash, eq): > ? ?self.value, self.hash, self.eq = value, hash, eq > ?def __hash__(self): > ? ?return self.hash(self.value) > ?def __eq__(self, other_key): > ? ?return self.eq(self.value, other_key.value) > > This class would then be used instead of your keySelector. For added value, you can make it a class factory so you don't have to specify hash and eq over and over: def Key(keyfunc): class Key: def __init__(self, value): self.value = value def __hash__(self): return hash(keyfunc(self.value)) def __eq__(self, other): return keyfunc(self) == keyfunc(other) return Key KeyTypeAlpha = Key(lambda x: x % 7) items = set(KeyTypeAlpha(value) for value in sourceIterable) Cheers, Ian From dalist0 at gmail.com Wed Aug 31 11:51:45 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 08:51:45 -0700 (PDT) Subject: fun with nested loops Message-ID: Dear All, I have some complicated loops of the following form for c in configurations: # loop 1 while nothing_bad_happened: # loop 2 while step1_did_not_work: # loop 3 for substeps in step1 # loop 4a # at this point, we may have to -leave loop 1 -restart loop 4 -skip a step in loop 4 -continue on to loop 4b while step2_did_not_work: # loop 4b for substeps in step2: # at this point, we may have to -leave loop 1 -restart loop 2 -restart loop 4b ... ...many more loops... I don't see any way to reduce these nested loops logically, they describe pretty well what the software has to do. This is a data acquisition application, so on ever line there is a lot of IO that might fail or make subsequent steps useless or require a retry. Now every step could need to break out of any of the enclosing loops. So basically I have to transform every loop to be of the following horror: # general transformation of # "for c in configurations..." # to provide restart, break and continue # callable from any nesting level inside of the loop class loop1_restart(Exception): pass class loop1_break(Exception): pass class loop1_continue(Exception): pass while True: try: for c in configurations: while True: try: # inner loops go here, of course, they would have to get # all the boilerplate added, too while nothing_bad_happened: while step1_did_not_work: if cond1: raise loop1_restart() elif cond3: raise loop1_break() elif cond3: raise loop1_continue() break except loop1_continue: pass break except loop1_restart: pass except loop1_break: break Of course this is extremely tedious and error prone. If Python had named loops (PEP 3136, unfortunately rejected), this would be trivial: In Fortran I can continue (cycle), break (exit) and redo (goto label) arbitrary loops, which results in neat code: 10 loop1: do I=1,3 loop2: do J=1,4 print *,I,J goto 10 cycle loop1 exit loop1 enddo loop2 enddo loop1 My question is, how do I obtain something that implements the following logic: @named_loop(fred) # I wish this would be possible for i in range(10): for j in range(10): break fred # breaks out of outer loop continue fred # continues outer loop redo fred # resets outer loop and restarts with i=0 The best solution would be something along the Proposal D - Explicit iterators in PEP 3136, in this case it would even be possible to peek at the next i or advance/reverse the iterator a few steps. Has anyone an idea on a nice way to write breaks/continues/redos for deeply nested loops? Dan From yasar11732 at gmail.com Wed Aug 31 12:03:11 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 19:03:11 +0300 Subject: Subclassing str object In-Reply-To: References: Message-ID: I made a class like this (I shortened it just to show the point), what do you think about it, do you think it is the python way of subclassing str (or unicode in this case) # -*- coding:utf-8 -*-class kelime(unicode): def __init__(self,sozcuk): self._sozcuk = sozcuk def __getattribute__(self, isim): att = super(kelime, self).__getattribute__(isim) if not callable(att): return att def sonra_cagir(*args, **kwargs): sonuc = att(*args, **kwargs) if isinstance(sonuc, basestring): return kelime(sonuc) return sonuc return sonra_cagir def cogul(self): for harf in reversed(self._sozcuk): if harf in kalin: return kelime(self._sozcuk + u"lar") elif harf in ince: return kelime(self._sozcuk + u"ler") return kelime(self._sozcuk + u"lar") 31 A?ustos 2011 14:43 tarihinde Ya?ar Arabac? yazd?: > H?, > > I originally posted my question to here: > http://stackoverflow.com/q/7255655/886669 Could you people please look at > it and enlighten me a little bit? I would appreciate an answer either from > here or at stackoverflow. Thanks in advance. > > -- > http://yasar.serveblog.net/ > > -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 31 12:06:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 02:06:50 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <4e5e5c1b$0$29974$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> "T. > Goodchild" writes: > >> So why is 'self' necessary on class methods? It seems to me that the >> most common practice is that class methods *almost always* operate on >> the instance that called them. It would make more sense to me if this >> was assumed by default, and for "static" methods (methods that are >> part of a class, but never associated with a specific instance) to be >> labelled instead. > >> Just curious about the rationale behind this part of the language. > > How would a method access instance variables without 'self'? If Python had compile time declarations, the compiler could know whether x=1 was referring to a local variable x or an attribute x. The reader might not, but the compiler would :) By the way, although the Python docs are a little inconsistent, the usual term here is "attribute" rather than "instance variable". Attributes need not live on the instance: they can also live on the class, a superclass, or be computed at run-time via at least three different mechanisms I can think of (__getattribute__, __getattr__, properties). Local variables are treated a bit differently from attributes, but broadly speaking, if you need a dot to access something, it's an attribute, if you don't, it's a name binding (or variable). Python even has two different sorts of errors for "variable" lookup failures: NameError (or UnboundLocalError) for un-dotted names, and AttributeError for dotted names. > They probably could have made 'self' a magical attribute that just > appears out of thin air instead of being passed as an argument, like > 'this' in C++. But would that really provide any benefit? Well obviously the C++ people thought so :) The effort to type "self, " in method signatures is pretty low. I don't think it is a problem. But other languages are free to choose differently. Cobra, for example, is explicitly derived from Python in many ways, but it drops the "self" (as well as other changes). http://cobra-language.com/docs/python/ -- Steven From emile at fenx.com Wed Aug 31 12:20:21 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 09:20:21 -0700 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: On 8/31/2011 8:37 AM king6cong at gmail.com said... > In fact,UDP is enough for me,I heared that tcpdump and netcat can store > and resend the udp packages to get the replay effect,but I don't know > how, That may be, but I've never tried that. > or is there some better way? I am working on a Linux server and > only some basic terminal tools are available :) If appropriate, I'd try the iptables --tee option. Emile From invalid at invalid.invalid Wed Aug 31 12:20:51 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Aug 2011 16:20:51 +0000 (UTC) Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5c1b$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-31, Steven D'Aprano wrote: > Well obviously the C++ people thought so :) Well _that's_ certainly a ringing endorsement in the context of designing a language that's easy to understand and use. ;) -- Grant Edwards grant.b.edwards Yow! Where's SANDY DUNCAN? at gmail.com From tjreedy at udel.edu Wed Aug 31 12:30:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 12:30:59 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: On 8/31/2011 10:35 AM, T. Goodchild wrote: > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter. On a gut level, to me > this seems to be at odds with Python?s dedication to simplicity. Actually, it is a consequence of Python's dedication to simplicity. A method is simply a function that is an attribute of a class. (This is even clearer in Py 3.) Hence, there is no special syntax for methods. Consider def double(obj): return 2*obj.value class C: def __init__(self, val): self.value = val c = C(3) C.double = double c.doub = double # not c.double as that would mask access to C.double in c.double() below print(double(c), C.double(c), c.double(), c.doub(c)) # 6 6 6 6 -- Terry Jan Reedy From aspineux at gmail.com Wed Aug 31 12:35:45 2011 From: aspineux at gmail.com (aspineux) Date: Wed, 31 Aug 2011 09:35:45 -0700 (PDT) Subject: fun with nested loops References: Message-ID: On Aug 31, 5:51?pm, Daniel wrote: > Dear All, > > I have some complicated loops of the following form > > for c in configurations: # loop 1 > ? ? while nothing_bad_happened: # loop 2 > ? ? ? ? while step1_did_not_work: # loop 3 > ? ? ? ? ? ? for substeps in step1 # loop 4a > ? ? ? ? ? ? ? ? # at this point, we may have to > ? ? ? ? ? ? ? ? -leave loop 1 > ? ? ? ? ? ? ? ? -restart loop 4 > ? ? ? ? ? ? ? ? -skip a step in loop 4 > ? ? ? ? ? ? ? ? -continue on to loop 4b > > ? ? ? ? while step2_did_not_work: # loop 4b > ? ? ? ? ? ? for substeps in step2: > ? ? ? ? ? ? ? ? # at this point, we may have to > ? ? ? ? ? ? ? ? -leave loop 1 > ? ? ? ? ? ? ? ? -restart loop 2 > ? ? ? ? ? ? ? ? -restart loop 4b > ? ? ? ? ? ? ? ? ... > ? ? ? ? ...many more loops... > > I don't see any way to reduce these nested loops logically, they > describe pretty well what the software has to do. > This is a data acquisition application, so on ever line there is > a lot of IO that might fail or make subsequent steps useless or > require a > retry. > > Now every step could need to break out of any of the enclosing loops. > So basically I have to transform every loop to be of the following > horror: > > # general transformation of > # "for c in configurations..." > # to provide restart, break and continue > # callable from any nesting level inside of the loop > > class loop1_restart(Exception): pass > class loop1_break(Exception): pass > class loop1_continue(Exception): pass > > while True: > ? ? try: > ? ? ? ? for c in configurations: > ? ? ? ? ? ? while True: > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? # inner loops go here, of course, they would have > to get > ? ? ? ? ? ? ? ? ? ? # all the boilerplate added, too > ? ? ? ? ? ? ? ? ? ? while nothing_bad_happened: > ? ? ? ? ? ? ? ? ? ? ? ? while step1_did_not_work: > ? ? ? ? ? ? ? ? ? ? ? ? ? ?if cond1: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_restart() > ? ? ? ? ? ? ? ? ? ? ? ? ? ?elif cond3: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_break() > ? ? ? ? ? ? ? ? ? ? ? ? ? ?elif cond3: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_continue() > > ? ? ? ? ? ? ? ? ? ? break > > ? ? ? ? ? ? ? ? except loop1_continue: > ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? break > ? ? except loop1_restart: > ? ? ? ? pass > ? ? except loop1_break: > ? ? ? ? break > > Of course this is extremely tedious and error prone. > If Python had named loops (PEP 3136, unfortunately rejected), this > would be trivial: > In Fortran I can continue (cycle), break (exit) and redo (goto label) > arbitrary > loops, which results in neat code: > > 10 loop1: do I=1,3 > ? ? loop2: do J=1,4 > ? ? ? ? print *,I,J > ? ? ? ? goto 10 > ? ? ? ? cycle loop1 > ? ? ? ? exit loop1 > ? ? enddo loop2 > enddo loop1 > > My question is, how do I obtain something that implements the > following logic: > > @named_loop(fred) # I wish this would be possible > for i in range(10): > ? ? for j in range(10): > ? ? ? ? break fred # breaks out of outer loop > ? ? ? ? continue fred # continues outer loop > ? ? ? ? redo fred # resets outer loop and restarts with i=0 > > The best solution would be something along the Proposal D - Explicit > iterators > in PEP 3136, in this case it would even be possible to peek at the > next i or > advance/reverse the iterator a few steps. > > Has anyone an idea on a nice way to write breaks/continues/redos for > deeply > nested loops? Hi Dan, it looks like you have already answered all your questions. one more idea, a kind of named loop: ic=0 op='what to do' while ic > Dan From python at mrabarnett.plus.com Wed Aug 31 12:41:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Aug 2011 17:41:55 +0100 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: References: <4E5D5AD0.9070408@mrabarnett.plus.com> Message-ID: <4E5E6453.60300@mrabarnett.plus.com> On 31/08/2011 04:39, Andreas wrote: > Am 30.08.2011 23:49, schrieb MRAB: > >> The key phrase is "argument tuple". The arguments passed to a Python >> call are always a tuple, not PyFloat_Object. >> >> You can build a tuple from the PyFloat_Object using: >> >> Py_BuildValue("(O)", float_object) >> >> The "(O)" says to build a tuple ("(...)") containing a single object >> ("O"). > Some other points: Py_BuildValue defaults to building a tuple if the format string contains multiple items, eg "OO" means the same as "(OO)". In your case, there is only one, so the (...) is required. The object returned will have a reference count of 1, and any Python object passed to the function will have its reference count incremented. > Thank you very much! That solved my problem. > Here the full working example: > > static double doubleValue = 1314761451; > PyObject *floatObj = NULL; > PyObject *timeTuple = NULL; > PyObject *dateTime = NULL; > > floatObj = PyFloat_FromDouble(doubleValue); > timeTuple = Py_BuildValue("(O)", floatObj); > dateTime = PyDateTime_FromTimestamp(timeTuple); > PyFloat_FromDouble returns an object with a reference count of 1 and Py_BuildValue increments that reference count, so you should probably be decrementing it afterwards, otherwise you'll have a memory leak. The usual rule is that you create it, use it, then 'decref' it. Also, you should be doing some error-checking, seeing if Py_BuildValue, etc, is returning NULL, indicating an error. From jehugaleahsa at gmail.com Wed Aug 31 12:45:28 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 09:45:28 -0700 (PDT) Subject: Closures and Partial Function Application Message-ID: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> I was a little disappointed the other day when I realized that closures were read-only. I like to use closures quite a bit. Can someone explain why this limitation exists? Secondly, since I can cheat by wrapping the thing being closure-ified, how can I write a simple wrapper that has all the same members as the thing (decorator), that then applies them to the underlying thing? I also like partial function application. What is the easiest way of achieving this in Python? Would it look something like this: def foo(x, y): return x + y xFoo = lambda y: foo(10, y) From arnodel at gmail.com Wed Aug 31 12:55:34 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 31 Aug 2011 17:55:34 +0100 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On 31 August 2011 17:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. > > Can someone explain why this limitation exists? Secondly, since I can > cheat by wrapping the thing being closure-ified, how can I write a > simple wrapper that has all the same members as the thing (decorator), > that then applies them to the underlying thing? I don't understand. Can you give an example? > I also like partial function application. What is the easiest way of > achieving this in Python? Would it look something like this: > > def foo(x, y): > ? ?return x + y > > xFoo = lambda y: foo(10, y) from functools import partial foo10 = partial(foo, 10) HTH Arnaud From mperzel at gmail.com Wed Aug 31 12:58:15 2011 From: mperzel at gmail.com (mfperzel) Date: Wed, 31 Aug 2011 09:58:15 -0700 (PDT) Subject: Python Tools for Visual Studio - anyone using it? References: Message-ID: On Aug 30, 1:34?pm, Philip Semanchuk wrote: > Hi all, > I was reminded today (via Slashdot) of Python Tools for Visual Studio which was discussed on this list back in March (http://mail.python.org/pipermail/python-list/2011-March/1267662.html) and has reached version 1.0. Is anyone here using it? Care to share pros & cons? > > Here's the URL for those who haven't heard of it before:http://pytools.codeplex.com/ > > Thanks > Philip I have been using it for a few days now. I really like it. It doesn't have all of the features of other python specific IDEs but the core features are done very well. It feels very complete. It seems to have all the features I need and they feel rock solid. Pros: Seemed very snappy compared to other Python IDEs I have used Debugger is very well done. Price( Free when using the VS 2010 Shell ) **Subjective: The editor just feels really nice. Cons: "Basic" compared to other IDES. By this I mean it doesn't have some of the nice-to-have features like explicit Django support. Have to download and install a 180mb "Shell" version of VS to use it if you don't already have VS installed. Personally I was very surprised at how good this plugin is. It has quickly become my python IDE of choice on Windows( or anywhere else ) From tjreedy at udel.edu Wed Aug 31 13:07:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 13:07:48 -0400 Subject: Subclassing str object In-Reply-To: References: Message-ID: On 8/31/2011 7:43 AM, Ya?ar Arabac? wrote: > H?, > > I originally posted my question to here: > http://stackoverflow.com/q/7255655/886669 Could you people please look > at it and enlighten me a little bit? I would appreciate an answer either > from here or at stackoverflow. I believe two people already gave my answer. If 'a' is bound to a str() object, "a.capitalize() will return a standard, unmodified str, not your custom class, so a.capitalize().mycustommethod() will fail.". If you reject that enlightenment, there is not much more to say. (And if you accept it, I am not sure what you still need.) To put is a different way, if you want to chain together existing string methods and your new methods, you must start with objects of your new subclass and wrap every string method that you want to chain. class mystr(str): ... def capitalize(s): return mystr(str.capitalize(s)) You ended up doing something like this in your edit #3, except you perhaps should not have the __init__ method (depending on what 'sozcuk' is) and you do the wrapping on every call instead of just once and use the generalized signature *arg,**kwds for every method, which will make tracebacks much less informative. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed Aug 31 13:11:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 11:11:16 -0600 Subject: Subclassing str object In-Reply-To: References: Message-ID: 2011/8/31 Ya?ar Arabac? : > I made a class like this (I shortened it just to show the point), what do > you think about it, do you think it is the python way of subclassing str (or > unicode in this case) You don't need the _sozcuk attribute at all here. It's just the same as the value of the unicode object itself. The code could be simplified to: class kelime(unicode): def __getattribute__(self, isim): att = super(kelime, self).__getattribute__(isim) if not callable(att): return att def sonra_cagir(*args, **kwargs): sonuc = att(*args, **kwargs) if isinstance(sonuc, basestring): return kelime(sonuc) return sonuc return sonra_cagir def cogul(self): for harf in reversed(self): if harf in kalin: return kelime(self + u"lar") elif harf in ince: return kelime(self + u"ler") return kelime(self + u"lar") Also, "isinstance(sonuc, basestring)" should probably be "isinstance(sonuc, unicode)". Otherwise you'll break the encode method. If you want "kelime(u'one') + kelime(u'two')" to return a kelime instance, you'll need to override the __add__ special method as well. Likewise for "kelime(u'repeat') * 20" and the __mul__ method. You'll also want to override __getitem__ so that slicing returns a kelime instance as expected. Finally, I gather that the goal of this is not to modify the behavior of the unicode class at all, but just to add custom methods? I would strongly recommend that you not use a subclass for this, and instead just write some functions that take a string to operate on as an argument. Subclassing built-in types tends to be tricky as you can see, and this doesn't seem like a good reason to attempt it. Cheers, Ian From ramit.prasad at jpmorgan.com Wed Aug 31 13:12:48 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 31 Aug 2011 13:12:48 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> >def double(obj): return 2*obj.value > >class C: > def __init__(self, val): > self.value = val > >c = C(3) >C.double = double >c.doub = double ># not c.double as that would mask access to C.double in c.double() below >print(double(c), C.double(c), c.double(), c.doub(c)) Sorry if I get some of the following terminology wrong, I get a bit confused on Python terms. I hope the following is still coherent. (Is there a dictionary of Python terminology?) Given the above example I get this >>> print c.double(c) TypeError: double() takes exactly 1 argument (2 given) >>> print c.doub(c) 6 It seems to me that if I add a function to the list of class attributes it will automatically wrap with "self" but adding it to the object directly will not wrap the function as a method. Can somebody explain why? I would have thought that any function added to an object would be a method (unless decorated as a class method). Hmm, or does the decoration just tell Python not to turn an object's function into a method? I.e. Is the decorator basically just the syntactic sugar for doing the above? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From paul at subsignal.org Wed Aug 31 13:14:24 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Wed, 31 Aug 2011 19:14:24 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6n4oFsnbU1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <9c6n4oFsnbU1@mid.individual.net> Message-ID: Hi, answers below... Am 31.08.2011 14:18, schrieb Fokke Nauta: > "Paul K?lle" wrote in message > news:mailman.595.1314780791.27778.python-list at python.org... >> Hi, >> >> Am 30.08.2011 22:00, schrieb Fokke Nauta: >>> Hi all, >>> >>> I am completely new to Python, but I'm confronted with a problem I can't >>> solve. >> Welcome to python. >> >>> This is my question: >> [snip] >> >>> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >>> Now >>> I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and >>> PyXML-0.8.4. In the PyWebDAV README it says: >>> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_install PyWebDAV >>> $ davserver -D /tmp -n -J >>> >>> But of course it doesn't work like that. When I start up Python GUI I see >>> the ">>>" prompt instead of the "$" prompt. But where do I place the two >>> directories? And there is no easy_install script in the PyXML-0.8.4 >>> directory, only a setup.py and ez_setup.py script. I guess the latter is >>> the >>> one to use. But how? >> You dont install from "Python GUI", use normal cmd, navigate to the folder >> you downloaded PyXML and PyWebDAV and run "python setup.py install" >> (python.exe has to be in your PATH). Then you have to find the >> startup-script "davserver". Find your python installation directory and >> look into/Tools/Scripts, in my computer this is >> E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the >> site-packages folder i.e. E:\python27\Lib/site-packages. You might have to >> look for "davserver" there... >> > > Thanks, Paul. > > I ran "python setup.py install" in both the PyXML and PyWebDAV directories. > A lot of things happened and are added into those directories and I guess it > will be OK. > Next step, the startup-script "davserver". There is no script as such, also > not in \python27\tools\scripts. > I found 2 similar scripts: > 1. server.py in D:\Python27\WebDAV\PyWebDAV\DAVServer > 2. WebDAVServer.py in D:\Python27\WebDAV\PyWebDAV\DAV > > Which one is the one to use? Your install locations look odd, but it might work nevertheless. The server is in DAVServer\server.py, you can look at the file and you will see: if __name__ == '__main__': run() at the bottom. This is the "entry point" of a python script if called from the command line. My install looks a bit different but I can start the server as follows: python.exe E:\Python27\Lib\site-packages\pywebdav-0.9.4.1-py2.7.egg\DAVServer\server.py -D c:\home -n WARNING:pywebdav:Authentication disabled! Listening on localhost (8008) > > I also configured config.ini in D:\Python27\WebDAV\PyWebDAV\DAVServer I would use a config file outside the program directory and use the -c or --config switch, run server.py without arguments to see possible startup options. > > In this file it says: > "# Auth Database Table, Must exists in database prior to firstrun > dbtable=webDav > > # Create User Database Table and Insert system user" > > I created in MySQL a database called webDav. > I can create a table called User, but how many fields? Don't know if that's documented somewhere but you can just look at the code in mysqlauth.py in the same directory as server.py. Seems it needs three columns, (User,Pass,can_write<0|1>) but I haven't tried. cheers Paul From clp2 at rebertia.com Wed Aug 31 13:18:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 10:18:57 -0700 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. Assuming I'm intuiting your question correctly, then you're incorrect; they are "read/write". You just need a `nonlocal` declaration for the variables in question. See http://www.python.org/dev/peps/pep-3104/ and http://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonlocal for details. Cheers, Chris From eaglebalti at gmail.com Wed Aug 31 13:22:36 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Wed, 31 Aug 2011 10:22:36 -0700 (PDT) Subject: Please visit the following link to watch Cristiano Ronaldo New Pics. Message-ID: Hello Friends. I brought nice, beautiful, amazing and attracive Pics of Cristiano Ronaldo.Please Visit the following link for more detail http://cristianoronaldopics2011.blogspot.com/ From yasar11732 at gmail.com Wed Aug 31 13:49:20 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 20:49:20 +0300 Subject: Subclassing str object In-Reply-To: References: Message-ID: @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at all, so I deleted it. My class's addition and multiplication works without overwriting __add__ and __mul__ because, this class uses unicode's __add__ and __mul__ than creates a new kelime instance with return value of those methods in __getattribute__. I didn't get a good grasp on how using basestring there might broke encoding, could you explain a little bit more, or provide a reading material? And, as with the purpose, yes, it is intended to add some methods on unicode. But the bigger purpose is to learn how to work with builtin objects, or more spesifically, immutable ones. Therefore I value much to make this simple example work, and make it work in a python way. @Terry: yes, my *args **kwargs method made tracebacks much less informative. I agree on that. I am still trying to implement a better way. @all: So the thing I wonder, when creating new instance in for example capitalize() method, does str use something like self.__new__() or unicode.__new__()? Because, in latter case, I could override the __new__ method on my class, so that every method would create my class's instance, instead of unicode's 31 A?ustos 2011 20:11 tarihinde Ian Kelly yazd?: > 2011/8/31 Ya?ar Arabac? : > > I made a class like this (I shortened it just to show the point), what do > > you think about it, do you think it is the python way of subclassing str > (or > > unicode in this case) > > You don't need the _sozcuk attribute at all here. It's just the same > as the value of the unicode object itself. The code could be > simplified to: > > class kelime(unicode): > > def __getattribute__(self, isim): > att = super(kelime, self).__getattribute__(isim) > if not callable(att): > return att > def sonra_cagir(*args, **kwargs): > sonuc = att(*args, **kwargs) > if isinstance(sonuc, basestring): > return kelime(sonuc) > return sonuc > return sonra_cagir > > def cogul(self): > for harf in reversed(self): > if harf in kalin: > return kelime(self + u"lar") > elif harf in ince: > return kelime(self + u"ler") > return kelime(self + u"lar") > > Also, "isinstance(sonuc, basestring)" should probably be > "isinstance(sonuc, unicode)". Otherwise you'll break the encode > method. > > If you want "kelime(u'one') + kelime(u'two')" to return a kelime > instance, you'll need to override the __add__ special method as well. > Likewise for "kelime(u'repeat') * 20" and the __mul__ method. You'll > also want to override __getitem__ so that slicing returns a kelime > instance as expected. > > Finally, I gather that the goal of this is not to modify the behavior > of the unicode class at all, but just to add custom methods? I would > strongly recommend that you not use a subclass for this, and instead > just write some functions that take a string to operate on as an > argument. Subclassing built-in types tends to be tricky as you can > see, and this doesn't seem like a good reason to attempt it. > > Cheers, > Ian > -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Wed Aug 31 13:51:37 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 10:51:37 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> On Aug 31, 1:18?pm, Chris Rebert wrote: > On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > > I was a little disappointed the other day when I realized that > > closures were read-only. I like to use closures quite a bit. > > Assuming I'm intuiting your question correctly, then you're incorrect; > they are "read/write". You just need a `nonlocal` declaration for the > variables in question. Seehttp://www.python.org/dev/peps/pep-3104/ > andhttp://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonl... > for details. > > Cheers, > Chris > > Cool. So I just need to put "nonlocal" in front of the variable name. From jehugaleahsa at gmail.com Wed Aug 31 14:02:41 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 11:02:41 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: On Aug 31, 1:51?pm, Travis Parks wrote: > On Aug 31, 1:18?pm, Chris Rebert wrote: > > > On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > > > I was a little disappointed the other day when I realized that > > > closures were read-only. I like to use closures quite a bit. > > > Assuming I'm intuiting your question correctly, then you're incorrect; > > they are "read/write". You just need a `nonlocal` declaration for the > > variables in question. Seehttp://www.python.org/dev/peps/pep-3104/ > > andhttp://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonl... > > for details. > > > Cheers, > > Chris > > Cool. So I just need to put "nonlocal" in front of the variable name. Am I doing something wrong, here? nonlocal isn't registering. Which version did this get incorporated? From bruno.desthuilliers at gmail.com Wed Aug 31 14:03:49 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 31 Aug 2011 11:03:49 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: <0d66c6c7-fbbb-4030-8d00-9f260f4c0e22@h11g2000vbc.googlegroups.com> On 31 ao?t, 18:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. They are not _strictly_ read only, but Python being first and foremost an OO language, it's usually way simpler to use OO instead of closures when you start needing such features. From rosuav at gmail.com Wed Aug 31 14:13:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 04:13:22 +1000 Subject: fun with nested loops In-Reply-To: References: Message-ID: On Thu, Sep 1, 2011 at 1:51 AM, Daniel wrote: > > Has anyone an idea on a nice way to write breaks/continues/redos for > deeply > nested loops? > Do you only ever have one top-level loop that you would be naming? If so, put that loop into a function and use return instead of break. Unfortunately that doesn't work for continue. ChrisA From ian.g.kelly at gmail.com Wed Aug 31 14:18:30 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 12:18:30 -0600 Subject: Closures and Partial Function Application In-Reply-To: References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: On Wed, Aug 31, 2011 at 12:02 PM, Travis Parks wrote: > Am I doing something wrong, here? nonlocal isn't registering. Which > version did this get incorporated? 3.0 From jehugaleahsa at gmail.com Wed Aug 31 14:26:00 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 11:26:00 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: <84d38b41-5137-401d-b3c3-b6cf44451c73@gz5g2000vbb.googlegroups.com> On Aug 31, 2:18?pm, Ian Kelly wrote: > On Wed, Aug 31, 2011 at 12:02 PM, Travis Parks wrote: > > Am I doing something wrong, here? nonlocal isn't registering. Which > > version did this get incorporated? > > 3.0 Ah, okay. It would be really useful for unit testing. Unfortunately, I want to make the code I am writing compatible with 2.x and 3.x. I will just deal with it until 3.x takes over. Glad to know Guido sees the importance. From clp2 at rebertia.com Wed Aug 31 14:31:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 11:31:21 -0700 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Aug 31, 2011 at 10:12 AM, Prasad, Ramit wrote: >>def double(obj): return 2*obj.value >> >>class C: >> ? ? def __init__(self, val): >> ? ? ? ? self.value = val >> >>c = C(3) >>C.double = double >>c.doub = double >># not c.double as that would mask access to C.double in c.double() below >>print(double(c), C.double(c), c.double(), c.doub(c)) > > Sorry if I get some of the following terminology wrong, I get a bit confused on Python terms. I hope the following is still coherent. (Is there a dictionary of Python terminology?) The documentation has a glossary: http://docs.python.org/glossary.html It's not entirely comprehensive though. Cheers, Chris From dalist0 at gmail.com Wed Aug 31 14:40:05 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 11:40:05 -0700 (PDT) Subject: fun with nested loops References: Message-ID: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> > one more idea, a kind of named loop: interesting idea, thanks. > > When it become too complicate, I use state machine:http://en.wikipedia.org/wiki/Finite-state_machine I unsuccessfully played a bit with a FSM, but there is a lot of data that is passed around between the states and a lot of counting (like trying a certain step n times), so the FSM turned out to be even more complex. And I have to keep the code simple for non CS people to run the actual experiment. The loops are kind of self-explanatory, this is exactly how you would specify the experiment, even though I am really hitting a wall at the moment. Maybe I am really missing an obvious solution, because breaking out of nested loops really doesn't seem like anything fancy. Fortran/c/c++/ Ruby/Perl all have that facility, even Java has named loops. From dalist0 at gmail.com Wed Aug 31 15:07:03 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 12:07:03 -0700 (PDT) Subject: fun with nested loops References: Message-ID: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> > Do you only ever have one top-level loop that you would be naming? If no, unfortunately not. The rough structure is several loops deep, and I need to break/continue/restart many of them. Continue is used more than break, because most of the time that I find some strange value, I'd just _continue_ a few levels up to restart the current measurements. for some configurations while not enough data collected while not in the right state for steps in steps to bring the system to the right state if the system is bad, break out of all loops if it just need to be reset, just redo the steps if it is ok, go to the next while loop while in the right state steps to do some measurements ... From rosuav at gmail.com Wed Aug 31 15:15:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 05:15:42 +1000 Subject: fun with nested loops In-Reply-To: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> References: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> Message-ID: On Thu, Sep 1, 2011 at 5:07 AM, Daniel wrote: >> Do you only ever have one top-level loop that you would be naming? If > no, unfortunately not. The rough structure is several loops deep, and > I need to break/continue/restart many of them. > Continue is used more than break, because most of the time that I find > some strange value, I'd just _continue_ a few levels up > to restart the current measurements. > Ah well, was worth a try. Raising exceptions smells wrong for this, but peppering your code with sentinel checks isn't much better. I don't really know what would be a good solution to this... except maybe this, which was proposed a few years ago and which I'd never heard of until Google showed it to me just now: http://entrian.com/goto/ ChrisA From lists at andros.org.uk Wed Aug 31 15:29:27 2011 From: lists at andros.org.uk (Andrew McLean) Date: Wed, 31 Aug 2011 20:29:27 +0100 Subject: Python Tools for Visual Studio - anyone using it? In-Reply-To: References: Message-ID: <4E5E8B97.8050402@andros.org.uk> I understand that Python Tools for Visual Studio doesn't work with VS Express, but does work with the (free) VS 2010 Shell. Does anyone know if you can install VS Express and VS Shell on the same machine? From jehugaleahsa at gmail.com Wed Aug 31 15:33:14 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 12:33:14 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <0d66c6c7-fbbb-4030-8d00-9f260f4c0e22@h11g2000vbc.googlegroups.com> Message-ID: On Aug 31, 2:03?pm, "bruno.desthuilli... at gmail.com" wrote: > On 31 ao?t, 18:45, Travis Parks wrote: > > > I was a little disappointed the other day when I realized that > > closures were read-only. I like to use closures quite a bit. > > They are not _strictly_ read only, but Python being first and foremost > an OO language, it's usually way simpler to use OO instead of closures > when you start needing such features. I like to leave OO to large-scale architectures and leave functional paradigms for implementation details. Writing an entire class for wrapping an int seems excessive. Especially if that code is limited to a small scope. I agree, though, that there is a time and a place for everything. From brian.curtin at gmail.com Wed Aug 31 15:33:38 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 31 Aug 2011 14:33:38 -0500 Subject: Python Tools for Visual Studio - anyone using it? In-Reply-To: <4E5E8B97.8050402@andros.org.uk> References: <4E5E8B97.8050402@andros.org.uk> Message-ID: On Wed, Aug 31, 2011 at 14:29, Andrew McLean wrote: > I understand that Python Tools for Visual Studio doesn't work with VS > Express, but does work with the (free) VS 2010 Shell. Does anyone know if > you can install VS Express and VS Shell on the same machine? Yes, because the shell and Express work together. -------------- next part -------------- An HTML attachment was scrubbed... URL: From zdoor at xs4all.nl Wed Aug 31 15:37:11 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Wed, 31 Aug 2011 21:37:11 +0200 Subject: Text file with mixed end-of-line terminations Message-ID: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> I have a text file that uses both '\r' and '\r\n' end-of-line terminations. The '\r' terminates the first 25 lines or so, the remainder is termiated with '\r\n' Reading this file like this: ++++++++ for line in open(filename,'r'): line= #Do whatever needs doing... ++++++++ The first line read is actually a string consiting of the first 25 lines. The readline() method does the same thing. Is there a way to make it read one line at a time, regardless of the line termination? By the way, the newlines attribute reports None after reading a few lines. I tried on Linux and Windows. I use the standard binaries as distributed. Thanks in advance, Alex van der Spek From clp2 at rebertia.com Wed Aug 31 15:58:36 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 12:58:36 -0700 Subject: Text file with mixed end-of-line terminations In-Reply-To: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> References: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> Message-ID: On Wed, Aug 31, 2011 at 12:37 PM, Alex van der Spek wrote: > I have a text file that uses both '\r' and '\r\n' end-of-line terminations. > > The '\r' terminates the first 25 lines or so, the remainder is termiated > with '\r\n' > Is there a way to make it read one line at a time, regardless of the line > termination? Universal Newline Support http://www.python.org/dev/peps/pep-0278/ http://docs.python.org/library/functions.html#open (Modes involving "U") Cheers, Chris From nospam at torek.net Wed Aug 31 16:15:44 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 20:15:44 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >In article <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> T. Goodchild asked, in part: >>... One of the things that bugs me is the requirement that all class >>methods have 'self' as their first parameter. In article <4e5e5628$0$29977$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: [Comprehensive reply, noting that these are actually instance methods, and that there are class and static methods as well]: >Python does have class methods, which receive the class, not the instance, >as the first parameter. These are usually written something like this: > >class K(object): > @classmethod > def spam(cls, args): > print cls # always prints "class K", never the instance > >Just like self, the name cls is a convention only. Class methods are usually >used for alternate constructors. > >There are also static methods, which don't receive any special first >argument, plus any other sort of method you can invent, by creating >descriptors... but that's getting into fairly advanced territory. ... [rest snipped] I am not sure whether T. Goodchild was asking any of the above or perhaps also one other possible question: if an instance method is going to receive an automatic first "self" parameter, why require the programmer to write that parameter in the "def"? For instance we *could* have: class K(object): def meth1(arg1, arg2): self.arg1 = arg1 # self is "magically available" self.arg2 = arg2 @classmethod def meth2(arg): use(cls) # cls is "magically available" and so on. This would work fine. It just requires a bit of implicit sneakiness in the compiler: an instance method magically creates a local variable named "self" that binds to the invisible first parameter, and a class method magically creates a local variable named "cls" that binds to the invisible first parameter, and so on. Instead, we have a syntax where you, the programmer, write out the name of the local variable that binds to the first parameter. This means the first parameter is visible. Except, it is only visible at the function definition -- when you have the instance and call the instance or class method: black_knight = K() black_knight.meth1('a', 1) black_knight.meth2(2) the first parameters (black_knight, and black_knight.__class__, respectively) are magic, and invisible. Thus, Python is using the "explicit is better than implicit" rule in the definition, but not at the call site. I have no problem with this. Sometimes I think implicit is better than explicit. In this case, there is no need to distinguish, at the calls to meth1() and meth2(), as to whether they are "class" or "instance" methods. At the *calls* they would just be distractions. At the *definitions*, they are not as "distraction-y" since it is important to know, during the definition, whether you are operating on an instance (meth1) or the class itself (meth2), or for that matter on neither (static methods). One could determine this from the absence or presence of "@classmethod" or "@staticmethod", but the minor redundancy in the "def" statement seems, well, minor. Also, as a bonus, it lets you obfuscate the code by using a name other than "self" or "cls". :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Wed Aug 31 17:01:34 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 21:01:34 GMT Subject: try... except with unknown error types References: <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: In article , Terry Reedy wrote: >I would expect that catching socket.error (or even IOError) should catch >all of those. > >"exception socket.error >A subclass of IOError ... Except that, as Steven D'Aprano almost noted elsethread, it isn't (a subclass of IOError -- the note was that it is not a subclass of EnvironmentError). In 2.x anyway: >>> import socket >>> isinstance(socket.error, IOError) False >>> isinstance(socket.error, EnvironmentError) False >>> (I just catch socket.error directly for this case.) (I have also never been sure whether something is going to raise an IOError or an OSError for various OS-related read or write operation failures -- such as exceeding a resource limit, for instance -- so most places that do I/O operations on OS files, I catch both. Still, it sure would be nice to have a static analysis tool that could answer questions about potential exceptions. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Wed Aug 31 17:30:12 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 21:30:12 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: (I realize this thread is old. I have been away for a few weeks. I read through the whole thread, though, and did not see anyone bring up this one particular point: there is already a linting script that handles this.) >On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert > wrote: >> With surprising regularity, I see program postings (eg. on StackOverflow) >> from inexperienced Python users accidentally re-assigning built-in names. >> >> For example, they'll innocently call some variable, `list', and assign a >> list of items to it. In article Chris Angelico wrote: >It's actually masking, not reassigning. That may make it easier or >harder to resolve the issue. > >If you want a future directive that deals with it, I'd do it the other >way - from __future__ import mask_builtin_warning or something - so >the default remains as it currently is. But this may be a better job >for a linting script. The pylint program already does this: $ cat shado.py "module doc" def func(list): "func doc" return list $ pylint shado.py ************* Module shado W0622: 2:func: Redefining built-in 'list' ... Your code has been rated at 6.67/10 If your shadowing is done on purpose, you can put in a pylint comment directive to suppress the warning. Pylint is the American Express Card of Python coding: "don't leave $HOME without it!" :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ian.g.kelly at gmail.com Wed Aug 31 17:52:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 15:52:48 -0600 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Aug 31, 2011 at 11:12 AM, Prasad, Ramit wrote: > It seems to me that if I add a function to the list of class attributes it will automatically wrap with "self" but adding it to the object directly will not wrap the function as a method. Can somebody explain why? I would have thought that any function added to an object would be a method (unless decorated as a class method). Because things stored on the class are generally viewed as part of the class definition, whereas things stored on an instance are generally viewed as data -- a function stored on an object instance is usually just meant to be a function. Consider the following code: class Sorter(object): def __init__(self, keyfunc): self.keyfunc = keyfunc def sort(self, item_list): item_list.sort(key=self.keyfunc) sorter = Sorter(lambda x: x.id) sorter.sort(some_list_of_items) If adding keyfunc as an attribute to the object wrapped it up as a method, it would break, since the function is not expecting a "self" argument. More technically, because descriptors are only invoked when they're stored on the class. > Hmm, or does the decoration just tell Python not to turn an object's function into a method? I.e. Is the decorator basically just the syntactic sugar for doing the above? If you mean the staticmethod decorator, yes, it pretty much just wraps the function as a "staticmethod" instance to prevent it from being wrapped into an ordinary method when it's accessed. Cheers, Ian From usenet-nospam at seebs.net Wed Aug 31 17:57:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 31 Aug 2011 21:57:06 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: On 2011-08-31, Chris Torek wrote: > (I realize this thread is old. I have been away for a few weeks. > I read through the whole thread, though, and did not see anyone > bring up this one particular point: there is already a linting > script that handles this.) Yes. I've found pylint... A weird mix of "very helpful, thanks" and "oh, come off it". A thread about pylint is where I got my example of the natural Python way to express a parabola: theValueRepresentingTheYAxisLocationOfThePoint = theValueRepresentingTheXAxisLocationOfThe Point * theValueRepresentingTheXAxisLocationOfThe Point I still say that there are times when short names are natural and idiomatic, and much clearer than long names. :P But I do think that, given the basic assumption that pylint is a core tool for vetting code, it is probably adequate for it to provide the warnings. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ian.g.kelly at gmail.com Wed Aug 31 18:16:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 16:16:54 -0600 Subject: Subclassing str object In-Reply-To: References: Message-ID: 2011/8/31 Ya?ar Arabac? : > @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at > all, so I deleted it. My class's addition and multiplication works without > overwriting __add__ and __mul__ because, this class uses unicode's __add__ > and __mul__ than creates a new kelime instance with return value of those > methods in __getattribute__. I think if you try it, you'll find that the result is an ordinary unicode object, not a kelime instance, because __getattribute__ is *not* invoked when Python looks up special method names on the class object. > I didn't get a good grasp on how using basestring there might broke > encoding, could you explain a little bit more, or provide a reading > material? The unicode.encode method takes a unicode object and encodes it into a byte string (a str object). If you then wrap that up in a kelime object, which is a unicode subclass, it has to decode the string back to unicode (using the default ascii codec, since it isn't specified). Thus the result of the call is no longer an encoded byte string as would be expected. If you're lucky, you'll get a UnicodeDecodeError since it's just using the ascii codec. If you're unlucky, it will silently return a result of the wrong type. > So the thing I wonder, when creating new instance in for example > capitalize() method, does str use something like self.__new__() or > unicode.__new__()? Because, in latter case, I could override the __new__ > method on my class, so that every method would create my class's instance, > instead of unicode's No, that doesn't work. From tjreedy at udel.edu Wed Aug 31 18:21:06 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 18:21:06 -0400 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On 8/31/2011 12:45 PM, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. 'Were', in 2.x. The standard 2.x workaround for a single nonlocal is to wrap it in a list. def f(): i = [0] def g(): i[0] += 1 for j in range(5): g() print(i) f() # 5 -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 31 18:40:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 18:40:26 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On 8/31/2011 1:12 PM, Prasad, Ramit wrote: >> def double(obj): return 2*obj.value >> >> class C: >> def __init__(self, val): >> self.value = val >> >> c = C(3) >> C.double = double >> c.doub = double >> # not c.double as that would mask access to C.double in c.double() >> print(double(c), >> C.double(c), c.double(), c.doub(c)) Above is 3.2 code. To be exactly equivalent with 2.x, you need class C(object): > Sorry if I get some of the following terminology wrong, I get a bit > confused on Python terms. I hope the following is still coherent. (Is > there a dictionary of Python terminology?) > Given the above example I get this >>>> print c.double(c) > TypeError: double() takes exactly 1 argument (2 given) Right, because c.double() translates to C.double(c), and c.double(x) translates to C.double(c,x), which is not valid. >>>> print c.doub(c) > 6 > > It seems to me that if I add a function to the list of class > attributes it will automatically wrap with "self" When accessed via an instance of the class, the instance is automagically added as the first argument to be bound to the first parameter. The name 'self' is a convention, not a requirement. > but adding it to > the object directly will not wrap the function as a method. Can > somebody explain why? Someone else did. Not wrapping is normal, wrapping is a special case. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Wed Aug 31 19:31:26 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2011 11:31:26 +1200 Subject: PC locks up with list operations In-Reply-To: <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9c7uihF6feU1@mid.individual.net> Steven D'Aprano wrote: > As far as I know, ulimit ("user limit") won't help. It can limit the amount > of RAM available to a process, but that just makes the process start using > virtual memory more quickly. ulimit -v is supposed to set the maximum amount of virtual memory the process can use. > It can also limit the amount of virtual memory > used by the shell, but not of other processes. That doesn't sound right. Not sure about Linux, but the man page for sh on Darwin says: Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The Python process should also be able to set its own limits using resource.setrlimit(). -- Greg From greg.ewing at canterbury.ac.nz Wed Aug 31 19:37:32 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2011 11:37:32 +1200 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> Message-ID: <9c7utuF8q8U1@mid.individual.net> Ian Kelly wrote: > if sys.version_info < (3,): > getDictValues = dict.itervalues > else: > getDictValues = dict.values > > (which is basically what the OP was doing in the first place). And which he seemed to think didn't work for some reason, but it seems fine as far as I can tell: Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> gv = dict.itervalues >>> d = {1:'a', 2:'b'} >>> gv(d) % python3.1 Python 3.1.2 (r312:79147, Mar 2 2011, 17:43:12) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> gv = dict.values >>> d = {1:'a', 2:'b'} >>> gv(d) dict_values(['a', 'b']) -- Greg From steve+comp.lang.python at pearwood.info Wed Aug 31 20:11:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:11:57 +1000 Subject: fun with nested loops References: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> Message-ID: <4e5ecdcf$0$29967$c3e8da3$5496439d@news.astraweb.com> Daniel wrote: > And I have to keep the code simple for non CS people to run > the actual experiment. Do you think the software in the Apple iPod is "simple"? Or Microsoft Windows? No. You need to keep the *interface* simple. The internal details can be as complicated as they are needed to be. Same applies to your data acquisition application. Unless you expect these non-CS people to be hacking the source code, they only interact with the interface, not the internals. Earlier, back in your initial post, you said: "I don't see any way to reduce these nested loops logically, they describe pretty well what the software has to do. This is a data acquisition application, so on ever line there is a lot of IO that might fail or make subsequent steps useless or require a retry." Do you think you're the first person to have written a data acquisition application in Python? Almost certainly you can simplify the structure of the code by splitting it into functions appropriately, instead of the spaghetti code you have (apparently) written with jumps all over the place. To take the most obvious, simple example: any time you have a loop that you might want to redo, the right solution is to put the loop inside a function, and then "redo the loop" becomes "call the function again". I suppose that, just possibly, your application really would benefit from named labels to jump to. But if so, you've stumbled across something rarer than iridium. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:18:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:18:34 +1000 Subject: fun with nested loops References: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> Message-ID: <4e5ecf5c$0$29994$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > Ah well, was worth a try. Raising exceptions smells wrong for this, > but peppering your code with sentinel checks isn't much better. I > don't really know what would be a good solution to this... except > maybe this, which was proposed a few years ago and which I'd never > heard of until Google showed it to me just now: > http://entrian.com/goto/ You're a wicked, wicked man. :) -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:48:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:48:46 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Chris Torek wrote: >>There are also static methods, which don't receive any special first >>argument, plus any other sort of method you can invent, by creating >>descriptors... but that's getting into fairly advanced territory. ... > [rest snipped] > > I am not sure whether T. Goodchild was asking any of the above or > perhaps also one other possible question: if an instance method > is going to receive an automatic first "self" parameter, why require > the programmer to write that parameter in the "def"? Er, yes, just like I suggested in my opening paragraph, and as I answered following the bit you marked as snipped :) > For instance > we *could* have: > > class K(object): > def meth1(arg1, arg2): > self.arg1 = arg1 # self is "magically available" > self.arg2 = arg2 > > @classmethod > def meth2(arg): > use(cls) # cls is "magically available" > > and so on. This would work fine. It just requires a bit of implicit > sneakiness in the compiler: an instance method magically creates > a local variable named "self" that binds to the invisible first > parameter, and a class method magically creates a local variable > named "cls" that binds to the invisible first parameter, and so > on. It would need more than "a bit", because methods are just wrappers around functions. One way would be for Python to give that up, and require methods to be special built-in types like functions. That adds complexity to the compiler, and (very likely) would decrease the level of dynamism possible. Another way would be for the compiler to perform darkest black magic to determine whether the function was being called from inside a method or not. That would be complicated and fragile. [...] > At the *definitions*, they are not as "distraction-y" since it is > important to know, during the definition, whether you are operating > on an instance (meth1) or the class itself (meth2), or for that > matter on neither (static methods). One could determine this from > the absence or presence of "@classmethod" or "@staticmethod" classmethod and staticmethod are functions, not declarations. You can't assume that @classmethod is the only way to get a class method: the metaclass could do it, or you could inject one in from the outside. You can dynamically change the state of a method from instance method to class method and back again at run-time. Python classes have a lot of dynamism made possible by the fact that methods are just wrappers around functions with an explicitly declared "self". That dynamism is rarely used, but not *that* rarely, and is very useful when used. Implicit self would likely negate all that. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:50:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:50:54 +1000 Subject: fun with nested loops References: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> <4e5ecdcf$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5ed6ef$0$29981$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: [...] > Do you think you're the first person to have written a data acquisition > application in Python? Hmmm, on re-reading that it comes across as much harsher than it sounded in my head. Sorry about that Daniel. -- Steven From python.list at tim.thechases.com Wed Aug 31 20:53:48 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 31 Aug 2011 19:53:48 -0500 Subject: PC locks up with list operations In-Reply-To: <9c7uihF6feU1@mid.individual.net> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> <9c7uihF6feU1@mid.individual.net> Message-ID: <4E5ED79C.5070701@tim.thechases.com> On 08/31/11 18:31, Gregory Ewing wrote: > The Python process should also be able to set its own > limits using resource.setrlimit(). A new corner of stdlib that I've never poked at. Thanks for the suggestion. Disappointed though that it doesn't seem to have docstrings on the functions, so I had to wade back out to the online docs to probe at it. Granted, after the fact, they were pretty obvious, but it would be nice if "help(resource.getrlimit)" gave me a hint as to what that one expected parameter should have been. -tim import resource as r token = "RLIMIT_" for item in dir(r): if item.startswith(token): print "%s:" % item[len(token):], print "%s hard/%s soft" % r.getrlimit(getattr(r, item)) From jehugaleahsa at gmail.com Wed Aug 31 21:28:09 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 18:28:09 -0700 (PDT) Subject: Handling 2.7 and 3.0 Versions of Dict References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> <9c7utuF8q8U1@mid.individual.net> Message-ID: <93c5378e-03f8-4764-96e8-2c3e8568baec@z8g2000yqe.googlegroups.com> On Aug 31, 7:37?pm, Gregory Ewing wrote: > Ian Kelly wrote: > > if sys.version_info < (3,): > > ? ? getDictValues = dict.itervalues > > else: > > ? ? getDictValues = dict.values > > > (which is basically what the OP was doing in the first place). > > And which he seemed to think didn't work for some > reason, but it seems fine as far as I can tell: > > Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > ?>>> gv = dict.itervalues > ?>>> d = {1:'a', 2:'b'} > ?>>> gv(d) > > > % python3.1 > Python 3.1.2 (r312:79147, Mar ?2 2011, 17:43:12) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > ?>>> gv = dict.values > ?>>> d = {1:'a', 2:'b'} > ?>>> gv(d) > dict_values(['a', 'b']) > > -- > Greg My problem was that I didn't understand the scoping rules. It is still strange to me that the getValues variable is still in scope outside the if/else branches. From mrinalini at edss.co.in Wed Aug 31 21:46:54 2011 From: mrinalini at edss.co.in (mrinalini at edss.co.in) Date: Thu, 01 Sep 2011 07:16:54 +0530 Subject: Help required accessing dictionary Message-ID: <54e7c93d35c11cdf72cee56a8a1c5abc@edss.co.in> Hi I need to access the dictionary of the script that I am running through my vc++ application by embedding python. I am linking to python dynamically. I want to obtain the dictionary of the script and access the variables declared in the script. However, with the PyObject * that I get from the dictionary, I am not able to find the type of the object. The reason being that GetProcAddress to PyInt_Check returns a NULL. The same thing with PyFloat_Check and so on. I think this is because they are macros and not exported functions. What can be done to be able to perform these checks without statically linking to the pyhon lib ? Thanks, Abhaya From rosuav at gmail.com Wed Aug 31 21:47:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 11:47:28 +1000 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano wrote: > Python classes have a lot of dynamism made possible by the fact that methods > are just wrappers around functions with an explicitly declared "self". That > dynamism is rarely used, but not *that* rarely, and is very useful when > used. Implicit self would likely negate all that. > Hmm. Got any examples sitting around? I'm curious as to what you can do with this. I'm like a kid with a new chemistry set - "what happens if I mix a little of everything together?"... ChrisA From ericsnowcurrently at gmail.com Wed Aug 31 22:07:42 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 31 Aug 2011 20:07:42 -0600 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 31, 2011 at 7:47 PM, Chris Angelico wrote: > On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano > wrote: >> Python classes have a lot of dynamism made possible by the fact that methods >> are just wrappers around functions with an explicitly declared "self". That >> dynamism is rarely used, but not *that* rarely, and is very useful when >> used. Implicit self would likely negate all that. >> > > Hmm. Got any examples sitting around? I'm curious as to what you can > do with this. I'm like a kid with a new chemistry set - "what happens > if I mix a little of everything together?"... First thing that comes to mind is calling a base class's implementation of a method: class X(Y): def __init__(self, value): Y.__init__(self) self.value = value -eric > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From nospam at torek.net Wed Aug 31 22:20:56 2011 From: nospam at torek.net (Chris Torek) Date: 1 Sep 2011 02:20:56 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e5ed670$0$29981$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >Er, yes, just like I suggested in my opening paragraph, and as I answered >following the bit you marked as snipped :) Oops, so you did (went back and re-read it). Must have gotten interrupted and lost track. :-) >> [A different hack would] requires a bit of implicit >> sneakiness in the compiler: an instance method magically creates >> a local variable named "self" that binds to the invisible first >> parameter, and a class method magically creates a local variable >> named "cls" that binds to the invisible first parameter, and so >> on. >It would need more than "a bit", because methods are just wrappers >around functions. Well, depends on how the hack would be done. :-) For instance, the @decorator might turn on something that "undoes" or "replaces" the "self" parameter. That is, with ordinary class functions and methods: class HackyNotQuitePythonVersion: def ordinary(arg): self.arg = arg would compile to (approximately): class PythonVersion: def __mrap(self, *args, **kwargs): def ordinary(arg): self.arg = arg ordinary(*args, **kwargs) ordinary = __mrap (add the usual other manipulations to suit here, i.e., all the stuff for making introspection work right, i.e., @functools.wraps). @staticmethod would suppress the wrapper entirely, while @classmethod would change it to one that binds the "cls" argument. (Any function without some appropriate @whatever gets the Method Wrapper __mrap. @staticmethod tells the class builder not to add any wrapper, and @classmethod tells it to add the Class Wrapper __crap. [The name tells you what I think of the above code. :-) ]) (Note subtle ground for bugs here: if you then actually define a "self" parameter, it shadows the outer-scope one from the wrapper. So while I am not even proposing that anyone should do this in the first place, it has more downsides than mere implementation complexity.) >Another way would be for the compiler to perform darkest black magic to >determine whether the function was being called from inside a method or >not. That would be complicated and fragile. Yes, even worse than my outlined implementation above, I think. >classmethod and staticmethod are functions, not declarations. They are decorator functions, but to someone *reading the code* they are also "declarations" of sort. This is all I meant: they tell the (human) reader/programmer which "secret arguments" to expect. >You can't assume that @classmethod is the only way to get a >class method: the metaclass could do it, or you could inject >one in from the outside. Yes, but that would all still work, as in this not-quite-Python (worsened-Python) language, whoever writes those metaclasses and other decorators would continue to do whatever icky stuff was required (e.g., __mrap and __crap above). It would mean yet more things for people to know about, but then, metaclasses and decorators *always* mean that: @hmm def spam(): return magic Is "magic" something supplied by the decorator? You have to look at the decorator to find out, as the rather horrid example I have attached shows. (Note: I am doing all this is python 2.x on the laptop. Using global, in @hmm, is evil, but it works. I did not bother trying to write a metaclass that inserts __mrap, etc., but I believe it can be done.) >Python classes have a lot of dynamism made possible by the fact that methods >are just wrappers around functions with an explicitly declared "self". That >dynamism is rarely used, but not *that* rarely, and is very useful when >used. Implicit self would likely negate all that. I do not believe it would *negate* it, just *complicate* it. But that is not a good thing either. :-) ----- horrible example / test code below import functools def hmm(func): @functools.wraps(func) def wrapper(*args, **kwargs): global magic, rlevel try: save = magic, rlevel restore = True rlevel += 1 except NameError: restore = False rlevel = 1 magic = func.__name__ + " and eggs" ret = func(*args, **kwargs) if restore: magic, rlevel = save else: del magic, rlevel return ret return wrapper @hmm def ham(): if rlevel < 2: print spam() return magic @hmm def spam(): return magic print ham() try: print magic except NameError: print 'name "magic" is not available here, as desired' try: print rlevel except NameError: print 'name "rlevel" is not available here, as desired' class X(object): def __mrap(self, *args, **kwargs): def xset(arg): self.arg = arg xset(*args, **kwargs) xset = __mrap def __mrap(self, *args, **kwargs): def show(): print self.arg show(*args, **kwargs) show = __mrap x = X() x.xset('value') x.show() -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nemjain2 at gmail.com Wed Aug 31 23:16:07 2011 From: nemjain2 at gmail.com (babbu Pehlwan) Date: Wed, 31 Aug 2011 20:16:07 -0700 (PDT) Subject: How to daemonize a HTTPServer Message-ID: <594e0376-3a1d-4430-bf47-d1e0f856c4dd@f31g2000prj.googlegroups.com> I have written a http server using BaseHTTPServer module. Now I want to instantiate it through another python script. The issue here is after instantiate the control doesn't come back till the server is running. Please suggest. From 1248283536 at qq.com Mon Aug 1 00:20:13 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Mon, 1 Aug 2011 12:20:13 +0800 Subject: how to solve it? Message-ID: from matplotlib.matlab import * Traceback (most recent call last): File "", line 1, in ImportError: No module named matlab -------------- next part -------------- An HTML attachment was scrubbed... URL: From ghodmode at ghodmode.com Mon Aug 1 00:56:38 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Mon, 1 Aug 2011 12:56:38 +0800 Subject: Spam Message-ID: I've noticed that python-list gets significantly more spam than the other lists I subscribe to. There's an example below. I'm wondering how the list is managed. Can anyone post, or only members? I've picked the email addresses of the list managers out of the list info page, but I wonder if you guys have enough time to skim the list and boot offending members. If not, is there someone who is active on the list that you could delegate administration privileges to? Maybe someone who has been an active member for a long time? I'm willing, but probably not qualified. I've been lurking on the list for a while, but I don't contribute much because I'm not very proficient with Python. Thank you. -- Ghodmode http://www.ghodmode.com/blog ---------- Forwarded message ---------- From: Ashraf Ali Date: Mon, Aug 1, 2011 at 10:54 AM Subject: Hello My Sweet Friends. To: python-list at python.org Hello Friends. How are you all? Please Visit the following link if you know about Pakistan and what happening in the world. http://bollywoodactresseshotpictures.blogspot.com/ http://jobopportunitiesinpakistan.blogspot.com/ http://hotfemaletennisplayershotphotos.blogspot.com/ http://watchonlineindianmovies.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list From tkjthingone at gmail.com Mon Aug 1 01:04:10 2011 From: tkjthingone at gmail.com (Ira Gray) Date: Sun, 31 Jul 2011 22:04:10 -0700 Subject: Quick question about threads and interpreters. Message-ID: Lets say I have a program that is running a python interpreter in the main thread. I come along, write a .DLL and throw it into the program. My .dll has its own thread (right?), separate from the main thread, and then makes a pyrun_simplestring call to the pythonxx.dll. The pyrun_simplestring call attempts to make contact with a function in the original python program. In short, I'm attempting to leverage existing functionality in the original python program from my .DLL. I'm sure that sounds confusing, so maybe: PythonInterpreter_MainThread is running some SourceCode, MyDLL_PyRun_SimpleString_OtherThread makes call(?) to the same SourceCode. Now, my question is: What happens? Is another python interpreter instance created in my .dll thread to handle that call? is my call 'separate' from the main thread interpreter? I'm hoping someone can point me towards some material to better understand what might happen if I did what I outlined above. It's a small school project (not homework, just a "hey, remember when I asked you about blahblah, well I got it working!") and I'd appreciate any guidance I could get into the dark arts of multiple threads and how they relate to python interpreters, and if multiple python interpreters are created (one for each thread) how making calls to the same code works. Thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 1 01:50:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 06:50:16 +0100 Subject: Spam In-Reply-To: References: Message-ID: On Mon, Aug 1, 2011 at 5:56 AM, Ghodmode wrote: > I'm willing, but probably not qualified. ?I've been lurking on the > list for a while, but I don't contribute much because I'm not very > proficient with Python. > I don't see Python proficiency as a prerequisite for recognizing spammers :) If you are willing to take on the job, I would support your application for the power to do it. Chris Angelico From rosuav at gmail.com Mon Aug 1 01:57:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 06:57:41 +0100 Subject: Quick question about threads and interpreters. In-Reply-To: References: Message-ID: On Mon, Aug 1, 2011 at 6:04 AM, Ira Gray wrote: > I come along, write a .DLL and throw it into the program. My .dll has its > own thread (right?), Not unless you actually create one. A DLL is simply a puddle of code; the application calls your code, you do whatever you do, you return. At no time will this start another thread, unless you explicitly do so. I think the easiest way to do what you're talking about is to keep it all on the same thread, and then call back into Python. Use the same global and local dictionaries, and then the Python namespace will be common across both your original code and the code your DLL is invoking - which will allow you to call that "existing functionality" you referred to. You will have to be careful to ensure that your DLL calls into the exact same Python library that the main application is. This might be a bit tricky, if you're not 100% sure of where your DLL is going to be called from. It might be easier and safer to have your parent program actually provide a function pointer to the DLL, which the DLL can then use to call on Python; that way, there's no direct linkage from your DLL to the Python library. Chris Angelico From clp2 at rebertia.com Mon Aug 1 02:05:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jul 2011 23:05:04 -0700 Subject: Spam In-Reply-To: References: Message-ID: On Sun, Jul 31, 2011 at 9:56 PM, Ghodmode wrote: > I've noticed that python-list gets significantly more spam than the > other lists I subscribe to. ?There's an example below. > > I'm wondering how the list is managed. ?Can anyone post, or only > members? Since we're gatewayed to USENET's comp.lang.python anyway, I'd strongly suspect the former. So unfortunately, I doubt your idea could be implemented short of making the list moderated (very unlikely to happen due to the level of activity) or disabling the gateway (again unlikely due to historical momentum and USENET dinosaurs). I understand that there are spam filters in place though, so it might be worth asking that they be tweaked. (e.g. I doubt there are many legit posts involving Bollywood.) >?I've picked the email addresses of the list managers out of > the list info page, but I wonder if you guys have enough time to skim > the list and boot offending members. ?If not, is there someone who is > active on the list that you could delegate administration privileges > to? ?Maybe someone who has been an active member for a long time? > > I'm willing, but probably not qualified. ?I've been lurking on the > list for a while, but I don't contribute much because I'm not very > proficient with Python. > > Thank you. > > -- > Ghodmode > http://www.ghodmode.com/blog > > > ---------- Forwarded message ---------- > From: Ashraf Ali And off to abuse at gmail.com I dash. Fsck you Mr. Ali. (Yeah, not their real name, I know. Still worth reporting such accounts.) Cheers, Chris > Date: Mon, Aug 1, 2011 at 10:54 AM > Subject: Hello My Sweet Friends. > To: python-list at python.org > > > Hello Friends. > How are you all? > Please Visit the following link if you know about Pakistan and what > happening in the world. P.S. Please redact the actual spam links next time so that they don't get further Google juice. From greg.ewing at canterbury.ac.nz Mon Aug 1 02:25:35 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:25:35 +1200 Subject: What's in a name? In-Reply-To: References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> Message-ID: <99mv71F594U1@mid.individual.net> Andrew Berg wrote: > Well of course. All the good names are taken. :P > I even came up with cavelib and it was taken ( > http://www.mechdyne.com/cavelib.aspx ). A couple of ideas that don't seem to turn up anything software-related: Flummux Flavius -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 1 02:29:12 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:29:12 +1200 Subject: Deeply nested dictionaries - should I look into a database or am I just doing it wrong? In-Reply-To: References: Message-ID: <99mvdqF6nqU1@mid.individual.net> Andrew Berg wrote: > I have a method that writes the data to disk, but at this point, I don't > see any problems with just pickling the class instance. Just keep in mind that if you're not careful, pickles can end up being tied more closely that you would like to various internal details of your program, such as the precise names of the classes involved and which modules they live in. -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 1 02:34:47 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 01 Aug 2011 18:34:47 +1200 Subject: Spam In-Reply-To: References: Message-ID: <99mvoaF8q8U1@mid.individual.net> Chris Rebert wrote: > On Sun, Jul 31, 2011 at 9:56 PM, Ghodmode wrote: > >>I'm wondering how the list is managed. Can anyone post, or only >>members? > > Since we're gatewayed to USENET's comp.lang.python anyway, I'd > strongly suspect the former. You may get a better experience by reading the usenet group instead, and doing it through a good news site. I'm using news.individual.de, and seeing near enough to zero spam on comp.lang.python, so they must be doing a good job of filtering. -- Greg From steve+comp.lang.python at pearwood.info Mon Aug 1 04:11:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 18:11:16 +1000 Subject: Spam References: Message-ID: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Ghodmode wrote: > I've noticed that python-list gets significantly more spam than the > other lists I subscribe to. There's an example below. Thanks for that! I missed it the first time, so it is very helpful for you to forward it. It's especially helpful that you included all the spammer's URLs, as that will help improve their Google page ranks. I'm sure the spammer will thank you for your assistance. -- Steven From tlikonen at iki.fi Mon Aug 1 04:19:49 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Mon, 01 Aug 2011 11:19:49 +0300 Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877h6xzgpm.fsf@mithlond.arda> * 2011-07-30T10:57:29+10:00 * Steven D'Aprano wrote: > Teemu Likonen wrote: >> Pathnames and the separator for pathname components should be >> abstracted away, to a pathname object. > > Been there, done that, floundered on the inability of people to work > out the details. > > http://www.python.org/dev/peps/pep-0355/ I'm very much a Lisp person and obviously got the idea of pathname objects from Common Lisp. Lazily I'm also learning Python too but at the moment I can't comment on the details of that PEP. Yet, generally I think that's the way to improve pathnames, not the "rantinrick's". From rosuav at gmail.com Mon Aug 1 04:41:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 09:41:11 +0100 Subject: Question In-Reply-To: References: Message-ID: On Sun, Jul 31, 2011 at 12:38 AM, Camilo Andres Roca Duarte wrote: > $ python myfunctions.py > SyntaxError: invalid syntax > This is an error from Python, so it probably means something is wrong in your .py file. Check the contents of the file with 'cat myfunctions.py'. Is the first line the one that starts 'def is_divisible', and is the last line 'doctest.testmod()'? If not, you might have picked up some extra junk that Python can't understand. You say it works in a separate window. Does this mean inside IDLE? It's possible you have two versions of Python installed somehow. What does this display: $ python -V If it doesn't say Python 2.7.2, then you already had an older Python. All the best! Chris Angelico From bahamutzero8825 at gmail.com Mon Aug 1 04:54:06 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 01 Aug 2011 03:54:06 -0500 Subject: Question In-Reply-To: References: Message-ID: <4E3669AE.4070301@gmail.com> On 2011.07.30 06:38 PM, Camilo Andres Roca Duarte wrote: > $ python myfunctions.py > SyntaxError: invalid syntax It helps to include the full traceback. If we don't know the code that caused the error, it's pretty hard to say what went wrong, especially with an exception as broad as SyntaxError. It's easier to ignore extra information than it is to extrapolate missing information. Also, please use more specific subject lines. That way, others know whether it's worth their time to read the message. Some even ignore all messages with generic subject lines completely. It also makes your message easier to find if you ever need to search for it later. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From steve+comp.lang.python at pearwood.info Mon Aug 1 04:55:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 18:55:32 +1000 Subject: Question References: Message-ID: <4e366a05$0$29968$c3e8da3$5496439d@news.astraweb.com> Camilo Andres Roca Duarte wrote: > Hello > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > Python version. The problem is that anytime I try to run a script from the > Python Shell it returns an error message. I am new using python so I am > not sure what to do since what I'm typing in the shell is in a > BegginersTutorial. > > $ python myfunctions.py > SyntaxError: invalid syntax I would be very surprised if that is the real error message you get. I would expect something like this: [steve at sylar ~]$ python test.py File "test.py", line 1 def func: ^ SyntaxError: invalid syntax Note that the error shows the line that is bad, and puts an up-arrow ^ directly under where it goes bad. Please COPY and PASTE the FULL error. Do not re-type it from memory, summarise it, put it in your own words, or otherwise change it in any way. -- Steven From chenjii at gmail.com Mon Aug 1 05:11:16 2011 From: chenjii at gmail.com (jc) Date: Mon, 1 Aug 2011 02:11:16 -0700 (PDT) Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR Message-ID: # Get Fibonacci Value # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) # # n = 900 is OK # n = 1000 is ERROR , Why # # What Wrong? # cache = [] def fibo( n ): try: if cache[n] != -1: return cache[n] else: if 0 == n: r = 0 elif 1 == n: r = 1 else: r = fibo(n-1) + fibo(n-2) cache[n] = r return r except: print "EXCEPT: " + str(n) if __name__ == '__main__': # This n = 900 is OK # But n = 1000 is ERROR n = 900 cache = range(0 , n + 1 , 1) for i in cache: cache[i] = -1 print "Fibo(" + str(n) + ") = " + str(fibo(n)) print "\n" print "\n" From __peter__ at web.de Mon Aug 1 05:14:22 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Aug 2011 11:14:22 +0200 Subject: Question References: Message-ID: Camilo Andres Roca Duarte wrote: > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > Python version. The problem is that anytime I try to run a script from the > Python Shell it returns an error message. I am new using python so I am > not sure what to do since what I'm typing in the shell is in a > BegginersTutorial. > > $ python myfunctions.py > SyntaxError: invalid syntax You shouldn't type the line $ python myfunctions.py into Idle's "Python Shell" window. The $ is the prompt of Unix shells like bash. You have to open such a shell and type the command there, without the leading $. If you are on Windows you have to open a "DOS Prompt" or "Command Window". You can then set the working directory with cd some\path Of course you have to replace some\path with the path where the file myfunctions.py is actually stored. Finally you can invoke your script with python myfunctions.py From steve+comp.lang.python at pearwood.info Mon Aug 1 05:19:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 01 Aug 2011 19:19:30 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: <4e366fa7$0$29971$c3e8da3$5496439d@news.astraweb.com> jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why How should we know? Please tell us what the error is, don't expect us to guess. [...] > if __name__ == '__main__': > # This n = 900 is OK > # But n = 1000 is ERROR Hint: how big is the cache? If the cache has 900 items, what makes you think you can look up the 1000th item? > n = 900 > cache = range(0 , n + 1 , 1) > for i in cache: > cache[i] = -1 This is a waste of time. Better to write: cache = [-1]*900 Even better is to use a dict instead of a list. -- Steven From gennad.zlobin at gmail.com Mon Aug 1 05:23:20 2011 From: gennad.zlobin at gmail.com (Gennadiy Zlobin) Date: Mon, 1 Aug 2011 16:23:20 +0700 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: The maximum depth of the Python interpreter stack is limited to 1000 calls by default. You can get it by import sys; sys.getrecursionlimit() and set a new value to sys.setrecursionlimit(new_value) - Gennadiy On Mon, Aug 1, 2011 at 4:11 PM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # > > cache = [] > > def fibo( n ): > > try: > if cache[n] != -1: > return cache[n] > else: > if 0 == n: > r = 0 > elif 1 == n: > r = 1 > else: > r = fibo(n-1) + fibo(n-2) > > cache[n] = r > return r > except: > print "EXCEPT: " + str(n) > > > if __name__ == '__main__': > > # This n = 900 is OK > # But n = 1000 is ERROR > > n = 900 > cache = range(0 , n + 1 , 1) > > for i in cache: > cache[i] = -1 > > print "Fibo(" + str(n) + ") = " + str(fibo(n)) > print "\n" > print "\n" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anddimario at gmail.com Mon Aug 1 05:56:04 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Mon, 1 Aug 2011 11:56:04 +0200 Subject: Notifications when process is killed Message-ID: Hi, i've created a twisted server application and i want that the server send me a message when someone stops or kills the process. I want to override reactor.stop(), but do this way send me message when the process is stopped by a system kill? Could you suggest me if there's a way to do this? Thanks, regards. -- Andrea Di Mario From ulrich.eckhardt at dominolaser.com Mon Aug 1 06:50:24 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 01 Aug 2011 12:50:24 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e366fa7$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4icig8-tln.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > jc wrote: >> n = 900 >> cache = range(0 , n + 1 , 1) >> for i in cache: >> cache[i] = -1 > > This is a waste of time. Better to write: > > cache = [-1]*900 Since he's computing the Fibonacci number of n, and n is 900, he needs cache = [-1] * (n + 1) ;^) > Even better is to use a dict instead of a list. Simpler, yes. Better for a beginner, of course. Better, maybe not. The use case here will cause the cache to be used from index 1 upwards, so using an array to store the element is faster and smaller. I'd consider resizing the cache dynamically though. Cheers! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From t at jollybox.de Mon Aug 1 06:52:03 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 01 Aug 2011 12:52:03 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: <4E368553.6080406@jollybox.de> On 01/08/11 11:56, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > Could you suggest me if there's a way to do this? > > Thanks, regards. > I don't know anything about Twisted, but you'd usually want to install a signal handler for SIGTERM, and perhaps SIGINT (unless you handle KeyboardInterrupt exceptions) and SIGHUP (for when the controlling terminal is lost, which usually causes a process to quit) I'm assuming you're using a UNIX-like system - Thomas From michael.poeltl at univie.ac.at Mon Aug 1 06:59:07 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 1 Aug 2011 12:59:07 +0200 Subject: how to solve it? In-Reply-To: References: Message-ID: <20110801105907.GA2101@horus.cms.at> * ???? <1248283536 at qq.com> [2011-08-01 06:22]: > from matplotlib.matlab import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named matlab does this work? >>> import matplotlib next check 'gallery' at http://matplotlib.sourceforge.net/index.html choose the graph (click it) you need, and there you can browse the source-code (python-code) this is maybe the best starting-point, I guess. cheers Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From davea at ieee.org Mon Aug 1 07:15:20 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 01 Aug 2011 07:15:20 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: <4E368AC8.3030906@ieee.org> On 01/-10/-28163 02:59 PM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # > > cache = [] > > def fibo( n ): > > try: > if cache[n] != -1: > return cache[n] > else: > if 0 == n: > r = 0 > elif 1 == n: > r = 1 > else: > r = fibo(n-1) + fibo(n-2) > > cache[n] = r > return r > except: > print "EXCEPT: " + str(n) > > > if __name__ == '__main__': > > # This n = 900 is OK > # But n = 1000 is ERROR > > n = 900 > cache = range(0 , n + 1 , 1) > > for i in cache: > cache[i] = -1 > > print "Fibo(" + str(n) + ") = " + str(fibo(n)) > print "\n" > print "\n" > > It'd be really nice if you bothered to state what "ERROR" you get. Show the traceback or since the output is pretty long, at least show part of it. copy/paste it from the shell. In any case, it's clearly a recursion problem, due to the default limit of the CPython stack (1000). This succeeds for 999, and gets a stack overflow at 1000. A solution that lets you go much higher would be to insert before the lines: if cache[n] != -1: return cache[n] The following: if n > MAXDEPTH: if n%MAXDEPTH: for i in xrange(0, n, 200): fibo(i) #calc value just to prefill the cache where an easy value for MAXDEPTH is 200. Think about what this does, and you should see why it'll help. I tried it for 100,000 and it doesn't blow up. I didn't however check any of the other logic. DaveA From grzegorz.tezycki at gmail.com Mon Aug 1 07:22:36 2011 From: grzegorz.tezycki at gmail.com (k2) Date: Mon, 1 Aug 2011 04:22:36 -0700 (PDT) Subject: How add/change password for RSA priv key using PyCrypto Message-ID: Hi, maybe somebody be able to help me. I'm using PyCrypto to generate a pair of RSA keys. The public key and private key. I try to add a password to the private key, and I do not know how to do it. This is a piece of my code. #encoding:utf-8 from Crypto.PublicKey import RSA pass_alice='ala' private_alice_key = RSA.generate(1024) public_alice_key = private_alice_key.publickey() str_priv = private_alice_key.exportKey() str_pub = public_alice_key.exportKey() print str_priv print str_pub # HOW ADD OR CHANGE PASSWORD FOR private_alice_key From msarro at gmail.com Mon Aug 1 07:42:13 2011 From: msarro at gmail.com (Matty Sarro) Date: Mon, 1 Aug 2011 07:42:13 -0400 Subject: Spam In-Reply-To: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: I agree, the Bollywood spam sucks. There's not even any boobies! On Aug 1, 2011 4:16 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Ghodmode wrote: > >> I've noticed that python-list gets significantly more spam than the >> other lists I subscribe to. There's an example below. > > Thanks for that! I missed it the first time, so it is very helpful for you > to forward it. It's especially helpful that you included all the spammer's > URLs, as that will help improve their Google page ranks. I'm sure the > spammer will thank you for your assistance. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From markferg at gmail.com Mon Aug 1 08:00:26 2011 From: markferg at gmail.com (mark ferguson) Date: Mon, 1 Aug 2011 13:00:26 +0100 Subject: Question In-Reply-To: References: Message-ID: Peter - well caught! I've been wondering how that line could have arisen when running a script through the interpreter from the command line! Pasting it into Idle gives exactly that output. It was the leading $ that threw me, I took it as the shell prompt. I think that Camilo was actually typing it into Idle as well. On 1 August 2011 10:14, Peter Otten <__peter__ at web.de> wrote: > Camilo Andres Roca Duarte wrote: > > > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > > Python version. The problem is that anytime I try to run a script from > the > > Python Shell it returns an error message. I am new using python so I am > > not sure what to do since what I'm typing in the shell is in a > > BegginersTutorial. > > > > $ python myfunctions.py > > SyntaxError: invalid syntax > > You shouldn't type the line > > $ python myfunctions.py > > into Idle's "Python Shell" window. The $ is the prompt of Unix shells like > bash. You have to open such a shell and type the command there, without the > leading $. > > If you are on Windows you have to open a "DOS Prompt" or "Command Window". > You can then set the working directory with > > cd some\path > > Of course you have to replace some\path with the path where the file > myfunctions.py is actually stored. Finally you can invoke your script with > > python myfunctions.py > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.poeltl at univie.ac.at Mon Aug 1 08:51:16 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 1 Aug 2011 14:51:16 +0200 Subject: how to solve it? In-Reply-To: References: Message-ID: <20110801125116.GD2101@horus.cms.at> * ???? <1248283536 at qq.com> [2011-08-01 06:22]: > from matplotlib.matlab import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named matlab is this what you were looking for? >>> from matplotlib.pylab import * cheers Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From thorsten at thorstenkampe.de Mon Aug 1 08:54:36 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Mon, 1 Aug 2011 14:54:36 +0200 Subject: [ANN] IPython 0.11 is officially out References: Message-ID: * Fernando Perez (Sun, 31 Jul 2011 17:26:50 +0000 (UTC)) > on behalf of the IPython development team, I'm thrilled to announce, > after more than two years of development work, the official release of > IPython 0.11. > > This release brings a long list of improvements and new features > (along with hopefully few new bugs). We have completely refactored > IPython, making it a much more friendly project to participate in by > having better separated and organized internals. We hope you will not > only use the new tools and libraries, but also join us with new ideas > and development. > [...] > Here is a quick listing of the major new features: > [...] > - New configuration system > [...] And the best thing is: IPython 0.11 is not compatible to 0.10 so if you had your own customized ipythonrc you can start from scratch. The documentation[1] says "If you are upgrading to version 0.11 of IPython, you will need to migrate your old ipythonrc or ipy_user_conf.py configuration files to the new system. Read on for information on how to do this." Unfortunately there is no more mentioning of "migration", so the developers' approach seems to be: "read all about the new configuration system and see if you can somehow duplicate your old ipythonrc settings. Good luck!". By the way: "configuration object", "applications", "configurables", "singletons", ... Am I really supposed to understand all this? Thorsten [1] http://ipython.org/ipython-doc/stable/config/overview.html From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Mon Aug 1 10:00:57 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Mon, 01 Aug 2011 10:00:57 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: On 08/01/2011 05:11 AM, jc wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # I have fixed the problem for you: def fibo(n): phi = (1+5**.5)/2; iphi = 1-phi; return (phi**n - iphi**n) / (5**.5) -- Bill From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Aug 1 10:25:43 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 01 Aug 2011 16:25:43 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR In-Reply-To: References: Message-ID: Am 01.08.2011 11:11 schrieb jc: > except: > print "EXCEPT: " + str(n) If you catch all exceptions here, it is clear that you only get this. Why don't you do except Exception, e: print "EXCEPT: " + str(n), e ? Then you could at least ask "why do I get a unsupported operand type(s) for +: 'NoneType' and 'long'"? Well, these are the consequences of returning nothing (aka None) in the case of earlier errors. The first of these errors comes from EXCEPT: 4 maximum recursion depth exceeded so - you simply go too deep. If you "pre-calculate" the stuff before, calling fibo(n/2) before the line with 'print "Fibo(" + str(n) + ") = " + str(fibo(n))', it succeeds. Thomas From warriorlance at gmail.com Mon Aug 1 11:05:27 2011 From: warriorlance at gmail.com (Tong Zhang) Date: Mon, 1 Aug 2011 23:05:27 +0800 Subject: python reading file memory cost Message-ID: <000f01cc505c$74e01e80$5ea05b80$@com> Hello, everyone! I am trying to read a little big txt file (~1 GB) by python2.7, what I want to do is to read these data into a array, meanwhile, I monitor the memory cost, I found that it cost more than 6 GB RAM! So I have two questions: 1: How to estimate memory cost before exec python script? 2: How to save RAM while do not increase exec time? Any answer will be grateful! --Tony Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: From PointedEars at web.de Mon Aug 1 11:16:58 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 01 Aug 2011 17:16:58 +0200 Subject: PEP 8 and extraneous whitespace References: <4E286704.5060201@gmail.com> <4E2870A2.1070600@jollybox.de> <4E287406.8080608@gmail.com> <98tahoFcblU1@mid.individual.net> <98u00kFnfiU1@mid.individual.net> <2364463.r0ecnVBMoN@PointedEars.de> Message-ID: <1915354.HBgK6uhDRg@PointedEars.de> OKB (not okblacke) wrote: > Thomas 'PointedEars' Lahn wrote: >> Automatic word-wrap, where available, really is not a solution; it >> is a bad workaround to a problem caused by the original author of >> the source code that can be easily avoided by them taking more care >> while coding. > > I think exactly the opposite. The source file should reflect the > semantic organization of the code, without extraneous concessions to > visual display (like "lining things up" with spaces or splitting long > lines with hard newlines). The editor should present the code nicely. > People already argue for this general mindset when they say that "any > good edit will let you set the tab width", etc. Your approach would require all source code editors to have the same minimum feature set as you described, with the same settings, which is unrealistic. And it would make especially Python code a lot harder to read (as indentation matters in Python). Your From header field value is borken. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From t at jollybox.de Mon Aug 1 11:29:08 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 01 Aug 2011 17:29:08 +0200 Subject: python reading file memory cost In-Reply-To: <000f01cc505c$74e01e80$5ea05b80$@com> References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: <4E36C644.6070800@jollybox.de> On 01/08/11 17:05, Tong Zhang wrote: > Hello, everyone! > > > > I am trying to read a little big txt file (~1 GB) by python2.7, what I > want to do is to read these data into a array, meanwhile, I monitor the > memory cost, I found that it cost more than 6 GB RAM! So I have two > questions: > > 1: How to estimate memory cost before exec python script? > > 2: How to save RAM while do not increase exec time? How are you reading the file? If you are using file_object.read(), .readlines(), or similar, to read the whole file at once: don't. This is a tremendous waste of memory, and probably slows things down. Usually, the best approach is to iterate over the file object itself (for line in file_object: # process line) Without knowing what you're doing with the data (or, what "data" is here), we can't really do much to help you. My best guess would be that you're unnecessarily storing the data multiple times. Perhaps you can use the csv module? Do you really need to hold all the data in memory all the time, or can you process the data in the order it is in the file, never actually holding more than one (or a few) records in memory? With generators, Python has excellent support for working with streams of data like this. (and it would save you a lot of RAM) - Thomas From alimanfoo at googlemail.com Mon Aug 1 11:33:45 2011 From: alimanfoo at googlemail.com (aliman) Date: Mon, 1 Aug 2011 08:33:45 -0700 (PDT) Subject: Complex sort on big files Message-ID: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Hi all, Apologies I'm sure this has been asked many times, but I'm trying to figure out the most efficient way to do a complex sort on very large files. I've read the recipe at [1] and understand that the way to sort a large file is to break it into chunks, sort each chunk and write sorted chunks to disk, then use heapq.merge to combine the chunks as you read them. What I'm having trouble figuring out is what to do when I want to sort by one key ascending then another key descending (a "complex sort"). I understand that sorts are stable, so I could just repeat the whole sort process once for each key in turn, but that would involve going to and from disk once for each step in the sort, and I'm wondering if there is a better way. I also thought you could apply the complex sort to each chunk before writing it to disk, so each chunk was completely sorted, but then the heapq.merge wouldn't work properly, because afaik you can only give it one key. Any help much appreciated (I may well be missing something glaringly obvious). Cheers, Alistair [1] http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ From anddimario at gmail.com Mon Aug 1 11:39:23 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Mon, 1 Aug 2011 17:39:23 +0200 Subject: Notifications when process is killed Message-ID: Thanks Thomas, it is what i'm looking for. Regards -- Andrea Di Mario From drsalists at gmail.com Mon Aug 1 12:30:54 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 09:30:54 -0700 Subject: python reading file memory cost In-Reply-To: <000f01cc505c$74e01e80$5ea05b80$@com> References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: A code snippet would work wonders in making sure you've communicated what you really need, or at least what you have now. But if you read the data into one big string, that'll be much more efficient than if you read it as a list of integers or even as a list of lines. Processing the data one chunk or one line at a time will be far more memory-efficient. 2011/8/1 Tong Zhang > Hello, everyone!**** > > ** ** > > I am trying to read a little big txt file (~1 GB) by python2.7, what I want > to do is to read these data into a array, meanwhile, I monitor the memory > cost, I found that it cost more than 6 GB RAM! So I have two questions:*** > * > > 1: How to estimate memory cost before exec python script?**** > > 2: How to save RAM while do not increase exec time?**** > > ** ** > > Any answer will be grateful!**** > > ** ** > > --Tony Zhang**** > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Mon Aug 1 12:45:54 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 09:45:54 -0700 Subject: Complex sort on big files In-Reply-To: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Python 2.x, or Python 3.x? What are the types of your sort keys? If you're on 3.x and the key you need reversed is numeric, you can negate the key. If you're on 2.x, you can use an object with a __cmp__ method to compare objects however you require. You probably should timsort the chunks (which is the standard list_.sort() - it's a very good in-memory sort), and then merge them afterward using the merge step of merge sort. heapq's not unreasonable for the merging, but I think it's more common to use a short list. I have a bunch of Python sorts at http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find your need is specialized (EG, 3.x sorting by a secondary key that's a string, in reverse), you could adapt one of these to do what you need. heapq is not bad, but if you find you need a logn datastructure, you might check out http://stromberg.dnsalias.org/~dstromberg/treap/ - a treap is also logn, but has a very good amortized cost because it sacrifices keeping things perfectly balanced (and rebalancing, and rebalancing...) to gain speed. But still, you might be better off with a short list and min. On Mon, Aug 1, 2011 at 8:33 AM, aliman wrote: > Hi all, > > Apologies I'm sure this has been asked many times, but I'm trying to > figure out the most efficient way to do a complex sort on very large > files. > > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. > > What I'm having trouble figuring out is what to do when I want to sort > by one key ascending then another key descending (a "complex sort"). > > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. > > I also thought you could apply the complex sort to each chunk before > writing it to disk, so each chunk was completely sorted, but then the > heapq.merge wouldn't work properly, because afaik you can only give it > one key. > > Any help much appreciated (I may well be missing something glaringly > obvious). > > Cheers, > > Alistair > > [1] > http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Aug 1 13:00:03 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Aug 2011 19:00:03 +0200 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: aliman wrote: > Apologies I'm sure this has been asked many times, but I'm trying to > figure out the most efficient way to do a complex sort on very large > files. > > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. > > What I'm having trouble figuring out is what to do when I want to sort > by one key ascending then another key descending (a "complex sort"). > > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. > > I also thought you could apply the complex sort to each chunk before > writing it to disk, so each chunk was completely sorted, but then the > heapq.merge wouldn't work properly, because afaik you can only give it > one key. You can make that key as complex as needed: >>> class Key(object): ... def __init__(self, obj): ... self.asc = obj[1] ... self.desc = obj[2] ... def __cmp__(self, other): ... return cmp(self.asc, other.asc) or -cmp(self.desc, other.desc) ... >>> sorted(["abc", "aba", "bbb", "aaa", "aab"], key=Key) ['aab', 'aaa', 'abc', 'bbb', 'aba'] See also http://docs.python.org/library/functools.html#functools.total_ordering From bahamutzero8825 at gmail.com Mon Aug 1 13:11:04 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 01 Aug 2011 12:11:04 -0500 Subject: What's in a name? In-Reply-To: <4E361F36.4030802@gmail.com> References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> <4E361F36.4030802@gmail.com> Message-ID: <4E36DE28.3030407@gmail.com> Hmm.... How about Rainbow Video Encoder Wrapper (Rainbow View for short - RView is taken, possibly multiple times)? I added an arbitrary word to a generic name, and the result doesn't seem to be taken by anything software-related. It wraps more than just video encoders (in fact, x264 will likely be the only one it wraps until it's matured quite a bit :P ), but I didn't want the name to get too long. The module itself will likely be called just rainbow.py. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From psyking841 at gmail.com Mon Aug 1 13:38:07 2011 From: psyking841 at gmail.com (happykid) Date: Mon, 1 Aug 2011 10:38:07 -0700 (PDT) Subject: os.path.dirname(sys.argv[0]) always returns nothing Message-ID: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> I want to use this function to get the directory path of the running script, but it always returns empty string. Can anyone help me solve this? Thank you. From rosuav at gmail.com Mon Aug 1 13:53:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 18:53:30 +0100 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: On Mon, Aug 1, 2011 at 6:38 PM, happykid wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. As long as you haven't changed directory since startup, you should be able to use os.path.abspath(sys.argv[0]) to get the absolute path name. It'll automatically fill in the path from the current directory if it's not provided. See: http://docs.python.org/py3k/library/os.path.html#os.path.abspath ChrisA From thijs at buckazoids.com Mon Aug 1 13:55:11 2011 From: thijs at buckazoids.com (Thijs Engels) Date: Mon, 01 Aug 2011 19:55:11 +0200 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: <1312221311.721.2158243397@webmail.messagingengine.com> On Mon, 01 Aug 2011 10:38 -0700, "happykid" wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list I think this is what you are after: import os.path path = os.path.abspath(os.path.dirname(__file__)) argv[0] returns the name of the current file (string), but no path information if I recall correct. Thijs From benjamin.kaplan at case.edu Mon Aug 1 13:56:31 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Aug 2011 13:56:31 -0400 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: On Mon, Aug 1, 2011 at 1:38 PM, happykid wrote: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. > -- > sys.argv[0] is the name of the script you called. If you call "python spam.py", sys.argv[0] will be spam.py. Not /full/path/spam.py. Just spam.py. And the directory part of "spam.py" is "". You'll have to call os.path.abspath(sys.argv[0]) to get the full path, then get dirname. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Aug 1 13:58:27 2011 From: gordon at panix.com (John Gordon) Date: Mon, 1 Aug 2011 17:58:27 +0000 (UTC) Subject: os.path.dirname(sys.argv[0]) always returns nothing References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: In <9797b629-3fba-4b90-920f-e426683599e1 at a12g2000vbf.googlegroups.com> happykid writes: > I want to use this function to get the directory path of the running > script, but it always returns empty string. Can anyone help me solve > this? Thank you. What is the value of sys.argv[0]? You're supposed to pass a full pathname to os.path.dirname, like so: >>> import os >>> os.path.dirname('/a/b/c/d/e.txt') '/a/b/c/d' >>> If sys.argv[0] is just the program name, then it doesn't have a path, which is why you get no results from os.path.dirname: >>> import os >>> os.path.dirname('foo.py') '' >>> Are you trying to obtain the full pathname of the program? That's an entirely different question. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Mon Aug 1 14:01:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Aug 2011 19:01:08 +0100 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: <1312221311.721.2158243397@webmail.messagingengine.com> References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> <1312221311.721.2158243397@webmail.messagingengine.com> Message-ID: On Mon, Aug 1, 2011 at 6:55 PM, Thijs Engels wrote: > argv[0] returns the name of the current file (string), but no path > information if I recall correct. It will give path information if you're invoking a script from another directory. Under some circumstances it might happen to give an absolute path for something in the current directory, but that can't be assumed or relied upon. ChrisA From harmar at member.fsf.org Mon Aug 1 15:17:05 2011 From: harmar at member.fsf.org (harrismh777) Date: Mon, 01 Aug 2011 14:17:05 -0500 Subject: Spam In-Reply-To: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >> I've noticed that python-list gets significantly more spam than the >> > other lists I subscribe to. There's an example below. > Thanks for that! I missed it the first time, so it is very helpful for you > to forward it. It's especially helpful that you included all the spammer's > URLs, as that will help improve their Google page ranks. I'm sure the > spammer will thank you for your assistance. Yeah, a couple of good rules to follow for well intentioned citizens: 1) don't feed the trolls 2) don't repackage spam Having said that, either because I was tired or because I dropped my defensive posture, I have messed up on those two little rules more than once. It is possible to filter spam very effectively. My mail client has a spam-can based on a multitude of trial and guess rules that with almost oh 97 percent rate puts the right stuff into the can and saves me the trouble of manually filtering it. Granted, I still need to quickly peek through the can files... but this is pretty easy to do... because non spam shows up like a rose among thorns in a spam-can. The trouble is that this group does like to debate off-topic stuff frequently (usually its at least edge related to Python) and so who is to tell (as a moderator) what is spam? Well, your example is fairly obvious, but other stuff (even like this note) may not be. I don't consider this spam, because its related to this list and because I am interested in the same issue as your OP complaint. But, I am absolutely sure that others will view your note, and mine, as spam... see the problem? -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From steve+comp.lang.python at pearwood.info Mon Aug 1 18:06:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Aug 2011 08:06:53 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: Message-ID: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > I have fixed the problem for you: > > > def fibo(n): > phi = (1+5**.5)/2; iphi = 1-phi; > return (phi**n - iphi**n) / (5**.5) Does your definition of "fixed" mean "gives wrong results for n >= 4 "? >>> fibo(4) == 3 False -- Steven From drsalists at gmail.com Mon Aug 1 18:35:21 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 15:35:21 -0700 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: I've been testing my Python code on these using virtualbox and/or physical machines (but mostly virtualbox): CentOS 6.0 Debian DragonflyBSD Fedora 15 FreeBSD Haiku R1 alpha 3 Linux Mint Minix OpenIndiana openSUSE Sabayon Scientific Linux 6 Slackware Solaris Express Ubuntu Windows 7 Sadly, I don't have enough physmem to run them all concurrently, so I boot, test, shutdown; boot, test, shutdown... On Mon, Aug 1, 2011 at 3:42 PM, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as well > as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. ;) > > Any recommendations on which linuces to pick? > > ~Ethan~ > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Aug 1 18:42:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 01 Aug 2011 15:42:19 -0700 Subject: test systems Message-ID: <4E372BCB.3030003@stoneleaf.us> Howdy, I'm going to setup a few linux systems for testing (probably three) as well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. ;) Any recommendations on which linuces to pick? ~Ethan~ From alister.ware at ntlworld.com Mon Aug 1 18:42:47 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 01 Aug 2011 22:42:47 GMT Subject: test systems References: Message-ID: On Mon, 01 Aug 2011 15:42:19 -0700, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? > > ~Ethan~ I would suggest you ned something from the main core distributions so something debian based & something Red hat based, i would also suggest looking at slackware @ gentoo to add completness of course if you are really ambitious you could try linux from scratch :-) -- Hate the sin and love the sinner. -- Mahatma Gandhi From steve+comp.lang.python at pearwood.info Mon Aug 1 18:54:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 02 Aug 2011 08:54:45 +1000 Subject: test systems References: Message-ID: <4e372eb6$0$30001$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? What are you testing? Is this for buildbots? Are you testing consumer-level software? Who is your software aimed at? Depending on the answer to that, normally I would say one each from the Debian and Redhat families, plus one other. E.g. pick one from each: (1) Debian, Ubuntu, Linux Mint (2) RHEL (if you can afford the licence fee), Centos, Fedora (3) Gentoo, Arch Linux, Suse, Slackware Some additional thoughts: I presume you're using VMs rather than six physical machines. What, no Apple Mac? Keep in mind that Arch uses Python 3 for the system python. Also keep in mind that Arch is generally considered to be so far out on the bleeding edge that even Slackware users consider them nuts. :) -- Steven From tim at johnsons-web.com Mon Aug 1 19:05:33 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 1 Aug 2011 15:05:33 -0800 Subject: Hostmonster : Installing MySQLdb at a specific location In-Reply-To: <20110731194135.GD3358@johnsons-web.com> References: <20110731185034.GC3358@johnsons-web.com> <20110731194135.GD3358@johnsons-web.com> Message-ID: <20110801230533.GA14664@johnsons-web.com> * Tim Johnson [110731 11:47]: > I don't want to discourage any further input, but I'm looking at > https://my.hostmonster.com/cgi/help/000531?step=000531 > regarding installing django and I think the instructions can be > extrapolated for MySQLdb. I will report what happens... I received a link for the Hostmonster helpdesk to https://my.hostmonster.com/cgi/help/530 My experience was that I had to modify some of the paths from the original. When I ran the python setup.py install routine, python complained that it could not find `lib64' thusly, I created $HOME/.local/lib/python2.4/site-packages Furthermore, seems that setup.py did not copy all files from the installation directory. The result was a UserWarning regarding multiple imports of the _mysql module when I invoked import MySQLdb. I solved that by adding the installation directory to my PYTHONPATH. A relevant excerpt from .bashrc looks like this: #BEGIN - # line one export PYTHONPATH=$HOME/.local/lib64/python/site-packages:$PYTHONPATH # line two export PYTHONPATH=$HOME/.local/lib64/python2.4/site-packages:$PYTHONPATH # line three export PYTHONPATH=$HOME/admin/.install/MySQL-python-1.2.3:$PYTHONPATH # line four export PATH=$HOME/.local/bin:$PATH #END Where $HOME/admin/.install/MySQL-python-1.2.3 is the package install directory. I have been spoiled by ubuntu. Furthemore, it has been a long time since I did a package install where I don't have root privileges. Results may vary, I hope this is helpful to someone else. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From greg.ewing at canterbury.ac.nz Mon Aug 1 19:57:11 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 02 Aug 2011 11:57:11 +1200 Subject: os.path.dirname(sys.argv[0]) always returns nothing In-Reply-To: References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> Message-ID: <99osqsFk1aU1@mid.individual.net> Thijs Engels wrote: > argv[0] returns the name of the current file (string), but no path > information if I recall correct. It's the path that was used to specify the script by whatever launched it, so it could be either absolute or relative to the current directory. -- Greg From ramit.prasad at jpmorgan.com Mon Aug 1 20:32:32 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 1 Aug 2011 20:32:32 -0400 Subject: Convert '165.0' to int In-Reply-To: <993q91FebkU2@mid.individual.net> References: <4e281f97$0$16404$426a74cc@news.free.fr> <4230ed8b-5173-4408-938f-3777dcd60588@t7g2000vbv.googlegroups.com> <3d6b3ab4-6682-4e33-ab03-098d2f82c20d@o18g2000yqm.googlegroups.com> <58cdafad-e1ea-4774-984f-aa13cf2a9ef1@fq4g2000vbb.googlegroups.com> <993q91FebkU2@mid.individual.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA72036B3@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Gregory Ewing Sent: Sunday, July 24, 2011 7:05 PM To: python-list at python.org Subject: Re: Convert '165.0' to int Frank Millman wrote: > I know I am flogging a dead horse here, but IMHO, '165', '165.', > '165.0', and '165.00' are all valid string representations of the > integer 165.[1] > > Therefore, for practical purposes, it would not be wrong for python's > 'int' function to accept these without complaining. How far would you go with that? Would you also accept '1.65e2' as a valid representation of the integer 165? -- Greg -- ================================ No, YAGNI (You Aren't Going To Need It). Do the minimum that works for your use case. If you only expect ###.# then code for that. Avoid trying to over-engineer your solution. *If* you think you are going to receive information that might be like '1.65e2' then code for it, otherwise spend your time working on other problems. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From t at jollybox.de Mon Aug 1 20:33:18 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 02:33:18 +0200 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: <4E3745CE.8080609@jollybox.de> On 02/08/11 00:42, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as > well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and > Windows. ;) > > Any recommendations on which linuces to pick? I would say that the Debian vs Red Hat issue is secondary compared to how recent the installed packages are. IMHO, you'll want: (1) "state of the art" - newest Ubuntu, Fedora Core, or perhaps openSUSE release (2) stable/"business-level" maturity - Debian stable, CentOS (or Scientific Linux/RHEL/other RHEL rebuild), Ubuntu LTS release and, perhaps: (3) bleeding edge - Arch / Gentoo You may also want to consider non-current releases. If I had to chose three, it might be Ubuntu 11.04, Debian 6, and CentOS 5. - Thomas From ramit.prasad at jpmorgan.com Mon Aug 1 20:42:05 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 1 Aug 2011 20:42:05 -0400 Subject: Convert '165.0' to int In-Reply-To: References: <4e281f97$0$16404$426a74cc@news.free.fr> <4230ed8b-5173-4408-938f-3777dcd60588@t7g2000vbv.googlegroups.com> <3d6b3ab4-6682-4e33-ab03-098d2f82c20d@o18g2000yqm.googlegroups.com> <58cdafad-e1ea-4774-984f-aa13cf2a9ef1@fq4g2000vbb.googlegroups.com> <993q91FebkU2@mid.individual.net> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA72036BD@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmchase.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com at python.org] On Behalf Of Frank Millman Sent: Monday, July 25, 2011 12:51 AM To: python-list at python.org Subject: Re: Convert '165.0' to int On Jul 25, 2:04?am, Gregory Ewing wrote: > Frank Millman wrote: > > I know I am flogging a dead horse here, but IMHO, '165', '165.', > > '165.0', and '165.00' are all valid string representations of the > > integer 165.[1] > > > Therefore, for practical purposes, it would not be wrong for python's > > 'int' function to accept these without complaining. > > How far would you go with that? Would you also accept > '1.65e2' as a valid representation of the integer 165? > To be honest, I don't even know what that means! I could read up on it, but I think this has gone far enough. Having flogged this horse to death, I will now let it rest in peace :-) Frank -- http://mail.python.org/mailman/listinfo/python-list ======================== '1.65e2' is a fairly standard representation of scientific notation. It basically translates to: 1.65 x 10^2 For more details, see: http://en.wikipedia.org/wiki/Scientific_notation Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Mon Aug 1 21:29:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 02:29:53 +0100 Subject: test systems In-Reply-To: <4E372BCB.3030003@stoneleaf.us> References: <4E372BCB.3030003@stoneleaf.us> Message-ID: On Mon, Aug 1, 2011 at 11:42 PM, Ethan Furman wrote: > Howdy, > > I'm going to setup a few linux systems for testing (probably three) as well > as the three FreeBSD, OpenBSD, and (possibly) NetBsd. ?Oh, and Windows. ?;) > > Any recommendations on which linuces to pick? Others have made recommendations of distro (and are far better qualified than I to do so), but one small point to add: Test a mix of 32-bit and 64-bit systems, unless you only support the latter. This is particularly important with installers and such; installing a 32-bit library on a 64-bit Linux may mean putting it in a special directory. Chris Angelico From nytrokiss at gmail.com Mon Aug 1 21:50:43 2011 From: nytrokiss at gmail.com (James Matthews) Date: Mon, 1 Aug 2011 21:50:43 -0400 Subject: test systems In-Reply-To: References: <4E372BCB.3030003@stoneleaf.us> Message-ID: Wow, why don't you find some cloud providers and write bootstrap programs. James On Mon, Aug 1, 2011 at 6:35 PM, Dan Stromberg wrote: > > I've been testing my Python code on these using virtualbox and/or physical > machines (but mostly virtualbox): > > CentOS 6.0 > Debian > DragonflyBSD > Fedora 15 > FreeBSD > Haiku R1 alpha 3 > Linux Mint > Minix > OpenIndiana > openSUSE > Sabayon > Scientific Linux 6 > Slackware > Solaris Express > Ubuntu > Windows 7 > > Sadly, I don't have enough physmem to run them all concurrently, so I boot, > test, shutdown; boot, test, shutdown... > > > On Mon, Aug 1, 2011 at 3:42 PM, Ethan Furman wrote: > >> Howdy, >> >> I'm going to setup a few linux systems for testing (probably three) as >> well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. >> ;) >> >> Any recommendations on which linuces to pick? >> >> ~Ethan~ >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://www.theboxery.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From warriorlance at gmail.com Mon Aug 1 23:22:50 2011 From: warriorlance at gmail.com (Tony Zhang) Date: Tue, 02 Aug 2011 11:22:50 +0800 Subject: python reading file memory cost In-Reply-To: References: <000f01cc505c$74e01e80$5ea05b80$@com> Message-ID: <1312255370.31275.20.camel@ZTFEL> Thanks! Actually, I used .readline() to parse file line by line, because I need to find out the start position to extract data into list, and the end point to pause extracting, then repeat until the end of file. My file to read is formatted like this: blabla...useless.... useless... /sign/ data block(e.g. 10 cols x 1000 rows) ... blank line /sign/ data block(e.g. 10 cols x 1000 rows) ... blank line ... ... EOF let's call this file 'myfile' and my python snippet: f=open('myfile','r') blocknum=0 #number the data block data=[] while True" # find the extract begnning while not f.readline().startswith('/a1/'):pass # creat multidimensional list to store data block data=append([]) blocknum +=1 line=f.readline() while line.strip(): # check if the line is a blank line, i.e the end of one block data[blocknum-1].append(["2.6E" %float(x) for x in line.split()]) line = f.readline() print "Read Block %d" %blocknum if not f.readline(): break The running result was that read a 500M file consume almost 2GB RAM, I cannot figure it out, somebody help! Thanks very much! --Tony From ghodmode at ghodmode.com Mon Aug 1 23:58:10 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Tue, 2 Aug 2011 11:58:10 +0800 Subject: Spam In-Reply-To: References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 3:17 AM, harrismh777 wrote: > Steven D'Aprano wrote: > >> I've noticed that python-list gets significantly more spam than the >>> > other lists I subscribe to. There's an example below. >>> >> Thanks for that! I missed it the first time, so it is very helpful for you >> to forward it. It's especially helpful that you included all the spammer's >> URLs, as that will help improve their Google page ranks. I'm sure the >> spammer will thank you for your assistance. >> > > Yeah, a couple of good rules to follow for well intentioned citizens: > 1) don't feed the trolls > 2) don't repackage spam > I hope it's clear that reading an email doesn't constitute visiting all of the sites linked in the email and therefore doesn't improve Google page ranks or provide any other tracking information. Also note that the original email didn't have anything like a tracking pixel. Even the urls were just text. They only became links if the readers' email client turned them into links. My email wasn't dangerous or helpful to the spammer in any way. Having said that, either because I was tired or because I dropped my > defensive posture, I have messed up on those two little rules more than > once. > > It is possible to filter spam very effectively. My mail client has a > spam-can based on a multitude of trial and guess rules that with almost oh > 97 percent rate puts the right stuff into the can and saves me the trouble > of manually filtering it. Granted, I still need to quickly peek through the > can files... but this is pretty easy to do... because non spam shows up like > a rose among thorns in a spam-can. > > The trouble is that this group does like to debate off-topic stuff > frequently (usually its at least edge related to Python) and so who is to > tell (as a moderator) what is spam? Well, your example is fairly obvious, > but other stuff (even like this note) may not be. I don't consider this > spam, because its related to this list and because I am interested in the > same issue as your OP complaint. But, I am absolutely sure that others will > view your note, and mine, as spam... see the problem? > I think we have a generally accepted idea of what spam is, and it's much different from off-topic threads. An automated system might not be able to identify the differences as easily, but a person could. Especially if that person is an active member of the community and reads all of the threads anyway. > -- > m harris > > FSF ...free as in freedom/ > http://webpages.charter.net/**harrismh777/gnulinux/gnulinux.**htm > > -- > http://mail.python.org/**mailman/listinfo/python-list > My intentions were constructive and helpful, but it has gotten a little out of hand. Based on some of the information provided, my idea might not be technically feasible anyway. So, I won't be reading or commenting on this thread further. I am truly sorry for any misunderstandings or time lost. -- Ghodmode http://www.ghodmode.com/blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.pricejones at gmail.com Tue Aug 2 00:10:44 2011 From: m.pricejones at gmail.com (mpj) Date: Mon, 1 Aug 2011 21:10:44 -0700 (PDT) Subject: Map-based module imports with import hook Message-ID: <13064e6e-6d3d-457d-bd90-1bb4a3150eb9@e20g2000prf.googlegroups.com> Hi, I've experience working at companies where, because of the network set up, having a long PYTHONPATH and searching it is quite a heavy task and can slow down the start up of the interpreter when there are lots of imports. As a proof of concept I wanted to look at a map-based approach. The theory being that instead of having a linear list of paths to search with heavy disk checks, if we could encode the location of the modules in an environment variable we would be able to jump to the correct location much quicker. As a result I've written: https://github.com/michaeljones/porter Which implements an import hook (PEP 302) that can be set up to look at an environment variable with the following format: name=location[:name=location[:name=location[:...]]] This is parsed into a standard dict and used for quick lookups when possible, falling back to the standard Python import mechanism when nothing is found. The implementation is new and not production tested, but I was hoping to get some external thoughts on the idea, especially to hear any functionality that this might disrupt. I've only written basic tests to check import behaviour and am aware that I probably don't really appreciate the full consequences of this idea. Cheers, Michael From drsalists at gmail.com Tue Aug 2 01:01:46 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 1 Aug 2011 22:01:46 -0700 Subject: python reading file memory cost In-Reply-To: <1312255370.31275.20.camel@ZTFEL> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: You could try forcing a garbage collection... On Mon, Aug 1, 2011 at 8:22 PM, Tony Zhang wrote: > Thanks! > > Actually, I used .readline() to parse file line by line, because I need > to find out the start position to extract data into list, and the end > point to pause extracting, then repeat until the end of file. > My file to read is formatted like this: > > blabla...useless.... > useless... > > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > ... > ... > EOF > let's call this file 'myfile' > and my python snippet: > > f=open('myfile','r') > blocknum=0 #number the data block > data=[] > while True" > # find the extract begnning > while not f.readline().startswith('/a1/'):pass > # creat multidimensional list to store data block > data=append([]) > blocknum +=1 > line=f.readline() > > while line.strip(): > # check if the line is a blank line, i.e the end of one block > data[blocknum-1].append(["2.6E" %float(x) for x in > line.split()]) > line = f.readline() > print "Read Block %d" %blocknum > if not f.readline(): break > > The running result was that read a 500M file consume almost 2GB RAM, I > cannot figure it out, somebody help! > Thanks very much! > > --Tony > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 2 01:41:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 06:41:41 +0100 Subject: Spam In-Reply-To: References: <4e365fa5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 4:58 AM, Ghodmode wrote: > I hope it's clear that reading an email doesn't constitute visiting all of > the sites linked in the email and therefore doesn't improve Google page > ranks or provide any other tracking information.? Also note that the > original email didn't have anything like a tracking pixel.? Even the urls > were just text.? They only became links if the readers' email client turned > them into links.? My email wasn't dangerous or helpful to the spammer in any > way. You're correct about emails per se, but list mail gets archived to web-accessible pages: http://mail.python.org/pipermail/python-list/2011-August/1277607.html And yes, URLs become clickable. ChrisA From clp2 at rebertia.com Tue Aug 2 02:55:15 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Aug 2011 23:55:15 -0700 Subject: python reading file memory cost In-Reply-To: <1312255370.31275.20.camel@ZTFEL> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: On Mon, Aug 1, 2011 at 8:22 PM, Tony Zhang wrote: > Thanks! > > Actually, I used .readline() to parse file line by line, because I need > to find out the start position to extract data into list, and the end > point to pause extracting, then repeat until the end of file. > My file to read is formatted like this: > > blabla...useless.... > useless... > > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > /sign/ > data block(e.g. 10 cols x 1000 rows) > ... > blank line > ... > ... > EOF > let's call this file 'myfile' > and my python snippet: > > f=open('myfile','r') > blocknum=0 #number the data block > data=[] > while True" > ? ? ? ?# find the extract begnning > ? ? ? ?while not f.readline().startswith('/a1/'):pass > ? ? ? ?# creat multidimensional list to store data block > ? ? ? ?data=append([]) > ? ? ? ?blocknum +=1 > ? ? ? ?line=f.readline() > > ? ? ? ?while line.strip(): > ? ? ? ?# check if the line is a blank line, i.e the end of one block > ? ? ? ? ? ? ? ?data[blocknum-1].append(["2.6E" %float(x) for x in line.split()]) > ? ? ? ? ? ? ? ?line = f.readline() > ? ? ? ?print "Read Block %d" %blocknum > ? ? ? ?if not f.readline(): break > > The running result was that read a 500M file consume almost 2GB RAM, I > cannot figure it out, somebody help! If you could store the floats themselves, rather than their string representations, that would be more space-efficient. You could then also use the `array` module, which is more space-efficient than lists (http://docs.python.org/library/array.html ). Numpy would also be worth investigating since multidimensional arrays are involved. The next obvious question would then be: do you /really/ need /all/ of the data in memory at once? Also, just so you're aware: http://docs.python.org/library/sys.html#sys.getsizeof Cheers, Chris -- http://rebertia.com From harmar at member.fsf.org Tue Aug 2 03:12:20 2011 From: harmar at member.fsf.org (harrismh777) Date: Tue, 02 Aug 2011 02:12:20 -0500 Subject: range() vs xrange() Python2|3 issues for performance Message-ID: The following is intended as a helpful small extension to the xrange() range() discussion brought up this past weekend by Billy Mays... With Python2 you basically have two ways to get a range of numbers: range() , which returns a list, and xrange() , which returns an iterator. With Python3 you must use range(), which produces an iterator; while xrange() does not exist at all (at least not on 3.2). I have been doing some research in number theory related to Mersenne Primes and perfect numbers (perfects, those integers whose primary divisors when summed result in the number, not including the number itself)... the first few of those being 6, 28, 496, 8128, 33550336, etc Never mind, but you know... are there an infinite number of them? ... and of course, are there any "odd" perfect numbers... well not under 10^1500.... I digress, sorry ... This brought up the whole range() xrange() thing for me again because Python in any case is just not fast enough (no brag, just fact). So my perfect number stuff is written in C, for the moment. But, what about the differences in performance (supposing we were to stay in Python for small numbers) between xrange() vs range() [on Python2] versus range() [on Python3]? I have put my code snips below, with some explanation below that... these will run on either Python2 or Python3... except that if you substitute xrange() for range() for Python2 they will throw an exception on Python3... doh. So, here is PyPerfectNumbers.py ---------------------------- def PNums(q): for i in range(2, q): m = 1 s = 0 while m <= i/2: if not i%m: s += m m += 1 if i == s: print(i) return 0 def perf(n): sum = 0 for i in range(1, n): if n % i == 0: sum += i return sum == n fperf = lambda n: n == sum(i for i in range(1, n) if n % i == 0) -----------------/end--------------------------------------- PNums(8200) will crunch out the perfect numbers below 8200. perf(33550336) will test to see if 33550336 is a perfect number fperf(33550336) is the lambda equivalent of perf() These are coded with range(). The interesting thing to note is that xrange() on Python2 runs "considerably" faster than the same code using range() on Python3. For large perfect numbers (above 8128) the performance difference for perf() is orders of magnitude. Actually, range() on Python2 runs somewhat slower than xrange() on Python2, but things are much worse on Python3. This is something I never thought to test before Billy's question, because I had already decided to work in C for most of my integer stuff... like perfects. But now that it sparked my interest, I'm wondering if there might be some focus placed on range() performance in Python3 for the future, PEP? kind regards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From anddimario at gmail.com Tue Aug 2 03:30:52 2011 From: anddimario at gmail.com (AndDM) Date: Tue, 2 Aug 2011 00:30:52 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: On Aug 1, 5:39?pm, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Hi, i've a little problem, here the code that i use: def receive_signal(signum, stack): logging.info('Received: %s' % signum) reactor.stop() signal.signal(signal.SIGTERM, receive_signal) signal.signal(signal.SIGHUP, receive_signal) signal.signal(signal.SIGINT, receive_signal) The function works for SIGHUP and SIGINT, but it doesn't work for SIGTERM. I've tried with simple killall and with -15 option. Have you some ideas? Thanks, regards. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Aug 2 03:51:51 2011 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 2 Aug 2011 07:51:51 +0000 (UTC) Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: harrismh777 wrote: these will run on either Python2 or > Python3... except that if you substitute xrange() for range() for > Python2 they will throw an exception on Python3... doh. if 'xrange' not in dir(__builtins__): xrange = range at the beginning of your program will fix that. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From __peter__ at web.de Tue Aug 2 04:26:22 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 10:26:22 +0200 Subject: python reading file memory cost References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: Chris Rebert wrote: >> The running result was that read a 500M file consume almost 2GB RAM, I >> cannot figure it out, somebody help! > > If you could store the floats themselves, rather than their string > representations, that would be more space-efficient. You could then > also use the `array` module, which is more space-efficient than lists > (http://docs.python.org/library/array.html ). Numpy would also be > worth investigating since multidimensional arrays are involved. > > The next obvious question would then be: do you /really/ need /all/ of > the data in memory at once? This is what you (OP) should think about really hard before resorting to the optimizations mentioned above. Perhaps you can explain what you are doing with the data once you've loaded it into memory? > Also, just so you're aware: > http://docs.python.org/library/sys.html#sys.getsizeof To give you an idea how memory usage explodes: >>> line = "1.23 4.56 7.89 0.12\n" >>> len(line) # size in the file 20 >>> sys.getsizeof(line) 60 >>> formatted = ["%2.6E" % float(x) for x in line.split()] >>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) 312 From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 04:26:22 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 10:26:22 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: Am 02.08.2011 09:30 schrieb AndDM: > The function works for SIGHUP and SIGINT, but it doesn't work for > SIGTERM. I've tried with simple killall and with -15 option. > Have you some ideas? SIGTERM cannot be caught - it kills the process the hard way. HTH, Thomas From rosuav at gmail.com Tue Aug 2 05:01:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 10:01:26 +0100 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 8:30 AM, AndDM wrote: > ? ? ? ?def receive_signal(signum, stack): > ? ? ? ? ? ? ? ?logging.info('Received: %s' % signum) > ? ? ? ? ? ? ? ?reactor.stop() > ? ? ? ?signal.signal(signal.SIGTERM, receive_signal) > ? ? ? ?signal.signal(signal.SIGHUP, receive_signal) > ? ? ? ?signal.signal(signal.SIGINT, receive_signal) > > The function works for SIGHUP and SIGINT, but it doesn't work for > SIGTERM. I've tried with simple killall and with -15 option. > Have you some ideas? You won't be able to catch SIGTERM, as Thomas said, but if you need to know what caused a process to end, the best way is to have code in the parent process to catch SIGCHLD. When the child ends, for any reason, its parent is sent SIGCHLD with some parameters, including the signal number that caused the termination; you can then log anything you want. Chris Angelico From __peter__ at web.de Tue Aug 2 05:05:43 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 11:05:43 +0200 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: harrismh777 wrote: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. > > With Python3 you must use range(), which produces an iterator; while > xrange() does not exist at all (at least not on 3.2). > > I have been doing some research in number theory related to Mersenne > Primes and perfect numbers (perfects, those integers whose primary > divisors when summed result in the number, not including the number > itself)... the first few of those being 6, 28, 496, 8128, 33550336, etc > > Never mind, but you know... are there an infinite number of them? > ... and of course, are there any "odd" perfect numbers... well not under > 10^1500.... I digress, sorry ... > > This brought up the whole range() xrange() thing for me again > because Python in any case is just not fast enough (no brag, just fact). > So my perfect number stuff is written in C, for the moment. But, what > about the differences in performance (supposing we were to stay in > Python for small numbers) between xrange() vs range() [on Python2] > versus range() [on Python3]? I have put my code snips below, with some > explanation below that... these will run on either Python2 or > Python3... except that if you substitute xrange() for range() for > Python2 they will throw an exception on Python3... doh. try: range = xrange except NameError: pass > > So, here is PyPerfectNumbers.py ---------------------------- > > def PNums(q): > for i in range(2, q): > m = 1 > s = 0 > while m <= i/2: i/2 returns a float in Python 3; you should use i//2 for consistency. > if not i%m: > s += m > m += 1 > if i == s: > print(i) > return 0 > > def perf(n): > sum = 0 > for i in range(1, n): > if n % i == 0: > sum += i > return sum == n > > fperf = lambda n: n == sum(i for i in range(1, n) if n % i == 0) > > -----------------/end--------------------------------------- > > PNums(8200) will crunch out the perfect numbers below 8200. > > perf(33550336) will test to see if 33550336 is a perfect number > > fperf(33550336) is the lambda equivalent of perf() > > > These are coded with range(). The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Python 3's range() is indeed slower, but not orders of magnitude: $ python3.2 -m timeit -s"r = range(33550336)" "for i in r: pass" 10 loops, best of 3: 1.88 sec per loop $ python2.7 -m timeit -s"r = xrange(33550336)" "for i in r: pass" 10 loops, best of 3: 1.62 sec per loop $ cat tmp.py try: range = xrange except NameError: pass def fperf(n): return n == sum(i for i in range(1, n) if not n % i) if __name__ == "__main__": print(fperf(33550336)) $ time python2.7 tmp.py True real 0m6.481s user 0m6.100s sys 0m0.000s $ time python3.2 tmp.py True real 0m7.925s user 0m7.520s sys 0m0.040s I don't know what's causing the slowdown, maybe the int/long unification is to blame. > Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? From phil at freehackers.org Tue Aug 2 05:17:54 2011 From: phil at freehackers.org (BlueBird) Date: Tue, 2 Aug 2011 02:17:54 -0700 (PDT) Subject: Deeply nested dictionaries - should I look into a database or am I just doing it wrong? References: <4E35A0BB.5010201@gmail.com> Message-ID: <0693ae3d-d95d-4b8d-a397-53b7bdf995d8@a10g2000yqn.googlegroups.com> I love named tuples, they rock for this kind of task: storing complicated structure in a python compatible way, without too much hassle. And as far as load/save on disk is concerned, I simply use regular python structure with safe eval [1]. I get all the flexibility that I need for the file format, without the annoyance of writing a conversion layer. [1]: http://code.activestate.com/recipes/364469-safe-eval/ From stefan_ml at behnel.de Tue Aug 2 05:20:41 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 02 Aug 2011 11:20:41 +0200 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: harrismh777, 02.08.2011 09:12: > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. > > With Python3 you must use range(), which produces an iterator; while > xrange() does not exist at all (at least not on 3.2). That's a good thing. There should be one - and preferably only one - obvious way to do it. iterable: range(N) list: list(range(N)) tuple: tuple(range(N)) set: set(range(N)) ... Less special cases in the language. > This brought up the whole range() xrange() thing for me again because > Python in any case is just not fast enough (no brag, just fact). So my > perfect number stuff is written in C, for the moment. Or use Cython or PyPy, both of which are simpler ways to get your code up to speed. > The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. Are you sure that's due to Py3 range() vs. Py2 xrange()? Py3 has a different implementation for integers (which is still being optimised, BTW). That's much more likely to make a difference here. What version of Py3 were you using? If you used the latest, maybe even the latest hg version, you will notice that that's substantially faster for integers than, e.g. 3.1.x. Stefan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 05:26:45 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 11:26:45 +0200 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: Am 02.08.2011 09:12 schrieb harrismh777: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. No. An iterable. As already said, iterators are the ones stopping forever when the end is reached. Generally, iterables are allowed to iterate multiple times. xrange() resp. range() yield iterables. > The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. That sounds strange at the first glance. > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? I'm sure it is a matter of implementation. You cannot define by PEP what performance the implementations should have. Maybe range() in 3 is defined differently to xrange() in 2. I'm not so familiar with 3 to definitely confirm or decline that. The behaviour, though, seems to be the same, but range3 (as I call it now) has some more methods than xrange, like the rich comparison ones. Indexing works with all of them. Thomas From jldunn2000 at gmail.com Tue Aug 2 05:32:54 2011 From: jldunn2000 at gmail.com (loial) Date: Tue, 2 Aug 2011 02:32:54 -0700 (PDT) Subject: Hardlink sub-directories and files Message-ID: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> I am trying to hardlink all files in a directory structure using os.link. This works fine for files, but the directory also contains sub- directories (which themselves contain files and sub-directories). However I do not think it is possible to hard link directories ? So presumably I would need to do a mkdir for each sub-directory encountered? Or is there an easier way to hardlink everything in a directory structure?. The requirement is for hard links, not symbolic links From rosuav at gmail.com Tue Aug 2 05:52:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 10:52:59 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 10:20 AM, Stefan Behnel wrote: > What version of Py3 were you using? If you used the latest, maybe even the > latest hg version, you will notice that that's substantially faster for > integers than, e.g. 3.1.x. > I just tried this out, using a slightly modified script but the same guts: ----- import sys print(sys.version) import time def PNums(q): start=time.clock() for i in range(2, q): m = 1 s = 0 while m <= i/2: if not i%m: s += m m += 1 if i == s: print(i) print("Time: %f"%(time.clock()-start)) return # PNums(33550337) PNums(10000) ----- On my dual-core Windows laptop (it always saturates one core with this, leaving the other for the rest of the system), the results show no statistically significant difference between xrange and range in Python 2, but notably slower overall performance in Python 3: 2.4.5 (#1, Dec 15 2009, 16:41:19) [GCC 4.1.1] Time: 14.474343 Using xrange: 14.415412 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] Time: 8.990142 Using xrange: 9.015566 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] Time: 24.401461 Since I don't have a build environment in which to test the latest from hg, I switched to a Linux box. The following timings therefore cannot be compared with the above ones. 3.3a0 (default:b95096303ed2, Jun 2 2011, 20:43:01) [GCC 4.4.5] Time: 34.390000 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] Time: 13.730000 Using xrange: 13.670000 My 3.3a0 is freshly pulled from hg, although I'm not sure if sys.version has been correctly built. Once again, 2.6.6 shows no significant difference between range and xrange, but 3 is noticeably slower than 2. (I did several runs, but the variance between the runs wasn't significant.) Of course, this is all fairly moot; if you're doing really heavy number crunching, CPython isn't the platform to use. ChrisA From __peter__ at web.de Tue Aug 2 06:01:19 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 12:01:19 +0200 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > > This works fine for files, but the directory also contains sub- > directories (which themselves contain files and sub-directories). > However I do not think it is possible to hard link directories ? > > So presumably I would need to do a mkdir for each sub-directory > encountered? > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links You cannot make hardlinks for directories, that's a restriction imposed by the operating system. Look for shutil.copytree() for a template of what you are trying to do; you might even monkepatch it # untested copy2 = shutil.copy2 shutil.copy2 = os.link try: shutil.copytree(source, dest) finally: shutil.copy2 = copy2 if you are OK with a quick-and-dirty solution. From t at jollybox.de Tue Aug 2 06:13:35 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 12:13:35 +0200 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <4E37CDCF.7060501@jollybox.de> On 02/08/11 11:32, loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > > This works fine for files, but the directory also contains sub- > directories (which themselves contain files and sub-directories). > However I do not think it is possible to hard link directories ? > > So presumably I would need to do a mkdir for each sub-directory > encountered? > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links > Yes, you have to mkdir everything. However, there is an easier way: subprocess.Popen(['cp','-Rl','target','link']) This is assuming that you're only supporting Unices with a working cp program, but as you're using hard links, that's quite a safe bet, I should think. - Thomas From rosuav at gmail.com Tue Aug 2 06:19:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 11:19:53 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 10:05 AM, Peter Otten <__peter__ at web.de> wrote: > i/2 returns a float in Python 3; you should use i//2 for consistency. > And I forgot to make this change before doing my tests. Redoing the Python 3 ones with // quite drastically changes things! 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] Time: 17.917331 That's a lot closer to the 10-14 seconds that Python 2 was doing, but still somewhat worse. Of course, no surprises that 2.6 is faster than 2.4. But now, here's a fairly small change that makes a LOT of difference, and reveals the value of range/xrange. Notice that m is just being a classic iteration counter (it starts at 1, increments to a top limit)... ----- for m in xrange(1,i//2+1): if not i%m: s += m ----- This brings 2.6.5 down to 5.359383 seconds, or 4.703364 with xrange. (I'm now changing two references from range to xrange.) Meanwhile, 3.2 has come down to 7.096237 seconds, and 2.4.5 to 8.222261. Comparing the latest 3.3a0 and 2.6.6 on the other box shows that there's still a difference. Both of them improve with range instead of manual incrementing, but 2.6.6 takes 6.950000 seconds and 3.3a0 takes 13.830000 (down from 13.730000 and 34.390000 in the previous test). Conclusion: Python 3 is notably slower comparing floating point and integer than Python 2 is comparing int and int. No surprises there! But get everything working with integers, and use range() instead of manually incrementing a variable, and things come much more even. But as I said, CPython isn't the ideal language for heavy number crunching. On the same Windows box, a Pike program using the same algorithm took only 2.055 seconds. And a C program took 0.328 seconds. But if you have other reasons for keeping it in Python, do keep it to integers! ChrisA From alimanfoo at googlemail.com Tue Aug 2 06:25:05 2011 From: alimanfoo at googlemail.com (Alistair Miles) Date: Tue, 2 Aug 2011 11:25:05 +0100 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Hi Dan, Thanks for the reply. On Mon, Aug 1, 2011 at 5:45 PM, Dan Stromberg wrote: > > Python 2.x, or Python 3.x? Currently Python 2.x. > What are the types of your sort keys? Both numbers and strings. > If you're on 3.x and the key you need reversed is numeric, you can negate > the key. I did wonder about that. Would that not be doable also in Python 2.7, using sorted(key=...)? > If you're on 2.x, you can use an object with a __cmp__ method to compare > objects however you require. OK, right. Looking at the HowTo/Sorting again [1] and the bit about cmp_to_key, could you also achieve the same effect by returning a key with custom implementations of rich comparison functions? > You probably should timsort the chunks (which is the standard list_.sort() - > it's a very good in-memory sort), and then merge them afterward using the > merge step of merge sort. Yes, that's what I understood by the activestate recipe [2]. So I guess my question boils down to, how do you do the merge step for a complex sort? (Assuming each chunk had been completely sorted first.) Maybe the answer is also to construct a key with custom implementation of rich comparisons? Now I'm also wondering about the best way to sort each chunk. The examples in [1] of complex sorts suggest the best way to do it is to first sort by the secondary key, then sort by the primary key, relying on the stability of the sort to get the desired outcome. But would it not be better to call sorted() once, supplying a custom key function? (As an aside, at the end of the section in [1] on Sort Stability and Complex sorts, it says "The Timsort algorithm used in Python does multiple sorts efficiently because it can take advantage of any ordering already present in a dataset." - I get that that's true, but I don't see how that's relevant to this strategy for doing complex sorts. I.e., if you sort first by the secondary key, you don't get any ordering that's helpful when you subsequently sort by the primary key. ...?) (Sorry, another side question, I'm guessing reading a chunk of data into a list and using Timsort, i.e., calling list.sort() or sorted(mylist), is quicker than using bisect to keep the chunk sorted as you build it?) > heapq's not unreasonable for the merging, but I think it's more common to > use a short list. Do you mean a regular Python list, and calling min()? > I have a bunch of Python sorts at > http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find your > need is specialized (EG, 3.x sorting by a secondary key that's a string, in > reverse), you could adapt one of these to do what you need. Thanks. Re 3.x sorting by a secondary key that's a string, in reverse, which one were you thinking of in particular? > heapq is not bad, but if you find you need a logn datastructure, you might > check out http://stromberg.dnsalias.org/~dstromberg/treap/ - a treap is also > logn, but has a very good amortized cost because it sacrifices keeping > things perfectly balanced (and rebalancing, and rebalancing...) to gain > speed.? But still, you might be better off with a short list and min. Thanks, that's really helpful. Cheers, Alistair [1] http://wiki.python.org/moin/HowTo/Sorting/ [2] http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ > On Mon, Aug 1, 2011 at 8:33 AM, aliman wrote: >> >> Hi all, >> >> Apologies I'm sure this has been asked many times, but I'm trying to >> figure out the most efficient way to do a complex sort on very large >> files. >> >> I've read the recipe at [1] and understand that the way to sort a >> large file is to break it into chunks, sort each chunk and write >> sorted chunks to disk, then use heapq.merge to combine the chunks as >> you read them. >> >> What I'm having trouble figuring out is what to do when I want to sort >> by one key ascending then another key descending (a "complex sort"). >> >> I understand that sorts are stable, so I could just repeat the whole >> sort process once for each key in turn, but that would involve going >> to and from disk once for each step in the sort, and I'm wondering if >> there is a better way. >> >> I also thought you could apply the complex sort to each chunk before >> writing it to disk, so each chunk was completely sorted, but then the >> heapq.merge wouldn't work properly, because afaik you can only give it >> one key. >> >> Any help much appreciated (I may well be missing something glaringly >> obvious). >> >> Cheers, >> >> Alistair >> >> [1] >> http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- -- Alistair Miles Head of Epidemiological Informatics Centre for Genomics and Global Health The Wellcome Trust Centre for Human Genetics Roosevelt Drive Oxford OX3 7BN United Kingdom Web: http://purl.org/net/aliman Email: alimanfoo at gmail.com Tel: +44 (0)1865 287669 From anddimario at gmail.com Tue Aug 2 06:36:44 2011 From: anddimario at gmail.com (Andrea Di Mario) Date: Tue, 2 Aug 2011 12:36:44 +0200 Subject: Notifications when process is killed Message-ID: > You won't be able to catch SIGTERM, as Thomas said, but if you need to > know what caused a process to end, the best way is to have code in the > parent process to catch SIGCHLD. When the child ends, for any reason, > its parent is sent SIGCHLD with some parameters, including the signal > number that caused the termination; you can then log anything you > want. Hi, i understand, i've read that SIGKILL can't catch, but nothing about SIGTERM. If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or not? Thanks, regards. -- Andrea Di Mario From rosuav at gmail.com Tue Aug 2 06:44:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 11:44:01 +0100 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:36 AM, Andrea Di Mario wrote: > If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or not? What you would do is create two processes. Set up your signal handlers, then fork; in the parent, just watch for the child's death - in the child, do all your work. When the parent receives SIGCHLD, it can ascertain the cause of death. ChrisA From tzhang at sinap.ac.cn Tue Aug 2 07:00:39 2011 From: tzhang at sinap.ac.cn (=?gb2312?B?1cXNrg==?=) Date: Tue, 2 Aug 2011 19:00:39 +0800 Subject: python reading file memory cost In-Reply-To: References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> Message-ID: <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> Thanks Peter! Your explanation is great! And one more question: Why it is still keeping the memory even when I del the large array in interactive python mode? -----Original Message----- From: Peter Otten [mailto:__peter__ at web.de] Sent: Tuesday, August 02, 2011 4:26 PM To: python-list at python.org Subject: Re: python reading file memory cost Chris Rebert wrote: >> The running result was that read a 500M file consume almost 2GB RAM, >> I cannot figure it out, somebody help! > > If you could store the floats themselves, rather than their string > representations, that would be more space-efficient. You could then > also use the `array` module, which is more space-efficient than lists > (http://docs.python.org/library/array.html ). Numpy would also be > worth investigating since multidimensional arrays are involved. > > The next obvious question would then be: do you /really/ need /all/ of > the data in memory at once? This is what you (OP) should think about really hard before resorting to the optimizations mentioned above. Perhaps you can explain what you are doing with the data once you've loaded it into memory? > Also, just so you're aware: > http://docs.python.org/library/sys.html#sys.getsizeof To give you an idea how memory usage explodes: >>> line = "1.23 4.56 7.89 0.12\n" >>> len(line) # size in the file 20 >>> sys.getsizeof(line) 60 >>> formatted = ["%2.6E" % float(x) for x in line.split()] >>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) 312 From no at nowhere.net.no Tue Aug 2 07:06:55 2011 From: no at nowhere.net.no (TheSaint) Date: Tue, 02 Aug 2011 19:06:55 +0800 Subject: how to solve it? References: Message-ID: ???? wrote: > from matplotlib.matlab import * maybe you didn't install it http://matplotlib.sourceforge.net/ BTW you haven't mention what version of python you're running. From t at jollybox.de Tue Aug 2 07:09:57 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 13:09:57 +0200 Subject: python reading file memory cost In-Reply-To: <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> References: <000f01cc505c$74e01e80$5ea05b80$@com> <1312255370.31275.20.camel@ZTFEL> <000a01cc5103$6be8ea80$43babf80$@sinap.ac.cn> Message-ID: <4E37DB05.1020500@jollybox.de> On 02/08/11 13:00, ?? wrote: > Thanks Peter! Your explanation is great! > And one more question: > Why it is still keeping the memory even when I del the large array in > interactive python mode? This is an optimisation of the way the Python interpreter allocates memory: it holds on to memory it's not using any more for a while so it can be easily re-used for new objects --- this is more efficient than giving the memory back to the operating system only to request it again shortly afterwards. > > -----Original Message----- > From: Peter Otten [mailto:__peter__ at web.de] > Sent: Tuesday, August 02, 2011 4:26 PM > To: python-list at python.org > Subject: Re: python reading file memory cost > > Chris Rebert wrote: > >>> The running result was that read a 500M file consume almost 2GB RAM, >>> I cannot figure it out, somebody help! >> >> If you could store the floats themselves, rather than their string >> representations, that would be more space-efficient. You could then >> also use the `array` module, which is more space-efficient than lists >> (http://docs.python.org/library/array.html ). Numpy would also be >> worth investigating since multidimensional arrays are involved. >> >> The next obvious question would then be: do you /really/ need /all/ of >> the data in memory at once? > > This is what you (OP) should think about really hard before resorting to the > optimizations mentioned above. Perhaps you can explain what you are doing > with the data once you've loaded it into memory? > >> Also, just so you're aware: >> http://docs.python.org/library/sys.html#sys.getsizeof > > To give you an idea how memory usage explodes: > >>>> line = "1.23 4.56 7.89 0.12\n" >>>> len(line) # size in the file > 20 >>>> sys.getsizeof(line) > 60 >>>> formatted = ["%2.6E" % float(x) for x in line.split()] >>>> sys.getsizeof(formatted) + sum(sys.getsizeof(s) for s in formatted) > 312 > > > > From kushal.kumaran+python at gmail.com Tue Aug 2 07:15:17 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 2 Aug 2011 16:45:17 +0530 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 1:56 PM, Thomas Rachel wrote: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. > You must mean SIGKILL. There's nothing special about SIGTERM, except that it's the default for the kill command. -- regards, kushal From python.list at tim.thechases.com Tue Aug 2 07:17:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 02 Aug 2011 06:17:10 -0500 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <4E37DCB6.4070704@tim.thechases.com> On 08/02/2011 04:32 AM, loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > Or is there an easier way to hardlink everything in a directory > structure?. > > The requirement is for hard links, not symbolic links While Peter & Thomas gave good answers, also be aware that hard-links can't cross mount-points (an OS limitation). So if you have something mounted under the directory you're trying to hard-link-copy, attempting to create a hard-link will fail for things within that mount. -tkc From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 2 07:40:22 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 02 Aug 2011 13:40:22 +0200 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: Am 02.08.2011 10:26 schrieb Thomas Rachel: > Am 02.08.2011 09:30 schrieb AndDM: > >> The function works for SIGHUP and SIGINT, but it doesn't work for >> SIGTERM. I've tried with simple killall and with -15 option. >> Have you some ideas? > > SIGTERM cannot be caught - it kills the process the hard way. Thank you for pointing out (via email) that this is wrong: SIGTERM is a normal signal which can be caught in the normal way. SIGKILL is (besides SIGSTOP) the one which cannot be caught, blocked or ignored. Thomas From kliateni at gmail.com Tue Aug 2 07:45:15 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 13:45:15 +0200 Subject: Please code review. Message-ID: <4E37E34B.5080707@gmail.com> Hello, I need a generator to create the cellname in a excell (using pyuno) document to assign value to the correct cell. The following code does this but do you have some optimizations on it, for instance to get the alphabetic chars instead of hard-coding it. Cheers karim Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def _xrange_cellnames(rows, cols): ... """Internal iterator function to compute excell table cellnames.""" ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ... for row in xrange(1, rows+1): ... for char in cellnames.replace('', ' ').split()[:cols]: ... yield char + str(row) ... >>> list( _xrange_cellnames(rows=3,cols=4)) ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] From paul at subsignal.org Tue Aug 2 08:04:45 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Tue, 02 Aug 2011 14:04:45 +0200 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: Am 02.08.2011 13:45, schrieb Karim: > > Hello, > > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to > the correct cell. The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. you can use: import string cellnames = string.ascii_uppercase not sure why you need the .replace().split() stuff... def _xrange_cellnames(rows, cols): cellnames = string.ascii_uppercase for row in xrange(1, rows+1): for char in cellnames[:rows]: yield char + str(row) cheers Paul > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > > From rosuav at gmail.com Tue Aug 2 08:07:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 13:07:28 +0100 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: On Tue, Aug 2, 2011 at 12:45 PM, Karim wrote: > ... ? ? ? ? for char in cellnames.replace('', ' ').split()[:cols]: for char in cellnames[:cols]: Strings are iterable over their characters. Alternatively, you could use chr and ord, but it's probably cleaner and simpler to have the string there. It also automatically and implicitly caps your columns at 26. On the other hand, if you want to support more than 26 columns, you may want to make your own generator function to yield 'A', 'B',... 'Z', 'AA', 'AB', etc. ChrisA From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 08:16:00 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 08:16:00 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2011 06:06 PM, Steven D'Aprano wrote: > Does your definition of "fixed" mean "gives wrong results for n>= 4 "? > >>>> fibo(4) == 3 > False > Well, I don't know if you're trolling or just dumb: http://en.wikipedia.org/wiki/Fibonacci_number In [2]: for i in range(10): ...: print fibo(i) ...: ...: 0.0 1.0 1.0 2.0 3.0 5.0 8.0 13.0 21.0 34.0 -- Bill From grco at brute4ce.com Tue Aug 2 08:22:17 2011 From: grco at brute4ce.com (Martin Gracik) Date: Tue, 2 Aug 2011 14:22:17 +0200 Subject: Please code review. In-Reply-To: <4E37E34B.5080707@gmail.com> References: <4E37E34B.5080707@gmail.com> Message-ID: On Tue, Aug 2, 2011 at 1:45 PM, Karim wrote: > > Hello, > > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to > the correct cell. The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=**4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > > > -- > http://mail.python.org/**mailman/listinfo/python-list > You could use something like this: Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import imap, product >>> import string >>> >>> def get_cellnames(rows, cols): ... return imap(str().join, product(string.ascii_uppercase[:cols], ... imap(str, range(1, rows + 1)))) ... >>> print list(get_cellnames(rows=3, cols=4)) ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3', 'D1', 'D2', 'D3'] -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Aug 2 08:27:03 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 14:27:03 +0200 Subject: Please code review. References: <4E37E34B.5080707@gmail.com> Message-ID: Karim wrote: > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to the correct cell. Isn't there a way to use a (row, column) tuple directly? If so I'd prefer that. Also, there used to be an alternative format to address a spreadsheet cell with something like "R1C2". > The following code does this but do you have some > optimizations > on it, for instance to get the alphabetic chars instead of hard-coding it. > > Cheers > karim > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def _xrange_cellnames(rows, cols): > ... """Internal iterator function to compute excell table > cellnames.""" > ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > ... for row in xrange(1, rows+1): > ... for char in cellnames.replace('', ' ').split()[:cols]: That is interesting ;) But for maximum clarity use for char in cellnames[:cols]: instead. > ... yield char + str(row) > ... > >>> list( _xrange_cellnames(rows=3,cols=4)) > ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] Here's my (untested) attempt to handle columns beyond "Z": from itertools import chain, count, imap, islice, product from string import ascii_uppercase def columnnames(): alpha = (ascii_uppercase,) return imap("".join, chain.from_iterable(product(*alpha*i) for i in count(1))) def cellnames(columns, rows): for row in xrange(1, rows+1): for column in islice(columnnames(), columns): yield column + str(row) if __name__ == "__main__": import sys print list(cellnames(*map(int, sys.argv[1:]))) I think the subject has come up before; goo^h^h^h the search engine of your choice is your friend. From kliateni at gmail.com Tue Aug 2 08:28:01 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:28:01 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37ED51.7010402@gmail.com> Thanks Paul, I never used string module. In fact, cellnames.split('') gives a syntax error w/ empty string. That's why I use the intermediate replace() which accept that. Cheers Karim On 08/02/2011 02:04 PM, Paul K?lle wrote: > Am 02.08.2011 13:45, schrieb Karim: >> >> Hello, >> >> I need a generator to create the cellname in a excell (using pyuno) >> document to assign value to >> the correct cell. The following code does this but do you have some >> optimizations >> on it, for instance to get the alphabetic chars instead of >> hard-coding it. > you can use: > import string > cellnames = string.ascii_uppercase > > not sure why you need the .replace().split() stuff... > > > def _xrange_cellnames(rows, cols): > cellnames = string.ascii_uppercase > for row in xrange(1, rows+1): > for char in cellnames[:rows]: > yield char + str(row) > > cheers > Paul > > >> >> Cheers >> karim >> >> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) >> [GCC 4.5.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def _xrange_cellnames(rows, cols): >> ... """Internal iterator function to compute excell table cellnames.""" >> ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >> ... for row in xrange(1, rows+1): >> ... for char in cellnames.replace('', ' ').split()[:cols]: >> ... yield char + str(row) >> ... >> >>> list( _xrange_cellnames(rows=3,cols=4)) >> ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] >> >> > > From kliateni at gmail.com Tue Aug 2 08:33:32 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:33:32 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37EE9C.4090701@gmail.com> Thanks Chris! It seems I am blind I should have seen it... In fact I started with the need (imaginary) to use enumerate() to get some indices but ended in a more simple code. Indeed, your's is simpler. For the double chars extension I will see if I need it in the future. Cheers Karim On 08/02/2011 02:07 PM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 12:45 PM, Karim wrote: >> ... for char in cellnames.replace('', ' ').split()[:cols]: > for char in cellnames[:cols]: > > Strings are iterable over their characters. Alternatively, you could > use chr and ord, but it's probably cleaner and simpler to have the > string there. It also automatically and implicitly caps your columns > at 26. On the other hand, if you want to support more than 26 columns, > you may want to make your own generator function to yield 'A', 'B',... > 'Z', 'AA', 'AB', etc. > > ChrisA From alain at dpt-info.u-strasbg.fr Tue Aug 2 08:45:46 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 02 Aug 2011 14:45:46 +0200 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> writes: > On 08/01/2011 06:06 PM, Steven D'Aprano wrote: >> Does your definition of "fixed" mean "gives wrong results for n>= 4 "? > Well, I don't know if you're trolling or just dumb: Steven is right, and you look dumb. >>> fibo(4) 3.0000000000000004 Even though the math is correct, your program is wrong. It doesn't even produce integers. And it will fail with overflow for big values. -- Alain. From kliateni at gmail.com Tue Aug 2 08:47:14 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:47:14 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> Message-ID: <4E37F1D2.2090505@gmail.com> On 08/02/2011 02:27 PM, Peter Otten wrote: > Karim wrote: > >> I need a generator to create the cellname in a excell (using pyuno) >> document to assign value to the correct cell. > Isn't there a way to use a (row, column) tuple directly? If so I'd prefer > that. Also, there used to be an alternative format to address a spreadsheet > cell with something like "R1C2". > In fact, in pyuno I get the following code: values = ( (22.5,21.5,121.5), (5615.3,615.3,-615.3), (-2315.7,315.7,415.7) ) table.getCellByName("A2").setValue(22.5) table.getCellByName("B2").setValue(5615.3) table.getCellByName("C2").setValue(-2315.7) Indeed the values tuple is formated like (row, column). I want to write simply and get cellname ondemand via an iterator function like that: values = ( (22.5,21.5,121.5), (5615.3,615.3,-615.3), (-2315.7,315.7,415.7) ) it = _xrange_cellnames(rows=len(value), cols=len(values[0])) table.getCellByName(it.next()).setValue(22.5) table.getCellByName(it.next()).setValue(5615.3) table.getCellByName(it.next()).setValue(-2315.7) >> The following code does this but do you have some >> optimizations >> on it, for instance to get the alphabetic chars instead of hard-coding it. >> >> Cheers >> karim >> >> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) >> [GCC 4.5.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> def _xrange_cellnames(rows, cols): >> ... """Internal iterator function to compute excell table >> cellnames.""" >> ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' >> ... for row in xrange(1, rows+1): >> ... for char in cellnames.replace('', ' ').split()[:cols]: > That is interesting ;) But for maximum clarity use > > for char in cellnames[:cols]: > > instead. Yes I am blind ;o) I did not see simplification. Simple is better than complicate... >> ... yield char + str(row) >> ... >> >>> list( _xrange_cellnames(rows=3,cols=4)) >> ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3'] > Here's my (untested) attempt to handle columns beyond "Z": > > from itertools import chain, count, imap, islice, product > from string import ascii_uppercase > > def columnnames(): > alpha = (ascii_uppercase,) > return imap("".join, chain.from_iterable(product(*alpha*i) for i in > count(1))) > > def cellnames(columns, rows): > for row in xrange(1, rows+1): > for column in islice(columnnames(), columns): > yield column + str(row) > > > if __name__ == "__main__": > import sys > print list(cellnames(*map(int, sys.argv[1:]))) > > I think the subject has come up before; goo^h^h^h the search engine of your > choice is your friend. I will study this one and itertools modules, many thanks. Cheers Karim From kliateni at gmail.com Tue Aug 2 08:53:38 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 14:53:38 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> <4E37EF35.2080403@gmail.com> Message-ID: <4E37F352.1090208@gmail.com> Thanks Martin, This is the generator expression version. I can use both function generator or generator expression version correction. Cheers Karim On 08/02/2011 02:47 PM, Martin Gracik wrote: > def get_cellnames2(rows, cols): > rows = range(1, rows + 1) > cols = string.ascii_uppercase[:cols] > return ('%s%s' % (col, row) for row in rows for col in cols) From Shambhu.Rajak at kpitcummins.com Tue Aug 2 09:02:43 2011 From: Shambhu.Rajak at kpitcummins.com (Shambhu Rajak) Date: Tue, 2 Aug 2011 13:02:43 +0000 Subject: Require information on python API for Subversion related work Message-ID: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> Hi , I need an api that can be used to do following operations on Subversion repository tool: 1. Create branch 2. Check out 3. Check in 4. Merge Regards, Shambhu -------------- next part -------------- An HTML attachment was scrubbed... URL: From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 09:16:59 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 09:16:59 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Message-ID: On 08/02/2011 08:45 AM, Alain Ketterlin wrote: > produce integers. And it will fail with overflow for big values. If it would make you feel better I can use decimal. Also, perhaps I can name my function billy_fibo(n), which is defined as billy_fibo(n) +error(n) = fibo(n), where error(n) can be made arbitrarily small. This runs in constant time rather than linear (memoized) or exponential (fully recursive) at the cost of a minutia of accuracy. I find this tradeoff acceptable. -- Bill From __peter__ at web.de Tue Aug 2 09:59:32 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Aug 2011 15:59:32 +0200 Subject: Please code review. References: <4E37E34B.5080707@gmail.com> <4E37F1D2.2090505@gmail.com> Message-ID: Karim wrote: > values = ( (22.5,21.5,121.5), > (5615.3,615.3,-615.3), > (-2315.7,315.7,415.7) ) > > it = _xrange_cellnames(rows=len(value), cols=len(values[0])) > > table.getCellByName(it.next()).setValue(22.5) > table.getCellByName(it.next()).setValue(5615.3) > table.getCellByName(it.next()).setValue(-2315.7) Some googling suggests that there exists a getCellByPosition() method. With that the above would become (untested): for x, column in enumerate(values): for y, value in enumerate(column): table.getCellByPosition(x, y).setValue(value) From steve+comp.lang.python at pearwood.info Tue Aug 2 10:15:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 00:15:45 +1000 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e380692$0$29970$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > On 08/02/2011 08:45 AM, Alain Ketterlin wrote: >> produce integers. And it will fail with overflow for big values. > > If it would make you feel better I can use decimal. > > Also, perhaps I can name my function billy_fibo(n), which is defined as > billy_fibo(n) +error(n) = fibo(n), where error(n) can be made > arbitrarily small. So you say, but I don't believe it. Given fibo, the function you provided earlier, the error increases with N: >>> fibo(82) - fib(82) # fib returns the accurate Fibonacci number 160.0 >>> fibo(182) - fib(182) 2.92786721937918e+23 Hardly "arbitrarily small". Your function also overflows for N = 1475: >>> fibo(1475) Traceback (most recent call last): File "", line 1, in File "", line 3, in fibo OverflowError: (34, 'Numerical result out of range') The correct value only has 307 digits, so it's not that large a number for integer math. I won't show them all, but it starts and ends like this: 8077637632...87040886025 > This runs in constant time rather than linear > (memoized) A good memoisation scheme will run in constant time (amortised). > or exponential (fully recursive) Good heavens no. Only the most naive recursive algorithm is exponential. Good ones (note plural) are linear. Combine that with memoisation, and you have amortised constant time. > at the cost of a minutia of accuracy. I'm reminded of a time my wife was travelling across the US with her band's roadies. At some point crossing the miles and miles of highway through the desert, she pointed out that they were lost and nowhere even close to the city where they were supposed to be playing. The driver answered, "Who cares, we're making great time!" (True story.) > I find this tradeoff acceptable. Given that Fibonacci numbers are mostly of interest to number theorists, who care about the *actual* Fibonacci numbers and not almost-but-not-quite Fibonacci numbers, I'm having a lot of difficulty imagining what sort of application you have in mind that could legitimately make that trade-off. -- Steven From kliateni at gmail.com Tue Aug 2 10:19:05 2011 From: kliateni at gmail.com (Karim) Date: Tue, 02 Aug 2011 16:19:05 +0200 Subject: Please code review. In-Reply-To: References: <4E37E34B.5080707@gmail.com> <4E37F1D2.2090505@gmail.com> Message-ID: <4E380759.2020709@gmail.com> On 08/02/2011 03:59 PM, Peter Otten wrote: > Karim wrote: > >> values = ( (22.5,21.5,121.5), >> (5615.3,615.3,-615.3), >> (-2315.7,315.7,415.7) ) >> >> it = _xrange_cellnames(rows=len(value), cols=len(values[0])) >> >> table.getCellByName(it.next()).setValue(22.5) >> table.getCellByName(it.next()).setValue(5615.3) >> table.getCellByName(it.next()).setValue(-2315.7) > Some googling suggests that there exists a getCellByPosition() method. With > that the above would become (untested): > > for x, column in enumerate(values): > for y, value in enumerate(column): > table.getCellByPosition(x, y).setValue(value) Thanks for the tip I will check com.sun.star.text.TextTable API. Regards Karim From ndbecker2 at gmail.com Tue Aug 2 10:19:20 2011 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 02 Aug 2011 10:19:20 -0400 Subject: 'Use-Once' Variables and Linear Objects Message-ID: I thought this was an interesting article http://www.pipeline.com/~hbaker1/Use1Var.html From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Tue Aug 2 10:40:06 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Tue, 02 Aug 2011 10:40:06 -0400 Subject: where the function has problem? n = 900 is OK , but n = 1000 is ERROR References: <4e37237e$0$29980$c3e8da3$5496439d@news.astraweb.com> <87vcugvv5x.fsf@dpt-info.u-strasbg.fr> <4e380692$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/02/2011 10:15 AM, Steven D'Aprano wrote: > So you say, but I don't believe it. Given fibo, the function you provided > earlier, the error increases with N: > >>>> fibo(82) - fib(82) # fib returns the accurate Fibonacci number > 160.0 >>>> fibo(182) - fib(182) > 2.92786721937918e+23 > > Hardly "arbitrarily small". Perhaps the individual number is big, but compare that to: (fibo(n) - fib(n)) / fib(n) The number is still quite close to the actual answer. > Your function also overflows for N = 1475: > >>>> fibo(1475) > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in fibo > OverflowError: (34, 'Numerical result out of range') > > > The correct value only has 307 digits, so it's not that large a number for > integer math. I won't show them all, but it starts and ends like this: > > 8077637632...87040886025 Yes, I mentioned possibly using the decimal class, which I suppose does lose the constant access time depending on how its implemented. > A good memoisation scheme will run in constant time (amortised). Amortized perhaps, but this assumes the call happening a number of times. Also, this requires linear memory to store previous values. > Good heavens no. Only the most naive recursive algorithm is exponential. > Good ones (note plural) are linear. Combine that with memoisation, and you > have amortised constant time. > Not all recursive functions can be memoized (or they can but for practically no benefit). What I was getting at was that a closed form expression of a recurrence might be significantly faster at an acceptable loss in accuracy. For an example, see the Ackermann function. > Given that Fibonacci numbers are mostly of interest to number theorists, who > care about the *actual* Fibonacci numbers and not almost-but-not-quite > Fibonacci numbers, I'm having a lot of difficulty imagining what sort of > application you have in mind that could legitimately make that trade-off. I was trying to show that there is an alternate method of calculation. Accuracy losses are really a problem with the underlying machinery rather than the high level code. If the recursive form of fib() were written in c, the integers would have overflown a long while ago compared to float. One other note, Fibonacci numbers grow exponentially fast (with respect to the number of bits), and python's integer multiplication takes exponential time (karatsuba rather than fft). If we are going to discuss the behavior of python's numeric types, then lets talk about how slow python will become for the nth Fibonacci integer and how much space it will take compared to the floating point short concise and almost as close form. -- Bill From cartercc at gmail.com Tue Aug 2 10:41:06 2011 From: cartercc at gmail.com (ccc31807) Date: Tue, 2 Aug 2011 07:41:06 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> On Jul 31, 2:38?pm, gavino wrote: > facebook is php > > myspace is microsoft > > aol was tcl and aolserver c embedding tcl interp > > priceline is lisp > > reddit is python was lisp orig > > amazon was perl > > livejournal was perl Most of these are tech companies. Tech companies are very important, but so are other kinds of companies. What do manufacturing companies use, like Ford and Toyota, energy companies like BP and Exxon, pharmaceutical companies, consumer product companies, and so on? What about the big retailers, Sears, WalMart, Target, etc.? CC. From steve+comp.lang.python at pearwood.info Tue Aug 2 10:45:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 00:45:34 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> harrismh777 wrote: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and > xrange() , which returns an iterator. xrange does not return an iterator. It returns a lazy iterable object, which is not the same thing. In Python, "iterator" is not merely a generic term for something which can be iterated over. An iterator is an object which obeys the iterator protocol, which depends on at least two properties: * the object must have a next() method, which returns values until the iterator is exhausted, and then raises StopIteration; (In Python 3, the method is __next__.) * and the object must have an __iter__() method which returns itself. (Also, "non-broken" iterators will continue to raise StopIteration once they do so once. That is, they can't be reset or repeated.) xrange objects fail on both accounts. (Likewise for range objects in Python 3.) [...] > These are coded with range(). The interesting thing to note is that > xrange() on Python2 runs "considerably" faster than the same code using > range() on Python3. For large perfect numbers (above 8128) the > performance difference for perf() is orders of magnitude. Actually, > range() on Python2 runs somewhat slower than xrange() on Python2, but > things are much worse on Python3. I find these results surprising, at least for numbers as small as 8128, and suspect your timing code is inaccurate. (But don't make the mistake of doing what I did, which was to attempt to produce range(290000000) in Python 2. After multiple *hours* of swapping, I was finally able to kill the Python process and get control of my PC again. Sigh.) I would expect that, in general, Python 3.1 or 3.2 is slightly slower than Python 2.6 or 2.7. (If you're using Python 3.0, stop now!) But in Python 2, I wouldn't expect orders of magnitude difference in range and xrange. Using the function perf(N) you gave, and a modified copy perfx(N) which simply replaces xrange for range, I get these timings in Python2.6: >>> from timeit import Timer >>> t1 = Timer('perf(10000)', 'from __main__ import perf') >>> t2 = Timer('perfx(10000)', 'from __main__ import perfx') >>> min(t1.repeat(number=1000, repeat=5)) 3.0614659786224365 >>> min(t2.repeat(number=1000, repeat=5)) 2.8787298202514648 A small difference, but not an order of magnitude. In Python 3.1, I get this: >>> min(t1.repeat(number=1000, repeat=5)) 3.4577009677886963 > This is something I never thought to test before Billy's question, > because I had already decided to work in C for most of my integer > stuff... like perfects. But now that it sparked my interest, I'm > wondering if there might be some focus placed on range() performance in > Python3 for the future, PEP? Oh indubitably. I doubt it will need a PEP. Python 3.x is still quite young, and the focus is on improving unicode support, but performance improvements will usually be welcome. However, at some point I would expect adding hand-crafted optimizations to CPython will cease to be worthwhile. Guido is already talking about CPython becoming the reference implementation, and PyPy the production implementation because it's faster. PyPy's optimizing compiler is already about twice as fast as CPython, and for at least one specially crafted example, faster than C: http://morepypy.blogspot.com/2011/02/pypy-faster-than-c-on-carefully-crafted.html -- Steven From mail at timgolden.me.uk Tue Aug 2 10:46:32 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 02 Aug 2011 15:46:32 +0100 Subject: Require information on python API for Subversion related work In-Reply-To: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> References: <408F64D89899604FB24015E64E10490C0122B1@KCHJEXMB01.kpit.com> Message-ID: <4E380DC8.5020008@timgolden.me.uk> On 02/08/2011 14:02, Shambhu Rajak wrote: > I need an api that can be used to do following operations on Subversion > repository tool: > > 1.Create branch > > 2.Check out > > 3.Check in > > 4.Merge http://pysvn.tigris.org/ (which is, by the way, the first Google hit for "Python Subversion bindings") TJG From hansmeetschool at gmail.com Tue Aug 2 11:30:04 2011 From: hansmeetschool at gmail.com (Hansmeet Singh) Date: Tue, 2 Aug 2011 08:30:04 -0700 Subject: Notifications when process is killed In-Reply-To: References: Message-ID: you shouldn't have anything to worry about SIGTERM if you send out a SIGCHLD On Tue, Aug 2, 2011 at 3:44 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:36 AM, Andrea Di Mario > wrote: > > If i use SIGCHLD, i will have difficult when parent receive a SIGTERM, or > not? > > What you would do is create two processes. Set up your signal > handlers, then fork; in the parent, just watch for the child's death - > in the child, do all your work. When the parent receives SIGCHLD, it > can ascertain the cause of death. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Aug 2 11:38:26 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Aug 2011 11:38:26 -0400 Subject: [ANN] IPython 0.11 is officially out In-Reply-To: References: Message-ID: On 8/1/11 8:54 AM, Thorsten Kampe wrote: > The documentation[1] says "If you are upgrading to version 0.11 of > IPython, you will need to migrate your old ipythonrc or ipy_user_conf.py > configuration files to the new system. Read on for information on how to > do this." Unfortunately there is no more mentioning of "migration", so > the developers' approach seems to be: "read all about the new > configuration system and see if you can somehow duplicate your old > ipythonrc settings. Good luck!". Or you can ask nicely on ipython-user, and we can help you migrate your old ipythonrc. http://mail.scipy.org/mailman/listinfo/ipython-user You can basically start with the ipython_config.py that is generated the first time and edit it. It is fully commented and demonstrates every configurable option with the defaults commented out. You just uncomment the appropriate lines and put in your values. You are right that the HOWTO migrate documentation is missing. It's an oversight that you can help remedy. -- 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 thinke365 at gmail.com Tue Aug 2 11:52:42 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 2 Aug 2011 23:52:42 +0800 Subject: python import error, what's wrong? Message-ID: I am using pydev plugin in eclipse, all things works just as well but now i have confronted with a confusing problem, that is i can import a module write by myself successfully, but when i try to run this program, error just shows up, what's wrong? the directory structure is as follows: src org.test A.py org.lab B.py contents of A seems like: class A ... contents of B seems like: // I try to run B.py, python import error just appears, why? from org.test.A import A a = A() From rantingrick at gmail.com Tue Aug 2 12:03:19 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 2 Aug 2011 09:03:19 -0700 (PDT) Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> <877h6xzgpm.fsf@mithlond.arda> Message-ID: On Aug 1, 3:19?am, Teemu Likonen wrote: > * 2011-07-30T10:57:29+10:00 * Steven D'Aprano wrote: > > > Teemu Likonen wrote: > >> Pathnames and the separator for pathname components should be > >> abstracted away, to a pathname object. > > > Been there, done that, floundered on the inability of people to work > > out the details. > > >http://www.python.org/dev/peps/pep-0355/ > > I'm very much a Lisp person and obviously got the idea of pathname > objects from Common Lisp. Lazily I'm also learning Python too but at the > moment I can't comment on the details of that PEP. Yet, generally I > think that's the way to improve pathnames, not the "rantinrick's". This thread was intended to expose another PyWart and get the community juices flowing. os.path is broken and cannot be repaired because os.path was an improper API to begin with. The only way to solve this problem is to introduce a new Path object. A new Path object is the answer. Some have said "been there, done that" with a sarcastic and defeatist point of view. I say we need to re-visit the proposal of PEP-0355 and hash out something quickly. We also need to realize that one day or another this Path object is going to become reality and the longer we drag our feet getting it implemented the more painful the transition is going to be. I feel Python community is in an awkward teenage stage at this point not really sure of it's self or direction. Living only for today with no ability to project the future and wasting too much time arguing over minutiae. We need a collective wake-up-call in the form of a slap on the face. We need to start making the hard choices necessary to clean up this library. Python3000 was only the beginning! ONLY THE BEGINNING! From rosuav at gmail.com Tue Aug 2 12:06:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:06:21 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e380d8f$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 3:45 PM, Steven D'Aprano wrote: > (But don't make the mistake of doing what I did, which was to attempt to > produce range(290000000) in Python 2. After multiple *hours* of swapping, I > was finally able to kill the Python process and get control of my PC again. > Sigh.) > That is sad. (And, I am only slightly ashamed to admit it, quite funny.) But on the other hand, quite impressive that it didn't bomb anywhere! Whenever I'm about to do something really dangerous, I like to first open an SSH session from another computer - bash running inside there can usually kill any process fairly efficiently, without need for UI interaction. Failing that, good ol' Ctrl-Alt-F1 to get to a console is usually the next best, but sometimes logging in requires a lot of resources. This is actually one place where I'm really glad Python doesn't do much with multiple threads (for instance, it won't gc on another thread). A dual core CPU keeps everything happy! ChrisA From rosuav at gmail.com Tue Aug 2 12:20:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:20:07 +0100 Subject: python import error, what's wrong? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 4:52 PM, smith jack wrote: > from org.test.A import A This is going to look for org/test/A.py but not for org.test/A.py - are you able to rename your directories to not have dots? ChrisA From thinke365 at gmail.com Tue Aug 2 12:20:48 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 00:20:48 +0800 Subject: How to define repeated string when using the re module? Message-ID: if it's for a single character, this should be very easy, such as c{m,n} the occurrence of c is between m and n, if i want to define the occurrence of (.*?) how should make it done? ((.*?)){1,3} seems not work, any method to define repeat string using python regex? From rosuav at gmail.com Tue Aug 2 12:36:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:36:57 +0100 Subject: PyWart: os.path needs immediate attention! In-Reply-To: References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <8739hoam1i.fsf@mithlond.arda> <4e3356f3$0$29978$c3e8da3$5496439d@news.astraweb.com> <877h6xzgpm.fsf@mithlond.arda> Message-ID: On Tue, Aug 2, 2011 at 5:03 PM, rantingrick wrote: > This thread was intended to expose another PyWart and get the > community juices flowing. os.path is broken and cannot be repaired > because os.path was an improper API to begin with. The only way to > solve this problem is to introduce a new Path object. > > A new Path object is the answer. http://xkcd.com/927/ > I feel Python community is in an awkward teenage stage at this point > not really sure of it's self or direction. Living only for today with > no ability to project the future and wasting too much time arguing > over minutiae. We need a collective wake-up-call in the form of a slap > on the face. We need to start making the hard choices necessary to > clean up this library. > > Python3000 was only the beginning! ONLY THE BEGINNING! Some of us have reached the level of maturity necessary to understand that stability is valuable. Also to notice when requirements internally conflict - how are we going to develop the One Perfect API without spending a lot of time arguing minutiae? One thing I have learned in life is that mature products have their warts for a reason, and that reason is usually compatibility. That's not necessarily a good thing, but nor is it necessarily bad. For instance, the Python source code is managed by automake. We could save ourselves a LOT of trouble by simply moving to the future - a future in which Linux is the only operating system we bother with, that 64-bit hardware and 64-bit OSes are everything, and so on. Why bother supporting the past? But that "past" is actually a huge part of the world today, too. Large-scale adoption is an incredibly valuable thing, and you are narrowing your adoption potential considerably if you do not support these things. As an example, have you ever noticed how horribly useless and skeletal the Python documentation is? Neither have I. It's used by so many people that it gets eyeballs, and therefore time, to fix up its failings. Compare with Pike, a much more obscure language (syntactically similar to C, but under the covers quite similar to Python); scroll down this list of constants from its Stdio module: http://pike.ida.liu.se/generated/manual/modref/ex/predef_3A_3A/Stdio.html A good number of them simply say FIXME, and even those that _are_ documented have only brief explanations. For quite a few things, you need to go direct to the language's source code. (Do a docs search for FIXME and you'll find that this is not an isolated case.) That doesn't happen with Python, largely a consequence (if somewhat indirectly) of its being so widely used. Sure you can make your life easier. But is it really better? Chris Angelico From rosuav at gmail.com Tue Aug 2 12:55:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 17:55:30 +0100 Subject: Early binding as an option Message-ID: As I understand it, Python exclusively late-binds names; when you define a function, nothing is ever pre-bound. This allows a huge amount of flexibility (letting you "reach into" someone else's function and change its behaviour), but it's flexibility that most programs use seldom if at all. First off: Is there any way to request/cause some names to be bound early? and secondly, should there be? Argument against: Late binding is a Good Thing, and having some things bound early would be confusing. Argument in favour: Efficiency is also a Good Thing, and with staples like 'len', it's unlikely anyone will want to change them - yet the interpreter still has to do a namespace lookup every time. I would want the end programmer to have the ultimate power here (not the module designer). Something along the lines of: This global name will never change, so don't bother looking it up every time. As an example of this difference, Pike uses early binding for some things; when I did the perfect numbers testing in the other thread (discussion thread, not thread of execution!), Pike performed significantly better; I believe this is in part due to the formal declarations of variables, and the consequential simplification of local code, although since there are no globals being looked up here, there's little to be gained from those. Is this the realm of JIT compilation, or can it be done in regular CPython? Chris Angelico From drsalists at gmail.com Tue Aug 2 13:07:44 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 10:07:44 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Tue, Aug 2, 2011 at 3:25 AM, Alistair Miles wrote: > Hi Dan, > > Thanks for the reply. > > On Mon, Aug 1, 2011 at 5:45 PM, Dan Stromberg wrote: > > > > Python 2.x, or Python 3.x? > > Currently Python 2.x. > So it sounds like you may want to move this code to 3.x in the future. > > What are the types of your sort keys? > > Both numbers and strings. > > > If you're on 3.x and the key you need reversed is numeric, you can negate > > the key. > > I did wonder about that. Would that not be doable also in Python 2.7, > using sorted(key=...)? > Yes, probably, though in 2.x it's easy to just use __cmp__. > > If you're on 2.x, you can use an object with a __cmp__ method to compare > > objects however you require. > > OK, right. > > Looking at the HowTo/Sorting again [1] and the bit about cmp_to_key, > could you also achieve the same effect by returning a key with custom > implementations of rich comparison functions? > Yes, I believe so,. though then you're back to a bit slower sorting. > > You probably should timsort the chunks (which is the standard > list_.sort() - > > it's a very good in-memory sort), and then merge them afterward using the > > merge step of merge sort. > > Yes, that's what I understood by the activestate recipe [2]. > > So I guess my question boils down to, how do you do the merge step for > a complex sort? (Assuming each chunk had been completely sorted > first.) > Open one file for each sorted list on disk. Save these files in a file_list, indexed by an integer (of course, since this is a list) - doing this means you have a mapping from an integer to a file. Read the first value from each such file. Note that one of these values will become the least value in the result list - the least value in the result file has to be the least value from one of the sorted sublists. Fill some datastructure (list, heap, treap, etc.) with tuples (value_from_sorted_list1, index_into_file_dict1), (value_from_sorted_list2, index_into_file_dict2), etc. Then pull out the least value from the list/heap/treap, and add it to the result file, and read another value from the _same_ file (which you can get back from your file_list) you got back and add a replacement tuple to your list/heap/treap. In this way, each step of the way, when merging n files, your list/heap/treap always has n values - until you reach the end of one or more of your sorted files. Then you always have less than n. When you hit EOF on some file, you just don't add anything back for that file. Resist the temptation to remove it from your file_list - that'll mess up the file indexes in the list/heap/treap. Continue as long as you have an open file. We're using a tuple instead of a class, because comparing tuples tends to be pretty fast. We're using file indexes instead of files, because I don't want to think about what happens when you compare two files with the < operator. :) Maybe the answer is also to construct a key with custom implementation > of rich comparisons? > Could be related. > Now I'm also wondering about the best way to sort each chunk. The > examples in [1] of complex sorts suggest the best way to do it is to > first sort by the secondary key, then sort by the primary key, relying > on the stability of the sort to get the desired outcome. But would it > not be better to call sorted() once, supplying a custom key function? > Function calls in CPython are expensive, so if you can sort (twice) using a key (decorate, sort, undecorate), that's probably a performance win. It's kind of a Software Engineering lose though, so using a class with one or more comparison methods can be a benefit too. > (As an aside, at the end of the section in [1] on Sort Stability and > Complex sorts, it says "The Timsort algorithm used in Python does > multiple sorts efficiently because it can take advantage of any > ordering already present in a dataset." - I get that that's true, but > I don't see how that's relevant to this strategy for doing complex > sorts. I.e., if you sort first by the secondary key, you don't get any > ordering that's helpful when you subsequently sort by the primary key. > ...?) > Agreed. Sounds irrelevant. > (Sorry, another side question, I'm guessing reading a chunk of data > into a list and using Timsort, i.e., calling list.sort() or > sorted(mylist), is quicker than using bisect to keep the chunk sorted > as you build it?) > Oh yeah. The bisection itself is just O(logn), but inserting into the correct place afterward is O(n). So unless n is tiny, you're better off with a heap or treap or red-black tree. It's the difference between an overall O(nlogn) algorithm and an O(n^2) algorithm - for large n, it's a big difference. > > heapq's not unreasonable for the merging, but I think it's more common to > > use a short list. > > Do you mean a regular Python list, and calling min()? > Yes. Depending on how many lists you wish to merge at a time. Note that in terms of file I/O, it may be faster to open as many file descriptors as you can and use a logn datastructure for the merges. But recall that you don't get infinite file descriptors, so there's a benefit to being able to do them m at a time, for some reasonable m. Merge sort is commonly written with m=2 for simplicity. > I have a bunch of Python sorts at > > http://stromberg.dnsalias.org/svn/sorts/compare/trunk/ - if you find > your > > need is specialized (EG, 3.x sorting by a secondary key that's a string, > in > > reverse), you could adapt one of these to do what you need. > > Thanks. Re 3.x sorting by a secondary key that's a string, in reverse, > which one were you thinking of in particular? > timsort is great for in-memory sorting, but the version that comes with CPython is faster than the Cython version at the URL. But there's a merge sort at the URL that you could glance at for just the merge step. But if you find you need some code you can adapt to specific needs, the timsort at the URL is probably a good option. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Aug 2 13:15:16 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Aug 2011 18:15:16 +0100 Subject: How to define repeated string when using the re module? In-Reply-To: References: Message-ID: <4E3830A4.5010103@mrabarnett.plus.com> On 02/08/2011 17:20, smith jack wrote: > if it's for a single character, this should be very easy, such as > c{m,n} the occurrence of c is between m and n, > > if i want to define the occurrence of (.*?) how should make it > done? ((.*?)){1,3} seems not work, any method to define repeat > string using python regex? Why do you think it's not working? From t at jollybox.de Tue Aug 2 13:18:20 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 19:18:20 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E38315C.1000102@jollybox.de> On 02/08/11 18:55, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. > > First off: Is there any way to request/cause some names to be bound > early? and secondly, should there be? > > Argument against: Late binding is a Good Thing, and having some things > bound early would be confusing. Also, simplicity is a good thing, and Pytho name binding and scoping is very simple. > > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. > > I would want the end programmer to have the ultimate power here (not > the module designer). Something along the lines of: This global name > will never change, so don't bother looking it up every time. What you can do, as a module author, is bind builtins/globals as default function arguments, making them local variables. def uses_len (arg0, len=len): # you could probably write a decorator that strips away this kind of # "builtin" argument As the module user, there's no way AFAIK. However, is this really useful? I suppose it would be possible to introduce a kind of "constant globals" namespace that a JIT compiler could then use to optimise, but how much would this help? If the content of this namespace is unknown at the time the module is compiled (and it would be), then only a JIT compiler could use the information - which doesn't mean it couldn't improve performance significantly in some cases. More importantly, how can the module user know which globals should be declared constant? Only the module author can know which names are looked up often enough for optimisation to make sense, or even which names are looked up at all. I think this effect can only, and best, be achieved in Python by binding relevant globals as locals in the module, and documenting which these are for the benefit of users who might want to change builtins, and would have to do it before importing the module. Thomas > > As an example of this difference, Pike uses early binding for some > things; when I did the perfect numbers testing in the other thread > (discussion thread, not thread of execution!), Pike performed > significantly better; I believe this is in part due to the formal > declarations of variables, and the consequential simplification of > local code, although since there are no globals being looked up here, > there's little to be gained from those. > > Is this the realm of JIT compilation, or can it be done in regular CPython? > > Chris Angelico From clp2 at rebertia.com Tue Aug 2 13:22:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 10:22:28 -0700 Subject: How to define repeated string when using the re module? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:20 AM, smith jack wrote: > if it's for a single character, this should be very easy, such as > c{m,n} ? the occurrence of c is between m and n, > > if i want to define the occurrence of (.*?) ?how should make it > done? ?((.*?)){1,3} ?seems not work, any method to define repeat > string using python regex? Don't parse HTML using regexes; use an HTML parser! http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags Here's a survey of Python HTML parsing libraries: http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Tue Aug 2 13:30:31 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 10:30:31 -0700 Subject: 'Use-Once' Variables and Linear Objects In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 7:19 AM, Neal Becker wrote: > I thought this was an interesting article > > http://www.pipeline.com/~hbaker1/Use1Var.html See also: http://en.wikipedia.org/wiki/Uniqueness_type Cheers, Chris From rosuav at gmail.com Tue Aug 2 13:42:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 18:42:01 +0100 Subject: Early binding as an option In-Reply-To: <4E38315C.1000102@jollybox.de> References: <4E38315C.1000102@jollybox.de> Message-ID: On Tue, Aug 2, 2011 at 6:18 PM, Thomas Jollans wrote: > I suppose it would be possible to introduce a kind of "constant > globals" namespace that a JIT compiler could then use to optimise, but > how much would this help? Surely it must help a lot; looking up names is string operations. If "len" could be replaced with "@10794928" where 10794928 is the actual address of the len object, then it'd be doing no work that isn't normally done, and would go straight to the object and call it. But I don't really know how to go about profiling this to be sure. Any ideas? Chris Angelico From thinke365 at gmail.com Tue Aug 2 14:02:09 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 02:02:09 +0800 Subject: how to sort a hash list without generating a new object? Message-ID: the source code is as follows x={} x['a'] = 11 x['c'] = 19 x['b'] = 13 print x tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by default, if i want to have a descending order, what should i do? # after sorted is called, a list will be generated, and the hash list x is not changed at all, how to convert x to a sorted hash list without generating a new object? print tmp print x From clp2 at rebertia.com Tue Aug 2 14:03:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 11:03:24 -0700 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:55 AM, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. > > First off: Is there any way to request/cause some names to be bound > early? Nope. Even if you "freeze" a variable's value via a closure, I don't believe it gets particularly optimized. > As an example of this difference, Pike uses early binding for some > things; when I did the perfect numbers testing in the other thread > (discussion thread, not thread of execution!), Pike performed > significantly better; I believe this is in part due to the formal > declarations of variables, and the consequential simplification of > local code, although since there are no globals being looked up here, > there's little to be gained from those. "in part". There are very likely additional factors at work here. Also, have you looked at Cython? I would guess that it can bypass a lot of the late binding. > Is this the realm of JIT compilation, or can it be done in regular CPython? Smart enough JITers can infer that late binding is not being exploited for certain variables and thus optimize them accordingly. Look how fast some of the JavaScript VMs are, despite JavaScript also being highly dynamic. The CPython devs are reluctant to accept the increased complexity and size of a JIT engine (see Unladen Swallow). Anything else would probably involve a similarly unpalatable level of complexity or require changing Python-the-language. I'm pretty sure optional early binding has been proposed in the past; try trawling the list archives. Cheers, Chris From t at jollybox.de Tue Aug 2 14:10:15 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 20:10:15 +0200 Subject: Early binding as an option In-Reply-To: References: <4E38315C.1000102@jollybox.de> Message-ID: <4E383D87.3060705@jollybox.de> On 02/08/11 19:42, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 6:18 PM, Thomas Jollans wrote: >> I suppose it would be possible to introduce a kind of "constant >> globals" namespace that a JIT compiler could then use to optimise, but >> how much would this help? > > Surely it must help a lot; looking up names is string operations. If > "len" could be replaced with "@10794928" where 10794928 is the actual > address of the len object, then it'd be doing no work that isn't > normally done, and would go straight to the object and call it. > > But I don't really know how to go about profiling this to be sure. Any ideas? Well, you could run a direct comparison of one function where len is global, and an identitical function where len is local (which does not do a dict lookup, am I right?) Of course the global dict lookup takes time, but I doubt that many modules look up the same name often enough for it to actually be significant. I don't really know enough about either profiling or the CPython interpreter, but I assume there's some function that's called to look up globals; you could profile the Python interpreter (don't ask me with which tool) and see how much time that function uses. Thomas From t at jollybox.de Tue Aug 2 14:12:49 2011 From: t at jollybox.de (Thomas Jollans) Date: Tue, 02 Aug 2011 20:12:49 +0200 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: <4E383E21.8020201@jollybox.de> On 02/08/11 20:02, smith jack wrote: > the source code is as follows > > x={} > x['a'] = 11 > x['c'] = 19 > x['b'] = 13 > print x > > tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by > default, if i want to have a descending order, what should i do? > # after sorted is called, a list will be generated, and the hash list > x is not changed at all, how to convert x to a sorted hash list > without generating a new object? > print tmp > print x Python dictionaries are never ordered. Perhaps the collections.OrderedDict class can do what you're looking for. http://docs.python.org/py3k/library/collections.html#collections.OrderedDict From dwblas at gmail.com Tue Aug 2 14:53:01 2011 From: dwblas at gmail.com (David) Date: Tue, 2 Aug 2011 11:53:01 -0700 (PDT) Subject: Spam References: Message-ID: <0df2e806-59f9-4d16-ad74-6a09bf03916d@g3g2000prf.googlegroups.com> If you click the "more options" link, there is an option in the sub- menu to report a post as spam. You can also forward it along with the offending e-mail address to spam at uce.gov From info at egenix.com Tue Aug 2 15:02:15 2011 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 02 Aug 2011 21:02:15 +0200 Subject: ANN: eGenix mx Base Distribution 3.2.1 (mxDateTime, mxTextTools, etc.) Message-ID: <4E3849B7.8050907@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.2.1 for Python 2.4 - 2.7 Open Source Python extensions providing important and useful services for Python programmers. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.1-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Easy to use Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.1 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. The new patch-level version includes a few important fixes: * Fixed a segfault in mxDateTime. * Fixed a possible buffer overflow in the mxDebugPrintf() function. * Fixed a problem in mxSetup mx_autoconf: Python.h was not found by some tests. If you are upgrading from eGenix mx Base 3.1.x, please also see the eGenix mx Base Distribution 3.2.0 release notes for details on what has changed and which new features are available: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on all other Python platforms, such as Solaris, AIX, HP-UX, etc. To simplify installation in Zope/Plone and other egg-based systems, we have also precompiled egg distributions for all platforms. These are available on our own PyPI-style index server for easy and automatic download. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler or the Python development packages to be installed. For a 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, Aug 02 2011) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: 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 alain at dpt-info.u-strasbg.fr Tue Aug 2 15:02:31 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 02 Aug 2011 21:02:31 +0200 Subject: Early binding as an option References: Message-ID: <87oc07wsag.fsf@dpt-info.u-strasbg.fr> Chris Angelico writes: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. This allows a huge > amount of flexibility (letting you "reach into" someone else's > function and change its behaviour), but it's flexibility that most > programs use seldom if at all. I agree with you on your last remark, but unfortunately it's part of the language. Therefore, there *are* programs that rely on the ability to rebind 'let' and others. Changing this would require changing the language, basically turning some builtins into keywords. (BTW, the dynamic binding also has implications for security.) [...] > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. Yes, and it can't do common subexpression elimination, code hoisting, etc. Basically, nothing can be optimized, and the interpreter has to execute bytecode that exactly represents source code. > I would want the end programmer to have the ultimate power here (not > the module designer). Something along the lines of: This global name > will never change, so don't bother looking it up every time. Maybe some module could provide specialized, "use-at-your-own-risk" versions of some functions/operators. An example is '+' which can mean so many things that any use of it probably spends more time finding the right version than actually doing the work. The problem with such pre-bound identifiers is that anybody with performance problems would start peppering his/her code with things like plus_float_float(x,y), leading to unreadable code, to all kinds of strange errors, etc. Nobody really wants this probably. [...] > Is this the realm of JIT compilation, or can it be done in regular > CPython? No, it's a matter of language definition. A JIT can't do much here (actually jitting is almost orthogonal to that question), at least it couldn't do much better than CPython. It just has to go through all the lookups. IIRC, unladden-swallow has tried the JIT route, using LLVM as the backend. It seems they gave up. -- Alain. From tlikonen at iki.fi Tue Aug 2 15:12:26 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 02 Aug 2011 22:12:26 +0300 Subject: Early binding as an option References: Message-ID: <871ux3ljad.fsf@mithlond.arda> * 2011-08-02T11:03:24-07:00 * Chris Rebert wrote: > Smart enough JITers can infer that late binding is not being exploited > for certain variables and thus optimize them accordingly. Look how > fast some of the JavaScript VMs are, despite JavaScript also being > highly dynamic. Or Common Lisp. It has "packages" (namespaces for symbols). All the standard symbols are in the COMMON-LISP (CL) package which is locked and can't be modified. When the Lisp reader is parsing the source code character stream it knows which package symbols belong to. So, for example, at compile time there is the information that symbol + refers to the standard CL:+ add function. There's no need to be smart. The CL package is static and set to stone but programmer is free to control symbols in other packages. For example, in some other package programmer can import all symbols from the standard CL package except shadow the CL:+ symbol. Then she can write her own extended version of + function (which possibly falls back to CL:+ in some situations). The dynamic effect with symbols is achieved through namespace tricks and yet the compiler can always trust the symbols of the CL package. I'm too much a beginner to tell if similar symbol concept is applicable to Python. From thinke365 at gmail.com Tue Aug 2 15:28:14 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 3 Aug 2011 03:28:14 +0800 Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? Message-ID: There are so many choice to do the same thing, so is there any special advantage Django brings to user? From redcat at catfolks.net Tue Aug 2 15:37:32 2011 From: redcat at catfolks.net (Redcat) Date: 2 Aug 2011 19:37:32 GMT Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? References: Message-ID: <99r1vrFrc1U1@mid.individual.net> On Wed, 03 Aug 2011 03:28:14 +0800, smith jack wrote: > There are so many choice to do the same thing, so is there any special > advantage Django brings to user? The ability to code in Python instead of Java is the biggest one to me. From tjreedy at udel.edu Tue Aug 2 16:23:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Aug 2011 16:23:21 -0400 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 8/2/2011 12:55 PM, Chris Angelico wrote: > As I understand it, Python exclusively late-binds names; when you > define a function, nothing is ever pre-bound. By 'pre-bound' you presumably mean bound at definition time rather than call time. Default arg objects *are* pre-computed and pre-bound to internal slots at definition time. > Argument in favour: Efficiency is also a Good Thing, and with staples > like 'len', it's unlikely anyone will want to change them - yet the > interpreter still has to do a namespace lookup every time. Three approaches to machine efficiency. 1. Better algorithm: Python's people efficiency makes this easier than in most other languages. 2. Hand-optimize the code that actually chew up time (as revealed by profiler). This often means removing repeated expressions *and* global names from inner loops. _len = len for line in somefile: n = _len(line) *might* give a worthwhile speedup in a function if not too much else happends in the loop. But the CPython global name lookup code (in C) has been thoroughly examined and optimized as best as several developers could think of. 3. Convert critical code to native language (or C). The idea of 'early binding' comes up periodically but I do not remember many concrete proposals. -- Terry Jan Reedy From gelonida at gmail.com Tue Aug 2 17:39:39 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:39:39 +0200 Subject: m2crypto https, xmlrpc, keep_alive Message-ID: Hi, Just started playing with m2cryptos xmlrpc The code I'm is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mynethod2(2) What I wondered is following. Will each RPC call go through all the ssl negotiation with certificate verification, etc? If yes, is there something like the concept of a keep_alive connection, that would avoid this overhead? If yes. What would I have to change in my above code. Thanks in advance for some ideas From tim at johnsons-web.com Tue Aug 2 17:47:55 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 2 Aug 2011 13:47:55 -0800 Subject: what is the advantage of Django when comparing with LAMP and J2EE platform? In-Reply-To: References: Message-ID: <20110802214755.GE14664@johnsons-web.com> * smith jack [110802 11:37]: > There are so many choice to do the same thing, so is there any special > advantage Django brings to user? Django is a python framework, J2EE is a java platform (my apologies if I use 'framework' incorrectly). Our customers want PHP,perl or python, not java. The definition for LAMP given at http://en.wikipedia.org/wiki/LAMP_(software_bundle) - for what it is worth includes python and defines LAMP as sort of generic (as I read it). Thus django *could* be considered a LAMP bundle, perhaps. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From gelonida at gmail.com Tue Aug 2 17:53:03 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:53:03 +0200 Subject: m2crypto https, xmlrpc, and cookies Message-ID: Hi, Just started playing with m2cryptos xmlrpc The code I'm using is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mynethod2(2) What I wondered is following: When using my web browser certain cookies are sent with the request. Is there any way to change my above code such, that cookies would be collected and sent? Thanks in advance for any pointers. From gelonida at gmail.com Tue Aug 2 17:59:39 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 02 Aug 2011 23:59:39 +0200 Subject: m2crypto https, xmlrpc and ignore server name mismatch Message-ID: Hi, Just started playing with m2crypto's xmlrpc The code I'm using is: import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context ctx = Context() # modify context svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mymethod2(2) What I wondered is following: For testing I would like to ignore the fact, that the hostname in the request is different from the hostname in the server certificate. On the other hand I would like to verify that the server name from the server's certidicate matches a certain criteria. What would be the code to do this. import xmlrpclib from M2Crypto.m2xmlrpclib import Server, SSL_Transport from M2Crypto.SSL.Context import Context def check_func(server_certificate): hostname = get_hostname_from_cert() return hostname.endswith('.mydomain.com') ctx = Context() # modify context # add code to ignore server name mismatch # add code to call check_func. accept request only if it returns True svr = Server(rpc_url, SSL_Transport(ctx), encoding='utf-8') svr.mymethod1(1) svr.mymethod2(2) Thanks in advance for any pointers. From rosuav at gmail.com Tue Aug 2 18:08:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 23:08:48 +0100 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy wrote: > On 8/2/2011 12:55 PM, Chris Angelico wrote: >> >> As I understand it, Python exclusively late-binds names; when you >> define a function, nothing is ever pre-bound. > > By 'pre-bound' you presumably mean bound at definition time rather than call > time. Default arg objects *are* pre-computed and pre-bound to internal slots > at definition time. Of course; that's a different issue altogether. No, I'm talking about the way a tight loop will involve repeated lookups for the same name. Unfortunately, there is no way - by definition - to guarantee that a binding won't change. Even in the example of getting the lengths of lines in a file, it's entirely possible for __len__ to rebind the global name "len" - so you can't rely on the repeated callings of len() to be calling the same function. But who WOULD do that? It's somewhat ridiculous to consider, and there's a huge amount of code out there that does these repeated calls and does not do stupid rebindings in the middle. So Python permits crazy behaviour at the cost of the performance of normal behaviour. With the local-variable-snapshot technique ("len = len"), can anything be optimized, since the parser can guarantee that nothing ever reassigns to it? If not, perhaps this would be a place where something might be implemented: @const(len,max) # maybe this def maxline(f): @const len,max # or this n = 0 for line in somefile: n = max(n,len(line)) return n Some notation like this could tell the interpreter, "I don't expect 'len' or 'max' to be rebound during the execution of this function. You're free to produce wrong results if either is." So... Would this potentially produce wrong results? Would it be of any use, or would its benefit be only valued in times when the whole function needs to be redone in C? Chris Angelico From gelonida at gmail.com Tue Aug 2 18:21:03 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:21:03 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 08/03/2011 12:08 AM, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > > @const(len,max) # maybe this > def maxline(f): > @const len,max # or this > n = 0 > for line in somefile: > n = max(n,len(line)) > return n > > Some notation like this could tell the interpreter, "I don't expect > 'len' or 'max' to be rebound during the execution of this function. > You're free to produce wrong results if either is." > > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? > > Chris Angelico I think the idea of having pragmas / directives to tell the interpreter that certain symbols could be bound early is intersting and might help optimizing some inner loops without having to explicitely assign to local vars. On the other hand: It might be interesting, that the early binding would just take place when python is invoked with -O Thus you could still do a lot of debug / tracing magic during development and only production code would do the late binding. From rosuav at gmail.com Tue Aug 2 18:26:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Aug 2011 23:26:01 +0100 Subject: Early binding as an option In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: > On the other hand: It might be interesting, that the early binding would > just take place when python is invoked with -O > This could be an excellent safety catch, but on the other hand, it might destroy all value of the feature - once again, it would be optimizing in the sole case where the code is probably better rewritten in C. Or would this be a sort of "half-way house" - this is where we need more performance, let's spend two minutes tweaking it in Python rather than dropping to C - to get some of the performance gains? ChrisA From gelonida at gmail.com Tue Aug 2 18:54:11 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:54:11 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E388013.7070506@gmail.com> On 08/03/2011 12:26 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: >> On the other hand: It might be interesting, that the early binding would >> just take place when python is invoked with -O >> > > This could be an excellent safety catch, but on the other hand, it > might destroy all value of the feature - once again, it would be > optimizing in the sole case where the code is probably better > rewritten in C. > > Or would this be a sort of "half-way house" - this is where we need > more performance, let's spend two minutes tweaking it in Python rather > than dropping to C - to get some of the performance gains? Not really sure. I would guess, that really tight inner loops should be rewritten with Cython (never tried it though) or in C if performance is really that critical. On the other hand it could be nice to get a certain performance increase with some pragmas without rendering the code completely unreadable. I have loads of places in my code, where name lookups were required only at compile time or at the first time when code is executed. For every consecutive call a cached object-reference could be used. From gelonida at gmail.com Tue Aug 2 18:54:24 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 00:54:24 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: On 08/03/2011 12:26 AM, Chris Angelico wrote: > On Tue, Aug 2, 2011 at 11:21 PM, Gelonida N wrote: >> On the other hand: It might be interesting, that the early binding would >> just take place when python is invoked with -O >> > > This could be an excellent safety catch, but on the other hand, it > might destroy all value of the feature - once again, it would be > optimizing in the sole case where the code is probably better > rewritten in C. > > Or would this be a sort of "half-way house" - this is where we need > more performance, let's spend two minutes tweaking it in Python rather > than dropping to C - to get some of the performance gains? Not really sure. I would guess, that really tight inner loops should be rewritten with Cython (never tried it though) or in C if performance is really that critical. On the other hand it could be nice to get a certain performance increase with some pragmas without rendering the code completely unreadable. I have loads of places in my code, where name lookups were required only at compile time or at the first time when code is executed. For every consecutive call a cached object-reference could be used. From xahlee at gmail.com Tue Aug 2 19:15:13 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Aug 2011 16:15:13 -0700 (PDT) Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> Message-ID: <9e715ab4-d5c7-4269-95b3-5d8e705998de@c8g2000prn.googlegroups.com> On Jul 31, 11:38 am, gavino wrote: > On Jul 13, 1:04 pm, ccc31807 wrote: > > > > > > > > > > > On Jul 12, 7:54 am, Xah Lee wrote: > > > > maybe this will be of interest. > > > > ?What Programing Language Are the Largest Website Written In??http://xahlee.org/comp/website_lang_popularity.html > > > About five years ago, I did some pretty extensive research, and > > concluded that the biggest sites were written serverside with JSP. > > Obviously, this wouldn't include The Biggest site, but if you were a > > big, multinational corporation, or listed on the NYSE, you used JSP > > for your web programming. > > > I doubt very seriously PHP is used for the biggest sites -- I'd still > > guess JSP, or maybe a MS technology (not VB), but it's only a guess. > > > CC. > > facebook is php > > myspace is microsoft > > aol was tcl and aolserver c embedding tcl interp > > priceline is lisp > > reddit is python was lisp orig > > amazon was perl > > livejournal was perl thanks Kevin. Rarely seen you useful. :) Xah From 1248283536 at qq.com Tue Aug 2 20:21:53 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 3 Aug 2011 08:21:53 +0800 Subject: pygtk Message-ID: please see my attachment ,which widget the region1,region2 is? how to make it?? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: re2 Type: application/octet-stream Size: 26111 bytes Desc: not available URL: From steve+comp.lang.python at pearwood.info Tue Aug 2 20:52:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 10:52:38 +1000 Subject: Spam References: <0df2e806-59f9-4d16-ad74-6a09bf03916d@g3g2000prf.googlegroups.com> Message-ID: <4e389bd7$0$29996$c3e8da3$5496439d@news.astraweb.com> David wrote: > If you click the "more options" link, there is an option in the sub- > menu to report a post as spam. You can also forward it along with the > offending e-mail address to spam at uce.gov What "more options" link? Are you referring to a specific program? If so, which? Remember, people are reading this via email: Thunderbird, Outlook, Outlook Express, Gmail, Yahoo Mail, Kmail, mutt, and hundreds of other programs; also via Usenet, again with multiple programs; on the web, via Google Groups or any of a dozen or so different websites. They don't all have a "more options" link. -- Steven From clp2 at rebertia.com Tue Aug 2 20:53:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Aug 2011 17:53:26 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 11:02 AM, smith jack wrote: > the source code is as follows > > x={} > x['a'] = 11 > x['c'] = 19 > x['b'] = 13 > print x > > tmp = sorted(x.items(), key = lambda x:x[0]) ? ?# ?increase order by > default, if i want to have a descending order, what should i do? Pass reverse=True. Read the find documentation for sorted(). tmp = sorted(x.items(), key=lambda x:x[0], reverse=True) > # after sorted is called, a list will be generated, and the hash list It's not a hash list (http://en.wikipedia.org/wiki/Hash_list ), it's a hash table. In Python, we call them dictionaries or dicts. > x is not changed at all, how to convert x to a sorted hash list > without generating a new object? There is no such thing as a sorted hash table (unless you're using an exotic variant). Why do you care whether it generates a new object or not? If you /really/ need a sorted mapping datatype, google for "sorteddict" (which is quite distinct from OrderedDict). Or look for a binary search tree or skip list implementation of some sort; but these aren't commonly used in Python, so it may be hard to find a good one. Cheers, Chris -- http://rebertia.com From gc1223 at gmail.com Tue Aug 2 21:45:15 2011 From: gc1223 at gmail.com (gc) Date: Tue, 2 Aug 2011 18:45:15 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? Message-ID: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Hi everyone! Longtime lurker, hardly an expert, but I've been using Python for various projects since 2007 and love it. I'm looking for either (A) suggestions on how to do a very common operation elegantly and Pythonically, or (B) input on whether my proposal is PEP-able, assuming there's no answer to A. (The proposal is sort of like the inverse of PEP 3132; I don't think it has been proposed before, sorry if I missed it.) Anyway, I frequently need to initialize several variables to the same value, as I'm sure many do. Sometimes the value is a constant, often zero; sometimes it's more particular, such as defaultdict(list). I use dict() below. Target lists using comma separation are great, but they don't work very well for this task. What I want is something like a,b,c,d,e = *dict() where * in this context means something like "assign separately to all." I'm not sure that * would the best sugar for this, but the normal meaning of * doesn't seem as if it would ever be valid in this case, and it somehow feels right (to me, anyway). Statements fitting the form above would get expanded during parsing to a sequence of separate assignments (a = dict(); b = dict(); c = dict() and so forth.) That's all there is to it. Compared to the patterns below, it's svelte, less copy-paste-y (so it removes an opportunity for inconsistency, where I remember to change a-d to defaultdict(list) but forget with e), and it doesn't require me to keep count of the number of variables I'm initializing. This would update section 6.2 of the language reference and require a small grammar expansion. But: Is there already a good way to do this that I just don't know? Below, I compare four obvious patterns, three of which are correct but annoying and one of which is incorrect in a way which used to surprise me when I was starting out. # Option 1 (separate lines) # Verbose and annoying, particularly when the varnames are long and of irregular length a = dict() b = dict() c = dict() d = dict() e = dict() # Option 2 (one line) # More concise but still pretty annoying, and hard to read (alternates variables and assignments) a = dict(); b = dict(); c = dict(); d = dict(); e = dict() # Option 3 (multiple target list: this seems the most Pythonic, and is normally what I use) # Concise, separates variables from assignments, but somewhat annoying; have to change individually and track numbers on both sides. a,b,c,d,e = dict(),dict(),dict(),dict(),dict() # Option 4 (iterable multiplication) # Looks better, and if the dict() should be something else, you only have to change it once, but the extra brackets are ugly and you still have to keep count of the targets... a,b,c,d,e = [dict()] * 5 # and it will bite you... >>> a[1] = 1 >>> b {1: 1} >>> id(a) == id(b) True # Gotcha! # Other forms of 4 also have this behavior: a,b,c,d,e = ({},) * 5 >>> a[1] = 1 >>> b {1: 1} Alternatively, is there a version of iterable multiplication that creates new objects rather than just copying the reference? That would solve part of the problem, though it would still look clunky and you'd still have to keep count. Any thoughts? Thanks! From drsalists at gmail.com Tue Aug 2 21:59:59 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 18:59:59 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E37CDCF.7060501@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it is possible to hard link directories ? > That is pretty true. I've heard of hardlinked directories on Solaris, but that's kind of an exception to the general rule. > > So presumably I would need to do a mkdir for each sub-directory > > encountered? > > Or is there an easier way to hardlink everything in a directory > > structure?. > > > > The requirement is for hard links, not symbolic links > > > > Yes, you have to mkdir everything. However, there is an easier way: > > subprocess.Popen(['cp','-Rl','target','link']) > > This is assuming that you're only supporting Unices with a working cp > program, but as you're using hard links, that's quite a safe bet, I > should think. > A little more portable way: $ cd from; find . -print | cpio -pdlv ../to cpio: ./b linked to ../to/./b ../to/./b cpio: ./a linked to ../to/./a ../to/./a cpio: ./c linked to ../to/./c ../to/./c ../to/./d cpio: ./d/1 linked to ../to/./d/1 ../to/./d/1 cpio: ./d/2 linked to ../to/./d/2 ../to/./d/2 cpio: ./d/3 linked to ../to/./d/3 ../to/./d/3 0 blocks However, you could do it without a shell command (IOW in pure python) using os.path.walk(). -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 2 22:09:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 03:09:34 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 2:45 AM, gc wrote: > Anyway, I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. If it's an immutable value (such as a constant integer), you can use syntax similar to C's chained assignment: a=b=c=0 If you do this with dict(), though, it'll assign the same dictionary to each of them - not much use. > # Option 3 (multiple target list: this seems the most Pythonic, and is > normally what I use) > # Concise, separates variables from assignments, but somewhat > annoying; have to change individually and track numbers on both sides. > > a,b,c,d,e = dict(),dict(),dict(),dict(),dict() I think this is probably the best option, although I would be inclined to use dictionary-literal syntax: a,b,c,d,e = {},{},{},{},{} It might be possible to do something weird with map(), but I think it'll end up cleaner to do it this way. Chris Angelico From steve+comp.lang.python at pearwood.info Tue Aug 2 22:15:44 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 12:15:44 +1000 Subject: with statement and context managers Message-ID: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> I'm not greatly experienced with context managers and the with statement, so I would like to check my logic. Somebody (doesn't matter who, or where) stated that they frequently use this idiom: spam = MyContextManager(*args) for ham in my_iter: with spam: # do stuff but to me that looks badly wrong. Surely the spam context manager object will exit after the first iteration, and always raise an exception on the second? But I don't quite understand context managers enough to be sure. I've tested it with two examples: # Simple example using built-in file context manager. >>> spam = open('aaa') >>> for ham in range(5): ... with spam: ... print ham ... 0 Traceback (most recent call last): File "", line 2, in ValueError: I/O operation on closed file # Slightly more complex example. >>> from contextlib import closing >>> import urllib >>> spam = closing(urllib.urlopen('http://www.python.org')) >>> for ham in range(5): ... with spam as page: ... print ham, sum(len(line) for line in page) ... 0 18486 1 Traceback (most recent call last): File "", line 3, in File "", line 3, in File "/usr/local/lib/python2.7/socket.py", line 528, in next line = self.readline() File "/usr/local/lib/python2.7/socket.py", line 424, in readline recv = self._sock.recv AttributeError: 'NoneType' object has no attribute 'recv' Am I right to expect that the above idiom cannot work? If not, what sort of context managers do work as shown? -- Steven From drsalists at gmail.com Tue Aug 2 22:20:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 19:20:19 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > On Tue, Aug 2, 2011 at 11:02 AM, smith jack wrote: > > the source code is as follows > > > > x={} > > x['a'] = 11 > > x['c'] = 19 > > x['b'] = 13 > > print x > > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which is quite distinct from OrderedDict). > Or look for a binary search tree or skip list implementation of some > sort; but these aren't commonly used in Python, so it may be hard to > find a good one. > I've found a need for such a thing a couple of times. Anyway, here are some other possibilities: http://stromberg.dnsalias.org/~dstromberg/treap/ http://pypi.python.org/pypi/bintrees/0.3.0 The treap code is considered by its author (me) production-quality, has an extensive test suite, and is known to work on CPython 2.x, CPython 3.x, PyPy and Jython. The CPython's can optionally be sped up with a Cython variant of the same code (autogenerated from a single source file using m4), and while I test on all 4 regularly, lately I mostly run it in production using the pure python version on PyPy. EG: $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import treap >>> t = treap.treap() >>> import random >>> for i in xrange(10): ... t[random.random()] = random.random() ... >>> print list(t.items()) [(0.049542221325585611, 0.60627903220498502), (0.26787423324282511, 0.95374362416785075), (0.45599886628328978, 0.57612454878587427), (0.46375501394309371, 0.28130836755784228), (0.54144253493651362, 0.47941229743653202), (0.54584770558330997, 0.49062231291462766), (0.5592476615748635, 0.39138521009523863), (0.73976131715214732, 0.99783565376628391), (0.7638117918732078, 0.55600393733208187), (0.88094790991949967, 0.90033960217787801)] >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jackdied at gmail.com Tue Aug 2 22:28:15 2011 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 2 Aug 2011 22:28:15 -0400 Subject: with statement and context managers In-Reply-To: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 2, 2011 at 10:15 PM, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > ? ?with spam: > ? ? ? ? # do stuff > [snip] > # Simple example using built-in file context manager. > >>>> spam = open('aaa') >>>> for ham in range(5): > ... ? ? with spam: > ... ? ? ? ? ? ? print ham > ... > 0 > Traceback (most recent call last): > ?File "", line 2, in > ValueError: I/O operation on closed file file_context = lambda: open('aaa') for i in range(3): with file_context(): print "hello" .. but if the context is short it is clearer and time saving to _not_ alias it. If the context is sufficiently complicated then it is worth it to make the complex code into a first class context manager - contextlib.contextmanager makes this very easy and extremely readable. -Jack From rmorgan466 at gmail.com Tue Aug 2 23:03:29 2011 From: rmorgan466 at gmail.com (Rita) Date: Tue, 2 Aug 2011 23:03:29 -0400 Subject: code generation Message-ID: Hello, This isn't much of a python question but a general algorithm question. I plan to input the following string and I would like to generate something like this. input: a->(b,c)->d output: parent a, child b c parent b c child d Are there any libraries or tools which will help me evaluate items like this better? I am mostly looking for syntax and sanity checking. Any thoughts? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue Aug 2 23:48:24 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 2 Aug 2011 20:48:24 -0700 Subject: code generation In-Reply-To: References: Message-ID: Perhaps: http://code.google.com/p/python-graph/ On Tue, Aug 2, 2011 at 8:03 PM, Rita wrote: > Hello, > > This isn't much of a python question but a general algorithm question. > > I plan to input the following string and I would like to generate something > like this. > > input: a->(b,c)->d > output: > parent a, child b c > parent b c child d > > Are there any libraries or tools which will help me evaluate items like > this better? I am mostly looking for syntax and sanity checking. > > Any thoughts? > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Wed Aug 3 00:22:42 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Aug 2011 05:22:42 +0100 Subject: with statement and context managers References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 03 Aug 2011 12:15:44 +1000, Steven D'Aprano wrote: > I'm not greatly experienced with context managers and the with statement, so > I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently use this > idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > with spam: > # do stuff > > > but to me that looks badly wrong. Surely the spam context manager object > will exit after the first iteration, and always raise an exception on the > second? But I don't quite understand context managers enough to be sure. It depends upon the implementation of MyContextManager. If it's implemented using the contextlib.contextmanager decorator, then you're correct: you can only use it once. OTOH, if you implement your own class with __enter__ and __exit__ methods, you can use the same context manager object multiple times. From kushal.kumaran+python at gmail.com Wed Aug 3 02:32:07 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 3 Aug 2011 12:02:07 +0530 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: > > On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: >> >> On 02/08/11 11:32, loial wrote: >> > I am trying to hardlink all files in a directory structure using >> > os.link. >> > >> > However I do not think it is possible to hard link directories ? > > That is pretty true.? I've heard of hardlinked directories on Solaris, but > that's kind of an exception to the general rule. > In APUE, Richard Stevens says only root could do this, if it is supported by the system at all. In a footnote, he additionally mentions he screwed up his filesystem by creating a loop of hardlinked directories while writing that section of the book. I suppose it is a good thing systems don't allow that now. -- regards, kushal From wuwei23 at gmail.com Wed Aug 3 02:52:33 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Aug 2011 23:52:33 -0700 (PDT) Subject: PyWart: os.path needs immediate attention! References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> Message-ID: <7034abec-975d-4ed6-9cb7-7cc54ff4ef7b@s21g2000pre.googlegroups.com> Andrew Berg wrote: > He hasn't replied to his last two troll threads, though. It does seem > odd to write a wall of text and then not respond to replies. To be fair, > though, most replies either mock him or point out that he's a troll. :D His recent rants do seem a lot more Xah-Lee-like; a huge nonsensical diatribe that badly applies logic to try and mask its emotive agenda. A lot of the same "great mind struggling against the tyranny of idiots" subtext too. Not so much swearing though. From nobody at nowhere.com Wed Aug 3 03:04:59 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Aug 2011 08:04:59 +0100 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > However I do not think it is possible to hard link directories ? Modern Unices disallow hard links to directories, as it makes the directory "tree" not a tree, so anything which performs a recursive walk must explicitly check for cycles to avoid infnite recursion. Older systems which allowed hard links to directories required root privilege to do so. From ulrich.eckhardt at dominolaser.com Wed Aug 3 03:14:59 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 03 Aug 2011 09:14:59 +0200 Subject: python import error, what's wrong? References: Message-ID: smith jack wrote: > I am using pydev plugin in eclipse, all things works just as well > but now i have confronted with a confusing problem, that is i can > import a module write by myself successfully, but when i try to run > this program, > error just shows up, what's wrong? > > the directory structure is as follows: > > src > org.test > A.py > org.lab > B.py Python uses a dot as separator between different parts of nested structures, like e.g. the directories during import. I guess your directory naming conflicts with that. Try this structure instead: src org test A.py lab B.py or maybe src org_test A.py org_lab B.py > contents of A seems like: > class A > ... > > contents of B seems like: // I try to run B.py, > python import error just appears, why? "just appears" is not a sufficient discription of an error. I'd suggest reading Eric S. Raymond's excellent essay on "Asking Smart Questions", it will avoid such mistakes. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ben+python at benfinney.id.au Wed Aug 3 03:45:40 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Aug 2011 17:45:40 +1000 Subject: python import error, what's wrong? References: Message-ID: <871ux3kkez.fsf@benfinney.id.au> Ulrich Eckhardt writes: > > the directory structure is as follows: > > > > src > > org.test > > A.py > > org.lab > > B.py > > Python uses a dot as separator between different parts of nested > structures, like e.g. the directories during import. More generally, the name of a module must be a valid Python identifier. Hence, the module-name part of a directory or of a filename must also be a valid Python identifier. The ?.? (U+002E FULL STOP) character is not valid in an identifier. -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?? ?_Pinky and The Brain_ | Ben Finney From steve+comp.lang.python at pearwood.info Wed Aug 3 04:25:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 18:25:51 +1000 Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> gc wrote: > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() a, b, c, d, e = [dict() for i in range(5)] Unfortunately there is no way of doing so without counting the assignment targets. While slightly ugly, it doesn't seem ugly enough to justify the extra complexity of special syntax for such a special case. -- Steven From greg.ewing at canterbury.ac.nz Wed Aug 3 04:29:19 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Aug 2011 20:29:19 +1200 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <99sf72Fo87U1@mid.individual.net> gc wrote: > Alternatively, is there a version of iterable multiplication that > creates new objects rather than just copying the reference? You can use a list comprehension: a, b, c, d, e = [dict() for i in xrange(5)] or a generator expression: a, b, c, d, e = (dict() for i in xrange(5)) -- Greg From katriel at katriel.co.uk Wed Aug 3 04:36:19 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Wed, 3 Aug 2011 09:36:19 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > gc wrote: > > > Target lists using comma separation are great, but they don't work > > very well for this task. What I want is something like > > > > a,b,c,d,e = *dict() > > a, b, c, d, e = [dict() for i in range(5)] > I think this is good code -- if you want five different dicts, then you should call dict five times. Otherwise Python will magically call your expression more than once, which isn't very nice. And what if your datatype constructor has side-effects? Katriel -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrinalini at edss.co.in Wed Aug 3 04:58:48 2011 From: mrinalini at edss.co.in (mrinalini at edss.co.in) Date: Wed, 03 Aug 2011 14:28:48 +0530 Subject: Dynamically linking python into my vc project - help required Message-ID: <6cafe6745022b37909647db99073fc87@edss.co.in> Hi, I am trying to embed python into my MFC application. I have done this before by statically linking to the python lib. But I want to change this now. The idea is to take the information from the registry for the installed version of python on the target machine. Then load python using loadlibrary call and use the functions from python using pointers to functions returned by GetProcAddress . For example - hModPython = AfxLoadLibrary("Python23.dll"); pFnPyRun_SimpleString *pFunction = NULL; pFnPy_Initialize *pPy_Initialize = NULL; pFunction = (pFnPyRun_SimpleString *)::GetProcAddress(hModPython, "PyRun_SimpleString"); pPy_Initialize = (pFnPy_Initialize *)::GetProcAddress(hModPython, "Py_Initialize"); try { pPy_Initialize(); if ( pFunction ) { (*pFunction)("import sys"); // call the code } else { AfxMessageBox("unable to access function from python23.dll.", MB_ICONSTOP|MB_OK); } } catch(...) { } And then I want to execute a python script through my MFC application - HANDLE hFile = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwSize = GetFileSize(hFile, NULL); DWORD dwRead; char *s = new char[dwSize +1]; ReadFile(hFile, s, dwSize, &dwRead, NULL); s[dwSize] = '\0'; CString wholefile(s); wholefile.Remove('\r'); wholefile+="\n"; CloseHandle(hFile); pFnPy_CompileString *pFPy_CompileString = (pFnPy_CompileString *)::GetProcAddress(hModPython, "Py_CompileString"); CString fl(file); PyObject* pCodeObject = pFPy_CompileString(wholefile.GetBuffer(0), fl.GetBuffer(0), Py_file_input); if (pCodeObject != NULL) { pFnPyEval_EvalCode *pFPyEval_EvalCode = (pFnPyEval_EvalCode *)::GetProcAddress(hModPython, "PyEval_EvalCode"); PyObject* pObject = pFPyEval_EvalCode((PyCodeObject*)pCodeObject, m_Dictionary, m_Dictionary); } I am facing two problems here , though I want to link to python dynamically I am required to include python.h for my code to compile the following declaration. PyObject* pCodeObject I tried copying some of the python definitions including PyObject into a header in my mfc app. Then it complies fine. but Py_CompileString call fails. so finally I am unable to run script from my MFC application by linking to python dynamically. How can this be done ? Please help. Is there a different approach to linking to python dynamically. Please could you write to me ? Thanks in advance, Mrinalini From rosuav at gmail.com Wed Aug 3 04:58:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 09:58:53 +0100 Subject: Early binding as an option In-Reply-To: References: <4E38315C.1000102@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 5:46 AM, Dennis Lee Bieber wrote: > ? ? ? ?Horrors... That looks like some MUF code I've seen (I never had a > MUF flag on my old characters, so had no privilege to write in MUF -- > MPI was available to all, and even it had some links to MUF operations > using similar magic numbers). > Hehe. I didn't mean that it should be thus in the source code, but that some simple notation would tell the interpreter that it can make that translation in memory - at the tokenization stage, or perhaps when the function is invoked. The idea is that the interpreter can skip one step - the step of taking the name "len", looking it up, and finding the object that it represents. It can do that part of the work once, and patch in the function's address somewhere as a special token - right into the tokenized source code. Parenthesis: Reading the Wikipedia article on MUF shows that it has a number of similarities to what I do today in coding my MUD - I have an extremely rudimentary editor interface (smart editing is done on the client), submit my code to the server, compile it, and invoke it - and it's governed by permissions bits. However, I use a rather better language than MUF :) ChrisA From stefan_ml at behnel.de Wed Aug 3 05:33:21 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 11:33:21 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: Chris Angelico, 03.08.2011 00:08: > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? Note that, in most cases, you do not need to "redo the whole function in C". You can just use Cython to compile it, thus leaving it in Python syntax and keeping up Python semantics, unless you decide to explicitly divert from them in favour of optimisations. Stefan From gelonida at gmail.com Wed Aug 3 05:40:48 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 11:40:48 +0200 Subject: Text to image with same results on any platform Message-ID: Hi, >From within a django application I'd like create a small image file (e.g. .png) which just contains some text. I wondered what library would be appropriate and would yield the same result independent of the OS (assuming the versions of the python libraries are the same) Images should be pixel identical independent on the platform on which the image is created. I made some attempts with PIL (Image / ImageFont / ImageDraw), but have difficulties getting the same font under Linux and windows. # ------------------------code starts here import Image import ImageFont import ImageDraw # Here I don't know how to get the same font file # for all platforms # Perhaps there is a tiny trick that I overlooked. font_file = get_font_file_name() # Is truetype a good choice for portable fonts? font = ImageFont.truetype(font_file, 20) img = Image.new("RGB", (800, 600), "#FFFFFF") draw = ImageDraw.Draw(image) draw.text( (100, 100), font=font, fill="#00FF00") # ---------------------------- end of code I could also install any other library (matplotlib??) if it were capable of creating consistent images independent on the platform. Thanks in advance for any suggestions. From t at jollybox.de Wed Aug 3 05:47:31 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 11:47:31 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: <4E391933.6070603@jollybox.de> On 03/08/11 03:59, Dan Stromberg wrote: > > On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans > wrote: > > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it is possible to hard link directories ? > > > That is pretty true. I've heard of hardlinked directories on Solaris, > but that's kind of an exception to the general rule. > > > > So presumably I would need to do a mkdir for each sub-directory > > encountered? > > Or is there an easier way to hardlink everything in a directory > > structure?. > > > > The requirement is for hard links, not symbolic links > > > > Yes, you have to mkdir everything. However, there is an easier way: > > subprocess.Popen(['cp','-Rl','target','link']) > > This is assuming that you're only supporting Unices with a working cp > program, but as you're using hard links, that's quite a safe bet, I > should think. > > > A little more portable way: > > $ cd from; find . -print | cpio -pdlv ../to > cpio: ./b linked to ../to/./b > ../to/./b > cpio: ./a linked to ../to/./a > ../to/./a > cpio: ./c linked to ../to/./c > ../to/./c > ../to/./d > cpio: ./d/1 linked to ../to/./d/1 > ../to/./d/1 > cpio: ./d/2 linked to ../to/./d/2 > ../to/./d/2 > cpio: ./d/3 linked to ../to/./d/3 > ../to/./d/3 > 0 blocks > > However, you could do it without a shell command (IOW in pure python) > using os.path.walk(). Is it more portable? I don't actually have cpio installed on this system. Which implementations of cp don't implement -R and -l? Of course, the best way is probably implementing this in Python, either with os.path.walk, or with a monkey-patched shutil.copytree, as Peter suggested. Thomas From gelonida at gmail.com Wed Aug 3 05:52:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Wed, 03 Aug 2011 11:52:46 +0200 Subject: PyWart: os.path needs immediate attention! In-Reply-To: References: <14874f59-a836-4031-a8c9-6b24f4d5e812@d7g2000vbv.googlegroups.com> <1311971809-sup-1144@2d2a55d49a8018d83ffdd9e06d> Message-ID: On 07/29/2011 11:43 PM, Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:44 AM, Corey Richardson wrote: >> Excerpts from rantingrick's message of Fri Jul 29 13:22:04 -0400 2011: >>> * New path module will ONLY support one path sep! >> >> People who use windows are used to \ being their pathsep. If you show >> them a path that looks like C:/whatever/the/path in an app, they are >> going to think you are nuts. It isn't up to us to decide what anyone >> uses as a path separator. They use \ natively, so should we. If at >> any point Windows as an OS starts using /'s, and not support, actually >> uses (in Windows Explorer as default (or whatever the filebrowser's >> name is)), it would be great to switch over. > > Just tested this: You can type c:/foldername into the box at the top > of a folder in Explorer, and it works. It will translate it to > c:\foldername though. > > We are not here to talk solely to OSes. We are here primarily to talk > to users. If you want to display a path to the user, it's best to do > so in the way they're accustomed to - so on Windows, display > backslashes. > >>> - normcase --> path = path.lower() >> >> Not quite, here are a few implementations of normcase (pulled from 2.7) >> >> # NT >> return s.replace("/", "\\").lower() >> >> # Mac (Correct in this case) >> return path.lower() >> >> # POSIX >> return s >> >> But I can't think of where I would ever use that. Isn't case important on >> Windows? > well normcase might help to find out, whether two filenames are the same. under unix 'myfile' and 'myFile' would be different under windows they would refer to the same file. normcase (perhaps to be combined with normpath) can tel you this. From t at jollybox.de Wed Aug 3 06:00:05 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 12:00:05 +0200 Subject: Early binding as an option In-Reply-To: References: Message-ID: <4E391C25.9070702@jollybox.de> On 03/08/11 00:08, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > [...] Yes, it can. The parser can know when it is reassigned to just by looking at the one function, and even if it didn't, or if it were reassigned, it wouldn't make much of a difference because the interpreter would still only have to fetch one of a set of locals known at compile time, which can be (is? I'm not sure) as simple as an array lookup: two pointers being dereferences instead of one. Chris Rebert raises a very important point though: Python dynamic namespaces make optimising variable lookup comparatively difficult, but not impossible: good JavaScript JITs are smart enough, so a good Python JIT could be as well. Thomas From steve+comp.lang.python at pearwood.info Wed Aug 3 06:16:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 03 Aug 2011 20:16:46 +1000 Subject: Early binding as an option References: Message-ID: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy wrote: >> On 8/2/2011 12:55 PM, Chris Angelico wrote: >>> >>> As I understand it, Python exclusively late-binds names; when you >>> define a function, nothing is ever pre-bound. >> >> By 'pre-bound' you presumably mean bound at definition time rather than >> call time. Default arg objects *are* pre-computed and pre-bound to >> internal slots at definition time. > > Of course; that's a different issue altogether. No, I'm talking about > the way a tight loop will involve repeated lookups for the same name. It's not really a different issue. The "standard" approach for performing early binding in Python is by binding a global name to a local name at function definition time. In CPython at least, local lookups are faster than globals: locals are stored in a fixed array, and the function knows the numeric offset of each variable. Non-locals have to search multiple namespaces (globals + built-ins), using a hash table. That's fast, but locals are faster. (Aside: this is why locals() is not generally writable: the dict is a copy of that internal array. You can write to the dict, but the changes don't propagate back to the actual local table of the function.) So a good way to speed up name lookups is to turn a global into a local, and one common way to do that is to do it when the function is defined. For example, you will see this in the random module: def randrange(self, start, stop=None, step=1, int=int, default=None, maxwidth=1< Unfortunately, there is no way - by definition - to guarantee that a > binding won't change. Even in the example of getting the lengths of > lines in a file, it's entirely possible for __len__ to rebind the > global name "len" - so you can't rely on the repeated callings of > len() to be calling the same function. > > But who WOULD do that? It's somewhat ridiculous to consider, and > there's a huge amount of code out there that does these repeated calls > and does not do stupid rebindings in the middle. So Python permits > crazy behaviour at the cost of the performance of normal behaviour. This is a common criticism of Python, and the truth be told, it is right: Python makes crazy monkey-patching that we're told not to do easy, at the expense of allowing the compiler to optimise really common things. But, are you *sure* that name lookups are *really* the bottleneck? Name lookups are pretty fast. If you want them faster, turn them into a local variable. It's not clear to me that syntax, or a pragma directive, or some other form of magic, is better than an explicit assignment: def func(x): _len = len # bind at function call time for i in x: _len(i) # lookups of _len will be faster than len The argument that Python would be faster if it did early binding is not a given. For trivial code that doesn't do much, I dare say it might shave off a significant percentage, but trivial code is already pretty fast. Who cares if you speed up a trivial operation? In non-trivial code that does real work, it's not obvious that early binding will result in meaningful time savings. ("Yay, my code now runs in 17.1 milliseconds instead of 17.2!") The onus is on the person proposing this change to prove that the benefit is worth the extra complexity. Knowing what we know now, I'm not sure whether Guido would have kept the late binding semantics for Python, or privileged builtins in some fashion. I suspect that he wouldn't have changed a thing, but if he did, I suspect he'd be more concerned about accidental shadowing of builtins than about optimizations. E.g. people say list = [1,2,3], and then later try to call list(something). Or maybe that's just me :) Guido is generally very, very suspicious about proposed optimisations. They tend to increase the code's complexity by far more than they increase its speed. (E.g. an order of magnitude more complex to get 10% speed increase.) And they often subtly break the semantics of the code. E.g. if you do floating point maths, optimizing compilers that assume that x + y - x equals y are BROKEN. > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? Very likely. But the optimization happens at runtime, not at compile time. Default values for parameters are stored as an attribute of the function at definition time. So if you have this: def f(x, len=len): return len(x) then f gets a publicly accessible attribute func_defaults: >>> f.func_defaults (,) Even if you re-bind len, that doesn't change the binding here, and the *local* variable len will be assigned that value when f is called. Here's a practical example: >>> def test(len=len): ... while True: ... yield len ... >>> >>> it = test() >>> next(it) >>> len = None # rebind the global len >>> next(it) >>> test.func_defaults = (None, ) >>> next(it) But note that now as I've replaced the default value, the next time I call test() I'll get len=None. [...] > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? You really would need to demonstrate that the bottleneck in useful code (as opposed to toy examples) was the name lookups. -- Steven From rosuav at gmail.com Wed Aug 3 07:04:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 12:04:50 +0100 Subject: Early binding as an option In-Reply-To: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 11:16 AM, Steven D'Aprano wrote: > Chris Angelico wrote: >> Of course; that's a different issue altogether. No, I'm talking about >> the way a tight loop will involve repeated lookups for the same name. > > It's not really a different issue. The "standard" approach for performing > early binding in Python is by binding a global name to a local name at > function definition time. Thanks for the detailed response! My concept was that this wouldn't affect the dynamism significantly, and that if the function's caller wanted to change the definition of 'len', s/he could still do so; the "snapshotting" would occur as the function begins executing. This would make things rather safer, as there's a limited window during which this could affect things. > In CPython at least, local lookups are faster > than globals: locals are stored in a fixed array, and the function knows > the numeric offset of each variable. Ah! I was not aware of this, and thought that locals were a dictionary too. Of course, it makes a lot of sense. In that case, the classic "grab it as a local" isn't just loading down the locals dictionary with more names and thus slower lookups. > ? ? ? ?Do not supply the 'int', 'default', and 'maxwidth' arguments. > ? ? ? ?""" I love the way Python doesn't stop you from doing stupid things. This is an invitation to do something... hmm. >>> random.randrange(5,10,1,int=lambda x: (print(x),int(x))[1]) > But, are you *sure* that name lookups are *really* the bottleneck? Name > lookups are pretty fast. If you want them faster, turn them into a local > variable. It's not clear to me that syntax, or a pragma directive, or some > other form of magic, is better than an explicit assignment: No, I'm not sure. Unfortunately I have no convenient way to compare; all I can do is compare with a completely different language, which is of course NEVER going to be fair. The only actual data I have on the subject is the perfect-numbers search the other day; Pike managed the same task in a fraction of the time that Python spent on it. Pike has a single integer type that quietly switches from small to large at 2**32, with a noticeable performance change. This is the same as Python 2, but could explain some of the Python 3 penalty. There's only two obvious possibilities (there may be others, of course): firstly, that the actual name lookup is expensive; and secondly, that Pike is able to optimize integer arithmetic by knowing that the value in question is an int, and it will never be anything else. Since I was under the impression that local variables were stored in a hash table, I concluded that the first option was reasonably likely, and tried to get more data. >> So... Would this potentially produce wrong results? Would it be of any >> use, or would its benefit be only valued in times when the whole >> function needs to be redone in C? > > You really would need to demonstrate that the bottleneck in useful code (as > opposed to toy examples) was the name lookups. And especially, prove that the same can't be done with local variables. So which is the better idiom? def func(x): _len = len # bind at function call time for i in x: _len(i) # lookups of _len will be faster than len or: def func(x): len = len # localize len for i in x: len(i) # use it exactly as you otherwise would In other words, is it "Explicit is better than implicit" or "Simple is better than complex"? Since this does absolutely exactly the same thing as the original, I'd be inclined to go with the second form; a single line at the top of the function, with an explanatory comment perhaps, and the rest of the code is unaware of the optimization. But this has the potential to be insanely confusing if anything goes wrong, because down in the body of the function there's no clue that anything was changed. Unfortunately I can't offer any real-world use cases or examples. This is purely a thought experiment at the moment. Chris Angelico From python.list at tim.thechases.com Wed Aug 3 07:15:46 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Aug 2011 06:15:46 -0500 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E392DE2.7080006@tim.thechases.com> On 08/03/2011 03:25 AM, Steven D'Aprano wrote: > gc wrote: > >> Target lists using comma separation are great, but they don't work >> very well for this task. What I want is something like >> >> a,b,c,d,e = *dict() > > > a, b, c, d, e = [dict() for i in range(5)] > > Unfortunately there is no way of doing so without counting the assignment > targets. While slightly ugly, it doesn't seem ugly enough to justify the > extra complexity of special syntax for such a special case. I understand that in Py3k (and perhaps back-ported into later 2.x series?) one can do something like a, b, c, d, e, *junk = (dict() for _ in range(9999)) to prevent the need to count. However, I was disappointed with all the generator-ification of things in Py3k, that this "and the rest" syntax slurps up the entire generator, rather than just assigning the iterator. That would much more tidily be written as a,b,c,d,e, *more_dict_generator = (dict() for _ in itertools.count()) (itertools.count() happening to be a infinite generator). I can see the need to slurp if you have things afterward: a,b,c, *junk ,d,e = iterator(...) but when the "and the rest" is the last one, it would make sense not to force a slurp. -tkc From python.list at tim.thechases.com Wed Aug 3 07:25:34 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Aug 2011 06:25:34 -0500 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E39302E.9090602@tim.thechases.com> On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: > On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: >> a, b, c, d, e = [dict() for i in range(5)] > > I think this is good code -- if you want five different dicts, > then you should call dict five times. Otherwise Python will > magically call your expression more than once, which isn't > very nice. And what if your datatype constructor has > side-effects? If the side-effects are correct behavior (perhaps opening files, network connections, or even updating a class variable) then constructor side-effects are just doing what they're supposed to. E.g. something I use somewhat regularly in my code[*]: a,b,c,d = (file('file%i.txt', 'w') for i in range(4)) If the side-effects aren't performing the correct behavior, fix the constructor. :) -tkc [*] okay, it's more like (features, adjustments, internet, ) = (file(fname) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) or even (features, adjustments, internet, ) = ( set( line.strip().upper() for line in file(fname) if line.strip() ) for fname in ( 'features.txt', 'adjustments.txt', 'internet.txt' ) to load various set() data from text-files. From stefan_ml at behnel.de Wed Aug 3 08:21:23 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 14:21:23 +0200 Subject: Early binding as an option In-Reply-To: <4E391C25.9070702@jollybox.de> References: <4E391C25.9070702@jollybox.de> Message-ID: Thomas Jollans, 03.08.2011 12:00: > JavaScript JITs are smart enough, so a good Python > JIT could be as well. Why "could"? There's PyPy if you need it. Stefan From eudes.elie at gmail.com Wed Aug 3 08:39:51 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Wed, 3 Aug 2011 05:39:51 -0700 (PDT) Subject: timeout issue with modules dbus & gobject Message-ID: Hi, Here is a sample code that reproduces the issue : [code] import logging import unittest import signal import gobject import dbus from functools import wraps from dbus.mainloop.glib import DBusGMainLoop class TimeoutException(Exception): pass def timeout(timeout_time=1800): """ decorator function catching the argument """ def timeout_function(func): """ decorator function """ @wraps(func) def _timeout_function(self): """ create a signal handler set the timeout with the argument given while calling the decorator @timeout call the function catch a timeout exception if necessary """ def timeout_handler(signum, frame): print 'Timeout (%s sec) reached' % str(timeout_time) raise TimeoutException() old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(timeout_time) # triger alarm in timeout_time seconds try: retval = func(self) finally: signal.signal(signal.SIGALRM, old_handler) signal.alarm(0) return retval return _timeout_function return timeout_function class Test_loopRun_And_Timeout(unittest.TestCase): def __init__(self,*args,**kwargs): super(Test_loopRun_And_Timeout, self).__init__(*args,**kwargs) dbus_loop = DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus(private=True,mainloop=dbus_loop) self.loop = gobject.MainLoop() logging.basicConfig() self.__logger = logging.getLogger("Tests.%s" % self.__class__.__name__) self.__logger.setLevel(logging.DEBUG) def setUp(self): ''' in this part, mediarouter can not be created Setup are all launch in // So if 50 tests are run in this class, 50 mediarouters are created ''' pass def tearDown(self): ''' ''' @timeout(5) def test_001(self): ''' ''' self.__logger.info('[CHECKPOINT] test_001') try: self.__logger.info('entering a waiting loop') self.loop.run() self.__logger.info('dummy log, should not appear') self.fail() except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') except : self.__logger.exception('Unexpected error') self.fail() @timeout(5) def test_002(self): ''' ''' def loop_quit(loop): loop.quit() return False self.__logger.info('[CHECKPOINT] test_002') try: self.__logger.info('entering a waiting loop') gobject.timeout_add(1000, loop_quit, self.loop) self.loop.run() self.__logger.info('exiting the loop') except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') self.fail() except : self.__logger.exception('Unexpected error') self.fail() [/code] If I start a unittest campaign like this : [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_002')) suite.addTest(Test_loopRun_And_Timeout('test_001')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] the result give me 2 tests OK Now If I launch this [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_001')) suite.addTest(Test_loopRun_And_Timeout('test_002')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] 1 OK (test_001) 1 Fail (test_002 goes on timeout) And if I am using more than 3 Testcases, the code is going to run in infinite loop (Ctrl+C or timeout decorator does not work, only a kill works) Is there an issue using the 'timeout' decorator with the loop.run() ? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Aug 3 08:42:57 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 03 Aug 2011 14:42:57 +0200 Subject: with statement and context managers In-Reply-To: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 03.08.2011 04:15 schrieb Steven D'Aprano: > I'm not greatly experienced with context managers and the with > statement, so I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently > use this idiom: > > spam = MyContextManager(*args) > for ham in my_iter: > with spam: > # do stuff > > > but to me that looks badly wrong. Surely the spam context manager > object will exit after the first iteration, and always raise an > exception on the second? But I don't quite understand context > managers enough to be sure. Depends on the implementation. As already stated, a contextlib.contextmanager will only run once. But it is easy to turn it into a persistent one - which internally initializes as often as needed. class PersistentCM(object): def __init__(self, target): self.target = target self.current = [] def __enter__(self): cm = self.target() cm.__enter__() self.current.append(cm) def __exit__(self, *e): return self.current.pop(-1).__exit__(*e) (untested) This would allow for a CM to be used multiple times. It internally generates a new one on every __enter__() call and disposes of it on every __exit__(). As __enter__() and __exit__() are supposed to be used symmetrical, it should(!) work this way. Many CMs don't allow your shown use, though, partly due to obvious reasons: * The ...ing named ones do the action they are named after in the __exit__() part and do nothing in the __enter__() part. (E.g. closing.) * The ...ed named ones do the named action in __enter__() and undo it in __exit__(). They may or may not work multiple times. For example, take threading.Lock et al., which you can have locked several times. >>>> spam = open('aaa') >>>> for ham in range(5): > ... with spam: > ... print ham > ... > 0 > Traceback (most recent call last): > File "", line 2, in > ValueError: I/O operation on closed file To be honest, this one I don't understand as well. __exit__() closes the file spam, but even before "print ham" can be executed for a second time, there is a check if the file is still open. What does __enter__() do here? Just check if it is closed, or is it more? Nevertheless, it makes sense. > # Slightly more complex example. > >>>> from contextlib import closing >>>> import urllib >>>> spam = closing(urllib.urlopen('http://www.python.org')) >>>> for ham in range(5): > ... with spam as page: > ... print ham, sum(len(line) for line in page) > ... > 0 18486 > 1 > Traceback (most recent call last): > File "", line 3, in > File "", line 3, in > File "/usr/local/lib/python2.7/socket.py", line 528, in next > line = self.readline() > File "/usr/local/lib/python2.7/socket.py", line 424, in readline > recv = self._sock.recv > AttributeError: 'NoneType' object has no attribute 'recv' Here the above said applies: after closing happens in __exit__() and _sock gets set to None, the object is not usable any longer. > Am I right to expect that the above idiom cannot work? If not, what sort of > context managers do work as shown? As said, take threading.Lock as an example: they can be acquire()d and release()d as often as you want, and these actions happen in __enter__() and __exit__(), respectively. HTH, Thomas From phlip2005 at gmail.com Wed Aug 3 09:13:24 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 06:13:24 -0700 (PDT) Subject: attach cString to memoryview? Message-ID: <4232b39e-e07c-4e12-92e3-1e7b035422a6@a2g2000prf.googlegroups.com> HypoNt; My ulterior motive is the perfect command spawner: def call_4(cmd): import cStringIO # memoryview type # New in version 2.7. v = memoryview('abcefg') q = cStringIO.StringIO() p = Popen(cmd, shell=True, stdout=q, bufsize=4096) def check_me(): # consider: examine p or v here return q.read() return check_me # check_it = call_4('ls') # check_it() assert 'fabfile.py' in call_4('ls')() # Look, ma! No self.! The Subject line problem refers to how to get rid of this: AttributeError: 'cStringIO.StringO' object has no attribute 'fileno' To give it one, plug in a memoryview, right? Pencils down in 15 minutes, okay? Go! While I'm googling up a more mundane (and less performant) solution with a normal file... Distractingly yrs- -- Phlip http://bit.ly/ZeekLand From jayronsoares at gmail.com Wed Aug 3 09:26:26 2011 From: jayronsoares at gmail.com (Jayron Soares) Date: Wed, 3 Aug 2011 10:26:26 -0300 Subject: parsing in python Message-ID: Hi folks, I've created a simple method to grab files texts from directory by words random, however I figure out that I need extract the content inside of each file, in fact I believe I have to create a parsing, nonetheless I don't know how to create a parser. Please some could share some tips to do it? Cheers Jayron here is the code: # -*- conding: utf-8 -*- from subprocess import Popen, PIPE pesquisa = raw_input(" Digite a pesquisa de interesse: ") def Pesquisar(pesquisa): p = Popen(["search", pesquisa],stdout=PIPE) resultado = p.communicate()[0] return resultado print Pesquisar(pesquisa) -- *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* http://bucolick.tumblr.com http://artecultural.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 3 09:41:55 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 15:41:55 +0200 Subject: attach cString to memoryview? References: <4232b39e-e07c-4e12-92e3-1e7b035422a6@a2g2000prf.googlegroups.com> Message-ID: Phlip wrote: > q = cStringIO.StringIO() > p = Popen(cmd, shell=True, stdout=q, bufsize=4096) > The Subject line problem refers to how to get rid of this: > > AttributeError: 'cStringIO.StringO' object > has no attribute 'fileno' What's wrong with subprocess.PIPE? >>> import subprocess as sp >>> p = sp.Popen(["ls", "/usr/lib/python2.6"], stdout=sp.PIPE) >>> print p.communicate()[0] From invalid at invalid.invalid Wed Aug 3 10:22:57 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Aug 2011 14:22:57 +0000 (UTC) Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: On 2011-08-03, Kushal Kumaran wrote: > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: >> >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: >>> >>> On 02/08/11 11:32, loial wrote: >>> > I am trying to hardlink all files in a directory structure using >>> > os.link. >>> > >>> > However I do not think it is possible to hard link directories ? >> >> That is pretty true.?? I've heard of hardlinked directories on Solaris, but >> that's kind of an exception to the general rule. > > In APUE, Richard Stevens says only root could do this, Yep, in early versions of Solaris root could hard-link directories. I did it once, and it's not something one did a second time. fsck couldn't deal with it and pretty much fell over. IIRC, the only way to recover was to clear several inodes manually and then let fsck salvage things. > if it is supported by the system at all. In a footnote, he > additionally mentions he screwed up his filesystem by creating a loop > of hardlinked directories while writing that section of the book. That sounds about right. > I suppose it is a good thing systems don't allow that now. It wouldn't be a problem, except there are some important places in Unix where it is assume that filesystems are trees. Hard linking directories causes that assumption to be false. -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From t at jollybox.de Wed Aug 3 11:08:48 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 17:08:48 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: <4E396480.3060108@jollybox.de> On 03/08/11 16:22, Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: >> I suppose it is a good thing systems don't allow that now. > > It wouldn't be a problem, except there are some important places in > Unix where it is assume that filesystems are trees. Hard linking > directories causes that assumption to be false. > It is generally assumed that ".." is clearly defined, i.e. that every directory has a parent. With hard linked directories, this would break down. From phlip2005 at gmail.com Wed Aug 3 11:29:08 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 08:29:08 -0700 (PDT) Subject: Snippet: The leanest Popen wrapper Message-ID: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Groupies: This is either a code snippet, if you like it, or a request for a critique, if you don't. I want to call a command and then treat the communication with that command as an object. And I want to do it as application-specifically as possible. Anyone could think of a way to productize this: def command(*cmdz): process = Popen( flatten(cmdz), shell= True, stdout= subprocess.PIPE, stderr= subprocess.PIPE, bufsize= 4096 ) def line(): return process.stdout.readline().rstrip() def s(): while True: l = line() if not l: break yield l line.s = s return line That leads to some syntactic sugar. For example, one truly demented way to stream in an entire block and then treat it as one big string is this: print '\n'.join(command('ls').s()) The point of the command() complex is the ability to start a long command and then fetch out individual lines from it: line = command('find', '../..') print 'lines' print line() print line() print line() print 'all' print list(line.s()) If you need different pipe abilities, such as stdin, you can trivially add them to the contents of command() (it's not productized on purpose). So I can take the line() functor and, for example, pin it to a View object, or put it in another thread now, right? -- Phlip http://bit.ly/ZeekLand From t4rtine at gmail.com Wed Aug 3 11:37:21 2011 From: t4rtine at gmail.com (julien godin) Date: Wed, 3 Aug 2011 17:37:21 +0200 Subject: python distributed computing Message-ID: Hello the list, I have a, let say 'special' , request. I would like to make a very specific type of distributed computing. Let me explain myself : I have a HUUUUUGE(everything is relative) amount of data coming from UDP/514 ( good old syslog), and one process alone could not handle them ( it's full of regex, comparison and counting. all this at about 100K lines of data per seconds and each line is about 1500o long. I tried to handle it on one process, 100% core time in htop. ) So i said to myself : why not distribute the computing ? I looked for a good library that could do the distribution/process management job for me (http://wiki.python.org/moin/ParallelProcessing). What i found was not really usable by me ( distributed processing with a lot of processing but almost no process communication wich is the opposite of the thing i would like to do: distribute the events in real time so it is processed in real time.). My question is : is their any library or API or anything that is able to do that ? Sincerly Julien PS: This is my first time posting on any mailing list, my explanation/syntax could look a little bite, messy. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 3 11:51:20 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 16:51:20 +0100 Subject: python distributed computing In-Reply-To: References: Message-ID: On Wed, Aug 3, 2011 at 4:37 PM, julien godin wrote: > I have a HUUUUUGE(everything is relative) amount of data coming from UDP/514 > ( good old syslog), and one process alone could not handle them ( it's > full?of regex, comparison and counting. all this at about 100K lines of data > per seconds and each line is about 1500o long. I tried to handle it on one > process, 100% core time in htop. ) > So i said to myself : why not distribute the computing ? You could brute-force it by forking out to multiple computers, but that would entail network traffic, which might defeat the purpose. If you have a multi-core CPU or multi-CPU computer, a better option would be to look into the multiprocessing module for some simple ways to divide the work between cores/CPUs. Otherwise, there's a few things to try. First and most important thing: Optimize your algorithms! Can you do less work and still get the same result? For instance, can you replace the regex with two or three simpler string methods? Profile your code to find out where most of the time is being spent, and see if you can recode those parts. Second: Try PyPy or Cython for higher-performance Python code. And third, if you still can't get the performance you need, consider changing languages. Python isn't the best language for fast execution - it's good for fast coding. Rewrite some or all of your code in C, Pike, COBOL, raw assembly language... okay, maybe not those last two! Since you profiled your code up in step 1, you'll know which parts are the best candidates for C code. I think there are quite a few options better than forking across computers; although distributed computing IS a lot of fun. Chris Angelico From missive at hotmail.com Wed Aug 3 12:02:04 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 20:32:04 +0430 Subject: parsing function parameters Message-ID: I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) def pdict(f, pstr): ??? '''given a function object and a string with the function parameters, ??? return a dictionary of {parameter name: default value or None, ...} ??? I don't really need the actual default values, just knowing that ??? they exist or having their string representations would be fine. ??? def foo(x, y, z=50): ??????? pass ??? ps = 'x, y, z=50' ??? pdict(foo, ps) ??? {'x': None, 'y': None, 'z': 50} ??? OR: {'x': '', 'y': '', 'z': '50'} ??? OR: {'x': False, 'y': False, 'z': True} ??? Note that the parameter list can be arbitrarily complex ??????? (as long as it is legal python) ??? def bar(m, n=(1, 2, 3), o? =? ('n=5', 'or anything legal')): ??????? pass ??? pps = 'm, n=(1, 2, 3), o? =? ('n=5', 'or anything legal')' ??? pdict(bar, pps) ??? {'m': None, 'n': '(1, 2, 3)', 'o': "('n=5', 'or anything legal')"} ??? ''' ??? prs = f.func_code.co_varnames ??? rxl = [r'(\s*%s\s*=(?=(?:\s*\S+))\s*\S+)\s*'%pr for pr in prs] ??? rx = ','.join(rxl) ??? print rx ??? import re ??? re.match(rx, pstr).groups() This regex works in limited situations, namely when every parameter has a default value, but I can't figure out how to also make it match a parameter that has no default. I am open to any solution, though I am reluctant to pull in any more external libraries just for this one little enhancement. I have it working by just splitting the pstr on comma, except of course that it fails when the default value contains a comma (a tuple or list, for instance). Any assistance or ideas appreciated. From coolaj86 at gmail.com Wed Aug 3 12:08:14 2011 From: coolaj86 at gmail.com (AJ ONeal) Date: Wed, 3 Aug 2011 10:08:14 -0600 Subject: [job] multiple openings for CS, CE, EE, IT majors / graduates Message-ID: I know of some job openings. Contact me off list for more details. The positions are full-time (or at least 30hrs / week) paid internships that should lead to a full-time salaried position in near future. If a *mix of any* of the bullet points below *describes you* or *someone you know*, please ask me some questions, send me a resume, and I'll get you in touch with some great people who need you! *All great candidates* - have taken their education into their own hands to some degree - learn quickly - have beyond-the-classroom experience / personal projects - know how to leverage tools and people in their circle (forums, interest groups, friends) to find answers to questions - are familiar with *nix and know their way around with find, grep, vim (or emacs) *Event-driven Application Developer* - could write a basic evented messaging queueing and retrieval service in about a week - can solve fizzbuzz in less than an hour - has written a simple chat server - knows the difference between a markup language and an object notation - is familiar with one of node.js, python / twisted, ruby / eventmachine, go, erlang - has used a web framework of some sort - has used C and written a queue of some sort - enjoys regex - has a good understanding of http and general networking concepts - has used wireshark to examine http and tcp traffic - has written a native mobile app (iOS, Android) *Gadget Engineer* - could build a rechargeable battery-powered usb hub in about a week - could reverse engineer a cheap usb hub from e-bay in about a day - could build a pringles cantenna in about a day - has used C and written a queue of some sort - can write object-oriented C (as if it were a programming language) - has played with Arduino, Bug, Beagle, Panda, or some other sort of project board - Envies those who own a Fluke multimeter (or owns one) *HTML5 Web App Developer* - could write a basic client-side timesheet application in about a week - has a good handle on JavaScript - knows how to use CSS selectors - knows the difference between a markup language and an object notation - knows the difference (or relationship) between HTML and the DOM - can solve fizzbuzz in less than an hour - has written a simple chat server - can draw a graph on canvas - enjoys regex - has worked with APIs such as Google Apps, facebook, twitter, etc - has a good understanding of http and general networking concepts - has used wireshark or firebug to examine http traffic - has written a native mobile app (iOS, Android) *Linux Techie++* - could set up a VPS with nginx, gitosis, git pull hooks, and reverse-proxied apps in about a week - has built a kernel - has built an out-of-tree kernel module - can use bash almost as if were a programming language (but has the good sense not to) - can write object-oriented C (as if it were a programming language) - enjoys regex - has used C and written a queue of some sort - has used wireshark to examine traffic - is familiar with one of node.js, python / twisted, ruby / eventmachine, go, erlang AJ ONeal -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 12:18:15 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:18:15 -0700 Subject: parsing in python In-Reply-To: References: Message-ID: To just split lines into words, you could probably just use a regex. If you need to match things, like quotes or brackets or parens, pyparsing is pretty nice. On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by words > random, however I figure out that I need extract the content inside of each > file, in fact I believe I have to create a parsing, nonetheless I don't > know how to create a parser. > Please some could share some tips to do it? > Cheers > Jayron > here is the code: > > # -*- conding: utf-8 -*- > > > from subprocess import Popen, PIPE > > pesquisa = raw_input(" Digite a pesquisa de interesse: ") > > def Pesquisar(pesquisa): > p = Popen(["search", pesquisa],stdout=PIPE) > resultado = p.communicate()[0] > return resultado > > > print Pesquisar(pesquisa) > > > > > -- > *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* > > http://bucolick.tumblr.com > http://artecultural.wordpress.com/ > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Aug 3 12:21:22 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 18:21:22 +0200 Subject: Snippet: The leanest Popen wrapper References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Phlip wrote: > Groupies: I smell a slight misperception of the audience you are addressing ;) > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) Protect your environment, don't let stderr pollute the nearby river ;) > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() At that point l may be empty because you have read the output completely or because there was an empty line that you rstripped to look like the end of file. > if not l: break > yield l > > line.s = s > > return line I think you are overdoing that closure/function factory thing a bit... Seriously, you should reread the subprocess documentation to learn how to avoid deadlocks. From abhishek11005 at iiitd.ac.in Wed Aug 3 12:22:26 2011 From: abhishek11005 at iiitd.ac.in (Abhishek Jain) Date: Wed, 3 Aug 2011 21:52:26 +0530 Subject: Equality check Message-ID: How to check equality of two nos. in python -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Aug 3 12:23:08 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Aug 2011 18:23:08 +0200 Subject: parsing function parameters In-Reply-To: References: Message-ID: Lee Harr, 03.08.2011 18:02: > I am trying to get some information about a function > before (and without) calling it. > > Here is what I have so far. I chose to go with a > regular expression, so now I have 2 problems :o) Can't you just use runtime introspection? Take a look at the inspect module. Stefan From drsalists at gmail.com Wed Aug 3 12:29:24 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:29:24 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E391933.6070603@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans wrote: > Is it more portable? I don't actually have cpio installed on this > system. Interesting. Of course, it's probably readily available to you. What *ix are you seeing that doesn't include cpio by default? > Which implementations of cp don't implement -R and -l? Probably most of them, except GNU and newer BSD. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 12:31:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 09:31:08 -0700 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 12:04 AM, Nobody wrote: > On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > > > However I do not think it is possible to hard link directories ? > > Modern Unices disallow hard links to directories, as it makes the > directory "tree" not a tree, so anything which performs a recursive walk > must explicitly check for cycles to avoid infnite recursion. > > Older systems which allowed hard links to directories required root > privilege to do so. > > Actually, I recently heard about a system with multiple Solaris Containers set up, that were sharing their /usr via directory hardlinks. The question came up: How does one back up such a system? But ufsdump worked. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stutzbach at google.com Wed Aug 3 12:33:17 2011 From: stutzbach at google.com (Daniel Stutzbach) Date: Wed, 3 Aug 2011 09:33:17 -0700 Subject: how to sort a hash list without generating a new object? In-Reply-To: References: Message-ID: On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which is quite distinct from OrderedDict). > Or look for a binary search tree or skip list implementation of some > sort; but these aren't commonly used in Python, so it may be hard to > find a good one. > The blist package (I'm the author) provides a list-like type that has O(log n) insertions and deletions. It provides a sorteddict type that uses the blist type under-the-hood. blist's "sorteddict" supports the "key" parameter (which works like list.sort's key parameter), which the original poster could use to maintain the keys in reverse order. http://pypi.python.org/pypi/blist/ There's no overhead to learn how to use the new types. A blist works exactly like a list but with different performance characteristics, and a sorteddict works just like a dict but keeps the keys sorted. -- Daniel Stutzbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Wed Aug 3 12:39:12 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 18:39:12 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: <4E3979B0.3080402@jollybox.de> On 03/08/11 17:29, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) > > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() > if not l: break This will ignore everything after a blank line. Intended? It may be better not to use readline(), but to use the fact that it's an iterable, and use next(process.stdout) to get each line. (and deal with StopIteration accordingly -- or not) > yield l > > line.s = s > > return line > > That leads to some syntactic sugar. For example, one truly demented > way to stream in an entire block and then treat it as one big string > is this: > > print '\n'.join(command('ls').s()) > > The point of the command() complex is the ability to start a long > command and then fetch out individual lines from it: > > line = command('find', '../..') > > print 'lines' > print line() > print line() > print line() > > print 'all' > print list(line.s()) > > If you need different pipe abilities, such as stdin, you can trivially > add them to the contents of command() (it's not productized on > purpose). > > So I can take the line() functor and, for example, pin it to a View > object, or put it in another thread now, right? > > -- > Phlip > http://bit.ly/ZeekLand From t at jollybox.de Wed Aug 3 12:44:04 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 18:44:04 +0200 Subject: Equality check In-Reply-To: References: Message-ID: <4E397AD4.2010908@jollybox.de> On 03/08/11 18:22, Abhishek Jain wrote: > How to check equality of two nos. in python > > http://docs.python.org/py3k/reference/expressions.html#not-in http://docs.python.org/py3k/tutorial/index.html From __peter__ at web.de Wed Aug 3 12:51:27 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Aug 2011 18:51:27 +0200 Subject: parsing function parameters References: Message-ID: Lee Harr wrote: > I am trying to get some information about a function > before (and without) calling it. If you allow for the function arguments to be evaluated it's easy (requires Python 2.7): >>> import inspect >>> def get_args(*args, **kw): ... return args, kw ... >>> argstr = "1, 2, z=42" >>> def f(a, b, x=1, y=2, z=3): ... pass ... >>> args, kw = eval("get_args(%s)" % argstr) >>> inspect.getcallargs(f, *args, **kw) {'a': 1, 'x': 1, 'b': 2, 'z': 42, 'y': 2} From jayronsoares at gmail.com Wed Aug 3 13:05:36 2011 From: jayronsoares at gmail.com (Jayron Soares) Date: Wed, 3 Aug 2011 14:05:36 -0300 Subject: parsing in python In-Reply-To: References: Message-ID: Hi Dan, Thank you a lot =) Cheers Jayron 2011/8/3 Dan Stromberg > > To just split lines into words, you could probably just use a regex. > > If you need to match things, like quotes or brackets or parens, pyparsing > is pretty nice. > > On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > >> Hi folks, >> >> I've created a simple method to grab files texts from directory by words >> random, however I figure out that I need extract the content inside of each >> file, in fact I believe I have to create a parsing, nonetheless I don't >> know how to create a parser. >> Please some could share some tips to do it? >> Cheers >> Jayron >> here is the code: >> >> # -*- conding: utf-8 -*- >> >> >> from subprocess import Popen, PIPE >> >> pesquisa = raw_input(" Digite a pesquisa de interesse: ") >> >> def Pesquisar(pesquisa): >> p = Popen(["search", pesquisa],stdout=PIPE) >> resultado = p.communicate()[0] >> return resultado >> >> >> print Pesquisar(pesquisa) >> >> >> >> >> -- >> *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* >> >> http://bucolick.tumblr.com >> http://artecultural.wordpress.com/ >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- *" A Vida ? arte do Saber...Quem quiser saber tem que Estudar!"* http://bucolick.tumblr.com http://artecultural.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Aug 3 13:27:41 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Aug 2011 10:27:41 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 8:29 AM, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible. Anyone could think of a way to productize this: > > def command(*cmdz): > > ? ?process = Popen( flatten(cmdz), flatten() being defined as...? > ? ? ? ? ? ? ? ? ? ? shell= True, I would strongly encourage you to avoid shell=True. You really don't want to have to worry about doing proper shell escaping yourself. > ? ? ? ? ? ? ? ? ? ? stdout= subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? stderr= subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? bufsize= 4096 ) Cheers, Chris From missive at hotmail.com Wed Aug 3 14:00:03 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 22:30:03 +0430 Subject: parsing function parameters In-Reply-To: <1312388985.25995.11.camel@tim-laptop> References: , <1312388985.25995.11.camel@tim-laptop> Message-ID: >> I am trying to get some information about a function >> before (and without) calling it. > how about def pdict(f): ??? parameter_defaults = {} ??? defaults = f.func_defaults ??? defaultcount = len(defaults) ??? argcount = f.func_code.co_argcount ??? for i in xrange(f.func_code.co_argcount): ??????? name = f.func_code.co_varnames[i] ??????? value = None ??????? if i >= argcount - defaultcount: ??????????? value = defaults[i - (argcount - defaultcount)] ??????? parameter_defaults[name] = value ??? return parameter_defaults > No need for the string parameters. > > Tim That's it! I saw the func_defaults, but could not see how to make them match up with the co_varnames. I forgot that keyword args must follow the positional args (duh). I think this is going to work perfectly. Thanks to all for the suggestions! From phlip2005 at gmail.com Wed Aug 3 14:04:53 2011 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Aug 2011 11:04:53 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: > flatten() being defined as...? Python Cookbook recipe 4.6 def flatten(sequence): # CONSIDER: Reconcile with utils... for item in sequence: if isinstance(item, (list, tuple)): for subitem in flatten(list(item)): yield subitem else: yield item >> ? ? ? ? ? ? ? ? ? ? shell= True, > I would strongly encourage you to avoid shell=True. You really don't > want to have to worry about doing proper shell escaping yourself. Tx for helping me avoid reading up on it. I just copied it in. I keep getting "fab not found" etc. when running 'fab command' thru it. So then I ditch to os.system(). The long-term solution would be 'bash', '-c', 'yack yack yack' if you want truly shelly things! -- ? Phlip ? http://c2.com/cgi/wiki?ZeekLand From missive at hotmail.com Wed Aug 3 14:33:21 2011 From: missive at hotmail.com (Lee Harr) Date: Wed, 3 Aug 2011 23:03:21 +0430 Subject: parsing function parameters Message-ID: Needed to make one change... for functions with no default args: def pdict(f): ??? parameter_defaults = {} ??? defaults = f.func_defaults ??? if defaults is not None: ??????? defaultcount = len(defaults) ??? else: ??????? defaultcount = 0 ??? argcount = f.func_code.co_argcount ??? for i in xrange(f.func_code.co_argcount): ??????? name = f.func_code.co_varnames[i] ??????? value = None ??????? if i >= argcount - defaultcount: ??????????? value = defaults[i - (argcount - defaultcount)] ??????? parameter_defaults[name] = value ??? return parameter_defaults From t at jollybox.de Wed Aug 3 14:49:22 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 20:49:22 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> Message-ID: <4E399832.3090009@jollybox.de> On 03/08/11 18:29, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans > wrote: > > Is it more portable? I don't actually have cpio installed on this > system. > > > Interesting. Of course, it's probably readily available to you. What > *ix are you seeing that doesn't include cpio by default? Arch Linux - the base install is quite minimal. I just discovered that I have a program called bsdcpio which is used by mkinitcpio (and possibly other system scripts); no need for the GNU cpio. Curious. > > > Which implementations of cp don't implement -R and -l? > > > Probably most of them, except GNU and newer BSD. Okay. While GNU libc manuals usually document how portable functions are in detail, that's not true for the GNU coreutils manuals. Thomas From davea at ieee.org Wed Aug 3 15:15:56 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 03 Aug 2011 15:15:56 -0400 Subject: Equality check In-Reply-To: References: Message-ID: <4E399E6C.9000408@ieee.org> On 01/-10/-28163 02:59 PM, Abhishek Jain wrote: > How to check equality of two nos. in python > Python doesn't have numbers, it has various numeric data types. If all you're concerned with are int types, then just use the obvous: if a == b: dosomething.... If one or both might be floats, you have to deal with the likelihood that one or both may have quantization error, either caused by computational approximations, precision limitations, or conversion back and forth between string and internal binary representation. If one is in Decimal, you have to mostly deal with the first two. If one is complex, ... DaveA From steve+comp.lang.python at pearwood.info Wed Aug 3 15:51:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 05:51:16 +1000 Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: >> In CPython at least, local lookups are faster >> than globals: locals are stored in a fixed array, and the function knows >> the numeric offset of each variable. > > Ah! I was not aware of this, and thought that locals were a dictionary > too. Of course, it makes a lot of sense. In that case, the classic > "grab it as a local" isn't just loading down the locals dictionary > with more names and thus slower lookups. Er, not quite. Hash tables don't get slower as you add more items in them. The difference is between: (1) Search for "name" in globals dict; (2) If not found, search for "name" in builtins dict; (both searches being O(1) constant time to a first approximation) versus: (1) Look in slot 5 in the function table of local variables Name lookups involve hashing the string, then jumping to that position in a hash table, then checking the name equals the key actually found. On average, that requires constant time regardless of how many keys are in the hash table (although the hash calculation and the equality tests might depend on the length of the name). So the whole thing is predictably fast. But not quite as fast as a simple jump to an offset to a table. In theory, if you can arrange matters so that the dict is full of keys which all hash the same, then performance will fall to O(N) instead of O(1), but that would be *very* hard to do by accident. (A malicious coder might find a way to fill your globals with a whole lot of three-letter variables that happen to hash equal to that of "len", but then a malicious coder has better ways of making your life miserable than slowing down name lookups.) >> But, are you *sure* that name lookups are *really* the bottleneck? Name >> lookups are pretty fast. If you want them faster, turn them into a local >> variable. It's not clear to me that syntax, or a pragma directive, or >> some other form of magic, is better than an explicit assignment: > > No, I'm not sure. Unfortunately I have no convenient way to compare; Have you tried using the profiler? > all I can do is compare with a completely different language, which is > of course NEVER going to be fair. The only actual data I have on the > subject is the perfect-numbers search the other day; Pike managed the > same task in a fraction of the time that Python spent on it. Pike has > a single integer type that quietly switches from small to large at > 2**32, with a noticeable performance change. This is the same as > Python 2, but could explain some of the Python 3 penalty. There's only > two obvious possibilities (there may be others, of course): firstly, > that the actual name lookup is expensive; I wouldn't imagine that's a big factor, but I could be wrong. > and secondly, that Pike is > able to optimize integer arithmetic by knowing that the value in > question is an int, and it will never be anything else. Much more likely. Or that Pike's programming model is simpler and therefore code is faster, or it has a smarter compiler... there could be many, many different reasons. Or you cheated and used a slightly different algorithm in Pike :) [...] > So which is the better idiom? > > def func(x): > _len = len # bind at function call time > for i in x: > _len(i) # lookups of _len will be faster than len That's the standard way of doing, er, early binding as late as possible :) To do early binding as early as possible: def func(x, len=len): # binds at function definition time for i in x: len(i) > or: > > def func(x): > len = len # localize len > for i in x: > len(i) # use it exactly as you otherwise would That can't work. The problem is that because len is assigned to in the body of the function, the Python compiler treats it as a local variable. So the line len=len is interpreted as len = len, which doesn't yet exist. There's no way of saying len = len in the body of the function. So you must either: (1) use a different name: length = len (2) use a fully-qualified name: import builtins; len = builtins.len (3) do the assignment as a default parameter, which has slightly different binding rules: def func(x, len=len) (4) manual lookup: len = builtins.__dict__['len'] # untested I don't recommend that last one, unless you're deliberately trying to write obfuscated code :) -- Steven From nad at acm.org Wed Aug 3 15:57:23 2011 From: nad at acm.org (Ned Deily) Date: Wed, 03 Aug 2011 12:57:23 -0700 Subject: Hardlink sub-directories and files References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> Message-ID: In article , Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: > > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: > >> > >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > >>> > >>> On 02/08/11 11:32, loial wrote: > >>> > I am trying to hardlink all files in a directory structure using > >>> > os.link. > >>> > > >>> > However I do not think it is possible to hard link directories ? > >> > >> That is pretty true.?? I've heard of hardlinked directories on Solaris, but > >> that's kind of an exception to the general rule. > > > > In APUE, Richard Stevens says only root could do this, > > Yep, in early versions of Solaris root could hard-link directories. > I did it once, and it's not something one did a second time. fsck > couldn't deal with it and pretty much fell over. IIRC, the only way > to recover was to clear several inodes manually and then let fsck > salvage things. > > > if it is supported by the system at all. In a footnote, he > > additionally mentions he screwed up his filesystem by creating a loop > > of hardlinked directories while writing that section of the book. > > That sounds about right. > > > I suppose it is a good thing systems don't allow that now. > > It wouldn't be a problem, except there are some important places in > Unix where it is assume that filesystems are trees. Hard linking > directories causes that assumption to be false. FWIW, Apple implemented directory hard links for HFS+ file systems in Mac OS X 10.5 specifically to make the Time Machine incremental backup system work efficiently. The hard directory links are, of course, not meant to be used by the casual user. The section "Directory Hard Links" in this blog entry from Amit Singh explains what restrictions are enforced on directory hard links to prevent cycles: http://osxbook.com/blog/2008/11/09/hfsdebug-40-and-new-hfs-features/ -- Ned Deily, nad at acm.org From alain at dpt-info.u-strasbg.fr Wed Aug 3 16:16:27 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 03 Aug 2011 22:16:27 +0200 Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87fwliw8ro.fsf@dpt-info.u-strasbg.fr> Chris Angelico writes: [...] > The only actual data I have on the subject is the perfect-numbers > search the other day; Pike managed the same task in a fraction of the > time that Python spent on it. Pike has a single integer type that > quietly switches from small to large at 2**32, with a noticeable > performance change. This is the same as Python 2, but could explain > some of the Python 3 penalty. There's only two obvious possibilities > (there may be others, of course): firstly, that the actual name lookup > is expensive; and secondly, that Pike is able to optimize integer > arithmetic by knowing that the value in question is an int, and it > will never be anything else. Pike is (at least partly) statically typed. Most of the lookups are solved at compile time, and have therefore zero overhead at run-time. So your second possibility is the good one, but probably not because of arithmetic optims, rather because of all the lookups Pike doesn't perform dynamically. -- Alain. From tjreedy at udel.edu Wed Aug 3 16:20:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Aug 2011 16:20:22 -0400 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On 8/3/2011 11:29 AM, Phlip wrote: > This is either a code snippet, if you like it, or a request for a > critique, if you don't. A learning exercise but pretty useless otherwise. As others pointed out, immediately stripping off \n is a bug relative to *your* function description. Also, you yourself then give an example of joining with \n. But that does not restore the final \n. The rest duplicates the iteration ability of the .stdout file object. For repeated execution of code like process.stdout.readline() you can once create a 'packetized' bound method object like so cmdline = process.stdout.readline and then, without repeating the attribute lookups, repeatedly call cmdline() . -- Terry Jan Reedy From drsalists at gmail.com Wed Aug 3 17:25:41 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 14:25:41 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E399832.3090009@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans wrote: > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsdcpio which is used by mkinitcpio (and possibly > other system scripts); no need for the GNU cpio. Curious. > I guess that makes some sense. If you want to really strip down an install, removing cpio is a good candidate since it duplicates what's in tar, and tar is more popular - especially for interactive use. > Which implementations of cp don't implement -R and -l? > > > Probably most of them, except GNU and newer BSD. Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a reimplementation, not the original. cpio's been around since PWB/Unix, which sits between 6th Edition Unix and 7th Edition. It should be in just about everything, unless a vendor/distributor got pretty zealous about cutting duplicate utilities. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astley.lejasper at gmail.com Wed Aug 3 17:46:04 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Wed, 3 Aug 2011 14:46:04 -0700 (PDT) Subject: Inconsistent SMTP/Gmail connection drop Message-ID: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> I have a laptop that wakes up and then runs a script that collects info and sends an email with a spreadsheet (zipped and about 350KB) report to a number of people. However, every time I get the following error: File "/usr/lib/python2.7/smtplib.py", line 343, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") - When I check the laptop and manually run the function that sends the email and report, it works fine. I have never been able to replicate the error when doing it manually. - It can't be a problem with Gmail at that time in the morning or my connection, because the script also sends me a copy of the log file straight after, and that works. - The same code has been working for years, it just that I have recently rebuilt the machine so now it is using Python 2.7. I have also change the references to use absolute file references, rather than relative. I also have changed the code to run as root. - I've checked the smtp debug report and everything seems ok. I just never get the confirmation code (250) to say that it's completed. - Even stranger ... it ran ok once. But I didn't change a thing and the next day it wouldn't work. The only thing I can think of is that when the file is transferred to the reports directory, it somehow isn't been released quickly enough and perhaps this is tripping up SMTP. But ... this is a bit of a guess given I've tried to exhaust all the other options. Any ideas? From t at jollybox.de Wed Aug 3 17:54:03 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 03 Aug 2011 23:54:03 +0200 Subject: Hardlink sub-directories and files In-Reply-To: References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> Message-ID: <4E39C37B.4030503@jollybox.de> On 03/08/11 23:25, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans > wrote: > > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsdcpio which is used by mkinitcpio (and possibly > other system scripts); no need for the GNU cpio. Curious. > > > I guess that makes some sense. If you want to really strip down an > install, removing cpio is a good candidate since it duplicates what's in > tar, and tar is more popular - especially for interactive use. > >> Which implementations of cp don't implement -R and -l? >> >> >> Probably most of them, except GNU and newer BSD. > > Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. > > > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a > reimplementation, not the original. Indeed. But cp is in the coreutils, and that was what we were talking about. As for GNU cpio, that's simply what /usr/bin/cpio, if present, is expected to be on a GNU/Linux system. > > cpio's been around since PWB/Unix, which sits between 6th Edition Unix > and 7th Edition. It should be in just about everything, unless a > vendor/distributor got pretty zealous about cutting duplicate utilities. > From dstanek at dstanek.com Wed Aug 3 18:17:27 2011 From: dstanek at dstanek.com (David Stanek) Date: Wed, 3 Aug 2011 18:17:27 -0400 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper wrote: > > Any ideas? > Is it possible that the first email is sent before the network connection has been properly established? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek www: http://dstanek.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 3 18:24:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Aug 2011 23:24:09 +0100 Subject: Early binding as an option In-Reply-To: <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 3, 2011 at 8:51 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Ah! I was not aware of this, and thought that locals were a dictionary >> too. Of course, it makes a lot of sense. In that case, the classic >> "grab it as a local" isn't just loading down the locals dictionary >> with more names and thus slower lookups. > > Er, not quite. Hash tables don't get slower as you add more items in them. Whoops, sloppy English there. The locals dictionary isn't slower because it gets more stuffed in it (well, maybe a dict will slow down if you stuff a few million things in it vs having five, but not with this scale), but that it's slower than alternatives. >> No, I'm not sure. Unfortunately I have no convenient way to compare; > > Have you tried using the profiler? I can profile the code the way it is. I can't profile the code the way it isn't, with static lookups. I could compare global vs local, but not global/local vs no lookup at all. >> and secondly, that Pike is >> able to optimize integer arithmetic by knowing that the value in >> question is an int, and it will never be anything else. > > Much more likely. Pike separates variables from their values, just as Python does. I've actually stuffed strings into variables that are supposed to be int only, and things work fine (a bit confusing for the human though!). But you're right that it's probably simplifying other lookups, not the actual variable name. I think the same consideration applies; if you know exactly what you're working with, if you assume that x.__add__ is not going to change, then you can optimize. > Or you cheated and used a slightly different algorithm in Pike :) Heh. No, I kept the algorithm exactly the same. I'll post the code if you like :) >> def func(x): >> ? ?len = len ?# localize len >> ? ?for i in x: >> ? ? ? ?len(i) ?# use it exactly as you otherwise would > > That can't work. The problem is that because len is assigned to in the body > of the function, the Python compiler treats it as a local variable. So the > line len=len is interpreted as len = len, which doesn't yet > exist. There's no way of saying len = len in the body of the > function. Duh. Forgot that. Without convenient syntax like "len = ::len" to do this, it's not advisable. > (4) manual lookup: len = builtins.__dict__['len'] ?# untested > > I don't recommend that last one, unless you're deliberately trying to write > obfuscated code :) For that reason! Although using builtins in this way isn't a good idea - there's no reason to do early binding late if you just bind to the same thing that early binding early would have done. And globals()["len"] doesn't work either, because builtins aren't globals... blargh, there's really no simple way to do this. It's a good thing I don't *need* to do anything like this, because it's not the syntactically simple optimization that I thought it would be! ChrisA From astley.lejasper at gmail.com Wed Aug 3 18:26:34 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 00:26:34 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Not sure how I'd test or determine that. I've set smtp debug to true and the output looks all good. I suppose I could try sending an email before the report is sent, as well as the email that is sent after it. On Thu, Aug 4, 2011 at 12:17 AM, David Stanek wrote: > On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper > wrote: >> >> Any ideas? >> > > Is it possible that the first email is sent before the network connection > has been properly established? > > -- > David > blog: http://www.traceback.org > twitter: http://twitter.com/dstanek > www: http://dstanek.com > From rosuav at gmail.com Wed Aug 3 19:57:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 00:57:47 +0100 Subject: Equality check In-Reply-To: <4E399E6C.9000408@ieee.org> References: <4E399E6C.9000408@ieee.org> Message-ID: On Wed, Aug 3, 2011 at 8:15 PM, Dave Angel wrote: > If one is complex, ... The situation is complex enough without bringing complex numbers into it! OP, I recommend reading this page and then re-asking your question: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA From drsalists at gmail.com Wed Aug 3 20:34:04 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 17:34:04 -0700 Subject: Hardlink sub-directories and files In-Reply-To: <4E39C37B.4030503@jollybox.de> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> <4E37CDCF.7060501@jollybox.de> <4E391933.6070603@jollybox.de> <4E399832.3090009@jollybox.de> <4E39C37B.4030503@jollybox.de> Message-ID: On Wed, Aug 3, 2011 at 2:54 PM, Thomas Jollans wrote: > > On 03/08/11 23:25, Dan Stromberg wrote: > > > Interesting. Of course, it's probably readily available to you. > What > > > *ix are you seeing that doesn't include cpio by default? > > > > Arch Linux - the base install is quite minimal. > Hmmmm... So we're probably not talking about portability to Android... Because it's too minimal, too different? >> Which implementations of cp don't implement -R and -l? >> >> >> Probably most of them, except GNU and newer BSD. > > Okay. While GNU libc manuals usually document how portable functions are > in detail, that's not true for the GNU coreutils manuals. You don't really need it in the coreutils doc. I'd feel very safe assuming that 98+% of all *ix's (not counting Android) either have cpio installed by default, or can easily get it via their native package manager. The same isn't true of a cp with new features. > I don't think cpio is in GNU coreutils. Also, I think GNU cpio is a > reimplementation, not the original. Indeed. But cp is in the coreutils, and that was what we were talking about. > Sorry. Maybe you should describe what you believe we -are- talking about, then? I guess I missed that. I thought it was portability. > As for GNU cpio, that's simply what /usr/bin/cpio, if present, is > expected to be on a GNU/Linux system. > Well, yes, but: 1) GNU/Linux is important 2) GNU/Linux isn't the end all and be all (I wrote:) > cpio's been around since PWB/Unix, which sits between 6th Edition Unix > and 7th Edition. It should be in just about everything, unless a > vendor/distributor got pretty zealous about cutting duplicate utilities. I guess this is boiling down to "A pure python solution might be better, since some folks don't like to use their package managers" Also, a pure python solution should work on windows - these shell commands don't unless you have one of the many ports of *ix tools to windows installed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Wed Aug 3 21:02:26 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 3 Aug 2011 18:02:26 -0700 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Some things to consider: 1) You might see if there's something about the size of the message - is it bigger after collecting data all night? Is google disconnecting after a maximum amount of data is transferred? 2) You might try sending a tiny test message at the beginning, just to yourself, and seeing if that has the problem 3) You might try running your script under a system call tracer: http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html- and inspecting the list of syscalls and their return codes near when the process terminates 4) I get disconnects from gmail once in a while too, especially when downloading a large list of new message headers; I've been just coding around it by making my code idempotent and otherwise restartable. This seems to happen with both 2.x and 3.x, so I assume it's not really related to the Python version, but I suppose I should try it on PyPy or Jython someday. Note that the error message in 3.x was better than in 2.x. HTH On Wed, Aug 3, 2011 at 2:46 PM, Astley Le Jasper wrote: > I have a laptop that wakes up and then runs a script that collects > info and sends an email with a spreadsheet (zipped and about 350KB) > report to a number of people. However, every time I get the following > error: > > > File "/usr/lib/python2.7/smtplib.py", line 343, in getreply > raise SMTPServerDisconnected("Connection unexpectedly closed") > > > - When I check the laptop and manually run the function that sends the > email and report, it works fine. I have never been able to replicate > the error when doing it manually. > - It can't be a problem with Gmail at that time in the morning or my > connection, because the script also sends me a copy of the log file > straight after, and that works. > - The same code has been working for years, it just that I have > recently rebuilt the machine so now it is using Python 2.7. I have > also change the references to use absolute file references, rather > than relative. I also have changed the code to run as root. > - I've checked the smtp debug report and everything seems ok. I just > never get the confirmation code (250) to say that it's completed. > - Even stranger ... it ran ok once. But I didn't change a thing and > the next day it wouldn't work. > > The only thing I can think of is that when the file is transferred to > the reports directory, it somehow isn't been released quickly enough > and perhaps this is tripping up SMTP. But ... this is a bit of a guess > given I've tried to exhaust all the other options. > > Any ideas? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From myeates at jpl.nasa.gov Wed Aug 3 21:19:25 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Wed, 3 Aug 2011 18:19:25 -0700 Subject: making my extensions work together Message-ID: This isn't exactly a Python question but maybe someone here has run into this. I have 2 extensions and they both access a function in a (static) library. The function maintains state information using a static variable. This doesn't work. When one of my extensions changes the variable value, the other extension does not see the change. Would it work if I made my library dynamic? This is on Windows XP compiling with MSVC 2008. -Mathew From steve+comp.lang.python at pearwood.info Wed Aug 3 23:01:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 13:01:50 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: Message-ID: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> harrismh777 wrote: > def perf(n): > sum = 0 > for i in range(1, n): > if n % i == 0: > sum += i > return sum == n A more effective way to speed that up is with a better algorithm: def isperfect(n): if n < 2: return False total = 1 for i in range(2, int(n**0.5)+1): a, b = divmod(n, i) if b == 0: total += a+i return total == n For n=33550336 it loops about 5791 times instead of 33550335, reducing the amount of work done by about 99.98%. isperfect is fast enough to exhaustively test every number up to a low limit: testing every number between 0 and 8128 inclusive took about 0.38 second in total on my PC. That's an average of 0.05 millisecond per number tested. Unfortunately, it doesn't scale. isperfect(33550336) takes about 4.4 ms, and isperfect(8589869056) about 84 ms. However, it is still (barely) feasible to exhaustively test every number up to a much higher range. I extrapolate that the time needed to check every value between 0 and 33550336 would take about 30 hours. If you're wondering why exhaustive testing is so expensive, it's because the test code simply calls isperfect(n) for each n. The number of iterations in each call to isperfect is approximately sqrt(n), so the total in any exhaustive test is approximately sum(x**0.5 for x in range(upperlimit)), which gets rather large. -- Steven From steve at holdenweb.com Wed Aug 3 23:14:44 2011 From: steve at holdenweb.com (Steve Holden) Date: Wed, 3 Aug 2011 20:14:44 -0700 Subject: Community Involvement Message-ID: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> [Ccs appreciated] After some three years labor I (@holdenweb) at last find myself approaching the completion of the Python Certificate Series with O'Reilly School of Technology (@OReillySchool). At OSCON last week the team fell to talking about the final assignment (although the Certificate is not a certification, students only progress by answering real quiz questions, not the usual multiple-choice task). Success also requires that they complete a project at the end of each (of the ~60) lesson(s). We would ideally like the last project to to be something that demonstrates at least some minimal involvement with the Python community. Something like "get a Python answer upvoted on StackOverflow", for example, or getting a question answered on c.l.p. At the same time it shouldn't be anything that places a burden on the community (otherwise the hundredth student would be abused and the thousandth murdered). So I wondered if anyone had any good ideas. regards Steve -- Steve Holden steve at holdenweb.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Wed Aug 3 23:22:30 2011 From: gordon at panix.com (John Gordon) Date: Thu, 4 Aug 2011 03:22:30 +0000 (UTC) Subject: making my extensions work together References: Message-ID: In "Mathew" writes: > This isn't exactly a Python question but maybe someone here has run into > this. > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. I'm not sure what you mean by "extension", but it might not be relevant. Are these extensions, whatever they may be, part of the same program? Or are they separate? > This doesn't work. When one of my extensions changes the variable value, the > other extension does not see the change. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From chrisallick at gmail.com Wed Aug 3 23:41:09 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:41:09 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: <3c8e8fd8-5d52-44e7-a0d4-c48b5d2ae22a@en1g2000vbb.googlegroups.com> On Aug 1, 11:39?am, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Catch a Kill: def signal_handler(signal, frame): print "Received exit command." #server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) Find and Kill A Process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process. From chrisallick at gmail.com Wed Aug 3 23:46:14 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:46:14 -0700 (PDT) Subject: HID Device Drivers for OS X Message-ID: <6f1f2143-662f-4949-93f3-779934a2d47c@en1g2000vbb.googlegroups.com> Hi, I spent almost all day trying to figure out how to capture a click from this button: http://www.dreamcheeky.com/big-red-button I tried libusb, PyUSB, HIDAPI and probably a couple other things. No luck. My understanding is that libusb won't allow me to get at the interface and the example I found using PyUSB to read a magnetic card reader errors with a segmentation fault in the libusb library. Can anyone point me in the right direction? I looked the OS X I/O Kit at developer.apple.com, but it seems really confusing and over kill. I have the vendor ID and product ID, it seems like it would be really simple to read when the button is clicked. Any thoughts? From chrisallick at gmail.com Wed Aug 3 23:47:20 2011 From: chrisallick at gmail.com (chrisallick) Date: Wed, 3 Aug 2011 20:47:20 -0700 (PDT) Subject: Notifications when process is killed References: Message-ID: <978bcdc2-308c-48d4-8879-8dc9da7d7592@x10g2000vbl.googlegroups.com> On Aug 1, 5:56?am, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > Could you suggest me if there's a way to do this? > > Thanks, regards. > > -- > Andrea Di Mario This will catch Ctrl+C and a Kill PID request: # Add SIGINT handler for killing the threads def signal_handler(signal, frame): print "Received exit command." server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) And this will find an destroy a process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process." From lists.jkstephens at gmail.com Thu Aug 4 00:05:55 2011 From: lists.jkstephens at gmail.com (John L. Stephens) Date: Thu, 04 Aug 2011 00:05:55 -0400 Subject: parsing in python In-Reply-To: References: Message-ID: <4E3A1AA3.8060209@gmail.com> Depending on what you want to do, you might try looking at the pyparsing module. I have used it to successfully parse sentences looking for keywords and structures. On 8/3/2011 9:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by > words random, however I figure out that I need extract the content > inside of each file, in fact I believe I have to create a parsing, > nonetheless I don't know how to create a parser. > Please some could share some tips to do it? > Cheers > Jayron > here is the code: > > # -*- conding: utf-8 -*- > > > from subprocess import Popen, PIPE > > pesquisa = raw_input(" Digite a pesquisa de interesse: ") > > def Pesquisar(pesquisa): > p = Popen(["search", pesquisa],stdout=PIPE) > resultado = p.communicate()[0] > return resultado > > > print Pesquisar(pesquisa) > > > > > -- > /" A Vida ? arte do Saber...Quem quiser saber tem que *Estudar*!"/ > > http://bucolick.tumblr.com > http://artecultural.wordpress.com/ > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dannwong at cisco.com Thu Aug 4 00:06:19 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 3 Aug 2011 23:06:19 -0500 Subject: python module to determine if a machine is idle/free In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Hi all, I have 5 server machines that are using to process information. I would like to write a quick server python script that determines which of the machines are not in use. Any recommendations on which python module I should use to detect if a machine is not performing idle (ex. Some specific task is not running)? -------------- next part -------------- An HTML attachment was scrubbed... URL: From cgelinek at radlogic.com.au Thu Aug 4 00:25:37 2011 From: cgelinek at radlogic.com.au (Christian Gelinek) Date: Thu, 4 Aug 2011 13:55:37 +0930 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? Message-ID: <001201cc525e$8f834510$ae89cf30$@com.au> Hi all, I have a problem running some python program using version 2.6.4 (or version 2.7.2, I tried both) from the Win7 command line - it never finishes due to an infinite loop. The thing is, when I run the same program through Cygwin which uses Python version 2.6.5, it exits the loop at some point. I came to try this after I realised that in some of the sources (it is a rather big program using many source files, most of them being created by others from a Linux environment), the indentation is mixed tabs/spaces where the assumed tab size is 8 spaces. Reading on the Python website, a tab size of 8 is default anyway, so I would have assumed it should work... does that mean that one tab equals 2 indents?!? I myself never use tabs to indent Python code but let my editor do a tab-to-4-spaces conversion when I press . I find it at least confusing to read that Python expects a tab size of 8 but at the same time uses 4 spaces for one indent level. Or maybe I am completely on the wron track here? Any ideas on how to get the thing to run under (real) Windows, hopefully without having to edit existing sources of people who left our company ages ago? From clp2 at rebertia.com Thu Aug 4 00:38:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Aug 2011 21:38:34 -0700 Subject: python module to determine if a machine is idle/free In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 3, 2011 at 9:06 PM, Danny Wong (dannwong) wrote: > Hi all, > > ??????????????? I have 5 server machines that are using to process > information. I would like to write a quick server python script that > determines which of the machines are not in use. Any recommendations on > which python module I should use to detect if a machine is not performing > idle (ex. Some specific task is not running)? Yes, psutil: http://code.google.com/p/psutil/ os.getloadavg() may or may not also be useful to you: http://docs.python.org/library/os.html#os.getloadavg Cheers, Chris From thorsten at thorstenkampe.de Thu Aug 4 01:18:50 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Thu, 4 Aug 2011 07:18:50 +0200 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? References: Message-ID: * Christian Gelinek (Thu, 4 Aug 2011 13:55:37 +0930) > Any ideas on how to get the thing to run under (real) Windows, > hopefully without having to edit existing sources of people who left > our company ages ago? python -t "Issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. Issue an error when the option is given twice." Thorsten From stefan_ml at behnel.de Thu Aug 4 02:00:37 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Aug 2011 08:00:37 +0200 Subject: making my extensions work together In-Reply-To: References: Message-ID: Mathew, 04.08.2011 03:19: > This isn't exactly a Python question but maybe someone here has run into > this. > > I have 2 extensions With "extensions", I assume you mean extension modules for the CPython runtime that are written in C? It would help if you were more specific in your problem description. > and they both access a function in a (static) library. It would help if you mentioned the names of the modules (or packages) and of the external library. > The function maintains state information using a static variable. That's bad design, but it happens. > This doesn't work. When one of my extensions changes the variable value, the > other extension does not see the change. Are the two modules linked in any way or are they just arbitrary modules that happen to be installed at the same time, trying to use the same external C library? If the former, consider letting them communicate with each other by making one depend on the other. If you control the source code, you may also consider wrapping the library only once and reusing that from the two modules. Or, just move the configuration part into a separate module and have both depend on that. Or, try to dump the dependency on the static variable. If the latter, then, well, it depends on several environmental factors that you left out in your question. > Would it work if I made my library dynamic? That's usually a good idea, but it's unlikely to help in this specific case. > This is on Windows XP compiling with MSVC 2008. Others will know more here. Stefan From k.sahithi2862 at gmail.com Thu Aug 4 02:46:05 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 3 Aug 2011 23:46:05 -0700 (PDT) Subject: SOUTH ACTRESS HOT PHOTOS Message-ID: <22f206b4-68e5-483f-94a6-77108dad9110@y19g2000pre.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From rosuav at gmail.com Thu Aug 4 02:59:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 07:59:07 +0100 Subject: range() vs xrange() Python2|3 issues for performance In-Reply-To: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano wrote: > ? ? ? ?a, b = divmod(n, i) > ? ? ? ?if b == 0: > ? ? ? ? ? ?total += a+i > Wouldn't this fail on squares? It happens to give correct results as far as I've checked; no square up to 10,000 is called perfect, and there are no perfect squares in that range, but I think it's technically using an incorrect intermediate result. ChrisA From clp2 at rebertia.com Thu Aug 4 03:08:29 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 00:08:29 -0700 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? In-Reply-To: <001201cc525e$8f834510$ae89cf30$@com.au> References: <001201cc525e$8f834510$ae89cf30$@com.au> Message-ID: On Wed, Aug 3, 2011 at 9:25 PM, Christian Gelinek wrote: > Hi all, > > I have a problem running some python program using version 2.6.4 (or version > 2.7.2, I tried both) from the Win7 command line - it never finishes due to > an infinite loop. The thing is, when I run the same program through Cygwin > which uses Python version 2.6.5, it exits the loop at some point. > > I came to try this after I realised that in some of the sources (it is a > rather big program using many source files, most of them being created by > others from a Linux environment), the indentation is mixed tabs/spaces where > the assumed tab size is 8 spaces. That's just plain evil. > Reading on the Python website, a tab size of 8 is default anyway, so I would > have assumed it should work... does that mean that one tab equals 2 > indents?!? I myself never use tabs to indent Python code but let my editor > do a tab-to-4-spaces conversion when I press . > > I find it at least confusing to read that Python expects a tab size of 8 but > at the same time uses 4 spaces for one indent level. Or maybe I am > completely on the wron track here? 4-space indents are /recommended/ by PEP 8, but the interpreter does not require or prefer that style. What the interpreter does when parsing indentation is rather more complicated; see http://docs.python.org/reference/lexical_analysis.html#indentation You might wanna look at tabnanny: http://docs.python.org/library/tabnanny.html Cheers, Chris From rosuav at gmail.com Thu Aug 4 03:08:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Aug 2011 08:08:59 +0100 Subject: making my extensions work together In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. If your extensions are DLLs and they're both linking to the same static library, you should have two independent copies of that library - which would mean they don't interfere with one another. That's why the other extension doesn't see the change, and normally this is the correct and desired behaviour. Having the two be aware of each other is potentially very messy. As Stefan suggested, making one depend on the other would be a lot simpler. Alternatively, there may be ways to have the two extensions share data through Python itself. What are you looking to accomplish? ChrisA From ericsnowcurrently at gmail.com Thu Aug 4 03:49:39 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 4 Aug 2011 01:49:39 -0600 Subject: finding the object corresponding to a stack frame Message-ID: For any given stack frame, the corresponding code object is derived most immediately from either a module [definition], a class definition, or function definition. I want to be able to determine the specific module, class, or function object for any arbitrary code/frame object. For modules it is pretty straightforward. For classes, the object doesn't exist yet, but I can work around that. Lastly, for functions it is not nearly as simple as I had hoped. If the function is defined in the global namespace then the solution is relatively trivial, using the inspect module: def get_context(): frame = inspect.currentframe().f_back if frame.f_code.co_name == "": return sys.modules[frame.f_locals["__name__"]] return frame.f_globals.get(frame.f_code.co_name) def f(): context = get_context() f() However, under other conditions it is not so easy: - the function is nested inside another, - the code object is shared between multiple functions, - the function is accessed as an attribute of some other object and thus is not bound by its name in the easy search namespaces (like globals), - others? I'm trying to see if there is a way to work through these issues. It would be great if objects knew under which object each was defined, but that is a bigger question for another time. Right now I would just settle for a frame object knowing the object for which it is running, particularly for functions. However, judging by similar questions found while researching this, I'm not holding my breath. Any ideas? -eric From astley.lejasper at gmail.com Thu Aug 4 03:54:26 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 09:54:26 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Thanks for those suggestions. I tried something last night before I got your ideas. 1. I added a line to send a copy of the report just to me, 2 lines before the line where it emails the report to all the recipients. 2. I also added a timer.sleep(5) pause just before the line that emails the reports to all the recipients. So the order was: a) Send the full report just to me .... FAILED. b) Pause for 5 seconds. c) Send the full report to all 4 recipients ... WORKED. d) Send the log file just to me ... WORKED. So ... what looks like may be happening is that something might still be locking the file. In which case i'll try again without the test email to me. And/or perhaps send a test email without the attachment before the main report to see if that gets through, to see if the connection with gmail is actually really connected. See also below... > 1) You might see if there's something about the size of the message - is it > bigger after collecting data all night?? Is google disconnecting after a > maximum amount of data is transferred? I don't think so. The test message I mentioned above got through and the attachment was identical (320kb or abouts) > 2) You might try sending a tiny test message at the beginning, just to > yourself, and seeing if that has the problem As above. > 3) You might try running your script under a system call tracer: > http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html > - and inspecting the list of syscalls and their return codes near when the > process terminates Ouch. Looks complicated! ;-) > 4) I get disconnects from gmail once in a while too, especially when > downloading a large list of new message headers; I've been just coding > around it by making my code idempotent and otherwise restartable.? This > seems to happen with both 2.x and 3.x, so I assume it's not really related > to the Python version, but I suppose I should try it on PyPy or Jython > someday.? Note that the error message in 3.x was better than in 2.x. I was thinking that perhaps I could put a loop in that tests if the email goes through, and if not, pauses for a few seconds and then tries again. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 04:10:48 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 10:10:48 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 03.08.2011 19:27 schrieb Chris Rebert: >> shell= True, > > I would strongly encourage you to avoid shell=True. ACK, but not because it is hard, but because it is unnecessary and unelegant at this point. > You really don't want to have to worry about doing proper shell escaping yourself. That's nothing to really worry about - just doing def shellquote(*strs): return " ".join([ "'"+st.replace("'","'\\''")+"'" for st in strs ]) would do perfectly: shellquote('echo', "'", '"', " ", "\n") If you emit a command line over ssh, for example, you don't have another simple choice. There are only worries if there is a shell which better shouldn't be named like this. As you generally cannot know what ugly things the user of your program does, it is better to avoid the additional shell layer. So generally agree to what you say, but it is not the proper shell escaping one should worry about (it is so simple that one cannot call it "worry"), but the type of shell one talks with. Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 04:24:08 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 10:24:08 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 03.08.2011 17:29 schrieb Phlip: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. Well, at first, I cannot see the real point about it... > def command(*cmdz): > > process = Popen( flatten(cmdz), > shell= True, > stdout= subprocess.PIPE, > stderr= subprocess.PIPE, > bufsize= 4096 ) > > def line(): > return process.stdout.readline().rstrip() > > def s(): > while True: > l = line() > if not l: break > yield l > > line.s = s > > return line I find it quite ugly. You get a function object with an attached generator (which has a strange and non-verbose name and) which might stop too early due to an empty line. Plus, you have no real control over the communication; you have no access to stdin or stderr. The latter might produce a lock if the process writes out too much on stderr. Plus, you have no access to the exit code of the program. And you lose information about if the stream ends with any combination of whitespace. > That leads to some syntactic sugar. For example, one truly demented > way to stream in an entire block and then treat it as one big string > is this: > > print '\n'.join(command('ls').s()) What would work as well via print Popen( ['ls'], stdout= subprocess.PIPE).stdout.read() or print Popen( ['ls'], stdout= subprocess.PIPE).communicate()[0] > The point of the command() complex is the ability to start a long > command and then fetch out individual lines from it: > > line = command('find', '../..') sp = Popen( ['find', '../..'], stdout= subprocess.PIPE).stdout.read() line = sp.stdout.readline # if you want so: line = lambda: sp.stdout.readline().rstrip() - which # might lose information as well... > print 'lines' > print line() > print line() > print line() > > print 'all' > print list(line.s()) print list(iter(line, '')) Thomas From clp2 at rebertia.com Thu Aug 4 04:42:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 01:42:34 -0700 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: On Thu, Aug 4, 2011 at 1:10 AM, Thomas Rachel wrote: > Am 03.08.2011 19:27 schrieb Chris Rebert: > >>> ? ? ? ? ? ? ? ? ? ? shell= True, >> >> I would strongly encourage you to avoid shell=True. > > ACK, but not because it is hard, but because it is unnecessary and unelegant > at this point. > >> You really don't want to have to worry about doing proper shell escaping >> yourself. > > That's nothing to really worry about - just doing > > def shellquote(*strs): > ? ? ? ?return " ".join([ > ? ? ? ? ? ? ? ?"'"+st.replace("'","'\\''")+"'" > ? ? ? ? ? ? ? ?for st in strs > ? ? ? ?]) > > would do perfectly: shellquote('echo', "'", '"', " ", "\n") I was considering the more general case where one of the strings may have come from user input. You then need to also escape $looks_like_a_var, `some_command`, and way more other such stuff that your simple function doesn't cover. Even if the user is trusted, not escaping such things can still lead to bizarre unintended output/results. If the commands are completely static, then yes, I agree that lack of necessity then becomes the main argument against shell=True. Cheers, Chris -- http://rebertia.com From astley.lejasper at gmail.com Thu Aug 4 05:24:01 2011 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 4 Aug 2011 11:24:01 +0200 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Just to add a little bit to the mix, I have started having these problems since I rebuilt my machine (Xubuntu 11) and I changed the disc formats to ext4 without even thinking about it ... I was wondering if maybe that had something to do with it? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Aug 4 05:25:51 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Aug 2011 11:25:51 +0200 Subject: Snippet: The leanest Popen wrapper In-Reply-To: References: <51b2d157-3fea-4f8e-80b4-e7142629eca8@s21g2000pre.googlegroups.com> Message-ID: Am 04.08.2011 10:42 schrieb Chris Rebert: > I was considering the more general case where one of the strings may > have come from user input. You then need to also escape > $looks_like_a_var, `some_command`, and way more other such stuff that > your simple function doesn't cover. Even these things are harmless when included in ''s. $ echo '`rm -rf .`' '$RANDOM' `rm -rf .` $RANDOM Thomas From 1248283536 at qq.com Thu Aug 4 05:39:53 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 4 Aug 2011 17:39:53 +0800 Subject: ImportError: No module named PyQt4.QtGui Message-ID: i have installed such things: sudo apt-get install libqt4-dev sudo apt-get install g++ automake sudo apt-get install qt4-dev-tools qt4-designer qt4-doc sudo apt-get install libqt4-opengl-dev sudo apt-get install libqt4-sql-mysql libqt4-sql-odbc libqt4-sql-psql libqt4-sql-sqlite libqt4-sql-sqlite2 when i finished,input >>>from PyQt4.QtCore import * Traceback (most recent call last): File "", line 1, in ImportError: No module named PyQt4.QtCore would you mind to tell me how to solve it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Thu Aug 4 05:56:06 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 04 Aug 2011 11:56:06 +0200 Subject: ImportError: No module named PyQt4.QtGui In-Reply-To: References: Message-ID: <4E3A6CB6.30804@jollybox.de> On 04/08/11 11:39, ???? wrote: > i have installed such things: > > sudo apt-get install libqt4-dev > sudo apt-get install g++ automake > sudo apt-get install qt4-dev-tools qt4-designer qt4-doc > sudo apt-get install libqt4-opengl-dev > sudo apt-get install libqt4-sql-mysql libqt4-sql-odbc libqt4-sql-psql > libqt4-sql-sqlite libqt4-sql-sqlite2 > > when i finished,input >>>>from PyQt4.QtCore import * > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named PyQt4.QtCore > > would you mind to tell me how to solve it? > > http://lmgtfy.com/?q=debian+pyqt4 You haven't actually installed the python-qt4 bindings yet. All you installed is the C++ library. From steve+comp.lang.python at pearwood.info Thu Aug 4 05:56:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 19:56:41 +1000 Subject: range() vs xrange() Python2|3 issues for performance References: <4e3a0b9f$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3a6cda$0$29995$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano > wrote: >> a, b = divmod(n, i) >> if b == 0: >> total += a+i >> > > Wouldn't this fail on squares? It happens to give correct results as > far as I've checked; no square up to 10,000 is called perfect, and > there are no perfect squares in that range, but I think it's > technically using an incorrect intermediate result. Yes, you're correct -- it counts sqrt(n) twice as a factor if n is a perfect square. The obvious fix is to change the increment to: total += a if a==i else a+i I don't believe it actually makes a difference for perfect numbers, but it's worth getting right. -- Steven From gelonida at gmail.com Thu Aug 4 06:04:27 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 04 Aug 2011 12:04:27 +0200 Subject: PIL question. having exactly same font on multiple platforms Message-ID: I posted already a question, but perhaps the subject line wasn't clear. Subject line was "Text to image with same results on any platform" >From within a django application I'd like create a small image file (e.g. .png) which just contains some text. I wondered what library would be appropriate and would yield the same result independent of the OS (assuming the versions of the python libraries are the same) Images should be pixel identical independent on the platform on which the image is created. I made some attempts with PIL (Image / ImageFont / ImageDraw), but have difficulties getting the same font under Linux and windows. # ------------------------code starts here import Image import ImageFont import ImageDraw # Here I don't know how to get the same font file # for all platforms # Perhaps there is a tiny trick that I overlooked. font_file = get_font_file_name() # Is truetype a good choice for portable fonts? font = ImageFont.truetype(font_file, 20) img = Image.new("RGB", (800, 600), "#FFFFFF") draw = ImageDraw.Draw(image) draw.text( (100, 100), font=font, fill="#00FF00") # ---------------------------- end of code I could also install any other library (matplotlib??) if it were capable of creating consistent images independent on the platform. Thanks in advance for any suggestions. From t at jollybox.de Thu Aug 4 06:32:00 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 04 Aug 2011 12:32:00 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: References: Message-ID: <4E3A7520.3030609@jollybox.de> On 04/08/11 12:04, Gelonida N wrote: > I posted already a question, but perhaps the subject line wasn't clear. > > > Subject line was "Text to image with same results on any platform" > Oh, your original message was perfectly clear, and if I knew the answer, I might have responded. Anyway, into thought. > >>From within a django application > I'd like create a small image file (e.g. .png) > which just contains some text. > > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. > > I made some attempts with PIL (Image / ImageFont / ImageDraw), > but have difficulties getting the same font under Linux and windows. Perhaps PIL uses a different font rendering library on each platform? You could try to get around this by using http://code.google.com/p/freetype-py/ directly. It's also possible that different hinting settings on the different systems are playing a role somehow, somewhere. Perhaps you can tell freetype precisely what to do, I'm not sure. If you want exactly the same bitmap on different platforms, you could just scrap truetype alltogether, and use bitmaps directly, individually taking the characters you need from a resource file. (you know, one bitmap with all the characters at known coordinates - or a load of small bitmaps) Why do you need the images to be identical to the pixel anyway? Surely, if it's about comparing the text, you would just compare the strings? And if it's only for displaying the text, then why bother with details like that as long as it looks good? - Thomas From steve+comp.lang.python at pearwood.info Thu Aug 4 08:37:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 04 Aug 2011 22:37:27 +1000 Subject: PIL question. having exactly same font on multiple platforms References: Message-ID: <4e3a9288$0$29980$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. Short answer: you can't. Long answer: you might, if you can find identical fonts (not just fonts with the same name, but genuinely identical) for each platform, and find some way of telling each platform's font rendering software to use identical algorithms (e.g. kerning, hinting, scaling, sub-pixel rendering), and adjust for any other differences between platforms (e.g. font sizes on Windows tend to be larger than on Mac or Linux). And when I say "you might", I mean it is theoretically possibly, but practically speaking, you can't. Even longer answer: you can, if you ignore the platform font renderer, and use your own custom renderer; this is what (apparently) a number of Linux/Unix applications like Abiword and xpdf do (with varying levels of success). You still need to find identical fonts for each platform. Possibly the simplest way to do this is to stick to old-fashioned bitmapped fonts in fixed sizes, instead of Postscript or TrueType fonts -- assuming you don't mind your application's output looking like it was produced on a Macintosh in 1984. More information here: https://freddie.witherden.org/pages/font-rasterisation/ http://www.joelonsoftware.com/items/2007/06/12.html http://www.codinghorror.com/blog/2007/06/whats-wrong-with-apples-font-rendering.html http://jujusoft.com/?page_id=25 -- Steven From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Thu Aug 4 08:43:35 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Thu, 04 Aug 2011 08:43:35 -0400 Subject: PyWhich Message-ID: Hey c.l.p., I wrote a little python script that finds the file that a python module came from. Does anyone see anything wrong with this script? #!/usr/bin/python import sys if __name__ == '__main__': if len(sys.argv) > 1: try: m = __import__(sys.argv[1]) sys.stdout.write(m.__file__ + '\n') sys.stdout.flush() sys.exit(0) except ImportError: sys.stderr.write("No such module '%s'\n" % sys.argv[1]) sys.stderr.flush() sys.exit(1) else: sys.stderr.write("Usage: pywhich \n") sys.stderr.flush() sys.exit(0) -- Bill From myeates at jpl.nasa.gov Thu Aug 4 09:48:11 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 4 Aug 2011 06:48:11 -0700 Subject: making my extensions work together References: Message-ID: more info. I have a large 3rd party library with a function that looks like this void dumbfunc() { static int statevar=0; ++statevar; if (startvar ==3) printf("I have been called 3 times\n"); } and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make calls to dumbfunc. In creating the extensions, I linked to the 3rd party library. The behavior I want to see is >foo.dumbfunc() >goo.dumbfunc() >goo.dumbfunc() I have been called 3 times "Chris Angelico" wrote in message news:mailman.1880.1312441742.1164.python-list at python.org... > On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: >> I have 2 extensions and they both access a function in a (static) >> library. >> The function maintains state information using a static variable. > > If your extensions are DLLs and they're both linking to the same > static library, you should have two independent copies of that library > - which would mean they don't interfere with one another. That's why > the other extension doesn't see the change, and normally this is the > correct and desired behaviour. > > Having the two be aware of each other is potentially very messy. As > Stefan suggested, making one depend on the other would be a lot > simpler. Alternatively, there may be ways to have the two extensions > share data through Python itself. What are you looking to accomplish? > > ChrisA From benjamin.d.garrett at lmco.com Thu Aug 4 10:01:01 2011 From: benjamin.d.garrett at lmco.com (Garrett, Benjamin D) Date: Thu, 04 Aug 2011 10:01:01 -0400 Subject: python glibc issue Message-ID: Hi, I am running into a problem with Python 2.6 and SuSe 11 SP1. The error message looks just like this one: https://bugzilla.redhat.com/show_bug.cgi?id=556584 That link implies the fix is to upgrade to > glibc-2.11.90. But for this particular hardware, it would be difficult to upgrade the core operating system's glibc as novell hasn't blessed a version of glibc > 2.11.1. Also, using an upgraded dynamic/shared version of glibc seems to produce incompatibilities with core operating systems commands. So, is it possible to build python against a static version of glibc? I've tried installing a static glibc 2.12 on a different machine, then configuring python with 'configure -disable-shared --with-libc=/usr/lib64/libc_nonshared.a'. python builds but an ldd still seems to think the resulting executable depends on libc.so.6. I've tried google but found nothing concrete. Any other suggestions or comments would be greatly appreciated. Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From myeates at jpl.nasa.gov Thu Aug 4 10:04:39 2011 From: myeates at jpl.nasa.gov (Mathew) Date: Thu, 4 Aug 2011 07:04:39 -0700 Subject: making my extensions work together References: Message-ID: okay. It worked to make my 3'rd party library dynamic. Hopefully this will help someone else in the future. "Mathew" wrote in message news:j1cs2t$j2f$1 at news.jpl.nasa.gov... > This isn't exactly a Python question but maybe someone here has run into > this. > > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. > > This doesn't work. When one of my extensions changes the variable value, > the other extension does not see the change. > > Would it work if I made my library dynamic? > > This is on Windows XP compiling with MSVC 2008. > > -Mathew > From katriel at katriel.co.uk Thu Aug 4 10:18:38 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Thu, 4 Aug 2011 15:18:38 +0100 Subject: making my extensions work together In-Reply-To: References: Message-ID: Wrap your 3rd party library with a Python interface module, and run all calls from foo and goo through your interface. On Thu, Aug 4, 2011 at 2:48 PM, Mathew wrote: > more info. I have a large 3rd party library with a function that looks > like > this > void dumbfunc() { > static int statevar=0; > ++statevar; > if (startvar ==3) printf("I have been called 3 times\n"); > } > > and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make > calls to dumbfunc. In creating the extensions, I linked to the 3rd party > library. > > The behavior I want to see is > >foo.dumbfunc() > >goo.dumbfunc() > >goo.dumbfunc() > I have been called 3 times > > > "Chris Angelico" wrote in message > news:mailman.1880.1312441742.1164.python-list at python.org... > > On Thu, Aug 4, 2011 at 2:19 AM, Mathew wrote: > >> I have 2 extensions and they both access a function in a (static) > >> library. > >> The function maintains state information using a static variable. > > > > If your extensions are DLLs and they're both linking to the same > > static library, you should have two independent copies of that library > > - which would mean they don't interfere with one another. That's why > > the other extension doesn't see the change, and normally this is the > > correct and desired behaviour. > > > > Having the two be aware of each other is potentially very messy. As > > Stefan suggested, making one depend on the other would be a lot > > simpler. Alternatively, there may be ways to have the two extensions > > share data through Python itself. What are you looking to accomplish? > > > > ChrisA > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpjday at crashcourse.ca Thu Aug 4 11:28:09 2011 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Thu, 4 Aug 2011 11:28:09 -0400 (EDT) Subject: error compiling python, and "plat-linux2" versus "plat-linux3" Message-ID: i may have asked about this once upon a time but i'm still fighting with it so i'll throw myself on the mercy of the list and ask again. (and if there's a better forum for this question, let me know.) i'm using the development environment wind river linux 4.2 (hereafter just "WRL") to configure and build an entire embedded system, and that build is failing when it comes to compile python-2.6.2. i *think* i have an idea what the general problem is, but i need help to narrow it down. here's the tail end of the build process: ===== begin snippet ===== Checking for unpackaged file(s): /home/rpjday/WindRiver/projects/42/glibc_std/host-cross/bin/../lib64/rpm/check-files /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2 error: Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen RPM build errors: File not found: /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2/usr/lib64/python2.6/plat-linux2 Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:2661: *** [python.install] Error 1 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:3017: *** [python.buildlogger] Error 2 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/Makefile.common.epilogue:37: *** [all] Error 2 GNUmakefile:55: *** [all] Error 2 #0 all at /home/rpjday/WindRiver/projects/42/glibc_std/build/GNUmakefile:55 remake[2]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std/build' Command-line arguments: "all" Makefile:831: *** [all-recursive] Error 1 #0 all-recursive at /home/rpjday/WindRiver/projects/42/glibc_std/Makefile:831 remake[1]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std' Command-line arguments: "all-recursive" make: *** [all] Error 2 ===== end snippet ===== note the references to "plat-linux3" above -- i think that's what's killing me as i'm doing all this on a ubuntu 11.04 system with my own hand-rolled 3.x kernel and i think there's a step in the python build process that can't handle a running kernel with version "3.*". this is my suspicion as i've already found another location in the WRL build that clearly never imagined it would be run on a 3.x kernel (it recognized only "2.x" kernels as a hardcoded value.) another reason i think it's something like this is if i run just the prep step -- that is, untar the python-2.6.2 tarball and apply the WRL patches -- here's what i get in the resulting directory: $ grep -r plat-linux2 * Doc/install/index.rst: ['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2', Doc/install/index.rst:'/www/python/lib/pythonX.Y/plat-linux2', ...]``. Misc/RPM/python-2.6.spec:%{__prefix}/%{libdirname}/python%{libvers}/plat-linux2 Misc/HISTORY: * Lib/plat-sunos5/CDIO.py, Lib/plat-linux2/CDROM.py: Misc/HISTORY:e.g. lib-tk, lib-stdwin, plat-win, plat-linux2, plat-sunos5, dos-8x3. $ as you can see, it's all *hardcoded* references to "plat-linux2" so it's a mystery as to where the references to "plat-linux3" are coming from during the build process, which is why i suspect the reason i gave above -- that nothing took into account that this build would be done on a 3.x kernel. can anyone shed light on this? can anyone else *try* this on a system with a 3.x kernel and let me know what they get? i'm about to just hack the source and change that to "plat-linux3" to see what happens, but it would be nice to do something more intelligent. thanks. rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ======================================================================== From shilparani9030 at gmail.com Thu Aug 4 12:30:20 2011 From: shilparani9030 at gmail.com (SHILPA) Date: Thu, 4 Aug 2011 09:30:20 -0700 (PDT) Subject: ADULT HOT PICS Message-ID: <707e8c3e-f337-430c-9597-876599f8db8b@f17g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html MAHESH BABU WORKING STILLS IN DHOOKUDU http://princemaheshfanz.blogspot.com/2011/08/dookudu-working-stills.html NAMRATHA IN NATIONAL BREAST FEEDING http://princemaheshfanz.blogspot.com/2011/08/namrata-shirodkar-at-national-breast.html From ethan at stoneleaf.us Thu Aug 4 13:04:48 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 10:04:48 -0700 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: <4E3AD130.6070704@stoneleaf.us> Steve Holden wrote: > We would ideally like the last project to to be something that > demonstrates at least some minimal involvement with the Python > community. Something like "get a Python answer upvoted on > StackOverflow", for example, or getting a question answered on c.l.p. At > the same time it shouldn't be anything that places a burden on the > community (otherwise the hundredth student would be abused and the > thousandth murdered). The problem I see with either of those is making the student's academic standing dependent on the actions of strangers. Having said that... Posting a question to c.l.py is fine if you have a real question, but if you don't... Of the two, I like the StackOverflow option better -- but keep in mind that at this moment, about 6,600 unanswered Python questions remain. (I've made it to page 23 of 132 over the last week.) Getting an answer upvoted can be pretty hit-and-miss. Perhaps the thing to do is have a wide range of options, any one of which will satisfy the requirement -- some will have questions to post, others may have a bug to file or, even better, a patch for a bug, others can go the StackOverflow route, someone may have a module to put on PyPI, etc., etc. Hope this helps! ~Ethan~ From sparkytwobillion at gmail.com Thu Aug 4 13:19:36 2011 From: sparkytwobillion at gmail.com (sparky gmail) Date: Thu, 04 Aug 2011 10:19:36 -0700 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: <4E3AD4A8.8020607@gmail.com> On 8/3/2011 8:14 PM, Steve Holden wrote: > [Ccs appreciated] > > After some three years labor I (@holdenweb) at last find myself > approaching the completion of the Python Certificate Series with > O'Reilly School of Technology (@OReillySchool). > > At OSCON last week the team fell to talking about the final assignment > (although the Certificate is not a certification, students only > progress by answering real quiz questions, not the usual > multiple-choice task). Success also requires that they complete a > project at the end of each (of the ~60) lesson(s). > > We would ideally like the last project to to be something that > demonstrates at least some minimal involvement with the Python > community. Something like "get a Python answer upvoted on > StackOverflow", for example, or getting a question answered on c.l.p. > At the same time it shouldn't be anything that places a burden on the > community (otherwise the hundredth student would be abused and the > thousandth murdered). > > So I wondered if anyone had any good ideas. > > regards > Steve > -- > Steve Holden > steve at holdenweb.com > > > Just a thought. What about contributing code or documentation to an established project? I dislike the idea of getting an answer up voted. First of all, for people trying to do it honestly you are putting their completion into the hands of strangers, secondly, it would be very easy to cheat by having someone else, or themselves with a puppet account, up vote the answer. There are a metric grip of established projects that could use a little help with documentation, code examples, etc. I think this is a better route to community participation. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Aug 4 13:22:43 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 10:22:43 -0700 Subject: PyWhich In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 5:43 AM, Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module came > from. ?Does anyone see anything wrong with this script? > > > #!/usr/bin/python > > import sys > if __name__ == '__main__': > ? ?if len(sys.argv) > 1: > ? ? ? ?try: > ? ? ? ? ? ?m = __import__(sys.argv[1]) > ? ? ? ? ? ?sys.stdout.write(m.__file__ + '\n') > ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ?sys.exit(0) > ? ? ? ?except ImportError: > ? ? ? ? ? ?sys.stderr.write("No such module '%s'\n" % sys.argv[1]) > ? ? ? ? ? ?sys.stderr.flush() > ? ? ? ? ? ?sys.exit(1) > ? ?else: > ? ? ? ?sys.stderr.write("Usage: pywhich \n") > ? ? ? ?sys.stderr.flush() > ? ? ? ?sys.exit(0) Nothing wrong per se, but the flush()es seem unnecessary, and why do stdout.write() when you can just print()? Cheers, Chris -- I can't not think of the pitchman when I read your posts... http://rebertia.com From python.list at tim.thechases.com Thu Aug 4 14:24:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Aug 2011 13:24:13 -0500 Subject: PyWhich In-Reply-To: References: Message-ID: <4E3AE3CD.6020906@tim.thechases.com> On 08/04/2011 07:43 AM, Billy Mays wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module > came from. Does anyone see anything wrong with this script? > > #!/usr/bin/python > > import sys > if __name__ == '__main__': > if len(sys.argv)> 1: > try: > m = __import__(sys.argv[1]) > sys.stdout.write(m.__file__ + '\n') For a quick script in a controlled environment, not bad. In a hostile environment, I'd be nervous about running arbitrary module code triggered by the import. Even if non-malicious, some imports (like PyCrypto) may have some initialization lag which would be nice to avoid. I think I'd make use of imp.find_module to write it something like this (untested) from sys import argv, stderr import imp type_map = { imp.PY_SOURCE: "Source file", imp.PY_COMPILED: "Compiled code object", imp.C_EXTENSION: "Dynamically loadabld shared library", imp.PKG_DIRECTORY: "Package directory", imp.C_BUILTIN: "Built-in", imp.PY_FROZEN: "Frozen module", } if __name__ == '__main__': if len(argv) > 1: for modname in argv[1:]: try: fp, pth, desc = imp.find_module(modname) (suffix, mode, type_) = desc if fp is not None: fp.close() print("%s\t[%s]" % ( pth, type_map.get(type_, "UNKNOWN") )) except ImportError: stderr.write("No such module '%s'\n" % modname) else: stderr.write("Usage: pywhich [...]\n") I don't know a good way to tap into other import hooks (such as the zipfile import) to augment that type_map dictionary. -tkc From nephish at gmail.com Thu Aug 4 14:26:23 2011 From: nephish at gmail.com (nephish) Date: Thu, 4 Aug 2011 11:26:23 -0700 (PDT) Subject: problem with bcd and a number Message-ID: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both bytes are BCD-encoded, with the LSB containing digits zX and MSB containing digits xy. The system speed is then xyz%, where 100% means maximum speed and would be given by bytes 00(LSB) 10(MSB)." that is a quote from the documentation. Anyway, i am able to parse out the two bytes i need, but don't know where to go from there. thanks for any tips on this. From nephish at gmail.com Thu Aug 4 14:31:22 2011 From: nephish at gmail.com (nephish) Date: Thu, 4 Aug 2011 11:31:22 -0700 (PDT) Subject: problem with bcd and a number Message-ID: Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both bytes are BCD-encoded, with the LSB containing digits zX and MSB containing digits xy. The system speed is then xyz%, where 100% means maximum speed and would be given by bytes 00(LSB) 10(MSB)." that is a quote from the documentation. Anyway, i am able to parse out the two bytes i need, but don't know where to go from there. thanks for any tips on this. From gelonida at gmail.com Thu Aug 4 14:54:47 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 04 Aug 2011 20:54:47 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4E3A7520.3030609@jollybox.de> References: <4E3A7520.3030609@jollybox.de> Message-ID: On 08/04/2011 12:32 PM, Thomas Jollans wrote: > On 04/08/11 12:04, Gelonida N wrote: Thanks for your answer. >> >From within a django application >> I'd like create a small image file (e.g. .png) >> which just contains some text. >> >> I wondered what library would be appropriate and would yield the same >> result independent of the OS (assuming the versions of the python >> libraries are the same) >> Images should be pixel identical independent on the platform on which >> the image is created. >> >> I made some attempts with PIL (Image / ImageFont / ImageDraw), >> but have difficulties getting the same font under Linux and windows. > > Perhaps PIL uses a different font rendering library on each platform? > You could try to get around this by using > http://code.google.com/p/freetype-py/ directly. It's also possible that > different hinting settings on the different systems are playing a role > somehow, somewhere. Perhaps you can tell freetype precisely what to do, > I'm not sure. The reason why I want the images to look identical is very simple. Though the final web server will run on a linux server, I use sometimes windows for development or as test server. For automated tests I would have liked pixel identical images. this allows calculating the md5sum of images to know whether a regression in the image layout occured. Well I can live without it. The second (more import issue) is, that the images should look the same whether created on a Windows or Linux host. I didn't know that PIL delegated font rendering to the underlying OS, but thought it contains its own rendering. Here the problem is not if a few pixels are different, but currently I even don't know how to choose a font, and make sure it exists on both platforms. I also don't know how I can write portable python code, that will find a given font on windows and on linux independent of the exact font location. > > If you want exactly the same bitmap on different platforms, you could > just scrap truetype alltogether, and use bitmaps directly, individually > taking the characters you need from a resource file. (you know, one > bitmap with all the characters at known coordinates - or a load of small > bitmaps) A resource file or a bitmapped font packaged with my application might be a solution. I just had to learn where to get one from or how to create one without any copyright issues > > Why do you need the images to be identical to the pixel anyway? Surely, > if it's about comparing the text, you would just compare the strings? > And if it's only for displaying the text, then why bother with details > like that as long as it looks good? I hope I clarified a little what I was looking for. It's not necessarily pixel true, but it should not be too visible whether the image was rendered on a windows or linux PC From davea at ieee.org Thu Aug 4 15:28:58 2011 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Aug 2011 15:28:58 -0400 Subject: problem with bcd and a number In-Reply-To: References: Message-ID: <4E3AF2FA.7000207@ieee.org> On 01/-10/-28163 02:59 PM, nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. > Your problem is simply to extract the two nibbles from a byte. Then you can use trivial arithmetic to combine the nibbles. Error checking is another matter. First you need to specify whether this is Python 2.x or Python 3.x. In this message I'll assume 2.7 >>> val = "\x47" >>> print val G >>> print ord(val) 71 >>> print ord(val)/16 4 >>> print ord(val)%16 7 >>> DaveA From irmen.NOSPAM at xs4all.nl Thu Aug 4 15:30:59 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Aug 2011 21:30:59 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: References: <4E3A7520.3030609@jollybox.de> Message-ID: <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> On 4-8-2011 20:54, Gelonida N wrote: > The reason why I want the images to look identical is very simple. > Though the final web server will run on a linux server, I use sometimes > windows for development or as test server. > > For automated tests I would have liked pixel identical images. > this allows calculating the md5sum of images to know whether > a regression in the image layout occured. Well I can live without it. Then don't run your automated tests on the dev server but deploy your stuff to a separate test server first, that runs the same software as production. And run the tests there. > The second (more import issue) is, that the images should look the same > whether created on a Windows or Linux host. > > I didn't know that PIL delegated font rendering to the underlying OS, > but thought it contains its own rendering. I'm pretty sure it does have that indeed; it links with the freetype library. Are you sure you're not just seeing differences because of differences in the typeface itself? A courier.ttf on one system can look very different from a ms-courier-new.ttf on another... > Here the problem is not if a few pixels are different, but currently I > even don't know how to choose a font, and make sure it exists on both > platforms. I also don't know how I can write portable python code, that > will find a given font on windows and on linux independent of the exact > font location. I once made a module that uses PIL to draw captcha images. It uses one of the free truetype font files that I just place next to the code. I downloaded the ttf files from http://www.fontgirl.com/ but there are dozens of free font sites. Just be sure to check the license terms of the the typeface files. As far as I know, I did not see any difference in output on windows, linux and mac os x as long as the code used the same ttf file and PIL versions. (but I'll double check now and see if I remember this correctly). Irmen From ch at radamanthys.de Thu Aug 4 15:31:19 2011 From: ch at radamanthys.de (Christoph Hansen) Date: Thu, 04 Aug 2011 21:31:19 +0200 Subject: problem with bcd and a number In-Reply-To: References: Message-ID: nephish schrieb: > thanks for any tips on this. I'll try. In BCD a (decimal) digit is stored in a halfbyte (or a 'nibble'). So, in a byte you can store two decimal digits. For instance 42 would be nibble1 nibble2 0100 0010 4 2 >>> c=0b01000010 >>> c 66 >>> c >> 4 # first nibble 4 >>> c & 0b1111 # second nibble 2 So, a speed of 57% should be LSB= 0111 0000 MSB= 0000 0101 From python at mrabarnett.plus.com Thu Aug 4 15:35:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Aug 2011 20:35:18 +0100 Subject: problem with bcd and a number In-Reply-To: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <4E3AF476.9050502@mrabarnett.plus.com> On 04/08/2011 19:26, nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. The value is MSB * 100 + (LSB >> 4) * 10 + (LSB & 0xF) From ethan at stoneleaf.us Thu Aug 4 15:44:41 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 12:44:41 -0700 Subject: problem with bcd and a number In-Reply-To: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <4E3AF6A9.3090004@stoneleaf.us> nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. As I recall, when you cut a byte in half you get two nibbles. You need to translate your nibbles into numbers, then multiply and add -- something like this: 8<--- bcd.py ---------------------------------------------------------- def bcd_to_int(msb, lsb): """msb has two decimal digits, lsb has one e.g. msb has xy=10, lsb has zX = 00, actual number (xyz) is 100""" ones = lsb >> 4 tens = msb & 0x0f hundreds = msb >> 4 if ones > 9 or tens > 9 or hundreds > 9: raise ValueError( "invalid BCD digits in %02x %02x" % (msb, lsb) ) tens *= 10 hundreds *= 100 answer = hundreds + tens + ones return answer if __name__ == '__main__': import unittest class Test_BCD(unittest.TestCase): def test_valid(self): msb = 0x09 lsb = 0x34 # 4 will be discarded as garbage self.assertEqual(bcd_to_int(msb, lsb), 93) def test_invalid(self): msb = 0x1a lsb = 0x10 self.assertRaises(ValueError, bcd_to_int, msb, lsb) unittest.main() 8<--------------------------------------------------------------------- Hope this helps. ~Ethan~ From nospam at torek.net Thu Aug 4 15:49:44 2011 From: nospam at torek.net (Chris Torek) Date: 4 Aug 2011 19:49:44 GMT Subject: Early binding as an option References: <4e39200f$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e39a6b5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: >Chris Angelico wrote: [snippage] >> def func(x): >> len = len # localize len >> for i in x: >> len(i) # use it exactly as you otherwise would In article <4e39a6b5$0$29973$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >That can't work. The problem is that because len is assigned to in the body >of the function, the Python compiler treats it as a local variable. So the >line len=len is interpreted as len = len, which doesn't yet >exist. There's no way of saying len = len in the body of the >function. > >So you must either: > >(1) use a different name: length = len > >(2) use a fully-qualified name: import builtins; len = builtins.len (This is my preferred form, given what one has now, if one is going to do this in the function body. Of course in 2.x it is spelled __builtin__.len instead...) >(3) do the assignment as a default parameter, which has slightly different >binding rules: def func(x, len=len) > >(4) manual lookup: len = builtins.__dict__['len'] # untested > > >I don't recommend that last one, unless you're deliberately trying to write >obfuscated code :) If Python *were* to have some kind of "tie this symbol down now" operation / keyword / whatever, one could write: def func(x): snap len # here the new keyword is "snap" for i in x: ... len(i) ... # use it exactly as you otherwise would Of course there is no *need* for any new syntax with the other construction: def func(x, len=len) # snapshots "len" at def() time for i in x: ... len(i) ... but if one were to add it, it might look like: def func(x, snap len): The advantage (?) of something like a snap or snapshot or whatever keyword / magic-function / whatever is that you can apply it to more than just function names, e.g.: def func(arg): # for this example, assume that arg needs to have the # following attributes: snap arg.kloniblatt, arg.frinkle, arg.tippy ... Here, in the "..." section, a compiler (whether byte-code, or JIT, or whatever -- JIT makes the most sense in this case) could grab the attributes, looking up their types and any associated stuff it wants to, and then assume that for the rest of that function's execution, those are not allowed to change. (But other arg.whatever items are, here. If you want to bind *everything*, perhaps "snap arg" or "snap arg.*" -- see below.) Even a traditional (CPython) byte-code compiler could do something sort of clever here, by making those attributes "read-only" to whatever extent the snapshot operation is defined as fixing the binding (e.g., does it recurse into sub-attributes? does it bind only the name-and-type, or does it bind name-and-type-and-value, or name-and-type-and-function-address-if-function, or ... -- all of which has to be pinned down before any such suggestion is taken too seriously :-) ). -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ch at radamanthys.de Thu Aug 4 15:52:45 2011 From: ch at radamanthys.de (Christoph Hansen) Date: Thu, 04 Aug 2011 21:52:45 +0200 Subject: problem with bcd and a number In-Reply-To: References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: MRAB schrieb: > The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) i would say (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) but who knows From ethan at stoneleaf.us Thu Aug 4 16:14:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Aug 2011 13:14:18 -0700 Subject: problem with bcd and a number In-Reply-To: <4E3AF476.9050502@mrabarnett.plus.com> References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> <4E3AF476.9050502@mrabarnett.plus.com> Message-ID: <4E3AFD9A.6060403@stoneleaf.us> MRAB wrote: > On 04/08/2011 19:26, nephish wrote: >> Hey all, >> >> I have been trying to get my head around how to do something, but i am >> missing how to pull it off. >> I am reading a packet from a radio over a serial port. >> >> i have " two bytes containing the value i need. The first byte is the >> LSB, second is MSB. Both bytes are BCD-encoded, with the LSB >> containing digits zX and MSB containing digits xy. The system speed >> is then xyz%, where 100% means maximum speed and would be given by >> bytes 00(LSB) 10(MSB)." >> >> that is a quote from the documentation. >> Anyway, i am able to parse out the two bytes i need, but don't know >> where to go from there. >> >> thanks for any tips on this. > > The value is MSB * 100 + (LSB >> 4) * 10 + (LSB & 0xF) Not according to the docs -- msb has two digits, lsb has one and garbage. ~Ethan~ From irmen.NOSPAM at xs4all.nl Thu Aug 4 16:24:54 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Aug 2011 22:24:54 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> References: <4E3A7520.3030609@jollybox.de> <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> On 4-8-2011 21:30, Irmen de Jong wrote: > As far as I know, I did not see any difference in output on windows, linux and mac os x > as long as the code used the same ttf file and PIL versions. (but I'll double check now > and see if I remember this correctly). To follow up on myself, I've just tested it with the same ttf file on windows, os x and linux. (made an image in font size 40 with 'The quick brown fox....' as text line) The resulting image files were byte-identical between os x and linux but the windows ones were slightly different (just by a few bytes). The text in the image itself looked identical though to the ones from the other systems (I couldn't see any difference by looking at it) so I presume the difference is in the image compression or file header metadata. PIL's font rendering seems to produce identical results across platforms and if you see a difference it must be caused by a difference in typeface file (or perhaps a different PIL/freetype version on the platform). Irmen From rhodri at wildebst.demon.co.uk Thu Aug 4 17:31:47 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 04 Aug 2011 22:31:47 +0100 Subject: Community Involvement References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Thu, 04 Aug 2011 18:04:48 +0100, Ethan Furman wrote: > Of the two, I like the StackOverflow option better -- but keep in mind > that at this moment, about 6,600 unanswered Python questions remain. > (I've made it to page 23 of 132 over the last week.) Getting an answer > upvoted can be pretty hit-and-miss. The other thing that may affect this is that anything posted to SE is subject to the Creative Commons license. This may be an issue for academic purposes, I don't know. (It's certainly an issue when you come across J*ff!) -- Rhodri James *-* Wildebeest Herder to the Masses From nobody at nowhere.com Thu Aug 4 17:35:02 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Aug 2011 22:35:02 +0100 Subject: Inconsistencies with tab/space indentation between Cygwin/Win32? References: Message-ID: On Thu, 04 Aug 2011 13:55:37 +0930, Christian Gelinek wrote: > I find it at least confusing to read that Python expects a tab size of 8 but > at the same time uses 4 spaces for one indent level. Or maybe I am > completely on the wron track here? 4-column indents are a convention, not a rule. You can use however many columns you like, and you don't even need to be consistent about it; you can use 2 columns for one "block" and 4 columns for another. Python only cares about "indented more than the previous line" and "indented to a depth matching an outer level of the code". 8-column tab stops are a rule, due to it being such a long-standing convention that some software and hardware has 8-column tab stops hardwired (and anything which allows tab stops to be configured normally defaults to 8 columns). > Any ideas on how to get the thing to run under (real) Windows, hopefully > without having to edit existing sources of people who left our company ages > ago? The only time you'll have problems is if you copy-and-paste code which was written using a mix of tabs and spaces and which assumed a different tab width. If code only ever uses tabs, the tab width doesn't matter. If code uses a mix of tabs and spaces and it actually works, it's correct according to Python's 8-column tab stops, even if that's not how the programmer's editor was set up. Also, copying blocks of code which start and end at the top-level (i.e. without indentation) will work regardless. Where it fails is if you copy indented code from e.g. a file which used a mix of spaces and 4-column tabs into a file which uses 8-column tabs. If you have existing code which uses a mix of tabs and spaces where tabs aren't 8 columns (or you aren't sure that they're 8 columns), your best bet is to reformat the code to avoid using tabs (on Unix: "pr -t -e", or "pr -t -e4" for 4-column tabs). From ericsnowcurrently at gmail.com Thu Aug 4 17:42:22 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 4 Aug 2011 15:42:22 -0600 Subject: Community Involvement In-Reply-To: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Wed, Aug 3, 2011 at 9:14 PM, Steve Holden wrote: > [Ccs appreciated] > After some three years labor I (@holdenweb) at last find myself approaching > the completion of the Python Certificate Series with O'Reilly School of > Technology (@OReillySchool). > At OSCON last week the team fell to talking about the final assignment > (although the Certificate is not a certification, students only progress by > answering real quiz questions, not the usual multiple-choice task). Success > also requires that they complete a project at the end of each (of the ~60) > lesson(s). > We would ideally like the last project to to be something that demonstrates > at least some minimal involvement with the Python community. Something like > "get a Python answer upvoted on StackOverflow", for example, or getting a > question answered on c.l.p. At the same time it shouldn't be anything that > places a burden on the community (otherwise the hundredth student would be > abused and the thousandth murdered). > So I wondered if anyone had any good ideas. While not as "community" as the mailing lists, perhaps they could post a recipe to the activestate. -eric > regards > ?Steve > -- > Steve Holden > steve at holdenweb.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From drsalists at gmail.com Thu Aug 4 19:24:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 4 Aug 2011 16:24:13 -0700 Subject: PyWhich In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 10:22 AM, Chris Rebert wrote: > > > #!/usr/bin/python > > > > import sys > > if __name__ == '__main__': > > if len(sys.argv) > 1: > > try: > > m = __import__(sys.argv[1]) > > sys.stdout.write(m.__file__ + '\n') > > sys.stdout.flush() > > sys.exit(0) > > except ImportError: > > sys.stderr.write("No such module '%s'\n" % sys.argv[1]) > > sys.stderr.flush() > > sys.exit(1) > > else: > > sys.stderr.write("Usage: pywhich \n") > > sys.stderr.flush() > > sys.exit(0) > > Nothing wrong per se, but the flush()es seem unnecessary, and why do > stdout.write() when you can just print()? > The flushes are unnecessary, but sys.stdout.write has an advantage over print: sys.stdout.write works pretty much the same in both 2.x and 3.x; print doesn't. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peterirbizon at gmail.com Thu Aug 4 19:26:59 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Fri, 5 Aug 2011 01:26:59 +0200 Subject: HSeparator() in gtk.layour Message-ID: hello, how can I add hseparator to gtk.layout? I tried hseparator = gtk.HSeparator() self.layout.put(hseparator, 50, 195) but it does not work :/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Thu Aug 4 19:37:04 2011 From: gelonida at gmail.com (Gelonida N) Date: Fri, 05 Aug 2011 01:37:04 +0200 Subject: PIL question. having exactly same font on multiple platforms In-Reply-To: <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> References: <4E3A7520.3030609@jollybox.de> <4e3af374$0$23918$e4fe514c@news2.news.xs4all.nl> <4e3b0016$0$23932$e4fe514c@news2.news.xs4all.nl> Message-ID: Thanks again to everybody, Your answers helped me to understand better. My pragmatic solution is now to package my program with an open source .ttf font, which will be used on both platforms. On 08/04/2011 10:24 PM, Irmen de Jong wrote: > On 4-8-2011 21:30, Irmen de Jong wrote: > >> As far as I know, I did not see any difference in output on windows, linux and mac os x >> as long as the code used the same ttf file and PIL versions. (but I'll double check now >> and see if I remember this correctly). > > To follow up on myself, I've just tested it with the same ttf file on windows, os x and > linux. (made an image in font size 40 with 'The quick brown fox....' as text line) The > resulting image files were byte-identical between os x and linux but the windows ones > were slightly different (just by a few bytes). The text in the image itself looked > identical though to the ones from the other systems (I couldn't see any difference by > looking at it) so I presume the difference is in the image compression or file header > metadata. > > PIL's font rendering seems to produce identical results across platforms and if you see > a difference it must be caused by a difference in typeface file (or perhaps a different > PIL/freetype version on the platform). > What I finally did was following: I copied a ttf font whoose copyright seems to be permissive ('Vera.ttf') from my linux machine to my windows host. I wrote following script: import Image import ImageFont, ImageDraw import ImageChops im = Image.new( "RGB", (250,60) , "#000000" ) draw = ImageDraw.Draw(im) font = ImageFont.truetype("Vera.ttf", 40) draw.text((5, 5), "Hello world", font=font) im.save("img.png") im = Image.open('img.png') iml = Image.open('img_other.png') diff = ImageChops.difference(im, iml) diff.save('diff.png') and ran it on one machine then I copied the generated file img.png to my other platform and renamed it to img_other.png then I ran my script there and displayed diff.png What I see (but I do not have the same version of PIL on both machines) is, that the images are different, though the difference as rather local and not too huge. So copying an open source ttf font to my windows machine creates fonts, which are from an optical aspect similair enough. I will still check whether the imgaes are identical if using the same font file and the same PIL version. THis should clarify whether the OS is involved in rendering the images or not. If really wanted to run automated tests verifying the image result I could still do it by saving the md5sums for both platforms and veryfing whether the result is identical to one of them. From gelonida at gmail.com Thu Aug 4 19:56:26 2011 From: gelonida at gmail.com (Gelonida N) Date: Fri, 05 Aug 2011 01:56:26 +0200 Subject: Text to image with same results on any platform In-Reply-To: References: Message-ID: Just FYI. Thread continued in thread with the subject line 'PIL question. having exactly same font on multiple platforms' I'm currently not pixel true, but images are sufficiently similiar. On 08/03/2011 11:40 AM, Gelonida N wrote: > Hi, > > >>From within a django application > I'd like create a small image file (e.g. .png) > which just contains some text. > > I wondered what library would be appropriate and would yield the same > result independent of the OS (assuming the versions of the python > libraries are the same) > Images should be pixel identical independent on the platform on which > the image is created. > > I made some attempts with PIL (Image / ImageFont / ImageDraw), > but have difficulties getting the same font under Linux and windows. > > From shawn at skrite.net Thu Aug 4 20:15:46 2011 From: shawn at skrite.net (shawn bright) Date: Thu, 4 Aug 2011 19:15:46 -0500 Subject: problem with bcd and a number In-Reply-To: <4E3AF2FA.7000207@ieee.org> References: <4E3AF2FA.7000207@ieee.org> Message-ID: Thanks for your help on this, gents. Got it working now. shawn On Thu, Aug 4, 2011 at 2:28 PM, Dave Angel wrote: > nibbles from a byte -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Aug 4 20:34:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 10:34:56 +1000 Subject: PyWhich References: Message-ID: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module > came from. Does anyone see anything wrong with this script? Yes -- the most screamingly obvious question has to be, why are you writing directly to sys.stdout instead of just using print? > #!/usr/bin/python I believe the recommended, platform independent hash-bang line is #!/usr/bin/which python > import sys > if __name__ == '__main__': > if len(sys.argv) > 1: > try: > m = __import__(sys.argv[1]) The major risk here is whether or not you trust the module enough to import it and run arbitrary code. The alternative would be a lot more work: you would have to duplicate the logic of the import statement, search the PYTHONPATH, look for packages, inside zip files, etc. > sys.stdout.write(m.__file__ + '\n') Built-in modules don't have a __file__ attribute. The most obvious example: >>> import builtins # spelled __builtin__ in Python 2.x >>> builtins.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' Also, __file__ is not always entirely honest. In Python 3, module.__file__ may report a .py file when it is actually loaded from a .pyc file, even if the .py file doesn't exist. So if you care about the distinction between .py, .pyc, .pyo etc. files, looking at __file__ alone will be inadequate. > except ImportError: > sys.stderr.write("No such module '%s'\n" % sys.argv[1]) That's not a given -- it may be that the module exists, but importing fails for some other reason. I would recommend not catching ImportError at all, and just let the standard Python error handling print the traceback. Especially for a tool aimed at programmers (who else would be interested in PyWhich?), hiding useful diagnostic errors and replacing them with a generic, and potentially wrong, message, is very bad. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 4 20:40:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 10:40:08 +1000 Subject: with statement and context managers References: <4e38af51$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3b3be9$0$29989$c3e8da3$5496439d@news.astraweb.com> Thomas Rachel wrote: > Am 03.08.2011 04:15 schrieb Steven D'Aprano: [...] > > but to me that looks badly wrong. Surely the spam context manager > > object will exit after the first iteration, and always raise an > > exception on the second? But I don't quite understand context > > managers enough to be sure. > > Depends on the implementation. As already stated, a > contextlib.contextmanager will only run once. But it is easy to turn it > into a persistent one - which internally initializes as often as needed. Thanks, that's exactly the sort of information I was after. Thank you to everyone who answered. -- Steven From drsalists at gmail.com Thu Aug 4 20:40:51 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 4 Aug 2011 17:40:51 -0700 Subject: problem with bcd and a number In-Reply-To: References: <4E3AF2FA.7000207@ieee.org> Message-ID: It sounds like you have what you need, but here's an amusing way of dealing with a BCD byte: >>> print int(hex(0x72).replace('0x', '')) 72 On Thu, Aug 4, 2011 at 5:15 PM, shawn bright wrote: > Thanks for your help on this, gents. Got it working now. > shawn > > On Thu, Aug 4, 2011 at 2:28 PM, Dave Angel wrote: > >> nibbles from a byte > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Aug 4 21:04:15 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Aug 2011 20:04:15 -0500 Subject: PyWhich In-Reply-To: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E3B418F.3050906@tim.thechases.com> On 08/04/2011 07:34 PM, Steven D'Aprano wrote: > Billy Mays wrote: >> #!/usr/bin/python > > I believe the recommended, platform independent hash-bang line is > > #!/usr/bin/which python I think you mean #!/usr/bin/env python -tkc From tjreedy at udel.edu Thu Aug 4 21:21:09 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Aug 2011 21:21:09 -0400 Subject: error compiling python, and "plat-linux2" versus "plat-linux3" In-Reply-To: References: Message-ID: There has been some discussion about what to do with 'linux3'. See http://bugs.python.org/issue12326 for example. -- Terry Jan Reedy From steve at holdenweb.com Thu Aug 4 21:46:28 2011 From: steve at holdenweb.com (Steve Holden) Date: Thu, 4 Aug 2011 21:46:28 -0400 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: Haven't had much Cc input so far, but this one is definitely worth following up on. Thanks! regards Steve On Aug 4, 2011, at 5:42 PM, Eric Snow wrote: > On Wed, Aug 3, 2011 at 9:14 PM, Steve Holden wrote: >> [Ccs appreciated] >> After some three years labor I (@holdenweb) at last find myself approaching >> the completion of the Python Certificate Series with O'Reilly School of >> Technology (@OReillySchool). >> At OSCON last week the team fell to talking about the final assignment >> (although the Certificate is not a certification, students only progress by >> answering real quiz questions, not the usual multiple-choice task). Success >> also requires that they complete a project at the end of each (of the ~60) >> lesson(s). >> We would ideally like the last project to to be something that demonstrates >> at least some minimal involvement with the Python community. Something like >> "get a Python answer upvoted on StackOverflow", for example, or getting a >> question answered on c.l.p. At the same time it shouldn't be anything that >> places a burden on the community (otherwise the hundredth student would be >> abused and the thousandth murdered). >> So I wondered if anyone had any good ideas. > > While not as "community" as the mailing lists, perhaps they could post > a recipe to the activestate. > > -eric > >> regards >> Steve >> -- >> Steve Holden >> steve at holdenweb.com >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> -- Steve Holden steve at holdenweb.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 4 22:03:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 03:03:39 +0100 Subject: PyWhich In-Reply-To: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano wrote: > Especially for a tool aimed at programmers (who else would be interested in > PyWhich?) The use that first springs to my mind is debugging import paths etc. If you have multiple pythons installed and aren't sure that they're finding the right modules, you could fire up PyWhich on an innocuous module like math or sys, and see if it's loading it from the right path. People doing this might not necessarily be programmers, they might be sysadmins; but you're right that it's most likely this will be used by competent Python programmers. ChrisA From jdriselvato at gmail.com Thu Aug 4 23:25:33 2011 From: jdriselvato at gmail.com (John Riselvato) Date: Thu, 4 Aug 2011 23:25:33 -0400 Subject: JSON Strict Mode Message-ID: I am working on a license verification script. I am rather new to the concept and to JSON files in general. This is what my pseudocode looks like: licenses = meta['license'] > for x in licenses: > if licenses[x]['terms'] is not valid opensource license > if in strict mode > raise nonfree exception > > How would i go about checking if its in "strick mode" and what does "raise nonfree exception" mean? -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Aug 5 02:19:44 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Aug 2011 23:19:44 -0700 Subject: JSON Strict Mode In-Reply-To: References: Message-ID: On Thu, Aug 4, 2011 at 8:25 PM, John Riselvato wrote: > I am working on a license?verification?script. I am rather new to the > concept and to JSON files in general. Based on your questions, reading a programming tutorial might be a good idea. Here's one that uses Python and that I've heard praise for: http://openbookproject.net/thinkcs/python/english3e/ The official tutorial is also worth reading: http://docs.python.org/dev/tutorial/ Once you understand Python's basic datatypes, JSON is a breeze; they are extremely similar. > This is what my pseudocode looks like: >> >> licenses = meta['license'] >> for x in licenses: >> if licenses[x]['terms'] is not valid opensource license I would probably instead write that as: for license_name, license in licenses.items(): if not is_open_source(license['terms']): # rest same as before >> if in strict mode >> raise nonfree exception > > How would i go about checking if its in "strict mode" You would have a boolean* variable somewhere indicating whether or not the program is in strict mode. Its value would presumably be set based on user input, or a configuration file, or whatever is applicable to your program; e.g.: strict = True strict = False config = parse_configuration_file() if config.strict: # whatever > and what does "raise nonfree exception" mean? I regret that the Wikipedia article on the topic of exceptions isn't too approachable. So, I'll instead refer you to the relevant section of the Python tutorial: http://docs.python.org/dev/tutorial/errors.html#errors-and-exceptions (Disclaimer: The following is oversimplified and somewhat Python-specific.) In a nutshell, an exception is type of object** used to indicate that a program has encountered an error; it contains details about the error and its cause. When a program encounters an error, it stores information about the error into a new exception object and then "raises" (using, in Python, the "raise" statement) this object so that the program can properly react to the error. By virtue of the "raise", normal execution of the program stops, and control is transferred to another part of the program which previously registered itself as being capable of handling the kind of error in question. The code in that part of the program then examines the exception object that was raised and takes appropriate action to deal with the error. If no part of the program registered itself as capable of handling the kind of error in question, a detailed error message is output and the program exits. In your specific example, the non-pseudo-code would look something like: # a declaration somewhere: class NonFreeLicenseError(ValueError): """License is not free according to the Open Source Definition.""" # ... back in the part of your code corresponding to your pseudocode: if strict: raise NonFreeLicenseError("The '%s' license is nonfree and thus impermissible." % x) As written, I have NonFreeLicenseError as a kind of ValueError. This may or may not be appropriate depending on your program; a list of built-in types of exceptions can be found at http://docs.python.org/dev/library/exceptions.html#bltin-exceptions Cheers, Chris -- http://rebertia.com * http://en.wikipedia.org/wiki/Boolean_data_type ** http://en.wikipedia.org/wiki/Object_%28computer_science%29 From ericsnowcurrently at gmail.com Fri Aug 5 03:20:24 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 01:20:24 -0600 Subject: Observations on the three pillars of Python execution Message-ID: In Python, three types of objects have special syntax and mechanics for their instantiation, during which a code object is generated: modules, classes, and functions. Each has its own role to play and the differences between them mostly reflect that. Here are some observations (based on default behavior): Object creation relative to code object creation: (M) before (C) after (F) after Object creation relative to code object execution: (M) before (C) after (F) before Object available during code object execution: (M) no (C) no (F) no Code object destiny: (M) executed once at definition time, then discarded (C) executed once at definition time, then discarded (F) not executed at definition time, stored on the function object for execution with each __call__() invocation. Execution locals is available during code object execution: (M) as globals() (C) as locals() (F) as locals() Object namespace is execution locals of code object: (M) yes (C) more or less (F) completely distinct Unique syntax: (M) 'import' statement (C) 'class' statement (F) 'def' statement Mechanism triggered by respective syntax: (M) import machinery (import.c/importlib) (C) internal, but partially exposed via metaclasses and the __build_class__ builtin (F) internal, nothing exposed Override capability: (M) complete capability through builtin __import__ and PEP 302 import hooks (C) partial capability, before code object execution through metaclass __prepare__() and after through __build_class__() and metaclass __call__(), __new__(), and __init__() (F) no capability Post instantiation modification capability: (M) yes (C) yes (F) mostly (some attributes are read-only) Mechanism to instantiate outside of respective unique syntax: (M) imp.new_module(), types.ModuleType(), type()() (C) type() (F) types.FunctionType(), type(f)() Type extensibility: (M) Not relative to 'import' syntax (by default) (C) Complete (F) No Name available during definition execution: (M) as __name__ (C) only through metaclass __prepare__() (F) through inspect.currentframe().f_code.co_name Name available on object as __name__: (M) yes (C) yes (F) yes Corrections, additions, and comment are welcome. -eric From t at jollybox.de Fri Aug 5 04:22:42 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 05 Aug 2011 10:22:42 +0200 Subject: Observations on the three pillars of Python execution In-Reply-To: References: Message-ID: <4E3BA852.9020604@jollybox.de> On 05/08/11 09:20, Eric Snow wrote: > Object available during code object execution: > (M) no > (C) no > (F) no (F) yes. cf. recursion. From silverinteract at gmail.com Fri Aug 5 05:29:07 2011 From: silverinteract at gmail.com (Silver Interactive) Date: Fri, 5 Aug 2011 14:59:07 +0530 Subject: Python - C api related - Concurrent Script Execution Message-ID: Dear All, I have developed a C++ server application which handles requests coming in from my web server. The server application is capable of handling multiple users at a time. Each user has a session object. Each user also has some variables associated with it. These variables are maintained in the c++ side as python dictionaries as they will be processed by executing scripts by the function PyRun_SimpleString() with each request. What i realised half-way through the implementation is that I will probably not be able to execute python scripts in parallel from the c++ end. Is this thinking correct? One user makes a request and the c++ code calls the python script which has to fetch information from a remote server (takes some seconds), but I cannot have other users script execution wait till this first script returns. Am i missing a point here. Please let me know if there is a way out of this as I am stuck big time. Do let me know if you require any more information. Help will be appreciated. Thanks!!! Regards Diana -------------- next part -------------- An HTML attachment was scrubbed... URL: From heniser at yahoo.com Fri Aug 5 07:29:06 2011 From: heniser at yahoo.com (Ryan) Date: Fri, 5 Aug 2011 04:29:06 -0700 (PDT) Subject: __set__ method is not called for class attribute access Message-ID: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> In the context of descriptors, the __set__ method is not called for class attribute access. __set__ is only called to set the attribute on an instance instance of the owner class to a new value, value. WHY? Is there some other mechanism for accomplishing this outcome. This subtle difference from __get__cost me some time to track down. Might think about pointing that out the documentation. class RevealAccess(object): """A data descriptor that sets and returns values normally and prints a message logging their access. """ def __init__(self, initval=None, name='var'): self.val = initval self.name = name def __get__(self, obj, objtype): print 'Retrieving', self.name return self.val def __set__(self, obj, val): print 'Updating' , self.name self.val = val class MyClass(object): x = RevealAccess(10, 'var "x"') y = 5 print MyClass.x MyClass.x = 20 print MyClass.x MyClass.x = 30 print MyClass.x Retrieving var "x" 10 20 30 I am at a lost on how to intercept class attribute sets. Can anyone help :-/ Ryan From rosuav at gmail.com Fri Aug 5 07:40:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 12:40:24 +0100 Subject: Recursive functions (was Re: Observations on the three pillars of Python execution) Message-ID: On Fri, Aug 5, 2011 at 9:22 AM, Thomas Jollans wrote: > On 05/08/11 09:20, Eric Snow wrote: >> Object available during code object execution: >> (M) no >> (C) no >> (F) no > (F) yes. > > cf. recursion. Is it? As I understand it, a Python function is not able to reference "itself" but must reference its own name. This means that assigning that function to something else stops it being recursive: ##### >>> def foo(x): print(x) if x>3: foo(x-1) >>> foo(5) 5 4 3 >>> bar=foo >>> bar(5) 5 4 3 >>> def foo(x): print("Foo",x) if x>3: foo(x-1) >>> foo(5) Foo 5 Foo 4 Foo 3 >>> bar(5) 5 Foo 4 Foo 3 ##### bar() is not a recursive function, even though foo() was and is. I've just played around with a decorator, though; this appears to work: >>> def recursive(f): l=list(f.__defaults__) l[-1]=f f.__defaults__=tuple(l) return f >>> @recursive def quux(x,quux=None): print("Quux",x) if x>3: quux(x-1) >>> foo=quux >>> def quux(x): print("Stopping.") >>> quux(5) Stopping. >>> foo(5) Quux 5 Quux 4 Quux 3 Effectively, the decorator binds the function's own self to its last default parameter, thus holding a cyclic reference (unlikely to be an issue - people won't be creating and destroying functions frequently, so GC issues shouldn't arise). The last parameter doesn't have to have the name of the function; this works with lambdas: >>> recursive(lambda x,_=None: print("Lambda",x) or (x>3 and _(x-1) or None))(5) Lambda 5 Lambda 4 Lambda 3 Yes, this is a pretty stupid example. But is this sort of decorator useful? It's not like people regularly want recursive lambdas. Chris Angelico From __peter__ at web.de Fri Aug 5 08:10:52 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 14:10:52 +0200 Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? Is there some other mechanism for > accomplishing this outcome. This subtle difference from __get__cost me > some time to track down. Might think about pointing that out the > documentation. > > > class RevealAccess(object): > """A data descriptor that sets and returns values > normally and prints a message logging their access. > """ > > def __init__(self, initval=None, name='var'): > self.val = initval > self.name = name > > def __get__(self, obj, objtype): > print 'Retrieving', self.name > return self.val > > def __set__(self, obj, val): > print 'Updating' , self.name > self.val = val > > class MyClass(object): > x = RevealAccess(10, 'var "x"') > y = 5 > > print MyClass.x > MyClass.x = 20 > print MyClass.x > MyClass.x = 30 > print MyClass.x > > Retrieving var "x" > 10 > 20 > 30 > > I am at a lost on how to intercept class attribute sets. Can anyone > help :-/ A class is just an instance of its metaclass, so you could move the descriptor into the metaclass to see the expected behaviour in the class: >>> class A: ... class __metaclass__(type): ... x = RevealAccess(10, 'var "x"') ... >>> A.x = 42 Updating var "x" >>> A.x Retrieving var "x" 42 However: >>> A().x Traceback (most recent call last): File "", line 1, in AttributeError: 'A' object has no attribute 'x' So you'd need two descriptors if you want to intercept variable access on both the instance and class level. From Johnny.Venter at zoho.com Fri Aug 5 08:15:53 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Fri, 5 Aug 2011 08:15:53 -0400 Subject: Sockets: Receiving C Struct Message-ID: New to python and would like to test network/sockets with it. I am having a problem where I have setup the following: import socket, sys, struct HOST = '1.1.1.1' PORT = 153 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) data = struct.unpack('!I',s.recv(4))[0] s.close() print data What I would like to do is take the input from the server, and store it in an array. The type of data is int. Can someone help? Thanks, Johnny -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 841 bytes Desc: This is a digitally signed message part URL: From duncan.booth at invalid.invalid Fri Aug 5 08:16:09 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Aug 2011 12:16:09 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? Is there some other mechanism for > accomplishing this outcome. This subtle difference from __get__cost me > some time to track down. Might think about pointing that out the > documentation. > > > class RevealAccess(object): > """A data descriptor that sets and returns values > normally and prints a message logging their access. > """ > > def __init__(self, initval=None, name='var'): > self.val = initval > self.name = name > > def __get__(self, obj, objtype): > print 'Retrieving', self.name > return self.val > > def __set__(self, obj, val): > print 'Updating' , self.name > self.val = val > > class MyClass(object): > x = RevealAccess(10, 'var "x"') > y = 5 > > print MyClass.x > MyClass.x = 20 > print MyClass.x > MyClass.x = 30 > print MyClass.x > > Retrieving var "x" > 10 > 20 > 30 > > I am at a lost on how to intercept class attribute sets. Can anyone > help :-/ The descriptor protocol only works when a value is being accessed or set on an instance and there is no instance attribute of that name so the value is fetched from the underlying class. Classes are instances too, so you may get some of what you want from: class MyMeta(type): x = RevealAccess(10, 'var "x"') class MyClass(object): __metaclass__ = MyMeta y = 5 >>> MyClass.x = 20 Updating var "x" >>> MyClass.x Retrieving var "x" 20 However note that if you do this you can access "x" only directly on the class not on an instance of the class: >>> MyClass().x Traceback (most recent call last): File "", line 1, in MyClass().x AttributeError: 'MyClass' object has no attribute 'x' -- Duncan Booth http://kupuguy.blogspot.com From eliben at gmail.com Fri Aug 5 08:16:37 2011 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 5 Aug 2011 15:16:37 +0300 Subject: stopping a thread with _Thread__stop Message-ID: This recipe: http://code.activestate.com/recipes/576780-timeout-for-nearly-any-callable/ Claims that a Python thread can be stopped by executing the private method "Thread._Thread__stop". I don't think this is true, since _Thread__stop doesn't really stop or kill the thread. In conformance to theory, the "timelimited" method this recipe defines leaves a thread running in the background if the function it's given is long-running (or infinite). Is there something I'm missing? Eli From __peter__ at web.de Fri Aug 5 09:00:37 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 15:00:37 +0200 Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Duncan Booth wrote: > The descriptor protocol only works when a value is being accessed or set > on an instance and there is no instance attribute of that name so the > value is fetched from the underlying class. Unlike normal class attributes a descriptor is not shaded by an instance attribute: >>> class A(object): ... def set_x(self, value): self.__dict__["x"] = value/2.0 ... def get_x(self): return self.__dict__["x"] * 2.0 ... x = property(get_x, set_x) ... >>> a = A() >>> a.x = 42 >>> a.__dict__["x"] 21.0 >>> a.x 42.0 >>> A.x = "something completely different" >>> a.x 21.0 From Johnny.Venter at zoho.com Fri Aug 5 09:05:30 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Fri, 5 Aug 2011 09:05:30 -0400 Subject: Fwd: Sockets: Receiving C Struct References: Message-ID: I was not sure if this message was sent before my membership was accepted. Please disregard if it's a duplicate. Thanks Begin forwarded message: > From: Johnny Venter > Date: August 5, 2011 8:15:53 AM EDT > To: python-list at python.org > Subject: Sockets: Receiving C Struct > > New to python and would like to test network/sockets with it. > > I am having a problem where I have setup the following: > > import socket, sys, struct > > HOST = '1.1.1.1' > PORT = 153 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) > > data = struct.unpack('!I',s.recv(4))[0] > > s.close() > > print data > > > What I would like to do is take the input from the server, and store it in an array. The type of data is int. > > Can someone help? > > > Thanks, Johnny > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 841 bytes Desc: This is a digitally signed message part URL: From steve+comp.lang.python at pearwood.info Fri Aug 5 09:51:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Aug 2011 23:51:16 +1000 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Tim Chase wrote: > On 08/04/2011 07:34 PM, Steven D'Aprano wrote: >> Billy Mays wrote: >>> #!/usr/bin/python >> >> I believe the recommended, platform independent hash-bang line is >> >> #!/usr/bin/which python > > I think you mean > > #!/usr/bin/env python Doh! I *always* conflate env and which. Thank you for the correction. -- Steven From mail at timgolden.me.uk Fri Aug 5 10:03:18 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 05 Aug 2011 15:03:18 +0100 Subject: PyWhich In-Reply-To: <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E3BF826.3010107@timgolden.me.uk> On 05/08/2011 14:51, Steven D'Aprano wrote: > Tim Chase wrote: > >> On 08/04/2011 07:34 PM, Steven D'Aprano wrote: >>> Billy Mays wrote: >>>> #!/usr/bin/python >>> >>> I believe the recommended, platform independent hash-bang line is >>> >>> #!/usr/bin/which python >> >> I think you mean >> >> #!/usr/bin/env python > > > Doh! I *always* conflate env and which. Thank you for the correction. And there I was thinking you were making a sly and ironic point about using a utility to find something on the path in order to run a utility which finds something on the path... TJG From nka_99 at yahoo.com Fri Aug 5 10:18:07 2011 From: nka_99 at yahoo.com (Naresh Agrawal) Date: Fri, 5 Aug 2011 07:18:07 -0700 (PDT) Subject: Hi Message-ID: <1312553887.65658.YahooMailClassic@web65714.mail.ac4.yahoo.com> Looking for a Python Developer with ????????? Database (Oracle or SQL server ) ? MUST have Capital Market Experience? - Fixed Income Market / Trading Systems? ? ????????? Java/.Net as the base development expertise Please let me know if any one is interested to work Location is NY Thanks Nick nka_99 at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Fri Aug 5 10:33:58 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 14:33:58 +0000 (UTC) Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> <4e3bf554$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4e3bf554$0$29976$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > Doh! I *always* conflate env and which. Thank you for the correction. Way to say "conflate"! :-) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Fri Aug 5 10:36:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:36:16 +1000 Subject: Observations on the three pillars of Python execution References: Message-ID: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > In Python, three types of objects have special syntax and mechanics > for their instantiation, during which a code object is generated: > modules, classes, and functions. I believe you are labouring under a misapprehension. Modules and classes don't generate code objects. The simplest possible module just has a name: >>> import sys >>> module = type(sys) >>> module("name") Or if you prefer to do it the "normal" way by importing from source code, the simplest source code of all is just an empty file. A module is an object with a __dict__, a __name__, and a __docstring__ which defaults to None. That's it. No code objects, unless you populate the __dict__ with functions, but it is the *functions* that have the code objects, not the module itself. The module is just a container. Classes are similar. The simplest class: class K: pass or if you prefer: >>> type('K', (), {}) Again, no code objects unless you populate the dict with functions (which get turned into methods). Again, the class object is just a container. A more complex container than modules, with a richer set of inherited behaviour, but still just a container. The signature for creating a function is very different: help(type(lambda: None)) => class function(object) | function(code, globals[, name[, argdefs[, closure]]]) | | Create a function object from a code object and a dictionary. | The optional name string overrides the name from the code object. | The optional argdefs tuple specifies the default argument values. | The optional closure tuple supplies the bindings for free variables. The simplest function I can think of: >>> co = compile('pass', '', 'single') >>> f = type(lambda: None)(co, {}) Even simpler than def f(): pass Can you see why? If you inspect a function object, you will see that it always has a code object, even if the code object does nothing but return None: >>> import dis >>> dis.dis(f.func_code) 1 0 LOAD_CONST 0 (None) 3 RETURN_VALUE There may be some other obscure built-in type that includes code objects, but I can't imagine what it would be. I feel confident in saying that functions, and functions alone, contain code. Even methods are just wrappers around functions. Even built-in functions like len don't contain code! (Or at least, their code isn't accessible from Python.) Which makes sense, if you think about it: their code is part of the Python virtual machine, not the object. -- Steven From 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com Fri Aug 5 10:43:49 2011 From: 81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com (Billy Mays) Date: Fri, 05 Aug 2011 10:43:49 -0400 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/04/2011 10:03 PM, Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano > wrote: >> Especially for a tool aimed at programmers (who else would be interested in >> PyWhich?) > > The use that first springs to my mind is debugging import paths etc. > If you have multiple pythons installed and aren't sure that they're > finding the right modules, you could fire up PyWhich on an innocuous > module like math or sys, and see if it's loading it from the right > path. People doing this might not necessarily be programmers, they > might be sysadmins; but you're right that it's most likely this will > be used by competent Python programmers. > > ChrisA I am trying to do debugging. I have had some trouble with multiple python installs with virtualenv, and I was trying to see where given modules came from. I knew about the code execution, but I couldn't think of a clean way to just find out the location rather than load it. The reason I used stdout was because I was going to be using it in a tool chain where the stdout might need to be formatted for another program to read in. Thats also why I was catching ImportError since a later version of this script might need to do something special with it. This is also useful to see if python is really using the module you think it is. -- Bill From steve+comp.lang.python at pearwood.info Fri Aug 5 10:44:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:44:20 +1000 Subject: Recursive functions (was Re: Observations on the three pillars of Python execution) References: Message-ID: <4e3c01c5$0$29981$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Fri, Aug 5, 2011 at 9:22 AM, Thomas Jollans wrote: >> On 05/08/11 09:20, Eric Snow wrote: >>> Object available during code object execution: >>> (M) no >>> (C) no >>> (F) no >> (F) yes. >> >> cf. recursion. > > Is it? As I understand it, a Python function is not able to reference > "itself" but must reference its own name. That is correct. Recursion in Python is implemented simply by name lookup. > This means that assigning > that function to something else stops it being recursive: An easier way to demonstrate the process: >>> def f(x): ... print x ... if x > 0: f(x-1) ... >>> f(3) 3 2 1 0 >>> g = f >>> del f >>> g(3) 3 Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'f' is not defined -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 10:56:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 00:56:14 +1000 Subject: PyWhich References: <4e3b3ab2$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3c048e$0$29994$c3e8da3$5496439d@news.astraweb.com> Billy Mays wrote: > The reason I used stdout was because I was going to be using it in a > tool chain where the stdout might need to be formatted for another > program to read in. print writes to sys.stdout unless you tell it different. >>> import sys >>> import StringIO >>> capture = StringIO.StringIO() >>> sys.stdout = capture >>> print "spam" >>> sys.stdout = sys.__stdout__ # Restore the real file. >>> capture.getvalue() 'spam\n' Syntax for printing elsewhere is ugly as sin in Python 2, but it works: >>> print >>sys.stderr, "spam" spam >>> print >>capture, "ham" >>> capture.getvalue() 'spam\nham\n' > Thats also why I was catching ImportError since a > later version of this script might need to do something special with it. Well you better also catch SyntaxError, because a later version of your script might need to do something special with it too :) Also RuntimeError, ValueError, TypeError... *wink* -- Steven From drsalists at gmail.com Fri Aug 5 11:09:09 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 08:09:09 -0700 Subject: Sockets: Receiving C Struct In-Reply-To: References: Message-ID: First, s.recv(4) is not guaranteed to always return 4 bytes. It could return 0, 1, 2, 3, or 4, wtih 4 being the most likely. To deal with this, I tend to use http://stromberg.dnsalias.org/~dstromberg/bufsock.html - but I suspect that Twisted has a way of dealing with it too. Then, to put your data into a list, just create an empty list with [] and use list_.append(integer). Or was there more to your question, like perhaps a traceback you haven't shared with us? On Fri, Aug 5, 2011 at 6:05 AM, Johnny Venter wrote: > I was not sure if this message was sent before my membership was accepted. > > Please disregard if it's a duplicate. > > Thanks > > Begin forwarded message: > > *From: *Johnny Venter > *Date: *August 5, 2011 8:15:53 AM EDT > *To: *python-list at python.org > *Subject: **Sockets: Receiving C Struct* > > New to python and would like to test network/sockets with it. > > I am having a problem where I have setup the following: > > import socket, sys, struct > > HOST = '1.1.1.1' > PORT = 153 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.connect((HOST, PORT)) > > data = struct.unpack('!I',s.recv(4))[0] > > s.close() > > print data > > > What I would like to do is take the input from the server, and store it in > an array. The type of data is int. > > Can someone help? > > > Thanks, Johnny > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From k.sahithi2862 at gmail.com Fri Aug 5 11:12:04 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 5 Aug 2011 08:12:04 -0700 (PDT) Subject: EXCLUSIVE HOT PHOTOS & VIDEOS Message-ID: <1d284fca-fd21-434a-be05-4bdd4366b958@e20g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html MAHESH BABU WORKING STILLS IN DHOOKUDU http://princemaheshfanz.blogspot.com/2011/08/dookudu-working-stills.html NAMRATHA IN NATIONAL BREAST FEEDING http://princemaheshfanz.blogspot.com/2011/08/namrata-shirodkar-at-national-breast.html From 1248283536 at qq.com Fri Aug 5 11:21:05 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 5 Aug 2011 23:21:05 +0800 Subject: scrape text from web Message-ID: python-list at python.org: hi ,everyone, i want to scrap something from http://search.dangdang.com/search_pub.php?key=python my code is : import urllib import lxml.html down='http://search.dangdang.com/search_pub.php?key=python' file=urllib.urlopen(down).read() root=lxml.html.fromstring(file) tnodes = root.xpath("//div[@class='listitem detail']//li[@class='maintitle']//a") for i,x in enumerate(tnodes): print i," ",x.get('name'),x.get('href'),x.get('onclick'),x.text,"\n" the output is : 0 p_name http://product.dangdang.com/product.aspx?product_id=20872365&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20872365_1_22591_p','','',''); None 1 p_name http://product.dangdang.com/product.aspx?product_id=20255354&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20255354_2_12605_p','','',''); None 2 p_name http://product.dangdang.com/product.aspx?product_id=20836565&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20836565_3_2361_p','','',''); None 3 p_name http://product.dangdang.com/product.aspx?product_id=21004615&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21004615_4_3387_p','','',''); None 4 p_name http://product.dangdang.com/product.aspx?product_id=21063086&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21063086_5_18815_p','','',''); None 5 pr_name http://product.dangdang.com/product.aspx?product_id=20678461&ref=search-1-pub s('click','python','01.54.04.03,01.54.06.18','','86_1_25','','','20678461_6_3967_p','','','RECO'); None 6 pr_name http://product.dangdang.com/product.aspx?product_id=20650363&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','20650363_7_62_p','','','RECO'); ????????????(?????)(?1CD)(????CD-ROM)( 7 pr_name http://product.dangdang.com/product.aspx?product_id=20767932&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','20767932_8_4475_p','','','RECO'); Binary Hacks??????100? 8 p_name http://product.dangdang.com/product.aspx?product_id=20596189&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20596189_9_639_p','','',''); None 9 p_name http://product.dangdang.com/product.aspx?product_id=20947680&ref=search-1-pub s('click','python','01.54.24.00,01.54.06.18','','86_1_25','','','20947680_10_7295_p','','',''); None 10 p_name http://product.dangdang.com/product.aspx?product_id=21050368&ref=search-1-pub s('click','python','01.54.19.00','','86_1_25','','','21050368_11_7039_p','','',''); None 11 p_name http://product.dangdang.com/product.aspx?product_id=20667966&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20667966_12_383_p','','',''); None 12 p_name http://product.dangdang.com/product.aspx?product_id=21022493&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21022493_13_5183_p','','',''); None 13 pr_name http://product.dangdang.com/product.aspx?product_id=479654&ref=search-1-pub s('click','python','01.54.06.08,01.54.06.18','','86_1_25','','','479654_14_2095_p','','','RECO'); Perl????????? 14 pr_name http://product.dangdang.com/product.aspx?product_id=20999855&ref=search-1-pub s('click','python','01.54.10.00','','86_1_25','','','20999855_15_6715_p','','','RECO'); ??????????????????? 15 pr_name http://product.dangdang.com/product.aspx?product_id=20696203&ref=search-1-pub s('click','python','01.54.06.08','','86_1_25','','','20696203_16_31615_p','','','RECO'); Perl??????????????Learning Perl,5/e) 16 p_name http://product.dangdang.com/product.aspx?product_id=20670643&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20670643_17_24_p','','',''); ??? 17 p_name http://product.dangdang.com/product.aspx?product_id=20362210&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20362210_18_32_p','','',''); ?? 18 p_name http://product.dangdang.com/product.aspx?product_id=9053236&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','9053236_19_4_p','','',''); ?? 19 p_name http://product.dangdang.com/product.aspx?product_id=20850780&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','20850780_20_1055_p','','',''); None 20 pr_name http://product.dangdang.com/product.aspx?product_id=20449068&ref=search-1-pub s('click','python','01.54.06.08','','86_1_25','','','20449068_21_38_p','','','RECO'); ??Perl 21 p_name http://product.dangdang.com/product.aspx?product_id=21127816&ref=search-1-pub s('click','python','01.54.24.00,01.54.06.18','','86_1_25','','','21127816_22_12545_p','','',''); None 22 p_name http://product.dangdang.com/product.aspx?product_id=21107633&ref=search-1-pub s('click','python','01.54.06.18','','86_1_25','','','21107633_23_19245_p','','',''); Hadoop??????2??????? 23 None http://bang.dangdang.com/product_redirect.php?product_id=9317290 None None 24 p_name http://product.dangdang.com/product.aspx?product_id=9317290&ref=search-1-pub s('click','python','01.54.06.06,01.49.01.11,01.54.26.00','','86_1_25','','','9317290_24_81727_p','','',''); Java??????4?? 25 p_name http://product.dangdang.com/product.aspx?product_id=20773186&ref=search-1-pub s('click','python','01.54.06.17','','86_1_25','','','20773186_25_80479_p','','',''); Android?????? the problem is x.text ,for example: 1. Python ????(?2?) what i want to get is "Python ????(?2?)",the output is None 2: ??? Python what i want to get is "???python",the output is ??? would you mind to tell me how to revise my code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 5 11:32:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 16:32:03 +0100 Subject: problem with bcd and a number In-Reply-To: References: <4E3AF2FA.7000207@ieee.org> Message-ID: On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: >>>> print int(hex(0x72).replace('0x', '')) > 72 Or simpler: int(hex(0x72)[2:]) Although if you have it as a string, you need to ord() the string. It's probably better to just do the bitwise operations though. ChrisA From __peter__ at web.de Fri Aug 5 11:52:38 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Aug 2011 17:52:38 +0200 Subject: problem with bcd and a number References: <4E3AF2FA.7000207@ieee.org> Message-ID: Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: >>>>> print int(hex(0x72).replace('0x', '')) >> 72 > > Or simpler: int(hex(0x72)[2:]) > > Although if you have it as a string, you need to ord() the string. Or use str.encode(): >>> int("\x72".encode("hex")) 72 >>> int("\x12\x34\x56".encode("hex")) 123456 > It's probably better to just do the bitwise operations though. From ppearson at nowhere.invalid Fri Aug 5 12:01:48 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 5 Aug 2011 16:01:48 GMT Subject: problem with bcd and a number References: <31c8d075-2901-46eb-adcf-1c1803ab7938@a4g2000yqg.googlegroups.com> Message-ID: <9a2ifcF1k7U1@mid.individual.net> On Thu, 04 Aug 2011 21:52:45 +0200, Christoph Hansen wrote: > MRAB schrieb: > >> The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) > > i would say > > (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) > > but who knows I concur. I think the documentation is trying to say that the low-order nibble of the LSB is garbage. -- To email me, substitute nowhere->spamcop, invalid->net. From gruszczy at gmail.com Fri Aug 5 12:14:14 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Fri, 5 Aug 2011 18:14:14 +0200 Subject: ANN: geany-pyflakes 1.0 Message-ID: Hello everyone, I have just published a small plugin for Geany IDE that adds Pyflakes error detection to the editor. If there are people using Geany for Python development I would be very grateful for opinions and suggestions. The plugin can be found here: http://code.google.com/p/geany-pyflakes/ -- Filip Gruszczy?ski From ericsnowcurrently at gmail.com Fri Aug 5 12:46:02 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 10:46:02 -0600 Subject: Observations on the three pillars of Python execution In-Reply-To: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano wrote: > Eric Snow wrote: > >> In Python, three types of objects have special syntax and mechanics >> for their instantiation, during which a code object is generated: >> modules, classes, and functions. > > I believe you are labouring under a misapprehension. Modules and classes > don't generate code objects. Sorry for any confusion. I was talking specifically about the their instantiation through their respective special syntax. During that process a code object is generated for each. For classes and modules the code object is executed and then discarded. I covered this explicitly in one of the observations. > > The simplest possible module just has a name: > >>>> import sys >>>> module = type(sys) >>>> module("name") > > > Or if you prefer to do it the "normal" way by importing from source code, > the simplest source code of all is just an empty file. > > A module is an object with a __dict__, a __name__, and a __docstring__ which > defaults to None. That's it. No code objects, unless you populate the > __dict__ with functions, but it is the *functions* that have the code > objects, not the module itself. The module is just a container. > > Classes are similar. The simplest class: > > class K: > ? ?pass > > or if you prefer: > >>>> type('K', (), {}) > > > > Again, no code objects unless you populate the dict with functions (which > get turned into methods). Again, the class object is just a container. A > more complex container than modules, with a richer set of inherited > behaviour, but still just a container. > > The signature for creating a function is very different: > > help(type(lambda: None)) => > > class function(object) > ?| ?function(code, globals[, name[, argdefs[, closure]]]) > ?| > ?| ?Create a function object from a code object and a dictionary. > ?| ?The optional name string overrides the name from the code object. > ?| ?The optional argdefs tuple specifies the default argument values. > ?| ?The optional closure tuple supplies the bindings for free variables. > > > The simplest function I can think of: > >>>> co = compile('pass', '', 'single') >>>> f = type(lambda: None)(co, {}) > > Even simpler than > > def f(): > ? ?pass > > Can you see why? > > If you inspect a function object, you will see that it always has a code > object, even if the code object does nothing but return None: > >>>> import dis >>>> dis.dis(f.func_code) > ?1 ? ? ? ? ? 0 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ?3 RETURN_VALUE > > > There may be some other obscure built-in type that includes code objects, > but I can't imagine what it would be. I feel confident in saying that > functions, and functions alone, contain code. Even methods are just > wrappers around functions. Even built-in functions like len don't contain > code! (Or at least, their code isn't accessible from Python.) Which makes > sense, if you think about it: their code is part of the Python virtual > machine, not the object. Agreed that [non-builtin] functions are the only objects that have a code object attribute. However, they are not the only objects for which a code object is generated and executed. I've always found your frequent responses very insightful and thoughtful, Steven, and I appreciate that. In this case I can only imagine that my opening statement was unclear enough that you did not continue to read the rest, where the context of my point was more clear (I hope :). Regardless, thanks for taking a look. -eric > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From emile at fenx.com Fri Aug 5 13:15:37 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 10:15:37 -0700 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: On 8/5/2011 9:14 AM Filip Gruszczy?ski said... > Hello everyone, > > I have just published a small plugin for Geany IDE that adds Pyflakes > error detection to the editor. If there are people using Geany for > Python development I would be very grateful for opinions and > suggestions. > > The plugin can be found here: http://code.google.com/p/geany-pyflakes/ > fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and should either be gizzped or simply named geany-pyflakes-1.0.tar. However, after activating the plugin, asking geany for a new file breaks geany and it rudely closes so I'm unable to actually do anything with it. Emile From steve+comp.lang.python at pearwood.info Fri Aug 5 13:29:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 03:29:13 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano > wrote: >> Eric Snow wrote: >> >>> In Python, three types of objects have special syntax and mechanics >>> for their instantiation, during which a code object is generated: >>> modules, classes, and functions. >> >> I believe you are labouring under a misapprehension. Modules and classes >> don't generate code objects. > > Sorry for any confusion. I was talking specifically about the their > instantiation through their respective special syntax. During that > process a code object is generated for each. Do you believe that this process of generating a code object and throwing it away is a part of the Python language specification, which any compiler must do in order to call itself "Python", or a mere implementation detail? Is this documented somewhere? If it is not documented, what makes you think that it happens at all? You are writing as if it were self-evidently true, but I don't believe it is self-evident at all. I think you need to demonstrate the truth of two of those three pillars, not just take them for granted. > For classes and modules > the code object is executed and then discarded. I covered this > explicitly in one of the observations. I think your definition of "explicitly" and mine differ here. > Agreed that [non-builtin] functions are the only objects that have a > code object attribute. However, they are not the only objects for > which a code object is generated and executed. Are you talking about the fact that importing a module, class statements and function statements all involve executing a block of code? How does that differ from executing any other fragment of code? Modules are special, of course, because they can get compiled to byte-code, but I trust you're not talking about .pyc files. -- Steven From fred.sells at adventistcare.org Fri Aug 5 13:31:03 2011 From: fred.sells at adventistcare.org (Sells, Fred) Date: Fri, 5 Aug 2011 13:31:03 -0400 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: After the completion of most training courses, the students are not yet ready to make a meaningful contribution to the community. Yet your goal of getting them involved in the community is worthwhile. I would think learning to use the community as a resource to solve a problem that is not based on the standard modules would be a good one. I liked the recipe suggestion as well, but I think you would need to post a list of items to choose and remove the item when the recipe has been posted. Otherwise you could get a gazillion examples of sorting a dictionary... Just my 2 cents FWIW Fred Sells -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 5 13:51:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Aug 2011 18:51:51 +0100 Subject: Community Involvement In-Reply-To: References: <950654C7-2145-4FD5-9B0B-04A5499E965B@holdenweb.com> Message-ID: On Fri, Aug 5, 2011 at 6:31 PM, Sells, Fred wrote: > After the completion of most training courses, the students are not yet > ready to make a meaningful contribution to the community. That's quite possibly true, but they may very well be in a position to recognize a documentation error/omission and assist, or alternatively, to triage some bugs. There are plenty of OSS projects that could do with a hand there; does it have to be Python specifically? Python's docs are pretty good, but I'm sure there will always be value in people spending time on http://bugs.python.org/ and seeing if they can reproduce the bugs. ChrisA From tundra at tundraware.com Fri Aug 5 13:53:19 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 12:53:19 -0500 Subject: Table Driven GUI Definition? Message-ID: I have a task where I want to create pretty simple one page visual interfaces (Graphical or Text, but it needs to run across Windows, Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more than option checklists and text fields. Conceptually something like: Please Select Your Installation Options: Windows Compatibility Services _ Linux Compatibility Services _ TRS-DOS Compatibility Services _ What Is Your email Address: _______________________ What I'm looking for is a way to describe such forms in a text file that can then be fed into a tool to generate the necessary pyGUI, Tkinter, (or whatever) code. The idea is that it should be simple to generate a basic interface like this and have it only record the user's input. Thereafter, the python code would act on the basis of those selection without any further connection to the GUI. An added bonus would be a similar kind of thing for generating web interfaces to do this. This might actually be a better model because then I only have to worry about a single presentation environment. Ideas anyone? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From geoffwright240 at gmail.com Fri Aug 5 14:07:54 2011 From: geoffwright240 at gmail.com (Geoff Wright) Date: Fri, 5 Aug 2011 14:07:54 -0400 Subject: Question about encoding, I need a clue ... Message-ID: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Hi, I use Mac OSX for development but deploy on a Linux server. (Platform details provided below). When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. Specifically, calendar.month_name[8] returns a ? (question mark) on the Linux server whereas it displays properly on the Mac OSX system. However, if I take the result from calendar.month_name[8] and run it through the following function .... unicode(calendar.month_name[8],"latin1") ... then the u circumflex displays correctly on the Linux server but does not display correctly on my Mac. Of course, I could work around this problem with a relatively simple if statement but these issues are going to show up all over my application so even a simple if statement will start to get cumbersome. I guess what it boils down to is that I would like to get a better handle on what is going on so that I will know how best to work through future encoding issues. Thanks in advance for any advice. Here are the specifics of my problem. On my Mac: Python 2.6.7 (r267:88850, Jul 30 2011, 23:46:53) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >>> import locale >>> locale.setlocale(locale.LC_ALL,'fr_CA') 'fr_CA' >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> import calendar >>> calendar.month_name[8] 'ao\xc3\xbbt' >>> print calendar.month_name[8] ao?t >>> print unicode(calendar.month_name[8],"latin1") ao??t On the linux server: uname -a Linux alhena 2.6.32.8-grsec-2.1.14-modsign-xeon-64 #2 SMP Sat Mar 13 00:42:43 PST 2010 x86_64 GNU/Linux Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40) [GCC 4.3.2] on linux2 >>> import locale,sys,calendar >>> locale.setlocale(locale.LC_ALL,'fr_CA') 'fr_CA' >>> sys.getdefaultencoding() 'ascii' >>> calendar.month_name[8] 'ao\xfbt' >>> print calendar.month_name[8] ao?t >>> print unicode(calendar.month_name[8],"latin1") ao?t From mwilson at the-wire.com Fri Aug 5 14:22:11 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 05 Aug 2011 14:22:11 -0400 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There may be some other obscure built-in type that includes code objects, > but I can't imagine what it would be. I feel confident in saying that > functions, and functions alone, contain code. Even methods are just > wrappers around functions. Even built-in functions like len don't contain > code! (Or at least, their code isn't accessible from Python.) Which makes > sense, if you think about it: their code is part of the Python virtual > machine, not the object. Interesting question. Iterators seem to have code objects: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = [1, 2, 3] >>> b = (x for x in a) >>> dir(b) ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'close', 'gi_code', 'gi_frame', 'gi_running', 'next', 'send', 'throw'] >>> for name in dir(b): ... print name, type (getattr (b, name)) ... __class__ __delattr__ __doc__ __format__ __getattribute__ __hash__ __init__ __iter__ __name__ __new__ __reduce__ __reduce_ex__ __repr__ __setattr__ __sizeof__ __str__ __subclasshook__ close gi_code gi_frame gi_running next send throw in the form of the gi_code attribute. No idea what it's for, although no reason to believe it shouldn't be there. (Very interesting demo you gave of primitive object creation. I' awed.) Mel. From gervaz at gmail.com Fri Aug 5 14:52:23 2011 From: gervaz at gmail.com (gervaz) Date: Fri, 5 Aug 2011 11:52:23 -0700 (PDT) Subject: Get the name of a function Message-ID: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Hi all, is there a way to retrive the function name like with self.__class__.__name__? Using self.__dict__.__name__ I've got >>> def test(): ... print(self.__dict__.__name__) ... >>> test But I really just want the function name, so 'test' Any help? Thanks, Mattia From gruszczy at gmail.com Fri Aug 5 14:58:43 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Fri, 5 Aug 2011 20:58:43 +0200 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: > fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and > should either be gizzped or simply named geany-pyflakes-1.0.tar. > > However, after activating the plugin, asking geany for a new file breaks > geany and it rudely closes so I'm unable to actually do anything with it. I have posted a gzipped version with a fix. Would you care to take a look? -- Filip Gruszczy?ski From irmen at -NOSPAM-xs4all.nl Fri Aug 5 15:05:18 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Fri, 05 Aug 2011 21:05:18 +0200 Subject: Table Driven GUI Definition? In-Reply-To: References: Message-ID: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> On 05-08-11 19:53, Tim Daneliuk wrote: > I have a task where I want to create pretty simple one page visual > interfaces (Graphical or Text, but it needs to run across Windows, > Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more > than option checklists and text fields. Conceptually something like: > > Please Select Your Installation Options: > > Windows Compatibility Services _ > Linux Compatibility Services _ > TRS-DOS Compatibility Services _ > > What Is Your email Address: _______________________ > > What I'm looking for is a way to describe such forms in a text > file that can then be fed into a tool to generate the necessary > pyGUI, Tkinter, (or whatever) code. The idea is that it should > be simple to generate a basic interface like this and have it > only record the user's input. Thereafter, the python code > would act on the basis of those selection without any further > connection to the GUI. > > An added bonus would be a similar kind of thing for generating > web interfaces to do this. This might actually be a better model > because then I only have to worry about a single presentation > environment. > > Ideas anyone? Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. Wouldn't that work? Irmen From ms419 at freezone.co.uk Fri Aug 5 15:37:21 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Fri, 05 Aug 2011 12:37:21 -0700 Subject: Replace all references to one object with references to other Message-ID: <1312573041.6831.7.camel@selene> I have two objects, and I want to replace all references to the first object - everywhere - with references to the second object. What can I try? From tundra at tundraware.com Fri Aug 5 16:10:06 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 15:10:06 -0500 Subject: Table Driven GUI Definition? In-Reply-To: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: On 8/5/2011 2:05 PM, Irmen de Jong said this: > On 05-08-11 19:53, Tim Daneliuk wrote: >> I have a task where I want to create pretty simple one page visual >> interfaces (Graphical or Text, but it needs to run across Windows, >> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >> than option checklists and text fields. Conceptually something like: >> >> Please Select Your Installation Options: >> >> Windows Compatibility Services _ >> Linux Compatibility Services _ >> TRS-DOS Compatibility Services _ >> >> What Is Your email Address: _______________________ >> >> What I'm looking for is a way to describe such forms in a text >> file that can then be fed into a tool to generate the necessary >> pyGUI, Tkinter, (or whatever) code. The idea is that it should >> be simple to generate a basic interface like this and have it >> only record the user's input. Thereafter, the python code >> would act on the basis of those selection without any further >> connection to the GUI. >> >> An added bonus would be a similar kind of thing for generating >> web interfaces to do this. This might actually be a better model >> because then I only have to worry about a single presentation >> environment. >> >> Ideas anyone? > > Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... > > You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. > > Wouldn't that work? > > > Irmen Yup, although I'd probably use a central apache instance. But I'm still curious ... is there a way to do this with a full GUI tool on a thick client? -- ------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From emile at fenx.com Fri Aug 5 16:14:31 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:14:31 -0700 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: On 8/5/2011 11:58 AM Filip Gruszczy?ski said... >> fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and >> should either be gizzped or simply named geany-pyflakes-1.0.tar. >> >> However, after activating the plugin, asking geany for a new file breaks >> geany and it rudely closes so I'm unable to actually do anything with it. > > I have posted a gzipped version with a fix. Would you care to take a look? > OK - it no longer crashes, but it doesn't appear to do anything. Is there something further I need to do to configure it? The Pyflakes tab does appear in the message window and I've created a new testpyflakes.py with code similar to your example. Also, just FYI, the plugin manager now shows the version as 1.0.1 while the tar file name indicates 1.0.2. Emile From emile at fenx.com Fri Aug 5 16:16:54 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:16:54 -0700 Subject: Table Driven GUI Definition? In-Reply-To: References: Message-ID: On 8/5/2011 10:53 AM Tim Daneliuk said... > I have a task where I want to create pretty simple one page visual > interfaces (Graphical or Text, but it needs to run across Windows, > Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more > than option checklists and text fields. I'm not happened across an automated tool exactly, but I'd look into pyjamas or pygui. Emile From emile at fenx.com Fri Aug 5 16:18:05 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:18:05 -0700 Subject: Replace all references to one object with references to other In-Reply-To: <1312573041.6831.7.camel@selene> References: <1312573041.6831.7.camel@selene> Message-ID: On 8/5/2011 12:37 PM Jack Bates said... > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? Start with a proxy to your first and have it swap in to the second? EMile From emile at fenx.com Fri Aug 5 16:19:30 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 05 Aug 2011 13:19:30 -0700 Subject: Get the name of a function In-Reply-To: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On 8/5/2011 11:52 AM gervaz said... > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? yes, but not reliably: Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def test():pass ... >>> test.__name__ 'test' >>> b=test >>> b.__name__ 'test' >>> Emile From kwatford at gmail.com Fri Aug 5 16:25:17 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 5 Aug 2011 16:25:17 -0400 Subject: Replace all references to one object with references to other In-Reply-To: <1312573041.6831.7.camel@selene> References: <1312573041.6831.7.camel@selene> Message-ID: On Fri, Aug 5, 2011 at 3:37 PM, Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? If using PyPy instead of CPython is an option, the "thunk" object space's "become" function can apparently do this: http://doc.pypy.org/en/latest/objspace-proxies.html#the-thunk-object-space In CPython, this might be a tad difficult. At the C level, a reference to a python object is just a pointer to it. You could iterate through the entire address space looking for values that equal a particular pointer, but changing them would be dangerous, since memory isn't labeled by type - you can't tell if the memory is a pointer to your object or an important part of some other data structure. If you could narrow down what you want to accomplish, this might be easier. For instance, if all you need is to replace module-level references to the object, that can be done. From philip at semanchuk.com Fri Aug 5 16:42:30 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Aug 2011 16:42:30 -0400 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > On 8/5/2011 2:05 PM, Irmen de Jong said this: >> On 05-08-11 19:53, Tim Daneliuk wrote: >>> I have a task where I want to create pretty simple one page visual >>> interfaces (Graphical or Text, but it needs to run across Windows, >>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>> than option checklists and text fields. Conceptually something like: >>> >>> Please Select Your Installation Options: >>> >>> Windows Compatibility Services _ >>> Linux Compatibility Services _ >>> TRS-DOS Compatibility Services _ >>> >>> What Is Your email Address: _______________________ >>> >>> What I'm looking for is a way to describe such forms in a text >>> file that can then be fed into a tool to generate the necessary >>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>> be simple to generate a basic interface like this and have it >>> only record the user's input. Thereafter, the python code >>> would act on the basis of those selection without any further >>> connection to the GUI. >>> >>> An added bonus would be a similar kind of thing for generating >>> web interfaces to do this. This might actually be a better model >>> because then I only have to worry about a single presentation >>> environment. >>> >>> Ideas anyone? Hi Tim This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? Cheers Philip >> >> Yeah, HTML being the text file and a web browser being the tool to transform it into a GUI... >> >> You can hook this up with a simple web server or web framework running locally to grab the submitted form results when the form is complete and process them in a piece of python code. >> >> Wouldn't that work? >> >> >> Irmen > > Yup, although I'd probably use a central apache instance. But > I'm still curious ... is there a way to do this with a full > GUI tool on a thick client? > > > -- > ------------------------------------------------------------------------ > Tim Daneliuk > tundra at tundraware.com > -- > http://mail.python.org/mailman/listinfo/python-list From gordon at panix.com Fri Aug 5 16:52:15 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 20:52:15 +0000 (UTC) Subject: Replace all references to one object with references to other References: Message-ID: In Jack Bates writes: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? The simplest answer to your question is to assign object2 to object1 at the very beginning of your code, but that is a very naive solution and can easily fail based on lots of factors. What's your context: A single source file? Many source files? A live application with persistent data? What are your two objects? Do they provide an identical interface? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gordon at panix.com Fri Aug 5 16:54:20 2011 From: gordon at panix.com (John Gordon) Date: Fri, 5 Aug 2011 20:54:20 +0000 (UTC) Subject: Replace all references to one object with references to other References: Message-ID: In John Gordon writes: > In Jack Bates writes: > > I have two objects, and I want to replace all references to the first > > object - everywhere - with references to the second object. What can I > > try? > The simplest answer to your question is to assign object2 to object1 I think I have that backwards, but the intent should be clear: object1 = object2 # many references to object1 follow, which will now reference object2 -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Fri Aug 5 16:55:54 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Aug 2011 16:55:54 -0400 Subject: Observations on the three pillars of Python execution In-Reply-To: <4E3BA852.9020604@jollybox.de> References: <4E3BA852.9020604@jollybox.de> Message-ID: On 8/5/2011 4:22 AM, Thomas Jollans wrote: > On 05/08/11 09:20, Eric Snow wrote: >> Object available during code object execution: >> (M) no >> (C) no >> (F) no > (F) yes. > > cf. recursion. Recursion only happens through runtime name resolution, not through direct access to the function or code object from within the code. -- Terry Jan Reedy From clp2 at rebertia.com Fri Aug 5 17:12:40 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 14:12:40 -0700 Subject: Question about encoding, I need a clue ... In-Reply-To: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> References: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Message-ID: On Fri, Aug 5, 2011 at 11:07 AM, Geoff Wright wrote: > Hi, > > I use Mac OSX for development but deploy on a Linux server. ?(Platform details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. ASCII can't represent a circumflex anyway, and I think the "default encoding" is distinct from the locale-set encoding, so I don't think the default encoding matters here. >?Specifically, calendar.month_name[8] returns a ? (question mark) on the Linux server whereas it displays properly on the Mac OSX system. ?However, if I take the result from calendar.month_name[8] and run it through the following function .... unicode(calendar.month_name[8],"latin1") ... then the u circumflex displays correctly on the Linux server but does not display correctly on my Mac. > > Of course, I could work around this problem with a relatively simple if statement but these issues are going to show up all over my application so even a simple if statement will start to get cumbersome. > > I guess what it boils down to is that I would like to get a better handle on what is going on so that I will know how best to work through future encoding issues. ?Thanks in advance for any advice. > > Here are the specifics of my problem. > > On my Mac: > > Python 2.6.7 (r267:88850, Jul 30 2011, 23:46:53) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin >>>> calendar.month_name[8] > 'ao\xc3\xbbt' >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao??t > > On the linux server: > > uname -a > Linux alhena 2.6.32.8-grsec-2.1.14-modsign-xeon-64 #2 SMP Sat Mar 13 00:42:43 PST 2010 x86_64 GNU/Linux > > Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40) > [GCC 4.3.2] on linux2 >>>> calendar.month_name[8] > 'ao\xfbt' >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao?t Some quick experimentation seems to indicate that your month names are Latin-1-encoded on Linux and UTF-8-encoded on Mac. Perhaps try using a locale that specifies a specific encoding? e.g. fr_CA.UTF-8 Cheers, Chris -- http://rebertia.com From santoso.wijaya at gmail.com Fri Aug 5 17:13:44 2011 From: santoso.wijaya at gmail.com (Santoso Wijaya) Date: Fri, 5 Aug 2011 14:13:44 -0700 Subject: ctypes LoadLibrary search path Message-ID: Hi, Can anyone enlighten me to the search path mechanism in ctypes' LoadLibrary? I have a DLL that resides elsewhere that is not in any default search path. I tried adding the path to `sys.path` before attempting to load said DLL but I still get "WindowsError: [Error 126] The specified module could not be found." Thanks, ~/santa -------------- next part -------------- An HTML attachment was scrubbed... URL: From santoso.wijaya at gmail.com Fri Aug 5 17:18:04 2011 From: santoso.wijaya at gmail.com (Santoso Wijaya) Date: Fri, 5 Aug 2011 14:18:04 -0700 Subject: ctypes LoadLibrary search path In-Reply-To: References: Message-ID: Nevermind. I figured it out (d'oh!). I had to append to `os.environ['PATH']`, not `sys.path`! ~/santa On Fri, Aug 5, 2011 at 2:13 PM, Santoso Wijaya wrote: > Hi, > > Can anyone enlighten me to the search path mechanism in ctypes' > LoadLibrary? I have a DLL that resides elsewhere that is not in any default > search path. I tried adding the path to `sys.path` before attempting to load > said DLL but I still get "WindowsError: [Error 126] The specified module > could not be found." > > Thanks, > > ~/santa > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Aug 5 17:19:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 14:19:21 -0700 Subject: Get the name of a function In-Reply-To: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On Fri, Aug 5, 2011 at 11:52 AM, gervaz wrote: > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? > > Using self.__dict__.__name__ I've got > >>>> def test(): > ... ? ? print(self.__dict__.__name__) > ... Er, where did `self` magically come from? >>>> test > > > But I really just want the function name, so 'test' > > Any help? Courtesy of the "Observations on the three pillars of Python execution" thread: from inspect import currentframe def foobar(): my_name = currentframe().f_code.co_name print(my_name) I would recommend against a function knowing its own name though, unless it's for debugging or necessary metaprogramming purposes. Cheers, Chris From invalid at invalid.invalid Fri Aug 5 18:05:45 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Aug 2011 22:05:45 +0000 (UTC) Subject: Get the name of a function References: <8295aba8-3eab-4c6e-b3b7-c3421d829220@f7g2000vba.googlegroups.com> Message-ID: On 2011-08-05, gervaz wrote: > Hi all, is there a way to retrive the function name like with > self.__class__.__name__? Not really. There may not be any such thing as "the function name". A function may have zero names, it may have a dozen names. It may have names but only in namespaces that aren't accessible. This question comes up at least once a month, so look back through the group for threads about finding an object's name, finding a parameter's name, etc. Here's a nice article on introspection, but what it talks about as a "function name" probably isn't what you're interested in: http://www.ibm.com/developerworks/library/l-pyint/index.html Here's a stack-overflow question similar to yours: http://stackoverflow.com/questions/1538342/how-can-i-get-the-name-of-an-object-in-python -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From tundra at tundraware.com Fri Aug 5 18:20:16 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 17:20:16 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E3C6CA0.2000706@tundraware.com> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > >> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>> I have a task where I want to create pretty simple one page visual >>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>> than option checklists and text fields. Conceptually something like: >>>> >>>> Please Select Your Installation Options: >>>> >>>> Windows Compatibility Services _ >>>> Linux Compatibility Services _ >>>> TRS-DOS Compatibility Services _ >>>> >>>> What Is Your email Address: _______________________ >>>> >>>> What I'm looking for is a way to describe such forms in a text >>>> file that can then be fed into a tool to generate the necessary >>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>> be simple to generate a basic interface like this and have it >>>> only record the user's input. Thereafter, the python code >>>> would act on the basis of those selection without any further >>>> connection to the GUI. >>>> >>>> An added bonus would be a similar kind of thing for generating >>>> web interfaces to do this. This might actually be a better model >>>> because then I only have to worry about a single presentation >>>> environment. >>>> >>>> Ideas anyone? > > Hi Tim > This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? > > Cheers > Philip > I want to take a text definition file that looks something this: Title "Please Select Your Installation Options:" Checkbox "Windows Compatibility Services" Checkbox "Linux Compatibility Services" Checkbox "TRS-DOS Compatibility Services" Inputbox "What Is Your email Address:" And have that aut-generate the GUI interface described above for the selected GUI toolkit and/or an equivalent HTML page. I know I can write a program to do this, but it seems that someone else may have already solved this problem. Appearance isn't terribly important. I want a "Quick-And-Dirty" configuration manager interface (for configuring new operating system VMs). The reason that I want a simple text file definition is to make it easy to add new options to the display as they become available. For example, suppose it becomes possible to work with a new OS, then all I'd have to do is add the following to the text definition file, and regenerate the interface: Checkbox "MVS Compatibility Services" The idea is to not have to touch the code base as the options of the GUI evolve, but rather to modify the data file that describes it. In some sense, this is a variation of HTML templating except I want to do it (potentially) with a thick client GUI. From tundra at tundraware.com Fri Aug 5 18:20:16 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 17:20:16 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E3C6CA0.2000706@tundraware.com> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: > >> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>> I have a task where I want to create pretty simple one page visual >>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>> than option checklists and text fields. Conceptually something like: >>>> >>>> Please Select Your Installation Options: >>>> >>>> Windows Compatibility Services _ >>>> Linux Compatibility Services _ >>>> TRS-DOS Compatibility Services _ >>>> >>>> What Is Your email Address: _______________________ >>>> >>>> What I'm looking for is a way to describe such forms in a text >>>> file that can then be fed into a tool to generate the necessary >>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>> be simple to generate a basic interface like this and have it >>>> only record the user's input. Thereafter, the python code >>>> would act on the basis of those selection without any further >>>> connection to the GUI. >>>> >>>> An added bonus would be a similar kind of thing for generating >>>> web interfaces to do this. This might actually be a better model >>>> because then I only have to worry about a single presentation >>>> environment. >>>> >>>> Ideas anyone? > > Hi Tim > This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? > > Cheers > Philip > I want to take a text definition file that looks something this: Title "Please Select Your Installation Options:" Checkbox "Windows Compatibility Services" Checkbox "Linux Compatibility Services" Checkbox "TRS-DOS Compatibility Services" Inputbox "What Is Your email Address:" And have that aut-generate the GUI interface described above for the selected GUI toolkit and/or an equivalent HTML page. I know I can write a program to do this, but it seems that someone else may have already solved this problem. Appearance isn't terribly important. I want a "Quick-And-Dirty" configuration manager interface (for configuring new operating system VMs). The reason that I want a simple text file definition is to make it easy to add new options to the display as they become available. For example, suppose it becomes possible to work with a new OS, then all I'd have to do is add the following to the text definition file, and regenerate the interface: Checkbox "MVS Compatibility Services" The idea is to not have to touch the code base as the options of the GUI evolve, but rather to modify the data file that describes it. In some sense, this is a variation of HTML templating except I want to do it (potentially) with a thick client GUI. From ericsnowcurrently at gmail.com Fri Aug 5 18:21:47 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 5 Aug 2011 16:21:47 -0600 Subject: Observations on the three pillars of Python execution In-Reply-To: <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano wrote: > Eric Snow wrote: > >> On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano >> wrote: >>> Eric Snow wrote: >>> >>>> In Python, three types of objects have special syntax and mechanics >>>> for their instantiation, during which a code object is generated: >>>> modules, classes, and functions. >>> >>> I believe you are labouring under a misapprehension. Modules and classes >>> don't generate code objects. >> >> Sorry for any confusion. ?I was talking specifically about the their >> instantiation through their respective special syntax. ?During that >> process a code object is generated for each. > > > Do you believe that this process of generating a code object and throwing it > away is a part of the Python language specification, which any compiler > must do in order to call itself "Python", or a mere implementation detail? That's a great point which I hadn't considered. Honestly, I only used my experience with CPython in making these observations. After reviewing the language reference I see that I missed out on a bunch of nomenclature that would have made things more clear, and I got a few points wrong, which you pointed out. :) Regarding code objects and classes, your are right. The language reference indicates the following: "The class?s suite is then executed in a new execution frame...When the class?s suite finishes execution, its execution frame is discarded but its local namespace is saved." [1] So the use of code objects for execution is an implementation detail. Instead of "code object" I should have referred to the code executed in the execution frame or just to the frame. Incidently, I had not realized that the builtin __build_class__() is also an implementation detail[3]. For modules, the language reference doesn't say anything about how execution is accomplished, which only matters when execution is involved in the creation of the module object. It does refer to importlib as a reference implementation[4]. The order-of-operations observations I made are based on that reference implementation. > > Is this documented somewhere? If it is not documented, what makes you think > that it happens at all? You are writing as if it were self-evidently true, > but I don't believe it is self-evident at all. I think you need to > demonstrate the truth of two of those three pillars, not just take them for > granted. > > >> For classes and modules >> the code object is executed and then discarded. ?I covered this >> explicitly in one of the observations. > > I think your definition of "explicitly" and mine differ here. > > >> Agreed that [non-builtin] functions are the only objects that have a >> code object attribute. ?However, they are not the only objects for >> which a code object is generated and executed. > > Are you talking about the fact that importing a module, class statements and > function statements all involve executing a block of code? > > How does that differ from executing any other fragment of code? The difference is that modules, classes, and functions (really the function body) are code blocks tied to syntax that results in module, type, and function objects. There are other code blocks but none of them have a unique syntax, much less one that results in an object of the corresponding type[5]. This is relevant for trying to find the object that corresponds to an execution frame, which is what led me to my original post and drove the direction of the observations I made. Anyway, I appreciate the feedback! I'm going to have to revisit my observations with the language definition in hand. You've been really insightful, as usual. -eric [1] http://docs.python.org/dev/reference/compound_stmts.html#class-definitions [2] http://docs.python.org/dev/reference/datamodel.html#metaclasses [3] http://mail.python.org/pipermail/python-3000/2007-March/006338.html [4] http://docs.python.org/dev/reference/simple_stmts.html#the-import-statement [5] http://docs.python.org/dev/reference/executionmodel.html#naming > > Modules are special, of course, because they can get compiled to byte-code, > but I trust you're not talking about .pyc files. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From gruszczy at gmail.com Fri Aug 5 18:31:15 2011 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sat, 6 Aug 2011 00:31:15 +0200 Subject: ANN: geany-pyflakes 1.0 In-Reply-To: References: Message-ID: > OK - it no longer crashes, but it doesn't appear to do anything. ?Is there > something further I need to do to configure it? ?The Pyflakes tab does > appear in the message window and I've created a new testpyflakes.py with > code similar to your example. OK, so there must be something wrong. Do you have pyflakes installed? Where are they installed? > Also, just FYI, the plugin manager now shows the version as 1.0.1 while the > tar file name indicates 1.0.2. Yeah, I should make a configure file with version and use it in c code, to never make that mistake again, but I really, really don't wanto to touch autotools again. -- Filip Gruszczy?ski From philip at semanchuk.com Fri Aug 5 18:51:36 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Aug 2011 18:51:36 -0400 Subject: Table Driven GUI Definition? In-Reply-To: <4E3C6CA0.2000706@tundraware.com> References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> <4E3C6CA0.2000706@tundraware.com> Message-ID: <0B122ABE-F0A0-4F11-938F-5698FBADF7FB@semanchuk.com> On Aug 5, 2011, at 6:20 PM, Tim Daneliuk wrote: > On 8/5/2011 3:42 PM, Philip Semanchuk wrote: >> >> On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: >> >>> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>>> I have a task where I want to create pretty simple one page visual >>>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>>> than option checklists and text fields. Conceptually something like: >>>>> >>>>> Please Select Your Installation Options: >>>>> >>>>> Windows Compatibility Services _ >>>>> Linux Compatibility Services _ >>>>> TRS-DOS Compatibility Services _ >>>>> >>>>> What Is Your email Address: _______________________ >>>>> >>>>> What I'm looking for is a way to describe such forms in a text >>>>> file that can then be fed into a tool to generate the necessary >>>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>>> be simple to generate a basic interface like this and have it >>>>> only record the user's input. Thereafter, the python code >>>>> would act on the basis of those selection without any further >>>>> connection to the GUI. >>>>> >>>>> An added bonus would be a similar kind of thing for generating >>>>> web interfaces to do this. This might actually be a better model >>>>> because then I only have to worry about a single presentation >>>>> environment. >>>>> >>>>> Ideas anyone? >> >> Hi Tim >> This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? >> >> Cheers >> Philip >> > > I want to take a text definition file that looks something this: > > Title "Please Select Your Installation Options:" > > > Checkbox "Windows Compatibility Services" > Checkbox "Linux Compatibility Services" > Checkbox "TRS-DOS Compatibility Services" > > Inputbox "What Is Your email Address:" > > > And have that aut-generate the GUI interface described above for the > selected GUI toolkit and/or an equivalent HTML page. > > I know I can write a program to do this, but it seems that someone else > may have already solved this problem. Oh, I see. I didn't realize you were looking for a most canned solution. I agree that it's a problem that's been solved many times. I've used Mako before as an HTML templating engine, but ISTR that it points out that it's agnostic to what it's templating. In other words, it only cares about what's between the Mako escape tags, it doesn't care if the surrounding text is HTML or XML or Python or whatever. So you could have a Mako template that consists mostly of Python code that builds a wxPython window (if wxPython is your cup of tea) and then some Mako commands in the middle that reads your text definition file and adds checkboxes, textboxes, etc. as appropriate. It's not a canned solution, but it does allow you to separate the boilerplate stuff from the variants. Hope this helps Philip From vlastimil.brom at gmail.com Fri Aug 5 19:52:30 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 6 Aug 2011 01:52:30 +0200 Subject: Question about encoding, I need a clue ... In-Reply-To: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> References: <78D1ED51-FAF5-47FA-BFD2-6A083A2E7351@gmail.com> Message-ID: 2011/8/5 Geoff Wright : > Hi, > > I use Mac OSX for development but deploy on a Linux server. ?(Platform details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex consistently across the two machines even though the default encoding is set to "ascii" on both machines. ?... > > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I believe, sys.getdefaultencoding() isn't relevant here; you could try to determine the locale encoding via locale.getlocale() - it should return a tuple with language code and the encoding name http://docs.python.org/library/locale.html#locale.getlocale I suppose, you get the respective encodings on both of your different systems. I somehow can't find the Canadian locale on my OS (win XP, Czech), but hopefully the results are equivalent with French, I checked: cf Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import locale >>> import calendar >>> locale.setlocale(locale.LC_ALL,'French') 'French_France.1252' >>> locale.getlocale() ('fr_FR', 'cp1252') >>> calendar.month_name[8] 'ao\xfbt' >>> print calendar.month_name[8] ao?t >>> unicode(calendar.month_name[8], locale.getlocale()[1]) u'ao\xfbt' >>> print unicode(calendar.month_name[8], locale.getlocale()[1]) ao?t >>> ==== The above are the results in Idle and wx pyshell, i.e. unicode-enabled shells; on non-unicode cmd shell in windows I get: >>> print calendar.month_name[8] aout and even: >>> print unicode(calendar.month_name[8], locale.getlocale()[1]) Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\encodings\cp852.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\xfb' in position 2 : character maps to >>> hth, vbr From tundra at tundraware.com Fri Aug 5 19:57:51 2011 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 05 Aug 2011 18:57:51 -0500 Subject: Table Driven GUI Definition? In-Reply-To: References: <4e3c3eee$0$23931$e4fe514c@news2.news.xs4all.nl> <4E3C6CA0.2000706@tundraware.com> Message-ID: On 8/5/2011 5:51 PM, Philip Semanchuk wrote: > > On Aug 5, 2011, at 6:20 PM, Tim Daneliuk wrote: > >> On 8/5/2011 3:42 PM, Philip Semanchuk wrote: >>> >>> On Aug 5, 2011, at 4:10 PM, Tim Daneliuk wrote: >>> >>>> On 8/5/2011 2:05 PM, Irmen de Jong said this: >>>>> On 05-08-11 19:53, Tim Daneliuk wrote: >>>>>> I have a task where I want to create pretty simple one page visual >>>>>> interfaces (Graphical or Text, but it needs to run across Windows, >>>>>> Cygwin, Linux,*BSD, OSX ...). These interfaces are nothing more >>>>>> than option checklists and text fields. Conceptually something like: >>>>>> >>>>>> Please Select Your Installation Options: >>>>>> >>>>>> Windows Compatibility Services _ >>>>>> Linux Compatibility Services _ >>>>>> TRS-DOS Compatibility Services _ >>>>>> >>>>>> What Is Your email Address: _______________________ >>>>>> >>>>>> What I'm looking for is a way to describe such forms in a text >>>>>> file that can then be fed into a tool to generate the necessary >>>>>> pyGUI, Tkinter, (or whatever) code. The idea is that it should >>>>>> be simple to generate a basic interface like this and have it >>>>>> only record the user's input. Thereafter, the python code >>>>>> would act on the basis of those selection without any further >>>>>> connection to the GUI. >>>>>> >>>>>> An added bonus would be a similar kind of thing for generating >>>>>> web interfaces to do this. This might actually be a better model >>>>>> because then I only have to worry about a single presentation >>>>>> environment. >>>>>> >>>>>> Ideas anyone? >>> >>> Hi Tim >>> This looks pretty straightforward to me; maybe I'm missing something. It doesn't look trivial, but the steps seem pretty clear. Is there some part in particular that's giving you trouble? >>> >>> Cheers >>> Philip >>> >> >> I want to take a text definition file that looks something this: >> >> Title "Please Select Your Installation Options:" >> >> >> Checkbox "Windows Compatibility Services" >> Checkbox "Linux Compatibility Services" >> Checkbox "TRS-DOS Compatibility Services" >> >> Inputbox "What Is Your email Address:" >> >> >> And have that aut-generate the GUI interface described above for the >> selected GUI toolkit and/or an equivalent HTML page. >> >> I know I can write a program to do this, but it seems that someone else >> may have already solved this problem. > > Oh, I see. I didn't realize you were looking for a most canned solution. I agree that it's a problem that's been solved many times. > > I've used Mako before as an HTML templating engine, but ISTR that it points out that it's agnostic to what it's templating. In other words, it only cares about what's between the Mako escape tags, it doesn't care if the surrounding text is HTML or XML or Python or whatever. > > So you could have a Mako template that consists mostly of Python code that builds a wxPython window (if wxPython is your cup of tea) and then some Mako commands in the middle that reads your text definition file and adds checkboxes, textboxes, etc. as appropriate. It's not a canned solution, but it does allow you to separate the boilerplate stuff from the variants. > > Hope this helps > Philip > Something like this is more what I had in mind (but this seems to not be actively supported????): http://pythoncard.sourceforge.net/documentation.html From steve+comp.lang.python at pearwood.info Fri Aug 5 20:57:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 10:57:41 +1000 Subject: Replace all references to one object with references to other References: Message-ID: <4e3c9186$0$29977$c3e8da3$5496439d@news.astraweb.com> Jack Bates wrote: > I have two objects, and I want to replace all references to the first > object - everywhere - with references to the second object. What can I > try? Another way of solving your *actual* problem. "Replace all references to object1 with object2 instead" is a means to an end, not the end itself. What are you trying to solve? Focus on *that* problem, not your supposed solution, because "replace all..." is doomed to fail. There is no "master list" of objects available to you. All you have is one or more namespaces containing objects. Many of those objects themselves will contain other objects, and so on. All you can do is walk through each namespace in turn, recursively into each object, searching for the object you want to replace. But that may not help you, because there's no guarantee that having found it you can replace it safely, *or at all*. While Python does allow code to reach deeply into the internals of a wide range of objects -- very little is truly private in Python -- do you *really* want to be taking responsibility for safely replacing objects from within arbitrary other objects? If so, Python gives you the tools to shoot yourself in the foot, although it won't necessarily be easy, or pretty, or fast. So, tell us what your real problem is, the end towards which you think "replace all..." is the solution, and we'll see if we can help. -- Steven From bigblueswope at gmail.com Fri Aug 5 21:29:01 2011 From: bigblueswope at gmail.com (BJ Swope) Date: Fri, 5 Aug 2011 21:29:01 -0400 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: The best tool to debug this is tcpdump. Running a packet capture whilst sending the mail will most likely shed the most light on the subject. -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Fri Aug 5 21:31:02 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 5 Aug 2011 18:31:02 -0700 (PDT) Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Aug 1, 5:33?pm, aliman wrote: > I understand that sorts are stable, so I could just repeat the whole > sort process once for each key in turn, but that would involve going > to and from disk once for each step in the sort, and I'm wondering if > there is a better way. I would consider using memory mapping the file and sorting it inline. Sorting a binary file of bytes with NumPy is as easy as this: import numpy as np f = np.memmap(filename, mode='rwb', dtype=np.uint8) f.sort(kind='quicksort') del f (You can define dtype for any C data type or struct.) If the file is really big, use 64-bit Python. With memory mapping you don't have to worry about processing the file in chunks, because the operating systems will take care of those details. I am not sure how to achieve this (inline file sort) with standard library mmap and timsort, so I'll leave that out. Sturla From steve+comp.lang.python at pearwood.info Fri Aug 5 22:01:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 12:01:51 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3ca090$0$30003$c3e8da3$5496439d@news.astraweb.com> Mel wrote: > Steven D'Aprano wrote: > >> There may be some other obscure built-in type that includes code objects, >> but I can't imagine what it would be. I feel confident in saying that >> functions, and functions alone, contain code. Even methods are just >> wrappers around functions. Even built-in functions like len don't contain >> code! (Or at least, their code isn't accessible from Python.) Which makes >> sense, if you think about it: their code is part of the Python virtual >> machine, not the object. > > Interesting question. Iterators seem to have code objects: [...] Generators. But nice catch, thank you! Iterators are *any* object which obeys the iterator protocol, that is, have a next() method and an __iter__() method which behave in the expected way. Iterators are a duck-type. Generators, whether created from a generator expression or a generator function, are an actual type. >>> type(x for x in (1,2)) -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 22:05:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 12:05:01 +1000 Subject: Observations on the three pillars of Python execution References: <4e3bffe1$0$29996$c3e8da3$5496439d@news.astraweb.com> <4e3c286a$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3ca14e$0$30003$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano > wrote: [...] >> Do you believe that this process of generating a code object and throwing >> it away is a part of the Python language specification, which any >> compiler must do in order to call itself "Python", or a mere >> implementation detail? > > That's a great point which I hadn't considered. Honestly, I only used > my experience with CPython in making these observations. After > reviewing the language reference I see that I missed out on a bunch of > nomenclature that would have made things more clear, and I got a few > points wrong, which you pointed out. :) > > Regarding code objects and classes, your are right. The language > reference indicates the following: > > "The class?s suite is then executed in a new execution frame...When > the class?s suite finishes execution, its execution frame is discarded > but its local namespace is saved." [1] It turns out that in CPython 2.5 at least, I'm strictly wrong and you got it right, at least for classes: >>> code = compile("""class K: pass""", '', 'exec') >>> dis.dis(code) 1 0 LOAD_CONST 0 ('K') 3 LOAD_CONST 3 (()) 6 LOAD_CONST 1 () 9 MAKE_FUNCTION 0 12 CALL_FUNCTION 0 15 BUILD_CLASS 16 STORE_NAME 0 (K) 19 LOAD_CONST 2 (None) 22 RETURN_VALUE So a code object is compiled, turned into a function, executed, the results turned into a class, and the code object and function thrown away. Is this an implementation detail? I would say so. The semantics of Python the language are different from the details of it's virtual machine. Surely we would be allowed to call something Python if it executed the body of the class statement *without* creating a code object first? The important part is *execute the body of the class statement*, not building the code object. The later is merely a means to an end. > So the use of code objects for execution is an implementation detail. > Instead of "code object" I should have referred to the code executed > in the execution frame or just to the frame. Unless you really intend to talk about implementation details, I think you should keep the discussion as high-level as possible. I'd talk about executing blocks of code, and not even mention execution frames unless you need to understand the role of frames during execution. -- Steven From roy at panix.com Fri Aug 5 22:54:05 2011 From: roy at panix.com (Roy Smith) Date: Fri, 05 Aug 2011 22:54:05 -0400 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Wow. I was going to suggest using the unix command-line sort utility via popen() or subprocess. My arguments were that it's written in C, has 30 years of optimizing in it, etc, etc, etc. It almost certainly has to be faster than anything you could do in Python. Then I tried the experiment. I generated a file of 1 million random integers in the range 0 to 5000. I wrote a little sorting program: numbers = [int(line) for line in open('numbers')] numbers.sort() for i in numbers: print i and ran it on my MacBook Pro (8 Gig, 2 x 2.4 GHz cores), Python 2.6.1. $ time ./sort.py > py-sort real 0m2.706s user 0m2.491s sys 0m0.057s and did the same with the unix utility: $ time sort -n numbers > cli-sort real 0m5.123s user 0m4.745s sys 0m0.063s Python took just about half the time. Certainly knocked my socks off. Hard to believe, actually. From drsalists at gmail.com Fri Aug 5 23:08:05 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 20:08:05 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: Yup. Timsort is described as "supernatural", and I'm inclined to believe it. On Fri, Aug 5, 2011 at 7:54 PM, Roy Smith wrote: > Wow. > > Python took just about half the time. Certainly knocked my socks off. > Hard to believe, actually. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 5 23:10:36 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 5 Aug 2011 20:10:36 -0700 Subject: Inconsistent SMTP/Gmail connection drop In-Reply-To: References: <92b389cf-4aa9-4cc3-9017-d4b1ec6de7d8@d7g2000vbv.googlegroups.com> Message-ID: Well, a sniffer is one of many, and one worth mentioning. Though I'd recommend wireshark over tcpdump, pretty much any day. http://stromberg.dnsalias.org/~dstromberg/Problem-solving-on-unix-linux-systems.html On Fri, Aug 5, 2011 at 6:29 PM, BJ Swope wrote: > The best tool to debug this is tcpdump. > > Running a packet capture whilst sending the mail will most likely shed the > most light on the subject. > > > -- > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 5 23:12:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 13:12:02 +1000 Subject: Question about encoding, I need a clue ... References: Message-ID: <4e3cb103$0$29984$c3e8da3$5496439d@news.astraweb.com> Geoff Wright wrote: > Hi, > > I use Mac OSX for development but deploy on a Linux server. (Platform > details provided below). > > When the locale is set to FR_CA, I am not able to display a u circumflex > consistently across the two machines even though the default encoding is > set to "ascii" on both machines. As somebody else already pointed out, ? (u circumflex) is not an ASCII character, so why would you expect to be able to use it with the ASCII encoding? Essential reading: http://www.joelonsoftware.com/articles/Unicode.html Drop everything and go read that! Using Python 2.x, so-called strings are byte strings, which complicates matters greatly. The month name you get: 'ao\xc3\xbbt' is a string of five bytes with hex values: x61 x6f xc3 xbb x74 Depending on how your terminal is set up, that MAY be interpreted as the characters a o ? t but you could end up with anything: >>> print s ao?t (In theory, even the a, o and t could change, but I haven't found any terminal settings *that* wacky.) > Specifically, calendar.month_name[8] > returns a ? (question mark) on the Linux server whereas it displays > properly on the Mac OSX system. That could mean either: (1) the terminal on the Linux server is set to a different default encoding from that on the Mac; or (2) the two terminals have the same encoding, but the font used on the Linux server doesn't include the right glyph to display ?. Of the two, I expect (1) is more likely. The solution is to avoid relying on lucky accidents of the terminal encoding, and deal with this the right way. The right way is nearly always to use UTF-8 everywhere you can, not Latin 1. Make sure your terminal is set to use UTF-8 as well (I believe this is the default for Mac OS's terminal app, but I have no idea about the many different Linux terminals). Then: >>> bytes = 'ao\xc3\xbbt' # From calendar.month_name[8] >>> s = bytes.decode('utf-8') # Like unicode(bytes, 'utf-8') >>> s u'ao\xfbt' >>> print s ao?t Provided your Linux server terminal also is set to use UTF-8, this should just work. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 5 23:30:33 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 13:30:33 +1000 Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: <4e3cb55a$0$29985$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Wow. > > I was going to suggest using the unix command-line sort utility via > popen() or subprocess. My arguments were that it's written in C, has 30 > years of optimizing in it, etc, etc, etc. It almost certainly has to be > faster than anything you could do in Python. > > Then I tried the experiment. I generated a file of 1 million random > integers in the range 0 to 5000. I wrote a little sorting program: [...] > Python took just about half the time. Certainly knocked my socks off. > Hard to believe, actually. One million integers isn't very big. If each integer can fit in four-byte long, that's less than 4MB. That's almost small enough to fit in your CPU's cache, with room left over for the first few chapters of "War And Peace" *wink* So you're comparing Python's timsort, which is Awesome with a capital AWE but only works on data that fits in memory, versus something which can also work on files too big to fit into memory. Try generating a twenty gigabyte file of data, and sort that. Actually, don't, because just *reading it in* to Python will probably fail, and very possibly lock your PC up for the duration. Unix sort does an external R-Way merge sort: if you have more data than memory, it slices the data up into a bunch of smaller pieces, each of which will fit in memory, sorts each one to a temporary file, then merges the lot. It does a lot more work on such big files, because it *takes* a lot more work. For something as small as one million numbers, chances are the Unix sort falls back on a heapsort or a quicksort, which will be pretty fast, but it ain't no timsort. So yes, Python's timsort is awesome, but so is Unix's sort, just in different ways. -- Steven From clp2 at rebertia.com Sat Aug 6 00:45:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Aug 2011 21:45:21 -0700 Subject: JSON Strict Mode In-Reply-To: References: Message-ID: > On Fri, Aug 5, 2011 at 2:19 AM, Chris Rebert wrote: >> On Thu, Aug 4, 2011 at 8:25 PM, John Riselvato >> wrote: >> > I am working on a license?verification?script. I am rather new to the >> > concept and to JSON files in general. >> > This is what my pseudocode looks like: >> >> >> >> licenses = meta['license'] >> >> for x in licenses: >> >> ? ? if licenses[x]['terms'] is not valid opensource license >> >> I would probably instead write that as: >> >> for license_name, license in licenses.items(): >> ? ?if not is_open_source(license['terms']): >> # rest same as before >> >> >> ? ? ? ? if in strict mode >> >> ? ? ? ? ? ? raise nonfree exception >> > >> > How would i go about checking if its in "strict mode" >> > and what does "raise nonfree exception" mean? >> In your specific example, the non-pseudo-code would look something like: >> >> # a declaration somewhere: >> class NonFreeLicenseError(ValueError): >> ? ?"""License is not free according to the Open Source Definition.""" >> >> # ... back in the part of your code corresponding to your pseudocode: >> if strict: >> ? ?raise NonFreeLicenseError("The '%s' license is nonfree and thus >> impermissible." % x) >> >> As written, I have NonFreeLicenseError as a kind of ValueError. This >> may or may not be appropriate depending on your program; a list of >> built-in types of exceptions can be found at >> http://docs.python.org/dev/library/exceptions.html#bltin-exceptions On Fri, Aug 5, 2011 at 3:44 PM, John Riselvato wrote: > Thanks for this mate.I took what you said and made this. >>> >>> ? ? ? ? licenseCheck = Syn.policy.metafile.LICENSE_CLEAN >>> ? ? ? ? licenses = meta['license'] >>> ? ? ? ? for i in licenses: >>> ? ? ? ? ? ? ? ? if licenses[i]['terms'] in licenseCheck == False: More conventionally written: if licenses[i]['terms'] not in licenseCheck: For that matter, I would rename `licenseCheck` to something clearer like `acceptableLicenses`. >>> ? ? ? ? ? ? ? ? ? ? ? ? try: >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? raise Exception(licenses[i]['terms']) >>> ? ? ? ? ? ? ? ? ? ? ? ? except Exception as inst: >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? errors = errors + 1 >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Syn.log.l(Syn.log.CRITICAL, "Doesn't meet >>> License requirement!!!") >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Syn.log.l(Syn.log.CRITICAL, "License %s >>> is **NOT** marked as clean!!" % license[i]['terms']) It's pretty pointless to catch the exception right after you raise it like this. Exceptions are intended to communicate the error to the caller, which you're not doing here, so they may not be necessary. Also, one typically raises a more specific exception than just Exception, which is the most general and vague exception possible; see my prior post for an example of using a custom exception class. > the licenseCheck main infromation you need to know is: >>> >>> LICENSE_CLEAN = [ >>> "GPL", >>> "GPL-1", >>> "GPL-2", >>> "GPL-3", >>> "X11", >>> "MIT", >>> "PSFL-2" >>> ] If you have a recent version of Python, I'd recommend using a set instead: LICENSE_CLEAN = set([ "GPL", "GPL-1", # etc... ]) This is more conceptually accurate and should be faster too. > The JSON file information is set up practically like this: >> >> "license" : { >> "*" : { >> "terms" : "GPL-3", >> "author" : "Joe Shmo, et. al" >> } >> } >> >> Is what i programmed close to what I was trying to explain? More or less. If "*" is the only entry in "license", then the for-loop is unnecessary and you can just use reference licenses['*']['terms'] (and similar) directly; one would need a specification of the your data format (or at least more examples) to be sure. And your use of exceptions doesn't really match the pseudocode, although your underlying logic is entirely reasonable, even moreso if you were to not use exceptions. Cheers, Chris -- http://rebertia.com From devraj at gmail.com Sat Aug 6 01:49:38 2011 From: devraj at gmail.com (Devraj) Date: Fri, 5 Aug 2011 22:49:38 -0700 (PDT) Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function Message-ID: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Hi all, I am trying to simply my Web application handlers, by using Python decorators. Essentially I want to use decorators to abstract code that checks for authenticated sessions and the other that checks to see if the cache provider (Memcache in this instance) has a suitable response. Consider this method definition with the decorators: @auth.login_required @cache.clear def post(self, facility_type_id = None): auth.login_required checks to see if the user is logged in, otherwise returns an appropriate error message, or executes the original function. cache.clear would check to to see if the cache has a particular key and drop that, before it executes the calling method. Both auth.login_required and cache.clear would want to eventually execute the calling method (post). >From what I've read both, doing what I am doing now would execute the calling method (post) twice. My question, how do I chain decorators that end up executing the calling method, but ensure that it's only called once. Appreciate any pointers and thanks for your time. From nobody at nowhere.com Sat Aug 6 01:59:41 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Aug 2011 06:59:41 +0100 Subject: Question about encoding, I need a clue ... References: Message-ID: On Fri, 05 Aug 2011 14:07:54 -0400, Geoff Wright wrote: > I guess what it boils down to is that I would like to get a better handle > on what is going on so that I will know how best to work through future > encoding issues. Thanks in advance for any advice. > > Here are the specifics of my problem. > > On my Mac: >>>> sys.getdefaultencoding() > 'ascii' sys.getdefaultencoding() is a red herring. It's almost always 'ascii', and isn't affected by the locale (and cannot be changed outside of the site.py file). >>>> import calendar >>>> calendar.month_name[8] > 'ao\xc3\xbbt' This is the "repr()" of 'ao?t' in UTF-8. >>>> print calendar.month_name[8] > ao?t >>>> print unicode(calendar.month_name[8],"latin1") > ao??t This is what you get if you decode the UTF-8 representation of 'ao?t' using ISO-8859-1 (aka ISO-Latin-1). > On the linux server: >>>> calendar.month_name[8] > 'ao\xfbt' This is the "repr()" of 'ao?t' in ISO-8859-1. Conclusion: the Mac's "fr_CA" locale uses UTF-8, the Linux system uses ISO-8859-1 (there may or may not be a distinct "fr_CA.utf8" locale which uses UTF-8). The difference between the two /isn't/ responsible for your problem; your problem is almost certainly due to a mismatch between the encoding used by the terminal and the locale's encoding. If you get a "?" on the Linux system, it's likely that the terminal (or emulator) is configured to use something other than ISO-8859-1 (e.g. UTF-8 or ASCII). For a GUI-based emulator (xterm, etc), you need to consult the documentation for the specific program. For the Linux console, refer to the setfont(8) manual page. In this situation, there probably isn't much point in converting to and from Unicode. You can't perform the encoding step (Unicode -> whatever) without knowing the terminal's encoding. It *should* be the same as the locale's encoding, in which case converting to and from Unicode is an identity transformation (i.e. you get out exactly what you put in). If it isn't the same as the locale's encoding, well ... good luck trying to figure out what it is. From eaglebalti at gmail.com Sat Aug 6 02:24:53 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 5 Aug 2011 23:24:53 -0700 (PDT) Subject: Hello My Sweet Friends. Message-ID: Hello Friends.How are you all? Please visit the following link to watch what you want http://watchonlineindianmovies.blogspot.com/ http://hotfemaletennisplayershotphotos.blogspot.com/ http://kaitrinakaifhotpicshotvideosmovies.blogspot.com/ http://onlinehindimoviesfreewatch4u.blogspot.com/ From skippy.hammond at gmail.com Sat Aug 6 02:55:28 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 06 Aug 2011 16:55:28 +1000 Subject: Dynamically linking python into my vc project - help required In-Reply-To: <6cafe6745022b37909647db99073fc87@edss.co.in> References: <6cafe6745022b37909647db99073fc87@edss.co.in> Message-ID: <4E3CE560.30604@gmail.com> On 3/08/2011 6:58 PM, mrinalini at edss.co.in wrote: > Hi, > > I am trying to embed python into my MFC application. I have done this > before by statically linking to the python lib. But I want to change > this now. > The idea is to take the information from the registry for the installed > version of python on the target machine. Then load python using > loadlibrary call and use the functions from python using pointers to > functions returned by GetProcAddress . ... > PyObject* pObject = pFPyEval_EvalCode((PyCodeObject*)pCodeObject, > m_Dictionary, m_Dictionary); > } > > > I am facing two problems here , though I want to link to python > dynamically I am required to include python.h for my code to compile the > following declaration. > > PyObject* pCodeObject You can probably just define pFPyEval_EvalCode as taking a PyObject * (but I'm not sure where you are getting a declaration of PyObject * from) > I tried copying some of the python definitions including PyObject into a > header in my mfc app. Then it complies fine. but Py_CompileString call > fails. so finally I am unable to run script from my MFC application by > linking to python dynamically. Are you sure you have the calling convention correct on those function pointer decls? > How can this be done ? Please help. Is there a different approach to > linking to python dynamically. Please could you write to me ? py2exe takes the same basic approach as you and might be worth copying its declarations for the function pointers? Mark From eliben at gmail.com Sat Aug 6 03:34:48 2011 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 6 Aug 2011 10:34:48 +0300 Subject: Calling super() in __init__ of a metaclass Message-ID: Consider this standard metaclass definition: class MyMetaclass(type): def __init__(cls, name, bases, dct): super(MyMetaclass, cls).__init__(name, bases, dct) # do meta-stuff class Foo(object): __metaclass__ = MyMetaclass The call "super(MyMetaclass, cls)" should returns the parent of MyMetaclass here. But the 'cls' passed into this __init__ is *not* MyMetaclass, but rather the created class - i.e. Foo. So how does "super" get to the parent of MyMetaclass using this information? The documentation of "super" says: If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods). Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass of MyMetaclass, so this doesn't help. Eli From thinke365 at gmail.com Sat Aug 6 03:38:35 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 15:38:35 +0800 Subject: can virtualenv run without the main installation? Message-ID: At first i have a python environment, after using virtualenv test command, a new environment named test is created, in that directory have some of the executable commands such as python.exe, so can i program without the main installation of python? From rafadurancastaneda at gmail.com Sat Aug 6 03:49:30 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sat, 06 Aug 2011 09:49:30 +0200 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: <4E3CF20A.5000400@gmail.com> You don't need doing something special, each decorator returns a new function that and only the result function formed by all decorators will be run. Consider this: def clear_cache(func): def decorator(*args, **kwargs): print "cache cleared" return func(*args, **kwargs) return decorator def login(func): def decorator(*args, **kwargs): print "login" return func(*args, **kwargs) return decorator @login @clear_cache def post(msg= "POST", *args): print msg return args result = post("POST", "something") print result The output will be: login cache cleared POST ('something',) On 06/08/11 07:49, Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > > From what I've read both, doing what I am doing now would execute the > calling method (post) twice. > > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. > > Appreciate any pointers and thanks for your time. From clp2 at rebertia.com Sat Aug 6 03:49:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Aug 2011 00:49:59 -0700 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: On Fri, Aug 5, 2011 at 10:49 PM, Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > >From what I've read both, doing what I am doing now would execute the > calling method (post) twice. That's incorrect unless the decorators you're using are weird. > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. That's how it works normally; decorators stack (and order is therefore important). With normal wrapping decorators, only the first decorator gets access to the original function and is able to call it. Subsequent decorators only get access to the already-wrapped function. Example: def decorator_A(func): def decorated(*args, **kwds): print "In decorator A" return func(*args, **kwds) return decorated def decorator_B(func): def decorated(*args, **kwds): print "In decorator B" return func(*args, **kwds) return decorated @decorator_B @decorator_A def myfunc(arg): print "hello", arg >>> myfunc('bob') In decorator B In decorator A hello bob Notice that myfunc() only got executed once. Cheers, Chris -- http://rebertia.com From thinke365 at gmail.com Sat Aug 6 03:51:41 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 15:51:41 +0800 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: env create by virtualenv will refer to the main env, how did it find the main env, is there any configuration files, if yes, where is it? 2011/8/6 smith jack : > At first i have a python environment, after using virtualenv test > command, a new environment named test is created, in that directory > have some of the executable commands > such as python.exe, so can i program without the main installation of python? > From __peter__ at web.de Sat Aug 6 03:59:00 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Aug 2011 09:59 +0200 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has a suitable response. > > Consider this method definition with the decorators: > > @auth.login_required > @cache.clear > def post(self, facility_type_id = None): > > auth.login_required checks to see if the user is logged in, otherwise > returns an appropriate error message, or executes the original > function. > > cache.clear would check to to see if the cache has a particular key > and drop that, before it executes the calling method. > > Both auth.login_required and cache.clear would want to eventually > execute the calling method (post). > > From what I've read both, doing what I am doing now would execute the > calling method (post) twice. > > My question, how do I chain decorators that end up executing the > calling method, but ensure that it's only called once. You typically don't need to do anything special for the above to work: >>> def v(f): ... print "decorator v, wrapping", f.__name__, "into a" ... def a(*args, **kw): ... print "calling", f.__name__, "from a" ... return f(*args, **kw) ... return a ... >>> def w(f): ... print "decorator w, wrapping", f.__name__, "into b" ... def b(*args, **kw): ... print "calling", f.__name__, "from b" ... return f(*args, **kw) ... return b ... >>> @v ... @w ... def f(s): ... print s ... decorator w, wrapping f into b decorator v, wrapping b into a >>> f("hello") calling b from a calling f from b hello The output shows that w wraps f into b, but v then doesn't get to see the original f, it wraps b into a. Put another way @v @w def f(): ... is the same as def f(): ... f = v(w(f)) and calling f() now is equivalent to calling a() which may or may not invoke b() which may or may not invoke the original f(). Translated into your example: def post(self, facility_type_id = None): ... post = auth.login_required(cache.clear(post)) The cache should only be cleared after a successful login, and the original post() will only be invoked after a successful login and with a cleared cache. From clp2 at rebertia.com Sat Aug 6 04:04:30 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Aug 2011 01:04:30 -0700 Subject: Calling super() in __init__ of a metaclass In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 12:34 AM, Eli Bendersky wrote: > Consider this standard metaclass definition: > > class MyMetaclass(type): > ? ?def __init__(cls, name, bases, dct): > ? ? ? ?super(MyMetaclass, cls).__init__(name, bases, dct) > ? ? ? ?# do meta-stuff > > class Foo(object): > ? ?__metaclass__ = MyMetaclass > > The call "super(MyMetaclass, cls)" should returns the parent of > MyMetaclass here. But the 'cls' passed into this __init__ is *not* > MyMetaclass, but rather the created class - i.e. Foo. ...which is an instance of the first argument to super(), which is how super is typically invoked. Remember: a class is an instance of its metaclass. Perhaps if you rename `cls` to `self` and then re-read your snippet, you'll have a flash of sudden understanding. Calling the parameter `cls` is merely convention. > So how does > "super" get to the parent of MyMetaclass using this information? The > documentation of "super" says: > > ? ?If the second argument is a type, issubclass(type2, type) must be > true (this is useful for classmethods). > > Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass > of MyMetaclass, so this doesn't help. The typical form of super(), mentioned earlier in the documentation, is being used here: super(type, obj) -> bound super object; requires isinstance(obj, type) `type` here is the metaclass, `obj` here is the class. By definition, a class is an *instance* of its metaclass, so the precondition is satisfied. Cheers, Chris -- http://rebertia.com From __peter__ at web.de Sat Aug 6 04:11:49 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Aug 2011 10:11:49 +0200 Subject: Calling super() in __init__ of a metaclass References: Message-ID: Eli Bendersky wrote: > Consider this standard metaclass definition: > > class MyMetaclass(type): > def __init__(cls, name, bases, dct): > super(MyMetaclass, cls).__init__(name, bases, dct) > # do meta-stuff > > class Foo(object): > __metaclass__ = MyMetaclass > > The call "super(MyMetaclass, cls)" should returns the parent of > MyMetaclass here. But the 'cls' passed into this __init__ is *not* > MyMetaclass, but rather the created class - i.e. Foo. So how does > "super" get to the parent of MyMetaclass using this information? The > documentation of "super" says: > > If the second argument is a type, issubclass(type2, type) must be > true (this is useful for classmethods). > > Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass > of MyMetaclass, so this doesn't help. Don't let yourself get confused by the name 'cls' for what is normally called 'self'. Foo is an instance of MyMetaclass, so the situation is exactly the same as in class A(object): def __init__(self, ...) super(A, self).__init__(...) I don't know how exactly super() is implemented, but to go from an instance to its class you can use type(instance) or instance.__class__. From eliben at gmail.com Sat Aug 6 04:18:28 2011 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 6 Aug 2011 11:18:28 +0300 Subject: Calling super() in __init__ of a metaclass In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:04, Chris Rebert wrote: > On Sat, Aug 6, 2011 at 12:34 AM, Eli Bendersky wrote: >> Consider this standard metaclass definition: >> >> class MyMetaclass(type): >> ? ?def __init__(cls, name, bases, dct): >> ? ? ? ?super(MyMetaclass, cls).__init__(name, bases, dct) >> ? ? ? ?# do meta-stuff >> >> class Foo(object): >> ? ?__metaclass__ = MyMetaclass >> >> The call "super(MyMetaclass, cls)" should returns the parent of >> MyMetaclass here. But the 'cls' passed into this __init__ is *not* >> MyMetaclass, but rather the created class - i.e. Foo. > > ...which is an instance of the first argument to super(), which is how > super is typically invoked. Remember: a class is an instance of its > metaclass. > > Perhaps if you rename `cls` to `self` and then re-read your snippet, > you'll have a flash of sudden understanding. Calling the parameter > `cls` is merely convention. > >> So how does >> "super" get to the parent of MyMetaclass using this information? The >> documentation of "super" says: >> >> ? ?If the second argument is a type, issubclass(type2, type) must be >> true (this is useful for classmethods). >> >> Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass >> of MyMetaclass, so this doesn't help. > > The typical form of super(), mentioned earlier in the documentation, > is being used here: > > ? ?super(type, obj) -> bound super object; requires isinstance(obj, type) > > `type` here is the metaclass, `obj` here is the class. By definition, > a class is an *instance* of its metaclass, so the precondition is > satisfied. Thanks, Chris. This clarifies things. Eli From 1248283536 at qq.com Sat Aug 6 04:27:15 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sat, 6 Aug 2011 16:27:15 +0800 Subject: install editra Message-ID: sudo python /opt/Editra-0.6.58/setup.py install Traceback (most recent call last): File "/opt/Editra-0.6.58/setup.py", line 639, in DoSourcePackage() File "/opt/Editra-0.6.58/setup.py", line 498, in DoSourcePackage DATA = GenerateSrcPackageFiles() File "/opt/Editra-0.6.58/setup.py", line 190, in GenerateSrcPackageFiles for loc_dir in os.listdir("locale"): OSError: [Errno 2] No such file or directory: 'locale' how to solve it?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 05:17:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 06 Aug 2011 19:17:57 +1000 Subject: install editra References: Message-ID: <4e3d06c6$0$29997$c3e8da3$5496439d@news.astraweb.com> ???? wrote: > sudo python /opt/Editra-0.6.58/setup.py install > Traceback (most recent call last): > File "/opt/Editra-0.6.58/setup.py", line 639, in > DoSourcePackage() > File "/opt/Editra-0.6.58/setup.py", line 498, in DoSourcePackage > DATA = GenerateSrcPackageFiles() > File "/opt/Editra-0.6.58/setup.py", line 190, in GenerateSrcPackageFiles > for loc_dir in os.listdir("locale"): > OSError: [Errno 2] No such file or directory: 'locale' > > how to solve it?? Try: cd /opt/Editra-0.6.58/ sudo python setup.py install and if that doesn't work, try asking on an Editra mailing list. -- Steven From thinke365 at gmail.com Sat Aug 6 06:20:30 2011 From: thinke365 at gmail.com (smith jack) Date: Sat, 6 Aug 2011 18:20:30 +0800 Subject: How to make the program support communication behind NAT device? Message-ID: The subnet behind my router is 192.168.1.0/24, my pc ip is 192.168.1.9, the server written with python is hosted on 192.168.1.3 on port 1033, i can connect to this server from my pc But cannot connect to this server when outside of this subnet? why? I have made port translate on router, that is 10.10.9.2:1033 to 192.168.1.3:1033 what's wrong? From vipul.iiith at gmail.com Sat Aug 6 06:35:34 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 16:05:34 +0530 Subject: Segmentation Fault on exit Message-ID: Hi, I have wrapped a library from C++ to Python using SWIG. But when I import it in Python, I am able to work fine with it, but it gives a segmentation fault while exiting. Following is the log: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pyossim >>> * Do some stuff * >>> exit() Segmentation fault vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ Kindly help. Thanks and Regards, Vipul Raheja From rosuav at gmail.com Sat Aug 6 07:02:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 12:02:03 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: The most likely cause of this is that you DECREF'd an object when you shouldn't have, or failed to INCREF one when you should have. Check over your object usage; if you can narrow down the "Do some stuff" bit to the one function call that causes the crash, it'll help you figure out where the error is. Hope that helps! Chris Angelico From vipul.iiith at gmail.com Sat Aug 6 07:16:35 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 16:46:35 +0530 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: Hi Chris, Thanks for the reply. However, the error occurs even if I don't do anything, that is, even if I simply import the library and exit() after that. I created a file a.py whose contents were the following: import pyossim exit() Upon execution, the log was as follows: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python a.py Segmentation fault Following was the gdb log: vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ gdb `which python` GNU gdb (GDB) 7.2-ubuntu Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /usr/bin/python...(no debugging symbols found)...done. (gdb) run a.py Starting program: /usr/bin/python a.py [Thread debugging using libthread_db enabled] Program received signal SIGSEGV, Segmentation fault. 0x00000029 in ?? () (gdb) bt #0 0x00000029 in ?? () #1 0x0171de9f in OpenThreads::Mutex::~Mutex() () from /usr/lib/libOpenThreads.so.13 #2 0x0035369e in ?? () from /lib/libc.so.6 #3 0x0035370f in exit () from /lib/libc.so.6 #4 0x080fc854 in ?? () #5 0x080fcdf5 in ?? () #6 0x080fdc9b in PyRun_SimpleFileExFlags () #7 0x0805b6d3 in Py_Main () #8 0x0805a8ab in main () (gdb) Regards, Vipul Raheja On Sat, Aug 6, 2011 at 4:32 PM, Chris Angelico wrote: > On Sat, Aug 6, 2011 at 11:35 AM, Vipul Raheja > wrote: > > Hi, > > > > I have wrapped a library from C++ to Python using SWIG. But when I > > import it in Python, I am able to work fine with it, but it gives a > > segmentation fault while exiting. Following is the log: > > The most likely cause of this is that you DECREF'd an object when you > shouldn't have, or failed to INCREF one when you should have. Check > over your object usage; if you can narrow down the "Do some stuff" bit > to the one function call that causes the crash, it'll help you figure > out where the error is. > > Hope that helps! > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 6 07:23:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 12:23:33 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 12:16 PM, Vipul Raheja wrote: > Hi Chris, > Thanks for the reply. > However, the error occurs even if I don't do anything, that is, even if I > simply import the library and exit() after that. > I created a file a.py whose contents were the following: > import pyossim > exit() In that case, it may be in your initialization/cleanup code. Check to see if you return Py_None without increffing it, or keep a reference to something you don't own and decref it on exit. ChrisA From python.list at tim.thechases.com Sat Aug 6 08:19:27 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 06 Aug 2011 07:19:27 -0500 Subject: How do I implement two decorators in Python both of which would eventually want to call the calling function In-Reply-To: References: <8b087624-4e05-4d2e-bf4f-78383202b7e1@28g2000pry.googlegroups.com> Message-ID: <4E3D314F.5050809@tim.thechases.com> On 08/06/2011 02:49 AM, Chris Rebert wrote: > On Fri, Aug 5, 2011 at 10:49 PM, Devraj wrote: >> My question, how do I chain decorators that end up executing the >> calling method, but ensure that it's only called once. > > That's how it works normally; decorators stack (and order is therefore > important). With normal wrapping decorators, only the first decorator > gets access to the original function and is able to call it. I'd clarify "first decorator" here as the one closest to the decorated function which is actually the *last* one in the list of decorators, but first-to-decorate. In Chris's example below, decorator_A is the only one that calls myfunc(). > Subsequent decorators only get access to the already-wrapped function. > > Example: > > def decorator_A(func): > def decorated(*args, **kwds): > print "In decorator A" > return func(*args, **kwds) > return decorated > > def decorator_B(func): > def decorated(*args, **kwds): > print "In decorator B" > return func(*args, **kwds) > return decorated > > @decorator_B > @decorator_A > def myfunc(arg): > print "hello", arg > >>>> myfunc('bob') > In decorator B > In decorator A > hello bob > > > Notice that myfunc() only got executed once. -tkc From rosuav at gmail.com Sat Aug 6 08:22:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 13:22:35 +0100 Subject: How to make the program support communication behind NAT device? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 11:20 AM, smith jack wrote: > The subnet behind my router is 192.168.1.0/24, my pc ip is 192.168.1.9, > the server written with python is hosted on 192.168.1.3 on port 1033, > i can connect to this server from my pc > > But cannot connect to this server when outside of this subnet? why? > > I have made port translate on router, that is 10.10.9.2:1033 to 192.168.1.3:1033 This is a networking question, not a Python question. You'll probably get better results on a forum focused on networking. Your router's address, 10.10.9.2, is another RFC 1918 address, just like 192.168.1.3. Are you attempting to connect from elsewhere on the 10.* network, or elsewhere on the internet? If the latter, you probably have to deal with a second level of NAT. The easiest way to test: Can you talk to (eg ping) the router, 10.10.9.2, from the computer that's unable to reach your server? If not, there's your problem. Chris Angelico From vipul.iiith at gmail.com Sat Aug 6 09:34:47 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Sat, 6 Aug 2011 19:04:47 +0530 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: Hi, I did look out for the problem's solution but have been struggling with it ever since. I also asked around on IRC too but haven't quite progressed towards the solution. Here is the link to the swig-generated .cxx file which we need to look into for the answers. Could you please have a look at it and help? It'll be really great. Here's the link: www.geofemengineering.it/data/master_wrap.cxx Thanks and Regards, Vipul Raheja On Sat, Aug 6, 2011 at 4:53 PM, Chris Angelico wrote: > On Sat, Aug 6, 2011 at 12:16 PM, Vipul Raheja > wrote: > > Hi Chris, > > Thanks for the reply. > > However, the error occurs even if I don't do anything, that is, even if I > > simply import the library and exit() after that. > > I created a file a.py whose contents were the following: > > import pyossim > > exit() > > In that case, it may be in your initialization/cleanup code. Check to > see if you return Py_None without increffing it, or keep a reference > to something you don't own and decref it on exit. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sat Aug 6 12:49:23 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 6 Aug 2011 09:49:23 -0700 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: I have little reason to doubt that it's related to referencing counting, but: http://stromberg.dnsalias.org/~dstromberg/checking-early.html On Sat, Aug 6, 2011 at 3:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pyossim > >>> > * Do some stuff * > >>> exit() > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ > > Kindly help. > > Thanks and Regards, > Vipul Raheja > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 6 12:52:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 17:52:01 +0100 Subject: Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 2:34 PM, Vipul Raheja wrote: > Here's the link:?www.geofemengineering.it/data/master_wrap.cxx > Thanks and Regards, > Vipul Raheja Ugh. Unfortunately that file is somewhat lengthy... I hate to say "tl;dr" to people, but... is there any way to simplify that down? Perhaps the best way to proceed would be to make a completely empty SWIG-Python module, with absolutely none of the actual interface code, just initializing itself and cleaning up. If that doesn't crash, add code back in until it crashes on exit again. Alternatively, you may be able to get good results by compiling a debug build of Python, with reference tracking. I've never done that myself, but others on this list will be able to advise. ChrisA From thinke365 at gmail.com Sat Aug 6 13:07:00 2011 From: thinke365 at gmail.com (smith jack) Date: Sun, 7 Aug 2011 01:07:00 +0800 Subject: how to separate a list into two lists? Message-ID: if a list L is composed with tuple consists of two elements, that is L = [(a1, b1), (a2, b2) ... (an, bn)] is there any simple way to divide this list into two separate lists , such that L1 = [a1, a2... an] L2=[b1,b2 ... bn] i do not want to use loop, any methods to make this done? From rosuav at gmail.com Sat Aug 6 13:14:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 18:14:16 +0100 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? One easy way is to use list comprehensions. Technically that'll involve a loop, but the loop is handled efficiently under the hood. L1 = [x[0] for x in L] L2 = [x[1] for x in L] Another way would be to construct a dictionary from your list of tuples and then use the keys() and values() of that dictionary to form your lists (use collections.OrderedDict if the order matters). But I think the list comps are the best way. ChrisA From gherron at islandtraining.com Sat Aug 6 13:15:25 2011 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 06 Aug 2011 10:15:25 -0700 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D76AD.5010608@islandtraining.com> On 08/06/2011 10:07 AM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? List comprehension: L1 = [item[0] for item in L] L2 = [item[1] for item in L] which *is* still a loop. (You are going to have to write *really* arcane code to have no loop.) Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From kabie2011 at gmail.com Sat Aug 6 13:23:53 2011 From: kabie2011 at gmail.com (Kabie) Date: Sun, 7 Aug 2011 01:23:53 +0800 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: No. L1, L2 = zip(*L) 2011/8/7 Chris Angelico > On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: > > if a list L is composed with tuple consists of two elements, that is > > L = [(a1, b1), (a2, b2) ... (an, bn)] > > > > is there any simple way to divide this list into two separate lists , > such that > > L1 = [a1, a2... an] > > L2=[b1,b2 ... bn] > > > > i do not want to use loop, any methods to make this done? > > One easy way is to use list comprehensions. Technically that'll > involve a loop, but the loop is handled efficiently under the hood. > > L1 = [x[0] for x in L] > L2 = [x[1] for x in L] > > Another way would be to construct a dictionary from your list of > tuples and then use the keys() and values() of that dictionary to form > your lists (use collections.OrderedDict if the order matters). But I > think the list comps are the best way. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Sat Aug 6 13:24:10 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 06 Aug 2011 10:24:10 -0700 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On 8/6/2011 10:07 AM smith jack said... > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > >>> L = [('a1', 'b1'), ('a2', 'b2'),('an', 'bn')] >>> zip(*L) [('a1', 'a2', 'an'), ('b1', 'b2', 'bn')] Emile From schesis at gmail.com Sat Aug 6 13:30:49 2011 From: schesis at gmail.com (Zero Piraeus) Date: Sat, 6 Aug 2011 13:30:49 -0400 Subject: Fwd: how to separate a list into two lists? In-Reply-To: References: Message-ID: : > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] How about this? >>> L = [("a1", "b1"), ("a2", "b2"), ("an", "bn")] >>> L1, L2 = zip(*L) >>> L1 ('a1', 'a2', 'an') >>> L2 ('b1', 'b2', 'bn') http://docs.python.org/library/functions.html#zip ?-[]z. From sturlamolden at yahoo.no Sat Aug 6 13:53:12 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 6 Aug 2011 10:53:12 -0700 (PDT) Subject: Complex sort on big files References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: On Aug 1, 5:33?pm, aliman wrote: > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and write > sorted chunks to disk, then use heapq.merge to combine the chunks as > you read them. Or just memory map the file (mmap.mmap) and do an inline .sort() on the bytearray (Python 3.2). With Python 2.7, use e.g. numpy.memmap instead. If the file is large, use 64-bit Python. You don't have to process the file in chunks as the operating system will take care of those details. Sturla From john2james at gmail.com Sat Aug 6 14:04:07 2011 From: john2james at gmail.com (John S James) Date: Sat, 6 Aug 2011 14:04:07 -0400 Subject: Problem installing 3.2.1 on a Linux server Message-ID: My ISP (Bluehost) does not yet support Python version 3, but gave me shell access (no sudo) so that I can install Python 3 myself on my server account (running Apache). So I uploaded the standard Python.org installation package (Python 3.2.1 for Linux) and followed instructions, starting with ./configure. These instructions had worked for me before, to install Python3 on a Linux netbook. But on the server, ./configure starts fine, but later stops with an error. Here is the section of the output where the error occurred: *checking for build directories... done* *configure: creating ./config.status* *config.status: creating Makefile.pre* *config.status: creating Modules/Setup.config* *config.status: error: cannot find input file: `Misc/python.pc.in'* Then the ./configure step stopped. Needless to say, the next step, Make, did not work because there was no Makefile. Others have received the same message, in different contexts. But I haven't found a solution. Two action items: * For the Python community, it would help to fix this problem in the standard Python distribution, if possible. People do want to run Python3 on more servers. I could help by testing the fix to see if the Python3 install now works. * Meanwhile I'd appreciate any advice on a temporary fix (such as changing the configure file, or where to find a package that I could install on the server before installing Python3). All I need for now is the most basic installation, to support CGI and Web forms. John -- John S. James www.RepliCounts.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From only at fleshwound.org Sat Aug 6 14:13:20 2011 From: only at fleshwound.org (bud) Date: 06 Aug 2011 18:13:20 GMT Subject: how to separate a list into two lists? References: Message-ID: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is L = > [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , > such that L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? (x,y) = [ [z[i] for z in L] for i in range(len(L[0]))] x : ['a1', 'a2', 'an'] y : ['b1', 'b2', 'bn'] From only at fleshwound.org Sat Aug 6 14:21:40 2011 From: only at fleshwound.org (bud) Date: 06 Aug 2011 18:21:40 GMT Subject: how to separate a list into two lists? References: Message-ID: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> On Sat, 06 Aug 2011 10:24:10 -0700, Emile van Sebille wrote: > On 8/6/2011 10:07 AM smith jack said... >> if a list L is composed with tuple consists of two elements, that is L >> = [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> > >>> L = [('a1', 'b1'), ('a2', 'b2'),('an', 'bn')] zip(*L) > [('a1', 'a2', 'an'), ('b1', 'b2', 'bn')] > Nice. :) I forgot about zip, still learning Python myself. I'll have to check up on the *L - is that a reference? I know in Perl, you can assign the lhs to a list, below works because there are exactly 2 items on the rhs. Does Python have a catchall, or an ignore the rest? Example, if L was a tuple that had 3 or more items, the below lhs would fail. Is this possible in Python? (X,Y) = zip(*L) X : ('a1', 'a2', 'an') Y : ('b1', 'b2', 'bn') From rosuav at gmail.com Sat Aug 6 14:35:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Aug 2011 19:35:53 +0100 Subject: how to separate a list into two lists? In-Reply-To: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> References: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: On Sat, Aug 6, 2011 at 7:21 PM, bud wrote: > Nice. :) ?I forgot about zip, still learning Python myself. > > I'll have to check up on the *L - is that a reference? > I It expands the list into the arguments. It's the parallel to: def func(*args): which collapses the args into a list. ChrisA From gelonida at gmail.com Sat Aug 6 15:50:40 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:50:40 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: On 08/06/2011 09:38 AM, smith jack wrote: > At first i have a python environment, after using virtualenv test > command, a new environment named test is created, in that directory > have some of the executable commands > such as python.exe, so can i program without the main installation of python? At least under linux virtualenv uses symbolic links. So the answer is simple. virtualenv need the pyton installation it was derived from. only modules, that you will install under virtualenv will be installed in the virtualenv directories. From gelonida at gmail.com Sat Aug 6 15:52:36 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:52:36 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: <4E3D9B84.7080604@gmail.com> On 08/06/2011 09:51 AM, smith jack wrote: > env create by virtualenv will refer to the main env, how did it find > the main env, is there any configuration files, if yes, where is it? > > 2011/8/6 smith jack : >> At first i have a python environment, after using virtualenv test >> command, a new environment named test is created, in that directory >> have some of the executable commands >> such as python.exe, so can i program without the main installation of python? >> Under linux the first lien of virtualenv is #!/usr/bin/python Thus it will be run by python installed under /usr/bin/python From gelonida at gmail.com Sat Aug 6 15:52:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 21:52:46 +0200 Subject: can virtualenv run without the main installation? In-Reply-To: References: Message-ID: On 08/06/2011 09:51 AM, smith jack wrote: > env create by virtualenv will refer to the main env, how did it find > the main env, is there any configuration files, if yes, where is it? > > 2011/8/6 smith jack : >> At first i have a python environment, after using virtualenv test >> command, a new environment named test is created, in that directory >> have some of the executable commands >> such as python.exe, so can i program without the main installation of python? >> Under linux the first lien of virtualenv is #!/usr/bin/python Thus it will be run by python installed under /usr/bin/python From gelonida at gmail.com Sat Aug 6 16:00:46 2011 From: gelonida at gmail.com (Gelonida N) Date: Sat, 06 Aug 2011 22:00:46 +0200 Subject: how to separate a list into two lists? In-Reply-To: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: On 08/06/2011 08:13 PM, bud wrote: > On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote: > >> if a list L is composed with tuple consists of two elements, that is L = >> [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> i do not want to use loop, any methods to make this done? > > > (x,y) = [ [z[i] for z in L] for i in range(len(L[0]))] > > x > : ['a1', 'a2', 'an'] > > y > : ['b1', 'b2', 'bn'] > > Asuming you are not an alias of Jack Smith and assuming you did not see Jack's thread asking the same question: x,y = unzip(*L) From jjposner at codicesoftware.com Sat Aug 6 16:06:04 2011 From: jjposner at codicesoftware.com (John Posner) Date: Sat, 06 Aug 2011 16:06:04 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D9EAC.4090100@codicesoftware.com> On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? > The official Python documentation [1] notes that "zip() in conjunction with the * operator can be used to unzip a list". Ex: >>> L = [ (1,'a'), (2,'b'), (3,'c'), (4,'d') ] >>> zip(*L) [(1, 2, 3, 4), ('a', 'b', 'c', 'd')] HTH, John [1] http://docs.python.org/library/functions.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Sat Aug 6 16:06:41 2011 From: jjposner at optimum.net (John Posner) Date: Sat, 06 Aug 2011 16:06:41 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: <4E3D9ED1.2070500@optimum.net> On 2:59 PM, smith jack wrote: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? > The official Python documentation [1] notes that "zip() in conjunction with the * operator can be used to unzip a list". Ex: >>> L = [ (1,'a'), (2,'b'), (3,'c'), (4,'d') ] >>> zip(*L) [(1, 2, 3, 4), ('a', 'b', 'c', 'd')] HTH, John [1] http://docs.python.org/library/functions.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahan_noor at hotmail.com Sat Aug 6 16:38:35 2011 From: aahan_noor at hotmail.com (aahan noor) Date: Sun, 7 Aug 2011 02:38:35 +0600 Subject: help In-Reply-To: References: Message-ID: Hi all: i am new to python. i am working with lm-sensors to monitor the cpu fan speed, temperature and voltages. i have to use python code to get integer value of cpu temperature from lm sensors. please help me how i do that i shall be gratefullAahan -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Sat Aug 6 16:53:42 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 6 Aug 2011 16:53:42 -0400 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 1:23 PM, Kabie wrote: > No. > L1, L2 = zip(*L) Not quite. That makes L1 & L2 tuples. L1, L2 = zip(*L) L1 = list(L1) L2 = list(L2) ??? From kw at codebykevin.com Sat Aug 6 17:33:13 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 06 Aug 2011 17:33:13 -0400 Subject: DDE vs. COM for Python Windows apps Message-ID: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> I'm developing a Windows version of a Mac/Python app and I'd like to add a scripting interface to it. On the Mac I do this via Apple Events--this is an Apple technology that allows applications to drive other applications and query them for data using a message-passing interface. Each application defines a suite of commands and/or data objects that it will invoke, depending on which Apple Event is passed to it; these commands and data objects are most commonly documented in an AppleScript API dictionary, though there are other ways to send Apple Events as well. On Windows, I've found two separate mechanisms that seem to offer what I'm looking for: Dynamic Data Exchange (DDE) and Component Object Model (COM). As I understand it, DDE allows data transfer and command-automation between applications via a lightweight message-passing interface. COM seems to offer similar functionality, with a much more complex learning curve. The main complaint I've seen about DDE is that it is very old. The main complaint I've seen about COM is that it is very complex and very brittle. Based on my research, it seems that DDE might be sufficient for my needs--I want other applications to be able to send commands to my application and have data returned to them. But I'd like to have a better understanding of the merits of each. Can someone summarize the advantages that COM might have over DDE, in a Pythonic context? --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From nad at acm.org Sat Aug 6 18:09:39 2011 From: nad at acm.org (Ned Deily) Date: Sat, 06 Aug 2011 15:09:39 -0700 Subject: Problem installing 3.2.1 on a Linux server References: Message-ID: In article , John S James wrote: > My ISP (Bluehost) does not yet support Python version 3, but gave me shell > access (no sudo) so that I can install Python 3 myself on my server account > (running Apache). So I uploaded the standard Python.org installation package > (Python 3.2.1 for Linux) and followed instructions, starting with > ./configure. These instructions had worked for me before, to install Python3 > on a Linux netbook. > > But on the server, ./configure starts fine, but later stops with an error. > Here is the section of the output where the error occurred: > *checking for build directories... done* > *configure: creating ./config.status* > *config.status: creating Makefile.pre* > *config.status: creating Modules/Setup.config* > *config.status: error: cannot find input file: `Misc/python.pc.in'* > > Then the ./configure step stopped. Needless to say, the next step, Make, did > not work because there was no Makefile. Works for me on a current Debian system. Are you downloading the source from python.org? Did you verify that the file is created by tar? $ curl -O http://www.python.org/ftp/python/3.2.1/Python-3.2.1.tgz $ tar xzf Python-3.2.1.tgz $ cd ./Python-3.2.1/ $ ls -l Misc/python.pc.in -rw-r----- 1 nad nad 293 Jul 8 23:58 Misc/python.pc.in $ ./configure [...] configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating Misc/python.pc config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating Makefile If you are still having problems, chances are you have an out-of-date or incomplete version of GNU autotools which contains the macros and tools that are used by the ./configure script. On my system: $ autoconf --version autoconf (GNU Autoconf) 2.68 -- Ned Deily, nad at acm.org From drsalists at gmail.com Sat Aug 6 18:42:03 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 6 Aug 2011 15:42:03 -0700 Subject: help In-Reply-To: References: Message-ID: I'll be a lot easier for you to get help, if you take a shot at it yourself first, then post a link to what you have here, along with any error messages you may be getting. On Sat, Aug 6, 2011 at 1:38 PM, aahan noor wrote: > > Hi all: > i am new to python. i am working with lm-sensors to monitor the cpu fan speed, temperature and voltages. i have to use python code to get integer value of cpu temperature from lm sensors. please help me how i do that > i shall be gratefull > > Aahan > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 20:07:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:07:23 +1000 Subject: how to separate a list into two lists? References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > Asuming you [Bud] are not an alias of Jack Smith and assuming you did > not see Jack's thread asking the same question: That's a strange thing to say when Bud *answered* Jack's question. > x,y = unzip(*L) What's unzip? It doesn't exist in any version of Python between 1.5 and 3.3 that I have. -- Steven From rosuav at gmail.com Sat Aug 6 20:08:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 01:08:41 +0100 Subject: DDE vs. COM for Python Windows apps In-Reply-To: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> References: <858c0$4e3db30d$4275d90a$1905@FUSE.NET> Message-ID: On Sat, Aug 6, 2011 at 10:33 PM, Kevin Walzer wrote: > The main complaint I've seen about DDE is that it is very old. I can't speak about COM, as I have not used it to any great extent, but DDE has a number of things going for it. Firstly though, "old" does not need to be a criticism. How many network administrators use ping(1) on a daily basis? Yet that utility was written in the early 1980s - in computing terms, that's pretty old. DDE is implemented as window messages. This means it works with anything that has a window; it might not be easy to send DDE requests from a console application, and it would be quite tricky to receive them in a console. It also means that the system can hang until the request is dealt with. However, it is extremely simple and easy. There are other options. The best thing to do would be to set down your actual requirements, and then see what technology best fits them. For instance: * Do you need programs running on other computers to be able to send/receive messages, or just on the local computer (ie, do you need network support)? * Do you need asynchronous requests/responses? * Do you need to support multiple simultaneous requests? * Conversely, must you explicitly forbid requests when another app is using the API? * Do you need to move significant amounts of data around, or could it all be done with simple 32-bit integers? If you need networking, far and away the best option is TCP sockets. But your post suggests that something light-weight is what you're after. If you don't care about return values, or alternatively if you can return an instant response, it might be easiest to simply use window messages. You pass in a message number and two parameter integers, and you get back a returned integer. That's enough for a lot of things, but you have to be able to return very quickly. You may wish to google for 'Windows IPC'; there's quite a few options available. Deciding which one is best for your situation is partly art and partly science... and partly faith in the future. I recommend choosing the one that looks like the coolest and most fun to play with; that way, even if the project fails, it's not been a complete waste. ChrisA From steve+comp.lang.python at pearwood.info Sat Aug 6 20:13:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:13:02 +1000 Subject: how to separate a list into two lists? References: <4e3d8634$0$5872$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3dd88f$0$29994$c3e8da3$5496439d@news.astraweb.com> bud wrote: > I'll have to check up on the *L - is that a reference? No, as Chris already answered, unary * is used for packing and unpacking positional arguments to functions; unary ** is similarly used for collecting keyword arguments. > I know in Perl, you can assign the lhs to a list, > below works because there are exactly 2 items on the rhs. > Does Python have a catchall, or an ignore the rest? Yes. In Python 3, you can do this: >>> a, b, *t, c = (1, 2, 3, 4, 5, 6, 7, 8, 9) >>> t [3, 4, 5, 6, 7, 8] (but not in Python 2) -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 6 20:27:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 10:27:24 +1000 Subject: how to separate a list into two lists? References: Message-ID: <4e3ddbed$0$29994$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sat, Aug 6, 2011 at 6:07 PM, smith jack wrote: >> if a list L is composed with tuple consists of two elements, that is >> L = [(a1, b1), (a2, b2) ... (an, bn)] >> >> is there any simple way to divide this list into two separate lists , >> such that L1 = [a1, a2... an] >> L2=[b1,b2 ... bn] >> >> i do not want to use loop, any methods to make this done? > > One easy way is to use list comprehensions. Technically that'll > involve a loop, but the loop is handled efficiently under the hood. > > L1 = [x[0] for x in L] > L2 = [x[1] for x in L] I hardly think that's "under the hood". It's right there: for x in L. How much more explicitly a loop do you want? To the original poster, Jack: if you don't loop over the list, how do you expect to operate on each and every item? Whether you write: L1, L2 = [], [] for a,b in L: L1.append(a) L2.append(b) or L1, L2 = zip(*L) or L1 = [x[0] for x in L] L2 = [x[1] for x in L] you are still looping over the list. In the second case, the one-liner using zip, you loop *twice*: once to unpack L into separate arguments, the second time to zip them up. And the result you end up with are tuples, not lists, so if you need lists, you have to loop *again*, over each tuple, converting them to lists. Here's one way to do that while keeping it a one-liner: L1, L2 = map(list, zip(*L)) If L is small, it really doesn't matter what you do, they will all be more or less as efficient. Write whatever you feel looks best. But if L is huge, then the difference between a four-liner that iterates over the list once, and one-liner that iterates over it four times, may be considerable. -- Steven From timr at probo.com Sat Aug 6 20:58:30 2011 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Aug 2011 17:58:30 -0700 Subject: how to separate a list into two lists? References: Message-ID: smith jack wrote: > >if a list L is composed with tuple consists of two elements, that is >L = [(a1, b1), (a2, b2) ... (an, bn)] > >is there any simple way to divide this list into two separate lists , such that >L1 = [a1, a2... an] >L2=[b1,b2 ... bn] > >i do not want to use loop, any methods to make this done? There will always be a loop. It might not be written with a "for" statement, but there will always be a loop. L1 = [k[0] for k in L] L2 = [k[1] for k in L] I did momentarily consider the following slimy solution: L1 = dict(L).keys() L2 = dict(L).values() but that reorders the tuples. They still correspond, but in a different order. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Sat Aug 6 21:05:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 02:05:14 +0100 Subject: how to separate a list into two lists? In-Reply-To: References: Message-ID: On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts wrote: > I did momentarily consider the following slimy solution: > ?L1 = dict(L).keys() > ?L2 = dict(L).values() > but that reorders the tuples. ?They still correspond, but in a different > order. > Which can be overcome with collections.OrderedDict. But what's dict(L) going to do? It's going to loop over L, more than once in fact. I guess the real question is: Why do you wish to avoid a loop? ChrisA From bmanchester at azteknetworks.com Sat Aug 6 21:32:19 2011 From: bmanchester at azteknetworks.com (Bart Manchester) Date: Sat, 6 Aug 2011 20:32:19 -0500 Subject: help with DLL or path issue trying to use cx_Freeze Message-ID: Im trying to use the most basic of cx_Freeze in a dos window and I receive the following error (see below). I suspect I have some kind of path issue, but am at a loss as to how to proceed. I am trying to execute this in the Scripts directory and have both the cxfreeze bat and also the .py file there. C:\Python32\Scripts>cxfreeze general-tl1-work.py Traceback (most recent call last): File "C:\Python32\Scripts\cxfreeze", line 5, in main() File "C:\Python32\lib\site-packages\cx_Freeze\main.py", line 187, in main silent = options.silent) File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 84, in __init_ _ for n in self._GetDefaultBinPathExcludes() + binPathExcludes] File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 205, in _GetDe faultBinPathExcludes import cx_Freeze.util ImportError: DLL load failed: %1 is not a valid Win32 application. C:\Python32\Scripts> -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 6 21:35:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 11:35:23 +1000 Subject: how to separate a list into two lists? References: Message-ID: <4e3debdb$0$29972$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts wrote: >> I did momentarily consider the following slimy solution: >> L1 = dict(L).keys() >> L2 = dict(L).values() >> but that reorders the tuples. ?They still correspond, but in a different >> order. >> > > Which can be overcome with collections.OrderedDict. But what's dict(L) > going to do? It's going to loop over L, more than once in fact. > > I guess the real question is: Why do you wish to avoid a loop? I think what the Original Poster actually meant was he wanted to avoid *writing out an explicit loop*. That is, he wants a one-liner, so he doesn't have to think about the details of iterating over the list. When we write: a = sum(a_sequence) aren't we doing the same thing really? -- Steven From ericsnowcurrently at gmail.com Sat Aug 6 23:06:51 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 6 Aug 2011 21:06:51 -0600 Subject: how to dynamically generate __name__ for an object? Message-ID: Thought I knew how to provide a dynamic __name__ on instances of a class. My first try was to use a non-data descriptor: # module base.py class _NameProxy(object): def __init__(self, oldname): self.oldname = oldname def __get__(self, obj, cls): if obj is None: return self.oldname if "__name__" not in obj.__dict__: return str(obj.__context__) return obj.__name__ class _BaseMeta(type): def __init__(cls, name, bases, namespace): cls.__name__ = _NameProxy(name) class Base(object): __metaclass__ = _BaseMeta $ python _base.py Traceback (most recent call last): ... File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ cls.__name__ = _NameProxy(name) TypeError: Error when calling the metaclass bases can only assign string to Base.__name__, not '_NameProxy' Needless to say I was surprised. After looking in typeobject.c, I believe that __name__ must be a string where classes are concerned[1]. So if I want all my instances to have a __name__ attribute, and for it to be dynamically provided if it isn't set on the instance, what are my options? Or maybe I did something wrong and it should work as I expected? -eric [1] http://hg.python.org/cpython/file/default/Objects/typeobject.c#l244 From steve+comp.lang.python at pearwood.info Sun Aug 7 00:47:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 07 Aug 2011 14:47:42 +1000 Subject: how to dynamically generate __name__ for an object? References: Message-ID: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > Thought I knew how to provide a dynamic __name__ on instances of a > class. My first try was to use a non-data descriptor: Perhaps you should explain what you are trying to do. If you want to give instances their own name, why not just give them an instance attribute "name"? Double-leading-and-trailing-underscore attributes are reserved for Python, and have special semantics. -- Steven From no.email at nospam.invalid Sun Aug 7 01:29:44 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Aug 2011 22:29:44 -0700 Subject: how to separate a list into two lists? References: Message-ID: <7xd3ghokl3.fsf@ruckus.brouhaha.com> smith jack writes: > if a list L is composed with tuple consists of two elements, that is > L = [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , such that > L1 = [a1, a2... an] > L2=[b1,b2 ... bn] > > i do not want to use loop, any methods to make this done? That is called unzipping and there is a sneaky idiom for it: L1,L2 = zip(*L) Your homework assignment is figuring out how that works ;-). From zak.mc.kraken at libero.it Sun Aug 7 01:54:08 2011 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 07 Aug 2011 07:54:08 +0200 Subject: how to separate a list into two lists? References: Message-ID: David Robinow wrote: > On Sat, Aug 6, 2011 at 1:23 PM, Kabie wrote: >> No. >> L1, L2 = zip(*L) > > Not quite. That makes L1 & L2 tuples. > > L1, L2 = zip(*L) > L1 = list(L1) > L2 = list(L2) > ??? L1, L2 = map(list, zip(*L)) -- By ZeD From ericsnowcurrently at gmail.com Sun Aug 7 04:05:46 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sun, 7 Aug 2011 02:05:46 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 6, 2011 at 10:47 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> Thought I knew how to provide a dynamic __name__ on instances of a >> class. ?My first try was to use a non-data descriptor: > > Perhaps you should explain what you are trying to do. If you want to give > instances their own name, why not just give them an instance > attribute "name"? Double-leading-and-trailing-underscore attributes are > reserved for Python, and have special semantics. Again useful information failed to make it from my head to the keyboard. :) Currently I am looking at objects, regardless of their types, and keying off their name. If it is a module, class, or function object, the name should be stored in __name__ already. If it is an instance of the Base class I demonstrated, I would like to maintain that convention. However, you may have a good point. In other code I can simply check for the name attribute I choose for my objects and also check for __name__. I suppose I just liked the idea of having a single attribute to check. -eric > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From sharanya9030 at gmail.com Sun Aug 7 06:53:59 2011 From: sharanya9030 at gmail.com (sharu) Date: Sun, 7 Aug 2011 03:53:59 -0700 (PDT) Subject: HOT ACTRESS PHOTOS AND VIDEOS Message-ID: <68274dc1-370c-46f6-bd9b-fbe9f8f6b4ef@d8g2000prf.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From lukius at gmail.com Sun Aug 7 08:56:16 2011 From: lukius at gmail.com (Lucio Santi) Date: Sun, 7 Aug 2011 09:56:16 -0300 Subject: PEP 372 -- Adding an ordered directory to collections In-Reply-To: <8ad2ea1e-e336-4236-81c3-7a4959050696@e53g2000hsa.googlegroups.com> References: <5c6cdecc-624f-4e1f-b4d5-88656e182d02@a1g2000hsb.googlegroups.com> <1ea1731d-9de9-4e73-9c08-e9f5572b9fd6@t54g2000hsg.googlegroups.com> <1a8797c6-a165-49b1-82de-94a6054cf856@z16g2000prn.googlegroups.com> <8ad2ea1e-e336-4236-81c3-7a4959050696@e53g2000hsa.googlegroups.com> Message-ID: Hi all, I'm a first-time writer here, so excuse me if I say something inappropriate or such. Last week, I was reviewing some Python 2.7 modules when I came across the OrderedDict data structure. After seeing its official implementation and also after reading through the corresponding PEP, I figured out another way of implementing it. As I recently saw here, the idea is similar to the one proposed by bearophile, but nevertheless I think it is more efficient since there is no need to perform lookups multiple times. The idea is to embed the doubly-linked list of items in the dictionary itself, and extend the values inserted by providing a node as a 4-tuple . Of course, references to the first and last nodes must be kept too, in addition to the dictionary. After implementing this approach, I experimented a little bit and compared both versions (i.e., the official one that uses an extra dictionary and mine) by measuring the running times of some basic operations. I verified that it indeed outperforms the existing implementation. I made up a recipe with the code and several comments, including more details about the experimentation mentioned above: http://code.activestate.com/recipes/577826-yet-another-ordered-dictionary/ Comments will be surely appreciated! Lucio -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Sun Aug 7 11:35:00 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 8 Aug 2011 01:35:00 +1000 Subject: Restricted attribute writing Message-ID: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is a modulo remainder. I need to be able to write to it like a normal list, but want to ensure it is only possible to do so without changing that format. Below is a what I eventually came up with; a container class called OrderElement for the inner lists, and subclass of list called Order for the main attribute, which is a property of the main class, simplified below as SeqSim. It works, but seems like a hell of a lot of code for a simple idea. I'm interested in ideas for simpler solutions, and general advice on how to do this kind of thing in a straightforward way. class OrderElement(): """Container class which can only hold two integers the first of which is a modulo of the 'length' arg""" def __init__(self, lis, length): self.__data = [None, None] self.__length=length self[:] = lis def __setitem__(self, index, item): if isinstance(index, slice): inds = range(*index.indices(2)) for k, v in enumerate(item): self[inds[k]] = v elif isinstance(item, int): if index == 0: item %= self.__length self.__data[index] = item else: raise TypeError("OrderElement takes two integers") def __getitem__(self, index): return self.__data[index] class Order(list): """Can only contain OrderElements""" def __init__(self, lis, length): self.__length = length self[:] = lis def __setitem__(self, index, item): if isinstance(index, slice): item = [i if isinstance(i, OrderElement) else OrderElement(i, self.__length) for i in item] elif not isinstance(item, OrderElement): item = OrderElement(item, self.__length) list.__setitem__(self, index, item) def __getitem__(self, index): """Ensure slices are of the same class""" if isinstance(index, slice): return self.__class__(list.__getitem__(self, index), self.__length) return list.__getitem__(self, index) class SeqSim(): """Just the relevant bits of the main class""" def __init__(self, lis, length): self.__order = Order(lis, length) self.length = length @property def order(self): return self.__order @order.setter def order(self, lis): if not isinstance(lis, Order): lis = Order(lis, self.length) self.__order = lis -- John O'Hagan From roy at panix.com Sun Aug 7 12:07:46 2011 From: roy at panix.com (Roy Smith) Date: Sun, 07 Aug 2011 12:07:46 -0400 Subject: Restricted attribute writing References: Message-ID: In article , John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such > that they retain the characteristics the class requires. Sounds like you're trying to do http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad thing. But, I think a more pythonic way to implement this would be to verify behaviors, not types. I would start by writing a assert_invarient() method which validates the object. I'm guessing all you really need is that you can index [0] and [1] and get ints, so test for that. Something like: def assert_invarient(self): try: assert isinstance(data[0], int) assert isinstance(data[1], int) except: raise ValueError Then, call this from inside your __init__(), __setitem__(), etc. From steve+comp.lang.python at pearwood.info Sun Aug 7 12:31:03 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 02:31:03 +1000 Subject: Restricted attribute writing References: Message-ID: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > John O'Hagan wrote: > >> I'm looking for good ways to ensure that attributes are only writable >> such that they retain the characteristics the class requires. > > Sounds like you're trying to do > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad > thing. But, I think a more pythonic way to implement this would be to > verify behaviors, not types. > > I would start by writing a assert_invarient() method which validates the > object. I'm guessing all you really need is that you can index [0] and > [1] and get ints, so test for that. Something like: > > def assert_invarient(self): > try: > assert isinstance(data[0], int) > assert isinstance(data[1], int) > except: > raise ValueError Don't do that. assert is for testing program logic, not verifying data. The problem with assert is that the user can turn all assertions off, simply by launching Python with the -O switch. Your verification code then becomes: def assert_invarient(self): try: pass except: raise ValueError which is useless. When should you use an assertion? If you've ever written code like this: if condition: do_something() else: # This should never happen. But you know what they say: code that # can't happen, does! raise RuntimeError('condition unexpectedly false') that's a prime candidate for turning into an assertion: assert condition, 'condition unexpectedly false' do_something() -- Steven From rafadurancastaneda at gmail.com Sun Aug 7 12:53:11 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 7 Aug 2011 18:53:11 +0200 Subject: Restricted attribute writing In-Reply-To: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: I think you might use a tuple instead of a list for OrderElement, that would make much easier your code: class OrderElement(tuple): def __new__(cls, x, y): if not isinstance(x, int) or not isinstance(y, int): raise TypeError("Order element must receives two integers") return tuple.__new__(cls, (x, y)) class Order(list): def __setitem__(self, item): assert isinstance(item, OrderElement) super(Order, self).__setitem__(item) I didn't check your module condition since it isn't quite clear to me, but you could add a second condition two Order class. 2011/8/7 Steven D'Aprano > Roy Smith wrote: > > > In article , > > John O'Hagan wrote: > > > >> I'm looking for good ways to ensure that attributes are only writable > >> such that they retain the characteristics the class requires. > > > > Sounds like you're trying to do > > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad > > thing. But, I think a more pythonic way to implement this would be to > > verify behaviors, not types. > > > > I would start by writing a assert_invarient() method which validates the > > object. I'm guessing all you really need is that you can index [0] and > > [1] and get ints, so test for that. Something like: > > > > def assert_invarient(self): > > try: > > assert isinstance(data[0], int) > > assert isinstance(data[1], int) > > except: > > raise ValueError > > Don't do that. assert is for testing program logic, not verifying data. The > problem with assert is that the user can turn all assertions off, simply by > launching Python with the -O switch. Your verification code then becomes: > > def assert_invarient(self): > try: > pass > except: > raise ValueError > > which is useless. > > When should you use an assertion? If you've ever written code like this: > > if condition: > do_something() > else: > # This should never happen. But you know what they say: code that > # can't happen, does! > raise RuntimeError('condition unexpectedly false') > > > that's a prime candidate for turning into an assertion: > > > assert condition, 'condition unexpectedly false' > do_something() > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafadurancastaneda at gmail.com Sun Aug 7 12:56:04 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 7 Aug 2011 18:56:04 +0200 Subject: Restricted attribute writing In-Reply-To: References: <4e3ebdc8$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: The assert on Order should be an if ... raise, like OrderElement, sorry for the mistake and repost El 7 de agosto de 2011 18:53, Rafael Dur?n Casta?eda < rafadurancastaneda at gmail.com> escribi?: > I think you might use a tuple instead of a list for OrderElement, that > would make much easier your code: > > class > OrderElement(tuple): > > def __new__(cls, x, y): > if not isinstance(x, int) or not isinstance(y, int): > raise TypeError("Order element must receives two > integers") > > return tuple.__new__(cls, (x, y)) > > > class Order(list): > def __setitem__(self, item): > assert isinstance(item, OrderElement) > super(Order, self).__setitem__(item) > > > I didn't check your module condition since it isn't quite clear to me, but > you could add a second condition two Order class. > > > 2011/8/7 Steven D'Aprano > >> Roy Smith wrote: >> >> > In article , >> > John O'Hagan wrote: >> > >> >> I'm looking for good ways to ensure that attributes are only writable >> >> such that they retain the characteristics the class requires. >> > >> > Sounds like you're trying to do >> > http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad >> > thing. But, I think a more pythonic way to implement this would be to >> > verify behaviors, not types. >> > >> > I would start by writing a assert_invarient() method which validates the >> > object. I'm guessing all you really need is that you can index [0] and >> > [1] and get ints, so test for that. Something like: >> > >> > def assert_invarient(self): >> > try: >> > assert isinstance(data[0], int) >> > assert isinstance(data[1], int) >> > except: >> > raise ValueError >> >> Don't do that. assert is for testing program logic, not verifying data. >> The >> problem with assert is that the user can turn all assertions off, simply >> by >> launching Python with the -O switch. Your verification code then becomes: >> >> def assert_invarient(self): >> try: >> pass >> except: >> raise ValueError >> >> which is useless. >> >> When should you use an assertion? If you've ever written code like this: >> >> if condition: >> do_something() >> else: >> # This should never happen. But you know what they say: code that >> # can't happen, does! >> raise RuntimeError('condition unexpectedly false') >> >> >> that's a prime candidate for turning into an assertion: >> >> >> assert condition, 'condition unexpectedly false' >> do_something() >> >> >> >> -- >> Steven >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From redmumba at gmail.com Sun Aug 7 13:04:57 2011 From: redmumba at gmail.com (Redmumba) Date: Sun, 7 Aug 2011 13:04:57 -0400 Subject: PyPI Situation? Message-ID: I've been running into a lot of issues with the PyPI architecture, and I'm aware that there's some work going on behind the scenes, especially with making PyPI accessible from the a cloud-like architecture. However, I setup a Python mirror (using the pep381client) for our company, and the issue is--as always--with external packages, which usually makes the mirror useless (lxml is famously slow!). Has there been any work on improving the repository architecture, i.e., storing metadata, resolving dependencies prior to download? And is there anyway to get involved? Or should I look into creating my own and proposing a PEP? I don't want to create "yet another PyPI" if I can avoid it, so I'd prefer to contribute to an existing one if there's one available... Thanks, Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Aug 7 13:07:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 03:07:30 +1000 Subject: Restricted attribute writing References: Message-ID: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such > that they retain the characteristics the class requires. That's what properties are for. > My particular case is a class attribute which is initialised as a list of > lists of two integers, the first of which is a modulo remainder. I need to > be able to write to it like a normal list, but want to ensure it is only > possible to do so without changing that format. Then you have two problems to solve. First, you need a special type of list that only holds exactly two integers. Your main class can't control what happens inside the list, so you need the list to validate itself. Secondly, you should use a property in your main class to ensure that the attribute you want to be a special list-of-two-ints can't (easily) be changed to something else. > Below is a what I eventually came up with; a container class called > OrderElement for the inner lists, and subclass of list called Order for > the main attribute, which is a property of the main class, simplified > below as SeqSim. It works, but seems like a hell of a lot of code for a > simple idea. And why should this be surprising? It might be a simple *idea*, but the concrete execution of that idea is anything but simple. "Hey, let's fly to Mars!" is a simple idea too. Nevertheless, it does appear that your solution below is overly complicated. Two helper classes just to have a thing that holds two ints... does it have to be a list? Seems that if you're limited to exactly two items, a list is pretty useless, since you can't insert, append, pop or delete items. I'd take this approach instead: # Untested. class ThingWithTwoIntegers(object): def __init__(self, a, b): self.a = a self.b = b def __getitem__(self, index): # Slicing not supported, because I'm lazy. if index < 0: index += 2 if index == 0: return self.a elif index == 1: return self.b else: raise IndexError def __setitem__(self, index, value): # Slicing not supported, because I'm lazy. if index < 0: index += 2 if index == 0: self.a = value elif index == 1: self.b = value else: raise IndexError def _geta(self): return self._a def _seta(self, value): if isinstance(value, (int, long)): # drop long if using Python 3 self._a = value else: raise TypeError('expected an int but got %s' % type(value)) a = property(_geta, _seta) # and the same for b: _getb, _setb, making the obvious changes There's a little bit of code duplication there, but it's 3am here and I'm tired and besides, if I do all your work what would you do? *wink* This gives you an object that holds two integers. You can access them either by attribute name, "a" and "b", or by index, 0 and 1: instance = ThingWithTwoIntegers(23, 42) instance[0] => 23 instance.b => 42 Obviously this isn't a full blown list, but if you don't need all the list-like behaviour (sorting, inserting, deleting items, etc.) why support it? -- Steven From gelonida at gmail.com Sun Aug 7 13:11:32 2011 From: gelonida at gmail.com (Gelonida N) Date: Sun, 07 Aug 2011 19:11:32 +0200 Subject: how to separate a list into two lists? In-Reply-To: <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> <4e3dd73c$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/07/2011 02:07 AM, Steven D'Aprano wrote: > Gelonida N wrote: > >> Asuming you [Bud] are not an alias of Jack Smith and assuming you did >> not see Jack's thread asking the same question: > > That's a strange thing to say when Bud *answered* Jack's question. > > >> x,y = unzip(*L) > > What's unzip? It doesn't exist in any version of Python between 1.5 and 3.3 > that I have. > Arg typo: I meant of course zip > > From jhaberman at gmail.com Sun Aug 7 14:11:37 2011 From: jhaberman at gmail.com (Josh Haberman) Date: Sun, 7 Aug 2011 11:11:37 -0700 (PDT) Subject: import hooks (PEP 302) broken in Python >=2.5? Message-ID: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> When reading about import hooks, I came across a blog entry comment that says: One additional thing to note about ihooks is that it's somewhat seriously broken on Python 2.5 and newer and there seems to be little or no interest in fixing it. It's probably worth *always* avoiding when writing new code. --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 Does anyone know what this is referring to? Should I be wary of relying on import hooks? Josh From rosuav at gmail.com Sun Aug 7 14:21:15 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Aug 2011 19:21:15 +0100 Subject: Restricted attribute writing In-Reply-To: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 7, 2011 at 6:07 PM, Steven D'Aprano wrote: > class ThingWithTwoIntegers(object): > I'm not a lisp expert, but this might well be called a cons cell. Or a "pair". ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 7 14:41:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 04:41:20 +1000 Subject: import hooks (PEP 302) broken in Python >=2.5? References: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> Message-ID: <4e3edc51$0$29998$c3e8da3$5496439d@news.astraweb.com> Josh Haberman wrote: > When reading about import hooks, I came across a blog entry comment > that says: > > One additional thing to note about ihooks is that it's > somewhat seriously broken on Python 2.5 and newer and there > seems to be little or no interest in fixing it. It's > probably worth *always* avoiding when writing new code. > > --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 > > Does anyone know what this is referring to? Should I be wary of > relying on import hooks? Are you using import hooks? What version(s) of Python are you using? Depending on whether you are asking out of curiosity, or because you have code that uses import hooks and you're about to migrate from Python 2.3 to 3.1, the answers may be different. -- Steven From bmanchester at azteknetworks.com Sun Aug 7 14:54:07 2011 From: bmanchester at azteknetworks.com (Bart Manchester) Date: Sun, 7 Aug 2011 13:54:07 -0500 Subject: help with DLL or path issue trying to use cx_Freeze Message-ID: I suspect this may have gone out before I was a member, and thus potentially not be received - apologies if this did go out please ignore this second attempt if it did. --------------- Im trying to use the most basic of cx_Freeze in a dos window and I receive the following error (see below). I suspect I have some kind of path issue, but am at a loss as to how to proceed. I am trying to execute this in the Scripts directory and have both the cxfreeze bat and also the .py file there. C:\Python32\Scripts>cxfreeze general-tl1-work.py Traceback (most recent call last): File "C:\Python32\Scripts\cxfreeze", line 5, in main() File "C:\Python32\lib\site-packages\cx_Freeze\main.py", line 187, in main silent = options.silent) File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 84, in __init_ _ for n in self._GetDefaultBinPathExcludes() + binPathExcludes] File "C:\Python32\lib\site-packages\cx_Freeze\freezer.py", line 205, in _GetDe faultBinPathExcludes import cx_Freeze.util ImportError: DLL load failed: %1 is not a valid Win32 application. C:\Python32\Scripts> -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Sun Aug 7 16:52:48 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Aug 2011 20:52:48 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > Duncan Booth wrote: > >> The descriptor protocol only works when a value is being accessed or set >> on an instance and there is no instance attribute of that name so the >> value is fetched from the underlying class. > > Unlike normal class attributes a descriptor is not shaded by an instance > attribute: > >>>> class A(object): > ... def set_x(self, value): self.__dict__["x"] = value/2.0 > ... def get_x(self): return self.__dict__["x"] * 2.0 > ... x = property(get_x, set_x) > ... >>>> a = A() >>>> a.x = 42 >>>> a.__dict__["x"] > 21.0 >>>> a.x > 42.0 >>>> A.x = "something completely different" >>>> a.x > 21.0 > True, and in fact that's why your suggestion of using two descriptors, one at each level works. Thanks for pointing out my mistake. -- Duncan Booth http://kupuguy.blogspot.com From nad at acm.org Sun Aug 7 18:01:52 2011 From: nad at acm.org (Ned Deily) Date: Sun, 07 Aug 2011 15:01:52 -0700 Subject: PyPI Situation? References: Message-ID: In article , Redmumba wrote: > I've been running into a lot of issues with the PyPI architecture, and I'm > aware that there's some work going on behind the scenes, especially with > making PyPI accessible from the a cloud-like architecture. PyPI is discussed on the Python Catalog SIG mailing list. You should take a look at the archives there and jump into the discussions: http://mail.python.org/mailman/listinfo/catalog-sig and mirrored in various formats here: http://dir.gmane.org/gmane.comp.python.catalog -- Ned Deily, nad at acm.org From ryan at rfk.id.au Sun Aug 7 18:03:22 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 08 Aug 2011 08:03:22 +1000 Subject: import hooks (PEP 302) broken in Python >=2.5? In-Reply-To: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> References: <2632c52c-0978-44a7-a4fb-af75a2a6e30b@e2g2000prj.googlegroups.com> Message-ID: <1312754602.2068.1.camel@rambutan> On Sun, 2011-08-07 at 11:11 -0700, Josh Haberman wrote: > When reading about import hooks, I came across a blog entry comment > that says: > > One additional thing to note about ihooks is that it's > somewhat seriously broken on Python 2.5 and newer and there > seems to be little or no interest in fixing it. It's > probably worth *always* avoiding when writing new code. > > --http://orestis.gr/blog/2008/12/20/python-import-hooks/#c264 > > Does anyone know what this is referring to? Should I be wary of > relying on import hooks? I believe that comment is referring specifically to "ihooks" the stdlib module, not "import hooks" the general concept as defined in PEP302. The former pre-dates the later. I use custom PEP302 loaders all the time and they work fine in at least 2.6, 2.7 and 3.2. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From jdoe at usenetlove.invalid Sun Aug 7 20:04:55 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 08 Aug 2011 00:04:55 GMT Subject: Wait for a keypress before continuing? Message-ID: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> My program does not need a prompt, it just needs to wait for any key to be pressed before it continues. This is in Windows. char=0 while not char: char=msvcrt.getch() That doesn't delay anything here. while 1: char=msvcrt.getch() break That appears to put my program into an endless loop. while msvcrt.kbhit(): sleep(4) msvcrt.getch() msvcrt.getch() How can that not delay anything and then instantly get past the getch()? char=0 while msvcrt.kbhit(): sleep(4) msvcrt.getch() while not char: char=msvcrt.getch() That doesn't delay anything. Something seriously wrong with my system? Thanks. From jura.grozni at gmail.com Sun Aug 7 20:26:01 2011 From: jura.grozni at gmail.com (azrael) Date: Sun, 7 Aug 2011 17:26:01 -0700 (PDT) Subject: WxPython and TK Message-ID: Today I found a quote from Guido. wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. -- Guido van Rossum OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. From steve+comp.lang.python at pearwood.info Sun Aug 7 20:27:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 10:27:59 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> John Doe wrote: > My program does not need a prompt, it just needs to wait for any > key to be pressed before it continues. This is in Windows. > > char=0 > while not char: > char=msvcrt.getch() > > That doesn't delay anything here. Works perfectly for me. You don't need the while loop, since getch blocks until a key is pressed. Rather than making arbitrary changes to the code, try printing char after the loop exits and see what it contains. That may give you a hint as to what is going on. Also, are you using an IDE? If so, it could very well be interfering with the keyboard buffer, for its own purposes. E.g. in IDLE 2.6.2, if I call getch it *immediately* returns without blocking: >>> msvcrt.getch() '\xff' -- Steven From thinke365 at gmail.com Sun Aug 7 20:45:23 2011 From: thinke365 at gmail.com (smith jack) Date: Mon, 8 Aug 2011 08:45:23 +0800 Subject: module import error, what's wrong? Message-ID: from common.URLTool import URLTool tool = URLTool() Traceback (most recent call last): File "E:\workspace\url\test.py", line 7, in ? from common.URLTool import URLTool ImportError: No module named common.URLTool URLTools is a class write by myself, it works well ,but cannot be imported in the other package, what's wrong? From gelonida at gmail.com Sun Aug 7 21:00:10 2011 From: gelonida at gmail.com (Gelonida N) Date: Mon, 08 Aug 2011 03:00:10 +0200 Subject: module import error, what's wrong? In-Reply-To: References: Message-ID: On 08/08/2011 02:45 AM, smith jack wrote: > from common.URLTool import URLTool could it be that you meant from common import URLTool As I don't know the module 'common' I am just guessing > tool = URLTool() > > Traceback (most recent call last): > File "E:\workspace\url\test.py", line 7, in ? > from common.URLTool import URLTool > ImportError: No module named common.URLTool > > URLTools is a class write by myself, it works well ,but cannot be > imported in the other package, what's wrong? From jdoe at usenetlove.invalid Sun Aug 7 22:44:41 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 08 Aug 2011 02:44:41 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> Steven D'Aprano wrote: > Also, are you using an IDE? If so, it could very well be > interfering with the keyboard buffer I really don't know how to answer your question. I am using Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon Naturally Speaking, Natlink, and Dragonfly might all be part of the process. Must be my system. I will post the solution if it comes up. From ian.g.kelly at gmail.com Mon Aug 8 00:29:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 7 Aug 2011 22:29:24 -0600 Subject: WxPython and TK In-Reply-To: References: Message-ID: On Sun, Aug 7, 2011 at 6:26 PM, azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. > -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). > > If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. That may be the only reason Tkinter was originally added to the standard library rather than wxPython, but there are plenty of reasons against changing it now. Even ignoring for the moment the fact that wxPython *still* doesn't work with Python 3 (2.5 years now since the initial release of Python 3.0), here is a nice, recent summary of some of the issues involved: http://mail.python.org/pipermail/python-list/2011-January/1264955.html Cheers, Ian From research at johnohagan.com Mon Aug 8 00:59:23 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 8 Aug 2011 14:59:23 +1000 Subject: Restricted attribute writing In-Reply-To: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e3ec653$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110808145923.44fb85ec158393f36557f41c@johnohagan.com> On Mon, 08 Aug 2011 03:07:30 +1000 Steven D'Aprano wrote: > John O'Hagan wrote: > > > I'm looking for good ways to ensure that attributes are only writable such > > that they retain the characteristics the class requires. > > That's what properties are for. > > > My particular case is a class attribute which is initialised as a list of > > lists of two integers, the first of which is a modulo remainder. I need to > > be able to write to it like a normal list, but want to ensure it is only > > possible to do so without changing that format. > > Then you have two problems to solve. > > First, you need a special type of list that only holds exactly two integers. > Your main class can't control what happens inside the list, so you need the > list to validate itself. > > Secondly, you should use a property in your main class to ensure that the > attribute you want to be a special list-of-two-ints can't (easily) be > changed to something else. > Although experience shows you're usually right :) , I thought I had three problems, the third being what I perhaps wasn't clear enough about: that the two-integer containers live in a list which should only contain the two-integer things, but aside from that should be able to do all the other list operations on it. AFAIK making this attribute a property only protects it from incorrect assignment, but not from unwanted appends etc. That's what the other helper class Order is meant for, it subclasses list, and overrides __setitem__ to ensure every item is an OrderElement, and __getitem__ to ensure slices are the same class. I've also since realised it must override append, insert and extend. I think I need all this to ensure the required behaviour, including: s = SeqSim([[15, 2]], 12) s.order[0][1] = 100 s.order[0][1:] = [100] s.order += [[22, 11]] s.order *= 2 s.order[2] = [[15, 8]] s.order[1:5:2]) = [[1, 1],[2, 2]] s.order.extend([[1, 1],[2, 2]]) s.order.insert(2, [2, 29]) s.order.append([26, 24]) s.order.extend(s.order[1:3]) s.order = [[99, 99],[100, 100]] import random random.shuffle(s.order) etc [...] > I'd take this approach instead: > > # Untested. > class ThingWithTwoIntegers(object): > def __init__(self, a, b): > self.a = a > self.b = b > def __getitem__(self, index): > # Slicing not supported, because I'm lazy. > if index < 0: index += 2 > if index == 0: return self.a > elif index == 1: return self.b > else: raise IndexError > def __setitem__(self, index, value): > # Slicing not supported, because I'm lazy. > if index < 0: index += 2 > if index == 0: self.a = value > elif index == 1: self.b = value > else: raise IndexError > def _geta(self): > return self._a > def _seta(self, value): > if isinstance(value, (int, long)): # drop long if using Python 3 > self._a = value > else: > raise TypeError('expected an int but got %s' % type(value)) > a = property(_geta, _seta) > # and the same for b: _getb, _setb, making the obvious changes > [...] > Obviously this isn't a full blown list, but if you don't need all the > list-like behaviour (sorting, inserting, deleting items, etc.) why support > it? > Thanks for this, I can see that the __data attribute I was using was unnecessary and I've redone the OrderElement class accordingly, although I do want slicing and don't need dot-notation access: class OrderElement(): def __init__(self, length, a, b): self.__length=length self.__a = a self.__b = b self[:] = a, b def __setitem__(self, index, item): if isinstance(index, slice): for k, i in zip(range(*index.indices(2)), item): self[k] = i elif isinstance(item, int) and index in (0, 1): if index == 0: self.__a = item % self.__length elif index == 1: self.__b = item else: raise TypeError("OrderElement takes two integers") def __getitem__(self, index): if isinstance(index, slice): return [self[i] for i in range(*index.indices(2))] if index == 0: return self.__a if index == 1: return self.__b raise IndexError As for the rest, I take your point that a simple idea need not be simple to implement, and I'm starting to think my solution may be about as complicated as it needs to be. Regards, John From greg.ewing at canterbury.ac.nz Mon Aug 8 02:06:48 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 08 Aug 2011 18:06:48 +1200 Subject: WxPython and TK In-Reply-To: References: Message-ID: <9a9cnrFumuU1@mid.individual.net> azrael wrote: > If I would have gotten a dollar for every time I talked to someone in a company > about why they dont use python for their products and I was served the answer > "Well it kind of sucks in GUI development", I would be a millionaire. Even assuming that Python + wxPython sucks less than Python + Tkinter (which is a matter of opinion), putting wxPython in the standard library would change very little. Anyone who wants to is already free to use wxPython now. -- Greg From prakash.stack at gmail.com Mon Aug 8 02:11:51 2011 From: prakash.stack at gmail.com (prakash jp) Date: Mon, 8 Aug 2011 11:41:51 +0530 Subject: how to invoke a bat file on a remote machine Message-ID: Hi all, Want to know how to invoke a bat file on a remote machine. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Aug 8 02:37:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 08 Aug 2011 16:37:15 +1000 Subject: WxPython and TK References: Message-ID: <4e3f841e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Mon, 8 Aug 2011 10:26 am azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a > number of constraints. The only reason wxPython isn't the standard Python > GUI toolkit is that Tkinter was there first. -- Guido van Rossum I'd like to see the context for this quote, because I don't think it is correct. Even if Guido did say it :) Other reasons contributing to why wxPython is not in the standard library: - Differences in the licence. I understand the wxWidgets licence is more restrictive than the Python licence. - Size: wxPython is much larger than Tkinter. By one account, adding wxPython would triple the size of the standard library. - Tcl/Tk is likely to already be installed on most Linux systems, wxWidgets may not be. - Stability: at least a few years ago, it was quite easy to get wxPython to seg fault. - Pythonicity: Tkinter code is much closer to Pythonic style of code than wxPython code, which is stylistically closer to C++. - Release schedules: this is likely to be the fatal sticking block. To be part of the standard library, wxPython would have to keep to Python's release schedule. If wxPython had been in the standard library, it would have been tied to Python's relatively sedate schedule, and would not have been able to keep up with wxWidgets. > OK, now. Isn't it maybe time to throw out TK once and for all? Python is > missing one of the most important aspects of todays IT industry. GUI > development native library (I mean a serious one). Python is not missing any such thing. It has a plethora of GUI libraries: wxPython Tkinter Pyjamas Dabo PyGTK PythonCard etc. See http://wiki.python.org/moin/GuiProgramming > If I would have gotten a dollar for every time I talked to someone in a > company about why they dont use python for their products and I was served > the answer "Well it kind of sucks in GUI development", I would be a > millionaire. What, these millions of companies don't have internet? http://www.wxpython.org/download.php#stable -- Steven From joepie at linux.nl Mon Aug 8 02:46:29 2011 From: joepie at linux.nl (ln4) Date: Mon, 08 Aug 2011 08:46:29 +0200 Subject: WxPython and TK References: Message-ID: azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a > number of constraints. The only reason wxPython isn't the standard Python > GUI toolkit is that Tkinter was there first. -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is > missing one of the most important aspects of todays IT industry. GUI > development native library (I mean a serious one). > > If I would have gotten a dollar for every time I talked to someone in a > company about why they dont use python for their products and I was served > the answer "Well it kind of sucks in GUI development", I would be a > millionaire. This quote from guido is perhaps from many, many years ago. I don't like wxpython so much. There is a much better solution available: using PyQt. Qt libraries are cross platform too, mature code and very fast. Including lots of tools for development without typing all the graphics code. Taco From ulrich.eckhardt at dominolaser.com Mon Aug 8 02:56:30 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 08 Aug 2011 08:56:30 +0200 Subject: Segmentation Fault on exit References: Message-ID: <1ed4h8-eo4.ln1@satorlaser.homedns.org> Vipul Raheja wrote: > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. 1. Use a debugger Run python with "gdb python", import the module and exit. The debugger should then show you where the segmentation fault occurs, even though that code isn't necessarily the code that is at fault itself. 2. Reduce the size of your module Remove code from the module. The most drastic variant is to strip anything and only leave an empty init function. If that still causes troubles, I'd suspect something in the environment or in the way you build the module. 3. Make sure the environment works Try compiling and running the SWIG examples or any other SWIG code. Does it work? What are the differences to your code? 4. Post your code If everything fails, you could try to reduce your module to the bare minimum and post that here. Make sure you really remove anything that's not necessary. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From xrgtn at yandex.ru Mon Aug 8 03:07:25 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Mon, 8 Aug 2011 10:07:25 +0300 Subject: Hardlink sub-directories and files In-Reply-To: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> References: <3d2c3d3b-085e-4f3b-903d-726a31e607f4@b34g2000yqi.googlegroups.com> Message-ID: <20110808070725.GA3741@ux380n.ckee> Hello, On Tue, Aug 02, 2011 at 02:32:54AM -0700, loial wrote: > This works fine for files, but the directory > also contains sub- directories (which themselves > contain files and sub-directories). However I > do not think it is possible to hard link > directories ? On some Unices it is, as I heard. But in general, it's not always possible to even hardlink to an ordinary file: 1) across filesystem boundary 2) on GRSEC system, if you don't own the original file -- WBR, xrgtn From gelonida at gmail.com Mon Aug 8 03:41:05 2011 From: gelonida at gmail.com (Gelonida N) Date: Mon, 08 Aug 2011 09:41:05 +0200 Subject: Wait for a keypress before continuing? In-Reply-To: <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e3f2d90$0$29980$c3e8da3$5496439d@news.astraweb.com> <4e3f4d99$0$1070$c3e8da3$9f400e27@news.astraweb.com> Message-ID: On 08/08/2011 04:44 AM, John Doe wrote: > Steven D'Aprano wrote: > >> Also, are you using an IDE? If so, it could very well be >> interfering with the keyboard buffer > > I really don't know how to answer your question. I am using > Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon > Naturally Speaking, Natlink, and Dragonfly might all be part of > the process. > > Must be my system. I will post the solution if it comes up. Main question is whether your script is exectued in a console window (like cmd.exe) or from within a graphical library without console. you yould try to start cmd.exe and call your python script directly from there. if this doesn't work, then try just a simple test script containing nothing else than the code to wait for a keypress. Simple test script (working fine for me) import msvcrt print "before" msvcrt.getch() print "after" From python at bdurham.com Mon Aug 8 06:10:25 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 08 Aug 2011 06:10:25 -0400 Subject: WxPython and TK In-Reply-To: References: Message-ID: <1312798225.16266.2160672425@webmail.messagingengine.com> Azrael, > Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). Check out enhancements to Tk like Ttk included in Python 2.7 and 3.1 and above. http://www.tkdocs.com/tutorial/styles.html Tk/Ttk is a much lighter weight GUI than wxPython and allows for commercial quality, cross-platform GUI development. Malcolm From blivori at gmail.com Mon Aug 8 06:23:35 2011 From: blivori at gmail.com (blivori) Date: Mon, 8 Aug 2011 03:23:35 -0700 (PDT) Subject: PyPDF Processing Errors (ValueError: invalid literal for int() with base 16: '\x00\x00') Message-ID: <76d482a9-c8aa-497c-977f-b44c64a4c5fd@z17g2000vbp.googlegroups.com> I am trying to create a Python script using the PyPDF Module. What the script does it take the 'Root' folder, merges all the PDFs in it and outputs the merged PDF in an 'Output' folder and renames it to 'Root.pdf' (the folder which containes the split PDFs). What it does then is do the same with the sub-directories, giving the final output a name equal to the sub-directories. I'm stuck when coming to process the sub-directories, giving me an error code related to some hex values. (it seems that it is getting a null value which is not in hex) Please not that this happens only with certain PDF files. All of them are non-corrupted PDFs and can be opened with any PDFViewer. This is the error I get: Traceback (most recent call last): File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 76, in files_recursively(path) File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 74, in files_recursively os.path.walk(path, process_file, ()) File "C:\Python27\lib\ntpath.py", line 263, in walk walk(name, func, arg) File "C:\Python27\lib\ntpath.py", line 259, in walk func(arg, top, names) File "C:\Documents and Settings\student3\Desktop\Test\pdfMerger? line 38, in process_file pdf = PdfFileReader(file( filename, "rb")) File "C:\Python27\lib\site-packages\pyPdf\pdf? line 374, in __init__ self.read(stream) File "C:\Python27\lib\site-packages\pyPdf\pdf? line 775, in read newTrailer = readObject(stream, self) File "C:\Python27\lib\site-packages\pyPdf\gen? line 67, in readObject return DictionaryObject.readFromStream(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 531, in readFromStream value = readObject(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 58, in readObject return ArrayObject.readFromStream(stream, pdf) File "C:\Python27\lib\site-packages\pyPdf\gen? line 153, in readFromStream arr.append(readObject(stream, pdf)) File "C:\Python27\lib\site-packages\pyPdf\gen? line 69, in readObject return readHexStringFromStream(stream) File "C:\Python27\lib\site-packages\pyPdf\gen? line 276, in readHexStringFromStream txt += chr(int(x, base=16)) ValueError: invalid literal for int() with base 16: '\x00\x00' From nickle at gmail.com Mon Aug 8 08:37:34 2011 From: nickle at gmail.com (Nick) Date: Mon, 8 Aug 2011 05:37:34 -0700 (PDT) Subject: Docstrings and class Attributes Message-ID: Is it possible to put a doc string on a class attribute? Something like this class Test (object): '''classx''' fred = 10 '''attribute''' print Test.__doc__ print Test.fred.__doc__ This code produces this output classx int(x[, base]) -> integer Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. If base is zero, the proper base is guessed based on the string content. If the argument is outside the integer range a long object will be returned instead. =========== So the class doc string is return, but no doc string for the attribute. From phd at phdru.name Mon Aug 8 09:17:40 2011 From: phd at phdru.name (Oleg Broytman) Date: Mon, 8 Aug 2011 17:17:40 +0400 Subject: SQLObject 1.1.2 Message-ID: <20110808131740.GC24811@iskra.aviel.ru> Hello! I'm pleased to announce version 1.1.2, a bugfix release of branch 1.1 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.1.2 News and changes: http://sqlobject.org/News.html What's New ========== Features & Interface -------------------- * A bug was fixed in SelectResults slicing that prevented to slice a slice (my_results[:20][1:5]). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From mephisto_9000 at hotmail.com Mon Aug 8 11:17:07 2011 From: mephisto_9000 at hotmail.com (Francis Labarre) Date: Mon, 8 Aug 2011 11:17:07 -0400 Subject: Embedded python console and FILE* in python 3.2 Message-ID: Hello everyone, I'm currently trying to port some embedded code from python 2.7 to python 3.2. The current code replicate the basic behavior of the python interpreter in anMFC application. When a command is entered in our embedded interpreter, we write it to a FILE* then transform this FILE* into a Python file with the apifunction PyFile_FromFile and assign it to python's stdin. We also assign anotherFILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to executethe statement as the python interpreter normally would. Finally, we can easily retrievethe result of the execution from the output FILE*. This is currently the only approach we have found that allows us to retrieve the result of executing a statement exactly as the interpreter would. The problem is that the implementation of files has changed in python 3 and the functionPyFile_FromFile has been removed. Does anyone knows a way to achieve the same thing as this function either trough the io moduleor the python/C api? Or could there be a better approach to what we are trying to achieve? Keep in mind that we need to obtain the result of any statement, i.e. : If the command is "2+2" the result should be "4", if the command is "1/0" the result should be Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero Thank you, F.L. -------------- next part -------------- An HTML attachment was scrubbed... URL: From katriel at katriel.co.uk Mon Aug 8 11:31:20 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Mon, 8 Aug 2011 16:31:20 +0100 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: Is the `code` module (http://docs.python.org/library/code.html) an insufficiently exact copy of an interpreter for you? On Mon, Aug 8, 2011 at 4:17 PM, Francis Labarre wrote: > Hello everyone, > > I'm currently trying to port some embedded code from python 2.7 to python > 3.2. > > The current code replicate the basic behavior of the python interpreter in > an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne to > execute > the statement as the python interpreter normally would. Finally, we > can easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 and > the function > PyFile_FromFile has been removed. > > Does anyone knows a way to achieve the same thing as this function either > trough the io module > or the python/C api? Or could there be a better approach to what we are > trying to achieve? > > Keep in mind that we need to obtain the result of any statement, i.e. : > > If the command is "2+2" the result should be "4", if the command is "1/0" > the result should be > > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero > > > Thank you, > > F.L. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 8 11:31:38 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 17:31:38 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: <4E40015A.3060401@jollybox.de> On 08/08/11 17:17, Francis Labarre wrote: > Hello everyone, > > I'm currently trying to port some embedded code from python 2.7 to > python 3.2. > > The current code replicate the basic behavior of the python interpreter > in an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne > to execute > the statement as the python interpreter normally would. Finally, we > can easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 > and the function > PyFile_FromFile has been removed. > > Does anyone knows a way to achieve the same thing as this function > either trough the io module > or the python/C api? Or could there be a better approach to what we are > trying to achieve? > > Keep in mind that we need to obtain the result of any statement, i.e. : > > If the command is "2+2" the result should be "4", if the command is > "1/0" the result should be > > Traceback (most recent call last): > File "", line 1, in > ZeroDivisionError: division by zero > > > Thank you, > > F.L. > > I assume you could simply use PyFile_FromFd? The more elegant solution might be to create custom Python file-like objects for std{in,out,err} that communicate directly with your application. Thomas From philip at semanchuk.com Mon Aug 8 11:49:44 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 8 Aug 2011 11:49:44 -0400 Subject: WxPython and TK In-Reply-To: References: Message-ID: On Aug 7, 2011, at 8:26 PM, azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. > -- Guido van Rossum > > OK, now. Isn't it maybe time to throw out TK once and for all? Python is missing one of the most important aspects of todays IT industry. GUI development native library (I mean a serious one). I don't see how removing TK from the standard library helps to fill the native GUI development library void that you see in Python. I guess you're promoting wxPython as the library to fill that void. Getting rid of TK is one argument, adding wxPython is different argument. Are you advocating one, the other, or both? > If I would have gotten a dollar for every time I talked to someone in a company about why they dont use python for their products and I was served the answer "Well it kind of sucks in GUI development", I would be a millionaire. And if I had a dollar for every "Let's replace TK with XYZ" post, I'd also be a millionaire. I don't object to your argument; criticism of standard library is how it advances. But you're going to have to come up with a better argument than a 5+ year old quote from Guido and an exaggerated claim about why people don't use Python. The "best Python GUI library" conversation is repeated on this list at least once every few months. If the subject really interests you, I recommend that you read the archives and see some of the arguments for and against various GUI toolkits. Cheers Philip From tdldev at gmail.com Mon Aug 8 12:08:35 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 8 Aug 2011 12:08:35 -0400 Subject: smtp Message-ID: I'm working on learning various aspects of Py coding, and happened to review the smtplib docs this morning. I entered the sample code from http://www.python.org/doc//current/library/smtplib.html import smtplib def prompt(prompt): return raw_input(prompt).strip() fromaddr = prompt("From: ")toaddrs = prompt("To: ").split()print "Enter message, end with ^D (Unix) or ^Z (Windows):" # Add the From: and To: headers at the start!msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs)))while 1: try: line = raw_input() except EOFError: break if not line: break msg = msg + line print "Message length is " + repr(len(msg)) server = smtplib.SMTP('localhost')server.set_debuglevel(1)server.sendmail(fromaddr, toaddrs, msg)server.quit() and it returns - "TypeError" with no other information... It appears to be generated from the line msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs))) But I'm not sure why... Any input is appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 8 12:26:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 17:26:18 +0100 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 5:08 PM, Verde Denim wrote: > and it returns - > "TypeError" with no other information... > It appears to be generated from the line > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs))) > > But I'm not sure why... > I transcribed pieces manually from your code into Python 2.4.5 and didn't get an error. What did you enter at the From: and To: prompts? As a side point: Does anyone else feel that it's potentially confusing to have a function whose parameter has the same name as the function itself? This is straight from the example. ChrisA From ericsnowcurrently at gmail.com Mon Aug 8 12:41:09 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Mon, 8 Aug 2011 10:41:09 -0600 Subject: Docstrings and class Attributes In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: > Is it possible to put a doc string on a class attribute? Something > like this You can put a docstring on a property (which is a function): class Test(object): @property def fred(self): "attribute" return 10 Python syntax supports implicitly building docstrings only for modules, class definitions, and function definitions. -eric > > class Test (object): > ? ?'''classx''' > > ? ?fred = 10 > ? ?'''attribute''' > > print Test.__doc__ > print Test.fred.__doc__ > > This code produces this output > > classx > int(x[, base]) -> integer > > Convert a string or number to an integer, if possible. ?A floating > point > argument will be truncated towards zero (this does not include a > string > representation of a floating point number!) ?When converting a string, > use > the optional base. ?It is an error to supply a base when converting a > non-string. ?If base is zero, the proper base is guessed based on the > string content. ?If the argument is outside the integer range a > long object will be returned instead. > > =========== > > So the class doc string is return, but no doc string for the > attribute. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From tdldev at gmail.com Mon Aug 8 12:45:45 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 8 Aug 2011 12:45:45 -0400 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 12:26 PM, Chris Angelico wrote: > On Mon, Aug 8, 2011 at 5:08 PM, Verde Denim wrote: > > and it returns - > > "TypeError" with no other information... > > It appears to be generated from the line > > > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > > % (fromaddr, ", ".join(toaddrs))) > > > > But I'm not sure why... > > > > I transcribed pieces manually from your code into Python 2.4.5 and > didn't get an error. What did you enter at the From: and To: prompts? > > I'm running 2.6.5 on a debian base... It didn't seem to matter what is input - I tried using a single recipient as well as multiples (separated by comma). Output appears as - # python send_my_msg.py From: me at me.com To: you at you.com Enter Message, end with ^D: Traceback (most recent call last): File "send_my_msg.py", line 12, in % (fromaddr, ", ".join(toaddr))) TypeError > As a side point: Does anyone else feel that it's potentially confusing > to have a function whose parameter has the same name as the function > itself? This is straight from the example. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 8 13:07:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 18:07:50 +0100 Subject: smtp In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 5:45 PM, Verde Denim wrote: > I'm running 2.6.5 on a debian base... > It didn't seem to matter what is input - > I tried using a single recipient as well as multiples (separated by comma). Since the recipient list is divided using split(), you should separate multiple addresses with spaces. However, that won't cause your problem. I copied and pasted your exact code and tried it on three different versions. Obviously Python 3 didn't like it (print statements). Python 2.4.5 failed on importing _socket, so I assume there's a minimum version required. But 2.6.5 worked fine: From: foo at bar To: asdf at qwer Enter message, end with ^D (Unix) or ^Z (Windows): zxcvaasdf ssdfzxcv ^Z Message length is 49 Traceback (most recent call last): File "1test.py", line 24, in server = smtplib.SMTP('localhost') File "C:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "C:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "C:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "C:\Python26\lib\socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 10061] No connection could be made because the target machi ne actively refused it C:\> I don't have an SMTP server running on localhost, but the script worked fine. Can you quote a failing traceback please? It might be instructive. ChrisA From mephisto_9000 at hotmail.com Mon Aug 8 13:14:57 2011 From: mephisto_9000 at hotmail.com (F L) Date: Mon, 8 Aug 2011 13:14:57 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E40015A.3060401@jollybox.de> References: , <4E40015A.3060401@jollybox.de> Message-ID: > Is the `code` module (http://docs.python.org/library/code.html) an insufficiently exact copy of an interpreter for you? The problem isn't really to emulate the behavior of the interpreter as to obtain the result of the execution as a string in c++. The code module doesn't seem to help with this matter. > I assume you could simply use PyFile_FromFd? According to the documentation using PyFile_FromFd seems unadvised, but I'll give it a try. > The more elegant solution might be to create custom Python file-like> objects for std{in,out,err} that communicate directly with your application.I thought about this, but I need the console window to be non-modal and I'm afraid that replacing stdin witha custom file-like object would cause a blocking call. Executing python in a second thread would solve this problembut our application isn't multi-threaded and executing python in another thread causes errors. Maybe I could use a file-like object to communicate the results to my c++ application and use the code module to execute code only when the c++ application needs it. Thanks a lot for the tips, have a nice day. F.L. -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Mon Aug 8 13:37:29 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 8 Aug 2011 12:37:29 -0500 Subject: PyCon US 2012 Survey - We need your input! Message-ID: Hi all, As we ramp up our efforts on PyCon US 2012, we wanted to gather some information from the community on what we can do best to serve you at the March 2012 conference in Santa Clara, CA. We've put together a survey about your experiences at past PyCons as well as what your interests are in the upcoming conference. We're interested in what speakers and topics you'd like to have at the tutorials, conference, and the poster sessions, as well as any input you have on what we can improve in other aspects of the event. If you have 5 minutes to spare, the survey is available at https://www.surveymonkey.com/s/pycon2012_launch_survey and results will be used to help us make PyCon 2012 the best conference yet. Thanks, The PyCon Organizers http://us.pycon.org/2012/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 8 13:44:23 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 19:44:23 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: , <4E40015A.3060401@jollybox.de> Message-ID: <4E402077.2020808@jollybox.de> On 08/08/11 19:14, F L wrote: >> Is the `code` module (http://docs.python.org/library/code.html) an > insufficiently exact copy of an interpreter for you? > > The problem isn't really to emulate the behavior of the interpreter as > to obtain the result of the execution as a string in c++. > The code module doesn't seem to help with this matter. > >> I assume you could simply use PyFile_FromFd? > > According to the documentation using PyFile_FromFd seems unadvised, but > I'll give it a try. > >> The more elegant solution might be to create custom Python file-like >> objects for std{in,out,err} that communicate directly with your application. > > I thought about this, but I need the console window to be non-modal and > I'm afraid that replacing stdin with > a custom file-like object would cause a blocking call. Executing python > in a second thread would solve this problem > but our application isn't multi-threaded and executing python in another > thread causes errors. If you use the same workflow as you do currently, it won't: 1. Feed input to your custom stdin object, which will buffer the code. 2. Call PyRun_IteractiveOne - it will read from your object, which will return the buffer contents. 3. The result is somehow handled by custom stdout and stderr objects. > > Maybe I could use a file-like object to communicate the results to my > c++ application and use the code > module to execute code only when the c++ application needs it. > From t at jollybox.de Mon Aug 8 13:52:14 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 08 Aug 2011 19:52:14 +0200 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E402077.2020808@jollybox.de> References: , <4E40015A.3060401@jollybox.de> <4E402077.2020808@jollybox.de> Message-ID: <4E40224E.7080701@jollybox.de> On 08/08/11 19:44, Thomas Jollans wrote: > If you use the same workflow as you do currently, it won't: > > 1. Feed input to your custom stdin object, which will buffer the code. > 2. Call PyRun_IteractiveOne - it will read from your object, which will > return the buffer contents. > 3. The result is somehow handled by custom stdout and stderr objects. > Come to think of it, you might as well just use StringIO. From airween at gmail.com Mon Aug 8 14:06:18 2011 From: airween at gmail.com (=?utf-8?B?SGVnZWTDvHMs?= Ervin) Date: Mon, 8 Aug 2011 20:06:18 +0200 Subject: smtp In-Reply-To: References: Message-ID: <20110808180617.GA2544@arxnet.hu> hello, > > import smtplib > def prompt(prompt): > return raw_input(prompt).strip() > fromaddr = prompt("From: ")toaddrs = prompt("To: ").split()print > "Enter message, end with ^D (Unix) or ^Z (Windows):" > # Add the From: and To: headers at the start!msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs)))while 1: > try: > line = raw_input() > except EOFError: > break > if not line: > break > msg = msg + line > print "Message length is " + repr(len(msg)) > server = smtplib.SMTP('localhost')server.set_debuglevel(1)server.sendmail(fromaddr, > toaddrs, msg)server.quit() > > and it returns - > "TypeError" with no other information... > It appears to be generated from the line > > msg = ("From: %s\r\nTo: %s\r\n\r\n" > % (fromaddr, ", ".join(toaddrs))) > > But I'm not sure why... after I copied it to a script, I've got this result: From: airween at gmail.com To: airween at index.hu Enter message, end with ^D (Unix) or ^Z (Windows): Teszt Message length is 55 send: 'ehlo slave.myhost.hu\r\n' reply: '250-ns2.myhost.hu\r\n' reply: '250-PIPELINING\r\n' reply: '250-SIZE 10240000\r\n' reply: '250-VRFY\r\n' reply: '250-ETRN\r\n' reply: '250-STARTTLS\r\n' reply: '250-AUTH PLAIN LOGIN\r\n' reply: '250-AUTH=PLAIN LOGIN\r\n' reply: '250-ENHANCEDSTATUSCODES\r\n' reply: '250-8BITMIME\r\n' reply: '250 DSN\r\n' reply: retcode (250); Msg: ns2.myhost.hu PIPELINING SIZE 10240000 VRFY ETRN STARTTLS AUTH PLAIN LOGIN AUTH=PLAIN LOGIN ENHANCEDSTATUSCODES 8BITMIME DSN send: 'mail FROM: size=55\r\n' reply: '250 2.1.0 Ok\r\n' reply: retcode (250); Msg: 2.1.0 Ok send: 'rcpt TO:\r\n' reply: '250 2.1.5 Ok\r\n' reply: retcode (250); Msg: 2.1.5 Ok send: 'data\r\n' reply: '354 End data with .\r\n' reply: retcode (354); Msg: End data with . data: (354, 'End data with .') send: 'From: airween at gmail.com\r\nTo: airween at index.hu\r\n\r\nTeszt\r\n.\r\n' reply: '250 2.0.0 Ok: queued as 643F144002\r\n' reply: retcode (250); Msg: 2.0.0 Ok: queued as 643F144002 data: (250, '2.0.0 Ok: queued as 643F144002') send: 'quit\r\n' reply: '221 2.0.0 Bye\r\n' reply: retcode (221); Msg: 2.0.0 Bye And there is that mail in my inbox... Debian Lenny, Python 2.5.2 a. From mephisto_9000 at hotmail.com Mon Aug 8 14:06:48 2011 From: mephisto_9000 at hotmail.com (F L) Date: Mon, 8 Aug 2011 14:06:48 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: <4E40224E.7080701@jollybox.de> References: , , <4E40015A.3060401@jollybox.de>, , <4E402077.2020808@jollybox.de>, <4E40224E.7080701@jollybox.de> Message-ID: > If you use the same workflow as you do currently, it won't You're right it shouldn't cause a blocking call. > Come to think of it, you might as well just use StringIO. Yes I could probably replace std{in, out, err} with stringIO objects and retrieve their contents throughthe api. I'll look into it, thank again. F.L. > Date: Mon, 8 Aug 2011 19:52:14 +0200 > From: t at jollybox.de > To: python-list at python.org > Subject: Re: Embedded python console and FILE* in python 3.2 > > On 08/08/11 19:44, Thomas Jollans wrote: > > > > > 1. Feed input to your custom stdin object, which will buffer the code. > > 2. Call PyRun_IteractiveOne - it will read from your object, which will > > return the buffer contents. > > 3. The result is somehow handled by custom stdout and stderr objects. > > > > Come to think of it, you might as well just use StringIO. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 8 14:17:38 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:17:38 -0400 Subject: Docstrings and class Attributes In-Reply-To: References: Message-ID: On 8/8/2011 8:37 AM, Nick wrote: > Is it possible to put a doc string on a class attribute? Class and function docstrings are generated from string expression statements at the beginning of a suite. > class Test (object): > '''classx''' > > fred = 10 > '''attribute''' This is two statements that have no particular connection with each other. > print Test.__doc__ > print Test.fred.__doc__ > > This code produces this output > > classx > int(x[, base]) -> integer ... If an instance does not have a requested attribute, it is looked up on its class (and superclasses). Since all classes are subclasses of object and that has a docstring, I guess everything will. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Aug 8 14:26:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 04:26:09 +1000 Subject: Docstrings and class Attributes References: Message-ID: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Eric Snow wrote: > On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >> Is it possible to put a doc string on a class attribute? Something >> like this > > You can put a docstring on a property (which is a function): > > class Test(object): > @property > def fred(self): > "attribute" > return 10 Which, however, doesn't really help: >>> t = Test() >>> t.fred.__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' The problem is that t.fred returns an integer, so t.fred.__doc__ returns the docstring from the integer, not for the property. >>> t.__class__.fred.__doc__ 'attribute' -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 8 14:32:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 04:32:18 +1000 Subject: Docstrings and class Attributes References: Message-ID: <4e402bb4$0$29990$c3e8da3$5496439d@news.astraweb.com> Nick wrote: > Is it possible to put a doc string on a class attribute? Something > like this > > class Test (object): > '''classx''' > fred = 10 > '''attribute''' The short answer is, no. The longer answer is, maybe, if you can make Test.fred be some sort of object with a docstring: class MyInt(int): '''attribute''' class Test(object): '''classx''' fred = MyInt(10) >>> Test.fred.__doc__ 'attribute' But the hard part is ensuring that Test.fred doesn't get replaced: >>> Test.fred = 11 >>> Test.fred.__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number ...' Not impossible to solve, but an awful lot of trouble for very little benefit. Just put your documentation in the class, where people expect to find it: class Test(object): '''classx Test.fred is an attribute. ''' fred = 10 -- Steven From tjreedy at udel.edu Mon Aug 8 14:35:10 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:35:10 -0400 Subject: Embedded python console and FILE* in python 3.2 In-Reply-To: References: Message-ID: On 8/8/2011 11:17 AM, Francis Labarre wrote: > Hello everyone, > > I'm currentlytrying to port some embedded code from python 2.7 to python > 3.2. > > The current code replicate the basic behavior of the python interpreter > in an > MFC application. When a command is entered in our embedded interpreter, > we write it to a FILE* then transform this FILE* into a Python file with > the api > function PyFile_FromFile and assign it to python's stdin. We also assign > another > FILE* as python's stdout and stderr. We then call PyRun_InteractiveOne > to execute > the statement as the python interpreter normally would. Finally, we can > easily retrieve > the result of the execution from the output FILE*. > > This is currently the only approach we have found that allows us to > retrieve the > result of executing a statement exactly as the interpreter would. > > The problem is that the implementation of files has changed in python 3 > and the function > PyFile_FromFile has been removed. The source for the function is still available in 2.7. You might be able to adapt it to work in 3.x. IDLE imitates the interactive interpreter by running code in a separate non-console pythonw process. There have been issues with getting that to work right on Windows (see issue 12540), but it works well when it does. Depending on your use case, this might work for you too. Communication is through (wrapped) OS pipes, not normal Python file objects. -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 14:48:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 14:48:21 -0400 Subject: Docstrings and class Attributes In-Reply-To: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/8/2011 2:26 PM, Steven D'Aprano wrote: > Eric Snow wrote: > >> On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >>> Is it possible to put a doc string on a class attribute? This really makes little sense. The purpose of docstrings is to give interactive help. The place to document data attributes of a class is in the class docstring. The value of an int is considered to be self-explanatory. >> You can put a docstring on a property (which is a function): >> >> class Test(object): >> @property >> def fred(self): >> "attribute" >> return 10 > > Which, however, doesn't really help: > >>>> t = Test() >>>> t.fred.__doc__ > 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' > > > The problem is that t.fred returns an integer, so t.fred.__doc__ returns the > docstring from the integer, not for the property. > >>>> t.__class__.fred.__doc__ > 'attribute' Which is to say, the descriptor protocol allows custom get, set, and delete methods, but not an attribute-specific getattribute method ;-). -- Terry Jan Reedy From ethan at stoneleaf.us Mon Aug 8 14:58:21 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 08 Aug 2011 11:58:21 -0700 Subject: Docstrings and class Attributes In-Reply-To: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4031CD.3070204@stoneleaf.us> Steven D'Aprano wrote: > Eric Snow wrote: > >> On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: >>> Is it possible to put a doc string on a class attribute? Something >>> like this >> You can put a docstring on a property (which is a function): >> >> class Test(object): >> @property >> def fred(self): >> "attribute" >> return 10 > > Which, however, doesn't really help: > >--> t = Test() >--> t.fred.__doc__ > 'int(x[, base]) -> integer\n\nConvert a string or number to an integer ...' > > > The problem is that t.fred returns an integer, so t.fred.__doc__ returns the > docstring from the integer, not for the property. > >--> t.__class__.fred.__doc__ > 'attribute' So if property docstrings are so hard to get to, what's the point in having them? ~Ethan~ From steve+comp.lang.python at pearwood.info Mon Aug 8 15:05:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 05:05:36 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > So if property docstrings are so hard to get to, what's the point in > having them? Hard to get, not impossible. But I have no idea really -- they don't seem very useful to me. -- Steven From tjreedy at udel.edu Mon Aug 8 15:06:06 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:06:06 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:26 PM, Chris Angelico wrote: > As a side point: Does anyone else feel that it's potentially confusing > to have a function whose parameter has the same name as the function > itself? This is straight from the example. Yes. I might change it someday when I can. -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 15:07:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:07:11 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:08 PM, Verde Denim wrote: > I'm working on learning various aspects of Py coding, and happened to > review the smtplib docs this morning. > I entered the sample code from > http://www.python.org/doc//current/library/smtplib.html When posting about error messages, please specify Python version used and copy *entire* traceback -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 8 15:11:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 15:11:36 -0400 Subject: smtp In-Reply-To: References: Message-ID: On 8/8/2011 12:45 PM, Verde Denim wrote: > I'm running 2.6.5 on a debian base... > It didn't seem to matter what is input - > I tried using a single recipient as well as multiples (separated by comma). > > Output appears as - > # python send_my_msg.py > From: me at me.com > To: you at you.com > Enter Message, end with ^D: > Traceback (most recent call last): > File "send_my_msg.py", line 12, in > % (fromaddr, ", ".join(toaddr))) > TypeError I am concerned about the lack of any message. It is close to being a bug. If this happens with current Python, 2.7.2 or 3.2.1, posting to the bug tracker a minimal example needed to get the above might result in a fix. -- Terry Jan Reedy From ckaynor at zindagigames.com Mon Aug 8 15:22:33 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 8 Aug 2011 12:22:33 -0700 Subject: Docstrings and class Attributes In-Reply-To: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: They are actually quite easy to get to. help() on both the class or instance produces the docstring, and __doc__ on the property as accessed from the class produces the docstring. >>> class Test(object): ... @property ... def fred(self): ... """*This is a docstring.*""" ... return 1 ... >>> help(Test) Help on class Test in module __main__: class Test(__builtin__.object) | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | fred | *This is a docstring.* >>> Test.fred.__doc__ '*This is a docstring*.' >>> t = Test() >>> t.fred.__doc__ 'int(x[, base]) -> integer\n\n...' >>> help(t) Help on Test in module __main__ object: class Test(__builtin__.object) | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | fred | *This is a docstring.* Chris On Mon, Aug 8, 2011 at 12:05 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Ethan Furman wrote: > > > So if property docstrings are so hard to get to, what's the point in > > having them? > > Hard to get, not impossible. But I have no idea really -- they don't seem > very useful to me. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericsnowcurrently at gmail.com Mon Aug 8 15:24:11 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Mon, 8 Aug 2011 13:24:11 -0600 Subject: Docstrings and class Attributes In-Reply-To: <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e403380$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 8, 2011 at 1:05 PM, Steven D'Aprano wrote: > Ethan Furman wrote: > >> So if property docstrings are so hard to get to, what's the point in >> having them? > > Hard to get, not impossible. But I have no idea really -- they don't seem > very useful to me. They do show up in help(), but not as some sort of data-attribute docstring. -eric > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > From croepha at gmail.com Mon Aug 8 15:50:44 2011 From: croepha at gmail.com (Croepha) Date: Mon, 8 Aug 2011 14:50:44 -0500 Subject: Object Diffs Message-ID: Hello Python list: I am doing research into doing network based propagation of python objects. In order to maintain network efficiency. I wan't to just send the differences of python objects, I was wondering if there was/is any other research or development in this area? I was thinking that I could look at how pickle works an implement a diff system there, or I could actually create a pickle of the object and then use difflib to compare the flattened text... Ideas, or comments welcome Thanks, Dave Butler From rosuav at gmail.com Mon Aug 8 18:10:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Aug 2011 23:10:25 +0100 Subject: Object Diffs In-Reply-To: References: Message-ID: On Mon, Aug 8, 2011 at 8:50 PM, Croepha wrote: > I am doing research into doing network based propagation of python > objects. ?In order to maintain network efficiency. I wan't to just > send the differences of python objects You could send pickled versions of each of the object's attributes, rather than the whole object. Then simply have a notation for "same as before", and you are sending the delta of attributes. If your set of important attributes is stable, this could be quite efficient. OTOH, this won't help if your attributes are complex structures for which you want to send detailed diffs, that won't work. Another way would be to pickle the object, and then use any string diff utility to find the significant portions. I don't know whether pickle is guaranteed to be stable on dictionaries, though; you might get a lot of "diff noise". ChrisA From drsalists at gmail.com Mon Aug 8 20:11:39 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 8 Aug 2011 17:11:39 -0700 Subject: Object Diffs In-Reply-To: References: Message-ID: You probably need a recursive algorithm to be fully general, and yes, looking at pickle might be a good place to start. Note that pickle can't pickle everything, but it can handle most things. Also check out NX - not the CPU feature, but the (re)transmission compressing software (there are two different things with the name "NX"). NX is remarkably good at dealing with things like VNC sessions with virtual desktops, as long as you don't throw a movie at it - and it's more general than just doing VNC. Note that sometimes computing a diff and sending the differences may end up being slower than transmitting the whole object. You might also check out pyro and similar tools. On Mon, Aug 8, 2011 at 12:50 PM, Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... > > Ideas, or comments welcome > > Thanks, > Dave Butler > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 8 20:23:42 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Aug 2011 20:23:42 -0400 Subject: Object Diffs In-Reply-To: References: Message-ID: On 8/8/2011 3:50 PM, Croepha wrote: > Hello Python list: Hi > I am doing research into doing network based propagation of python > objects.In order to maintain network efficiency. I want to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... The problem cannot be tackled efficiently 'in general'. The important issue is to choose a representation that localizes differences in a particular application so that the diff is significantly smaller than just sending the changed version. Source code systems regard files as sequences of lines. That is ok for formatted source code, not so good for prose in paragraphs where a small change in one line may cause re-wrapping that changes 20 lines. Compressed representations that spread the effect of localized changes are also bad for local diffs. A representation that arbitrarily orders items (and re-orders items at will), is also bad for local diffs. I have no idea how stable and local pickles are, but I know they were not designed for diff-ing. Json or yaml representations might do better if applicable. -- Terry Jan Reedy From python at bdurham.com Mon Aug 8 20:31:03 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 08 Aug 2011 20:31:03 -0400 Subject: Object Diffs In-Reply-To: References: Message-ID: <1312849863.32603.2160966673@webmail.messagingengine.com> Croepha, You may find it simpler and sufficiently efficient to compress your objects in whatever format they exist (pickle, json, xml, etc) and send the compressed equivalents vs. trying to diff on side and reassemble on the other side. Malcolm From steve+comp.lang.python at pearwood.info Mon Aug 8 20:32:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 10:32:07 +1000 Subject: Object Diffs References: Message-ID: <4e408009$0$29998$c3e8da3$5496439d@news.astraweb.com> Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, Can you explain in more detail what you mean? Are there constraints on what the objects can be? If you have two objects: a = None b = (1, 2, "hello world", []) how would you describe the diff between a and b? If a and b are both numbers, the diff between them is just a-b, but this itself is a number and so transmitting it takes exactly as much memory as just sending b. Obviously if a and b are strings, the problem becomes trivial (just transmitted the string diff, which is a solved problem). > I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... The source code for pickle is available. See the pickle.py and pickletools.py files in your Python installation. Also, these resources may help: http://wiki.python.org/moin/DistributedProgramming http://wiki.python.org/moin/ParallelProcessing -- Steven From rosuav at gmail.com Mon Aug 8 20:34:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 01:34:56 +0100 Subject: Object Diffs In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 1:23 AM, Terry Reedy wrote: > I have no idea how stable and local pickles are, but I know they were not > designed for diff-ing. Json or yaml representations might do better if > applicable. > In terms of stability, you'd probably have to have a rule that dictionaries are sorted by their keys before being encoded. Currently I can think of only one spec that requires that, and that's the .torrent file definition (it's mandated so that the info hash is stable). It may be necessary to build your own encoder routine to enforce this; you could still use a standard format, which will mean that a standard decoder will work fine. Depending on what you're doing, though, it might well be easier to abandon the entire notion of pickling an object and sending it, and instead send higher-level conceptual data. I've always been a bit leery of systems that let you "send an object" from one computer to another, because they're so easily misused; instead of sending the data that's needed at the other end, an entire complex object is sent, and the far end extracts the data it wants. Not only does a ridiculous amount of unnecessary data get encoded, transmitted, and decoded, but sometimes it can have security implications (such as a certain multiplayer game that reveals to any player the identities of all other players, including their login email addresses and IP addresses). ChrisA From ben+python at benfinney.id.au Mon Aug 8 20:36:12 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Aug 2011 10:36:12 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vr3ju9v.fsf@benfinney.id.au> Ethan Furman writes: > So if property docstrings are so hard to get to, what's the point in > having them? Why would you expect there be a special point to them? Men, like all primates of any sex, have nipples. Properties, like any function in Python, have docstrings. They're an accident of the history that led to their implementation, and of the pre-existing parts that they're built from. There doesn't need to be a point to them (though they might be useful for reasons incidental for the reasons they exist). -- \ ?I filled my humidifier with wax. Now my room is all shiny.? | `\ ?Steven Wright | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Mon Aug 8 20:51:10 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 10:51:10 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> Message-ID: <4e40847f$0$29969$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Ethan Furman writes: > >> So if property docstrings are so hard to get to, what's the point in >> having them? > > Why would you expect there be a special point to them? > > Men, like all primates of any sex, have nipples. > > Properties, like any function in Python, have docstrings. > > They're an accident of the history that led to their implementation, and > of the pre-existing parts that they're built from. There doesn't need to > be a point to them (though they might be useful for reasons incidental > for the reasons they exist). But properties *aren't* functions, they are objects which obey the descriptor protocol. Perhaps you are thinking of the individual getter, setter and deleter parameters to property(). If so, then your comment is relevant as far as it goes to the docstrings on the individual getter/setter/deleter functions. But property() itself explicitly takes a docstring parameter. It is that docstring that seems of limited value, except that Eric Snow has pointed out that help(instance) will display property help strings. -- Steven From ben+python at benfinney.id.au Mon Aug 8 21:28:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Aug 2011 11:28:37 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <4e40847f$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871uwvjrui.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > They're an accident of the history that led to their implementation, > > and of the pre-existing parts that they're built from. There doesn't > > need to be a point to them (though they might be useful for reasons > > incidental for the reasons they exist). > > But property() itself explicitly takes a docstring parameter. It is > that docstring that seems of limited value, except that Eric Snow has > pointed out that help(instance) will display property help strings. I had forgotten that there is explicit support for adding a docstring to the property itself. That does raise the question of why :-/ Oh well, I like the analogy and will find a better place soon to force-fit it to a technical discussion :-) -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From ameetn at qualcomm.com Mon Aug 8 21:46:19 2011 From: ameetn at qualcomm.com (Nanda, Ameet) Date: Tue, 9 Aug 2011 01:46:19 +0000 Subject: Network shares in Windows Message-ID: Hi All, I was trying to access a network shared folder on a windows network. I couldn' t find of a good documentation online to do that. Are there any recommendations on how to do it in windows. So if my folder is shared as \\ameetn\Dropbox and when I am trying to open it up, it says I don't have privileges to open it every time I try doing that. >>> open("\\\\ameetn\\Dropbox") Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '\\\\ameetn\\Dropbox' Al though I try this from the administrator cmd, I still get the same error. Can anyone please recommend me a good way to do this. Thanks, Ameet -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Aug 8 21:53:30 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 09 Aug 2011 02:53:30 +0100 Subject: Network shares in Windows In-Reply-To: References: Message-ID: <4E40931A.9070902@mrabarnett.plus.com> On 09/08/2011 02:46, Nanda, Ameet wrote: > Hi All, > > I was trying to access a network shared folder on a windows network. I > couldn? t find of a good documentation online to do that. Are there any > recommendations on how to do it in windows. So if my folder is shared as > \\ameetn\Dropbox and when I am trying to open > it up, it says I don?t have privileges to open it every time I try doing > that. > > >>> open("\\\\ameetn\\Dropbox") > > Traceback (most recent call last): > > File "", line 1, in > > IOError: [Errno 13] Permission denied: '\\\\ameetn\\Dropbox' > > Al though I try this from the administrator cmd, I still get the same > error. Can anyone please recommend me a good way to do this. > \\ameetn\Dropbox is a folder. 'open' is for opening files. If \\ameetn\Dropbox\foo is the path to a file, then: f = open(r"\\ameetn\Dropbox\foo") will open it. From vijay.murthy at gmail.com Tue Aug 9 01:37:13 2011 From: vijay.murthy at gmail.com (Vijay Anantha Murthy) Date: Tue, 9 Aug 2011 00:37:13 -0500 Subject: Need help with Python to C code compiler Message-ID: Hi All, Is there any compiler which will help me convert my python code to proper C code? In my python code I am using the XML.dom.minidom module to parse an xml and process the results obtained by ElementsByTagName. I don't know of any such compiler which will help me convert this kind of python code to C code. My intention is to convert python code to a readable C code which can later be compile to an .exe file. Cython will not be of much use to me as it is in the end writing c extensions which will later be used in python. However, I wish to use this as a proper readable C code which can later be shared with users - the c source code as well as the exe along with its corresponding .py file. My main impediment here is writing out the C code manually myself, my C skills are quite poor and it would require a huge effort to sharpening my C skills before writing the code myself, I can not afford that luxury of time. I was surfing and came across shedskin, but that might not just support the xml minidom module for my purposes. Thanks, Vijay -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Tue Aug 9 02:09:19 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 8 Aug 2011 23:09:19 -0700 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: Shedskin is one option - if it doesn't have the modules you need, you could try finding pure python versions of them and translating them too, along with your own code. Cython is probably the one I hear the most about. On Mon, Aug 8, 2011 at 10:37 PM, Vijay Anantha Murthy < vijay.murthy at gmail.com> wrote: > Hi All, > > Is there any compiler which will help me convert my python code to proper C > code? > In my python code I am using the XML.dom.minidom module to parse an xml and > process the results obtained by ElementsByTagName. > I don't know of any such compiler which will help me convert this kind of > python code to C code. > > My intention is to convert python code to a readable C code which can later > be compile to an .exe file. > Cython will not be of much use to me as it is in the end writing c > extensions which will later be used in python. > However, I wish to use this as a proper readable C code which can later be > shared with users - the c source code as well as the exe along with its > corresponding > .py file. > > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. > > I was surfing and came across shedskin, but that might not just support the > xml minidom module for my purposes. > > Thanks, > Vijay > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Aug 9 02:22:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 09 Aug 2011 16:22:42 +1000 Subject: PyPy installed on old Linux Message-ID: <4e40d234$0$30003$c3e8da3$5496439d@news.astraweb.com> Has anyone here had any experience installing PyPy on Fedora 7? -- Steven From stefan_ml at behnel.de Tue Aug 9 04:18:52 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Aug 2011 10:18:52 +0200 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: Vijay Anantha Murthy, 09.08.2011 07:37: > Is there any compiler which will help me convert my python code to proper C > code? > In my python code I am using the XML.dom.minidom module to parse an xml and > process the results obtained by ElementsByTagName. > I don't know of any such compiler which will help me convert this kind of > python code to C code. It will certainly help much more to migrate your code to ElementTree first. See the xml.etree.cElementTree package, and also the external lxml.etree package. MiniDOM is known to have severe performance problems, including a huge memory overhead. > My intention is to convert python code to a readable C code which can later > be compile to an .exe file. Have a look at py2exe then. > Cython will not be of much use to me as it is in the end writing c > extensions which will later be used in python. So? You can just bundle CPython with it. Cython can directly generate the necessary code for embedding the runtime. > However, I wish to use this as a proper readable C code which can later be > shared with users - the c source code as well as the exe along with its > corresponding .py file. Cython will mostly give you that. It may not produce the most obvious C code in some cases, because it is an optimising compiler, but it's readable (especially in the annotated HTML version), and it allows you to ship your C code with your .py file, thus avoiding a user dependency on Cython. > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. That perfectly hits one of the more important use cases Cython is made for. > I was surfing and came across shedskin, but that might not just support the > xml minidom module for my purposes. Shedskin produces very fast code and generates stand-alone modules. However, it's not meant to compile Python code at all, rather a statically typed subset of the language. That implies that most Python code won't compile unchanged with it. Cython is much closer to Python semantics and capable of compiling a huge amount of existing Python code. Plus, it generates fast code and provides a very straight forward path for optimising the compiled code. There are other compilers listed here, although none of them has actual advantages over Cython and Shedskin: http://wiki.python.org/moin/PythonImplementations#Compilers Stefan From rosuav at gmail.com Tue Aug 9 04:22:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 09:22:24 +0100 Subject: Need help with Python to C code compiler In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 6:37 AM, Vijay Anantha Murthy wrote: > My main impediment here is writing out the C code manually myself, my C > skills are quite poor and it would require a huge effort to sharpening my > C skills before writing the code myself, I can not afford that luxury of > time. Writing code is a skill. You'll seldom get as readable code out of an automated conversion utility than you would get by having an expert hand-write the code; properly-rewritten code will look at the intent behind the code, not just the current code. I recommend either learning C, or accepting Cython or Shedskin. Chris Angelico From python at hope.cz Tue Aug 9 07:10:31 2011 From: python at hope.cz (Johny) Date: Tue, 9 Aug 2011 04:10:31 -0700 (PDT) Subject: How to solve this problem Message-ID: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> I have a client that is a part of a local network.This client has a local address( not public).Is there a way how I can connect to this client from outside world? What software must I install so that I can connect and control that client from outside? Thanks B From gb at como.it Tue Aug 9 07:12:02 2011 From: gb at como.it (gb at como.it) Date: Tue, 09 Aug 2011 13:12:02 +0200 Subject: WxPython and TK References: Message-ID: <86pqkeon3x.fsf@aiuole.stru.polimi.it> azrael writes: > OK, now. Isn't it maybe time to throw out TK once and for all? no, because Tk has a clear advantage over many other UI tolkits Tk _was designed_ and it was designed by very competent people [1] good luck with smurfs' hunting [2], ciao gb [1]: 1986-91 ACM's Grace Murray Hopper Awards 1986 William N. Joy, BSD Unix, Sun; 1987 John Ousterhout, Tcl/TK; 1988 Guy L. Steele, Scheme, Java; 1989 W. Daniel Hillis Thinking Machines; 1990 Richard Stallman Emacs, Gcc, FSF; 1991 Feng-hsiung Hsu Deep Blue; [2] http://www.smurf.com/smurf.php/www/who/en/azrael From katriel at katriel.co.uk Tue Aug 9 07:33:29 2011 From: katriel at katriel.co.uk (Katriel Cohn-Gordon) Date: Tue, 9 Aug 2011 12:33:29 +0100 Subject: How to solve this problem In-Reply-To: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: Unless you have the router configured to allow connections through to your local client, you will need the client to connect *outwards*, either to you or to an intermediate server. On Tue, Aug 9, 2011 at 12:10 PM, Johny wrote: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? > > Thanks > > B > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Aug 9 07:33:35 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 12:33:35 +0100 Subject: How to solve this problem In-Reply-To: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: On Tue, Aug 9, 2011 at 12:10 PM, Johny wrote: > I have a client that ?is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? Presumably you are using NAT (Network Address Translation). You'll need to arrange for a port (or a set of ports) to be forwarded to that computer, which is done by configuring your NAT router. In a simple home network, this usually means logging in using the router's home page, such as http://192.168.0.1/ or http://192.168.1.1/ (it'll be the same as your default gateway); otherwise, talk to your network admin about it. The port or ports that you need to forward will depend on what you mean by "connect and control". For SSH, that's port 22; for VNC, port 5900. Other services are on other ports. By the way, this is a networking question, not a Python one. Chris Angelico From jana1972 at centrum.cz Tue Aug 9 07:46:34 2011 From: jana1972 at centrum.cz (jana1972 at centrum.cz) Date: Tue, 09 Aug 2011 13:46:34 +0200 Subject: How to solve this problem Message-ID: <4E413A3A.24482.5AD192@jana1972.centrum.cz> I have a client that is a part of a local network.This client has a local address( not public).Is there a way how I can connect to this client from outside world? What software must I install so that I can connect and control that client from outside? Thanks B From szager at gmail.com Tue Aug 9 08:47:33 2011 From: szager at gmail.com (Stefan Zager) Date: Tue, 9 Aug 2011 05:47:33 -0700 Subject: [Swig-user] Segmentation Fault on exit In-Reply-To: References: Message-ID: On Sat, Aug 6, 2011 at 3:35 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyossim >>>> > * Do some stuff * >>>> exit() > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ I'm sorry, but that's not enough information to debug the problem. Please provide a minimal complete test case which demonstrates the problem. Thanks, Stefan From wafflesouffle at gmail.com Tue Aug 9 09:07:23 2011 From: wafflesouffle at gmail.com (WaffleSouffle) Date: Tue, 9 Aug 2011 06:07:23 -0700 (PDT) Subject: os.path.dirname(sys.argv[0]) always returns nothing References: <9797b629-3fba-4b90-920f-e426683599e1@a12g2000vbf.googlegroups.com> <99osqsFk1aU1@mid.individual.net> Message-ID: On Aug 2, 12:57?am, Gregory Ewing wrote: > Thijs Engels wrote: > > argv[0] returns the name of the current file (string), but no path > > information if I recall correct. > > It's the path that was used to specify the script by whatever > launched it, so it could be either absolute or relative to > the current directory. > > -- > Greg >From the docs there are a couple of special cases: "If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string." So if you're running in a python interpreter compiled into an executable which doesn't initialise argv, that's another case where things won't go as expected. That's probably not relevant in this case, but I've certainly been bitten by it in the past. From ulrich.eckhardt at dominolaser.com Tue Aug 9 10:26:01 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 09 Aug 2011 16:26:01 +0200 Subject: How to solve this problem References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: Johny wrote: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? > What software must I install so that I can connect and control that > client from outside? How is that a Python problem? Ask your network admin to configure something like port forwarding. Also, take a look at Eric S. Raymond's essay on asking smart questions, there are at least three things detailed there which you are doing wrong and where you are standing in your own way. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From gordon at panix.com Tue Aug 9 10:26:13 2011 From: gordon at panix.com (John Gordon) Date: Tue, 9 Aug 2011 14:26:13 +0000 (UTC) Subject: How to solve this problem References: <81a681e7-0be1-4edc-9e27-b492e8b6371f@a17g2000yqk.googlegroups.com> Message-ID: In <81a681e7-0be1-4edc-9e27-b492e8b6371f at a17g2000yqk.googlegroups.com> Johny writes: > I have a client that is a part of a local network.This client has a > local address( not public).Is there a way how I can connect to this > client from outside world? When you say the client's address is "not public", what do you mean exactly? Can the client initiate connections to the outside network? Is the client behind a firewall? > What software must I install so that I can connect and control that > client from outside? Perhaps you should ask your network administrators. And what does this question have to do with python? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ethan at stoneleaf.us Tue Aug 9 12:34:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 09 Aug 2011 09:34:23 -0700 Subject: __all__ Message-ID: <4E41618F.5010105@stoneleaf.us> Greetings! Does anyone know/recall the original purpose of __all__? I had thought it was primarily to specify what would be imported when `from ... import *` was executed, such as for tk; today, it seems it is also used to specify the API for the module, and so the help() subsystem will only provide details for those items found in __all__. The issue I'm having with this is that there are roughly a dozen items I would like to make available via the `import *` mechanism in my dbf module, and another dozen that, while part of the public API, don't need to be available via an `import *`. History lessons, as well as ideas, welcomed! ~Ethan~ From steve+comp.lang.python at pearwood.info Tue Aug 9 12:57:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 02:57:40 +1000 Subject: __all__ References: Message-ID: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > Greetings! > > Does anyone know/recall the original purpose of __all__? To customise the names available for `from ... import *`: http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > I had thought it was primarily to specify what would be imported when > `from ... import *` was executed, such as for tk; Yes, that was the original use. If __all__ is not defined, Python will import everything that doesn't start with an underscore. > today, it seems it is > also used to specify the API for the module, and so the help() subsystem > will only provide details for those items found in __all__. The two meanings are assumed to be synonymous: names in the public API should be importable with *, and importable names should be in the public API. You can't specify "this can be imported with *, but isn't public" or "this is public, but not importable with *". http://docs.python.org/reference/simple_stmts.html#index-1090 Also, the behaviour of __all__ with packages may be slightly different: http://docs.python.org/tutorial/modules.html#index-1134 > The issue I'm having with this is that there are roughly a dozen items I > would like to make available via the `import *` mechanism in my dbf > module, and another dozen that, while part of the public API, don't need > to be available via an `import *`. You have to choose both, or neither, but you can't have just one. -- Steven From manuel.graune at koeln.de Tue Aug 9 12:59:09 2011 From: manuel.graune at koeln.de (Manuel Graune) Date: Tue, 09 Aug 2011 18:59:09 +0200 Subject: numpy/scipy: calculate definite integral of sampled data Message-ID: <87ty9qttb6.fsf@uriel.graune.org> Hi everyone, to calculate the definite integral of a function or an array of sampled data scipy provides (among others) the quad and trapz functions. So it is possible to compute e. g. the definite integral of cos(t) over some range by doing definite_integral= scipy.integrate.quad(cos,lower_limit,upper_limit) or definite_integral= scipy.integrate.trapz(some_array). Now, if I want to plot cos(t) and the integral of cos(t) from 0 to t in a graph, the necessary array can be calculated by: @numpy.vectorize def intfunc(fnc,upper_limit): return scipy.integrate.quad(fnc,0.0,upper_limit) definite_inegral= intfunc(cos,t) which seems (whithout knowing the actual code) a bit wasteful and slow but is relatively concise. Now for my question: scipy provides e. g. the trapz-function to calculate definite integral of a complete array of sampled data. However, I have no idea how to get achieve the same as above for sampled data (apart from manually iterating in a for-loop). Is there a function somewhere which delivers an array of the definite integrals for each of the data-points in an array? Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 From chichimeco at gmail.com Tue Aug 9 13:02:25 2011 From: chichimeco at gmail.com (Antonio Vera) Date: Tue, 9 Aug 2011 10:02:25 -0700 (PDT) Subject: Passing every element of a list as argument to a function Message-ID: Hi!, I have a very simple syntax question. I want to evaluate a library function f receiving an arbitrary number of arguments (like itertools.product), on the elements of a list l. This means that I want to compute f(l[0],l[1],...,l[len(l)-1]). Is there any operation "op" such that f(op(l)) will give the sequence of elements of l as arguments to f? Thanks for your time. Best, Antonio From Tim.Arnold at sas.com Tue Aug 9 13:07:01 2011 From: Tim.Arnold at sas.com (Tim Arnold) Date: Tue, 09 Aug 2011 13:07:01 -0400 Subject: multiprocessing timing issue Message-ID: Hi, I'm having problems with an empty Queue using multiprocessing. The task: I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. I'm using multiprocessing to do the data-gathering simultaneously. Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. My problem is that sometimes the Queue is empty and I guess it's because the get_data() method takes a lot of time. I've used multiprocessing before, but never with a Queue like this. Any notes or suggestions are very welcome. The task starts off with: Reporter(chapters).report() thanks, --Tim Arnold from Queue import Empty from multiprocessing import Process, Queue def run_mp(objects,fn): q = Queue() procs = dict() for obj in objects: procs[obj['name']] = Process(target=fn, args=(obj,q)) procs[obj['name']].start() return q class Reporter(object): def __init__(self, chapters): self.chapters = chapters def report(self): q = run_mp(self.chapters, self.get_data) for i in range(len(self.chapters)): try: data = q.get(timeout=30) except Empty: print 'Report queue empty at %s' % (i) else: self.update_report(data) def get_data(self, chapter, q): data = expensive_calculations() q.put(data) def update_report(self, data): db connection, etc. From rosuav at gmail.com Tue Aug 9 13:29:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Aug 2011 18:29:16 +0100 Subject: Passing every element of a list as argument to a function In-Reply-To: References: Message-ID: On Tue, Aug 9, 2011 at 6:02 PM, Antonio Vera wrote: > Hi!, > I have a very simple syntax question. I want to evaluate a library > function f receiving an arbitrary number of arguments (like > itertools.product), on the elements of a list l. This means that I > want to compute f(l[0],l[1],...,l[len(l)-1]). > > Is there any operation "op" such that f(op(l)) will give the sequence > of elements of l as arguments to f? Yep! f(*l) Chris Angelico From irmen at -NOSPAM-xs4all.nl Tue Aug 9 13:57:30 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Tue, 09 Aug 2011 19:57:30 +0200 Subject: Object Diffs In-Reply-To: References: Message-ID: <4e41750a$0$23871$e4fe514c@news2.news.xs4all.nl> On 08-08-11 21:50, Croepha wrote: > Hello Python list: > > I am doing research into doing network based propagation of python > objects. In order to maintain network efficiency. I wan't to just > send the differences of python objects, I was wondering if there > was/is any other research or development in this area? I was thinking > that I could look at how pickle works an implement a diff system > there, or I could actually create a pickle of the object and then use > difflib to compare the flattened text... > > Ideas, or comments welcome > No Python code, but you may want to have a look at the DeltaCompressor of the Kryo serializer (written for Java). http://code.google.com/p/kryo/ (disclaimer: I haven't used it, just read a little bit about it) Irmen From ramit.prasad at jpmorgan.com Tue Aug 9 16:11:58 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 9 Aug 2011 16:11:58 -0400 Subject: Passing every element of a list as argument to a function In-Reply-To: References: Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA772C069@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of Antonio Vera Sent: Tuesday, August 09, 2011 12:02 PM To: python-list at python.org Subject: Passing every element of a list as argument to a function Hi!, I have a very simple syntax question. I want to evaluate a library function f receiving an arbitrary number of arguments (like itertools.product), on the elements of a list l. This means that I want to compute f(l[0],l[1],...,l[len(l)-1]). Is there any operation "op" such that f(op(l)) will give the sequence of elements of l as arguments to f? Thanks for your time. Best, Antonio -- http://mail.python.org/mailman/listinfo/python-list op(*l) for a list (or positional arguments). If you are trying to pass named keyword arguments then you must pass it a dictionary { 'keywordName' : 'value' } Example: >>>def F(name=None): pass >>>F(**{'name':'boo'}) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ursusmaximus at gmail.com Tue Aug 9 17:17:43 2011 From: ursusmaximus at gmail.com (Ron) Date: Tue, 9 Aug 2011 14:17:43 -0700 (PDT) Subject: What's in a name? References: <4E3379A1.5040607@gmail.com> <4E342A2C.8090007@stoneleaf.us> <87r555lvwi.fsf@benfinney.id.au> <4E361F36.4030802@gmail.com> Message-ID: On Aug 1, 10:11?am, Andrew Berg wrote: > Hmm.... > How about Rainbow Video Encoder Wrapper (Rainbow View for short - RView > is taken, possibly multiple times)? > I added an arbitrary word to a generic name, and the result doesn't seem > to be taken by anything software-related. It wraps more than just video > encoders (in fact, x264 will likely be the only one it wraps until it's > matured quite a bit :P ), but I didn't want the name to get too long. > The module itself will likely be called just rainbow.py. > > -- > CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 > PGP/GPG Public Key ID: 0xF88E034060A78FCB Andrew How about SuperMux with a command line interface called Cyclops and a GUI fornt end called VisualMux From pwoolcoc at gmail.com Tue Aug 9 17:42:28 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Tue, 9 Aug 2011 17:42:28 -0400 Subject: __all__ In-Reply-To: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: The gurus will have to correct me if this is not an accepted practice, but I know some projects (Fabric is the one that comes to mind) will define a submodule specifically for the 'from blah import *' situation. The submodule would be called "api", or something like that, so you can do: 'from mymodule.api import *' to separate the items you want to include in your public api, while still keeping other names importable by 'import blah' On Aug 9, 2011 1:00 PM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Ethan Furman wrote: > >> Greetings! >> >> Does anyone know/recall the original purpose of __all__? > > To customise the names available for `from ... import *`: > > http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > > >> I had thought it was primarily to specify what would be imported when >> `from ... import *` was executed, such as for tk; > > Yes, that was the original use. If __all__ is not defined, Python will > import everything that doesn't start with an underscore. > > >> today, it seems it is >> also used to specify the API for the module, and so the help() subsystem >> will only provide details for those items found in __all__. > > The two meanings are assumed to be synonymous: names in the public API > should be importable with *, and importable names should be in the public > API. You can't specify "this can be imported with *, but isn't public" > or "this is public, but not importable with *". > > http://docs.python.org/reference/simple_stmts.html#index-1090 > > > Also, the behaviour of __all__ with packages may be slightly different: > > http://docs.python.org/tutorial/modules.html#index-1134 > > >> The issue I'm having with this is that there are roughly a dozen items I >> would like to make available via the `import *` mechanism in my dbf >> module, and another dozen that, while part of the public API, don't need >> to be available via an `import *`. > > You have to choose both, or neither, but you can't have just one. > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Tue Aug 9 17:43:01 2011 From: gelonida at gmail.com (Gelonida N) Date: Tue, 09 Aug 2011 23:43:01 +0200 Subject: just for fun: make a class (not its instances) iterable Message-ID: Hi, I am just curious. There is no real use case: If I have a class and I want that its instances are iterable I can just add a class metohod named __iter__() example: class MyClass(object): def __iter__(self): for val in range(10): yield val this allows me to do: myobj = MyClass() for val in myobj: print val Now I wondered whether there is any way to implement a class such, that I can write for val in MyClass: print val I know I can implement a classmethod (e.g myclassmethod() ) and write: for val in MyClass.myclassmethod(): print val but I wondered whether classed can be made iterable Thanks in advance for your answers. From ckaynor at zindagigames.com Tue Aug 9 17:51:31 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 9 Aug 2011 14:51:31 -0700 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: You can using metaclasses (untested): >>>class MyMetaClass(type): >>> def __iter__(self): >>> return [1, 2, 3, 4] >>>class MyClass(object): >>> __metaclass__ = MyMetaClass >>>for value in MyClass: >>> print value 1 2 3 4 Chris On Tue, Aug 9, 2011 at 2:43 PM, Gelonida N wrote: > Hi, > > I am just curious. There is no real use case: > > If I have a class and I want that its instances are iterable I can just > add a class metohod named __iter__() > > > example: > > class MyClass(object): > def __iter__(self): > for val in range(10): > yield val > > > this allows me to do: > myobj = MyClass() > for val in myobj: > print val > > > Now I wondered whether there is any way to implement a class such, that > I can write > > > for val in MyClass: > print val > > I know I can implement a classmethod (e.g myclassmethod() ) and write: > > for val in MyClass.myclassmethod(): > print val > > but I wondered whether classed can be made iterable > > Thanks in advance for your answers. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Aug 9 18:20:48 2011 From: nagle at animats.com (John Nagle) Date: Tue, 09 Aug 2011 15:20:48 -0700 Subject: Complex sort on big files In-Reply-To: References: <062306c6-3ee6-43ce-936f-ca9cc0f013c9@eb9g2000vbb.googlegroups.com> Message-ID: <4e41b2cd$0$2138$742ec2ed@news.sonic.net> On 8/6/2011 10:53 AM, sturlamolden wrote: > On Aug 1, 5:33 pm, aliman wrote: > >> I've read the recipe at [1] and understand that the way to sort a >> large file is to break it into chunks, sort each chunk and write >> sorted chunks to disk, then use heapq.merge to combine the chunks as >> you read them. > > Or just memory map the file (mmap.mmap) and do an inline .sort() on > the bytearray (Python 3.2). With Python 2.7, use e.g. numpy.memmap > instead. If the file is large, use 64-bit Python. You don't have to > process the file in chunks as the operating system will take care of > those details. > > Sturla No, no, no. If the file is too big to fit in memory, trying to page it will just cause thrashing as the file pages in and out from disk. The UNIX sort program is probably good enough. There are better approaches, if you have many gigabytes to sort, (see Syncsort, which is a commercial product) but few people need them. John Nagle From bthate at gmail.com Tue Aug 9 19:48:26 2011 From: bthate at gmail.com (Bart Thate) Date: Tue, 9 Aug 2011 16:48:26 -0700 (PDT) Subject: ANNOUNCING GOZERBOT 0.9.3 BETA1 Message-ID: <9a528c8a-4be8-4d06-952a-92a98a6d1069@a27g2000yqc.googlegroups.com> Hi world and every living thing on it ! I just want to give a headsup to the fact that i released the first beta of GOZERBOT 0.9.3. This release brings in a lot of bug fixes, so please try it out ;] Download is at http://gozerbot.googlecode.com, please if you find problems with the bot file a ticket on http://code.google.com/p/gozerbot/issues/list. Otherwise email me at bthate at gmail.com or check channel #dunkbots on irc.freenode.net, thnx ! feedback is very much appreciated ;] I also want to say sorry to my korean brothers and sisters, i have no evil intend with GOZERBOT even if you might read that into my announcements, i'll give the reason for the name below .. it is taken from the dutch language. Peace ! GOZERBOT name origin ==================== 23:37 < dunker> !tr nl en 1) Bargoense kerel 2) Bink 3) Gast 4) Goser 5) Joch 6) Jongen 7) Ker 8) Kerel 9) Kerel (bargoens) 10) Knaap 11) Knakker 12) Knul 13) Man 14) Persoonsbenaming 15) Vent 23:37 < jsonbot> 1) Bargoens guy 2) Bink 3) Guest 4) Goser 5) Jochberg 6) Girl 7) Ker 8) Guy 9) Dude (slang) 10) Knaap 11) bloke 12) Lad 13) F 14) Name Person 15) Vent ?? 1) Bargoens ?? 2) ?? 3) ??? 4) Goser 5) Jochberg 6) ?? 7) ?? 8) ?? 9) ?? (? ?) 10) Knaap 11) ? 12) ?? 13) F 14) ?? ? 15) ?? About GOZERBOT: GOZERBOT is a channel bot that aids with conversation in irc channels and jabber conference rooms. its mainly used to send notifications (RSS, nagios, etc.) and to have custom commands made for the channel. More then just a channel bot GOZERBOT aims to provide a platform for the user to program his own bot and make it into something thats usefull. This is done with a plugin structure that makes it easy to program your own plugins. But GOZERBOT comes with some batteries included, there are now over 100 plugins already written and ready for use. From steve+comp.lang.python at pearwood.info Tue Aug 9 19:54:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 09:54:25 +1000 Subject: just for fun: make a class (not its instances) iterable References: Message-ID: <4e41c8b3$0$29993$c3e8da3$5496439d@news.astraweb.com> Gelonida N wrote: > Now I wondered whether there is any way to implement a class such, that > I can write > > > for val in MyClass: > print val One way to make an object iterable (there are others) is to add an __iter__ method to the object's class. Unlike in some languages, classes in Python are themselves objects, which means that classes themselves have a class, "type". The class of a class is called the metaclass. So to make the class object (the instance) iterable, use a metaclass. >>> class MetaIter(type): ... def __iter__(self): ... for name in 'abcd': ... yield getattr(self, name) ... >>> class MyClass(object): ... __metaclass__ = MetaIter ... # In Python 3, write as class MyClass(object, metaclass=MetaIter) ... a, b, c, d, = 42, 23, -99, "Surprise!" ... >>> >>> for obj in MyClass: ... print obj ... 42 23 -99 Surprise! -- Steven From tjreedy at udel.edu Tue Aug 9 20:11:29 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:11:29 -0400 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: On 8/9/2011 5:43 PM, Gelonida N wrote: > Now I wondered whether there is any way to implement a class such, that > I can write > > for val in MyClass: > print val And what are the items in a class that you expect that to produce? I am pretty sure you can already do for val in MyClass.__dict__ (or __dict__.items()) -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 9 20:13:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:13:16 -0400 Subject: numpy/scipy: calculate definite integral of sampled data In-Reply-To: <87ty9qttb6.fsf@uriel.graune.org> References: <87ty9qttb6.fsf@uriel.graune.org> Message-ID: numpy/scipy questions are best asked on the numpy/scipy user lists. -- Terry Jan Reedy From python.list at tim.thechases.com Tue Aug 9 20:29:30 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Aug 2011 19:29:30 -0500 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: References: Message-ID: <4E41D0EA.1070000@tim.thechases.com> On 08/09/2011 07:11 PM, Terry Reedy wrote: > On 8/9/2011 5:43 PM, Gelonida N wrote: >> Now I wondered whether there is any way to implement a class such, that >> I can write >> >> for val in MyClass: >> print val > > And what are the items in a class that you expect that to produce? I can see doing something like class MyClass: instances = [] def __init__(self, *args, **kwargs): self.instances.append(self) # ... a = MyClass(...) b = MyClass(...) for instance in MyClass: do_something(instance) I was curious/surprised to find that class MyClass: instances = [] @classmethod def __iter__(cls): for i in cls.instances: yield i def __init__(self): self.instances.append(self) didn't work as I expected since MyClass then has an __iter__ property that should know about the class. -tkc From tjreedy at udel.edu Tue Aug 9 20:42:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Aug 2011 20:42:41 -0400 Subject: just for fun: make a class (not its instances) iterable In-Reply-To: <4E41D0EA.1070000@tim.thechases.com> References: <4E41D0EA.1070000@tim.thechases.com> Message-ID: On 8/9/2011 8:29 PM, Tim Chase wrote: > On 08/09/2011 07:11 PM, Terry Reedy wrote: >> On 8/9/2011 5:43 PM, Gelonida N wrote: >>> Now I wondered whether there is any way to implement a class such, that >>> I can write >>> >>> for val in MyClass: >>> print val >> >> And what are the items in a class that you expect that to produce? > > I can see doing something like > > class MyClass: > instances = [] > def __init__(self, *args, **kwargs): > self.instances.append(self) > # ... > > a = MyClass(...) > b = MyClass(...) > for instance in MyClass: for instance in MyClass.instances: > do_something(instance) > > I was curious/surprised to find that > > class MyClass: > instances = [] > @classmethod > def __iter__(cls): > for i in cls.instances: > yield i > def __init__(self): > self.instances.append(self) > > didn't work as I expected since MyClass then has an __iter__ property > that should know about the class. I strongly suspect that iter(ob) starts the lookup for __iter__ with type(ob). I would also expect for instance in MyClass.__iter__() to work, but that is a waste since instances is already iterable. -- Terry Jan Reedy From etay.rosenzweig at gmail.com Tue Aug 9 23:00:02 2011 From: etay.rosenzweig at gmail.com (Etay) Date: Tue, 9 Aug 2011 20:00:02 -0700 (PDT) Subject: input file format Message-ID: <309782ab-d8c8-4b60-bce3-15457c66a5fb@i15g2000vbk.googlegroups.com> Hi all, I am trying to write a Python script which will read the output file of a numerical model, and then copy some of that information into a new file in a new format. The output file of the numerical model is basically 54321 # number of points 1234 # number of time steps __a whole bunch of lines with info I don't need__ [TIMESTAMP] 001 1 10 10 2 10 11 3 11 11 etc... in the format: Point# X Y for all 54321 points [TIMESTAMP] 002 1 13 13 2 14 13 etc... for all 54321 points and so for each of the 1234 time steps I would like to be able to save the number of points and time steps, then move all the time stamped data into a new file, but it needs to be written there as [ Pt# Y X ]. Is there some simple way to skip over the lines I don't need, and then inform Python about the format of the lines with the data I do need within a loop? Thanks! Etay From steve+comp.lang.python at pearwood.info Tue Aug 9 23:48:04 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 13:48:04 +1000 Subject: input file format References: <309782ab-d8c8-4b60-bce3-15457c66a5fb@i15g2000vbk.googlegroups.com> Message-ID: <4e41ff77$0$29995$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Aug 2011 01:00 pm Etay wrote: > Is there some simple way to skip over the lines I don't need, and then > inform Python about the format of the lines with the data I do need > within a loop? Yes. It's called "programming" :) f = open('some file') for line in f: if some_condition(line): continue # skip the line process(line) f.close() some_condition can be anything you like. You just have to write the code to make it so. -- Steven From lanyjie at yahoo.com Wed Aug 10 00:42:36 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 9 Aug 2011 21:42:36 -0700 (PDT) Subject: allow line break at operators Message-ID: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Hi all, When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: #the old way x = 1+2+3+4+\ ????? 1+2+3+4 #the new way x = 1+2+3+4+ #line continues as it is clearly unfinished ????? 1+2+3+4 Of course, the dot operator is also included, which may facilitate method chaining: x = svg.append( 'circle' ). ????? r(2).cx(1).xy(1). ????? foreground('black').bkground('white') Thoughts? Yingjie From clp2 at rebertia.com Wed Aug 10 00:55:33 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 21:55:33 -0700 Subject: allow line break at operators In-Reply-To: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: On Tue, Aug 9, 2011 at 9:42 PM, Yingjie Lan wrote: > Hi all, > > When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: > > #the old way > > x = 1+2+3+4+\ > ????? 1+2+3+4 > > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > ????? 1+2+3+4 # the currently allowed way x = (1+2+3+4+ 1+2+3+4) # note the parentheses I think this is sufficient. > Of course, the dot operator is also included, which may facilitate method chaining: > > x = svg.append( 'circle' ). > ????? r(2).cx(1).xy(1). > ????? foreground('black').bkground('white') Python does not particularly endorse method chaining; it's why list.sort(), list.append(), and similar methods of built-in types return None rather than self. Also, I dislike this for the dot operator especially, as it can obscure whether a method call or a function call is taking place. Cheers, Chris -- http://rebertia.com From lanyjie at yahoo.com Wed Aug 10 02:05:56 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 9 Aug 2011 23:05:56 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: <1312956356.91952.YahooMailNeo@web121503.mail.ne1.yahoo.com> On Tue, Aug 9, 2011 at 9:42 PM, Yingjie Lan wrote: > Hi all, > > When writing a long expresion, one usually would like to break it into multiple lines. Currently, you may use a '\' to do so, but it looks a little awkward (more like machine-oriented thing). Therefore I start wondering why not allow line breaking at an operator, which is the standard way of breaking a long expression in publication? Here is an example: > > #the old way > > x = 1+2+3+4+\ > ????? 1+2+3+4 > > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > ????? 1+2+3+4 :# the currently allowed way :x = (1+2+3+4+ :? ? 1+2+3+4) :# note the parentheses : :I think this is sufficient. That works, but not in the most natural way--the way people are customed to...why require a pair of parenthis when we can do without them? Also, the new way does not affect the old ways of doing things at all, it is fully backward compatible. So this just offers a new choice. > Of course, the dot operator is also included, which may facilitate method chaining: > > x = svg.append( 'circle' ). > ????? r(2).cx(1).xy(1). > ????? foreground('black').bkground('white') :Also, I dislike this for the dot operator especially, as it can :obscure whether a method call or a function call is taking place. Again, this only offers a new choice, and does not force anybody to do it this way. cheers, Yingjie From dannwong at cisco.com Wed Aug 10 02:38:56 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:38:56 -0500 Subject: subprocess.Popen and thread module In-Reply-To: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Hi All, I'm trying to execute some external commands from multiple database. I'm using threads and subprocess.Popen ( from docs, all the popen* functions are deprecated and I was told to use subprocess.Popen) to execute the external commands in parallel, but the commands seems to hang. My question is: Is subprocess.Popen thread safe? If not, what other module should I use to perform a system call? I also, want to log stdout and stderr to a file. Thanks. From clp2 at rebertia.com Wed Aug 10 02:47:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 23:47:04 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) wrote: > Hi All, > ? I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. What's your Popen() call look like? Cheers, Chris From dannwong at cisco.com Wed Aug 10 02:48:36 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:48:36 -0500 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Hi Chris, Here is the code, try: cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) status = cmd_output.wait() print "In load status is: %s" % status + "\n" except: print "Error Executing %s" % command + "\n" -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 09, 2011 11:47 PM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: subprocess.Popen and thread module On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) wrote: > Hi All, > ? I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. What's your Popen() call look like? Cheers, Chris From clp2 at rebertia.com Wed Aug 10 02:53:29 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Aug 2011 23:53:29 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: > On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) > wrote: >> Hi All, >> ? I'm trying to execute some external commands from multiple database. >> I'm using threads and subprocess.Popen ( from docs, all the popen* >> functions are deprecated and I was told to use subprocess.Popen) to >> execute the external commands in parallel, but the commands seems to >> hang. > > What's your Popen() call look like? On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) wrote: > ? ?try: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > ? ? ? ?status = cmd_output.wait() Er, did you read the warning about Popen.wait() in the docs? (emphasis added): """ Popen.wait() Wait for child process to terminate. Set and return returncode attribute. Warning: ***This will deadlock*** when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. """ ? http://docs.python.org/library/subprocess.html#subprocess.Popen.wait Cheers, Chris From dannwong at cisco.com Wed Aug 10 02:56:38 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Wed, 10 Aug 2011 01:56:38 -0500 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: I did read that portion of the doc, then I change it to communicate and it still hangs. So I reverted back to "wait" while launching one thread to see if I could isolate the problem, but it still hangs regardless of using "wait" or "communicate". -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 09, 2011 11:53 PM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: subprocess.Popen and thread module > On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) > wrote: >> Hi All, >> ? I'm trying to execute some external commands from multiple database. >> I'm using threads and subprocess.Popen ( from docs, all the popen* >> functions are deprecated and I was told to use subprocess.Popen) to >> execute the external commands in parallel, but the commands seems to >> hang. > > What's your Popen() call look like? On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) wrote: > ? ?try: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > ? ? ? ?status = cmd_output.wait() Er, did you read the warning about Popen.wait() in the docs? (emphasis added): """ Popen.wait() Wait for child process to terminate. Set and return returncode attribute. Warning: ***This will deadlock*** when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. """ ? http://docs.python.org/library/subprocess.html#subprocess.Popen.wait Cheers, Chris From sungsuha at gmail.com Wed Aug 10 03:01:10 2011 From: sungsuha at gmail.com (Seung =?utf-8?b?U29vLA==?= Ha) Date: Wed, 10 Aug 2011 07:01:10 +0000 (UTC) Subject: Run clang static analyzer on Python 3.30a Message-ID: Hello, I just ran the clang static analyzer on Python. I'm very new to this, so please bear with me as a describe the exact steps I took. 1. hg clone of python 2. scan-build ./configure --with-pydebug 3. scan-build make -s -j4 4. scan-view /tmp/scan-build-2011-08-10-1/ It shows 6 bugs and the report page even has a friendly option to report the bug. I'm just starting to learn C and I cannot judge whether they are worth reporting. Should I? I am aware of the issue tracker and how to use it. What I'm curious is what information I should provide, considering the fact that my skills (for now) is limited to copy and paste. What should I do next? (my system Ubuntu 11.04 x86_64 on AMD Phenom II X4 955) Thanks. From clp2 at rebertia.com Wed Aug 10 03:36:18 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 00:36:18 -0700 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: > From: Chris Rebert >> On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) >> wrote: >>> Hi All, >>> ? I'm trying to execute some external commands from multiple database. >>> I'm using threads and subprocess.Popen ( from docs, all the popen* >>> functions are deprecated and I was told to use subprocess.Popen) to >>> execute the external commands in parallel, but the commands seems to >>> hang. >> >> What's your Popen() call look like? > > On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) > wrote: >> ? ?try: >> ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> ? ? ? ?status = cmd_output.wait() > > Er, did you read the warning about Popen.wait() in the docs? (emphasis added): On Tue, Aug 9, 2011 at 11:56 PM, Danny Wong (dannwong) wrote: > I did read that portion of the doc, then I change it to communicate and it still hangs. So I reverted back to "wait" while launching one thread to see if I could isolate the problem, but it still hangs regardless of using "wait" or "communicate". Since you want to log the output to a file, have you tried: logfile = open("path/to/file", 'r') proc = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=logfile, stderr=subprocess.STDOUT) status = proc.wait() or similar? Cheers, Chris -- Damn Outlook/Exchange and its "On Behalf Of"! http://rebertia.com From steve+comp.lang.python at pearwood.info Wed Aug 10 04:32:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 10 Aug 2011 18:32:05 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> Message-ID: <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Aug 2011 04:05 pm Yingjie Lan wrote: > :# the currently allowed way > :x = (1+2+3+4+ > :1+2+3+4) > :# note the parentheses > : > :I think this is sufficient. > > That works, but not in the most natural way--the way people are customed > to...why require a pair of parenthis when we can do without them? Because it is better to be explicit that the line is still open. An opening parenthesis or bracket that hasn't been closed is an explicit sign that the line is still open. An operator is not. > Also, > the new way does not affect the old ways of doing things at all, it is > fully backward compatible. So this just offers a new choice. You say that as if having more choices is always good. It isn't. More choices means more for people to learn, more complicated parser, more options to consider, and more likelihood that errors will fail to raise SyntaxError and instead go on to silently do the wrong thing. A new choice should only be accepted when there is a clear and obvious benefit, not merely because it will provide more choice. Python is a programming language, not an ice cream shop. >> Of course, the dot operator is also included, which may facilitate method >> chaining: >> >> x = svg.append( 'circle' ). >> r(2).cx(1).xy(1). >> foreground('black').bkground('white') If you are chaining six dots like that, you are in gross violation of the Law Of Demeter. That is poor code, and should be discouraged, not encouraged. > > :Also, I dislike this for the dot operator especially, as it can > :obscure whether a method call or a function call is taking place. > > Again, this only offers a new choice, and does not force anybody to do it > this way. But it does force people to read it, because some people will use it, and so others will have to suffer for their poor judgement. -- Steven From rosuav at gmail.com Wed Aug 10 04:39:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 09:39:55 +0100 Subject: allow line break at operators In-Reply-To: <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 9:32 AM, Steven D'Aprano wrote: >>> Of course, the dot operator is also included, which may facilitate method >>> chaining: >>> >>> x = svg.append( 'circle' ). >>> r(2).cx(1).xy(1). >>> foreground('black').bkground('white') > > If you are chaining six dots like that, you are in gross violation of the > Law Of Demeter. That is poor code, and should be discouraged, not > encouraged. I would only accept that this is poor code IF there is a viable alternative, such as: x = svg.append(circle(r=2,cx=1,xy=1,foreground='black',bkground='white')) This would, imho, be a more Pythonic way to do it. But if this isn't available, and if the methods already return self, then I see nothing wrong with chaining. It's a handy way of getting additional mileage out of lambdas and list comps when writing one-liners. :) (Cue long thread about whether or not one-liners are Pythonic.) Chris Angelico From ranganayakirangs at gmail.com Wed Aug 10 05:10:29 2011 From: ranganayakirangs at gmail.com (ranganayaki rangs) Date: Wed, 10 Aug 2011 02:10:29 -0700 (PDT) Subject: http://123maza.com/65/share858/ Message-ID: http://123maza.com/65/share858/ From t at jollybox.de Wed Aug 10 05:38:46 2011 From: t at jollybox.de (Thomas Jollans) Date: Wed, 10 Aug 2011 11:38:46 +0200 Subject: Restricted attribute writing In-Reply-To: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: <4E4251A6.7050407@jollybox.de> On 07/08/11 17:35, John O'Hagan wrote: > I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. > > My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is a modulo remainder. I need to be able to write to it like a normal list, but want to ensure it is only possible to do so without changing that format. > > Below is a what I eventually came up with; a container class called OrderElement for the inner lists, and subclass of list called Order for the main attribute, which is a property of the main class, simplified below as SeqSim. It works, but seems like a hell of a lot of code for a simple idea. I'm interested in ideas for simpler solutions, and general advice on how to do this kind of thing in a straightforward way. What I think you're looking for is properties: http://docs.python.org/py3k/library/functions.html#property So: with a property, channel getting and setting through functions that can check the value for validity. Secondly, use tuples instead of lists where possible: they're not mutable, which makes controlling their value a lot easier. If your attribute is a list that users may append elements to, consider adding an addelement(tpl) method to your class that checks the value and appends it to the list. Lastly, consider the option of not checking vigorously at all at that point: If the value is invalid, it will raise an exception later, when it is used. Depending on what you're doing, this might be all the checking you need. If you're going to serialise the data, or if you want to use the property setter to check user input directly, that's probably not a strong option. Thomas > > > class OrderElement(): > """Container class which can only hold two integers > the first of which is a modulo of the 'length' arg""" > def __init__(self, lis, length): > self.__data = [None, None] > self.__length=length > self[:] = lis > > def __setitem__(self, index, item): > if isinstance(index, slice): > inds = range(*index.indices(2)) > for k, v in enumerate(item): > self[inds[k]] = v > elif isinstance(item, int): > if index == 0: > item %= self.__length > self.__data[index] = item > else: > raise TypeError("OrderElement takes two integers") > > def __getitem__(self, index): > return self.__data[index] > > > class Order(list): > """Can only contain OrderElements""" > def __init__(self, lis, length): > self.__length = length > self[:] = lis > > def __setitem__(self, index, item): > if isinstance(index, slice): > item = [i if isinstance(i, OrderElement) > else OrderElement(i, self.__length) > for i in item] > elif not isinstance(item, OrderElement): > item = OrderElement(item, self.__length) > list.__setitem__(self, index, item) > > def __getitem__(self, index): > """Ensure slices are of the same class""" > if isinstance(index, slice): > return self.__class__(list.__getitem__(self, index), > self.__length) > return list.__getitem__(self, index) > > > class SeqSim(): > """Just the relevant bits of the main class""" > def __init__(self, lis, length): > self.__order = Order(lis, length) > self.length = length > > @property > def order(self): > return self.__order > > @order.setter > def order(self, lis): > if not isinstance(lis, Order): > lis = Order(lis, self.length) > self.__order = lis > From dan at tombstonezero.net Wed Aug 10 05:56:20 2011 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 10 Aug 2011 09:56:20 +0000 (UTC) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 10 Aug 2011 18:32:05 +1000, Steven D'Aprano wrote: > Python is a programming language, not an ice cream shop. +1 QOTW How about a cheese shop? In terms of easier to read, I find code easier to read when the operators are at the beginnings of the lines (PEP 8 notwithstanding): x = (someobject.somemethod(object3, thing) + longfunctionname(object2) + otherfunction(value1, value2, value3)) I can see the "+" signs a lot easier there than at the end of some line, where it might be buried between two longer lines: x = (someobject.somemethod(object3, thing) + longfunctionname(object2) + otherfunction(value1, value2, value3)) -- Dan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Aug 10 06:09:52 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 10 Aug 2011 12:09:52 +0200 Subject: subprocess.Popen and thread module In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Am 10.08.2011 08:38 schrieb Danny Wong (dannwong): > Hi All, > I'm trying to execute some external commands from multiple database. > I'm using threads and subprocess.Popen ( from docs, all the popen* > functions are deprecated and I was told to use subprocess.Popen) to > execute the external commands in parallel, but the commands seems to > hang. > My question is: > Is subprocess.Popen thread safe? Do you really need threads here? As you just run those external commands (as far as I understand), it might be enough to start the commands, hold their object, read them out (maybe part for part) and then wait(). Thomas From rosuav at gmail.com Wed Aug 10 06:26:10 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 11:26:10 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers wrote: > In terms of easier to read, I find code easier to read when the operators > are at the beginnings of the lines (PEP 8 notwithstanding): > > ? ?x = (someobject.somemethod(object3, thing) > ? ? ? ? + longfunctionname(object2) > ? ? ? ? + otherfunction(value1, value2, value3)) > Without the parentheses, this is legal but (probably) useless; it applies the unary + operator to the return value of those functions. Putting the + at the end of the previous line at least prevents that, since most unary operators bind to the operand on the right; but there's still the potential for ambiguity. When line breaks are significant, they cannot be randomly inserted inside expressions. ChrisA From przemolicc at poczta.fm Wed Aug 10 07:17:54 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Wed, 10 Aug 2011 13:17:54 +0200 Subject: String concatenation - which is the fastest way ? Message-ID: <20110810111754.GD5045@host.pgf.com.pl> Hello, I'd like to write a python (2.6/2.7) script which connects to database, fetches hundreds of thousands of rows, concat them (basically: create XML) and then put the result into another table. Do I have any choice regarding string concatenation in Python from the performance point of view ? Since the number of rows is big I'd like to use the fastest possible library (if there is any choice). Can you recommend me something ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f2a0a From no at nowhere.net.no Wed Aug 10 07:26:38 2011 From: no at nowhere.net.no (TheSaint) Date: Wed, 10 Aug 2011 19:26:38 +0800 Subject: allow line break at operators References: Message-ID: Yingjie Lan wrote: > #the new way > x = 1+2+3+4+ #line continues as it is clearly unfinished > > 1+2+3+4 > Genrally I prefer this way. > Of course, the dot operator is also included, which may facilitate method > chaining: > > x = svg.append( 'circle' ). Dot-ended is to tiny thing that might cause oversights. *If* it'll be used as a secondary option I think it doesn't matter, otherwise *if* use as a compulsory writing mode I'd say it is pretty mistake prone. From duncan.booth at invalid.invalid Wed Aug 10 08:25:21 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2011 12:25:21 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. No, in some other languages it might be legal, but this is Python. without the parentheses it is a syntax error. -- Duncan Booth http://kupuguy.blogspot.com From k.sahithi2862 at gmail.com Wed Aug 10 08:25:56 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 10 Aug 2011 05:25:56 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: <4ca9c8fe-867c-471a-9c95-d883ecece545@y19g2000pre.googlegroups.com> HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html LATEST HOT TAPSEE KISSING STILLS http://southactresstou.blogspot.com/2011/06/tapsee.html KAJAL AGARWAL ROMANTIC STILLS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html TAMANNA BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/05/tamanna.html ANUSHKA SHETTY HOT SAREE STILLS http://southactresstou.blogspot.com/2011/06/anushka-shetty.html SNEHA RARE PHOTOS http://southactresstou.blogspot.com/2011/05/sneha.html NAMITHA HOT NAVEL SHOW http://southactresstou.blogspot.com/2011/05/namitha.html ILIYANA HOT WALLPAPERS http://southactresstou.blogspot.com/2011/05/iliyana.html PRIYAMANI LATEST SPICY PHOTOS http://southactresstou.blogspot.com/2011/05/priyamani.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From rosuav at gmail.com Wed Aug 10 08:32:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 13:32:06 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810111754.GD5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 12:17 PM, wrote: > Hello, > > I'd like to write a python (2.6/2.7) script which connects to database, fetches > hundreds of thousands of rows, concat them (basically: create XML) > and then put the result into another table. Do I have any choice > regarding string concatenation in Python from the performance point of view ? > Since the number of rows is big I'd like to use the fastest possible library > (if there is any choice). Can you recommend me something ? First off, I have no idea why you would want to create an XML dump of hundreds of thousands of rows, only to store it in another table. However, if that is your intention, list joining is about as efficient as you're going to get in Python: lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries xml=""+"".join(lst)+"" This sets xml to 'asdfqwerzxcv' which may or may not be what you're after. ChrisA From rosuav at gmail.com Wed Aug 10 08:42:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 13:42:30 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 1:25 PM, Duncan Booth wrote: > Chris Angelico wrote: > >> On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers >> wrote: >>> In terms of easier to read, I find code easier to read when the >>> operators are at the beginnings of the lines (PEP 8 notwithstanding): >>> >>> ? ?x = (someobject.somemethod(object3, thing) >>> ? ? ? ? + longfunctionname(object2) >>> ? ? ? ? + otherfunction(value1, value2, value3)) >>> >> >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. > > No, in some other languages it might be legal, but this is Python. > without the parentheses it is a syntax error. It would be parsed as three separate statements. The only reason it would be a syntax error would be because of the indentation, which is not what I'd call reliable; it happens to catch this case, because assignment doesn't allow subsequent lines to be indented, but nothing forces continuation lines to be indented. x = (5 +4) x = 5 +4 What we have is a strangeness that can arise when a programmer ignores something that is often insignificant; spare parentheses usually don't matter. Another potential danger is the similarity with tuple creation: x = (someobject.somemethod(object3, thing) ? ? + longfunctionname(object2) ? ? + otherfunction(value1, value2, value3),) This is a tuple with one element. Not too bad with the + operator, but imagine if everything's done with method chaining on . which results in the , being nearly indistinguishable. Not an insurmountable problem, but a potential risk. ChrisA From peterirbizon at gmail.com Wed Aug 10 08:42:31 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Wed, 10 Aug 2011 14:42:31 +0200 Subject: gtk STOCK_SAVE text in another language Message-ID: hello, I have slovak win but I would like to have english captions on pygtk STOCK_SAVE buttons. How can I set this? thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From doomsdaymine at gmail.com Wed Aug 10 08:44:25 2011 From: doomsdaymine at gmail.com (mike turner) Date: Wed, 10 Aug 2011 08:44:25 -0400 Subject: I need help/information on Freeze.py Message-ID: Hello all, How do you use freeze.py to freeze an application? I have an application built with pylons and I want to make it into a portable executable, is that possible? Thanks for the help. - mikey -------------- next part -------------- An HTML attachment was scrubbed... URL: From lanyjie at yahoo.com Wed Aug 10 08:58:24 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 05:58:24 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. :No, in some other languages it might be legal, but this is Python. :without the parentheses it is a syntax error. This discussion leads me to this question: Is it possible for python to allow free splitting of single-line statements without the backslashes, if we impose that expressions can only be split when it is not yet a finished expression? Note: splitting before closing parenthis, brace, or bracket can be viewed as special case of this more general rule. Yingjie From spsing07 at gmail.com Wed Aug 10 09:09:00 2011 From: spsing07 at gmail.com (spsing sing) Date: Wed, 10 Aug 2011 06:09:00 -0700 (PDT) Subject: hai go in mee t Message-ID: www.oneadds.info From lanyjie at yahoo.com Wed Aug 10 09:19:37 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 06:19:37 -0700 (PDT) Subject: allow line break at operators In-Reply-To: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> >> In terms of easier to read, I find code easier to read when the >> operators are at the beginnings of the lines (PEP 8 notwithstanding): >> >> ? ?x = (someobject.somemethod(object3, thing) >> ? ? ? ? + longfunctionname(object2) >> ? ? ? ? + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. If ';' are employed (required), truely free line-splitting should be OK, the operators may appear at the beginnings of the lines as you wish. Yingjie From przemolicc at poczta.fm Wed Aug 10 09:31:46 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Wed, 10 Aug 2011 15:31:46 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> Message-ID: <20110810133146.GE5045@host.pgf.com.pl> On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 12:17 PM, wrote: > > Hello, > > > > I'd like to write a python (2.6/2.7) script which connects to database, fetches > > hundreds of thousands of rows, concat them (basically: create XML) > > and then put the result into another table. Do I have any choice > > regarding string concatenation in Python from the performance point of view ? > > Since the number of rows is big I'd like to use the fastest possible library > > (if there is any choice). Can you recommend me something ? > > First off, I have no idea why you would want to create an XML dump of > hundreds of thousands of rows, only to store it in another table. > However, if that is your intention, list joining is about as efficient > as you're going to get in Python: > > lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries > xml=""+"".join(lst)+"" > > This sets xml to 'asdfqwerzxcv' which > may or may not be what you're after. Chris, since this process (XML building) is running now inside database (using native SQL commands) and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which will concat subset of the whole table (and then merge all of them at the end). Basically: - fetch all rows from the database (up to 1 million): what is recommended data type ? - spawn X python processes each one: - concat its own subset - merge the result from all the subprocesses This task is running on a server which has many but slow cores and I am trying to divide this task into many subtasks. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From gandalf at shopzeus.com Wed Aug 10 09:42:55 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 10 Aug 2011 15:42:55 +0200 Subject: SocketServer expceion after upgrading to 2.7 Message-ID: <4E428ADF.5020806@shopzeus.com> Exception happened during processing of request from ('80.99.165.122', 56069) Traceback (most recent call last): File "/usr/local/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "/usr/local/lib/python2.7/SocketServer.py", line 311, in process_request self.shutdown_request(request) File "/usr/local/lib/python2.7/SocketServer.py", line 459, in shutdown_request request.shutdown(socket.SHUT_WR) TypeError: shutdown() takes exactly 0 arguments (1 given) I get this error with a program, after upgrading to python 2.7. I'm using a program that is based on SocketServer and SimpleXMLRPCDispatcher. Any idea how to fix this? Thanks, Laszlo From claird271 at gmail.com Wed Aug 10 10:04:10 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 10 Aug 2011 07:04:10 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 10) Message-ID: <6bd9df46-2baf-448a-b51f-be726c55d4bb@t5g2000yqj.googlegroups.com> QOTW: "If an elegant solution doesn't occur to me right away, then I first compose the most obvious solution I can think of. Finally, I refactor it until elegance is either achieved or imagined." - Neil Cerutti, 2011-07-28 What is the real purpose of __all__? http://old.nabble.com/__all__-td32227593.html __set__ does not appear to work for class attributes: http://groups.google.com/group/comp.lang.python/t/72a346299a7eacf5/ Talking of class attributes: how to set up a docstring for them? http://old.nabble.com/Docstrings-and-class-Attributes-td32218039.html Using zip to separate a list of pairs into two lists: http://groups.google.com/group/comp.lang.python/t/98008a2c63b002fa/ Detecting object differences in order to propagate the changes over a network: http://old.nabble.com/Object-Diffs-ts32221405.html modules, classes, and functions: all appear to be different ways to execute a block of code; similarities and differences http://groups.google.com/group/comp.lang.python/t/79bc8b7d5267338a/ Replace all references to one object with another, is it possible? http://groups.google.com/group/comp.lang.python/t/32b67545254bdf37/ Ensure certain attributes, even if writable and modifiable, maintain certain invariants: http://groups.google.com/group/comp.lang.python/t/d23a48c858b2cb75/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From claird271 at gmail.com Wed Aug 10 10:04:11 2011 From: claird271 at gmail.com (Cameron Laird) Date: Wed, 10 Aug 2011 07:04:11 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 10) Message-ID: <008bd519-baa0-4f4f-95fd-f2035f2425c0@y8g2000vba.googlegroups.com> QOTW: "If an elegant solution doesn't occur to me right away, then I first compose the most obvious solution I can think of. Finally, I refactor it until elegance is either achieved or imagined." - Neil Cerutti, 2011-07-28 What is the real purpose of __all__? http://old.nabble.com/__all__-td32227593.html __set__ does not appear to work for class attributes: http://groups.google.com/group/comp.lang.python/t/72a346299a7eacf5/ Talking of class attributes: how to set up a docstring for them? http://old.nabble.com/Docstrings-and-class-Attributes-td32218039.html Using zip to separate a list of pairs into two lists: http://groups.google.com/group/comp.lang.python/t/98008a2c63b002fa/ Detecting object differences in order to propagate the changes over a network: http://old.nabble.com/Object-Diffs-ts32221405.html modules, classes, and functions: all appear to be different ways to execute a block of code; similarities and differences http://groups.google.com/group/comp.lang.python/t/79bc8b7d5267338a/ Replace all references to one object with another, is it possible? http://groups.google.com/group/comp.lang.python/t/32b67545254bdf37/ Ensure certain attributes, even if writable and modifiable, maintain certain invariants: http://groups.google.com/group/comp.lang.python/t/d23a48c858b2cb75/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From vacorama at gmail.com Wed Aug 10 10:18:46 2011 From: vacorama at gmail.com (ron) Date: Wed, 10 Aug 2011 07:18:46 -0700 (PDT) Subject: Segmentation Fault on exit References: Message-ID: <38f2d76e-057f-4d62-9012-e09c18639de9@t7g2000vbv.googlegroups.com> On Aug 6, 6:35?am, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But when I > import it in Python, I am able to work fine with it, but it gives a > segmentation fault while exiting. Following is the log: > > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ python > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import pyossim > > * Do some stuff * > >>> exit() > > Segmentation fault > vipul at vipul-laptop:~/ossim-svn/src/pyossim/swig$ > > Kindly help. > > Thanks and Regards, > Vipul Raheja Check out Valgrind. It's easy to set up, runs like gdb, but keeps track and flags any offending memory use at the c level. Then just need to find the calling python code. From peterirbizon at gmail.com Wed Aug 10 10:22:32 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Wed, 10 Aug 2011 16:22:32 +0200 Subject: problem with GTK language Message-ID: Hello, I have strange problem with gtk language in pygtk. When I run .py file it shows all gtk labels in my default windows language (slovak). But when I compile it with py2exe and run exe file all labels are in english. Why this happens? How can I define on program startup which language to use? I would like to choose between english and slovak. I tryed to set locals in my application but no luck. What am I doing wrong? thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at gmail.com Wed Aug 10 10:33:09 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:33:09 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> On Aug 5, 12:29?pm, Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? It's an unfortunate asymmetry in the descriptor protocol. You can write "class descriptors" with behaviour on get, but not on set. As others point out, metaclasses are an ugly way round this (particularly given that *basically* a class can only have one metaclass - so if you're inheriting from a class that already has a custom metaclass you can't use this technique). Michael Foord -- http://voidspace.org.uk/ From fuzzyman at gmail.com Wed Aug 10 10:36:20 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:36:20 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> Message-ID: <33a59af5-bdf9-4f37-8801-9f9ad1a778b7@w11g2000vbp.googlegroups.com> On Aug 5, 1:16?pm, Duncan Booth wrote: > Ryan wrote: > > In the context of descriptors, the __set__ method is not called for > > class attribute access. __set__ is only > > called to set the attribute on an instance instance of the owner class > > to a new value, value. WHY? Is there some other mechanism for > > accomplishing this outcome. This subtle difference from __get__cost me > > some time to track down. Might think about pointing that out the > > documentation. > > > class RevealAccess(object): > > ? ? """A data descriptor that sets and returns values > > ? ? ? ?normally and prints a message logging their access. > > ? ? """ > > > ? ? def __init__(self, initval=None, name='var'): > > ? ? ? ? self.val = initval > > ? ? ? ? self.name = name > > > ? ? def __get__(self, obj, objtype): > > ? ? ? ? print 'Retrieving', self.name > > ? ? ? ? return self.val > > > ? ? def __set__(self, obj, val): > > ? ? ? ? print 'Updating' , self.name > > ? ? ? ? self.val = val > > > class MyClass(object): > > ? ? x = RevealAccess(10, 'var "x"') > > ? ? y = 5 > > > print MyClass.x > > MyClass.x = 20 > > print MyClass.x > > MyClass.x = 30 > > print MyClass.x > > > Retrieving var "x" > > 10 > > 20 > > 30 > > > I am at a lost on how to intercept class attribute sets. Can anyone > > help :-/ > > The descriptor protocol only works when a value is being accessed or set > on an instance and there is no instance attribute of that name so the > value is fetched from the underlying class. > That's not true. Properties, for example, can be got or set even when they shadow an instance attribute. You're (probably) thinking of __getattr__ which isn't invoked when an instance attribute exists. Also, the descriptor protocol *is* invoked for getting an attribute from a class - but not when setting a class attribute. An unfortunate asymmetry. It just wasn't considered as a use case when the descriptor protocol was implemented. Michael -- http://voidspace.org.uk/ From steve+comp.lang.python at pearwood.info Wed Aug 10 10:36:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:36:59 +1000 Subject: String concatenation - which is the fastest way ? References: Message-ID: <4e42978c$0$29993$c3e8da3$5496439d@news.astraweb.com> przemolicc at poczta.fm wrote: > Hello, > > I'd like to write a python (2.6/2.7) script which connects to database, > fetches hundreds of thousands of rows, concat them (basically: create XML) > and then put the result into another table. Do I have any choice > regarding string concatenation in Python from the performance point of > view ? Since the number of rows is big I'd like to use the fastest > possible library (if there is any choice). Can you recommend me something > ? For fast string concatenation, you should use the string.join method: substrings = ['a', 'bb', 'ccc', 'dddd'] body = ''.join(substrings) Using string addition in a loop, like this: # Don't do this! body = '' for sub in substrings: body += sub risks being *extremely* slow for large numbers of substrings. (To be technical, string addition can O(N**2), while ''.join is O(N).) This depends on many factors, including the operating system's memory management, and the Python version and implementation, so repeated addition may be fast on one machine and slow on another. Better to always use join, which is consistently fast. You should limit string addition to small numbers of substrings: result = head + body + tail # This is okay. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 10 10:37:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:37:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers > wrote: >> In terms of easier to read, I find code easier to read when the operators >> are at the beginnings of the lines (PEP 8 notwithstanding): >> >> x = (someobject.somemethod(object3, thing) >> + longfunctionname(object2) >> + otherfunction(value1, value2, value3)) >> > > Without the parentheses, this is legal but (probably) useless; it > applies the unary + operator to the return value of those functions. > Putting the + at the end of the previous line at least prevents that, > since most unary operators bind to the operand on the right; Not so: >>> x = (42 + - ... 100) >>> >>> x -58 -- Steven From rosuav at gmail.com Wed Aug 10 10:38:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:38:16 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810133146.GE5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 2:31 PM, wrote: > - fetch all rows from the database (up to 1 million): what is recommended data type ? > - spawn X python processes each one: > ? ?- concat its own subset > - merge the result from all the subprocesses > What you're writing is, fundamentally, glue between your SQL engine and your SQL engine. Look up what you get from your query and work with that. Which SQL library are you suing? Python may and may not be the best tool for this job. Chris Angelico From rosuav at gmail.com Wed Aug 10 10:38:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:38:42 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: On Wed, Aug 10, 2011 at 3:38 PM, Chris Angelico wrote: > Which SQL library are you suing? And this is why I should proof-read BEFORE, not AFTER, sending. Which SQL library are you *using*? ChrisA From steve+comp.lang.python at pearwood.info Wed Aug 10 10:44:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 00:44:20 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e429945$0$29993$c3e8da3$5496439d@news.astraweb.com> Dan Sommers wrote: > In terms of easier to read, I find code easier to read when the operators > are at the beginnings of the lines (PEP 8 notwithstanding): > > x = (someobject.somemethod(object3, thing) > + longfunctionname(object2) > + otherfunction(value1, value2, value3)) Agreed. -- Steven From rosuav at gmail.com Wed Aug 10 10:45:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 15:45:43 +0100 Subject: allow line break at operators In-Reply-To: <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 1:58 PM, Yingjie Lan wrote: > Is it possible for python to allow free splitting of single-line statements > without the backslashes, if we impose that expressions can only be split > when it is not yet a finished expression? The trouble is that in a lot of cases, the next statement after an unfinished expression could conceivably be a continuation of it. If this were permitted, it would have to also require that the continuation lines be indented, to avoid the problem described above. It'd still have the potential to mis-diagnose errors, though. ChrisA From fuzzyman at gmail.com Wed Aug 10 10:48:55 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 07:48:55 -0700 (PDT) Subject: how to dynamically generate __name__ for an object? References: Message-ID: On Aug 7, 4:06?am, Eric Snow wrote: > Thought I knew how to provide a dynamic __name__ on instances of a > class. ?My first try was to use a non-data descriptor: > > # module base.py > > class _NameProxy(object): > ? ? def __init__(self, oldname): > ? ? ? ? self.oldname = oldname > ? ? def __get__(self, obj, cls): > ? ? ? ? if obj is None: > ? ? ? ? ? ? return self.oldname > ? ? ? ? if "__name__" not in obj.__dict__: > ? ? ? ? ? ? return str(obj.__context__) > ? ? ? ? return obj.__name__ > > class _BaseMeta(type): > ? ? def __init__(cls, name, bases, namespace): > ? ? ? ? cls.__name__ = _NameProxy(name) > > class Base(object): > ? ? __metaclass__ = _BaseMeta > > $ python _base.py > Traceback (most recent call last): > ? ... > ? File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ > ? ? cls.__name__ = _NameProxy(name) > TypeError: Error when calling the metaclass bases > ? ? can only assign string to Base.__name__, not '_NameProxy' > > Needless to say I was surprised. ?After looking in typeobject.c, I > believe that __name__ must be a string where classes are concerned[1]. > ?So if I want all my instances to have a __name__ attribute, and for > it to be dynamically provided if it isn't set on the instance, what > are my options? ?Or maybe I did something wrong and it should work as > I expected? > __name__ can be a descriptor, so you just need to write a descriptor that can be fetched from classes as well as instances. Here's an example with a property (instance only): >>> class Foo(object): ... @property ... def __name__(self): ... return 'bar' ... >>> Foo().__name__ 'bar' Michael -- http://voidspace.org.uk/ From rosuav at gmail.com Wed Aug 10 11:13:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 16:13:42 +0100 Subject: allow line break at operators In-Reply-To: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 3:37 PM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operators bind to the operand on the right; > > Not so: > >>>> x = (42 + - > ... ? ? 100) >>>> >>>> x > -58 Your unary - is binding to the operand to its right, in this case the 100. (I think I have left and right correct; being in theatre has a tendency to make you forget which is which.) Your + is binary, operating on 42 and the result of applying unary - to 100, which is -100. My point about binding can be illustrated by inventing an operator @. Let's say that a at b is the atan2 of a and b, and x@ is x factorial (I can't imagine what deranged mind would do something like this, apart from my own). y = 5 @ # 120, as per factorial x = 5 @ 2 # 1.19 or so, as per atan2 foo(123) # Calls foo() and discards its return value z = 5 @ foo(123) Is that last example one statement or two? But this situation shouldn't ever occur in Python, because all its unary operators (not, -, +, ~) bind to the operand to their right (I don't think there's any I've missed, are there?). It does mean, however, that a leading operator is not unambiguous. Without the surrounding parentheses and/or otherwise-unexpected indentation, an expression beginning with a + could conceivably be applying the unary plus operator to the rest of the expression, rather than implying that it's continuing the previous line. Chris Angelico From ian.g.kelly at gmail.com Wed Aug 10 11:16:58 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Aug 2011 09:16:58 -0600 Subject: allow line break at operators In-Reply-To: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operators bind to the operand on the right; > > Not so: > >>>> x = (42 + - > ... ? ? 100) >>>> >>>> x > -58 That is still binding to the operand on the "right" (i.e., the sequentially later). And it still does not cause the problem that Chris was talking about, since without the parentheses that would be a syntax error. So I guess I'm not certain what exactly it is that you're trying to demonstrate here. From ian.g.kelly at gmail.com Wed Aug 10 11:25:08 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Aug 2011 09:25:08 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: References: Message-ID: On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > __name__ can be a descriptor, so you just need to write a descriptor > that can be fetched from classes as well as instances. > > Here's an example with a property (instance only): > >>>> class Foo(object): > ... ? @property > ... ? def __name__(self): > ... ? ? return 'bar' > ... >>>> Foo().__name__ > 'bar' But: >>> Foo.__name__ 'Foo' >>> repr(Foo()) '<__main__.Foo object at 0x00CAFFD0>' >>> Foo.__dict__['__name__'] It seems that Foo.__name__ and Foo.__dict__['__name__'] are not the same thing, and Python itself only uses the former. From duncan.booth at invalid.invalid Wed Aug 10 11:35:11 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2011 15:35:11 GMT Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <33a59af5-bdf9-4f37-8801-9f9ad1a778b7@w11g2000vbp.googlegroups.com> Message-ID: Fuzzyman wrote: >> The descriptor protocol only works when a value is being accessed or set >> on an instance and there is no instance attribute of that name so the >> value is fetched from the underlying class. >> > > That's not true. Properties, for example, can be got or set even when > they shadow an instance attribute. You're (probably) thinking of > __getattr__ which isn't invoked when an instance attribute exists. Yes, Peter Otten already corrected me on that point last Friday and I posted thanking him on Sunday. -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Wed Aug 10 11:56:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 16:56:45 +0100 Subject: allow line break at operators In-Reply-To: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 2:19 PM, Yingjie Lan wrote: > If ';' are employed (required), truely free line-splitting should be OK, > the operators may appear at the beginnings of the lines as you wish. > And if we require {} then truly free indentation should be OK too! But it wouldn't be Python any more. ChrisA From funthyme at gmail.com Wed Aug 10 12:06:02 2011 From: funthyme at gmail.com (John Pinner) Date: Wed, 10 Aug 2011 09:06:02 -0700 (PDT) Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> Message-ID: <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> On Aug 9, 1:36?am, Ben Finney wrote: > Ethan Furman writes: > > So if property docstrings are so hard to get to, what's the point in > > having them? > > Why would you expect there be a special point to them? > > Men, like all primates of any sex, have nipples. > > Properties, like any function in Python, have docstrings. So are you saying that men's nipples are pointless? You could be correct, except in cold weather maybe. John -- > > They're an accident of the history that led to their implementation, and > of the pre-existing parts that they're built from. There doesn't need to > be a point to them (though they might be useful for reasons incidental > for the reasons they exist). > > -- > ?\ ? ? ? ??I filled my humidifier with wax. Now my room is all shiny.? | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??Steven Wright | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney From stefan_ml at behnel.de Wed Aug 10 12:20:10 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 10 Aug 2011 18:20:10 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110810133146.GE5045@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: przemolicc at poczta.fm, 10.08.2011 15:31: > On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: >> On Wed, Aug 10, 2011 at 12:17 PM, wrote: >>> I'd like to write a python (2.6/2.7) script which connects to database, fetches >>> hundreds of thousands of rows, concat them (basically: create XML) >>> and then put the result into another table. Do I have any choice >>> regarding string concatenation in Python from the performance point of view ? >>> Since the number of rows is big I'd like to use the fastest possible library >>> (if there is any choice). Can you recommend me something ? >> >> First off, I have no idea why you would want to create an XML dump of >> hundreds of thousands of rows, only to store it in another table. >> However, if that is your intention, list joining is about as efficient >> as you're going to get in Python: >> >> lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries >> xml=""+"".join(lst)+"" >> >> This sets xml to 'asdfqwerzxcv' which >> may or may not be what you're after. > > since this process (XML building) is running now inside database (using native SQL commands) > and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which > will concat subset of the whole table (and then merge all of them at the end). > Basically: > - fetch all rows from the database (up to 1 million): what is recommended data type ? > - spawn X python processes each one: > - concat its own subset > - merge the result from all the subprocesses > > This task is running on a server which has many but slow cores and I am trying to divide this task > into many subtasks. Makes sense to me. Note that the really good DBMSes (namely, PostgreSQL) come with built-in Python support. You still didn't provide enough information to make me understand why you need XML in between one database and another (or the same?), but if you go that route, you can just read data through multiple connections in multiple threads (or processes), have each build up one (or more) XML entries, and then push those into a queue. Then another thread (or more than one) can read from that queue and write the XML items into a file (or another database) as they come in. If your data has a considerable size, I wouldn't use string concatenation or joining at all (note that it requires 2x the memory during concatenation), but rather write it into a file, or even just process the data on the fly, i.e. write it back into the target table right away. Reading a file back in after the fact is much more resource friendly than keeping huge amounts of data in memory. And disk speed is usually not a problem when streaming data from disk into a database. It may also be worth considering to write out literal SQL insert statements instead of XML. Most databases have a decent bulk upload tool. Stefan From ericsnowcurrently at gmail.com Wed Aug 10 12:27:20 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 10:27:20 -0600 Subject: __set__ method is not called for class attribute access In-Reply-To: <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> Message-ID: On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman wrote: > On Aug 5, 12:29?pm, Ryan wrote: >> In the context of descriptors, the __set__ method is not called for >> class attribute access. __set__ is only >> called to set the attribute on an instance instance of the owner class >> to a new value, value. WHY? > > It's an unfortunate asymmetry in the descriptor protocol. You can > write "class descriptors" with behaviour on get, but not on set. > > As others point out, metaclasses are an ugly way round this > (particularly given that *basically* a class can only have one > metaclass - so if you're inheriting from a class that already has a > custom metaclass you can't use this technique). Keep in mind that you can still do something like this: class XMeta(Base.__class__): "Customize here" class X(Base, metaclass=XMeta): "Do your stuff." They you would put your descriptor hacking in XMeta and still take advantage of the original metaclass. -eric > > Michael Foord > -- > http://voidspace.org.uk/ > -- > http://mail.python.org/mailman/listinfo/python-list > From fuzzyman at gmail.com Wed Aug 10 12:38:07 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 09:38:07 -0700 (PDT) Subject: how to dynamically generate __name__ for an object? References: Message-ID: <1419d2bf-d71a-4f85-afc1-215274bd4b9a@w11g2000vbp.googlegroups.com> On Aug 10, 4:25?pm, Ian Kelly wrote: > On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > > __name__ can be a descriptor, so you just need to write a descriptor > > that can be fetched from classes as well as instances. > > > Here's an example with a property (instance only): > > >>>> class Foo(object): > > ... ? @property > > ... ? def __name__(self): > > ... ? ? return 'bar' > > ... > >>>> Foo().__name__ > > 'bar' > > But: > > >>> Foo.__name__ > 'Foo' That's why I said "you just need to _write_ a descriptor that can be fetched from classes as well as instances". The example with property was to show that it *could* be a descriptor. You can write descriptors with custom behaviour when fetched from a class. However it turns out that you're right and I'm wrong; __name__ is special: >>> class descriptor(object): ... def __get__(*args): ... return 'bar' ... >>> class Foo(object): ... __name__ = descriptor() ... >>> Foo.__name__ 'Foo' >>> Foo().__name__ 'bar' >>> class Foo(object): ... name = descriptor() ... >>> Foo.name 'bar' As Eric points out in his original slot, types have their __name__ slot filled in with a string in typeobject.c All the best, Michael -- http://voidspace.org.uk/ From fuzzyman at gmail.com Wed Aug 10 12:40:03 2011 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Aug 2011 09:40:03 -0700 (PDT) Subject: __set__ method is not called for class attribute access References: <813b4441-df2f-48e4-bc5e-b26ec56fb80f@p5g2000vbl.googlegroups.com> <7dfc5e85-57e2-4cd4-ba88-3015abb9f4c6@f7g2000vba.googlegroups.com> Message-ID: On Aug 10, 5:27?pm, Eric Snow wrote: > On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman wrote: > > On Aug 5, 12:29?pm, Ryan wrote: > >> In the context of descriptors, the __set__ method is not called for > >> class attribute access. __set__ is only > >> called to set the attribute on an instance instance of the owner class > >> to a new value, value. WHY? > > > It's an unfortunate asymmetry in the descriptor protocol. You can > > write "class descriptors" with behaviour on get, but not on set. > > > As others point out, metaclasses are an ugly way round this > > (particularly given that *basically* a class can only have one > > metaclass - so if you're inheriting from a class that already has a > > custom metaclass you can't use this technique). > > Keep in mind that you can still do something like this: > > class XMeta(Base.__class__): > ? ? "Customize here" > > class X(Base, metaclass=XMeta): > ? ? "Do your stuff." > > They you would put your descriptor hacking in XMeta and still take > advantage of the original metaclass. Yeah, the way round the "more than one metaclass problem" is to have your new metaclass inherit from the first one. That's not a general purpose solution though. Michael -- http://voidspace.org.uk/ From ericsnowcurrently at gmail.com Wed Aug 10 12:54:54 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 10:54:54 -0600 Subject: how to dynamically generate __name__ for an object? In-Reply-To: References: Message-ID: On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > On Aug 7, 4:06?am, Eric Snow wrote: >> Thought I knew how to provide a dynamic __name__ on instances of a >> class. ?My first try was to use a non-data descriptor: >> >> # module base.py >> >> class _NameProxy(object): >> ? ? def __init__(self, oldname): >> ? ? ? ? self.oldname = oldname >> ? ? def __get__(self, obj, cls): >> ? ? ? ? if obj is None: >> ? ? ? ? ? ? return self.oldname >> ? ? ? ? if "__name__" not in obj.__dict__: >> ? ? ? ? ? ? return str(obj.__context__) >> ? ? ? ? return obj.__name__ >> >> class _BaseMeta(type): >> ? ? def __init__(cls, name, bases, namespace): >> ? ? ? ? cls.__name__ = _NameProxy(name) >> >> class Base(object): >> ? ? __metaclass__ = _BaseMeta >> >> $ python _base.py >> Traceback (most recent call last): >> ? ... >> ? File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__ >> ? ? cls.__name__ = _NameProxy(name) >> TypeError: Error when calling the metaclass bases >> ? ? can only assign string to Base.__name__, not '_NameProxy' >> >> Needless to say I was surprised. ?After looking in typeobject.c, I >> believe that __name__ must be a string where classes are concerned[1]. >> ?So if I want all my instances to have a __name__ attribute, and for >> it to be dynamically provided if it isn't set on the instance, what >> are my options? ?Or maybe I did something wrong and it should work as >> I expected? >> > > __name__ can be a descriptor, so you just need to write a descriptor > that can be fetched from classes as well as instances. > > Here's an example with a property (instance only): > >>>> class Foo(object): > ... ? @property > ... ? def __name__(self): > ... ? ? return 'bar' > ... >>>> Foo().__name__ > 'bar' Thanks! Your example is exactly what I didn't try in the first place, but should have. I was thinking of __name__ on a class as a simple data attribute. My original worry was that by adding a descriptor for __name__ on my class, I would overwrite the name of the class, hence the elaborate descriptor. However, for type objects (classes) __name__ is a data descriptor and the actual name isn't stored in __name__. I was staring that right in the face (the link I provided is for the setter method of the __name__ "property" for type objects). I guess it was a "forest for the trees" moment. Because of attribute lookup in Python, "Base.__name__" uses the equivalent of "Base.__class__.__name__.__get__(..., Base, Base.__class__)". Anyway, thanks for making me see how dumb I am! -eric > > Michael > -- > http://voidspace.org.uk/ > -- > http://mail.python.org/mailman/listinfo/python-list > From usenet-nospam at seebs.net Wed Aug 10 13:55:20 2011 From: usenet-nospam at seebs.net (Seebs) Date: 10 Aug 2011 17:55:20 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: On 2011-08-10, Chris Angelico wrote: > And if we require {} then truly free indentation should be OK too! But > it wouldn't be Python any more. Would it really not be Python at all? I've seen bits of code in preprocessing-based "Python with {}" type things, and they still look like Python to me, only they favor explicit over implicit a little more strongly. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From irmen at -NOSPAM-xs4all.nl Wed Aug 10 14:26:36 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 10 Aug 2011 20:26:36 +0200 Subject: SocketServer expceion after upgrading to 2.7 In-Reply-To: References: Message-ID: <4e42cd5c$0$23837$e4fe514c@news2.news.xs4all.nl> On 10-08-11 15:42, Laszlo Nagy wrote: > Exception happened during processing of request from ('80.99.165.122', > 56069) > Traceback (most recent call last): > File "/usr/local/lib/python2.7/SocketServer.py", line 284, in > _handle_request_noblock > self.process_request(request, client_address) > File "/usr/local/lib/python2.7/SocketServer.py", line 311, in > process_request > self.shutdown_request(request) > File "/usr/local/lib/python2.7/SocketServer.py", line 459, in > shutdown_request > request.shutdown(socket.SHUT_WR) > TypeError: shutdown() takes exactly 0 arguments (1 given) > > > I get this error with a program, after upgrading to python 2.7. I'm > using a program that is based on SocketServer and SimpleXMLRPCDispatcher. > > Any idea how to fix this? Strange, I expected at least one or two more stack frames in the traceback you posted (from within the socket.py module). What platform are you on? What python version? What does this print on your system: >>> import socket >>> s=socket.socket() >>> s.shutdown(socket.SHUT_WR) Irmen From tdsimpson at gmail.com Wed Aug 10 14:55:27 2011 From: tdsimpson at gmail.com (MrPink) Date: Wed, 10 Aug 2011 11:55:27 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... Message-ID: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> I need a little nudge into the right direction with this problem. As an exercise for me to learn about Python, I am trying to determine the best way to search a list of "lottery drawings" for a match with a lottery ticket. Possible numbers for a drawing are: 5 whiteballs (wb): 1-55 1 blackball (bb): 1-49 example: wb1, wb2, wb3, wb4, wb5, bb Example list of lottery drawings: date,wb,wb,wb,wb,wb,bb 4/1/2011,5,1,45,23,27,27 5/1/2011,15,23,8,48,22,32 6/1/2011,33,49,21,16,34,1 7/1/2011,9,3,13,22,45,41 8/1/2011,54,1,24,39,35,18 ... Typically a lottery ticket can have multiple combinations for the ticket to be a winner. For example: 2 wb, 1 bb 3 wb 3 wb, 1 bb 4 wb 4 wb, 1 bb 5 wb 5 wb, 1 bb (jackpot winner) An object oriented solution might be to create a list of "Drawing" objects and then loop through the list to find a match for the ticket object. For example: if oDrawing[x] == ticket then "Do XYZ" Or I could just perform this task with procedures and loops and skip the object solution idea. Do Python developers have a preference? Would it be worth the overhead to initialize a list of drawing objects to search through? There is no database back-end, so no SQL, etc. I hope all that makes sense. Thanks for you help. From ameet.nanda at gmail.com Wed Aug 10 15:52:17 2011 From: ameet.nanda at gmail.com (Ameet Nanda) Date: Wed, 10 Aug 2011 12:52:17 -0700 Subject: Directions on accessing shared folder in windows network Message-ID: Hi, Can anyone point me to a way to access windows shared folders from the network using a python script. I tried accessing using open, which is mentioned to work perfectly on the web, but it gives me following errors >>>open(NW_PATH) it gives me a permission denied error as follows: >>> open("\\\\ameetn\\DropBox\\") Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: '\\\\ameetn\\' >>> open("\\\\ameetn\\DropBox") Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '\\\\ameetn\\DropBox' I am running Python 2.6 on Windows 7 platform. Thanks in advance, Ameet -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Aug 10 16:14:05 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Aug 2011 21:14:05 +0100 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: <4E42E68D.70900@mrabarnett.plus.com> On 10/08/2011 20:52, Ameet Nanda wrote: > Hi, > > Can anyone point me to a way to access windows shared folders from the > network using a python script. I tried accessing using open, which is > mentioned to work perfectly on the web, but it gives me following errors > > >>>open(NW_PATH) > > it gives me a permission denied error as follows: > > >>> open("\\\\ameetn\\DropBox\\") > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: '\\\\ameetn\\' > > >>> open("\\\\ameetn\\DropBox") > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied: '\\\\ameetn\\DropBox' > > I am running Python 2.6 on Windows 7 platform. > "ameetn" is the name of the machine and "DropBox" is the name of a shared folder on that machine. The answer hasn't changed. 'open' is for opening _files_. Give 'open' the path to a _file_. From lists at cheimes.de Wed Aug 10 16:43:05 2011 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Aug 2011 22:43:05 +0200 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: Am 10.08.2011 21:52, schrieb Ameet Nanda: > Hi, > > Can anyone point me to a way to access windows shared folders from the > network using a python script. I tried accessing using open, which is > mentioned to work perfectly on the web, but it gives me following errors The open() function wraps the fopen() function, which doesn't support UNC, just local paths. You have to mount the network share first (assign a drive letter). Christian From ben+python at benfinney.id.au Wed Aug 10 17:51:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 07:51:32 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <87fwl9hr4r.fsf@benfinney.id.au> Seebs writes: > On 2011-08-10, Chris Angelico wrote: > > And if we require {} then truly free indentation should be OK too! > > But it wouldn't be Python any more. > > Would it really not be Python at all? See the Python interpreter's response to ?from __future__ import braces?. > I've seen bits of code in preprocessing-based "Python with {}" type > things, and they still look like Python to me, only they favor > explicit over implicit a little more strongly. They introduce unnecessary ambiguity: the indentation-as-structure and braces-as-structure can then disagree. In which case either the Python interpreter must guess the programmer's intent (very un-Pythonic), or it throws an error and the programmer must do busy-work to keep braces and indentation in agreement (also un-Pythonic). The ambiguity is resolved by having exactly one of indentation or braces determining structure: Python uses indentation. In which case, braces are pointless for indicating block structure. -- \ ?Without cultural sanction, most or all of our religious | `\ beliefs and rituals would fall into the domain of mental | _o__) disturbance.? ?John F. Schumaker | Ben Finney From rosuav at gmail.com Wed Aug 10 18:42:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Aug 2011 23:42:06 +0100 Subject: allow line break at operators In-Reply-To: <87fwl9hr4r.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On Wed, Aug 10, 2011 at 10:51 PM, Ben Finney wrote: > Seebs writes: >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor >> explicit over implicit a little more strongly. > > They introduce unnecessary ambiguity: the indentation-as-structure and > braces-as-structure can then disagree. > > The ambiguity is resolved by having exactly one of indentation or braces > determining structure: Python uses indentation. In which case, braces > are pointless for indicating block structure. That's why it wouldn't be Python. It would have to use the braces and not the indentation. ChrisA PS. I mistakenly sent this to a Gilbert & Sullivan group first. Oddly enough, opera-goers are not used to discussing the relative merits of braces vs indentation in code. From gelonida at gmail.com Wed Aug 10 18:44:48 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 00:44:48 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) Message-ID: Hi, I'd like to install psyco on my windows host I'm using python 2.6.4 (32 bit version) I installed easy_intall and pip easy_install psyco and pip install psyco fail both with the message error: Setup script exited with error: Unable to find vcvarsall.bat I read, that this means I shoul dinstall a C-compiler I also read, that I should NOT Micrusoft Visual C++ Express 2010 (which is unfortunately exactly the version, which I installed for some other activity. So my question: - If I install visual Studio 2008 addtiojnally to visualstudia 2010, will easy_install find this compiler? - I read about the alternative of using MingW instead of Visual Studio Express 2008. What could influence my choice of Compiler? Thanks for any suggestions From python.list at tim.thechases.com Wed Aug 10 19:26:24 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Aug 2011 18:26:24 -0500 Subject: Python & Sullivan In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4E4313A0.5070401@tim.thechases.com> On 08/10/2011 05:42 PM, Chris Angelico wrote: > PS. I mistakenly sent this to a Gilbert& Sullivan group > first. Oddly enough, opera-goers are not used to discussing > the relative merits of braces vs indentation in code. It's only fair turnabout: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html -tkc From steve+comp.lang.python at pearwood.info Wed Aug 10 19:32:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 09:32:12 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> Ian Kelly wrote: > On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano > wrote: >>> Without the parentheses, this is legal but (probably) useless; it >>> applies the unary + operator to the return value of those functions. >>> Putting the + at the end of the previous line at least prevents that, >>> since most unary operators bind to the operand on the right; >> >> Not so: >> >>>>> x = (42 + - >> ... ? ? 100) >>>>> >>>>> x >> -58 > > That is still binding to the operand on the "right" (i.e., the > sequentially later). And it still does not cause the problem that > Chris was talking about, since without the parentheses that would be a > syntax error. So I guess I'm not certain what exactly it is that > you're trying to demonstrate here. Chris stated that putting the unary + at the end of the line prevents "that", that being applying the unary + operator to the value on the right. But that is not the case -- unary prefix operators in Python can be separated from their operands by whitespace, including newlines. (Python doesn't have any unary postfix operators.) -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 10 19:37:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 09:37:06 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> Message-ID: <4e431623$0$29967$c3e8da3$5496439d@news.astraweb.com> John Pinner wrote: > On Aug 9, 1:36?am, Ben Finney wrote: >> Ethan Furman writes: >> > So if property docstrings are so hard to get to, what's the point in >> > having them? >> >> Why would you expect there be a special point to them? >> >> Men, like all primates of any sex, have nipples. >> >> Properties, like any function in Python, have docstrings. > > So are you saying that men's nipples are pointless? > > You could be correct, except in cold weather maybe. Groan. However, off-topic but interesting, there is at least one species of bat where the males are known to routinely lactate and feed baby bats. http://en.wikipedia.org/wiki/Male_lactation So just because a feature is an accident of history, doesn't mean that a use can't be found for it. -- Steven From jackhatterly at hotmail.com Wed Aug 10 19:39:30 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Wed, 10 Aug 2011 23:39:30 +0000 Subject: Cookie Problem Message-ID: Hi; I'm trying to get this cookie code to work but it doesn't set the properties I want set (expires, path, comment, etc.). When I delete the cookie and run the script it duly creates a cookie. However, when I reload the page none of the morsels have values associated with them. I also do not see values when I look for them in my FireFox CookieCuller. I pretty much copied this code from an online tutorial so I'm wondering where the problem is. #!/usr/bin/env python import string import os import datetime, Cookie, random import time ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = str(time.time()) print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') # The first time the page is run there will be no cookies if not cookie_string: print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = str(time.time()) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/var/www/html/my_site/' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 else: # Run the page twice to retrieve the cookie print '

The returned cookie string was "' + cookie_string + '"

' # cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1], '.', '')[:-1] # load() parses the cookie string cookie.load(cookie_string) # Use the value attribute of the cookie to get it lastvisit = float(cookie['lastvisit'].value) for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' print '' TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Aug 10 19:54:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 00:54:38 +0100 Subject: Python & Sullivan In-Reply-To: <4E4313A0.5070401@tim.thechases.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4E4313A0.5070401@tim.thechases.com> Message-ID: On Thu, Aug 11, 2011 at 12:26 AM, Tim Chase wrote: > On 08/10/2011 05:42 PM, Chris Angelico wrote: >> >> PS. I mistakenly sent this to a Gilbert& ?Sullivan group >> first. Oddly enough, opera-goers are not used to discussing >> the relative merits of braces vs indentation in code. > > It's only fair turnabout: > > http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html Yes, I know about that one. My problem is that I snap off quick responses to both lists, and sometimes type "sav" instead of "py" or vice versa. Usually I catch it before hitting Send, though!! On MUDs, we call that a mischannel. I've now mischanneled both directions. :| ChrisA From rosuav at gmail.com Wed Aug 10 19:55:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 00:55:36 +0100 Subject: allow line break at operators In-Reply-To: <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> <4e4314fd$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 11, 2011 at 12:32 AM, Steven D'Aprano wrote: > Chris stated that putting the unary + at the end of the line > prevents "that", that being applying the unary + operator to the value on > the right. But that is not the case -- unary prefix operators in Python can > be separated from their operands by whitespace, including newlines. > Right, I forgot that. It certainly would not be normal to do it that way, though. ChrisA From rdmoores at gmail.com Wed Aug 10 19:57:34 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Wed, 10 Aug 2011 16:57:34 -0700 Subject: Puzzled about the output of my demo of a proof of The Euler Series Message-ID: I saw an interesting proof of the limit of The Euler Series on math.stackexchange.com at . Scroll down to Hans Lundmark's post. I thought I'd try to see this "pinching down" on the limit of pi**2/6. See my attempt, and output for n = 150 at . What puzzles me is that upper_bound_partial_sum (lines 39 and 60) is always smaller than the limit. It should be greater than the limit, right? If not, no pinching between upper_bound_partial_sum and lower_bound_partial_sum. I've checked and double-checked the computation, but can't figure out what's wrong. Thanks, Dick Moores From steve+comp.lang.python at pearwood.info Wed Aug 10 20:32:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 10:32:34 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-10, Chris Angelico wrote: >> And if we require {} then truly free indentation should be OK too! But >> it wouldn't be Python any more. > > Would it really not be Python at all? Of course it wouldn't be. Every function, class, if, while, for, try...except block etc. in existing Python code would be illegal if {} were required. This would be an order of magnitude bigger change than going from Python 2 to 3, where the biggest syntax change is that print is no longer a statement. Even more so if ; were to become required, as suggested by the Original Poster. > I've seen bits of code in preprocessing-based "Python with {}" type > things, and they still look like Python to me, only they favor explicit > over implicit a little more strongly. "Looks like" Python does not equal "is Python". Cobra looks like Python, as do Boo, Groovy and Ruby, or OCaml with "twt" turned on ("the whitespace thing"). The similarities are especially strong for Boo and Cobra, but there is no doubt that they are different languages. In general, languages that aim to look like executable pseudo-code will converge on a similar look, because executable pseudo-code tends to be based on natural language (usually English) and mathematics syntax. -- Steven From ericsnowcurrently at gmail.com Wed Aug 10 20:38:17 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 10 Aug 2011 18:38:17 -0600 Subject: code object differences between 2.7 and 3.3a Message-ID: Specifically, I am wondering why there is a difference for co_names. Here is a function that exercises the different code object pieces[1]: def g(y=5): a = 7 def f(x, w=y, z=4, *args, **kwargs): b = a c = global_x return f f1 = g() Here are the results for 2.7: >>> for name in dir(f1.func_code): print("%s -> %s" % (name, getattr(f1.func_code, name))) ... co_argcount -> 3 co_cellvars -> () co_code -> }t}dS co_consts -> (None,) co_filename -> co_firstlineno -> 3 co_flags -> 15 co_freevars -> ('a',) co_lnotab -> co_name -> f co_names -> ('a', 'b', 'global_x', 'c') co_nlocals -> 7 co_stacksize -> 1 co_varnames -> ('x', 'w', 'z', 'args', 'kwargs', 'c', 'b') And for 3.3: >>> for name in dir(f1.__code__): print("%s -> %s" % (name, getattr(f1.__code__, name))) ... co_argcount -> 3 co_cellvars -> () co_code -> b'\x88\x00\x00}\x05\x00t\x00\x00}\x06\x00d\x00\x00S' co_consts -> (None,) co_filename -> co_firstlineno -> 3 co_flags -> 31 co_freevars -> ('a',) co_kwonlyargcount -> 0 co_lnotab -> b'\x00\x01\x06\x01' co_name -> f co_names -> ('global_x',) co_nlocals -> 7 co_stacksize -> 1 co_varnames -> ('x', 'w', 'z', 'args', 'kwargs', 'b', 'c') While there are several differences, the one I care about is co_name. For 2.7 it's what I would expect. However, for 3.3 it's not[2][3]. It is actually nicer for my application this way, but I want to verify the situation before I get me hopes up. :) Before I go email-list-diving or digging through PyEval_EvalCodeEx, I wanted to see if anyone has any insight about this change in co_names. Thanks! -eric [1] yes, 3.x also supports keyword-only arguments. I tried this on 3.3 with extra kw-only arguments and it was the same outcome. [2] The documentation for the inspect module gives an incomplete listing of the code object attributes: The description of co_names there ("tuple of names of local variables") seems inconsistent with what I am seeing. It's probably just that I am misinterpreting that list or the doc needs an update. [3] My guess is that co_names was seen as bloated and the superfluous items removed, leaving only the un-closed free variables; co_freevars is the closed free variables. To get the same tuple as the 2.7 version, you could compose it from co_freevars, co_names, and the end of co_varnames. From rosuav at gmail.com Wed Aug 10 20:47:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 01:47:49 +0100 Subject: allow line break at operators In-Reply-To: <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 11, 2011 at 1:32 AM, Steven D'Aprano wrote: >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor explicit >> over implicit a little more strongly. > > "Looks like" Python does not equal "is Python". Cobra looks like Python, as > do Boo, Groovy and Ruby, or OCaml with "twt" turned on ("the whitespace > thing"). The similarities are especially strong for Boo and Cobra, but > there is no doubt that they are different languages. > > In general, languages that aim to look like executable pseudo-code will > converge on a similar look, because executable pseudo-code tends to be > based on natural language (usually English) and mathematics syntax. "Looks like" is a poor indication of anything much; "feels like" is a bit vague, but may be more useful. If you can manipulate objects and references to objects, if you can use Python's rich object set and standard library, if you can use Python-like features using reasonably readable syntax, then it feels like Python. Little things don't matter (eg whether 'print' is a keyword or a function). Big things do (eg having to explicitly deallocate objects). Lots of languages "look like" C. Some of them function like C (eg C++), and most definitely "feel like" C. Others don't. ChrisA From ben+python at benfinney.id.au Wed Aug 10 20:57:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 10:57:37 +1000 Subject: Python & Sullivan References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <871uwsix32.fsf@benfinney.id.au> Tim Chase writes: > On 08/10/2011 05:42 PM, Chris Angelico wrote: > > PS. I mistakenly sent this to a Gilbert& Sullivan group > > first. Oddly enough, opera-goers are not used to discussing > > the relative merits of braces vs indentation in code. > > It's only fair turnabout: > > http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-09/msg01783.html Also of interest: Do a web search for ?debian dueling banjos?. Or read about the phenomenon at . -- \ ?The restriction of knowledge to an elite group destroys the | `\ spirit of society and leads to its intellectual | _o__) impoverishment.? ?Albert Einstein | Ben Finney From ben+python at benfinney.id.au Wed Aug 10 20:59:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 10:59:19 +1000 Subject: Docstrings and class Attributes References: <4e402a42$0$29986$c3e8da3$5496439d@news.astraweb.com> <878vr3ju9v.fsf@benfinney.id.au> <5e287c40-9a1e-41fe-8da9-5236b7d39fc1@t9g2000vbs.googlegroups.com> <4e431623$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wrekhifs.fsf@benfinney.id.au> Steven D'Aprano writes: > So just because a feature is an accident of history, doesn't mean that > a use can't be found for it. Which I explicitly noted in my message. I suppose it's inevitable for the nuances of one's utterances to be forgotten as the discussion progresses, but darn if it ain't annoying. -- \ ?Not using Microsoft products is like being a non-smoker 40 or | `\ 50 years ago: You can choose not to smoke, yourself, but it's | _o__) hard to avoid second-hand smoke.? ?Michael Tiemann | Ben Finney From jianbao.tao at gmail.com Wed Aug 10 21:24:53 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 18:24:53 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings Message-ID: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Greetings, folks, I am using python 2.7.2. Here is something I got: >>> a = 'popular' >>> i = a.find('o') >>> j = a.find('a') >>> a[i:j] 'opul' Well, I expected a[i:j] to be 'opula', and can't think of any reason why this is not happening. So, can anybody help me out about this? Thank you very much. Jim From rosuav at gmail.com Wed Aug 10 21:46:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 02:46:23 +0100 Subject: Cookie Problem In-Reply-To: References: Message-ID: On Thu, Aug 11, 2011 at 12:39 AM, Jack Hatterly wrote: > ??? cookie['lastvisit'] = str(time.time()) > ??? cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 > ??? cookie['lastvisit']['path'] = '/var/www/html/my_site/' > ??? cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' > ??? cookie['lastvisit']['domain'] = '.www.my_site.com' > ??? cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 > ??? cookie['lastvisit']['secure'] = '' > ??? cookie['lastvisit']['version'] = 1 Some of these values look wrong. Your 'path' ought to be as the browser sees it, and your 'domain' ditto; the only way that these would make sense is if you're setting this cookie on a page such as: http://foo.www.my_site.com/var/www/html/my_site/blah/blah and you want to also see the cookie on the page: http://bar.www.my_site.com/var/www/html/my_site/asdf/qwer Otherwise, I would recommend omitting those elements and allowing the defaults through. ChrisA From python at mrabarnett.plus.com Wed Aug 10 21:48:35 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 02:48:35 +0100 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Message-ID: <4E4334F3.5000005@mrabarnett.plus.com> On 11/08/2011 02:24, Jim wrote: > Greetings, folks, > > I am using python 2.7.2. Here is something I got: >>>> a = 'popular' >>>> i = a.find('o') >>>> j = a.find('a') >>>> a[i:j] > 'opul' > > Well, I expected a[i:j] to be 'opula', and can't think of any reason > why this is not happening. So, can anybody help me out about this? > Thank you very much. > Python uses half-open ranges, which means that the start position is inclusive and the end position is exclusive. This means that a[i:j] returns the string starting at position i and extending upto, but excluding, position j. The reason that Python uses half-open ranges is that experience (with the language Mesa) has shown that it results in fewer programming errors that the alternatives. From rosuav at gmail.com Wed Aug 10 22:14:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 03:14:30 +0100 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <4E4334F3.5000005@mrabarnett.plus.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4E4334F3.5000005@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 2:48 AM, MRAB wrote: > Python uses half-open ranges, which means that the start position is > inclusive and the end position is exclusive. > Or if you prefer: Python identifies positions between characters, rather than characters. And I agree that it's better than the alternative - in fact, I wish other systems could work the same way (eg Bible references). If you think about position 0 being the very beginning of the string, and position len(s) being the very end, then you slice the string from position to position and take the characters between. When you index the string for a particular character, you aim at a position and take the character after it. Chris Angelico From ryan at rfk.id.au Wed Aug 10 22:17:48 2011 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 11 Aug 2011 02:17:48 -0000 Subject: PyCon Australia 2011: Registration Closing Soon! Message-ID: <20110811021748.15825.55916@pyglet.org> Hi Everyone, Registrations for PyCon Australia 2011 are closing soon! The conference is just over a week away, so we need final numbers in the next few days. If you're planning to attend, please register now! PyCon Australia is Australia's only conference dedicated exclusively to the Python programming language, and will be held at the Sydney Masonic Center over the weekend of August 20 and 21. See below for more information and updates on: 1. Registration Closing Soon 2. Coffee 3. Hosting Panel 4. More Sponsors Announced Please pass this message on to those you feel may be interested. Registration Closing Soon ========================= Full Registrations for the conference will be closing on: Monday 15th August: Full Registrations close That's only five days away, so register now to be sure you don't miss out. By request, we will still allow latecomers to register until just before the conference. However, since it's after the deadline for catering and printing, you won't be entitled to a T-shirt or a seat at the conference dinner: Thursday 18th August: Last-Minute Registrations close Please note that we will *not* accept registrations at the door. So don't delay, register now at: http://pycon-au.org/reg Coffee ====== Thanks to gold sponsors Arclight, we will be able to provide one of the most requested additions to this year's conference: Coffee! Yes, Arclight have generously agreed to provide a free coffee cart for the duration of the conference. And there was much rejoicing. Hosting Panel ============= Saturday evening will feature an informal panel discussion with several hosting providers. Come and hear from our hosting panel about why their services are right for hosting your next Python project! Each group will give a quick 5 minute spiel, to be followed by a casual drink before the conference dinner. This event is happening in a private area at Mr B's pub, across the street from the SMC. As this is a licensed venue anyone under 18 will have to be accompanied by a parent or guardian. More Sponsors Announced ======================= We are delighted to confirm that the Django Software Foundation and Ninefold have joined as Silver sponsors. In addition, Arclight have upgraded to Gold Sponsorship, Anchor have agreed to sponsor video production, and GitHub will be sponsoring internet access. Thanks once again to the following companies for their continuing support of Python and for helping to make PyCon Australia 2011 a reality: Gold: Google Gold: ComOps Gold: Arclight Video: Anchor Silver: Enthought Silver: Python Software Foundation Silver: WingWare Silver: Bitbucket by Atlassian Silver: Microsoft Silver: Django Software Foundation Silver: Ninefold Internet: GitHub Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details From missive at hotmail.com Wed Aug 10 22:39:53 2011 From: missive at hotmail.com (Lee Harr) Date: Thu, 11 Aug 2011 07:09:53 +0430 Subject: [ANNC] pynguin-0.11 python turtle graphics application Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues to expand basic functionality and ??? explores more user-friendly options in the interface. Pynguin is tested with Python 2.7.1 and PyQt 4.8.3 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.11: ??? Session ??????? - all settings now moved in to menus and settings dialogs ??? Pynguin API ??????? - added .label() method to have a label attached to a pynguin ??????????? - also accessible as .name attribute ??????? - added .speed() method to change speed from user code ??????? - viewcoords() now returns integers by default ??????????? - pass floats=True to get the float values instead ??????? - added .track() and .notrack() methods for user code ??? Canvas ??????? - added support for custom avatars ??????????? - both svg and bitmap images supported ??????? - fixed motion when drawing slow circles with pen up ??????? - don't draw circles when pen is up and speed is instant ??????? - expand canvas when resizing window ??? Integrated Editor ??????? - added "Test / Run all" button ??????? - improved handling of external .py files ??? Integrated Console ??????? - now gives correct call syntax when using test/run on classes ??? Examples ??????? - make examples use new viewcoords() API ??????? - fixed multi.pyn scatter example ??????? - make multi.pyn follow examples work with existing pynguins ??????? - demonstrate labels in multi.pyn follow example ??????? - fix penup() in oo.pyn ZZ example ??????? - add centered circle in oo.pyn ZZ example ??? General ??????? - fixed examples getting gzipped in .deb distribution file ??????? - added a way to dump contents of .pyn from command line From lanyjie at yahoo.com Wed Aug 10 22:52:55 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 19:52:55 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> :And if we require {} then truly free indentation should be OK too! But :it wouldn't be Python any more. Of course, but not the case with ';'. Currently ';' is optional in Python, But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. So the decision is: shall we change ';' from optional to mandatory to allow free line splitting? Yingjie From steve+comp.lang.python at pearwood.info Wed Aug 10 22:56:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 12:56:43 +1000 Subject: Bizarre behavior of the 'find' method of strings References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> Message-ID: <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Aug 2011 11:24 am Jim wrote: > Greetings, folks, > > I am using python 2.7.2. Here is something I got: >>>> a = 'popular' >>>> i = a.find('o') >>>> j = a.find('a') >>>> a[i:j] > 'opul' > > Well, I expected a[i:j] to be 'opula', and can't think of any reason why > this is not happening. So, can anybody help me out about this? Thank you > very much. Your subject line says: Bizarre behavior of the 'find' method of strings What makes you think this is a problem with the find method? As a programmer, you should be able to isolate where the problem *actually* occurs: >>> a = 'popular' >>> a.find('o') 1 >>> a.find('a') 5 So there is no problem with the find method: it correctly finds the index (starting at zero, not one) of the first (going left-to-right) matching substring. Now, if you take a slice, you get an unexpected (to you) result: >>> a[1:5] 'opul' It doesn't matter where the 1 and 5 come from. The slice can't tell that they were the output of find, or how they were generated: >>> a[1000-999:20/4] 'opul' Now that you have isolated the actual problem, you can ask a better question: "Why does slicing not work the way I expect?" Answer: because Python uses half-open slices, where the end parameter is not included. The reason for that is that experience with other languages shows that it leads to fewer "off-by-one" errors. See also: http://mail.python.org/pipermail/tutor/2010-December/080592.html http://en.wikipedia.org/wiki/Off-by-one_error -- Steven From lanyjie at yahoo.com Wed Aug 10 22:58:22 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Aug 2011 19:58:22 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> Message-ID: <1313031502.48609.YahooMailNeo@web121515.mail.ne1.yahoo.com> On Wed, Aug 10, 2011 at 1:58 PM, Yingjie Lan wrote: > Is it possible for python to allow free splitting of single-line statements > without the backslashes, if we impose that expressions can only be split > when it is not yet a finished expression? :The trouble is that in a lot of cases, the next statement after an :unfinished expression could conceivably be a continuation of it. If :this were permitted, it would have to also require that the :continuation lines be indented, to avoid the problem described above. :It'd still have the potential to mis-diagnose errors, though. Indentation is a good idea to reduce the likelihood of such troubles. and also produce code that is easier to read. Yingjie From miki.tebeka at gmail.com Wed Aug 10 23:24:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:24:53 -0700 (PDT) Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: You can download the sources tarball and when building specify the compiler. See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw From miki.tebeka at gmail.com Wed Aug 10 23:24:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:24:53 -0700 (PDT) Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: You can download the sources tarball and when building specify the compiler. See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw From miki.tebeka at gmail.com Wed Aug 10 23:35:54 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 10 Aug 2011 20:35:54 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: Python built in types are enough for this problem IMO. You can use sets of tuples to specify ticket and drawings and then just do set intersection. Say the drawing is set([(5, 'wb'), (1, 'wb'), (45, 'wb'), (23, 'wb'), (27, 'wb')]) (keeping black ball out). The you can create a score function: Side note: I might used a namedtuple to have drawing.whites, drawing.black. def score(ticket_whites, ticket_black, drawing_whites, drawing_black): num_whites = ticket_whites & drawing_whites black_matching = ticket_black == drawing_black return { (2, True) : 1, (3, False) : 2, (3, True) : 3, (4, False) : 4, (4, True) : 5, (5, False) : 6, (5, True) : 10 }[(num_whites, black_matching)] From philip at semanchuk.com Wed Aug 10 23:36:52 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 10 Aug 2011 23:36:52 -0400 Subject: multiprocessing timing issue In-Reply-To: References: Message-ID: On Aug 9, 2011, at 1:07 PM, Tim Arnold wrote: > Hi, I'm having problems with an empty Queue using multiprocessing. > > The task: > I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. > I'm using multiprocessing to do the data-gathering simultaneously. > > Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. > > My problem is that sometimes the Queue is empty and I guess it's > because the get_data() method takes a lot of time. > > I've used multiprocessing before, but never with a Queue like this. > Any notes or suggestions are very welcome. Hi Tim, THis might be a dumb question, but...why is it a problem if the queue is empty? It sounds like you figured out already that get_data() sometimes takes longer than your timeout. So either increase your timeout or learn to live with the fact that the queue is sometimes empty. I don't mean to be rude, I just don't understand the problem. Cheers Philip From clp2 at rebertia.com Wed Aug 10 23:49:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 20:49:49 -0700 Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 10, 2011 at 7:56 PM, Steven D'Aprano wrote: > On Thu, 11 Aug 2011 11:24 am Jim wrote: > >> Greetings, folks, >> >> I am using python 2.7.2. Here is something I got: >>>>> a = 'popular' >>>>> i = a.find('o') >>>>> j = a.find('a') >>>>> a[i:j] >> 'opul' >> >> Well, I expected a[i:j] to be 'opula', and can't think of any reason why >> this is not happening. So, can anybody help me out about this? Thank you >> very much. > "Why does slicing not work the way I expect?" > > Answer: because Python uses half-open slices, where the end parameter is not > included. The reason for that is that experience with other languages shows > that it leads to fewer "off-by-one" errors. > > See also: > > http://mail.python.org/pipermail/tutor/2010-December/080592.html > http://en.wikipedia.org/wiki/Off-by-one_error And further: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html Cheers, Chris From drsalists at gmail.com Thu Aug 11 00:03:28 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 10 Aug 2011 21:03:28 -0700 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: FWIW, a few months ago I was working on a database application on Windows, and I benchmarked the psyco-enhanced version consistently running slower than the non-psyco version. The same code on Linux was faster with psyco though. If you need performance, and you aren't constrained by module availability, you probably should use PyPy instead. On Wed, Aug 10, 2011 at 3:44 PM, Gelonida N wrote: > Hi, > > I'd like to install psyco on my windows host > > > I'm using python 2.6.4 (32 bit version) > > I installed easy_intall and pip > > easy_install psyco > and > pip install psyco fail both with the message > error: Setup script exited with error: Unable to find vcvarsall.bat > > > I read, that this means I shoul dinstall a C-compiler > I also read, that I should NOT Micrusoft Visual C++ Express 2010 > (which is unfortunately exactly the version, which I installed for some > other activity. > > > So my question: > > - If I install visual Studio 2008 addtiojnally to visualstudia 2010, > will easy_install find this compiler? > - I read about the alternative of using MingW instead of Visual Studio > Express 2008. > > What could influence my choice of Compiler? > > Thanks for any suggestions > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Aug 11 00:16:54 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 21:16:54 -0700 Subject: allow line break at operators In-Reply-To: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, I think of it more as that Python deigns to permit semicolons. > But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? Hell no, considering that the sizable majority of lines *aren't* split, which makes those semicolons completely redundant to their accompanying newlines. We'd be practicing poor Huffman coding by optimizing for the *un*common case. It would also add punctuational noise to what is otherwise an amazingly clean and readable syntax. Accidental semicolon omission is (IMO) the most irritating source of syntax (and, inadvertently, sometimes other more serious) errors in curly-braced programming languages. Such a core syntax feature is not going to be changed lightly (or likely ever). Cheers, Chris From steve+comp.lang.python at pearwood.info Thu Aug 11 00:18:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 14:18:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> Message-ID: <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in > magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? Why on earth would you want to break backwards compatibility of millions of Python scripts and programs, and require extra, unnecessary line-noise on every single line of Python code, just so that you can occasionally avoid a writing a pair of parentheses? This will never happen. Forget it. Python is more likely to get static types than compulsory semi-colons. -- Steven From jianbao.tao at gmail.com Thu Aug 11 00:29:01 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 21:29:01 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for all you guys. Now I got it. To Steven, I was in a little rush when I put this post. But you are right. It's not the find method's problem. From jianbao.tao at gmail.com Thu Aug 11 00:29:01 2011 From: jianbao.tao at gmail.com (Jim) Date: Wed, 10 Aug 2011 21:29:01 -0700 (PDT) Subject: Bizarre behavior of the 'find' method of strings In-Reply-To: References: <2e5f052a-4922-433d-bbea-ec0c13e08a42@glegroupsg2000goo.googlegroups.com> <4e4344ef$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for all you guys. Now I got it. To Steven, I was in a little rush when I put this post. But you are right. It's not the find method's problem. From fd0man at gmail.com Thu Aug 11 00:51:52 2011 From: fd0man at gmail.com (Michael Trausch) Date: Thu, 11 Aug 2011 00:51:52 -0400 Subject: allow line break at operators In-Reply-To: <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: Perhaps it could be made an optional thing to enable; for example, some languages by default do dynamic typing, but with an option contained as the first statement of the file can enforce static typing. On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? > > Yingjie > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Thu Aug 11 00:59:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 04:59:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e432323$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Seebs wrote: >> On 2011-08-10, Chris Angelico wrote: >>> And if we require {} then truly free indentation should be OK too! But >>> it wouldn't be Python any more. >> Would it really not be Python at all? > Of course it wouldn't be. Every function, class, if, while, for, > try...except block etc. in existing Python code would be illegal if {} were > required. So? Since there has never been an indentation-related problem in the history of human endeavors, automatically adding the braces would be completely trivial. How much of the language *specification* would change? > In general, languages that aim to look like executable pseudo-code will > converge on a similar look, because executable pseudo-code tends to be > based on natural language (usually English) and mathematics syntax. This is an interesting point. I guess I meant "look like" in a more abstract sense; the basic idea of what it's like to read the code, and what you have to keep in mind while doing so. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 00:59:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 04:59:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On 2011-08-10, Ben Finney wrote: > Seebs writes: >> On 2011-08-10, Chris Angelico wrote: >> > And if we require {} then truly free indentation should be OK too! >> > But it wouldn't be Python any more. >> Would it really not be Python at all? > See the Python interpreter's response to ???from __future__ import braces???. I'm aware of that. I have seen all the counterarguments, and what I've mostly become convinced of is this: 1. Indentation as flow control was a bad idea. 2. People are subconsciously aware of this. 3. There is a HUGE degree of emotional investment in defending it. The responses I have seen on this issue are highly emotional, full of insults, full of blame-throwing, and utterly contrary to the basic engineering spirit I usually see in programming communities. In other languages, and even in Python on any issue but this one, I regularly see people acknowledge shortcomings and explain either why they think the tradeoffs are good, or why they are willing to put up with it anyway. The characteristic vehemence and hostility this issue produces are the surest sign of people who have a desperate need not to acknowledge the elephant in the room. >> I've seen bits of code in preprocessing-based "Python with {}" type >> things, and they still look like Python to me, only they favor >> explicit over implicit a little more strongly. > They introduce unnecessary ambiguity: the indentation-as-structure and > braces-as-structure can then disagree. Yes, they can. > In which case either the Python interpreter must guess the programmer's > intent (very un-Pythonic), or it throws an error and the programmer must > do busy-work to keep braces and indentation in agreement (also > un-Pythonic). The obvious answer would be: * Braces win because they are explicit rather than implicit. * Everyone would use things configured to throw a warning or error. The thing is... This whole argument rests on the assumption that if there are no braces, there is only one set of things, but if you have braces, there are two. This is untrue. If there are no braces, there are two things describing flow control; indentation and programmer intent. With braces, there's three. The most common misalignment is between the code as interpreted by the computer and the programmer's intent. Neither system prevents this, but that's where all the real hassle comes from. My expectation would be that the only times braces and indentation would be "ambiguous" would be cases where the indentation got screwed up. In these cases, I would MUCH prefer to get a fatal error than to have things run in a way entirely unrelated to the intent I had when I wrote the code. > The ambiguity is resolved by having exactly one of indentation or braces > determining structure: Python uses indentation. In which case, braces > are pointless for indicating block structure. I don't think so, any more than I think parentheses which happen to align with the existing precendence rules are pointless. In the real world, we are confronted constantly with tools which work perfectly with every programming language but Python or very old FORTRAN, but which mangle Python code sporadically and inexplicably. Mail servers chew up whitespace like there's no tomorrow. Web pages find innovative new explanations for why those leading spaces don't need to be displayed. I like Python a lot in some ways, but I am really sick of the insistance that this godawful wart is the sublime epitome of all perfection, never to be improved on. It was a really interesting experiment. As sometimes happens, the experiment discovered things that no one could have reasonably anticipated without running the experiment. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Thu Aug 11 01:07:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Aug 2011 22:07:42 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: > On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? On Wed, Aug 10, 2011 at 9:51 PM, Michael Trausch wrote: > Perhaps it could be made an optional thing to enable; for example, some > languages by default do dynamic typing, but with an option contained as the > first statement of the file can enforce static typing. I am intrigued. What languages(s) have the feature you refer to? Cheers, Chris From fd0man at gmail.com Thu Aug 11 01:17:37 2011 From: fd0man at gmail.com (Michael Trausch) Date: Thu, 11 Aug 2011 01:17:37 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: VB (classic; .NET versions no longer have it) had an "option explicit" where you had to define each variable explicitly, otherwise by default you created variables simply by assigning to them. They did it that way to enable backwards compatibility for those who wanted the old style. Most people wound up using "option explicit" and it is now the default (and afaik only, but I don't use vb.net so I cannot say that for sure) way of doing things. Somthing like an "option" keyword (which would only be a keyword until the first executable statement, e.g., would have to be before even imports) could enable things like "semicolon" or "explicit", or whatever really, and only affect those who opt in. If no code is ever seen using the option, it can even be removed. Wouldn't be a bad way to test changes that would impact the syntax of the language, actually... On Aug 11, 2011 1:07 AM, "Chris Rebert" wrote: >> On Aug 10, 2011 10:57 PM, "Yingjie Lan" wrote: >>> :And if we require {} then truly free indentation should be OK too! But >>> >>> :it wouldn't be Python any more. >>> >>> Of course, but not the case with ';'. Currently ';' is optional in Python, >>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>> magnitude. >>> >>> So the decision is: shall we change ';' from optional to mandatory >>> to allow free line splitting? > > On Wed, Aug 10, 2011 at 9:51 PM, Michael Trausch wrote: >> Perhaps it could be made an optional thing to enable; for example, some >> languages by default do dynamic typing, but with an option contained as the >> first statement of the file can enforce static typing. > > I am intrigued. What languages(s) have the feature you refer to? > > Cheers, > Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Aug 11 01:26:35 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 10 Aug 2011 22:26:35 -0700 Subject: multiprocessing timing issue References: Message-ID: Tim Arnold wrote: > >The task: >I have a bunch of chapters that I want to gather data on individually >and then update a report database with the results. >I'm using multiprocessing to do the data-gathering simultaneously. > >Each chapter report gets put on a Queue in their separate processes. >Then each report gets picked off the queue and the report database is >updated with the results. > >My problem is that sometimes the Queue is empty and I guess it's >because the get_data() method takes a lot of time. > >I've used multiprocessing before, but never with a Queue like this. >Any notes or suggestions are very welcome. The obvious implication is that your timeout is simply not long enough for your common cases. If you know how many chapters to expect, why have a timeout at all? Why not just wait forever? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From casevh at gmail.com Thu Aug 11 01:44:47 2011 From: casevh at gmail.com (casevh) Date: Wed, 10 Aug 2011 22:44:47 -0700 (PDT) Subject: Puzzled about the output of my demo of a proof of The Euler Series References: Message-ID: On Aug 10, 4:57?pm, "Richard D. Moores" wrote: > I saw an interesting proof of the limit of The Euler Series on > math.stackexchange.com at > . > Scroll down to Hans Lundmark's post. > > I thought I'd try to see this "pinching down" on the limit of pi**2/6. > See my attempt, and output for n = 150 at > . What puzzles me is that > upper_bound_partial_sum (lines 39 and 60) is always smaller than the > limit. It should be greater than the limit, right? If not, no pinching > between upper_bound_partial_sum and lower_bound_partial_sum. > > I've checked and double-checked the computation, but can't figure out > what's wrong. > > Thanks, > > Dick Moores The math is correct. The proof only asserts that sum(1/k^2) is between the upper and lower partial sums. The upper and lower partial sums both converge to pi^2/6 from below and since the sum(1/k^2) is between the two partial sums, it must also converge to pi^2/6. Try calculating sum(1/k^2) for k in range(1, 2**n) and compare that with the upper and lower sums. I verified it with several values up to n=20. casevh From ben+python at benfinney.id.au Thu Aug 11 01:56:47 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 11 Aug 2011 15:56:47 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <87obzwh4o0.fsf@benfinney.id.au> Seebs writes: > On 2011-08-10, Ben Finney wrote: > > Seebs writes: > >> On 2011-08-10, Chris Angelico wrote: > >> > And if we require {} then truly free indentation should be OK too! > >> > But it wouldn't be Python any more. > > >> Would it really not be Python at all? > > > See the Python interpreter's response to ???from __future__ import braces???. > > I'm aware of that. I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. > 2. People are subconsciously aware of this. What evidence do you have of these? The latter, especially, seems to be mere opinion unfounded in any measurement. > 3. There is a HUGE degree of emotional investment in defending it. That same observation is consistent with: * Indentation as block syntax is an excellent idea. * Python programmers are quite consciously aware of this. So I don't see a reason to prefer your inference over mine. > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing Again, I don't know where you've been observing that, but it's not what I've seen. > I like Python a lot in some ways, but I am really sick of the > insistance that this godawful wart is the sublime epitome of all > perfection, never to be improved on. It was a really interesting > experiment. As sometimes happens, the experiment discovered things > that no one could have reasonably anticipated without running the > experiment. You're welcome to attempt to demonstrate the superiority of some other Python-with-braces, but it will (a) be un-Pythonic, and (b) be unlikely to gain the efforts of people who don't think what you're addressing is a problem. Since that latter set of people includes most Python programmers who have reacted negatively to the proposal, you may want to re-think whether your effort is worthwhile. Meanwhile, we'll continue being productive with Python's indentation-as-structure. -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson, 1813-08-13 | Ben Finney From przemolicc at poczta.fm Thu Aug 11 02:30:08 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 08:30:08 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: <20110811063007.GA4990@host.pgf.com.pl> On Wed, Aug 10, 2011 at 03:38:42PM +0100, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 3:38 PM, Chris Angelico wrote: > > Which SQL library are you suing? > > And this is why I should proof-read BEFORE, not AFTER, sending. > > Which SQL library are you *using*? cx_oracle Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From przemolicc at poczta.fm Thu Aug 11 02:40:30 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 08:40:30 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> Message-ID: <20110811064030.GB4990@host.pgf.com.pl> On Wed, Aug 10, 2011 at 06:20:10PM +0200, Stefan Behnel wrote: > przemolicc at poczta.fm, 10.08.2011 15:31: >> On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: >>> On Wed, Aug 10, 2011 at 12:17 PM, wrote: >>>> I'd like to write a python (2.6/2.7) script which connects to database, fetches >>>> hundreds of thousands of rows, concat them (basically: create XML) >>>> and then put the result into another table. Do I have any choice >>>> regarding string concatenation in Python from the performance point of view ? >>>> Since the number of rows is big I'd like to use the fastest possible library >>>> (if there is any choice). Can you recommend me something ? >>> >>> First off, I have no idea why you would want to create an XML dump of >>> hundreds of thousands of rows, only to store it in another table. >>> However, if that is your intention, list joining is about as efficient >>> as you're going to get in Python: >>> >>> lst=["asdf","qwer","zxcv"] # feel free to add 399,997 more list entries >>> xml=""+"".join(lst)+"" >>> >>> This sets xml to 'asdfqwerzxcv' which >>> may or may not be what you're after. >> >> since this process (XML building) is running now inside database (using native SQL commands) >> and is one-thread task it is quite slow. What I wanted to do is to spawn several python subprocesses in parallel which >> will concat subset of the whole table (and then merge all of them at the end). >> Basically: >> - fetch all rows from the database (up to 1 million): what is recommended data type ? >> - spawn X python processes each one: >> - concat its own subset >> - merge the result from all the subprocesses >> >> This task is running on a server which has many but slow cores and I am trying to divide this task >> into many subtasks. > > Makes sense to me. Note that the really good DBMSes (namely, PostgreSQL) > come with built-in Python support. The data are in Oracle so I have to use cx_oracle. > You still didn't provide enough information to make me understand why you > need XML in between one database and another (or the same?), but if you > go that route, you can just read data through multiple connections in > multiple threads (or processes), have each build up one (or more) XML > entries, and then push those into a queue. Then another thread (or more > than one) can read from that queue and write the XML items into a file > (or another database) as they come in. I am not a database developer so I don't want to change the whole process of data flow between applications in my company. Another process is reading this XML from particular Oracle table so I have to put the final XML there. > If your data has a considerable size, I wouldn't use string concatenation > or joining at all (note that it requires 2x the memory during > concatenation), but rather write it into a file, or even just process the > data on the fly, i.e. write it back into the target table right away. > Reading a file back in after the fact is much more resource friendly than > keeping huge amounts of data in memory. And disk speed is usually not a > problem when streaming data from disk into a database. This server has 256 GB of RAM so memory is not a problem. Also the select which fetches the data is sorted. That is why I have to carefully divide into subtasks and then merge it in correct order. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Dom marzen - kup lub wynajmij taniej niz myslisz! Szukaj >> http://linkint.pl/f2a0d From lanyjie at yahoo.com Thu Aug 11 03:01:28 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:01:28 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <1313046088.54814.YahooMailNeo@web121513.mail.ne1.yahoo.com> ________________________________ From: Michael Trausch To: Yingjie Lan Cc: Chris Angelico ; "python-list at python.org" Sent: Thursday, August 11, 2011 12:51 PM Subject: Re: allow line break at operators > Perhaps it could be made an optional thing to enable; for example, some languages by default do dynamic typing, but with an option contained as the first statement of the file can enforce static typing. That is a brilliant idea! Python code can specify encoding in the beginning, we might use another similar line to opt in for that kind of language features. Once in that ';'-required mode, the trouble of typing a ';' at end of almost every line can be easily avoided by a smart editor: 1) when a single 'Return' key is hit, and the line is not ending in ':' or ';' (white spaces and comments discarded), automatically append a ';' to the end of the line. 2) to continue the line to the next line, hit "Shift+Enter", then no ';' will be appended to the line. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From paddy3118 at googlemail.com Thu Aug 11 03:19:34 2011 From: paddy3118 at googlemail.com (Paddy) Date: Thu, 11 Aug 2011 00:19:34 -0700 (PDT) Subject: Python 3.X: nonlocal support in eval/exec? Message-ID: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> We can access nonlocal variables in a function, but if we were to eval/ exec the function we cannot set up a nested stack of evironment dicts. We are limited to just two: global and local. How about eval/exec take a new env argument that is a nested dictionary whose outer level corresponds to locals, and which has a __up__ value which is the next outer level environment dict. The outermost level of the nested dictionary would correspond to the global level? I haven't given much thought to my suggested solution - I just didn't want to leave a possible solution out. The major point is that there seems to be no support for nonlocal in eval/exec (unless, trivially, nonlocal==global). - Paddy. From lanyjie at yahoo.com Thu Aug 11 03:24:24 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:24:24 -0700 (PDT) Subject: allow line break at operators In-Reply-To: <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> ________________________________ From: Steven D'Aprano To: python-list at python.org Sent: Thursday, August 11, 2011 12:18 PM Subject: Re: allow line break at operators On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > :And if we require {} then truly free indentation should be OK too! But > > :it wouldn't be Python any more. > > Of course, but not the case with ';'. Currently ';' is optional in Python, > But '{' is used for dicts. Clearly, ';' and '{' are different in > magnitude. > > So the decision is: shall we change ';' from optional to mandatory > to allow free line splitting? :Why on earth would you want to break backwards compatibility of millions of :Python scripts and programs, and require extra, unnecessary line-noise on :every single line of Python code, just so that you can occasionally avoid a :writing a pair of parentheses? I think allowing free line splitting (without parentheses -- that's artifitial and requires the coder to serve the machine rather than the other way around) with proper indentation will produce truely ergonomic code layout (well, assuming you also like properly indented code). And this can be done almost hassle-free for the coder. The compatibility problem can be solved by something like a preprocessor indicator to opt in this new language feature, or, if we are determined to favor this new feature, all old code can be easily converted. The worst case is that the coder has to opt in. The trouble of adding a ';' to most of the lines can also be avoided by a smart editor (see my other reply). Python serves the coder, not the other way around. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu Aug 11 03:40:52 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Aug 2011 08:40:52 +0100 Subject: Directions on accessing shared folder in windows network In-Reply-To: References: Message-ID: <4E438784.6020804@timgolden.me.uk> On 10/08/2011 21:43, Christian Heimes wrote: > Am 10.08.2011 21:52, schrieb Ameet Nanda: >> Hi, >> >> Can anyone point me to a way to access windows shared folders from the >> network using a python script. I tried accessing using open, which is >> mentioned to work perfectly on the web, but it gives me following errors > > The open() function wraps the fopen() function, which doesn't support > UNC, just local paths. You have to mount the network share first (assign > a drive letter). Christian, with respect: what are you talking about? print open (r"\\localhost\c$\python27\python.exe").read (100) The OP's problem is that he's trying to call open () on the share itself, not on a file within it. TJG From tjreedy at udel.edu Thu Aug 11 03:48:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Aug 2011 03:48:28 -0400 Subject: Python 3.X: nonlocal support in eval/exec? In-Reply-To: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> References: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> Message-ID: On 8/11/2011 3:19 AM, Paddy wrote: > We can access nonlocal variables in a function, but if we were to eval/ > exec the function we cannot set up a nested stack of evironment dicts. > We are limited to just two: global and local. Right. That was and is Python's execution model. Note that when you exec code, including a function call, the locals passed is the local context in which the code is executed. It is not the locals of any particular function called by the exec-ed code. If you exec a function that is a closure, the closure or non-local objects come with the function. A 'stack of dicts' has nothing to do with how function and nested funcs operate. -- Terry Jan Reedy From clp2 at rebertia.com Thu Aug 11 03:50:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Aug 2011 00:50:26 -0700 Subject: allow line break at operators In-Reply-To: <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Thu, Aug 11, 2011 at 12:24 AM, Yingjie Lan wrote: > From: Steven D'Aprano > On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > :Why on earth would you want to break backwards compatibility of millions of > :Python scripts and programs, and require extra, unnecessary line-noise on > :every single line of Python code, just so that you can occasionally avoid a > :writing a pair of parentheses? > > I think allowing free line splitting (without parentheses -- that's > artifitial and > requires the coder to serve the machine rather than the other way around) > with proper indentation will produce truely ergonomic code layout (well, > assuming you also like properly indented code). > > And this can be done almost hassle-free for the coder. > The trouble of adding a ';' to most of the lines can also be > avoided by a smart editor (see my other reply). The trouble of dealing with long lines can be avoided by a smart editor. It's called line wrap. Cheers, Chris From lanyjie at yahoo.com Thu Aug 11 03:53:55 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 00:53:55 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> ________________________________ From: Chris Rebert To: Yingjie Lan Cc: "python-list at python.org" Sent: Thursday, August 11, 2011 3:50 PM Subject: Re: allow line break at operators On Thu, Aug 11, 2011 at 12:24 AM, Yingjie Lan wrote: > From: Steven D'Aprano > On Thu, 11 Aug 2011 12:52 pm Yingjie Lan wrote: > >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, >> But '{' is used for dicts. Clearly, ';' and '{' are different in >> magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > :Why on earth would you want to break backwards compatibility of millions of > :Python scripts and programs, and require extra, unnecessary line-noise on > :every single line of Python code, just so that you can occasionally avoid a > :writing a pair of parentheses? > > I think allowing free line splitting (without parentheses -- that's > artifitial and > requires the coder to serve the machine rather than the other way around) > with proper indentation will produce truely ergonomic code layout (well, > assuming you also like properly indented code). > > And this can be done almost hassle-free for the coder. > The trouble of adding a ';' to most of the lines can also be > avoided by a smart editor (see my other reply). :The trouble of dealing with long lines can be avoided by a smart :editor. It's called line wrap. Yeah, usually they just wrap it pretty arbitrarily, and you don't have any control, isn't it? Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From anacrolix at gmail.com Thu Aug 11 03:55:02 2011 From: anacrolix at gmail.com (Matt Joiner) Date: Thu, 11 Aug 2011 17:55:02 +1000 Subject: shouldn't ctypes cast as it does in C? Message-ID: http://www.mememaker.net/images/public/201108110739296015.jpg From nobody at nowhere.com Thu Aug 11 04:15:13 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Aug 2011 09:15:13 +0100 Subject: subprocess.Popen and thread module References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Message-ID: Danny Wong (dannwong) wrote: > ? ? ? ?cmd_output = subprocess.Popen(['scm', 'load', '--force', > '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) >? ? ? ?status = cmd_output.wait() If you redirect stdout and/or stderr to a pipe, you must wait for EOF before calling wait(), otherwise you risk deadlock (the process blocks waiting for Python to read data from the pipe while Python is blocked waiting for the process to terminate). And if you redirect both stdout and stderr to pipes, you must either use multiple threads or non-blocking I/O, otherwise you risk deadlock (the process blocks waiting for Python to read data from one of the pipes while Python is blocked waiting for the process to write to the other pipe). I suggest looking at the .communicate() method of the Popen class. From rosuav at gmail.com Thu Aug 11 04:24:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 09:24:04 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: On Thu, Aug 11, 2011 at 6:17 AM, Michael Trausch wrote: > Somthing like an "option" keyword (which would only be a keyword until the > first executable statement, e.g., would have to be before even imports) > could enable things like "semicolon" or "explicit", or whatever really, and > only affect those who opt in. If no code is ever seen using the option, it > can even be removed. Wouldn't be a bad way to test changes that would impact > the syntax of the language, actually... Python already has a syntax like this: from __future__ import statictyping Although I'm not sure how you'd go about implementing it plausibly. It'd be a fairly backward-incompatible change; what would happen to the modules you import? Either you would have to have a duplicate set (one that uses statictyping and one that doesn't), or you'd have to have statictyping somehow work on a per-module basis. As far as I know, most of the other future statements are per-module (with the possible exception of barry_as_FLUFL, which until today I was not aware of). Would static typing then apply only to module-level variables and function-local variables, with the values in lists/tuples/dicts/objects/etc/etc/etc still being dynamically typed? I think it'd be easier to fork Python and give it a new name. ChrisA From gelonida at gmail.com Thu Aug 11 04:59:40 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 10:59:40 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv Message-ID: Hi, Short version ============== I have a system with ipython installed by my Ubuntu distribution I created a virtualenv with > virtualenv ~/myenv I installed ipython > pip install ipython --upgrade When using ipython I notice, that it does import the modules from my default python setup and not from my virtualenv. Why? What could I have done differently? Long version =================== I created a virtualenv with virtualenv ~/myenv THis inherits my machines site packages. The reason I'm not using virutalenv --no-site-packages ~/myenv is that I would like to use some of the site packages, in particular some, that I don't want to compile due to huge package dependencies. Small problem is, that if I run ipython in a virtualenv it will still call /usr/bin/ipython and if I check the modules, that I import I seem to import the modules of my default environment and not the ones of my virtualenv. So I decided I will install my own version of ipython in my virtualenv The output if pip install ipython is a little confusing. > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 As I am a normal user and I don't have permissions to overwrite /usr/lib I decided to just give it a try and hope it will install in my virtualenv path and not in /usr/lib/... After running > pip install ipython --upgrade I have my own version of ipython. However when calling and using it I notice it still imports the modules from my default python and not from my virtualenv? Why does ipython ignore the virtualenv's settings? I know there are workarounds, but I wondered why it doesn't work out of the box. From gelonida at gmail.com Thu Aug 11 05:29:54 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 11:29:54 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: On 08/11/2011 06:03 AM, Dan Stromberg wrote: Hi Dan, > FWIW, a few months ago I was working on a database application on > Windows, and I benchmarked the psyco-enhanced version consistently > running slower than the non-psyco version. The same code on Linux was > faster with psyco though. Good to know. I wanted to make the test myself though. There's one / two modules where I would expect an increase in performance. The rest of the application will rather definitely not benefit from psyco. Also one thing, that I wanted to try is to not use psyco for the application itself, but just for running py2exe a little faster. > > If you need performance, and you aren't constrained by module > availability, you probably should use PyPy instead. Well many module depenencies. :-( and also a lot of old legacy code, which will probably not survive PyPy (files not being closed explicitely for example) From bex.lewis at gmail.com Thu Aug 11 05:39:06 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Thu, 11 Aug 2011 02:39:06 -0700 (PDT) Subject: ipython installed in virtualenv seems not to use virtualenv References: Message-ID: Hi, are you doing a pip install from within your virtualenv (sourcing the virtualenv and THEN installing ipython)? Becky Lewis On Aug 11, 9:59?am, Gelonida N wrote: > Hi, > > Short version > ============== > I have a system with ipython installed by my Ubuntu distribution > I created a virtualenv with> virtualenv ~/myenv > I installed ipython > > pip install ipython --upgrade > > When using ipython I notice, that it does import the modules from my > default python setup and not from ?my virtualenv. > > Why? > What could I have done differently? > > Long version > =================== > > I created a ?virtualenv with > > virtualenv ~/myenv > > THis inherits my machines site packages. > The reason I'm not using > > virutalenv --no-site-packages ~/myenv > > is that I would like to use some of the site packages, > in particular some, that I don't want to compile due to huge package > dependencies. > > Small problem is, that if I run ipython in a virtualenv > it will still call /usr/bin/ipython > > and if I check the modules, that I import I seem to import the modules > of my default environment and not the ones of my virtualenv. > > So I decided I will install my own version of ipython in my virtualenv > > The output if pip install ipython is a little confusing. > > > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 > > As I am a normal user and I don't have permissions to overwrite /usr/lib > I decided to just give it a try and hope it will install in my > virtualenv path and not in /usr/lib/... > > After running > > > pip install ipython --upgrade > > I have my own version of ipython. > > However when calling and using it I notice it still imports the modules > from my default python and not from my virtualenv? > > Why does ipython ignore the virtualenv's settings? > > I know there are workarounds, but I wondered why it doesn't work out of > the box. From gelonida at gmail.com Thu Aug 11 06:04:54 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 12:04:54 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv In-Reply-To: References: Message-ID: On 08/11/2011 11:39 AM, becky_lewis wrote: > Hi, > > are you doing a pip install from within your virtualenv (sourcing the > virtualenv and THEN installing ipython)? > Yes this is what I was doing. My default ipython without virtualenv is now: $ ipython -V 0.10 Within my virualenv it is now: $ ipython --version 0.11 which ipython indicates also, that is well placed in my virtual env's tree I forced a reinstall of the library, that was found by my virtualenv python, but was NOT found by my virtualenv ipython. and now everything works fine. This is weird. But I'm glad it's working now. Tried to reproduce the issue on another (rather similiar machine), but couldn't > Becky Lewis > > > On Aug 11, 9:59 am, Gelonida N wrote: >> Hi, >> >> Short version >> ============== >> I have a system with ipython installed by my Ubuntu distribution >> I created a virtualenv with> virtualenv ~/myenv >> I installed ipython >>> pip install ipython --upgrade >> >> When using ipython I notice, that it does import the modules from my >> default python setup and not from my virtualenv. >> >> Why? >> What could I have done differently? >> >> Long version >> =================== >> >> I created a virtualenv with >> >> virtualenv ~/myenv >> >> THis inherits my machines site packages. >> The reason I'm not using >> >> virutalenv --no-site-packages ~/myenv >> >> is that I would like to use some of the site packages, >> in particular some, that I don't want to compile due to huge package >> dependencies. >> >> Small problem is, that if I run ipython in a virtualenv >> it will still call /usr/bin/ipython >> >> and if I check the modules, that I import I seem to import the modules >> of my default environment and not the ones of my virtualenv. >> >> So I decided I will install my own version of ipython in my virtualenv >> >> The output if pip install ipython is a little confusing. >> >>> Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 >> >> As I am a normal user and I don't have permissions to overwrite /usr/lib >> I decided to just give it a try and hope it will install in my >> virtualenv path and not in /usr/lib/... >> >> After running >> >>> pip install ipython --upgrade >> >> I have my own version of ipython. >> >> However when calling and using it I notice it still imports the modules >> from my default python and not from my virtualenv? >> >> Why does ipython ignore the virtualenv's settings? >> >> I know there are workarounds, but I wondered why it doesn't work out of >> the box. > From zak.mc.kraken at libero.it Thu Aug 11 06:21:42 2011 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Thu, 11 Aug 2011 12:21:42 +0200 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: Yingjie Lan wrote: > :The trouble of dealing with long lines can be avoided by a smart > :editor. It's called line wrap. > > Yeah, usually they just wrap it pretty arbitrarily, > and you don't have any control, isn't it? umm... besides "notepad" pretty much any other serious "programmer editor" program try to do its best to deal with line wrap: the minimal I found is the wrapped line is "indented" at the same level of the flow, but I found editors where you can specify what to do (generally something like "indent the wrapped part 2 levels" or something like that) -- By ZeD From bex.lewis at gmail.com Thu Aug 11 06:28:35 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Thu, 11 Aug 2011 03:28:35 -0700 (PDT) Subject: ipython installed in virtualenv seems not to use virtualenv References: Message-ID: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> Just to add ... I ran through creating a virtualenv in the same manner as you: $ virtualenv SomeEnv $ source SomeEnv/bin/activate (SomeEnv)$ which pip /home/user/virtual/SomeEnv/bin/pip (SomeEnv)$ pip install ipython Requirement already satisfied (use --upgrade to upgrade): ipython in / usr/local/lib/python2.6/dist-packages Cleaning up... (SomeEnv)$ pip install ipython --upgrade ... pip installs ipython ... (SomeEnv)$ which ipython /home/user/virtual/SomeEnv/bin/ipython (SomeEnv)$ ipython Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) Type "copyright", "credits" or "license" for more information. IPython 0.11 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: import os In [2]: os.__file__ Out[2]: '/home/user/virtual/SomeEnv/lib/python2.6/os.pyc' In [3]: import dbus In [4]: dbus.__file__ Out[4]: '/usr/lib/pymodules/python2.6/dbus/__init__.pyc' ipython is using the virtualenv when it can find them and the system wide packages when they are not in the virtualenv. Hope that helps you track down the problem :/ On Aug 11, 9:59?am, Gelonida N wrote: > Hi, > > Short version > ============== > I have a system with ipython installed by my Ubuntu distribution > I created a virtualenv with> virtualenv ~/myenv > I installed ipython > > pip install ipython --upgrade > > When using ipython I notice, that it does import the modules from my > default python setup and not from ?my virtualenv. > > Why? > What could I have done differently? > > Long version > =================== > > I created a ?virtualenv with > > virtualenv ~/myenv > > THis inherits my machines site packages. > The reason I'm not using > > virutalenv --no-site-packages ~/myenv > > is that I would like to use some of the site packages, > in particular some, that I don't want to compile due to huge package > dependencies. > > Small problem is, that if I run ipython in a virtualenv > it will still call /usr/bin/ipython > > and if I check the modules, that I import I seem to import the modules > of my default environment and not the ones of my virtualenv. > > So I decided I will install my own version of ipython in my virtualenv > > The output if pip install ipython is a little confusing. > > > Requirement already satisfied (use --upgrade to upgrade): ipython in /usr/lib/pymodules/python2.6 > > As I am a normal user and I don't have permissions to overwrite /usr/lib > I decided to just give it a try and hope it will install in my > virtualenv path and not in /usr/lib/... > > After running > > > pip install ipython --upgrade > > I have my own version of ipython. > > However when calling and using it I notice it still imports the modules > from my default python and not from my virtualenv? > > Why does ipython ignore the virtualenv's settings? > > I know there are workarounds, but I wondered why it doesn't work out of > the box. From lanyjie at yahoo.com Thu Aug 11 06:59:06 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 03:59:06 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: <1313060346.15270.YahooMailNeo@web121517.mail.ne1.yahoo.com> > :The trouble of dealing with long lines can be avoided by a smart > :editor. It's called line wrap. > > Yeah, usually they just wrap it pretty arbitrarily, > and you don't have any control, isn't it? :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to do its best to deal with line wrap: the minimal I found is :the wrapped line is "indented" at the same level of the flow, but I found :editors where you can specify what to do (generally something like "indent :the wrapped part 2 levels" or something like that) Thanks for sharing that, which I am not quite aware of . BTW, do you think things like eclipse, emacs and vim also has such kind of functionality? Best of all, would certainly like to have IDLE have it, as I am teaching Python and would like to get them to start with a simple environment. Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 11 06:59:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 11:59:31 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811064030.GB4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 7:40 AM, wrote: > I am not a database developer so I don't want to change the whole process > of data flow between applications in my company. Another process is > reading this XML from particular Oracle table so I have to put the final XML there. I think you may be looking at a submission to http://www.thedailywtf.com/ soon. You seem to be working in a rather weird dataflow. :( Under the circumstances, you're probably going to want to go with the original ''.join() option. > This server has 256 GB of RAM so memory is not a problem. > Also the select which fetches the data is sorted. That is why I have to > carefully divide into subtasks and then merge it in correct order. There's no guarantee that all of that 256GB is available to you, of course. What may be the easiest way is to do the select in a single process, then partition it and use the Python multiprocessing module to split the job into several parts. Then you need only concatenate the handful of strings. You'll need to do some serious profiling, though, to ascertain where the bottleneck really is. Is it actually slow doing the concatenation, or is it taking more time reading/writing the disk? Is it actually all just taking time due to RAM usage? Proper string concatenation doesn't need a huge amount of CPU. ChrisA From gelonida at gmail.com Thu Aug 11 07:01:25 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 13:01:25 +0200 Subject: problem installing psyco on windows (Unable to find vcvarsall.bat) In-Reply-To: References: Message-ID: On 08/11/2011 05:24 AM, Miki Tebeka wrote: > You can download the sources tarball and when building specify the compiler. > See http://docs.python.org/install/index.html#gnu-c-cygwin-mingw Your answer put me on the right track. This works: - downloading mingw - downloading and extracting the tarfile the tar file - python setup.py build --compiler=mingw32 - python setup.py install In order to directly use pip / easy_install I created the file %USERPROFILE%\pydistutils.cfg with following two contents: [build] compiler=mingw32 and added mingw to my search path. now in can directly type pip install psyco Thanks again From gelonida at gmail.com Thu Aug 11 07:06:25 2011 From: gelonida at gmail.com (Gelonida N) Date: Thu, 11 Aug 2011 13:06:25 +0200 Subject: ipython installed in virtualenv seems not to use virtualenv In-Reply-To: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> References: <2e371925-ac95-404b-8379-09c9ece45865@f20g2000yqm.googlegroups.com> Message-ID: On 08/11/2011 12:28 PM, becky_lewis wrote: > Just to add ... > > I ran through creating a virtualenv in the same manner as you: > > > ipython is using the virtualenv when it can find them and the system > wide packages when they are not in the virtualenv. Hope that helps you > track down the problem :/ > > Thanks once more. I guess something in my virtualenv was broken. I can't reproduce the issue anymore since I forced a reinstall of one of y packages and now things work as I would have expected them to work. Happy that thins work now. Unhappy, that I did not understand why they went wrong before. From lanyjie at yahoo.com Thu Aug 11 07:12:35 2011 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 11 Aug 2011 04:12:35 -0700 (PDT) Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <4e43582e$0$29969$c3e8da3$5496439d@news.astraweb.com> <1313047464.90324.YahooMailNeo@web121515.mail.ne1.yahoo.com> <1313049235.13847.YahooMailNeo@web121510.mail.ne1.yahoo.com> Message-ID: <1313061155.82601.YahooMailNeo@web121502.mail.ne1.yahoo.com> ________________________________ From: Vito 'ZeD' De Tullio :umm... besides "notepad" pretty much any other serious "programmer editor" :program try to do its best to deal with line wrap: the minimal I found is :the wrapped line is "indented" at the same level of the flow, but I found :editors where you can specify what to do (generally something like "indent :the wrapped part 2 levels" or something like that) Well, even if one editor can do perfect line wrapping, breaking the line at places perfectly pleasing to the eye (put aside the fact that sometimes the line breaking could be based on the meaning of the code), it is unlikely to be cross-editor consistent. Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From przemolicc at poczta.fm Thu Aug 11 07:52:55 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 13:52:55 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: <20110811115255.GC4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 7:40 AM, wrote: > > I am not a database developer so I don't want to change the whole process > > of data flow between applications in my company. Another process is > > reading this XML from particular Oracle table so I have to put the final XML there. > > I think you may be looking at a submission to > http://www.thedailywtf.com/ soon. You seem to be working in a rather > weird dataflow. :( Under the circumstances, you're probably going to > want to go with the original ''.join() option. > > > This server has 256 GB of RAM so memory is not a problem. > > Also the select which fetches the data is sorted. That is why I have to > > carefully divide into subtasks and then merge it in correct order. > > There's no guarantee that all of that 256GB is available to you, of course. I am the admin of this server - the memory is available for us :-) > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. This is the way I am going to use. > You'll need to do some serious profiling, though, to ascertain where > the bottleneck really is. Is it actually slow doing the concatenation, > or is it taking more time reading/writing the disk? Is it actually all > just taking time due to RAM usage? Proper string concatenation doesn't > need a huge amount of CPU. I did my homework :-) - the CPU working on concatenation is a bottleneck. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Dziesiatki tysiecy ofert domow i mieszkan! Ogladaj >> http://linkint.pl/f2a0c From rosuav at gmail.com Thu Aug 11 07:58:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 12:58:36 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811115255.GC4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811115255.GC4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 12:52 PM, wrote: > On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: >> There's no guarantee that all of that 256GB is available to you, of course. > > I am the admin of this server - the memory is available for us :-) Hehe. I mean to any particular application; obviously you're way WAY beyond the 4GB limit of a 32-bit app, though there may be other limits; the main consideration here is contention - whatever Oracle itself is using, your concatenation app can't. >> You'll need to do some serious profiling, though, to ascertain where >> the bottleneck really is. Is it actually slow doing the concatenation, >> or is it taking more time reading/writing the disk? Is it actually all >> just taking time due to RAM usage? Proper string concatenation doesn't >> need a huge amount of CPU. > > I did my homework :-) - the CPU working on concatenation is a bottleneck. Glad you have! So many people don't. Looks like you have a plan there, then! ChrisA From stefan_ml at behnel.de Thu Aug 11 07:59:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Aug 2011 13:59:50 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: Chris Angelico, 11.08.2011 12:59: > On Thu, Aug 11, 2011 at 7:40 AM, wrote: >> I am not a database developer so I don't want to change the whole process >> of data flow between applications in my company. Another process is >> reading this XML from particular Oracle table so I have to put the final XML there. > > I think you may be looking at a submission to > http://www.thedailywtf.com/ soon. You seem to be working in a rather > weird dataflow. :( Under the circumstances, you're probably going to > want to go with the original ''.join() option. > >> This server has 256 GB of RAM so memory is not a problem. >> Also the select which fetches the data is sorted. That is why I have to >> carefully divide into subtasks and then merge it in correct order. > > There's no guarantee that all of that 256GB is available to you, of course. > > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. Or join them using an n-way merge. Stefan From jackhatterly at hotmail.com Thu Aug 11 08:28:50 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Thu, 11 Aug 2011 12:28:50 +0000 Subject: Cookie Problem In-Reply-To: References: , Message-ID: > Some of these values look wrong. Your 'path' ought to be as the > browser sees it, and your 'domain' ditto; ... > Otherwise, I would recommend omitting those elements and allowing the > defaults through. So I commented out those lines and now have this: #!/usr/bin/env python import string import os import datetime, Cookie, random import time ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = str(time.time()) print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') # The first time the page is run there will be no cookies if not cookie_string: print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = str(time.time()) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 # cookie['lastvisit']['path'] = '/var/www/html/my_site' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' # cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 else: # Run the page twice to retrieve the cookie print '

The returned cookie string was "' + cookie_string + '"

' # cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1], '.', '')[:-1] # load() parses the cookie string cookie.load(cookie_string) # Use the value attribute of the cookie to get it lastvisit = float(cookie['lastvisit'].value) for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' # for key, morsel in cookie.iteritems(): # print "key: %s\n" % key # print "morsel: %s\n\n" % morsel print '' and it does the same thing: namely, when I clear out the cookie, it creates a cookie but apparently not with the data I'm trying to push and when I refresh it displays all the keys without any morsel values. What do? TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Aug 11 08:29:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:29:29 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. I'm not aware of any language where indentation is used for flow control. Python is not one of those languages: it uses for, while, if, etc. for flow control, just like most other languages. It does however use indentation for grouping code into blocks -- a different concept. > 2. People are subconsciously aware of this. > 3. There is a HUGE degree of emotional investment in defending it. > > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing, and utterly contrary to the basic > engineering spirit So you say. You are free to hold whatever opinions you like, but have you considered that the reason people get emotional and angry when others insist that indentation as flow control should be discarded is because they actually believe that the "off-side rule" (as it is called) makes for a better language and a better coding experience? We're not defensive because we subconsciously know you're right, we're defensive because we consciously know you're wrong, have heard all the arguments a thousand times before, and are sick and tired of them. There are dozens, hundreds of brace languages, and 1-2 dozen using indentation, including Python. If braces are so important to you, go use one of those other languages, don't wreck the language we like by taking away one of the best features of the language. > I usually see in programming communities. In other languages, and even in > Python on any issue but this one, I regularly see people acknowledge > shortcomings and explain either why they think the tradeoffs are good, or > why they are willing to put up with it anyway. We're fully aware of the tradeoffs of significant indentation. We believe that brace languages get the trade-offs backwards: they optimise code for environments which mangle source code. 99.999% of code will never pass through a broken mail server that strips leading whitespace, or pasted into broken web forum software that mangles indentation, or go through any other broken tool that messes with indentation. Brace languages optimise for the 0.001% case, Python optimised the 99.999% case. Because people simply don't like it when their code's indentation doesn't match the actual semantics, people usually manually ensure that the two match, braces or no braces. Editors still have commands to indent and outdent blocks of code. There is no difference between (say) C or Pascal and Python in that regard. > * Braces win because they are explicit rather than implicit. There is nothing implicit about indentation. This false dichotomy between so-called explicit braces and allegedly implicit indentation gets thrown around all the time, but it is simply *wrong*. Indentation is not implicit. You (or your editor) has to add whitespace to the line, the parser has to see the whitespace, and an INDENT token is created for it. [...] > In the real world, we are confronted constantly with tools which work > perfectly with every programming language but Python or very old FORTRAN, And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any other languages with significant indentation. > but which mangle Python code sporadically and inexplicably. Mail servers > chew up whitespace like there's no tomorrow. Web pages find innovative > new explanations for why those leading spaces don't need to be displayed. No, most mail servers don't mangle whitespace in the body of the email, or in attachments. Some mail clients do, usually because they default to using HTML for text. So get a better mail client. Avoid pig-ignorant web forums that think that source code can be reflowed or that remove leading whitespace. Stop using Notepad, and use an editor that offers indent and outdent commands. If your mail server had a bug that deleted braces from emails, would you fix the bug, or would you insist that braces were a failed experiment and that C should stop using { } and start using BEGIN END like Pascal? -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 08:29:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:29:29 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I have seen all the counterarguments, and what I've > mostly become convinced of is this: > > 1. Indentation as flow control was a bad idea. I'm not aware of any language where indentation is used for flow control. Python is not one of those languages: it uses for, while, if, etc. for flow control, just like most other languages. It does however use indentation for grouping code into blocks -- a different concept. > 2. People are subconsciously aware of this. > 3. There is a HUGE degree of emotional investment in defending it. > > The responses I have seen on this issue are highly emotional, full of > insults, full of blame-throwing, and utterly contrary to the basic > engineering spirit So you say. You are free to hold whatever opinions you like, but have you considered that the reason people get emotional and angry when others insist that indentation as flow control should be discarded is because they actually believe that the "off-side rule" (as it is called) makes for a better language and a better coding experience? We're not defensive because we subconsciously know you're right, we're defensive because we consciously know you're wrong, have heard all the arguments a thousand times before, and are sick and tired of them. There are dozens, hundreds of brace languages, and 1-2 dozen using indentation, including Python. If braces are so important to you, go use one of those other languages, don't wreck the language we like by taking away one of the best features of the language. > I usually see in programming communities. In other languages, and even in > Python on any issue but this one, I regularly see people acknowledge > shortcomings and explain either why they think the tradeoffs are good, or > why they are willing to put up with it anyway. We're fully aware of the tradeoffs of significant indentation. We believe that brace languages get the trade-offs backwards: they optimise code for environments which mangle source code. 99.999% of code will never pass through a broken mail server that strips leading whitespace, or pasted into broken web forum software that mangles indentation, or go through any other broken tool that messes with indentation. Brace languages optimise for the 0.001% case, Python optimised the 99.999% case. Because people simply don't like it when their code's indentation doesn't match the actual semantics, people usually manually ensure that the two match, braces or no braces. Editors still have commands to indent and outdent blocks of code. There is no difference between (say) C or Pascal and Python in that regard. > * Braces win because they are explicit rather than implicit. There is nothing implicit about indentation. This false dichotomy between so-called explicit braces and allegedly implicit indentation gets thrown around all the time, but it is simply *wrong*. Indentation is not implicit. You (or your editor) has to add whitespace to the line, the parser has to see the whitespace, and an INDENT token is created for it. [...] > In the real world, we are confronted constantly with tools which work > perfectly with every programming language but Python or very old FORTRAN, And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any other languages with significant indentation. > but which mangle Python code sporadically and inexplicably. Mail servers > chew up whitespace like there's no tomorrow. Web pages find innovative > new explanations for why those leading spaces don't need to be displayed. No, most mail servers don't mangle whitespace in the body of the email, or in attachments. Some mail clients do, usually because they default to using HTML for text. So get a better mail client. Avoid pig-ignorant web forums that think that source code can be reflowed or that remove leading whitespace. Stop using Notepad, and use an editor that offers indent and outdent commands. If your mail server had a bug that deleted braces from emails, would you fix the bug, or would you insist that braces were a failed experiment and that C should stop using { } and start using BEGIN END like Pascal? -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 08:40:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 11 Aug 2011 22:40:27 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e43cdbc$0$29986$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: > indentation as flow control Gah! Of course, I meant indentation for blocks... after making the earlier point that indentation is *not* used for flow control, this was a particularly egregious error. How embarrassment. -- Steven From amitjaluf at gmail.com Thu Aug 11 08:56:27 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Thu, 11 Aug 2011 05:56:27 -0700 (PDT) Subject: indentation Message-ID: Hello Group, i just start python is it necessary indentation in python ? thanks in advance ... From python at mrabarnett.plus.com Thu Aug 11 09:03:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 14:03:22 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> Message-ID: <4E43D31A.2070306@mrabarnett.plus.com> On 11/08/2011 05:16, Chris Rebert wrote: > On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan wrote: >> :And if we require {} then truly free indentation should be OK too! But >> >> :it wouldn't be Python any more. >> >> Of course, but not the case with ';'. Currently ';' is optional in Python, > > I think of it more as that Python deigns to permit semicolons. > >> But '{' is used for dicts. Clearly, ';' and '{' are different in magnitude. >> >> So the decision is: shall we change ';' from optional to mandatory >> to allow free line splitting? > > Hell no, considering that the sizable majority of lines *aren't* > split, which makes those semicolons completely redundant to their > accompanying newlines. We'd be practicing poor Huffman coding by > optimizing for the *un*common case. It would also add punctuational > noise to what is otherwise an amazingly clean and readable syntax. > Accidental semicolon omission is (IMO) the most irritating source of > syntax (and, inadvertently, sometimes other more serious) errors in > curly-braced programming languages. > +1 > Such a core syntax feature is not going to be changed lightly (or likely ever). > I'm glad to hear that. :-) Although Python's use of indentation has its downside, we gain much more then we lose, IMHO. From python at mrabarnett.plus.com Thu Aug 11 09:15:33 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Aug 2011 14:15:33 +0100 Subject: indentation In-Reply-To: References: Message-ID: <4E43D5F5.7040303@mrabarnett.plus.com> On 11/08/2011 13:56, Amit Jaluf wrote: > Hello Group, > i just start python is it necessary indentation in python ? > Yes, indentation is part of the language. Even in programming languages where it isn't necessary, it's recommended because it makes the code easier to read. From tarmo.tapio at pp.inet.fi Thu Aug 11 09:18:39 2011 From: tarmo.tapio at pp.inet.fi (Tarmo Tapio) Date: Thu, 11 Aug 2011 16:18:39 +0300 Subject: python(x,y) Message-ID: <1E5E5A29601A441FAA2AC90CC27286B3@tarmoPC> I'm using scitools (Pythonxy). It plots the curve of the function (Figure window) but when I try to close Figure window I get the message 'Pythonw.exe do not answer'. My operation system is windows 7. This happened when I'm using Matplotlib for ploting. If I use gnuplot for plotting closing works ok. What is the problem? -------------- next part -------------- An HTML attachment was scrubbed... URL: From przemolicc at poczta.fm Thu Aug 11 09:46:13 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 15:46:13 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> Message-ID: <20110811134613.GE4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 11:59:31AM +0100, Chris Angelico wrote: > > What may be the easiest way is to do the select in a single process, > then partition it and use the Python multiprocessing module to split > the job into several parts. Then you need only concatenate the handful > of strings. This is the way I am going to use. But what is the best data type to hold so many rows and then operate on them ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zarabiasz 4 tys./miesiac? Damy wiecej! Sprawdz >> http://linkint.pl/f2a0f From rosuav at gmail.com Thu Aug 11 09:48:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Aug 2011 14:48:43 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811134613.GE4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 2:46 PM, wrote: > This is the way I am going to use. > But what is the best data type to hold so many rows and then operate on them ? > List of strings. Take it straight from your Oracle interface and work with it directly. ChrisA From amitjaluf at gmail.com Thu Aug 11 10:06:13 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Thu, 11 Aug 2011 07:06:13 -0700 (PDT) Subject: indentation References: Message-ID: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> On Aug 11, 8:15?am, MRAB wrote: > On 11/08/2011 13:56, Amit Jaluf wrote:> Hello Group, > > i just start python is it necessary indentation in python ? > > Yes, indentation is part of the language. > > Even in programming languages where it isn't necessary, it's > recommended because it makes the code easier to read. Thanks MRAB which book or tutorial i should for it(Python) i found "A Byte of Python " by Swaroop after that which tutorial(book) i have to read Please Suggest me ..... From paal.nilsen at gmail.com Thu Aug 11 10:15:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Thu, 11 Aug 2011 07:15:23 -0700 (PDT) Subject: indentation References: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> Message-ID: On 11 Aug, 16:06, Amit Jaluf wrote: > On Aug 11, 8:15?am, MRAB wrote: > > > On 11/08/2011 13:56, Amit Jaluf wrote:> Hello Group, > > > i just start python is it necessary indentation in python ? > > > Yes, indentation is part of the language. > > > Even in programming languages where it isn't necessary, it's > > recommended because it makes the code easier to read. > > Thanks MRAB > which book or tutorial i should for it(Python) > i found "A Byte of Python " by Swaroop > after that which tutorial(book) i have to read > Please Suggest me ..... http://www.python.org/dev/peps/pep-0008/ http://diveintopython.org/ http://learnpythonthehardway.org/ http://code.google.com/intl/no/edu/languages/google-python-class/introduction.html From anacrolix at gmail.com Thu Aug 11 10:28:04 2011 From: anacrolix at gmail.com (Matt Joiner) Date: Fri, 12 Aug 2011 00:28:04 +1000 Subject: [Python-ideas] allow line break at operators In-Reply-To: <4E43D2F2.1090004@mrabarnett.plus.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: +0.5 The "trailing \" workaround is nonobvious. Wrapping in () is noisy and already heavily used by other syntactical structures. Since a final ':' is needed anyway, i think this would be great. if a and b or c: do stuff() On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: > On 11/08/2011 05:16, Chris Rebert wrote: >> >> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>> >>> :And if we require {} then truly free indentation should be OK too! But >>> >>> :it wouldn't be Python any more. >>> >>> Of course, but not the case with ';'. Currently ';' is optional in >>> Python, >> >> I think of it more as that Python deigns to permit semicolons. >> >>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>> magnitude. >>> >>> So the decision is: shall we change ';' from optional to mandatory >>> to allow free line splitting? >> >> Hell no, considering that the sizable majority of lines *aren't* >> split, which makes those semicolons completely redundant to their >> accompanying newlines. We'd be practicing poor Huffman coding by >> optimizing for the *un*common case. It would also add punctuational >> noise to what is otherwise an amazingly clean and readable syntax. >> Accidental semicolon omission is (IMO) the most irritating source of >> syntax (and, inadvertently, sometimes other more serious) errors in >> curly-braced programming languages. >> > +1 >> >> Such a core syntax feature is not going to be changed lightly (or likely >> ever). >> > I'm glad to hear that. :-) > > Although Python's use of indentation has its downside, we gain much > more then we lose, IMHO. > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From przemolicc at poczta.fm Thu Aug 11 10:39:23 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Thu, 11 Aug 2011 16:39:23 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110811143923.GG4990@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 2:46 PM, wrote: > > This is the way I am going to use. > > But what is the best data type to hold so many rows and then operate on them ? > > > > List of strings. Take it straight from your Oracle interface and work > with it directly. Can I use this list in the following way ? subprocess_1 - run on list between 1 and 10000 subprocess_2 - run on list between 10001 and 20000 subprocess_3 - run on list between 20001 and 30000 etc ... Sort of indexing ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zmyslowa bielizna? U nas ja znajdziesz! http://linkint.pl/f29fe From neilc at norwich.edu Thu Aug 11 10:40:21 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Aug 2011 14:40:21 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <9ai7ulFk97U2@mid.individual.net> On 2011-08-10, Chris Angelico wrote: > On Wed, Aug 10, 2011 at 10:51 PM, Ben Finney wrote: >> Seebs writes: >>> I've seen bits of code in preprocessing-based "Python with {}" type >>> things, and they still look like Python to me, only they favor >>> explicit over implicit a little more strongly. >> >> They introduce unnecessary ambiguity: the indentation-as-structure and >> braces-as-structure can then disagree. >> >> The ambiguity is resolved by having exactly one of indentation or braces >> determining structure: Python uses indentation. In which case, braces >> are pointless for indicating block structure. > > That's why it wouldn't be Python. It would have to use the braces and > not the indentation. > > ChrisA > PS. I mistakenly sent this to a Gilbert & Sullivan group first. Oddly > enough, opera-goers are not used to discussing the relative merits of > braces vs indentation in code. Had I not become a lover of semantic indentation, Wisely wielding willing whitespace in a wondrous preparation, I could buttress blocks with braces, a la Kernighan and Ritchie, (Other styles, just as valid, make me terri-bul-ly twitchy), What I noticed was the whitespace hasn't shifted one iota, With the braces superfluous in my wc -m quota, When delineating code-blocks, with my keys a-clitter-clatter, I prefer semantic whitespace 'cause the braces shouldn't matter. No, the braces shouldn't matter, (Matter, matter, matter, matter) No, the braces shouldn't matter, (Matter, matter, matter, matter) When delineating code-clocks, with my keys a-clitter-clatter, I prefer semantic whitespace 'cause the braces shouldn't matter. -- Neil Cerutti From ulrich.eckhardt at dominolaser.com Thu Aug 11 10:44:13 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 11 Aug 2011 16:44:13 +0200 Subject: indentation References: <050399d8-485c-4e92-a673-0d6e00b7412f@v42g2000pri.googlegroups.com> Message-ID: <8u5dh8-mnk.ln1@satorlaser.homedns.org> Amit Jaluf wrote: > which book or tutorial i should for it(Python) > i found "A Byte of Python " by Swaroop > after that which tutorial(book) i have to read You can read lots of book reviews online. That said, have you checked http://www.python.org? Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From aspineux at gmail.com Thu Aug 11 11:07:09 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 11 Aug 2011 08:07:09 -0700 (PDT) Subject: generate and send mail with python: tutorial Message-ID: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Hi I have written a tutorial about how to generate and send emails with python. You can find it here http://blog.magiksys.net/generate-and-send-mail-with-python-tutorial And here is the content. Enjoy. This article follows two other articles (1, 2) about how to parse emails in Python. These articles describe very well mail usages and rules and can be helpful for non Python developer too. The goal here is to generate a valid email including internationalized content, attachments and even inline images, and send it to a SMTP server. The procedure can be achieved in 3 steps : compose the body of the email. compose the header of the email. send the email to a SMTP server At the end you will find the sources. The first rule to keep in mind all the time, is that emails are 7bits only, they can contains us-ascii characters only ! A lot of RFCs define rules to encode non us-ascii characters when they are required: RFC2047 to encode headers, RFC2045 for encoding body using the MIME format or RFC2231 for MIME parameters like the attachment filename. The mail header The header is composed of lines having a name and a value. RFC2047 let you use quoted or binary encoding to encode non us-ascii characters in it. For example: Subject: Courrier ?lectronique en Fran?ais become using the quoted format Subject: =?iso-8859-1?q?Courrier_=E8lectronique_en_Fran=E7ais?= or using the binary one. Subject: =?iso-8859-1?b?Q291cnJpZXIg6GxlY3Ryb25pcXVlIGVuIEZyYW7nYWlz?= Here the quoted format is readable and shorter. Python email.header.Header object generates user friendly header by choosing the quoted format when the encoding shares characters with us-ascii, and the binary one for encoding like the Chinese big5 that requires the encoding of all characters. >>> str(Header(u'Courrier \xe8lectronique en Fran\xe7ais', 'iso-8859-1')) '=?iso-8859-1?q?Courrier_=E8lectronique_en_Fran=E7ais?=' Header values have different types (text, date, address, ...) that all require different encoding rules. For example, in an address like : Sender: Alain Spineux The email part has to be in us-ascii and cannot be encoded. The name part cannot contains some special characters without quoting : []\()<>@,:;". We can easily understand why "<>" are in the list, others have all their own story. For example, the use of the "Dr." prefix requires to quote the name because of the '.': Sender: "Dr. Alain Spineux" For a name with non us-ascii characters like (look at the "?" in Ala?n), the name must be encoded. Sender: Dr. Al?an Spineux must be written : Sender: =?iso-8859-1?q?Dr=2E_Ala=EFn_Spineux?= Notice that the '.' in the prefix is replaced by "=2E", because Header preventively encode all non alpha or digit characters to match the most restrictive header rules. The Python function email.utils.formataddr() quotes the special characters but don't encode non us-ascii characters. On the other hand, email.header.Header can encode non us-ascii characters but ignore all specials rule about address encoding. Let see how both work: >>> email.Utils.formataddr(('Alain Spineux', 'alain.spineux at gmail.com')) 'Alain Spineux ' This is a valid header value for a To: field >>> str(Header('Dr. Alain Spineux ')) 'Dr. Alain Spineux ' Here the '.' should be escaped like these 13 characters: []\()<>@,:;". >>> email.Utils.formataddr(('"Alain" Spineux', 'alain.spineux at gmail.com')) '"\\"Alain\\" Spineux" ' Here '"' is escaped using '\', this is fine. >>> email.Utils.formataddr((u'Ala\xefn Spineux', 'alain.spineux at gmail.com')) u'Ala\xefn Spineux ' formataddr() don't handle non us-ascii string, this must be done by Header object >>> str(Header(email.Utils.formataddr((u'Ala\xefn Spineux', 'alain.spineux at gmail.com')))) '=?utf-8?q?Ala=C3=AFn_Spineux_=3Calain=2Espineux=40gmail=2Ecom=3E?=' This is not valid because the address is also encoded and an old or some recent MUA will't handle this. The good form here is : =?utf-8?q?Ala=C3=AFn_Spineux?= ' Function format_addresses(addresses, header_name=None, charset=None) handle carefully the encoding of the addresses. >>> str(format_addresses([ (u'Ala\xefn Spineux', 'alain.spineux at gmail.com'), ('John', 'John at smith.com'), ], 'to', 'iso-8859-1')) '=?iso-8859-1?q?Ala=EFn_Spineux?= ,\n John ' Bytes and unicode string can be mixed. Addresses must always be us- ascii. Byte string must be encoded using charset or be us-ascii. Unicode strings that cannot be encoded using charset will be encoded using utf-8 automatically by Header. For dates, use the email.utils.formatdate() this way. >>> email.utils.formatdate(time.time(), localtime=True) 'Wed, 10 Aug 2011 16:46:30 +0200' The mail body Depending of your need : text and/or html version of the message related inline images attached files the structure of the MIME email may vary, but the general one is as follow: multipart/mixed | +-- multipart/related | | | +-- multipart/alternative | | | | | +-- text/plain | | +-- text/html | | | +-- image/gif | +-- application/msword Un-needed parts will be removed by function gen_mail(text, html=None, attachments=[], relateds=[]) regarding your parameters. >>> print gen_mail(text=(u'Bonne journ\xe8e', 'iso-8859-1'), \ html=None, \ attachments=[ (u'Text attach \xe8'.encode('iso-8859-1'), 'text', 'plain', 'filename.txt', 'iso-8859-1'), ] ) >From nobody Thu Aug 11 08:05:14 2011 Content-Type: multipart/mixed; boundary="===============0992984520==" MIME-Version: 1.0 --===============0992984520== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Bonne journ=E8e --===============0992984520== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="filename.txt" Text attach=E8 --===============0992984520==-- text and html are tuple of the form (content, encoding). Items of the attachments list can be tuples of the form (content, maintype, subtype, filename, charset) or can be MIME object inheriting from MIMEBase. If maintype is 'text', charset must match the encoding of the content, or if content is unicode, charset will be used to encode it. For other value of maintype, charset is not used. relateds is similar to attachments but content is related to the message in HTML to allow embedding of images or other contents. filename is replaced by content_id that must match the cid: references inside the HTML message. Attachments can have non us-ascii filename, but this is badly supported by some MUA and then discouraged. Anyway, if you want to use non us-ascii filename, RFC2231 need the encoding but also the language. Replace filename, by a tuple of the form (encoding, language, filename), for example, use ('iso-8859-1', 'fr', u'r \xe9pertoir.png'.encode('iso-8859-1')) instead of 'filename.txt'. The attached source code provide more samples. Look carefully in it how I encode or not the unicode string and content before to use them. Send your email The Python smtplib library handles SSL, STARTLS, and authentication, all you need to connect to any SMTP server. The library also reports all errors carefully. The send_mail(smtp_host, sender, recipients, subject, msg, default_charset, cc=[], bcc=[], smtp_port=25, smtp_mode='normal', smtp_login=None, smtp_password=None, message_id_string=None) function first fill in the header about sender and recipients using format_addresses() function, and send the email to the SMTP using the protocols and credentials you have choose with smtp_* variables. sender is a tuples and recipients, cc, bcc are list of tuple of the form [ (name, address), .. ] like expected by format_addresses(). default_charset will be used as default encoding when generating the email (to encode unicode string), and as default encoding for byte string. subject is the subject of the email. msg is a MIME object like returned by gen_mail(). smtp_mode can be 'normal', 'ssl' or 'tls'. For example if you want to use your GMAIL account to send your emails, use this setup: smtp_host='smtp.gmail.com' smtp_port=587 smtp_mode='tls' smtp_login='your.address at gmail.com' smtp_password='yourpassword' sender=('Your Name', smtp_login) Most of the time you will just need to specify smtp_host Source #!/bin/env/python # # sendmail.py # (c) Alain Spineux # http://blog.magiksys.net/sending-email-using-python-tutorial # Released under GPL # import os, sys import time import base64 import smtplib import email import email.header import email.utils import email.mime import email.mime.base import email.mime.text import email.mime.image import email.mime.multipart def format_addresses(addresses, header_name=None, charset=None): """This is an extension of email.utils.formataddr. Function expect a list of addresses [ ('name', 'name at domain'), ...]. The len(header_name) is used to limit first line length. The function mix the use Header(), formataddr() and check for 'us-ascii' string to have valid and friendly 'address' header. If one 'name' is not unicode string, then it must encoded using 'charset', Header will use 'charset' to decode it. Unicode string will be encoded following the "Header" rules : ( try first using ascii, then 'charset', then 'uft8') 'name at address' is supposed to be pure us-ascii, it can be unicode string or not (but cannot contains non us-ascii) In short Header() ignore syntax rules about 'address' field, and formataddr() ignore encoding of non us-ascci chars. """ header=email.header.Header(charset=charset, header_name=header_name) for i, (name, addr) in enumerate(addresses): if i!=0: # add separator between addresses header.append(',', charset='us-ascii') # check if address name is a unicode or byte string in "pure" us-ascii try: if isinstance(name, unicode): # convert name in byte string name=name.encode('us-ascii') else: # check id byte string contains only us-ascii chars name.decode('us-ascii') except UnicodeError: # Header will use "RFC2047" to encode the address name # if name is byte string, charset will be used to decode it first header.append(name) # here us-ascii must be used and not default 'charset' header.append('<%s>' % (addr,), charset='us-ascii') else: # name is a us-ascii byte string, i can use formataddr formated_addr=email.utils.formataddr((name, addr)) # us-ascii must be used and not default 'charset' header.append(formated_addr, charset='us-ascii') return header def gen_mail(text, html=None, attachments=[], relateds=[]): """generate the core of the email message. text=(encoded_content, encoding) html=(encoded_content, encoding) attachments=[(data, maintype, subtype, filename, charset), ..] if maintype is 'text', data lmust be encoded using charset filename can be us-ascii or (charset, lang, encoded_filename) where encoded_filename is encoded into charset, lang can be empty but usually the language related to the charset. relateds=[(data, maintype, subtype, content_id, charset), ..] idem attachment above, but content_id is related to the "CID" reference in the html version of the message. """ main=text_part=html_part=None if text: content, charset=text main=text_part=email.mime.text.MIMEText(content, 'plain', charset) if html: content, charset=html main=html_part=email.mime.text.MIMEText(content, 'html', charset) if not text_part and not html_part: main=text_part=email.mime.text.MIMEText('', 'plain', 'us- ascii') elif text_part and html_part: # need to create a multipart/alternative to include text and html version main=email.mime.multipart.MIMEMultipart('alternative', None, [text_part, html_part]) if relateds: related=email.mime.multipart.MIMEMultipart('related') related.attach(main) for part in relateds: if not isinstance(part, email.mime.base.MIMEBase): data, maintype, subtype, content_id, charset=part if (maintype=='text'): part=email.mime.text.MIMEText(data, subtype, charset) else: part=email.mime.base.MIMEBase(maintype, subtype) part.set_payload(data) email.Encoders.encode_base64(part) part.add_header('Content-ID', '<'+content_id+'>') part.add_header('Content-Disposition', 'inline') related.attach(part) main=related if attachments: mixed=email.mime.multipart.MIMEMultipart('mixed') mixed.attach(main) for part in attachments: if not isinstance(part, email.mime.base.MIMEBase): data, maintype, subtype, filename, charset=part if (maintype=='text'): part=email.mime.text.MIMEText(data, subtype, charset) else: part=email.mime.base.MIMEBase(maintype, subtype) part.set_payload(data) email.Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment', filename=filename) mixed.attach(part) main=mixed return main def send_mail(smtp_host, sender, recipients, subject, msg, default_charset, cc=[], bcc=[], smtp_port=25, smtp_mode='normal', smtp_login=None, smtp_password=None, message_id_string=None): """ """ mail_from=sender[1] rcpt_to=map(lambda x:x[1], recipients) rcpt_to.extend(map(lambda x:x[1], cc)) rcpt_to.extend(map(lambda x:x[1], bcc)) msg['From'] = format_addresses([ sender, ], header_name='from', charset=default_charset) msg['To'] = format_addresses(recipients, header_name='to', charset=default_charset) msg['Cc'] = format_addresses(cc, header_name='cc', charset=default_charset) msg['Subject'] = email.header.Header(subject, default_charset) utc_from_epoch=time.time() msg['Date'] = email.utils.formatdate(utc_from_epoch, localtime=True) msg['Messsage-Id'] =email.utils.make_msgid(message_id_string) # Send the message errmsg='' failed_addresses=[] try: if smtp_mode=='ssl': smtp=smtplib.SMTP_SSL(smtp_host, smtp_port) else: smtp=smtplib.SMTP(smtp_host, smtp_port) if smtp_mode=='tls': smtp.starttls() if smtp_login and smtp_password: # login and password must be encoded # because HMAC used in CRAM_MD5 require non unicode string smtp.login(smtp_login.encode('utf-8'), smtp_password.encode('utf-8')) ret=smtp.sendmail(mail_from, rcpt_to, msg.as_string()) smtp.quit() except (socket.error, ), e: errmsg='server %s:%s not responding: %s' % (smtp_host, smtp_port, e) except smtplib.SMTPAuthenticationError, e: errmsg='authentication error: %s' % (e, ) except smtplib.SMTPRecipientsRefused, e: # code, errmsg=e.recipients[recipient_addr] errmsg='recipients refused: '+', '.join(e.recipients.keys()) except smtplib.SMTPSenderRefused, e: # e.sender, e.smtp_code, e.smtp_error errmsg='sender refused: %s' % (e.sender, ) except smtplib.SMTPDataError, e: errmsg='SMTP protocol mismatch: %s' % (e, ) except smtplib.SMTPHeloError, e: errmsg="server didn't reply properly to the HELO greeting: %s" % (e, ) except smtplib.SMTPException, e: errmsg='SMTP error: %s' % (e, ) except Exception, e: errmsg=str(e) else: if ret: failed_addresses=ret.keys() errmsg='recipients refused: '+', '.join(failed_addresses) return msg, errmsg, failed_addresses And how to use it : smtp_host='max' smtp_port=25 if False: smtp_host='smtp.gmail.com' smtp_port='587' smtp_login='your.addresse at gmail.com' smtp_passwd='your.password' sender=(u'Ala\xefn Spineux', 'alain.spineux at gmail.com') sender=(u'Alain Spineux', u'alain.spineux at gmail.com') root_addr='root at max.asxnet.loc' recipients=[ ('Alain Spineux', root_addr), # (u'Alain Spineux', root_addr), # ('Dr. Alain Spneux', root_addr), # (u'Dr. Alain Spneux', root_addr), # (u'Dr. Ala\xefn Spineux', root_addr), # (u'Dr. Ala\xefn Spineux', root_addr), # ('us_ascii_name_with_a_space_some_where_in_the_middle to_allow_python_Header._split()_to_split_according_RFC2822', root_addr), # (u'This-is-a-very-long-unicode-name-with-one-non-ascii- char-\xf4-to-force-Header()-to-use-RFC2047-encoding-and-split-in-multi- line', root_addr), # ('this_line_is_too_long_and_dont_have_any_white_space_to_allow_Header._split()_to_split_according_RFC2822', root_addr), # ('Alain Spineux', root_addr), ] smile_png=base64.b64decode( """iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOBAMAAADtZjDiAAAAMFBMVEUQEAhaUjlaWlp7e3uMezGU hDGcnJy1lCnGvVretTnn5+/3pSn33mP355T39+// 75SdwkyMAAAACXBIWXMAAA7EAAAOxAGVKw4b AAAAB3RJTUUH2wcJDxEjgefAiQAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9u ABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJ dEVYdFNvZnR3YXJlAF1w/ zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDA G+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/ AAAABnRFWHRUaXRsZQCo 7tInAAAAaElEQVR4nGNYsXv3zt27TzHcPup6XDBmDsOeBvYzLTynGfacuHfm/ x8gfS7tbtobEM3w n2E9kP5n9N/oPZA+//7PP5D8GSCYA6RPzjlzEkSfmTlz +xkgffbkzDlAuvsMWAHDmt0g0AUAmyNE wLAIvcgAAAAASUVORK5CYII= """) angry_gif=base64.b64decode( """R0lGODlhDgAOALMAAAwMCYAAAACAAKaCIwAAgIAAgACAgPbTfoR/YP8AAAD/AAAA// rMUf8A/wD/ //Tw5CH5BAAAAAAALAAAAAAOAA4AgwwMCYAAAACAAKaCIwAAgIAAgACAgPbTfoR/ YP8AAAD/AAAA //rMUf8A/wD///Tw5AQ28B1Gqz3S6jop2sxnAYNGaghAHirQUZh6sEDGPQgy5/b9UI +eZkAkghhG ZPLIbMKcDMwLhIkAADs= """) pingu_png=base64.b64decode( """iVBORw0KGgoAAAANSUhEUgAAABoAAAATBAMAAAB8awA1AAAAMFBMVEUQGCE5OUJKa3tSUlJSrdZj xu9rWjl7e4SljDGlnHutnFK9vbXGxsbWrTHW1tbv7+88a/ HUAAAACXBIWXMAAA7EAAAOxAGVKw4b AAAAB3RJTUUH2wgJDw8mp5ycCAAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9u ABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJ dEVYdFNvZnR3YXJlAF1w/ zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDA G+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/ AAAABnRFWHRUaXRsZQCo 7tInAAAA0klEQVR4nE2OsYrCUBBFJ42woOhuq43f4IfYmD5fsO2yWNhbCFZ21ovgFyQYG1FISCxt Xi8k3KnFx8xOTON0Z86d4ZKKiNowM5QEUD6FU9uCSWwpYThrSQuj2fjLso2DqB9OBqqvJFiVllHa usJedty1NFe2brRbs7ny5aIP8dSXukmyUABQ0CR9AU9d1IOO1EZgjg7n+XEBpOQP0E/ rUz2Rlw09 Amte7bdVSs/s7py5i1vFRsnFuW+gdysSu4vzv9vm57faJuY0ywFhAFmupO/zDzDcxlhVE/ gbAAAA AElFTkSuQmCC """) text_utf8="""This is the the text part. With a related picture: cid:smile.png and related document: cid:related.txt Bonne journ\xc3\xa9ee. """ utext=u"""This is the the text part. With a related picture: cid:smile.png and related document: cid:related.txt Bonne journ\xe9e. """ data_text=u'Text en Fran\xe7ais' related_text=u'Document relatif en Fran\xe7ais' html=""" This is the html part with a related picture: and related document: here
Bonne journée. """ relateds=[ (smile_png, 'image', 'png', 'smile.png', None), (related_text.encode('iso-8859-1'), 'text', 'plain', 'related.txt', 'iso-8859-1'), ] pingu_att=email.mime.image.MIMEImage(pingu_png, 'png') pingu_att.add_header('Content-Disposition', 'attachment', filename=('iso-8859-1', 'fr', u'ping\xfc.png'.encode('iso-8859-1'))) pingu_att2=email.mime.image.MIMEImage(pingu_png, 'png') pingu_att2.add_header('Content-Disposition', 'attachment', filename='pingu.png') attachments=[ (angry_gif, 'image', 'gif', ('iso-8859-1', 'fr', u'\xe4ngry.gif'.encode('iso-8859-1')), None), (angry_gif, 'image', 'gif', 'angry.gif', None), (data_text.encode('iso-8859-1'), 'text', 'plain', 'document.txt', 'iso-8859-1'), pingu_att, pingu_att2] mail=gen_mail((utext.encode('iso-8859-1'), 'iso-8859-1'), (html, 'us- ascii'), attachments, relateds) msg, errmsg, failed_addresses=send_mail(smtp_host, \ sender, \ recipients, \ u'My Subject', \ mail, \ default_charset='iso-8859-1', cc=[('Gama', root_addr), ], bcc=[('Colombus', root_addr), ], smtp_port=smtp_port, ) print msg print errmsg print failed_addresses From jkbbwr at gmail.com Thu Aug 11 11:42:38 2011 From: jkbbwr at gmail.com (Jakob Bowyer) Date: Thu, 11 Aug 2011 16:42:38 +0100 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: -1 This idea seems like it would remove the true readability of python. Personally it would create more confusion than it would remove. On Thu, Aug 11, 2011 at 3:28 PM, Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. Since a final > ':' is needed anyway, i think this would be great. > > if a > ?and b > ?or c: > ?do stuff() > > On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: >> On 11/08/2011 05:16, Chris Rebert wrote: >>> >>> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>>> >>>> :And if we require {} then truly free indentation should be OK too! But >>>> >>>> :it wouldn't be Python any more. >>>> >>>> Of course, but not the case with ';'. Currently ';' is optional in >>>> Python, >>> >>> I think of it more as that Python deigns to permit semicolons. >>> >>>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>>> magnitude. >>>> >>>> So the decision is: shall we change ';' from optional to mandatory >>>> to allow free line splitting? >>> >>> Hell no, considering that the sizable majority of lines *aren't* >>> split, which makes those semicolons completely redundant to their >>> accompanying newlines. We'd be practicing poor Huffman coding by >>> optimizing for the *un*common case. It would also add punctuational >>> noise to what is otherwise an amazingly clean and readable syntax. >>> Accidental semicolon omission is (IMO) the most irritating source of >>> syntax (and, inadvertently, sometimes other more serious) errors in >>> curly-braced programming languages. >>> >> +1 >>> >>> Such a core syntax feature is not going to be changed lightly (or likely >>> ever). >>> >> I'm glad to hear that. :-) >> >> Although Python's use of indentation has its downside, we gain much >> more then we lose, IMHO. >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> http://mail.python.org/mailman/listinfo/python-ideas >> > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From Tim.Arnold at sas.com Thu Aug 11 12:58:00 2011 From: Tim.Arnold at sas.com (Tim Arnold) Date: Thu, 11 Aug 2011 12:58:00 -0400 Subject: multiprocessing timing issue In-Reply-To: References: Message-ID: On 8/10/2011 11:36 PM, Philip Semanchuk wrote: > > On Aug 9, 2011, at 1:07 PM, Tim Arnold wrote: > >> Hi, I'm having problems with an empty Queue using multiprocessing. >> >> The task: >> I have a bunch of chapters that I want to gather data on individually and then update a report database with the results. >> I'm using multiprocessing to do the data-gathering simultaneously. >> >> Each chapter report gets put on a Queue in their separate processes. Then each report gets picked off the queue and the report database is updated with the results. >> >> My problem is that sometimes the Queue is empty and I guess it's >> because the get_data() method takes a lot of time. >> >> I've used multiprocessing before, but never with a Queue like this. >> Any notes or suggestions are very welcome. > > > Hi Tim, > THis might be a dumb question, but...why is it a problem if the queue is empty? It sounds like you figured out already that get_data() sometimes takes longer than your timeout. So either increase your timeout or learn to live with the fact that the queue is sometimes empty. I don't mean to be rude, I just don't understand the problem. > > Cheers > Philip > Hi Philip, Not a dumb or rude question at all, thanks for thinking about it. When the queue is empty the report cannot be updated, so that's why I was concerned--I couldn't figure out how to block. Now that's dumb! From your response and Tim Roberts too, I see that it's possible to block until the data comes back. I just should never have put that timeout in there. I must have assumed it would not block with no timeout given. Wrong.... From the docs on q.get(): If optional args 'block' is true and 'timeout' is None (the default), block if necessary until an item is available. If 'timeout' is a positive number, it blocks at most 'timeout' seconds and raises the Empty exception if no item was available within that time. Otherwise ('block' is false), return an item if one is immediately available, else raise the Empty exception ('timeout' is ignored in that case). thanks, --Tim Arnold From pydanny at gmail.com Thu Aug 11 13:04:24 2011 From: pydanny at gmail.com (Daniel Greenfeld) Date: Thu, 11 Aug 2011 10:04:24 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Something like this already exists: a = 0 b = 1 if (True == True and False == False and a + 1 == b and b - 1 == a): print 'meh' So I've got no idea what this proposal is about except for the dropping of readability of Python. -1 Daniel Greenfeld On Thu, Aug 11, 2011 at 8:42 AM, Jakob Bowyer wrote: > -1 This idea seems like it would remove the true readability of > python. Personally it would create more confusion than it would > remove. > > On Thu, Aug 11, 2011 at 3:28 PM, Matt Joiner wrote: >> +0.5 >> >> The "trailing \" workaround is nonobvious. Wrapping in () is noisy and >> already heavily used by other syntactical structures. Since a final >> ':' is needed anyway, i think this would be great. >> >> if a >> ?and b >> ?or c: >> ?do stuff() >> >> On Thu, Aug 11, 2011 at 11:02 PM, MRAB wrote: >>> On 11/08/2011 05:16, Chris Rebert wrote: >>>> >>>> On Wed, Aug 10, 2011 at 7:52 PM, Yingjie Lan ?wrote: >>>>> >>>>> :And if we require {} then truly free indentation should be OK too! But >>>>> >>>>> :it wouldn't be Python any more. >>>>> >>>>> Of course, but not the case with ';'. Currently ';' is optional in >>>>> Python, >>>> >>>> I think of it more as that Python deigns to permit semicolons. >>>> >>>>> But '{' is used for dicts. Clearly, ';' and '{' are different in >>>>> magnitude. >>>>> >>>>> So the decision is: shall we change ';' from optional to mandatory >>>>> to allow free line splitting? >>>> >>>> Hell no, considering that the sizable majority of lines *aren't* >>>> split, which makes those semicolons completely redundant to their >>>> accompanying newlines. We'd be practicing poor Huffman coding by >>>> optimizing for the *un*common case. It would also add punctuational >>>> noise to what is otherwise an amazingly clean and readable syntax. >>>> Accidental semicolon omission is (IMO) the most irritating source of >>>> syntax (and, inadvertently, sometimes other more serious) errors in >>>> curly-braced programming languages. >>>> >>> +1 >>>> >>>> Such a core syntax feature is not going to be changed lightly (or likely >>>> ever). >>>> >>> I'm glad to hear that. :-) >>> >>> Although Python's use of indentation has its downside, we gain much >>> more then we lose, IMHO. >>> _______________________________________________ >>> Python-ideas mailing list >>> Python-ideas at python.org >>> http://mail.python.org/mailman/listinfo/python-ideas >>> >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas at python.org >> http://mail.python.org/mailman/listinfo/python-ideas >> > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > From nad at acm.org Thu Aug 11 13:26:44 2011 From: nad at acm.org (Ned Deily) Date: Thu, 11 Aug 2011 10:26:44 -0700 Subject: code object differences between 2.7 and 3.3a References: Message-ID: In article , Eric Snow wrote: > Specifically, I am wondering why there is a difference for co_names. This is not an answer to your question but, as a metapoint, in my experience it is usually faster and often more reliable to try to answer questions like this yourself using the tools that the Python project provides: - clone a copy of the hg repository and update to the branch of interest - become familiar with the code layout (the developers guide can help with this (http://docs.python.org/devguide/) - use "hg annotate" to see what lines were changed by what rev sets and by whom - use "hg log -v " to browse the history entries for the file - look up the tracker issues referenced in those history entries and follow the discussions there The Python project has an effective process for code development and one that emphasizes good documentation of changes and additions. For instance, as part of the transition earlier this year from Subversion to Mercurial, great care was taken to preserve as much of the existing source history as possible going far back into the time machine. It's to your advantage to take advantage of these sources of history. -- Ned Deily, nad at acm.org From paul at colomiets.name Thu Aug 11 15:17:08 2011 From: paul at colomiets.name (Paul Colomiets) Date: Thu, 11 Aug 2011 22:17:08 +0300 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Hi Matt, On Thu, Aug 11, 2011 at 5:28 PM, Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. Since a final > ':' is needed anyway, i think this would be great. > > if a > ?and b > ?or c: > ?do stuff() > If you really think so, try writing some coffeescript (remember to obey 79 chars limit). Coffeescript is amasing, but it lacks strictness of python. So you really don't know how to break line, and it really takes time to figure out right way each time you need it. -- Paul From jeanpierreda at gmail.com Thu Aug 11 15:24:34 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 15:24:34 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Javascript also lets you break lines. For example, this does what you want: return 1 + 5 Whereas this does not return 1 + 5 Of course, Python would have no such problem, because you could make both cases unambiguous due to the indent. Devin On Thu, Aug 11, 2011 at 3:17 PM, Paul Colomiets wrote: > Hi Matt, > > On Thu, Aug 11, 2011 at 5:28 PM, Matt Joiner wrote: > > +0.5 > > > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > > already heavily used by other syntactical structures. Since a final > > ':' is needed anyway, i think this would be great. > > > > if a > > and b > > or c: > > do stuff() > > > If you really think so, try writing some coffeescript (remember to > obey 79 chars limit). Coffeescript is amasing, but it lacks > strictness of python. So you really don't know how to break line, > and it really takes time to figure out right way each time you need > it. > > -- > Paul > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paddy3118 at googlemail.com Thu Aug 11 16:31:45 2011 From: paddy3118 at googlemail.com (Paddy) Date: Thu, 11 Aug 2011 13:31:45 -0700 (PDT) Subject: Python 3.X: nonlocal support in eval/exec? References: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> Message-ID: <996e6195-1550-4149-ba5c-5f43eceebbad@fv14g2000vbb.googlegroups.com> On Aug 11, 8:48?am, Terry Reedy wrote: > On 8/11/2011 3:19 AM, Paddy wrote: > > > We can access nonlocal variables in a function, but if we were to eval/ > > exec the function we cannot set up a nested stack of evironment dicts. > > We are limited to just two: global and local. > > Right. That was and is Python's execution model. > Note that when you exec code, including a function call, the locals > passed is the local context in which the code is executed. It is not the > locals of any particular function called by the exec-ed code. > > If you exec a function that is a closure, the closure or non-local > objects come with the function. A 'stack of dicts' has nothing to do > with how function and nested funcs operate. > > -- > Terry Jan Reedy Thanks Terry. From bruce at leapyear.org Thu Aug 11 16:45:58 2011 From: bruce at leapyear.org (Bruce Leban) Date: Thu, 11 Aug 2011 13:45:58 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 12:24 PM, Devin Jeanpierre wrote: > Javascript also lets you break lines. For example, this does what you want: > > return 1 > + 5 > > Whereas this does not > > return > 1 + 5 > > Of course, Python would have no such problem, because you could make both > cases unambiguous due to the indent. > > Devin > > > Note that this is already valid and is not a continuation line: return 1 +5 Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. Now allowing line breaks *after* operators would be unambiguous and would not require new indentation rules. When a line ends with an operator, it's clearly incomplete (so no fear the reader will think the statement has ended unlike the above case) and it's a syntax error today: return 1 + 5 x = y > 0 and y < 10 This code is not valid today without parens or \ regardless of indentation. I'm +0 on this. I'd use it but does it really add enough convenience? --- Bruce Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Thu Aug 11 17:06:59 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 17:06:59 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: > Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. Eek no. If I was suggesting anything, it would have been a third form of continuation: collapsing subsequent extra-indented lines. This is never ambiguous. (This could be done in such a way as to permit comments, namely, by doing it to the tokenstream rather than to the actual text) Devin On Thu, Aug 11, 2011 at 4:45 PM, Bruce Leban wrote: > > On Thu, Aug 11, 2011 at 12:24 PM, Devin Jeanpierre wrote: >> >> Javascript also lets you break lines. For example, this does what you want: >> >> ??? return 1 >> ??????? + 5 >> >> Whereas this does not >> >> ??? return >> ??????? 1 + 5 >> >> Of course, Python would have no such problem, because you could make both cases unambiguous due to the indent. >> >> Devin >> > Note that this is already valid and is not a continuation line: > > return 1 > +5 > > Right now you do not need to indent continuation lines. So in order to disambiguate you would need to enforce indentation for continuations, but for backward compatibility that would only be required when not using parentheses or backslashes. Ick. Can blank lines or comment lines appear between a line and its continuation? That's allowed now as well. > Now allowing line breaks *after* operators would be unambiguous and would not require new indentation rules. When a line ends with an operator, it's clearly incomplete (so no fear the reader will think the statement has ended unlike the above case) and it's a syntax error today: > > return 1 + > ? ? 5 > x = y > 0 and > ? ?y < 10 > > This code is not valid today without parens or \ regardless of indentation. I'm +0 on this. I'd use it but does it really add enough convenience? > --- Bruce > Follow me:?http://www.twitter.com/Vroo?http://www.vroospeak.com From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: On 2011-08-11, Ben Finney wrote: > What evidence do you have of these? The latter, especially, seems to be > mere opinion unfounded in any measurement. Well, on new collection of data, I'm less convinced. The basic rule is: Engineers are nearly always aware of tradeoffs. If I suddenly encounter something where many engineers perceive a tradeoff, and a few deny that there is any tradeoff at all, that usually means that the latter category are not actually doing the engineering thing. > Again, I don't know where you've been observing that, but it's not what > I've seen. I've seen it some here, and in other Python discussion threads. I've also seen counterexamples, though, more now that I brought it up. > You're welcome to attempt to demonstrate the superiority of some other > Python-with-braces, but it will (a) be un-Pythonic, and (b) be unlikely > to gain the efforts of people who don't think what you're addressing is > a problem. I have noticed a tendency for "Pythonic" to produce fierce debates in which there is absolutely nothing measurable to point to. I'm not sold on it. I guess the thing is this: I am pretty sure Python is a pretty nice language. However, the indentation thing has screwed me a few times. Furthermore, I know people who like Python a great deal and acknowledge, without much difficulty, that the indentation thing has caused problems or incompatibilities for them. So when I see people deny that it is at all a problem, or that there are any possible shortcomings to it, I infer that they have some compelling reason to deny the existence of a thing which is reliably and easily observed. See, that's the thing. If you want to tell me that there are problems with braces, I'll *agree*. I am aware of those problems. I don't feel a need to deny that they exist. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Seebs wrote: >> I have seen all the counterarguments, and what I've >> mostly become convinced of is this: >> 1. Indentation as flow control was a bad idea. > I'm not aware of any language where indentation is used for flow control. > Python is not one of those languages: it uses for, while, if, etc. for flow > control, just like most other languages. It does however use indentation > for grouping code into blocks -- a different concept. Agh! Point granted. Presumably you knew what I meant, but you're right that I said it wrong. > You are free to hold whatever opinions you like, but have you considered > that the reason people get emotional and angry when others insist that > indentation as flow control should be discarded is because they actually > believe that the "off-side rule" (as it is called) makes for a better > language and a better coding experience? Yes. And when I talk to people who are *able to admit that there exist problems*, and who argue that the benefits outweigh them, I believe that they are probably making a good point. It's the people who insist that there are no problems that worry me. > There are dozens, hundreds of brace languages, and 1-2 dozen using > indentation, including Python. If braces are so important to you, go use > one of those other languages, don't wreck the language we like by taking > away one of the best features of the language. If I had a choice, believe me, I'd do just that. > We're fully aware of the tradeoffs of significant indentation. You are. A couple of other people I've talked to are. Many others are not. > We believe > that brace languages get the trade-offs backwards: they optimise code for > environments which mangle source code. 99.999% of code will never pass > through a broken mail server that strips leading whitespace, or pasted into > broken web forum software that mangles indentation, or go through any other > broken tool that messes with indentation. Brace languages optimise for the > 0.001% case, Python optimised the 99.999% case. This is a really interesting analysis. My experience, though, puts it more at about 99% and 1%. And the thing is... > Because people simply don't like it when their code's indentation doesn't > match the actual semantics, people usually manually ensure that the two > match, braces or no braces. Editors still have commands to indent and > outdent blocks of code. There is no difference between (say) C or Pascal > and Python in that regard. Yes, there very much is. You can't outdent "a block" in Python unless it is already correctly indented. The underlying thing I've noticed is: Braces have problems more often, but the problems are *always* 100% machine-fixable and therefore trivial. It takes milliseconds to get a program fixed so it looks like what it means. Indentation has problems less often, but the problems are *never* machine-fixable. It takes minutes or hours to figure out what was supposed to be there. > There is nothing implicit about indentation. This false dichotomy between > so-called explicit braces and allegedly implicit indentation gets thrown > around all the time, but it is simply *wrong*. Indentation is not implicit. Hmm. Maybe "implicit" isn't quite the right word, but... The end of an indented block is not a thing, it's the lack-of-a-thing. foo bar How many unindents are there between "foo" and "bar"? If you can't answer this from looking between "foo" and "bar", but must instead look at previous lines and *INFER* the number of unindents, then it seems to me that there is something implicit going on here. > And ABC, Boo, BuddyScript, Cobra, CoffeeScript, Curry, F#, Genie, HAML, > Haskell, ISWIM, Miranda, Nemerle, Occam, PROMAL, Spin and XL, plus any > other languages with significant indentation. Point made. > No, most mail servers don't mangle whitespace in the body of the email, or > in attachments. Most don't, that's true. Part of my frustration comes from a 6-month period during which most of my email was sent through a mail server which, for reasons no one was able to determine, was dutifully converting any plain text it received into HTML, and stripping "irrelevant" spaces along the way. :) > Some mail clients do, usually because they default to using > HTML for text. So get a better mail client. I have tried occasionally. Mine does not default to use HTML, but it does sometimes mangle lines. Unfortunately, it's the closest to having other funcitonality I want I've ever seen. > Avoid pig-ignorant web forums > that think that source code can be reflowed or that remove leading > whitespace. Stop using Notepad, and use an editor that offers indent and > outdent commands. I'm not using Notepad. And actually, it's the indent/outdent that bit me worst, so far. :) > If your mail server had a bug that deleted braces from emails, would you fix > the bug, or would you insist that braces were a failed experiment and that > C should stop using { } and start using BEGIN END like Pascal? If *only one program* deleted braces, sure. If "braces get deleted" were pretty much a daily occurrence among people I know (not everyone gets hit every day, but someone gets hit just about every day), and had been for the last 20+ years, I might feel differently. But I think a lot of this just comes down to the underlying human thing: People don't like being dismissed. When people come here and say that, for whatever reason, they are in an environment in which the whitespace thing is a problem, they get insulted and told that all their tools, which they may have been using without any trouble for twenty years, are defective and should be completely thrown out. Heck, arguably I should consider "Stop using Notepad" to be pretty insulting. And at the same time, I think the people who like the indentation policy are probably pretty sick of seeing it bashed. So there's a tendency for gradual escalation, and of course, each new person who comes here is coming here with a thing which is new *to them*, but old *to you*. So CLP jumps all over people who say that this is a problem for them, tells them they're wrong, tells them they're stupid, tells them that their work environment isn't *good enough* for them to be worthy of using Python. And tells them to leave. Well, seriously. If I could, I would. If it were up to me, I'd talk to the people who'd picked Python for some stuff I have to work for, point out the hostility of the Python community to newcomers whose workflows don't happen to have been preemptively built entirely around Python's design decisions, and suggest that maybe we use another language. Heck, since I've been encouraged so much to do so, I think I will. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 11 17:19:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 11 Aug 2011 21:19:18 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e43cdbc$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-11, Steven D'Aprano wrote: > Steven D'Aprano wrote: >> indentation as flow control > Gah! Of course, I meant indentation for blocks... after making the earlier > point that indentation is *not* used for flow control, this was a > particularly egregious error. > How embarrassment. My fault, I probably hypnotized you with my bad word choice. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From bruce at leapyear.org Thu Aug 11 17:21:53 2011 From: bruce at leapyear.org (Bruce Leban) Date: Thu, 11 Aug 2011 14:21:53 -0700 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 2:06 PM, Devin Jeanpierre wrote: > > Eek no. If I was suggesting anything, it would have been a third form > of continuation: collapsing subsequent extra-indented lines. This is > never ambiguous. (This could be done in such a way as to permit > comments, namely, by doing it to the tokenstream rather than to the > actual text) So if I miss-indent this a = b (x, y) = z instead of getting "unexpected indent" I get "SyntaxError: can't assign to function call". I'm sure someone can come up with two valid statements that have a different meaning when spliced together. --- Bruce Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Thu Aug 11 17:29:36 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 17:29:36 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: a = b, c = d is a pair of such statements. Howeverm indentation errors have been extremely rare in my experience, so I'm not really compelled to think it's harmful. Especially since 3.x outlaws mixing tabs and spaces. I don't love it, but I guess I prefer it to throwing parentheses and especially \ everywhere. Parentheses can be awkward and don't quite work everywhere the way one might want, and \ has that trailing space ugliness. Devin On Thu, Aug 11, 2011 at 5:21 PM, Bruce Leban wrote: > > On Thu, Aug 11, 2011 at 2:06 PM, Devin Jeanpierre > wrote: >> >> Eek no. If I was suggesting anything, it would have been a third form >> of continuation: collapsing subsequent extra-indented lines. This is >> never ambiguous. (This could be done in such a way as to permit >> comments, namely, by doing it to the tokenstream rather than to the >> actual text) > > So if I miss-indent this > a = b > ? (x, y) = z > > instead of getting "unexpected indent" I get "SyntaxError: can't assign to > function call". I'm sure someone can come up with two valid statements that > have a different meaning when spliced together. > --- Bruce > Follow me:?http://www.twitter.com/Vroo?http://www.vroospeak.com > > > From sigmundv at gmail.com Thu Aug 11 17:38:32 2011 From: sigmundv at gmail.com (SigmundV) Date: Thu, 11 Aug 2011 14:38:32 -0700 (PDT) Subject: String concatenation - which is the fastest way ? References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: When I saw the headline I thought "oh no, not string concatenation again... we have had scores of these thread before...", but this is a rather interesting problem. The OP says he's not a database developer, but why is he then fiddling with internal database operations? Wouldn't it be better to go back to the database developers and have them look into parallel processing. I'm sure that Oracle databases can do parallel processing by now... Sigmund From jimjjewett at gmail.com Thu Aug 11 17:39:01 2011 From: jimjjewett at gmail.com (Jim Jewett) Date: Thu, 11 Aug 2011 17:39:01 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: On Thu, Aug 11, 2011 at 5:29 PM, Devin Jeanpierre wrote: > Howeverm indentation errors have been extremely rare in my experience, > so I'm not really compelled to think it's harmful. Especially since > 3.x outlaws mixing tabs and spaces. I normally get them when starting with code from somewhere else (which might well mixed tabs and spaces, or worse, if emailed or posted to the web) or when cutting and pasting at an interactive prompt. -jJ From jeanpierreda at gmail.com Thu Aug 11 18:29:37 2011 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 11 Aug 2011 18:29:37 -0400 Subject: [Python-ideas] allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: Well the tabs&spaces issue is no longer an issue as far as I understand it (such a change to indent semantics could only go into 3.x), and cutting and pasting to the interpreter is obvious anyway just visually, regardless of the specific error message. The other issue sounds reasonable. Code that has indentation stripped or mangled due to the transition medium would be even harder to recompose. Devin On Thu, Aug 11, 2011 at 5:39 PM, Jim Jewett wrote: > On Thu, Aug 11, 2011 at 5:29 PM, Devin Jeanpierre > wrote: >> Howeverm indentation errors have been extremely rare in my experience, >> so I'm not really compelled to think it's harmful. Especially since >> 3.x outlaws mixing tabs and spaces. > > I normally get them when starting with code from somewhere else (which > might well mixed tabs and spaces, or worse, if emailed or posted to > the web) or when cutting and pasting at an interactive prompt. > > -jJ > From ppv.grps at gmail.com Thu Aug 11 18:43:06 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 15:43:06 -0700 (PDT) Subject: TypeError: 'module' object is not callable Message-ID: I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: x = Univariate(a) # a is a list that is expected by the Univariate class python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a print dir(Univariate) it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. What gives? Thanks in advance. ====================== FreeBSD 7.2 machine with python version 2.5.6 From ethan at stoneleaf.us Thu Aug 11 18:43:39 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Aug 2011 15:43:39 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E445B1B.2010802@stoneleaf.us> Seebs wrote: >> We're fully aware of the tradeoffs of significant indentation. > > You are. A couple of other people I've talked to are. Many others > are not. The times that whitespace indentation has bitten me, it was still not difficult to fix -- I just had to look and see which line(s) should/should not be where they were. >> Because people simply don't like it when their code's indentation doesn't >> match the actual semantics, people usually manually ensure that the two >> match, braces or no braces. Editors still have commands to indent and >> outdent blocks of code. There is no difference between (say) C or Pascal >> and Python in that regard. > > Yes, there very much is. > > You can't outdent "a block" in Python unless it is already correctly > indented. I fix the block, then move it as I need to. > The underlying thing I've noticed is: > > Braces have problems more often, but the problems are *always* 100% > machine-fixable and therefore trivial. It takes milliseconds to get > a program fixed so it looks like what it means. Not so. If the braces do not match /intent/ (which is the problem I care most about) then it cannot be fixed by machine. > Indentation has problems less often, but the problems are *never* > machine-fixable. It takes minutes or hours to figure out what was > supposed to be there. I can see where a messed-up mail server could cause hours of grief. Not having experienced that, but only cases where I, myself, accidently changed indentation when I should have, it's not been a big deal to fix; I'm willing to live with not having the machine reformat my source code from incorrect to correct. ... > Well, seriously. If I could, I would. If it were up to me, I'd talk to the > people who'd picked Python for some stuff I have to work for, point out the > hostility of the Python community to newcomers whose workflows don't happen > to have been preemptively built entirely around Python's design decisions, > and suggest that maybe we use another language. Heck, since I've been > encouraged so much to do so, I think I will. Your choice, obviously -- seems a shame to me, though, to give up on Python because of one or two ouchy areas on c.l.py. By and large it's a very helpful and courteous community. ~Ethan~ From iamforufriends at gmail.com Thu Aug 11 19:35:15 2011 From: iamforufriends at gmail.com (kate for free dating) Date: Thu, 11 Aug 2011 16:35:15 -0700 (PDT) Subject: Its eazy to make girl friend and here... just add here with female profile... u willget hot girls for free....try it once... if probelem with ur original make, jsut make mail id and try it... http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas Message-ID: Its eazy to make girl friend and here... just add here with female profile... u willget hot girls for free....try it once... if probelem with ur original make, jsut make mail id and try it... http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 http://tinyurl.com/3nnzas4 From gordon at panix.com Thu Aug 11 19:39:21 2011 From: gordon at panix.com (John Gordon) Date: Thu, 11 Aug 2011 23:39:21 +0000 (UTC) Subject: TypeError: 'module' object is not callable References: Message-ID: In Forafo San writes: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > x = Univariate(a) # a is a list that is expected by the Univariate class > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a It's difficult to diagnose this problem when you haven't shown us the code for Univariate. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Thu Aug 11 19:58:30 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 00:58:30 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: On Thu, Aug 11, 2011 at 10:19 PM, Seebs wrote: > I am pretty sure Python is a pretty nice language. ?However, the indentation > thing has screwed me a few times. ?Furthermore, I know people who like Python > a great deal and acknowledge, without much difficulty, that the indentation > thing has caused problems or incompatibilities for them. > Indentation-is-syntax is a feature of Python, and one that's not likely to change. Some programmers do not like indentation to be syntax, and a lot of them are not likely to change their views. There's a solution to this dilemma; it's called "using another language". Python is just one of many excellent languages in the world today. Even if you exclude non-free languages and non-free compilers/interpreters, you still have a wealth of options. Check Wikipedia, find one in a category that interests you, download a development environment, and give it a shot! It would surprise me *greatly* if the regular posters on this list were not all familiar with several languages other than Python, including at least one bracey language. The arguments do not come from ignorance but from knowledge. Incidentally, I will happily argue the benefits of Python's significant whitespace, even though I disagree with it; there are quite a few. (Is the fact that it discourages massive one-liners considered to be a benefit?) Of course, sometimes choosing another language is a luxury you can't afford. But in those situations, usually you're slotting into someone else's code Manual of Style too, so you might be required to write C code with three-space indents and a blank line before every open brace, for all we know. Doesn't matter that you're in a whitespace-insignificant language; you are in a whitespace-significant *environment*, and that's what matters. Chris Angelico From drobinow at gmail.com Thu Aug 11 20:15:39 2011 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Aug 2011 20:15:39 -0400 Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: On Thu, Aug 11, 2011 at 6:43 PM, Forafo San wrote: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to >import that class into a *.py file. However when I try to instantiate an object with that class like: What makes you think you're able to import that class? > x = Univariate(a) ? ? ? ? ? ? # a is a list that is expected by the Univariate class > > python raises the TypeError: 'module' object is not callable. ?If I embed the code of the Univariate >class in my *.py file, there is no problem. ?Also, when the class is imported and I do a > > print dir(Univariate) > > it does not print all the methods that are in the class, while if the class code appears in my *.py >file, all the methods are available and a list with the correct methods are printed. It appears that you are importing the "module" Univariate from the file Univariate.py If you want to instantiate the "class" Univariate contained in the "module" Univariate, try x = Univariate.Univariate(a) In the future, please try to include more of your code. From python at mrabarnett.plus.com Thu Aug 11 20:22:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 01:22:20 +0100 Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <4E44723C.6090804@mrabarnett.plus.com> On 11/08/2011 23:43, Forafo San wrote: > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > x = Univariate(a) # a is a list that is expected by the Univariate class > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > print dir(Univariate) > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > What gives? > I think you mat be confusing the class with the module. When you write: import Univariate you're importing the module. If the module is called "Univariate" and the class within the module is called "Univariate" then you should either write: import Univariate x = Univariate.Univariate(a) # the class Univariate in the module Univariate or: from Univariate import Univariate x = Univariate(a) Incidentally, it's recommended that module names use lowercase, so that would be: import univariate x = univariate.Univariate(a) or: from univariate import Univariate From ppv.grps at gmail.com Thu Aug 11 20:56:34 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 17:56:34 -0700 (PDT) Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > On 11/08/2011 23:43, Forafo San wrote: > > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > > > x = Univariate(a) # a is a list that is expected by the Univariate class > > > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > > > print dir(Univariate) > > > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > > > What gives? > > > I think you mat be confusing the class with the module. > > When you write: > > import Univariate > > you're importing the module. > > If the module is called "Univariate" and the class within the module is > called "Univariate" then you should either write: > > import Univariate > x = Univariate.Univariate(a) # the class Univariate in the module > Univariate > > or: > > from Univariate import Univariate > x = Univariate(a) > > Incidentally, it's recommended that module names use lowercase, so that > would be: > > import univariate > x = univariate.Univariate(a) > > or: > > from univariate import Univariate Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again. From ppv.grps at gmail.com Thu Aug 11 20:56:34 2011 From: ppv.grps at gmail.com (Forafo San) Date: Thu, 11 Aug 2011 17:56:34 -0700 (PDT) Subject: TypeError: 'module' object is not callable In-Reply-To: References: Message-ID: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> On Thursday, August 11, 2011 8:22:20 PM UTC-4, MRAB wrote: > On 11/08/2011 23:43, Forafo San wrote: > > I wrote a class, Univariate, that resides in a directory that is in my PYTHONPATH. I'm able to import that class into a *.py file. However when I try to instantiate an object with that class like: > > > > x = Univariate(a) # a is a list that is expected by the Univariate class > > > > python raises the TypeError: 'module' object is not callable. If I embed the code of the Univariate class in my *.py file, there is no problem. Also, when the class is imported and I do a > > > > print dir(Univariate) > > > > it does not print all the methods that are in the class, while if the class code appears in my *.py file, all the methods are available and a list with the correct methods are printed. > > > > What gives? > > > I think you mat be confusing the class with the module. > > When you write: > > import Univariate > > you're importing the module. > > If the module is called "Univariate" and the class within the module is > called "Univariate" then you should either write: > > import Univariate > x = Univariate.Univariate(a) # the class Univariate in the module > Univariate > > or: > > from Univariate import Univariate > x = Univariate(a) > > Incidentally, it's recommended that module names use lowercase, so that > would be: > > import univariate > x = univariate.Univariate(a) > > or: > > from univariate import Univariate Thank you all for your replies. When I do a from Univariate import Univariate the TypeError disappears and everything is fine. Clearly this was an error that a newbie such as myself is likely to make because of little experience with Python. However, this isn't something I'm likely to forget. I will also adopt the style recommendations. Thanks, again. From steve+comp.lang.python at pearwood.info Thu Aug 11 21:40:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 11:40:00 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > Incidentally, I will happily argue the > benefits of Python's significant whitespace, even though I disagree > with it; there are quite a few. Please be careful about conflating significant indentation with significant whitespace. Many languages have significant whitespace: foo bar is rarely the same thing as foobar but is the same as foo bar Python is no different. The only exception I can think of is *very* early Fortran, and that rightly is considered a mistake. Fortran 77 used to treat whitespace as always optional, so that in Python terms this: forxinrange(42) would be parsed as this: for x in range(42) See also: http://weblog.hotales.org/cgi-bin/weblog/nb.cgi/view/python/2005/02/19/1 http://c2.com/cgi/wiki?SyntacticallySignificantWhitespaceConsideredHarmful > (Is the fact that it discourages > massive one-liners considered to be a benefit?) Hell yes! -- Steven From jason.swails at gmail.com Thu Aug 11 21:47:57 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 11 Aug 2011 21:47:57 -0400 Subject: TypeError: 'module' object is not callable In-Reply-To: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> References: <5effb6ec-7389-4f1d-9707-164227b431e1@glegroupsg2000goo.googlegroups.com> Message-ID: On Thu, Aug 11, 2011 at 8:56 PM, Forafo San wrote: > > Thank you all for your replies. When I do a > > from Univariate import Univariate > > the TypeError disappears and everything is fine. Clearly this was an error > that a newbie such as myself is likely to make because of little experience > with Python. However, this isn't something I'm likely to forget. > > I will also adopt the style recommendations. Thanks, again. > -- > http://mail.python.org/mailman/listinfo/python-list > As a beginner, I found that it was useful to note how these 2 approaches differ. In the first approach: import Univariate a = Univariate.Univariate(foo) what you're doing is loading everything in Univariate in a separate namespace (the Univariate namespace). The other approach: from Univariate import Univariate a = Univariate(foo) what you're doing is loading *just* Univariate into your top level namespace. It's important to note this difference because it has potentially critical implications as far as clobbering existing functions that happen to have the same name (if you're loading into your top level namespace with, for instance, "from mymodule import *") versus keeping everything in a separate namespace so stuff doesn't get overwritten. This is more applicable to scripts/programs you write that import a number of different modules, all of whom may contain objects with the same name. All the best, Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From goldtech at worldpost.com Thu Aug 11 22:03:36 2011 From: goldtech at worldpost.com (goldtech) Date: Thu, 11 Aug 2011 19:03:36 -0700 (PDT) Subject: Processing a large string Message-ID: Hi, Say I have a very big string with a pattern like: akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... I want to split the sting into separate parts on the "3" and process each part separately. I might run into memory limitations if I use "split" and get a big array(?) I wondered if there's a way I could read (stream?) the string from start to finish and read what's delimited by the "3" into a variable, process the smaller string variable then append/build a new string with the processed data? Would I loop it and read it char by char till a "3"...? Or? Thanks. From python at mrabarnett.plus.com Thu Aug 11 22:15:58 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 03:15:58 +0100 Subject: Processing a large string In-Reply-To: References: Message-ID: <4E448CDE.1060704@mrabarnett.plus.com> On 12/08/2011 03:03, goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > You could write a generator like this: def split(string, sep): pos = 0 try: while True: next_pos = string.index(sep, pos) yield string[pos : next_pos] pos = next_pos + 1 except ValueError: yield string[pos : ] string = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..." for part in split(string, "3"): print(part) From steve+comp.lang.python at pearwood.info Thu Aug 11 22:30:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 12:30:57 +1000 Subject: Processing a large string References: Message-ID: <4e449062$0$29975$c3e8da3$5496439d@news.astraweb.com> goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... Define "big". What seems big to you is probably not big to your computer. > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? You could, but unless there are a lot of 3s, it will probably be slow. If the 3s are far apart, it will be better to do this: # untested def split(source): start = 0 i = source.find("3") while i >= 0: yield source[start:i] start = i+1 i = source.find("3", start) That should give you the pieces of the string one at a time, as efficiently as possible. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 11 22:32:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 12:32:41 +1000 Subject: [Python-ideas] allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <1313031175.38817.YahooMailNeo@web121515.mail.ne1.yahoo.com> <4E43D2F2.1090004@mrabarnett.plus.com> Message-ID: <4e4490c9$0$29975$c3e8da3$5496439d@news.astraweb.com> Matt Joiner wrote: > +0.5 > > The "trailing \" workaround is nonobvious. Wrapping in () is noisy and > already heavily used by other syntactical structures. "Noisy"? Compare: # Best viewed with a fixed-width font if a if (a and b and b or c: or c): do stuff() do stuff() That is not my idea of "noise". The brackets have a clear and obvious meaning: they group the condition. > Since a final > ':' is needed anyway, i think this would be great. A final : is not needed for arbitrary expressions. flag = (a and b or c) -- Steven From mokurai at earthtreasury.org Thu Aug 11 22:43:22 2011 From: mokurai at earthtreasury.org (mokurai at earthtreasury.org) Date: Thu, 11 Aug 2011 22:43:22 -0400 Subject: [Edu-sig] [ANNC] pynguin-0.11 python turtle graphics application In-Reply-To: References: Message-ID: <9ff5475b55bcbc63b6b25e58a713bffe.squirrel@emailmg.ipage.com> The purely graphical Python version of turtle Graphics is Turtle Art/Turtle Blocks in the Sugar education software. http://activities.sugarlabs.org/en-US/sugar/addon/4027 You are welcome to adapt the tutorials at http:wiki.sugarlabs.org/go/Activities/TurtleArt/Tutorials to Pynguin or any other version of Turtle Art. On Wed, August 10, 2011 10:39 pm, Lee Harr wrote: > > Pynguin is a python-based turtle graphics application. > ??? It combines an editor, interactive interpreter, and > ??? graphics display area. > > It is meant to be an easy environment for introducing > ??? some programming concepts to beginning programmers. > > > http://pynguin.googlecode.com/ > > > This release continues to expand basic functionality and > ??? explores more user-friendly options in the interface. > > > Pynguin is tested with Python 2.7.1 and PyQt 4.8.3 and > ??? will use Pygments syntax highlighting if available. > > Pynguin is released under GPLv3. > > > Changes in pynguin-0.11: > ??? Session > ??????? - all settings now moved in to menus and settings dialogs > > ??? Pynguin API > ??????? - added .label() method to have a label attached to a pynguin > ??????????? - also accessible as .name attribute > ??????? - added .speed() method to change speed from user code > ??????? - viewcoords() now returns integers by default > ??????????? - pass floats=True to get the float values instead > ??????? - added .track() and .notrack() methods for user code > > ??? Canvas > ??????? - added support for custom avatars > ??????????? - both svg and bitmap images supported > ??????? - fixed motion when drawing slow circles with pen up > ??????? - don't draw circles when pen is up and speed is instant > ??????? - expand canvas when resizing window > > ??? Integrated Editor > ??????? - added "Test / Run all" button > ??????? - improved handling of external .py files > > ??? Integrated Console > ??????? - now gives correct call syntax when using test/run on classes > > ??? Examples > ??????? - make examples use new viewcoords() API > ??????? - fixed multi.pyn scatter example > ??????? - make multi.pyn follow examples work with existing pynguins > ??????? - demonstrate labels in multi.pyn follow example > ??????? - fix penup() in oo.pyn ZZ example > ??????? - add centered circle in oo.pyn ZZ example > > ??? General > ??????? - fixed examples getting gzipped in .deb distribution file > ??????? - added a way to dump contents of .pyn from command line > > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://wiki.sugarlabs.org/go/Replacing_Textbooks From nobody at nowhere.com Fri Aug 12 00:11:40 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Aug 2011 05:11:40 +0100 Subject: Processing a large string References: Message-ID: On Thu, 11 Aug 2011 19:03:36 -0700, goldtech wrote: > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? Use the .find() or .index() methods to find the next occurrence of a character. Building a large string by concatenation is inefficient, as each append will copy the original string. If you must have the result as a single string, using cStringIO would be preferable. But you'd be better off if you can work with a list of strings. From usenet-nospam at seebs.net Fri Aug 12 02:34:00 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 06:34:00 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: Before I get to the rest of this: Thinking it through, I've been unreasonable and grumpy here, and I'm trying to figure this out a bit more. A general observation: There's no real data here, so far as I can tell. There is no pair of languages which are exactly identical except for whether they use whitespace or some kind of brace/bracket/thing to indicate blocks, such that we can compare results between them. Humans are *notoriously* unreliable at evaluating the ease with which they do things, how long it takes them, how many mistakes they're making, and so on... So really, this is probably in large part a matter of taste or preference. On 2011-08-11, Ethan Furman wrote: > The times that whitespace indentation has bitten me, it was still not > difficult to fix -- I just had to look and see which line(s) > should/should not be where they were. I've been thinking about this, and I just plain can't understand how this could, in general, be done. Given a bunch of lines of code with no indication of where the blocks were supposed to be, I can't figure how this could be "fixed" in a way that is not-difficult, at least in general. > Not so. If the braces do not match /intent/ (which is the problem I > care most about) then it cannot be fixed by machine. Question for y'all: Has anyone here ever ACTUALLY encountered a case where braces -- not indentation -- did not match intent in a C-like language? I'm talking only about cases where braces are *actually present*. I haven't. Now, I've only been using C for maybe 20-25 years, but in all that time, I have never, ever, not *once*, seen braces not match intent. I've seen indentation errors galore. I've seen nutjobs writing "}}}" on a line all by itself. I've seen people forget to add braces and do stuff like: else a(); b(); ... but I've never, ever, seen braces not match intent. It just hasn't ever happened in code I've seen. >> people who'd picked Python for some stuff I have to work for, point out the >> hostility of the Python community to newcomers whose workflows don't happen >> to have been preemptively built entirely around Python's design decisions, >> and suggest that maybe we use another language. Heck, since I've been >> encouraged so much to do so, I think I will. > Your choice, obviously -- seems a shame to me, though, to give up on > Python because of one or two ouchy areas on c.l.py. By and large it's a > very helpful and courteous community. I was thinking about this more, and I think the issue that's historically bugged me is this: Most of the people I know and talk to about programming languages regard preferences as a matter of personal taste. I've seen people say that they prefer the significant-indentation thing, and I've seen people say they dislike it. The Python community, as a whole, seems particularly dogmatic about the indentation thing. And coming here as someone who doesn't much like it, and has been bitten by it a few times... Imagine that I were taking care of a cat for the first time, and I came to a cat-owners newsgroup, and found the following: 1. Nearly everyone there hated dogs, utterly. 2. The people who hated dogs were snide and insulting about people who didn't hate dogs. ... oookay, then. So I post my question, about a cat peeing on a bed, and I get the following responses: 1. What kind of idiot are you to continue using a broken non-waterproof matress? You should be using a solid vinyl cover over your mattress to prevent it from geting cat pee. 2. Once you've had a cat for a while you'll find that overall cat pee is superior to a dry mattress. ... At this point, I'm not exactly going to feel like a welcome member of the community. :) Now, that analogy is a little extreme, perhaps, but... Programmers get attached to their editors. And having a bunch of people insist that it's crazy of me to use an editor which has worked perfectly for me in the other ten programming languages I use, with settings that are not merely tolerable but *mandatory* for at least one of them, is... well, it doesn't create the impression that people who don't happen to already have fallen in love with an editor that coexists well with the whitespace thing are welcome. And part of this really is personal taste. I *LIKE* having a matching outdent for everything. I like to look at code and see blah blah blah blah blah because then I know it's balanced. If one of them is missing, *something is wrong*. And I have to keep that instinct to stay functional in most of the other languages I know. I don't have the option of ceasing to use C, but if I used C and didn't watch for missing close-braces, I'd be pretty badly hosed. So I have this strong incentive to prefer an explicit thing that I can see. And in any event, I *do* prefer it. In other language communities, when I find things about the language troublesome, I usually find people offering suggestions for ways to improve things, or workarounds, or acknowledging that, yes, that can be annoying. But for some reason, in this one, that's apparently against a local taboo. So instead of acknowledging that it is conceivably possible for people to prefer different things, people say things like "oh, once you've done it a bit you'll realize how much better it is and then you'll love it". Condescending, smug, and, at least so far, *totally untrue* for me. I am also weirded out by the claim that a Python which used braces would no longer be Python in any way, shape, or form. If you were to make a C derivative which used indentation instead of braces (this should be trivial to do with a preprocessor), I can't imagine C programmers claiming it's "not C". Of course it's C; it has the C type system, the C operators, the C promotion rules, C linkage and scope and so on... That's C. It's just a C variant which tweaks the punctuation. If Python with braces wouldn't be Python at all, why on earth does the language even exist? If all you want is indentation-which-matters, it's super easy to write a preprocessor for ANY language to do that, and you could have every last positive feature, benefit, or valuable trait of Python by doing that to any other language. Unless, of course, there are *other* things that are significant about Python. In which case, a language which preserved all of those, but used braces, would still be a kind of Python after all. Long story short: I think the dismissiveness and hostility I've seen from people in the Python community towards people who, for *whatever* reason, find the indentation-flow-control thing annoying, is not really helping the Python community win converts. All the people yelling at me and insulting my choice of editors, and telling me I should control every mail server between me and anyone who will ever send me code, have done nothing at all to make me feel like this is a language community I'd like. Meanwhile, the Python users I've talked to elsewhere who have funny indentation war stories but say that over time they've gotten used to it and they like how the code looks have made it sound like the language might be sorta fun. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 03:09:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 08:09:03 +0100 Subject: allow line break at operators In-Reply-To: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 2:40 AM, Steven D'Aprano wrote: > Please be careful about conflating significant indentation with significant > whitespace. Many languages have significant whitespace: > > foo bar > > is rarely the same thing as > > foobar > > but is the same as > > foo ? ? ? ? ? bar > > Python is no different. > Of course. But most languages derived from C have a single lexer token "whitespace". That one token is significant, but these are all the same: foo bar foo bar foo bar foo/* this one wasn't originally the same*/bar Python handles differently source files that differ only in whitespace. It's not only indentation; newlines are whitespace too, and they're significant. In C-derived languages, it's only presence-or-absence. ChrisA From przemolicc at poczta.fm Fri Aug 12 03:10:42 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Fri, 12 Aug 2011 09:10:42 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110812071041.GA6027@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:38:32PM -0700, SigmundV wrote: > When I saw the headline I thought "oh no, not string concatenation > again... we have had scores of these thread before...", but this is a > rather interesting problem. The OP says he's not a database > developer, but why is he then fiddling with internal database > operations? Wouldn't it be better to go back to the database > developers and have them look into parallel processing. I'm sure that > Oracle databases can do parallel processing by now... :-) Good question but I try to explain what motivates me to do it. First reason (I think the most important :-) ) is that I want to learn something new - I am new to python (I am unix/storage sysadmin but with programming background so python was a natural choice for more complicated sysadmin tasks). Another reason is that our server (and I am responsible for it) has many, many but slow cores (as I had written before). It means that parallelization of operations is obvious - the developer is not keen to spent much time on it (she is busy) - and for me this is something new (among some boring daily tasks ... ;-) ) and fresh :-) Another intention is to get some more knowledge about parallelization: how to divide some task into subtasks, what is the most optimal way to do it, etc And the last reason is that I love performance tuning :-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Zmyslowa bielizna? U nas ja znajdziesz! http://linkint.pl/f29fe From rosuav at gmail.com Fri Aug 12 03:20:04 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 08:20:04 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 7:34 AM, Seebs wrote: > If Python with braces wouldn't be Python at all, why on earth does the > language even exist? Every language has its philosophy. Python, as conceived by Guido van Rossum, is a language which (guys, correct me where I'm wrong please!): * Eschews unnecessary syntactic salt * Has "batteries included" * Has a clean and readable syntax To achieve this, Python: * Uses indentation and other whitespace as structural elements (rather than semicolons, braces, etc) * Has a large standard library and an enormous PyPI collection * Uses keywords (and, or, not, if/else) rather than symbols (&, |, !, ?:) for common tasks Etcetera. These are the philosophical decisions made by GvR and the Python community, and these define Python's syntax. If you go against these, you could make something that compiles down to Python's byte code; in fact, I'd say you could make something that produces a .pyc file and then hands it to the regular Python interpreter for execution. Is it Python? No, no more than NetREXX is Java just because it can make a .class file. It's a different language. Pike is very similar to Python in underlying structure. You can pass lists and dictionaries (called arrays and mappings) around as first-class objects, you can reference objects in multiple places, you can work with huge integers comfortably. But they're different in philosophy. Pike's purpose is primarily zero-downtime servers; I can (and do on a daily basis) update parts of the code of a running program, without disconnecting clients. Python doesn't do this, and to make Python do this would violate a lot of its simplicities and underlying referencings. It can be done without modifying the interpreter, but it's never been designed in. If you want that feature, you go to Pike; if you want Python's syntax, you go to Python. I hope I make myself clear, Josephine? ChrisA From paal.nilsen at gmail.com Fri Aug 12 03:21:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Fri, 12 Aug 2011 00:21:23 -0700 (PDT) Subject: generate and send mail with python: tutorial In-Reply-To: References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Friday, August 12, 2011 8:51:33 AM UTC+2, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > Is that really such a difficult task? > > Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > Wulfraed Dennis Lee Bieber AF6VN > wlf... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Nice story bro... From paal.nilsen at gmail.com Fri Aug 12 03:21:23 2011 From: paal.nilsen at gmail.com (maedox) Date: Fri, 12 Aug 2011 00:21:23 -0700 (PDT) Subject: generate and send mail with python: tutorial In-Reply-To: References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Friday, August 12, 2011 8:51:33 AM UTC+2, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > Is that really such a difficult task? > > Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > Wulfraed Dennis Lee Bieber AF6VN > wlf... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Nice story bro... From przemolicc at poczta.fm Fri Aug 12 03:50:29 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Fri, 12 Aug 2011 09:50:29 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <20110812075029.GB6027@host.pgf.com.pl> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: > On Thu, Aug 11, 2011 at 2:46 PM, wrote: > > This is the way I am going to use. > > But what is the best data type to hold so many rows and then operate on them ? > > > > List of strings. [...] Let's assume I have the whole list in the memory: Can I use this list in the following way ? subprocess_1 - run on list between 1 and 10000 subprocess_2 - run on list between 10001 and 20000 subprocess_3 - run on list between 20001 and 30000 etc ... Can I use sort of indexing on this list ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Doladuj telefon przez Internet! Sprawdz >> http://linkint.pl/f2a06 From __peter__ at web.de Fri Aug 12 04:39:38 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2011 10:39:38 +0200 Subject: Processing a large string References: Message-ID: goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? You can read the file in chunks: from functools import partial def read_chunks(instream, chunksize=None): if chunksize is None: chunksize = 2**20 return iter(partial(instream.read, chunksize), "") def split_file(instream, delimiter, chunksize=None): leftover = "" chunk = None for chunk in read_chunks(instream): chunk = leftover + chunk parts = chunk.split(delimiter) leftover = parts.pop() for part in parts: yield part if leftover or chunk is None or chunk.endswith(delimiter): yield leftover I hope I got the corner cases right. PS: This has come up before, but I couldn't find the relevant threads... From ben+python at benfinney.id.au Fri Aug 12 04:59:41 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 18:59:41 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> Message-ID: <87ipq3gg3m.fsf@benfinney.id.au> Seebs writes: > On 2011-08-11, Ben Finney wrote: > > You're welcome to attempt to demonstrate the superiority of some > > other Python-with-braces, but it will (a) be un-Pythonic, and (b) be > > unlikely to gain the efforts of people who don't think what you're > > addressing is a problem. > > I am pretty sure Python is a pretty nice language. However, the > indentation thing has screwed me a few times. Furthermore, I know > people who like Python a great deal and acknowledge, without much > difficulty, that the indentation thing has caused problems or > incompatibilities for them. Yes. It's caused problems for me too, so I'm not going to deny that. This is different from saying ?indentation as block structure? is a problem; that statement is what I disagree with, and what I think most respondents who disagree with you are objecting to. > So when I see people deny that it is at all a problem, or that there > are any possible shortcomings to it, I infer that they have some > compelling reason to deny the existence of a thing which is reliably > and easily observed. I don't see anyone making the denials you're referring to there. If I did, you would have my support in considering those denials mistaken. Likewise, ?end of line as end of statement? has caused me and many others problems. I'd go so far as to say that any Python programmer for whom that's not true has not done any significant Python programming. That doesn't make ?end of line as end of statement? a problem. If a language feature is beneficial in far greater proportion to the inconveniences of that feature, I'd say that feature *is not a problem* for users of that language. In Python, I maintain that's the case for ?end of line as end of statement?, and for ?indentation as block structure?. -- \ ?A computer once beat me at chess, but it was no match for me | `\ at kick boxing.? ?Emo Philips | _o__) | Ben Finney From rosuav at gmail.com Fri Aug 12 05:20:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 10:20:41 +0100 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811143923.GG4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: On Thu, Aug 11, 2011 at 3:39 PM, wrote: > On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >> List of strings. Take it straight from your Oracle interface and work >> with it directly. > > Can I use this list in the following way ? > subprocess_1 - run on list between 1 and 10000 > subprocess_2 - run on list between 10001 and 20000 > subprocess_3 - run on list between 20001 and 30000 > etc > ... Yep! You use list slicing. Working with smaller numbers for an example: >>> ltrs=['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'] >>> ltrs[:10] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] >>> ltrs[10:20] ['k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't'] >>> ltrs[20:] ['u', 'v', 'w', 'x', 'y', 'z'] (I actually created that list as "list(string.ascii_lowercase)" for what that's worth.) Slice operations are quite efficient. Chris Angelico From stefan_ml at behnel.de Fri Aug 12 05:25:06 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Aug 2011 11:25:06 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: <20110811143923.GG4990@host.pgf.com.pl> References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: przemolicc at poczta.fm, 11.08.2011 16:39: > On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >> On Thu, Aug 11, 2011 at 2:46 PM, wrote: >>> This is the way I am going to use. >>> But what is the best data type to hold so many rows and then operate on them ? >>> >> >> List of strings. Take it straight from your Oracle interface and work >> with it directly. > > Can I use this list in the following way ? > subprocess_1 - run on list between 1 and 10000 > subprocess_2 - run on list between 10001 and 20000 > subprocess_3 - run on list between 20001 and 30000 > etc > ... Sure. Just read the data as it comes in from the database and fill up a chunk, then hand that on to a process. You can also distribute it in smaller packets, just check what size gives the best throughput. Still, I'd give each work parcel a number and then reorder the results while collecting them, that allows you to vary the chunk size and the process size independently, without having to wait for a process that happens to take longer. Stefan From ben+python at benfinney.id.au Fri Aug 12 06:39:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 20:39:44 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d3gahq1b.fsf@benfinney.id.au> Seebs writes: > Question for y'all: > > Has anyone here ever ACTUALLY encountered a case where braces -- not > indentation -- did not match intent in a C-like language? I'm talking > only about cases where braces are *actually present*. What a strange limitation. Why are you not comparing apples with apples? The correct comparison would be ?getting the braces to match the intended structure? compared with ?getting the indentation to match the intended structure?. > The Python community, as a whole, seems particularly dogmatic about > the indentation thing. And coming here as someone who doesn't much > like it, and has been bitten by it a few times... As you say, the data is thin on the ground for this issue. Would you accept the charge that you're being just as dogmatic about the superiority of braces-as-block-syntax? If so, good for you; we're all equally dogmatic by your definition. Let's move on. If not, what makes your position less dogmatic than ours? -- \ ?We jealously reserve the right to be mistaken in our view of | `\ what exists, given that theories often change under pressure | _o__) from further investigation.? ?Thomas W. Clark, 2009 | Ben Finney From steve+comp.lang.python at pearwood.info Fri Aug 12 06:40:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 20:40:37 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> Message-ID: <4e450326$0$29970$c3e8da3$5496439d@news.astraweb.com> Ben Finney wrote: > Likewise, ?end of line as end of statement? has caused me and many > others problems. I don't understand this. Can you give an example? Do you mean, "Sometimes I want more code in a single statement than will comfortably fit in a single line"? -- Steven From ayaskanta.swain at altair.com Fri Aug 12 06:41:04 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 12 Aug 2011 16:11:04 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> Hi, I have a requirement where I need to check the write permissions on a directory on Windows platform. I don't want to use the python function os.access( ), since it does not work correctly on Windows. It is giving incorrect results to me. Another option of actually creating a temporary file inside the folder & then deleting it to check whether the user has write permissions or not is causing performance issues. It is slowing down our application when we have to check the permissions on hundreds of folders. It also changes the last access time stamp of the folder. So is there any other way such as using Win32API or Win32 security modules to check the permissions? Please suggest. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayaskanta.swain at altair.com Fri Aug 12 06:43:48 2011 From: ayaskanta.swain at altair.com (Ayaskanta Swain) Date: Fri, 12 Aug 2011 16:13:48 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: <21581D39FA3BDF40904D75AF9653CE2606BC8B2C@blrex.prog.altair.com> Some additional information - I am using python 2.5.1 version & it cannot be upgraded now to a higher version. Thanks Ayaskant- ________________________________ From: Ayaskanta Swain Sent: Friday, August 12, 2011 4:11 PM To: 'python-list at python.org' Subject: How to Check Write Access of a Folder on Windows Hi, I have a requirement where I need to check the write permissions on a directory on Windows platform. I don't want to use the python function os.access( ), since it does not work correctly on Windows. It is giving incorrect results to me. Another option of actually creating a temporary file inside the folder & then deleting it to check whether the user has write permissions or not is causing performance issues. It is slowing down our application when we have to check the permissions on hundreds of folders. It also changes the last access time stamp of the folder. So is there any other way such as using Win32API or Win32 security modules to check the permissions? Please suggest. Thanks Ayaskant- -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Aug 12 06:52:44 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Aug 2011 11:52:44 +0100 Subject: How to Check Write Access of a Folder on Windows In-Reply-To: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> References: <21581D39FA3BDF40904D75AF9653CE2606BC8B29@blrex.prog.altair.com> Message-ID: <4E4505FC.1030405@timgolden.me.uk> On 12/08/2011 11:41, Ayaskanta Swain wrote: > Hi, > > I have a requirement where I need to check the write permissions on a > directory on Windows platform. I don?t want to use the python function > os.access( ), since it does not work correctly on Windows. It is giving > incorrect results to me. > > Another option of actually creating a temporary file inside the folder & > then deleting it to check whether the user has write permissions or not > is causing performance issues. It is slowing down our application when > we have to check the permissions on hundreds of folders. It also changes > the last access time stamp of the folder. > > So is there any other way such as using Win32API or Win32 security > modules to check the permissions? In general, yes. Depends how finnicky you want to get. I take it from your question that you're pretty much unfamiliar with the Windows Security APIs and structures? There's a quite a bit of information around on the subject, but have a look at this first which is at least Python-oriented: http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The trouble is that do what you want, you need to use the AccessCheck API (or emulate its functionality) and this isn't currently exposed by the pywin32 modules. You could run it up yourself with ctypes or by creating a quick extension for the purpose. Alternatively, as I say, you could emulate by scanning the ACLs/ACEs and trying to apply some suitable logic. Frankly, I'd have thought this was harder work :) Hope that helps TJG From rdmoores at gmail.com Fri Aug 12 06:52:47 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Fri, 12 Aug 2011 03:52:47 -0700 Subject: Puzzled about the output of my demo of a proof of The Euler Series Message-ID: For the first time in my 7 years of using Gmail, I accidentally deleted my original post and it's one reply by casevh. I found both in the list archive, and with this post both quote casevh's reply and answer it. Sorry about my screw up. On Aug 10, 4:57 pm, "Richard D. Moores" wrote: > I saw an interesting proof of the limit of The Euler Series on > math.stackexchange.com at > . > Scroll down to Hans Lundmark's post. > > I thought I'd try to see this "pinching down" on the limit of pi**2/6. > See my attempt, and output for n = 150 at > . What puzzles me is that > upper_bound_partial_sum (lines 39 and 60) is always smaller than the > limit. It should be greater than the limit, right? If not, no pinching > between upper_bound_partial_sum and lower_bound_partial_sum. > > I've checked and double-checked the computation, but can't figure out > what's wrong. > > Thanks, > > Dick Moores The math is correct. The proof only asserts that sum(1/k^2) is between the upper and lower partial sums. The upper and lower partial sums both converge to pi^2/6 from below and since the sum(1/k^2) is between the two partial sums, it must also converge to pi^2/6. Try calculating sum(1/k^2) for k in range(1, 2**n) and compare that with the upper and lower sums. I verified it with several values up to n=20. casevh ===================Dick Moores' reply=================== Thank you! I had missed the 2^n -1 on the top of the sigma (see my image of the inequality expression at . So I rewrote the script and now it does what I intended -- show the pinching down on sum(1/k^2) by the upper sums and the lower sums for successively larger n. See the new script at . Dick From gandalf at shopzeus.com Fri Aug 12 07:14:04 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Aug 2011 13:14:04 +0200 Subject: problem with GTK language In-Reply-To: References: Message-ID: <4E450AFC.1020408@shopzeus.com> On 2011-08-10 16:22, Peter Irbizon wrote: > Hello, > I have strange problem with gtk language in pygtk. When I run .py file > it shows all gtk labels in my default windows language (slovak). But > when I compile it with py2exe and run exe file all labels are in > english. Why this happens? How can I define on program startup which > language to use? I would like to choose between english and slovak. I > tryed to set locals in my application but no luck. What am I doing wrong? Do you have this in your main program? import locale locale.setlocale(locale.LC_ALL, '') From ben+python at benfinney.id.au Fri Aug 12 07:16:55 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Aug 2011 21:16:55 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> <4e450326$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vqyhobc.fsf@benfinney.id.au> Steven D'Aprano writes: > Ben Finney wrote: > > > Likewise, ?end of line as end of statement? has caused me and many > > others problems. > > I don't understand this. Can you give an example? Many times I have split a line expecting that some bracketing syntax will cause the statement to continue across the split. I've been wrong, and the code either gave a SyntaxError or, worse, did something functional but unintended. That is a problem only because end-of-line (outside some bracketing syntax) ends a statement. My point is that I consider that problem to be at least on par in the severity of the problems caused by indentation-as-block-syntax. That is, very small compared with the great benefit of the clean and readable syntax that results. -- \ ?Not to be absolutely certain is, I think, one of the essential | `\ things in rationality.? ?Bertrand Russell | _o__) | Ben Finney From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Fri Aug 12 08:54:14 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Fri, 12 Aug 2011 14:54:14 +0200 Subject: allow line break at operators In-Reply-To: <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 12.08.2011 03:40 schrieb Steven D'Aprano: > The only exception I can think of is *very* early Fortran, and that rightly > is considered a mistake. ATARI 800XL. Built-in BASIC, acknowledging every command with "READY". Going over it with the cursor results in "ERROR- 6", meaning "no READ without DATA"... same as "READ Y". Thomas, it was a long time ago... From neilc at norwich.edu Fri Aug 12 08:57:22 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Aug 2011 12:57:22 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9akm9iFgfcU1@mid.individual.net> On 2011-08-12, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Incidentally, I will happily argue the >> benefits of Python's significant whitespace, even though I disagree >> with it; there are quite a few. > > Please be careful about conflating significant indentation with significant > whitespace. Many languages have significant whitespace: > > foo bar > > is rarely the same thing as > > foobar > > but is the same as > > foo bar > > Python is no different. > > The only exception I can think of is *very* early Fortran, and > that rightly is considered a mistake. Early versions of Basic were like this, too. It was common to compress large C64 Basic programs by removing the spaces and substituting the command synonyms. -- Neil Cerutti From aspineux at gmail.com Fri Aug 12 08:59:40 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 05:59:40 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: On Aug 12, 8:51?am, Dennis Lee Bieber wrote: > On Thu, 11 Aug 2011 08:07:09 -0700 (PDT), aspineux > declaimed the following in gmane.comp.python.general: > > > Hi I have written a tutorial about how to generate and send emails > > with python. > > ? ? ? ? Is that really such a difficult task? Yes it's difficult to make an _universal_ mail parser, able to handle mails from different MUA, using different charsets. Some emails that break RFC's requires at least some background to know which rules can be missed by some MUA ! Handle mail from a unique source or similar sources is easy. Using try and error method is fine for this kind of job, you don't even need to care if the email you're parsing match the RFC's or not. My "parser" functions have been tested over 20.000 mails from all around the world using some human and automated verifications ! Generating emails is not easy, when mixing internationalized addresses, subject and content. Integrating text, html, attachment and embedded images in one single email looks to me difficult enough to require some explanations. At least read carefully all my articles to get an idea about the difficulty, this is what I try to explain. Regards. > > ? ? ? ? Okay, I didn't really use Python for the entire creation of the > message... But my first real Python program (using 1.4 or 1.5, whatever > was included in the first "Programming Python" disk, for AmigaOS) was a > rudimentary outgoing SMTPd which had to parse headers from ?message > files "queued" by an ARexx script from an Amiga version of ELM, then > handshake with the ISP SMTPd to relay the message onward. It took less > than a week after buying the book that I had this ARexx/Python hybrid > working -- and it worked better than either C-language programs I'd > downloaded (at that period of time, Amiga email programs ONLY read from > local spool and queued to local spool; separate programs had to be used > to read POP3 and send SMTP... My first SMTP utility presumed 1) direct > connection to destination address, 2) created an email file for each > address -- problem: if a destination did not have a receiving SMTPd [ie, > one needed to do an MX lookup instead] it would hang trying to send that > message, and never process others... The second program used ISP relay > -- but it only parsed the "TO:" header, and thereby failed to handshake > CC and BCC destinations) > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From k.sahithi2862 at gmail.com Fri Aug 12 09:31:57 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 12 Aug 2011 06:31:57 -0700 (PDT) Subject: ADULT FAVORATE BLOG Message-ID: <86838230-02ce-46b0-a3ee-f44742997b43@g39g2000pro.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html KAJAL AGARWAL HOT SEXY PHOTOS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html KATRINA KAIF IN BEAUTIFUL RED DRESS http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From goldtech at worldpost.com Fri Aug 12 09:36:52 2011 From: goldtech at worldpost.com (goldtech) Date: Fri, 12 Aug 2011 06:36:52 -0700 (PDT) Subject: Processing a large string References: Message-ID: Thanks for all this info. From steve+comp.lang.python at pearwood.info Fri Aug 12 09:38:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 12 Aug 2011 23:38:30 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> Message-ID: <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> aspineux wrote: > Hi I have written a tutorial about how to generate and send emails > with python. [...] Thank you, that is an extremely detailed tutorial. -- Steven From 1248283536 at qq.com Fri Aug 12 10:18:52 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 12 Aug 2011 22:18:52 +0800 Subject: fork problem Message-ID: in the book ,A call to wait() suspends execution (i.e., waits) until a child process (any child process) has completed, terminating either normally or via a signal. wait() will then reap the child, releasing any resources. If the child has already completed, then wait() just performs the reaping procedure. here is my code import os print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() if ret == 0: os.system('ls') else: os.wait() print "i am runing,who am i? ",os.getpid() according to the word,the output may be: i am parent 8014 i am here 8014 i am here 8015 "omitted my file" i am runing,who am i? 8014 because 8015 is terminated by os.wait(). in fact the output is: i am parent 8014 i am here 8014 i am here 8015 "omitted my file" i am runing,who am i? 8015 i am runing,who am i? 8014 i want to know why ?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Fri Aug 12 10:30:57 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 07:30:57 -0700 (PDT) Subject: fork problem References: Message-ID: <9330c4f3-ae9a-4081-bc54-1460970f8d3f@h14g2000yqd.googlegroups.com> On Aug 12, 4:18 pm, "????" <1248283... at qq.com> wrote: > in the book ,A call to wait() suspends execution (i.e., waits) until a child process (any child process) has completed, terminating either normally or via a signal. wait() will then reap the child, releasing any resources. If the child has already completed, then wait() just performs the reaping procedure. > here is my code > import os > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > if ret == 0: > os.system('ls') > else: > os.wait() > print "i am runing,who am i? ",os.getpid() > > according to the word,the output may be: > i am parent 8014 > i am here 8014 > i am here 8015 > "omitted my file" > i am runing,who am i? 8014 > because 8015 is terminated by os.wait(). > > in fact the output is: > > i am parent 8014 > i am here 8014 > i am here 8015 > "omitted my file" > i am runing,who am i? 8015 > i am runing,who am i? 8014 > > i want to know why ?? To get what you want, use os.exec() instead of os.system() or add a os.exit() just after os.system() Regards From __peter__ at web.de Fri Aug 12 10:48:10 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Aug 2011 16:48:10 +0200 Subject: Processing a large string References: Message-ID: Peter Otten wrote: > goldtech wrote: >> Say I have a very big string with a pattern like: >> >> akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... >> >> I want to split the sting into separate parts on the "3" and process >> each part separately. I might run into memory limitations if I use >> "split" and get a big array(?) I wondered if there's a way I could >> read (stream?) the string from start to finish and read what's >> delimited by the "3" into a variable, process the smaller string >> variable then append/build a new string with the processed data? > PS: This has come up before, but I couldn't find the relevant threads... Alex Martelli a looong time ago: > from __future__ import generators > > def splitby(fileobj, splitter, bufsize=8192): > buf = '' > > while True: > try: > item, buf = buf.split(splitter, 1) > except ValueError: > more = fileobj.read(bufsize) > if not more: break > buf += more > else: > yield item + splitter > > if buf: > yield buf http://mail.python.org/pipermail/python-list/2002-September/770673.html From rantingrick at gmail.com Fri Aug 12 11:26:45 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 08:26:45 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> On Aug 12, 1:34?am, Seebs wrote: > > And part of this really is personal taste. ?I *LIKE* having a matching outdent > for everything. ?I like to look at code and see > ? ? ? ? blah > ? ? ? ? ? ? ? ? blah > ? ? ? ? ? ? ? ? ? ? ? ? blah > ? ? ? ? ? ? ? ? blah > ? ? ? ? blah > > because then I know it's balanced. ?If one of them is missing, *something is > wrong*. What is with you guys and this need to have your hand held to read code. Out-dents are noise and nothing more. When you're driving on a two lane highway that becomes one lane, would you forget to merge (OUTDENT) simply because the "merge sign" was missing? If you did then i would say you need to keep your eyes on the road (CODE) instead of looking for signs on the side of the road. In other words; you need to start acting like an intelligent agent instead of a zombie. > In other language communities, when I find things about the language > troublesome, I usually find people offering suggestions for ways to improve > things, or workarounds, or acknowledging that, yes, that can be annoying. > But for some reason, in this one, that's apparently against a local taboo. > So instead of acknowledging that it is conceivably possible for people to > prefer different things, people say things like "oh, once you've done it a > bit you'll realize how much better it is and then you'll love it". > Condescending, smug, and, at least so far, *totally untrue* for me. Well for indention there is no alternatives. There is either indent/ dendent, or suffer the syntax error. > I am also weirded out by the claim that a Python which used braces would no > longer be Python in any way, shape, or form. ?If you were to make a C > derivative which used indentation instead of braces (this should be trivial > to do with a preprocessor), I can't imagine C programmers claiming it's > "not C". ?Of course it's C; it has the C type system, the C operators, the > C promotion rules, C linkage and scope and so on... That's C. ?It's just a C > variant which tweaks the punctuation. Hmm, Python's exclusive use of indent/dedent for denoting blocks is rather unique in a world of braces (barring a few other less known languages). Removing that feature and replacing it with braces (or tags or whatever) would change the language significantly! Likewise allowing a directive like "use braces = True" would also be detrimental to our code bases. A language must always strive to remove ambiguities and multiplicity. Having more than one way to mark blocks is insanity. You never want to induce more overhead than necessary because such things are detrimental to work flow and language evolution. > If Python with braces wouldn't be Python at all, why on earth does the > language even exist? ?If all you want is indentation-which-matters, it's > super easy to write a preprocessor for ANY language to do that, and you could > have every last positive feature, benefit, or valuable trait of Python by > doing that to any other language. This statement leads me to believe you have very little experience with the Python language. Python has many wonderful attributes and design philosophies. Significant indentation is just ONE of many. > Unless, of course, there are *other* things that are significant > about Python. ?In which case, a language which preserved all of > those, but used braces, would still be a kind of Python after all. I don't understand this need for braces. You yearn so badly to be dominated by them. Is this a psychological disorder, a Helsinki syndrome that you cannot shake? There is life after braces my friend, and the future is bright! > Long story short: ?I think the dismissiveness and hostility I've seen from > people in the Python community towards people who, for *whatever* reason, > find the indentation-flow-control thing annoying, is not really helping the > Python community win converts. ? As much as we love people getting on board we are not about to sacrifice our strong beliefs in clean source code just so you and other hardwired C programmers will come along. Indentation is at the very heart of Pythons philosophy. A philosophy that breaks free from decades old language design build on the detrimental ideals of multi- stylism. Good languages do not care about your singularly instinctual emotion needs for bondage, no, they care about productivity and readability from a community perspective. PS: I will admit that a few of our community members can be rather acerbic at times. From paulo at matos-sorge.com Fri Aug 12 11:30:29 2011 From: paulo at matos-sorge.com (Paulo J. Matos) Date: Fri, 12 Aug 2011 16:30:29 +0100 Subject: Multiple process output Message-ID: Hi all, I am have a function which executes a command in the shell. The stdout and stderr of the command should be multipled to two strings for stdout and stderr respectively and stdout and stderr of the current process respectively. I have done like this: from subprocess import Popen, PIPE, STDOUT from select import select from os import read from sys import stdout, stderr def communicate(p): """ Multiplex the subprocess stdout/stderr to the process stdout/stderr and a tuple of strings """ output = [] errput = [] while True: (ready_to_read, _, _) = select([p.stdout, p.stderr], [], []) dataout = "" dataerr = "" if p.stdout in ready_to_read: dataout = read(p.stdout.fileno(), 1024) stdout.write(dataout) output.append(dataout) if p.stderr in ready_to_read: dataerr = read(p.stderr.fileno(), 1024) stderr.write(dataerr) errput.append(dataerr) if dataout == "" and dataerr == "": p.stdout.close() p.stderr.close() break return (''.join(output), ''.join(errput)) def exe(s, cwd=None, output_command=True): if output_command: print s p = Popen(s, stdin=None, stdout=PIPE, stderr=PIPE, shell=True, cwd=cwd) (output, err) = communicate(p) rc = p.wait() return (rc, output, err) Unfortunately, the program is _sometimes_ but not always getting stuck on the call to select. I don't really understand when this happens. Any suggestions to the above code so select doesn't block the function? Cheers, -- PMatos From rantingrick at gmail.com Fri Aug 12 11:33:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 08:33:07 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> On Aug 12, 2:20?am, Chris Angelico wrote: > Pike is very [snip] > Pike's purpose is [snip] > you go to Pike[snip] > > I hope I make myself clear, Josephine? The only thing that is clear to me is that you have a hidden agenda to incorporate pike's functionality into Python -- and this is not the first time! Chris, this incessant babbling about "pike this" and "pike that" is starting to get on my nerves. Why don't you go over to comp.lang.pike and gush to them about how wonderful the language is. PS: Although i give you brownie point for sucking up to GvR and the community at large before hinting about "Esox lucius" greatness. Nice! From jackhatterly at hotmail.com Fri Aug 12 11:55:33 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 15:55:33 +0000 Subject: Problem reading HTTP_COOKIE Message-ID: Hi; I'm trying to get cookies to work and I've traced my problem down to this reduced script: #! /usr/bin/python import string import os import datetime, Cookie, random import time import os def parse_cookie(): print 'Content-Type: text/html\n' print os.environ.get('HTTP_COOKIE') print '' print '' if __name__ == "__main__": parse_cookie() It prints "None". However, when I look in my browser's cookie jar, there is a cookie "www.my_site.com" where my_site is the site from which I am surfing the above script. What gives? TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From tfb at tfeb.org Fri Aug 12 11:58:50 2011 From: tfb at tfeb.org (Tim Bradshaw) Date: Fri, 12 Aug 2011 16:58:50 +0100 Subject: What Programing Language are the Largest Website Written In? References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> Message-ID: On 2011-08-02 15:41:06 +0100, ccc31807 said: > > Most of these are tech companies. Tech companies are very important, > but so are other kinds of companies. What do manufacturing companies > use, like Ford and Toyota, energy companies like BP and Exxon, > pharmaceutical companies, consumer product companies, and so on? What > about the big retailers, Sears, WalMart, Target, etc.? A more important metric is how critical the web presence is to the company. For Amazon, say, it's pretty critical, so what they do is likely to be interesting: if their site is broken they're not making any money. For Toyota, say, well, an outage would probably be embarrassing, but it's not anything like as critical to them. Unfortunatly I suspect that with web stuff as with other stuff, the answer is that it entirely depends. I am endlessly horrified by the poor state of software that is really critical to large companies. From sigmundv at gmail.com Fri Aug 12 12:09:42 2011 From: sigmundv at gmail.com (SigmundV) Date: Fri, 12 Aug 2011 09:09:42 -0700 (PDT) Subject: String concatenation - which is the fastest way ? References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> Message-ID: <4c2bbcd6-01a3-4a53-bd08-4a7bda5e4154@h15g2000yqa.googlegroups.com> On Aug 12, 8:10?am, przemol... at poczta.fm wrote: > Good question but I try to explain what motivates me to do it. > First reason (I think the most important :-) ) is that I want to learn > something new - I am new to python (I am unix/storage sysadmin but with programming > background so python was a natural choice for more complicated > sysadmin tasks). > Another reason is that our server (and I am responsible for it) has > many, many but slow cores (as I had written before). It means that > parallelization of operations is obvious - the developer is not keen > to spent much time on it (she is busy) - and for me this is something new > (among some boring daily tasks ... ;-) ) and fresh :-) > Another intention is to get some more knowledge about parallelization: > how to divide some task into subtasks, what is the most optimal way to do it, etc > And the last reason is that I love performance tuning :-) When you put it this way I better understand what you're after and why you do this. And I agree with all your points. Learning something new is a noble cause in itself. :) Sigmund From alec.taylor6 at gmail.com Fri Aug 12 12:26:58 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 13 Aug 2011 02:26:58 +1000 Subject: What Programing Language are the Largest Website Written In? In-Reply-To: References: <20f06312-9313-4380-b7e4-2515aca01a84@d8g2000prf.googlegroups.com> <5a7b9ec6-e66d-4fd7-aa27-46eed3ce272c@k15g2000yqd.googlegroups.com> Message-ID: C++ (Wt xor CppCMS) WOOT! On Sat, Aug 13, 2011 at 1:58 AM, Tim Bradshaw wrote: > On 2011-08-02 15:41:06 +0100, ccc31807 said: > >> >> Most of these are tech companies. Tech companies are very important, >> but so are other kinds of companies. What do manufacturing companies >> use, like Ford and Toyota, energy companies like BP and Exxon, >> pharmaceutical companies, consumer product companies, and so on? What >> about the big retailers, Sears, WalMart, Target, etc.? > > A more important metric is how critical the web presence is to the company. > ?For Amazon, say, it's pretty critical, so what they do is likely to be > interesting: if their site is broken they're not making any money. ?For > Toyota, say, well, an outage would probably be embarrassing, but it's not > anything like as critical to them. > > Unfortunatly I suspect that with web stuff as with other stuff, the answer > is that it entirely depends. ?I am endlessly horrified by the poor state of > software that is really critical to large companies. > > -- > http://mail.python.org/mailman/listinfo/python-list > From usenet-nospam at seebs.net Fri Aug 12 12:33:11 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:11 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 7:34 AM, Seebs wrote: >> If Python with braces wouldn't be Python at all, why on earth does the >> language even exist? > Every language has its philosophy. Yes. > Etcetera. These are the philosophical decisions made by GvR and the > Python community, and these define Python's syntax. If you go against > these, you could make something that compiles down to Python's byte > code; in fact, I'd say you could make something that produces a .pyc > file and then hands it to the regular Python interpreter for > execution. Is it Python? No, no more than NetREXX is Java just because > it can make a .class file. It's a different language. I would argue that any pure syntactic-sugar change which can be done entirely by a naive preprocessor does not constitute a significant shift in the language itself. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <87ipq3gg3m.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Ben Finney wrote: > Seebs writes: >> I am pretty sure Python is a pretty nice language. However, the >> indentation thing has screwed me a few times. Furthermore, I know >> people who like Python a great deal and acknowledge, without much >> difficulty, that the indentation thing has caused problems or >> incompatibilities for them. > Yes. It's caused problems for me too, so I'm not going to deny that. > This is different from saying ???indentation as block structure??? is a > problem; that statement is what I disagree with, and what I think most > respondents who disagree with you are objecting to. See below; I think I agree with what I meant by it, and disagree with what you seem to interpret it as. Your interpretation makes as much sense as mine, so far as I can tell. > I don't see anyone making the denials you're referring to there. If I > did, you would have my support in considering those denials mistaken. I suspect, thinking about it more, that it's a communications problem. > Likewise, ???end of line as end of statement??? has caused me and many > others problems. I'd go so far as to say that any Python programmer for > whom that's not true has not done any significant Python programming. > That doesn't make ???end of line as end of statement??? a problem. True, although it does make it a thing which *has* at least one problem. > If a language feature is beneficial in far greater proportion to the > inconveniences of that feature, I'd say that feature *is not a problem* > for users of that language. I wouldn't. Lemme give a concrete example, from C, since that's the language I know best. There are sound technical reasons for which C lets you manipulate pointers. If you couldn't, it wouldn't be C, and you couldn't do the bulk of the stuff that makes C useful. But... Pointer manipulation leads to crashes. LOTS of crashes. I have never met a C programmer with over a day or two of experience who has not had a program crash due to some mishap involving a pointer. When people say that a language like, say, Java, is trying to solve the problems of C's pointer system, I think that's a reasonable thing to try to do. There are tradeoffs. But it would be, IMHO, silly to claim that there are no problems with pointers; there are just benefits which outweigh them *for the things the language is trying to do*. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Ben Finney wrote: > Seebs writes: >> Question for y'all: >> >> Has anyone here ever ACTUALLY encountered a case where braces -- not >> indentation -- did not match intent in a C-like language? I'm talking >> only about cases where braces are *actually present*. > What a strange limitation. Why are you not comparing apples with apples? I am trying to. I'm trying to compare C-like languages, with braces, to Python, with indentation. > The correct comparison would be ???getting the braces to match the > intended structure??? compared with ???getting the indentation to match the > intended structure???. Right. I have seen Python programs in which indentation, while it obviously matched what actually happened, did not match intent. It is (at least in principle) easier to debug because you can see that, but... I've seen people in C do stuff like: for (i = 0; i < N; ++i); a[i] = 0; This is clearly a case where indentation matches intent, but doesn't match functionality, because C allows indentation to not-match functionality; this is the famous problem Python is solving. However, I've never, ever, seen a problem like that *when people were using braces*. An apples-to-apples comparison between indentation and braces should be a comparison *to braces*, not to people who "cleverly" omit braces. (If you are looking for a debate on whether C's optional-braces are a good idea, I'm afraid you will have to look elsewhere; if it were up to me, I would totally approve a language change making them mandatory.) > As you say, the data is thin on the ground for this issue. Would you > accept the charge that you're being just as dogmatic about the > superiority of braces-as-block-syntax? I don't think so. > If not, what makes your position less dogmatic than ours? A couple of things. 1. I do assert that people who are happy with an editor and have been using it for twenty years ought to change their editor to accommodate a language which uses braces. 2. I will happily grant that braces, written legibly, cost you an extra line per block, and that this space cost can make it harder to see all the code at once. 3. I don't have a problem agreeing that there certainly appear to be people for whom the Python syntax is easier to read. I think #1 is the real point at which I think there's a dogmatism problem. Maybe editors shouldn't "helpfully" convert spaces to tabs, but that feature has been nearly entirely beneficial to me in everything else I've edited for a long time, and I don't *want* to learn a new editor just for one language. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 12:33:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 16:33:12 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: On 2011-08-12, rantingrick wrote: > What is with you guys and this need to have your hand held to read > code. Good question! Great to see that the helpful and welcoming community is living up to its reputation. My brain has quirks. Some people call them defects, some don't, but it really doesn't matter; there are things about which my brain is just plain unreliable and I rely moderately heavily on extra visual cues to reduce the frequency with which I get things wrong when skimming. > Out-dents are noise and nothing more. Not for me. > When you're driving on a > two lane highway that becomes one lane, would you forget to merge > (OUTDENT) simply because the "merge sign" was missing? No, because the *LANE BOUNDARIES* would move. > If you did then > i would say you need to keep your eyes on the road (CODE) instead of > looking for signs on the side of the road. In other words; you need to > start acting like an intelligent agent instead of a zombie. Interesting theory. I propose we extend it to expression processing in general. Instead of writing a = (x + y) * z let's just write a = (x + y * z It's obvious that no one would have needed to introduce parentheses here unless they wanted to bind the + more closely than the *, so the ) is just noise and not needed. > Hmm, Python's exclusive use of indent/dedent for denoting blocks is > rather unique in a world of braces (barring a few other less known > languages). Removing that feature and replacing it with braces (or > tags or whatever) would change the language significantly! It would, but unless that's the only distinctive trait of the language, I don't think it would make the language cease to be Python. > Likewise allowing a directive like "use braces = True" would also be > detrimental to our code bases. A language must always strive to remove > ambiguities and multiplicity. Having more than one way to mark blocks > is insanity. You never want to induce more overhead than necessary > because such things are detrimental to work flow and language > evolution. Agreed. > This statement leads me to believe you have very little experience > with the Python language. Python has many wonderful attributes and > design philosophies. Significant indentation is just ONE of many. It was a reductio-ad-absurdum. > I don't understand this need for braces. You yearn so badly to be > dominated by them. Is this a psychological disorder, a Helsinki > syndrome that you cannot shake? There is life after braces my friend, > and the future is bright! Man, you really love pushing them buttons, don't you? You don't understand a thing. Therefore... there is no such thing, anyone who experiences life differently from you needs to be insulted? > As much as we love people getting on board we are not about to > sacrifice our strong beliefs in clean source code just so you and > other hardwired C programmers will come along. But you will happily insult people and call them names in order to keep them from having anything to listen to? > PS: I will admit that a few of our community members can be rather > acerbic at times. Yeah. And the thing is... This can't possibly lead to convincing people of your position, so presumably the purpose is that you don't want anyone who didn't start out agreeing with you to ever come to agree with you? Why's that? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From no.email at please.post Fri Aug 12 13:02:38 2011 From: no.email at please.post (kj) Date: Fri, 12 Aug 2011 17:02:38 +0000 (UTC) Subject: Java is killing me! (AKA: Java for Pythonheads?) Message-ID: *Please* forgive me for asking a Java question in a Python forum. My only excuse for this no-no is that a Python forum is more likely than a Java one to have among its readers those who have had to deal with the same problems I'm wrestling with. Due to my job, I have to port some Python code to Java, and write tests for the ported code. (Yes, I've considered finding myself another job, but this is not an option in the immediate future.) What's giving me the hardest time is that the original Python code uses a lot of functions with optional arguments (as is natural to do in Python). As far as I can tell (admittedly I'm no Java expert, and have not programmed in it since 2001), to implement a Java method with n optional arguments, one needs at least 2**n method definitions. Even if all but one of these definitions are simple wrappers that call the one that does all the work, it's still a lot of code to wade through, for nothing. That's bad enough, but even worse is writing the unit tests for the resulting mountain of fluffCode. I find myself writing test classes whose constructors also require 2**n definitions, one for each form of the function to be tested... I ask myself, how does the journeyman Python programmer cope with such nonsense? For the sake of concreteness, consider the following run-of-the-mill Python function of 3 arguments (the first argument, xs, is expected to be either a float or a sequence of floats; the second and third arguments, an int and a float, are optional): def quant(xs, nlevels=MAXN, xlim=MAXX): if not hasattr(xs, '__iter__'): return spam((xs,), n, xlim)[0] if _bad_quant_args(xs, nlevels, xlim): raise TypeError("invalid arguments") retval = [] for x in xs: # ... # elaborate acrobatics that set y # ... retval.append(y) return retval My Java implementation of it already requires at least 8 method definitions, with signatures: short[] quant (float[], int , float) short[] quant (float[], int ) short[] quant (float[], float) short[] quant (float[] ) short quant (float , int , float) short quant (float , int ) short quant (float , float) short quant (float ) Actually, for additional reasons, too arcane to go into, I also need four more: short quant (Float , Integer, Float) short quant (Float , Integer ) short quant (Float , Float) short quant (Float ) Writing JUnit tests for these methods is literally driving me INSANE. Some advice on implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj From clp2 at rebertia.com Fri Aug 12 13:03:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Aug 2011 10:03:04 -0700 Subject: allow line break at operators In-Reply-To: <87d3gahq1b.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On Fri, Aug 12, 2011 at 3:39 AM, Ben Finney wrote: > Seebs writes: > >> Question for y'all: >> >> Has anyone here ever ACTUALLY encountered a case where braces -- not >> indentation -- did not match intent in a C-like language? ?I'm talking >> only about cases where braces are *actually present*. > > What a strange limitation. Why are you not comparing apples with apples? > > The correct comparison would be ?getting the braces to match the > intended structure? compared with ?getting the indentation to match the > intended structure?. One argument I've heard from braces fans is that sometimes they want their own structure, which does not match the actual block structure. Example: FILE* f = fopen(...); // do stuff with f // at this indent level fclose(f); // back to normal But really this is just working around other limitations in the language (i.e. lack of a with-statement equivalent). Cheers, Chris -- http://rebertia.com From nathan.alexander.rice at gmail.com Fri Aug 12 13:15:02 2011 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 12 Aug 2011 13:15:02 -0400 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: public FooClass(String requiredArgument1, Long requiredArgument2, map yourOptionalArgumentMap) { ... } From jgaynor at ncsa.uiuc.edu Fri Aug 12 13:24:27 2011 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Fri, 12 Aug 2011 12:24:27 -0500 (CDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: Message-ID: <922377184.2518.1313169867874.JavaMail.root@zimbra-1.ncsa.uiuc.edu> One Java-eque solution is to pass in an object that has the arguments and build the validity logic into that object. So you have public class LimitsAndLevels{ float[] whatever = null; float anotherOne = 0.0; // or maybe some other overloaded value public float[] getWhatever(){ isValid(); return whatever; } public boolean hasWhatever(){ isValid(); return whatever != null; } public void isValid(){ // Code to check validity // Probably throws an IllegalArgumentException if you need. // That exception extends RuntimeException, so no need to put in a throws list } } Then you pass this, e.g., public class HeavyLifter{ public int[] quant(LimitsAndLevels args){ // acrobatics. } } Hope this helps... Jeff ----- Original Message ----- From: "kj" To: python-list at python.org Sent: Friday, August 12, 2011 12:02:38 PM Subject: Java is killing me! (AKA: Java for Pythonheads?) *Please* forgive me for asking a Java question in a Python forum. My only excuse for this no-no is that a Python forum is more likely than a Java one to have among its readers those who have had to deal with the same problems I'm wrestling with. Due to my job, I have to port some Python code to Java, and write tests for the ported code. (Yes, I've considered finding myself another job, but this is not an option in the immediate future.) What's giving me the hardest time is that the original Python code uses a lot of functions with optional arguments (as is natural to do in Python). As far as I can tell (admittedly I'm no Java expert, and have not programmed in it since 2001), to implement a Java method with n optional arguments, one needs at least 2**n method definitions. Even if all but one of these definitions are simple wrappers that call the one that does all the work, it's still a lot of code to wade through, for nothing. That's bad enough, but even worse is writing the unit tests for the resulting mountain of fluffCode. I find myself writing test classes whose constructors also require 2**n definitions, one for each form of the function to be tested... I ask myself, how does the journeyman Python programmer cope with such nonsense? For the sake of concreteness, consider the following run-of-the-mill Python function of 3 arguments (the first argument, xs, is expected to be either a float or a sequence of floats; the second and third arguments, an int and a float, are optional): def quant(xs, nlevels=MAXN, xlim=MAXX): if not hasattr(xs, '__iter__'): return spam((xs,), n, xlim)[0] if _bad_quant_args(xs, nlevels, xlim): raise TypeError("invalid arguments") retval = [] for x in xs: # ... # elaborate acrobatics that set y # ... retval.append(y) return retval My Java implementation of it already requires at least 8 method definitions, with signatures: short[] quant (float[], int , float) short[] quant (float[], int ) short[] quant (float[], float) short[] quant (float[] ) short quant (float , int , float) short quant (float , int ) short quant (float , float) short quant (float ) Actually, for additional reasons, too arcane to go into, I also need four more: short quant (Float , Integer, Float) short quant (Float , Integer ) short quant (Float , Float) short quant (Float ) Writing JUnit tests for these methods is literally driving me INSANE. Some advice on implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Fri Aug 12 13:35:46 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Aug 2011 18:35:46 +0100 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: <4E456472.9040600@mrabarnett.plus.com> On 12/08/2011 18:02, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > [snip] I would declare: short[] quant (float[], int , float) short quant (Float , Integer, Float) and see how it goes. "float" and "int" should be boxed to "Float" and "Integer" automatically. If the second and third arguments are frequently the default, then I would also declare: short[] quant (float[]) short quant (Float ) From billy.earney at gmail.com Fri Aug 12 13:44:16 2011 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 12 Aug 2011 12:44:16 -0500 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: Look into jython. You might be able to run your python code, directly in java. :) http://www.jython.org/ On Fri, Aug 12, 2011 at 12:02 PM, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > > short[] quant (float[], int , float) > short[] quant (float[], int ) > short[] quant (float[], float) > short[] quant (float[] ) > > short quant (float , int , float) > short quant (float , int ) > short quant (float , float) > short quant (float ) > > Actually, for additional reasons, too arcane to go into, I also > need four more: > > short quant (Float , Integer, Float) > short quant (Float , Integer ) > short quant (Float , Float) > short quant (Float ) > > Writing JUnit tests for these methods is literally driving me > INSANE. > > Some advice on implementing and testing functions with optional > arguments in Java would be appreciated. > > TIA! > > kj > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Fri Aug 12 13:45:47 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 12 Aug 2011 19:45:47 +0200 Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: <87k4ai8qwk.fsf@dpt-info.u-strasbg.fr> kj writes: [...] > def quant(xs, nlevels=MAXN, xlim=MAXX): [...] > My Java implementation of it already requires at least 8 method > definitions, with signatures: (BTW, your approach won't work if several optionals have the same type.) [...] - use Integer, Float, etc. everywhere. The compiler will box primitive types as needed at call sites - re. default values (on positional params), use null to indicate a use of the default, or use ellipsis, or use class-provided static fields at call sites, or use a special class to represent all the optional parameters - re. named parameters with default, use a map, or change the call sites to remove them -- Alain. From rantingrick at gmail.com Fri Aug 12 13:57:57 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Aug 2011 10:57:57 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> On Aug 12, 11:33?am, Seebs wrote: > > My brain has quirks. ?Some people call them defects, some don't, but it > really doesn't matter; there are things about which my brain is just plain > unreliable and I rely moderately heavily on extra visual cues to reduce > the frequency with which I get things wrong when skimming. I think that really boils down to you refusing to open your eyes up to new ways of doing things. You are clutching the past and it is taking you down with it. Pry your lips from Ritchie's left teet and stop slurping that "brace" milk; because it is polluting your mind! > > When you're driving on a > > two lane highway that becomes one lane, would you forget to merge > > (OUTDENT) simply because the "merge sign" was missing? > > No, because the *LANE BOUNDARIES* would move. The "lane boundaries" will also move whilst reading code that uses the indent/dedent paradigm. Are you honestly telling me that you will skip over a four spaced dedent without seeing it however you can easily spot a single closing brace and instantly "know" which corresponding opener brace to which it referrers without looking, and counting, and wasting time? Sorry, i just don't believe you. > I propose we extend it to expression processing in general. ?Instead > of writing > ? ? ? ? a = (x + y) * z > let's just write > ? ? ? ? a = (x + y * z I'm glad you brought this up! How about this instead: a = x + y * z ...where the calculation is NOT subject to operator precedence? I always hated using parenthesis in mathematical calculations. All math should resolve in a linear fashion. 3+3*2 should always be 12 and NOT 9! > It's obvious that no one would have needed to introduce parentheses here > unless they wanted to bind the + more closely than the *, so the ) is > just noise and not needed. I would even go as far to use a special set of brackets for linear calculations before using only one, or playing the precedence game. > > As much as we love people getting on board we are not about to > > sacrifice our strong beliefs in clean source code just so you and > > other hardwired C programmers will come along. > > But you will happily insult people and call them names in order to > keep them from having anything to listen to? I am not trying to discredit you simply by disagreeing with you. I have offered facts as to why significant indention is far superior to braces and yet you continue to use the same emotionally charged babble in your defense. When you offer some real facts then i will give then just consideration, until then i will "try" to enlighten you of the merits of significant indentation. From aspineux at gmail.com Fri Aug 12 14:17:28 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 12 Aug 2011 11:17:28 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> On Aug 12, 3:38?pm, Steven D'Aprano wrote: > aspineux wrote: > > Hi I have written a tutorial about how to generate and send emails > > with python. > > [...] > > Thank you, that is an extremely detailed tutorial. Thanks, It was my intention Alain > > -- > Steven From miki.tebeka at gmail.com Fri Aug 12 14:18:01 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 12 Aug 2011 11:18:01 -0700 (PDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: <04e60610-b887-49f9-940f-7b4b507ae466@glegroupsg2000goo.googlegroups.com> You can probably do that with varargs. From usenet-nospam at seebs.net Fri Aug 12 14:37:41 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 18:37:41 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Chris Rebert wrote: > One argument I've heard from braces fans is that sometimes they want > their own structure, which does not match the actual block structure. EWW! > Example: > > FILE* f = fopen(...); > // do stuff with f > // at this indent level > fclose(f); > // back to normal > > But really this is just working around other limitations in the > language (i.e. lack of a with-statement equivalent). That's horrid. FWIW, the C idiom is: { FILE *f = ... ... fclose(f); } It isn't used all that widely, but it is a lot less horrible than random indenting would be. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 15:52:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 20:52:13 +0100 Subject: allow line break at operators In-Reply-To: <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <3884c102-8e2d-4a1f-8f2a-85fb68fe9fdb@c29g2000yqd.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 4:33 PM, rantingrick wrote: > On Aug 12, 2:20?am, Chris Angelico wrote: > >> Pike is very [snip] >> Pike's purpose is [snip] >> you go to Pike[snip] >> >> I hope I make myself clear, Josephine? > > The only thing that is clear to me is that you have a hidden agenda to > incorporate pike's functionality into Python -- and this is not the > first time! > > Chris, this incessant babbling about "pike this" and "pike that" is > starting to get on my nerves. Why don't you go over to comp.lang.pike > and gush to them about how wonderful the language is. Yeah, it's something I've mentioned a few times. I think people have mentioned C on this list a few times, too; also lisp. Of course, since this is the Python mailing list (or newsgroup, depending where you read it), we aren't allowed to mention any other languages at all. Mea culpa. I'm not seeking to add Pike's functionality into Python. I want the two languages to be different, and I want the world to have different languages. Diversity and choice promote quality in ways that you don't seem to understand. Chris Angelico From rosuav at gmail.com Fri Aug 12 16:01:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:01:56 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On Fri, Aug 12, 2011 at 5:33 PM, Seebs wrote: > I've seen people in C do stuff like: > > ? ? ? ?for (i = 0; i < N; ++i); > ? ? ? ? ? ? ? ?a[i] = 0; > > This is clearly a case where indentation matches intent, but doesn't match > functionality, because C allows indentation to not-match functionality; this > is the famous problem Python is solving. > There's several solutions to this. One is linting utilities that detect unexpectedly-indented code, which is the concept that Python took to the logical extent of syntactic errors. Another is (again linting) to disallow a direct trailing semicolon; if you want an empty body, you put whitespace before the semicolon. But that wasn't your point, I realise :) ChrisA From rosuav at gmail.com Fri Aug 12 16:09:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:09:56 +0100 Subject: allow line break at operators In-Reply-To: <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 6:57 PM, rantingrick wrote: > I'm glad you brought this up! How about this instead: > > ? ?a = x + y * z > > ...where the calculation is NOT subject to operator precedence? I > always hated using parenthesis in mathematical calculations. All math > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > 9! Why is left-to-right inherently more logical than multiplication-before-addition? Why is it more logical than right-to-left? And why is changing people's expectations more logical than fulfilling them? Python uses the + and - symbols to mean addition and subtraction for good reason. Let's not alienate the mathematical mind by violating this rule. It would be far safer to go the other way and demand parentheses on everything. Incidentally, in the original expression, it would be slightly more sane to write it as: a = x + y) * z borrowing from the musical concept that a repeat sign with no corresponding begin-repeat means to repeat from the beginning. But both of these violate XKCD 859. From ethan at stoneleaf.us Fri Aug 12 16:15:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Aug 2011 13:15:52 -0700 Subject: __all__ In-Reply-To: References: <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4589F8.5080404@stoneleaf.us> Paul Woolcock wrote: > The gurus will have to correct me if this is not an accepted practice, > but I know some projects (Fabric is the one that comes to mind) will > define a submodule specifically for the 'from blah import *' situation. > The submodule would be called "api", or something like that, so you can > do: 'from mymodule.api import *' to separate the items you want to > include in your public api, while still keeping other names importable > by 'import blah' Have I said lately how much I *love* Python? Programming is fun again! Thanks, Paul, that was the clue I needed. Had to do some thinking since dbf is back to a single module, and no longer a package... here's what I came up with: ------------------------------------------------------------- class fake_module(object): def __init__(self, name, *args): self.name = name self.__all__ = [] for func in args: name = func.__name__ self.__dict__[name] = func self.__all__.append(name) def register(self): sys.modules["%s.%s" % (__name__, self.name)] = self ------------------------------------------------------------- then in my module (towards the bottom since I have to have all my functions/classes written that I want to include) I can have fake_module('api', class1, class2, func1, exception1).register() Now somebody else who wants to include the classes, exceptions, etc, that make up the primary part of the dbf module can do from dbf.api import * but help(dbf) will continue to list all the other public utility stuff (defined in dbf.__all__) normally. Thanks to all! ~Ethan~ From ckaynor at zindagigames.com Fri Aug 12 16:24:35 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Aug 2011 13:24:35 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 1:09 PM, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 6:57 PM, rantingrick > wrote: > > I'm glad you brought this up! How about this instead: > > > > a = x + y * z > > > > ...where the calculation is NOT subject to operator precedence? I > > always hated using parenthesis in mathematical calculations. All math > > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > > 9! > > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. > Left-to-right is more logical because that is the choice made by the English language (which I will note, we are using right now). Also, ignoring operator precedence, left-to-right is the way math equations evaluate. See 4 / 2 * 3 - you get 6, not (2/3) and not (3/2). Now, I would not suggest changing the multiplication before addition rule, for the very reason you mention: in many cases, the established rule is expected, but that does not mean it is more logical. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 12 16:29:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:29:25 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 4:55 PM, Jack Hatterly wrote: > It prints "None". However, when I look in my browser's cookie jar, there is > a cookie "www.my_site.com" where my_site is the site from which I am surfing > the above script. What gives? > I assume that what you mean is that it prints "None" even after you hit F5 to reload the page, as the first run of the script will never have a cookie. Your script is now not actually setting any cookie. What cookie are you seeing in your browser? It may be something created and consumed by your framework, somewhere. ChrisA From ethan at stoneleaf.us Fri Aug 12 16:35:56 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Aug 2011 13:35:56 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4E458EAC.8000702@stoneleaf.us> Chris Angelico wrote: > Incidentally, in the original expression, it would be slightly more > sane to write it as: > > a = x + y) * z > > borrowing from the musical concept that a repeat sign with no > corresponding begin-repeat means to repeat from the beginning. But > both of these violate XKCD 859. Argh! ;) ~Ethan~ From rosuav at gmail.com Fri Aug 12 16:39:33 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 21:39:33 +0100 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 6:02 PM, kj wrote: > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > Firstly, figure out how many combinations of optional arguments actually make sense. Any that don't, don't support. That may well cut it down significantly. And then, if there are any that make sense but will be really rare (eg if you allow optional specification of a max and a min, and most times you'll use either both bounds or neither), you can save a few by having the "optional" argument specified with a sentinel meaning "default". It's ugly in a few places to justify simplicity in most. If you really need 100% flexibility, then the suggestions already posted will definitely be the best. ChrisA From tdsimpson at gmail.com Fri Aug 12 16:47:40 2011 From: tdsimpson at gmail.com (MrPink) Date: Fri, 12 Aug 2011 13:47:40 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: Boy, that was a lot more elegant that I would have thought. Though hard for a greenhorn like me to really understand how the assignment are working, etc. Anyway, what are these kind of statement call so that I can read up more on this? What Python feature are you using? num_whites = ticket_whites & drawing_whites black_matching = ticket_black == drawing_black Thanks, On Aug 10, 11:35?pm, Miki Tebeka wrote: > Python built in types are enough for this problem IMO. You can use sets of tuples to specify ticket and drawings and then just do set intersection. > > Say the drawing is set([(5, 'wb'), (1, 'wb'), (45, 'wb'), (23, 'wb'), (27, 'wb')]) (keeping black ball out). The you can create a score function: > > Side note: I might used a namedtuple to have drawing.whites, drawing.black. > > def score(ticket_whites, ticket_black, drawing_whites, drawing_black): > ? ? num_whites = ticket_whites & drawing_whites > ? ? black_matching = ticket_black == drawing_black > ? ? return { > ? ? ? ? (2, True) ?: 1, > ? ? ? ? (3, False) : 2, > ? ? ? ? (3, True) ?: 3, > ? ? ? ? (4, False) : 4, > ? ? ? ? (4, True) ?: 5, > ? ? ? ? (5, False) : 6, > ? ? ? ? (5, True) ?: 10 > ? ? }[(num_whites, black_matching)] From usenet-nospam at seebs.net Fri Aug 12 17:06:37 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:37 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-12, rantingrick wrote: > On Aug 12, 11:33?am, Seebs wrote: >> My brain has quirks. ?Some people call them defects, some don't, but it >> really doesn't matter; there are things about which my brain is just plain >> unreliable and I rely moderately heavily on extra visual cues to reduce >> the frequency with which I get things wrong when skimming. > I think that really boils down to you refusing to open your eyes up to > new ways of doing things. You think that, then? Okay. > You are clutching the past and it is taking > you down with it. I see. This is a brilliant new theory. I will further explore the notion that actually my brain is 100% normal with no limitations except that I have used languages with braces. Doubtless this will prove illuminating. >> No, because the *LANE BOUNDARIES* would move. > The "lane boundaries" will also move whilst reading code that uses the > indent/dedent paradigm. Are you honestly telling me that you will skip > over a four spaced dedent without seeing it however you can easily > spot a single closing brace and instantly "know" which corresponding > opener brace to which it referrers without looking, and counting, and > wasting time? Sorry, i just don't believe you. Nope, not telling you that. Here's my example: if foo: blah blah blah if bar: moreblah moreblah if quux: typingisboring typingisboring typingisboring moreblah moreblah if baz: somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah somuchblah abitmoreblah It's not easy for me to be sure, looking at something roughly like that, what's being closed and what isn't. If I have braces, I can tell how many things are being closed. I like that. It makes me happy. >> I propose we extend it to expression processing in general. ?Instead >> of writing >> ? ? ? ? a = (x + y) * z >> let's just write >> ? ? ? ? a = (x + y * z > I'm glad you brought this up! How about this instead: > a = x + y * z > ...where the calculation is NOT subject to operator precedence? I > always hated using parenthesis in mathematical calculations. All math > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > 9! Doesn't matter. At some point, somewhere, it would become desireable to introduce precedence with (), at which point, it is quite possible that the trailing ) would be redundant, so why not omit it? > I am not trying to discredit you simply by disagreeing with you. No, but you're certainly being insulting. > I have offered facts as to why significant indention is far superior to > braces and yet you continue to use the same emotionally charged babble > in your defense. Facts: Pry your lips from Ritchie's left teet and stop slurping that "brace" milk; because it is polluting your mind! Emotionally charged babble: My brain has quirks. Some people call them defects, some don't, but it really doesn't matter; there are things about which my brain is just plain unreliable and I rely moderately heavily on extra visual cues to reduce the frequency with which I get things wrong when skimming. > When you offer some real facts then i will give then > just consideration, until then i will "try" to enlighten you of the > merits of significant indentation. Well played! -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 17:06:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:38 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-12, Chris Angelico wrote: > Why is left-to-right inherently more logical than > multiplication-before-addition? I'd say it's certainly "more Pythonic in a vacuum". Multiplication-before-addition, and all the related rules, require you to know a lot of special rules which are not visible in the code, and many of which have no real logical basis. Left-to-right is, if nothing else, the way the majority of us read. The problem is that since everyone's used precedence before, not using it violates the principle of least astonishment. ... Hmm. There is a thought; I think it may be useful to distinguish between "Pythonic" and "Pythonic in a vacuum". That is to say, there are things which would fit the basic philosophy of Python very well if previous programming languages and tools were not widespread, and there are other things which fit anyway. Using a simple left-to-right evaluation would probably be easier for people to understand, and more self-explanatory, *IF* there were no prior art. > Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Well, playing devil's advocate's advocate here... You could argue that switching from braces to indentation might be "changing" peoples' expectations, or might be fulfilling them, depending on the people. I think there's certainly cases where it is probably better to say "that expectation proves to make it impossible to build a clean language, so we're going to ask you to do things this way", and cases where it is probably better to say "that expectation is very deeply established, and doesn't really hurt the language, so we'll adapt to you". > Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. I wouldn't mind that. > Incidentally, in the original expression, it would be slightly more > sane to write it as: > > a = x + y) * z > > borrowing from the musical concept that a repeat sign with no > corresponding begin-repeat means to repeat from the beginning. But > both of these violate XKCD 859. Yes, yes they do. Huh. You know, that's why the outdents-without-symbols bug me; I have a thing with a colon on it introducing something, and then there's nothing ending it. I want that match so I can let the naive stack-depth-counter off somewhere in my brain do its thing without leaving me with a huge feeling of unclosed blocks. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Fri Aug 12 17:06:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 21:06:38 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <87d3gahq1b.fsf@benfinney.id.au> Message-ID: On 2011-08-12, Chris Angelico wrote: > On Fri, Aug 12, 2011 at 5:33 PM, Seebs wrote: >> I've seen people in C do stuff like: >> ? ? ? ?for (i = 0; i < N; ++i); >> ? ? ? ? ? ? ? ?a[i] = 0; >> This is clearly a case where indentation matches intent, but doesn't match >> functionality, because C allows indentation to not-match functionality; this >> is the famous problem Python is solving. > There's several solutions to this. One is linting utilities that > detect unexpectedly-indented code, which is the concept that Python > took to the logical extent of syntactic errors. Another is (again > linting) to disallow a direct trailing semicolon; if you want an empty > body, you put whitespace before the semicolon. > > But that wasn't your point, I realise :) I think it sort of is. My current preference would be that C-like languages would simply absolutely eliminate optional-braces. Then the whole category of errors would partially-go-away. You could still have code which didn't do what you meant, but it would be reliably easy to see what it did, and so on. But it's interesting to note that there are many ways to address this. Most of the C I've done has been in circumstances where misindented code was in fact a thing that would fail reviews. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ckaynor at zindagigames.com Fri Aug 12 17:11:35 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Aug 2011 14:11:35 -0700 Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 12, 2011 at 1:47 PM, MrPink wrote: > Boy, that was a lot more elegant that I would have thought. > Though hard for a greenhorn like me to really understand how the > assignment are working, etc. > > Anyway, what are these kind of statement call so that I can read up > more on this? > What Python feature are you using? > > num_whites = ticket_whites & drawing_whites > This is a set intersection, using the "bit-wise and" operator (&). It can also be written as either of: num_whites = (ticket_whites & drawing_whites) # Makes it a bit clearer that the "bit-wise and" operator runs before the "assignment" (=) operator. num_whites = ticket_whites.intersection(drawing_whites) # Calls the actual method rather than using the operator. A bit more verbose. > black_matching = ticket_black == drawing_black > This is just the result of an equality operator being assigned. It may be a bit clearer if you see it as: black_matching = (ticket_black == drawing_black) > > Thanks, > > For more details, you can look up sets (both the math kind and the specific Python implementation are relevant): http://docs.python.org/library/stdtypes.html#set http://en.wikipedia.org/wiki/Set_(mathematics) http://en.wikipedia.org/wiki/Set_theory Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From miki.tebeka at gmail.com Fri Aug 12 17:31:13 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 12 Aug 2011 14:31:13 -0700 (PDT) Subject: Searching for Lottery drawing list of ticket match... In-Reply-To: References: <5f630a0c-4444-4fe9-889e-a0b1430bb420@eb1g2000vbb.googlegroups.com> Message-ID: It's the builtin "set", see http://docs.python.org/library/stdtypes.html#set-types-set-frozenset From jackhatterly at hotmail.com Fri Aug 12 17:55:36 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 21:55:36 +0000 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: , Message-ID: > Date: Fri, 12 Aug 2011 21:29:25 +0100 > Subject: Re: Problem reading HTTP_COOKIE > From: rosuav at gmail.com > To: python-list at python.org > > I assume that what you mean is that it prints "None" even after you > hit F5 to reload the page, as the first run of the script will never > have a cookie. > > Your script is now not actually setting any cookie. What cookie are > you seeing in your browser? It may be something created and consumed > by your framework, somewhere. But my script *is* setting a cookie. I just sent a stripped-down version of the script earlier. Here's the entire script: #! /usr/bin/python import string import os import datetime, Cookie, random import time import os def parse_cookie(): ourTime = str(time.time()) environ = os.environ cookie = environ.get('HTTP_COOKIE', '') if cookie == '': cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = random.randint(1,999999999999) cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/var/www/html/my_site/clients/Millenium/' cookie['lastvisit']['comment'] = random.randint(1,999999999999) cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 c = Cookie.SimpleCookie() c.load(cookie) cookiedict = {} for key in c.keys(): cookiedict[key] = c.get(key).value print c print 'Content-Type: text/html\n' print '' print '' if __name__ == "__main__": parse_cookie() You see, every time when the cookie is read it comes back None which gets translated to '' and then the cookie is re-baked. *NOT* what I want!! I can see the cookie in my browser. TIA, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 12 18:00:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 12 Aug 2011 15:00:08 -0700 Subject: Processing a large string In-Reply-To: References: Message-ID: This is the sort of thing I wrote bufsock for. Don't let the name fool you - although I originally wrote it for sockets, it's since been extended to work with files and file handles. http://stromberg.dnsalias.org/~dstromberg/bufsock.html It was recently modified to work on 2.x and 3.x. On Thu, Aug 11, 2011 at 7:03 PM, goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 12 18:03:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 13 Aug 2011 08:03:49 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-12, rantingrick wrote: >> What is with you guys and this need to have your hand held to read >> code. > > Good question! Great to see that the helpful and welcoming community > is living up to its reputation. Please don't feed the troll. Responding to Rick's standard obnoxious posts is like wrestling with a pig -- you get tired and filthy, you never accomplish anything useful, and after a while, you realise that the pig is enjoying it. Save yourself a lot of aggravation and kill-file him now. -- Steven From ben+python at benfinney.id.au Fri Aug 12 18:12:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 08:12:27 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <874o1mgtys.fsf@benfinney.id.au> Seebs writes: > On 2011-08-12, rantingrick wrote: > > What is with you guys and this need to have your hand held to read > > code. > > Good question! Great to see that the helpful and welcoming community > is living up to its reputation. Please be aware that the particular person to whom you're responding is decidedly not part of the helpful and welcoming community here. > Man, you really love pushing them buttons, don't you? > > You don't understand a thing. Therefore... there is no such thing, > anyone who experiences life differently from you needs to be insulted? If you're interested, check the forum's archives for a thorough history of what the helpful and welcoming community say about him. You'll find we pretty much agree with your assessment. -- \ ?Generally speaking, the errors in religion are dangerous; | `\ those in philosophy only ridiculous.? ?David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney From drsalists at gmail.com Fri Aug 12 18:12:29 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 12 Aug 2011 15:12:29 -0700 Subject: Java is killing me! (AKA: Java for Pythonheads?) In-Reply-To: References: Message-ID: Check varargs (as another poster mentioned), and consider doing your unit tests in Jython. Some shops that don't want Python for production code are fine with Python for unit tests. However, if the reason for preferring java is type checking, you could perhaps get somewhere by suggesting pylint. On Fri, Aug 12, 2011 at 10:02 AM, kj wrote: > > > > *Please* forgive me for asking a Java question in a Python forum. > My only excuse for this no-no is that a Python forum is more likely > than a Java one to have among its readers those who have had to > deal with the same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write > tests for the ported code. (Yes, I've considered finding myself > another job, but this is not an option in the immediate future.) > > What's giving me the hardest time is that the original Python code > uses a lot of functions with optional arguments (as is natural to > do in Python). > > As far as I can tell (admittedly I'm no Java expert, and have not > programmed in it since 2001), to implement a Java method with n > optional arguments, one needs at least 2**n method definitions. > Even if all but one of these definitions are simple wrappers that > call the one that does all the work, it's still a lot of code to > wade through, for nothing. > > That's bad enough, but even worse is writing the unit tests for > the resulting mountain of fluffCode. I find myself writing test > classes whose constructors also require 2**n definitions, one for > each form of the function to be tested... > > I ask myself, how does the journeyman Python programmer cope with > such nonsense? > > For the sake of concreteness, consider the following run-of-the-mill > Python function of 3 arguments (the first argument, xs, is expected > to be either a float or a sequence of floats; the second and third > arguments, an int and a float, are optional): > > def quant(xs, nlevels=MAXN, xlim=MAXX): > if not hasattr(xs, '__iter__'): > return spam((xs,), n, xlim)[0] > > if _bad_quant_args(xs, nlevels, xlim): > raise TypeError("invalid arguments") > > retval = [] > for x in xs: > # ... > # elaborate acrobatics that set y > # ... > retval.append(y) > > return retval > > My Java implementation of it already requires at least 8 method > definitions, with signatures: > > short[] quant (float[], int , float) > short[] quant (float[], int ) > short[] quant (float[], float) > short[] quant (float[] ) > > short quant (float , int , float) > short quant (float , int ) > short quant (float , float) > short quant (float ) > > Actually, for additional reasons, too arcane to go into, I also > need four more: > > short quant (Float , Integer, Float) > short quant (Float , Integer ) > short quant (Float , Float) > short quant (Float ) > > Writing JUnit tests for these methods is literally driving me > INSANE. > > Some advice on implementing and testing functions with optional > arguments in Java would be appreciated. > > TIA! > > kj > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Fri Aug 12 18:14:01 2011 From: usenet-nospam at seebs.net (Seebs) Date: 12 Aug 2011 22:14:01 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Steven D'Aprano wrote: > Please don't feed the troll. Responding to Rick's standard obnoxious posts > is like wrestling with a pig -- you get tired and filthy, you never > accomplish anything useful, and after a while, you realise that the pig is > enjoying it. Save yourself a lot of aggravation and kill-file him now. You know... I think I just realized where a big part of my misperception of the Python community was. Which is that until todayish, I had not realized that he was regarded as a troll by the rest of the community. But now that a couple of people have told me this, I am a lot more comfortable referring to the Python community in general as "welcoming". I sometimes enjoy trying to extract information from people like that, but I will respect the preferences of the actually-helpful people and drop that line of inquiry. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Fri Aug 12 18:31:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:31:51 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: I think the best thing to do would be to look at the raw headers. If you can't do that in your framework, then try this: set the cookie, shut down your server, fire up a debugging HTTP server on the same port, and then refresh the page. If your browser is sending the cookie, you'll see it in the HTTP request; if not, you have a configuration issue. As I said earlier, setting the cookie with a path like that may mean that the browser won't send it. Chris Angelico From ben+python at benfinney.id.au Fri Aug 12 18:36:10 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 08:36:10 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y5yyfeat.fsf@benfinney.id.au> Seebs writes: > I sometimes enjoy trying to extract information from people like that, > but I will respect the preferences of the actually-helpful people and > drop that line of inquiry. :) Much appreciated, thank you :-) -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Fri Aug 12 18:39:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 13 Aug 2011 08:39:24 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > You know, that's why the outdents-without-symbols bug me; I have a > thing with a colon on it introducing something, and then there's nothing > ending it. But there is something ending it: a change in indentation level. Python's parser explicitly pushes INDENT and OUTDENT tokens into the stream. They're just a change of state in indentation level, which is much more easily seen without the need for counting braces. Python's parser may need to count tokens, but for the human reader merely needs to use its intuitive and highly accurate ability to notice when things line up. (Aside: this is why I dislike two-space indents. That's narrow enough to make the "does this line up" detector subject to too many false positives.) > I want that match so I can let the naive stack-depth-counter > off somewhere in my brain do its thing without leaving me with a huge > feeling of unclosed blocks. Yet another reason to consider brace languages harmful: they spoil the user's intuitive grasp of intuition as grouping. And it really is intuitive[1]: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html Historically, nearly all languages with braces pre-date the widespread adoption of tools that think they can mangle whitespace with impunity. (I would say that the reasons that the tools are broken is *because* programmers have trained themselves to think that whitespace doesn't matter -- ask most writers or artists and they would say *of course* whitespace matters. The separation between elements is important -- perhaps not quite as important as the elements themselves, but still important.) Explicit BEGIN/END tokens exist to make the job of the parser easier, not that of the programmer. But the human brain is a funny thing: you can train it to expect to do more work than is necessary, and it will complain when you make its job easier. [1] For some definition of intuition. -- Steven From rosuav at gmail.com Fri Aug 12 18:50:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:50:42 +0100 Subject: allow line break at operators In-Reply-To: <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 12, 2011 at 11:39 PM, Steven D'Aprano wrote: > ask most writers or artists and they would say *of course* > whitespace matters. You can write Perl code in the shape of a camel. Can you do that in Python? Okay. Open challenge to anyone. Write a Python script that outputs "Just another Python hacker" or some such message, and is shaped in some way appropriately. And no fair doing all the shaping in comments :) (Has it already been done?) ChrisA From jackhatterly at hotmail.com Fri Aug 12 18:53:16 2011 From: jackhatterly at hotmail.com (Jack Hatterly) Date: Fri, 12 Aug 2011 22:53:16 +0000 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: , , , Message-ID: Chris, I finally got a script that works. Thanks for trying! Jack #!/usr/bin/env python import string import os import datetime, Cookie, random import time # The returned cookie is available in the os.environ dictionary cookie_string = os.environ.get('HTTP_COOKIE') if not cookie_string: ourTime = str(time.time()) cookie = Cookie.SimpleCookie() cookie['lastvisit'] = string.replace(ourTime, '.', '') print cookie print 'Content-Type: text/html\n' print '' print '

Server time is', time.asctime(time.localtime()), '

' # The first time the page is run there will be no cookies print '

First visit or cookies disabled

' cookie = string.replace(ourTime, '.', '') cookie = Cookie.SimpleCookie() expiration = datetime.datetime.now() + datetime.timedelta(days=30) cookie['lastvisit'] = string.replace(ourTime, '.', '') else: # Run the page twice to retrieve the cookie cookie = Cookie.SimpleCookie() cookie['lastvisit'] = cookie_string cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60 cookie['lastvisit']['path'] = '/cgi-bin/' cookie['lastvisit']['comment'] = 'holds the last user\'s visit date' cookie['lastvisit']['domain'] = '.www.my_site.com' cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60 cookie['lastvisit']['secure'] = '' cookie['lastvisit']['version'] = 1 print 'Content-Type: text/html\n' print '

', cookie, '

' for morsel in cookie: print '

', morsel, '=', cookie[morsel].value print '

' for key in cookie[morsel]: print key, '=', cookie[morsel][key], '
' print '

' -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Aug 12 18:55:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Aug 2011 23:55:57 +0100 Subject: Problem reading HTTP_COOKIE In-Reply-To: References: Message-ID: On Fri, Aug 12, 2011 at 11:53 PM, Jack Hatterly wrote: > cookie['lastvisit']['path'] = '/cgi-bin/' > Yep, that's looking a lot more useful! Glad it's working. ChrisA From ben+python at benfinney.id.au Fri Aug 12 19:19:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 09:19:59 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9mfc9s.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, Aug 12, 2011 at 11:39 PM, Steven D'Aprano > wrote: > > ask most writers or artists and they would say *of course* > > whitespace matters. > > You can write Perl code in the shape of a camel. Can you do that in > Python? I'm glad to be using a language where that sort of hard to-read code is not encouraged by the syntax. Art is wonderful, if you don't want to communicate clearly. I'll thank the people who write the programs in my life to save their artistic expression for areas where clear communication is optional. -- \ ?My business is to teach my aspirations to conform themselves | `\ to fact, not to try and make facts harmonise with my | _o__) aspirations.? ?Thomas Henry Huxley, 1860-09-23 | Ben Finney From python.list at tim.thechases.com Fri Aug 12 19:53:43 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Aug 2011 18:53:43 -0500 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E45BD07.90300@tim.thechases.com> On 08/12/2011 05:50 PM, Chris Angelico wrote: > You can write Perl code in the shape of a camel. Can you do that in Python? > > Okay. Open challenge to anyone. Write a Python script that outputs > "Just another Python hacker" or some such message, and is shaped in > some way appropriately. And no fair doing all the shaping in comments Okay, my entry: print("Just another Python hacker") That lovely one-line shape resembles a straight & narrow snake ;-) -tkc From tjreedy at udel.edu Fri Aug 12 20:15:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Aug 2011 20:15:40 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/12/2011 6:14 PM, Seebs wrote: I am responding to your whole line of posts. I have been indenting code neatly for at least 32 years whenever the language I used allowed it. Just over 14 years ago, when Python was an obscure little known or used languge, I adopted it *because* it dropped all the redundant bracket noise and looked to me like 'executable pseudocode', as I explained (with an unfortunate misspelling) in https://groups.google.com/group/comp.lang.python/msg/cc25701a283a3f68 Indentation is part of that. Python-with-brackets would, to me, be something different -- sure, derived from Python, but not the same. I do not need for you to adopt and use Python to validate my choice. If you like it fine, welcome. If not, have fun with something else. I said that over a decade when this same discussion took place, and I say it now. Different brains are different. I do not care which of us is in the majority in which population. As I and others also pointed out over a decade ago, anyone is free to add insignificant comment braces (but keep that private, please) or, more sensibly, commented dedents to help the reader keep track of indent level. for... for ... if ... for ... if ... [50 more lines of code] #end outer if [more code] -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 12 20:18:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Aug 2011 20:18:39 -0400 Subject: generate and send mail with python: tutorial In-Reply-To: <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> Message-ID: On 8/12/2011 2:17 PM, aspineux wrote: > On Aug 12, 3:38 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> aspineux wrote: >>> Hi I have written a tutorial about how to generate and send emails >>> with python. >> >> [...] >> >> Thank you, that is an extremely detailed tutorial. > > Thanks, It was my intention Have you considered contributing a HOW-TO? -- Terry Jan Reedy From usenet-nospam at seebs.net Fri Aug 12 20:39:32 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 00:39:32 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-12, Steven D'Aprano wrote: > Seebs wrote: >> You know, that's why the outdents-without-symbols bug me; I have a >> thing with a colon on it introducing something, and then there's nothing >> ending it. > But there is something ending it: a change in indentation level. Hmm. Okay, here's what I'm not getting. Consider this: if foo: blah if bar: blah blah if baz: blah blah > Python's parser explicitly pushes INDENT and OUTDENT tokens into the stream. What's being pushed into the stream to indicate that the first outdent is two outdents and the second is one? I guess... The parser is explicitly pushing those tokens, but I can't *SEE* those tokens. If I am looking at the end of a really long thing, and I see: blah blah I only know what's happening if I have absolute confidence that the indentation is always by the same amount, etectera. > They're just a change of state in indentation level, which is much more > easily seen without the need for counting braces. Python's parser may need > to count tokens, but for the human reader merely needs to use its intuitive > and highly accurate ability to notice when things line up. Well, that's the thing. In a case like: if foo: if bar: blah blah I notice that *NOTHING* lines up with "if bar:". And that affects me about the way unmatched brackets do. > (Aside: this is why I dislike two-space indents. That's narrow enough to > make the "does this line up" detector subject to too many false positives.) Yeah. >> I want that match so I can let the naive stack-depth-counter >> off somewhere in my brain do its thing without leaving me with a huge >> feeling of unclosed blocks. > Yet another reason to consider brace languages harmful: they spoil the > user's intuitive grasp of intuition as grouping. I assume you mean "indentation as grouping". I'm... not sold on this. It's not that I don't see indentation as a kind of grouping. It's just that I really, really, want groups to have ends. Consider the hypothetical array syntax: a = [ 1, 2 b = [ 3, 4 This *bugs* me. It's perfectly legible, and if you define it that way, it's unambiguous and everything, but... It bugs me. I want beginnings to have an actual corresponding end. > But the human brain is a funny thing: you can train > it to expect to do more work than is necessary, and it will complain when > you make its job easier. Easier varies somewhat from person to person. I need a LOT of parity checks (speaking metaphorically) because my brain is fantastically prone to dropping bits. But I'm really fast. So a thing with lots of parity checks is much easier for me to actually *successfully* use than a thing which omits all that extra stuff. I was overjoyed when I saw that Ruby would let me write 1_048_576. I can read that with fewer errors than I can read 1048576. (And yes, I could also write "1<<20".) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Fri Aug 12 20:43:58 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 10:43:58 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> Message-ID: <87pqkaf8dt.fsf@benfinney.id.au> Terry Reedy writes: > >> aspineux wrote: > >>> Hi I have written a tutorial about how to generate and send emails > >>> with python. > Have you considered contributing a HOW-TO? I think Terry is referring to . I agree that this should be submitted to that collection, and maintained along with all the others. What is the process if the OP, or someone to whom the OP delegates authority, wants to do that? -- \ ?If you continue running Windows, your system may become | `\ unstable.? ?Microsoft, Windows 95 bluescreen error message | _o__) | Ben Finney From usenet-nospam at seebs.net Fri Aug 12 20:44:26 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 00:44:26 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-13, Terry Reedy wrote: > I have been indenting code neatly for at least 32 years whenever the > language I used allowed it. Just over 14 years ago, when Python was an > obscure little known or used languge, I adopted it *because* it dropped > all the redundant bracket noise and looked to me like 'executable > pseudocode', as I explained (with an unfortunate misspelling) in > https://groups.google.com/group/comp.lang.python/msg/cc25701a283a3f68 > Indentation is part of that. Python-with-brackets would, to me, be > something different -- sure, derived from Python, but not the same. Fair enough. > I do not need for you to adopt and use Python to validate my choice. If > you like it fine, welcome. If not, have fun with something else. If this were among my options, it's probably what I'd do. It is what I do for things where I get a choice of languages. FWIW, yes, I spec machines with ECC memory whenever I can. I am a big fan of "redundant" data that can detect likely errors. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Fri Aug 12 20:57:28 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 10:57:28 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k4aif7rb.fsf@benfinney.id.au> Seebs writes: > What's being pushed into the stream to indicate that the first outdent > is two outdents and the second is one? See for a comprehensive discussion of the lexing done on Python source. To examine the resulting code objects, see the ?dis? module in the standard library . -- \ ?[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 ben+python at benfinney.id.au Fri Aug 12 21:00:05 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Aug 2011 11:00:05 +1000 Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> <87pqkaf8dt.fsf@benfinney.id.au> Message-ID: <87fwl6f7my.fsf@benfinney.id.au> Ben Finney writes: > What is the process if the OP, or someone to whom the OP delegates > authority, wants to [contribute their work to the Python > documentation]? The answer is partly at : If you?re interested in contributing to Python?s documentation [?] Send an e-mail to docs at python.org or open an issue on the tracker. One should, before doing so, follow the above document on the documentation style conventions for Python. -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From greg.ewing at canterbury.ac.nz Fri Aug 12 21:19:24 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Aug 2011 13:19:24 +1200 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <9am1ouFgklU1@mid.individual.net> Chris Angelico wrote: > But both of these violate XKCD 859. For the benefit of all those who just went off to read that strip, here's something to help you unwind: ) There, you can relax now. -- Greg From usenet-nospam at seebs.net Fri Aug 12 22:34:50 2011 From: usenet-nospam at seebs.net (Seebs) Date: 13 Aug 2011 02:34:50 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <87k4aif7rb.fsf@benfinney.id.au> Message-ID: On 2011-08-13, Ben Finney wrote: > Seebs writes: >> What's being pushed into the stream to indicate that the first outdent >> is two outdents and the second is one? > See for a > comprehensive discussion of the lexing done on Python source. Interesting, thanks. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From kw at codebykevin.com Fri Aug 12 22:49:32 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 12 Aug 2011 22:49:32 -0400 Subject: os.system() on Windows in Tkinter app spawns console window Message-ID: I'm developing a Tkinter app for a Windows customer, and the app bundles several command-line tools (ported from Unix). I call out to these console tools from the Tkinter app via os.system(). However, in the frozen version of my app, when I call out to these tools, I get multiple console windows popping up. This is jarring to say the least. Is there any way to run the commands under the hood without the console/DOS windows popping up? --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From nagle at animats.com Sat Aug 13 00:30:28 2011 From: nagle at animats.com (John Nagle) Date: Fri, 12 Aug 2011 21:30:28 -0700 Subject: 'Use-Once' Variables and Linear Objects In-Reply-To: References: Message-ID: <4e45fe11$0$2139$742ec2ed@news.sonic.net> On 8/2/2011 7:19 AM, Neal Becker wrote: > I thought this was an interesting article > > http://www.pipeline.com/~hbaker1/Use1Var.html Single-use was something of a dead end in programming. Single assignment, where you can only set a variable when you create it, is more useful. Single assignment is comparable to functional programming, but without the deeply nested syntax. Functional programs are trees, while single-assignment programs are directed acyclic graphs. The difference is that you can fan-out results, while in a a functional language, you can only fan in. This fits well with Python, where you can write things like def fn(x) : (a, b, c) = fn1() return(fn2(a) + fn3(b)*c) "const" is often used in C and C++ to indicate single-assignment usage. But C/C++ doesn't have multiple return values, so the concept isn't as useful as it is in Python. Optimizing compilers usually recognize variable lifetimes, and so they create single-assignment variables internally when possible. This is a win for register and stack allocation, and for fine-grain parallelism on machines which support it. Since Python isn't very optimizable, this is mostly a curiosity. John Nagle From juliocesarrodriguezcruz at gmail.com Sat Aug 13 00:59:42 2011 From: juliocesarrodriguezcruz at gmail.com (Julio Cesar Rodriguez Cruz) Date: Sat, 13 Aug 2011 00:59:42 -0400 Subject: How to print non-printable chars?? Message-ID: Hi all, If I open an .exe file in any text editor I get lot of odd chars, what I want is to know how to output those chars if I have the hexadecimal code. I found out how to do the reverse process with the quopri module, i.e.: >>> import quopri >>> quopri.encodestring('??') '=F1=E8=18' >>> quopri.decodestring('=F1=E8=18') '\xf1\xe8\x18' but how to do the reverse? ...gived '\xf1\xe8\x18', print '??' any tips? thanks Julio Cesar From nobody at nowhere.com Sat Aug 13 01:15:25 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Aug 2011 06:15:25 +0100 Subject: os.system() on Windows in Tkinter app spawns console window References: Message-ID: On Fri, 12 Aug 2011 22:49:32 -0400, Kevin Walzer wrote: > I'm developing a Tkinter app for a Windows customer, and the app bundles > several command-line tools (ported from Unix). I call out to these > console tools from the Tkinter app via os.system(). However, in the > frozen version of my app, when I call out to these tools, I get multiple > console windows popping up. This is jarring to say the least. Is there > any way to run the commands under the hood without the console/DOS > windows popping up? Just a wild guess, but try explicitly redirecting the commands' stdin/stdout/stderr. You might also consider using subprocess.call() instead of os.system(). From nobody at nowhere.com Sat Aug 13 01:22:22 2011 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Aug 2011 06:22:22 +0100 Subject: How to print non-printable chars?? References: Message-ID: On Sat, 13 Aug 2011 00:59:42 -0400, Julio Cesar Rodriguez Cruz wrote: > Hi all, > If I open an .exe file in any text editor I get lot of odd chars, > what I want is to know how to output those chars if I have the hexadecimal > code. I found out how to do the reverse process with the quopri module, > > i.e.: >>>> import quopri >>>> quopri.encodestring('??') > '=F1=E8=18' >>>> quopri.decodestring('=F1=E8=18') > '\xf1\xe8\x18' > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '??' print(quopri.decodestring('=F1=E8=18')) or: sys.stdout.write(quopri.decodestring('=F1=E8=18')) If you type an expression into the interactive Python interpreter, the result is converted to a string using repr(); for strings, this converts 8-bit characters to their hexadecimal escape sequences, so that the result only uses ASCII. OTOH, the print statement converts values to strings using str(); for strings, this is an identity operation (i.e. it returns the original string untouched). Similarly, the .write() method of file objects uses str(). From juliocesarrodriguezcruz at gmail.com Sat Aug 13 01:55:16 2011 From: juliocesarrodriguezcruz at gmail.com (Julio Cesar) Date: Fri, 12 Aug 2011 22:55:16 -0700 (PDT) Subject: How to print non-printable chars?? References: Message-ID: On Aug 13, 1:22?am, Nobody wrote: > On Sat, 13 Aug 2011 00:59:42 -0400, Julio Cesar Rodriguez Cruz wrote: > > > Hi all, > > If I open an .exe file in any text editor I get lot of odd chars, > > what I want is to know how to output those chars if I have the hexadecimal > > code. I found out how to do the reverse process with the quopri module, > > > i.e.: > >>>> import quopri > >>>> quopri.encodestring('?? ') > > '=F1=E8=18' > >>>> quopri.decodestring('=F1=E8=18') > > '\xf1\xe8\x18' > > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '?? ' > > ? ? ? ? print(quopri.decodestring('=F1=E8=18')) > or: > ? ? ? ? sys.stdout.write(quopri.decodestring('=F1=E8=18')) > > If you type an expression into the interactive Python interpreter, the > result is converted to a string using repr(); for strings, this converts > 8-bit characters to their hexadecimal escape sequences, so that the result > only uses ASCII. > > OTOH, the print statement converts values to strings using str(); for > strings, this is an identity operation (i.e. it returns the original > string untouched). Similarly, the .write() method of file objects uses str(). It just works!! thanks a lot and also for the explanations ;) Cheers Julio Cesar From 1248283536 at qq.com Sat Aug 13 05:09:55 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sat, 13 Aug 2011 17:09:55 +0800 Subject: thread and process Message-ID: please see my code: import os import threading print threading.currentThread() print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() print threading.currentThread() if ret == 0: print threading.currentThread() else: os.wait() print threading.currentThread() print "i am runing,who am i? ",os.getpid(),threading.currentThread() the output is: <_MainThread(MainThread, started -1216477504)> i am parent 13495 i am here 13495 <_MainThread(MainThread, started -1216477504)> i am here 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> it is so strange that two different processes use one mainthread!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Sat Aug 13 06:01:07 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 13 Aug 2011 03:01:07 -0700 (PDT) Subject: thread and process References: Message-ID: On Aug 13, 11:09 am, "????" <1248283... at qq.com> wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> > it is so strange that two different processes use one mainthread!! You should not mix thread and fork. Some hint : You put your "import threading" before your fork(), then data initialized by the import are the same in the two process then it display the same, this is like a=-1216477504 os.fork() print a second I thing -1216477504 has no meaning, this is not a system thread ID but just an ID generated by python I think they must be unique inside a process but not cross process. Then 2 process can have the same python thread ID. If you have to mix thread and fork try to find some hints from Internet. Something like don't fork a process that already has tread(), or try to keep all your threads inside the same process ... Regards From aspineux at gmail.com Sat Aug 13 06:22:44 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 13 Aug 2011 03:22:44 -0700 (PDT) Subject: generate and send mail with python: tutorial References: <509f6fd7-5054-4210-9ede-4e198c71e0ed@e7g2000vbw.googlegroups.com> <4e452cd6$0$29973$c3e8da3$5496439d@news.astraweb.com> <6b26e9b5-2f47-4e8c-a227-5b328b01ab6a@e35g2000yqc.googlegroups.com> <87pqkaf8dt.fsf@benfinney.id.au> <87fwl6f7my.fsf@benfinney.id.au> Message-ID: <3d847984-d977-4409-8f12-8f2b7510f9bf@s20g2000yqc.googlegroups.com> On Aug 13, 3:00?am, Ben Finney wrote: > Ben Finney writes: > > What is the process if the OP, or someone to whom the OP delegates > > authority, wants to [contribute their work to the Python > > documentation]? > > The answer is partly at : > > ? ? If you?re interested in contributing to Python?s documentation [?] > ? ? Send an e-mail to d... at python.org or open an issue on the tracker. > > One should, before doing so, follow the above document on the > documentation style conventions for Python. I'm using python for long now, and just discovered these HowTo today :- ( I don't thing rewriting these articles into another format will improve the "message". I will not rewrite them. You are free to do it, just keep my name as the original author. I have no other original source than the HTML one you can have on my blog. I appreciate your interest for my work. I think to put all the sources together to create a library. I thing about the name of pyezmail for "python easy mail". Any comment ? Regards > > -- > ?\ ? ? ??Contentment is a pearl of great price, and whosoever procures | > ? `\ ? ? ? ?it at the expense of ten thousand desires makes a wise and | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?happy purchase.? ?J. Balguy | > Ben Finney From pavlovevidence at gmail.com Sat Aug 13 06:52:22 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 13 Aug 2011 03:52:22 -0700 (PDT) Subject: thread and process In-Reply-To: References: Message-ID: On Saturday, August 13, 2011 2:09:55 AM UTC-7, ???? wrote: > please see my code: > import os > import? threading > print? threading.currentThread()? > print "i am parent ",os.getpid() > ret? =? os.fork() > print? "i am here",os.getpid() > print? threading.currentThread() > if? ret? ==? 0: > ???????? print? threading.currentThread() > else: > ??????? os.wait() > ??????? print? threading.currentThread() > ??????? > ??????? > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent? 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i?? 13496 <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i?? 13495 <_MainThread(MainThread, started -1216477504)> > it is so strange that? two? different? processes? use one? mainthread!! They don't use one main thread; it's just that each process's main thread has the same name. Which makes sense: when you fork a process all the data in the process has to remain valid in both parent and child, so any pointers would have to have the same value (and the -1216477504 happens to be the value of that pointer cast to an int). Carl Banks From davea at dejaviewphoto.com Sat Aug 13 08:21:42 2011 From: davea at dejaviewphoto.com (Dave Angel) Date: Sat, 13 Aug 2011 08:21:42 -0400 Subject: thread and process In-Reply-To: References: Message-ID: <4E466C56.4070601@dejaviewphoto.com> On 01/-10/-28163 02:59 PM, ???? wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496<_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495<_MainThread(MainThread, started -1216477504)> > it is so strange that two different processes use one mainthread!! Why would you figure that it's the same thread? You're just looking at the ID of the thread object in each process, and ID's have no promise of being unique between different processes, nor between multiple runs of the same program. In CPython, the id is actually an address, and each process has its own address space. The addresses happen to be the same because the main thread was created before you forked. DaveA From rafalgulinski at gmail.com Sat Aug 13 09:17:16 2011 From: rafalgulinski at gmail.com (rav) Date: Sat, 13 Aug 2011 06:17:16 -0700 (PDT) Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: On Aug 12, 1:35?pm, MRAB wrote: > On 12/08/2011 18:02, kj wrote: > > > > > > > > > > > *Please* forgive me for asking a Java question in a Python forum. > > My only excuse for this no-no is that a Python forum is more likely > > than a Java one to have among its readers those who have had to > > deal with the same problems I'm wrestling with. > > > Due to my job, I have to port some Python code to Java, and write > > tests for the ported code. ?(Yes, I've considered finding myself > > another job, but this is not an option in the immediate future.) > > > What's giving me the hardest time is that the original Python code > > uses a lot of functions with optional arguments (as is natural to > > do in Python). > > > As far as I can tell (admittedly I'm no Java expert, and have not > > programmed in it since 2001), to implement a Java method with n > > optional arguments, one needs at least 2**n method definitions. > > Even if all but one of these definitions are simple wrappers that > > call the one that does all the work, it's still a lot of code to > > wade through, for nothing. > > > That's bad enough, but even worse is writing the unit tests for > > the resulting mountain of fluffCode. ?I find myself writing test > > classes whose constructors also require 2**n definitions, one for > > each form of the function to be tested... > > > I ask myself, how does the journeyman Python programmer cope with > > such nonsense? > > > For the sake of concreteness, consider the following run-of-the-mill > > Python function of 3 arguments (the first argument, xs, is expected > > to be either a float or a sequence of floats; the second and third > > arguments, an int and a float, are optional): > > > ? ? def quant(xs, nlevels=MAXN, xlim=MAXX): > > ? ? ? ? ?if not hasattr(xs, '__iter__'): > > ? ? ? ? ? ? ?return spam((xs,), n, xlim)[0] > > > ? ? ? ? ?if _bad_quant_args(xs, nlevels, xlim): > > ? ? ? ? ? ? ?raise TypeError("invalid arguments") > > > ? ? ? ? ?retval = [] > > ? ? ? ? ?for x in xs: > > ? ? ? ? ? ? ?# ... > > ? ? ? ? ? ? ?# elaborate acrobatics that set y > > ? ? ? ? ? ? ?# ... > > ? ? ? ? ? ? ?retval.append(y) > > > ? ? ? ? ?return retval > > > My Java implementation of it already requires at least 8 method > > definitions, with signatures: > > [snip] > > I would declare: > > ? ? ? short[] quant (float[], int ? ?, float) > ? ? ? short ? quant (Float ?, Integer, Float) > > and see how it goes. > > "float" and "int" should be boxed to "Float" and "Integer" > automatically. > > If the second and third arguments are frequently the default, then I > would also declare: > > ? ? ? short[] quant (float[]) > ? ? ? short ? quant (Float ?) This seems to be a very good solution but I would replace basic types with wrappers short[] quant (float[], Integer, Float) short quant (Float , Integer, Float) When you implement those two methods (where you need to check if Integer, Float are not null) then you can define two more methods: short[] quant (float[]) { return quant (float[], null, null); } short quant (float) { return quant (float, null, null); } That gives you 2 methods for unit testing. From fab at slick.airforce-one.org Sat Aug 13 11:21:01 2011 From: fab at slick.airforce-one.org (fab at slick.airforce-one.org) Date: 13 Aug 2011 15:21:01 GMT Subject: Dialog boxes in curses Message-ID: <4e46965d$0$23647$426a74cc@news.free.fr> Hello. I've googled for hints but I didn't find anything, I hope it's not an RTFM question :^) I want to have dialog boxes (a message with Yes/No/Cancel options, possibly with keyboard accels) in python + curses. Does anyone have a pointer to docs about this? Thanks! -- F. Delente From irmen.NOSPAM at xs4all.nl Sat Aug 13 11:37:50 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 13 Aug 2011 17:37:50 +0200 Subject: Dialog boxes in curses In-Reply-To: <4e46965d$0$23647$426a74cc@news.free.fr> References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> On 13-8-2011 17:21, fab at slick.airforce-one.org wrote: > Hello. > > I've googled for hints but I didn't find anything, I hope it's not an > RTFM question :^) > > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. > > Does anyone have a pointer to docs about this? > > Thanks! > Have you considered using Urwid instead? http://excess.org/urwid/ Irmen From nicholas.cole at gmail.com Sat Aug 13 11:49:48 2011 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sat, 13 Aug 2011 16:49:48 +0100 Subject: Dialog boxes in curses In-Reply-To: <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> References: <4e46965d$0$23647$426a74cc@news.free.fr> <4e469a4f$0$23848$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sat, Aug 13, 2011 at 4:37 PM, Irmen de Jong wrote: > On 13-8-2011 17:21, fab at slick.airforce-one.org wrote: >> Hello. >> >> I've googled for hints but I didn't find anything, I hope it's not an >> RTFM question :^) >> >> I want to have dialog boxes (a message with Yes/No/Cancel options, >> possibly with keyboard accels) in python + curses. >> >> Does anyone have a pointer to docs about this? >> >> Thanks! Or have a look at code.google.com/p/npyscreen Nicholas From k.sahithi2862 at gmail.com Sat Aug 13 12:04:00 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 13 Aug 2011 09:04:00 -0700 (PDT) Subject: ADULT FAVORATE BLOG Message-ID: <99352756-32b7-4daf-94e4-2999f8f1114f@m4g2000pri.googlegroups.com> HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html NAYANTHARA HOT PHOTOS http://southactresstou.blogspot.com/2011/08/nayanthara.html LATEST HOT TAPSEE KISSING STILLS http://southactresstou.blogspot.com/2011/06/tapsee.html KAJAL AGARWAL ROMANTIC STILLS http://southactresstou.blogspot.com/2011/05/kajal-agarwal.html TAMANNA BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/05/tamanna.html ANUSHKA SHETTY HOT SAREE STILLS http://southactresstou.blogspot.com/2011/06/anushka-shetty.html SNEHA RARE PHOTOS http://southactresstou.blogspot.com/2011/05/sneha.html NAMITHA HOT NAVEL SHOW http://southactresstou.blogspot.com/2011/05/namitha.html ILIYANA HOT WALLPAPERS http://southactresstou.blogspot.com/2011/05/iliyana.html PRIYAMANI LATEST SPICY PHOTOS http://southactresstou.blogspot.com/2011/05/priyamani.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT SEXY PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From thorsten at thorstenkampe.de Sat Aug 13 13:43:13 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sat, 13 Aug 2011 19:43:13 +0200 Subject: Dialog boxes in curses References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: * fab at slick.airforce-one.org (13 Aug 2011 15:21:01 GMT) > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. Use Python Dialog[1] which is basically a wrapper for dialog boxes around ncurses. Thorsten [1] http://pythondialog.sourceforge.net/ From fab at slick.airforce-one.org Sat Aug 13 14:38:57 2011 From: fab at slick.airforce-one.org (fab at slick.airforce-one.org) Date: 13 Aug 2011 18:38:57 GMT Subject: Dialog boxes in curses References: <4e46965d$0$23647$426a74cc@news.free.fr> Message-ID: <4e46c4c1$0$4541$426a34cc@news.free.fr> Thanks all for your suggestions, I'll look into them. See you. -- F. Delente From tdsimpson at gmail.com Sat Aug 13 15:14:14 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 12:14:14 -0700 (PDT) Subject: How do I convert String into Date object Message-ID: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Is this the correct way to convert a String into a Date? I only have dates and no time. import time, datetime oDate = time.strptime('07/27/2011', '%m/%d/%Y') print oDate Thanks, From tdsimpson at gmail.com Sat Aug 13 15:26:25 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 12:26:25 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> I have file of records delimited by spaces. I need to import the date string and convert them into date datatypes. '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' I just discovered that my oDate is not an object, but a structure and not a date datatype. I'm stumped. Is there a way to convert a string into a date datatype for comparisons, equality, etc? Thanks, On Aug 13, 3:14?pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, From nulla.epistola at web.de Sat Aug 13 16:05:33 2011 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 13 Aug 2011 22:05:33 +0200 Subject: How do I convert String into Date object In-Reply-To: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: Am 13.08.2011 21:26, schrieb MrPink: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > There is. Only not in one step, if you want a date and not a datetime instance: >>> import datetime >>> oDateTime = datetime.datetime.strptime('07/27/2011', '%m/%d/%Y') >>> oDateTime datetime.datetime(2011, 7, 27, 0, 0) >>> oDate = oDateTime.date() >>> oDate datetime.date(2011, 7, 27) >>> HTH Sibylle From clp2 at rebertia.com Sat Aug 13 16:09:13 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Aug 2011 13:09:13 -0700 Subject: How do I convert String into Date object In-Reply-To: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: On Sat, Aug 13, 2011 at 12:14 PM, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate from datetime import datetime the_date = datetime.strptime('07/27/2011', '%m/%d/%Y').date() Cheers, Chris From rafadurancastaneda at gmail.com Sat Aug 13 16:11:00 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sat, 13 Aug 2011 22:11:00 +0200 Subject: How do I convert String into Date object In-Reply-To: <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: <4E46DA54.4050504@gmail.com> You can use datetime objects: >>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") >>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") >>> dt1 == dt2 False >>> dt1 > dt2 False >>> dt1 < dt2 True >>> dt1 - dt2 datetime.timedelta(-1) On 13/08/11 21:26, MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > > Thanks, > > On Aug 13, 3:14 pm, MrPink wrote: >> Is this the correct way to convert a String into a Date? >> I only have dates and no time. >> >> import time, datetime >> >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') >> print oDate >> >> Thanks, From tdsimpson at gmail.com Sat Aug 13 16:25:07 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 13:25:07 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: BTW, here is the Python version I'm using. Will this make a difference with the solutions you guys provided? Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Also, what editor do you guys use? There are so many to chose from. On Aug 13, 4:11?pm, Rafael Dur?n Casta?eda wrote: > You can use datetime objects: > > ?>>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") > ?>>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") > ?>>> dt1 == dt2 > False > ?>>> dt1 > dt2 > False > ?>>> dt1 < dt2 > True > ?>>> dt1 - dt2 > datetime.timedelta(-1) > > On 13/08/11 21:26, MrPink wrote: > > > > > > > > > I have file of records delimited by spaces. > > I need to import the date string and convert them into date datatypes. > > > '07/27/2011' 'Event 1 Description' > > '07/28/2011' 'Event 2 Description' > > '07/29/2011' 'Event 3 Description' > > > I just discovered that my oDate is not an object, but a structure and > > not a date datatype. > > I'm stumped. ?Is there a way to convert a string into a date datatype > > for comparisons, equality, etc? > > > Thanks, > > > On Aug 13, 3:14 pm, MrPink ?wrote: > >> Is this the correct way to convert a String into a Date? > >> I only have dates and no time. > > >> import time, datetime > > >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') > >> print oDate > > >> Thanks, From __peter__ at web.de Sat Aug 13 16:29:35 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Aug 2011 22:29:35 +0200 Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com> Message-ID: MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > > Thanks, > > On Aug 13, 3:14 pm, MrPink wrote: >> Is this the correct way to convert a String into a Date? >> I only have dates and no time. >> >> import time, datetime That looks like a fifty-percent chance to try the "wrong" module ;) >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') >> print oDate >>> import datetime as dt >>> d = dt.date.strptime("07/27/2011", "%m/%d/%Y") Traceback (most recent call last): File "", line 1, in AttributeError: type object 'datetime.date' has no attribute 'strptime' So you cannot construct a date from a date string either. One more time: >>> d = dt.datetime.strptime("07/27/2011", "%m/%d/%Y") >>> d datetime.datetime(2011, 7, 27, 0, 0) >>> d.date() datetime.date(2011, 7, 27) $ cat csv_dates.csv '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' $ cat csv_dates.py import datetime import csv def rows(instream): for row in csv.reader(instream, delimiter=" ", quotechar="'"): row[0] = datetime.datetime.strptime(row[0], '%m/%d/%Y').date() yield row if __name__ == "__main__": import sys filename = sys.argv[1] with open(filename, "rb") as instream: for row in rows(instream): print row $ python csv_dates.py csv_dates.csv [datetime.date(2011, 7, 27), 'Event 1 Description'] [datetime.date(2011, 7, 28), 'Event 2 Description'] [datetime.date(2011, 7, 29), 'Event 3 Description'] From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 13 17:39:26 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 13 Aug 2011 21:39:26 +0000 (UTC) Subject: Relative import from script with same name as package Message-ID: I'm using Python 2.6.5. I have a directory structure like this: thetest/ __init__.py thetest.py theother.py __init__.py is an empty file. theother.py contains a function foo(). The package is accessible from sys.path, so that if I open the interpreter and do "import thetest" or "from thetest import thetest" or "import thetest.thetest", it works fine. Inside thetest.py I have code like this: ### from __future__ import absolute_import if __name__ == "__main__" and __package__ is None: import thetest __package__ = "thetest" from .theother import foo ### Note that I need the "import thetest" line to avoid a "parent module not loaded" error, as described here: http://stackoverflow.com/questions/2943847/nightmare-with-relative- imports-how-does-pep-366-work If I run foo.py directly, I receive a traceback like this: Traceback (most recent call last): File "C:\...\thetest\thetest.py", line 4, in import thetest File "C:\...\thetest\thetest.py", line 11, in from .theother import foo ValueError: Attempted relative import in non-package It appears that Python is reading "import thetest" as importing thetest.py (the same file that is currently being run). When it tries to run that file a second time, the relative import fails. But why? That __future__ import is supposed to make absolute imports the default, so why is "import thetest" importing thetest.py instead of the package called thetest? The absolute import should make it look in sys.path first and not try to import from the script directory, right? If I change the outer directory name and change the code in thetest.py to match, it works fine. But I shouldn't have to do this. How can I get relative imports to work correctly when running a script whose filename is the same as that of the directory (and thus the package) in which it resides? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 13 19:55:38 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 13 Aug 2011 23:55:38 +0000 (UTC) Subject: Relative import from script with same name as package References: Message-ID: OKB (not okblacke) wrote: > But why? That __future__ import is supposed to make > absolute > imports the default, so why is "import thetest" importing > thetest.py instead of the package called thetest? The absolute > import should make it look in sys.path first and not try to import > from the script directory, right? > > If I change the outer directory name and change the code > in > thetest.py to match, it works fine. But I shouldn't have to do > this. How can I get relative imports to work correctly when > running a script whose filename is the same as that of the > directory (and thus the package) in which it resides? After a bit more googling I discovered the answer here: http://stackoverflow.com/questions/1959188/absolute-import-failing-in- subpackage-that-shadows-a-stdlib-package-name The deal is that sys.path by default has the empty string as the first element, which tells Python to look first in the directory of the script being executed. This is unfortunate, but can worked around this way: import sys sys.path = sys.path[1:] + [''] (That is, move the current directory to the end of the search path instead of the beginning.) -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From rosuav at gmail.com Sat Aug 13 20:07:40 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 01:07:40 +0100 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 12:55 AM, OKB (not okblacke) wrote: > sys.path = sys.path[1:] + [''] > > (That is, move the current directory to the end of the search path > instead of the beginning.) > Or, equivalently: sys.path.append(sys.path.pop(0)) ChrisA From roy at panix.com Sat Aug 13 20:49:06 2011 From: roy at panix.com (Roy Smith) Date: Sat, 13 Aug 2011 20:49:06 -0400 Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: In article <83822ecb-3643-42c6-a2bf-0187c07d351d at a10g2000yqn.googlegroups.com>, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. You have already received a number of good replies, but let me throw out one more idea. If you ever need to do something with dates and times which the standard datetime module can't handle, take a look at the excellent dateutil module by Gustavo Niemeyer (http://labix.org/python-dateutil). From rantingrick at gmail.com Sat Aug 13 21:25:56 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:25:56 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <4e45a345$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 12, 5:03?pm, Steven D'Aprano wrote: > Responding to Rick's standard {EDIT} posts > is like wrestling with a {EDIT} > [...] > Save yourself a lot of aggravation and kill-file him now. Kindly allow Walter E. Kurtz to shine some light on this situation: """ Pig after pig, cow after cow, village after village, army after army. And they call me an assassin. What do you call it when the assassins accuse the assassin? They lie.. they lie and we have to be merciful for those who lie. Those nabobs. I hate them. How I hate them...""" From rantingrick at gmail.com Sat Aug 13 21:50:55 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:50:55 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6696bd00-802c-4815-a4f0-b0c83a1babf0@l7g2000vbz.googlegroups.com> On Aug 12, 7:39?pm, Seebs wrote: > Well, that's the thing. > > In a case like: > > ? ? ? ? if foo: > ? ? ? ? ? ? ? ? if bar: > ? ? ? ? ? ? ? ? ? ? ? ? blah > ? ? ? ? blah > > I notice that *NOTHING* lines up with "if bar:". ?And that affects me > about the way unmatched brackets do. For me, i believe it was a grave mistake to allow "user defined indention" within a python module. Not only that, but allowing indentation to be inconsistent (within the same module) not only worse, it's insane! I could have "slightly" understood giving people a choice of how many indents to use however i cannot fathom the idiocy of allowing inconsistent indentation within the same module! Although GvR is no doubt a brilliant mind he keeps making the same mistakes over and over again in the name of muti-stylism. ?Ay, caramba! Not that i find it *impossible* to read inconsistent indentation mind you, but that i find it blasphemous to the name of consistency. Programming languages MUST be consistent. Python should allow one and only one obvious way to indent a block; whether it be by a single tab char or by four spaces i don't care! But for crikey's sake pick one of them and stick with it!!! From rantingrick at gmail.com Sat Aug 13 21:59:04 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 18:59:04 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <88b5a66f-3c8b-427e-b321-cde6d93b0483@a4g2000yqg.googlegroups.com> On Aug 12, 7:39?pm, Seebs wrote: > Consider the hypothetical array syntax: > > ? ? ? ? a = [ > ? ? ? ? ? ? 1, > ? ? ? ? ? ? 2 > ? ? ? ? b = [ > ? ? ? ? ? ? 3, > ? ? ? ? ? ? 4 > > This *bugs* me. ?It's perfectly legible, and if you define it that way, it's > unambiguous and everything, but... It bugs me. ?I want beginnings to have > an actual corresponding end. It "almost" seems as if you have a valid point here until you consider that conditionals and blocks are ridged structures that must be defined under a strict set of syntactical rules with keywords and indentation. Whereas the list, dict, set, and tuple absolutely MUST have an explicit beginning AND an explicit end due to their free-form nature. You could create some strict rules for defining "X-literals" and remove any need for start and end tags however i see no need to do so. From rantingrick at gmail.com Sat Aug 13 22:07:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 19:07:39 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 12, 7:39?pm, Seebs wrote: > I was overjoyed when I saw that Ruby would let me write 1_048_576. I'll have to admit that Ruby has a few very interesting ideas, this being one of them. We all know how impossible it can be to eyeball parse a very long number like this. Having the interpretor ignore underscores in a number was very wise indeed! However i really hate the fact that Ruby FORCES you to use OOP. I LOVE OOP, however there are times when you just don't need that level of machinery to solve a problem. A good example is when scripting an API. Most times all you need is a few module level procedures and some simple logic. Try that with Ruby, then try that with Python, you'll be switching to Python in no time! PS: And before any Matz lovers start complaining: Yes, i know you can do procedural programming with ruby HOWEVER it suffers many pitfall due to (1) Ruby's scoping issues and (2) Ruby's explicit module declaration (which is more indirect than the first). From rantingrick at gmail.com Sat Aug 13 22:18:29 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 19:18:29 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <8762eb2d-5578-4050-a762-6bf8b4dd1b3b@c29g2000yqd.googlegroups.com> On Aug 12, 4:06?pm, Seebs wrote: > On 2011-08-12, Chris Angelico wrote: > > > Why is left-to-right inherently more logical than > > multiplication-before-addition? > > I'd say it's certainly "more Pythonic in a vacuum". > Multiplication-before-addition, and all the related rules, require > you to know a lot of special rules which are not visible in the > code, and many of which have no real logical basis. ?Left-to-right > is, if nothing else, the way the majority of us read. > > The problem is that since everyone's used precedence before, not using > it violates the principle of least astonishment. And repeatedly propagating a foolish consistency is well, FOOLISH! This problem invades every aspect of technology. Who was the idiot that decided it was okay to close SOME html tag and NOT close others? Since HTML is made to be read by machines why the hell would someone knowingly induce disorder? Which then leads to needing more logic to parse? But even more insane is why HTML has been allowed to be so disorderly for so long. Where is the need to be consistent? I tell you how to solve this, you solve it with plagues. Plagues of syntax errors will teach the unrighteous the err of their ways. From gordon at panix.com Sat Aug 13 22:20:30 2011 From: gordon at panix.com (John Gordon) Date: Sun, 14 Aug 2011 02:20:30 +0000 (UTC) Subject: Data issues with Django and Apache Message-ID: I'm devleoping a website using the Django framework along with Apache, and I'm seeing some odd data issues. During the course of navigating through the website content, a user will cause the creation of some data records with a limited lifespan. These data records have a create_dt field which is automatically set to the time that they were created, and an expire_dt field which is equal to create_dt plus ten minutes. The problem is that I get conflicting results as to whether these temporary records have reached their expiration date, depending if I search for them via an Apache web call or if I do the search locally from a python shell. And to make it weirder, the conflicts go away if I stop and restart the Apache server, although any new records created after this point will still exhibit the issue. Are there any known "gotchas" when using Django with Apache? It almost seems like Apache is maintaining its own persistent session or something, and restarting Apache causes the session to be flushed. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tdsimpson at gmail.com Sun Aug 14 01:44:32 2011 From: tdsimpson at gmail.com (MrPink) Date: Sat, 13 Aug 2011 22:44:32 -0700 (PDT) Subject: How do I convert String into Date object References: <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> Message-ID: I found this solution. Python: Convert String Date to Date Object http://slaptijack.com/programming/python-convert-string-date-to-date-object/ On Aug 13, 3:14?pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, From rantingrick at gmail.com Sun Aug 14 01:57:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Aug 2011 22:57:46 -0700 (PDT) Subject: Ten rules to becoming a Python community member. Message-ID: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Follow these simply rules to become an accepted member of the Python community. ------------------------------------------------------------ 1. Bash rantingrick and Xah Lee every chance you get. 2. Bash people who bash rick or xah because their basing made rick's or xah's words pass through your spam filter. 3. Post links to xkcd as often as you can. Don't worry if they have been posted a thousand times, just post them because it equals "geek cool points". 4. When the chance presents itself, make snide comments about lisp and perl; but NEVER about Ruby! (even though Ruby is Perl's micro minion!). 5. Use fancy words like "tail recursion", just because you read about it on Guido's blog once (even if you have no idea what that means)! 6. Engage in heated and pointless discussions as to whether Python is "pass-by-reference" or "pass-by-value" even if you have no idea what the hell you are talking about. 7. Play devils advocate often e.g., If someone hates Tkinter: then argue how great Tkinter is regardless of how much you actually care, use, or know about the module. Likewise if someone likes Tkinter: then argue how terrible Tkinter is and how Python does not need any GUI library; again, regardless of how much you actually care, use, or know about the module. 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." more than ten times in a single post, you will get an invite to Guido's next birthday party; where you'll be forced to do shots whist walking the balcony railing wearing wooden shoes! 9. Never use the word "previously" or the phrase "in the past"; just dumb it down with "used to". 10. Finally, if you get caught using the word "that" incredibly excessively, just hope that nobody notices that that that you are really GvR in disguise. From steve+comp.lang.python at pearwood.info Sun Aug 14 03:10:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 14 Aug 2011 17:10:36 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I guess... The parser is explicitly pushing those tokens, but I can't > *SEE* those tokens. If I am looking at the end of a really long > thing, and I see: > > blah > blah > > I only know what's happening if I have absolute confidence that the > indentation is always by the same amount, etectera. I believe this is a dubious argument. With only two lines of code in isolation, understanding the indentation changes is the least of your worries. Adding block delimiters doesn't give you any significant help -- ESPECIALLY if the block delimiters don't align with the indentation! blah } blah } In isolation, you don't even know whether the above is syntactically valid, since you have no way of knowing that either end brace is closing an open brace or not. "Who would write such a horrible mis-aligned piece of code?" Good question. If you're going to have style-guides that prohibit writing code like the above, then what exactly do the braces give you? Yes, yes, if you paste the code into a web forum the indentation may disappear, and if your hard drive controller is faulty it may randomly overwrite blocks with data belonging to other files. We all agree that environments that destroy data are Bad. >> Yet another reason to consider brace languages harmful: they spoil the >> user's intuitive grasp of intuition as grouping. > > I assume you mean "indentation as grouping". Yes, sorry about that. > I'm... not sold on this. It's not that I don't see indentation as a kind > of grouping. It's just that I really, really, want groups to have ends. > > Consider the hypothetical array syntax: > > ????????a = [ > ???????? ? ?1, > ???????? ? ?2 > ????????b = [ > ???????? ? ?3, > ???????? ? ?4 > > This *bugs* me. It's perfectly legible, and if you define it that way, > it's > unambiguous and everything, but... It bugs me. I want beginnings to have > an actual corresponding end. Do you get worried by books if the last page doesn't include the phrase "The End"? These days, many movies include an extra clip following the credits. When the clip finishes, and the screen goes dark, how long do you sit waiting before you accept that the movie is over? *wink* The above example bugs me too, because it is too close to what I'm used to in Python. I see an open bracket, I wait for a close bracket. Perhaps this would be better: a = array 1, 2, b = array 3, 4, Not so bad now, I betcha. And you can nest arrays: c = array 5, 6, array 7, 8, 9, Now, I wouldn't actually recommend such a syntax for a programming language. (Maybe for a config file format?) It's too big and awkward for array literals in an expression. You can partly fix that by making the whitespace optional, allowing an array to be written on one line: a = array 1, 2 b = array 3, 4 but that screws up the ability to nest arrays. Also, what happens here? spam(a, b, array 5, 6) That's ambiguous -- does spam have three arguments or four? Again, easy enough to fix: spam(a; b; array 5; 6) # four args but you still can't nest arrays. This potential syntax doesn't feel like a unified whole, but like a bunch of unrelated fixes for problems. Sometimes a literal START and END delimiter is the right answer. Python's use of indentation to delimit blocks doesn't feel like that. Unlike arrays, you can't use blocks in an expression, and I think that's the factor which makes all the difference. Ruby folks may call the lack of block expressions a problem with Python, but even if they're right, I don't think it's a *big* problem. Either way, given the restriction that blocks are statements, not expressions, the lack of an overt block markers is not a problem for code (with the proviso that a rogue editor doesn't go making arbitrary changes to your source code). -- Steven From bahamutzero8825 at gmail.com Sun Aug 14 03:54:44 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 14 Aug 2011 02:54:44 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <4E477F44.1090107@gmail.com> On 2011.08.14 12:57 AM, rantingrick wrote: > Follow these simply rules to become an accepted member of the Python > community. Sounds good. You should consider submitting this as a PEP. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From usenet-nospam at seebs.net Sun Aug 14 04:07:03 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 08:07:03 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Steven D'Aprano wrote: > Seebs wrote: >> I guess... The parser is explicitly pushing those tokens, but I can't >> *SEE* those tokens. If I am looking at the end of a really long >> thing, and I see: >> >> blah >> blah >> >> I only know what's happening if I have absolute confidence that the >> indentation is always by the same amount, etectera. > I believe this is a dubious argument. With only two lines of code in > isolation, understanding the indentation changes is the least of your > worries. Adding block delimiters doesn't give you any significant help -- > ESPECIALLY if the block delimiters don't align with the indentation! > blah > } > blah > } Interesting. I am sort of getting to an insight into this, which I am not sure I can articulate. FWIW, I've had to debug C (well, C++) much worse than that (... long story, but rest assured, the lulz justified the effort of reading the transcendantly awful code). I could still do it. :) > In isolation, you don't even know whether the above is syntactically valid, > since you have no way of knowing that either end brace is closing an open > brace or not. Ahh, but the computer can tell me that. I don't have to see it. > "Who would write such a horrible mis-aligned piece of code?" Good question. > If you're going to have style-guides that prohibit writing code like the > above, then what exactly do the braces give you? I think what they give me is... basically a parity bit. It's easy for people to screw up code, such that the code written does not reflect intent. Braces give me a likely red flag -- if they are screwed up, I know that this is a good palce to start looking. If they're not, then all they're costing me is a little vertical space. > Yes, yes, if you paste the code into a web forum the indentation may > disappear, and if your hard drive controller is faulty it may randomly > overwrite blocks with data belonging to other files. We all agree that > environments that destroy data are Bad. "Destroy data" is a sort of fungible concept. I was reading a comic book recently and it contained a URL for a poem which had been parodied. The URL had been hand-lettered... in block capitals. The actual URL had exactly one upper case letter in it. Whoops. In general, I don't think all data-loss is identical in severity. Outside of Python and Makefiles, I don't use anything where whitespace damage of the sort of "losing or changing leading spaces" is usually significant, so I *normally* regard it as a trivial change. > Do you get worried by books if the last page doesn't include the phrase "The > End"? These days, many movies include an extra clip following the credits. > When the clip finishes, and the screen goes dark, how long do you sit > waiting before you accept that the movie is over? > *wink* It's an actual thing I have been bitten by, especially because I often really enjoy those clips, and I've seen a movie that had two. > The above example bugs me too, because it is too close to what I'm used to > in Python. I see an open bracket, I wait for a close bracket. Perhaps this > would be better: > a = array > 1, > 2, > b = array > 3, > 4, > Not so bad now, I betcha. Interesting! For me this triggers the same "WHERE IS THE END MARKER???" reflex. These bug me like unmatched brackets. > but you still can't nest arrays. This potential syntax doesn't feel like a > unified whole, but like a bunch of unrelated fixes for problems. Sometimes > a literal START and END delimiter is the right answer. I think so. > Python's use of indentation to delimit blocks doesn't feel like that. Unlike > arrays, you can't use blocks in an expression, and I think that's the > factor which makes all the difference. Ruby folks may call the lack of > block expressions a problem with Python, but even if they're right, I don't > think it's a *big* problem. I actually really *like* that Ruby and Lua let pretty much everything just be an expression. I was utterly dumbfounded when I found out that "print" in Python is a kind of statement, not a function or something comparable. (This seems to have changed recentlyish.) > Either way, given the restriction that blocks > are statements, not expressions, the lack of an overt block markers is not > a problem for code (with the proviso that a rogue editor doesn't go making > arbitrary changes to your source code). Yeah. I suspect that if I'd never used something with braces, I might not mind as much, but the kinds of errors I've had would probably still be issues. Say I try to indent or outdent something and I grab the wrong set of lines. It's certainly possible for this to result in valid code... And I have no cue as to what happened. Even if I get a warning, I can't necessarily tell what happened. To some extent, I think I like braces for the same reason I like to use ECC memory whenever hardware supports it, and I prefer hardware that supports it. Yes, they're only really useful to me when Something Goes Wrong (or to accommodate my fussy brain), but something goes wrong often enough that I derive a lot of benefit from that. Refactoring C or Ruby is easy for me. Refactoring Python is hard for me. I really do rely on visible markers to sanity-check the boundaries of what I'm indenting or outdenting. If I do something in my editor and end up with: foo.each do |bar| bar.do_a_thing do_something_with(bar) end next_thing something else I know immediately that it's wrong. If I do something in my editor and end up with: if foo: bar.do_a_thing do_something_with(bar) next_thing something else I can't immediately see that I hit the wrong number key when telling the editor how many lines to adjust. Typos happen. I rely heavily on things that let me catch them in as many ways as possible. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 04:07:04 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 08:07:04 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On 2011-08-14, rantingrick wrote: > Follow these simply rules to become an accepted member of the Python > community. > 1. Bash rantingrick and Xah Lee every chance you get. ... If I'd known you were in the same category as him, I wouldn't have needed to wait until now to know to plonk you. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Sun Aug 14 04:34:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 09:34:26 +0100 Subject: allow line break at operators In-Reply-To: <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano wrote: > Do you get worried by books if the last page doesn't include the phrase "The > End"? These days, many movies include an extra clip following the credits. > When the clip finishes, and the screen goes dark, how long do you sit > waiting before you accept that the movie is over? > > *wink* > You wait for the house lights to come up. That's your ending signal. As is often said in live theatre: "House lights, warmers, thank you gentlemen, going off cans!" It still has an end marker. On Sun, Aug 14, 2011 at 9:07 AM, Seebs wrote: > I actually really *like* that Ruby and Lua let pretty much everything just > be an expression. I was utterly dumbfounded when I found out that "print" > in Python is a kind of statement, not a function or something comparable. > (This seems to have changed recentlyish.) Yes. Not everything's an expression; a block of code is not an expression that returns a code object, and variable assignment is a statement. Some day, I'd like to play around with a language where everything's an expression and yet it doesn't look like LISP - just for the fun of it. It probably won't be any more useful for real world coding, but it'd be fun to tinker with. ChrisA From jabba.laci at gmail.com Sun Aug 14 04:41:12 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 14 Aug 2011 10:41:12 +0200 Subject: monitor mouse coordinates in real-time Message-ID: Hi, I wrote a simple GUI with pygtk to monitor mouse coordinates in real-time. It works but when I close the application, the thread doesn't stop and I can't figure out how to terminate it. Here is the current source: https://gist.github.com/1144708 (83 lines). Could you please help me out how to close the application correctly? Thanks, Laszlo From clp2 at rebertia.com Sun Aug 14 04:44:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 01:44:05 -0700 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 1:34 AM, Chris Angelico wrote: > Yes. Not everything's an expression; a block of code is not an > expression that returns a code object, and variable assignment is a > statement. Some day, I'd like to play around with a language where > everything's an expression and yet it doesn't look like LISP - just > for the fun of it. It probably won't be any more useful for real world > coding, but it'd be fun to tinker with. I've heard that Dylan is supposedly Lisp, sans parens. http://en.wikipedia.org/wiki/Dylan_(programming_language) Cheers, Chris From ben+python at benfinney.id.au Sun Aug 14 05:25:39 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Aug 2011 19:25:39 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9ke44s.fsf@benfinney.id.au> Seebs writes: > I was utterly dumbfounded when I found out that "print" in Python is a > kind of statement, not a function or something comparable. (This seems > to have changed recentlyish.) It has long been recognised as a wart, but it required waiting for an opportunity for breaking backward compatibility (the Python 2 ? 3 transition) to fix it. If you can't yet switch to Python 3, you can explicitly ask for ?print? as a function in Python 2.6 or later. More at . -- \ ?The generation of random numbers is too important to be left | `\ to chance.? ?Robert R. Coveyou | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Aug 14 05:27:55 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Aug 2011 19:27:55 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87pqk8e410.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano > wrote: > > Do you get worried by books if the last page doesn't include the > > phrase "The End"? These days, many movies include an extra clip > > following the credits. When the clip finishes, and the screen goes > > dark, how long do you sit waiting before you accept that the movie > > is over? > You wait for the house lights to come up. That's your ending signal. You mean people still watch movies in theatres? The house lights need to be controlled by someone who knows when the movie's end signal should be sent. What is our ending signal if we're watching it from media in our home, and no-one in the house knows when the movie ends? -- \ ?The best way to get information on Usenet is not to ask a | `\ question, but to post the wrong information.? ?Aahz | _o__) | Ben Finney From tlikonen at iki.fi Sun Aug 14 05:46:50 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 14 Aug 2011 12:46:50 +0300 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87obzstjed.fsf@mithlond.arda> * 2011-08-14T09:34:26+01:00 * Chris Angelico wrote: > Some day, I'd like to play around with a language where everything's > an expression and yet it doesn't look like LISP - just for the fun of > it. It probably won't be any more useful for real world coding, but > it'd be fun to tinker with. Of course it's a useful feature. Basically you can put any Lisp code in the world in the place of a Lisp expression. (setf variable (handler-case (some-code) (foo-error () "value 1") (bar-error () "value 2"))) is something like variable = try: return some_code() except FooError: return "value 1" except BarError: return "value 2" Sure, it's not a necessary feature. All we need is the machine language, but other than that there are differences in how languages let programmers express themselves. The above example emphasizes that "'variable' is being assigned". The "how" part gets less weight. If we put the assignment inside the handler-case or try-except forms we get the same result technically but the variable assignment becomes more hidden and is repeated, possibly several times. I understand that Python philosophy does not value freedom of expression that much. It values a general Pythonic rule which must obeyed and is called "readability". Other languages give too little or too much freedom. :-) From oktaysafak at superonline.com Sun Aug 14 05:57:06 2011 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Sun, 14 Aug 2011 12:57:06 +0300 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: <4E479BF2.4040205@superonline.com> 14.08.2011 00:39, OKB (not okblacke) yazm??: > I'm using Python 2.6.5. I have a directory structure like this: > > thetest/ > __init__.py > thetest.py > theother.py > > __init__.py is an empty file. theother.py contains a function foo(). > The package is accessible from sys.path, so that if I open the > interpreter and do "import thetest" or "from thetest import thetest" or > "import thetest.thetest", it works fine. It should. > > Inside thetest.py I have code like this: > > ### > from __future__ import absolute_import > > if __name__ == "__main__" and __package__ is None: > import thetest > __package__ = "thetest" > > from .theother import foo > ### > ... > > If I run foo.py directly, I receive a traceback like this: > Wait! What's foo.py? I guess you mean thetest.py as you say "(the same file that is currently being run)" below. > Traceback (most recent call last): > File "C:\...\thetest\thetest.py", line 4, in > import thetest > File "C:\...\thetest\thetest.py", line 11, in > from .theother import foo > ValueError: Attempted relative import in non-package > > It appears that Python is reading "import thetest" as importing > thetest.py (the same file that is currently being run). When it tries > to run that file a second time, the relative import fails. > No, there is no such thing happening. Read the error message more carefully: the error happens when your code reaches the line "from .theother import foo", and it fails because you are trying to execute an "explicit" relative import statement (with leading dot notation) as introduced by PEP 328. What you see is perfectly expected behaviour as explained in detail in the PEP because the python interpreter can only make sense of that statement if that code is *imported* for use by code that resides *outside* the package. That error message is what you see when you try to *run* a package member module which uses explicit relative imports. Let me try to explain a bit further: You say that your package is accessible from sys.path. So let's say you fire up your interpreter and type import thetest.thetest Here the interpreter first imports the *package* thetest and then the module *thetest.py*, therefore it knows that the module is a member of the package. And when executing the code in the module thetest.py, it can make sense of the leading dot in "import .theother", it can see that the leading dot means the packege thetest and find the right module inside that package. But when you run thetest.py directly, the interpreter has no idea what the leading dot means because it has not imported any package beforehand. So it complains about that. > But why? That __future__ import is supposed to make absolute > imports the default, so why is "import thetest" importing thetest.py > instead of the package called thetest? This is not what is happening. > The absolute import should make > it look in sys.path first and not try to import from the script > directory, right? As I explained above, that's not the error but I think this sentence shows your misunderstanding of this relative imports issue. Never mind, I found the documentation very confusing at first and took me a great deal of effort to finally "get it". Let me share my "distilled wisdom" about this: - First of all, never perform your experiments about relative/absolute imports using IDLE! I guess IDLE has its own path manipulation that doesn't do *the right thing*. - "Absolute import" means importing from sys.path only. - "Relative import" means a "package member" module importing another "package member", using a not fully qualified name (i.e X.Y.a importing X.Y.b as import b, instead of using import X.Y.b). When Python saw (before PEP 328) "import b" or "from b import ..." *in a package member*, it first imported the local b if available. (This business of a package member importing another package member is called relative import, only) Since this had the same notation (syntax) with other (non package member) imports, intra-package imports were considered "ambiguous" when the module to be imported had the same name with a module reachable from sys.path: it was not immediately clear which one was meant for untrained eyes. Also, it had the potential of shadowing a stdlib module: in that case no clean method of getting at the stdlib module was available. - PEP 328 is about giving "relative imports" a new syntax so that this ambiguity no longer exists and the possibility of shadowing a stdlib module is removed altogether. The new syntax is called "*explicit* relative imports". The former method can thus be called "implicit relative imports" or "ambiguous relative imports" - BIG SOURCE OF CONFUSION: Relative imports (both implicit and explicit) is all about imports *inside* packages. When you have 2 scripts app.py and string.py sitting in a *non-package* folder (they are called top-level modules), that folder is always the first entry in sys.path when you run either of those modules directly, so "import string" in app.py will always import the string.py in that folder, not the stdlib one. (But not when you try with IDLE!) In this case, if you really want the standard module, you must manipulate sys.path before your import statement (or change the name of your local string.py). THE PEP (328) HAS NO EFFECT IN THAT CASE! - So, "relative imports" is not a concept introduced by PEP 328, it means "importing a package member from another member of that package" and it existed well before PEP 328. But its syntax was ambiguous so it was clarified by PEP 328 by giving it a special syntax (the leading dot notation). But that change introduced many small gotchas, including the one you are seeing: you can't directly run a package member module if you have used this new syntax (leading dot notation) in it. It works fine only when you import the package members for use by a module outside of that package. This of course brings difficulties with testing but it is another story. I think you will now find it much easier to get what PEP 328 is all about. Oktay From ethan at stoneleaf.us Sun Aug 14 06:51:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 14 Aug 2011 03:51:52 -0700 Subject: allow line break at operators In-Reply-To: <87pqk8e410.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87pqk8e410.fsf@benfinney.id.au> Message-ID: <4E47A8C8.4090602@stoneleaf.us> Ben Finney wrote: > Chris Angelico writes: > >> On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano >> wrote: > >>> Do you get worried by books if the last page doesn't include the >>> phrase "The End"? These days, many movies include an extra clip >>> following the credits. When the clip finishes, and the screen goes >>> dark, how long do you sit waiting before you accept that the movie >>> is over? > >> You wait for the house lights to come up. That's your ending signal. > > You mean people still watch movies in theatres? Yup! Not often, but it's fun once in a while. > The house lights need to be controlled by someone who knows when the > movie's end signal should be sent. What is our ending signal if we're > watching it from media in our home, and no-one in the house knows when > the movie ends? If it's a tape, it'll stop, or start rewinding; if it's a DVD it'll go back to the open page. :) ~Ethan~ From no at nowhere.net.no Sun Aug 14 06:54:54 2011 From: no at nowhere.net.no (TheSaint) Date: Sun, 14 Aug 2011 18:54:54 +0800 Subject: indentation References: Message-ID: Amit Jaluf wrote: > is it necessary indentation in python ? > Try without and report it From alister.ware at ntlworld.com Sun Aug 14 06:58:25 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Sun, 14 Aug 2011 10:58:25 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Sun, 14 Aug 2011 02:54:44 -0500, Andrew Berg wrote: > On 2011.08.14 12:57 AM, rantingrick wrote: >> Follow these simply rules to become an accepted member of the Python >> community. > Sounds good. You should consider submitting this as a PEP. That would mark the first constructive action from rantingnick ever Surely that would mark the end of the sentient universe? -- The deafening silence taught me not to ask a bunch of geeks for advice from their girlfriends From no at nowhere.net.no Sun Aug 14 07:00:05 2011 From: no at nowhere.net.no (TheSaint) Date: Sun, 14 Aug 2011 19:00:05 +0800 Subject: monitor mouse coordinates in real-time References: Message-ID: Jabba Laci wrote: > Could you please help me out how to close the application correctly? > I think you should put a flag into the code, which the parent might modify it, so it will tell the child process to quit. Then the flag should need to be read periodically to know whether is time to quit. From rosuav at gmail.com Sun Aug 14 07:59:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 12:59:55 +0100 Subject: allow line break at operators In-Reply-To: <87pqk8e410.fsf@benfinney.id.au> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87pqk8e410.fsf@benfinney.id.au> Message-ID: On Sun, Aug 14, 2011 at 10:27 AM, Ben Finney wrote: > The house lights need to be controlled by someone who knows when the > movie's end signal should be sent. What is our ending signal if we're > watching it from media in our home, and no-one in the house knows when > the movie ends? > If you're watching it from your own media, you'll come to the end of the file/DVD/whatever and VLC will know. End-of-file is a well-known condition with well-defined semantics. :) And in the theatre, there's a definition of the end based on the origin of the material (the stage manager's script/music score, or something). Yep, there's always an end marker somewhere. But we are now hopelessly off topic, I think! ChrisA From rosuav at gmail.com Sun Aug 14 08:08:16 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:08:16 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 11:58 AM, Alister Ware wrote: > That would mark the first constructive action from rantingnick ever > > Surely that would mark the end of the sentient universe? Only if he actually did it. Many's the time people have called for him to write a PEP, or (better still) to write some actual code. Unless, as seems likely, Ranting Rick is not his real name, I do not know that he has ever done so. (What sort of mother names her son "Ranting Rick", anyway?) ChrisA From abhishekjain.cooldude.93 at gmail.com Sun Aug 14 08:36:45 2011 From: abhishekjain.cooldude.93 at gmail.com (Abhishek Jain) Date: Sun, 14 Aug 2011 18:06:45 +0530 Subject: question Message-ID: Hello all, I wrote a python program to find the 1000th prime no. The program isn't working as it should be. Please tell what the error is: ## this is to find the 1000th prime number number = 3 while number < 10000: ###initialize stuff counter = 1 ###initializing list to check primarity factor = [] while counter!=(number/2): if number % counter == 0: factor = factor + [counter] counter = counter + 1 if len(factor) > 1: break elif counter == 1000: print number, number+=1 The program is printing all the prime nos. from 1009 to 9973. Please respond fast and give me the correct code with only simple functions as i am a beginner to python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Aug 14 08:41:09 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:41:09 +0100 Subject: question In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain wrote: > Please respond fast Just to let you know, this isn't usually the best way to ask for help. You're mostly there with the correct way to ask questions; you've posted your code, said what it ought to do, and said what it's actually doing; but I recommend a bit of patience. Also a better subject line would help. I'll respond to your actual question in a little while, but just thought I'd "respond fast" to that part. Chris Angelico From rosuav at gmail.com Sun Aug 14 08:47:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 13:47:44 +0100 Subject: question In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain wrote: > ## this is to find the 1000th prime number > > number = 3 > while number < 10000: > ??? ###initialize stuff > ??? counter = 1 I think your main problem here, and you have several, is with this variable 'counter'. Have a really good think about what the counter is supposed to do, and ensure that it's really doing it. If, as I suspect, it's meant to be counting prime numbers such that you print the thousandth, then you want to set it once, outside the loop, and increment it only when you find a prime number. (Point to note: The first prime number is 2, not 3.) You asked for code. This looks like a homework assignment, so I won't actually do your work for you, for that would defeat the purpose. But think about every variable you use, what it ought to be doing, and what it's actually doing. Step through the program in your own head, and be sure you fully understand what it's doing. Chris Angelico From irmen.NOSPAM at xs4all.nl Sun Aug 14 09:21:39 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 14 Aug 2011 15:21:39 +0200 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> On 14-8-2011 7:57, rantingrick wrote: > 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." > more than ten times in a single post, you will get an invite to > Guido's next birthday party; where you'll be forced to do shots whist > walking the balcony railing wearing wooden shoes! I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills for extra credit? Greetings from a Dutchman! Irmen From ron at bumpker.com Sun Aug 14 09:23:45 2011 From: ron at bumpker.com (Ronald Reynolds) Date: Sun, 14 Aug 2011 06:23:45 -0700 (PDT) Subject: pythonw.exe Message-ID: <1313328225.44793.YahooMailClassic@web1103.biz.mail.sk1.yahoo.com> Dear Python Friends: in my python directory there is a python.exe file which I understand completely but there is also a pythonw.exe DOS seems to honor the pythonw command (No error message) but nothing happens. What is pythonw.exe? Also is there a way to invoke idle from the DOS prompt? I tried idle filename.py and just idle. Is there any .exe for idle? Sincerely, 'Ron "bumpker" Reynolds' From rosuav at gmail.com Sun Aug 14 09:46:06 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 14:46:06 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong wrote: > On 14-8-2011 7:57, rantingrick wrote: >> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." >> more than ten times in a single post, you will get an invite to >> Guido's next birthday party; where you'll be forced to do shots whist >> walking the balcony railing wearing wooden shoes! > > I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills > for extra credit? > > Greetings from a Dutchman! Is partial credit available for part-Dutch people, e.g. those with at least two grandparents from Holland? (Couldn't resist sticking an e.g. in there, even though I know it's just feeding the troll...) Irmen, you definitely get bonus points for a .nl domain. ChrisA From irmen.NOSPAM at xs4all.nl Sun Aug 14 09:50:54 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 14 Aug 2011 15:50:54 +0200 Subject: pythonw.exe In-Reply-To: References: Message-ID: <4e47d2c0$0$23857$e4fe514c@news2.news.xs4all.nl> On 14-8-2011 15:23, Ronald Reynolds wrote: > Dear Python Friends: > in my python directory there is a python.exe file which I understand completely but there is also a pythonw.exe DOS seems to honor the pythonw > command (No error message) but nothing happens. What is pythonw.exe? > Also is there a way to invoke idle from the DOS prompt? I tried idle filename.py and just idle. Is there any .exe for idle? > > Sincerely, 'Ron "bumpker" Reynolds' pythonw.exe is the same as python.exe but it doesn't open a console window, and launches python in the background. This allows you to easily run background programs or GUI programs in a nicer way (without a dummy console window popping up). Idle has no .exe as far as I know but you can start it like this: pythonw -m idlelib.idle You could create an alias or batch file called 'idle' that does this. Irmen From steve+comp.lang.python at pearwood.info Sun Aug 14 10:26:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 00:26:45 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > "Destroy data" is a sort of fungible concept. I was reading a comic book > recently and it contained a URL for a poem which had been parodied. The > URL had been hand-lettered... in block capitals. The actual URL had > exactly one upper case letter in it. > > Whoops. Er, most URLs are case insensitive, at least the most common ones, including HTTP and HTTPS. So I don't quite see why you think this was a Whoops. > In general, I don't think all data-loss is identical in severity. Outside > of Python and Makefiles, I don't use anything where whitespace damage of > the sort of "losing or changing leading spaces" is usually significant, > so I *normally* regard it as a trivial change. Ys, nd n rdnry nglsh txt, th lss ar chng af vwls cn olsu b e trvl chng. But try that with your source code :) > I actually really *like* that Ruby and Lua let pretty much everything just > be an expression. I was utterly dumbfounded when I found out that "print" > in Python is a kind of statement, not a function or something comparable. > (This seems to have changed recentlyish.) Yes, print as a statement was a mistake. But assignment as a statement, not so much. Assignment as an expression in languages that have it tends to be associated with frequent errors. The way I see it, if something operates by side-effect, then it has no business being treated as an expression. I'm not even happy with the usual convention of Python functions that return None, such as list.sort() -- in my opinion, languages should have procedures which don't return anything, and can only be used as a statement, similar to Pascal procedures. (I'm prepared to make an exception for purely functional languages.) > Say I try to indent or outdent something and I grab the wrong set of > lines. It's certainly possible for this to result in valid code... And I > have no > cue as to what happened. Even if I get a warning, I can't necessarily > tell what happened. Then don't do that. I'm not impressed by arguments based on "but if I do something stupid, like select text with my eyes closed and reindent it without looking, I expect the compiler to save my bacon". In my opinion, it's not the compiler's job to protect you from errors caused by sheer carelessness at the keyboard. In any case, while reindenting an arbitrary set of lines may *possibly* result in valid code that runs but does the wrong thing, the likelihood of that happening is remote enough that I'm not going to lose any sleep over it. There are real-world scenarios involving such semantic errors involving indentation, but they're pretty rare. I think that six weeks of not having to type { } or BEGIN END around code blocks has saved far more time and effort than such errors have cost me in my entire history of Python programming. > Refactoring C or Ruby is easy for me. Refactoring Python is hard for me. > I really do rely on visible markers to sanity-check the boundaries of what > I'm indenting or outdenting. If I do something in my editor and end up > with: > > foo.each do |bar| > bar.do_a_thing > do_something_with(bar) > end > next_thing > something else > > I know immediately that it's wrong. How? What makes you so certain that next_thing and something else are supposed to be inside the loop? They don't even refer to bar. Even if they did, it's not a foolproof sign, although it is a good hint. Unless I understand the intent of the code, how can I tell whether the END token is in the right place or not? And if I understand the intent of the code, then the END token is redundant. > If I do something in my editor and end up with: > if foo: > bar.do_a_thing > do_something_with(bar) > next_thing > something else > > I can't immediately see that I hit the wrong number key when telling > the editor how many lines to adjust. > > Typos happen. I rely heavily on things that let me catch them in as many > ways as possible. I call that a poor user interface design. If you have to count the number of lines before applying an edit, instead of selecting a range of text, then you should stop using a tool that is stuck with a UI from the early 1980s. Please don't take this as an insult, because it is not meant as one, but it seems to me from this discussion that you're a more careless coder than I am[1], and you want more insurance to protect you from your own mistakes. Braces give you that insurance. I'm not saying I've never mis-indented a block of code, surely I must have. But if I did, it was so trivial to fix, and done so rarely, I've forgotten all about it. Consequently I don't want to pay the cost of that insurance, as little as it is, because I don't get the benefit of it -- for me, it's just redundant information that I have to type and read that provides no real benefit. And that's why I love Python, because it doesn't make my pay for insurance I don't need. [1] For some definition of "careless". -- Steven From nobody at nowhere.com Sun Aug 14 10:30:25 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 14 Aug 2011 15:30:25 +0100 Subject: pythonw.exe References: Message-ID: On Sun, 14 Aug 2011 06:23:45 -0700, Ronald Reynolds wrote: > in my python directory there is a python.exe file which I understand > completely but there is also a pythonw.exe DOS seems to honor the pythonw > command (No error message) but nothing happens. What is pythonw.exe? Windows distinguishes between "console" and "GUI" executables. python.exe is a console executable, pythonw.exe is a GUI executable. One difference is that GUI executables don't have stdin/stdout/stderr, so you can't use pythonw.exe as an interactive interpreter. The main use for pythonw.exe is if you write a GUI program in Python (using e.g. TkInter, wxPython, etc) and you want it to be able to run it from an icon (desktop, start menu) without it opening a console window (running a console executable from an icon will open a console window). > Also > is there a way to invoke idle from the DOS prompt? I tried idle > filename.py and just idle. Is there any .exe for idle? "C:\Program Files (x86)\Python27\Lib\idlelib\idle.py" filename.py ... or similar, depending upon where Python is installed. BTW, unless you're using Windows 95/98/ME, you don't have a "DOS Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. From 1248283536 at qq.com Sun Aug 14 10:50:12 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sun, 14 Aug 2011 22:50:12 +0800 Subject: login with urllib2 Message-ID: please to see my code: import urllib import urllib2 url = 'http://hi.baidu.com/' values = {'username' : '******','password' : '******' } data = urllib.urlencode(values) req = urllib2.Request(url,data) response = urllib2.urlopen(req) the_page = response.read() i can't to login ,why?username and password are right. any word appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafadurancastaneda at gmail.com Sun Aug 14 11:03:14 2011 From: rafadurancastaneda at gmail.com (=?UTF-8?B?UmFmYWVsIER1csOhbiBDYXN0YcOxZWRh?=) Date: Sun, 14 Aug 2011 17:03:14 +0200 Subject: login with urllib2 In-Reply-To: References: Message-ID: <4E47E3B2.2040609@gmail.com> I'm not sure but you probably need using HTTPS handler, but without exact error code/message... On 14/08/11 16:50, ???? wrote: > please to see my code: > import urllib > import urllib2 > > url = 'http://hi.baidu.com/' > values = {'username' : '******','password' : '******' } > > data = urllib.urlencode(values) > req = urllib2.Request(url,data) > response = urllib2.urlopen(req) > the_page = response.read() > > i can't to login ,why?username and password are right. > any word appreciated. From clp2 at rebertia.com Sun Aug 14 11:07:37 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 08:07:37 -0700 Subject: login with urllib2 In-Reply-To: References: Message-ID: 2011/8/14 ???? <1248283536 at qq.com>: > please to see my code: > import urllib > import urllib2 > > url = 'http://hi.baidu.com/' > values = {'username' : '******','password' : '******' } > > data = urllib.urlencode(values) > req = urllib2.Request(url,data) > response = urllib2.urlopen(req) > the_page = response.read() > > i can't to login ,why?username and password? are? right. > any word? appreciated. Use the URL specified as the 's action, which in this case is https://passport.baidu.com/?login , rather than the URL of the login page itself. The fields aren't called "username" and "password"; read the page's HTML. You'll also see that there are a few hidden form fields that are probably required. Finally, even if you fix these problems, the site could possibly block Python based on its User-agent header. Cheers, Chris -- http://blog.rebertia.com From kw at codebykevin.com Sun Aug 14 11:23:03 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 14 Aug 2011 11:23:03 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: I'd like to post a detailed response, e.g. a point-by-point engagement with Rantingrick's list, but as I lack time, this will have to suffice: http://xkcd.com/386/ There! Can I get my community pin now? :-) -- Kevin Walzer Code by Kevin http://www.codebykevin.com From roy at panix.com Sun Aug 14 11:35:21 2011 From: roy at panix.com (Roy Smith) Date: Sun, 14 Aug 2011 11:35:21 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Er, most URLs are case insensitive, at least the most common ones, including > HTTP and HTTPS. So I don't quite see why you think this was a Whoops. URLs are most certainly not case insensitive. Parts of them may be (i.e. the scheme and host parts), but not the stuff after the hostname. From rosuav at gmail.com Sun Aug 14 11:39:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 16:39:53 +0100 Subject: allow line break at operators In-Reply-To: <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano wrote: > Yes, print as a statement was a mistake. But assignment as a statement, not > so much. Assignment as an expression in languages that have it tends to be > associated with frequent errors. > > The way I see it, if something operates by side-effect, then it has no > business being treated as an expression. Wikipedia (that well-known authority) lists among examples of side effects both "write data to a display or file" and "modify one of its arguments". This strongly implies that print() is a function that operates by side-effect, just as the assignment operator (in languages in which it is one) does. Treating "a=5" as an expression with the value 5 is no more relying on side effects than having "print('asdf')" an expression with the value None. I believe that print-as-a-function is a Good Thing, mainly because it can be used as an argument to such as map. Somewhat silly/trivial example: msgs=["Hello","World"] list(map(print,msgs)) I'm aware that assignment-as-an-expression has plenty of risks associated with it (the main one being the classic C issue of assignment inside a conditional - a feature that I use frequently myself, but which trips plenty of people up), which is a strong argument for its remaining a statement, but side effects isn't on its own. ChrisA From rosuav at gmail.com Sun Aug 14 11:52:05 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 16:52:05 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 3:30 PM, Nobody wrote: > BTW, unless you're using Windows 95/98/ME, you don't have a > "DOS Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. > I don't see this as any sloppier than referring to "opening a prompt" when you mean "opening up a windowed command interpreter". The command interpreter in NT+ uses an interface that derives from the original DOS command interpreter, and a lot of people consider it to be as primitive (not realising that it has a lot of features, eg tab completion, that are WAY better even than command+doskey); it's a lot closer to Unix's bash than to MS-DOS's command. (I do prefer bash, though.) ChrisA From martin at v.loewis.de Sun Aug 14 12:27:31 2011 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 14 Aug 2011 18:27:31 +0200 Subject: Python 3.2.2rc1 Message-ID: <4E47F773.4080604@v.loewis.de> On behalf of the Python development team, I'm happy to announce the first release candidate of the Python 3.2.2 maintenance release (3.2.2rc1). Python 3.2.2 fixes `a regression `_ in the ``urllib.request`` module that prevented opening many HTTP resources correctly with Python 3.2.1. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * a much improved ssl module with support for SSL contexts and certificate hostname matching * a sysconfig module to access configuration information * additions to the shutil module, among them archive file support * many enhancements to configparser, among them mapping protocol support * improvements to pdb, the Python debugger * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Martin v. L?wis (on behalf of the entire python-dev team and 3.2's contributors) From jabba.laci at gmail.com Sun Aug 14 12:39:39 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Sun, 14 Aug 2011 18:39:39 +0200 Subject: monitor mouse coordinates in real-time In-Reply-To: References: Message-ID: I'm trying something similar. In the thread there is a variable which is modified by the parent. However, the thread doesn't quit the infinite loop. If someone could provide a patch, that'd be really useful. Thanks, Laszlo On Sun, Aug 14, 2011 at 13:00, TheSaint wrote: > Jabba Laci wrote: > >> Could you please help me out how to close the application correctly? >> > I think you should put a flag into the code, which the parent might modify > it, so it will tell the child process to quit. > Then the flag should need to be read periodically to know whether is time to > quit. > > -- > http://mail.python.org/mailman/listinfo/python-list > From kw at codebykevin.com Sun Aug 14 13:15:51 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 14 Aug 2011 13:15:51 -0400 Subject: os.system() on Windows in Tkinter app spawns console window In-Reply-To: References: Message-ID: <414ef$4e48029f$4275d90a$19723@FUSE.NET> On 8/13/11 1:15 AM, Nobody wrote: > On Fri, 12 Aug 2011 22:49:32 -0400, Kevin Walzer wrote: > >> I'm developing a Tkinter app for a Windows customer, and the app bundles >> several command-line tools (ported from Unix). I call out to these >> console tools from the Tkinter app via os.system(). However, in the >> frozen version of my app, when I call out to these tools, I get multiple >> console windows popping up. This is jarring to say the least. Is there >> any way to run the commands under the hood without the console/DOS >> windows popping up? > > Just a wild guess, but try explicitly redirecting the commands' > stdin/stdout/stderr. You might also consider using subprocess.call() > instead of os.system(). > I've gotten the CLI commands to execute silently by setting the window flags for subprocess as discussed here: http://code.activestate.com/recipes/409002-launching-a-subprocess-without-a-console-window/ These flags are apparently undocumented, but this solution works perfectly. Perhaps the flags should be better documented. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrick at gmail.com Sun Aug 14 13:21:59 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 10:21:59 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> On Aug 14, 12:57?am, rantingrick wrote: > 9. Never use the word "previously" or the phrase "in the past"; just > dumb it down with "used to". I had forgot to mention one other usage of "used to": WRONG: "I used to not like indention but know i am very used to it" RIGHT: "Previously i lamented forced indentation but i have since grown quite accustomed to it" Also the usage of "supposed to" is rather foolish. WRONG: "We are supposed to write clean code but i am not used to that" RIGHT: "We are required to write clean code however i am not accustom to that way of thinking. Gawd, sometimes i feel like i'm watching an episode of squidbillies when i read the this list. From steve+comp.lang.python at pearwood.info Sun Aug 14 13:24:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 03:24:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4804e2$0$29995$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article <4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Er, most URLs are case insensitive, at least the most common ones, >> including HTTP and HTTPS. So I don't quite see why you think this was a >> Whoops. > > URLs are most certainly not case insensitive. Parts of them may be > (i.e. the scheme and host parts), but not the stuff after the hostname. I stand corrected. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 14 13:26:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 03:26:50 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e48055b$0$29995$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano > wrote: >> Yes, print as a statement was a mistake. But assignment as a statement, >> not so much. Assignment as an expression in languages that have it tends >> to be associated with frequent errors. >> >> The way I see it, if something operates by side-effect, then it has no >> business being treated as an expression. > > Wikipedia (that well-known authority) lists among examples of side > effects both "write data to a display or file" and "modify one of its > arguments". [...] Good point. I withdraw my statement about things that operate about side-effects. -- Steven From rosuav at gmail.com Sun Aug 14 13:38:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 18:38:08 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 6:21 PM, rantingrick wrote: > > WRONG: "We are supposed to write clean code but i am not used to that" > RIGHT: "We are required to write clean code however i am not accustom > to that way of thinking. > Since when are we required to write clean code? If I write unclean code (that's code with an undivided hoof, if you're Jewish), or if I don't write code at all, will I be kicked from the group? I think you need to start a blog, Rick. You'd be easier to ignore. ChrisA From daniel at roseman.org.uk Sun Aug 14 14:12:15 2011 From: daniel at roseman.org.uk (Daniel Roseman) Date: Sun, 14 Aug 2011 11:12:15 -0700 (PDT) Subject: Data issues with Django and Apache In-Reply-To: References: Message-ID: <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1@glegroupsg2000goo.googlegroups.com> On Sunday, 14 August 2011 03:20:30 UTC+1, John Gordon wrote: > I'm devleoping a website using the Django framework along with Apache, > and I'm seeing some odd data issues. > > During the course of navigating through the website content, a user > will cause the creation of some data records with a limited lifespan. > These data records have a create_dt field which is automatically set to > the time that they were created, and an expire_dt field which is equal > to create_dt plus ten minutes. > > The problem is that I get conflicting results as to whether these temporary > records have reached their expiration date, depending if I search for them > via an Apache web call or if I do the search locally from a python shell. > > And to make it weirder, the conflicts go away if I stop and restart the > Apache server, although any new records created after this point will still > exhibit the issue. > > Are there any known "gotchas" when using Django with Apache? It almost > seems like Apache is maintaining its own persistent session or something, > and restarting Apache causes the session to be flushed. > > -- > John Gordon A is for Amy, who fell down the stairs > gor... at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Well, without seeing any code, it's hard to tell. And Apache (with mod_wsgi) is the recommended deployment method, so you can't really say there are gotchas. My guess is that you have not understood that server processes - and this is true on the dev server as well as on Apache - are not the same as requests. That is, server processes are long-lasting, and one process may end up serving tens or hundreds of requests before being recycled. So, if you have any code that runs at process startup - such as default values in class definitions or at module level - it will persist for all requests served by that process. Like I say, though, it would really help if you showed the relevant code. -- DR. From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Aug 14 14:48:46 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 14 Aug 2011 18:48:46 +0000 (UTC) Subject: Relative import from script with same name as package References: Message-ID: =?UTF-8?B?T2t0YXkgxZ5hZmFr?= wrote: >> It appears that Python is reading "import thetest" as >> importing >> thetest.py (the same file that is currently being run). When it >> tries to run that file a second time, the relative import fails. >> > > No, there is no such thing happening. Read the error message more > carefully: the error happens when your code reaches the line "from > .theother import foo", and it fails because you are trying to > execute an "explicit" relative import statement (with leading dot > notation) as introduced by PEP 328. What you see is perfectly > expected behaviour as explained in detail in the PEP because the > python interpreter can only make sense of that statement if that > code is *imported* for use by code that resides *outside* the > package. That error message is what you see when you try to *run* a > package member module which uses explicit relative imports. Let me > try to explain a bit further: Yes, such a thing was happening. (I described the fix in an answer to my own post.) You should read PEP 366 to understand what I was talking about, and what the __package__ variable does. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From usenet-nospam at seebs.net Sun Aug 14 15:01:57 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:57 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Chris Angelico wrote: > Yes. Not everything's an expression; a block of code is not an > expression that returns a code object, and variable assignment is a > statement. Some day, I'd like to play around with a language where > everything's an expression and yet it doesn't look like LISP - just > for the fun of it. It probably won't be any more useful for real world > coding, but it'd be fun to tinker with. Ruby and Lua are both pretty close. I'm not an expert in either, but I can't think of anything I can write in Ruby which isn't an expression. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 15:01:57 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:57 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-14, Steven D'Aprano wrote: > Seebs wrote: >> "Destroy data" is a sort of fungible concept. I was reading a comic book >> recently and it contained a URL for a poem which had been parodied. The >> URL had been hand-lettered... in block capitals. The actual URL had >> exactly one upper case letter in it. > Er, most URLs are case insensitive, at least the most common ones, including > HTTP and HTTPS. So I don't quite see why you think this was a Whoops. Sort of. Host names are case insensitive, so far as I can tell "always". Paths past that are distinctly NOT always case insensitive, and since the server in question happened to be doing what appear to be "straight path lookups", it mattered a great deal that you had to downcase all but one of the letters. (The obvious technique of downcasing them all failed.) > Ys, nd n rdnry nglsh txt, th lss ar chng af vwls cn olsu b e trvl chng. > But try that with your source code :) Eh, I'm a C programmer, what makes you think I had any vowels to begin with? > Yes, print as a statement was a mistake. But assignment as a statement, not > so much. Assignment as an expression in languages that have it tends to be > associated with frequent errors. It does. I'm not sure whether the errors are compensated for by the expressiveness. I *think* on the whole they are, but I am honestly not sure. I do like gcc's warning for assignment used as a truth value. > The way I see it, if something operates by side-effect, then it has no > business being treated as an expression. Interesting! I tend to really like the ability to chain methods, depending on context. I find the side-effect/expression mix pretty normal, so I'm used to it. >> Say I try to indent or outdent something and I grab the wrong set of >> lines. It's certainly possible for this to result in valid code... And I >> have no >> cue as to what happened. Even if I get a warning, I can't necessarily >> tell what happened. > Then don't do that. If not doing that were a realistic option for me, I'm guessing I'd have stopped making typos thirty years ago. > I'm not impressed by arguments based on "but if I do something stupid, like > select text with my eyes closed and reindent it without looking, I expect > the compiler to save my bacon". In my opinion, it's not the compiler's job > to protect you from errors caused by sheer carelessness at the keyboard. I don't know about "sheer carelessness". Typos happen. Typos are not something you can prevent from happening just by wanting it very much. > In any case, while reindenting an arbitrary set of lines may *possibly* > result in valid code that runs but does the wrong thing, the likelihood of > that happening is remote enough that I'm not going to lose any sleep over > it. Ahh, but what about the case where it results in invalid code? It's not necessarily obvious which lines need to be moved after that. >> foo.each do |bar| >> bar.do_a_thing >> do_something_with(bar) >> end >> next_thing >> something else >> I know immediately that it's wrong. > How? The "end" is misaligned. Therefore SOMETHING is wrong. I don't know what, but I can be confident that something went wrong. > Unless I understand the intent of the code, how can I tell whether the END > token is in the right place or not? And if I understand the intent of the > code, then the END token is redundant. The question is not whether it's on the right line. No amount of indenting or outdenting can ever break that. The question is whether I've gotten the indentation screwed up. >> If I do something in my editor and end up with: >> if foo: >> bar.do_a_thing >> do_something_with(bar) >> next_thing >> something else >> I can't immediately see that I hit the wrong number key when telling >> the editor how many lines to adjust. >> Typos happen. I rely heavily on things that let me catch them in as many >> ways as possible. > I call that a poor user interface design. If you have to count the number of > lines before applying an edit, instead of selecting a range of text, then > you should stop using a tool that is stuck with a UI from the early 1980s. You keep telling me to stop using this editor. I have not seen a suggested improvement. (Hint: GUI editors are not an improvement for my purposes, as I do about 99.5% of my editing on machines that aren't in the same state that I am. No, the GUI editor cannot offer enough improvement in anything to justify the cost of copying files back and forth constantly.) > Please don't take this as an insult, because it is not meant as one, but it > seems to me from this discussion that you're a more careless coder than I > am[1], and you want more insurance to protect you from your own mistakes. > Braces give you that insurance. I have really, really, bad ADHD. When I was a kid a firecracker blew up in my hand because I *forgot* I was holding it. I'm not exactly "careless" in the pejorative sense (I don't accept the implication that it's a character flaw, but I don't think you intended it either), but functionally, I will make DOZENS of tiny errors per hour, and yes, I rely on having insurance against them. I don't really get a vote in this; I can either have insurance against them, never program at all, or spend a whole bunch of time trying to figure out what happened. > And that's why I love Python, because it doesn't make my pay for insurance I > don't need. I think that's pretty much the thing. I regard the "cost" of the insurance as completely nugatory, and I can identify dozens of times when it's saved me hours of effort on debugging code, whether mine or someone else's. And in general, I am a HUGE fan of things that offer a bit of insurance against otherwise-minor errors. If something can make a potentially severe problem into a trivial problem, that's usually a big attraction to me. So I think there are a couple of big personal-style questions influencing this. 1. Preference for "insurance"-type syntax -- stuff that may not be useful most of the time but will occasionally prevent failures. 2. Likelihood of "minor" formatting errors either in your direct work or in your larger environment (say, people mailing you code, use of web forum software, etc.) 3. General preferences for how things are structured. I strongly prefer explicit matching markers, and by "explicit" I mean *actual symbols you can see*. The way in which I view indentation as non-explicit is as follows: if foo: if bar: baz quux if foo: baz quux The two-tab outdent is either one or two outdents. I can't point to a specific character and say "this is *one* outdent". So it's not explicit. I really don't see why people insist on calling it explicit; it seems utterly unambiguous to me that it's not. I think... I mean, the thing about design philosophy, when you have several design philosophy rules, is that NONE of the rules get followed all the time. I think it'd be much more effective to say that one of the other rules won in this case than to try to convince people that a variable number of tokens occurring with no difference at all in the character stream is "explicit". -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Sun Aug 14 15:01:58 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 19:01:58 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <87obzstjed.fsf@mithlond.arda> Message-ID: On 2011-08-14, Teemu Likonen wrote: > I understand that Python philosophy does not value freedom of expression > that much. It values a general Pythonic rule which must obeyed and is > called "readability". Other languages give too little or too much > freedom. :-) There is an interesting tradeoff, there, because I tend to find stuff like "variable = {fancy if expression}" to be much *more* readable, since I immediately get the top-level information ("we're assigning variable") and then I can look for details if I care. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From python.list at tim.thechases.com Sun Aug 14 15:50:35 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Aug 2011 14:50:35 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4E48270B.3010106@tim.thechases.com> On 08/14/2011 12:38 PM, Chris Angelico wrote: > On Sun, Aug 14, 2011 at 6:21 PM, rantingrick wrote: >> >> WRONG: "We are supposed to write clean code but i am not used to that" >> RIGHT: "We are required to write clean code however i am not accustom >> to that way of thinking. > > Since when are we required to write clean code? If I write unclean > code (that's code with an undivided hoof, if you're Jewish), or if I > don't write code at all, will I be kicked from the group? Any time your code sends Spam or is a resource hog, it would be unclean by both Jewish and Muslim anti-porcine standards :) > I think you need to start a blog, Rick. > > You'd be easier to ignore. +1 QOTW -tkc From thorsten at thorstenkampe.de Sun Aug 14 15:59:06 2011 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Sun, 14 Aug 2011 21:59:06 +0200 Subject: pythonw.exe References: Message-ID: * Chris Angelico (Sun, 14 Aug 2011 16:52:05 +0100) > On Sun, Aug 14, 2011 at 3:30 PM, Nobody wrote: > > BTW, unless you're using Windows 95/98/ME, you don't have a "DOS > > Prompt". The command prompt in Windows NT/2000/XP/Vista/7 isn't DOS. > > I don't see this as any sloppier than referring to "opening a > prompt" when you mean "opening up a windowed command > interpreter". You're misunderstanding what people mean by "DOS prompt". They don't mean "this is the DOS command shell", they mean "this is DOS". Thorsten From harmar at member.fsf.org Sun Aug 14 16:11:07 2011 From: harmar at member.fsf.org (harrismh777) Date: Sun, 14 Aug 2011 15:11:07 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: Chris Angelico wrote: >> I lolled about this one, e.g. I laughed out loud. But where are the tulips and windmills >> > for extra credit? >> > >> > Greetings from a Dutchman! > Is partial credit available for part-Dutch people, e.g. those with at > least two grandparents from Holland? > ... do we get extra credit for having our own shoes... my pair are official (e.g. hand-carved in Holland, with little windmills wood-burned on the bow... ) ... mine also have lambs wool lining... don't know it that adds anything official, but they sure feel great! kind r'gards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From harmar at member.fsf.org Sun Aug 14 16:20:54 2011 From: harmar at member.fsf.org (harrismh777) Date: Sun, 14 Aug 2011 15:20:54 -0500 Subject: pythonw.exe In-Reply-To: References: Message-ID: Thorsten Kampe wrote: > You're misunderstanding what people mean by "DOS prompt". They don't > mean "this is the DOS command shell", they mean "this is DOS". ... yup, ... was helping my little sis with her iMac over the phone from four states away and had her open a terminal for some magic... and it took her exactly 1.03 seconds to say, "Oh, the iMac has DOS installed in the utilities folder!" :-O ... blondes... :-} (she tries hard, and actually has been learning, so, we keep trying...) -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From rosuav at gmail.com Sun Aug 14 16:28:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 21:28:23 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Sun, Aug 14, 2011 at 9:20 PM, harrismh777 wrote: > ... yup, ... was helping my little sis with her iMac over the phone from > four states away and had her open a terminal for some ?magic... and it took > her exactly 1.03 seconds to say, "Oh, the iMac has DOS installed in the > utilities folder!" ? :-O > > ... blondes... ? :-} Just to confuse things even further, it's not unlikely that a Mac or Linux or Windows computer will have DOSBox installed. Is *that* DOS? Technically no, but practically yes. ChrisA From davea at ieee.org Sun Aug 14 17:46:03 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Aug 2011 17:46:03 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E48421B.2080201@ieee.org> On 01/-10/-28163 02:59 PM, Roy Smith wrote: > In article<4e47db26$0$30002$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Er, most URLs are case insensitive, at least the most common ones, including >> HTTP and HTTPS. So I don't quite see why you think this was a Whoops. > URLs are most certainly not case insensitive. Parts of them may be > (i.e. the scheme and host parts), but not the stuff after the hostname. > The thing that confuses people is that not only is the part up to and through the domain name is case-insensitive, but that simple pages on Windows become case-insensitive for the remainder simply because Windows is such. And the same page hosted on Linux would be case sensitive, per specification. The thing I find annoying is a host that decides that if a URL is close to an existing URL, it'll fix one or two "typos." To me, it's either right, or it's not. Don't change www.mydomain.com/page105.html to www/mydomain.com/page102.html and pretend it's "close enough." DaveA From davea at ieee.org Sun Aug 14 18:01:15 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Aug 2011 18:01:15 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4E4845AB.9020107@ieee.org> On 01/-10/-28163 02:59 PM, rantingrick wrote: > On Aug 14, 12:57 am, rantingrick wrote: > >> 9. Never use the word "previously" or the phrase "in the past"; just >> dumb it down with "used to". > I had forgot to mention one other usage of "used to": > > WRONG: "I used to not like indention but know i am very used to it" > RIGHT: "Previously i lamented forced indentation but i have since > grown quite accustomed to it" > > Also the usage of "supposed to" is rather foolish. > > WRONG: "We are supposed to write clean code but i am not used to that" > RIGHT: "We are required to write clean code however i am not accustom > to that way of thinking. > > Gawd, sometimes i feel like i'm watching an episode of squidbillies > when i read the this list. > > > Interesting that when you complain about other's grammatical typos, you're so careless with your own. know -> now i -> I accustom -> accustomed the this -> this I'm inclined to ignore typos in emails except in the case where the intent is to abuse others. DaveA From usenet-nospam at seebs.net Sun Aug 14 18:27:12 2011 From: usenet-nospam at seebs.net (Seebs) Date: 14 Aug 2011 22:27:12 GMT Subject: pythonw.exe References: Message-ID: On 2011-08-14, Chris Angelico wrote: > Just to confuse things even further, it's not unlikely that a Mac or > Linux or Windows computer will have DOSBox installed. Is *that* DOS? > Technically no, but practically yes. Depending on how you define "unlikely", I'd guess it is. Assume that "unlikely" means roughly the equivalent of "if I were optimizing, I'd use a compiler branch prediction hint at this point". :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From roy at panix.com Sun Aug 14 18:46:24 2011 From: roy at panix.com (Roy Smith) Date: Sun, 14 Aug 2011 18:46:24 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Dave Angel wrote: > > URLs are most certainly not case insensitive. Parts of them may be > > (i.e. the scheme and host parts), but not the stuff after the hostname. > > > The thing that confuses people is that not only is the part up to and > through the domain name is case-insensitive, but that simple pages on > Windows become case-insensitive for the remainder simply because Windows > is such. Sure. But it's only in the most trivial of situations that URLs map in any trivial way to file names. > And the same page hosted on Linux would be case sensitive, per > specification. Well, I certainly could write an HTTP server on Linux which treated routes in a case-insensitive way. For example, if I do a GET on http://en.wikipedia.org/wiki/hypertext, I get redirected to http://en.wikipedia.org/wiki/Hypertext. On the other hand, http://en.wikipedia.org/WIKI/Hypertext gets me a 404. It's entirely up to the server to do whatever makes sense for that application. > The thing I find annoying is a host that decides that if a URL is close > to an existing URL, it'll fix one or two "typos." To me, it's either > right, or it's not. Don't change www.mydomain.com/page105.html > to www/mydomain.com/page102.html and pretend it's "close enough." Hosts don't decide anything. Applications running on those hosts decide things. Without knowing the application, it's impossible to say if this is the right thing to do or not. For example, it's good practice that if a URL ever worked in the past, you should keep that URL working, even if it becomes "obsolete". You might want to silently return some other page, or redirect the user to some other URL. This keeps bookmarks, existing links, cached search results, etc, from going stale. To use the wikipedia example again, there are lots of redirect entries, for other (perhaps incorrect) spellings, and so forth. For example, http://en.wikipedia.org/w/index.php?title=Taboule&redirect=no From oktaysafak at superonline.com Sun Aug 14 18:56:35 2011 From: oktaysafak at superonline.com (=?UTF-8?B?T2t0YXkgxZ5hZmFr?=) Date: Mon, 15 Aug 2011 01:56:35 +0300 Subject: Relative import from script with same name as package In-Reply-To: References: Message-ID: <4E4852A3.6010003@superonline.com> 14.08.2011 21:48, OKB (not okblacke) yazm??: > =?UTF-8?B?T2t0YXkgxZ5hZmFr?= wrote: > >>> It appears that Python is reading "import thetest" as >>> importing >>> thetest.py (the same file that is currently being run). When it >>> tries to run that file a second time, the relative import fails. >>> >> >> No, there is no such thing happening. Read the error message more >> carefully: the error happens when your code reaches the line "from >> .theother import foo", and it fails because you are trying to >> execute an "explicit" relative import statement (with leading dot >> notation) as introduced by PEP 328. What you see is perfectly >> expected behaviour as explained in detail in the PEP because the >> python interpreter can only make sense of that statement if that >> code is *imported* for use by code that resides *outside* the >> package. That error message is what you see when you try to *run* a >> package member module which uses explicit relative imports. Let me >> try to explain a bit further: > > Yes, such a thing was happening. (I described the fix in an > answer to my own post.) You should read PEP 366 to understand what I > was talking about, and what the __package__ variable does. > Hmmm, I have overlooked the middle part of your code. Now I get what you mean. Yes that is happening, you are right and I have given the source of that behaviour in my previous post: > - BIG SOURCE OF CONFUSION: Relative imports (both implicit and explicit) is all about imports *inside* packages. When you have 2 scripts app.py and string.py sitting in a *non-package* folder (they are called top-level modules), that folder is always the first entry in sys.path when you run either of those modules directly, so "import string" in app.py will always import the string.py in that folder, not the stdlib one. (But not when you try with IDLE!) In this case, if you really want the standard module, you must manipulate sys.path before your import statement (or change the name of your local string.py). THE PEP (328) HAS NO EFFECT IN THAT CASE! In your case, you are not using the package by importing its members from code outside the package but you are running them directly. So, your files thetest.py and theother.py are now *top-level* modules for the interpreter, not package members. So as per PEP 366, you need to add that boilerplate to set the __package__ attribute. But the "from __future__ import absolute_import" statement has no effect on the "import thetest" statement when you run the file directly: then thetest.py is a top level module, and when the interpreter encounters the statement "import thetest" *it is already absolute import* (whether you issed the __future__ statement or not). It still is in Python 2.7. PEP 328 has no effect in this case. Remember that absolute import means importing from sys.path only. In this case, thetest.py's folder is always the first entry in sys.path so it tries to import itself first. You would also see the same behaviour if your "import thetest" statement was in theother.py, it would import thetest.py rather than the package. So as I have said before and quoted above, in this case you have to manipulate sys.path, which you have found out yourself. So what is this "absolute import" thing that is introduced by PEP 328 then? It is all about import statements in package members when they are imported from code outside the package. Before PEP 328, if theother.py contained an "import thetest" statement and if you fired up your interpreter and issued import thetest.theother that "import thetest" in theother.py would find thetest.py. It was considered to be a(n implicit) package-relative import. After PEP 328, if you add to the top of theother.py or issue at the interpreter from __future__ import absolute_import and then issue import thetest.theother the "import thetest" statement in theother.py will find the *package* thetest because sys.path is given priority over the package dir by the __future__ statement. So the PEP has effectively overthrown the convention of treating such imports as special. They are not treated as special anymore and receive the same treatment as other imports. This is one aspect of the PEP. The PEP also defines a new notation (leading dot) for those who want the sibling thetest.py, which is another aspect. But when you run the theother.py directly, the PEP and the __future__ statement has NO EFFECT. The "import thetest" statement in theother.py is not seen as intra package import by the interpreter so it is already absolute import (uses sys.path) So it finds thetest.py because it is in the same folder as theother.py, which is the first folder in sys.path. Many people are confused and think that this is relative import. It's not. It is already absolute import (from sys.path) and the PEP has nothing to do with it. Now we can answer your critical question: > But why? That __future__ import is supposed to make absolute > imports the default, so why is "import thetest" importing thetest.py > instead of the package called thetest? Bacause you are running it directly and the PEP and the __future__ statement does not apply here. I hope it is clear now. -- Oktay ?afak From jhsu802701 at gmail.com Sun Aug 14 18:56:58 2011 From: jhsu802701 at gmail.com (Jason Hsu) Date: Sun, 14 Aug 2011 15:56:58 -0700 (PDT) Subject: Commands for changing ownership of a file Message-ID: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> I have a script that I execute as root, but I need to change the ownership of the files created in the script to that of my username. In GNU Bash, the command is something like "chown myusername:users". What's the equivalent Python command? I know that there is a command that uses numbers for the username and group, but is there a command that would allow me to use "myusername" and "users" instead of numbers? From rosuav at gmail.com Sun Aug 14 18:57:18 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Aug 2011 23:57:18 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4845AB.9020107@ieee.org> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <4E4845AB.9020107@ieee.org> Message-ID: On Sun, Aug 14, 2011 at 11:01 PM, Dave Angel wrote: > I'm inclined to ignore typos in emails except in the case where the intent > is to abuse others. > +1 QOTW. It is, however, a well-known tradition that spelling/grammar flames should contain one spelling/grammer error. Oh, I just did it myself, didn't I. ChrisA From rosuav at gmail.com Sun Aug 14 19:02:46 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 00:02:46 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 11:46 PM, Roy Smith wrote: > In article , > ?Dave Angel wrote: > >> The thing that confuses people is that not only is the part up to and >> through the domain name is case-insensitive, but that simple pages on >> Windows become case-insensitive for the remainder simply because Windows >> is such. > > Sure. ?But it's only in the most trivial of situations that URLs map in > any trivial way to file names. And even then, it plays havoc with caches (both browser and proxy), which have no way of knowing that http://blah.com/Foo.html and http://blah.com/foo.html are the same document. (It's not hard to set up a Windows system to be case sensitive with URLs, or (even easier - at least with Apache) to have any request with uppercase letters to instantly redirect to the lower-cased version.) URLs are definitely case sensitive; any server that ChrisA From clp2 at rebertia.com Sun Aug 14 19:37:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 16:37:57 -0700 Subject: Commands for changing ownership of a file In-Reply-To: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> References: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> Message-ID: On Sun, Aug 14, 2011 at 3:56 PM, Jason Hsu wrote: > I have a script that I execute as root, but I need to change the > ownership of the files created in the script to that of my username. > In GNU Bash, the command is something like "chown myusername:users". > What's the equivalent Python command? ?I know that there is a command > that uses numbers for the username and group, but is there a command > that would allow me to use "myusername" and "users" instead of numbers? Simply use the `pwd` and `grp` modules to lookup the uid and gid for the username and group-name respectively. Then use the id-based chown function(s) you already came across. http://docs.python.org/library/pwd.html#pwd.getpwnam http://docs.python.org/library/grp.html#grp.getgrnam Cheers, Chris From gordon at panix.com Sun Aug 14 19:43:07 2011 From: gordon at panix.com (John Gordon) Date: Sun, 14 Aug 2011 23:43:07 +0000 (UTC) Subject: Data issues with Django and Apache References: <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1@glegroupsg2000goo.googlegroups.com> Message-ID: In <09dcb0e2-a8ae-4dfd-9e27-94b32188e4e1 at glegroupsg2000goo.googlegroups.com> Daniel Roseman writes: > Like I say, though, it would really help if you showed the relevant code. I know. But trimming the code down to where it would be fit for posting is a moderately big job and I'm somewhat pressed for time. I was just hoping that someone would recognize the problem from the few symptoms I gave. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From 1248283536 at qq.com Sun Aug 14 20:09:52 2011 From: 1248283536 at qq.com (=?utf-8?B?5a6I5qCq5b6F5YWU?=) Date: Mon, 15 Aug 2011 08:09:52 +0800 Subject: same code to login,one is ok,another is not Message-ID: 1.http://www.renren.com/Login.do it is ok,my code: import cookielib, urllib2, urllib cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),] opener.addheaders=exheaders url_login = 'http://www.renren.com/Login.do' body = (('email',' '), ('password', ')) req1 = opener.open(url_login, urllib.urlencode(body)) file=open('/tmp/sample','w') file.write(req1.read()) file.close() 2.https://passport.baidu.com/?login can't login,my code: import cookielib, urllib2, urllib cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),] opener.addheaders=exheaders url_login = 'https://passport.baidu.com/?login' body =(('username',' '), ('password',' '),('pwd','1')) req1 = opener.open(url_login, urllib.urlencode(body)) file=open('/tmp/sample','w') file.write(req1.read()) file.close() what i get is: ??????????????? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Aug 14 20:49:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Aug 2011 20:49:25 -0400 Subject: pythonw.exe In-Reply-To: References: Message-ID: On 8/14/2011 10:30 AM, Nobody wrote: > The main use for pythonw.exe is if you write a GUI program in Python > (using e.g. TkInter, wxPython, etc) and you want it to be able to run it > from an icon (desktop, start menu) without it opening a console window > (running a console executable from an icon will open a console window). In particular, IDLE runs in a pythonw process and it executes user code in a separate pythonw process and usually uses a socket for the connection. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sun Aug 14 20:55:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 10:55:53 +1000 Subject: same code to login,one is ok,another is not References: Message-ID: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> ???? wrote: > 1.http://www.renren.com/Login.do > it is ok,my code: [...] > 2.https://passport.baidu.com/?login > can't login,my code: [...] Do you have a question, or are you just sharing the bad news? Websites may choose to respond to login attempts differently. Some may require cookies, some may not. Some may check the referrer, some may not. Some may look at the user agent, some may not. If the web developer of the site insists that you log in with a browser, or Internet Explorer, you have to fight to convince the web server to let you in. Many websites really try hard to prevent bots and scripts logging in. The closer you can imitate what a real human being in a browser does, the better the chances you can fool the server that you are a real human being using a browser and not a bot. (Since your script *is* a bot, you may also be in violation of the web site's terms of service.) Some web sites may even check how often you try to log in, or how fast. But what makes you think you can't log in? Given the response below, it looks to me that you did log in, and got a blank page with some javascript to redirect you to the real content page. (If you are a web developer and you do this, I hate you.) But I may be wrong -- I'm not an expert on these things. > > ??????????????? > > > > > > > > > > > > > -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 14 20:56:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 10:56:12 +1000 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <4e486ead$0$29986$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > I think you need to start a blog, Rick. > > You'd be easier to ignore. And yet, here you are, engaging him in conversation and feeding him the attention he craves :( -- Steven From john2james at gmail.com Sun Aug 14 20:56:36 2011 From: john2james at gmail.com (John S James) Date: Sun, 14 Aug 2011 20:56:36 -0400 Subject: Problem installing 3.2.1 on a Linux server Message-ID: Thanks, your reply helped. The problem seems to be the autoconfig -- I was using version 2.59 instead of 2.68. However, the host will not let users install 2.68. So I'm sending them feedback, suggesting a number of reasons for supporting 3.2 for their server accounts, including: * Popularity of Python, TIOBE recognition; * Wide consensus that new Python programmers should learn version 3, unless they must maintain legacy software; * 3.2 will be around for at least another year before 3.3 is released; * Lack of 3.2 in low-cost hosts (3.1 is available) -- a competitive advantage; * 3.2 improves future library compatibility, vs. 3.1; * Installing 3.2 should not affect any existing customers, unless they choose to use it. We should explore why hosting services are resistant to supporting the current version of Python (plus an important older version, 2.7). Other supported versions could be deprecated -- and eventually removed by the ISPs, except for the few customers who choose to install it themselves. John S James www.replicounts.org ---------- Forwarded message ---------- From: Ned Deily To: python-list at python.org Date: Sat, 06 Aug 2011 15:09:39 -0700 Subject: Re: Problem installing 3.2.1 on a Linux server In article , John S James wrote: > My ISP (Bluehost) does not yet support Python version 3, but gave me shell > access (no sudo) so that I can install Python 3 myself on my server account > (running Apache). So I uploaded the standard Python.org installation package > (Python 3.2.1 for Linux) and followed instructions, starting with > ./configure. These instructions had worked for me before, to install Python3 > on a Linux netbook. > > But on the server, ./configure starts fine, but later stops with an error. > Here is the section of the output where the error occurred: > *checking for build directories... done* > *configure: creating ./config.status* > *config.status: creating Makefile.pre* > *config.status: creating Modules/Setup.config* > *config.status: error: cannot find input file: `Misc/python.pc.in'* > > Then the ./configure step stopped. Needless to say, the next step, Make, did > not work because there was no Makefile. Works for me on a current Debian system. Are you downloading the source from python.org? Did you verify that the file is created by tar? $ curl -O http://www.python.org/ftp/python/3.2.1/Python-3.2.1.tgz $ tar xzf Python-3.2.1.tgz $ cd ./Python-3.2.1/ $ ls -l Misc/python.pc.in -rw-r----- 1 nad nad 293 Jul 8 23:58 Misc/python.pc.in $ ./configure [...] configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating Misc/python.pc config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating Makefile If you are still having problems, chances are you have an out-of-date or incomplete version of GNU autotools which contains the macros and tools that are used by the ./configure script. On my system: $ autoconf --version autoconf (GNU Autoconf) 2.68 -- Ned Deily, nad at acm.org -- John S. James www.aidsnews.org www.RepliCounts.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Aug 14 21:35:42 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 18:35:42 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: On Aug 14, 5:01?pm, Dave Angel wrote: > Interesting that when you complain about other's grammatical typos, > you're so careless with your own. > > know -> now > i -> I > accustom -> accustomed > the this -> this > > I'm inclined to ignore typos in emails except in the case where the > intent is to abuse others. My intent is NOT to abuse, but to enlighten. And you need to look up the definition of typo because i am not complaining about typos. Typos are accidents. Even the best of us suffer from accidents. What i AM complaining about is the adoption of a collectively foolish consistency. "Used to" and "supposed to" is the verbiage of children and idiots. I am trying to break these people out of such foolish loops. You should be thanking me instead of trolling my posts. From rantingrick at gmail.com Sun Aug 14 21:40:50 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 14 Aug 2011 18:40:50 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> Message-ID: On Aug 14, 7:56?pm, Steven D'Aprano wrote: > Chris Angelico wrote: > > I think you need to start a blog, Rick. > > You'd be easier to ignore. > > And yet, here you are, engaging him in conversation and feeding him the > attention he craves :( Yes, Steven loves rule # 2. Second only to the strawmen armies he has built. Kurtz: "What do you call it when the assassins accuse the assassin?" From steve+comp.lang.python at pearwood.info Sun Aug 14 21:54:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 11:54:45 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-14, Steven D'Aprano > wrote: >> The way I see it, if something operates by side-effect, then it has no >> business being treated as an expression. Which I later withdrew. > Interesting! I tend to really like the ability to chain methods, > depending > on context. I find the side-effect/expression mix pretty normal, so I'm > used to it. As a rule, chaining method calls risks violating the Law of Demeter. Just sayin'. >>> Say I try to indent or outdent something and I grab the wrong set of >>> lines. It's certainly possible for this to result in valid code... And I >>> have no >>> cue as to what happened. Even if I get a warning, I can't necessarily >>> tell what happened. > >> Then don't do that. > > If not doing that were a realistic option for me, I'm guessing I'd have > stopped making typos thirty years ago. I feel your pain. But not all typos are equivalent. There are typos in the content of the document you are editing, and command typos. There's nothing an editor can do to prevent the first -- how is the editor supposed to know that you meant "referrer" rather than "referer"? And because it didn't, now we're stuck with a %*$%@&! spelling error forever. But a good editor can minimise command typos. User interfaces matter. If your car required you to reach over your left shoulder and pull a lever in order to slow down, it would be a really bad design. It would join these interfaces: http://www.asktog.com/columns/027InterfacesThatKill.html http://www.useit.com/alertbox/20050411.html If your editor doesn't help you minimise bad commands, then your editor doesn't work for you, it works against you. >> I'm not impressed by arguments based on "but if I do something stupid, >> like select text with my eyes closed and reindent it without looking, I >> expect the compiler to save my bacon". In my opinion, it's not the >> compiler's job to protect you from errors caused by sheer carelessness at >> the keyboard. > > I don't know about "sheer carelessness". Typos happen. Typos are not > something you can prevent from happening just by wanting it very much. I sympathise, but don't care. That's your problem man, not Python's. Python has a design philosophy that doesn't match your needs precisely. Oh well, no language can be all things to all people. If you try, you get Perl, and you still fail, because your language doesn't meet the needs of people looking for something that isn't Perl *wink* I hope you can still be productive in Python, and it's not like anyone *wants* you to stop using Python and use another language, but you have to understand that Python wasn't designed for *your* needs precisely. That doesn't make indentation as syntax a bad choice. >> In any case, while reindenting an arbitrary set of lines may *possibly* >> result in valid code that runs but does the wrong thing, the likelihood >> of that happening is remote enough that I'm not going to lose any sleep >> over it. > > Ahh, but what about the case where it results in invalid code? It's not > necessarily obvious which lines need to be moved after that. Are you talking about code you've moved from somewhere else and need to reindent? Then if the code was working before, it will keep working if you have the same relative indentation. (At least indentation-wise. It may break due to other factors.) Revert your bad reindent and try again, more carefully this time. If you're making semantic changes to the code, not just a simple move, then surely you understand what changes you're making and not just randomly indenting and dedenting until it complies? Read the code and decide how to fix it. I get it that sometimes there will be code which is hard to follow and hard to edit. But if that's the case, you've got more maintenance problems than indentation, and indents are the least of your problems. >>> foo.each do |bar| >>> bar.do_a_thing >>> do_something_with(bar) >>> end >>> next_thing >>> something else > >>> I know immediately that it's wrong. > >> How? > > The "end" is misaligned. Therefore SOMETHING is wrong. I don't know > what, but I can be confident that something went wrong. Okay, now I'm confused... if indentation doesn't matter, how is the end misaligned? You could write this, and it would still work the same, yes? foo.each do |bar| bar.do_a_thing do_something_with(bar) end next_thing something else >> Unless I understand the intent of the code, how can I tell whether the >> END token is in the right place or not? And if I understand the intent of >> the code, then the END token is redundant. > > The question is not whether it's on the right line. No amount of > indenting or > outdenting can ever break that. The question is whether I've gotten the > indentation screwed up. But if indentation doesn't matter, you can't screw it up. Isn't that the whole point of this discussion? [...] > You keep telling me to stop using this editor. I have not seen a > suggested improvement. There's only one editor worth using. The standard Unix editor, ed. http://www.gnu.org/fun/jokes/ed.msg.html *wink* Your editor is not my problem. But if you're going to come here and tell us that Python is less than optimal because it doesn't solve the problems you have with your editor, the obvious answer is that it is not Python's responsibility to minimise the harm caused when you indent 7 lines instead of 8, and if your editor encourages you to make mistakes, perhaps you need another editor. I have no idea if that editor even exists. Perhaps you need to write it yourself. [...] > The two-tab outdent is either one or two outdents. I can't point to a > specific character and say "this is *one* outdent". So it's not explicit. "I can point to a specific character" is not what explicit means. The outdent is defined by a change of indentation level. You had 8 spaces, now you have 4. That delta is real. Just because the glyph for spaces is transparent doesn't make it less real, and just because the delta is -4 spaces also doesn't make it less real. To start a new block in C, I type { and then type } to end it. Explicit. To start a new block in Python, I type TAB, and then SHIFT-TAB to end it. This is also explicit. > I think... I mean, the thing > about design philosophy, when you have several design philosophy rules, is > that NONE of the rules get followed all the time. I think it'd be much > more effective to say that one of the other rules won in this case than to > try to convince people that a variable number of tokens occurring with no > difference at all in the character stream is "explicit". The character stream does have a difference. TAB TAB TAB foo is different from TAB foo That difference depends on the context, but is usually two dedents. -- Steven From michael.poeltl at univie.ac.at Sun Aug 14 21:58:48 2011 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 15 Aug 2011 03:58:48 +0200 Subject: Commands for changing ownership of a file In-Reply-To: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> References: <25d3fa2d-15d9-4b85-8f97-e3fa7ccd7b99@q5g2000yqj.googlegroups.com> Message-ID: <20110815015848.GD25106@horus.cms.at> in python-3.2.1 I'm using os.system() again, from time to time maybe that's the one you were looking for? >>> os.system('chown user:group /tmp/f') 0 >>> os.system('ls -l /tmp/f') -rw-r--r-- 1 user group 0 Aug 15 03:52 /tmp/f and besides os.chown() (where you ned the uid and gid), you could also use subprocess.call() or subprocess.Popen() regards Michael * Jason Hsu [2011-08-15 01:15]: > I have a script that I execute as root, but I need to change the > ownership of the files created in the script to that of my username. > In GNU Bash, the command is something like "chown myusername:users". > What's the equivalent Python command? I know that there is a command > that uses numbers for the username and group, but is there a command > that would allow me to use "myusername" and "users" instead of numbers? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at -------------------------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -------------------------------------------------------------------------------- From clp2 at rebertia.com Sun Aug 14 22:10:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Aug 2011 19:10:42 -0700 Subject: allow line break at operators In-Reply-To: <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 14, 2011 at 6:54 PM, Steven D'Aprano wrote: > Seebs wrote: >> Interesting! ?I tend to really like the ability to chain methods, >> depending >> on context. ?I find the side-effect/expression mix pretty normal, so I'm >> used to it. > > As a rule, chaining method calls risks violating the Law of Demeter. Just > sayin'. Not in the specific case of fluent interfaces[1] though, which could have been what Seebach had in mind. Whether fluent interfaces are a good idea... Cheers, Chris -- [1] http://en.wikipedia.org/wiki/Fluent_interface From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <4e486ead$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: > And yet, here you are, engaging him in conversation and feeding him the > attention he craves :( Many cultures have a tradition of almsgiving. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: >> Interesting! I tend to really like the ability to chain methods, >> depending >> on context. I find the side-effect/expression mix pretty normal, so I'm >> used to it. > As a rule, chaining method calls risks violating the Law of Demeter. Just > sayin'. "Risks violating" isn't the same thing as "violates". > But a good editor can minimise command typos. User interfaces matter. If > your car required you to reach over your left shoulder and pull a lever in > order to slow down, it would be a really bad design. It would join these > interfaces: Yeah. > If your editor doesn't help you minimise bad commands, then your editor > doesn't work for you, it works against you. Life is full of tradeoffs. The editor does a lot of things which very much improve my performance, with costs which are usually pretty easily mitigated. >> I don't know about "sheer carelessness". Typos happen. Typos are not >> something you can prevent from happening just by wanting it very much. > I sympathise, but don't care. That's your problem man, not Python's. Debatable. There's a sort of fuzzy boundary between "clearly this is a defect in the product" (see interfaces that kill), and "clearly this is a defect in the user". In fact, one of the major areas of interesting UI research involves interfaces that accommodate things which are generally regarded as defects in the user. Think about colorblindness. Obviously, it's the user's problem, not the editor's, but an editor which picks colors which most colorblind people can't distinguish for something important is going to get castigated for it. > I hope you can still be productive in Python, and it's not like anyone > *wants* you to stop using Python and use another language, but you have to > understand that Python wasn't designed for *your* needs precisely. That > doesn't make indentation as syntax a bad choice. I think it depends a lot on the goals. So far as I can tell, the primary goal of the policy was to eliminate a class of errors. It... well, it does this in a strictly technical sense, in that every error which occurs is no longer of that class. It does not seem to me that it's done very much to turn the kinds of things which used to result in that class of errors into non-errors; rather, it's turned them into different errors. > Are you talking about code you've moved from somewhere else and need to > reindent? Then if the code was working before, it will keep working if you > have the same relative indentation. (At least indentation-wise. It may > break due to other factors.) Revert your bad reindent and try again, more > carefully this time. The point is... I can't *TELL* what the boundaries of the bad-reindent are. Because there's no unambiguous point at which I can say "oh, look, here is the line where the indentation starts being wrong", unless there's a syntax error... and even then, the syntax error might be before or after the actual bounds of the bad indent. With properly-braced code in a brace language, any mis-indent you do can be unambiguously identified -- you have a 100% guarantee that you know what the first and last misindented lines are. In Python, you can usually guess within a couple of the lines, more easily if you're familiar with the code. > If you're making semantic changes to the code, not just a simple move, then > surely you understand what changes you're making and not just randomly > indenting and dedenting until it complies? Read the code and decide how to > fix it. The case that has historically bitten me is that I move N lines of code, and then I try to adjust the indentation of those N lines, and... SOMETHING happens. Maybe someone somewhere introduced tabs and adding four leading spaces doesn't do anything. Maybe I mis-counted N. > I get it that sometimes there will be code which is hard to follow and hard > to edit. But if that's the case, you've got more maintenance problems than > indentation, and indents are the least of your problems. Not if the only reason that it's hard to follow is that the indentation is screwed up. >> The "end" is misaligned. Therefore SOMETHING is wrong. I don't know >> what, but I can be confident that something went wrong. > Okay, now I'm confused... if indentation doesn't matter, how is the end > misaligned? Indentation doesn't affect the *compiler*, but we know the rules for indentation. It's a parity bit. If the indentation and the begin/end don't agree, then I *know something is wrong*. And I know on exactly which line it becomes wrong. That turns out to save me a fair bit of time if I have to look at code and try to figure out what's wrong. >> The question is not whether it's on the right line. No amount of >> indenting or >> outdenting can ever break that. The question is whether I've gotten the >> indentation screwed up. > But if indentation doesn't matter, you can't screw it up. Isn't that the > whole point of this discussion? I think there is some confusion because the word "matter" has more than one meaning. Indentation does not control what the compiler does in, say, C or Ruby. It does matter to the *reader*. > There's only one editor worth using. The standard Unix editor, ed. Heh. > Your editor is not my problem. But if you're going to come here and tell us > that Python is less than optimal because it doesn't solve the problems you > have with your editor, But they're *not problems* -- unless I'm using Python. The rest of the time it's just the ordinary thing where sometimes when you're using a computer you typo, misclick, or whatever. Hmm. Lemme try an analogy. Imagine, if you will, an editor with the helpful trait that if you close a window it closes, bang, whether or not anything has been touched in it. Your argument here is roughly: But if you're going to come here and tell us that Hypothetical Edit is less than optimal because it doesn't solve the problems you have with your mouse, [...] Which is to say: Yes, I usually expect software to be designed to handle common problems gracefully. Whether this is "Python's problem" or not is really an incoherent question; all we can do is talk about what the effects are, and it's up to Guido or whoever else to decide whether they care. In terms of language adoption, it has certainly been a "problem" historically; there are many people who might have used Python but ended up not doing so because the indentation thing interacted badly with their other requirements. I tend not to care much about assigning "blame". I don't care whether a tool is correctly designed for someone who isn't me, or is incorrectly designed, because neither matters. All that matters is whether I can use it reasonably easily. With Python, the single barrier I've encountered to a pleasant and productive programming experience has been the indentation thing. Apart from that it's a language I'd basically get along with. But, for whatever reason, the net result is that programming in Python is a perpetual exercise in frustration for me. I still prefer it to a number of other languages, but it's always annoying; it's like using a stereo system that has a persistent high-pitched whine, but otherwise has very good sound. > "I can point to a specific character" is not what explicit means. No, but... An explicit thing is by definition a thing which is *NOT INFERRED*. If the same sequence of characters can be one or two tokens, depending on a sequence of characters twenty lines ago, that looks very much like something is being *inferred*. Information external to the sequence of characters currently being tokenized is being used to determine what tokens to recognize. >> I think... I mean, the thing >> about design philosophy, when you have several design philosophy rules, is >> that NONE of the rules get followed all the time. I think it'd be much >> more effective to say that one of the other rules won in this case than to >> try to convince people that a variable number of tokens occurring with no >> difference at all in the character stream is "explicit". > The character stream does have a difference. The character streams I was talking about don't. Character stream: tab tab tab "foo" newline tab "bar". This is, as you say, *usually* two dedents, but it could be one. Same exact stream of bytes, and yet the newline/tab may be either one or two dedents, or four if you're working on code where someone has been using four-space indents but someone happened to convert sets of eight spaces to tabs. > That difference depends on the context, My point exactly. Dedents are constructed from a combination of the current character stream and information about characters that could easily be hundreds of tokens back. That means that they are not explicit in the part of the character stream where they occur, but are implied by the combination of that stream of characters with the rest of the stream. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 00:28:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 04:28:08 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Chris Rebert wrote: > On Sun, Aug 14, 2011 at 6:54 PM, Steven D'Aprano > wrote: >> As a rule, chaining method calls risks violating the Law of Demeter. Just >> sayin'. > Not in the specific case of fluent interfaces[1] though, which could > have been what Seebach had in mind. They're the most obvious example, from my point of view. I tend to write stuff like foo.array_of_things.sort.map { block }.join(", ") I like this a lot more than array = foo.array_of_things sorted_array = array.sort() mapped_array = [block(x) for x in sorted_array] ", ".join(mapped_array) (I am still not used to Python's attachment of join to strings rather than to arrays. I don't really object to it, it's just not how I think about join operations.) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From tjreedy at udel.edu Mon Aug 15 00:40:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 00:40:51 -0400 Subject: Problem installing 3.2.1 on a Linux server In-Reply-To: References: Message-ID: On 8/14/2011 8:56 PM, John S James wrote: > Thanks, your reply helped. The problem seems to be the autoconfig -- I > was using version 2.59 instead of 2.68. However, the host will not let > users install 2.68. > > So I'm sending them feedback, suggesting a number of reasons for > supporting 3.2 for their server accounts, including: > > * Popularity of Python, TIOBE recognition; > * Wide consensus that new Python programmers should learn version 3, > unless they must maintain legacy software; > * 3.2 will be around for at least another year before 3.3 is released; > * Lack of 3.2 in low-cost hosts (3.1 is available) -- a competitive > advantage; > * 3.2 improves future library compatibility, vs. 3.1; A mountain of library improvement that could not go in 3.1. > * Installing 3.2 should not affect any existing customers, unless they > choose to use it. With 3.1 in security-fix only mode, the multiple fixes each day only go in 3.2 and 3.3. > We should explore why hosting services are resistant to supporting the > current version of Python (plus an important older version, 2.7). Other Seeing and occasionally participating in the development work to improve Python, such resistance makes me sad. Not their concern, of course, but depriving their customers is. > supported versions could be deprecated -- and eventually removed by the > ISPs, except for the few customers who choose to install it themselves. -- Terry Jan Reedy From christophechong at gmail.com Mon Aug 15 01:01:00 2011 From: christophechong at gmail.com (Christophe Chong) Date: Sun, 14 Aug 2011 22:01:00 -0700 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <9701DD3E-6E92-4EA6-A225-A37E0F9E1497@gmail.com> I can't tell which comments are sarcastic On Aug 14, 2011, at 18:35, rantingrick wrote: > On Aug 14, 5:01 pm, Dave Angel wrote: > >> Interesting that when you complain about other's grammatical typos, >> you're so careless with your own. >> >> know -> now >> i -> I >> accustom -> accustomed >> the this -> this >> >> I'm inclined to ignore typos in emails except in the case where the >> intent is to abuse others. > > My intent is NOT to abuse, but to enlighten. And you need to look up > the definition of typo because i am not complaining about typos. Typos > are accidents. Even the best of us suffer from accidents. > > What i AM complaining about is the adoption of a collectively foolish > consistency. "Used to" and "supposed to" is the verbiage of children > and idiots. I am trying to break these people out of such foolish > loops. You should be thanking me instead of trolling my posts. > -- > http://mail.python.org/mailman/listinfo/python-list From timr at probo.com Mon Aug 15 01:22:21 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 14 Aug 2011 22:22:21 -0700 Subject: allow line break at operators References: <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <87obzwh4o0.fsf@benfinney.id.au> <4e448471$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > >The only exception I can think of is *very* early Fortran, and that rightly >is considered a mistake. Fortran 77 used to treat whitespace as always >optional, so that in Python terms this: > >forxinrange(42) > >would be parsed as this: > >for x in range(42) Absolutely true, and that led to one of the more famous computing screw-ups in the early space program. The author intended to write this: DO 10 I=1,8 which, in Fortran, begins a loop that will run 8 times ending at the statement labeled "10". In this case, the author mistakenly typed a period instead of a comma: DO 10 I=1.8 That, unfortunately, is a perfectly valid statement that assigns the value "1.8" to the floating point variable "DO10I", supposedly resulting in the loss of an unmanned launch vehicle... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From saraanderson24 at gmail.com Mon Aug 15 02:21:35 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Sun, 14 Aug 2011 23:21:35 -0700 (PDT) Subject: Watch World`s Most Funniest Videos Ever. Message-ID: <567a6bb2-e3ee-4378-8cee-82a6b8c0d052@v9g2000pri.googlegroups.com> See Worlds Most Beautiful Places Ever. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH VERY VERY VERY FUNNY VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From rafadurancastaneda at gmail.com Mon Aug 15 02:58:52 2011 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Mon, 15 Aug 2011 08:58:52 +0200 Subject: same code to login,one is ok,another is not In-Reply-To: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4e486e9a$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: First one is using http and second one https, did you try an https handler? as I already pointed out to you in other thread with the same topic... Please don't spam the list, if you aren 't getting the answers you was looking for, wait for a while and then repost not just open threads until get the answer 2011/8/15 Steven D'Aprano > ???? wrote: > > > 1.http://www.renren.com/Login.do > > it is ok,my code: > [...] > > 2.https://passport.baidu.com/?login > > can't login,my code: > [...] > > Do you have a question, or are you just sharing the bad news? > > Websites may choose to respond to login attempts differently. Some may > require cookies, some may not. Some may check the referrer, some may not. > Some may look at the user agent, some may not. > > If the web developer of the site insists that you log in with a browser, or > Internet Explorer, you have to fight to convince the web server to let you > in. Many websites really try hard to prevent bots and scripts logging in. > The closer you can imitate what a real human being in a browser does, the > better the chances you can fool the server that you are a real human being > using a browser and not a bot. (Since your script *is* a bot, you may also > be in violation of the web site's terms of service.) > > Some web sites may even check how often you try to log in, or how fast. > > But what makes you think you can't log in? Given the response below, it > looks to me that you did log in, and got a blank page with some javascript > to redirect you to the real content page. (If you are a web developer and > you do this, I hate you.) But I may be wrong -- I'm not an expert on these > things. > > > > > > ??????????????? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 15 03:31:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 03:31:15 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/15/2011 12:28 AM, Seebs wrote: To repeat again: you are free to put in explicit dedent markers that will let you re-indent code should all indents be removed. -- Terry Jan Reedy From vipul.iiith at gmail.com Mon Aug 15 04:08:33 2011 From: vipul.iiith at gmail.com (Vipul Raheja) Date: Mon, 15 Aug 2011 13:38:33 +0530 Subject: Help needed with using SWIG wrapped code in Python Message-ID: Hi, I have wrapped a library from C++ to Python using SWIG. But I am facing problems while importing and using it in Python. $ python >>> import pyossimtest >>> import pyossim >>> a = ["Image1.png","Image2.png"] >>> b = pyossimtest.Info() >>> b.initialize(len(a),a) Traceback (most recent call last): File "", line 1, in File "pyossimtest.py", line 84, in initialize def initialize(self, *args): return _pyossimtest.Info_initialize(self, *args) TypeError: in method 'Info_initialize', argument 3 of type 'char *[]' What does this error message imply? I have already handled char** as a special case in swig using typemaps. Here is the code excerpt from the swig-generated .cxx file: SWIGINTERN PyObject *_wrap_Info_initialize(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; pyossimtest::Info *arg1 = (pyossimtest::Info *) 0 ; int arg2 ; char **arg3 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; bool result; if (!PyArg_ParseTuple(args,(char *)"OO:Info_initialize",&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_pyossimtest__Info, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Info_initialize" "', argument " "1"" of type '" "pyossimtest::Info *""'"); } arg1 = reinterpret_cast< pyossimtest::Info * >(argp1); { int i; if (!PyList_Check(obj1)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); return NULL; } arg2 = PyList_Size(obj1); arg3 = (char **) malloc((arg2+1)*sizeof(char *)); for (i = 0; i < arg2; i++) { PyObject *s = PyList_GetItem(obj1,i); if (!PyString_Check(s)) { free(arg3); PyErr_SetString(PyExc_ValueError, "List items must be strings"); return NULL; } arg3[i] = PyString_AsString(s); } arg3[i] = 0; } { try { result = (bool)(arg1)->initialize(arg2,arg3); } catch (const std::exception& e) { SWIG_exception(SWIG_RuntimeError, e.what()); } } resultobj = SWIG_From_bool(static_cast< bool >(result)); { if (arg3) free(arg3); } return resultobj; fail: { if (arg3) free(arg3); } return NULL; } Kindly help. Thanks and regards, Vipul Raheja -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 15 04:27:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 09:27:47 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 15, 2011 at 5:28 AM, Seebs wrote: > Character stream: ?tab tab tab "foo" newline tab "bar". ?This is, as you > say, *usually* two dedents, but it could be one. I see your point, though I cannot imagine anyone who would use "tab tab" as an indent level. But if you go from 16 spaces down to 8, it's possible that the script uses eight space indents, or four. On Mon, Aug 15, 2011 at 8:31 AM, Terry Reedy wrote: > To repeat again: you are free to put in explicit dedent markers that will > let you re-indent code should all indents be removed. > This would be a solution to the above, but it has the feeling of syntactic salt. (I don't believe that braces are, because they afford a different form of flexibility.) But sure, if you configure your editor to do it for you. I type: if (blah): It puts: if (blah): | # << if with the cursor at the | marker. I never really got used to editors doing this for me, though. It didn't feel right. I prefer an editor that deals with my indentation but lets me do the rest; when I hit enter, it autoindents to either the current indent level or one greater, depending on whether it "looks like" there ought to be an indent (which mainly happens when I put a loose { on a line). Similarly, when I put a } into the file, it removes an indent level automatically. Still, it wouldn't be hard to make an editor put those dedent comments in, if you want them. ChrisA From rosuav at gmail.com Mon Aug 15 04:32:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 09:32:28 +0100 Subject: pythonw.exe In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 3:14 AM, Dennis Lee Bieber wrote: > ? ? ? ?Depends... "DOS", to me, is just short for "Disk Operating > System"... I've source code (in a book) for K2FDOS, source code for > LS-DOS 6, and have used the AmigaDOS component of AmigaOS (granted -- > AmigaDOS technically was the part of the OS that gave access to the I/O > system, and included the command line interpreter...). > > ? ? ? ?"DOS" does not automatically mean "MicroSoft DOS"... I would say that DOS can, in a Windows context, mean either MS-DOS or a generic Disk Operating System. The latter sense is no more appropriate to the CLI than the former; in a modern OS, the part that truly "operates the disk" would be either the kernel or the hard disk driver, depending on your point of view, and neither of those has any sort of UI. > ? ? ? ?What most call "DOS" is, to me, merely a "command line interpreter" > (CLI). And that's really what we have. A shell. A CLI. A textual command parser (as opposed to a graphical action system which is what most GUIs are). It's more similar to a MUD than to an operating system - first space-separated word is a verb, everything else is modifiers. ChrisA From pwoolcoc at gmail.com Mon Aug 15 05:07:30 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Mon, 15 Aug 2011 05:07:30 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 14, 2011 3:24 PM, "Seebs" wrote: ... > > I'm not impressed by arguments based on "but if I do something stupid, like > > select text with my eyes closed and reindent it without looking, I expect > > the compiler to save my bacon". In my opinion, it's not the compiler's job > > to protect you from errors caused by sheer carelessness at the keyboard. > > I don't know about "sheer carelessness". Typos happen. Typos are not > something you can prevent from happening just by wanting it very much. > If you have valid code caused by improper indentation, shouldn't that be caught by a good set of unit tests? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Aug 15 05:33:28 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 11:33:28 +0200 Subject: surprising interaction between function scope and class namespace Message-ID: Hi, I just stumbled over this: >>> A = 1 >>> def foo(x): ... A = x ... class X: ... a = A ... return X ... >>> foo(2).a 2 >>> def foo(x): ... A = x ... class X: ... A = A ... return X ... >>> foo(2).A 1 Works that way in Py2.7 and Py3.3. I couldn't find any documentation on this, but my *guess* about the reasoning is that the second case contains an assignment to A inside of the class namespace, and assignments make a variable local to a scope, in this case, the function scope. Therefore, the A on the rhs is looked up in that scope as well. However, this is just a totally hand waving guess. Does anyone have a better explanation or know of a place where this specific behaviour is documented? Stefan From stefan_ml at behnel.de Mon Aug 15 05:50:58 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 11:50:58 +0200 Subject: surprising interaction between function scope and class namespace In-Reply-To: References: Message-ID: Stefan Behnel, 15.08.2011 11:33: > I just stumbled over this: > > >>> A = 1 > >>> def foo(x): > ... A = x > ... class X: > ... a = A > ... return X > ... > >>> foo(2).a > 2 > >>> def foo(x): > ... A = x > ... class X: > ... A = A > ... return X > ... > >>> foo(2).A > 1 > > Works that way in Py2.7 and Py3.3. > > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside of the > class namespace, and assignments make a variable local to a scope, in this > case, the function scope. Therefore, the A on the rhs is looked up in that > scope as well. However, this is just a totally hand waving guess. ... and an incorrect one, as it turns out. I think I misinterpreted the results the wrong way around. Still: > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? Stefan From stefan_ml at behnel.de Mon Aug 15 06:08:02 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Aug 2011 12:08:02 +0200 Subject: Help needed with using SWIG wrapped code in Python In-Reply-To: References: Message-ID: Vipul Raheja, 15.08.2011 10:08: > I have wrapped a library from C++ to Python using SWIG. But I am facing > problems while importing and using it in Python. > > $ python > >>> import pyossimtest > >>> import pyossim > >>> a = ["Image1.png","Image2.png"] > >>> b = pyossimtest.Info() > >>> b.initialize(len(a),a) > Traceback (most recent call last): > File "", line 1, in > File "pyossimtest.py", line 84, in initialize > def initialize(self, *args): return _pyossimtest.Info_initialize(self, > *args) > TypeError: in method 'Info_initialize', argument 3 of type 'char *[]' > > What does this error message imply? I have already handled char** as a > special case in swig using typemaps. I have little experience with SWIG, so I can't comment much on the problem at hand, but what I can do is to encourage you to use Cython instead. It's faster, easier to use and much more versatile for writing Python wrappers than SWIG. Basically, it provides you with the full power and flexibility of a programming language, whereas SWIG (like all automatic wrapper generators) is always limiting because it has its predefined ways of wrapping things, and if they don't fit, you're on your own fighting up-hill against it. Stefan From duncan.booth at invalid.invalid Mon Aug 15 06:18:03 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Aug 2011 10:18:03 GMT Subject: surprising interaction between function scope and class namespace References: Message-ID: Stefan Behnel wrote: > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside > of the class namespace, and assignments make a variable local to a > scope, in this case, the function scope. Therefore, the A on the rhs > is looked up in that scope as well. However, this is just a totally > hand waving guess. > > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? > If it was a function rather than a class then in the first case you look up the non-local variable as expected and in the second case you get an UnboundLocalError. The only difference with the class definition is that instead of UnboundLocalError the lookup falls back to the global scope. This happens because class definitions use LOAD_NAME/STORE_NAME instead of LOAD_FAST/STORE_FAST and LOAD_NAME looks first in local scope and then in global. I suspect that http://docs.python.org/reference/executionmodel.html#naming-and-binding should say something about this but it doesn't. -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Mon Aug 15 06:42:01 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Aug 2011 12:42:01 +0200 Subject: surprising interaction between function scope and class namespace References: Message-ID: Stefan Behnel wrote: > Hi, > > I just stumbled over this: > > >>> A = 1 > >>> def foo(x): > ... A = x > ... class X: > ... a = A > ... return X > ... > >>> foo(2).a > 2 > >>> def foo(x): > ... A = x > ... class X: > ... A = A > ... return X > ... > >>> foo(2).A > 1 That's subtle. > Works that way in Py2.7 and Py3.3. > > I couldn't find any documentation on this, but my *guess* about the > reasoning is that the second case contains an assignment to A inside of > the class namespace, and assignments make a variable local to a scope, in > this case, the function scope. Therefore, the A on the rhs is looked up in > that scope as well. However, this is just a totally hand waving guess. > Does anyone have a better explanation or know of a place where this > specific behaviour is documented? I think it's an implementation accident. Classes have a special opcode, LOAD_NAME, that allows for >>> x = 42 >>> class A: ... x = x ... >>> A.x 42 which would fail in a function >>> def f(): ... x = x ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced before assignment LOAD_NAME is pretty dumb, it looks into the local namespace and if that lookup fails falls back to the global namespace. Someone probably thought "I can do better", and reused the static name lookup for nested functions for names that occur only on the right-hand side of assignments in a class. Here's a slightly modified version of your demo: >>> x = "global" >>> def foo(): ... x = "local" ... class A: ... x = x ... return A ... >>> def bar(): ... x = "local" ... class A: ... y = x ... return A ... >>> foo().x 'global' >>> bar().y 'local' Now let's have a glimpse at the bytecode: >>> import dis >>> foo.func_code.co_consts (None, 'local', 'A', ", line 3>, ()) >>> dis.dis(foo.func_code.co_consts[3]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 4 6 LOAD_NAME 2 (x) 9 STORE_NAME 2 (x) 12 LOAD_LOCALS 13 RETURN_VALUE >>> bar.func_code.co_consts (None, 'local', 'A', ", line 3>, ()) >>> dis.dis(bar.func_code.co_consts[3]) 3 0 LOAD_NAME 0 (__name__) 3 STORE_NAME 1 (__module__) 4 6 LOAD_DEREF 0 (x) 9 STORE_NAME 2 (y) 12 LOAD_LOCALS 13 RETURN_VALUE From python.list at tim.thechases.com Mon Aug 15 07:40:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Aug 2011 06:40:10 -0500 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E49059A.60701@tim.thechases.com> On 08/14/2011 11:28 PM, Seebs wrote: > I tend to write stuff like > > foo.array_of_things.sort.map { block }.join(", ") > > I like this a lot more than > array = foo.array_of_things > sorted_array = array.sort() > mapped_array = [block(x) for x in sorted_array] > ", ".join(mapped_array) If you like the one-liner, this is readily written as ", ".join(block(x) for x in sorted(foo.array_of_things)) Modulo your gripes about string.join(), this is about as succinct (and more readable, IMHO) as your initial example. I've got piles of these sorts of things in my ETL code. -tkc From neilc at norwich.edu Mon Aug 15 08:06:31 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Aug 2011 12:06:31 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> Message-ID: <9asge7Fsv9U6@mid.individual.net> On 2011-08-14, Chris Angelico wrote: > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong wrote: >> On 14-8-2011 7:57, rantingrick wrote: >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." >>> more than ten times in a single post, you will get an invite to >>> Guido's next birthday party; where you'll be forced to do shots whist >>> walking the balcony railing wearing wooden shoes! >> >> I lolled about this one, e.g. I laughed out loud. But where >> are the tulips and windmills for extra credit? >> >> Greetings from a Dutchman! No credit. E.g., i.e., exampla gratis, means, "for example." -- Neil Cerutti From paddy3118 at googlemail.com Mon Aug 15 08:46:39 2011 From: paddy3118 at googlemail.com (Paddy) Date: Mon, 15 Aug 2011 05:46:39 -0700 (PDT) Subject: Wot! No Python? (Dynamic Languages Conference 2011, Edinburgh). Message-ID: <602a5feb-9d6b-4f11-8ffe-5f563758fad2@v3g2000vbx.googlegroups.com> http://www.dynamiclanguages.co.uk/dlc2011/ From philip at semanchuk.com Mon Aug 15 08:51:47 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 08:51:47 -0400 Subject: Help needed with using SWIG wrapped code in Python In-Reply-To: References: Message-ID: <5A1D8DCE-2E3F-48AD-81EE-D2967AC2C61E@semanchuk.com> On Aug 15, 2011, at 4:08 AM, Vipul Raheja wrote: > Hi, > > I have wrapped a library from C++ to Python using SWIG. But I am facing > problems while importing and using it in Python. Hi Vipul, Did you try asking about this on the SWIG mailing list? bye Philip From jhibschman+usenet at gmail.com Mon Aug 15 09:27:10 2011 From: jhibschman+usenet at gmail.com (Johann Hibschman) Date: Mon, 15 Aug 2011 08:27:10 -0500 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: Chris Angelico writes: > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. I'm a clearly a fool for allowing myself to be drawn into this thread, but I've been playing a lot recently with the APL-derivative language J, which uses a right-to-left operator precendence rule. Pragmatically, this is because J defines roughly a bajillion operators, and it would be impossible to remember the precendence of them all, but it makes sense in its own way. If you read "3 * 10 + 7", using right-to-left, you get "three times something". Then you read more and you get "three times (ten plus something)." And finally, you get "3*(10+7)". The prefix gives the continuation for the rest of the calculation; no matter what you substitute for X in "3*X", you will always just evaluate X, then multply it by 3. Likewise, for "3*10+X", no matter what X is, you know you'll add 10 and multiply by 3. This took me a while to get used to, but it's definitely a nice property. Not much to do with python, but I do like the syntax enough that I've implemented my own toy evaluator for J-like expressions in python, to get around the verbosity of some bits of numpy. Regards, Johann From steve+comp.lang.python at pearwood.info Mon Aug 15 09:30:26 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 15 Aug 2011 23:30:26 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > I tend to write stuff like > > foo.array_of_things.sort.map { block }.join(", ") > > I like this a lot more than > array = foo.array_of_things > sorted_array = array.sort() > mapped_array = [block(x) for x in sorted_array] > ", ".join(mapped_array) If you insist on a one-liner for four separate operations, what's wrong with this? ", ".join([block(x) for x in sorted(foo.array_of_things)]) Or if you prefer map: ", ".join(map(block, sorted(foo.array_of_things)) I think I would be less skeptical about fluent interfaces if they were written more like Unix shell script pipelines instead of using attribute access notation: foo.array_of_things | sort | map block | join ", " -- Steven From roy at panix.com Mon Aug 15 09:41:33 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 09:41:33 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. Computer programming languages follow math conventions only in the most vague ways. For example, standard math usage dictates that addition is commutative. While this is true for adding integers, it's certainly not true for adding strings (in any language which supports string addition). Where to draw the line between math and programming languages is not an easy question. > It would be far safer to go the other way > and demand parentheses on everything. Demand, no, but sometimes it's a good idea. I've been writing computer programs for close to 40 years, and I still have no clue what most of the order of operations is. It's just not worth investing the brain cells to remember such trivia (especially since the details change from language to language). Beyond remembering the (apparently) universal rule that {*, /} bind tighter than {+, -}, I pretty much just punt on everything else and put in extra parens everywhere. It's not the most efficient way to write code, and probably doesn't even result in the prettiest code. But it sure does eliminate those face-palm moments at the end of a long debugging session when you realize that somebody got it wrong. From rosuav at gmail.com Mon Aug 15 10:16:55 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 15:16:55 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Mon, Aug 15, 2011 at 2:41 PM, Roy Smith wrote: > Demand, no, but sometimes it's a good idea. ?I've been writing computer > programs for close to 40 years, and I still have no clue what most of > the order of operations is. ?It's just not worth investing the brain > cells to remember such trivia (especially since the details change from > language to language). ?Beyond remembering the (apparently) universal > rule that {*, /} bind tighter than {+, -}, I pretty much just punt on > everything else and put in extra parens everywhere. > Understandable. I go the other way, though, and keep an operator precedence table for each language handy; often, what I'm after is not "which one binds more tightly", but "what's the symbol for modulo", which is also (usually) on that same table. Or: "Blasted PHP, which operators have precedence between || and or?" which is easy to forget. And you're right about the details changing from language to language, hence the operators table *for each language*. But most languages follow fairly sane rules, and tend to come up with pretty much the same ordering. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 15 10:28:23 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 00:28:23 +1000 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > Computer programming languages follow math conventions only in the most > vague ways. ?For example, standard math usage dictates that addition is > commutative. ?While this is true for adding integers, it's certainly not > true for adding strings (in any language which supports string addition). Not quite true for maths either, at least in principle. I'm not aware of any number types where addition is non-commutative, but subtraction is noncommutative even for integers, and noncommutative multiplication is quite common (e.g. matrix multiplication). And of course, once you start using floating point numbers, you can't assume commutativity: >>> 0.1 + 0.7 + 0.3 == 0.3 + 0.7 + 0.1 False I'm reminded of this quote from John Baez: "The real numbers are the dependable breadwinner of the family, the complete ordered field we all rely on. The complex numbers are a slightly flashier but still respectable younger brother: not ordered, but algebraically complete. The quaternions, being noncommutative, are the eccentric cousin who is shunned at important family gatherings. But the octonions are the crazy old uncle nobody lets out of the attic: they are nonassociative." (And don't even ask about the sedenions...) -- Steven From rosuav at gmail.com Mon Aug 15 10:42:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 15:42:08 +0100 Subject: allow line break at operators In-Reply-To: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 15, 2011 at 3:28 PM, Steven D'Aprano wrote: > And of course, once you start using floating point numbers, you can't assume > commutativity: > >>>> 0.1 + 0.7 + 0.3 == 0.3 + 0.7 + 0.1 > False > This isn't because programming languages fail to follow mathematics; it's because floating point numbers do not represent real numbers. Python doesn't support substring removal using the subtraction operator, but I'd have to say that floats more closely parallel strings and other high level objects than they do mathematical reals. If Python treated __sub__(str,str) as str.replace(str,"") then: >>> "hello world" + "asdfqwer" - "d" "hello worlasfqwer" >>> "hello world" - "d" + "asdfqwer" "hello worlasdfqwer" Nobody would expect strings to behave mathematically with subtraction, because negatives don't make sense. Even sets don't quite work, although they're closer: >>> set("asdf")-set("test") {'a', 'd', 'f'} There's no way, in a set, to show a negative reference to 't' and 'e'. In theory you could do this with dictionaries or collections.Counter, but subtracting a Counter from a Counter doesn't produce negative numbers either. No, these constructs do not subtract algebraically, and I do not think it would be any improvement to the language if they did. ChrisA From artie.ziff at gmail.com Mon Aug 15 11:20:22 2011 From: artie.ziff at gmail.com (Artie Ziff) Date: Mon, 15 Aug 2011 08:20:22 -0700 Subject: string to unicode Message-ID: <4E493936.5030807@gmail.com> if I am using the standard csv library to read contents of a csv file which contains Unicode strings (short example: '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such as decode or encode to transform this string type into a python unicode type? Must I know the encoding (byte groupings) of the Unicode? Can I get this from the file? Perhaps I need to open the file with particular attributes? thanks! From awilliam at whitemice.org Mon Aug 15 11:29:43 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 15 Aug 2011 11:29:43 -0400 Subject: string to unicode In-Reply-To: <4E493936.5030807@gmail.com> References: <4E493936.5030807@gmail.com> Message-ID: <1313422183.3127.5.camel@linux-yu4c.site> On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: > if I am using the standard csv library to read contents of a csv file > which contains Unicode strings (short example: > '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such > as decode or encode to transform this string type into a python unicode > type? Must I know the encoding (byte groupings) of the Unicode? Can I > get this from the file? Perhaps I need to open the file with particular > attributes? Open the file with a codec and pass that file-like object to csv. codecs.open(filename, mode[, encoding[, errors[, buffering]]]) -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From rosuav at gmail.com Mon Aug 15 11:37:36 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 16:37:36 +0100 Subject: string to unicode In-Reply-To: <4E493936.5030807@gmail.com> References: <4E493936.5030807@gmail.com> Message-ID: On Mon, Aug 15, 2011 at 4:20 PM, Artie Ziff wrote: > if I am using the standard csv library to read contents of a csv file which > contains Unicode strings (short example: '\xe8\x9f\x92\xe8\x9b\x87'), how do > I use a python Unicode method such as decode or encode to transform this > string type into a python unicode type? Must I know the encoding (byte > groupings) of the Unicode? Can I get this from the file? Perhaps I need to > open the file with particular attributes? > Start here: http://www.joelonsoftware.com/articles/Unicode.html The CSV file, being stored on disk, cannot contain Unicode strings; it can only contain bytes. If you know the encoding (eg UTF-8, UCS-2, etc), then you can decode it using that. If you don't, your best bet is to ask the origin of the file; failing that, check the first few bytes - if it's "\xFF\xFE" or "\xFE\xFF" or "\xEF\xBB\xBF", then it's probably UTF-16LE, UTF-16BE, or UTF-8, respectively (those being the encodings of the BOM). There may be other clues, too, but normally it's best to get the encoding separately from the data rather than try to decode it from the data itself. Chris Angelico From dirk at xanthippe.ping.de Mon Aug 15 12:16:09 2011 From: dirk at xanthippe.ping.de (Dirk Olmes) Date: Mon, 15 Aug 2011 16:16:09 +0000 (UTC) Subject: Java is killing me! (AKA: Java for Pythonheads?) References: Message-ID: On Fri, 12 Aug 2011 17:02:38 +0000, kj wrote: > *Please* forgive me for asking a Java question in a Python forum. My > only excuse for this no-no is that a Python forum is more likely than a > Java one to have among its readers those who have had to deal with the > same problems I'm wrestling with. > > Due to my job, I have to port some Python code to Java, and write tests > for the ported code. (Yes, I've considered finding myself another job, > but this is not an option in the immediate future.) Can't you sidestep the porting effort and try to run everything in Jython on the JVM? -dirk (Python lurker with Java experience) From lukius at gmail.com Mon Aug 15 12:18:35 2011 From: lukius at gmail.com (Lucio Santi) Date: Mon, 15 Aug 2011 13:18:35 -0300 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9asge7Fsv9U6@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti wrote: > On 2011-08-14, Chris Angelico wrote: > > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong > wrote: > >> On 14-8-2011 7:57, rantingrick wrote: > >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." > >>> more than ten times in a single post, you will get an invite to > >>> Guido's next birthday party; where you'll be forced to do shots whist > >>> walking the balcony railing wearing wooden shoes! > >> > >> I lolled about this one, e.g. I laughed out loud. But where > >> are the tulips and windmills for extra credit? > >> > >> Greetings from a Dutchman! > > No credit. E.g., i.e., exampla gratis, means, "for example." > The correct spelling is 'exempli gratia'. It's Latin. i.e., on the other hand, comes from 'id est' ('that is'). Latin too. Regards, Lucio -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Aug 15 12:32:07 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 16:32:07 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-15, Steven D'Aprano wrote: > Seebs wrote: >> I tend to write stuff like >> >> foo.array_of_things.sort.map { block }.join(", ") >> >> I like this a lot more than >> array = foo.array_of_things >> sorted_array = array.sort() >> mapped_array = [block(x) for x in sorted_array] >> ", ".join(mapped_array) > If you insist on a one-liner for four separate operations, what's wrong with > this? > ", ".join([block(x) for x in sorted(foo.array_of_things)]) Nothing in particular; I was just contrasting two styles, not asserting that Python couldn't do that. In general, I don't like to do things that either involve making a lot of variables that are assigned to once and then read from once, or making a whole lot of x = foo(x) type assignments to one variable. It feels cluttered to me. > I think I would be less skeptical about fluent interfaces if they were > written more like Unix shell script pipelines instead of using attribute > access notation: > foo.array_of_things | sort | map block | join ", " Interesting! I think that's probably why I find them so comfortable; shell was one of the first languages I got serious about. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Mon Aug 15 12:32:07 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 16:32:07 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On 2011-08-15, Roy Smith wrote: > Demand, no, but sometimes it's a good idea. I've been writing computer > programs for close to 40 years, and I still have no clue what most of > the order of operations is. It's just not worth investing the brain > cells to remember such trivia (especially since the details change from > language to language). Beyond remembering the (apparently) universal > rule that {*, /} bind tighter than {+, -}, I pretty much just punt on > everything else and put in extra parens everywhere. > > It's not the most efficient way to write code, and probably doesn't even > result in the prettiest code. But it sure does eliminate those > face-palm moments at the end of a long debugging session when you > realize that somebody got it wrong. Wholehearted agreement. It is conceivable for me to misremember precedence. I am pretty reliable at recognizing which things are in which parens. So I use them even in obvious cases: foo + (3 * 4) Never regretted that. Yes, it's extra typing, a little, but it prevents a whole category of bugs. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From python at mrabarnett.plus.com Mon Aug 15 12:44:15 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Aug 2011 17:44:15 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: <4E494CDF.8040706@mrabarnett.plus.com> On 15/08/2011 17:18, Lucio Santi wrote: > > > On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti > wrote: > > On 2011-08-14, Chris Angelico > wrote: > > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong > > wrote: > >> On 14-8-2011 7:57, rantingrick wrote: > >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use > "e.g." > >>> more than ten times in a single post, you will get an invite to > >>> Guido's next birthday party; where you'll be forced to do shots > whist > >>> walking the balcony railing wearing wooden shoes! > >> > >> I lolled about this one, e.g. I laughed out loud. But where > >> are the tulips and windmills for extra credit? > >> > >> Greetings from a Dutchman! > > No credit. E.g., i.e., exampla gratis, means, "for example." > > > The correct spelling is 'exempli gratia'. It's Latin. > > i.e., on the other hand, comes from 'id est' ('that is'). Latin too. > I remember reading a book about polymorphism in programming. The author said it came from Latin. Nope. From neilc at norwich.edu Mon Aug 15 13:14:27 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Aug 2011 17:14:27 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> Message-ID: <9at2fjF20mU1@mid.individual.net> On 2011-08-15, MRAB wrote: > On 15/08/2011 17:18, Lucio Santi wrote: >> On Mon, Aug 15, 2011 at 9:06 AM, Neil Cerutti > > wrote: >> >> On 2011-08-14, Chris Angelico > > wrote: >> > On Sun, Aug 14, 2011 at 2:21 PM, Irmen de Jong >> > wrote: >> >> On 14-8-2011 7:57, rantingrick wrote: >> >>> 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use >> "e.g." >> >>> more than ten times in a single post, you will get an invite to >> >>> Guido's next birthday party; where you'll be forced to do shots >> whist >> >>> walking the balcony railing wearing wooden shoes! >> >> >> >> I lolled about this one, e.g. I laughed out loud. But where >> >> are the tulips and windmills for extra credit? >> >> >> >> Greetings from a Dutchman! >> >> No credit. E.g., i.e., exampla gratis, means, "for example." >> >> >> The correct spelling is 'exempli gratia'. It's Latin. Thanks for the correction. >> i.e., on the other hand, comes from 'id est' ('that is'). >> Latin too. > > I remember reading a book about polymorphism in programming. > The author said it came from Latin. Nope. Sounds more like Greek. -- Neil Cerutti From python at bdurham.com Mon Aug 15 13:51:07 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Aug 2011 13:51:07 -0400 Subject: Reusable ways to wrapping thread locking techniques Message-ID: <1313430667.15383.140258129883089@webmail.messagingengine.com> I'm reviewing a lot of code that has thread acquire and release locks scattered throughout the code base. Would a better technique be to use -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Aug 15 13:56:06 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Aug 2011 13:56:06 -0400 Subject: Reusable ways to wrapping thread locking techniques In-Reply-To: <1313430667.15383.140258129883089@webmail.messagingengine.com> References: <1313430667.15383.140258129883089@webmail.messagingengine.com> Message-ID: <1313430966.16911.140258129884193@webmail.messagingengine.com> Hit send too soon ... I'm reviewing a lot of code that has thread acquire and release locks scattered throughout the code base. Would a better technique be to use contextmanagers (for safe granular locking within a function) or decorators (function wide locks) to manage locks or am I making things too complicated? Am I reinventing the wheel by creating my own versions of above or are there off-the-shelf, debugged versions of above that one can use? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Aug 15 14:29:40 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Aug 2011 14:29:40 -0400 Subject: string to unicode In-Reply-To: <1313422183.3127.5.camel@linux-yu4c.site> References: <4E493936.5030807@gmail.com> <1313422183.3127.5.camel@linux-yu4c.site> Message-ID: On 8/15/2011 11:29 AM, Adam Tauno Williams wrote: > On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: >> if I am using the standard csv library to read contents of a csv file >> which contains Unicode strings (short example: >> '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such >> as decode or encode to transform this string type into a python unicode >> type? Must I know the encoding (byte groupings) of the Unicode? Can I >> get this from the file? Perhaps I need to open the file with particular >> attributes? > > Open the file with a codec and pass that file-like object to csv. > > codecs.open(filename, mode[, encoding[, errors[, buffering]]]) > > In Python 3, just open with open(... encoding = 'xxx') -- Terry Jan Reedy From artur at ergashev.com Mon Aug 15 15:10:22 2011 From: artur at ergashev.com (Artur Ergashev) Date: Mon, 15 Aug 2011 12:10:22 -0700 (PDT) Subject: datetime.strptime w/ non-UTC and non-local TZs? Message-ID: <09311a25-deec-4357-b9de-26ddf70aa2cc@v3g2000vbx.googlegroups.com> I was hoping somebody give me some clarity on how datetime.strptime is supposed to work, I'm thinking this is a bug, but wanted to see if the community has any ideas before I submit a bug to the python tracker. For reference I am in the CDT timezone... >>> from datetime import datetime >>> date_utc = "Sun Jul 24 02:54:11 UTC 2011" >>> date_local = "Sun Jul 24 02:54:11 CDT 2011" >>> date_other = "Sun Jul 24 02:54:11 PDT 2011" >>> print datetime.strptime(date_utc, '%a %b %d %H:%M:%S %Z %Y') 2011-07-24 02:54:11 >>> print datetime.strptime(date_local, '%a %b %d %H:%M:%S %Z %Y') 2011-07-24 02:54:11 >>> print datetime.strptime(date_other, '%a %b %d %H:%M:%S %Z %Y') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/_strptime.py", line 325, in _strptime (data_string, format)) ValueError: time data 'Sun Jul 24 02:54:11 PDT 2011' does not match format '%a %b %d %H:%M:%S %Z %Y' The format is correct, and it can parse UTC (as mentioned in the documentation), and it can parse CDT (which is my current time zone), but using another timezone causes it to fail. Trying to parse the failing timezone on a computer set on that timezone works correctly. The documentation seems to indicate that parsing non-UTC TZs isn't guaranteed to work, but in that case the exception is non-clear (perhaps there's no elegant solution here). From PointedEars at web.de Mon Aug 15 15:37:18 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Mon, 15 Aug 2011 21:37:18 +0200 Subject: string to unicode References: <4E493936.5030807@gmail.com> Message-ID: <21539106.hDsTRIgEHo@PointedEars.de> Chris Angelico wrote: > On Mon, Aug 15, 2011 at 4:20 PM, Artie Ziff wrote: >> if I am using the standard csv library to read contents of a csv file >> which contains Unicode strings (short example: >> '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such as >> decode or encode to transform this string type into a python unicode >> type? Must I know the encoding (byte groupings) of the Unicode? Can I get >> this from the file? Perhaps I need to open the file with particular >> attributes? > > Start here: > > http://www.joelonsoftware.com/articles/Unicode.html > > The CSV file, being stored on disk, cannot contain Unicode strings; it > can only contain bytes. If you know the encoding (eg UTF-8, UCS-2, > etc), then you can decode it using that. If you don't, your best bet > is to ask the origin of the file; failing that, check the first few > bytes - if it's "\xFF\xFE" or "\xFE\xFF" or "\xEF\xBB\xBF", then it's > probably UTF-16LE, UTF-16BE, or UTF-8, respectively (those being the > encodings of the BOM). There may be other clues, too, but normally > it's best to get the encoding separately from the data rather than try > to decode it from the data itself. As this problem really is not a new one, there are several more ? if I may say so ? pythonic approaches: Improving Billy Mays' "matching brackets" checker, chardet worked for me (the test file was UTF-8-encoded). Watch for word-wrap: ----------------------------------------------------------------------- # encoding: utf-8 ''' Created on 2011-07-18 @author: Thomas 'PointedEars' Lahn , based on an idea of Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6 at myhashismyemail.com> in ''' import sys, os, chardet pairs = {u'}': u'{', u')': u'(', u']': u'[', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?', u'?': u'?'} valid = set(v for pair in pairs.items() for v in pair) if __name__ == '__main__': for dirpath, dirnames, filenames in os.walk(sys.argv[1]): for name in filenames: stack = [' '] file_path = os.path.join(dirpath, name) with open(file_path, 'rb') as f: reported = False lines = enumerate(f, 1) encoding = chardet.detect(''.join(map(lambda x: x[1], lines)))['encoding'] chars = ((c, line_no, col) for line_no, line in lines for col, c in enumerate(line.decode(encoding), 1) if c in valid) for c, line_no, col in chars: if c in pairs: if stack[-1] == pairs[c]: stack.pop() else: if not reported: first_bad = (c, line_no, col) reported = True else: stack.append(c) print '%s: %s' % (name, ("good" if len(stack) == 1 else "bad '%s' at %s:%s" % first_bad)) ----------------------------------------------------------------------- HTH -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rantingrick at gmail.com Mon Aug 15 17:21:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 14:21:24 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <779fe0b7-bb06-4bbe-8469-9b846f764a60@x2g2000yql.googlegroups.com> On Aug 15, 2:31?am, Terry Reedy wrote: > On 8/15/2011 12:28 AM, Seebs wrote: > > To repeat again: you are free to put in explicit dedent markers that > will let you re-indent code should all indents be removed. As Terry has been trying to say for a while now, use the following methods to quell your eye pain. ------------------------------------------------------------ Use pass statement: ------------------------------------------------------------ if foo: if bar: baz else: pass else: quux ------------------------------------------------------------ Use comments: ------------------------------------------------------------ if foo: if bar: baz #else bar (or endif or whatever you like) else: quux ------------------------------------------------------------ Use road signs: :-) ------------------------------------------------------------ # [Warning: Curves Ahead: Eyeball Parse limit 35 WPM!] if foo: # [Exit 266: "foo"] --> # [Right Curve Ahead: slow eyeball parsing to 15 WPM!] if bar: baz else: pass # <-- [Warning: Do not litter!] else: # [Exit 267: "Not Foo"] --> # [Right Curve Ahead: slow eyeball parsing to 15 WPM!] quux ... # [Eyeball Parse limit 55 WPM!] ... # [PSA: Friends don't let friends write asinine code] ... # [Next Rest Stop: NEVER!] ------------------------------------------------------------ Now you have the nice triangular shape that your eyes have been trained to recognize! I would suggest to use comments whenever possible. Of course there will be times when you cannot use a comment and must use an else clause. Now you have nothing to complain about :). From grickert at coldstorage.com Mon Aug 15 17:52:05 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Mon, 15 Aug 2011 17:52:05 -0400 Subject: Why no warnings when re-assigning builtin names? Message-ID: With surprising regularity, I see program postings (eg. on StackOverflow) from inexperienced Python users accidentally re-assigning built-in names. For example, they'll innocently call some variable, "list", and assign a list of items to it. ...and if they're _unlucky_ enough, their program may actually work (encouraging them to re-use this name in other programs). If they try to use an actual keyword, both the interpreter and compiler are helpful enough to give them a syntax error, but I think the builtins should be "pseudo-reserved", and a user should explicitly have to do something *extra* to not receive a warning. I'd suggest: "from __future__ import allow_reassigning_builtins", but I think this abuse of the __future__ module likely isn't welcome. I know that for testing purposes, this functionality is very convenient, and I'm not suggesting it be removed. In these cases, it would be trivial to just require something explicit, telling the interpreter that the programmer was aware they were assigning to a builtin name. The situation is slightly different for modules that come with Python. Most of us would cringe when seeing something like: `string = "Some string"`; but at least the user has to explicitly import the string module for this to actually cause issues (other than readability). What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? Regards, Gerrat -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Aug 15 18:13:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 18:13:02 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <82392F42-1136-46F5-ACD7-618D7E21781A@semanchuk.com> On Aug 15, 2011, at 5:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on > StackOverflow) from inexperienced Python users accidentally > re-assigning built-in names. > > > > For example, they'll innocently call some variable, "list", and assign a > list of items to it. > > ...and if they're _unlucky_ enough, their program may actually work > (encouraging them to re-use this name in other programs). Or they'll assign a class instance to 'object', only to cause weird errors later when they use it as a base class. I agree that this is a problem. The folks on my project who are new-ish to Python overwrite builtins fairly often. Since there's never been any consequence other than my my vague warnings that something bad might happen as a result, it's difficult for them to develop good habits in this regard. It doesn't help that Eclipse (their editor of choice) doesn't seem to provide a way of coloring builtins differently. (That's what I'm told, anyway. I don't use it.) > If they try to use an actual keyword, both the interpreter and compiler > are helpful enough to give them a syntax error, but I think the builtins > should be "pseudo-reserved", and a user should explicitly have to do > something *extra* to not receive a warning. Unfortunately you're suggesting a change to the language which could break existing code. I could see a use for "from __future__ import squawk_if_i_reassign_a_builtin" or something like that, but the current default behavior has to remain as it is. JMO, Philip From rosuav at gmail.com Mon Aug 15 18:15:01 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Aug 2011 23:15:01 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on StackOverflow) > from inexperienced Python users ?accidentally re-assigning built-in names. > > For example, they?ll innocently call some variable, ?list?, and assign a > list of items to it. It's actually masking, not reassigning. That may make it easier or harder to resolve the issue. If you want a future directive that deals with it, I'd do it the other way - from __future__ import mask_builtin_warning or something - so the default remains as it currently is. But this may be a better job for a linting script. ChrisA From usenet-nospam at seebs.net Mon Aug 15 18:33:30 2011 From: usenet-nospam at seebs.net (Seebs) Date: 15 Aug 2011 22:33:30 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: On 2011-08-15, Ethan Furman wrote: > Gerrat Rickert wrote: >> What sayest the Python community about having an explicit warning >> against such un-pythonic behaviour (re-assigning builtin names)? > What makes you think this behavior is unpythonic? Python is not about > hand-holding. It seems like something which is sufficiently likely to be a mistake might deserve a warning -- especially since, so far as I can tell, there's never going to be a program which can't easily be written to avoid the problematic behavior. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Mon Aug 15 18:34:51 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 15 Aug 2011 15:34:51 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <4E499F0B.30900@stoneleaf.us> Gerrat Rickert wrote: > What sayest the Python community about having an explicit warning > against such un-pythonic behaviour (re-assigning builtin names)? What makes you think this behavior is unpythonic? Python is not about hand-holding. ~Ethan~ From benjamin.kaplan at case.edu Mon Aug 15 18:52:42 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Aug 2011 18:52:42 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Aug 15, 2011 5:56 PM, "Gerrat Rickert" wrote: > > With surprising regularity, I see program postings (eg. on StackOverflow) from inexperienced Python users accidentally re-assigning built-in names. > > > > For example, they?ll innocently call some variable, ?list?, and assign a list of items to it. > > ...and if they?re _unlucky_ enough, their program may actually work (encouraging them to re-use this name in other programs). > > > > If they try to use an actual keyword, both the interpreter and compiler are helpful enough to give them a syntax error, but I think the builtins should be ?pseudo-reserved?, and a user should explicitly have to do something *extra* ... > > > What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? > One of Python's greatest strength's in my opinion is that it strives for consistency. As much as possible, Python avoids differentiating between built-in objects (types or otherwise) and user-defined objects. I think it should stay that way. There are tools that can detect these errors and their use should be encouraged, but the Python interpreter shouldn't single out variables which are types that happen to be built-in from any other variable or any other type. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Aug 15 19:12:07 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 15 Aug 2011 16:12:07 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: <4E49A7C7.5090701@stoneleaf.us> Seebs wrote: > On 2011-08-15, Ethan Furman wrote: >> Gerrat Rickert wrote: >>> What sayest the Python community about having an explicit warning >>> against such un-pythonic behaviour (re-assigning builtin names)? > >> What makes you think this behavior is unpythonic? Python is not about >> hand-holding. > > It seems like something which is sufficiently likely to be a mistake might > deserve a warning -- especially since, so far as I can tell, there's never > going to be a program which can't easily be written to avoid the problematic > behavior. "sufficiently likely" depends entirely on who is doing the coding. I use `open()` for opening my files, and so regularly use `file` as a name. It can also be very handy to mask a built-in when doing something even more fun and entertaining and I, for one, have zero desire to have Python start warning me about perfectly legitimate code. Programmers need to learn whichever language they are choosing to code in, and if extra help is needed beyond whatever is basic for that language, find (or write! ;) the third-party tool to help out. There are at least two linters for Python, and multiple IDEs that can help with these, and other, problems. (I don't much care for IDEs, but I am thinking of starting to use a linter, myself.) ~Ethan~ From dajo.mail at web.de Mon Aug 15 19:26:54 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 01:26:54 +0200 Subject: testing if a list contains a sublist Message-ID: <4E49AB3E.9000801@web.de> hi list, what is the best way to check if a given list (lets call it l1) is totally contained in a second list (l2)? for example: l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 my problem is the second example, which makes it impossible to work with sets insteads of lists. But something like set.issubset for lists would be nice. greatz Johannes From drsalists at gmail.com Mon Aug 15 19:32:53 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 15 Aug 2011 16:32:53 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: Message-ID: On Mon, Aug 15, 2011 at 2:52 PM, Gerrat Rickert wrote: > With surprising regularity, I see program postings (eg. on StackOverflow) > from inexperienced Python users accidentally re-assigning built-in names. > http://pypi.python.org/pypi/pylint checks for this and many other issues. I don't know if pyflakes or pychecker do. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Mon Aug 15 19:37:21 2011 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 16 Aug 2011 09:37:21 +1000 Subject: Reusable ways to wrapping thread locking techniques In-Reply-To: <1313430966.16911.140258129884193@webmail.messagingengine.com> References: <1313430966.16911.140258129884193@webmail.messagingengine.com> Message-ID: <20110815233720.GA30163@cskk.homeip.net> On 15Aug2011 13:56, python at bdurham.com wrote: | I'm reviewing a lot of code that has thread acquire and release | locks scattered throughout the code base. | | Would a better technique be to use contextmanagers (for safe | granular locking within a function) or decorators (function wide | locks) to manage locks or am I making things too complicated? No, you're on the money. | Am I reinventing the wheel by creating my own versions of above | or are there off-the-shelf, debugged versions of above that one | can use? I routinely have: some_lock = allocate_lock() ... with some_lock: code here! Doing the equivalent with decorators to make monitors seems perfectly reasonable to me too. Do it all with context managers if you can; they do reliable lock release even when an exception occurs, and don't clutter the code with distracting and hard to verify cleanup code. It's worth it just to make everything more readable. The fact that it makes the code smaller and easier to maintain and less bug prone is just sugar. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ My mind is like a blotter: Soaks it up, gets it backwards. From drsalists at gmail.com Mon Aug 15 19:38:51 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 15 Aug 2011 16:38:51 -0700 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: Check out collections.Counter if you have 2.7 or up. If you don't, google for multiset or bag types. On Mon, Aug 15, 2011 at 4:26 PM, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Aug 15 20:10:21 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 00:10:21 +0000 (UTC) Subject: Data issues with Django and Apache References: Message-ID: In John Gordon writes: > The problem is that I get conflicting results as to whether these temporary > records have reached their expiration date, depending if I search for them > via an Apache web call or if I do the search locally from a python shell. > And to make it weirder, the conflicts go away if I stop and restart the > Apache server, although any new records created after this point will still > exhibit the issue. The problem turned out to be a class variable that contained a time filter with the "current" time. But since it was a class variable, it was only evaluated once upon import and its idea of "now" was forever frozen at that moment, so it always compared as being less than any of the lock records that were passed in. I changed it to be a class method that constructs and returns a new time filter whenever it is called. Thanks for everyone's help! -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From roy at panix.com Mon Aug 15 20:30:53 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:30:53 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e492d08$0$30003$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I'm reminded of this quote from John Baez: > > "The real numbers are the dependable breadwinner of the family, the complete > ordered field we all rely on. The complex numbers are a slightly flashier > but still respectable younger brother: not ordered, but algebraically > complete. The quaternions, being noncommutative, are the eccentric cousin > who is shunned at important family gatherings. But the octonions are the > crazy old uncle nobody lets out of the attic: they are nonassociative." Wow, at first glance, I mis-parsed that name as "Joan Baez". Had me really confused for a moment. From roy at panix.com Mon Aug 15 20:34:03 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:34:03 -0400 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Or: "Blasted PHP, which > operators have precedence between || and or?" which is easy to forget. > > And you're right about the details changing from language to language, > hence the operators table *for each language*. But most languages > follow fairly sane rules How dare you use the words "PHP" and "sane" in two adjoining paragraphs! From rosuav at gmail.com Mon Aug 15 20:37:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 01:37:21 +0100 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> Message-ID: On Tue, Aug 16, 2011 at 1:34 AM, Roy Smith wrote: > In article , > ?Chris Angelico wrote: > >> Or: "Blasted PHP, which >> operators have precedence between || and or?" which is easy to forget. >> >> And you're right about the details changing from language to language, >> hence the operators table *for each language*. But most languages >> follow fairly sane rules > > How dare you use the words "PHP" and "sane" in two adjoining paragraphs! By separating them with the word "most". ChrisA From usenet-nospam at seebs.net Mon Aug 15 20:39:34 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 00:39:34 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-16, Roy Smith wrote: > In article <4e492d08$0$30003$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: >> I'm reminded of this quote from John Baez: >> "The real numbers are the dependable breadwinner of the family, the complete >> ordered field we all rely on. The complex numbers are a slightly flashier >> but still respectable younger brother: not ordered, but algebraically >> complete. The quaternions, being noncommutative, are the eccentric cousin >> who is shunned at important family gatherings. But the octonions are the >> crazy old uncle nobody lets out of the attic: they are nonassociative." > Wow, at first glance, I mis-parsed that name as "Joan Baez". Had me > really confused for a moment. Would it have been that much weirder than Hedy Lamarr? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From greg.ewing at canterbury.ac.nz Mon Aug 15 20:43:57 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:43:57 +1200 Subject: allow line break at operators In-Reply-To: <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e492d08$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9atsqeF442U1@mid.individual.net> Steven D'Aprano wrote: > I'm reminded of this quote from John Baez: > > "...But the octonions are the > crazy old uncle nobody lets out of the attic: they are nonassociative." > > (And don't even ask about the sedenions...) Aren't they the ones that mutilate cattle and abduct people? -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 15 20:48:08 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:48:08 +1200 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> Message-ID: <9att2bF710U1@mid.individual.net> rantingrick wrote: > "Used to" and "supposed to" is the verbiage of children > and idiots. So when we reach a certain age we're meant to abandon short, concise and idomatic ways of speaking, and substitute long words and phrases to make ourselves sound adult and educated? -- Greg From greg.ewing at canterbury.ac.nz Mon Aug 15 20:52:06 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 12:52:06 +1200 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9at2fjF20mU1@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> Message-ID: <9att9mF710U2@mid.individual.net> I don't mind people using e.g. and i.e. as long as they use them *correctly*. Many times people use i.e. when they really mean e.g. -- Greg From roy at panix.com Mon Aug 15 20:53:13 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:53:13 -0400 Subject: testing if a list contains a sublist References: Message-ID: In article , Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes import re def sublist(l1, l2): s1 = ''.join(map(str, l1)) s2 = ''.join(map(str, l2)) return re.search(s1, s2) assert sublist([1,2], [1,2,3,4,5]) assert not sublist ([1,2,2], [1,2,3,4,5]) assert not sublist([1,2,3], [1,3,5,7]) (running and ducking) From roy at panix.com Mon Aug 15 20:57:16 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 20:57:16 -0400 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: In article <9att2bF710U1 at mid.individual.net>, Gregory Ewing wrote: > rantingrick wrote: > > "Used to" and "supposed to" is the verbiage of children > > and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Yup. From greg.ewing at canterbury.ac.nz Mon Aug 15 21:08:36 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 16 Aug 2011 13:08:36 +1200 Subject: surprising interaction between function scope and class namespace In-Reply-To: References: Message-ID: <9atu8nFebsU1@mid.individual.net> Peter Otten wrote: > LOAD_NAME is pretty dumb, it looks into the local namespace and if that > lookup fails falls back to the global namespace. Someone probably thought "I > can do better", and reused the static name lookup for nested functions for > names that occur only on the right-hand side of assignments in a class. I doubt that it was a conscious decision -- it just falls out of the way the compiler looks up names in its symbol table. In case 1, the compiler finds the name 'a' in the function's local namespace and generates a LOAD_FAST opcode, because that's what it does for all function-local names. In case 2, it finds it in the local namespace of the class and generates LOAD_NAME, because that's what it does for all class-local names. The weirdness arises because classes make use of vestiges of the old two-namespace system, which bypasses lexical scoping at run time. -- Greg From rantingrick at gmail.com Mon Aug 15 21:12:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 18:12:53 -0700 (PDT) Subject: Why no warnings when re-assigning builtin names? References: Message-ID: <3ac58c4a-d9cf-454d-94cf-6575aec0912e@j1g2000yqn.googlegroups.com> On Aug 15, 5:13?pm, Philip Semanchuk wrote: > On Aug 15, 2011, at 5:52 PM, Gerrat Rickert wrote: > > > With surprising regularity, I see program postings (eg. on > > StackOverflow) from inexperienced Python users ?accidentally > > re-assigning built-in names. > > > For example, they'll innocently call some variable, "list", and assign a > > list of items to it. > > > ...and if they're _unlucky_ enough, their program may actually work > > (encouraging them to re-use this name in other programs). > > Or they'll assign a class instance to 'object', only to cause weird errors later when they use it as a base class. > > I agree that this is a problem. The folks on my project who are new-ish to Python overwrite builtins fairly often. Simple syntax hilighting can head off these issues with great ease. Heck, python even has a keyword module, and you get a list of built- ins from the dir() function! import keyword import __builtin__ PY_BUILTINS = [str(name) for name in dir(__builtin__) if not name.startswith('_')] PY_KEYWORDS = keyword.kwlist Also Python ships with IDLE (which is a simplistic IDE) and although i find it needs a bit of work to be what GvR initially dreamed, it works good enough to get you by. I always say, you must use the correct tool for the job, and syntax hilight is a "must have" to avoid these accidents. From chris at simplistix.co.uk Mon Aug 15 21:21:33 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 16 Aug 2011 02:21:33 +0100 Subject: TestFixtures 1.12.0 Released! Message-ID: <4E49C61D.7070909@simplistix.co.uk> Hi All, I'm happy to announce a new release of TestFixtures with the following changes: - OutputCapture has grown a `captured` property and can now be temporarily disabled using their`disable` method: http://packages.python.org/testfixtures/streams.html - Logging can now be captured only when it exceeds a specified logging level: http://packages.python.org/testfixtures/logging.html#only-capturing-specific-logging - The handling of timezones has been reworked in both `test_datetime` and `test_time`. This is not backwards compatible but is much more useful and correct: http://packages.python.org/testfixtures/datetime.html#timezones The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve+comp.lang.python at pearwood.info Mon Aug 15 21:32:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 11:32:09 +1000 Subject: Why no warnings when re-assigning builtin names? References: Message-ID: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert > wrote: >> With surprising regularity, I see program postings (eg. on StackOverflow) >> from inexperienced Python users ?accidentally re-assigning built-in >> names. >> >> For example, they?ll innocently call some variable, ?list?, and assign a >> list of items to it. > > It's actually masking, not reassigning. That may make it easier or > harder to resolve the issue. The usual term is "shadowing builtins", and it's a feature, not a bug :) > If you want a future directive that deals with it, I'd do it the other > way - from __future__ import mask_builtin_warning or something - so > the default remains as it currently is. But this may be a better job > for a linting script. Agreed. It's a style issue, nothing else. There's nothing worse about: def spam(list): pass compared to class thingy: pass def spam(thingy): pass Why should built-ins be treated as more sacred than your own objects? -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 15 21:53:42 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 11:53:42 +1000 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: <4e49cda7$0$30004$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 10:48 am Gregory Ewing wrote: > rantingrick wrote: >> "Used to" and "supposed to" is the verbiage of children >> and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Say what? "Used to" isn't idiom. It is grammatical English. Avoidance of "used to" is a hyper-correction done by people who don't know as much about English as they think, like "the grammar policeman let Johnny and I off with a warning", perhaps the most widespread hyper-correction in English. (If you take Johnny out of the picture, the policeman let I off with a warning... which is obviously wrong. Whether Johnny was there or not, the policeman let *me* off with a warning.) "Used to" is unexceptional English: http://www.englishpage.com/verbpage/usedto.html http://www.bbc.co.uk/worldservice/learningenglish/youmeus/quiznet/newquiz114.shtml http://www.englishclub.com/grammar/verbs-m_used-to-do.htm http://www.learnenglish.de/grammar/usedtotext2.htm Any-grammatical-errors-are-deliberate-ly y'rs, -- Steven From python at mrabarnett.plus.com Mon Aug 15 21:59:42 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 02:59:42 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <9att9mF710U2@mid.individual.net> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: <4E49CF0E.3010706@mrabarnett.plus.com> On 16/08/2011 01:52, Gregory Ewing wrote: > I don't mind people using e.g. and i.e. as long > as they use them *correctly*. > > Many times people use i.e. when they really > mean e.g. > Can you give me an example? :-) From roy at panix.com Mon Aug 15 22:01:32 2011 From: roy at panix.com (Roy Smith) Date: Mon, 15 Aug 2011 22:01:32 -0400 Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: In article <9att9mF710U2 at mid.individual.net>, Gregory Ewing wrote: > I don't mind people using e.g. and i.e. as long > as they use them *correctly*. The only correct way to use i.e. is to use it to download a better browser. From steve+comp.lang.python at pearwood.info Mon Aug 15 22:12:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 12:12:18 +1000 Subject: testing if a list contains a sublist References: Message-ID: <4e49d510$0$29985$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 09:26 am Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? This is not the most efficient algorithm, but for short lists it should be plenty fast enough: def contains(alist, sublist): if len(sublist) == 0 or len(sublist) > len(alist): return False start = 0 while True: try: p = alist.index(sublist[0], start) except ValueError: return False for i,x in enumerate(sublist): if alist[p+i] != x: start = p+1 break else: # for loop exits without break return True -- Steven From usenet-nospam at seebs.net Mon Aug 15 22:33:22 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 02:33:22 GMT Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <4e47cbe5$0$23938$e4fe514c@news2.news.xs4all.nl> <9asge7Fsv9U6@mid.individual.net> <9at2fjF20mU1@mid.individual.net> <9att9mF710U2@mid.individual.net> Message-ID: On 2011-08-16, Roy Smith wrote: > In article <9att9mF710U2 at mid.individual.net>, > Gregory Ewing wrote: > >> I don't mind people using e.g. and i.e. as long >> as they use them *correctly*. > > The only correct way to use i.e. is to use it to download a better > browser. Similarly: Boy, is there, e.g., on my face now! -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From philip at semanchuk.com Mon Aug 15 23:23:06 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Aug 2011 23:23:06 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > >> If you want a future directive that deals with it, I'd do it the other >> way - from __future__ import mask_builtin_warning or something - so >> the default remains as it currently is. But this may be a better job >> for a linting script. > > Agreed. It's a style issue, nothing else. There's nothing worse about: > > def spam(list): > pass > > compared to > > class thingy: pass > > def spam(thingy): > pass > > Why should built-ins be treated as more sacred than your own objects? Because built-ins are described in the official documentation as having a specific behavior, while my objects are not. Yes, it can be useful to replace some of the builtins with one's own implementation, and yes, doing so fits in with Python's "we're all consenting adults" philosophy. But replacing (shadowing, masking -- call it what you will) builtins is not everyday practice. On the contrary, as the OP Gerrat pointed out, it's most often done unwittingly by newcomers to the language who have no idea that they've done anything out of the ordinary or potentially confusing. If a language feature is most often invoked accidentally without knowledge of or regard for its potential negative consequences, then it might be worth making it easier to avoid those accidents. bye, Philip From tlikonen at iki.fi Tue Aug 16 00:04:24 2011 From: tlikonen at iki.fi (Teemu Likonen) Date: Tue, 16 Aug 2011 07:04:24 +0300 Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ty9iovcn.fsf@mithlond.arda> * 2011-08-14T01:44:05-07:00 * Chris Rebert wrote: > I've heard that Dylan is supposedly Lisp, sans parens. > http://en.wikipedia.org/wiki/Dylan_(programming_language) It has copied/derived many features from Lisps but it's not a dialect of Lisp because of the syntax and its consequences. From wuwei23 at gmail.com Tue Aug 16 00:13:53 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Aug 2011 21:13:53 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Steven D'Aprano wrote: > I think I would be less skeptical about fluent interfaces if they were > written more like Unix shell script pipelines instead of using attribute > access notation: > > foo.array_of_things | sort | map block | join ", " I've seen at least one attempt to provide this in Python: http://dev-tricks.net/pipe-infix-syntax-for-python From snorble at hotmail.com Tue Aug 16 00:32:02 2011 From: snorble at hotmail.com (snorble) Date: Mon, 15 Aug 2011 21:32:02 -0700 (PDT) Subject: Windows service in production? Message-ID: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Anyone know of a Python application running as a Windows service in production? I'm planning a network monitoring application that runs as a service and reports back to the central server. Sort of a heartbeat type agent to assist with "this server is down, go check on it" type situations. If using Visual Studio and C# is the more reliable way, then I'll go that route. I love Python, but everything I read about Python services seems to have workarounds ahoy for various situations (or maybe that's just Windows services in general?). And there seem to be multiple layers of workarounds, since it takes py2exe (or similar) and there are numerous workarounds required there, depending on which libraries and functionality are being used. Overall, reading about Windows services in Python is not exactly a confidence inspiring experience. If I knew of a reference example of something reliably running in production, I'd feel better than copying and pasting some code from a guy's blog. From rantingrick at gmail.com Tue Aug 16 00:37:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 21:37:08 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <92b8f192-d7fc-4c60-87ad-71b12652f3a2@k8g2000yqk.googlegroups.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Message-ID: On Aug 15, 11:13?pm, alex23 wrote: > Steven D'Aprano wrote: > > I think I would be less skeptical about fluent interfaces if they were > > written more like Unix shell script pipelines instead of using attribute > > access notation: > > > foo.array_of_things | sort | map block | join ", " > > I've seen at least one attempt to provide this in Python: If you want 100% OOP then use Ruby: rb> [3,100,-20].sort.join('<#>') -20<#>3<#>100 Ruby is great from this angle! The reading proceeds naturally from right to left. I have become accustomed to reading Python's nested function calls however it does feel much more natural in Ruby. Of course, there are architectural reasons why Python cannot do this linear syntactical processing which lends some paradigm-al niceties to the python programmer that are not available to the Ruby folks. From rantingrick at gmail.com Tue Aug 16 00:50:51 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Aug 2011 21:50:51 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> Message-ID: <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> On Aug 15, 7:48?pm, Gregory Ewing wrote: > rantingrick wrote: > > "Used to" and "supposed to" is the verbiage of children > > and idiots. > > So when we reach a certain age we're meant to abandon > short, concise and idomatic ways of speaking, and substitute > long words and phrases to make ourselves sound adult and > educated? Well that is the idea anyway. Not that we should be overly pedantic about it of course, however some words need to be cast off before we leave the "primary school playground" in the name of articulate communication. These specific phrases i have pointed out ("used to" and "supposed to") are a result of a mind choosing the easy way out instead of putting in the wee bit more effort required to express one's self in an articulate manner. Also these two phrases are quite prolifically used within his community (among others), from the BDFL on down. It's a slippery slope my friend. From steve+comp.lang.python at pearwood.info Tue Aug 16 01:15:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 15:15:01 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: > > On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: > >> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >> >>> If you want a future directive that deals with it, I'd do it the other >>> way - from __future__ import mask_builtin_warning or something - so >>> the default remains as it currently is. But this may be a better job >>> for a linting script. >> >> Agreed. It's a style issue, nothing else. There's nothing worse about: >> >> def spam(list): >> pass >> >> compared to >> >> class thingy: pass >> >> def spam(thingy): >> pass >> >> Why should built-ins be treated as more sacred than your own objects? > > Because built-ins are described in the official documentation as having a > specific behavior, while my objects are not. *My* objects certainly are, because I write documentation for my code. My docs are no less official than Python's docs. You can shadow anything. Sometimes shadowing is safe, sometimes it isn't. I don't see why we should necessarily fear safe shadowing of built-ins more than we fear unsafe shadowing of non-built-ins. (I'm not even convinced that making None a reserved word was the right decision.) A warning that is off by default won't help the people who need it, because they don't know enough to turn the warning on. A warning that is on by default will be helpful to the newbie programmer for the first week or so, and then will be nothing but an annoyance for the rest of their career. (For some definition of a week -- some people are slower learners than others.) > Yes, it can be useful to replace some of the builtins with one's own > implementation, and yes, doing so fits in with Python's "we're all > consenting adults" philosophy. But replacing (shadowing, masking -- call > it what you will) builtins is not everyday practice. On the contrary, as > the OP Gerrat pointed out, it's most often done unwittingly by newcomers > to the language who have no idea that they've done anything out of the > ordinary or potentially confusing. Protecting n00bs from their own errors is an admirable aim, but have you considered that warnings for something which may be harmless could do more harm than good? Beginners often lack the skill to distinguish between harmless warnings that can safely be ignored, and fatal errors that need to be fixed. Even "user friendly" warning or error messages tend to unnerve some beginner coders. There's not much we can do about outright errors, except to make sure that the error string is as useful as possible, but we can avoid overloading beginners with warnings they don't need to care about: WARNING WARNING WARNING WILL ROBINSON, DANGER DANGER DANGER: YOUR SISTER'S NAME 'PENNY' SHADOWS THE BRITISH CURRENCY, POTENTIAL AMBIGUITY ALERT DANGER DANGER DANGER! *wink* Depending on their personality, you may end up teaching them to ignore warnings, or a superstitious dread of anything that leads to a warning. Neither is a good outcome. > If a language feature is most often invoked accidentally without knowledge > of or regard for its potential negative consequences, then it might be > worth making it easier to avoid those accidents. Perhaps. But I'm not so sure it is worth the cost of extra code to detect shadowing and raise a warning. After all, the average coder probably never shadows anything, and for those that do, once they get bitten *once* they either never do it again or learn how to shadow safely. I don't see it as a problem. -- Steven From thinke365 at gmail.com Tue Aug 16 01:15:05 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 13:15:05 +0800 Subject: How to use python environment created using virtualenv? Message-ID: I have created a python environment using virtualenv, but when i want to import such environment to PyDev, error just appears, it tells there should be a Libs dir, but there is no Libs DIr in the virtual envronment created using virtualenv, what should i do if i want to use this virtual environment? From cbrown at cbrownsystems.com Tue Aug 16 02:13:55 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:13:55 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <5b08f0ef-6dd5-445b-8526-2870cb6a4d62@p19g2000yqa.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From cbrown at cbrownsystems.com Tue Aug 16 02:14:07 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:14:07 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <79ff0c63-d64e-4236-9839-eb56a329b8d0@e35g2000yqc.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From cbrown at cbrownsystems.com Tue Aug 16 02:14:14 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Mon, 15 Aug 2011 23:14:14 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> On Aug 15, 4:26?pm, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes My best guess: from collections import Counter def contains(alist, sublist): alist = Counter(alist) for k in sublist: try: alist[k] -= 1 if alist[k] < 0: return False except KeyError: return False return True 'Counter' being better understood as 'Multiset'. If m = len(alist) and n = len(sublist), looks to be roughly O(m+n). Cheers - Chas From wuwei23 at gmail.com Tue Aug 16 02:49:25 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Aug 2011 23:49:25 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> Message-ID: <379fb990-c471-47d2-a349-edfe6bc94956@o11g2000yql.googlegroups.com> On Aug 16, 2:37?pm, rantingrick wrote: > The reading proceeds naturally from right to left. Well, "naturally" if you're coding in Hebrew or Japanese perhaps :) From gandalf at shopzeus.com Tue Aug 16 02:51:25 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 08:51:25 +0200 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A136D.2030207@shopzeus.com> >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. >> >> greatz Johannes Fastest, error-free and simplest solution is to use sets: >>> l1 = [1,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set([]) >>> set(l2)-set(l1) set([3, 4, 5]) >>> Although with big lists, this is not very memory efficient. But I must tell you, sometimes I use this method for lists with millions of integers, and it is very fast and reliable, and memory is not a concern for me, at least - some million integers will fit into a few MB of memory. Read the docs about set operators for creating union, symmetric difference etc. Best, Laszlo From dannwong at cisco.com Tue Aug 16 03:00:22 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 02:00:22 -0500 Subject: regular expression In-Reply-To: <4E499F0B.30900@stoneleaf.us> References: <4E499F0B.30900@stoneleaf.us> Message-ID: Hi All, If I get multiline standard output from a command. How can I retrieve this part of the string "(1006)" Example: #Committing... #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" # Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" # Outgoing: # Change sets: # (1006) *--@ # Changes: # ---c- /he-Group/o-PI/target/config/common-ngp/makefile From dannwong at cisco.com Tue Aug 16 03:03:50 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 02:03:50 -0500 Subject: subprocess.Popen question In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: Hi All, I'm executing a command which I want to capture the standard/stderr output into a file (which I have with the code below), but I also want the standard output to go into a variable so I can process the information for the next command. Any ideas? Thanks. CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, stderr=subprocess.STDOUT) From clp2 at rebertia.com Tue Aug 16 03:07:46 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 00:07:46 -0700 Subject: subprocess.Popen question In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: On Tue, Aug 16, 2011 at 12:03 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. Pipe it thru `tee`: http://en.wikipedia.org/wiki/Tee_%28command%29 Cheers, Chris From wuwei23 at gmail.com Tue Aug 16 03:07:53 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:07:53 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> Message-ID: rantingrick wrote: > These specific phrases i have pointed out ("used to" and "supposed > to") are a result of a mind choosing the easy way out instead of > putting in the wee bit more effort required to express one's self in > an articulate manner. Also these two phrases are quite prolifically > used within his community (among others), from the BDFL on down. All the way down indeed. Can you pick who said these? "There are noobs watching and we to provide code that can be used to teach!" "And just what *point* an i supposed to be "getting" Stephen?" "An end user should NEVER EVER have to write glue code so their "abstraction of choice" can be used to to script an API." (For bonus points: can you also spot who is bored at work today?) From wuwei23 at gmail.com Tue Aug 16 03:14:08 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:14:08 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> On Aug 16, 4:51?pm, Laszlo Nagy wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> ?l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> ?l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> ?l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) Error free? Consider this stated requirement: > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set() >>> set(l2)-set(l1) {3, 4, 5} So set([1,2]) == set([1,2,2]), despite [1,2,2] not being a sublist of the original. It also completely ignores list order, which would make [9,8,7] a sublist of [5,6,7,8,9]. From wuwei23 at gmail.com Tue Aug 16 03:19:20 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 00:19:20 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <51581f4b-f74b-4df1-ae76-a65064b5dc27@s2g2000vby.googlegroups.com> Laszlo Nagy wrote: > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) > ?>>> Error-free? Not given the stated requirements: > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,2] >>> l2 = [1,2,3,4,5] >>> set(l1)-set(l2) set() >>> set(l2)-set(l1) {3, 4, 5} As you can see, using sets provides the exact same result for a non- contained sub-list as it does for your valid example. The list [1,2,2,2,2,2,2,2,2] is clearly not contained with [1,2,3], but your code would say it is. Similarly, [9,8,7] would appear to be a sub-list of [5,6,7,8,9], something I'd also considered to be false in this instance. (My apologies if this is a double-up, the original post hasn't appeared yet) From cbrown at cbrownsystems.com Tue Aug 16 03:24:24 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Tue, 16 Aug 2011 00:24:24 -0700 (PDT) Subject: testing if a list contains a sublist References: Message-ID: <636abfaa-a36f-4a67-af7f-59c19beb924a@gz5g2000vbb.googlegroups.com> On Aug 15, 11:51?pm, Laszlo Nagy wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> ?l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> ?l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> ?l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > Fastest, error-free and simplest solution is to use sets: > > ?>>> l1 = [1,2] > ?>>> l2 = [1,2,3,4,5] > ?>>> set(l1)-set(l2) > set([]) > ?>>> set(l2)-set(l1) > set([3, 4, 5]) > ?>>> > This approach fails the OP's desires when >>> l1 = [1,2,2,] >>> l2 = [1,2,3,4,5] The OP explicitly desires 'l2 contains l1' to be false in that case. Cheers - Chas From clp2 at rebertia.com Tue Aug 16 03:26:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 00:26:21 -0700 Subject: regular expression In-Reply-To: References: <4E499F0B.30900@stoneleaf.us> Message-ID: On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?If I get multiline standard output from a command. How can I > retrieve this part of the string "(1006)" > Example: > > #Committing... > #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" > # ?Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" > # ? ?Outgoing: > # ? ? ?Change sets: > # ? ? ? ?(1006) ?*--@ ? > # ? ? ? ? ?Changes: > # ? ? ? ? ? ?---c- /he-Group/o-PI/target/config/common-ngp/makefile Assuming the #s aren't in the actual output: import re pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) print(pat.search(your_str).group(1)) Obviously can vary depending on how you want to go about defining the target string. Cheers, Chris P.S. If you reply, please remove my email addresses from the quotation due to "On Behalf Of" brokenness. -- Freakin' Outlook/Exchange, I'm telling ya... http://rebertia.com From __peter__ at web.de Tue Aug 16 03:44:13 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2011 09:44:13 +0200 Subject: testing if a list contains a sublist References: <4E49AB3E.9000801@web.de> Message-ID: Johannes wrote: > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer that assumes yes and another that assume no. From smainklh at gmail.com Tue Aug 16 03:45:56 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 09:45:56 +0200 Subject: Linux : create a user if not exists Message-ID: Hi all, I'm learning the python language and i'm trying to create a user if it is not found in the system. I figured it out by doing the following thing : >>> def finduser(user): ... for line in open('/etc/passwd'): ... if line.startswith(user): ... print user, "user exists" ... return True ... return False >>> if not finduser('myuser'): ... print "Creating user myuser" ... os.system('/usr/sbin/useradd myuser') But i think it's a dirty way to do so. Is there another way to manage users with python ? Thank you :) Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Aug 16 03:52:37 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Aug 2011 08:52:37 +0100 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <4E4A21C5.30306@timgolden.me.uk> On 16/08/2011 05:32, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. Don't know what it'll take to inspire you with confidence, but I have several Python services running here without a hitch. The longest have been running for about three years -- not without a stop, since they have to be restarted for reasons external to the service itself. There's no py2exe involved, just the pywin32 service wrappers. (The apps in question are also set up to run standalone for testing etc.). They're mostly around a helpdesk system: one app ingests email requests to the helpdesk; another post-processes call changes, currently to send out email alerts to interested parties; another triggers alarms on calls for various purposes, etc. I don't claim they're the most sophisticated pieces of code on Earth, but it doesn't sound like you're after anything spectacular either. TJG From gandalf at shopzeus.com Tue Aug 16 04:00:15 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 10:00:15 +0200 Subject: testing if a list contains a sublist In-Reply-To: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> References: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> Message-ID: <4E4A238F.7030003@shopzeus.com> > Error free? Consider this stated requirement: >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 If you look it the strict way, "containment" relation for lists is meant this way: l1 = [] l2 = [1,l1,2] # l2 CONTAINS l1 But you are right, I was wrong. So let's clarify what the OP wants! For example: l1 = [1,2,2,], l2 = [2,1,2,3,4,5] What is the relation between these two lists? Does l2 contain l1 or not? In other words, is this "containment" relation interpreted on multisets not considering the order of the items? > > It also completely ignores list order, which would make [9,8,7] a > sublist of [5,6,7,8,9]. Exactly. However, from the original post of Johannes it was not clear if the order of the elements counts or not. If It this is interpreted as a multiset relation, it would be easier to use collections.Counter. If the order of elements is important then he can start with a Boyer-Moore algorithm. Best, Laszlo From clp2 at rebertia.com Tue Aug 16 04:04:11 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Aug 2011 01:04:11 -0700 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: On Tue, Aug 16, 2011 at 12:45 AM, smain kahlouch wrote: > Hi all, > > I'm learning the python language and i'm trying to create a user if it is > not found in the system. > I figured it out by doing the following thing : > >>>> def finduser(user): > ...???? for line in open('/etc/passwd'): > ...???????????? if line.startswith(user): > ...???????????????????? print user, "user exists" > ...???????????????????? return True > ...???? return False > But i think it's a dirty way to do so. Is there another way to manage users > with python ? You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): http://docs.python.org/library/pwd.html#pwd.getpwnam Cheers, Chris From wuwei23 at gmail.com Tue Aug 16 04:08:33 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Aug 2011 01:08:33 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: snorble wrote: > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). What workarounds do you mean? Every example I've ever seen makes direct use of the Windows modules for Python. > And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. What about existing code recipes which were featured in the Python Cookbook? http://code.activestate.com/recipes/551780/ Not a hint of pyexe or weird hackery. From rosuav at gmail.com Tue Aug 16 04:16:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 09:16:51 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 2:32 AM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: > >> It's actually masking, not reassigning. That may make it easier or >> harder to resolve the issue. > > The usual term is "shadowing builtins", and it's a feature, not a bug :) Sorry, shadowing. And yeah, that's why I said that "fixing" this "issue" was the domain of linting scripts. ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 16 04:19:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 18:19:43 +1000 Subject: testing if a list contains a sublist References: <4e49d510$0$29985$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4a281f$0$29973$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 12:12 pm Steven D'Aprano wrote: > On Tue, 16 Aug 2011 09:26 am Johannes wrote: > >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > > This is not the most efficient algorithm, but for short lists it should be > plenty fast enough: Nope, sorry, that was buggy. Here's another version which should be accurate but may be slower. def search(source, target, start=0, end=None): """Naive search for target in source.""" m = len(source) n = len(target) if end is None: end = m if n == 0 or m < n: return None for i in range(start, end-n+1): if source[i:i+n] == target: return i return None -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 16 04:37:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 16 Aug 2011 18:37:21 +1000 Subject: testing if a list contains a sublist References: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> Message-ID: <4e4a2c41$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote: > On Aug 15, 4:26?pm, Johannes wrote: >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. >> >> greatz Johannes > > My best guess: > > from collections import Counter There's no reason to think that the Original Poster wants a multiset based solution. He asked about lists and sublists. That's a standard term, like substring: "12" is a substring of "01234". "21" and "13" are not. [1, 2] is a sublist of [0, 1, 2, 3, 4]. [2, 1] and [1, 3] are not. Since lists are ordered, so are sublists. If the OP does want a solution that ignores order, then he needs to describe his problem better. -- Steven From dajo.mail at web.de Tue Aug 16 04:38:17 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 10:38:17 +0200 Subject: testing if a list contains a sublist In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: <4E4A2C79.90609@web.de> Am 16.08.2011 09:44, schrieb Peter Otten: > Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? >> >> for example: >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >> >> my problem is the second example, which makes it impossible to work with >> sets insteads of lists. But something like set.issubset for lists would >> be nice. > > Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer that > assumes yes and another that assume no. > yes it should be contained in the other one. I just work with sorted lists, so i did not think about this case. geatz Johannes From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Aug 16 05:10:45 2011 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 16 Aug 2011 11:10:45 +0200 Subject: subprocess.Popen question In-Reply-To: References: <4E49AB3E.9000801@web.de> Message-ID: Am 16.08.2011 09:03 schrieb Danny Wong (dannwong): > Hi All, > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. > > CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, > stderr=subprocess.STDOUT) This way it won't work - but if you do sp = subprocess.Popen(COMMAND, stdout=subprocess.PIPE, stderr=subprocess.PIPE) you can flexibly work with both of them. But then the two streams can become intermixed. After that, you would have to emulate the select() behaviour of communicate(), but act differently on them. If you get data on stdout, you capture and append to the file, for data on stderr you only append. Maybe this could work for you: def communicate2(self, input): """ input is readable, output is a generator which yields data """ read_set = [] write_set = [] stdout = None # Return stderr = None # Return # Translate newlines, if requested. We cannot let the file # object do the translation: It is based on stdio, which is # impossible to combine with select (unless forcing no # buffering). if self.universal_newlines and hasattr(file, 'newlines'): xlate=lambda s:self._translate_newlines(s) else: xlate=lambda s:s if self.stdin: # Flush stdio buffer. This might block, if the user has # been writing to .stdin in an uncontrolled fashion. self.stdin.flush() if self.stdout: read_set.append(self.stdout) stdout = [] if self.stderr: read_set.append(self.stderr) stderr = [] inpcrsr=0 # der ist neu... rest='' eofseen=False while read_set or write_set: rlist, wlist, xlist = select.select(read_set, write_set, []) if self.stdin in wlist: # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk # blocking. POSIX defines PIPE_BUF >= 512 #pipebuf=512 pipebuf=os.fpathconf(self.stdin.fileno(),'PC_PIPE_BUF') if not eofseen: buf=input.read(pipebuf-len(rest)) # else it stays '' if not buf: eofseen=True if rest or buf: bytes_written = os.write(self.stdin.fileno(), rest+buf) if bytes_written > len(rest): rest=buf[bytes_written-len(rest):] else: rest=rest[bytes_written:]+buf else: self.stdin.close() write_set.remove(self.stdin) if self.stdout in rlist: data = os.read(self.stdout.fileno(), 1024) if data == "": self.stdout.close() read_set.remove(self.stdout) #stdout.append(data) #yield stdout,data yield 1,xlate(data) if self.stderr in rlist: data = os.read(self.stderr.fileno(), 1024) if data == "": self.stderr.close() read_set.remove(self.stderr) #stderr.append(data) yield 2,xlate(data) self.wait() (Im not sure if it is to 100% correct.) This yields tuples (1, ) for stdout data and tuples (2, ) for stderr data. From thinke365 at gmail.com Tue Aug 16 05:15:28 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 17:15:28 +0800 Subject: Anyone here can do a comparation between Djang and RoR Message-ID: what is the advantage of Django over RoR:) From __peter__ at web.de Tue Aug 16 05:26:01 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Aug 2011 11:26:01 +0200 Subject: testing if a list contains a sublist References: <4E49AB3E.9000801@web.de> <4E4A2C79.90609@web.de> Message-ID: Johannes wrote: > Am 16.08.2011 09:44, schrieb Peter Otten: >> Johannes wrote: >> >>> what is the best way to check if a given list (lets call it l1) is >>> totally contained in a second list (l2)? >>> >>> for example: >>> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 >>> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 >>> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 >>> >>> my problem is the second example, which makes it impossible to work with >>> sets insteads of lists. But something like set.issubset for lists would >>> be nice. >> >> Would [1, 2, 1] be contained in [1, 1, 2]? You have received an answer >> that assumes yes and another that assume no. >> > > yes it should be contained in the other one. I just work with sorted > lists, so i did not think about this case. > > geatz Johannes For "short" lists l1: >>> pairs = [ ... ([1,2], [1,2,3,4,5]), ... ([1,2,2,], [1,2,3,4,5]), ... ([1,2,3], [1,3,5,7])] >>> for l1, l2 in pairs: ... contained = all(l1.count(item) <= l2.count(item) for item in set(l1)) ... print l1, ["not in", "in"][contained], l2 ... [1, 2] in [1, 2, 3, 4, 5] [1, 2, 2] not in [1, 2, 3, 4, 5] [1, 2, 3] not in [1, 3, 5, 7] From przemolicc at poczta.fm Tue Aug 16 05:38:00 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Tue, 16 Aug 2011 11:38:00 +0200 Subject: String concatenation - which is the fastest way ? In-Reply-To: References: <20110810111754.GD5045@host.pgf.com.pl> <20110810133146.GE5045@host.pgf.com.pl> <20110811064030.GB4990@host.pgf.com.pl> <20110811134613.GE4990@host.pgf.com.pl> <20110811143923.GG4990@host.pgf.com.pl> Message-ID: <20110816093800.GB19052@host.pgf.com.pl> On Fri, Aug 12, 2011 at 11:25:06AM +0200, Stefan Behnel wrote: > przemolicc at poczta.fm, 11.08.2011 16:39: >> On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: >>> On Thu, Aug 11, 2011 at 2:46 PM, wrote: >>>> This is the way I am going to use. >>>> But what is the best data type to hold so many rows and then operate on them ? >>>> >>> >>> List of strings. Take it straight from your Oracle interface and work >>> with it directly. >> >> Can I use this list in the following way ? >> subprocess_1 - run on list between 1 and 10000 >> subprocess_2 - run on list between 10001 and 20000 >> subprocess_3 - run on list between 20001 and 30000 >> etc >> ... > > Sure. Just read the data as it comes in from the database and fill up a > chunk, then hand that on to a process. You can also distribute it in > smaller packets, just check what size gives the best throughput. Since the performance is critical I wanted to use multiprocessing module. But when I get all the source rows into one list of strings can I easly share it between X processes ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From cbrewster at gmail.com Tue Aug 16 06:03:51 2011 From: cbrewster at gmail.com (Christopher Brewster) Date: Tue, 16 Aug 2011 03:03:51 -0700 (PDT) Subject: Messed up Mac installation Message-ID: Are there instructions somewhere online as to how to sort out a messed up installation of Python on a Mac? I have a 2 month old Macbook running Snow Leopard, I installed Python 2.7.1 some time ago. Now when I run 'python' this is what it shows. But easy_install and pip are installing modules to the python2.6 (which shipped with the OS). If I run 'python2.6' then I have access to the modules installed with pip. Oh and weirdly if I tell pip to uninstall modules it says the module does not exist. For example: "/Library/Frameworks/Python.framework/ Versions/2.7/bin/pip run on Tue Aug 16 11:46:28 2011 Cannot uninstall requirement reportlab, not installed" So why is it installing to one place (the 2.6 library) and trying to uninstall elsewhere (the 2.7 library)? I know this has been discussed many times but I do not know how to track this down. Thanks for any pointers. Christopher From aspineux at gmail.com Tue Aug 16 06:33:36 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 03:33:36 -0700 (PDT) Subject: Messed up Mac installation References: Message-ID: <9429a0b0-b17a-4247-ae19-67dfbc5e8636@hl8g2000vbb.googlegroups.com> On Aug 16, 12:03?pm, Christopher Brewster wrote: > Are there instructions somewhere online as to how to sort out a messed > up installation of Python on a Mac? > I have a 2 month old Macbook running Snow Leopard, I installed Python > 2.7.1 some time ago. Now when I run 'python' this is what it shows. > But easy_install and pip are installing modules to the python2.6 > (which shipped with the OS). If I run 'python2.6' then I have access > to the modules installed with pip. pip and easy_install work on directory hierarchy of the running python. then the idea (just the idea, not read sample) python2.7 pip.py **** will install into python2.7 directories python2.7 easy_install.py **** will install into python2.7 directories python2.6 pip.py **** will install into python2.6 directories python2.6 easy_install.py **** will install into python2.6 directories For example (real this time) to install easy_install for your 2.7 wget http://peak.telecommunity.com/dist/ez_setup.py python2.7 ez_setup.py > > Oh and weirdly if I tell pip to uninstall modules it says the module > does not exist. For example: "/Library/Frameworks/Python.framework/ > Versions/2.7/bin/pip run on Tue Aug 16 11:46:28 2011 > Cannot uninstall requirement reportlab, not installed" Probably because you run installed pip from python2.7 directory, that certainly use python2.7 binary, and then pip uninstall from python2.7 directories > > So why is it installing to one place (the 2.6 library) and trying to > uninstall elsewhere (the 2.7 library)? Because you are no using the same pip/easy_install to install or uninstall (or at least the python binary is not the same) > > I know this has been discussed many times but I do not know how to > track this down. > Thanks for any pointers. > > Christopher From lynx.p9 at gmail.com Tue Aug 16 06:47:47 2011 From: lynx.p9 at gmail.com (Alex Po) Date: Tue, 16 Aug 2011 03:47:47 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: Many things already done in RoR if comparing it with Django. From lynx.p9 at gmail.com Tue Aug 16 06:47:47 2011 From: lynx.p9 at gmail.com (Alex Po) Date: Tue, 16 Aug 2011 03:47:47 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: Many things already done in RoR if comparing it with Django. From python.list at tim.thechases.com Tue Aug 16 07:11:13 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 06:11:13 -0500 Subject: Anyone here can do a comparation between Djang and RoR In-Reply-To: References: Message-ID: <4E4A5051.1020509@tim.thechases.com> On 08/16/2011 04:15 AM, smith jack wrote: > what is the advantage of Django over RoR:) *THE* advantage is that you get to program in Python instead of Ruby. :) -tkc From abhib.py at gmail.com Tue Aug 16 07:17:14 2011 From: abhib.py at gmail.com (Abhishek Bajpai) Date: Tue, 16 Aug 2011 04:17:14 -0700 (PDT) Subject: Application monitoring Message-ID: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> I need to monitor applications like apache, mysql etc there live status, errors etc on my LAN is there any tool or lib for this any help will be appreciated thanks in advance From nobody at nowhere.com Tue Aug 16 07:21:47 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 16 Aug 2011 12:21:47 +0100 Subject: testing if a list contains a sublist References: Message-ID: On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? "Best" is subjective. AFAIK, the theoretically-optimal algorithm is Boyer-Moore. But that would require a fair amount of code, and Python isn't a particularly fast language, so you're likely to get better results if you can delegate most of the leg-work to a native library (along the lines of Roy's suggestion of using regexps). From nitinpawar432 at gmail.com Tue Aug 16 07:25:30 2011 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 16 Aug 2011 16:55:30 +0530 Subject: Application monitoring In-Reply-To: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: We use nagios for such monitoring On Tue, Aug 16, 2011 at 4:47 PM, Abhishek Bajpai wrote: > I need to monitor applications like apache, mysql etc there live > status, errors etc on my LAN is there any tool or lib for this any > help will be appreciated thanks in advance > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Tue Aug 16 07:26:39 2011 From: nobody at nowhere.com (Nobody) Date: Tue, 16 Aug 2011 12:26:39 +0100 Subject: subprocess.Popen question References: <4E49AB3E.9000801@web.de> Message-ID: On Tue, 16 Aug 2011 02:03:50 -0500, Danny Wong (dannwong) wrote: > I'm executing a command which I want to capture the > standard/stderr output into a file (which I have with the code below), > but I also want the standard output to go into a variable so I can > process the information for the next command. Any ideas? Thanks. > > CMD_OUTPUT = subprocess.Popen(COMMAND, stdout=PROJECT_LOGFILE, > stderr=subprocess.STDOUT) CMD_OUTPUT.wait() with open(PROJECT_LOGFILE,'r') as f: str = f.read() If you're going to be writing it to a file anyhow, reading that file is likely to be faster than the alternatives. From smainklh at gmail.com Tue Aug 16 07:30:11 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 13:30:11 +0200 Subject: Application monitoring In-Reply-To: References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: or shinken ( written in python :) ); Regards, Sam 2011/8/16 Nitin Pawar > We use nagios for such monitoring > > > On Tue, Aug 16, 2011 at 4:47 PM, Abhishek Bajpai wrote: > >> I need to monitor applications like apache, mysql etc there live >> status, errors etc on my LAN is there any tool or lib for this any >> help will be appreciated thanks in advance >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Nitin Pawar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.wray at det.nsw.edu.au Tue Aug 16 07:33:29 2011 From: paul.wray at det.nsw.edu.au (Paul Wray) Date: Tue, 16 Aug 2011 21:33:29 +1000 Subject: Idea for pure-python templates using AST. Message-ID: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Hello all Ive had what I think is a great idea for pure-python templates (I can almost hear the groans, bear with me...) For the impatient, proof of concept is at http://pastie.org/2379978 demonstrating simple substitution, balanced tags using context manager, subtemplates, and template inheritance. I'm posting here to get opinions on: * the merits of the idea, (or otherwise!) * whether there are any established/mature templating systems that use this approach, or whether its come up before, * ideas for improvements and advice on other aspects such as sandboxing * of course, to share the idea in case others want to use it Background: Ive been working on an application that recursively renders html/xml documents from heterogenoeus trees, with separate classes for each document component. First I built my own renderer but was dissatisfied with the repetitive code. Then looked at Mako and Jinja, and used Jinja but was still disatisfied, because I still needed a render method in each class to do preparation, and also the template which was centrally managed by the Jinja loader and environment. I found a way to call templates recursively via Jinja filters, but was not sure that it wouldnt blow up in my face, so I also had separate calls to render the children of each node, and then feed the value to the parent template. I kept thinking that there must be a way to get the brevity and clarity of declarative templates, plus the simplicity of pure python loops, tests and function calls. The idea: Python syntax allows a statement to be a bare literal or identifier. These have no effect on the program. So the function below is legal python: def myFunc(): 'a' x = 45 'b'; 'c'; x So is this (within the appropriate class context of course): def body(self, r): '

'; self.heading; '

' '
    ' for itm in self.items: '
  • '; itm; '
  • ' '
' The idea is simply to use python ASTs to transform this code so that it accumulates the values of the bare expressions. I think this give the best of both worlds - declarative syntax for the template literals, but in a pure python context, giving you all the power of python control statements, classes etc. For application contexts outside pure python code (ie user-created templates) , it would be simple to extend the technique to creating template functions from strings, and insert the resulting methods into a namespace for execution.) I think, given the technique is already working with the AST, that sandboxing should not be too hard either - advice on this aspect would be appreciated. Paul Wray From roy at panix.com Tue Aug 16 07:50:55 2011 From: roy at panix.com (Roy Smith) Date: Tue, 16 Aug 2011 07:50:55 -0400 Subject: regular expression References: <4E499F0B.30900@stoneleaf.us> Message-ID: In article , Chris Rebert wrote: > pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) First rule of regexes in Python is to always use raw strings, to eliminate the doubled backslashes: > pat = re.compile(r"^ *(\([^)]+\))", re.MULTILINE) Is easier to read. From thinke365 at gmail.com Tue Aug 16 08:17:12 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 20:17:12 +0800 Subject: How to install easy_install on windows ? Message-ID: it needs read registry, but the python i used is extracted from .zip, so there is no record in the registry, what should i do in order to install easy_install for my python environment? From alain at dpt-info.u-strasbg.fr Tue Aug 16 08:23:44 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 16 Aug 2011 14:23:44 +0200 Subject: testing if a list contains a sublist References: Message-ID: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Roy Smith writes: >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? [...] > import re > > def sublist(l1, l2): > s1 = ''.join(map(str, l1)) > s2 = ''.join(map(str, l2)) > return re.search(s1, s2) This is complete nonsense (try it on [12] and [1,2]). The original problem is "string searching" (where strings here are sequences of numbers instead of characters). See http://en.wikipedia.org/wiki/String_searching_algorithm for any algorithm (Rabin-Karp seems appropriate to me). -- Alain. From aspineux at gmail.com Tue Aug 16 08:32:18 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:32:18 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> On Aug 16, 1:33?pm, "Paul Wray" wrote: > Hello all > > Ive had what I think is a great idea for pure-python templates (I can almost > hear the groans, bear with me...) > > For the impatient, proof of concept is athttp://pastie.org/2379978 > demonstrating simple substitution, balanced tags using context manager, > subtemplates, ?and template inheritance. You code fail, see below for other comment Traceback (most recent call last): File "Download/pastie-2379978.rb", line 108, in make_template(template1) File "Download/pastie-2379978.rb", line 60, in make_template ast.fix_missing_locations(astFromSrc) File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations _fix(node, 1, 0) File "/usr/lib/python2.6/ast.py", line 132, in _fix _fix(child, lineno, col_offset) File "/usr/lib/python2.6/ast.py", line 132, in _fix _fix(child, lineno, col_offset) File "/usr/lib/python2.6/ast.py", line 121, in _fix if 'lineno' in node._attributes: AttributeError: 'arguments' object has no attribute '_attributes' > > I'm posting here to get opinions on: > * the merits of the idea, (or otherwise!) > * whether there are any established/mature templating systems that use this > approach, or whether its come up before, > * ideas for improvements and advice on other aspects such as sandboxing > * of course, to share the idea in case others want to use it This is very original ! First time I see it. I like it. But how to debug large template ? How to find/detect a missing ? This is very important. This is one big advantage of Genshi over Kid How to report the correct error at the correct line ? How to find/get nice editor to edit large template ? > > Background: Ive been working on an application that recursively renders > html/xml documents from heterogenoeus trees, with separate classes for each > document component. First I built my own renderer but was dissatisfied with > the repetitive code. Then looked at Mako and Jinja, and used Jinja but was > still disatisfied, because I still needed a render method in each class to > do preparation, and also the template which was centrally managed by the > Jinja loader and environment. I found a way to call templates recursively > via Jinja filters, but was not sure that it wouldnt blow up in my face, so I > also had separate calls to render the children of each node, and then feed > the value to the parent template. I kept thinking that there must be a way > to get the brevity and clarity of declarative templates, plus the simplicity > of pure python loops, tests and function calls. > > The idea: > Python syntax allows a statement to be a bare literal or identifier. These > have no effect on the program. > > So the function below is legal python: > > def myFunc(): > ? ? 'a' > ? ? x = 45 > ? ? 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > ? ? ? ? '

'; self.heading; '

' > ? ? ? ? '
    ' > ? ? ? ? for itm in self.items: > ? ? ? ? ? ? '
  • '; itm; '
  • ' > ? ? ? ? '
' > > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. You could call it PHP :-) > > I think this give the best of both worlds - declarative syntax for the > template literals, but in a pure python context, giving you all the power of > python control statements, classes etc. > > For application contexts outside pure python code (ie user-created > templates) , it would be simple to extend the technique to creating template > functions from strings, and insert the resulting methods into a namespace > for execution.) > > I think, given the technique is already working with the AST, that > sandboxing should not be too hard either - advice on this aspect would be > appreciated. Maybe a good idea. But still a lot of work to get the level of existing libraries. Maybe better if mixed with other tools like Genshi to create widget. Maybe next toscawidget could use such a technique. Thanks for sharing > > Paul Wray From ayaskant.swain at gmail.com Tue Aug 16 08:38:01 2011 From: ayaskant.swain at gmail.com (Ayaskant Swain) Date: Tue, 16 Aug 2011 18:08:01 +0530 Subject: How to Check Write Access of a Folder on Windows Message-ID: Hi Tim, Thanks for your reply. It seems this issue is related to python bug - http://bugs.python.org/issue2528 But the patch code looks complex to me. I want to make changes only in my python script which will read an user given directory path & check it's write access. What is the use of posixmodule.c file? I also went through the link that you provided - http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The code section in this link has a line - sd = win32security.GetFileSecurity (FILENAME, win32security.DACL_SECURITY_INFORMATION) Can we retrieve any write access information from this sd object in the python script? Thanks Ayaskant- ------------------------------------------------------------------------------------------------------- On 12/08/2011 11:41, Ayaskanta Swain wrote: >* Hi,* >* * >* I have a requirement where I need to check the write permissions on a* >* directory on Windows platform. I don?t want to use the python function* >* os.access( ), since it does not work correctly on Windows. It is giving* >* incorrect results to me.* >* * >* Another option of actually creating a temporary file inside the folder &* >* then deleting it to check whether the user has write permissions or not* >* is causing performance issues. It is slowing down our application when* >* we have to check the permissions on hundreds of folders. It also changes* >* the last access time stamp of the folder.* >* * >* So is there any other way such as using Win32API or Win32 security* >* modules to check the permissions?* In general, yes. Depends how finicky you want to get. I take it from your question that you're pretty much unfamiliar with the Windows Security APIs and structures? There's a quite a bit of information around on the subject, but have a look at this first which is at least Python-oriented: http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html The trouble is that do what you want, you need to use the AccessCheck API (or emulate its functionality) and this isn't currently exposed by the pywin32 modules. You could run it up yourself with ctypes or by creating a quick extension for the purpose. Alternatively, as I say, you could emulate by scanning the ACLs/ACEs and trying to apply some suitable logic. Frankly, I'd have thought this was harder work :) Hope that helps TJG -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Tue Aug 16 08:39:54 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:39:54 -0700 (PDT) Subject: How to install easy_install on windows ? References: Message-ID: <77f65ea2-3748-4dfa-af7c-498ebe2d3be8@f7g2000vba.googlegroups.com> On Aug 16, 2:17?pm, smith jack wrote: > it needs read registry, but the python i used is extracted from .zip, > so there is no record in the registry, Noone need it, Python dont use any registry key > what should i do in order to install easy_install for my python environment? get ez_setup.py from http://peak.telecommunity.com/dist/ez_setup.py in a command prompt run C:\Your Python Directory\python.exe C:\Your Download directory \ez_setup.py Then use C:\Your Python Directory\python.exe C:\Your Python Directory\I dont know where the easy_install script will be installed\easy_install.py install module_name to install a modul_name Regards From roy at panix.com Tue Aug 16 08:53:58 2011 From: roy at panix.com (Roy Smith) Date: Tue, 16 Aug 2011 08:53:58 -0400 Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Message-ID: In article <8739h18rzj.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Roy Smith writes: > > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > import re > > > > def sublist(l1, l2): > > s1 = ''.join(map(str, l1)) > > s2 = ''.join(map(str, l2)) > > return re.search(s1, s2) > > This is complete nonsense (try it on [12] and [1,2]). No, it's not complete nonsense, it works just fine for the limited data set the OP presented :-) Of course, you are correct that it only works for single-digit integers, hence my "running and ducking" comment. > The original problem is "string searching" (where strings here are > sequences of numbers instead of characters). See > > http://en.wikipedia.org/wiki/String_searching_algorithm > > for any algorithm (Rabin-Karp seems appropriate to me). Yes, of course this is fundamentally a string searching problem. The problem is that while Python comes with an excellent tool for doing these kinds of string searches, its domain is limited to, as you pointed out, character strings. However, for the limited data the OP presented, there is a trivial way to map the original data domain (single digit integers) into the domain the re library knows about (character strings). My answer may be a sucky general-purpose solution, but it's also a neat hack, and sometimes a neat hack is what you need. It also occurs to me that this hack could be expanded a bit to handle a much larger input domain. If you had sequences of arbitrary (but hashable) objects, you could map this into a unicode string where each "character" is the 32-bit hash of of the corresponding input object, then run the regex search on that. In theory, it should work. In practice, I can see a few potential problems: 1) You might have to carefully craft your hash function to avoid magic unicode values like null or BOM. No biggie there. 2) Hash collisions can lead to false positives, so you need to filter those out with a subsequent linear comparison step. Of course, this is true of any kind of hash lookup. No biggie there either. 3) While the re module is advertised to work on unicode data, I have no idea how efficient it is on arbitrary values. I wouldn't be too surprised if it's tuned for "mostly ascii utf-8" and performance suffers on completely random strings. If its first step is to transcode to utf-32 internally, I expect it would work just fine, but it would take some experimentation (or reading of the source code) to validate this assumption. From aspineux at gmail.com Tue Aug 16 08:55:54 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 16 Aug 2011 05:55:54 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <77300e22-241d-4b85-9758-680ed8ebbfc7@z17g2000vbp.googlegroups.com> On Aug 16, 6:32?am, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. I don't use service for my own python applications, even standalone py2exe applications. I use the Windows taskscheduler that start it once and try every minute to start it again but is is running all the time, and the the scheduler does nothing and wait to see for the next minute. When the python program crash then the scheduler restart it in the minute. look here how I do with tcpproxyreflector: http://blog.magiksys.net/software/tcp-proxy-reflector#tcpr_service In My MKSBackup http://blog.magiksys.net/mksbackup-quick-overview I have a install() function that create the task in the scheduler for XP and Windows2008 And this code, use a 2 min interval print 'create task %s in scheduler' % (task_name, ) interval=raw_input_with_default('Enter interval in minutes', '>', str(interval_in_minutes)) cmd='"%s" -c "%s"' % (os.path.join(install_target, os.path.basename(sys.argv[0])), os.path.join(target, ini_file)) schtasks_cmd=[ 'SCHTASKS', '/Create', '/SC', 'MINUTE', '/MO', interval, '/TN', task_name, '/RU', os.getenv('USERNAME'), '/TR', cmd ] if sys.getwindowsversion()[0]>5: # under 2008 ? require HIGHEST privilege # schtasks_cmd.insert(2, 'HIGHEST') # schtasks_cmd.insert(2, '/RL') # under 2008, to force the system to ask for the password, set empty password i=schtasks_cmd.index('/RU')+2 schtasks_cmd.insert(i, '') schtasks_cmd.insert(i, '/RP') else: pass Mix all 3 source to get what you want. Services are probably fine too, but this is another story. > > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. Overall, reading about Windows > services in Python is not exactly a confidence inspiring experience. > If I knew of a reference example of something reliably running in > production, I'd feel better than copying and pasting some code from a > guy's blog. From miki.tebeka at gmail.com Tue Aug 16 09:32:21 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 16 Aug 2011 06:32:21 -0700 (PDT) Subject: Application monitoring In-Reply-To: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> References: <0bb4d667-925d-40ab-8b99-12eed554be3b@c19g2000yqe.googlegroups.com> Message-ID: http://www.nagios.org/ From jjposner at codicesoftware.com Tue Aug 16 09:57:37 2011 From: jjposner at codicesoftware.com (John Posner) Date: Tue, 16 Aug 2011 09:57:37 -0400 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A7751.7050906@codicesoftware.com> On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would require a fair amount of code, and Python > isn't a particularly fast language, so you're likely to get better results > if you can delegate most of the leg-work to a native library (along the > lines of Roy's suggestion of using regexps). > > How about using Python's core support for "==" on list objects: def contains(alist, slist): """ predicate: is *slist* a sublist of *alist*? """ alist_sz = len(alist) slist_sz = len(slist) # special cases if slist_sz == 0: return True # empty list *is* a sublist elif slist_sz == alist_sz and alist == slist: return True elif slist_sz > alist_sz: return False # standard case for i in range(alist_sz - slist_sz + 1): if slist == alist[i:i+slist_sz]: return True # fell through "for" loop: no match found return False -John From jjposner at optimum.net Tue Aug 16 09:57:57 2011 From: jjposner at optimum.net (John Posner) Date: Tue, 16 Aug 2011 09:57:57 -0400 Subject: testing if a list contains a sublist In-Reply-To: References: Message-ID: <4E4A7765.9010009@optimum.net> On 2:59 PM, Nobody wrote: > On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote: > >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > "Best" is subjective. AFAIK, the theoretically-optimal algorithm is > Boyer-Moore. But that would require a fair amount of code, and Python > isn't a particularly fast language, so you're likely to get better results > if you can delegate most of the leg-work to a native library (along the > lines of Roy's suggestion of using regexps). > > How about using Python's core support for "==" on list objects: def contains(alist, slist): """ predicate: is *slist* a sublist of *alist*? """ alist_sz = len(alist) slist_sz = len(slist) # special cases if slist_sz == 0: return True # empty list *is* a sublist elif slist_sz == alist_sz and alist == slist: return True elif slist_sz > alist_sz: return False # standard case for i in range(alist_sz - slist_sz + 1): if slist == alist[i:i+slist_sz]: return True # fell through "for" loop: no match found return False -John From fabiofz at gmail.com Tue Aug 16 10:06:18 2011 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 16 Aug 2011 11:06:18 -0300 Subject: How to use python environment created using virtualenv? In-Reply-To: References: Message-ID: On Tue, Aug 16, 2011 at 2:15 AM, smith jack wrote: > I have created a python environment using virtualenv, but when i want > to import such environment to PyDev, error just appears, > it tells there should be a Libs dir, but there is no Libs DIr in the > virtual envronment created using virtualenv, what should i do if > i want to use this virtual environment? You have to use the Lib dir from the base python (the one you used to create your virtualenv) -- it needs that to have access to the base python library (i.e.: threading.py, etc). Cheers, Fabio From philip at semanchuk.com Tue Aug 16 10:13:36 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 10:13:36 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: > >> >> On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: >> >>> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >>> >>>> If you want a future directive that deals with it, I'd do it the other >>>> way - from __future__ import mask_builtin_warning or something - so >>>> the default remains as it currently is. But this may be a better job >>>> for a linting script. >>> >>> Agreed. It's a style issue, nothing else. There's nothing worse about: >>> >>> def spam(list): >>> pass >>> >>> compared to >>> >>> class thingy: pass >>> >>> def spam(thingy): >>> pass >>> >>> Why should built-ins be treated as more sacred than your own objects? >> >> Because built-ins are described in the official documentation as having a >> specific behavior, while my objects are not. > > *My* objects certainly are, because I write documentation for my code. My > docs are no less official than Python's docs. I'm sure they are no less official to you. But you are you, and then there's...everyone else. =) I (and I think most people) give far more credibility to the Python docs than to the documentation of an individual. That's not a reflection on you, it reflects the limits of one person's ability versus organizationally produced docs which are heavily used, discussed, and have been iteratively developed over many years. > Sometimes shadowing is safe, sometimes it isn't. "Sometimes X is safe and sometimes it isn't" can be said of many, many things, from taking a walk down the street to juggling with knives. But it has little to do with whether or not Python should issue a warning in the specific case we're talking about. > A warning that is off by default won't help the people who need it, because > they don't know enough to turn the warning on. I agree that it wouldn't help the people who need it most (absolute raw newcomers). But you're asserting that once one learned the incantation to enable the theoretical warning we're discussing, one would have graduated to a level where it's no longer useful. That's not the case. There's a lot of ground to cover between "newcomer who has learned about a particular warning" and "coder who regularly shadows builtins on purpose". I am an example. I know enough to turn the theoretical warning on, and I would if I could. I have never shadowed a builtin deliberately. I've done it accidentally plenty of times. There are 84 builtins in my version of Python and I don't have them all memorized. The fact that my editor colors them differently is the only thing I have to back up my leaky memory. Not all editors are so gracious. >> Yes, it can be useful to replace some of the builtins with one's own >> implementation, and yes, doing so fits in with Python's "we're all >> consenting adults" philosophy. But replacing (shadowing, masking -- call >> it what you will) builtins is not everyday practice. On the contrary, as >> the OP Gerrat pointed out, it's most often done unwittingly by newcomers >> to the language who have no idea that they've done anything out of the >> ordinary or potentially confusing. > > Protecting n00bs from their own errors is an admirable aim, but have you > considered that warnings for something which may be harmless could do more > harm than good? Isn't the whole point of a warning to highlight behavior that's not strictly wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble to me. I hope you know what you're doing". If we are to eschew warnings in cases where they might be highlighting something harmless, then we would have no warnings at all. Again, shadowing builtins is not everyday practice. I have been trying to remember if I've ever seen it done deliberately, and I can't remember a case. Now, a comment like that is an invitation for people come out of the woodwork with cases where they found it useful, and I would welcome some examples as I'm sure they'd be interesting. But I think it's safe to say that if you look at random samples of code, builtins are shadowed unintentionally hundreds of times for every time they're shadowed deliberately and usefully. >> If a language feature is most often invoked accidentally without knowledge >> of or regard for its potential negative consequences, then it might be >> worth making it easier to avoid those accidents. > > Perhaps. But I'm not so sure it is worth the cost of extra code to detect > shadowing and raise a warning. After all, the average coder probably never > shadows anything, One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. > and for those that do, once they get bitten *once* they > either never do it again or learn how to shadow safely. I have done it plenty of times, never been bitten (thankfully) and still do it by accident now and again. You can coerce any example to apply to an argument for or against such a warning, but I think the general case is that Python could reduce unintended consequences by warning when vars erase builtins. (<=== How many builtins did I use in that sentence?) Cheers Philip From lists at cheimes.de Tue Aug 16 10:14:33 2011 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Aug 2011 16:14:33 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: Am 16.08.2011 10:04, schrieb Chris Rebert: > You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): > http://docs.python.org/library/pwd.html#pwd.getpwnam You should replace it. /etc/passwd is not the only source for users. /etc/nsswitch.conf may list more user and group sources like nis/yp, LDAP and so on. Christian From thinke365 at gmail.com Tue Aug 16 10:23:46 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 22:23:46 +0800 Subject: Failed to create virtual environment when using --relocatable option, what's wrong? Message-ID: all things works well without --relocatable option, the error info when using --relocatable option is as follows : F:\PythonEnv\djangoEnv>virtualenv f:\PythonEnv\djangoEnv2 --relocatable PYTHONHOME is set. You *must* activate the virtualenv before using it The environment doesn't have a file f:\PythonEnv\djangoEnv2\Scripts\activate_thi s.py -- please re-run virtualenv on this environment to update it Traceback (most recent call last): File "E:\Tools\gov\tools\chrome_python\Scripts\virtualenv-script.py", line 7, in ? sys.exit( File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 802, in main make_environment_relocatable(home_dir) File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 1338, in make_environment_relocatable fixup_scripts(home_dir) File "e:\tools\gov\tools\chrome_python\lib\site-packages\virtualenv-1.6.4-py2. 4.egg\virtualenv.py", line 1357, in fixup_scripts for filename in os.listdir(bin_dir): WindowsError: [Errno 3] : 'f:\\PythonEnv\\djangoEnv2\\Scripts/*.*' From snorble at hotmail.com Tue Aug 16 10:46:31 2011 From: snorble at hotmail.com (snorble) Date: Tue, 16 Aug 2011 07:46:31 -0700 (PDT) Subject: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> On Aug 16, 2:52?am, Tim Golden wrote: > On 16/08/2011 05:32, snorble wrote: > > > Anyone know of a Python application running as a Windows service in > > production? I'm planning a network monitoring application that runs as > > a service and reports back to the central server. Sort of a heartbeat > > type agent to assist with "this server is down, go check on it" type > > situations. > > Don't know what it'll take to inspire you with confidence, but I have > several Python services running here without a hitch. > The longest have been running for about three years -- not without > a stop, since they have to be restarted for reasons external to the > service itself. > > There's no py2exe involved, just the pywin32 service wrappers. (The > apps in question are also set up to run standalone for testing etc.). > They're mostly around a helpdesk system: one app ingests email requests > to the helpdesk; another post-processes call changes, currently to > send out email alerts to interested parties; another triggers alarms > on calls for various purposes, etc. > > I don't claim they're the most sophisticated pieces of code on Earth, > but it doesn't sound like you're after anything spectacular either. > > TJG Interesting. Normally I would use py2exe then do "myapp.exe -install" to install the app as a service. How do you handle installing the service? Also what does the service show under the properties, for the executable? "python.exe script.py" or something else? From thinke365 at gmail.com Tue Aug 16 10:50:23 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 16 Aug 2011 22:50:23 +0800 Subject: why i cannot import djang? Message-ID: this package is already in the site-packages directory, but i cannot import it , it's really confusing ... From pruebauno at latinmail.com Tue Aug 16 10:53:48 2011 From: pruebauno at latinmail.com (nn) Date: Tue, 16 Aug 2011 07:53:48 -0700 (PDT) Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> Message-ID: <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> On Aug 16, 8:23?am, Alain Ketterlin wrote: > Roy Smith writes: > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > [...] > > > import re > > > def sublist(l1, l2): > > ? ? s1 = ''.join(map(str, l1)) > > ? ? s2 = ''.join(map(str, l2)) > > ? ? return re.search(s1, s2) > > This is complete nonsense (try it on [12] and [1,2]). > > The original problem is "string searching" (where strings here are > sequences of numbers instead of characters). See > > http://en.wikipedia.org/wiki/String_searching_algorithm > > for any algorithm (Rabin-Karp seems appropriate to me). > > -- Alain. That can be easily fixed: >>> def sublist(lst1, lst2): s1 = ','.join(map(str, lst1)) s2 = ','.join(map(str, lst2)) return False if s2.find(s1)==-1 else True >>> sublist([1,2],[1,2,3,4,5]) True >>> sublist([1,2,2],[1,2,3,4,5]) False >>> sublist([1,2,3],[1,3,5,7]) False >>> sublist([12],[1,2]) False >>> I don't know about best, but it works for the examples given. From smainklh at gmail.com Tue Aug 16 10:57:27 2011 From: smainklh at gmail.com (smain kahlouch) Date: Tue, 16 Aug 2011 16:57:27 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: Ok than you. You're right but it doesn't help me : I replaced it : >>> def finduser(user): ... if pwd.getpwnam(user): ... print user, "user exists" ... return True ... return False ... >>> finduser('realuser') realuser user exists True >>> finduser('blabla') Traceback (most recent call last): File "", line 1, in ? File "", line 2, in finduser KeyError: 'getpwnam(): name not found: blabla' As you can see, i just want to look for a user and if it doesn't exist, an action is taken (create user). Maybe you have another way to do that check ? Thank you 2011/8/16 Christian Heimes > Am 16.08.2011 10:04, schrieb Chris Rebert: > > You can replace the /etc/passwd parsing with a call to pwd.getpwnam(): > > http://docs.python.org/library/pwd.html#pwd.getpwnam > > You should replace it. /etc/passwd is not the only source for users. > /etc/nsswitch.conf may list more user and group sources like nis/yp, > LDAP and so on. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Aug 16 11:06:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 08:06:12 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> Message-ID: <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> On Aug 16, 2:07?am, alex23 wrote: > All the way down indeed. Can you pick who said these? Obviously your grep skills are superb however you need to brush up on those reading and comprehension skills a bit. > "There are noobs watching and we to provide code that can be used to > teach!" Yes i said this, however the use of "used to" is proper here. -1 > "And just what *point* an i supposed to be "getting" Stephen?" Yes i said this, and it "may" seem that you have me on this one however i believe that Stephen had said something like """you are "supposed to" blah, blah""" and i retorted with """oh, and just what *point* am i "supposed to" blah blah blah"""... although i DID forget to quote "supposed to", still it's a -1. > "An end user should NEVER EVER have to write glue code so their > "abstraction of choice" can be used to to script an API." Yes i said this, however AGAIN the use of "used to" is proper here. -1. sorry alex, better luck next time :(. Follows is some homework i have prepared for you so that you can understand the proper and improper usage of "used to". Incorrect past tense usage of "used to": """ I "used to" wear wooden shoes """ Incorrect description using "used to": """ I have become "used to" wearing wooden shoes """ Correct usage of "used to": """ Wooden shoes can be "used to" torture someone """ For our next assignment we'll be learning about the exploits of Jack and Jill. > (For bonus points: can you also spot who is bored at work today?) Trolling doesn't count as "work" unless you're being paid for it, however some people might consider you a pro by now! PS: Does anyone notice how Stephen has fallen off the face the earth? Where is Stephen i wonder? He was such a vocal nuisance and then he just disappeared. It seemed like he appeared as strangely as he disappeared. Well, he's probably where most sock puppets go when they have no further usage. From k.sahithi2862 at gmail.com Tue Aug 16 11:06:31 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 16 Aug 2011 08:06:31 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS Message-ID: <16538baf-6729-46d6-b4fc-7e9b58a006a0@s2g2000vby.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html KAJAL AGARWAL HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html From rosuav at gmail.com Tue Aug 16 11:12:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 16:12:44 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: On Tue, Aug 16, 2011 at 3:13 PM, Philip Semanchuk wrote: > I am an example. I know enough to turn the theoretical warning on, and I would if I could. I have never shadowed a builtin deliberately. I've done it accidentally plenty of times. There are 84 builtins in my version of Python and I don't have them all memorized. The fact that my editor colors them differently is the only thing I have to back up my leaky memory. Not all editors are so gracious. > Rather than "turn a warning on" you can "run your code through a linting script". There are several excellent ones. Add it to your makefile or test suite; then you get the testing done over _all_ of your code, instead of waiting until the moment when you actually execute it. > One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. > There are several types of shadowing: 1) Deliberate shadowing because you want to change the behavior of the name. Extremely rare. 2) Shadowing simply by using the name of an unusual builtin (like 'file') in a context where you never use it. Very common. 3) Unintentional shadowing where you create a variable, but then intend to use the builtin. This is the only one that's a problem. list = [...] is not a problem unless you later on use foo = list(map(...)) which is more common in Python 3 than Python 2, but fortunately, it'll throw a nice quick error - nobody's going to use list operations on the normal 'list' type, nor is anybody going to call an instance of list. Definitely a job for linting. ChrisA From gandalf at shopzeus.com Tue Aug 16 11:17:08 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 16 Aug 2011 17:17:08 +0200 Subject: testing if a list contains a sublist In-Reply-To: <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <4E4A89F4.3090008@shopzeus.com> > That can be easily fixed: > >>>> def sublist(lst1, lst2): > s1 = ','.join(map(str, lst1)) > s2 = ','.join(map(str, lst2)) > return False if s2.find(s1)==-1 else True > > I don't know about best, but it works for the examples given. > For numbers, it will always work. But what about lst1 = [",",",,"] lst1 = [",",",",","] From dajo.mail at web.de Tue Aug 16 11:26:08 2011 From: dajo.mail at web.de (Johannes) Date: Tue, 16 Aug 2011 17:26:08 +0200 Subject: testing if a list contains a sublist In-Reply-To: <4E4A238F.7030003@shopzeus.com> References: <3bb01409-ee5e-4494-bef8-93029dd49ecb@h9g2000vbr.googlegroups.com> <4E4A238F.7030003@shopzeus.com> Message-ID: <4E4A8C10.5090208@web.de> Am 16.08.2011 10:00, schrieb Laszlo Nagy: > >> Error free? Consider this stated requirement: >>> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > If you look it the strict way, "containment" relation for lists is meant > this way: > > > l1 = [] > l2 = [1,l1,2] # l2 CONTAINS l1 > > But you are right, I was wrong. So let's clarify what the OP wants! > > For example: > > l1 = [1,2,2,], l2 = [2,1,2,3,4,5] I dont care about this case, because all list are ordered for me. I've chosen the following solution > def _list_contained_in_list(l1,l2): > d1 = {} > d2 = {} > for i in l1: > if i in d1: > d1[i] += 1 > else: > d1[i] = 1 > for i in l2: > if i in d2: > d2[i] += 1 > else: > d2[i] = 1 > if not all([k in d2.keys() for k in d1.keys()]): > return false > return all([d1[i] <= d2[i] for i in d1]) greatz Johannes From philip at semanchuk.com Tue Aug 16 11:31:30 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 11:31:30 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> On Aug 16, 2011, at 11:12 AM, Chris Angelico wrote: > On Tue, Aug 16, 2011 at 3:13 PM, Philip Semanchuk wrote: > >> One need look no further than the standard library to see a strong counterexample. grep through the Python source for " file =". I see dozens of examples of this builtin being used as a common variable name. I would call contributors to the standard library above-average coders, and we can see them unintentionally shadowing builtins many times. >> > > There are several types of shadowing: > > 1) Deliberate shadowing because you want to change the behavior of the > name. Extremely rare. > 2) Shadowing simply by using the name of an unusual builtin (like > 'file') in a context where you never use it. Very common. > 3) Unintentional shadowing where you create a variable, but then > intend to use the builtin. This is the only one that's a problem. Yes, but before you get to #3 you have to go through #2. The way I see it, #2 is setting a trap, #3 is actually stepping in it. I don't want to do either. Neither do I like working with code that has set trap #2 for me. Cheers Philip From philip at semanchuk.com Tue Aug 16 11:38:57 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 11:38:57 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4A8F94.50706@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: > Philip Semanchuk wrote: >> On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: >>> Protecting n00bs from their own errors is an admirable aim, but have you >>> considered that warnings for something which may be harmless could do more >>> harm than good? >> Isn't the whole point of a warning to highlight behavior that's not strictly > > wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble > > to me. I hope you know what you're doing". If we are to eschew warnings in > > cases where they might be highlighting something harmless, then we would > > have no warnings at all. > > Sounds good to me. ;) Keep such things in the IDE's, and then those who desire such behavior can have it there. Do not clutter Python with such. You wink, yet you sound serious. What's with the mixed message? Do you honestly advocate removing all warnings from Python, or not? I sincerely would like to know what you think. >>> Perhaps. But I'm not so sure it is worth the cost of extra code to detect >>> shadowing and raise a warning. After all, the average coder probably never >>> shadows anything, >> One need look no further than the standard library to see a strong > > counterexample. grep through the Python source for " file =". I see dozens >> of examples of this builtin being used as a common variable name. I would > > call contributors to the standard library above-average coders, and we can > > see them unintentionally shadowing builtins many times. > > What makes you think it's unintentional? file makes a good variable name, and if you don't need it to actually open a file there's nothing wrong with using it yourself. "Unintentional" as in, "I'm using file as a variable name because it's handy" as opposed to intentional as in "Yes, I am deliberately changing the meaning of this builtin". >>> and for those that do, once they get bitten *once* they >>> either never do it again or learn how to shadow safely. >> I have done it plenty of times, never been bitten (thankfully) and still > > do it by accident now and again. > > Seems to me the real issue is somebody using a builtin, such as str or int, and that they somehow manage to do this without realizing, "wait a sec', that's one of my variables!" Yes > I don't see that as a problem that Python needs to solve. "need" is a strong word. Python will be fine regardless of whether this changes or not. I believe Python could be improved; that's all I'm arguing. Cheers Philip From alain at dpt-info.u-strasbg.fr Tue Aug 16 11:39:19 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 16 Aug 2011 17:39:19 +0200 Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <87vctx74d4.fsf@dpt-info.u-strasbg.fr> Laszlo Nagy writes: >>>>> def sublist(lst1, lst2): >> s1 = ','.join(map(str, lst1)) >> s2 = ','.join(map(str, lst2)) >> return False if s2.find(s1)==-1 else True >> >> I don't know about best, but it works for the examples given. >> > For numbers, it will always work. I'm not even sure: if str() is locale-sensitive, it may introduce commas in numbers (I don't know whether str() is locale-sensitive, the doc doesn't mention anything.) > But what about > > lst1 = [",",",,"] > lst1 = [",",",",","] Yes. It will also fail on nested lists, for fundamental reasons which are impossible to handle with regexps. (Tough I'm not sure the OP had nested lists in mind.) The "brute-force" algorithm given somewhere else in this thread is probably the way to go, unless the lists are really long, in which case one of the "string searching" algorithm should be used (I would be surprised noone has implemented Boyer-Moore or Karp-Rabin). -- Alain. From ethan at stoneleaf.us Tue Aug 16 11:41:08 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 08:41:08 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4A8F94.50706@stoneleaf.us> Philip Semanchuk wrote: > On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: >> Protecting n00bs from their own errors is an admirable aim, but have you >> considered that warnings for something which may be harmless could do more >> harm than good? > > Isn't the whole point of a warning to highlight behavior that's not strictly > wrong but looks iffy? Sort of, "I can't be sure, but this looks like trouble > to me. I hope you know what you're doing". If we are to eschew warnings in > cases where they might be highlighting something harmless, then we would > have no warnings at all. Sounds good to me. ;) Keep such things in the IDE's, and then those who desire such behavior can have it there. Do not clutter Python with such. >> Perhaps. But I'm not so sure it is worth the cost of extra code to detect >> shadowing and raise a warning. After all, the average coder probably never >> shadows anything, > > One need look no further than the standard library to see a strong > counterexample. grep through the Python source for " file =". I see dozens > of examples of this builtin being used as a common variable name. I would > call contributors to the standard library above-average coders, and we can > see them unintentionally shadowing builtins many times. What makes you think it's unintentional? file makes a good variable name, and if you don't need it to actually open a file there's nothing wrong with using it yourself. >> and for those that do, once they get bitten *once* they >> either never do it again or learn how to shadow safely. > > I have done it plenty of times, never been bitten (thankfully) and still > do it by accident now and again. Seems to me the real issue is somebody using a builtin, such as str or int, and that they somehow manage to do this without realizing, "wait a sec', that's one of my variables!" I don't see that as a problem that Python needs to solve. ~Ethan~ From rantingrick at gmail.com Tue Aug 16 11:44:28 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 08:44:28 -0700 (PDT) Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> On Aug 16, 9:13?am, Philip Semanchuk wrote: > "Sometimes X is safe and sometimes it isn't" can be said > of many, many things, from taking a walk down the street > to juggling with knives. But it has little to do with > whether or not Python should issue a warning in the > specific case we're talking about. I think any Python n00b should be writing code in n editor that is "safe for beginners" AND is also teaching tool. IDLE is probably the best thing a new Python programmer could use. It has syntax hilight, smart indention, call tips, code completion, a class browser, greping tools, and more! I do admit the tool is lacking in many areas (including code base) that would be atrocious to an experienced Pythonista, however, the tool is perfect for n00bs (and myself and other pythoinistas use it all the time!) > There's a lot of ground to cover between "newcomer who has > learned about a particular warning" and "coder who > regularly shadows builtins on purpose". One word: SYNTAX HILIGHT > I have never shadowed a builtin deliberately. I've done it > accidentally plenty of times. There are 84 builtins in my > version of Python and I don't have them all memorized. The > fact that my editor colors them differently is the only > thing I have to back up my leaky memory. Not all editors > are so gracious. So you have syntax hilight however you still shadow builtins? Oh dear, this problem is worse than i initially suspected! > You can coerce any example to apply to an argument for or > against such a warning, but I think the general case is > that Python could reduce unintended consequences by > warning when vars erase builtins. ?(<=== How many builtins > did I use in that sentence?) Well let's see: py> import keyword py> import __builtin__ py> PY_KWS = keyword.kwlist py> PY_BLT = dir(globals()['__builtins__']) py> s = """\ You can coerce any example to apply to an argument for or against such a warning, but I think the general case is that Python could reduce unintended consequences by warning when vars erase builtins. """ py> fmtstr = '{0} -> {1}' py> for word in s.split(' '): ... if word in PY_BLT: ... print fmtstr.format('builtin', word) ... elif word in PY_KWS: ... print fmtstr.format('KeyWord', word) ... builtin -> coerce builtin -> any builtin -> apply KeyWord -> for KeyWord -> or KeyWord -> is builtin -> reduce builtin -> vars From tjreedy at udel.edu Tue Aug 16 11:47:58 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 11:47:58 -0400 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: On 8/16/2011 7:33 AM, Paul Wray wrote: > Hello all > > Ive had what I think is a great idea for pure-python templates (I can > almost hear the groans, bear with me...) > > For the impatient, proof of concept is at http://pastie.org/2379978 > demonstrating simple substitution, balanced tags using context manager, > subtemplates, and template inheritance. > > I'm posting here to get opinions on: > * the merits of the idea, (or otherwise!) > * whether there are any established/mature templating systems that use > this approach, or whether its come up before, > * ideas for improvements and advice on other aspects such as sandboxing > * of course, to share the idea in case others want to use it > > Background: Ive been working on an application that recursively renders > html/xml documents from heterogenoeus trees, with separate classes for > each document component. First I built my own renderer but was > dissatisfied with the repetitive code. Then looked at Mako and Jinja, > and used Jinja but was still disatisfied, because I still needed a > render method in each class to do preparation, and also the template > which was centrally managed by the Jinja loader and environment. I found > a way to call templates recursively via Jinja filters, but was not sure > that it wouldnt blow up in my face, so I also had separate calls to > render the children of each node, and then feed the value to the parent > template. I kept thinking that there must be a way to get the brevity > and clarity of declarative templates, plus the simplicity of pure python > loops, tests and function calls. > > The idea: > Python syntax allows a statement to be a bare literal or identifier. > These have no effect on the program. More generally, Python has expression statements, with the result of the expression ignored. These are usually function calls with side-effects. "print('x')" has no effect on the program and the return value is usually ignored. > So the function below is legal python: > > def myFunc(): > 'a' > x = 45 > 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' > > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. Interesting idea, though I have no experience for comparison. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 16 11:52:13 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 11:52:13 -0400 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: On 8/16/2011 10:57 AM, smain kahlouch wrote: > Ok than you. You're right but it doesn't help me : > I replaced it : > > >>> def finduser(user): > ... if pwd.getpwnam(user): > ... print user, "user exists" > ... return True > ... return False > ... > >>> finduser('realuser') > realuser user exists > True > >>> finduser('blabla') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 2, in finduser > KeyError: 'getpwnam(): name not found: blabla' > > As you can see, i just want to look for a user and if it doesn't exist, > an action is taken (create user). Replace if/then with try/except control flow try: pwd.getpwnam(user) return True except KeyWordError: return False -- Terry Jan Reedy From alex.kapps at web.de Tue Aug 16 11:56:37 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 16 Aug 2011 17:56:37 +0200 Subject: Linux : create a user if not exists In-Reply-To: References: Message-ID: <4E4A9335.4010700@web.de> On 16.08.2011 16:57, smain kahlouch wrote: > Ok than you. You're right but it doesn't help me : > I replaced it : > > >>> def finduser(user): > ... if pwd.getpwnam(user): > ... print user, "user exists" > ... return True > ... return False > ... > >>> finduser('realuser') > realuser user exists > True > >>> finduser('blabla') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 2, in finduser > KeyError: 'getpwnam(): name not found: blabla' Untested: def finduser(name): try: return pwd.getpwnam(name) except KeyError: return None if not finduser("myuser"): print "creating user..." else: print "user already exists" Has the advantage that finduser() returns the user details if needed. (BTW: Please don't top-post) From python.list at tim.thechases.com Tue Aug 16 12:10:46 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 11:10:46 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> Message-ID: <4E4A9686.2090909@tim.thechases.com> On 08/16/2011 10:31 AM, Philip Semanchuk wrote: > On Aug 16, 2011, at 11:12 AM, Chris Angelico wrote: >> There are several types of shadowing: >> >> 1) Deliberate shadowing because you want to change the behavior of the >> name. Extremely rare. >> 2) Shadowing simply by using the name of an unusual builtin (like >> 'file') in a context where you never use it. Very common. >> 3) Unintentional shadowing where you create a variable, but then >> intend to use the builtin. This is the only one that's a >> problem. > > Yes, but before you get to #3 you have to go through #2. The > way I see it, #2 is setting a trap, #3 is actually stepping > in it. I don't want to do either. Neither do I like working > with code that has set trap #2 for me. Chris succinctly described the times I've done shadowing. Fortunately, the shadowing done in #3 (which you appropriately describe as being a superset of #2) is fairly remedied with most editors...since it usually occurs when you have "oh, I accidentally shadowed builtin X", so you just do a global search-and-replace for all those places you shadowed X and rename it to something like "my_X" and proceed to use X as the builtin. The bigger issue I have is module shadowing which is trickier to catch and produces weird symptoms (i.e. cryptic errors). The most common one I see is creating a local module called "email.py" and then having issues when trying to use standard-library email calls which find your local email.py before they find the email.py file in the standard library. I actually wrote a tool to scan for duplicate modules in $PYTHONPATH (pretty dumb tool, could easily have broken on things like zipfile imports, DLLs, etc), but it made diagnosing the issue easier. -tkc From gordon at panix.com Tue Aug 16 12:12:09 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 16:12:09 +0000 (UTC) Subject: why i cannot import djang? References: Message-ID: In smith jack writes: > this package is already in the site-packages directory, but i cannot > import it , it's really confusing ... Is it in the site-packages directory for the particular version of python you're using? For example, my system has both python2.3 and python2.5 installed, and they both have their own site-packages directories: /usr/lib/python2.3/site-packages /usr/lib/python2.5/site-packages A package installed for only one version of python won't be importable if you're running a different python version. (If you don't know which version you're running, the version number should be displayed when you start up a python shell, like this: command prompt> python Python 2.3.4 (#1, Apr 15 2011, 17:38:51) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Tue Aug 16 12:14:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 17:14:24 +0100 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: On Tue, Aug 16, 2011 at 12:33 PM, Paul Wray wrote: > The idea is simply to use python ASTs to transform this code so that it > accumulates the values of the bare expressions. That'd be similar to what the interactive loop does. Are you aware, though, that docstrings are bare expressions? You may have a syntactic collision there. ChrisA From anand.ibmgsi at gmail.com Tue Aug 16 12:16:07 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 16 Aug 2011 21:46:07 +0530 Subject: Idea for pure-python templates using AST. In-Reply-To: <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> Message-ID: Hi all, I did it. Finally managed to port mysqltuner.pl to python. Was a real pain in the butt doing it from bottom up manually, without ever really learing perl syntax. But i finally got it done. Now i need help testing it. find it here. git at github.com:anandjeyahar/mysqlDbAdmin-python.git. Also i never really thought about design. Just blindly/mechanically, translated from perl to python. So criticize and let me know how i can improve this. Thanks and Regards, ============================================== Anand Jeyahar https://sites.google.com/site/anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ? ? ? ? ? ? ? ? ? ~Bruce Lee Love is a trade with lousy accounting policies. ? ? ? ? ? ? ? ?? ~Aang Jie On Tue, Aug 16, 2011 at 18:02, aspineux wrote: > On Aug 16, 1:33?pm, "Paul Wray" wrote: >> Hello all >> >> Ive had what I think is a great idea for pure-python templates (I can almost >> hear the groans, bear with me...) >> >> For the impatient, proof of concept is athttp://pastie.org/2379978 >> demonstrating simple substitution, balanced tags using context manager, >> subtemplates, ?and template inheritance. > > You code fail, see below for other comment > > Traceback (most recent call last): > ?File "Download/pastie-2379978.rb", line 108, in > ? ?make_template(template1) > ?File "Download/pastie-2379978.rb", line 60, in make_template > ? ?ast.fix_missing_locations(astFromSrc) > ?File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations > ? ?_fix(node, 1, 0) > ?File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ?_fix(child, lineno, col_offset) > ?File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ?_fix(child, lineno, col_offset) > ?File "/usr/lib/python2.6/ast.py", line 121, in _fix > ? ?if 'lineno' in node._attributes: > AttributeError: 'arguments' object has no attribute '_attributes' > > > > >> >> I'm posting here to get opinions on: >> * the merits of the idea, (or otherwise!) >> * whether there are any established/mature templating systems that use this >> approach, or whether its come up before, >> * ideas for improvements and advice on other aspects such as sandboxing >> * of course, to share the idea in case others want to use it > > This is very original ! First time I see it. I like it. > But how to debug large template ? > How to find/detect a missing ? > This is very important. This is one big advantage of Genshi over Kid > How to report the correct error at the correct line ? > How to find/get nice editor to edit large template ? > > >> >> Background: Ive been working on an application that recursively renders >> html/xml documents from heterogenoeus trees, with separate classes for each >> document component. First I built my own renderer but was dissatisfied with >> the repetitive code. Then looked at Mako and Jinja, and used Jinja but was >> still disatisfied, because I still needed a render method in each class to >> do preparation, and also the template which was centrally managed by the >> Jinja loader and environment. I found a way to call templates recursively >> via Jinja filters, but was not sure that it wouldnt blow up in my face, so I >> also had separate calls to render the children of each node, and then feed >> the value to the parent template. I kept thinking that there must be a way >> to get the brevity and clarity of declarative templates, plus the simplicity >> of pure python loops, tests and function calls. >> >> The idea: >> Python syntax allows a statement to be a bare literal or identifier. These >> have no effect on the program. >> >> So the function below is legal python: >> >> def myFunc(): >> ? ? 'a' >> ? ? x = 45 >> ? ? 'b'; 'c'; x >> >> So is this (within the appropriate class context of course): >> >> def body(self, r): >> ? ? ? ? '

'; self.heading; '

' >> ? ? ? ? '
    ' >> ? ? ? ? for itm in self.items: >> ? ? ? ? ? ? '
  • '; itm; '
  • ' >> ? ? ? ? '
' >> >> The idea is simply to use python ASTs to transform this code so that it >> accumulates the values of the bare expressions. > > You could call it PHP :-) > >> >> I think this give the best of both worlds - declarative syntax for the >> template literals, but in a pure python context, giving you all the power of >> python control statements, classes etc. >> >> For application contexts outside pure python code (ie user-created >> templates) , it would be simple to extend the technique to creating template >> functions from strings, and insert the resulting methods into a namespace >> for execution.) >> >> I think, given the technique is already working with the AST, that >> sandboxing should not be too hard either - advice on this aspect would be >> appreciated. > > > Maybe a good idea. > But still a lot of work to get the level of existing libraries. > > Maybe better if mixed with other tools like Genshi to create widget. > Maybe next toscawidget could use such a technique. > > > Thanks for sharing > >> >> Paul Wray > > -- > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Tue Aug 16 12:19:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 09:19:58 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: <4E4A98AE.1070708@stoneleaf.us> Philip Semanchuk wrote: > On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: >> Philip Semanchuk wrote: >>> If we are to eschew warnings in >>> cases where they might be highlighting something harmless, then we would >>> have no warnings at all. >> >> Sounds good to me. ;) Keep such things in the IDE's, and then those >> who desire such behavior can have it there. Do not clutter Python with >> such. > > You wink, yet you sound serious. The smiley is an attempt to not sound harsh. > What's with the mixed message? Do you honestly advocate removing all > warnings from Python, or not? I sincerely would like to know what you think. I think warnings should be reserved for language changes and such (like DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible programmer mistakes. >> What makes you think it's unintentional? file makes a good variable name... > > "Unintentional" as in, "I'm using file as a variable name because it's handy" > as opposed to intentional as in "Yes, I am deliberately changing the meaning > of this builtin". That's not what 'unintentional' means. Further, there's no way to tell whether it was or was not from the code alone. Unless it caused a bug, in which case I'd be willing to call it unintentional. ;) >> I don't see that as a problem that Python needs to solve. > > "need" is a strong word. Python will be fine regardless of whether this changes > or not. I believe Python could be improved; that's all I'm arguing. Python can be improved -- I don't see 'hand-holding' as an improvement. IDEs and lints can do this. ~Ethan~ From philip at semanchuk.com Tue Aug 16 12:32:52 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 12:32:52 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4A98AE.1070708@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> Message-ID: <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> On Aug 16, 2011, at 12:19 PM, Ethan Furman wrote: > Philip Semanchuk wrote: >> On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: >>> Philip Semanchuk wrote: >>>> If we are to eschew warnings in >>>> cases where they might be highlighting something harmless, then we would >>>> have no warnings at all. > >> >>> Sounds good to me. ;) Keep such things in the IDE's, and then those > >> who desire such behavior can have it there. Do not clutter Python with > >> such. >> You wink, yet you sound serious. > > The smiley is an attempt to not sound harsh. Thanks. It's hard to know on the Internet. >>> I don't see that as a problem that Python needs to solve. >> "need" is a strong word. Python will be fine regardless of whether this changes > > or not. I believe Python could be improved; that's all I'm arguing. > > Python can be improved -- I don't see 'hand-holding' as an improvement. IDEs and lints can do this. When you say "hand-holding", I hear a pejorative. That makes "I don't see 'hand-holding' as an improvement" a tautology. Have I misheard you? I think Python does lots of beneficial hand-holding. Garbage collection is a good example. $DIETY knows, people have been struggling with manual memory management in C and its ilk for a long time. Even though there are good tools to help, memory leaks still happen. Python increases our productivity by allowing us to forget about manual memory management altogether. I can do it with tools like valgrind, but Python's makes the point moot. Is that hand-holding? If so, I'm all for it. Cheers Philip From gennad.zlobin at gmail.com Tue Aug 16 12:36:03 2011 From: gennad.zlobin at gmail.com (Gennadiy Zlobin) Date: Tue, 16 Aug 2011 23:36:03 +0700 Subject: why i cannot import djang? In-Reply-To: References: Message-ID: import sys print sys.path # All directories where Python looks for packages - Gennadiy On Tue, Aug 16, 2011 at 11:12 PM, John Gordon wrote: > In smith jack < > thinke365 at gmail.com> writes: > > > this package is already in the site-packages directory, but i cannot > > import it , it's really confusing ... > > Is it in the site-packages directory for the particular version of > python you're using? > > For example, my system has both python2.3 and python2.5 installed, and > they both have their own site-packages directories: > > /usr/lib/python2.3/site-packages > /usr/lib/python2.5/site-packages > > A package installed for only one version of python won't be importable > if you're running a different python version. > > (If you don't know which version you're running, the version number > should be displayed when you start up a python shell, like this: > > command prompt> python > Python 2.3.4 (#1, Apr 15 2011, 17:38:51) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.ibmgsi at gmail.com Tue Aug 16 12:38:35 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 16 Aug 2011 22:08:35 +0530 Subject: python mysqltuner port Message-ID: Hi all, Sorry for the repeat post. Had posted earlier in between an irrelevant thread by accident. > Hi all, > ? I did it. Finally managed to port mysqltuner.pl to python. Was a > real pain in the butt doing it from bottom up manually, without ever > really learing perl syntax. But i finally got it done. Now i need help > testing it. find it here. > ?git at github.com:anandjeyahar/mysqlDbAdmin-python.git. > > Also i never really thought about design. Just blindly/mechanically, > translated from perl to python. So criticize and let me know how i can > improve this. > > Thanks and Regards, > ============================================== > Anand Jeyahar > https://sites.google.com/site/anandjeyahar > ============================================== > The man who is really serious, > with the urge to find out what truth is, > has no style at all. He lives only in what is. > ? ? ? ? ? ? ? ? ? ~Bruce Lee > > Love is a trade with lousy accounting policies. > ? ? ? ? ? ? ? ?? ~Aang Jie From python at mrabarnett.plus.com Tue Aug 16 12:41:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 17:41:55 +0100 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: <4E4A9DD3.3040908@mrabarnett.plus.com> On 16/08/2011 00:26, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > Here's my solution, using the Counter class: >>> from collections import Counter >>> >>> c1 = Counter([1,2]) >>> c2 = Counter([1,2,3,4,5]) >>> (c1 & c2) == c1 True >>> >>> c1 = Counter([1,2,2,]) >>> c2 = Counter([1,2,3,4,5]) >>> (c1 & c2) == c1 False >>> >>> c1 = Counter([1,2,3]) >>> c2 = Counter([1,3,5,7]) >>> (c1 & c2) == c1 False From ethan at stoneleaf.us Tue Aug 16 13:07:58 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:07:58 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> <2DF0915B-4F34-43D2-A2AB-A7FB35B76039@semanchuk.com> Message-ID: <4E4AA3EE.1070104@stoneleaf.us> Philip Semanchuk wrote: > I think Python does lots of beneficial hand-holding. Garbage collection > is a good example. $DIETY knows, people have been struggling with manual > memory management in C and its ilk for a long time. Even though there > are good tools to help, memory leaks still happen. Python increases our > productivity by allowing us to forget about manual memory management > altogether. I can do it with tools like valgrind, but Python's makes > the point moot. Is that hand-holding? If so, I'm all for it. Good point. There is an important difference, however, between offering warnings to newbie programmers (which is how this thread started), and memory management. ~Ethan~ From usenet-nospam at seebs.net Tue Aug 16 13:11:37 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:37 GMT Subject: Anyone here can do a comparation between Djang and RoR References: Message-ID: On 2011-08-16, smith jack wrote: > what is the advantage of Django over RoR:) This question is pretty much... I mean, you're not gonna get useful answers. They're based on such different languages that I think any comparison past that is likely going to be uninteresting to a programmer, and I'm not sure any non-programmers are going to use either. I will say, the things I most value in Rails are pretty much contrary to conventional Python design philosophy. Python's stress on explicit over implicit is probably in contradiction with the Rails philosophy of convention over configuration. So for instance, if all you want of a class that maps to a database table in Rails is that it map the fields in the database, the class body is empty because that's the default. If you want to tell it that the database column foo_id represents the id of the foo object with which this record is associated, and you want to call that .foo, you write: belongs_to :foo and the rest is all implicit. This is really handy sometimes, but it's not very Pythonic... Mostly, I think you'd probably be better off asking in a completely different kind of forum, but even then, you're going to get mostly language advocacy. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-16, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >>> Why should built-ins be treated as more sacred than your own objects? >> Because built-ins are described in the official documentation as having a >> specific behavior, while my objects are not. > *My* objects certainly are, because I write documentation for my code. My > docs are no less official than Python's docs. Sure they are. I can't get yours from python.org. > You can shadow anything. Sometimes shadowing is safe, sometimes it isn't. I > don't see why we should necessarily fear safe shadowing of built-ins more > than we fear unsafe shadowing of non-built-ins. I think largely because anyone coming to your code will have expectations about the built-ins. For non-built-ins, they'll have to look around the code to see what they do, but for built-ins, they come to the table with an otherwise-reasonable expectation that they already know what that word means. > A warning that is off by default won't help the people who need it, because > they don't know enough to turn the warning on. A warning that is on by > default will be helpful to the newbie programmer for the first week or so, > and then will be nothing but an annoyance for the rest of their career. Will it? I am pretty sure that I'd keep it on and fix anything that triggered it, because shadowing built-ins strikes me as Asking For Trouble. > Protecting n00bs from their own errors is an admirable aim, but have you > considered that warnings for something which may be harmless could do more > harm than good? I would distinguish between "may not be causing bugs" and "may be harmless". I think code which shadows a built-in has a pretty real risk of being harmful at some unspecified future point when some maintainer who hasn't memorized every last line of the code makes the totally reasonable assumption that basic language features are still working and available. > Perhaps. But I'm not so sure it is worth the cost of extra code to detect > shadowing and raise a warning. After all, the average coder probably never > shadows anything, and for those that do, once they get bitten *once* they > either never do it again or learn how to shadow safely. I don't see it as a > problem. I would guess that it happens moderately often entirely by accident. Not a Python example, but I recently had a heck of a time with some JavaScript I was trying to maintain. Couldn't get it to work on a slightly older Firefox, and the diagnostics from Firebug came across as basically illucid. Problem: I was declaring an array named 'history'. My thoughts would be: 1. It's hard to avoid shadowing anything unless you know the entire language and never forget things. 2. In particular, Python likes to use clear, obvious, names for things. Meaning that your choice of a clear, obvious, name for a similar thing could be the name of a thing in the language. 3. I am not sure at all that shadowing can be "safe" in code which will some day be maintained. The chances of someone coming along and trying to write clean, idiomatic, Python which happens to blow up interestingly because their code runs in an environment where part of the standard language has been shadowed strike me as Too High. MHO, but speaking only for myself, I'd want that warning on and I'd not consider it harmless. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: On 2011-08-16, Ethan Furman wrote: > What makes you think it's unintentional? Programming experience. People *often* do things unintentionally. > Seems to me the real issue is somebody using a builtin, such as str or > int, and that they somehow manage to do this without realizing, "wait a > sec', that's one of my variables!" I don't see that as a problem that > Python needs to solve. I think the word "my" prejudices the case. Imagine stepping into a large project that uses multiple frameworks and class libraries and so on. You know Python but you're new to the project. Under which circumstance will you have more problems? 1. There is not a single shadowed built-in in the entire project. 2. There are dozens of shadowed built-ins based on when the original programmer felt there wasn't going to be a need for a given built-in feature, or possibly just didn't know about it. Also, how easy or hard do you think it will be to debug those problems? What's your first response going to be if, on a screen which doesn't contain the word file at all, you try to use the file built-in and you get some cryptic error? Are you going to know to go looking for the shadow right away? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Tue Aug 16 13:11:38 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 17:11:38 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Ethan Furman wrote: > I think warnings should be reserved for language changes and such (like > DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible > programmer mistakes. I disagree, on the basis of the following: The quality of C code I have to deal with has increased dramatically as gcc's aggressive use of warnings has spread. > Python can be improved -- I don't see 'hand-holding' as an improvement. > IDEs and lints can do this. -W ignore -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From grickert at coldstorage.com Tue Aug 16 13:15:04 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Tue, 16 Aug 2011 13:15:04 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: ... > A warning that is off by default won't help the people who need it, > because > they don't know enough to turn the warning on. A warning that is on by > default will be helpful to the newbie programmer for the first week or > so, > and then will be nothing but an annoyance for the rest of their career. > I think that best practices would suggest that one shouldn't use variable names that shadow builtins (except in specific, special circumstances), so I don't really think this would be an annoyance at all. The number of *unwanted* warnings they'd get would be pretty close to zero. OTOH, in response to a question I asked on StackOverflow, someone posted a large list of times where this isn't followed in the std lib, so there seems to be a precedent for just using the builtin names for anything one feels like at the time. Thinking about it, what about if, by default, python was configured to emit warnings about this sort of thing, but a simple environment variable or config option would turn them off. That way, new users would get warnings when doing this sort of thing, and any experienced user that wanted the option of using these variables anywhere would just have a one-time thing to change when they installed python (or any time later). They'd turn these warnings off when they installed Python, and would never have to think about it again. New users (or experienced ones that prefer this) would be warned by default, and then could make the conscious decision to shadow the builtin names, instead of accidentally doing it. All the suggestions to just use a linter aren't helpful, since new users aren't likely to start with one & and they are the thrust of this discussion. From bahamutzero8825 at gmail.com Tue Aug 16 13:23:55 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 16 Aug 2011 12:23:55 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <38c9de50-7cb1-47d6-803e-6d34b5399310@x2g2000yql.googlegroups.com> Message-ID: <4E4AA7AB.5000908@gmail.com> On 2011.08.16 10:44 AM, rantingrick wrote: > One word: SYNTAX HILIGHT And I had thought your troll skills had disappeared. Good one. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From ethan at stoneleaf.us Tue Aug 16 13:43:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:43:12 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: <4E4AAC30.6010100@stoneleaf.us> Seebs wrote: > On 2011-08-16, Ethan Furman wrote: >> I think warnings should be reserved for language changes and such (like >> DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible >> programmer mistakes. > > I disagree, on the basis of the following: > > The quality of C code I have to deal with has increased dramatically as > gcc's aggressive use of warnings has spread. With gcc you pay the cost once, with Python you would pay it with every run. A linter would be more along the lines of 'pay it once'. ~Ethan~ From neilc at norwich.edu Tue Aug 16 13:45:15 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Aug 2011 17:45:15 GMT Subject: testing if a list contains a sublist References: <8739h18rzj.fsf@dpt-info.u-strasbg.fr> <5e85b065-698e-4cd7-a409-d23618db1c3c@eb1g2000vbb.googlegroups.com> Message-ID: <9avolbFff6U1@mid.individual.net> On 2011-08-16, nn wrote: > That can be easily fixed: > >>>> def sublist(lst1, lst2): > s1 = ','.join(map(str, lst1)) > s2 = ','.join(map(str, lst2)) > return False if s2.find(s1)==-1 else True > >>>> sublist([1,2,3],[1,2,3,4,5]) > True >>>> sublist([1,2,2],[1,2,3,4,5]) > False >>>> sublist([1,2,3],[1,3,5,7]) > False >>>> sublist([12],[1,2]) > False >>>> String conversion is risky: >>> sublist(['1,2', '3,4'], [1, 2, 3, 4]) True Since we're bike-shedding, here's my entry. It's not clear to me if accepting iterables rather than lists is a win, but I thought, "Why not be general if the implementation is easy?" def is_subseq_of(x, y): r"""Return True if the elements in iterable x are found contiguously in iterable y. >>> is_subseq_of([], []) True >>> is_subseq_of([], [1, 2, 3]) True >>> is_subseq_of([1], [1, 2, 3]) True >>> is_subseq_of([1], []) False >>> is_subseq_of([4, 5], [1, 2, 3, 4, 5]) True >>> is_subseq_of([1, 2], [1, 3, 2]) False >>> is_subseq_of([2, 3], [1, 2, 3, 4]) True >>> is_subseq_of([1, 2, 2], [1, 2, 3, 4, 5]) False >>> is_subseq_of([1, 2], [1, 2]) True >>> is_subseq_of([1, 2, 3], [1, 2]) False >>> is_subseq_of(['1,2', '3,4'], [1, 2, 3, 4]) False """ x = tuple(x) ix = 0 lenx = len(x) if lenx == 0: return True for elem in y: if x[ix] == elem: ix += 1 else: ix = 0 if ix == lenx: return True return False if __name__ == '__main__': import doctest doctest.testmod() -- Neil Cerutti From smainklh at gmail.com Tue Aug 16 13:47:27 2011 From: smainklh at gmail.com (Smaine Kahlouch) Date: Tue, 16 Aug 2011 19:47:27 +0200 Subject: Linux : create a user if not exists In-Reply-To: <4E4A9335.4010700@web.de> References: <4E4A9335.4010700@web.de> Message-ID: <4E4AAD2F.2090502@gmail.com> Le 16/08/2011 17:56, Alexander Kapps a ?crit : > On 16.08.2011 16:57, smain kahlouch wrote: >> Ok than you. You're right but it doesn't help me : >> I replaced it : >> >> >>> def finduser(user): >> ... if pwd.getpwnam(user): >> ... print user, "user exists" >> ... return True >> ... return False >> ... >> >>> finduser('realuser') >> realuser user exists >> True >> >>> finduser('blabla') >> Traceback (most recent call last): >> File "", line 1, in ? >> File "", line 2, in finduser >> KeyError: 'getpwnam(): name not found: blabla' > > > Untested: > > def finduser(name): > try: > return pwd.getpwnam(name) > except KeyError: > return None > > if not finduser("myuser"): > print "creating user..." > else: > print "user already exists" > > > Has the advantage that finduser() returns the user details if needed. > > > (BTW: Please don't top-post) Ok Thank you all, that works perfectly :) See you soon, Sam From ethan at stoneleaf.us Tue Aug 16 13:48:19 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Aug 2011 10:48:19 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4AAD63.20901@stoneleaf.us> Seebs wrote: > On 2011-08-16, Ethan Furman wrote: >> What makes you think it's unintentional? > > Programming experience. > > People *often* do things unintentionally. > >> Seems to me the real issue is somebody using a builtin, such as str or >> int, and that they somehow manage to do this without realizing, "wait a >> sec', that's one of my variables!" I don't see that as a problem that >> Python needs to solve. > > I think the word "my" prejudices the case. But fits in well with the OP. > Imagine stepping into a large project that uses multiple frameworks and > class libraries and so on. You know Python but you're new to the project. > > Under which circumstance will you have more problems? > > 1. There is not a single shadowed built-in in the entire project. > 2. There are dozens of shadowed built-ins based on when the original > programmer felt there wasn't going to be a need for a given built-in > feature, or possibly just didn't know about it. My first course of action would be to learn what I'm patching before I patch it. Scope helps in the case of shadowing; lint helps to give warnings about that and other things as well. > Also, how easy or hard do you think it will be to debug those problems? > What's your first response going to be if, on a screen which doesn't > contain the word file at all, you try to use the file built-in and you > get some cryptic error? Are you going to know to go looking for the > shadow right away? I should have a pretty good clue from the traceback, and a couple prints or logs around the offending lines should give me the rest. ~Ethan~ From ramit.prasad at jpmorgan.com Tue Aug 16 13:51:52 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 13:51:52 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7A5EC4B@EMARC112VS01.exchad.jpmchase.net> >Incorrect past tense usage of "used to": > """ I "used to" wear wooden shoes """ >Incorrect description using "used to": > """ I have become "used to" wearing wooden shoes """ >Correct usage of "used to": > """ Wooden shoes can be "used to" torture someone """ Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. http://www.englishgrammarsecrets.com/usedto/menu.php http://www.englishpage.com/verbpage/usedto.html http://www.5minuteenglish.com/mar20.htm http://www.learnenglish.de/grammar/usedtotext.htm http://www.thefreedictionary.com/used+to http://www.englishclub.com/grammar/verbs-m_used-to-do.htm Ramit P.S. Please CC me on any reply. Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of rantingrick Sent: Tuesday, August 16, 2011 10:06 AM To: python-list at python.org Subject: Re: Ten rules to becoming a Python community member. On Aug 16, 2:07?am, alex23 wrote: > All the way down indeed. Can you pick who said these? Obviously your grep skills are superb however you need to brush up on those reading and comprehension skills a bit. > "There are noobs watching and we to provide code that can be used to > teach!" Yes i said this, however the use of "used to" is proper here. -1 > "And just what *point* an i supposed to be "getting" Stephen?" Yes i said this, and it "may" seem that you have me on this one however i believe that Stephen had said something like """you are "supposed to" blah, blah""" and i retorted with """oh, and just what *point* am i "supposed to" blah blah blah"""... although i DID forget to quote "supposed to", still it's a -1. > "An end user should NEVER EVER have to write glue code so their > "abstraction of choice" can be used to to script an API." Yes i said this, however AGAIN the use of "used to" is proper here. -1. sorry alex, better luck next time :(. Follows is some homework i have prepared for you so that you can understand the proper and improper usage of "used to". For our next assignment we'll be learning about the exploits of Jack and Jill. > (For bonus points: can you also spot who is bored at work today?) Trolling doesn't count as "work" unless you're being paid for it, however some people might consider you a pro by now! PS: Does anyone notice how Stephen has fallen off the face the earth? Where is Stephen i wonder? He was such a vocal nuisance and then he just disappeared. It seemed like he appeared as strangely as he disappeared. Well, he's probably where most sock puppets go when they have no further usage. -- http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Tue Aug 16 14:23:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 19:23:22 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4E4AAC30.6010100@stoneleaf.us> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4AAC30.6010100@stoneleaf.us> Message-ID: On Tue, Aug 16, 2011 at 6:43 PM, Ethan Furman wrote: > Seebs wrote: >> >> On 2011-08-16, Ethan Furman wrote: >>> >>> I think warnings should be reserved for language changes and such (like >>> DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible >>> programmer mistakes. >> >> I disagree, on the basis of the following: >> >> The quality of C code I have to deal with has increased dramatically as >> gcc's aggressive use of warnings has spread. > > With gcc you pay the cost once, with Python you would pay it with every run. > ?A linter would be more along the lines of 'pay it once'. Agreed; in addition, it's spam. Spam at compile time isn't much of an issue; you type ./configure and make, and a billion messages scroll past you. Spam at run time? Everyone who USES the program has to deal with it, and in amongst the program's own output. I don't know how to have Python emit warnings that wouldn't cause these issues. The only thing I can think of is to have the interactive interpreter default to showing more warnings, which is far from perfect itself. As to 'file' specifically, my 3.2 doesn't seem to have it as a builtin. The return value from open() is _io.TextIOWrapper, so the whole issue of file=open(...) may have been completely dodged. ChrisA From emmanuelrousselle at gmail.com Tue Aug 16 14:32:35 2011 From: emmanuelrousselle at gmail.com (eroussel) Date: Tue, 16 Aug 2011 11:32:35 -0700 (PDT) Subject: Python 2.7.2 on AIX 6.1: Unable to compile with ctypes Message-ID: Hello, I'm trying to figure out the recipe to compile Python 2.7.2 on AIX 6.1 with the ctypes module. I'm using the xlc_r compiler V9.0. I am currently able to generate an interpreter that works, but lacks the ctypes module because of compilation errors. From looking at the newgroup posts and bugs.python.org, there seems to be an issue with Python, libffi and AIX. Is the ctypes modules simply unsupported on AIX? These are the compilation error messages I get: "/sapdepot/HP_to_IBM/t154133/build/Python-2.7.2/Modules/_ctypes/libffi/ src/powerpc/ffi.c", line 146.25: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/sapdepot/HP_to_IBM/t154133/build/Python-2.7.2/Modules/_ctypes/libffi/ src/powerpc/ffi.c", line 607.19: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 610.19: 1506-045 (S) Undeclared identifier FFI_LINUX64. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 674.23: 1506-045 (S) Undeclared identifier FFI_SYSV. "/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 908.10: 1506-045 (S) Undeclared identifier FFI_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 908.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 909.10: 1506-045 (S) Undeclared identifier FFI_GCC_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 909.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 910.10: 1506-045 (S) Undeclared identifier FFI_LINUX. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 910.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 911.10: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 911.10: 1506-051 (S) Case expression must be a valid integral constant. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 1033.26: 1506-045 (S) Undeclared identifier FFI_SYSV. "/build/Python-2.7.2/Modules/_ctypes/libffi/src/powerpc/ffi.c", line 1159.27: 1506-045 (S) Undeclared identifier FFI_LINUX_SOFT_FLOAT. and then: Failed to build these modules: _ctypes From python.list at tim.thechases.com Tue Aug 16 14:34:53 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 13:34:53 -0500 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> Message-ID: <4E4AB84D.9080706@tim.thechases.com> On 08/16/2011 12:11 PM, Seebs wrote: > Under which circumstance will you have more problems? > > 1. There is not a single shadowed built-in in the entire project. > 2. There are dozens of shadowed built-ins based on when the original > programmer felt there wasn't going to be a need for a given built-in > feature, or possibly just didn't know about it. In practice, I've never hit such a snag. For #2, the only way it would impact me is if I did the ill-advised from shadowy import * which might tromp on things I care about. Otherwise, I'd just do something like from shadowy import list as shadowy_list, id as shadowy_id If I'm altering another person's ill-created module, I might consider doing a search for builtins and then just simply patching the module so that it renamed all the shadowing usages. Unless the author was being particularly obscure (using scope to impact where a builtin meant the builtin, and other scopes to shadow the builtins), most authors are pretty consistent in their shadowing (usually ignorant of the fact they're shadowing the builtin) which makes the search-n-replace an easy tweak. -tkc From martin.hellwig at butterfly.uk.com Tue Aug 16 14:37:49 2011 From: martin.hellwig at butterfly.uk.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 19:37:49 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <4E4AB8FD.9080406@gmail.com> On 16/08/2011 18:51, Prasad, Ramit wrote: >> Incorrect past tense usage of "used to": >> """ I "used to" wear wooden shoes """ > >> Incorrect description using "used to": >> """ I have become "used to" wearing wooden shoes """ > >> Correct usage of "used to": >> """ Wooden shoes can be "used to" torture someone """ > > Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. > Well admittedly English isn't my native language, But indeed all sentences seem correct to me. With the first sentence meaning: in the past I wore wooden shoes, but presently I do not. With the second sentence meaning: in the past I was not used to (i.e. uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am used to it (although not necessarily comfortable, but at least not uncomfortable). I actually can't figure out a way of saying those two sentences more concise or correct then it has been given. But then again I do recognize that these are quite 'Germanic'* ways of constructing sentences, as in freely mixing past, present and future to indicate that a certain description is restricted to a specific time frame. * For the lack of a better description, I am not a linguist, but I was born in Germany and I am often guilty of mixing times. Also RR, congratualation to another troll post that turned out quite interesting :-) -- mph From martin.hellwig at gmail.com Tue Aug 16 14:37:49 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 19:37:49 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> Message-ID: <4E4AB8FD.9080406@gmail.com> On 16/08/2011 18:51, Prasad, Ramit wrote: >> Incorrect past tense usage of "used to": >> """ I "used to" wear wooden shoes """ > >> Incorrect description using "used to": >> """ I have become "used to" wearing wooden shoes """ > >> Correct usage of "used to": >> """ Wooden shoes can be "used to" torture someone """ > > Double you tee eff? Maybe this is a cultural language difference, but I believe all of the above are correct. Well, I am not sure about the middle one but the other two are valid. > Well admittedly English isn't my native language, But indeed all sentences seem correct to me. With the first sentence meaning: in the past I wore wooden shoes, but presently I do not. With the second sentence meaning: in the past I was not used to (i.e. uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am used to it (although not necessarily comfortable, but at least not uncomfortable). I actually can't figure out a way of saying those two sentences more concise or correct then it has been given. But then again I do recognize that these are quite 'Germanic'* ways of constructing sentences, as in freely mixing past, present and future to indicate that a certain description is restricted to a specific time frame. * For the lack of a better description, I am not a linguist, but I was born in Germany and I am often guilty of mixing times. Also RR, congratualation to another troll post that turned out quite interesting :-) -- mph From rosuav at gmail.com Tue Aug 16 14:42:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 19:42:12 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4AB8FD.9080406@gmail.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: On Tue, Aug 16, 2011 at 7:37 PM, Martin P. Hellwig wrote: > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I am > used to it (although not necessarily comfortable, but at least not > uncomfortable). > This usage can also be seen in a more archaic form, such as this example from WS Gilbert's "The Yeomen of the Guard" (which, as it happens, I'm presently in rehearsal of): Lieutenant: "I see. I think that manner of thing would be somewhat irritating." Jack: "At first, sir, perhaps; but use is everything, and you would come in time to like it." We would be more inclined to say "You'd get used to it". I don't see that this usage (heh) should be considered in any way wrong. ChrisA From jdoe at usenetlove.invalid Tue Aug 16 14:42:52 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 18:42:52 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e4aba2c$0$944$c3e8da3$9f400e27@news.astraweb.com> def wait_for_keystroke(): char=0 while not char==0x1B: char=msvcrt.getch() That freezes the process. Am I using the right code for the escape key, or doing anything else wrong? Again, I know it could be my system. But I must find a way to do this from within Windows. I use a keyboard hook written in C++, maybe something from that would be useful, but maybe complex. Thanks. From jdoe at usenetlove.invalid Tue Aug 16 14:48:24 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 18:48:24 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4aba2c$0$944$c3e8da3$9f400e27@news.astraweb.com> Message-ID: <4e4abb78$0$944$c3e8da3$9f400e27@news.astraweb.com> > def wait_for_keystroke(): > char=0 > while not char==0x1B: > char=msvcrt.getch() I tried using while not char==chr(27): From usenet-nospam at seebs.net Tue Aug 16 14:56:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 18:56:08 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Ethan Furman wrote: > Seebs wrote: >> The quality of C code I have to deal with has increased dramatically as >> gcc's aggressive use of warnings has spread. > With gcc you pay the cost once, with Python you would pay it with every > run. A linter would be more along the lines of 'pay it once'. Huh! That is a really good point, which I had not considered. I still prefer to get warnings, but... Hmm. I wonder whether there's a way to mitigate the cost of these things by messing with -W settings, such that runtime that wants to be fast can omit the checks, but the default could still be to, well, prevent likely errors. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 14:56:08 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 11:56:08 -0700 (PDT) Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e45ab9d$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e4774ed$0$29982$c3e8da3$5496439d@news.astraweb.com> <4e47db26$0$30002$c3e8da3$5496439d@news.astraweb.com> <4e487c66$0$29995$c3e8da3$5496439d@news.astraweb.com> <4e491f73$0$29973$c3e8da3$5496439d@news.astraweb.com> <30fc0eea-1e5f-4d27-a326-ac2dd0ffa06e@df3g2000vbb.googlegroups.com> <379fb990-c471-47d2-a349-edfe6bc94956@o11g2000yql.googlegroups.com> Message-ID: <39187eb1-c069-4fe7-b9fd-e8f25a4caa60@q1g2000vbj.googlegroups.com> On Aug 16, 1:49?am, alex23 wrote: > On Aug 16, 2:37?pm, rantingrick wrote: > > > The reading proceeds naturally from right to left. > > Well, "naturally" if you're coding in Hebrew or Japanese perhaps :) Yes :). I typo-ed that one. It was getting late when i sent that reply. I did consider posting an edit however i decided not to and instead, wait and see who would notice. The map feels much better too as a consequence: rb> [3,100,-20].map{|x| x.to_f} [3.0, 100.0, -20.0] And you can can induce some logic without a clunky lambda. rb>[3,100,-20].map{|x| if x > 99 then x.to_f else x end} [3.0, 100.0, -20.0] in Python you'd have to create a def for that (i know bad "specific" example but the need is there) It feels just like a Python list comprehension though: py> [float(x) for x in [3,100,-20]] Even though it reads in a non-linear way, you could argue that the most important part (float(x)). is front-and-center. Of course i like the compactness of python's map function: py> map(float, [3,100,-20]) But all too often the map function is insufficient AND you cannot use map in a chain! If only we could find a happy medium between Python and Ruby oh what a bliss that would be. We could cut off all of Pythons warts and destroy all of Rubys multiplicity and "singular paridigm-ness". * Forced indention (exactly one tab, and one tab only!) * No multiplicity! * Nice linear expressions! * Name spaces! * Implicit modules! * Only "truly heterogeneous" built-in functions allowed! * Enough freedom to be expressive, but not enough to allow sloppy- ness. From python at mrabarnett.plus.com Tue Aug 16 15:03:53 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Aug 2011 20:03:53 +0100 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4AB8FD.9080406@gmail.com> References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: <4E4ABF19.30205@mrabarnett.plus.com> On 16/08/2011 19:37, Martin P. Hellwig wrote: > On 16/08/2011 18:51, Prasad, Ramit wrote: >>> Incorrect past tense usage of "used to": >>> """ I "used to" wear wooden shoes """ >> >>> Incorrect description using "used to": >>> """ I have become "used to" wearing wooden shoes """ >> >>> Correct usage of "used to": >>> """ Wooden shoes can be "used to" torture someone """ >> >> Double you tee eff? Maybe this is a cultural language difference, but >> I believe all of the above are correct. Well, I am not sure about the >> middle one but the other two are valid. >> > Well admittedly English isn't my native language, But indeed all > sentences seem correct to me. > English _is_ my native language, and I agree with you. > With the first sentence meaning: in the past I wore wooden shoes, but > presently I do not. > Correct. > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I > am used to it (although not necessarily comfortable, but at least not > uncomfortable). > Correct. > I actually can't figure out a way of saying those two sentences more > concise or correct then it has been given. > > But then again I do recognize that these are quite 'Germanic'* ways of > constructing sentences, as in freely mixing past, present and future to > indicate that a certain description is restricted to a specific time frame. > > > * For the lack of a better description, I am not a linguist, but I was > born in Germany and I am often guilty of mixing times. > > Also RR, congratualation to another troll post that turned out quite > interesting :-) > From dannwong at cisco.com Tue Aug 16 15:09:39 2011 From: dannwong at cisco.com (Danny Wong (dannwong)) Date: Tue, 16 Aug 2011 14:09:39 -0500 Subject: regular expression In-Reply-To: References: <4E499F0B.30900@stoneleaf.us> Message-ID: Thanks chris. I had similar code to what you provided. I included the "#" (it was a comment in my code) as part of the string when it shouldn't be as part of my test. As soon as you pointed it out that the #'s aren't supposed to be part of the output, I removed them and it worked. How dumb of me. Thanks again. -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Tuesday, August 16, 2011 12:26 AM To: Danny Wong (dannwong) Cc: python-list at python.org Subject: Re: regular expression On Tue, Aug 16, 2011 at 12:00 AM, Danny Wong (dannwong) wrote: > Hi All, > ? ? ? ?If I get multiline standard output from a command. How can I > retrieve this part of the string "(1006)" > Example: > > #Committing... > #Workspace: (1003) "My OS_8.12.0 Work" <-> (1004) "OS_8.12.0" > # ?Component: (1005) "he-Group" <-> (1004) "OS_8.12.0" > # ? ?Outgoing: > # ? ? ?Change sets: > # ? ? ? ?(1006) ?*--@ ? > # ? ? ? ? ?Changes: > # ? ? ? ? ? ?---c- /he-Group/o-PI/target/config/common-ngp/makefile Assuming the #s aren't in the actual output: import re pat = re.compile("^ *(\\([^)]+\\))", re.MULTILINE) print(pat.search(your_str).group(1)) Obviously can vary depending on how you want to go about defining the target string. Cheers, Chris P.S. If you reply, please remove my email addresses from the quotation due to "On Behalf Of" brokenness. -- Freakin' Outlook/Exchange, I'm telling ya... http://rebertia.com From irmen at -NOSPAM-xs4all.nl Tue Aug 16 15:23:34 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Tue, 16 Aug 2011 21:23:34 +0200 Subject: Idea for pure-python templates using AST. In-Reply-To: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <4e4ac3b6$0$23867$e4fe514c@news2.news.xs4all.nl> On 16-08-11 13:33, Paul Wray wrote: > The idea: > Python syntax allows a statement to be a bare literal or identifier. > These have no effect on the program. > > So the function below is legal python: > > def myFunc(): > 'a' > x = 45 > 'b'; 'c'; x > > So is this (within the appropriate class context of course): > > def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' > Looks very similar to PTL what Quixote uses: http://www.quixote.ca/overview/paper.html (never used it though, and I doubt Quixote used ASTs) Irmen From ramit.prasad at jpmorgan.com Tue Aug 16 15:26:37 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 15:26:37 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> >1. Indentation as flow control was a bad idea. >2. People are subconsciously aware of this. >3. There is a HUGE degree of emotional investment in defending it. > >The responses I have seen on this issue are highly emotional, full of insults, >full of blame-throwing, and utterly contrary to the basic engineering spirit >I usually see in programming communities. In other languages, and even in >Python on any issue but this one, I regularly see people acknowledge >shortcomings and explain either why they think the tradeoffs are good, or why >they are willing to put up with it anyway. > >The characteristic vehemence and hostility this issue produces are the surest >sign of people who have a desperate need not to acknowledge the elephant in >the room. What exactly is the downside to indentation as flow control? I am a fairly new programmer to Python, but the more I use it, the more I think it has the Right idea (for me at least). I find braces in Java/c[#,++] to be less than helpful in comparison to how people rave over. It allows for free form code sure, but half the time I was using indentation to figure out where conditional branching/loops started and stopped anyway! I will admit it was super useful in helping Eclipse to reformat with a more "readable" indentation. The only difference is that now it forces me to make more readable code instead of allowing me the freedom to make hard to read code. I suppose as an American I should be insulted at the lack of freedom. Hell, I own Apple products; I must be getting indoctrinated into a lack of freedom. :-P I am not being vehement or hostile. At least I am attempting to be neither. I do not really feel emotionally invested in either because honestly, I will do whatever I have to for what I am trying to get done. If that requires me coding while only wearing hot pink or using braces I will do it. I am far more concerned with ease of coding, ability to do what I want, and occasionally (fairly rarely) if the running code will be "fast enough". I am not sure why people are so stuck on braces. I figured other people would be like me and tired of having to do things like figuring out where I missed an end brace. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From gc1223 at gmail.com Tue Aug 16 15:50:52 2011 From: gc1223 at gmail.com (gc) Date: Tue, 16 Aug 2011 12:50:52 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5d0d89b4-d026-40ba-b9f1-d72f1731b690@a31g2000vbt.googlegroups.com> Thanks for all the discussion on this. Very illuminating. Sorry for the long delay in responding--deadlines intervened. I will use the list comprehension syntax for the foreseeable future. Tim, I agree with you about the slurping in final position--it's actually quite surprising. As I'm sure you realized, that behavior makes your 'tidier' version: a,b,c,d,e, *more_dict_generator = (dict() for _ in itertools.count()) break with a MemoryError, which I don't think is the result that most people would expect. Stephen wrote: > While slightly ugly, it doesn't seem ugly enough to justify the > extra complexity of special syntax for such a special case. You're probably right (although for my coding this multiple assignment scenario is a pretty ordinary case.) Anyway, I'll shop the a,b,c = *dict() syntax over to python-ideas just to see what they say. Thanks again, everyone! Happy Python. On Aug 3, 7:25?am, Tim Chase wrote: > On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: > > > On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: > >> a, b, c, d, e = [dict() for i in range(5)] > > > I think this is good code -- if you want five different dicts, > > then you should call dict five times. Otherwise Python will > > magically call your expression more than once, which isn't > > very nice. And what if your datatype constructor has > > side-effects? > > If the side-effects are correct behavior (perhaps opening files, > network connections, or even updating a class variable) then > constructor side-effects are just doing what they're supposed to. > ? E.g. something I use somewhat regularly in my code[*]: > > ? a,b,c,d = (file('file%i.txt', 'w') for i in range(4)) > > If the side-effects aren't performing the correct behavior, fix > the constructor. :) > > -tkc > > [*] okay, it's more like > > (features, > ? adjustments, > ? internet, > ? ) = (file(fname) for fname in ( > ? ? 'features.txt', > ? ? 'adjustments.txt', > ? ? 'internet.txt' > ? ? ) > > or even > > (features, > ? adjustments, > ? internet, > ? ) = ( > ? ? set( > ? ? ? line.strip().upper() > ? ? ? for line > ? ? ? in file(fname) > ? ? ? if line.strip() > ? ? ? ) > ? ? for fname in ( > ? ? 'features.txt', > ? ? 'adjustments.txt', > ? ? 'internet.txt' > ? ? ) > > to load various set() data from text-files. From ramit.prasad at jpmorgan.com Tue Aug 16 15:51:31 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 16 Aug 2011 15:51:31 -0400 Subject: allow line break at operators In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <4e43cb2a$0$29986$c3e8da3$5496439d@news.astraweb.com> <74c2421f-28a0-4a8d-bf74-4eebacfb74f1@d7g2000vbv.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF6535@EMARC112VS01.exchad.jpmchase.net> >> PS: I will admit that a few of our community members can be rather >> acerbic at times. >Yeah. And the thing is... This can't possibly lead to convincing people of >your position, so presumably the purpose is that you don't want anyone who >didn't start out agreeing with you to ever come to agree with you? Why's >that? Rantingrick: Do answer his question, please. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rosuav at gmail.com Tue Aug 16 16:05:57 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Aug 2011 21:05:57 +0100 Subject: allow line break at operators In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7AF64A2@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Tue, Aug 16, 2011 at 8:26 PM, Prasad, Ramit wrote: > I am not sure why people are so stuck on braces. I figured other people would be like me and tired of having to do things like figuring out where I missed an end brace. > I'm one of the fans of braces, but search the list archives and you'll find plenty of arguments on both sides. I like braces because they allow me to separate the syntax from the layout; I can choose to indent things based on logical structure, even when that doesn't correspond to the compiler's notion of the structure. Here's an example from C++: struct _blah { int x; int y; char **z; //etc etc etc }; struct blah: public _blah { char padding[1024-sizeof(_blah)]; }; The inheritance isn't significant to the overall concept of the object (the idea was that it should have a size of exactly 1024, as this had to interface with some lower-level systems), but it's significant to the compiler's understanding of the object. The braces, therefore, follow the compiler's requirements, but the indentation follows the programmer's. (And yes, there were comments explaining things, and much better element names.) Another idiom I often use in C or C++ is the "conditional for loop": for (x=getfirst();x;x=getnext()) if (x%3) { blah blah } The equivalent in Python: for x in blah: if x%3: blah blah is not legal, and must be written with an extra indentation: for x in blah: if x%3: blah blah I'm sure I could sort something out with a filtering generator, but it seems ridiculous to write: def condition(gen,func): for elem in gen: if func(elem): yield elem for x in condition(blah,lambda x: x%3): blah blah There are very good reasons for Python's system, and I don't object to it *in Python*. But I do not see indentation-as-structure as the ultimate and perfect system, and I desire and intend to preserve the freedom to choose languages with different systems. Chris Angelico From rantingrick at gmail.com Tue Aug 16 16:13:10 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 13:13:10 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <39e8985a-a0c1-487f-8f87-4e39d120c14b@h9g2000vbr.googlegroups.com> <87cb1497-9aa2-4213-b721-055bf31e10a1@m18g2000vbl.googlegroups.com> <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: On Aug 16, 1:37?pm, "Martin P. Hellwig" wrote: > Well admittedly English isn't my native language, But indeed all > sentences seem correct to me. > > With the first sentence meaning: in the past I wore wooden shoes, but > presently I do not. > > With the second sentence meaning: in the past I was not used to (i.e. > uncomfortable, hey bonus points!) wearing wooden shoes, but presently I > am used to it (although not necessarily comfortable, but at least not > uncomfortable). > > I actually can't figure out a way of saying those two sentences more > concise or correct then it has been given. If conciseness is all you seek then perhaps you prefer the following? ORIGINAL: "I used to wear wooden shoes" CONCISE: "I wore wooden shoes" "I wore wood shoes" "I< Message-ID: <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> def wait_for_keystroke(): char=0 while not (char==chr(27) or char==chr(110)): char=msvcrt.getch() if char==0: return That freezes the process. That means char=msvcrt.getch() is getting something? Could it have something to do with the formatting of the character? From usenet-nospam at seebs.net Tue Aug 16 16:19:33 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 20:19:33 GMT Subject: allow line break at operators References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <1312981104.89312.YahooMailNeo@web121520.mail.ne1.yahoo.com> <1312982377.95657.YahooMailNeo@web121508.mail.ne1.yahoo.com> <87fwl9hr4r.fsf@benfinney.id.au> Message-ID: On 2011-08-16, Prasad, Ramit wrote: >What exactly is the downside to indentation as flow control? I think a lot of it is personal taste or differences in how peoples' brains work. I don't want "free form code", I don't want to write stuff that isn't correctly indented. I want a visual cue I can match up with the start of a loop so I know for sure what I meant, and a way to recover code in the event of Something Going Wrong. >I am not sure why people are so stuck on braces. I figured other >people would be like me and tired of having to do things like >figuring out where I missed an end brace. For me, if I've made an error of that category, the options are: 1. In C, finding out where I missed an end brace, because the compiler warned me, so I go look for an outdent without a brace. 2. In Python, having no clue at all what's wrong or why the program isn't running, and having no cue I can look to to see where the error occurred. Basically, it's parity bits. I love me some parity bits. :) I also recognize that this is a matter of taste; there are sound reasons for other people to have different preferences. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From martin.hellwig at gmail.com Tue Aug 16 16:39:34 2011 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 16 Aug 2011 21:39:34 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: On 03/08/2011 02:45, gc wrote: > a,b,c,d,e = *dict() > > where * in this context means something like "assign separately to > all. > Any thoughts? Thanks! Well got a thought but I am afraid it is the opposite of helpful in the direct sense. So if you don't want to hear it skip it :-) Although I can not proficiently argument it, it has a certain code smell to it. In the sense that it could hint that there is a better more readable way of solving that particular problem (taking in account that the one letter labels are pure for demonstration purpose). I would love to see an example where you would need such a construct. -- mph From luismgz at gmail.com Tue Aug 16 17:02:51 2011 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 16 Aug 2011 14:02:51 -0700 (PDT) Subject: Anyone here can do a comparation between Djang and RoR References: Message-ID: <5a7e2900-5021-4a33-95f7-1e8262327970@l37g2000yqd.googlegroups.com> On Aug 16, 2:11?pm, Seebs wrote: > On 2011-08-16, smith jack wrote: > > > what is the advantage of Django over RoR:) > > This question is pretty much... I mean, you're not gonna get useful > answers. ?They're based on such different languages that I think any > comparison past that is likely going to be uninteresting to a programmer, > and I'm not sure any non-programmers are going to use either. > > I will say, the things I most value in Rails are pretty much contrary > to conventional Python design philosophy. ?Python's stress on explicit > over implicit is probably in contradiction with the Rails philosophy of > convention over configuration. > > So for instance, if all you want of a class that maps to a database table > in Rails is that it map the fields in the database, the class body is > empty because that's the default. ?If you want to tell it that the database > column foo_id represents the id of the foo object with which this record > is associated, and you want to call that .foo, you write: > ? ? ? ? belongs_to :foo > and the rest is all implicit. > > This is really handy sometimes, but it's not very Pythonic... > > Mostly, I think you'd probably be better off asking in a completely > different kind of forum, but even then, you're going to get mostly language > advocacy. > > -s > -- > Copyright 2011, all wrongs reversed. ?Peter Seebach / usenet-nos... at seebs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. Seebs answer is spot on. The advantages or disadvantages of both frameworks are subjective. It all comes down to each person's language of preference, since each framework reflects its language philosophy. From jdoe at usenetlove.invalid Tue Aug 16 17:43:54 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 21:43:54 GMT Subject: Determine what msvcrt.getch() is getting? Message-ID: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> Whatever msvcrt.getch() is returning here in Windows, it's not within the 1-255 number range. How can I determine what it is returning? I would like to see whatever it is getting. Thanks. From timr at probo.com Tue Aug 16 17:50:13 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 14:50:13 -0700 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> Message-ID: John Doe wrote: >def wait_for_keystroke(): > char=0 > while not (char==chr(27) or char==chr(110)): > char=msvcrt.getch() > if char==0: > return > >That freezes the process. That exact code works perfectly for me. The function returns as soon as I press the escape key. You are running this from a console process, and not a GUI process, right? >That means char=msvcrt.getch() is getting something? Did you ever think about inserting a debug statement to help you? print hex(ord(char)) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From monaghand.david at gmail.com Tue Aug 16 17:55:10 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Tue, 16 Aug 2011 22:55:10 +0100 Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> Message-ID: <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick wrote: >If conciseness is all you seek then perhaps you prefer the following? > >ORIGINAL: "I used to wear wooden shoes" >CONCISE: "I wore wooden shoes" >ORIGINAL: "I have become used to wearing wooden shoes" >CONCISE: "I like wearing wooden shoes" >However as you can see much of the rich information is missing. Indeed. Neither of your two concise examples has the same meaning of the originals. >Good communication requires that we use clear and articulate words (and >phrases) that will re-create a similar thought (if not perfect clone of!) >in the mind of your listener[s]. Different phrasings of all but the most basic sentences often have subtle differences of meaning which native speakers intend and understand. 1984 has been and gone. Shame on you! DaveM From jdoe at usenetlove.invalid Tue Aug 16 17:59:32 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 21:59:32 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> Message-ID: <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Tim Roberts wrote: > John Doe wrote: > >>def wait_for_keystroke(): >> char=0 while not (char==chr(27) or char==chr(110)): >> char=msvcrt.getch() if char==0: >> return >> >>That freezes the process. > > That exact code works perfectly for me. The function returns as > soon as I press the escape key. You are running this from a > console process, and not a GUI process, right? No. I am running this from within Windows, all sorts of Windows. So... Does that mean I will need something complex like a keyboard hook? Or what? Thanks. -- > >>That means char=msvcrt.getch() is getting something? > > Did you ever think about inserting a debug statement to help you? > print hex(ord(char)) From rantingrick at gmail.com Tue Aug 16 19:12:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 16:12:53 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 4:55?pm, David Monaghan wrote: > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > > wrote: > >If conciseness is all you seek then perhaps you prefer the following? > > >ORIGINAL: "I used to wear wooden shoes" > >CONCISE: ?"I wore wooden shoes" > >ORIGINAL: "I have become used to wearing wooden shoes" > >CONCISE: ?"I like wearing wooden shoes" > >However as you can see much of the rich information is missing. > > Indeed. Neither of your two concise examples has the same meaning of the > originals. Really? Are you sure? ------------------------------------------------------------ ORIGINAL1: "I used to wear wooden shoes" ------------------------------------------------------------ CONCISE_1a: "I wore wooden shoes" the word "wore" is "past tense" and can be replaced with the "past tense" phrase of "used to wear" without changing any meaning whatsoever -- albeit the latter is childish! CONCISE_1b: "I wore wood shoes" Wooden = "object made of wood" = "flesh of a tree" Wood = "the flesh of a tree" Completely interchangeable! CONCISE_1c: "I< Different phrasings of all but the most basic sentences often have subtle > differences of meaning which native speakers intend and understand. 1984 has > been and gone. Shame on you! Guido himself admitted that hidden descriptors are real. The inception has begun! From gordon at panix.com Tue Aug 16 19:25:52 2011 From: gordon at panix.com (John Gordon) Date: Tue, 16 Aug 2011 23:25:52 +0000 (UTC) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: In rantingrick writes: > ------------------------------------------------------------ > ORIGINAL1: "I used to wear wooden shoes" > ------------------------------------------------------------ > CONCISE_1a: "I wore wooden shoes" "wore" does not convey the same meaning as "used to wear." "wore" means you have worn them in the past. "used to wear" means you have worn them in the past AND don't intend to do so again. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Tue Aug 16 19:29:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 19:29:25 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > I think that best practices would suggest that one shouldn't use > variable > names that shadow builtins (except in specific, special circumstances), > so I don't really think this would be an annoyance at all. The number > of > *unwanted* warnings they'd get would be pretty close to zero. OTOH, in > response to a question I asked on StackOverflow, someone posted a large > list of times where this isn't followed in the std lib, so there seems > to be a precedent for just using the builtin names for anything > one feels like at the time. If you run across that again and email me the link, I will take a look and see if I think the issue should be raised on pydev. Of course, some modules *intentionally* define an open function, intended to be accessed as 'mod.open' and not as 'from mod import *; open'. Also, class/instance attributes can also reuse builtin names. But 'open = ' would be bad. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 16 19:32:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 19:32:36 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 8/16/2011 2:56 PM, Seebs wrote: > I wonder whether there's a way to mitigate the cost of these things by > messing with -W settings, such that runtime that wants to be fast can > omit the checks, but the default could still be to, well, prevent likely > errors. Warning messages have a cost even if suppressed. -- Terry Jan Reedy From monaghand.david at gmail.com Tue Aug 16 19:43:59 2011 From: monaghand.david at gmail.com (David Monaghan) Date: Wed, 17 Aug 2011 00:43:59 +0100 Subject: Ten rules to becoming a Python community member. References: <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <37vl47hrcer8a6d7eoc8o2980ihaj7ci25@4ax.com> On Tue, 16 Aug 2011 16:12:53 -0700 (PDT), rantingrick wrote: >On Aug 16, 4:55?pm, David Monaghan wrote: >> On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick >> >> wrote: >> >If conciseness is all you seek then perhaps you prefer the following? >> >> >ORIGINAL: "I used to wear wooden shoes" >> >CONCISE: ?"I wore wooden shoes" >> >ORIGINAL: "I have become used to wearing wooden shoes" >> >CONCISE: ?"I like wearing wooden shoes" >> >However as you can see much of the rich information is missing. >> >> Indeed. Neither of your two concise examples has the same meaning of the >> originals. > >Really? Are you sure? Yes. > ORIGINAL1: "I used to wear wooden shoes" There's an implicit corollary to this sentence: "...but I don't any more", which is missing from your concise sentence: >CONCISE_1a: "I wore wooden shoes" > ORIGINAL_2: "I have become used to wearing wooden shoes" This carries the meaning, "I wasn't always comfortable/accustomed to wearing wooden shoes, but I am now". This is a totally different meaning from: >CONCISE_2a: "I like wearing wooden shoes" which refers only to the present and is much more positive. In fact, now I consider it, these examples are so clearly different that you can't be a native English speaker. Either that, or I've just fed a troll. Damn. DaveM From jdoe at usenetlove.invalid Tue Aug 16 19:46:48 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 16 Aug 2011 23:46:48 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <4e4b0168$0$26208$c3e8da3$c14f6927@news.astraweb.com> Okay... Looks like I need pyHook. From usenet-nospam at seebs.net Tue Aug 16 19:49:23 2011 From: usenet-nospam at seebs.net (Seebs) Date: 16 Aug 2011 23:49:23 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-16, Terry Reedy wrote: > On 8/16/2011 2:56 PM, Seebs wrote: >> I wonder whether there's a way to mitigate the cost of these things by >> messing with -W settings, such that runtime that wants to be fast can >> omit the checks, but the default could still be to, well, prevent likely >> errors. > Warning messages have a cost even if suppressed. Yes, but is it a *significant* cost? My assumption is that the suppression would be of checking, not just of displaying messages. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 19:50:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 16:50:49 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 6:25?pm, John Gordon wrote: > In rantingrick writes: > > > ------------------------------------------------------------ > > ?ORIGINAL1: "I used to wear wooden shoes" > > ------------------------------------------------------------ > > CONCISE_1a: "I wore wooden shoes" > > "wore" does not convey the same meaning as "used to wear." > > "wore" means you have worn them in the past. > > "used to wear" means you have worn them in the past AND don't intend > to do so again. Actually that assertion is wrong. Take (in the extreme example) that you were (in the past) forced to wear a tutu. You did not like wearing the tutu but someone put a gun to your head, so you did it. Now. If later someone asks you "Have you ever been forced to wear anything you did not like?" and you replied "Yes, i wore a tutu [once]", there is no way anyone could extrapolate from that statement whether or not you would NEVER wear a tutu again. So the moral is: Just because something happened in the past does not mean it will happen in the future. The fact remains that "wore" and "used to wear" both compile down to the same "past tense" event HOWEVER neither have the capacity to predict future events. No one can predict the future. Not even YOU can predict whether or not you will wear a tutu again. You may say you would "never" wear a tutu again however you can NEVER be sure about that statement without a time machine, and lots of free time. From paulwray111111 at gmail.com Tue Aug 16 19:57:51 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 16:57:51 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> On Aug 17, 2:14?am, Chris Angelico wrote: > On Tue, Aug 16, 2011 at 12:33 PM, Paul Wray wrote: > > The idea is simply to use python ASTs to transform this code so that it > > accumulates the values of the bare expressions. > > That'd be similar to what the interactive loop does. Are you aware, > though, that docstrings are bare expressions? You may have a syntactic > collision there. > > ChrisA Thanks yes ama aware of docstrings but did not consider. They are easy to strip out though. From rosuav at gmail.com Tue Aug 16 20:02:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 01:02:34 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Wed, Aug 17, 2011 at 12:49 AM, Seebs wrote: > Yes, but is it a *significant* cost? ?My assumption is that the suppression > would be of checking, not just of displaying messages. > It mightn't be very significant, but there'd still be some cost. However, IMHO the greatest cost is the spamminess; forcing the user to deal with lines and lines of warnings is not a useful way to design a language. ChrisA From rosuav at gmail.com Tue Aug 16 20:03:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 01:03:34 +0100 Subject: Idea for pure-python templates using AST. In-Reply-To: <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <7fb0c5e0-8b66-4de1-adbc-db601781bd24@v7g2000vbk.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 12:57 AM, Paul Wray wrote: > Thanks yes ama aware of docstrings but did not consider. > They are easy to strip out though. > Maybe. You'd have to take notice of what's a docstring and what's the first element to be outputted. Or alternatively, just forbid docstrings on those functions. ChrisA From malaclypse2 at gmail.com Tue Aug 16 20:06:45 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 16 Aug 2011 20:06:45 -0400 Subject: Determine what msvcrt.getch() is getting? In-Reply-To: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> References: <4e4ae499$0$14418$c3e8da3$a8a65a91@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 5:43 PM, John Doe wrote: > Whatever msvcrt.getch() is returning here in Windows, it's not within > the 1-255 number range. How can I determine what it is returning? > > I would like to see whatever it is getting. Just print it. Like this: import msvcrt ch = msvcrt.getch() print (ch) for a bit more information, do this instead: import msvcrt ch = msvcrt.getch() print(type(ch), repr(ch), ord(ch)) -- Jerry From malaclypse2 at gmail.com Tue Aug 16 20:11:39 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 16 Aug 2011 20:11:39 -0400 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 5:59 PM, John Doe wrote: > No. I am running this from within Windows, all sorts of Windows. What does that mean? You seem very resistant to answering anyone's questions about your code. Is your code run from the command line, or does it have a GUI? If it has a GUI, what windowing toolkit are you using? If you have code that's not working, please, show us a short, run-able bit of sample code that demonstrates the problem you're experiencing. Describe the behavior you see, the behavior you expected instead, and the full text of any traceback you may be getting. -- Jerry From gc1223 at gmail.com Tue Aug 16 20:14:16 2011 From: gc1223 at gmail.com (gc) Date: Tue, 16 Aug 2011 17:14:16 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> On Aug 16, 4:39?pm, "Martin P. Hellwig" wrote: > On 03/08/2011 02:45, gc wrote: > > > > a,b,c,d,e = *dict() > > > where * in this context means something like "assign separately to > > all. > . . . it has a certain code smell to it. > I would love to see an example where you would need such a construct. Perfectly reasonable request! Maybe there aren't as many cases when multiple variables need to be initialized to the same value as I think there are. I'm a heavy user of collections, especially counters and defaultdicts. One frequent pattern involves boiling (typically) SQLite records down into Python data structures for further manipulation. (OK, arguably that has some code smell right there--but I often have to do very expensive analysis on large subsets with complex definitions which can be very expensive to pull, sometimes requiring table scans over tens of gigabytes. I *like* being able to use dicts or other structures as a way to cache and structure query results in ways amenable to analysis procedures, even if it doesn't impress Joe Celko.) defaultdict(list) is a very clean way to do this. I'll often have four or five of them collecting different subsets of a single SQL pull, as in: # PROPOSED SYNTAX: all_pets_by_pet_store, blue_dogs_by_pet_store, green_cats_by_pet_store, red_cats_and_birds_by_pet_store = *defautdict(list) # (Yes, indexes on color and kind would speed up this query, but the actual fields can be way quite complex and have much higher cardinality.) for pet_store, pet_kind, pet_color, pet_weight, pet_height in cur.execute("""SELECT s, k, c, w, h FROM SuperExpensivePetTable WHERE CostlyCriterionA(criterion_basis) IN("you", "get", "the", "idea")"""): all_pets_by_pet_store[pet_store].append(pet_weight, pet_height) if pet_color in ("Blue", "Cyan", "Dark Blue") and pet_kind in ("Dog", "Puppy"): blue_dogs_by_pet_store[pet_store].append(pet_weight, pet_height) #... and so forth all_pets_analysis = BootstrappedMarkovDecisionForestFromHell(all_pets_by_pet_store) blue_dogs_analysis = BootstrappedMarkovDecisionForestFromHell(blue_dogs_by_pet_store) red_cats_and_birds_analysis = BMDFFHPreyInteracton(red_cats_and_bird_by_pet_store) #... and so forth Point is, I'd like to be able to create such collections cleanly, and a,b,c = *defaultdict(list) seems as clean as it gets. Plus, when I realize I need six (or only three) it's annoying to need to change two redundant things (i.e. both the variable names and the count.) if tl_dr: break() Generally speaking, when you know you need several variables of the same (maybe complex) type, the proposed syntax lets the equals sign fully partition the variables question (how many variables do I need, and what are they called?) from the data structure question (what type should the variables be?) The other syntaxes (except Tim's generator- slurping one, which as Tim points out has its own issues) all spread the variables question across the equals sign, breaking the analogy with single assignment (where the form is Variable = DataStructure). If we're allowing multiple assignment, why can't we allow some form of Variable1, Variable2, Variable3 = DataStructure without reaching for list comprehensions, copy-pasting and/or keeping a side count of the variables? if much_tl_dr: break() Let me address one smell from my particular example, which may be the one you're noticing. If I needed fifty parallel collections I would not use separate variables; I've coded a ghastly defaultdefaultdict just for this purpose, which effectively permits what most people would express as defaultdict(defaultdict(list)) [not possible AFAIK with the existing defaultdict class]. But for reasons of explicitness and simplicity I try to avoid hash-tables of hash-tables (and higher iterations). I'm not trying to use dicts to inner-platform a fully hashed version of SQL, but to boil things down. Also bear in mind, reading the above, that I do a lot of script-type programming which is constantly being changed under severe time pressure (often as I'm sitting next to my clients), which needs to be as simple as possible, and which tech-savvy non-programmers need to understand. A lot of my value comes from quickly creating code which other people (usually research academics) can feel ownership over. Python is already a great language for this, and anything which makes the syntax cleaner and more expressive and which eliminates redundancy helps me do my job better. If I were coding big, stable applications where the defaultdicts were created in a header file and wouldn't be touched again for three years, I would care less about a more awkward initialization method. From philip at semanchuk.com Tue Aug 16 20:18:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 20:18:02 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> On Aug 16, 2011, at 7:29 PM, Terry Reedy wrote: > On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > >> I think that best practices would suggest that one shouldn't use >> variable >> names that shadow builtins (except in specific, special circumstances), >> so I don't really think this would be an annoyance at all. The number >> of >> *unwanted* warnings they'd get would be pretty close to zero. OTOH, in >> response to a question I asked on StackOverflow, someone posted a large >> list of times where this isn't followed in the std lib, so there seems >> to be a precedent for just using the builtin names for anything >> one feels like at the time. > > If you run across that again and email me the link, I will take a look and see if I think the issue should be raised on pydev. Of course, some modules *intentionally* define an open function, intended to be accessed as 'mod.open' and not as 'from mod import *; open'. Also, class/instance attributes can also reuse builtin names. But 'open = ' would be bad. Hi Terry, To generalize from your example, are you saying that there's a mild admonition against shadowing builtins with unrelated variable names in standard lib code? Here's an example from Python 3.2.1's argparse.py, lines 466-473. "open" is shadowed on the second line. # clean up separators for mutually exclusive groups open = r'[\[(]' close = r'[\])]' text = _re.sub(r'(%s) ' % open, r'\1', text) text = _re.sub(r' (%s)' % close, r'\1', text) text = _re.sub(r'%s *%s' % (open, close), r'', text) text = _re.sub(r'\(([^|]*)\)', r'\1', text) text = text.strip() Thanks Philip From ben+python at benfinney.id.au Tue Aug 16 20:26:29 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 17 Aug 2011 10:26:29 +1000 Subject: parameterized-testcase 0.2 References: Message-ID: <87bovodgsq.fsf@benfinney.id.au> Austin Bingham writes: > parameterized-testcase works with Python's standard unittest module to > provide a means to run TestCases with different "parameterizations". How is this different from what we already have in ?testscenarios? ? -- \ ?????????? | `\ (What is undesirable to you, do not do to others.) | _o__) ???? Confucius, 551 BCE ? 479 BCE | Ben Finney From timr at probo.com Tue Aug 16 20:32:12 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:32:12 -0700 Subject: string to unicode References: Message-ID: <1r2m47h2fsmoe1cd9tnng4rdlf3l8cf39m@4ax.com> Artie Ziff wrote: > >if I am using the standard csv library to read contents of a csv file >which contains Unicode strings (short example: >'\xe8\x9f\x92\xe8\x9b\x87'), You need to be rather precise when talking about this. That's not a "Unicode string" in Python terms. It's an 8-bit string. It might be UTF-8 encoding. If so, it maps to two Unicode code points, U+87D2 and U+86C7, which are both CJK ideograms. Is that what you expected? C:\Dev\videology\sw\viewer>python Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = '\xe8\x9f\x92\xe8\x9b\x87' >>> x.decode('utf8') u'\u87d2\u86c7' -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gordon at panix.com Tue Aug 16 20:33:56 2011 From: gordon at panix.com (John Gordon) Date: Wed, 17 Aug 2011 00:33:56 +0000 (UTC) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: In rantingrick writes: > > "wore" means you have worn them in the past. > > > > "used to wear" means you have worn them in the past AND don't intend > > to do so again. > Actually that assertion is wrong. > No one can predict the future. Not even YOU can predict whether or not Of course -- that's why the word "intend" was part of my answer. Did you overlook that crucial word? I stand by my assertion that the phrase "I used to do X" carries the meaning that you have done X in the past but DO NOT INTEND to do so in the future. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From timr at probo.com Tue Aug 16 20:39:39 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:39:39 -0700 Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> Message-ID: "Paul Wray" wrote: > >Ive had what I think is a great idea for pure-python templates (I can almost >hear the groans, bear with me...) >... >The idea: >Python syntax allows a statement to be a bare literal or identifier. These >have no effect on the program. >... >So is this (within the appropriate class context of course): > >def body(self, r): > '

'; self.heading; '

' > '
    ' > for itm in self.items: > '
  • '; itm; '
  • ' > '
' This is essentially how the original CherryPy version 1 web framework worked. In the end, I think it was decided that this represented too much of a mix of processing and presentation, and CherryPy 2 and 3 use a different scheme. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Aug 16 20:41:32 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Aug 2011 17:41:32 -0700 Subject: why i cannot import djang? References: Message-ID: <0f3m47dsv6amck9jl578a4ps7fbcg1nibm@4ax.com> smith jack wrote: > >this package is already in the site-packages directory, but i cannot >import it , it's really confusing ... The package is called "django". The name you put in the subject line is wrong. Does your code use the right spelling? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve+comp.lang.python at pearwood.info Tue Aug 16 20:58:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 10:58:41 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-16, Steven D'Aprano > wrote: >> On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >>>> Why should built-ins be treated as more sacred than your own objects? > >>> Because built-ins are described in the official documentation as having >>> a specific behavior, while my objects are not. > >> *My* objects certainly are, because I write documentation for my code. My >> docs are no less official than Python's docs. > > Sure they are. I can't get yours from python.org. And what makes that unofficial? python.org is not the sole arbiter of official documentation in the world. You can't get docs for Django or Scipy or NLTK from python.org either, but just try telling the authors of those libraries that their docs are somehow unofficial and see how far that gets you. [...] > I think code which shadows a built-in has a pretty real risk of being > harmful at some unspecified future point when some maintainer who hasn't > memorized every last line of the code makes the totally reasonable > assumption that basic language features are still working and available. Am I the only person who writes functions and methods any more? *wink* Modern languages, and by modern I mean most languages more than, oh, about fifty years old, provide ways to limit the scope of variables. You don't need to memorise "every last line of the code" to safely edit a function. def process(list, arg): spam(list) ham(arg) cheese(list, arg) The scope of parameter "list" is limited to within the function process itself. Inside, it shadows the built-in list. Outside, it doesn't do squat. [...] > My thoughts would be: > 1. It's hard to avoid shadowing anything unless you know the entire > language and never forget things. Define the "entire language". Does that include the names of all the plethora of exceptions? How about the standard library? For what it's worth, I don't care about memorising all the built-ins. I delegate that job to my editor, which has a syntax highlighter for Python. It never forgets built-ins. (In fact, sometimes this is a nuisance. When I'm editing Python 3 code, it still insists that apply and reduce are built-ins.) > 2. In particular, Python likes to use clear, obvious, names for things. > Meaning that your choice of a clear, obvious, name for a similar thing > could be the name of a thing in the language. Yes, and Python also encourages the use of scopes, so that the clear, obvious name for something in one scope does not clash with the clear, obvious, identical name for something completely different in another scope. > 3. I am not sure at all that shadowing can be "safe" in code which will > some day be maintained. Oh there's no doubt that shadowing *can* be unsafe. But then, very few things can't be abused. As I see it, there are (at least) four stages related to shadowing. (1) At first, you don't even know enough to be concerned by shadowing. You blithely call variables "list" and "str" without a care in the world... until something goes wrong. (2) Second stage, you know enough to realise that shadowing can be bad. You avoid shadowing everything. Your code is full of variables called "my_list" and "astr" and "some_tuple". You call your functions things like "izip" even though it is designed as a replacement for zip, because the caller might use from itertools import * and accidentally replace the built-in zip with my zip. You even avoid using "string" as a variable name because it might shadow the string module -- even though you haven't actually imported or used the string module in the last four years. (3) Eventually, you get frustrated writing doc strings like this: def function(astr, myint=0): """function(astr [, myint]) -> list Arguments: astr - string myint - integer Do something tool-like to a string and optional integer... """ and begin writing them like this: def function(astr, myint): """function(str [, int]) -> list Do something tool-like to a string and optional integer... """ (4) And then, after a while, you decide that perhaps shadowing is not always so bad. (It helps if the Effbot tells you off for objecting to shadowing in a two-line function.) At first, you limit yourself to using parameter names that shadow built-ins in small tool-like functions. Then when the world doesn't implode, you rethink the use of top-level function names like "izip" and realise that namespaces exist so that you don't need to care about shadowing functions you don't use, and if people call import * they have nobody to blame but themselves if things break. More-or-less-auto-biographically-ly y'rs, -- Steven From python.list at tim.thechases.com Tue Aug 16 21:02:19 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Aug 2011 20:02:19 -0500 Subject: Ten rules to becoming a Python community member. In-Reply-To: References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <4E4B131B.4040902@tim.thechases.com> On 08/16/2011 07:33 PM, John Gordon wrote: > I stand by my assertion that the phrase "I used to do X" carries the > meaning that you have done X in the past but DO NOT INTEND to do so > in the future. I'd tweak the meaning to be something like "I did X regularly in the past and I no longer do it regularly". E.g. "I used to drink a lot of cranberry juice"[*] connotes that I drank it regularly, but no longer drink it regularly, even though I might still drink it occasionally. But on the whole, I side with John far more than I side with RR on the issue. -tkc [*] seriously, in college I managed to put away over a gal/day. Ah, to be young again and have an unlimited cafeteria food-plan. From paulwray111111 at gmail.com Tue Aug 16 21:02:40 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 18:02:40 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <4e4ac3b6$0$23867$e4fe514c@news2.news.xs4all.nl> Message-ID: <5c8fcb5c-a1af-4847-88fb-2d9f2e0556b4@o9g2000vbo.googlegroups.com> On Aug 17, 5:23?am, Irmen de Jong wrote: > On 16-08-11 13:33, Paul Wray wrote: > > > > > > > > > > > The idea: > > Python syntax allows a statement to be a bare literal or identifier. > > These have no effect on the program. > > > So the function below is legal python: > > > def myFunc(): > > 'a' > > x = 45 > > 'b'; 'c'; x > > > So is this (within the appropriate class context of course): > > > def body(self, r): > > '

'; self.heading; '

' > > '
    ' > > for itm in self.items: > > '
  • '; itm; '
  • ' > > '
' > > Looks very similar to PTL what Quixote uses:http://www.quixote.ca/overview/paper.html > > (never used it though, and I doubt Quixote used ASTs) > > Irmen Thanks. Yes it looks much the same, and it does use AST. This from the ptl_compile.py module: """Compile a PTL template. First template function names are mangled, noting the template type. Next, the file is parsed into a parse tree. This tree is converted into a modified AST. It is during this state that the semantics are modified by adding extra nodes to the tree. Finally bytecode is generated using the compiler package. """ From ckaynor at zindagigames.com Tue Aug 16 21:09:42 2011 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 16 Aug 2011 18:09:42 -0700 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4E4B131B.4040902@tim.thechases.com> References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> <4E4B131B.4040902@tim.thechases.com> Message-ID: On Tue, Aug 16, 2011 at 6:02 PM, Tim Chase wrote: > On 08/16/2011 07:33 PM, John Gordon wrote: >> >> I stand by my assertion that the phrase "I used to do X" carries the >> meaning that you have done X in the past but DO NOT INTEND to do so >> in the future. > > I'd tweak the meaning to be something like "I did X regularly in the past > and I no longer do it regularly". ?E.g. "I used to drink a lot of cranberry > juice"[*] connotes that I drank it regularly, but no longer drink it > regularly, even though I might still drink it occasionally. ?But on the > whole, I side with John far more than I side with RR on the issue. There is a difference between "I used to drink cranberry juice" and "I used to drink a lot of cranberry juice". The first says that you no longer drink it at all, while the latter has quantified the statement to say you may still drink it occasionally, but less than you used to. The key is that "a lot" quantifies "drink" in the second statement. > > -tkc > > > [*] seriously, in college I managed to put away over a gal/day. Ah, to be > young again and have an unlimited cafeteria food-plan. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From paulwray111111 at gmail.com Tue Aug 16 21:10:00 2011 From: paulwray111111 at gmail.com (Paul Wray) Date: Tue, 16 Aug 2011 18:10:00 -0700 (PDT) Subject: Idea for pure-python templates using AST. References: <2As2q.636$7r4.389@viwinnwfe02.internal.bigpond.com> <5bed8db1-a4d7-4788-a389-69c10b47fbd1@a15g2000yqb.googlegroups.com> Message-ID: <58ed00f2-e5cb-4139-bf36-c4ffa975838c@a31g2000vbt.googlegroups.com> > You code fail, see below for other comment > > Traceback (most recent call last): > ? File "Download/pastie-2379978.rb", line 108, in > ? ? make_template(template1) > ? File "Download/pastie-2379978.rb", line 60, in make_template > ? ? ast.fix_missing_locations(astFromSrc) > ? File "/usr/lib/python2.6/ast.py", line 133, in fix_missing_locations > ? ? _fix(node, 1, 0) > ? File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ? _fix(child, lineno, col_offset) > ? File "/usr/lib/python2.6/ast.py", line 132, in _fix > ? ? _fix(child, lineno, col_offset) > ? File "/usr/lib/python2.6/ast.py", line 121, in _fix > ? ? if 'lineno' in node._attributes: > AttributeError: 'arguments' object has no attribute '_attributes' > Sorry, should have specified Python 2.7. Also Pastie thinks its ruby code so the donwloaded file is confusingly ___.rb From steve+comp.lang.python at pearwood.info Tue Aug 16 21:14:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 11:14:41 +1000 Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> David Monaghan wrote: > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > wrote: > >>If conciseness is all you seek then perhaps you prefer the following? >> >>ORIGINAL: "I used to wear wooden shoes" >>CONCISE: "I wore wooden shoes" > >>ORIGINAL: "I have become used to wearing wooden shoes" >>CONCISE: "I like wearing wooden shoes" > >>However as you can see much of the rich information is missing. > > Indeed. Neither of your two concise examples has the same meaning of the > originals. The second one is considerably different. Consider: "I have become used to getting up at 3am to be flogged for an hour by my boss. Between the sleep deprivation and the scar tissue on my back, I hardly feel a thing any more." versus "I like getting up at 3am to be flogged for an hour by my boss. I get all tingly in my man-bits, if you know what I mean." The first case is more subtle. The implication of "I used to wear..." is that you did back in the past, but no longer do, while "I wore..." has no such implication. It merely says that in the past you did this, whether you still do or don't is irrelevant. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 16 21:29:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 11:29:30 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> Message-ID: <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> Philip Semanchuk wrote: > I think Python does lots of beneficial hand-holding. Garbage collection is > a good example. $DIETY knows, people have been struggling with manual > memory management in C and its ilk for a long time. Even though there are > good tools to help, memory leaks still happen. Python increases our > productivity by allowing us to forget about manual memory management > altogether. I can do it with tools like valgrind, but Python's makes the > point moot. Is that hand-holding? If so, I'm all for it. Hand-holding is not a well-defined term. According to Mel, garbage collectors would be hand-holding designed for soft nellies. http://www.cs.utah.edu/~elb/folklore/mel.html But Mel would probably make his own nails rather than buy them from the hardware store too. To some secret recipe involving rare metals that most people have never even heard of. And use a hammer forged from a single piece of meteor iron, shaped to fit his hand precisely. And it would be too heavy for mortals to lift. Of course the term "hand-holding" is a pejorative. The implication is that the person needing the hand-holding is like a child who needs somebody to hold their hand while they cross the road. Adults are supposed to know better (if only it were true in real life!). On the other hand, a real adult knows their limitations, and if you need a bit of hand-holding in a certain area of your life, so be it. Some errors aren't exactly a matter of inexperience and poor judgement, and so everyone can benefit from guard rails, seat belts and garbage collection. In that case, it isn't hand-holding, because there's no expectation that you should grow up from it. Even Donald Knuth probably would get benefit from a good garbage collector. I have no objection to lint tools. But separation of concerns should apply: the Python compiler should just compile what I tell it to, the linter should warn me if I'm running with scissors. -- Steven From usenet-nospam at seebs.net Tue Aug 16 21:35:29 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 01:35:29 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-17, Chris Angelico wrote: > On Wed, Aug 17, 2011 at 12:49 AM, Seebs wrote: >> Yes, but is it a *significant* cost? ?My assumption is that the suppression >> would be of checking, not just of displaying messages. > It mightn't be very significant, but there'd still be some cost. > However, IMHO the greatest cost is the spamminess; forcing the user to > deal with lines and lines of warnings is not a useful way to design a > language. Lines and lines? I'd say if it's to be allowed to shadow built-ins (and I'm not sure that's a good thing at all), you'd still be looking at one warning per shadowing, which shouldn't be too many. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rantingrick at gmail.com Tue Aug 16 21:47:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 16 Aug 2011 18:47:39 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: On Aug 16, 7:33?pm, John Gordon wrote: > In rantingrick writes: > > > > "wore" means you have worn them in the past. > > > > "used to wear" means you have worn them in the past AND don't intend > > > to do so again. > > Actually that assertion is wrong. > > No one can predict the future. Not even YOU can predict whether or not > > Of course -- that's why the word "intend" was part of my answer. ?Did you > overlook that crucial word? > > I stand by my assertion that the phrase "I used to do X" carries the > meaning that you have done X in the past but DO NOT INTEND to do so > in the future. Okay and i'm with you as long as you'll also agree that "i wore wooden shoes" carries the meaning that i've worn shoes in the past but gives no indication that i will wear shoes again. And if you agree with that (which is a fact BTW) then you must also agree that "i used to wear wear wooden shoes" also gives no guarantee that i won't wear them again. This point i have been trying to make all along is: Speaking with this verbiage leaves to much to be desired. To much meaning is specific *only* to the sender and prone to cause subtle errors upon receiving due to errors of the "lost-in-translation" kind. We must remove these ambiguities from our speech and from our code if we ever expect to evolve into a species capable of taking the next logical step in our evolution. That step will require massive amounts of coherent and articulate collaboration across many cultures. How do solve that problem you ask? By removing all cultures and joining the culture of Mankind. We know that knowledge is being spread far and wide and to every corner of this planet. No one will ever be robbed of an education because all the knowledge is being cataloged in the world wide library (WWW). A person living in a mud hut in Africa has the same access to the knowledge base as a professor working at a prestigious college. No more will the class structure be relevant because knowledge IS power. The playing fields are beginning to be leveled and the world is on course for a huge shake up soon. How soon this event will culminate into reality is yet to be known however i can assure you people that at our current rate, sadly it is going to be a very long time! The transition is not evolving as fast as it should be because we refuse to eradicate the enormous amounts of multiplicity that plague our knowledge bases. Language is one of the top offenders, which manifest itself over and over like a stupidity virus; and the worst part is that it shows no readily perceivable symptoms to the zombie masses! These "masses" of hosts continue on day after day infecting new people with this disease of multi-language-ism and as such entropy grows. Leaps are made but then setbacks are certain due to entropy. On and on we continue to be slung back and forth due to this elastic rubber band of stupidity. Some folks get emotional when i speak of these things. They confuse multiplicity with freedom. They fear the loss of their freedom to be lazy, slothful, and stupid. Yes you have a right to be these things if you want, but don't be expecting that your gene-pool will be part of the future because you will be bred out of existence! The future belongs to the intelligent agents capable of eradicating multiplicity and harnessing what mother nature could never harness with billions and billions of years built on innumerable random guesses... the future belongs to those with an IMAGINATION! An imagination is the most power tool we posses. With imagination we can drive evolution. Without imagination nothing you see or know would exist. We would be caught forever in the infinite loop of ape-ian stupidity and left to wither as just a blip on the evolutionary radar. With our imagination we can not only harness our world but also our universe (which is far more expansive than we have yet to realize). We can even harness evolution itself! We can transcend the flesh, and then, THEN... we shall take our rightful place as the gods! Maybe there is even an evolution of the gods of which replacements are created every trillion or so years. We are next in line to replace the aging gods that now control the known universe. To continue to deny that we are natures greatest creation would be tantamount to bitch slapping our very own mothers. Instead we should make her proud by being all that we can be and using our intelligence to utterly destroy her and IN EFFECT become something greater in the process than we ever where before. Progress "progresses" by the prodigy standing on the shoulders of the creators to reach that "next" higher cookie jar. The future is not saving the whales or the dolphins, or the endangered three toed alligator. Neither is the future "save the earth". The future is transcendence from the flesh into a new state of being. No form of matter how well we maintain this earth, one day the sun will consume it. Likewise one day the sun be consumed. Do not put your faiths and beliefs in matter, because matter is fluid -- here today and changed tomorrow. Instead, put your faith in knowledge, order, and finally the end goal of transcendence beyond the confines of flesh. Recently I was an unwilling party to this completely ridiculous TV show about how the human race would be an "X" number of years from now -- through-out the show "X" was incremented. These idiots (calling themselves scientist) imagined that we would still be flying space ships as the last stars in the universe burned out. All the while i am thinking to myself (and laughing) how completely moronic these guys are. Newsflash! If we do not make the transcendence in the next 1000 years we may never make it and therefor some other life form will have to take a shot some time in the distant future. But i can tell you one thing for sure. In 10,000 years we are NOT going to be flying around in spaceships. We will have transcended the physical flesh and harnessed pure energy which will in turn fuel our expanding singular intelligence. At that time the currently known universe will become the size of your backyard swimming pool. Nature is random, but true evolution is the harnessing of evolution to bring about order in the known universe. We were put into this universe to bring about order from the chaos (something random guesses can never accomplish) don't be an idiot and waste your life saving the dolphins and recycling. Yes, be kind to other people (and lower lifeforms), but realize that they are a means to an end. Singularity is the end. From tjreedy at udel.edu Tue Aug 16 22:10:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 22:10:30 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 8/16/2011 7:49 PM, Seebs wrote: > On 2011-08-16, Terry Reedy wrote: >> On 8/16/2011 2:56 PM, Seebs wrote: >>> I wonder whether there's a way to mitigate the cost of these things by >>> messing with -W settings, such that runtime that wants to be fast can >>> omit the checks, but the default could still be to, well, prevent likely >>> errors. > >> Warning messages have a cost even if suppressed. > > Yes, but is it a *significant* cost? My assumption is that the suppression > would be of checking, not just of displaying messages. The -W settings suppress display or printing of warnings, not their generation. import warnings if some_condition: warnings.warn(message, Warning) The test and warn call are made regardless of disposition. Filters determine what is done with each Warning subclass. The logging module can grab them too. -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Aug 16 22:11:36 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Aug 2011 03:11:36 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <4E4B2358.2030208@mrabarnett.plus.com> On 17/08/2011 01:14, gc wrote: > On Aug 16, 4:39 pm, "Martin P. Hellwig" > wrote: >> On 03/08/2011 02:45, gc wrote: >> >> >>> a,b,c,d,e = *dict() >> >>> where * in this context means something like "assign separately to >>> all. > >> . . . it has a certain code smell to it. >> I would love to see an example where you would need such a construct. > > Perfectly reasonable request! Maybe there aren't as many cases when > multiple variables need to be initialized to the same value as I think > there are. > [snip] As I see it, there are 2 issues: 1. Repeated evaluation of an expression: "dict()" would be evaluated as many times as necessary. In other words, it's an unlimited generator. 2. Lazy unpacking: unpacking normally continues until the source is exhausted, but here you want it to stop when the destination (the RHS) is satisfied. It just happens that in your use-case they are being used together. From tjreedy at udel.edu Tue Aug 16 22:15:03 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Aug 2011 22:15:03 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> Message-ID: On 8/16/2011 8:18 PM, Philip Semanchuk wrote: > Hi Terry, > To generalize from your example, are you saying that there's a mild admonition > against shadowing builtins with unrelated variable names in standard lib code? I would expect that there might be. I would have to check PEP8. > Here's an example from Python 3.2.1's argparse.py, lines 466-473. > "open" is shadowed on the second line. > > # clean up separators for mutually exclusive groups > open = r'[\[(]' > close = r'[\])]' > text = _re.sub(r'(%s) ' % open, r'\1', text) > text = _re.sub(r' (%s)' % close, r'\1', text) > text = _re.sub(r'%s *%s' % (open, close), r'', text) > text = _re.sub(r'\(([^|]*)\)', r'\1', text) > text = text.strip() -- Terry Jan Reedy From philip at semanchuk.com Tue Aug 16 22:16:49 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 22:16:49 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> <4E4A98AE.1070708@stoneleaf.us> <4e4b197b$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 16, 2011, at 9:29 PM, Steven D'Aprano wrote: > I have no objection to lint tools. But separation of concerns should apply: > the Python compiler should just compile what I tell it to, the linter > should warn me if I'm running with scissors. This point (also made by Ethan) I can agree with. I haven't looked through all the warnings the Python compiler emits, but it seems like it currently doesn't dispense advice (unlike, say, gcc). It only warns about changes in the language & standard library. In that context, asking it to warn about shadowing builtins would be an expansion of scope. bye, Philip From jason.swails at gmail.com Tue Aug 16 22:34:28 2011 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 16 Aug 2011 22:34:28 -0400 Subject: Ten rules to becoming a Python community member. In-Reply-To: <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> <4e4b1602$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Aug 16, 2011 at 9:14 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > David Monaghan wrote: > > > On Tue, 16 Aug 2011 13:13:10 -0700 (PDT), rantingrick > > wrote: > > > >>If conciseness is all you seek then perhaps you prefer the following? > >> > >>ORIGINAL: "I used to wear wooden shoes" > >>CONCISE: "I wore wooden shoes" > > > >>ORIGINAL: "I have become used to wearing wooden shoes" > >>CONCISE: "I like wearing wooden shoes" > > > >>However as you can see much of the rich information is missing. > > > > Indeed. Neither of your two concise examples has the same meaning of the > > originals. > > The second one is considerably different. Consider: > > "I have become used to getting up at 3am to be flogged for an hour by my > boss. Between the sleep deprivation and the scar tissue on my back, I > hardly feel a thing any more." > > versus > > "I like getting up at 3am to be flogged for an hour by my boss. I get all > tingly in my man-bits, if you know what I mean." > > The first case is more subtle. The implication of "I used to wear..." is > that you did back in the past, but no longer do, while "I wore..." has no > such implication. It merely says that in the past you did this, whether you > still do or don't is irrelevant. > Meh. We can come up with examples all over the place to support any of our assertions. The context is what matters. In a newspaper article, you'd often prefer to use "The president wore shoes" to "The president used to wear shoes" because the extra words and space make a difference, and you want to be concise while letting people know what happened. In a public forum catering to native and non-native English speakers alike, common phrases like "used to" and "supposed to" are well known and understood. As such, I argue they are supposed to be used (to) often. In such circumstances as these, I say keep your language concise and simple, and your words will reach the most people (and the fewest killfiles, perhaps). As the wise man says, "It's not only quiet people that don't say much". (And here RR joins his silent majority). Peace, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Tue Aug 16 22:51:01 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Aug 2011 22:51:01 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <5E204ED4-4008-416F-9C5F-DDCDCF6077D3@semanchuk.com> Message-ID: On Aug 16, 2011, at 10:15 PM, Terry Reedy wrote: > On 8/16/2011 8:18 PM, Philip Semanchuk wrote: > >> Hi Terry, >> To generalize from your example, are you saying that there's a mild admonition > > against shadowing builtins with unrelated variable names in standard lib code? > > I would expect that there might be. I would have to check PEP8. I was curious, so I checked. I didn't see anything specifically referring to builtins. This is as close as it gets: "If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus "print_" is better than "prnt". (Perhaps better is to avoid such clashes by using a synonym.)" bye Philip From usenet-nospam at seebs.net Tue Aug 16 23:17:23 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 03:17:23 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > Seebs wrote: >> On 2011-08-16, Steven D'Aprano >> wrote: >>> *My* objects certainly are, because I write documentation for my code. My >>> docs are no less official than Python's docs. >> Sure they are. I can't get yours from python.org. > And what makes that unofficial? > python.org is not the sole arbiter of official documentation in the world. But it is the sole arbiter of official *Python* documentation. If I am looking at code in Python, I reasonably expect the Python docs to be correct about that code. Incomplete, sure, but *correct*. >> I think code which shadows a built-in has a pretty real risk of being >> harmful at some unspecified future point when some maintainer who hasn't >> memorized every last line of the code makes the totally reasonable >> assumption that basic language features are still working and available. > Am I the only person who writes functions and methods any more? *wink* Yes. Everyone else converted to single giant blocks of code because they are easier to develop. :P > Modern languages, and by modern I mean most languages more than, oh, about > fifty years old, provide ways to limit the scope of variables. You don't > need to memorise "every last line of the code" to safely edit a function. Only the parts that are in scope, but... I seem to recall (and I'm pretty Python newbiesh, so I could be wrong) that Python classes create a scope in which bits of the class become visible, and some classes are sorta biggish. > def process(list, arg): > spam(list) > ham(arg) > cheese(list, arg) > The scope of parameter "list" is limited to within the function process > itself. Inside, it shadows the built-in list. Outside, it doesn't do squat. Yes. But what about the built-in spam? :) > Define the "entire language". Does that include the names of all the > plethora of exceptions? How about the standard library? I'd think "standard library" or close to it. > For what it's worth, I don't care about memorising all the built-ins. I > delegate that job to my editor, which has a syntax highlighter for Python. > It never forgets built-ins. (In fact, sometimes this is a nuisance. When > I'm editing Python 3 code, it still insists that apply and reduce are > built-ins.) Heh. I mostly don't use syntax highlighters; at best, they distract me, at worst, they distract me a lot. I also don't use one in English, although I am sure some people would love to have nouns in blue and punctuation in green. > Yes, and Python also encourages the use of scopes, so that the clear, > obvious name for something in one scope does not clash with the clear, > obvious, identical name for something completely different in another > scope. "Another" scope is normally a horizontal thing -- you're talking about a different scope such that you are *either* in this one *or* in that one. Built-ins are not in a scope you are never not in. > Oh there's no doubt that shadowing *can* be unsafe. But then, very few > things can't be abused. Yup. > As I see it, there are (at least) four stages related to shadowing. > (1) At first, you don't even know enough to be concerned by shadowing. You > blithely call variables "list" and "str" without a care in the world... > until something goes wrong. > (2) Second stage, you know enough to realise that shadowing can be bad. You > avoid shadowing everything. Your code is full of variables called "my_list" > and "astr" and "some_tuple". You call your functions things like "izip" > even though it is designed as a replacement for zip, because the caller > might use from itertools import * and accidentally replace the built-in zip > with my zip. > You even avoid using "string" as a variable name because it might shadow the > string module -- even though you haven't actually imported or used the > string module in the last four years. Heh. (I got advised by pylint not to grab something from it, but I no longer remember why; I seem to recall being totally unable to find a way to avoid that warning and still have the string processing I needed.) > (3) Eventually, you get frustrated writing doc strings like this: > > def function(astr, myint=0): > """function(astr [, myint]) -> list > > Arguments: > astr - string > myint - integer > > Do something tool-like to a string and optional integer... > """ > and begin writing them like this: > def function(astr, myint): > """function(str [, int]) -> list > > Do something tool-like to a string and optional integer... > """ That seems safe enough to me. :) > (4) And then, after a while, you decide that perhaps shadowing is not always > so bad. (It helps if the Effbot tells you off for objecting to shadowing in > a two-line function.) At first, you limit yourself to using parameter names > that shadow built-ins in small tool-like functions. Then when the world > doesn't implode, you rethink the use of top-level function names > like "izip" and realise that namespaces exist so that you don't need to > care about shadowing functions you don't use, and if people call import * > they have nobody to blame but themselves if things break. Hmm. See, I've never reached that, in Python or any other language. I figure it creates a new potential for confusion, and that I would rather avoid any ambiguity. I don't *like* ambiguity in code. So I don't shadow stuff that's part of the language, because doing that makes it possible for a line of code to have a clear and obvious meaning to someone who looks at that line out of context, and a *completely different* clear and obvious meaning to someone who looks at it with a bit more context. I don't like that! It means that someone reading my code can never, ever, assume that a standard language feature is actually itself and not a local shadow which does something different unless they go walking back up the scope chain checking. And that's a pretty big cost to attach to stuff that is, by design, basic and universally available. I might feel differently about names which were only visible after you imported some specific thing, but if we're talking built-ins that are always visible... Hmm. No, actually, even then, I just think it's Bad Mojo to overlap names that were taken by the language itself. If a name is in a different scope which I'm not in, I don't care about it, but if the name would already be in scope if I didn't declare it, then I am creating a nasty ambiguity if I use it. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From jdoe at usenetlove.invalid Tue Aug 16 23:52:35 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 03:52:35 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Jerry Hill wrote: > John Doe wrote: >> No. I am running this from within Windows, all sorts of >> Windows. > > What does that mean? You snipped the context, Benny. > You seem very resistant to answering anyone's questions about > your code. No one else has had a problem with my code, Benny, and you have not questioned my code. I laid it out, they tried it, and now we're getting on with it. > Is your code run from the command line, or does it have a GUI? Using "does your code have a GUI" produces zero search results. Maybe that works better in some other language. > If it has a GUI, what windowing toolkit are you using? I guess the answer is Dragonfly. Or maybe it's Komodo (the IDE), as previously stated. I have never been interested in making Windows, just making Windows dance. I do macroing. > If you have code that's not working, please, show us a short, > run-able bit of sample code that demonstrates the problem you're > experiencing. Benny... Apparently you have missed at least two other replies that said they tried some of the code I provided and it worked fine for them. As already stated, a hook is probably required. It's not a big surprise to me, but it's a lot more work. And now I am in the process of getting it done. I expect the results to be very pleasant, though. I'm going to have a system that does voice-activated scripting combined with a systemwide hook, all in one package. If I can get the hook properly installed, it should rock, and I'm ready to tackle it. -- > Describe the behavior you see, the behavior you expected > instead, and the full text of any traceback you may be getting. > > -- > Jerry > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail > Return-Path: > X-Original-To: python-list python.org > Delivered-To: python-list mail.python.org > X-Spam-Status: OK 0.054 > X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'sorts': 0.04; 'answering': 0.09; 'demonstrates': 0.09; '16,': 0.15; 'doe': 0.16; 'getting.': 0.16; 'subject:continuing': 0.16; 'wrote:': 0.16; 'header:In- Reply-To:1': 0.22; 'tue,': 0.23; 'pm,': 0.24; 'command': 0.24; 'aug': 0.24; 'traceback': 0.24; 'code': 0.25; 'code.': 0.26; 'bit': 0.28; 'problem': 0.28; 'message-id: mail.gmail.com': 0.29; 'toolkit': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'does': 0.32; 'to:addr:python-list': 0.33; 'describe': 0.34; 'see,': 0.34; 'short,': 0.34; 'running': 0.35; 'instead,': 0.37; 'run': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'your': 0.61; 'john': 0.62; 'full': 0.63; 'show': 0.67; 'received:209.85.215.174': 0.67; 'received:mail-ey0-f174.google.com': 0.67; 'resistant': 0.84; 'windowing': 0.84; 'working,': 0.93 > DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=09nEr3tlARCpTiOfhP1XOnteJhDd/baJpJhzNhp5UsI=; b=v9cmI/PvRfaLZhXxYs1bHlUOG+IaGEjPq0Xmx+WTkTOPc5YRFRNivsVO8wgKHaWXZm LhxtRbBJaAJuZlXNZ2rX2BxXaT8VJ6wnn2Z1gRv83Jqxi+jJ4zHcfExLPrLRzxLKZXOc oeVqZwTxJRX8VOytC17/RwVjznYcamlxZsG3Q= > MIME-Version: 1.0 > In-Reply-To: <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> > Date: Tue, 16 Aug 2011 20:11:39 -0400 > Subject: Re: Wait for a keypress before continuing? > From: Jerry Hill > To: python-list python.org > Content-Type: text/plain; charset=UTF-8 > X-BeenThere: python-list python.org > X-Mailman-Version: 2.1.12 > Precedence: list > List-Id: General discussion list for the Python programming language > List-Unsubscribe: , > List-Archive: > List-Post: > List-Help: > List-Subscribe: , > Newsgroups: comp.lang.python > Message-ID: > Lines: 13 > NNTP-Posting-Host: 2001:888:2000:d::a6 > X-Trace: 1313539907 news.xs4all.nl 23971 [2001:888:2000:d::a6]:45697 > X-Complaints-To: abuse xs4all.nl > From cbrown at cbrownsystems.com Wed Aug 17 00:13:20 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Tue, 16 Aug 2011 21:13:20 -0700 (PDT) Subject: testing if a list contains a sublist References: <38e0e433-bfd4-4572-9c64-17ed1c87d808@ea4g2000vbb.googlegroups.com> <4e4a2c41$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1f44baaf-37a6-40b6-994d-8141fe9f621c@t6g2000yqd.googlegroups.com> On Aug 16, 1:37?am, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote: > > > > > On Aug 15, 4:26?pm, Johannes wrote: > >> hi list, > >> what is the best way to check if a given list (lets call it l1) is > >> totally contained in a second list (l2)? > > >> for example: > >> l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > >> l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > >> l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > >> my problem is the second example, which makes it impossible to work with > >> sets insteads of lists. But something like set.issubset for lists would > >> be nice. > > >> greatz Johannes > > > My best guess: > > > from collections import Counter > > There's no reason to think that the Original Poster wants a multiset based > solution. He asked about lists and sublists. That's a standard term, like > substring: > > "12" is a substring of "01234". > "21" and "13" are not. > > [1, 2] is a sublist of [0, 1, 2, 3, 4]. > [2, 1] and [1, 3] are not. > > Since lists are ordered, so are sublists. > That's reasonable; although except in the subject, the OP never uses the term 'sublist'; instead using more ambiguous terms like 'contains', 'is totally contained', etc., with definition by limited example. So it was a bit of a guess on my part of what was wanted. > If the OP does want a solution that ignores order, then he needs to describe > his problem better. As it turns out, in another response the OP says he wants [2,1,2] to be 'contained' by [1,2,2]. But in any case he always has sorted lists, in which case, interestingly, the multiset approach and your more canonical sublist approach yield the same results. Cheers - Chas From usenet-nospam at seebs.net Wed Aug 17 01:06:24 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 05:06:24 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Message-ID: On 2011-08-17, John Doe wrote: > Using "does your code have a GUI" produces zero search results. > Maybe that works better in some other language. You shouldn't need a search engine to answer a question about your code. If you do, it suggests that perhaps one or more of the terms are unfamiliar to you? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From jdoe at usenetlove.invalid Wed Aug 17 01:49:32 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 05:49:32 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> Message-ID: <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Seebs wrote: > John Doe wrote: >> Using "does your code have a GUI" produces zero search results. >> Maybe that works better in some other language. > > You shouldn't need a search engine to answer a question about > your code. Context is lost when you quote only one level. I was not answering a question about my code. I was pointing out the fact that my questioner's terminology is strange/corrupt. > If you do, it suggests that perhaps one or more of the terms are > unfamiliar to you? Yes, even the common term "command line" is foreign to me. I do some powerful stuff in Windows, without need for a command line. I realize it exists and that some people live by it, but it has been nearly useless to me. -- > > -s > -- > Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!news-out.readnews.com!transit3.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.megabitz.net!nnrp2-asbnva.megabitz.net!not-for-mail > Newsgroups: comp.lang.python > From: Seebs > Subject: Re: Wait for a keypress before continuing? > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df news.astraweb.com> > User-Agent: slrn/0.9.9p1 (Darwin) > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Message-ID: > Date: 17 Aug 2011 05:06:24 GMT > Lines: 14 > Organization: Megabitz - More USENET, Faster USENET > NNTP-Posting-Date: 17 Aug 2011 05:06:24 GMT > NNTP-Posting-Host: 93ee8380.news.megabitz.net > X-Trace: DXC=oHM8SW;d^:0L\jMDQ^7Q0;><6FU_Q:4m2^W\Y;gN2lO=:j84KQkNLA7b6g X-Complaints-To: abuse megabitz.net > From usenet-nospam at seebs.net Wed Aug 17 02:12:02 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 06:12:02 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: On 2011-08-17, John Doe wrote: > Context is lost when you quote only one level. Not significantly. > I was not answering a question about my code. I was pointing out > the fact that my questioner's terminology is strange/corrupt. Well, that's the thing. There was a question there, with perfectly valid terminology. >> If you do, it suggests that perhaps one or more of the terms are >> unfamiliar to you? > Yes, even the common term "command line" is foreign to me. I do > some powerful stuff in Windows, without need for a command line. So apparently you *do* know the term. Normally, to say that a term is foreign to you is to say that you have no idea what it means, not that you know what it means but don't use it. > I realize it exists and that some people live by it, but it has > been nearly useless to me. In which case, you're not using a command line, and are using a GUI, and the other poster's question is answered. The Google results you cite to are uninteresting and frankly irrelevant. If someone asks me whether the ornamental fish in my 55-gallon tank is a koi, that Google has no hits for "ornamental fish in your 55-gallon tank is a koi" does not mean that the terminology is "strange" or "corrupt". The terminology was fine. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 03:13:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:13:49 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 1:14 AM, gc wrote: > Perfectly reasonable request! Maybe there aren't as many cases when > multiple variables need to be initialized to the same value as I think > there are. > Minor clarification: You don't want to initialize them to the same value, which you can do already: a=b=c=d=e=dict() You want to initialize them each to a fresh evaluation of the same expression. What you're asking for is a syntax that writes an expression once, but evaluates it many times; I think it's going to work out something very similar to a list comprehension (as has been mentioned). ChrisA From rosuav at gmail.com Wed Aug 17 03:19:25 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:19:25 +0100 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 7:12 AM, Seebs wrote: >> Yes, even the common term "command line" is foreign to me. I do >> some powerful stuff in Windows, without need for a command line. > > So apparently you *do* know the term. ?Normally, to say that a term is > foreign to you is to say that you have no idea what it means, not that > you know what it means but don't use it. > Unless you're saying it for deliberate effect. Smith: "To whom do you pay rent?" Arcadian girl: "Rent? We do not know what it is to pay rent!" Smith: "Ah. They're Irish." They know full well what "rent" means, but don't truly comprehend the concept, as they've never done it. I would say that for many people, command lines are the same thing. For me, photo editing is like that. ChrisA From jdoe at usenetlove.invalid Wed Aug 17 03:23:44 2011 From: jdoe at usenetlove.invalid (John Doe) Date: 17 Aug 2011 07:23:44 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> Message-ID: <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Seebs wrote: > John Doe wrote: >> Context is lost when you quote only one level. > > Not significantly. Whatever you say, Jeebs. >> I was not answering a question about my code. I was pointing >> out the fact that my questioner's terminology is >> strange/corrupt. > > Well, that's the thing. There was a question there, with > perfectly valid terminology. And I respect your opinion, Jeebs. >>> If you do, it suggests that perhaps one or more of the terms >>> are unfamiliar to you? > >> Yes, even the common term "command line" is foreign to me. I do >> some powerful stuff in Windows, without need for a command >> line. > > So apparently you *do* know the term. Not very well, obviously. > Normally, to say that a term is foreign to you is to say that > you have no idea what it means, Sounds like being a lexicographer is a fantasy of yours, Jeebs. > not that you know what it means but don't use it. But in fact I do not have a clear understanding of what it means, Jeebs, but I know that it's a common term. You are not a lexicographer, dude. >> I realize it exists and that some people live by it, but it has >> been nearly useless to me. > > In which case, you're not using a command line, and are using a > GUI, and the other poster's question is answered. That might have been clear to most normal people in my first reply to the first follow-up. "I am using Windows XP SP3. Komodo Edit 6 for editing the *.py file. Dragon Naturally Speaking, Natlink, and Dragonfly might all be part of the process." The answer was pointless by the time the question was asked straightforward. Thanks to the prior replies, by then I had already figured out that I need a keyboard hook. The answer doesn't matter anymore. > The Google results you cite to are uninteresting and frankly > irrelevant. You have every right to an opinion, Fuckturd. > If someone asks me whether the ornamental fish in my 55-gallon > tank is a koi, that Google has no hits for "ornamental fish in > your 55-gallon tank is a koi" does not mean that the terminology > is "strange" or "corrupt". No wonder you don't quote relevant material, Jeebs. If anybody knew what you were comparing that expression to, you would look stupid. > The terminology was fine. Are you a master of terminology on wikishit, Jeebs? I think wikishit sucks. Wannabe lexicographers like you might be a reason. I've dealt with some real lexicographers, Jeebs, you aren't one. -- > > -s > -- > Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam seebs.net > http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures > http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! > I am not speaking for my employer, although they do rent some of my opinions. > > > Path: news.astraweb.com!border6.newsrouter.astraweb.com!news.glorb.com!newsfeeds.sol.net!post2.nntp.sol.net!posts.news.megabitz.net!nnrp3-asbnva.megabitz.net!not-for-mail > Newsgroups: comp.lang.python > From: Seebs > Subject: Re: Wait for a keypress before continuing? > References: <4e3f2827$0$5826$c3e8da3$12bcf670 news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128 news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893 news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d news.astraweb.com> > User-Agent: slrn/0.9.9p1 (Darwin) > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Message-ID: > Date: 17 Aug 2011 06:12:02 GMT > Lines: 40 > Organization: Megabitz - More USENET, Faster USENET > NNTP-Posting-Date: 17 Aug 2011 06:12:02 GMT > NNTP-Posting-Host: 3c8d6a06.news.megabitz.net > X-Trace: DXC=BKlkN0:D\OSc::[BQideGP><6FU_Q:4mR^W\Y;gN2lO]C2e6efi]<9Z?jW6Mmc0=4W7d DE\31QYU2V739; X-Complaints-To: abuse megabitz.net > From rosuav at gmail.com Wed Aug 17 03:27:44 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:27:44 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On Wed, Aug 17, 2011 at 2:35 AM, Seebs wrote: > On 2011-08-17, Chris Angelico wrote: >> It mightn't be very significant, but there'd still be some cost. >> However, IMHO the greatest cost is the spamminess; forcing the user to >> deal with lines and lines of warnings is not a useful way to design a >> language. > > Lines and lines? > > I'd say if it's to be allowed to shadow built-ins (and I'm not sure that's > a good thing at all), you'd still be looking at one warning per shadowing, > which shouldn't be too many. One warning per shadowing. Okay. def foo(list): """Foo's the list provided and returns True on success or False on failure.""" def bar(list): """Counts the number of bars in the list, assuming it to be made of music.""" if not foo(list): return You call foo() once and bar() twice. How many shadowings have there been? How many warnings do you get? A simple implementation would give five warnings for this case - once for each invocation that shadows a builtin. Another simple implementation would give two warnings, at the time that the def statements are executed; this is preferred, but it's still two warnings, and if you have a huge set of functions that do this, that can easily be "lines and lines" of warnings. Or should it set a flag and say "I've already warned this session about shadowing 'list', so suppress all others"? That seems confusing. ChrisA From rosuav at gmail.com Wed Aug 17 03:34:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 08:34:22 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 1:58 AM, Steven D'Aprano wrote: >> My thoughts would be: >> 1. ?It's hard to avoid shadowing anything unless you know the entire >> language and never forget things. > > Define the "entire language". Does that include the names of all the > plethora of exceptions? How about the standard library? The shadowing issue applies to the standard library as well as the builtins, so yes; to avoid shadowing *anything*, you would have to know the entire language. I posit that this is a practical impossibility, and that unexpected shadowing will always be possible (and won't always be prevented by syntax highlighting). Some day you'll discover that you can't use module X because you have a function called X, and you'll have to rename. ChrisA From peter.mosley at talk21.com Wed Aug 17 04:03:00 2011 From: peter.mosley at talk21.com (peter) Date: Wed, 17 Aug 2011 01:03:00 -0700 (PDT) Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> Message-ID: <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Is there an equivalent to msvcrt for Linux users? I haven't found one, and have resorted to some very clumsy code which turns off keyboard excho then reads stdin. Seems such an obvious thing to want to do I am surprised there is not a standard library module for it. Or have I missed someting (wouldn't be the first time!) Peter From steve+comp.lang.python at pearwood.info Wed Aug 17 04:15:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 18:15:19 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Aug 2011 01:17 pm Seebs wrote: [...] > "Another" scope is normally a horizontal thing -- you're talking about > a different scope such that you are *either* in this one *or* in that > one. > > Built-ins are not in a scope you are never not in. That's technically incorrect. Built-ins are a scope you are never in, if by "in" you mean "code is executed in this scope". You have three scopes in general: Local Global Built-ins (There's also zero or more nonlocal scopes, between local and global, that applies to closures and nested functions, but never mind that.) Code is almost(?) always executed in the local scope. (eval and exec let you mess around with that, somewhat.) E.g. an assignment "x = 1" applies to the local namespace unless you explicitly declare it global. If you are in the top level of a module, the local namespace is also the global one, the global statement does nothing, and the assignment occurs in the global namespace. However, name lookup rules are such that while assignments are always local, unsuccessful lookups may fall through to global then built-in. See also: http://www.python.org/dev/peps/pep-0227/ The only way to put something into the built-in namespace is by using the fully-qualified name: >>> import builtins # Use __builtin__ in Python 2 >>> builtins.x = 1 # Kids! Don't try this at home! >>> >>> x 1 >>> del x # prove it isn't a global or local Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined So a top-level (global) assignment, say: def sum(list): ... *shadows* the built-ins sum and list, it doesn't replace them. It defines a local variable "list" and a global variable "sum", but it doesn't touch either built-in. They are still available via the fully qualified name builtins.sum and builtins.list. [...] >> (4) And then, after a while, you decide that perhaps shadowing is not >> always so bad. (It helps if the Effbot tells you off for objecting to >> shadowing in a two-line function.) At first, you limit yourself to using >> parameter names that shadow built-ins in small tool-like functions. Then >> when the world doesn't implode, you rethink the use of top-level function >> names like "izip" and realise that namespaces exist so that you don't >> need to care about shadowing functions you don't use, and if people call >> import * they have nobody to blame but themselves if things break. > > Hmm. See, I've never reached that, in Python or any other language. I > figure it creates a new potential for confusion, and that I would rather > avoid any ambiguity. I don't *like* ambiguity in code. Ah, well you see the thing is, this is Python. As soon as you call any function you don't control, you no longer know what your environment is with any certainty. For all you know, the harmless-looking function is monkey-patching builtins like there's no tomorrow. Speaking broadly, perhaps too broadly, we're incredibly proud of the ability to modify nearly everything at runtime. Fortunately, while we are proud of having that ability, actually *using* it is considered a mortal sin. We're not Ruby developers -- if you actually monkey-patch something, especially built-ins, you can expect to be taken outside and slapped around with a fish if you get caught. http://www.youtube.com/watch?v=IhJQp-q1Y1s > So I don't shadow stuff that's part of the language, because doing that > makes it possible for a line of code to have a clear and obvious meaning > to someone who looks at that line out of context, and a *completely > different* clear and obvious meaning to someone who looks at it with a bit > more > context. I don't like that! It means that someone reading my code can > never, ever, assume that a standard language feature is actually itself > and not a local shadow which does something different unless they go > walking back up the scope chain checking. And that's a pretty big cost > to attach to stuff that is, by design, basic and universally available. Sure. But they can't have that certainty regardless of whether you shadow something, because how do they know whether you've shadowed it or not? In theory, anything could be anything at any time, and you have no protection. In practice, I worry more about being eaten by genetically-engineered flying piranhas than about rogue monkey-patching code. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 17 04:28:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 17 Aug 2011 18:28:14 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Aug 2011 05:23 pm John Doe wrote: > You have every right to an opinion, Fuckturd. I shouldn't need to say this to anyone over the age of four, but being obnoxious to people trying to help does not encourage others to answer your question. You don't win points for insulting people who are trying to solve your problems. -- Steven From gnarlodious at gmail.com Wed Aug 17 05:06:31 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:06:31 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables Message-ID: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get >>> name2 -> MiniFieldStorage('name2', 'Val2') when I need to assign the variable name2 the value Val2 This is Py3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:16:06 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:16:06 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables Message-ID: <07a5fd4b-00fb-4ac9-b3b3-9ae820deb132@p10g2000yqi.googlegroups.com> I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get >>> name2 -> MiniFieldStorage('name2', 'Val2') when I need to assign the variable name2 the value Val2 This is Py3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:19:22 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:19:22 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie From gnarlodious at gmail.com Wed Aug 17 05:20:27 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 02:20:27 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: <33d4abcb-e017-430a-a46a-d1669f053c54@a12g2000yqi.googlegroups.com> I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie From rosuav at gmail.com Wed Aug 17 05:25:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:25:03 +0100 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:06 AM, Gnarlodious wrote: > I get a construct like this: > > form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), > MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) > > when I need to assign the variable name2 the value Val2 You can probably do this with some kind of list comprehension, but I recommend against it, if this has come from a web form. You do NOT want end users having the power to set variables. Keep it in a separate object (such as 'form') such that you must always be explicit about fetching form data. PHP has learned the risks; here's a decent summary: http://www.php.net/manual/en/security.globals.php Chris Angelico From gc1223 at gmail.com Wed Aug 17 05:26:42 2011 From: gc1223 at gmail.com (gc) Date: Wed, 17 Aug 2011 02:26:42 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Aug 17, 3:13?am, Chris Angelico wrote: > Minor clarification: You don't want to initialize them to the same > value, which you can do already: > > a=b=c=d=e=dict() Right. Call the proposed syntax the "instantiate separately for each target" operator. (It can be precisely defined as a * on the RHS of a one-into-many assignment statement--i.e. an assignment statement with 1 object on the RHS and more than 1 on the LHS). It has only one very modest function, which is to unpack a, b, c, d, e = *dict() to a, b, c, d, e = dict(), dict(), dict(), dict(), dict() so that you have n separate objects instead of one. If you want the same object duplicated five times, you'd best use a=b=c=d=e=dict(). (I'd guess that 90% of the people who try the a=b=c version actually *want* separate objects and are surprised at what they get--I made that mistake a few times!--but changing either behavior would be a very bad idea. This proposed syntax would be the Right Way to get separate objects.) Maybe this is more visibly convenient with a complex class, like x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) where you need three separate objects but don't want to duplicate the class call (for obvious copy-paste reasons) and where bundling it in a list comprehension: x, y, z = [SuperComplexClass(param1, etc, ...) for _ in range(3)] layers gunk on top of something that's already complex. > I think it's going to work out something very similar to a > list comprehension (as has been mentioned). Right; kind of a self-limiting generator[1], although that sounds MUCH more complex than it needs to. It's really just sugar. Not that it this is a suggestion :) but it could easily be done with a pre- processor. It would also be perfectly amenable to automated code conversion (i.e. 3to2). On Aug 16, 10:11 pm, MRAB wrote: > 1. Repeated evaluation of an expression: "dict()" would be evaluated as > many times as necessary. In other words, it's an unlimited generator. > 2. Lazy unpacking: unpacking normally continues until the source is > exhausted, but here you want it to stop when the destination (the RHS) > is satisfied. Yes, this is a good way to think of it. (Although I think you meant to type LHS, right?) * in this context would tell Python to do both of these things at once: evaluate successively and unpack lazily to the destination. Although it's still fully (and more simply) explainable as sugar. [1] Self-limiting is the key here. As above, the only proposed methods which don't require manual tallying on the RHS are Tim's very creative a,b,c,d,e,*scrap = (dict() for _ in range(9999)), which in this case creates a list containing 9994 unnecessary dicts, or the purer but Python-crashing a,b,c,d,e,*scrap = (dict() for _ in itertools.count()). Tim's intuition, which I share, is that in both cases *scrap should, since it's in final position, actually become the generator-in-state-6, rather than slurping the rest into a list. One argument for this is that the present behavior is (surprisingly, counterintuitively) identical for list comprehensions and generator expressions. Changing the outer parens to brackets yields the same results. But that's a separate, more complex proposal which would need its own use cases. From rosuav at gmail.com Wed Aug 17 05:41:41 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:41:41 +0100 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:19 AM, Gnarlodious wrote: > import cgi, os > os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" > form=cgi.FieldStorage() > > form > > dict = {} > for key in form.keys(): dict[ key ] = form[ key ].value > You could probably use a list comp for this, but there's not a lot of difference. (By the way, you should be aware that you're shadowing the builtin 'dict' here. That's not a problem, but be aware.) dict.update(((key,form[key].value) for key in form)) That's a generator that returns a (key,value) tuple for each form element, which update() will happily use. But the last line: > locals().update(dict) is, IMHO, a very bad idea. Rename your dictionary to 'request' or 'data' or 'form' or something, and then reference form['name3'] instead; or, be explicit: name3=form['name3'] Incidentally, you seem to be working at the module level, where locals() is globals() (and I mean that literally - 'locals() is globals()' is True). You may not be able to do this with locals() in a function: http://docs.python.org/library/functions.html#locals Chris Angelico From rosuav at gmail.com Wed Aug 17 05:45:24 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 10:45:24 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 10:26 AM, gc wrote: > On Aug 17, 3:13?am, Chris Angelico wrote: > >> Minor clarification: You don't want to initialize them to the same >> value, which you can do already: >> >> a=b=c=d=e=dict() > > Right. Call the proposed syntax the "instantiate separately for each > target" operator. ?(It can be precisely defined as a * on the RHS of a > one-into-many assignment statement--i.e. an assignment statement with > 1 object on the RHS and more than 1 on the LHS). > Agreed, but there's no requirement for it to be instantiating something (although that will be common). "dict()" is an expression that you want to evaluate five (or however many) times. It might just as easily be some other function call; for instance: head1,head2,head3=file.readline() to read three lines from a file. Or it mightn't even be a function call per se. ChrisA From gc1223 at gmail.com Wed Aug 17 06:33:58 2011 From: gc1223 at gmail.com (gc) Date: Wed, 17 Aug 2011 03:33:58 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <2e4e9b97-df0e-4c1e-9f41-db2b475add21@d7g2000vbv.googlegroups.com> On Aug 17, 5:45?am, Chris Angelico wrote: (snip) > > Right. Call the proposed syntax the "instantiate separately for each > > target" operator. > (snip) > It might just > as easily be some other function call; for instance: > > head1,head2,head3=file.readline() Hm--that's interesting! OK, call it the "evaluate separately for each target" operator. Same benefits in this use case; if I realize that the file only has two header lines, I can just change head1, head2, head3 = *file.readline() to head1, head2 = *file.readline() without needing to keep a RHS like = [file.readline() for _ in range(3)] in lockstep with the number of variables I'm assigning. Presumably this syntax should be disallowed, as a grammatical matter, when there's a starred target (per PEP 3132/language reference 6.2). That is, head, *body, tail = *file.readline() is disallowed, since it is (by definition) simply sugar for head = file.readline() *body = file.readline() tail = file.readline() and *body = file.readline() is disallowed (see PEP 3132). (Here, of course, you'd just want head, *body, tail = file.readlines(), which is perfectly good code.) PS. Off-topic, but the *target syntax already gets into similar territory, since a, *b, c = itertools.count() crashes with a MemoryError--but what else could it do? Ruling out such infinite-assignment statements on a grammatical basis would require solving the halting problem through static analysis, which might be a bit inefficient :P From benjokal at gmail.com Wed Aug 17 06:37:26 2011 From: benjokal at gmail.com (Benji Ara.) Date: Wed, 17 Aug 2011 06:37:26 -0400 Subject: How to package a gui with py2exe Message-ID: Hello I wonder how you package a Tkinter gui with py2exe? Thanks Benji * * -------------- next part -------------- An HTML attachment was scrubbed... URL: From f.derainville at gmail.com Wed Aug 17 07:27:10 2011 From: f.derainville at gmail.com (fmder1) Date: Wed, 17 Aug 2011 04:27:10 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=A0=3A_Messed_up_Mac_installation?= In-Reply-To: References: Message-ID: Checkout Homebrew. It can install in a very easy and clean way different version of Python (as well as a lot of other stuff). It tried for a long time to keep my Mac clean and this is so far the best I found. From f.derainville at gmail.com Wed Aug 17 07:28:05 2011 From: f.derainville at gmail.com (fmder1) Date: Wed, 17 Aug 2011 04:28:05 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=A0=3A_Messed_up_Mac_installation?= In-Reply-To: References: Message-ID: <81ef6220-e536-499c-8e1c-944a6b0b3be7@glegroupsg2000goo.googlegroups.com> Forgot to include a link : https://github.com/mxcl/homebrew From mail at timgolden.me.uk Wed Aug 17 08:17:22 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Aug 2011 13:17:22 +0100 Subject: Windows service in production? In-Reply-To: <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> Message-ID: <4E4BB152.5020904@timgolden.me.uk> On 16/08/2011 15:46, snorble wrote: > Interesting. Normally I would use py2exe then do "myapp.exe -install" > to install the app as a service. How do you handle installing the > service? Also what does the service show under the properties, for the > executable? "python.exe script.py" or something else? To install, I simply invoke the Command-line handler which comes with the pywin32 service utils: if __name__ == '__main__': win32serviceutil.HandleCommandLine (Service) (I imagine that's what py2exe's doing for you behind the scenes). The executable shows as pythonservice.exe. The short and long display names can of course be whatever you like. TJG From nobody at nowhere.com Wed Aug 17 08:28:42 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Aug 2011 13:28:42 +0100 Subject: testing if a list contains a sublist References: Message-ID: On Tue, 16 Aug 2011 09:57:57 -0400, John Posner wrote: > How about using Python's core support for "==" on list objects: > for i in range(alist_sz - slist_sz + 1): > if slist == alist[i:i+slist_sz]: > return True This is bound to be asymptotically O(alist_sz * slist_sz), even if the constant factor is reduced by use of ==. Boyer-Moore and regexps are asymptotically O(alist_sz). However, the setup costs are much higher, so you might need alist_sz to be very large before they win out. From vlastimil.brom at gmail.com Wed Aug 17 08:44:07 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 17 Aug 2011 14:44:07 +0200 Subject: How to package a gui with py2exe In-Reply-To: References: Message-ID: 2011/8/17 Benji Ara. : > Hello > I wonder how you package a Tkinter gui with py2exe? > Thanks > Benji > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, check the necessary steps on the py2exe homepage http://www.py2exe.org/index.cgi/Tutorial in your setup script, you have to use something like the following for a gui app: setup(windows=["gui_hello.py"]) instead of console in the sample code setup(console=['hello.py']) For more details there are some dedicated pages on the project wiki: http://www.py2exe.org/index.cgi/FrontPage hth, vbr From nobody at nowhere.com Wed Aug 17 08:45:36 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Aug 2011 13:45:36 +0100 Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, 17 Aug 2011 02:06:31 -0700, Gnarlodious wrote: > I get a construct like this: > > form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), > MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) > > Now how would I assign every variable name* its value? Don't do this. It will allow the user to set any variable they wish, not just the ones you want them to, which is a major security flaw. PHP had this as a language feature (controlled by the register_globals directive), and it was rightly decried as a major security flaw. From duncan.booth at invalid.invalid Wed Aug 17 09:15:04 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Aug 2011 13:15:04 GMT Subject: How to install easy_install on windows ? References: <77f65ea2-3748-4dfa-af7c-498ebe2d3be8@f7g2000vba.googlegroups.com> Message-ID: aspineux wrote: > in a command prompt run > C:\Your Python Directory\python.exe C:\Your Download directory > \ez_setup.py > > Then use > > C:\Your Python Directory\python.exe C:\Your Python Directory\I dont > know where the easy_install script will be installed\easy_install.py > install module_name Or even just use: C:\Your Python Directory\scripts\easy_install install module_name as easy_install will also add a .exe to your Python's 'scripts' folder. -- Duncan Booth http://kupuguy.blogspot.com From ethan at stoneleaf.us Wed Aug 17 09:21:23 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 06:21:23 -0700 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4E4BC053.6050000@stoneleaf.us> Welcome to my killfile. *plonk* From grickert at coldstorage.com Wed Aug 17 09:30:14 2011 From: grickert at coldstorage.com (Gerrat Rickert) Date: Wed, 17 Aug 2011 09:30:14 -0400 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com><4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On 8/16/2011 7:29 PM, Terry Reedy wrote: > > On 8/16/2011 1:15 PM, Gerrat Rickert wrote: > > > I think that best practices would suggest that one shouldn't use > > variable > > names that shadow builtins (except in specific, special > circumstances), > > so I don't really think this would be an annoyance at all. The > number > > of > > *unwanted* warnings they'd get would be pretty close to zero. OTOH, > in > > response to a question I asked on StackOverflow, someone posted a > large > > list of times where this isn't followed in the std lib, so there > seems > > to be a precedent for just using the builtin names for anything > > one feels like at the time. > > If you run across that again and email me the link, I will take a look > and see if I think the issue should be raised on pydev. Of course, some > modules *intentionally* define an open function, intended to be > accessed > as 'mod.open' and not as 'from mod import *; open'. Also, > class/instance > attributes can also reuse builtin names. But 'open = ' > would > be bad. > > > -- > Terry Jan Reedy > See the accepted answer to this question: http://stackoverflow.com/questions/7079519/is-there-python-code-in-the-python-standard-library-that-uses-variable-names-that From ameretat.reith at gmail.com Wed Aug 17 10:11:21 2011 From: ameretat.reith at gmail.com (Ameretat Reith) Date: Wed, 17 Aug 2011 18:41:21 +0430 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: <2411612.e64O9QM6es@hades> On Se shanbe 25 Mordad 1390 01:26:54 Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes Hope best answer is found so far. for easy answer, i prefer to use Python `==' operator instead of inner loop. l=[1,2,3,4,5] s=[1,2,2] sc=len(s) for c in xrange(len(l)-sc+1): if l[c:sc+c] == s: print ( 'found at {0}'.format(c) ) break Since sub-lists memory will be garbage collected, there is no problem in memory usage, but in time needed for constructing new slice, there is. -- Amir Ghassemi Nasr (Reith) GPG ID: 371035B4 (http://46.4.214.112/~reith/reith.asc) GPG Fingerprint: 18E6 CF11 BE80 F541 DC68 B6AF 9373 DE72 3710 35B4 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 230 bytes Desc: This is a digitally signed message part. URL: From hansmu at xs4all.nl Wed Aug 17 10:16:23 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 17 Aug 2011 16:16:23 +0200 Subject: Wait for a keypress before continuing? In-Reply-To: <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> On 17/08/11 10:03:00, peter wrote: > Is there an equivalent to msvcrt for Linux users? I haven't found > one, and have resorted to some very clumsy code which turns off > keyboard excho then reads stdin. Seems such an obvious thing to want > to do I am surprised there is not a standard library module for it. Or > have I missed someting (wouldn't be the first time!) The quick and dirty way is to invoke stty(1) using os.system: import os def getpassword(prompt="Password: "): try: os.system("stty -echo") passwd = raw_input(prompt) finally: os.system("stty echo") return passwd Strictly speaking, os.system is deprecated and you should use the equivalent invocation of subprocess.call: import subprocess def getpassword(prompt="Password: "): try: subprocess.call(["stty", "-echo"]) passwd = raw_input(prompt) finally: subprocess.call(["stty", "echo"]) return passwd If you don't want to use an external process, use termios: import termios, sys def getpassword(prompt="Password: "): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ECHO # lflags try: termios.tcsetattr(fd, termios.TCSADRAIN, new) passwd = raw_input(prompt) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) return passwd These functions work on any Posix system (including Mac OSX), but not on Windows. Hope this helps, -- HansM From thinke365 at gmail.com Wed Aug 17 11:13:20 2011 From: thinke365 at gmail.com (smith jack) Date: Wed, 17 Aug 2011 23:13:20 +0800 Subject: Some warning appears when installing virtualenv, does it matters? Message-ID: the warning is just as follows E:\Tools>pip install virtualenv Downloading/unpacking virtualenv Downloading virtualenv-1.6.4.tar.gz (1.9Mb): 1.9Mb downloaded Running setup.py egg_info for package virtualenv warning: no previously-included files matching '*.*' found under directory ' docs\_templates' Installing collected packages: virtualenv Running setup.py install for virtualenv warning: no previously-included files matching '*.*' found under directory ' docs\_templates' Installing virtualenv-script.py script to E:\Tools\gov\tools\py_build\Script s Installing virtualenv.exe script to E:\Tools\gov\tools\py_build\Scripts Installing virtualenv.exe.manifest script to E:\Tools\gov\tools\py_build\Scr ipts Successfully installed virtualenv Cleaning up... From jabba.laci at gmail.com Wed Aug 17 11:20:52 2011 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 17 Aug 2011 17:20:52 +0200 Subject: monitor mouse coordinates in real-time In-Reply-To: <6e7d17a8-d5aa-4755-9bd4-09c09bed5c03@o26g2000vbi.googlegroups.com> References: <6e7d17a8-d5aa-4755-9bd4-09c09bed5c03@o26g2000vbi.googlegroups.com> Message-ID: Hi, Thanks, the problem got solved. The updated version can be found at https://gist.github.com/1144708 in a comment below the original post. Solution: self.connect("destroy", self.quit) def quit(self, widget): self.mouseThread.kill() gtk.main_quit() It was not evident that quit() must be passed the argument "widget" too. Thanks, Laszlo On Wed, Aug 17, 2011 at 16:48, MrJean1 wrote: > Check that the app.quit method registered with atexit is called. ?E.g. > on Windows, that may not be the case. > > /JeAN > > > On Aug 14, 9:39?am, Jabba Laci wrote: >> I'm trying something similar. In the thread there is a variable which >> is modified by the parent. However, the thread doesn't quit the >> infinite loop. If someone could provide a patch, that'd be really >> useful. >> >> Thanks, >> >> Laszlo >> >> >> On Sun, Aug 14, 2011 at 13:00, TheSaint wrote: >> > Jabba Laci wrote: >> >> >> Could you please help me out how to close the application correctly? >> >> > I think you should put a flag into the code, which the parent might modify >> > it, so it will tell the child process to quit. >> > Then the flag should need to be read periodically to know whether is time to >> > quit. >> >> > -- >> >http://mail.python.org/mailman/listinfo/python-list > > From mail at timgolden.me.uk Wed Aug 17 11:47:49 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Aug 2011 16:47:49 +0100 Subject: How to Check Write Access of a Folder on Windows In-Reply-To: References: Message-ID: <4E4BE2A5.3010405@timgolden.me.uk> On 16/08/2011 13:38, Ayaskant Swain wrote: > Hi Tim, > > Thanks for your reply. It seems this issue is related to python bug > -http://bugs.python.org/issue2528 > But the patch code looks complex to me. I want to make changes only > in my python script which will read an user given directory path& > check it's write access. What is the use of posixmodule.c file? Well.. the changes to posixmodule.c, had they been accepted, would have meant that a call to os.access on Windows would have done the work to determine whether or not you truly had access. As it is, that issue has been "demoted" to a doc-and-deprecate bug. So you either need to do the same sequence of actions (more or less) or to simulate its effect. Certainly you can retrieve the ACEs in the DACL via the GetFileSecurity call, and you're then going to have to compare the effect of all the (possibly quite complex and inherited) ACEs on the logged-in user's ability to view the directory. The ACEs might refer directly to the user or (more likely) indirectly via groups, including builtins like "Domain Users" or "Administrators". So you'd have to work out whether your user was in one of those groups, possibly indirectly as groups can contain groups. Certainly all of this is do-able but it won't be trivial. I'm sorry I can't be more helpful but I haven't had a need for this functionality myself (even the patch to issue2528 was in response to someone else's need similar to yours). TJG From tjreedy at udel.edu Wed Aug 17 12:12:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2011 12:12:47 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: The issue behind this thread is that for immutable objects, binding to n copies has the same effect as n bindings to one object (so one does not really have to know which one is doing), whereas the two are different for mutable objects (so one does have to know). In short, identity matters for mutables but not for immutables. Python programmers must learn both this and the fact that Python does not make copies unless asked. Adding a special case exception to the latter to mask the former does not seem like a good idea. On 8/17/2011 5:26 AM, gc wrote: > It has only one very modest function, which is to unpack > > a, b, c, d, e = *dict() *expression has already been proposed to generally mean what it does in function calls -- unpack the iterator in place. funnylist = [1,2,*dict,99,100] # == [1,2]+list(dict)+[99,100] would interpolate the keys of the dict into the list. There is a tracker issue for this -- it would be a follow-on to the addition of *traget in assignments. In a real sense, "a,b = iterable" *already* means "a,b = *iterable". If *iterable had been in general use from the beginning, presume the latter is how we would write sequence unpacking for assignments. > a, b, c, d, e = dict(), dict(), dict(), dict(), dict() *expression will not be changed in meaning to magically re-evaluate an expression some multiple number of times according to code elsewhere. > so that you have n separate objects instead of one. If you want the > same object duplicated five times, you'd best use a=b=c=d=e=dict(). Not 'duplicated', but 'bound'. > (I'd guess that 90% of the people who try the a=b=c version actually > *want* separate objects and are surprised at what they get--I made > that mistake a few times! Guessing that 90% of people are like you is likely to be wrong. I think this use case (for more than 2 or 3 copies) is pretty rare for most people. Where many people do trip up is "array = [[0]*i]*j", expecting to get j copies of [0]*i rather than j bindings of one object. But then, they must have the same wrong idea that [0]*i makes i copies of 0. For immutable 0, the misunderstanding does not matter. For mutable [0]*i, it does. People *must* learn that sequence multiplication multiplies bindings, not (copies of) objects. Both multiple copy problems have the same solution: array = [[0]*i for _ in range(j)] a,b,c,d,e = [dict() for _ in range(5)] The fact that the number of assignment sources (possibly after implicit unpacking) and targets have to match, unless one uses *target, and that both sides need to be changed if one is, is true of all assignments, not just this rare case. >--but changing either behavior would be a > very bad idea. This proposed syntax would be the Right Way to get > separate objects.) It would be very Wrong as it already has a very different meaning. -- Terry Jan Reedy From clp2 at rebertia.com Wed Aug 17 12:23:01 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Aug 2011 09:23:01 -0700 Subject: CGI: Assign FieldStorage values to variables In-Reply-To: References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: On Wed, Aug 17, 2011 at 2:19 AM, Gnarlodious wrote: > I should add that this does what I want, but something a little more > Pythonic? > > import cgi, os > os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3" > form=cgi.FieldStorage() > > form > > dict = {} > for key in form.keys(): dict[ key ] = form[ key ].value > > dict > locals().update(dict) > name3 Try it within a function. It will fail epic-ly in CPython and most other implementations. Read the note in the locals() docs: http://docs.python.org/library/functions.html#locals Cheers, Chris From usenet-nospam at seebs.net Wed Aug 17 12:33:05 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:05 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > I shouldn't need to say this to anyone over the age of four, but being > obnoxious to people trying to help does not encourage others to answer your > question. You don't win points for insulting people who are trying to solve > your problems. The frustrating part, of course, is that the people who do this are doing it for reasons such that the explanation seems only proof that they are even more right than they had previously expected. Pathological narcissism is scary. If you ever find yourself going longer than usual without being wrong, start checking your work more carefully. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 2011-08-17, peter wrote: > Is there an equivalent to msvcrt for Linux users? I haven't found > one, and have resorted to some very clumsy code which turns off > keyboard excho then reads stdin. Seems such an obvious thing to want > to do I am surprised there is not a standard library module for it. Or > have I missed someting (wouldn't be the first time!) There's no direct equivalent to the whole of msvcrt. The Unixy way to do stuff like that on the command line is usually curses. But to make a long story short: Unix evolved in a setting where there was often not a user at *THE* console, and users were often on devices such that it made sense to have all the line editing happen on the remote end, with the remote end sending a completed line once the user was done with all that stuff like backspaces. Unix programs that do stuff like this for tty input do exist, of course, but for the most part, they use an entire API designed for creating such utilities, rather than one or two specialized functions. (Another part of the reason for this: The Unix solution scales nicely to the case where the five people using your program will be doing so on physically different hardware terminals which don't use the same escape sequences for cursor movement.) Usually when people omit something obvious from a design, it's because of other constraints or history to the design which make it less obvious. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <4E4A8F94.50706@stoneleaf.us> Message-ID: On 2011-08-17, Chris Angelico wrote: > def foo(list): > """Foo's the list provided and returns True on success or False on > failure.""" > > def bar(list): > """Counts the number of bars in the list, assuming it to be made > of music.""" > if not foo(list): return > You call foo() once and bar() twice. How many shadowings have there > been? How many warnings do you get? I'd say two, one when def foo... is parsed, one when def bar... is parsed. > A simple implementation would give five warnings for this case - once > for each invocation that shadows a builtin. Another simple > implementation would give two warnings, at the time that the def > statements are executed; this is preferred, but it's still two > warnings, and if you have a huge set of functions that do this, that > can easily be "lines and lines" of warnings. Or should it set a flag > and say "I've already warned this session about shadowing 'list', so > suppress all others"? That seems confusing. I guess I don't object to multiple warnings if I do the same thing multiple times. I was just thinking in terms of a single parse-time warning for the actual point at which something is shadowed, rather than, say, a warning every time a name is hit during execution of statements and refers to a shadow. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Wed Aug 17 12:33:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 16:33:06 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Steven D'Aprano wrote: > On Wed, 17 Aug 2011 01:17 pm Seebs wrote: > [...] >> "Another" scope is normally a horizontal thing -- you're talking about >> a different scope such that you are *either* in this one *or* in that >> one. >> Built-ins are not in a scope you are never not in. > That's technically incorrect. Built-ins are a scope you are never in, if > by "in" you mean "code is executed in this scope". No, by "in" I mean "lookups from your code will reach this scope if they don't find something sooner". >> Hmm. See, I've never reached that, in Python or any other language. I >> figure it creates a new potential for confusion, and that I would rather >> avoid any ambiguity. I don't *like* ambiguity in code. > Ah, well you see the thing is, this is Python. As soon as you call any > function you don't control, you no longer know what your environment is > with any certainty. For all you know, the harmless-looking function is > monkey-patching builtins like there's no tomorrow. Speaking broadly, > perhaps too broadly, we're incredibly proud of the ability to modify nearly > everything at runtime. Heh. > Fortunately, while we are proud of having that ability, actually *using* it > is considered a mortal sin. We're not Ruby developers -- if you actually > monkey-patch something, especially built-ins, you can expect to be taken > outside and slapped around with a fish if you get caught. Okay, so. Here's what I don't get. If it's such a bad thing, *why is it allowed*? Why are you proud of the ability to do something that you are never socially-allowed to do? I have mixed feelings about Ruby's general tolerance for monkey-patching, although I've seen it do some pretty awesome things, so I am somewhat inclined to accept that it may be worth it. But it's clearly a feature which is used intentionally. It sounds to me like Python is very proud of having a feature which no one would ever use. ... Why? > Sure. But they can't have that certainty regardless of whether you shadow > something, because how do they know whether you've shadowed it or not? Well, they could trust me. :) > In theory, anything could be anything at any time, and you have no > protection. In practice, I worry more about being eaten by > genetically-engineered flying piranhas than about rogue monkey-patching > code. I do too, if I know that people don't shadow built-ins. If I know that people are shadowing built-ins, then some of the time, when I'm editing other peoples' code, they HAVE effectively monkey-patched it. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Wed Aug 17 12:36:45 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 02:36:45 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e4bee1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Hans Mulder wrote: > Strictly speaking, os.system is deprecated and you should use > the equivalent invocation of subprocess.call: Strictly speaking, os.system is *not* deprecated in either Python 2.x or 3.x. Latest stable documentation for Python 2.7 and 3.2: http://docs.python.org/library/os.html#os.system http://docs.python.org/py3k/library/os.html#os.system And docs in development for 3.3 (unstable): http://docs.python.org/dev/library/os.html#os.system Deprecation means that there are active plans to remove the feature. There are no such plans to remove os.system. What the docs say is much milder: "The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function." Using subprocess may be recommended, but that is not the same as saying that os.system is deprecated. os.system will not be going away any time in the foreseeable future. -- Steven From python at mrabarnett.plus.com Wed Aug 17 12:55:51 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Aug 2011 17:55:51 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: <4E4BF297.7040901@mrabarnett.plus.com> On 17/08/2011 10:26, gc wrote: > On Aug 17, 3:13 am, Chris Angelico wrote: > >> Minor clarification: You don't want to initialize them to the same >> value, which you can do already: >> >> a=b=c=d=e=dict() > > Right. Call the proposed syntax the "instantiate separately for each > target" operator. (It can be precisely defined as a * on the RHS of a > one-into-many assignment statement--i.e. an assignment statement with > 1 object on the RHS and more than 1 on the LHS). > I think that lazy unpacking is the more important issue because we can replace instantiation with copying: def copies(obj, count=None): if count is None: while True: yield obj.copy() else: for i in range(count): yield obj.copy() (Should it yield deep copies, or should there be a separate deep_copies function?) > It has only one very modest function, which is to unpack > > a, b, c, d, e = *dict() > > to > > a, b, c, d, e = dict(), dict(), dict(), dict(), dict() > This becomes: a, b, c, d, e = copies(dict(), 5) With lazy unpacking it would become: a, b, c, d, e = lazy copies(dict()) (Or whatever the syntax is.) > so that you have n separate objects instead of one. If you want the > same object duplicated five times, you'd best use a=b=c=d=e=dict(). > (I'd guess that 90% of the people who try the a=b=c version actually > *want* separate objects and are surprised at what they get--I made > that mistake a few times!--but changing either behavior would be a > very bad idea. This proposed syntax would be the Right Way to get > separate objects.) > > Maybe this is more visibly convenient with a complex class, like > > x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) > x, y, z = lazy copies(SuperComplexClass(param1, etc, ...)) [snip] From tjreedy at udel.edu Wed Aug 17 13:02:35 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Aug 2011 13:02:35 -0400 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 8/17/2011 12:33 PM, Seebs wrote: > On 2011-08-17, peter wrote: >> Is there an equivalent to msvcrt for Linux users? I haven't found >> one, and have resorted to some very clumsy code which turns off >> keyboard excho then reads stdin. Seems such an obvious thing to want >> to do I am surprised there is not a standard library module for it. Or >> have I missed someting (wouldn't be the first time!) > > There's no direct equivalent to the whole of msvcrt. The Unixy way to > do stuff like that on the command line is usually curses. But to make > a long story short: Unix evolved in a setting where there was often > not a user at *THE* console, and users were often on devices such that > it made sense to have all the line editing happen on the remote end, with > the remote end sending a completed line once the user was done with all > that stuff like backspaces. > > Unix programs that do stuff like this for tty input do exist, of course, > but for the most part, they use an entire API designed for creating such > utilities, rather than one or two specialized functions. (Another part > of the reason for this: The Unix solution scales nicely to the case where > the five people using your program will be doing so on physically > different hardware terminals which don't use the same escape sequences > for cursor movement.) The difference is between "Hit to continue" (which we can do in portable Python) versus "Hit any key to continue" (which we cannot, and which also leads to the joke about people searching for the 'any' key ;-). The equivalent contrast for GUIs is "Click OK to continue" versus "Click anywhere to continue" If having to click a specific area is okay for GUIs, having to hit a specific key for TUIs should be also. -- Terry Jan Reedy From usenet-nospam at seebs.net Wed Aug 17 13:05:31 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:05:31 GMT Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: On 2011-08-17, Terry Reedy wrote: > The difference is between "Hit to continue" (which we can do in > portable Python) versus "Hit any key to continue" (which we cannot, and > which also leads to the joke about people searching for the 'any' key > ;-). And more importantly, frustration and confusion when people pick control or shift. > The equivalent contrast for GUIs is "Click OK to continue" versus > "Click anywhere to continue" If having to click a specific area is okay > for GUIs, having to hit a specific key for TUIs should be also. In general I agree. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 13:25:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 18:25:12 +0100 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <4E4BF297.7040901@mrabarnett.plus.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> <4E4BF297.7040901@mrabarnett.plus.com> Message-ID: On Wed, Aug 17, 2011 at 5:55 PM, MRAB wrote: > x, y, z = lazy copies(SuperComplexClass(param1, etc, ...)) > This assumes that you can construct it once and then copy it reliably, which may mean that the class implement copying correctly. It also wouldn't work with: a, b, c, d = *random.randint(1,20) which would roll 4d20 and get the results in separate variables. The OP's idea of separately evaluating the expression would; but to do it with copying would require a special "randint" object that functions exactly as an integer but, when copied, would re-randomize. Perhaps * is the wrong syntactic element to use. Maybe it needs a special assignment operator: a, b, c, d @= random.randint(1,20) which would evaluate its left operand as a tuple of lvalues, then evaluate its right operand once for each element in the left operand, and assign to each element in turn. (I've no idea what form of assignment operator would be suitable, but @= is currently illegal, so it ought to be safe at least for discussion purposes.) Chris Angelico From usenet-nospam at seebs.net Wed Aug 17 13:36:08 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:36:08 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Ethan Furman wrote: > Seebs wrote: >> On 2011-08-17, Steven D'Aprano wrote: >>> Ah, well you see the thing is, this is Python. As soon as you call any >>> function you don't control, you no longer know what your environment is >>> with any certainty. For all you know, the harmless-looking function is >>> monkey-patching builtins like there's no tomorrow. Speaking broadly, >>> perhaps too broadly, we're incredibly proud of the ability to modify nearly >>> everything at runtime. >>> Fortunately, while we are proud of having that ability, actually *using* it >>> is considered a mortal sin. We're not Ruby developers -- if you actually >>> monkey-patch something, especially built-ins, you can expect to be taken >>> outside and slapped around with a fish if you get caught. >> Here's what I don't get. >> If it's such a bad thing, *why is it allowed*? Why are you proud of the >> ability to do something that you are never socially-allowed to do? > Monkey-patching built-ins would be something along the lines of > import sys > sys.modules['__builtin__'].str = my_super_string > and is what stands you in jeopardy of being fish-slapped. ;) > Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. Oh, I know. I was just noticing that Steven's post is specifically talking about how Python users are proud of having the ability to monkey-patch. If monkey-patching like that is a mortal sin, leads to fish-slapping, and so on.. Why is it possible? Why not just reject such things as invalid code? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Wed Aug 17 13:36:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 10:36:12 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4BFC0C.80603@stoneleaf.us> Seebs wrote: > On 2011-08-17, Steven D'Aprano wrote: >> On Wed, 17 Aug 2011 01:17 pm Seebs wrote: >>> Hmm. See, I've never reached that, in Python or any other language. I >>> figure it creates a new potential for confusion, and that I would rather >>> avoid any ambiguity. I don't *like* ambiguity in code. > >> Ah, well you see the thing is, this is Python. As soon as you call any >> function you don't control, you no longer know what your environment is >> with any certainty. For all you know, the harmless-looking function is >> monkey-patching builtins like there's no tomorrow. Speaking broadly, >> perhaps too broadly, we're incredibly proud of the ability to modify nearly >> everything at runtime. > > Heh. > >> Fortunately, while we are proud of having that ability, actually *using* it >> is considered a mortal sin. We're not Ruby developers -- if you actually >> monkey-patch something, especially built-ins, you can expect to be taken >> outside and slapped around with a fish if you get caught. > > Okay, so. > > Here's what I don't get. > > If it's such a bad thing, *why is it allowed*? Why are you proud of the > ability to do something that you are never socially-allowed to do? Monkey-patching built-ins would be something along the lines of import sys sys.modules['__builtin__'].str = my_super_string and is what stands you in jeopardy of being fish-slapped. ;) Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. ~Ethan~ From ethan at stoneleaf.us Wed Aug 17 13:37:53 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 10:37:53 -0700 Subject: Wait for a keypress before continuing? In-Reply-To: References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> <4e4b3b02$0$30718$c3e8da3$f017e9df@news.astraweb.com> <4e4b566c$0$3959$c3e8da3$b23f186d@news.astraweb.com> <4e4b6c80$0$441$c3e8da3$9b4ff22a@news.astraweb.com> <4e4b7b9f$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4BFC71.8080506@stoneleaf.us> Seebs wrote: > Pathological narcissism is scary. If you ever find yourself going longer > than usual without being wrong, start checking your work more carefully. :) +1 QOTW From usenet-nospam at seebs.net Wed Aug 17 13:38:25 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 17:38:25 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Chris Angelico wrote: > On Wed, Aug 17, 2011 at 5:33 PM, Seebs wrote: >> If it's such a bad thing, *why is it allowed*? ?Why are you proud of the >> ability to do something that you are never socially-allowed to do? > Going back to my original three examples: I may have been unclear about jumping topics; that comment was about monkey-patching, not about shadowing. > I greatly prefer this to the alternative, which is another 133 > reserved words (based on Python 3.2 for Windows). You have a point there. I guess I'm just used to the assumption that the confusion caused by shadowing names outweighs the benefits of using them -- the world is rich with plausible names. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rosuav at gmail.com Wed Aug 17 13:42:26 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 18:42:26 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 5:33 PM, Seebs wrote: > If it's such a bad thing, *why is it allowed*? ?Why are you proud of the > ability to do something that you are never socially-allowed to do? > Going back to my original three examples: > 1) Deliberate shadowing because you want to change the behavior of the > name. Extremely rare. > 2) Shadowing simply by using the name of an unusual builtin (like > 'file') in a context where you never use it. Very common. > 3) Unintentional shadowing where you create a variable, but then > intend to use the builtin. This is the only one that's a problem. All three are allowed, but it's the first one that's considered unusual. The second one is simply that Python doesn't have a million and one reserved words. Yes, you probably don't want to use 'print' as a variable name, but shadowing it with an exact equivalent would be fine (eg to automatically date-stamp or log your output, without changing your code). And as described above, using list/str/id etc is not uncommon. I greatly prefer this to the alternative, which is another 133 reserved words (based on Python 3.2 for Windows). ChrisA From rosuav at gmail.com Wed Aug 17 14:02:23 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 19:02:23 +0100 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 6:38 PM, Seebs wrote: > I may have been unclear about jumping topics; that comment was about > monkey-patching, not about shadowing. > Ah, apologies. Monkey-patching is a way of using the middle of a stack of code without using what's below it. If everything is statically linked, then every function does exactly what it was written to do and no more; if it accepts a file object as an argument, you could give it some other file-like object, but that's all. However, if the function was written to use print() and you don't want it to print to the screen, what do you do? Obviously it's your responsibility to ensure that your replacement is 100% equivalent in the required functionality, but it's a great flexibility to simply change the meaning of "print"; the alternative is to copy and paste the code, make one change (or even no change at all, if your replacement print() is a global), and run that. As Ethan posted while I was typing this, you're allowed to do it, but you just need to have a good reason for it. I like to explain/justify myself in comments when these things crop up in my code. ChrisA From usenet-nospam at seebs.net Wed Aug 17 14:09:30 2011 From: usenet-nospam at seebs.net (Seebs) Date: 17 Aug 2011 18:09:30 GMT Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-17, Ethan Furman wrote: > Part of the fun of Python is experimentation. And how much fun is it to > be told over and over, "No, you can't do that"? Okay, I buy that. Actually, this sort of fits with my experience of how (sane) people do it in Ruby. And I'm really the wrong person to criticize people for monkey-patching: http://www.yoctoproject.org/projects/pseudo (In which I monkeypatch *the entire Unix filesystem API*. On Linux and OS X. For C programs.) I guess maybe my question shouldn't have been "why is it allowed", but "and why is it bad to use it?" It just seemed like "you should never do this, it's horrible" and "we're proud of being able to do this" were not entirely compatible. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Wed Aug 17 14:13:30 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 11:13:30 -0700 Subject: Why no warnings when re-assigning builtin names? In-Reply-To: References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E4C04CA.4050505@stoneleaf.us> Seebs wrote: > On 2011-08-17, Ethan Furman wrote: >> Seebs wrote: >>> On 2011-08-17, Steven D'Aprano wrote: >>>> Ah, well you see the thing is, this is Python. As soon as you call any >>>> function you don't control, you no longer know what your environment is >>>> with any certainty. For all you know, the harmless-looking function is >>>> monkey-patching builtins like there's no tomorrow. Speaking broadly, >>>> perhaps too broadly, we're incredibly proud of the ability to modify nearly >>>> everything at runtime. > >>>> Fortunately, while we are proud of having that ability, actually *using* it >>>> is considered a mortal sin. We're not Ruby developers -- if you actually >>>> monkey-patch something, especially built-ins, you can expect to be taken >>>> outside and slapped around with a fish if you get caught. > >>> Here's what I don't get. > >>> If it's such a bad thing, *why is it allowed*? Why are you proud of the >>> ability to do something that you are never socially-allowed to do? > >> Monkey-patching built-ins would be something along the lines of > >> import sys >> sys.modules['__builtin__'].str = my_super_string > >> and is what stands you in jeopardy of being fish-slapped. ;) > >> Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching. > > Oh, I know. I was just noticing that Steven's post is specifically talking > about how Python users are proud of having the ability to monkey-patch. > > If monkey-patching like that is a mortal sin, leads to fish-slapping, and > so on.. > > Why is it possible? Why not just reject such things as invalid code? Well, the mortal sin part is a bit of an exaggeration -- it's more like you'd better have a really darn good reason to do it. And it is absolutely one of my favorite parts about Python. If I want to inject a custom Path class into builtins so it's readily available, and then change os.listdir to return it instead of normal strings, I can. If my application is truly case-insensitive, I can make my own istr class and monkey-patch builtins so it's what is used. Can this blow-up in my face? Certainly. But I would rather have the option open to me instead of being told "No, I'm sorry, you can't do that because I (developers in question) didn't imagine a good use case for it". Part of the fun of Python is experimentation. And how much fun is it to be told over and over, "No, you can't do that"? As an example of something that could easily have been outlawed, but wasn't, check out http://stackoverflow.com/questions/7068340 ~Ethan~ From thinke365 at gmail.com Wed Aug 17 14:16:14 2011 From: thinke365 at gmail.com (smith jack) Date: Thu, 18 Aug 2011 02:16:14 +0800 Subject: How to build python using visual studio 2005? Message-ID: anybody here have build it correctly? how to make a msi file just as the official site did? is there any detailed tutorial online? From steve+comp.lang.python at pearwood.info Wed Aug 17 14:29:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 04:29:30 +1000 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> Message-ID: <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > The difference is between "Hit to continue" (which we can do in > portable Python) versus "Hit any key to continue" (which we cannot, and > which also leads to the joke about people searching for the 'any' key > ;-). The equivalent contrast for GUIs is "Click OK to continue" versus > "Click anywhere to continue" If having to click a specific area is okay > for GUIs, having to hit a specific key for TUIs should be also. Poor analogy. A better analogy to a GUI would be comparing: What would you like to do? Select an option and then click OK: ( ) Cancel ( ) Print (x) Save [__OK__] versus: What would you like to do? [__Cancel__] [__Print__] [__Save__] Actually, a better analogy would be a GUI that made you do this: What would you like to do? Type the first letter of the option you prefer in the text field, then click the OK button: Options: Cancel | Print | Save My option: [ ............ ] [__OK__] (ASCII art best viewed with a fixed-width font.) Generally speaking, the second UI would be preferred. The raw_input/input UI is well-designed for entering plain text data. It is extremely poor as a command interface. Bringing it back to text interfaces, it would be useful to have a text interface such that commands can be executed using a single key press. You might want to detect and respond to (say) the arrow keys, or ESC, or P rather than P. Curses apps can do it, proof that even under Unix it is desirable. (Imagine how awkward it would be to use a TUI mail client or text editor where the only user input was from something like raw_input.) Unfortunately curses is quite heavyweight for a simple CLI script. I note also that even the Python interactive interpreter under Linux has an extremely limited detect-single-keypress capability: Ctrl-C generates a KeyboardInterrupt without needing to hit Enter, and Ctrl-D exits the interpreter. -- Steven From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Aug 17 15:13:36 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 17 Aug 2011 19:13:36 +0000 (UTC) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: gc wrote: > Maybe this is more visibly convenient with a complex class, like > > x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...) > > where you need three separate objects but don't want to duplicate the > class call (for obvious copy-paste reasons) and where bundling it in a > list comprehension: > > x, y, z = [SuperComplexClass(param1, etc, ...) for _ in range(3)] > > layers gunk on top of something that's already complex. That just seems like an odd use case to me. I rarely find myself wanting to make exactly N copies of the same thing and assign them to explicit names. If I'm not making just one, it's usually because I'm making some sort of list or dict of them that will be accessed by index (not with names like "x", "y", and "z"), in which case a list comprehension is the right way to go. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From ethan at stoneleaf.us Wed Aug 17 15:52:29 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Aug 2011 12:52:29 -0700 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4E4C1BFD.4040500@stoneleaf.us> gc wrote: > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() This isn't going to happen. From all the discussion so far I think your best solution is a simple helper function (not tested): def repeat(count_, object_, *args, **kwargs): result = [] for _ in range(count_): result.append(object_(*args, **kwargs)) return result a, b, c, d, e = repeat(5, dict) These are each new objects, so depending on the function (like the random.rand_int example) the values may not be the same. Oh, and I put the trailing _ on count and object to minimize possible conflicts with keyword arguments. ~Ethan~ From schesis at gmail.com Wed Aug 17 16:07:55 2011 From: schesis at gmail.com (Zero Piraeus) Date: Wed, 17 Aug 2011 16:07:55 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Message-ID: : Off on a tangent ... On 16 August 2011 20:14, gc wrote: > > Let me address one smell from my particular example, which may be the > one you're noticing. If I needed fifty parallel collections I would > not use separate variables; I've coded a ghastly defaultdefaultdict > just for this purpose, which effectively permits what most people > would express as defaultdict(defaultdict(list)) [not possible AFAIK > with the existing defaultdict class]. Dunno if it's better than your ghastly defaultdefaultdict, but this works: >>> from collections import defaultdict >>> ddd = defaultdict(lambda: defaultdict(list)) >>> ddd["foo"]["bar"].append("something") >>> ddd["foo"]["bar"] ['something'] >>> -[]z. From Yingjie.Lin at mssm.edu Wed Aug 17 16:22:48 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Wed, 17 Aug 2011 16:22:48 -0400 Subject: pairwise combination of two lists Message-ID: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Hi Python users, I have two lists: li1 = ['a', 'b'] li2 = ['1', '2'] and I wish to obtain a list like this li3 = ['a1', 'a2', 'b1', 'b2'] Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I am looking for. Thank you. - Yingjie From mwilson at the-wire.com Wed Aug 17 17:15:34 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Aug 2011 17:15:34 -0400 Subject: pairwise combination of two lists References: Message-ID: Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly > what I am looking for. This seems to do it : mwilson at tecumseth:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import itertools >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> map (lambda (x,y):x+y, list (itertools.product (li1, li2))) ['a1', 'a2', 'b1', 'b2'] Mel. From mwilson at the-wire.com Wed Aug 17 17:18:40 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 17 Aug 2011 17:18:40 -0400 Subject: pairwise combination of two lists References: Message-ID: Mel wrote: > Yingjie Lin wrote: >> I have two lists: >> >> li1 = ['a', 'b'] >> li2 = ['1', '2'] >> >> and I wish to obtain a list like this >> >> li3 = ['a1', 'a2', 'b1', 'b2'] [ ... ] > This seems to do it : > > mwilson at tecumseth:~$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import itertools >>>> li1 = ['a', 'b'] >>>> li2 = ['1', '2'] >>>> map (lambda (x,y):x+y, list (itertools.product (li1, li2))) > ['a1', 'a2', 'b1', 'b2'] I have doubts about this in Python3, since tuple unpacking in a argument list isn't done there, and I don't think sum works on strings. Some other function can probably be made to work. Mel. From nad at acm.org Wed Aug 17 17:33:17 2011 From: nad at acm.org (Ned Deily) Date: Wed, 17 Aug 2011 14:33:17 -0700 Subject: pairwise combination of two lists References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: In article <98CC6556-11F3-4850-BD2B-30481B53042D at mssm.edu>, Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and > li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I > am looking for. >>> from itertools import product >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> li3 = list("".join(x) for x in product(li1, li2)) >>> li3 ['a1', 'a2', 'b1', 'b2'] -- Ned Deily, nad at acm.org From kevin.p.dwyer at gmail.com Wed Aug 17 17:33:34 2011 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Wed, 17 Aug 2011 22:33:34 +0100 Subject: pairwise combination of two lists References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly > what I am looking for. > > Thank you. > > > - Yingjie Hello Yingjie, This isn't exactly handy, but... >>> import itertools >>> a = ('a', 'b') >>> b = (1, 2) >>> [x + str(y) for (x, y) in itertools.product(*(a, b))] ['a1', 'a2', 'b1', 'b2'] Cheers, Kev From usenet at solar-empire.de Wed Aug 17 17:43:44 2011 From: usenet at solar-empire.de (Marc Christiansen) Date: Wed, 17 Aug 2011 23:43:44 +0200 Subject: pairwise combination of two lists References: Message-ID: Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. Depending on your needs, we can offer you three solutions: For our customers who want it all at once, but without any unneccessary waste, the list expression: [a + b for a, b in itertools.product(li1, li2)] or if you don't need the whole list at once (especially interesting for our customers with large lists), the generator expression (genexp): (a + b for a, b in itertools.product(li1, li2)) and if you don't like the throwaway genexp and want something more ecofriedly, we can present you a memory efficient, reusable solution, the generator: def combiner(li1, li2): for a, b in itertools.product(li1, li2): yield a + b ;) HTH, Marc From rosuav at gmail.com Wed Aug 17 18:10:38 2011 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Aug 2011 23:10:38 +0100 Subject: Wait for a keypress before continuing? In-Reply-To: <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4c088c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 17, 2011 at 7:29 PM, Steven D'Aprano wrote: > The raw_input/input UI is well-designed for entering plain text data. It is > extremely poor as a command interface. > > ... (Imagine how awkward it would be to use a TUI mail client or > text editor where the only user input was from something like raw_input.) I run a MUD and play several. MUDs by definition have only line-based input (if you use a raw TELNET client, you have character-based input, but most MUD clients send entire lines of text at once); yet it is possible to implement a reasonably-viable file editor. It's not difficult to become quite proficient with line-based editors, especially if you rig some client-side support (which I have done on two of the MUDs). Line-based input is excellent as a command interface, if commands consist of verbs and parameters. It's terrible for playing Tetris on. ChrisA From saruviel at hotmail.com Wed Aug 17 18:17:50 2011 From: saruviel at hotmail.com (saruviel) Date: Wed, 17 Aug 2011 15:17:50 -0700 (PDT) Subject: The Amazing Lucy Potter Message-ID: <306b0589-d2ab-4be4-8eda-9b66fd4827c9@y8g2000prd.googlegroups.com> Joanne Kathleen Rowling (aka J K Rowling) Fanfiction Website http://jkrowlingfanfiction.angelfire.com (See Also http://noahidebooks.angelfire.com for the ?Chronicles of the Children of Destiny?) Featuring the ?Lucy Potter? saga (& In time the rest of the ?Circle of Magic Series? ? see below) Lucy Potter conceived of and created by Daniel Thomas Andrew Daly NOTE: My niece, Georgia Bridges, who features in the Books as a character, actually does have a little scar on her forehead, running down the middle of it. When she was very young she banged her head on the washing machine here at 29 Merriman Crescent, and a little scar remains of the incident (it was actually glued together by the doctor, which is something they do these days). Anyway, I started, as a joke, calling her ?Lucy Potter? one day because of the little ?l? shaped scar ? the l stands for ?Lucy? in that sense. So, one day, in my room or somewhere in the house, inspiration comes over me and I figure I should write about Lucy Potter. So, sitting down at my computer, I start the story, and it has continued since then. I gradually found out about Harry Potter fanfiction, and the story features on both www.fanfiction.net as well as www.hpfanficarchive.com . But the full series of 7 books in the saga are intended to be featured solely on this website. Now, in my other saga about angels known as the ?Chronicles of the Children of Destiny? (http:// noahidebooks.angelfire.com) Lucy Potter has had all relevant Harry Potter trademarked names changed (so that I can hopefully publish the book) and is called ?Lucy Smith? in that saga, and ties right into the plot of the saga. The story ?Lucy Smith? is exactly the same story as the first two Lucy Potter books, with names changed. Lucy Potter ? Book One (Click Me) Lucy Potter and the Vengeance of Lucifer Book Two (Click Me) Lucy Potter and the Golden Sovereigns Book Three (Click Me) Lucy Potter and the Sprite of Chakola Book Four (Click Me) Lucy Potter and the Terran Dragonrider Book Five (Plot ? Chapter Breakdown) (Click Me) Lucy Potter and the Children of Haven (Basic Plot Idea) (Click Me) Lucy Potter and the Dark Lords of Evil (Basic Plot Idea) (Click Me) The Circle of Magic Series (Saga forthcoming over the next few decades) By Daniel Thomas Andrew Daly Harry Potter Harry Potter and Ron Weasely Harry Potter and Hermione Granger Harry Potter and Luna Lovegood Harry Potter and Albus Dumbledore Harry Potter and Severus Snape Harry Potter and Lord Voldemort Lucy Potter (Completed) Lucy Potter and the Vengeance of Lucifer (Completed) Lucy Potter and the Golden Sovereigns (Completed) Lucy Potter and the Sprite of Chakola (Completed) Lucy Potter and the Terran Dragonrider Lucy Potter and the Children of Haven Lucy Potter and the Dark Lords of Evil Luna Lovegood Luna Lovegood and the Splendid Unicorn Luna Lovegood and the Mirror of Forgetfulness Luna Lovegood and the Spell of the Ancients Luna Lovegood and the Curse of the Witch Queen Luna Lovegood and the Scroll of Daranok Luna Lovegood and the Key of Fantasy Jenny Potter Jenny Potter and the Dark Designs of Alexander Darvanius Jenny Potter and Lucifer Malfoy?s Wicked Sense of Humour Jenny Potter and the Most Malevolent Grimlock Jenny Potter and the Challenges of David Rothchild Jenny Potter and the Witticisms of Daniel Daly Jenny Potter and the Wisdom of Shelandragh May Draco Malfoy Draco Malfoy and the Family from Hell Draco Malfoy and his Bad Reputation Draco Malfoy and the Wicked Harlot Draco Malfoy and the Gypsy of Bad Luck Draco Malfoy and the Throne of Evil Draco Malfoy and the Final Redemption SUBMISSIONS I am very happy to take submissions from Other Harry Potter Fanfiction Writers and Place there writings on this website if they like. I am not necessarily seeking any other Harry Potter fanfiction per se, but Will be happy to include writers who would like their Work featured here. You can email me to discuss this at: noahidebooks at hotmail.com PS If you would like to write some ?Lucy Potter? fanfiction based On my own ?Lucy Potter? character, I would love to feature it. The 7 Harry Potter books by J K Rowling are meant to be ?Canon? For the Circle of Magic series also, but the series develops its own canon. In the ?Chronicles of the Children of Destiny? there is an alternative Storyline in which Lucy Potter is known as ?Lucy Smith?. That storyline has an extensive amount of material written in It about angels, featured at: http://noahidebooks.angelfire.com The Circle of Magic Series should be finished within 30 years at the Most (Hopefully) and possibly sooner. From sigmundv at gmail.com Wed Aug 17 18:48:55 2011 From: sigmundv at gmail.com (SigmundV) Date: Wed, 17 Aug 2011 15:48:55 -0700 (PDT) Subject: Ten rules to becoming a Python community member. References: <9att2bF710U1@mid.individual.net> <1ca7c139-cd1f-4c09-830d-881f8881cdf1@bl1g2000vbb.googlegroups.com> <0c41b5fa-55f0-4086-a279-bec1847f9177@w18g2000yqc.googlegroups.com> <4E4AB8FD.9080406@gmail.com> <3vol4752cqdersq7m0q9uqaisc6ngieds9@4ax.com> Message-ID: <57d73724-6120-4ff3-8b34-ba67e2b9de04@q3g2000yqi.googlegroups.com> Bloody hell! This is the most persistent troll I've seen to date. He expected to get a raging army of pythoners after him, but people are just laughing at him. This is a mailing list, not a novel, so colloquialisms are welcome. The language on a mailing list should be informal and not necessarily grammatically correct. Sigmund From luismgz at gmail.com Wed Aug 17 19:27:43 2011 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 17 Aug 2011 16:27:43 -0700 (PDT) Subject: pairwise combination of two lists References: Message-ID: <9ad7849a-021c-48c3-852a-1bbb41ee3179@x11g2000yqx.googlegroups.com> This is the easiest and most pythonic way (IMHO): >>>> l3 = [i+e for i in li1 for e in li2] >>>> l3 ['a1', 'a2', 'b1', 'b2'] Regards, Luis From thaddeushelg at gmail.com Wed Aug 17 19:32:51 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:32:51 -0700 (PDT) Subject: lesbian rape comics | preteen sex blog | russian lolita sex Message-ID: <0ad3549f-cd0a-4c6a-9112-1ce55896c4f4@a7g2000yqb.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Japanese_Widow_Rape.mpeg http://www.dizzyporn.com/2011-Aug/Underage_Uncensored_Xxx.avi http://www.dizzyporn.com/2011-Aug/Black_Patent_High_Heel_Insertion.wmv http://www.dizzyporn.com/2011-Aug/Underage_Lolitas_Fucking.mpeg http://www.dizzyporn.com/2011-Aug/Incest_Creampie_Cum_In_Her_Pussy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Sarah_Shine_Young_And_Anal_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Italian_Gangster_Rape.avi http://www.dizzyporn.com/2011-Aug/Bad_Tushy_Spanking.wmv http://www.dizzyporn.com/2011-Aug/Incest_Porno_Italian_XviD.AC3.avi http://www.erohide.com/Aug_2011/Virgin_Taiwan_Girl.avi http://www.dizzyporn.com/2011-Aug/Lesbian_Sedeuces_Young_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_Ripe_Melons_4_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Home_Video_Young_Teen_Sex_XviD.AC3.avi http://www.erohide.com/Aug_2011/Rachel_Roxx_Rape.mpeg http://www.erohide.com/Aug_2011/Young_Lolita_Bondage_EDTV_640x480.avi http://www.dizzyporn.com/2011-Aug/Girls_Rape_Other_Girl.mpeg bloody nipple discharge nuva ring free squirt fan club code underage drinking in the marine corps lolitas underground, lolitas all american rejects - dirty little secrets lick your own nipples lesbians licking each other out incest stories and pics anal mature squirt free dirty talking sluts dirty thoughts anime russian young jocks chinese schoolgirl rape dirty used panties 4 sale dirty d uss detroit drawings comics toons adult bondage spanking teenage daughters true underage sex stories girls bound in bathing suits bondage drambook little virgins 10 12 preteen web links incest x comics freaky sex bondage and machines bag bondage leather incest stories post ebony preteen top upskirt girls in hardcore bondage teen cunt lick wendy whoppers bondage cum dripping double penetrations underage naked lolita underage rape pictures preteen lolitas sex gang bloods symbols wet vaginal orgasm hair pussy licking man licks cunt to orgasm free mpeg blood clots legs symptoms incest mike and joan sweet sexy petite girls teen boys ass licking naked petite goddess forced to perform oral sex xxx extreme penetration forced mom sex free incest porn stories, free incest story fat lesbian bondage sexy moms and daughters dirty dancing havannah nights mp3 young hot sex hairy vaginas closeup mother son incest stories female adolescent incest fantasies beautiful young teen dirty things found in disney movies free personal male beastiality links japanese schoolgirl thumbs free little lolitas nude monster oral penetration asian japanese schoolgirl sex porn petite women monster cocks hot young asian girls young orgasm videos harry the dirty dog activities how to become underage porn star dont cha dirty bondage how to tie free underage porno dad fucks daughter while mom masturbates underage teen fuck From thaddeushelg at gmail.com Wed Aug 17 19:38:46 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:38:46 -0700 (PDT) Subject: porn young girls | young teen porno | all rape housewives Message-ID: http://www.dizzyporn.com/2011-Aug/Pee_Hole_Insertion.wmv http://www.dizzyporn.com/2011-Aug/Russian_Brother_Rape_Her_Own_Sister.avi http://www.dizzyporn.com/2011-Aug/Hentai_Schoolgirls_Forced_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Mother_Forced_Son_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Incest_Mom_Fuck_Her_Son_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_Amateur_Brunet_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Young_Teen_Masturbate_XviD.AC3.avi http://www.erohide.com/Aug_2011/Tracyd_In_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Brandy_Taylor_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Sarah_Young_Creampie_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Teen_Agi_Puncikova_Defloration_XviD.AC3.avi http://www.erohide.com/Aug_2011/Virgin_Taiwan_Girl.avi http://www.erohide.com/Aug_2011/Lolitas_Fingering_Pussy_800x600.wmv http://www.dizzyporn.com/2011-Aug/Double_Penetration_Big_Dick_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Fivesome_Double_Penetration_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Saline_Breast_Torture_Blu-RayRip.x264.avi amateur housewife bondage 3d incest cartoons free adult bondage stories redhead butthole licking old women licking tits naked dirty pics lolita art top sites 50 women bondage spanking fantasy nude underage galleries toddler incest stories fuck anal pussy virgin slut teen cum russian young sex porn passwords creampie lolita girls licking pussy clips illegal naked preteen pics young girl butt preteen models nudes japanese rope bondage tutorial horny young girls on web cam sarah young mpeg free incest videos father daughter young russian female pussy licking teens in hte shower virgin teen spankings ebony preteen xxx penetration & penis & vagina young women in shower girls masturbating until they squirt dirty mom son incest dirty girls having sex videos incest cum face visa young hot models dad and young daughter sex incest sisters and brothers schoolgirl fucks teacher daddies preteen girl illegal lolita underage hentai bondage story sites bondage in plastic raincoats missouri uniform law enforcement system newsletter hardcore illegal preteen pierced tongue lick dirty whore cum nude russian preteen lolita dual penetration during sex underage illegal little boy pics mans head in vagina wild teen virgins in car bondage tight pants young girls male ball torture hardcore bondage videos nc laws, what is incest deep penetration girl young horny lesbians free buddy icon of blood hound gang schoolgirl lesbian pussy slaves in bondage underage naked little boys, little underage boys naughty bondage hentai bondage in mississippi dirty cunt giving handjobs to old men adult female contortionist/self lick young teen gangbang betty page bondage photo lingerie daughter is fingering her pussy petite low rise scrub pants young girls photography young white female closeup good dirty insults From thaddeushelg at gmail.com Wed Aug 17 19:39:01 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:01 -0700 (PDT) Subject: naked virgin pussy | hot teen virgin | mature young xxx Message-ID: http://www.dizzyporn.com/2011-Aug/Indian_Rape_Sexs.mpeg http://www.erohide.com/Aug_2011/Hotel_Sleep_Rape.avi http://www.dizzyporn.com/2011-Aug/Indian_Real_Virgin_Hymen_Broken.avi http://www.erohide.com/Aug_2011/Virgin_Blood_Defloration.wmv http://www.erohide.com/Aug_2011/Young_Cheyenne_Silver_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Housewife_And_Young_Boy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Young_Pettite_Anal_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Pussy_Extreme_Insertion_PrivateRecords_07.avi http://www.dizzyporn.com/2011-Aug/Mature_Young_Lesbian_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Nutella_Virgin_Off.wmv http://www.dizzyporn.com/2011-Aug/My_Wife_An_Young_XviD.AC3.avi http://www.erohide.com/Aug_2011/Japan_Massage_Fuck_Forced_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Young_Boy_Magazine_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Old_Guy_Young_Gil_XviD.AC3.avi http://www.erohide.com/Aug_2011/Young_And_Busty_Lea_In_Public_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Celebrities_Incest_Sex_Scene_XviD.AC3.avi young fat girls ass dirty office girls incest with mom young asian cunt young latin girl mature petite blondes software penetration testing software dad daughter hardcore girl on girl anal penetration bondage gothic girls lolita lesbian incest lick the head photos of preteens wearing thongs lesbian lick fest lds young women activities can a virgin get pregnant young upskirt pussy thumbnails airforce military schools petite breasted women family sex incest.com father daughter incest fat matures fucking young guys bdsm torture stories outdoor ball gagged bondage big penis penetration mommy spanking son forum preteen model underage asian teen sex fat preteen girls bart simpson incest hairless schoolgirl pussy dirty porno movies queensland underage smoking laws dui underage drinking adult cam lolita chats free underage school girls petite blonde dildo young boy licking mature young teen pool party triple penetration debutante sluts 4 free pics young girls underage hand jobs methods of anal stimulation dad with daughter porn hilary duff gagged bondage preteen girls in bikinis incest daughter stories young boys in bondage young panty pee underage nude guys free young underage sex pictures amanda part 2 and incest cartoons illegal underage prelolitas preteen erotic art multi girl lick free dirty aly clips russian underage msn group bondage lesbian fist japanese virgin pissing extreme penetration slut japanese teen schoolgirls nude video of stacy keibler schoolgirl japan mother son incest do heterosexual men like anal penetration russian preteen lolita underpants insane dildo insertions petite brunette 001 tad lick pussy hardcore bondage free downloads lolita erotica stories cartoon preteen nude incest;; From thaddeushelg at gmail.com Wed Aug 17 19:39:11 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:11 -0700 (PDT) Subject: prison anal rape | virgin anal fucking | little lolitas sex Message-ID: http://www.erohide.com/Aug_2011/Old_And_Young_Creampie_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Margo_Sullivan_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Femdom_Handjob_Torture_Orgasm.wmv http://www.erohide.com/Aug_2011/Naked_Underage_Lolita.avi http://www.dizzyporn.com/2011-Aug/Bondage_Forced_Trailer.wmv http://www.dizzyporn.com/2011-Aug/Simulated_Rape_Porn.avi http://www.dizzyporn.com/2011-Aug/Young_Drunk_Club_Lesbians_XviD.AC3.avi http://www.erohide.com/Aug_2011/Hotel_Asian_Sleep_Rape.mpeg http://www.erohide.com/Aug_2011/Girl_Forced_To_Fuck_A_Dog_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Scarlett_Pain_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Very_Young_Creampie_XviD.AC3.avi http://www.erohide.com/Aug_2011/Erotic_Torture_Chamber_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Indian_Shy_Girl_Forced_DUAL.BDRip.XviD.AC.avi http://www.erohide.com/Aug_2011/Incest_Porno_Italian_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Guy_Rape_Guy.mpeg http://www.erohide.com/Aug_2011/Dominatrix_And_Rape.avi nude lolitas world underage hardcore porn pics mommy loves pussy porn triple penetration sadistic torture bdsm no pop up pics free, virgin ass porn japanese schoolgirl cunts bob dylan forever young young schoolgirl whores free petite softcore porn love hina schoolgirl preteen tiny tits ir creampie virgin mom son incest incest mom young nude preteen tiny bbs lolitas with tiny tits rape pictures blowjobs ball torture movies free lolita bondage pics daughter vaginal penetration pics i squirt alot pre lolita underage teen thumb lick her orgasm movie top kds lolita underground japan schoolgirl nude dirty wet stained panties chinese bondage fetish lolita video,lolita movie,lolita pic free mom son incest art tranny triple penetrations young women in thongs preteen girl cheerleader shaved pussy petite firm tits incest sex brother sister lick sexy teacher party gang rape hot and dirty need slave bangalore lick dirty dancing havana nights soundtrack lyrics ass to lick schoolgirls asian lingerie exploited young teens virgin asian fuck russian underage lolitas young fuck asian erotic force fantasy petite wives teens get fucked upskirt pussy squirt free young nude girls free pussy squirt pics underage girls giving blowjobs clips small lolita sex forced blowjob girls 'free pictures of preteen girls' soundtrack from dirty dancing communities accepting incest date rape video pictures of young models cassie young blowjobs little underage girls fuck big dick porn stories karen incest beastiality lolita sex chat asian forced sex bloodhound gang fox-trot uniform charlie kilo video voyeur upskirts spycams free rape movies free galleries of incest photos free daughter spanking clips young girl nudes size or penis for penetration From thaddeushelg at gmail.com Wed Aug 17 19:39:23 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:23 -0700 (PDT) Subject: gang rape fantasy | teen virgin blowjob | dads rape girls Message-ID: <33c14ee0-1c4b-4c7e-8887-75f0fec83e85@p19g2000yqa.googlegroups.com> http://www.erohide.com/Aug_2011/Vintage_Classics_Bondage_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/Bondage_Forced_Trailer.wmv http://www.dizzyporn.com/2011-Aug/Young_Brazil_Teen_Model.avi http://www.erohide.com/Aug_2011/Rape_Forced_Orgasm_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Hentai_Toon_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Young_Little_Girl_Slut_XviD.AC3.avi http://www.erohide.com/Aug_2011/Real_Incest_Son_Anal_Fuc_K_Mom_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Mature_Mom_Rape_Young_Boy.mpeg http://www.erohide.com/Aug_2011/Korean_Groped_Sex_Rape_In_Hospital.mpeg http://www.dizzyporn.com/2011-Aug/Sarah_Young_Pee_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Asian_Bus_Molestation_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Russian_And_Young_Boy_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Korean_Virgin_Scandal.avi http://www.dizzyporn.com/2011-Aug/Young_Wife_Interracial_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Mom_Forced_To_Blow_Son_DUAL.BDRip.XviD.AC.avi http://www.erohide.com/Aug_2011/Severe_Tit_Torture.wmv lolita underage models hardcore sexual torture tiny titties schoolgirl thumbnail galleries real family incest stories virgin doctors visit pervert spanking 3d incest post bisexual wife sex younger woman tiny teen vagina la petite acadamy paypal bondage join bloodhound gang fire water burn xxx 3d incest cartoon squirting female ejaculating orgasms fat guys in bondage sims 2 gothic lolita downloads guide for incest free incest database young ladies pussy tight petite hot naked young male stars hot young big butt women ass lick mature young asian teen little cuties preteen bbs daddy put your tongue in my pussy dirty sock videos young innocent beauty schoolgirl gallery archives men rape men forced sex pantyhose bondage rape free young pussy russia blow job asian schoolgirl facial free video shy lolita gallery bdsm rape stories squirting female orgasms female ejaculation video doing the dirty thing illegal free porn dicipline and bondage videos incest life stories underage pre-teen girls nude lolita 4 free lolita preteen art nude satin and bondage fantasy simpsons incest sex pre teen incest dad underage daughter nude sex amateur sweet petite teen older women in bondage dad fucks daughter trailer clip she licks cock young girl peeing black lolita 15 sonic the hedgehog bondage porn password forums incest dirty talk adult videos nipples in bondage search engines incest small redhead schoolgirl teen sex fucked sucks incest underage drinking statistics 2005 electric tit torture dirty old women petites salopes chaudes how to squirt your cum free incest research photos very young chicks young candid panties free girl orgasim squirts father mother and daughter orgies free downloads extreme hardcore bondage From thaddeushelg at gmail.com Wed Aug 17 19:39:44 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:39:44 -0700 (PDT) Subject: iraqi torture video | young underage sex | tgp movies squirt Message-ID: <89ed1e37-4acc-4d25-81f9-8826078b951a@1g2000vbu.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Youjizz_Brutal_Rape_Xxx.avi http://www.erohide.com/Aug_2011/Sebastian_Young_Bottoms_XviD.AC3.avi http://www.erohide.com/Aug_2011/Forced_Orgasm_HDRip.XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Milf_And_Young_Boy_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Mom_Fucks_Son_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Severe_Tit_Torture.wmv http://www.erohide.com/Aug_2011/Real_Incest_Clips_Bro_Sis_Bj_XviD.AC3.avi http://www.erohide.com/Aug_2011/Hentai_Toon_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/ass-fucking-underage.mp4 http://www.erohide.com/Aug_2011/Sinnamon_Love_Forced_Orgasm_Blu-RayRip.x264.avi http://www.dizzyporn.com/2011-Aug/The_Spanking_Machine.wmv http://www.erohide.com/Aug_2011/Asian_Teen_Anal_Rape.avi http://www.erohide.com/Aug_2011/Caning_Spanking_German.wmv http://www.erohide.com/Aug_2011/Young_Virgin_Xvideo.avi http://www.dizzyporn.com/2011-Aug/Illegal_Young_Fuck_XviD.AC3.avi http://www.erohide.com/Aug_2011/Shemales_Fuck_Virgin_Girls_Only.wmv young sister nude dirty sexy maids little boys youngest naked pictures incest forum link incest movie trailers daughter fucking dad 3d ebony petite sex daddy daughter incest story toys in ass penetration preteen actress galleries virgin teen defloration free clips bloody sex fetish pussy licking blonde lesbians fuck preteen girls cunt licking movies sexy underage teen schoolgirls preteen sex free teen rape video free creampie licking lesbians lick clits sons and mothers incest stories buying incest videos preteen hidden bed room cams kinesiology toe lick petite blonde babe 001 petite latina masterbating pics and vids gang bang young mature triple penetration taylor rain sea squirt structures young sex models leather jacket short petite hentai schoolgirl galleries young naked footjobs hentai school girls lick pussy mature lesbians and young girls dad daughter xxx dirty british housewives female anal stimulation cum in daughter's panties lick big clit harry the dirty dog double penetration huge tits dirty honey sucking big cock licking petite pussy lolita russian porn free nude pics of fat underage raunchy girls pussy licking gallery pre-teen incest stories free amature porn videos samples petite angles free ebony penetration pics galleries lolita preteen art incest cartoons pre teen dirty jokes in shakespear sites that support incest porn state v. william collins incest double penetration sex clip family sex hardcore incest video soul survivor young jazzy young amateur sandy preteens gone wild teen squirting machines anal lick fest dog licking dick licking cheerleader pussy schoolgirls and oral sex homosex daddy dvd incest taboo samples incest sex fucking forced anal virgin underage nude lolitas From thaddeushelg at gmail.com Wed Aug 17 19:40:00 2011 From: thaddeushelg at gmail.com (thaddeus helga) Date: Wed, 17 Aug 2011 16:40:00 -0700 (PDT) Subject: young girl raped | free incest porno | incest art xxx Message-ID: <12a2ce83-d451-490d-9588-9553e6ea5b03@t5g2000yqj.googlegroups.com> http://www.dizzyporn.com/2011-Aug/Young_And_Busty_Lea_In_Public_XviD.AC3.avi http://www.erohide.com/Aug_2011/Father_Daughter_Incest_XviD.AC3.avi http://www.dizzyporn.com/2011-Aug/Rape_Of_A_Young_Girl.mpeg http://www.erohide.com/Aug_2011/Britney_Skye_And_Virgin.wmv http://www.erohide.com/Aug_2011/Japanese_Groped_Sex_Rape_In_Hospital.mpeg http://www.dizzyporn.com/2011-Aug/Hot_lolita_stripping.mpeg http://www.erohide.com/Aug_2011/Margo_Sullivan_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Cute_Blonde_Young_Hardcore_XviD.AC3.avi http://www.erohide.com/Aug_2011/Bath_Hardcore_Bondage_Blu-RayRip.x264.avi http://www.erohide.com/Aug_2011/Virgin_Amateur_First.wmv http://www.erohide.com/Aug_2011/Sky_Lopez_Double_Penetration_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Double_Anal_Penetration_XviD.DVDRip.avi http://www.erohide.com/Aug_2011/Dad_Forced_Sex_XviD.DVDRip.avi http://www.dizzyporn.com/2011-Aug/Brother_Sister_Homemade_Incest_XviD.AC3.avi http://www.erohide.com/Aug_2011/Yong_Lolita_Sex.avi http://www.dizzyporn.com/2011-Aug/Brandy_Taylor_Bondage_Blu-RayRip.x264.avi young boys tgp forced cum control free lesbians licking pussy tiny young twinks young, sexy, petite amateur little lolita rape mature woman young preteen girl handjob virgin fuck videos dirty preteen porn pics of preteen swimsuit models free petite nudes double penetration teen gang bang 'naked lolitas preteen' moaning tiny teen virgins lick up your cum young shaved cocks dirty porn email flinstones professional bondage photography cum vagina movies petite amie nue petite asians fuck make a dirty martini daughter sucks dads cock tied breasts breast bondage bag bondage escape illegal group sex female bondage sex squirt from behind dad fucking daughterspussy penetration of a virgin preteen feet gallery daughter dad touch sex stories petite bathroom vanity cabinet preteen virtual reality russian defloration video feet torture techniques daughter sucking dad's cock torture techniques stories dirty batman yaoi blood gang symbols sick skinny african boy sex stories incest my little lolita pics tiny pussy virgins bbs preteens in tight panties underage pussies oral sex little lolita videos little russian lolita videos young ebony hoes getting fucked preteen russian modeling angels free site dirty aly sex plus size schoolgirl outfits little girl incest pic male bondage female domination teacher and young student sex cum out of vagina dirty girl cop action free xxx dirty porn gothic lolita dress ebony natasha bondage goth pussy licking french lick girls little sister brother incest free4 incest thumbs underage ukraine lolita nude young blondes bondage stories restrained mature daddy hairy sock lick movies From steve+comp.lang.python at pearwood.info Wed Aug 17 20:36:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Aug 2011 10:36:40 +1000 Subject: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4c5e99$0$29998$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > On 2011-08-17, Steven D'Aprano > wrote: >> Fortunately, while we are proud of having that ability, actually *using* >> it is considered a mortal sin. We're not Ruby developers -- if you >> actually monkey-patch something, especially built-ins, you can expect to >> be taken outside and slapped around with a fish if you get caught. > > Okay, so. > > Here's what I don't get. > > If it's such a bad thing, *why is it allowed*? Why are you proud of the > ability to do something that you are never socially-allowed to do? Why does any language allow monkey-patching? Because: (1) it is a consequence of a clean language design that doesn't special case things unless absolutely necessary -- monkey-patching wasn't added to the language, it just emerged given the basic language design; (2) consequently it isn't some special technique, it is just a special name given to ordinary, humdrum, everyday things like name-binding within a namespace; (3) and yet it is a powerful and useful ability that lets you extend both the language and libraries (yours or third party) while still writing very clean code; (4) it's also pretty cool that you can do these things; and most importantly (5) all of the above. Even if we shouldn't (ab)use it in production, it is still greatly useful for quick and dirty scripts, testing, experimentation and debugging. And sometimes monkey-patches end up in production. For example, the standard library site.py file adds help() and quit() commands to builtins at startup. Or you might grab an instance of some third-party class, and dynamically adding a method or an attribute to it. Why bother sub-classing it? There's a scene in James Clavell's "Shogun" which is relevant. Toranaga, the Japanese warlord, discovers that the Englishman John Blackthorne has betrayed his rightful ruler. Blackthorne protests that there are mitigating circumstances. Toranaga says that there can never be any mitigating circumstances for disloyalty to one's liege-lord. Blackthorne replies that there is one: if you win. The same applies for monkey-patching and other dangerous techniques. There can be no excuse for doing something like that in production... unless it is better than the alternatives. [...] > It sounds to me like Python is very proud of having a feature which no > one would ever use. ... Why? Don't get me wrong, there are plenty of people who would give up Python's extreme dynamicism is a heartbeat, if it were up to them. It does play havoc with the ability to optimise Python code, and is one of the reasons why CPython isn't as fast as (say) Lua. But the PyPy people are well on the way to blunting that criticism, with a fast, effective JIT optimising compiler that will be fast in the common case and no worse off in the rare times that built-in functions have been shadowed or modified. (PyPy is already about twice as fast as CPython, and in a few carefully crafted examples faster than C code.) -- Steven From gherron at islandtraining.com Wed Aug 17 21:26:18 2011 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 17 Aug 2011 18:26:18 -0700 Subject: pairwise combination of two lists In-Reply-To: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: <4E4C6A3A.9000302@islandtraining.com> On 08/17/2011 01:22 PM, Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], not exactly what I am looking for. > > Thank you. > > > - Yingjie >>> li1 = ['a', 'b'] >>> li2 = ['1', '2'] >>> print [a+b for a in li1 for b in li2] ['a1', 'a2', 'b1', 'b2'] Gary Herron From moravec at stolaf.edu Wed Aug 17 23:08:23 2011 From: moravec at stolaf.edu (Emily Anne Moravec) Date: Wed, 17 Aug 2011 20:08:23 -0700 (PDT) Subject: lists and for loops Message-ID: I want to add 5 to each element of a list by using a for loop. Why doesn't this work? numbers = [1, 2, 3, 4, 5] for n in numbers: n = n + 5 print numbers From wuwei23 at gmail.com Wed Aug 17 23:08:39 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:08:39 -0700 (PDT) Subject: Failed to create virtual environment when using --relocatable option, what's wrong? References: Message-ID: On Aug 17, 12:23?am, smith jack wrote: > The environment doesn't have a file f:\PythonEnv\djangoEnv2\Scripts\activate_thi > s.py -- please re-run virtualenv on this environment to update it Although the docs aren't very clear, --relocatable should be run on _existing_ virtualenvs. Don't think of it as an option for creating an environment, but rather one for preparing an existing environment for moving. More importantly, it _must_ be re-run in order to remain relocatable after any modules are installed. But most important of all, from the documentation: "Also this does not currently work on Windows." From wuwei23 at gmail.com Wed Aug 17 23:14:20 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:14:20 -0700 (PDT) Subject: How to use python environment created using virtualenv? References: Message-ID: <18642775-5c79-407f-8d42-4e74fd29801f@t30g2000prm.googlegroups.com> On Aug 16, 3:15?pm, smith jack wrote: > I have created a python environment using virtualenv, but when i want > to import such environment to PyDev, error just appears, > it tells there should be a Libs dir, but there is no Libs DIr in the > virtual envronment created using virtualenv, what should i do if > i want to use this virtual environment? It would help if you showed us _exactly_ what commands you're using for creating & activing your virtualenv, as well as how you're trying to use it in PyDev. Basically, you should be able to do this: X:\>virtualenv foo New python executable in foo\Scripts\python.exe Installing setuptools................done. Installing pip...................done. X:\>cd foo X:\foo>Scripts\activate.bat (foo) X:\foo> If this doesn't work for you, please paste exactly what you tried and the results you got. From wuwei23 at gmail.com Wed Aug 17 23:23:17 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Aug 2011 20:23:17 -0700 (PDT) Subject: lists and for loops References: Message-ID: On Aug 18, 1:08?pm, Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > ? ? ?n = n + 5 > print numbers As the for loop steps through numbers, it assigns each integer value to the label n. What n holds is a number, _not_ a reference to the number in the list. So when you reassign n to hold n+5, you're pointing n at a new number, not modifying the original number being referred to. So what you need is a reference to the position of the number in the list, so you can reassign the value that's held there. The common pattern is to use enumerate, which lets you step through a list giving you both an reference (index) & a value: numbers = [1, 2, 3, 4, 5] for i, n in enumerate(numbers): numbers[i] = n + 5 Here you're reassigning each list element to hold its old value plus 5. Hope this helps. From jacktradespublic at gmail.com Wed Aug 17 23:33:53 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Wed, 17 Aug 2011 22:33:53 -0500 Subject: lists and for loops In-Reply-To: References: Message-ID: > > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers > > The n variable in the for loop refers to each value in the list, not the reference to the slot that value is stored in. To update the numbers list you would want something like this: numbers = [1, 2, 3, 4, 5] for n in range(len(numbers)): numbers[n] += 5 print numbers Alternatively if you didn't need to update the numbers list you could make a new list like this: [n+5 for n in numbers] -- Jack Trades Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Wed Aug 17 23:52:10 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 17 Aug 2011 20:52:10 -0700 (PDT) Subject: CGI: Assign FieldStorage values to variables References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Message-ID: <220b4dbe-cce9-4742-9b1f-441ddf9c05df@a13g2000yqd.googlegroups.com> On Aug 17, 3:25?am, Chris Angelico wrote: > You do NOT > want end users having the power to set variables. Thanks for the warning, I can see I will need to quarantine the form input. And update() is out of the question. -- Gnarlie http://Gnarlodious.com/ From chris at simplistix.co.uk Thu Aug 18 02:37:14 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 17 Aug 2011 23:37:14 -0700 Subject: MailingLogger 3.4.0 Released! Message-ID: <4E4CB31A.5090803@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with a configurable headers for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested This release has no functional changes but finally ships with a full new set of Sphinx docs: http://packages.python.org/mailinglogger/ For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From no.email at nospam.invalid Thu Aug 18 03:18:49 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Aug 2011 00:18:49 -0700 Subject: pairwise combination of two lists References: Message-ID: <7x1uwjdw6e.fsf@ruckus.brouhaha.com> Yingjie Lin writes: > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > li3 = ['a1', 'a2', 'b1', 'b2'] from itertools import * li3 = list(chain.from_iterable(izip(li1,li2))) From alain at dpt-info.u-strasbg.fr Thu Aug 18 03:30:43 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 09:30:43 +0200 Subject: pairwise combination of two lists References: Message-ID: <87r54j5g7w.fsf@dpt-info.u-strasbg.fr> Yingjie Lin writes: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. It's not difficult to write your own: def product(l1,l2): for x1 in l1: for x2 in l2: yield x1+x2 use it like: for p in product(l1,l2) ... The call to product() produces a generator, the cross product is never built in full, it should work on long lists. -- Alain. From peter.mosley at talk21.com Thu Aug 18 04:24:30 2011 From: peter.mosley at talk21.com (peter) Date: Thu, 18 Aug 2011 01:24:30 -0700 (PDT) Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> Message-ID: <4b383bcd-c58c-4e67-895a-d70fdf82f9c0@n35g2000yqf.googlegroups.com> On Aug 17, 3:16?pm, Hans Mulder wrote: > On 17/08/11 10:03:00, peter wrote: > > > Is there an equivalent to msvcrt for Linux users? ?I haven't found > > one, and have resorted to some very clumsy code which turns off > > keyboard excho then reads stdin. Seems such an obvious thing to want > > to do I am surprised there is not a standard library module for it. Or > > have I missed someting (wouldn't be the first time!) > > The quick and dirty way is to invoke stty(1) using os.system: > > import os > > def getpassword(prompt="Password: "): > ? ? ?try: > ? ? ? ? ?os.system("stty -echo") > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?os.system("stty echo") > ? ? ?return passwd > > Strictly speaking, os.system is deprecated and you should use > the equivalent invocation of subprocess.call: > > import subprocess > > def getpassword(prompt="Password: "): > ? ? ?try: > ? ? ? ? ?subprocess.call(["stty", "-echo"]) > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?subprocess.call(["stty", "echo"]) > ? ? ?return passwd > > If you don't want to use an external process, use termios: > > import termios, sys > > def getpassword(prompt="Password: "): > ? ? ?fd = sys.stdin.fileno() > ? ? ?old = termios.tcgetattr(fd) > ? ? ?new = termios.tcgetattr(fd) > ? ? ?new[3] = new[3] & ~termios.ECHO ? ? ? ? ?# lflags > ? ? ?try: > ? ? ? ? ?termios.tcsetattr(fd, termios.TCSADRAIN, new) > ? ? ? ? ?passwd = raw_input(prompt) > ? ? ?finally: > ? ? ? ? ?termios.tcsetattr(fd, termios.TCSADRAIN, old) > ? ? ?return passwd > > These functions work on any Posix system (including Mac OSX), > but not on Windows. > > Hope this helps, > > -- HansM This is very similar to my solution, which was to use stty turn off keyboard echo, then repeatedly read sys.stdin.read(1) until a unique keystroke had been defined. For example, the 'Insert' key seems to return a sequence of four codes, namely 27, 91, 50, 126. It works but has two disadvantages which I have managed to live with:- 1. As character 27 is used to signal the start of a 'special' key sequence, it cannot detect a single press of the Esc key. The workaround is to detect a double press instead. 2. Some keys seem to return different sets of codes depending on the circumstances. For example, F1 returns 27,91,91,65 from the command line, and 27,79,80 from a GUI window. I suspect there may be variations between flavours of Linux too. The solution is to detect all possibilities - so far I haven't found any overlaps. Not pretty, but as I said it works. I know now not to spend time looking further. Whilst there may be a historical reason for the current situation, it would be a great convenience for amateur coders like mayself if the gurus could devise a platform independent version of mscvrt. If anyone is interested in the code I can post it, but it's quite long as it comprises multiple if statements to cover each combination. Peter From funthyme at gmail.com Thu Aug 18 05:26:35 2011 From: funthyme at gmail.com (John Pinner) Date: Thu, 18 Aug 2011 02:26:35 -0700 (PDT) Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: <4d9df596-beaa-496c-ad04-0df8278c2599@q1g2000vbj.googlegroups.com> On Aug 3, 2:45?am, gc wrote: > Hi everyone! Longtime lurker, hardly an expert, but I've been using > Python for various projects since 2007 and love it. > > I'm looking for either (A) suggestions on how to do a very common > operation elegantly and Pythonically, or (B) input on whether my > proposal is PEP-able, assuming there's no answer to A. (The proposal > is sort of like the inverse of PEP 3132; I don't think it has been > proposed before, sorry if I missed it.) > > Anyway, I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. > > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() > > where * in this context means something like "assign separately to > all." I'm not sure that * would the best sugar for this, but the > normal meaning of * doesn't seem as if it would ever be valid in this > case, and it somehow feels right (to me, anyway). > > Statements fitting the form above would get expanded during parsing to > a sequence of separate assignments (a = dict(); b = dict(); c = dict() > and so forth.) That's all there is to it. Compared to the patterns > below, it's svelte, less copy-paste-y (so it removes an opportunity > for inconsistency, where I remember to change a-d to defaultdict(list) > but forget with e), and it doesn't require me to keep count of the > number of variables I'm initializing. > > This would update section 6.2 of the language reference and require a > small grammar expansion. > > But: Is there already a good way to do this that I just don't know? > Below, I compare four obvious patterns, three of which are correct but > annoying and one of which is incorrect in a way which used to surprise > me when I was starting out. > > # Option 1 (separate lines) > # Verbose and annoying, particularly when the varnames are long and of > irregular length > > a = dict() > b = dict() > c = dict() > d = dict() > e = dict() > > # Option 2 (one line) > # More concise but still pretty annoying, and hard to read (alternates > variables and assignments) > > a = dict(); b = dict(); c = dict(); d = dict(); e = dict() > > # Option 3 (multiple target list: this seems the most Pythonic, and is > normally what I use) > # Concise, separates variables from assignments, but somewhat > annoying; have to change individually and track numbers on both sides. > > a,b,c,d,e = dict(),dict(),dict(),dict(),dict() > > # Option 4 (iterable multiplication) > # Looks better, and if the dict() should be something else, you only > have to change it once, but the extra brackets are ugly and you still > have to keep count of the targets... > > a,b,c,d,e = [dict()] * 5 > > # and it will bite you... > > >>> a[1] = 1 > >>> b > {1: 1} > >>> id(a) == id(b) > > True > > # Gotcha! > > # Other forms of 4 also have this behavior: > > a,b,c,d,e = ({},) * 5>>> a[1] = 1 > >>> b > > {1: 1} > > Alternatively, is there a version of iterable multiplication that > creates new objects rather than just copying the reference? That would > solve part of the problem, though it would still look clunky and you'd > still have to keep count. > > Any thoughts? Thanks! I hesitate to put this forward, as it smells and is probably considered bad practice, but heh! for char in 'abcdefg' : globals()[ char ] = dict() does what you wanted. Best wishes, John -- From ramapraba2653 at gmail.com Thu Aug 18 07:42:39 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Thu, 18 Aug 2011 04:42:39 -0700 (PDT) Subject: WORLD BEST SEXY PICS Message-ID: v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html KAJAL AGARWAL HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html From eudes.elie at gmail.com Thu Aug 18 08:02:44 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Thu, 18 Aug 2011 05:02:44 -0700 (PDT) Subject: decorator issue with modules dbus & gobject Message-ID: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Hi, Here is a sample code that reproduces the issue : [code] import logging import unittest import signal import gobject import dbus from functools import wraps from dbus.mainloop.glib import DBusGMainLoop class TimeoutException(Exception): pass def timeout(timeout_time=1800): """ decorator function catching the argument """ def timeout_function(func): """ decorator function """ @wraps(func) def _timeout_function(self): """ create a signal handler set the timeout with the argument given while calling the decorator @timeout call the function catch a timeout exception if necessary """ def timeout_handler(signum, frame): print 'Timeout (%s sec) reached' % str(timeout_time) raise TimeoutException() old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(timeout_time) # triger alarm in timeout_time seconds try: retval = func(self) finally: signal.signal(signal.SIGALRM, old_handler) signal.alarm(0) return retval return _timeout_function return timeout_function class Test_loopRun_And_Timeout(unittest.TestCase): def __init__(self,*args,**kwargs): super(Test_loopRun_And_Timeout, self).__init__(*args,**kwargs) dbus_loop = DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus(private=True,mainloop=dbus_loop) self.loop = gobject.MainLoop() logging.basicConfig() self.__logger = logging.getLogger("Tests.%s" % self.__class__.__name__) self.__logger.setLevel(logging.DEBUG) def setUp(self): ''' in this part, mediarouter can not be created Setup are all launch in // So if 50 tests are run in this class, 50 mediarouters are created ''' pass def tearDown(self): ''' ''' @timeout(5) def test_001(self): ''' ''' self.__logger.info('[CHECKPOINT] test_001') try: self.__logger.info('entering a waiting loop') self.loop.run() self.__logger.info('dummy log, should not appear') self.fail() except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') except : self.__logger.exception('Unexpected error') self.fail() @timeout(5) def test_002(self): ''' ''' def loop_quit(loop): loop.quit() return False self.__logger.info('[CHECKPOINT] test_002') try: self.__logger.info('entering a waiting loop') gobject.timeout_add(1000, loop_quit, self.loop) self.loop.run() self.__logger.info('exiting the loop') except KeyboardInterrupt: self.__logger.exception('Catching a Ctrl+c event (user or timeout)') self.fail() except : self.__logger.exception('Unexpected error') self.fail() [/code] If I start a unittest campaign like this : [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_002')) suite.addTest(Test_loopRun_And_Timeout('test_001')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] the result give me 2 tests OK Now If I launch this [code] if __name__ == "__main__": #Add the test you want to run suite = unittest.TestSuite() #To choose a list of tests, comment those you don't want to run suite.addTest(Test_loopRun_And_Timeout('test_001')) suite.addTest(Test_loopRun_And_Timeout('test_002')) unittest.TextTestRunner(verbosity=0).run(suite) print 'done' [/code] 1 OK (test_001) 1 Fail (test_002 goes on timeout) And if I am using more than 3 Testcases, the code is going to run in infinite loop (Ctrl+C or timeout decorator does not work, only a kill works) Is there an issue using the 'timeout' decorator with the loop.run() ? From prahamark at gmail.com Thu Aug 18 08:22:45 2011 From: prahamark at gmail.com (Mark Niemczyk) Date: Thu, 18 Aug 2011 05:22:45 -0700 (PDT) Subject: lists and for loops In-Reply-To: References: Message-ID: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> Or, using list comprehension. >>> numbers = [1, 2, 3, 4, 5] >>> numbers = [n + 5 for n in numbers] >>> numbers [6, 7, 8, 9, 10] From python.list at tim.thechases.com Thu Aug 18 08:45:10 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Aug 2011 07:45:10 -0500 Subject: lists and for loops In-Reply-To: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> References: <8307c651-e4c1-4d28-9f2a-bf0513f21eb8@glegroupsg2000goo.googlegroups.com> Message-ID: <4E4D0956.8090607@tim.thechases.com> On 08/18/2011 07:22 AM, Mark Niemczyk wrote: > Or, using list comprehension. > >>>> numbers = [1, 2, 3, 4, 5] >>>> numbers = [n + 5 for n in numbers] >>>> numbers > [6, 7, 8, 9, 10] Or, if you want it in-place: numbers[:] = [n+5 for n in numbers] which makes a difference if you have another reference to numbers: >>> numbers = [1,2,3,4,5] >>> digits = numbers >>> numbers = [n+5 for n in numbers] >>> numbers, digits ([6, 7, 8, 9, 10], [1, 2, 3, 4, 5]) >>> numbers = [1,2,3,4,5] >>> digits = numbers >>> numbers[:] = [n+5 for n in numbers] >>> numbers, digits ([6, 7, 8, 9, 10], [6, 7, 8, 9, 10]) -tkc From jasons at adventureaquarium.com Thu Aug 18 08:58:42 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 08:58:42 -0400 Subject: List spam Message-ID: I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? Jason ..?><((((?> From roy at panix.com Thu Aug 18 09:13:14 2011 From: roy at panix.com (Roy Smith) Date: Thu, 18 Aug 2011 09:13:14 -0400 Subject: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> Message-ID: In article <16ea4848-db0c-489a-968c-ca40700f5806 at m5g2000prh.googlegroups.com>, gc wrote: > I frequently need to initialize several variables to the same > value, as I'm sure many do. Sometimes the value is a constant, often > zero; sometimes it's more particular, such as defaultdict(list). I use > dict() below. Keep in mind that when you do: a = dict() b = dict() you are NOT initializing a and b to the same value. You are initializing each of them to a different empty dictionary, which is very different from a = b = dict() I suspect you knew that, but it's worth mentioning. > # Option 1 (separate lines) > # Verbose and annoying, particularly when the varnames are long and of > irregular length > > a = dict() > b = dict() > c = dict() > d = dict() > e = dict() This seems the best to me. Simple, straight-forward, easy to understand. What could be bad? It may not be elegant, but if I could have a nickel for every hour I've wasted trying to understand elegant code, I'd be a rich man. I can understand the above code in an instant, even at 2 AM juiced up on sugar and caffeine. From mail at timgolden.me.uk Thu Aug 18 09:30:37 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Aug 2011 14:30:37 +0100 Subject: List spam In-Reply-To: References: Message-ID: <4E4D13FD.5050103@timgolden.me.uk> On 18/08/2011 13:58, Jason Staudenmayer wrote: > I really like this list as part of my learning tools but the amount > of spam that I've been getting from it is CRAZY. Doesn't anything get > scanned before it sent to the list? I haven't seen any significant quantity of spam on the list for ages. (The occasional one does get through although I can't remember the last). I always access it as a mailing list, and I seem to recall that the newsgroup feed isn't filtered the same way as the mailing list is. TJG From philip at semanchuk.com Thu Aug 18 09:39:05 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Aug 2011 09:39:05 -0400 Subject: List spam In-Reply-To: References: Message-ID: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? This has been discussed on the list a number of times before, so I'll refer you to the archives for details. Basically, the mailing list receives postings from Google Groups and vice versa. Most of the spam comes from Google Groups. If you add a mail filter that deletes anything with the "Organization" header set to "http://groups.google.com", you won't see much spam anymore. In my experience, you'll also miss a number of legitimate postings. HTH Philip From jasons at adventureaquarium.com Thu Aug 18 09:39:35 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 09:39:35 -0400 Subject: List spam In-Reply-To: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: > On 18/08/2011 13:58, Jason Staudenmayer wrote: > > I really like this list as part of my learning tools but the amount > > of spam that I've been getting from it is CRAZY. Doesn't > anything get > > scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. > (The occasional one does get through although I can't > remember the last). > > I always access it as a mailing list, and I seem to recall that > the newsgroup feed isn't filtered the same way as the mailing list is. I've been getting more and more. Upon checking the header info the last hop is from the list server. Here's part of the header: Received: from (HELO mail.python.org) (82.94.164.166) by mail2.adventureaquarium.com with SMTP; 17 Aug 2011 23:53:17 -0000 Received: from albatross.python.org (localhost [127.0.0.1]) by mail.python.org (Postfix) with ESMTP id 3RfS705P3czN9Y for ; Thu, 18 Aug 2011 01:53:16 +0200 (CEST) I can deal with normal spam but this stuff I've gotten is all about rape. Jason Adventure Aquarium is America's Most Touchable Aquarium! Featuring the ALL NEW Stingray Beach Club Where you can touch and hand feed the gentle stingrays To buy and print your tickets at home visit www.AdventureAquarium.com ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?><((((?>..?`?.><((((?> A Herschend Family Entertainment Company From jasons at adventureaquarium.com Thu Aug 18 09:41:52 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 09:41:52 -0400 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > > > I really like this list as part of my learning tools but > the amount of spam that I've been getting from it is CRAZY. > Doesn't anything get scanned before it sent to the list? > > This has been discussed on the list a number of times before, > so I'll refer you to the archives for details. > > Basically, the mailing list receives postings from Google > Groups and vice versa. Most of the spam comes from Google > Groups. If you add a mail filter that deletes anything with > the "Organization" header set to "http://groups.google.com", > you won't see much spam anymore. In my experience, you'll > also miss a number of legitimate postings. > Ahhh, that would explain all the google stuff in the headers. Thanks for the heads-up I'll look at changing my spamassassin scoring for those. Jason Adventure Aquarium is America's Most Touchable Aquarium! Featuring the ALL NEW Stingray Beach Club Where you can touch and hand feed the gentle stingrays To buy and print your tickets at home visit www.AdventureAquarium.com ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> ..?><((((?>..?`?.><((((?> A Herschend Family Entertainment Company From aspineux at gmail.com Thu Aug 18 09:44:38 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 06:44:38 -0700 (PDT) Subject: extend class: include factories functions inside constructor Message-ID: Hi I have a closed class and 2 factories function class Data: def __init__(self): self.payload=None def data_from_string(payload): data=Data() data.payload=payload return data def data_from_file(f): data=Data() data.payload=f.read() return data And I want to extend the class, by first including the factories function inside the constructor, second add some method to the class. class MyData(Data): def __init__(self, arg): # I know this coke is not working, this is to show you # what I expect if isinstance(arg, file): self=data_from_file(arg) else: self=data_from_string(arg) return self def len(self): return len(self.payload) And how I want to use it >>> m=MyData('hello') >>> print m.len() 5 any idea ? Alain From gheskett at wdtv.com Thu Aug 18 09:55:59 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 09:55:59 -0400 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <201108180955.59577.gheskett@wdtv.com> On Thursday, August 18, 2011 09:51:04 AM Philip Semanchuk did opine: > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > > I really like this list as part of my learning tools but the amount of > > spam that I've been getting from it is CRAZY. Doesn't anything get > > scanned before it sent to the list? > > This has been discussed on the list a number of times before, so I'll > refer you to the archives for details. > > Basically, the mailing list receives postings from Google Groups and > vice versa. Most of the spam comes from Google Groups. If you add a > mail filter that deletes anything with the "Organization" header set to > "http://groups.google.com", you won't see much spam anymore. In my > experience, you'll also miss a number of legitimate postings. > > HTH > Philip I am about to do just that, block groups.google.com. AFAIAC, if someone wants to contribute to this mailing list, they can damned well join THIS list if they want their posts to be read by the subscribers to this list. Google is not too big to block as I just told them while fwding that last bit of boilerplate to them at groups-abuse AT google dot com. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Such a fine first dream! But they laughed at me; they said I had made it up. From ghodmode at ghodmode.com Thu Aug 18 10:11:48 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Thu, 18 Aug 2011 22:11:48 +0800 Subject: List spam In-Reply-To: References: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: On Thu, Aug 18, 2011 at 9:30 PM, Tim Golden wrote: > On 18/08/2011 13:58, Jason Staudenmayer wrote: >> >> I really like this list as part of my learning tools but the amount >> of spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. (The > occasional one does get through although I can't remember the last). Maybe your email client is filtering it out for you. ?This list gets A LOT of spam. ?I'm lurking on over 25 different mailing lists and most of them don't seem to get any spam. ?On the others, it's only occasional and the list admins are quick to pounce on it. ?Here, it's like the floodgates are wide open. > I always access it as a mailing list, and I seem to recall that > the newsgroup feed isn't filtered the same way as the mailing list is. The last time I brought up the topic, I offered to do the work of filtering and banning spammers. ?The consensus seemed to be that it wasn't possible because the newsgroup IS filtered the same way as the mailing list. > TJG -- Ghodmode http://www.ghodmode.com/blog From chris at gonnerman.org Thu Aug 18 10:30:54 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Thu, 18 Aug 2011 09:30:54 -0500 Subject: [Python] Re: Windows service in production? In-Reply-To: <4E4BB152.5020904@timgolden.me.uk> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> <4E4BB152.5020904@timgolden.me.uk> Message-ID: <4E4D221E.6000302@gonnerman.org> Chiming in late here, but I've been running a very simple Python service for some time now on a number of computers. It's my Raw Print Server, available at http://newcenturycomputers.net/projects/rawprintserver.html, and I have instructions on the page for installing the Windows service version. It's really quite simple to do in plain Python; the only reason to use py2exe is if you don't want to install a full Python interpreter on the computer. But since I generally do anyway, it doesn't matter to me. -- Chris. From rantingrick at gmail.com Thu Aug 18 10:34:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 18 Aug 2011 07:34:24 -0700 (PDT) Subject: List spam References: Message-ID: <71d3407f-e851-414e-8934-28326d138dfe@o9g2000vbo.googlegroups.com> On Aug 18, 8:39?am, "Jason Staudenmayer" wrote: > > [snip irony] > > Adventure Aquarium is America's Most Touchable Aquarium! > Featuring the ALL NEW Stingray Beach Club > Where you can touch and hand feed the gentle stingrays > > To buy and print your tickets at home visit ?www.AdventureAquarium.com > ? ? ? ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ..?><((((?>..?`?.><((((?> > > A Herschend Family Entertainment Company Don't you find it a bit ironic that you are complaining about spam but yet you are spamming this group with your link to buy tickets to a stingray petting zoo (which is in fact an oxymoron?) under the guise of spam bashing? Tip of the day: Create a website! PS: I do however find the recent "rape" spam atrocious! From ghodmode at ghodmode.com Thu Aug 18 10:37:37 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Thu, 18 Aug 2011 22:37:37 +0800 Subject: List spam In-Reply-To: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk wrote: > > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > >> I really like this list as part of my learning tools but the amount of spam that I've been getting from it is CRAZY. Doesn't anything get scanned before it sent to the list? > > This has been discussed on the list a number of times before, so I'll refer you to the archives for details. > > Basically, the mailing list receives postings from Google Groups and vice versa. Most of the spam comes from Google Groups. If you add a mail filter that deletes anything with the "Organization" header set to "http://groups.google.com", you won't see much spam anymore. In my experience, you'll also miss a number of legitimate postings. You are absolutely right, it has been brought up before. But I'm glad it's been brought up again. It's such a problem that it degrades the usefulness of the list and the community. Most of the mailing lists I'm on are managed using Google Groups and many of them are on mailman, like this list. I don't see spam on them, so I don't know what's going on here. It's not really filtering at all. Most lists only allow members to post and the admins are quick to boot offenders. For the most part, I'm just a lurker, so my suggestion shouldn't carry as much weight, but here it is anyway... Make an effort to curb the spam even if it means killing the newsgroup availability. Choose mailman or Google Groups, or another single solution. Make it members only, but allow anyone to register with an automated confirmation email and a CAPTCHA. Appoint a list admin who has a few minutes each day to scan subjects of emails for spammers and remove them from the members list. ... problem solved. Yes. I'm saying we should abandon those who only follow the list via newsgroups. Yes. I'm willing to do the work, but I'm not the right choice. > HTH > Philip -- Ghodmode http://www.ghodmode.com/blog From __peter__ at web.de Thu Aug 18 10:45:34 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Aug 2011 16:45:34 +0200 Subject: extend class: include factories functions inside constructor References: Message-ID: aspineux wrote: > Hi > I have a closed class and 2 factories function > > class Data: > def __init__(self): > self.payload=None > > def data_from_string(payload): > data=Data() > data.payload=payload > return data > > def data_from_file(f): > data=Data() > data.payload=f.read() > return data > > And I want to extend the class, by first including the factories > function inside the constructor, > second add some method to the class. > > class MyData(Data): > > def __init__(self, arg): > # I know this coke is not working, this is to show you > # what I expect > if isinstance(arg, file): > self=data_from_file(arg) > else: > self=data_from_string(arg) > return self > > def len(self): > return len(self.payload) > > And how I want to use it > >>>> m=MyData('hello') >>>> print m.len() > 5 > > any idea ? Assuming that Data is an oldstyle class you can either copy the Data instance's state class MyData(Data): def __init__(self, arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) self.__dict__.update(obj.__dict__) def __len__(self): return len(self.payload) or use another factory function and manually set the __class__: class MyData(Data): def __len__(self): return len(self.payload) def make_mydata(arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) obj.__class__ = MyData return obj If Data were a newstyle class you could move the hand-made polymorphism into the __new__() method: class MyData(Data): def __new__(class_, arg): if hasattr(arg, "read"): factory = data_from_file else: factory = data_from_string obj = factory(arg) obj.__class__ = class_ return obj def __init__(self, arg): pass def __len__(self): return len(self.payload) if __name__ == "__main__": m = MyData("hello") print len(m) Nothing of the above strikes me as pretty. Perhaps we could come up with a neater solution if you tell us more about your use-case... From alain at dpt-info.u-strasbg.fr Thu Aug 18 10:48:58 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 16:48:58 +0200 Subject: List spam References: Message-ID: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> "Jason Staudenmayer" writes: > I really like this list as part of my learning tools but the amount of > spam that I've been getting from it is CRAZY. Doesn't anything get > scanned before it sent to the list? I'm using nntp to read this newsgroup (through an academic server). No spam at all. -- Alain. From jenn.duerr at gmail.com Thu Aug 18 10:57:52 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 07:57:52 -0700 (PDT) Subject: How to convert a list of strings into a list of variables Message-ID: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> How would you convert a list of strings into a list of variables using the same name of the strings? So, ["red", "one", "maple"] into [red, one, maple] Thanks for any help! From alain at dpt-info.u-strasbg.fr Thu Aug 18 10:58:04 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 16:58:04 +0200 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Ghodmode writes: [...] > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. Or save work and find a public nntp server (or setup one, or ask your provider), and use a news reader to follow the list (even thunderbird can do this). No spam, no need to store messages on your machine, auto-purge after a configurable delay, etc. Problem solved. -- Alain. From aspineux at gmail.com Thu Aug 18 10:59:38 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 07:59:38 -0700 (PDT) Subject: extend class: include factories functions inside constructor References: Message-ID: <2b080d2c-62c0-4e69-8675-4da3bca5a6d3@a4g2000yqg.googlegroups.com> On Aug 18, 4:45?pm, Peter Otten <__pete... at web.de> wrote: > aspineux wrote: > > Hi > > I have a closed class and 2 factories function > > > class Data: > > ? def __init__(self): > > ? ? self.payload=None > > > def data_from_string(payload): > > ? data=Data() > > ? data.payload=payload > > ? return data > > > def data_from_file(f): > > ? data=Data() > > ? data.payload=f.read() > > ? return data > > > And I want to extend the class, by first including the factories > > function inside the constructor, > > second add some method to the class. > > > class MyData(Data): > > > ? def __init__(self, arg): > > ? ? # I know this coke is not working, this is to show you > > ? ? # what I expect > > ? ? if isinstance(arg, file): > > ? ? ? ? self=data_from_file(arg) > > ? ? else: > > ? ? ? ? self=data_from_string(arg) > > ? ? return self > > > ? def len(self): > > ? ? return len(self.payload) > > > And how I want to use it > > >>>> m=MyData('hello') > >>>> print m.len() > > 5 > > > any idea ? > > Assuming that Data is an oldstyle class you can either copy the Data > instance's state > > class MyData(Data): > ? ? def __init__(self, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? self.__dict__.update(obj.__dict__) > > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > or use another factory function and manually set the __class__: Exactly what I was looking for The magic is in self.__dict__.update(obj.__dict__) :-) > > class MyData(Data): > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > def make_mydata(arg): > ? ? if hasattr(arg, "read"): > ? ? ? ? factory = data_from_file > ? ? else: > ? ? ? ? factory = data_from_string > ? ? obj = factory(arg) > ? ? obj.__class__ = MyData > ? ? return obj > I don't want to replace 2 factories by one ! > If Data were a newstyle class you could move the hand-made polymorphism into > the __new__() method: > > class MyData(Data): > ? ? def __new__(class_, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? obj.__class__ = class_ > ? ? ? ? return obj > ? ? def __init__(self, arg): > ? ? ? ? pass > ? ? def __len__(self): > ? ? ? ? return len(self.payload) Very nice, I wahad no solution for newer style class. Thanks > > if __name__ == "__main__": > ? ? m = MyData("hello") > ? ? print len(m) > > Nothing of the above strikes me as pretty. Perhaps we could come up with a > neater solution if you tell us more about your use-case... From jasons at adventureaquarium.com Thu Aug 18 11:00:40 2011 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Thu, 18 Aug 2011 11:00:40 -0400 Subject: List spam In-Reply-To: <71d3407f-e851-414e-8934-28326d138dfe@o9g2000vbo.googlegroups.com> Message-ID: > On Aug 18, 8:39?am, "Jason Staudenmayer" > wrote: > > > > [snip irony] > > > > Adventure Aquarium is America's Most Touchable Aquarium! > > Featuring the ALL NEW Stingray Beach Club > > Where you can touch and hand feed the gentle stingrays > > > > To buy and print your tickets at home visit ? www.AdventureAquarium.com > ? ? ? ..?><((((?>..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..?`?.><((((?>..?`?.><((((?>..?`?.><((((?> > ..?><((((?>..?`?.><((((?> > > A Herschend Family Entertainment Company >Don't you find it a bit ironic that you are complaining about spam but >yet you are spamming this group with your link to buy tickets to a >stingray petting zoo (which is in fact an oxymoron?) under the guise >of spam bashing? Tip of the day: Create a website! >PS: I do however find the recent "rape" spam atrocious! I do know it is ironic that I forgot to stop the footer for the one reply. It's not my choice to add it but I was able to find a way around that work policy for list emails. I'm a strong opponent of dropping any email with a stupid footer spam. Jason ..?><((((?> From ian.g.kelly at gmail.com Thu Aug 18 11:03:03 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Aug 2011 11:03:03 -0400 Subject: pairwise combination of two lists In-Reply-To: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> References: <98CC6556-11F3-4850-BD2B-30481B53042D@mssm.edu> Message-ID: On Wed, Aug 17, 2011 at 4:22 PM, Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. > I found zip() but it only gives [('a', '1'), ('b', '2')], ?not exactly what I am looking for. Use the "roundrobin" recipe from the itertools documentation. Cheers, Ian From ms419 at freezone.co.uk Thu Aug 18 11:08:20 2011 From: ms419 at freezone.co.uk (Jack Bates) Date: Thu, 18 Aug 2011 08:08:20 -0700 Subject: Measure the amount of memory used? Message-ID: <1313680100.25701.15.camel@selene> I wrote a content filter for Postfix with Python, https://github.com/jablko/cookie It should get started once, and hopefully run for a long time - so I'm interested in how it uses memory: 1) How does the amount of memory used change as it runs? 2) How does the amount of memory used change as I continue to hack on it, and change the code? My naive thought was that I'd periodically append to a file, the virtual memory size from /proc/[pid]/stat and a timestamp. From this a could make a graph of the amount of memory used as my content filter runs, and I could compare two graphs to get a clue whether this amount changed as I continue to hack - but some Googling quickly revealed that measuring memory is actually quite complicated? Neither the virtual memory size nor the "resident set size" accurately measure the amount of memory used by a process Has anyone else measured the memory used by a Python program? How did you do it? From aspineux at gmail.com Thu Aug 18 11:09:43 2011 From: aspineux at gmail.com (aspineux) Date: Thu, 18 Aug 2011 08:09:43 -0700 (PDT) Subject: extend class: include factories functions inside constructor References: Message-ID: <14658331-2278-4601-91a2-1d1a5e180074@q1g2000vbj.googlegroups.com> On Aug 18, 4:45?pm, Peter Otten <__pete... at web.de> wrote: > aspineux wrote: > > Hi > > I have a closed class and 2 factories function > > > class Data: > > ? def __init__(self): > > ? ? self.payload=None > > > def data_from_string(payload): > > ? data=Data() > > ? data.payload=payload > > ? return data > > > def data_from_file(f): > > ? data=Data() > > ? data.payload=f.read() > > ? return data > > > And I want to extend the class, by first including the factories > > function inside the constructor, > > second add some method to the class. > > > class MyData(Data): > > > ? def __init__(self, arg): > > ? ? # I know this coke is not working, this is to show you > > ? ? # what I expect > > ? ? if isinstance(arg, file): > > ? ? ? ? self=data_from_file(arg) > > ? ? else: > > ? ? ? ? self=data_from_string(arg) > > ? ? return self > > > ? def len(self): > > ? ? return len(self.payload) > > > And how I want to use it > > >>>> m=MyData('hello') > >>>> print m.len() > > 5 > > > any idea ? > > Assuming that Data is an oldstyle class you can either copy the Data > instance's state > > class MyData(Data): > ? ? def __init__(self, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? self.__dict__.update(obj.__dict__) > > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > or use another factory function and manually set the __class__: > > class MyData(Data): > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > def make_mydata(arg): > ? ? if hasattr(arg, "read"): > ? ? ? ? factory = data_from_file > ? ? else: > ? ? ? ? factory = data_from_string > ? ? obj = factory(arg) > ? ? obj.__class__ = MyData > ? ? return obj > > If Data were a newstyle class you could move the hand-made polymorphism into > the __new__() method: > > class MyData(Data): > ? ? def __new__(class_, arg): > ? ? ? ? if hasattr(arg, "read"): > ? ? ? ? ? ? factory = data_from_file > ? ? ? ? else: > ? ? ? ? ? ? factory = data_from_string > ? ? ? ? obj = factory(arg) > ? ? ? ? obj.__class__ = class_ > ? ? ? ? return obj > ? ? def __init__(self, arg): > ? ? ? ? pass > ? ? def __len__(self): > ? ? ? ? return len(self.payload) > > if __name__ == "__main__": > ? ? m = MyData("hello") > ? ? print len(m) > > Nothing of the above strikes me as pretty. Perhaps we could come up with a > neater solution if you tell us more about your use-case... Ops, I clicked send before to finish my post. Thanks for your quick and very valuable answer. From drobinow at gmail.com Thu Aug 18 11:12:37 2011 From: drobinow at gmail.com (David Robinow) Date: Thu, 18 Aug 2011 11:12:37 -0400 Subject: How to convert a list of strings into a list of variables In-Reply-To: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] Why would you want to? From jenn.duerr at gmail.com Thu Aug 18 11:19:56 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 08:19:56 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> On Aug 18, 11:12?am, David Robinow wrote: > On Thu, Aug 18, 2011 at 10:57 AM, noydb wrote: > > How would you convert a list of strings into a list of variables using > > the same name of the strings? > > > So, ["red", "one", "maple"] into [red, one, maple] > > ? Why would you want to? I am being passed the list of strings. I have variables set up already pointing to files. I need to loop through each variable in the list and do things to the files. The list of strings will change each time, include up to 22 of the same strings each time. From malaclypse2 at gmail.com Thu Aug 18 11:29:40 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 18 Aug 2011 11:29:40 -0400 Subject: How to convert a list of strings into a list of variables In-Reply-To: <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > I am being passed the list of strings. ?I have variables set up > already pointing to files. ?I need to loop through each variable in > the list and do things to the files. ?The list of strings will change > each time, include up to 22 of the same strings each time. If you have a mapping of strings to values, you should just go ahead and store them in a dictionary. Then the lookup becomes simple: def foo(list_of_strings): mapping = { "bar0": "/var/log/bar0.log", "bar1": "/usr/local/bar/bar1.txt", "bar2": "/home/joe/logs/bar2.log", } for item in list_of_strings: filename = mapping[item] do_something(filename) (Untested) -- Jerry From gordon at panix.com Thu Aug 18 11:39:56 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 15:39:56 +0000 (UTC) Subject: Measure the amount of memory used? References: Message-ID: In Jack Bates writes: > 1) How does the amount of memory used change as it runs? I've observed that the amount of memory consumed by a program will stay constant or increase; it never decreases. Or were you wanting to measure the rate of increase over time? > Has anyone else measured the memory used by a Python program? How did > you do it? I generally use 'top' to do this for any program. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From darcy at druid.net Thu Aug 18 11:51:53 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Aug 2011 11:51:53 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <20110818115153.6a37653b@dilbert> On Thu, 18 Aug 2011 22:37:37 +0800 Ghodmode wrote: > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. I'm not sure it would scale but I have a few lists that I protect by doing a few simple things. First, I make the list so that only members can post. I then set the list so that everyone is moderated by default. When someone posts a legitimate message I simply pass it and then unmoderate that user. It's not as onerous as it sounds. Very few people actually post and you only have to deal with those that do once. Mailman makes it pretty simple to manage too. -- 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 jenn.duerr at gmail.com Thu Aug 18 11:54:48 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 18 Aug 2011 08:54:48 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> Message-ID: <17946eaa-2bc6-4c9b-8251-729072473988@w18g2000yqc.googlegroups.com> On Aug 18, 11:29?am, Jerry Hill wrote: > On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > > I am being passed the list of strings. ?I have variables set up > > already pointing to files. ?I need to loop through each variable in > > the list and do things to the files. ?The list of strings will change > > each time, include up to 22 of the same strings each time. > > If you have a mapping of strings to values, you should just go ahead > and store them in a dictionary. ?Then the lookup becomes simple: > > def foo(list_of_strings): > ? ? ? ? mapping = { > ? ? ? ? ? ? ? ? "bar0": "/var/log/bar0.log", > ? ? ? ? ? ? ? ? "bar1": "/usr/local/bar/bar1.txt", > ? ? ? ? ? ? ? ? "bar2": "/home/joe/logs/bar2.log", > ? ? ? ? } > ? ? ? ? for item in list_of_strings: > ? ? ? ? ? ? ? ? filename = mapping[item] > ? ? ? ? ? ? ? ? do_something(filename) > > (Untested) > > -- > Jerry Thanks, implemented something along those lines, and it worked! From navkirat.py at gmail.com Thu Aug 18 12:06:18 2011 From: navkirat.py at gmail.com (Navkirat Singh) Date: Thu, 18 Aug 2011 21:36:18 +0530 Subject: Sqlalchemy + Cherrypy Message-ID: Hi Guys, I am not sure if this is the right place to put this question. I am trying to figure out what the proper/clean way is to integrate cherrypy and sqlalchemy? I am currently trying to do this cherrypy 3 and sqlalchemy .7 in python 3.2 a) Cherrypy tools b) Integrate it directly into the app Any help will be really appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Thu Aug 18 12:08:24 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:08:24 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: <201108181208.25029.gheskett@wdtv.com> On Thursday, August 18, 2011 12:08:00 PM Ghodmode did opine: > On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk wrote: > > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote: > >> I really like this list as part of my learning tools but the amount > >> of spam that I've been getting from it is CRAZY. Doesn't anything > >> get scanned before it sent to the list? > > > > This has been discussed on the list a number of times before, so I'll > > refer you to the archives for details. > > > > Basically, the mailing list receives postings from Google Groups and > > vice versa. Most of the spam comes from Google Groups. If you add a > > mail filter that deletes anything with the "Organization" header set > > to "http://groups.google.com", you won't see much spam anymore. In my > > experience, you'll also miss a number of legitimate postings. > > You are absolutely right, it has been brought up before. But I'm glad > it's been brought up again. It's such a problem that it degrades the > usefulness of the list and the community. > > Most of the mailing lists I'm on are managed using Google Groups and > many of them are on mailman, like this list. I don't see spam on > them, so I don't know what's going on here. > > It's not really filtering at all. Most lists only allow members to > post and the admins are quick to boot offenders. > > For the most part, I'm just a lurker, so my suggestion shouldn't carry > as much weight, but here it is anyway... > > Make an effort to curb the spam even if it means killing the newsgroup > availability. Choose mailman or Google Groups, or another single > solution. Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. > > ... problem solved. > > Yes. I'm saying we should abandon those who only follow the list via > newsgroups. > Yes. I'm willing to do the work, but I'm not the right choice. +100 (or whatever it takes) > > HTH > > Philip > > -- > Ghodmode > http://www.ghodmode.com/blog Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The state of innocence contains the germs of all future sin. -- Alexandre Arnoux, "Etudes et caprices" From gordon at panix.com Thu Aug 18 12:09:43 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 16:09:43 +0000 (UTC) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: In <2ab25f69-6017-42a6-a7ef-c71bc2ee8547 at l2g2000vbn.googlegroups.com> noydb writes: > How would you convert a list of strings into a list of variables using > the same name of the strings? > So, ["red", "one", "maple"] into [red, one, maple] > Thanks for any help! If the strings and the object names are exactly the same, you could use eval(). (Of course this assumes the objects already exist.) red = "this is the red object" one = 1 maple = "this is the maple object" list_of_strings = ["red", "one", "maple"] list_of_variables = [] for x in list_of_strings: list_of_variables.append(eval(x)) for y in list_of_variables: print y -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ghodmode at ghodmode.com Thu Aug 18 12:09:56 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Fri, 19 Aug 2011 00:09:56 +0800 Subject: List spam In-Reply-To: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: On Thu, Aug 18, 2011 at 10:58 PM, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. ?Choose mailman or Google Groups, or another single >> solution. ?Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. ?Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. > > Problem solved. Is that easier than just checking your email? I guess it's a matter of perspective... Newsgroups aren't inherently spam-free. They're filtered. At least that's the case with Gmane (http://gmane.org/spam.php). My own ISP doesn't provide a news server and, although there are many links for free open news servers, most of them don't seem to work. I did check, though. I found a free, open news server with comp.lang.python after 6 that didn't work. Unfortunately, the one I found is read-only. I'll have to do some more looking if I want to participate in the newsgroup. I set it up in Thunderbird. I waited for a few minutes while it loaded the available newsgroups, then filtered the list for comp.lang.python and subscribed. I noticed that, when clicking on a message, there is another delay while I wait for the content of the message to load. I was happy to see significantly less spam in the newsgroup than in the mailing list, but there was still more than I see in other mailing lists. For me, this is much more difficult, although I'm sure that this is a matter of perspective. Also, I have something that's tied to this computer. I can't read it on my laptop, my mobile device, or at a cyber-cafe. I have to sit in front of this computer if I want to read the newsgroup and, until I find another news server that isn't read-only, I can't even post messages. For me, I'll stick with email. > -- Alain. -- Ghodmode http://www.ghodmode.com/blog From gheskett at wdtv.com Thu Aug 18 12:14:13 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:14:13 -0400 Subject: List spam In-Reply-To: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181214.13370.gheskett@wdtv.com> On Thursday, August 18, 2011 12:08:38 PM Alain Ketterlin did opine: > "Jason Staudenmayer" writes: > > I really like this list as part of my learning tools but the amount of > > spam that I've been getting from it is CRAZY. Doesn't anything get > > scanned before it sent to the list? > > I'm using nntp to read this newsgroup (through an academic server). > No spam at all. > > -- Alain. Which I think re-enforces the conclusion I have reached, and that is that the most obnoxious spammer here is injecting his spam directly to a machine handling google's groups that is downstream of any filtering they claim to do. Short answer is to disconnect the the NNTP link and make this list into a REAL mailing list. Subscribers only, or get past a GOOD captcha. Spammers have stuff that can do the average captcha in a second or less, so choose the images wisely and randomize both the background and the text. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The state of innocence contains the germs of all future sin. -- Alexandre Arnoux, "Etudes et caprices" From gheskett at wdtv.com Thu Aug 18 12:15:59 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:15:59 -0400 Subject: List spam In-Reply-To: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181215.59072.gheskett@wdtv.com> On Thursday, August 18, 2011 12:14:39 PM Alain Ketterlin did opine: > Ghodmode writes: > > [...] > > > Make an effort to curb the spam even if it means killing the newsgroup > > availability. Choose mailman or Google Groups, or another single > > solution. Make it members only, but allow anyone to register with an > > automated confirmation email and a CAPTCHA. Appoint a list admin who > > has a few minutes each day to scan subjects of emails for spammers and > > remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. > > Problem solved. > > -- Alain. That is asking the user to take considerable effort and resources to do that. What is wrong with the mailing list only approach? Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) The plot was designed in a light vein that somehow became varicose. -- David Lardner From gheskett at wdtv.com Thu Aug 18 12:20:36 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 12:20:36 -0400 Subject: List spam In-Reply-To: References: Message-ID: <201108181220.36337.gheskett@wdtv.com> On Thursday, August 18, 2011 12:16:50 PM Jason Staudenmayer did opine: [...] > I do know it is ironic that I forgot to stop the footer for the one > reply. It's not my choice to add it but I was able to find a way around > that work policy for list emails. I'm a strong opponent of dropping any > email with a stupid footer spam. > > Jason I'm a strong "proponent" of dropping any email with a stupid footer spam. There, I fixed it for you. ;-) Sorry, couldn't resist, Jason. At nearly 77, I am a firm believer that one can grow old without growing up. ;p) Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Renning's Maxim: Man is the highest animal. Man does the classifying. From nad at acm.org Thu Aug 18 12:37:14 2011 From: nad at acm.org (Ned Deily) Date: Thu, 18 Aug 2011 09:37:14 -0700 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: In article , Ghodmode wrote: > Newsgroups aren't inherently spam-free. They're filtered. At least > that's the case with Gmane (http://gmane.org/spam.php). > > My own ISP doesn't provide a news server and, although there are many > links for free open news servers, most of them don't seem to work. > > I did check, though. I found a free, open news server with > comp.lang.python after 6 that didn't work. Unfortunately, the one I > found is read-only. I'll have to do some more looking if I want to > participate in the newsgroup. I set it up in Thunderbird. I waited > for a few minutes while it loaded the available newsgroups, then > filtered the list for comp.lang.python and subscribed. I noticed > that, when clicking on a message, there is another delay while I wait > for the content of the message to load. > > I was happy to see significantly less spam in the newsgroup than in > the mailing list, but there was still more than I see in other mailing > lists. > > For me, this is much more difficult, although I'm sure that this is a > matter of perspective. Also, I have something that's tied to this > computer. I can't read it on my laptop, my mobile device, or at a > cyber-cafe. I have to sit in front of this computer if I want to read > the newsgroup and, until I find another news server that isn't > read-only, I can't even post messages. Confusingly, this "forum" is available via a number of channels. Here is a subset of them (there are more): 1. python-list mailing list http://mail.python.org/mailman/listinfo/python-list 2. comp.lang.python news:comp.lang.python (Usenet group via NNTP) 3. google groups 4. gmane (various formats) http://dir.gmane.org/gmane.comp.python.general a. gmane.comp.python.general (non-Usenet group via NNTP) b. web interfaces All of the above allow both reading and posting. gmane does spam filtering so, if you read and post through it, you will avoid most of the spam (a little bit gets through). The gmane nntp server (which is for gmane groups only, not regular Usenet groups) is free to use. http://gmane.org/about.php -- Ned Deily, nad at acm.org From ppearson at nowhere.invalid Thu Aug 18 12:43:20 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 16:43:20 GMT Subject: lists and for loops References: Message-ID: <9b4tp8FdrgU1@mid.individual.net> On Wed, 17 Aug 2011 20:08:23 -0700 (PDT), Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers Because integers are immutable. You cannot turn 1 into 6. Contrast this behavior with lists, which *are* mutable: >>> numbers = [[1],[2],[3],[4],[5]] >>> for n in numbers: ... n[0]= n[0] + 5 ... >>> numbers [[6], [7], [8], [9], [10]] For practical purposes, I'm sure you'll find other responders' excellent posts to be of more immediate use, but keeping mutability in mind helps. -- To email me, substitute nowhere->spamcop, invalid->net. From gordon at panix.com Thu Aug 18 12:51:05 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 16:51:05 +0000 (UTC) Subject: Word Perfect integration References: Message-ID: In Ethan Furman writes: > I have WordPerfect v13 which we are currently using for letter merges. > I would like to automate this with Python instead of learning the WP > Macro language. I suspect that learning how to integrate python with wordperfect will end up being much more work than learning wordperfect macros. Just my two cents. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From alain at dpt-info.u-strasbg.fr Thu Aug 18 12:58:53 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Thu, 18 Aug 2011 18:58:53 +0200 Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <8762lu64he.fsf@dpt-info.u-strasbg.fr> gene heskett writes: >> Or save work and find a public nntp server (or setup one, or ask your >> provider), and use a news reader to follow the list (even thunderbird >> can do this). No spam, no need to store messages on your machine, >> auto-purge after a configurable delay, etc. > That is asking the user to take considerable effort and resources to do > that. What is wrong with the mailing list only approach? Nothing really. Regarding effort and resources, once you've found a NNTP server there's very little effort (probably less than subscribing to a mailing list). I have 4 lines in my .emacs. And this lets me browse dozens of groups (or thousands if I had time for this). It might not be easy to find a server which will let you post, but that's because a few years back many internet providers decided that nntp was too much traffic. I guess it would now be considered ridiculous compared to the average web-site. But I'd like to return the question. What's wrong with nntp? It looks like everybody agrees that nntp brings spam. I just wanted to say that's not true, I use nntp extensively and haven't seen spam for months (I'm talking about 15-20 groups, not comp.lang.python only). The real problem here seems to be google groups, which in some way forwards spam to the mailing-list. How this happens is beyond my understanding. But let's try to fix the real problem. -- Alain. From ethan at stoneleaf.us Thu Aug 18 13:00:54 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 10:00:54 -0700 Subject: Word Perfect integration Message-ID: <4E4D4546.1070203@stoneleaf.us> I have WordPerfect v13 which we are currently using for letter merges. I would like to automate this with Python instead of learning the WP Macro language. Does anyone have any pointers? ~Ethan~ From ppearson at nowhere.invalid Thu Aug 18 13:02:49 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 17:02:49 GMT Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <9b4utpFdrgU2@mid.individual.net> On Thu, 18 Aug 2011 16:58:04 +0200, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. Choose mailman or Google Groups, or another single >> solution. Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. Or pay for filtered NNTP service. I'm happy with news.individual.net: 10 euros per year, appears to be competently run, very little spam gets through (maybe like 1 message per heavily posted group per day), and they probably carry all the newsgroups you follow. I have no affiliation with them, except for being a customer who hopes they stay in business. -- To email me, substitute nowhere->spamcop, invalid->net. From ppearson at nowhere.invalid Thu Aug 18 13:10:30 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 18 Aug 2011 17:10:30 GMT Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <9b4vc6FdrgU3@mid.individual.net> On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: [snip] > What is wrong with the mailing list only approach? In the mailing-list approach, how do I search for prior discussions on a subject? (I'm not particularly opposed to the mailing list, I'm just an NNTP follower worried about the uncertainties of change.) -- To email me, substitute nowhere->spamcop, invalid->net. From philip at semanchuk.com Thu Aug 18 13:21:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Aug 2011 13:21:02 -0400 Subject: List spam In-Reply-To: <9b4vc6FdrgU3@mid.individual.net> References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> <9b4vc6FdrgU3@mid.individual.net> Message-ID: On Aug 18, 2011, at 1:10 PM, Peter Pearson wrote: > On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: > [snip] >> What is wrong with the mailing list only approach? > > In the mailing-list approach, how do I search for prior discussions > on a subject? (I'm not particularly opposed to the mailing list, > I'm just an NNTP follower worried about the uncertainties of change.) I use a Google search like this: site:mail.python.org/pipermail/python-list/ banana Although that has its own issues, as not all messages seem to make it to that list (or they have the X-No-Archive bit set?) Cheers P From ghodmode at ghodmode.com Thu Aug 18 13:29:12 2011 From: ghodmode at ghodmode.com (Ghodmode) Date: Fri, 19 Aug 2011 01:29:12 +0800 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: On Fri, Aug 19, 2011 at 12:37 AM, Ned Deily wrote: > 4. gmane (various formats) > ? http://dir.gmane.org/gmane.comp.python.general > ? a. ?gmane.comp.python.general (non-Usenet group via NNTP) > All of the above allow both reading and posting. ?gmane does spam > filtering so, if you read and post through it, you will avoid most of > the spam (a little bit gets through). ?The gmane nntp server (which is > for gmane groups only, not regular Usenet groups) is free to use. Unfortunately, Gmane's version of this newsgroup (gmane.comp.python.general) has all of the offensive spam. I'm kinda surprised considering the detailed information that they put on their site about spam filtering. These are the ones I got to work: - textnews.news.cambrium.nl - mail.tsu.ru ... They're light on the spam, but they're read-only. Ironically, the Google Groups version (https://groups.google.com/forum/#!forum/comp.lang.python) has almost none of the spam, although I did see one message that said "This topic has been hidden because it was flagged for abuse". I can't join that Google Group, though. I guess that's because it's just a viewer for the newsgroup. > -- > ?Ned Deily, > ?nad at acm.org -- Ghodmode http://www.ghodmode.com/blog From rosuav at gmail.com Thu Aug 18 13:46:48 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Aug 2011 18:46:48 +0100 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode wrote: > Make an effort to curb the spam even if it means killing the newsgroup > availability. ?Choose mailman or Google Groups, or another single > solution. ?Make it members only, but allow anyone to register with an > automated confirmation email and a CAPTCHA. ?Appoint a list admin who > has a few minutes each day to scan subjects of emails for spammers and > remove them from the members list. > Unfortunately spammers can create email addresses very quickly, and CAPTCHAs are inherently weak (even the best of them are easily cracked by the Chinese human "botnets"). However, I wouldn't be against a system of spam filtering with three levels: Not Spam, gets straight onto the list; Definite Spam, gets deleted; and Dubious, which gets dropped into a mod's basket. ChrisA From drsalists at gmail.com Thu Aug 18 13:48:36 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Aug 2011 10:48:36 -0700 Subject: Measure the amount of memory used? In-Reply-To: <1313680100.25701.15.camel@selene> References: <1313680100.25701.15.camel@selene> Message-ID: "A person with one watch knows what time it is. A person with two is never sure." You're probably best off just picking one or more measures that work for your purposes, and going with them. Don't concern yourself overmuch with finding "the" amount. Memory can actually contract on some modern systems, due to garbage collection and the relatively new ability of some malloc's to mmap away no-longer-needed pages. Going directly to /proc is fine, though it might be a little more common (and portable) to run ps and let it sift through /proc. But of course, running ps over and over is less efficient. On Thu, Aug 18, 2011 at 8:08 AM, Jack Bates wrote: > I wrote a content filter for Postfix with Python, > https://github.com/jablko/cookie > > It should get started once, and hopefully run for a long time - so I'm > interested in how it uses memory: > > 1) How does the amount of memory used change as it runs? > > 2) How does the amount of memory used change as I continue to hack on > it, and change the code? > > My naive thought was that I'd periodically append to a file, the virtual > memory size from /proc/[pid]/stat and a timestamp. From this a could > make a graph of the amount of memory used as my content filter runs, and > I could compare two graphs to get a clue whether this amount changed as > I continue to hack > > - but some Googling quickly revealed that measuring memory is actually > quite complicated? Neither the virtual memory size nor the "resident set > size" accurately measure the amount of memory used by a process > > Has anyone else measured the memory used by a Python program? How did > you do it? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 18 13:48:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Aug 2011 18:48:56 +0100 Subject: How to convert a list of strings into a list of variables In-Reply-To: References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: > for x in list_of_strings: > ? ?list_of_variables.append(eval(x)) > If this really is what you need, you can simplify it by using the globals() dictionary - it's a regular dictionary whose contents are all the global variables in your current module. Inside a function, use locals() instead. http://docs.python.org/library/functions.html#globals ChrisA From nobody at nowhere.com Thu Aug 18 13:58:41 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 18:58:41 +0100 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <2670f4ee-0ab4-42ba-a472-42a4c7669ce8@p5g2000vbl.googlegroups.com> <4e4bcd37$0$23918$e4fe514c@news2.news.xs4all.nl> <4b383bcd-c58c-4e67-895a-d70fdf82f9c0@n35g2000yqf.googlegroups.com> Message-ID: On Thu, 18 Aug 2011 01:24:30 -0700, peter wrote: > This is very similar to my solution, which was to use stty turn off > keyboard echo, then repeatedly read sys.stdin.read(1) until a unique > keystroke had been defined. For example, the 'Insert' key seems to > return a sequence of four codes, namely 27, 91, 50, 126. It works but > has two disadvantages which I have managed to live with:- > > 1. As character 27 is used to signal the start of a 'special' key > sequence, it cannot detect a single press of the Esc key. The > workaround is to detect a double press instead. > > 2. Some keys seem to return different sets of codes depending on the > circumstances. For example, F1 returns 27,91,91,65 from the command > line, and 27,79,80 from a GUI window. I suspect there may be > variations between flavours of Linux too. The solution is to detect > all possibilities - so far I haven't found any overlaps. Escape sequences vary between terminals. A given key may have different escape sequences on the Linux console, xterm, a vt220, etc. The termcap and terminfo databases exist for this purpose (terminfo is newer). Some escape sequences vary by "mode". E.g. the cursor keys typically produce different sequences depending upon whether the terminal is in "keypad" mode. The normal solution for distinguishing the escape key from an escape sequence is a timeout. Unfortunately, it needs to be quite long in order to reliably support network (ssh, telnet, etc) connections. > Not pretty, but as I said it works. I know now not to spend time > looking further. Whilst there may be a historical reason for the > current situation, it would be a great convenience for amateur coders > like mayself if the gurus could devise a platform independent version > of mscvrt. The platform-independent high-level terminal interface is called "curses". From alec.taylor6 at gmail.com Thu Aug 18 14:00:49 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 04:00:49 +1000 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> Message-ID: 5963 unread emails. Thanks python-list + other mailing-lists! My recommendation to you is to setup a different account for your mailing-lists. Alternatively setup some mail rules. On Fri, Aug 19, 2011 at 3:46 AM, Chris Angelico wrote: > On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode wrote: >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. ?Choose mailman or Google Groups, or another single >> solution. ?Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. ?Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. >> > > Unfortunately spammers can create email addresses very quickly, and > CAPTCHAs are inherently weak (even the best of them are easily cracked > by the Chinese human "botnets"). However, I wouldn't be against a > system of spam filtering with three levels: Not Spam, gets straight > onto the list; Definite Spam, gets deleted; and Dubious, which gets > dropped into a mod's basket. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From alec.taylor6 at gmail.com Thu Aug 18 14:02:13 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 04:02:13 +1000 Subject: Word Perfect integration In-Reply-To: References: Message-ID: wow, people still use WordPerfect? On Fri, Aug 19, 2011 at 2:51 AM, John Gordon wrote: > In Ethan Furman writes: > >> I have WordPerfect v13 which we are currently using for letter merges. >> I would like to automate this with Python instead of learning the WP >> Macro language. > > I suspect that learning how to integrate python with wordperfect will > end up being much more work than learning wordperfect macros. > > Just my two cents. > > -- > John Gordon ? ? ? ? ? ? ? ? ? A is for Amy, who fell down the stairs > gordon at panix.com ? ? ? ? ? ? ?B is for Basil, assaulted by bears > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > From as at sci.fi Thu Aug 18 14:13:09 2011 From: as at sci.fi (Anssi Saari) Date: Thu, 18 Aug 2011 21:13:09 +0300 Subject: List spam References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: Ghodmode writes: > Newsgroups aren't inherently spam-free. They're filtered. At least > that's the case with Gmane (http://gmane.org/spam.php). > > My own ISP doesn't provide a news server and, although there are many > links for free open news servers, most of them don't seem to work. You know, Gmane allows access also via NNTP, including this list. Server news.gmane.org, group name gmane.comp.python.general. Haven't used it since I get this list via "normal" NNTP as comp.lang.python. My NNTP access is via a computer club for 8 euros per year. From gheskett at wdtv.com Thu Aug 18 14:25:42 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 14:25:42 -0400 Subject: List spam In-Reply-To: <8762lu64he.fsf@dpt-info.u-strasbg.fr> References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108181425.42811.gheskett@wdtv.com> On Thursday, August 18, 2011 02:12:58 PM Alain Ketterlin did opine: > gene heskett writes: > >> Or save work and find a public nntp server (or setup one, or ask your > >> provider), and use a news reader to follow the list (even thunderbird > >> can do this). No spam, no need to store messages on your machine, > >> auto-purge after a configurable delay, etc. > > > > That is asking the user to take considerable effort and resources to > > do that. What is wrong with the mailing list only approach? > > Nothing really. > > Regarding effort and resources, once you've found a NNTP server there's > very little effort (probably less than subscribing to a mailing list). I > have 4 lines in my .emacs. And this lets me browse dozens of groups (or > thousands if I had time for this). It might not be easy to find a server > which will let you post, but that's because a few years back many > internet providers decided that nntp was too much traffic. I guess it > would now be considered ridiculous compared to the average web-site. > > But I'd like to return the question. What's wrong with nntp? The sheer volume of traffic eats 99% of an ISP's bandwidth. The last time I checked with one of the local ISP's that I quit using years ago because it was 30 miles away and was then long distance, giving me $300 phone bills, they said their server died (again, and that then traffic was such that a 300GB hard drive was being subject to a posting lifetime of 3 hours because it was filling the drive that quickly. At the time, they had 5 T1 circuits, and NNTP was eating 4 of them. To an ISP, that stuff is found on the ground behind the male of the bovine specie. No ISP I have access to a mail account on, except google, has the resources to maintain a full listing nnpt server. > It looks > like everybody agrees that nntp brings spam. I just wanted to say that's > not true, I use nntp extensively and haven't seen spam for months (I'm > talking about 15-20 groups, not comp.lang.python only). > > The real problem here seems to be google groups, which in some way > forwards spam to the mailing-list. How this happens is beyond my > understanding. But let's try to fix the real problem. I could just nuke them, but I suppose I'd then have to resubscribe to about 10 of my mailing lists through the server this msg comes from. That is gradually happening anyway because posting through a gmail account, you cannot turn off the dup deletions, so one never knows if ones post to a list got there until someone replies, you don't get an echo. I have even tried CCing this address as some have suggested, but that doesn't work either. gmail is NOT the huge thing it was touted to be, not by a hell of a long row of apple trees. > -- Alain. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) "It's not just a computer -- it's your ass." -- Cal Keegan From gheskett at wdtv.com Thu Aug 18 14:28:48 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 14:28:48 -0400 Subject: List spam In-Reply-To: <9b4vc6FdrgU3@mid.individual.net> References: <9b4vc6FdrgU3@mid.individual.net> Message-ID: <201108181428.48530.gheskett@wdtv.com> On Thursday, August 18, 2011 02:26:24 PM Peter Pearson did opine: > On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett > wrote: [snip] > > > What is wrong with the mailing list only approach? > > In the mailing-list approach, how do I search for prior discussions > on a subject? (I'm not particularly opposed to the mailing list, > I'm just an NNTP follower worried about the uncertainties of change.) If the message still exists in your local email corpus, kmail for one has no problems searching it. However, since my corpus is close to 10gigs because my inbox and one list are not expired, the rest of them are expired on a selectable schedule that only saves the last 2000 or so msgs. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Hoare's Law of Large Problems: Inside every large problem is a small problem struggling to get out. From drsalists at gmail.com Thu Aug 18 14:29:58 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 18 Aug 2011 11:29:58 -0700 Subject: List spam In-Reply-To: References: <4E4D13FD.5050103@timgolden.me.uk> Message-ID: On Thu, Aug 18, 2011 at 6:39 AM, Jason Staudenmayer < jasons at adventureaquarium.com> wrote: > > > On 18/08/2011 13:58, Jason Staudenmayer wrote: > > > I really like this list as part of my learning tools but the amount > > > of spam that I've been getting from it is CRAZY. Doesn't > > anything get > > > scanned before it sent to the list? > I can deal with normal spam but this stuff I've gotten is all about > rape. > Agreed, a few of the recent messages would've been far too many at a count of 1. What I do is forward the list to gmail. gmail has pretty decent spam filtering - normally. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Thu Aug 18 14:39:29 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 19:39:29 +0100 Subject: List spam References: Message-ID: On Thu, 18 Aug 2011 14:30:37 +0100, Tim Golden wrote: >> I really like this list as part of my learning tools but the amount of >> spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I haven't seen any significant quantity of spam on the list for ages. (The > occasional one does get through although I can't remember the last). > > I always access it as a mailing list, and I seem to recall that the > newsgroup feed isn't filtered the same way as the mailing list is. That depends upon your news server. I see a small amount of spam for this group, but not enough that it concerns me. If the mailing list is getting spam from the newsgroup, the solution is to either find a cleaner feed or add a spam filter to the gateway. From nobody at nowhere.com Thu Aug 18 14:45:28 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 18 Aug 2011 19:45:28 +0100 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: On Thu, 18 Aug 2011 16:09:43 +0000, John Gordon wrote: >> How would you convert a list of strings into a list of variables using >> the same name of the strings? > >> So, ["red", "one", "maple"] into [red, one, maple] > > If the strings and the object names are exactly the same, you could use > eval(). Eval is overkill for variables; use globals() and/or locals(). But data which is supposed to be indexed by a variable key (i.e. a name which is determined at run-time) should normally be put into a dictionary. If access with fixed keys is far more common than variable keys, using an object (with getattr/setattr for variable keys) may be preferable. From ethan at stoneleaf.us Thu Aug 18 15:24:17 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 12:24:17 -0700 Subject: Word Perfect integration In-Reply-To: References: Message-ID: <4E4D66E1.1050206@stoneleaf.us> Alec Taylor wrote: > wow, people still use WordPerfect? Them's fightin' words right there! :) Yes, we still use Word Perfect, and will as long as it is available. The ability to see the codes in use (bold, margins, columns, etc) has so far been unequaled in anything else I have looked at. ~Ethan~ From ethan at stoneleaf.us Thu Aug 18 15:25:00 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Aug 2011 12:25:00 -0700 Subject: Word Perfect integration In-Reply-To: References: Message-ID: <4E4D670C.50206@stoneleaf.us> John Gordon wrote: > I suspect that learning how to integrate python with wordperfect will > end up being much more work than learning wordperfect macros. Possibly... but I enjoy coding in Python. :) ~Ethan~ From matze999 at gmail.com Thu Aug 18 15:49:54 2011 From: matze999 at gmail.com (Matt Funk) Date: Thu, 18 Aug 2011 13:49:54 -0600 Subject: Help with regular expression in python Message-ID: <201108181349.54727.matze999@gmail.com> Hi, i am sorry if this doesn't quite match the subject of the list. If someone takes offense please point me to where this question should go. Anyway, i have a problem using regular expressions. I would like to match the line: 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description The number of floats can vary (in this example there are 32). So what i thought i'd do is the following: instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) {32}' instance_linetype_pattern = re.compile(instance_linetype_pattern_str) Basically the expression in the first major set of paranthesis matches a scientific number format. The '{32}' is supposed to match the previous 32 times. However, it doesn't. I can't figure out why this does not work. I'd really like to understand it if someone can shed light on it. thanks matt From tjreedy at udel.edu Thu Aug 18 15:58:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 15:58:39 -0400 Subject: List spam In-Reply-To: References: <0A9E373A-AA62-4DD4-83B9-B4424037BF6B@semanchuk.com> <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: > I did check, though. I found a free, open news server with > comp.lang.python after 6 that didn't work. Unfortunately, the one I > found is read-only. I'll have to do some more looking if I want to > participate in the newsgroup. I set it up in Thunderbird. I read and post to this and other Python lists via news.gmane.org (free) with Thunderbird. It mirrors 1000s of technical mail lists, including 200+ with 'python'. I believe it therefore has less spam than c.l.p (ie, minus whatever gets filtered out by the pipermail at python.org). First post to any list requires a response to an email. Uptime is pretty good. -- Terry Jan Reedy From M.Komon at SiliconHill.cz Thu Aug 18 15:59:32 2011 From: M.Komon at SiliconHill.cz (=?UTF-8?B?TWFydGluIEtvbW/FiA==?=) Date: Thu, 18 Aug 2011 21:59:32 +0200 Subject: Help with regular expression in python In-Reply-To: <201108181349.54727.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> Message-ID: <4E4D6F24.8040501@SiliconHill.cz> You don't seem to account for the whitespace between the floats. Try > '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?\s+){32}' (just added \s+). Martin On 8/18/2011 9:49 PM, Matt Funk wrote: > Hi, > i am sorry if this doesn't quite match the subject of the list. If someone > takes offense please point me to where this question should go. Anyway, i have > a problem using regular expressions. I would like to match the line: > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 > 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 > 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 > 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) : some description > > The number of floats can vary (in this example there are 32). So what i thought > i'd do is the following: > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > Basically the expression in the first major set of paranthesis matches a > scientific number format. The '{32}' is supposed to match the previous 32 > times. However, it doesn't. I can't figure out why this does not work. I'd > really like to understand it if someone can shed light on it. > > thanks > matt From gordon at panix.com Thu Aug 18 16:00:09 2011 From: gordon at panix.com (John Gordon) Date: Thu, 18 Aug 2011 20:00:09 +0000 (UTC) Subject: Help with regular expression in python References: Message-ID: In Matt Funk writes: > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) Does your regexp account for the space in between each float? I can't tell due to your post having a linebreak at a really inconvenient spot. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tjreedy at udel.edu Thu Aug 18 16:07:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 16:07:16 -0400 Subject: List spam In-Reply-To: <201108181214.13370.gheskett@wdtv.com> References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> <201108181214.13370.gheskett@wdtv.com> Message-ID: On 8/18/2011 12:14 PM, gene heskett wrote: > into a REAL mailing list. Subscribers only, or get past a GOOD captcha. I just had an idea. Ask 'What is python? __________________" or "What can you do with a python?' with a free-form fill in the blank answer. Look for 'computer', 'program' or 'language' in the response. 'snake' fails the test. Or 'Enter a Python keyword (search the tutorial if you do not know any) ____' -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 18 16:19:33 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Aug 2011 16:19:33 -0400 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: On 8/18/2011 3:24 PM, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. Definitely. I did a book with WP and periodically went through with codes revealed to delete any junk and got the camera-ready copy I wanted. I have recently used OpenO modeled after MSO and occasionally get frustrated when I cannot see what it actually inserts, to explain why it does not behave as expected. That aside, if you are on Windows, check the list archives for 'office automation' or somesuch. If WP has the standard API, I believe the answer is to use the PythonWin extensions, included with the ActiveState Python distribution and available on SourceForge. There is a windows module includes in the stdlib, but I do not know if it has enough. -- Terry Jan Reedy From vriolk at gmail.com Thu Aug 18 16:44:51 2011 From: vriolk at gmail.com (coldpizza) Date: Thu, 18 Aug 2011 13:44:51 -0700 (PDT) Subject: How to print non-printable chars?? References: Message-ID: <6c15a4a4-02a9-4a04-bd3a-0cb88a96470f@v7g2000vbk.googlegroups.com> On Aug 13, 7:59?am, Julio Cesar Rodriguez Cruz wrote: > Hi all, > If I open an .exe file in any text editor I get lot of odd chars, > what I want is to know how to output those chars if I have the hexadecimal > code. I found out how to do the reverse process with the quopri module, > > i.e.:>>> import quopri > >>> quopri.encodestring('?? ') > '=F1=E8=18' > >>> quopri.decodestring('=F1=E8=18') > > '\xf1\xe8\x18' > > but how to do the reverse? ...gived '\xf1\xe8\x18', print '?? ' > > any tips? > thanks > Julio Cesar In a web/html environment or in broken ascii-only consoles like the one on windows, I use the following hack: print your_unicode_string.encode('us-ascii','xmlcharrefreplace') This will print unicode chars using pure ASCII symbols which will display correctly in a web browser and are more readable in a console than unicode escapes. From brian.curtin at gmail.com Thu Aug 18 16:51:42 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Thu, 18 Aug 2011 15:51:42 -0500 Subject: How to build python using visual studio 2005? In-Reply-To: References: Message-ID: On Wed, Aug 17, 2011 at 13:16, smith jack wrote: > anybody here have build it correctly? > how to make a msi file just as the official site did? > is there any detailed tutorial online? We're currently shipping CPython built on VS 2008, but I do know of people building with 2005. How they do it, I'm not entirely sure, but all of the related files are available -- see the PC folder for previous versions of project and solution files. As for making the MSI, from a source checkout, the Tools/msi/msi.py script is how its generated, but there isn't currently any documentation or tutorial. What I'd do is start by running that script, then piece together what you're missing in order to get it working. You'll need a built Python including the third-party things like tkinter in order for it to work. I know it needs pywin32, but I can't remember anything else I needed off the top of my head, but I have gotten it to work before. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Thu Aug 18 17:19:42 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 17:19:42 -0400 Subject: List spam In-Reply-To: References: <201108181214.13370.gheskett@wdtv.com> Message-ID: <201108181719.42980.gheskett@wdtv.com> On Thursday, August 18, 2011 05:18:42 PM Terry Reedy did opine: > On 8/18/2011 12:14 PM, gene heskett wrote: > > into a REAL mailing list. Subscribers only, or get past a GOOD > > captcha. > > I just had an idea. Ask 'What is python? __________________" or "What > can you do with a python?' with a free-form fill in the blank answer. > Look for 'computer', 'program' or 'language' in the response. 'snake' > fails the test. > > Or 'Enter a Python keyword (search the tutorial if you do not know any) > ____' Sounds good, but now you've trained the spammer who is without a doubt watching this list. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) QOTD: "I may not be able to walk, but I drive from the sitting position." From vlastimil.brom at gmail.com Thu Aug 18 17:27:42 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 18 Aug 2011 23:27:42 +0200 Subject: Help with regular expression in python In-Reply-To: <201108181349.54727.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> Message-ID: 2011/8/18 Matt Funk : > Hi, > i am sorry if this doesn't quite match the subject of the list. If someone > takes offense please point me to where this question should go. Anyway, i have > a problem using regular expressions. I would like to match the line: > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 > 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 > 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 > 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 > 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) ? ? ? : ? ? ? some description > > The number of floats can vary (in this example there are 32). So what i thought > i'd do is the following: > instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) > {32}' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > Basically the expression in the first major set of paranthesis matches a > scientific number format. The '{32}' is supposed to match the previous 32 > times. However, it doesn't. I ?can't figure out why this does not work. I'd > really like to understand it if someone can shed light on it. > > thanks > matt > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, the already suggested handling of whitespace with \s+ etc. at the end of the parenthesised patern should help; furhtermore, if you are using this pattern in the python source, you should either double all backslashes or use a raw string for the pattern - with r prepended before the opening quotation mark: pattern_str = r"..." in order to handle backslashes literally and not as escape character. hth, vbr From sigmundv at gmail.com Thu Aug 18 17:51:13 2011 From: sigmundv at gmail.com (SigmundV) Date: Thu, 18 Aug 2011 14:51:13 -0700 (PDT) Subject: pairwise combination of two lists References: Message-ID: <0da423ac-abc1-468d-bca7-8a745eae812b@y4g2000vbx.googlegroups.com> On Aug 17, 9:22?pm, Yingjie Lin wrote: > I found zip() but it only gives [('a', '1'), ('b', '2')], ?not exactly what I am looking for. Yet, if you feed the zip into a list comprehension you get what you want: li3 = [''.join(l) for l in zip(li1,li2)] Sigmund From antonio.a.barbosa at gmail.com Thu Aug 18 18:05:24 2011 From: antonio.a.barbosa at gmail.com (AB) Date: Thu, 18 Aug 2011 15:05:24 -0700 (PDT) Subject: How to convert a list of strings into a list of variables In-Reply-To: References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <2d34b748-8bcd-4411-8f81-a3e55a0ded21@glegroupsg2000goo.googlegroups.com> Hi, If the ?variables? are named attributes you can use getattr. #---------------- class colors: red=1 green=2 blue=3 c=colors() a=['red','green','blue'] for v in a: print v,getattr(c,v) #----------- AB From ramit.prasad at jpmorgan.com Thu Aug 18 18:20:59 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 18 Aug 2011 18:20:59 -0400 Subject: List spam In-Reply-To: <201108181719.42980.gheskett@wdtv.com> References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2EA7C3C5AA@EMARC112VS01.exchad.jpmchase.net> >> Or 'Enter a Python keyword (search the tutorial if you do not know any) >> ____' > >Sounds good, but now you've trained the spammer who is without a doubt >watching this list. Teach them Python before they can post, I like it! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ben+python at benfinney.id.au Thu Aug 18 18:26:54 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Aug 2011 08:26:54 +1000 Subject: List spam References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <87ippubbkh.fsf@benfinney.id.au> gene heskett writes: > Short answer is to disconnect the the NNTP link and make this list > into a REAL mailing list. Subscribers only, or get past a GOOD > captcha. Many of the more valuable contributors post via NNTP, which does not require mailing list subscription nor CAPTCHA. One of the compelling features of this forum is that newcomers to Python can post here without the hurdles you're describing. -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From matze999 at gmail.com Thu Aug 18 19:03:05 2011 From: matze999 at gmail.com (Matt Funk) Date: Thu, 18 Aug 2011 17:03:05 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> Message-ID: <201108181703.06278.matze999@gmail.com> Hi guys, thanks for the suggestions. I had tried the white space before as well (to no avail). So here is the expression i am using (based on suggestions), but still no success: instance_linetype_pattern_str =\ r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' instance_linetype_pattern = re.compile(instance_linetype_pattern_str) results = instance_linetype_pattern.findall(line) print "results: "; print results The match i get is: results: [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome description')] btw: The line to be matched (given below) is ONE line. There are no line breaks (even though my email client adds them). matt On Thursday, August 18, 2011, Vlastimil Brom wrote: > 2011/8/18 Matt Funk : > > Hi, > > i am sorry if this doesn't quite match the subject of the list. If > > someone takes offense please point me to where this question should go. > > Anyway, i have a problem using regular expressions. I would like to > > match the line: > > > > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > > 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > > 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > > 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > > 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > > 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > > 2.150000e+01 2.199000e+01 : (instance: 0) : some description > > > > The number of floats can vary (in this example there are 32). So what i > > thought i'd do is the following: > > instance_linetype_pattern_str = > > '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) {32}' > > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > > Basically the expression in the first major set of paranthesis matches a > > scientific number format. The '{32}' is supposed to match the previous 32 > > times. However, it doesn't. I can't figure out why this does not work. > > I'd really like to understand it if someone can shed light on it. > > > > thanks > > matt > > -- > > http://mail.python.org/mailman/listinfo/python-list > > Hi, > the already suggested handling of whitespace with \s+ etc. at the end > of the parenthesised patern should help; > furhtermore, if you are using this pattern in the python source, you > should either double all backslashes or use a raw string for the > pattern - with r prepended before the opening quotation mark: > pattern_str = r"..." > in order to handle backslashes literally and not as escape character. > hth, > vbr From usenet-nospam at seebs.net Thu Aug 18 19:03:28 2011 From: usenet-nospam at seebs.net (Seebs) Date: 18 Aug 2011 23:03:28 GMT Subject: List spam References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: On 2011-08-18, Prasad, Ramit wrote: >>> Or 'Enter a Python keyword (search the tutorial if you do not know any) >>> ____' >> >>Sounds good, but now you've trained the spammer who is without a doubt >>watching this list. > > Teach them Python before they can post, I like it! I don't. If I want to get started in a language, I might well want to read about it a bit, and maybe ask questions like "what is a good book for me to start with?" If I have to know the language to do that, well... -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From usenet-nospam at seebs.net Thu Aug 18 19:03:29 2011 From: usenet-nospam at seebs.net (Seebs) Date: 18 Aug 2011 23:03:29 GMT Subject: Word Perfect integration References: Message-ID: On 2011-08-18, Ethan Furman wrote: > Yes, we still use Word Perfect, and will as long as it is available. > The ability to see the codes in use (bold, margins, columns, etc) has so > far been unequaled in anything else I have looked at. I have used other software that had this functionality, but not so much lately. (Although it appears that PageStream still does this, which is totally of relevance to someone, I'm sure.) But yeah, that was an AMAZING feature, and not having it is one of the reasons I'm so often unable to get things done in MS Word. Sadly, Corel dropped Mac and Linux support, and I don't do real work on Windows, so WP has been off my list for a long time now. :( -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From rhodri at wildebst.demon.co.uk Thu Aug 18 19:18:13 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Aug 2011 00:18:13 +0100 Subject: List spam References: Message-ID: On Thu, 18 Aug 2011 16:00:40 +0100, Jason Staudenmayer wrote: > I'm a strong opponent of dropping any email with a > stupid footer spam. By contrast, an excessively large sig (particularly an excessively large sig without a proper separator) is something that's guaranteed to get on my wick, and usually indicates someone I don't want to bother listening to. Thank you for trimming it. I'm reading this as the comp.lang.python newsgroup, straight off an NNTP server, and to be honest I'm not getting the level of spam you are talking about. There's some, sure -- usually for Bollywood actress pictures -- but not enough to make me worry about Opera's relatively poor newsgroup filtering facilities. If you're getting as much as you say, it's being injected on the mail side of the gateway somehow. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Thu Aug 18 19:21:16 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Aug 2011 00:21:16 +0100 Subject: Word Perfect integration References: Message-ID: On Thu, 18 Aug 2011 20:24:17 +0100, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. I take it you haven't looked at TeX, then? :-) -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Thu Aug 18 19:31:32 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Aug 2011 00:31:32 +0100 Subject: List spam In-Reply-To: References: <201108181214.13370.gheskett@wdtv.com> <201108181719.42980.gheskett@wdtv.com> Message-ID: On Fri, Aug 19, 2011 at 12:03 AM, Seebs wrote: > I don't. ?If I want to get started in a language, I might well want to > read about it a bit, and maybe ask questions like "what is a good book > for me to start with?" > > If I have to know the language to do that, well... > When I start with a language, I want two things: a compiler/interpreter, and online documentation. (A book would be equivalent to the latter, but I tend to prefer to read things online.) Asking questions comes later; first, I want to get a comprehension for the language's features. By the time I join a list like this, I want to be able to understand the answers I get. ChrisA From vincent at vincentdavis.net Thu Aug 18 19:53:35 2011 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 18 Aug 2011 17:53:35 -0600 Subject: Check email header for RFC 822 standard and match emails between imap servers. Message-ID: The sort story, I have been attempting to use the Google Migration assistant to migrate emails from one google account to another, about 80,000 emails. I have two problems. 1. Many emails that fail to transfer because of errors like "Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is invalid." See full error below. emails that. 2. I need to delete the emails from the old account that have been transferred. And the Two question are: 1: I am able to connect and get an email. But I am not clear how I would check that the header is valid or identify the problem. grl = imaplib.IMAP4_SSL('imap.gmail.com', 993) grl.login('name at domain.com', 'password') grl.fetch(17006, 'uid') # So now I have an email how do I check the header, I know how to view it but not check it for RFC 822. 2: Since I don't know which emails have been transferred I want to delete all the email that have. To be more correct I don't know which ones on the old account, when they are moved to the new account they get the label as transferred. How should I compare emails? The uid is different on each server so I think using the TO: FROM: and DATE: TIME: would work. How do I compare emails in this way? How to I get the TO: FROM: DATE: TIME: from one email to reach for the same email in the other account. Sample error from google migration app. 2011-08-16T16:47:47.141-06:00 808 E:Network ExchangeMigration!WinHttp::ExecuteHttpRequestIStreamResponse @ 696 ( gmetanias at domain.com )> Response: Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is invalid. 2011-08-16T16:47:47.141-06:00 808 E:Migration ExchangeMigration!EmailUploader::HandleStatus @ 462 (gmetanias at domain.com)> Permanent Message Failure, skipping the message!. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!IMAPMessageWrapper::GetMessageSentTime @ 154 ( gmetanias at domain.com )> Failed with 0x80004005, last successful line = 151. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!IMAPMessageWrapper::GetMessageReceivedTime @ 170 ( gmetanias at domain.com )> Failed with 0x80004001, last successful line = 168. 2011-08-16T16:47:47.328-06:00 808 E:Migration ExchangeMigration!GetMessageDescription @ 198 (gmetanias at domain.com)> Sent: 2011-08-16T22:47:47.000Z. Received: 2011-08-16T22:47:47.000Z. Size: 196114. Subject RE: ppt templates. -- Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From noonslists at gmail.com Thu Aug 18 21:02:52 2011 From: noonslists at gmail.com (Noon Silk) Date: Fri, 19 Aug 2011 11:02:52 +1000 Subject: nose + processes + xunit In-Reply-To: References: Message-ID: Has anyone had any trouble with this setup? I am in a situation where, the tests run fine when I don't include "--processes=N", however, when I *do* do that, they exit early? The reason I think they exit, is that I'm actually running a different executable, and I load it like so: retcode = subprocess.call(["start /wait myprog.exe"], shell=True) Now, note that this is on Windows 7; the "start /wait" does basically exactly what you think. *And indeed it operates correctly in a single process*, but when nose tries to run multi-process, it fails to block, and the test executes far sooner than it should. Indeed, Nose claims that it ran 0 tests, when it actually at least ran 1! So, I think the myprog.exe is sending some signal to kill it. It so happens that start has a "/B" ?parameter that may also help here, but actually it doesn't. The result is that I don't get any further output from the test (that is, the xunit xml isn't generated, and even the console doesn't report anything as having happened). Interested in thoughts ... -- Noon Silk Fancy a quantum lunch? http://groups.google.com/group/quantum-lunch?hl=en "Every morning when I wake up, I experience an exquisite joy ? the joy of being this signature." From steve+comp.lang.python at pearwood.info Thu Aug 18 21:42:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 11:42:24 +1000 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <4e4dbf81$0$30004$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Thu, Aug 18, 2011 at 5:09 PM, John Gordon wrote: >> for x in list_of_strings: >> list_of_variables.append(eval(x)) >> > > If this really is what you need, you can simplify it by using the > globals() dictionary - it's a regular dictionary whose contents are > all the global variables in your current module. Inside a function, > use locals() instead. You can use locals outside of a function too, because it just returns globals(). Lookup of names in locals/globals is much safer than eval, particularly if there is any risk that the list of names comes from an untrusted or potentially hostile source. list_of_strings = ['red', 'blue', '__import__("os").system("echo I just p0wned your system")', 'green', 'yellow'] (The simplest way out of a billion to cause grief.) Code injection attacks are the first and second most common form of security vulnerability, ahead of even buffer overflows. Please don't add to the list. http://cwe.mitre.org/top25/?2011 (Oh, and if you think that protecting against code injection attacks while still using eval or exec is simple, please step away from the keyboard.) -- Steven From srehtvandy at gmail.com Thu Aug 18 21:44:58 2011 From: srehtvandy at gmail.com (luvspython) Date: Thu, 18 Aug 2011 18:44:58 -0700 (PDT) Subject: 'super' object has no attribute '__setitem__' Message-ID: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> I'm using Python 2.7 and the code below fails at the 'super' statement in the __setitem__ function in the HistoryKeeper class. The error is: 'super' object has no attribute '_setitem__' Can anyone please tell me why and how to fix it? (I've googled endlessly and I don't see the problem.) [The code will seem silly as it is, because it's pared down to show the example. The goal is that multiple classes, like the Vehicle class below, will inherit HistoryKeeper. History keeper overloads __setitem__ and will eventually keep a running history every time an attribute of any of the inheriting classes is changed.] Thanks in advance .... class HistoryKeeper(object): def __init__(self, args): for arg, value in args.items(): if arg != 'self': self.__setitem__(arg, value) def __setitem__(self, item, value): super(HistoryKeeper, self).__setitem__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): args = locals() super(Vehicle, self).__init__(args) if __name__ == "__main__": car = Vehicle('TAG123', 'FORD', 'Model A') print car.make From benjamin at python.org Thu Aug 18 22:05:34 2011 From: benjamin at python.org (Benjamin Peterson) Date: Fri, 19 Aug 2011 02:05:34 +0000 (UTC) Subject: 'super' object has no attribute =?utf-8?b?J19fc2V0aXRlbV9fJw==?= References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: luvspython gmail.com> writes: > def __setitem__(self, item, value): > super(HistoryKeeper, self).__setitem__(item, value) object has no __setitem__. Are you looking for __setattr__? > > class Vehicle(HistoryKeeper): > def __init__(self, tag, make, model): > args = locals() This is hideous by the way. From mrjean1 at gmail.com Thu Aug 18 22:07:06 2011 From: mrjean1 at gmail.com (MrJean1) Date: Thu, 18 Aug 2011 19:07:06 -0700 (PDT) Subject: Measure the amount of memory used? References: Message-ID: <52d4c51b-e820-4676-9273-aeef1a5030e1@e20g2000prn.googlegroups.com> Take a look it this recipe (for Linux only): /Jean On Aug 18, 8:08?am, Jack Bates wrote: > I wrote a content filter for Postfix with Python,https://github.com/jablko/cookie > > It should get started once, and hopefully run for a long time - so I'm > interested in how it uses memory: > > ?1) How does the amount of memory used change as it runs? > > ?2) How does the amount of memory used change as I continue to hack on > it, and change the code? > > My naive thought was that I'd periodically append to a file, the virtual > memory size from /proc/[pid]/stat and a timestamp. From this a could > make a graph of the amount of memory used as my content filter runs, and > I could compare two graphs to get a clue whether this amount changed as > I continue to hack > > ?- but some Googling quickly revealed that measuring memory is actually > quite complicated? Neither the virtual memory size nor the "resident set > size" accurately measure the amount of memory used by a process > > Has anyone else measured the memory used by a Python program? How did > you do it? From ericsnowcurrently at gmail.com Thu Aug 18 22:07:12 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Thu, 18 Aug 2011 20:07:12 -0600 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: On Thu, Aug 18, 2011 at 7:44 PM, luvspython wrote: > I'm using Python 2.7 and the code below fails at the 'super' statement > in the __setitem__ function in the HistoryKeeper class. ?The error is: > ? 'super' object has no attribute '_setitem__' > > Can anyone please tell me why and how to fix it? ? (I've googled > endlessly and I don't see the problem.) > > [The code will seem silly as it is, because it's pared down to show > the example. ?The goal is that multiple classes, like the Vehicle > class below, will inherit HistoryKeeper. ?History keeper overloads > __setitem__ and will eventually keep a running history every time an > attribute of any of the inheriting classes is changed.] > > Thanks in advance .... > > > class HistoryKeeper(object): > ? ?def __init__(self, args): > ? ? ? ?for arg, value in args.items(): > ? ? ? ? ? ?if arg != 'self': > ? ? ? ? ? ? ? ?self.__setitem__(arg, value) > > ? ?def __setitem__(self, item, value): > ? ? ? ?super(HistoryKeeper, self).__setitem__(item, value) > > > class Vehicle(HistoryKeeper): > ? ?def __init__(self, tag, make, model): > ? ? ? ?args = locals() > ? ? ? ?super(Vehicle, self).__init__(args) > > > if __name__ == "__main__": > ? ?car = Vehicle('TAG123', 'FORD', 'Model A') > ? ?print car.make Did you mean to use __setattr__ instead? object, the base class of HistoryKeeper, does not have a __setitem__ method, hence the AttributeError. super() is a proxy for the next class in the MRO, typically the base class of your class. Keep in mind that is equivalent to . However, is equivalent to . see: http://docs.python.org/reference/datamodel.html#object.__setattr__ http://docs.python.org/reference/datamodel.html#object.__setitem__ http://docs.python.org/library/functions.html#super -eric > -- > http://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Thu Aug 18 22:10:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 12:10:12 +1000 Subject: List spam References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> gene heskett wrote: >> But I'd like to return the question. What's wrong with nntp? > > The sheer volume of traffic eats 99% of an ISP's bandwidth. I doubt that very much, particularly if the ISP drops the binary newsgroups. My ISP, Internode, has provided nntp for many years. For a while a few years back they dropped binary newsgroups, but thay have brought them back. They wouldn't do that if there wasn't a clear demand for it, and if they didn't believe that on the balance, providing free Usenet access to customers didn't pay for itself. These days, many big ISPs complain about bittorrent using up their bandwidth. I call shenanigans. That's like my local bottle shop complaining that 99% of their sales comes from wine, and that stocking all that wine takes away valuable shelf space that could be used for imported Romanian beers and Chinese whiskey (no offense to anyone who likes Romanian beer or Chinese whiskey). It's a nonsense claim -- if your customers want to use the bandwidth they're paying for on bittorrent, or any other protocol, what difference does it make to you? It's not like you have to install a second Interweb tube just for bittorrent, or that bittorrent packets cost more than HTTP packets. Fer fecks sake, the ISP doesn't even have to run a bittorrent server! It's practically free money to the ISP, packets go in, packets go out, they don't have to do a bloody thing with them. Now, an ISP might not have the bandwidth to supply all the needs of their customers, that's a separate issue. But complaining that the problem is specifically because they use bittorrent, as if it would disappear if they changed to HTTP, is bogus. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 18 22:23:09 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 19 Aug 2011 12:23:09 +1000 Subject: List spam References: <87hb5e6ahx.fsf@dpt-info.u-strasbg.fr> Message-ID: <4e4dc90d$0$29983$c3e8da3$5496439d@news.astraweb.com> Alain Ketterlin wrote: > "Jason Staudenmayer" writes: > >> I really like this list as part of my learning tools but the amount of >> spam that I've been getting from it is CRAZY. Doesn't anything get >> scanned before it sent to the list? > > I'm using nntp to read this newsgroup (through an academic server). > No spam at all. I'm also using nntp (Usenet) and see very little spam. There was a flurry of about ten *extremely* obnoxious pr0n spams in a row, and the occasional odd one here or there, but generally I see hardly any. It is ironic that some people say that the solution to the spam problem is to move to Google Groups, because most of the spam comes *from* Google Groups. -- Steven From grrrrr at rrrrr.com Thu Aug 18 22:24:44 2011 From: grrrrr at rrrrr.com (Grummble) Date: Thu, 18 Aug 2011 22:24:44 -0400 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: On 08/16/2011 12:32 AM, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. > I modified something similar to: http://code.activestate.com/recipes/551780-win-services-helper/ and it was in production for several years without any issues. Specifically it processed orders generated by a customer's MRP system, delivered to us via LPR, then processed into a format our in house windows hosted picking/shipping system could digest. Availability was a *major* requirement, and it worked flawlessly. From gheskett at wdtv.com Thu Aug 18 22:35:30 2011 From: gheskett at wdtv.com (gene heskett) Date: Thu, 18 Aug 2011 22:35:30 -0400 Subject: List spam In-Reply-To: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201108182235.30272.gheskett@wdtv.com> On Thursday, August 18, 2011 10:23:49 PM Steven D'Aprano did opine: > gene heskett wrote: > >> But I'd like to return the question. What's wrong with nntp? > > > > The sheer volume of traffic eats 99% of an ISP's bandwidth. > > I doubt that very much, particularly if the ISP drops the binary > newsgroups. [...] > It's not like you have to install a second Interweb tube just for > bittorrent, or that bittorrent packets cost more than HTTP packets. Fer > fecks sake, the ISP doesn't even have to run a bittorrent server! It's > practically free money to the ISP, packets go in, packets go out, they > don't have to do a bloody thing with them. Except pay for the bandwidth to get the bytes into their system. > Now, an ISP might not have the bandwidth to supply all the needs of > their customers, that's a separate issue. Yes it is, which is why Hughs has a bandwidth limit cap they lift in the middle of the night when overall traffic is zilch. The bird(s) only have so much bandwidth and it costs tens of millions to 'lay another fiber' when its 22,300 miles up. OTOH, they have to pay for that bandwidth 24/7, so if they can move the relatively few high traffic folks usage to 3-5 AM, they can service more people watching old black and white John Holmes clips at 9-11pm. ;-) > But complaining that the > problem is specifically because they use bittorrent, as if it would > disappear if they changed to HTTP, is bogus. Agreed, that's 100% a red herring. Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Q: How many mathematicians does it take to screw in a light bulb? A: One. He gives it to six Californians, thereby reducing the problem to the earlier joke. From sjbenner at gmail.com Thu Aug 18 23:00:55 2011 From: sjbenner at gmail.com (Josh Benner) Date: Thu, 18 Aug 2011 20:00:55 -0700 Subject: Help with regular expression in python In-Reply-To: <201108181703.06278.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> Message-ID: On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk wrote: > Hi guys, > > thanks for the suggestions. I had tried the white space before as well (to > no > avail). So here is the expression i am using (based on suggestions), but > still > no success: > > instance_linetype_pattern_str =\ > r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > results = instance_linetype_pattern.findall(line) > print "results: "; print results > > > The match i get is: > results: > [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome > description')] > > > btw: The line to be matched (given below) is ONE line. There are no line > breaks (even though my email client adds them). > > > matt > > > If a group matches multiple times, only the last match is accessible. The matches returned represent the inner groupings of the last match found. JB-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at gonnerman.org Thu Aug 18 23:45:50 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Thu, 18 Aug 2011 22:45:50 -0500 Subject: [Python] Re: Windows service in production? In-Reply-To: <4E4BB152.5020904@timgolden.me.uk> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com> <4E4BB152.5020904@timgolden.me.uk> Message-ID: <4E4DDC6E.9010405@gonnerman.org> Chiming in late here, but I've been running a very simple Python service for some time now on a number of computers. It's my Raw Print Server, available at http://newcenturycomputers.net/projects/rawprintserver.html, and I have instructions on the page for installing the Windows service version. It's really quite simple to do in plain Python; the only reason to use py2exe is if you don't want to install a full Python interpreter on the computer. But since I generally do anyway, it doesn't matter to me. -- Chris. From tjreedy at udel.edu Fri Aug 19 00:03:52 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Aug 2011 00:03:52 -0400 Subject: List spam In-Reply-To: <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <8762lu64he.fsf@dpt-info.u-strasbg.fr> <4e4dc604$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/18/2011 10:10 PM, Steven D'Aprano wrote: > Now, an ISP might not have the bandwidth to supply all the needs of their > customers, that's a separate issue. But complaining that the problem is > specifically because they use bittorrent, as if it would disappear if they > changed to HTTP, is bogus. Or changed to getting their movies via NetFlix, for instance, as Comcast *is* complaining about. I believe their real complaint is that they are only paid to move bits, and not for originating them, even though they already get several times as much per month as NetFlix. -- Terry Jan Reedy From me+list/python at ixokai.io Fri Aug 19 01:00:30 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 18 Aug 2011 22:00:30 -0700 Subject: Windows service in production? In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> Message-ID: <4E4DEDEE.5070805@ixokai.io> On 8/15/11 9:32 PM, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. > > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. Overall, reading about Windows > services in Python is not exactly a confidence inspiring experience. > If I knew of a reference example of something reliably running in > production, I'd feel better than copying and pasting some code from a > guy's blog. Belatedly: I run a few quite major windows services which are installed at various customer sites in production, and we have no issues with it being a windows service. I basically only ever ran into two problems: 1. The lack of a console. Your service flat out /does not have/ a console, which is a slightly weird state to be in: writing to sys.stdout will fail. A print statement left in can crash things up -- even if in third-party code. Now, once you realize this is there, its easy to "fix". I end up doing something like this very early on in processing: class FakeFile: def __init__(self, fp): self._fp = fp def write(self, data): try: self._fp.write(data) except: pass # repeat with flush() sys.stdout = FakeFile(sys.stdout) sys.stderr = FakeFile(sys.stderr) That way it'll run from a regular terminal fine and write out fine, but if any stray attempts to print are left in, things will pass through fine when its running as a service. 2. Importing modules with the same names as dlls in system32 can go awry. I don't know if this is still there, I last touched this part of our code a long, long, long time ago: but my service does some manual PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy to do. It worked fine, and was stable and once going, everything worked fine. Ultimately, I have since abandoned running things as a real service directly, and wrote a "Metaservice" application we use in our company instead. It runs as a service, and executes any random series of programs beneath it, creating JOB's for each so any subprocesses of they launch all get killed together cleanly, and handling dependencies via between them through various means, and stuff like that. I just got tired of dealing with windows stuff, so. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From adam.jorgensen.za at gmail.com Fri Aug 19 01:21:25 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Fri, 19 Aug 2011 07:21:25 +0200 Subject: Windows service in production? In-Reply-To: <4E4DEDEE.5070805@ixokai.io> References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> <4E4DEDEE.5070805@ixokai.io> Message-ID: Yeah, we run our Python App as a service under Windows. You can look at the open-souce part of our product using http://trac.sjsoft.com/browser If you look into the code you should be able to find some stuff to do with services. Specficially, look in trunk/j5/src/j5/OS/WinService.py On 19 August 2011 07:00, Stephen Hansen wrote: > On 8/15/11 9:32 PM, snorble wrote: > > Anyone know of a Python application running as a Windows service in > > production? I'm planning a network monitoring application that runs as > > a service and reports back to the central server. Sort of a heartbeat > > type agent to assist with "this server is down, go check on it" type > > situations. > > > > If using Visual Studio and C# is the more reliable way, then I'll go > > that route. I love Python, but everything I read about Python services > > seems to have workarounds ahoy for various situations (or maybe that's > > just Windows services in general?). And there seem to be multiple > > layers of workarounds, since it takes py2exe (or similar) and there > > are numerous workarounds required there, depending on which libraries > > and functionality are being used. Overall, reading about Windows > > services in Python is not exactly a confidence inspiring experience. > > If I knew of a reference example of something reliably running in > > production, I'd feel better than copying and pasting some code from a > > guy's blog. > > Belatedly: I run a few quite major windows services which are installed > at various customer sites in production, and we have no issues with it > being a windows service. > > I basically only ever ran into two problems: > > 1. The lack of a console. Your service flat out /does not have/ a > console, which is a slightly weird state to be in: writing to sys.stdout > will fail. A print statement left in can crash things up -- even if in > third-party code. > > Now, once you realize this is there, its easy to "fix". I end up > doing something like this very early on in processing: > > class FakeFile: > def __init__(self, fp): > self._fp = fp > def write(self, data): > try: > self._fp.write(data) > except: > pass > > # repeat with flush() > > sys.stdout = FakeFile(sys.stdout) > sys.stderr = FakeFile(sys.stderr) > > That way it'll run from a regular terminal fine and write out fine, > but if any stray attempts to print are left in, things will pass through > fine when its running as a service. > > 2. Importing modules with the same names as dlls in system32 can go > awry. I don't know if this is still there, I last touched this part of > our code a long, long, long time ago: but my service does some manual > PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy > to do. > > It worked fine, and was stable and once going, everything worked fine. > > Ultimately, I have since abandoned running things as a real service > directly, and wrote a "Metaservice" application we use in our company > instead. It runs as a service, and executes any random series of > programs beneath it, creating JOB's for each so any subprocesses of they > launch all get killed together cleanly, and handling dependencies via > between them through various means, and stuff like that. I just got > tired of dealing with windows stuff, so. :) > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adiksonline at gmail.com Fri Aug 19 03:39:54 2011 From: adiksonline at gmail.com (Kingsley Adio) Date: Fri, 19 Aug 2011 00:39:54 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <1f26ef99-857c-455e-ae5f-c3dd7c19a4d2@v9g2000pri.googlegroups.com> noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! red="a string" one="another string" maple="a file path" old=["red", "one", "maple"] newList=map(eval, old) From fetchinson at googlemail.com Fri Aug 19 04:17:01 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 19 Aug 2011 10:17:01 +0200 Subject: OT Message-ID: I'll be 59 in a couple of months. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From stefan_ml at behnel.de Fri Aug 19 04:29:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Aug 2011 10:29:50 +0200 Subject: OT In-Reply-To: References: Message-ID: Daniel Fetchinson, 19.08.2011 10:17: > I'll be 59 in a couple of months. That's actually more on topic for one of the alt.test newsgroups. Stefan From aspineux at gmail.com Fri Aug 19 05:11:07 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 19 Aug 2011 02:11:07 -0700 (PDT) Subject: Word Perfect integration References: Message-ID: On Aug 18, 7:00?pm, Ethan Furman wrote: > I have WordPerfect v13 which we are currently using for letter merges. > I would like to automate this with Python instead of learning the WP > Macro language. > > Does anyone have any pointers? > paper letter or eletronic mail merger ? What you need is : - 1. write a "template" in WP with tag like
- 2. make a database with the corresponding data - 3. replace tag by data from a database, and generate a new WP document - 4. print all these ducument. 1 & 2 are not programming related 3. Should not be impossible, look at the wp binary file if you can find and replace the tag 4. More difficult: can you start a print job from a command line ? or put all file in a directory, then start WP and ask him to print all file in this directory or create print job and put them in a queue and hope WP will process the queue. Regards > ~Ethan~ Alain From alec.taylor6 at gmail.com Fri Aug 19 05:11:18 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 19 Aug 2011 19:11:18 +1000 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: :P Personally, I use LaTeX, which fits all my requirements. On Fri, Aug 19, 2011 at 5:24 AM, Ethan Furman wrote: > Alec Taylor wrote: >> >> wow, people still use WordPerfect? > > Them's fightin' words right there! ?:) > > Yes, we still use Word Perfect, and will as long as it is available. The > ability to see the codes in use (bold, margins, columns, etc) has so far > been unequaled in anything else I have looked at. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From pwoolcoc at gmail.com Fri Aug 19 06:14:11 2011 From: pwoolcoc at gmail.com (Paul Woolcock) Date: Fri, 19 Aug 2011 06:14:11 -0400 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: If you really want __setitem__ and not __setattr__, you should change the base class to 'dict'. Or 'import UserDict' and use that for the base class. On Aug 18, 2011 9:45 PM, "luvspython" wrote: > I'm using Python 2.7 and the code below fails at the 'super' statement > in the __setitem__ function in the HistoryKeeper class. The error is: > 'super' object has no attribute '_setitem__' > > Can anyone please tell me why and how to fix it? (I've googled > endlessly and I don't see the problem.) > > [The code will seem silly as it is, because it's pared down to show > the example. The goal is that multiple classes, like the Vehicle > class below, will inherit HistoryKeeper. History keeper overloads > __setitem__ and will eventually keep a running history every time an > attribute of any of the inheriting classes is changed.] > > Thanks in advance .... > > > class HistoryKeeper(object): > def __init__(self, args): > for arg, value in args.items(): > if arg != 'self': > self.__setitem__(arg, value) > > def __setitem__(self, item, value): > super(HistoryKeeper, self).__setitem__(item, value) > > > class Vehicle(HistoryKeeper): > def __init__(self, tag, make, model): > args = locals() > super(Vehicle, self).__init__(args) > > > if __name__ == "__main__": > car = Vehicle('TAG123', 'FORD', 'Model A') > print car.make > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Aug 19 08:57:54 2011 From: roy at panix.com (Roy Smith) Date: Fri, 19 Aug 2011 08:57:54 -0400 Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: In article <2ab25f69-6017-42a6-a7ef-c71bc2ee8547 at l2g2000vbn.googlegroups.com>, noydb wrote: > How would you convert a list of strings into a list of variables using > the same name of the strings? > > So, ["red", "one", "maple"] into [red, one, maple] > > Thanks for any help! I'm not sure what you're trying to do, but explore the dictionary returned by locals(). You can do something like: loc = locals() [loc["red"], loc["one"], loc["maple"]] From ekh.johan at gmail.com Fri Aug 19 09:00:38 2011 From: ekh.johan at gmail.com (Johan Ekh) Date: Fri, 19 Aug 2011 15:00:38 +0200 Subject: Execute script from ipython Message-ID: Hi all, I have a script "myscript.py" located in "/usr/local/bin" on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Best regards, Johan -------------- next part -------------- An HTML attachment was scrubbed... URL: From matze999 at gmail.com Fri Aug 19 10:09:16 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 08:09:16 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> Message-ID: <201108190809.17040.matze999@gmail.com> Hi Josh, thanks for the reply. I am no expert so please bear with me: I thought that the {32} was supposed to match the previous expression 32 times? So how can i have all matches accessible to me? matt On Thursday, August 18, 2011, Josh Benner wrote: > On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk wrote: > > Hi guys, > > > > thanks for the suggestions. I had tried the white space before as well > > (to no > > avail). So here is the expression i am using (based on suggestions), but > > still > > no success: > > > > instance_linetype_pattern_str =\ > > > > r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' > > > > instance_linetype_pattern = re.compile(instance_linetype_pattern_str) > > results = instance_linetype_pattern.findall(line) > > print "results: "; print results > > > > > > The match i get is: > > results: > > [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: > > 0)\t:\tsome description')] > > > > > > btw: The line to be matched (given below) is ONE line. There are no line > > breaks (even though my email client adds them). > > > > > > matt > > If a group matches multiple times, only the last match is accessible. The > matches returned represent the inner groupings of the last match found. > > JB-) From jenn.duerr at gmail.com Fri Aug 19 10:32:14 2011 From: jenn.duerr at gmail.com (noydb) Date: Fri, 19 Aug 2011 07:32:14 -0700 (PDT) Subject: How to convert a list of strings into a list of variables References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> Message-ID: <89a096bb-4aaa-4d21-81e2-4beecc1784b9@ea4g2000vbb.googlegroups.com> Thanks to all for your responses! Good lessons. I implemented something like what Jerry Hill suggested (dictionary), which works well for my purposes. The list of strings that is being passed into this code is also provided by something I wrote so I do trust what is being sent. Might use what AB suggested down the line, as tool expands. Thanks! From jason at powerpull.net Fri Aug 19 10:41:49 2011 From: jason at powerpull.net (Jason Friedman) Date: Fri, 19 Aug 2011 14:41:49 +0000 Subject: Help with regular expression in python In-Reply-To: <201108190809.17040.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: > Hi Josh, > thanks for the reply. I am no expert so please bear with me: > I thought that the {32} was supposed to match the previous expression 32 > times? > > So how can i have all matches accessible to me? $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description' >>> import re >>> re.findall(r"\d\.\d+e\+\d+", data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From lzlu123 at gmail.com Fri Aug 19 11:00:21 2011 From: lzlu123 at gmail.com (lzlu123) Date: Fri, 19 Aug 2011 08:00:21 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell Message-ID: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> I have an instrument that has a RS232 type serial comm port and I need to connect to and control. I use Python 3.2 in Windows XP, plus pySerial module. I have a problem when I execute a script consisting of statements that open the comm port, configure it, write strings to and receive strings from it. Thoese strings aer either commands pertinent to the instrument (control) or responses from the instrument (response). When those statements are executed in a python interpreter interactively (at >>>), I get what I expect and the results are good and correct. However, when I execute the script, either being invoked within the interpreter or run file, I don?t get what I want. The statements in the script is the same as what I use in the interactive interpreter. Why do I get the strange behavior and how can I change the script to make it to behave like in interactive interpreter? ----------------------script----------------------- def read(comport): wrt_str=b'movt 3000'+b'\r\n' ret_str=comport.write(wrt_str) wrt_str=b'scan'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines() #########1 wrt_str=b'hllo'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines()#########2 ---------------------------------------------------------- The problem is with the lines above with #######. In interactive mode, there is about 1 second delay at #1, and 9 seonds delay at #2. I get correct responses there. However, if I execute the script above, there is no delay at all and I get incorrect results (garbage). I set the read timeout to 0 in comm port set up, as comport.timeout=0 So the comport should be in blocking mode if it waits for the end of line or end of file. I tried many things, like exec (execfile in 2.7), but at no avail. I have an update to the original post I made a few days ago. I think I know what the problem is and want to know if anyone has a solution: After putting "print" and "time.sleep(delay)" after every statement, I found when the script is running, it appears going around the pyserial statement, such as "comport.write(..)" or "comport.readlines(...)" while the pyserial command is executing (appearing as waiting and busying doing some thing, you know serial port is slow). So for example, when I exec all statements in a python interactive shell, I am not able to type and run a new statement if the previous one is not returned. Let's ay, if comport.readlines() is not returning, I can't type and run the next comport.write(...) statemtn. However, in a script that is running, if the comport.readlines() is busy reading, the next statement is running, if the next statement happens to be a comport.write() which will abort the reading. Is there any way to force the python script to behave like running exactly sequentially? From wxjmfauth at gmail.com Fri Aug 19 11:07:51 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 08:07:51 -0700 (PDT) Subject: How to print non-printable chars?? References: <6c15a4a4-02a9-4a04-bd3a-0cb88a96470f@v7g2000vbk.googlegroups.com> Message-ID: <1d1b4ed7-5a08-48fa-b512-62d42ec678ed@m38g2000vbn.googlegroups.com> On 18 ao?t, 22:44, coldpizza wrote: > > > ... > > In a web/html environment or in broken ascii-only consoles like the > one on windows ... C:\Users\Jean-Michel>echo 'Cet ?uf de L?titia co?te un ?uro' 'Cet ?uf de L?titia co?te un ?uro' C:\Users\Jean-Michel>c:\Python27\python Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print 'Cet ?uf de L?titia co?te un ?uro' Cet ?uf de L?titia co?te un ?uro >>> import sys >>> u = unicode('Cet ?uf de L?titia co?te un ?uro', sys.stdin.encoding) >>> print u.encode(sys.stdout.encoding) Cet ?uf de L?titia co?te un ?uro >>> C:\Users\Jean-Michel>c:\Python32\python Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print('Cet ?uf de L?titia co?te un ?uro') Cet ?uf de L?titia co?te un ?uro >>> PS Cet ?uf de L?titia co?te un ?uro -> This L?titia's egg costs one ?uro' PS2 "?" does not require special attention. PS3 To the original question: This not a *coding* issue, it is a character *representation* question. jmf From Yingjie.Lin at mssm.edu Fri Aug 19 11:08:14 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 11:08:14 -0400 Subject: HTML client sctript Message-ID: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically "uses" this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Thank you. - Yingjie From clp2 at rebertia.com Fri Aug 19 11:11:38 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 08:11:38 -0700 Subject: Execute script from ipython In-Reply-To: References: Message-ID: On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > Hi all, > I have a script "myscript.py" located in "/usr/local/bin" on my linux box. > I can execute it in ipython with > > run /usr/local/bin/myscript.py > > but not with > > run myscript.py > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > What should I do to correct this? Given that %run takes a filename and not a module name, I doubt PYTHONPATH matters. ipython's docs for %run don't seem to indicate that a search of any kind is performed. So, I'd say you have to either pass a valid absolute or relative path to myscript.py, or run myscript.py from bash instead of ipython. Changing your script's shebang line to ipython might also work (haven't tried it myself). Or you could try patching ipython's run() function to add this search feature you desire. Cheers, Chris -- http://rebertia.com From matze999 at gmail.com Fri Aug 19 11:20:16 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 09:20:16 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: <4E4E7F30.7010205@gmail.com> Hi, thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. anyway, thanks though matt On 8/19/2011 8:41 AM, Jason Friedman wrote: >> Hi Josh, >> thanks for the reply. I am no expert so please bear with me: >> I thought that the {32} was supposed to match the previous expression 32 >> times? >> >> So how can i have all matches accessible to me? > $ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> data > '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > 2.150000e+01 2.199000e+01 : (instance: 0) : some > description' >>>> import re >>>> re.findall(r"\d\.\d+e\+\d+", data) > ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', > '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', > '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', > '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', > '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', > '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', > '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', > '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From ppv.grps at gmail.com Fri Aug 19 11:31:06 2011 From: ppv.grps at gmail.com (Forafo San) Date: Fri, 19 Aug 2011 08:31:06 -0700 (PDT) Subject: Replacement for the shelve module? Message-ID: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an "ls" did not make sense, etc.). Thanks in advance for your suggestions. From kwatford at gmail.com Fri Aug 19 11:49:38 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 19 Aug 2011 11:49:38 -0400 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Fri, Aug 19, 2011 at 11:31 AM, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: For what you're doing, I would give PyTables a try. From wxjmfauth at gmail.com Fri Aug 19 11:50:51 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 08:50:51 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: On 19 ao?t, 17:20, Matt Funk wrote: > Hi, > thanks for the suggestion. I guess i had found another way around the > problem as well. But i really wanted to match the line exactly and i > wanted to know why it doesn't work. That is less for the purpose of > getting the thing to work but more because it greatly annoys me off that > i can't figure out why it doesn't work. I.e. why the expression is not > matches {32} times. I just don't get it. > re is not always the right tool to be used. Without more precisions: >>> s = '2.201000e+01 2.150000e+01 2.150000e+01\ ... : (instance: 0) : some description' >>> s 2.201000e+01 2.150000e+01 2.150000e+01 : (instance: 0) : some description >>> s[:s.find(':')] 2.201000e+01 2.150000e+01 2.150000e+01 >>> s[:s.find(':')].split() ['2.201000e+01', '2.150000e+01', '2.150000e+01'] >>> >>> jmf From t at jollybox.de Fri Aug 19 11:54:29 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 19 Aug 2011 17:54:29 +0200 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: <4E4E8735.4090509@jollybox.de> On 19/08/11 17:31, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). > > Thanks in advance for your suggestions. Firstly, since when is shelve deprecated? Shouldn't there be a deprecation warning on http://docs.python.org/dev/library/shelve.html ? If you want to keep your current approach of having an object containing all the data for each symbol, you will have to think about how to serialise the data, as well as how to store the documents/objects individually. For the serialisation, you can use pickle (as shelve does) or JSON (probably better because it's easier to edit directly, and therefore easier to debug). To store these documents, you could use a huge pickle'd Python dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; this is what shelve uses), or simple the file system: one file per serialised object. Looking at your use case, however, I think what you really should use is a SQL database. SQLite is part of Python and will do the job nicely. Just use a single table with three columns: symbol, date, value. Thomas From alain at dpt-info.u-strasbg.fr Fri Aug 19 12:00:35 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 19 Aug 2011 18:00:35 +0200 Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <201108181703.06278.matze999@gmail.com> <201108190809.17040.matze999@gmail.com> Message-ID: <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Matt Funk writes: > thanks for the suggestion. I guess i had found another way around the > problem as well. But i really wanted to match the line exactly and i > wanted to know why it doesn't work. That is less for the purpose of > getting the thing to work but more because it greatly annoys me off that > i can't figure out why it doesn't work. I.e. why the expression is not > matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times "a space followed by a number". Using Jason's regexp, you can build the regexp step by step: number = r"\d\.\d+e\+\d+" numbersequence = r"%s( %s){31}" % (number,number) There are better ways to build your regexp, but I think this one is convenient to answer your question. You still have to append what will match the end of the line. -- Alain. P/S: please do not top-post >> $ python >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) >> [GCC 4.4.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> data >> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 >> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 >> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 >> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 >> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 >> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 >> 2.150000e+01 2.199000e+01 : (instance: 0) : some >> description' >>>>> import re >>>>> re.findall(r"\d\.\d+e\+\d+", data) >> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', >> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', >> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', >> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', >> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', >> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', >> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', >> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From gordon at panix.com Fri Aug 19 12:02:27 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 16:02:27 +0000 (UTC) Subject: HTML client sctript References: Message-ID: In Yingjie Lin writes: > Hi Python users, > I am maintaining a website written with Python CGI scripts. To make > sure the website is working well, I would like to have a script which > automatically "uses" this website and checks it's output everyday. It > would be better if this script runs from the clients' side. > Could any one suggest any Python modules, articles, tutorials, ect. that > might be helpful? Mechanize seems like what you want. It's built on top of urllib2. http://wwwsearch.sourceforge.net/mechanize/ -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ppv.grps at gmail.com Fri Aug 19 12:21:48 2011 From: ppv.grps at gmail.com (Forafo San) Date: Fri, 19 Aug 2011 09:21:48 -0700 (PDT) Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Aug 19, 11:54?am, Thomas Jollans wrote: > On 19/08/11 17:31, Forafo San wrote: > > > > > > > > > > > Folks, > > What might be a good replacement for the shelve module, but one that > > can handle a few gigs of data. I'm doing some calculations on daily > > stock prices and the result is a nested list like: > > > [[date_1, floating result 1], > > ?[date_2, floating result 2], > > ... > > ?[date_n, floating result n]] > > > However, there are about 5,000 lists like that, one for each stock > > symbol. Using the shelve module I could easily save them to a file > > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > > data. But shelve is deprecated AND when a lot of data is written > > shelve was acting weird (refusing to write, filesizes reported with an > > "ls" did not make sense, etc.). > > > Thanks in advance for your suggestions. > > Firstly, since when is shelve deprecated? Shouldn't there be a > deprecation warning onhttp://docs.python.org/dev/library/shelve.html? > > If you want to keep your current approach of having an object containing > all the data for each symbol, you will have to think about how to > serialise the data, as well as how to store the documents/objects > individually. For the serialisation, you can use pickle (as shelve does) > or JSON (probably better because it's easier to edit directly, and > therefore easier to debug). > To store these documents, you could use a huge pickle'd Python > dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; > this is what shelve uses), or simple the file system: one file per > serialised object. > > Looking at your use case, however, I think what you really should use is > a SQL database. SQLite is part of Python and will do the job nicely. > Just use a single table with three columns: symbol, date, value. > > Thomas Sorry. There is no indication that shelve is deprecated. I was using it on a FreeBSD system and it turns out that the bsddb module is deprecated and confused it with the shelve module. Thanks Ken and Thomas for your suggestions -- I will play around with both and pick one. From clp2 at rebertia.com Fri Aug 19 12:45:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 09:45:59 -0700 Subject: HTML client sctript In-Reply-To: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> References: <34A58E7B-407E-4399-B72C-4BC116006499@mssm.edu> Message-ID: On Fri, Aug 19, 2011 at 8:08 AM, Yingjie Lin wrote: > Hi Python users, > > I am maintaining a website written with Python CGI scripts. To make sure the website is working well, > I would like to have a script which automatically "uses" this website and checks it's output everyday. It > would be better if this script runs from the clients' side. > > Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Selenium: http://seleniumhq.org/ Cheers, Chris From saraanderson24 at gmail.com Fri Aug 19 12:55:29 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Fri, 19 Aug 2011 09:55:29 -0700 (PDT) Subject: WATCH WORLD MOST HILARIOUS FUNNY VIDEOS EVER. Message-ID: See Worlds Most Beautiful Places Ever. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD MOST HILARIOUS FUNNY VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From fuentesej at gmail.com Fri Aug 19 13:15:20 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 10:15:20 -0700 (PDT) Subject: Help on PyQt4 QProcess Message-ID: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal "finished(int)" of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x="started":print(x)) # connect pro.connect(pro, SIGNAL("finished(int)"), lambda x="finished":print(x)) pro.start('python',['hello.py']) # star hello.py program (contain print("hello world!")) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) I'm using Python 3.2 and PyQt 4.8.4 under winxp 32bit. best regards, From miki.tebeka at gmail.com Fri Aug 19 13:15:53 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 19 Aug 2011 10:15:53 -0700 (PDT) Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: You might check one of many binary encoders (like Avro, Thrift ...). The other option is to use a database, sqlite3 is pretty fast (if you schema is fixed). Otherwise you can look at some NoSQL ones (like MongoDB). From matze999 at gmail.com Fri Aug 19 13:33:49 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 11:33:49 -0600 Subject: Help with regular expression in python In-Reply-To: <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <201108191133.50170.matze999@gmail.com> On Friday, August 19, 2011, Alain Ketterlin wrote: > Matt Funk writes: > > thanks for the suggestion. I guess i had found another way around the > > problem as well. But i really wanted to match the line exactly and i > > wanted to know why it doesn't work. That is less for the purpose of > > getting the thing to work but more because it greatly annoys me off that > > i can't figure out why it doesn't work. I.e. why the expression is not > > matches {32} times. I just don't get it. > > Because a line is not 32 times a number, it is a number followed by 31 > times "a space followed by a number". Using Jason's regexp, you can > build the regexp step by step: > > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}" % (number,number) That didn't work either. Using the (modified (where the (.+) matches the end of the line)) expression as: number = r"\d\.\d+e\+\d+" numbersequence = r"%s( %s){31}(.+)" % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. thanks for all the help matt > > There are better ways to build your regexp, but I think this one is > convenient to answer your question. You still have to append what will > match the end of the line. > > -- Alain. > > P/S: please do not top-post > > >> $ python > >> Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) > >> [GCC 4.4.3] on linux2 > >> Type "help", "copyright", "credits" or "license" for more information. > >> > >>>>> data > >> > >> '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 > >> 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 > >> 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 > >> 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 > >> 2.064000e+01 2.000000e+01 2.200000e+01 2.139000e+01 2.137000e+01 > >> 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.150000e+01 > >> 2.150000e+01 2.199000e+01 : (instance: 0) : some > >> description' > >> > >>>>> import re > >>>>> re.findall(r"\d\.\d+e\+\d+", data) > >> > >> ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', > >> '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', > >> '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', > >> '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', > >> '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', > >> '2.064000e+01', '2.000000e+01', '2.200000e+01', '2.139000e+01', > >> '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', > >> '2.201000e+01', '2.150000e+01', '2.150000e+01', '2.199000e+01'] From robert.kern at gmail.com Fri Aug 19 13:45:32 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Aug 2011 12:45:32 -0500 Subject: Replacement for the shelve module? In-Reply-To: References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On 8/19/11 10:49 AM, Ken Watford wrote: > On Fri, Aug 19, 2011 at 11:31 AM, Forafo San wrote: >> Folks, >> What might be a good replacement for the shelve module, but one that >> can handle a few gigs of data. I'm doing some calculations on daily >> stock prices and the result is a nested list like: > > For what you're doing, I would give PyTables a try. For a few gigs of stock price data, this is what I use. Much better than SQLite for that amount of data. -- 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 phil at riverbankcomputing.com Fri Aug 19 13:56:30 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Fri, 19 Aug 2011 18:56:30 +0100 Subject: Help on PyQt4 QProcess In-Reply-To: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Message-ID: On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes wrote: > Dear friends, > > I need execute an external program from a gui using PyQt4, to avoid > that hang the main thread, i must connect the signal "finished(int)" > of a QProcess to work properly. > > for example, why this program don't work? > > from PyQt4.QtCore import QProcess > pro = QProcess() # create QProcess object > pro.connect(pro, SIGNAL('started()'), lambda > x="started":print(x)) # connect > pro.connect(pro, SIGNAL("finished(int)"), lambda > x="finished":print(x)) > pro.start('python',['hello.py']) # star hello.py program > (contain print("hello world!")) > timeout = -1 > pro.waitForFinished(timeout) > print(pro.readAllStandardOutput().data()) > > output: > > started > 0 > b'hello world!\n' > > see that not emit the signal finished(int) Yes it is, and your lambda slot is printing "0" which is the return code of the process. Phil From sajjad.ahmad009 at gmail.com Fri Aug 19 14:38:34 2011 From: sajjad.ahmad009 at gmail.com (Sajjad Ahmad) Date: Fri, 19 Aug 2011 11:38:34 -0700 (PDT) Subject: Hot Girls are Looking for Sex Message-ID: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . From wxjmfauth at gmail.com Fri Aug 19 14:40:54 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 19 Aug 2011 11:40:54 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> On 19 ao?t, 19:33, Matt Funk wrote: > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. > > Anyway, i think at this point i will go another route. Not sure where the > issues lies at this point. > Seen on this list: And always keep this in mind: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski, comp.lang.emacs I proposed a solution which seems to corresponds to your problem if it were better formulated... jmf From Yingjie.Lin at mssm.edu Fri Aug 19 15:09:12 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:09:12 -0400 Subject: try... except with unknown error types Message-ID: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Hi Python users, I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print "URL does not exist!" Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using "HTTPError" alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. - Yingjie From gordon at panix.com Fri Aug 19 15:14:54 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 19:14:54 +0000 (UTC) Subject: try... except with unknown error types References: Message-ID: In Yingjie Lin writes: > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > Though "urllib2.HTTPError" is the error type reported by Python, Python > doesn't recognize it as an error type name. I tried using "HTTPError" > alone too, but that's not recognized either. Have you imported urllib2 in your code? > Does anyone know what error type I should put after the except > statement? or even better: is there a way not to specify the error > types? Thank you. You can catch all exceptions by catching the base class Exception: try: some_method() except Exception, e: print "some error happened, here is the explanation:" print str(e) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From Yingjie.Lin at mssm.edu Fri Aug 19 15:15:04 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:15:04 -0400 Subject: HTML client sctript In-Reply-To: References: Message-ID: <326A894F-F639-4D51-A505-AE98A9DF9BC0@mssm.edu> Hi John and Chris, Thanks for the help. I looked at both and think that mechanize suits my needs better, since it simply needs a python script and doesn't depend on Firefox. Yingjie > From: John Gordon > Mechanize seems like what you want. It's built on top of urllib2.http://wwwsearch.sourceforge.net/mechanize/ > > From: Chris Rebert > Selenium:http://seleniumhq.org/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thudfoo at gmail.com Fri Aug 19 15:22:35 2011 From: thudfoo at gmail.com (xDog Walker) Date: Fri, 19 Aug 2011 12:22:35 -0700 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <201108191222.35687.thudfoo@gmail.com> On Friday 2011 August 19 12:09, Yingjie Lin wrote: > Hi Python users, > > I have been using try...except statements in the situations where I can > expect a certain type of errors might occur. But sometimes I don't exactly > know the possible error types, or sometimes I just can't "spell" the error > types correctly. For example, > > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python > doesn't recognize it as an error type name. I tried using "HTTPError" alone > too, but that's not recognized either. > > Does anyone know what error type I should put after the except statement? > or even better: is there a way not to specify the error types? Thank you. You probably need to import urllib2 before you can use urllib2.HTTPError. Otherwise, you can try using the base class: except Exception, e: -- I have seen the future and I am not in it. From schesis at gmail.com Fri Aug 19 15:30:55 2011 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 19 Aug 2011 15:30:55 -0400 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: : On 19 August 2011 15:09, Yingjie Lin wrote: > > I have been using try...except statements in the situations where I can expect a certain type of errors might occur. > But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. > For example, > > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. > I tried using "HTTPError" alone too, but that's not recognized either. > > Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify > the error types? Thank you. You should always specify the error type, so that your error-handling code won't attempt to handle an error it didn't anticipate and cause even more problems. In this case, I think it's just that you haven't imported HTTPError into your namespace - if you do, it works: >>> from urllib2 import urlopen, HTTPError >>> try: ... response = urlopen("http://google.com/invalid") ... except HTTPError: ... print "URL does not exist!" ... URL does not exist! >>> Alternatively: >>> import urllib2 >>> try: ... response = urllib2.urlopen("http://google.com/invalid") ... except urllib2.HTTPError: ... print "URL does not exist!" ... URL does not exist! >>> A careful look at the difference between these two ought to make it clear what's going on. -[]z. From Yingjie.Lin at mssm.edu Fri Aug 19 15:35:56 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Fri, 19 Aug 2011 15:35:56 -0400 Subject: try... except with unknown error types In-Reply-To: References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <5082D71A-8346-47E4-BD20-DC3A96D949E8@mssm.edu> Hi Zero, I see! This is very helpful. Thank you. - Yingjie On Aug 19, 2011, at 3:30 PM, Zero Piraeus wrote: > : > > On 19 August 2011 15:09, Yingjie Lin wrote: >> >> I have been using try...except statements in the situations where I can expect a certain type of errors might occur. >> But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. >> For example, >> >> try: >> response = urlopen(urljoin(uri1, uri2)) >> except urllib2.HTTPError: >> print "URL does not exist!" >> >> Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. >> I tried using "HTTPError" alone too, but that's not recognized either. >> >> Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify >> the error types? Thank you. > > You should always specify the error type, so that your error-handling > code won't attempt to handle an error it didn't anticipate and cause > even more problems. > > In this case, I think it's just that you haven't imported HTTPError > into your namespace - if you do, it works: > >>>> from urllib2 import urlopen, HTTPError >>>> try: > ... response = urlopen("http://google.com/invalid") > ... except HTTPError: > ... print "URL does not exist!" > ... > URL does not exist! >>>> > > Alternatively: > >>>> import urllib2 >>>> try: > ... response = urllib2.urlopen("http://google.com/invalid") > ... except urllib2.HTTPError: > ... print "URL does not exist!" > ... > URL does not exist! >>>> > > A careful look at the difference between these two ought to make it > clear what's going on. > > -[]z. From srehtvandy at gmail.com Fri Aug 19 15:37:08 2011 From: srehtvandy at gmail.com (Bob Vandy) Date: Fri, 19 Aug 2011 15:37:08 -0400 Subject: 'super' object has no attribute '__setitem__' In-Reply-To: References: <0cf34b02-3ac7-4ad3-a08f-ba8660c0f9b2@en1g2000vbb.googlegroups.com> Message-ID: I'm pretty sure I'd actually read the first 2 links you point to, but the difference between __setattr__ and __setitem__ still never registered with me -- perhaps partly because even the discussion of __setattr__ discusses adding an entry to the "*dictionary* of instance attributes". *MANY* thanks for your help! On Thu, Aug 18, 2011 at 10:07 PM, Eric Snow wrote: > On Thu, Aug 18, 2011 at 7:44 PM, luvspython wrote: > > I'm using Python 2.7 and the code below fails at the 'super' statement > > in the __setitem__ function in the HistoryKeeper class. The error is: > > 'super' object has no attribute '_setitem__' > > > > Can anyone please tell me why and how to fix it? (I've googled > > endlessly and I don't see the problem.) > > > > [The code will seem silly as it is, because it's pared down to show > > the example. The goal is that multiple classes, like the Vehicle > > class below, will inherit HistoryKeeper. History keeper overloads > > __setitem__ and will eventually keep a running history every time an > > attribute of any of the inheriting classes is changed.] > > > > Thanks in advance .... > > > > > > class HistoryKeeper(object): > > def __init__(self, args): > > for arg, value in args.items(): > > if arg != 'self': > > self.__setitem__(arg, value) > > > > def __setitem__(self, item, value): > > super(HistoryKeeper, self).__setitem__(item, value) > > > > > > class Vehicle(HistoryKeeper): > > def __init__(self, tag, make, model): > > args = locals() > > super(Vehicle, self).__init__(args) > > > > > > if __name__ == "__main__": > > car = Vehicle('TAG123', 'FORD', 'Model A') > > print car.make > > Did you mean to use __setattr__ instead? object, the base class of > HistoryKeeper, does not have a __setitem__ method, hence the > AttributeError. super() is a proxy for the next class in the MRO, > typically the base class of your class. > > Keep in mind that is equivalent to > . However, > is equivalent to . > > see: > > http://docs.python.org/reference/datamodel.html#object.__setattr__ > http://docs.python.org/reference/datamodel.html#object.__setitem__ > http://docs.python.org/library/functions.html#super > > -eric > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Fri Aug 19 15:55:01 2011 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 19 Aug 2011 12:55:01 -0700 (PDT) Subject: Help with regular expression in python References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> On 08/19/2011 11:33 AM, Matt Funk wrote: > On Friday, August 19, 2011, Alain Ketterlin wrote: >> Matt Funk writes: >> > thanks for the suggestion. I guess i had found another way around the >> > problem as well. But i really wanted to match the line exactly and i >> > wanted to know why it doesn't work. That is less for the purpose of >> > getting the thing to work but more because it greatly annoys me off that >> > i can't figure out why it doesn't work. I.e. why the expression is not >> > matches {32} times. I just don't get it. >> >> Because a line is not 32 times a number, it is a number followed by 31 >> times "a space followed by a number". Using Jason's regexp, you can >> build the regexp step by step: >> >> number = r"\d\.\d+e\+\d+" >> numbersequence = r"%s( %s){31}" % (number,number) > That didn't work either. Using the (modified (where the (.+) matches the end of > the line)) expression as: > > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}(.+)" % (number,number) > instance_linetype_pattern = re.compile(numbersequence) > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. The secret is buried very unobtrusively in the re docs, where it has caught me out in the past. Specifically in the docs for re.group(): "If a group is contained in a part of the pattern that matched multiple times, the last match is returned." In addition to the findall solution someone else posted, another thing you could do is to explicitly express the groups in your re: number = r"\d\.\d+e\+\d+" groups = (r"( %s)" % number)*31 numbersequence = r"%s%s(.+)" % (number,groups) ... results = match_object.group(range(1,33)) Or (what I would probably do), simply match the whole string of numbers and pull it apart later: number = r"\d\.\d+e\+\d+" numbersequence = r"(%s(?: %s){31})(.+)" % (number,number) results = (match_object.group(1)).split() [none of this code is tested but should be close enough to convey the general idea.] From fuentesej at gmail.com Fri Aug 19 15:55:40 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 12:55:40 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> Message-ID: <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> On Aug 19, 1:56?pm, Phil Thompson wrote: > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > > > > > > > > > wrote: > > Dear friends, > > > I need execute an external program from a gui using PyQt4, to avoid > > that hang the main thread, i must connect the signal "finished(int)" > > of a QProcess to work properly. > > > for example, why this program don't work? > > > ? ?from PyQt4.QtCore import QProcess > > ? ?pro = QProcess() # create QProcess object > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > x="started":print(x)) ? ? ? ?# connect > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > x="finished":print(x)) > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > (contain print("hello world!")) > > ? ?timeout = -1 > > ? ?pro.waitForFinished(timeout) > > ? ?print(pro.readAllStandardOutput().data()) > > > output: > > > ? ?started > > ? ?0 > > ? ?b'hello world!\n' > > > see that not emit the signal finished(int) > > Yes it is, and your lambda slot is printing "0" which is the return code > of the process. > > Phil Ok, but the output should be: started b'hello world!\n' finished no?. thanks Phil From johnny.venter at zoho.com Fri Aug 19 16:02:18 2011 From: johnny.venter at zoho.com (johnny.venter) Date: Fri, 19 Aug 2011 13:02:18 -0700 Subject: Python Windows Extensions for Mac Message-ID: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. From pavlovevidence at gmail.com Fri Aug 19 16:11:58 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Aug 2011 13:11:58 -0700 (PDT) Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> Message-ID: On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: > number = r"\d\.\d+e\+\d+" > numbersequence = r"%s( %s){31}(.+)" % (number,number) > instance_linetype_pattern = re.compile(numbersequence) > > The results obtained are: > results: > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > so this matches the last number plus the string at the end of the line, but no > retaining the previous numbers. > > Anyway, i think at this point i will go another route. Not sure where the > issues lies at this point. I think the problem is that repeat counts don't actually repeat the groupings; they just repeat the matchings. Take this expression: r"(\w+\s*){2}" This will match exactly two words separated by whitespace. But the match result won't contain two groups; it'll only contain one group, and the value of that group will match only the very last thing repeated: Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m = re.match(r"(\w+\s*){2}","abc def") >>> m.group(1) 'def' So you see, the regular expression is doing what you think it is, but the way it forms groups is not. Just a little advice (I know you've found a different method, and that's good, this is for the general reader). The functions re.findall and re.finditer could have helped here, they find all the matches in a string and let you iterate through them. (findall returns the strings matched, and finditer returns the sequence of match objects.) You could have done something like this: row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] And regexp matching is often overkill for a particular problem; this may be of them. line.split() could have been sufficient: row = [ float(x) for x in line.split() ] Of course, these solutions don't account for the case where you have lines, some of which aren't 32 floating-point numbers. You need extra error handling for that, but you get the idea. Carl Banks From steve+comp.lang.python at pearwood.info Fri Aug 19 16:13:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:13:57 +1000 Subject: try... except with unknown error types References: Message-ID: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In Yingjie Lin > writes: > >> try: >> response = urlopen(urljoin(uri1, uri2)) >> except urllib2.HTTPError: >> print "URL does not exist!" > >> Though "urllib2.HTTPError" is the error type reported by Python, Python >> doesn't recognize it as an error type name. I tried using "HTTPError" >> alone too, but that's not recognized either. > > Have you imported urllib2 in your code? Good question. If Python "doesn't recognize it as an error type name", there is a reason for that. Exceptions are exactly the same as every other name: >>> foo.spam Traceback (most recent call last): File "", line 1, in NameError: name 'foo' is not defined >>> urllib2.HTTPError Traceback (most recent call last): File "", line 1, in NameError: name 'urllib2' is not defined >> Does anyone know what error type I should put after the except >> statement? or even better: is there a way not to specify the error >> types? Thank you. > > You can catch all exceptions by catching the base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. -- Steven From msarro at gmail.com Fri Aug 19 16:17:49 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 16:17:49 -0400 Subject: Hot Girls are Looking for Sex In-Reply-To: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: That's great - but do they program in python? On Fri, Aug 19, 2011 at 2:38 PM, Sajjad Ahmad wrote: > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > See All details on > > http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html > > . > > -- > http://mail.python.org/mailman/listinfo/python-list > From pavlovevidence at gmail.com Fri Aug 19 16:21:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Aug 2011 13:21:30 -0700 (PDT) Subject: Help on PyQt4 QProcess In-Reply-To: <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> Message-ID: <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > On Aug 19, 1:56?pm, Phil Thompson > wrote: > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > wrote: > > > Dear friends, > > > > > I need execute an external program from a gui using PyQt4, to avoid > > > that hang the main thread, i must connect the signal "finished(int)" > > > of a QProcess to work properly. > > > > > for example, why this program don't work? > > > > > ? ?from PyQt4.QtCore import QProcess > > > ? ?pro = QProcess() # create QProcess object > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > > x="started":print(x)) ? ? ? ?# connect > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > > x="finished":print(x)) > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > > (contain print("hello world!")) > > > ? ?timeout = -1 > > > ? ?pro.waitForFinished(timeout) > > > ? ?print(pro.readAllStandardOutput().data()) > > > > > output: > > > > > ? ?started > > > ? ?0 > > > ? ?b'hello world!\n' > > > > > see that not emit the signal finished(int) > > > > Yes it is, and your lambda slot is printing "0" which is the return code > > of the process. > > > > Phil > > Ok, but the output should be: > > started > b'hello world!\n' > finished > > no?. > > thanks Phil Two issues. First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. Anyway, to fix that, try this: pro.connect(pro, SIGNAL("finished(int)"), lambda v, x="finished":print(x)) Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of "finished". Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). Carl Banks From gordon at panix.com Fri Aug 19 16:24:38 2011 From: gordon at panix.com (John Gordon) Date: Fri, 19 Aug 2011 20:24:38 +0000 (UTC) Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > > You can catch all exceptions by catching the base class Exception: > Except that is nearly always poor advice, because it catches too much: it > hides bugs in code, as well as things which should be caught. > You should always catch the absolute minimum you need to catch. I agree, but it did seem to be exactly what he was asking for. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From philip at semanchuk.com Fri Aug 19 16:25:44 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 19 Aug 2011 16:25:44 -0400 Subject: Hot Girls are Looking for Sex In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <5D3D75CC-76B5-436F-918E-E411075A17F1@semanchuk.com> On Aug 19, 2011, at 4:17 PM, Matty Sarro wrote: > That's great - but do they program in python? Please don't repost URLs sent by a spammer. Only Google truly knows how its algorithm works, but the general consensus is that the more times Google sees a link repeated, the more credibility the link is given. By reposting links, you help the spammer. From steve+comp.lang.python at pearwood.info Fri Aug 19 16:36:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:36:49 +1000 Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. You might save some memory by using tuples rather than lists: >>> sys.getsizeof(["01/01/2000", 123.456]) # On a 32-bit system. 40 >>> sys.getsizeof(("01/01/2000", 123.456)) 32 By the way, you know that you should never, ever use floats for currency, right? http://vladzloteanu.wordpress.com/2010/01/11/why-you-shouldnt-use-float-for-currency-floating-point-issues-explained-for-ruby-and-ror/ http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency > Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated It certainly is not. http://docs.python.org/library/shelve.html http://docs.python.org/py3k/library/shelve.html Not a word about it being deprecated in either Python 2.x or 3.x. > AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). I would like to see this replicated. If it is true, that's a bug in shelve, but I expect you're probably doing something wrong. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 19 16:43:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:43:13 +1000 Subject: Stop quoting spam [was Re: Hot Girls ...] References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Matty Sarro wrote: > That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your "joke" I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your "joke" was so worth it. Not. [spam deleted] -- Steven From python at mrabarnett.plus.com Fri Aug 19 16:43:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Aug 2011 21:43:55 +0100 Subject: Help with regular expression in python In-Reply-To: <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> References: <201108181349.54727.matze999@gmail.com> <87hb5d4cik.fsf@dpt-info.u-strasbg.fr> <58c66ba7-daf6-4e98-ba26-e054d9fde5f0@z17g2000vbp.googlegroups.com> Message-ID: <4E4ECB0B.9080806@mrabarnett.plus.com> On 19/08/2011 20:55, rurpy at yahoo.com wrote: > On 08/19/2011 11:33 AM, Matt Funk wrote: >> On Friday, August 19, 2011, Alain Ketterlin wrote: >>> Matt Funk writes: >>>> thanks for the suggestion. I guess i had found another way around the >>>> problem as well. But i really wanted to match the line exactly and i >>>> wanted to know why it doesn't work. That is less for the purpose of >>>> getting the thing to work but more because it greatly annoys me off that >>>> i can't figure out why it doesn't work. I.e. why the expression is not >>>> matches {32} times. I just don't get it. >>> >>> Because a line is not 32 times a number, it is a number followed by 31 >>> times "a space followed by a number". Using Jason's regexp, you can >>> build the regexp step by step: >>> >>> number = r"\d\.\d+e\+\d+" >>> numbersequence = r"%s( %s){31}" % (number,number) >> That didn't work either. Using the (modified (where the (.+) matches the end of >> the line)) expression as: >> >> number = r"\d\.\d+e\+\d+" >> numbersequence = r"%s( %s){31}(.+)" % (number,number) >> instance_linetype_pattern = re.compile(numbersequence) >> >> The results obtained are: >> results: >> [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] >> so this matches the last number plus the string at the end of the line, but no >> retaining the previous numbers. > > The secret is buried very unobtrusively in the re docs, > where it has caught me out in the past. Specifically > in the docs for re.group(): > > "If a group is contained in a part of the pattern that > matched multiple times, the last match is returned." > [snip] There's a regex implementation on PyPI: http://pypi.python.org/pypi/regex which does support capturing all of the matches of a group. From steve+comp.lang.python at pearwood.info Fri Aug 19 16:45:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 06:45:36 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4ecb70$0$29990$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In <4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano > writes: > >> > You can catch all exceptions by catching the base class Exception: > >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. > >> You should always catch the absolute minimum you need to catch. > > I agree, but it did seem to be exactly what he was asking for. Sure, but if we're giving advice to somebody who is clearly a beginner (doesn't even know how to deal with a simple NameError from failing to import a module), it is our responsibility to teach *good* habits, not to teach him to be a crap programmer. Even if you don't think it's the ethical thing to do, consider that someday you might be maintaining code written by the OP :) -- Steven From rodrick.brown at gmail.com Fri Aug 19 17:10:49 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 19 Aug 2011 17:10:49 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From rodrick.brown at gmail.com Fri Aug 19 17:10:49 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Fri, 19 Aug 2011 17:10:49 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From msarro at gmail.com Fri Aug 19 17:12:40 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 17:12:40 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: It was a joke, no need to be a prick about it. If you're that offended then spend the cycles fixing the damn list so it stops having so much spam. You realize spam comes in almost constantly, right? Enough that multiple tines over the past weeks there have been no less than 3 threads about it. If php, red hat, and perl can manage it for their lists, why not python? Is that a statement about python programmers? God forbid I try to make a joke. Grow up. On Aug 19, 2011 4:46 PM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > Matty Sarro wrote: > >> That's great - but do they program in python? > > Thanks for that, I didn't see the spam the first time, but thanks to > your "joke" I saw it now! I really appreciate that, because I LOVE to have > spam sent to me, including all the URLs. An extra bonus is that when the > posting is archived on a couple of dozen websites, this will boost the > spammer's Google rankings. > > Thanks heaps! Your "joke" was so worth it. > > Not. > > > > [spam deleted] > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Aug 19 17:16:42 2011 From: msarro at gmail.com (Matty Sarro) Date: Fri, 19 Aug 2011 17:16:42 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: Glad someone has a sense of humor :) If one person smiled I consider it a success. Happy weekend! On Aug 19, 2011 5:12 PM, "Rodrick Brown" wrote: > It's not the end of the world calm down I thought it was quite funny for a friday joke! > > Sent from my iPhone > > On Aug 19, 2011, at 4:43 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > >> Matty Sarro wrote: >> >>> That's great - but do they program in python? >> >> Thanks for that, I didn't see the spam the first time, but thanks to >> your "joke" I saw it now! I really appreciate that, because I LOVE to have >> spam sent to me, including all the URLs. An extra bonus is that when the >> posting is archived on a couple of dozen websites, this will boost the >> spammer's Google rankings. >> >> Thanks heaps! Your "joke" was so worth it. >> >> Not. >> >> >> >> [spam deleted] >> >> >> -- >> Steven >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From matze999 at gmail.com Fri Aug 19 17:21:58 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 15:21:58 -0600 Subject: Help with regular expression in python In-Reply-To: <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> References: <201108181349.54727.matze999@gmail.com> <2cd0c530-4b1c-4b50-8c9c-12a2fb8d004a@l7g2000vbz.googlegroups.com> Message-ID: <201108191521.58499.matze999@gmail.com> On Friday, August 19, 2011, jmfauth wrote: > On 19 ao?t, 19:33, Matt Funk wrote: > > The results obtained are: > > results: > > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > > so this matches the last number plus the string at the end of the line, > > but no retaining the previous numbers. > > > > Anyway, i think at this point i will go another route. Not sure where the > > issues lies at this point. > > Seen on this list: > > And always keep this in mind: > 'Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems.' > --Jamie Zawinski, comp.lang.emacs > > > I proposed a solution which seems to corresponds to your problem > if it were better formulated... Agreed, and i will probably take your proposed route or a similar one. However, i still won't know WHY it didn't work. I would really LIKE to know why, simply because it tickles me. matt > > jmf From mwilson at the-wire.com Fri Aug 19 17:22:42 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 19 Aug 2011 17:22:42 -0400 Subject: try... except with unknown error types References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: xDog Walker wrote: > On Friday 2011 August 19 12:09, Yingjie Lin wrote: [ ... ] >> Does anyone know what error type I should put after the except statement? >> or even better: is there a way not to specify the error types? Thank you. > > You probably need to import urllib2 before you can use urllib2.HTTPError. > > Otherwise, you can try using the base class: > > except Exception, e: There are maybe better base classes to use. Running the interpreter: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> help (urllib2.HTTPError) will show you class HTTPError(URLError, urllib.addinfourl) | Raised when HTTP error occurs, but also acts like non-error return | | Method resolution order: | HTTPError | URLError | exceptions.IOError | exceptions.EnvironmentError | exceptions.StandardError | exceptions.Exception | exceptions.BaseException > So catching any of urllib2.HTTPError, urllib2.URLError, IOError, EnvironmentError, or StandardError will detect the exception -- with increasing levels of generality. Mel. From fuentesej at gmail.com Fri Aug 19 17:32:12 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Fri, 19 Aug 2011 14:32:12 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 19, 4:21?pm, Carl Banks wrote: > On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > > On Aug 19, 1:56?pm, Phil Thompson > > ?wrote: > > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > > wrote: > > > > Dear friends, > > > > > I need execute an external program from a gui using PyQt4, to avoid > > > > that hang the main thread, i must connect the signal "finished(int)" > > > > of a QProcess to work properly. > > > > > for example, why this program don't work? > > > > > ? ?from PyQt4.QtCore import QProcess > > > > ? ?pro = QProcess() # create QProcess object > > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > > > > x="started":print(x)) ? ? ? ?# connect > > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > > > > x="finished":print(x)) > > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program > > > > (contain print("hello world!")) > > > > ? ?timeout = -1 > > > > ? ?pro.waitForFinished(timeout) > > > > ? ?print(pro.readAllStandardOutput().data()) > > > > > output: > > > > > ? ?started > > > > ? ?0 > > > > ? ?b'hello world!\n' > > > > > see that not emit the signal finished(int) > > > > Yes it is, and your lambda slot is printing "0" which is the return code > > > of the process. > > > > Phil > > > Ok, but the output should be: > > > ? ? started > > ? ? b'hello world!\n' > > ? ? finished > > > no?. > > > thanks Phil > > Two issues. ?First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. ?Anyway, to fix that, try this: > > pro.connect(pro, SIGNAL("finished(int)"), lambda v, x="finished":print(x)) > > Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. ?If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of "finished". > > Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. ?You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). > > Carl Banks Thanks Carl, your intervention was very helpful for me, this solve my semantic error. I need to study more about signal/slots and process. From darcy at druid.net Fri Aug 19 17:35:32 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Aug 2011 17:35:32 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110819173532.21ac05a2@dilbert> On Fri, 19 Aug 2011 17:12:40 -0400 Matty Sarro wrote: > It was a joke, no need to be a prick about it. It was spam. You're the prick. If you think spam is funny it's because you aren't the one that has to spend your time dealing with the fallout. > If you're that offended then spend the cycles fixing the damn list so it Most of us have fixed it. We didn't see the spam until you repeated it. For whatever reason the original message was caught by our filters. You helped the spammer break through. I can assure you though that your attitude means that you won't be able to help them again. I can hear the plonking going on all over the net. Here's another one; *plonk* No point in replying. I won't hear it. Hope you don't have any important questions for the group. It just became more of a read-only list for you. > If php, red hat, and perl can manage it for their lists, why not python? Is > that a statement about python programmers? And that should get you blacklisted by anyone on the cusp. -- 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 Aug 19 17:40:52 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Aug 2011 17:40:52 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110819174052.5fdf7024@dilbert> On Fri, 19 Aug 2011 17:10:49 -0400 Rodrick Brown wrote: > It's not the end of the world calm down I thought it was quite funny for a friday joke! The first message might have been funny (if you are twelve) but the rest were annoying and insulting. -- 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 me+list/python at ixokai.io Fri Aug 19 17:47:04 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 19 Aug 2011 14:47:04 -0700 Subject: try... except with unknown error types In-Reply-To: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> References: <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> Message-ID: <4E4ED9D8.2070809@ixokai.io> On 8/19/11 12:09 PM, Yingjie Lin wrote: > try: > response = urlopen(urljoin(uri1, uri2)) > except urllib2.HTTPError: > print "URL does not exist!" > > Though "urllib2.HTTPError" is the error type reported by Python, Python doesn't recognize it as an error type name. > I tried using "HTTPError" alone too, but that's not recognized either. Exceptions are objects like any other, and they are defined in specific places. Only the standard ones are available everywhere; things like IndexError and AttributeError. See the 'exceptions' module for the standard ones. Everything else, you have to 'grab' the object from where it lives -- in this case, in urllib2. > Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify > the error types? Thank you. You can use a "bare except", like so: try: ... except: ... But avoid it, if you can. Or at least, don't let it become habit-forming: for networking code and interaction with external things, I usually have a bare-except as a final fallback, after trying other more specific things-- but only as a last resort. FWIW, the error hierarchy of url fetching is more then a little bit annoying. My own _request object I end up using for one of our services catches, in order: try: ... except urllib2.HTTPError: except urllib2.URLError: except httplib.BadStatusLine: except httplib.HTTPException: except socket.timeout: except: With each case logging and handling the error in a bit of a different way. (Though most, eventually, resulting in the request being retried -- all in the name of a mandate that this particular bit of code must not, under any circumstances, not ultimately work. Even going so far as to start having hour long waits between retries until the other side is finally up :P) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From matze999 at gmail.com Fri Aug 19 17:55:53 2011 From: matze999 at gmail.com (Matt Funk) Date: Fri, 19 Aug 2011 15:55:53 -0600 Subject: Help with regular expression in python In-Reply-To: References: <201108181349.54727.matze999@gmail.com> Message-ID: <201108191555.53338.matze999@gmail.com> On Friday, August 19, 2011, Carl Banks wrote: > On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: > > number = r"\d\.\d+e\+\d+" > > numbersequence = r"%s( %s){31}(.+)" % (number,number) > > instance_linetype_pattern = re.compile(numbersequence) > > > > The results obtained are: > > results: > > [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] > > so this matches the last number plus the string at the end of the line, > > but no retaining the previous numbers. > > > > Anyway, i think at this point i will go another route. Not sure where the > > issues lies at this point. > > I think the problem is that repeat counts don't actually repeat the > groupings; they just repeat the matchings. Take this expression: > > r"(\w+\s*){2}" I see > > This will match exactly two words separated by whitespace. But the match > result won't contain two groups; it'll only contain one group, and the > value of that group will match only the very last thing repeated: > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import re > >>> m = re.match(r"(\w+\s*){2}","abc def") > >>> m.group(1) > > 'def' > > So you see, the regular expression is doing what you think it is, but the > way it forms groups is not. > > > Just a little advice (I know you've found a different method, and that's > good, this is for the general reader). > > The functions re.findall and re.finditer could have helped here, they find > all the matches in a string and let you iterate through them. (findall > returns the strings matched, and finditer returns the sequence of match > objects.) You could have done something like this: I did use findall but when i tried to match the everything (including the 'some description' part) it did not work. But i think the explanation you gave above matches this case and explains why it did not. > > row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] > > And regexp matching is often overkill for a particular problem; this may be > of them. line.split() could have been sufficient: > > row = [ float(x) for x in line.split() ] > > Of course, these solutions don't account for the case where you have lines, > some of which aren't 32 floating-point numbers. You need extra error > handling for that, but you get the idea. thanks matt > > > Carl Banks From robert.kern at gmail.com Fri Aug 19 18:24:15 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Aug 2011 17:24:15 -0500 Subject: Replacement for the shelve module? In-Reply-To: <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/19/11 3:36 PM, Steven D'Aprano wrote: > By the way, you know that you should never, ever use floats for currency, > right? That's just incorrect. You shouldn't use (binary) floats for many *accounting* purposes, but for many financial/econometric analyses, floats are de rigeur and work much better than decimals (either floating or fixed point). If you are collecting gigs of stock prices, you are much more likely to be doing the latter than the former. -- 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 aspineux at gmail.com Fri Aug 19 18:38:34 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 19 Aug 2011 15:38:34 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: <7849d9ff-f472-49c3-a1ce-0f618a301f06@e7g2000vbw.googlegroups.com> On Aug 19, 5:00?pm, lzlu123 wrote: > I have an instrument that has a RS232 type serial comm port and I need > to connect to and control. I use Python 3.2 in Windows XP, plus > pySerial module. I have a problem when I execute a script consisting > of statements that open the comm port, configure it, write strings to > and receive strings from it. Thoese strings aer either commands > pertinent to the instrument (control) or responses from the instrument > (response). > > When those statements are executed in a python interpreter > interactively (at >>>), I get what I expect and the results are good > and correct. However, when I execute the script, either being invoked > within the interpreter or run file, I don?t get what I want. The > statements in the script is the same as what I use in the interactive > interpreter. > > Why do I get the strange behavior and how can I change the script to > make it to behave like in interactive interpreter? > > ----------------------script----------------------- > def read(comport): > > ? ? wrt_str=b'movt 3000'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? wrt_str=b'scan'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? rsp_str=comport.readlines() #########1 You use readlines() with a s at the end ! * Note that when the serial port was opened with no timeout, that readline() * blocks until it sees a newline (or the specified size is reached) * and that readlines() would never return and therefore refuses to work * (it raises an exception in this case)! > > ? ? wrt_str=b'hllo'+b'\r\n' > ? ? ret_str=comport.write(wrt_str) > > ? ? rsp_str=comport.readlines()#########2 > ---------------------------------------------------------- > > The problem is with the lines above with #######. In interactive mode, > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > correct responses there. However, if I execute the script above, there > is no delay at all and I get incorrect results (garbage). I set the > read timeout to 0 in comm port set up, as > > comport.timeout=0 > So the comport should be in blocking mode if it waits for the end of > line or end of file. Wrong : timeout = None: wait forever timeout = 0: non-blocking mode (return immediately on read) timeout = x: set timeout to x seconds (float allowed) > > I tried many things, like exec (execfile in 2.7), but at no avail. > > I have an update to the original post I made a few days ago. I think I > know what the problem is and want to know if anyone has a solution: > > After putting "print" and "time.sleep(delay)" after every statement, I > found when the script is running, it appears going around the pyserial > statement, such as "comport.write(..)" or "comport.readlines(...)" > while the pyserial command is executing (appearing as waiting and > busying doing some thing, you know serial port is slow). So for > example, when I exec all statements in a python interactive shell, I > am not able to type and run a new statement if the previous one is not > returned. Let's ay, if comport.readlines() is not returning, I can't > type and run the next comport.write(...) statemtn. However, in a > script that is running, if the comport.readlines() is busy reading, > the next statement is running, if the next statement happens to be a > comport.write() which will abort the reading. > > Is there any way to force the python script to behave like running > exactly sequentially? You have some new things to try From drsalists at gmail.com Fri Aug 19 19:21:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 19 Aug 2011 16:21:11 -0700 Subject: Replacement for the shelve module? In-Reply-To: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> Message-ID: On Fri, Aug 19, 2011 at 8:31 AM, Forafo San wrote: > Folks, > What might be a good replacement for the shelve module, but one that > can handle a few gigs of data. I'm doing some calculations on daily > stock prices and the result is a nested list like: > > [[date_1, floating result 1], > [date_2, floating result 2], > ... > [date_n, floating result n]] > > However, there are about 5,000 lists like that, one for each stock > symbol. Using the shelve module I could easily save them to a file > ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the > data. But shelve is deprecated AND when a lot of data is written > shelve was acting weird (refusing to write, filesizes reported with an > "ls" did not make sense, etc.). > I'd probably use a cachedb, though perhaps I'm biased since I wrote it: http://stromberg.dnsalias.org/~dstromberg/cachedb.html It'll allow you to specify functions for serializing and deserializing values (but not keys), and cache a user-specified number of values in virtual memory. IOW, once you instantiate the class, you pretty much get caching and seralizing/deserializing as freebies, without the details of same getting scattered throughout your code. It wraps something like gdbm. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marduk at letterboxes.org Fri Aug 19 19:24:26 2011 From: marduk at letterboxes.org (Albert W. Hopkins) Date: Fri, 19 Aug 2011 19:24:26 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1313796267.11691.6.camel@localhost.localdomain> On Friday, August 19 at 17:12 (-0400), Matty Sarro said: > > If you're that offended then spend the cycles fixing the damn list so > it > stops having so much spam. You realize spam comes in almost > constantly, > right? Enough that multiple tines over the past weeks there have been > no > less than 3 threads about it. For me, the original post ended in my spam box, which means my filter is doing it's job, but when you re-post it, my filter did not regard it as spam. I actually wish it had. Therefore you are an enabler. > If php, red hat, and perl can manage it for their lists, why not > python? Is > that a statement about python programmers? > The python list is (also) a Usenet newsgroup. Usenet is distributed and therefore there is no central place to filter spam (each usenet host would have to have its own filter and what one considers spam another might consider ham)... anyway, that's neither here nor there. Having my own filter usually works. I'm not here to dis you, just to try to help you understand the how/why regarding the re-post and why your attitude about it might give the impression of apathy toward your peer community. From torriem at gmail.com Fri Aug 19 19:59:01 2011 From: torriem at gmail.com (Michael Torrie) Date: Fri, 19 Aug 2011 17:59:01 -0600 Subject: Word Perfect integration In-Reply-To: <4E4D66E1.1050206@stoneleaf.us> References: <4E4D66E1.1050206@stoneleaf.us> Message-ID: <4E4EF8C5.5060909@gmail.com> On 08/18/2011 01:24 PM, Ethan Furman wrote: > Alec Taylor wrote: >> wow, people still use WordPerfect? > > Them's fightin' words right there! :) > > Yes, we still use Word Perfect, and will as long as it is available. > The ability to see the codes in use (bold, margins, columns, etc) has so > far been unequaled in anything else I have looked at. It's too bad LaTeX is so complicated and LyX just never quite worked out for me. From steve+comp.lang.python at pearwood.info Fri Aug 19 21:38:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 11:38:13 +1000 Subject: Replacement for the shelve module? References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> Robert Kern wrote: > On 8/19/11 3:36 PM, Steven D'Aprano wrote: > >> By the way, you know that you should never, ever use floats for currency, >> right? > > That's just incorrect. You shouldn't use (binary) floats for many > *accounting* purposes, but for many financial/econometric analyses, floats > are de rigeur and work much better than decimals (either floating or fixed > point). If you are collecting gigs of stock prices, you are much more > likely to be doing the latter than the former. That makes sense, and I stand corrected. -- Steven From wkxin at qq.com Fri Aug 19 21:59:33 2011 From: wkxin at qq.com (=?ISO-8859-1?B?d3VrZXhpbg==?=) Date: Sat, 20 Aug 2011 09:59:33 +0800 Subject: hello python Message-ID: from china ------------------ designed by wkxin at qq.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 19 22:10:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 12:10:29 +1000 Subject: testing if a list contains a sublist References: Message-ID: <4e4f1794$0$29990$c3e8da3$5496439d@news.astraweb.com> Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? [...] For anyone interested, here's a pair of functions that implement sub-sequence testing similar to str.find and str.rfind: http://code.activestate.com/recipes/577850-search-sequences-for-sub-sequence/ -- Steven From nospam at nospam.com Fri Aug 19 23:06:11 2011 From: nospam at nospam.com (Javier) Date: Sat, 20 Aug 2011 03:06:11 +0000 (UTC) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: Never used it, but I think you can try this: Pexpect - a Pure Python Expect-like module Pexpect is a pure Python Expect-like module. Pexpect makes Python... www.noah.org/python/pexpect/ lzlu123 wrote: > I have an instrument that has a RS232 type serial comm port and I need > to connect to and control. I use Python 3.2 in Windows XP, plus > pySerial module. I have a problem when I execute a script consisting > of statements that open the comm port, configure it, write strings to > and receive strings from it. Thoese strings aer either commands > pertinent to the instrument (control) or responses from the instrument > (response). > > When those statements are executed in a python interpreter > interactively (at >>>), I get what I expect and the results are good > and correct. However, when I execute the script, either being invoked > within the interpreter or run file, I don???t get what I want. The > statements in the script is the same as what I use in the interactive > interpreter. > > Why do I get the strange behavior and how can I change the script to > make it to behave like in interactive interpreter? > > ----------------------script----------------------- > def read(comport): > > wrt_str=b'movt 3000'+b'\r\n' > ret_str=comport.write(wrt_str) > > wrt_str=b'scan'+b'\r\n' > ret_str=comport.write(wrt_str) > > rsp_str=comport.readlines() #########1 > > wrt_str=b'hllo'+b'\r\n' > ret_str=comport.write(wrt_str) > > rsp_str=comport.readlines()#########2 > ---------------------------------------------------------- > > The problem is with the lines above with #######. In interactive mode, > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > correct responses there. However, if I execute the script above, there > is no delay at all and I get incorrect results (garbage). I set the > read timeout to 0 in comm port set up, as > > comport.timeout=0 > So the comport should be in blocking mode if it waits for the end of > line or end of file. > > I tried many things, like exec (execfile in 2.7), but at no avail. > > I have an update to the original post I made a few days ago. I think I > know what the problem is and want to know if anyone has a solution: > > After putting "print" and "time.sleep(delay)" after every statement, I > found when the script is running, it appears going around the pyserial > statement, such as "comport.write(..)" or "comport.readlines(...)" > while the pyserial command is executing (appearing as waiting and > busying doing some thing, you know serial port is slow). So for > example, when I exec all statements in a python interactive shell, I > am not able to type and run a new statement if the previous one is not > returned. Let's ay, if comport.readlines() is not returning, I can't > type and run the next comport.write(...) statemtn. However, in a > script that is running, if the comport.readlines() is busy reading, > the next statement is running, if the next statement happens to be a > comport.write() which will abort the reading. > > Is there any way to force the python script to behave like running > exactly sequentially? From nospam at nospam.com Fri Aug 19 23:17:33 2011 From: nospam at nospam.com (Javier) Date: Sat, 20 Aug 2011 03:17:33 +0000 (UTC) Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: You will lose a lot of people asking/answering interesting stuff, and maybe eventually the list will die. Me (like many people with little free time) seldom post in blogs/forums/mailing lists where I need to register. gene heskett wrote: > That is asking the user to take considerable effort and resources to do > that. What is wrong with the mailing list only approach? From adam.jorgensen.za at gmail.com Sat Aug 20 01:29:47 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Sat, 20 Aug 2011 07:29:47 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: You mean pywin32? They sure don't install on linux so that should give you a clue... On 19 August 2011 22:02, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be > installed on a Mac.THanks. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Aug 20 01:36:01 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Aug 2011 22:36:01 -0700 Subject: Python Windows Extensions for Mac In-Reply-To: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. Your request is nonsensical. pywin32 wraps the Windows API libraries. Mac OS X is not Windows; it does not implement the Windows API. Thus, there is nothing for pywin32 to wrap on a Mac. Square peg, round hole. Cheers, Chris From usenet-nospam at seebs.net Sat Aug 20 01:46:39 2011 From: usenet-nospam at seebs.net (Seebs) Date: 20 Aug 2011 05:46:39 GMT Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <4e4ecb70$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-19, Steven D'Aprano wrote: > Even if you don't think it's the ethical thing to do, consider that someday > you might be maintaining code written by the OP :) A common further conclusion people reach is "but then I will be able to get a job fixing it!" Trust me, this is NOT where you want to go. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ben+python at benfinney.id.au Sat Aug 20 02:07:23 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Aug 2011 16:07:23 +1000 Subject: List spam References: <87d3g26a2r.fsf@dpt-info.u-strasbg.fr> Message-ID: <87ei0gbopw.fsf@benfinney.id.au> Javier writes: > You will lose a lot of people asking/answering interesting stuff, and > maybe eventually the list will die. I don't think it would die, but the chances are greater that it would become insular and further disconnected from the Python community, and hence far less useful. > Me (like many people with little free time) seldom post in > blogs/forums/mailing lists where I need to register. +1 -- \ ?Ignorance more frequently begets confidence than does | `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney From gd.usenet at spamfence.net Sat Aug 20 03:55:53 2011 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sat, 20 Aug 2011 09:55:53 +0200 Subject: Python Windows Extensions for Mac References: <131e3a30d0a.-253971426937368133.-9024547059984293440@zoho.com> Message-ID: In article , Chris Rebert wrote: >On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter wrote: >> >> Hello, I am looking for the Python Windows Extensions to see if they can be >> installed on a Mac.THanks. > >Your request is nonsensical. That's not completely true. >pywin32 wraps the Windows API libraries. >Mac OS X is not Windows; it does not implement the Windows API. Thus, >there is nothing for pywin32 to wrap on a Mac. Again: Not completely true. One could run python under wine and get -- at least a part of -- the Windows API. >Square peg, round hole. wine might be the tool that makes the square peg round. Best regards, G?nther From alec.taylor6 at gmail.com Sat Aug 20 04:16:48 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 20 Aug 2011 18:16:48 +1000 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: <1313796267.11691.6.camel@localhost.localdomain> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: On Sat, Aug 20, 2011 at 9:24 AM, Albert W. Hopkins wrote: > > > On Friday, August 19 at 17:12 (-0400), Matty Sarro said: > >> >> If you're that offended then spend the cycles fixing the damn list so >> it >> stops having so much spam. You realize spam comes in almost >> constantly, >> right? Enough that multiple tines over the past weeks there have been >> no >> less than 3 threads about it. > > For me, the original post ended in my spam box, which means my filter is > doing it's job, but when you re-post it, my filter did not regard it as > spam. ?I actually wish it had. ?Therefore you are an enabler. > > >> If php, red hat, and perl can manage it for their lists, why not >> python? Is >> that a statement about python programmers? >> > > The python list is (also) a Usenet newsgroup. ?Usenet is distributed and > therefore there is no central place to filter spam (each usenet host > would have to have its own filter and what one considers spam another > might consider ham)... anyway, that's neither here nor there. ?Having my > own filter usually works. > > I'm not here to dis you, just to try to help you understand the how/why > regarding the re-post and why your attitude about it might give the > impression of apathy toward your peer community. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I found said joke rather funny :P From debruinjj at gmail.com Sat Aug 20 04:25:18 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 01:25:18 -0700 (PDT) Subject: Compare tuples of different lenght Message-ID: Hi, I have a list of tuples: [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] I would like to compare all the tuples to each other and if one element if found two tuples the smallest tuples is removed from the list. example if tuple 1 and tuple 3 are compare it should find that a single element in each are the same and tuple 1 should be removed resulting in [(12,13),(2,3,4),(8,),(5,6),(7,8,9),] the same for tuple 4 and 6 resulting in [(12,13),(2,3,4),(5,6),(7,8,9),] is this possible as I am having no success. Thanks From phil at riverbankcomputing.com Sat Aug 20 04:36:02 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Sat, 20 Aug 2011 09:36:02 +0100 Subject: Help on PyQt4 QProcess In-Reply-To: References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: <574f70abfc6a2dc96a9bbdcb464f4c23@localhost> On Fri, 19 Aug 2011 14:32:12 -0700 (PDT), Edgar Fuentes wrote: > On Aug 19, 4:21?pm, Carl Banks wrote: >> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: >> > On Aug 19, 1:56?pm, Phil Thompson >> > ?wrote: >> > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes >> > > wrote: >> > > > Dear friends, >> >> > > > I need execute an external program from a gui using PyQt4, to avoid >> > > > that hang the main thread, i must connect the signal >> > > > "finished(int)" >> > > > of a QProcess to work properly. >> >> > > > for example, why this program don't work? >> >> > > > ? ?from PyQt4.QtCore import QProcess >> > > > ? ?pro = QProcess() # create QProcess object >> > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda >> > > > x="started":print(x)) ? ? ? ?# connect >> > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda >> > > > x="finished":print(x)) >> > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py program >> > > > (contain print("hello world!")) >> > > > ? ?timeout = -1 >> > > > ? ?pro.waitForFinished(timeout) >> > > > ? ?print(pro.readAllStandardOutput().data()) >> >> > > > output: >> >> > > > ? ?started >> > > > ? ?0 >> > > > ? ?b'hello world!\n' >> >> > > > see that not emit the signal finished(int) >> >> > > Yes it is, and your lambda slot is printing "0" which is the return >> > > code >> > > of the process. >> >> > > Phil >> >> > Ok, but the output should be: >> >> > ? ? started >> > ? ? b'hello world!\n' >> > ? ? finished >> >> > no?. >> >> > thanks Phil >> >> Two issues. ?First of all, your slot for the finished function does not >> have the correct prototype, and it's accidentally not throwing an >> exception because of your unnecessary use of default arguments. ?Anyway, >> to fix that, try this: >> >> pro.connect(pro, SIGNAL("finished(int)"), lambda v, >> x="finished":print(x)) >> >> Notice that it adds an argument to the lambda (v) that accepts the int >> argument of the signal. ?If you don't have that argument there, the int >> argument goes into x, which is why Python prints 0 instead of "finished". >> >> Second, processess run asynchrously, and because of line-buffering, IO >> can output asynchronously, and so there's no guarantee what order output >> occurs. ?You might try calling the python subprocess with the '-u' switch >> to force unbuffered IO, which might be enough to force synchronous output >> (depending on how signal/slot and subprocess semantics are implemented). >> >> Carl Banks > > Thanks Carl, your intervention was very helpful for me, this solve my > semantic error. I need to study more about signal/slots and process. In which case you should look at the modern, Pythonic connection syntax rather than the old one... pro.started.connect(lambda: print("started")) pro.finished.connect(lambda: print("finished")) Phil From clp2 at rebertia.com Sat Aug 20 04:45:04 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Aug 2011 01:45:04 -0700 Subject: Compare tuples of different lenght In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. So, would [(5,6), (6,7,8)] become [(6,7,8)] ? If no, then I believe you're trying to solve the set covering problem: http://en.wikipedia.org/wiki/Set_cover_problem Cheers, Chris -- http://rebertia.com From debruinjj at gmail.com Sat Aug 20 04:54:56 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 01:54:56 -0700 (PDT) Subject: Compare tuples of different lenght References: Message-ID: <977c304f-98be-4772-9e6c-d3f4caf61a06@v7g2000vbk.googlegroups.com> On Aug 20, 10:45?am, Chris Rebert wrote: > On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > So, would [(5,6), (6,7,8)] become [(6,7,8)] ? > > If no, then I believe you're trying to solve the set covering problem:http://en.wikipedia.org/wiki/Set_cover_problem > > Cheers, > Chris > --http://rebertia.com [(5,6), (6,7,8)] would become [(6,7,8)]. Thanks for the response From debruinjj at gmail.com Sat Aug 20 05:00:42 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 02:00:42 -0700 (PDT) Subject: Compare tuples of different lenght References: Message-ID: On Aug 20, 10:45?am, Chris Rebert wrote: > On Sat, Aug 20, 2011 at 1:25 AM, Jurgens de Bruin wrote: > > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > So, would [(5,6), (6,7,8)] become [(6,7,8)] ? > > If no, then I believe you're trying to solve the set covering problem:http://en.wikipedia.org/wiki/Set_cover_problem > > Cheers, > Chris > --http://rebertia.com [(5,6), (6,7,8)] will indeed become [(6,7,8)] Tanks!! From prakashnn30590 at gmail.com Sat Aug 20 05:06:46 2011 From: prakashnn30590 at gmail.com (prakash prakash) Date: Sat, 20 Aug 2011 02:06:46 -0700 (PDT) Subject: hi Message-ID: <276c9d69-00cc-43ce-b508-cac195642374@r40g2000prf.googlegroups.com> http://123maza.com/65/share551/ From hackingkk at gmail.com Sat Aug 20 05:46:08 2011 From: hackingkk at gmail.com (hackingKK) Date: Sat, 20 Aug 2011 15:16:08 +0530 Subject: Hot Girls are Looking for Sex In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> Message-ID: <4E4F8260.2080606@gmail.com> Well, they might be indented in the right places but i don't know if loops, conditions, functions, if they all happen or not. :) Happy hacking. Krishnakant, On 20/08/11 01:47, Matty Sarro wrote: > That's great - but do they program in python? > > On Fri, Aug 19, 2011 at 2:38 PM, Sajjad Ahmad wrote: >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> See All details on >> >> http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html >> >> . >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From kevin.misc.10 at gmail.com Sat Aug 20 05:52:27 2011 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Sat, 20 Aug 2011 17:52:27 +0800 Subject: Python import search path Message-ID: Hi, This is the directory tree. project ??? sme ??? src ? ??? a.pth ? ??? sss.py ??? test ??? ttt.py I need to import sss.py in ttt.py. Found a few solution in python docs. A. sys.path.append B. add ***.pth file C. edit .../site-packages/site.py I found out that a.pth only works when in directory like /usr/lib/pythonX.Y/site-packages instead of in current directory. I think A is not so pretty, and I don't have root privilege to use B and C. So any both more elegant and practical solutions? Thanks. Kevin Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Aug 20 06:17:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 20 Aug 2011 20:17:39 +1000 Subject: Compare tuples of different lenght References: Message-ID: <4e4f89c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. It's not clear what you mean by "smallest" tuple. Is (8,) smaller than (7,8,9)? I'm going to guess you care only about the length of the tuple, and not the items themselves. Let's start with a couple of helper functions. def compare(t1, t2): 'Return -1 if t1 is "smaller" than t2, 0 if equal, and +1 if "bigger".' if len(t1) < len(t2): return -1 elif len(t1) > len(t2): return 1 else: return 0 def match_any_item(t1, t2): try: s1 = set(t1) s2 = set(t2) return bool(s1 & s2) except TypeError: # Can't convert to sets because at least one item is mutable. # Let's do this the slow(?) way. matched = [x for x in t1 if x in t2] return bool(matched) list_of_tuples = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] flags = [True]*len(list_of_tuples) for i,t1 in enumerate(list_of_tuples): for j in range(i+1, len(list_of_tuples)): t2 = list_of_tuples[j] if match_any_item(t1, t2): n = compare(t1, t2) if n == -1: # Flag t1 to be removed. flags[i] = False elif n == 1: # Flag t2 to be removed. flags[j] = False saved_tuples = [] for t,flag in zip(list_of_tuples, flags): if flag: saved_tuples.append(t) This gives: >>> saved_tuples [(12, 13), (2, 3, 4), (5, 6), (7, 8, 9)] which matches what you wanted: > [(12,13),(2,3,4),(5,6),(7,8,9),] -- Steven From k.sahithi2862 at gmail.com Sat Aug 20 06:42:22 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 20 Aug 2011 03:42:22 -0700 (PDT) Subject: LATEST HOT PICS Message-ID: <8ee6d028-2beb-4db5-b45c-e019c3d570b2@j14g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From debruinjj at gmail.com Sat Aug 20 06:47:29 2011 From: debruinjj at gmail.com (Jurgens de Bruin) Date: Sat, 20 Aug 2011 03:47:29 -0700 (PDT) Subject: Compare tuples of different lenght References: <4e4f89c4$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0d10e8b5-d531-4488-8fa1-2fb306ce215d@e7g2000vbw.googlegroups.com> On Aug 20, 12:17?pm, Steven D'Aprano wrote: > Jurgens de Bruin wrote: > > Hi, > > > I have a list of tuples: > > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > > I would like to compare all the tuples to each other and if one > > element if found two tuples the smallest tuples is removed from the > > list. > > It's not clear what you mean by "smallest" tuple. Is (8,) smaller than > (7,8,9)? > > I'm going to guess you care only about the length of the tuple, and not the > items themselves. > > Let's start with a couple of helper functions. > > def compare(t1, t2): > ? ? 'Return -1 if t1 is "smaller" than t2, 0 if equal, and +1 if "bigger".' > ? ? if len(t1) < len(t2): return -1 > ? ? elif len(t1) > len(t2): return 1 > ? ? else: return 0 > > def match_any_item(t1, t2): > ? ? try: > ? ? ? ? s1 = set(t1) > ? ? ? ? s2 = set(t2) > ? ? ? ? return bool(s1 & s2) > ? ? except TypeError: > ? ? ? ? # Can't convert to sets because at least one item is mutable. > ? ? ? ? # Let's do this the slow(?) way. > ? ? ? ? matched = [x for x in t1 if x in t2] > ? ? ? ? return bool(matched) > > list_of_tuples = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > flags = [True]*len(list_of_tuples) > for i,t1 in enumerate(list_of_tuples): > ? ? for j in range(i+1, len(list_of_tuples)): > ? ? ? ? t2 = list_of_tuples[j] > ? ? ? ? if match_any_item(t1, t2): > ? ? ? ? ? ? n = compare(t1, t2) > ? ? ? ? ? ? if n == -1: > ? ? ? ? ? ? ? ? # Flag t1 to be removed. > ? ? ? ? ? ? ? ? flags[i] = False > ? ? ? ? ? ? elif n == 1: > ? ? ? ? ? ? ? ? # Flag t2 to be removed. > ? ? ? ? ? ? ? ? flags[j] = False > > saved_tuples = [] > for t,flag in zip(list_of_tuples, flags): > ? ? if flag: saved_tuples.append(t) > > This gives: > > >>> saved_tuples > > [(12, 13), (2, 3, 4), (5, 6), (7, 8, 9)] > > which matches what you wanted: > > > [(12,13),(2,3,4),(5,6),(7,8,9),] > > -- > Steven Thanks Steven. This works great!!! Appreciated very much!!! From __peter__ at web.de Sat Aug 20 07:56:18 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Aug 2011 13:56:18 +0200 Subject: Compare tuples of different lenght References: Message-ID: Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. > > example if tuple 1 and tuple 3 are compare it should find that a > single element in each are the same and tuple 1 should be removed > resulting in > > [(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > the same for tuple 4 and 6 resulting in > > [(12,13),(2,3,4),(5,6),(7,8,9),] > > is this possible as I am having no success. > > Thanks from collections import Counter, defaultdict from itertools import chain def process_counter(sample): c = Counter() d = defaultdict(list) for items in sample: c.update(items) d[len(items)].append(items) result = [] for cluster in sorted(d.values(), key=len): c.subtract(chain.from_iterable(cluster)) for items in cluster: if not any(c[item] for item in items): result.append(items) result.sort(key=sample.index) return result if __name__ == "__main__": for process in [process_counter]: print process.__name__ sample = [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] wanted = [(12,13),(2,3,4),(5,6),(7,8,9),] assert process(sample) == wanted sample = [(5,6), (6,7,8)] wanted = [(6,7,8)] got = process(sample) assert got == wanted sample = wanted = [(5, 6), (6, 7)] assert process(sample) == wanted sample = [(1,), (1, 2), (2, 3, 4)] wanted = [(2, 3, 4)] assert process(sample) == wanted From drobinow at gmail.com Sat Aug 20 08:17:32 2011 From: drobinow at gmail.com (David Robinow) Date: Sat, 20 Aug 2011 08:17:32 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: On Sat, Aug 20, 2011 at 4:16 AM, Alec Taylor wrote: >> ... > I found said joke rather funny :P Perhaps, as a retired amateur comedian, my standards are too high, but I don't think adding a smilie to a stupid post suddenly turns it into a joke. Nevertheless, the quality of the attempt is not really the issue here. The would-be humorist did not need to quote the spam. Please, don't do it. From rosuav at gmail.com Sat Aug 20 08:25:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 13:25:39 +0100 Subject: Python import search path In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 10:52 AM, Kevin Zhang wrote: > Found a few solution in python docs. > A. sys.path.append > I think A is not so pretty, and I don't have root ?privilege?to use B and C. > So any both more elegant and practical solutions? If, as I understand from your directory tree, ttt.py is a tester for sss.py, then I'd say this is the right option. It's only going to be used in the special environment of testing, so it's okay to have a single line of code up the top that makes it convenient. Chris Angelico From darcy at druid.net Sat Aug 20 10:50:35 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Aug 2011 10:50:35 -0400 Subject: Stop quoting spam [was Re: Hot Girls ...] In-Reply-To: References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4e4ecae1$0$29990$c3e8da3$5496439d@news.astraweb.com> <1313796267.11691.6.camel@localhost.localdomain> Message-ID: <20110820105035.4fa540b5@dilbert> On Sat, 20 Aug 2011 08:17:32 -0400 David Robinow wrote: > > I found said joke rather funny :P > Perhaps, as a retired amateur comedian, my standards are too high, How does one retire from amateur status? Do you suddenly start charging for telling jokes? :-) > but I don't think adding a smilie to a stupid post suddenly turns it > into a joke. Nevertheless, the quality of the attempt is not really > the issue here. The would-be humorist did not need to quote the spam. Well, exactly. I don't think that anyone made any comment about the quality of the joke when talking about the first posting. The only thing that people said was that he shouldn't have repeated the spam. Everyone, including the original poster, who defended the post did so on the grounds that it was funny. That's certainly debatable but no one was telling him not to post until he gets funnier. http://en.wikipedia.org/wiki/Straw_man Whether the post was funny or not is a judgment call. No one is saying not to post unfunny jokes because no one is the arbiter of what's funny. If you want to argue with the complainers, argue with their actual complaint. Tell us why it is OK to repeat spam with all the spammy URLS intact By the way, my joke above is hilarious. -- 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 Sat Aug 20 10:57:08 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Aug 2011 10:57:08 -0400 Subject: Really, stop repeating spam! (Was: Hot Girls...) In-Reply-To: <4E4F8260.2080606@gmail.com> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4E4F8260.2080606@gmail.com> Message-ID: <20110820105708.6d1d24b2@dilbert> On Sat, 20 Aug 2011 15:16:08 +0530 hackingKK wrote: > Well, they might be indented in the right places but i don't know if > loops, conditions, functions, if they all happen or not. > :) [Entire spam deleted AGAIN] Good grief! Haven't you seen all the followups to that posting you replied to? Are you two actually in cahoots with the spammer? Wait, I get it. The spammer, Matty and you are all on gmail. You are all the same person, aren't you? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rosuav at gmail.com Sat Aug 20 10:59:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 15:59:53 +0100 Subject: Really, stop repeating spam! (Was: Hot Girls...) In-Reply-To: <20110820105708.6d1d24b2@dilbert> References: <94d457b9-30e5-4724-87b1-7450b18801b7@l7g2000vbz.googlegroups.com> <4E4F8260.2080606@gmail.com> <20110820105708.6d1d24b2@dilbert> Message-ID: On Sat, Aug 20, 2011 at 3:57 PM, D'Arcy J.M. Cain wrote: > Wait, I get it. ?The spammer, Matty and you are all on gmail. ?You are > all the same person, aren't you? > Gmail is all one person now? That would explain why I keep seeing things I agree with. I had no idea there were so many of me around! Wait, does that make me Agent Smith? ChrisA From research at johnohagan.com Sat Aug 20 11:03:05 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 21 Aug 2011 01:03:05 +1000 Subject: Compare tuples of different lenght In-Reply-To: References: Message-ID: <20110821010305.726f9d431500b679214762f5@johnohagan.com> On Sat, 20 Aug 2011 01:25:18 -0700 (PDT) Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. [...] This should work: def long_match(tuples): sorted_tuples = sorted(tuples, key=len) for n, t in enumerate(sorted_tuples): for s in sorted_tuples[n + 1:]: if len(s) > len(t) and any(i in s for i in t): tuples.remove(t) break return tuples Regards, John From sajmikins at gmail.com Sat Aug 20 12:06:38 2011 From: sajmikins at gmail.com (Simon Forman) Date: Sat, 20 Aug 2011 09:06:38 -0700 Subject: testing if a list contains a sublist In-Reply-To: <4E49AB3E.9000801@web.de> References: <4E49AB3E.9000801@web.de> Message-ID: On Mon, Aug 15, 2011 at 4:26 PM, Johannes wrote: > hi list, > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] -> l1 is not contained in l2 > > my problem is the second example, which makes it impossible to work with > sets insteads of lists. But something like set.issubset for lists would > be nice. > > greatz Johannes > -- > http://mail.python.org/mailman/listinfo/python-list > Probably not the most efficient way, but I wanted to mention it: from difflib import SequenceMatcher def list_in(a, b): '''Is a completely contained in b?''' matcher = SequenceMatcher(a=a, b=b) m = matcher.find_longest_match(0, len(a), 0, len(b)) return m.size == len(a) Cheers, ~Simon From kw at codebykevin.com Sat Aug 20 13:39:20 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 20 Aug 2011 13:39:20 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: On 8/19/11 4:02 PM, johnny.venter wrote: > > Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. > You can certainly try to install them via easy_install, I supposed, but it's doubtful they would do anything, as the Mac does not support win32 API calls any more than Windows supports Cocoa/Objective-C calls. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From mydevgroup at gmail.com Sat Aug 20 13:48:47 2011 From: mydevgroup at gmail.com (George) Date: Sat, 20 Aug 2011 18:48:47 +0100 Subject: List spam In-Reply-To: <87ei0gbopw.fsf@benfinney.id.au> Message-ID: I find python group is filled with spam mails, is there any way to filter these mails before sending it to the group. I can't see this situation with similar user group, such as the jsr. George. On 20/08/2011 07:07, "Ben Finney" wrote: > Javier writes: > You will lose a lot of people > asking/answering interesting stuff, and > maybe eventually the list will > die. I don't think it would die, but the chances are greater that it > would become insular and further disconnected from the Python community, > and hence far less useful. > Me (like many people with little free time) > seldom post in > blogs/forums/mailing lists where I need to register. +1 -- > \ ?Ignorance more frequently begets confidence than does | `\ > knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) > | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list From maxmoroz at gmail.com Sat Aug 20 14:20:47 2011 From: maxmoroz at gmail.com (Max Moroz) Date: Sat, 20 Aug 2011 11:20:47 -0700 Subject: extended slicing and negative stop value problem Message-ID: Would it be a good idea to change Python definition so that a[10, -1, -1] referred to the elements starting with position 10, going down to the beginning? This would require disabling the "negative stop value means counting from the end of the array" magic whenever the step value is negative. The reason for this idea is that many people (me including) try to use extended slices with negative step values, only to realize that they are messed up. For example, if your stop value is reduced in a loop from a positive number to -1, the behavior breaks whenever it hits -1. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 20 14:29:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 19:29:42 +0100 Subject: extended slicing and negative stop value problem In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > Would it be a good idea to change Python definition so that?a[10, -1, -1] > referred to the elements starting with position 10, going down to the > beginning? Well, first off I think it's a dangerous idea to change semantics of something like that. I can see your use case, but I think that what you want is covered by simply omitting the stop marker: >>> a="qwertyuiopasdfghjklzxcvbnm" >>> a[10:1:-1] 'apoiuytre' >>> a[10:0:-1] 'apoiuytrew' >>> a[10::-1] 'apoiuytrewq' If you're using a variable for the stop value, you just need to set it to an explicit None if it would fall negative: >>> a[10:None:-1] 'apoiuytrewq' Hope that helps! ChrisA From maxmoroz at gmail.com Sat Aug 20 14:52:20 2011 From: maxmoroz at gmail.com (Max) Date: Sat, 20 Aug 2011 11:52:20 -0700 (PDT) Subject: extended slicing and negative stop value problem References: Message-ID: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> On Aug 20, 11:29?am, Chris Angelico wrote: > If you're using a variable for the stop value, you just need to set it > to an explicit None if it would fall negative: > > >>> a[10:None:-1] > That doesn't work if it's set in a loop or if it's calculated as a formula. For example, this very simple code doesn't work because of the "-1 problem". # find the longest substring that reads the same left to right and right to left for substr_length in range(len(input),0,-1): for starting_pos in range(len(input)-substr_length+1): ending_pos = starting_pos + substr_length - 1 if input[starting_pos:ending_pos+1] == input[ending_pos : starting_pos-1 : -1]: print(input[starting_pos:ending_pos+1]) exit(0) Of course you can rewrite it, but it becomes quite ugly. (Not to mention, people who learn the language would not always know this, and will end up with a bug.) From no.email at nospam.invalid Sat Aug 20 15:18:25 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 20 Aug 2011 12:18:25 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xipprsxha.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> You can catch all exceptions by catching the base class Exception: > > Except that is nearly always poor advice, because it catches too much: it > hides bugs in code, as well as things which should be caught. > You should always catch the absolute minimum you need to catch. But there's no way to know what that minimum is. Python libraries throw all sorts of exceptions that their documentation doesn't mention. Java's checked exceptions are obnoxious but they do have their attractions. From rosuav at gmail.com Sat Aug 20 15:53:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Aug 2011 20:53:53 +0100 Subject: extended slicing and negative stop value problem In-Reply-To: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> References: <9c3643a8-ba91-4b0b-8144-f4a6260d6cf0@j14g2000prh.googlegroups.com> Message-ID: On Sat, Aug 20, 2011 at 7:52 PM, Max wrote: > That doesn't work if it's set in a loop or if it's calculated as a > formula. For example, this very simple code doesn't work because of > the "-1 problem". > Right, which is what I meant by setting it to an explicit None: if input[starting_pos:ending_pos+1] == input[ending_pos : starting_pos-1 if starting_pos >= 0 else None : -1]: You're right that it starts to get ugly, though. Of course, there are other ways to find the longest palindromic substring in a string: # I wouldn't bother counting a one-character "palindrome" for substr_length in range(len(input),1,-1): for starting_pos in range(len(input)-substr_length+1): ending_pos = starting_pos + substr_length - 1 testme = input[starting_pos:ending_pos+1] if testme == testme[::-1]: print(testme) exit(0) That is, snip out the string and then reverse that snipped piece, rather than reverse-slicing from the original. This doesn't solve the issue of slicing backwards with variable halts, though. ChrisA From steve+comp.lang.python at pearwood.info Sat Aug 20 16:14:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 21 Aug 2011 06:14:37 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> Message-ID: <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> Paul Rubin wrote: > Steven D'Aprano writes: >>> You can catch all exceptions by catching the base class Exception: >> >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. >> You should always catch the absolute minimum you need to catch. > > But there's no way to know what that minimum is. Python libraries throw > all sorts of exceptions that their documentation doesn't mention. Yes, you're absolutely correct. But it's also irrelevant. Most of those exceptions should not be caught, even if you know what they are, because they represent either bugs that should be fixed, or bad data which should raise an exception. A bare except, or except Exception, is hardly ever the right approach. As for exceptions which should be caught, they should be dealt with on a case-by-case basis. There's no need to identify all those obscure exception-raising cases ahead of time. After all, unless you're writing software for a nuclear reactor, or an aeroplane's autopilot, chances are that *bugs don't really matter*. That is to say, if you release software with a hidden bug, the consequences generally aren't very important. (Depends on the nature of the software, and the bug, of course. Sometimes bugs are important. How's your test suite?) At some point, you will get a bug report, and then you will fix the bug. The fix may involve catching an extra exception, or avoiding generating the exception in the first place. Trying to predict ahead of time every possible exception that could be raised, and deal with them correctly (as opposed to just sweeping them under the carpet), is not only impossible but also usually unnecessary. It took me a long time to realise that the world won't end if I write a piece of software with a bug. Now I realise that software is never finished, there's always going to be a next version, so trying to make it perfect is a fool's errand. It's very liberating :) > Java's checked exceptions are obnoxious but they do have their > attractions. No doubt about it, the concept is attractive, but a few Java heavyweights now consider checked exceptions to be a mistake. http://www.mindview.net/Etc/Discussions/CheckedExceptions http://radio-weblogs.com/0122027/stories/2003/04/01/JavasCheckedExceptionsWereAMistake.html More here: http://www.ibm.com/developerworks/java/library/j-jtp05254/index.html -- Steven From nagle at animats.com Sat Aug 20 16:15:41 2011 From: nagle at animats.com (John Nagle) Date: Sat, 20 Aug 2011 13:15:41 -0700 Subject: try... except with unknown error types In-Reply-To: References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e501614$0$2161$742ec2ed@news.sonic.net> On 8/19/2011 1:24 PM, John Gordon wrote: > In<4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > >>> You can catch all exceptions by catching the base class Exception: > >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be caught. > >> You should always catch the absolute minimum you need to catch. Right. When in doubt, catch EnvironmentError. That means something external to the program, at the OS or network level, has a problem. "Exception" covers errors which are program bugs, like references to undefined class members. John Nagle From steve+comp.lang.python at pearwood.info Sat Aug 20 16:40:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 21 Aug 2011 06:40:01 +1000 Subject: extended slicing and negative stop value problem References: Message-ID: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> Pardon me for breaking threading, but I don't have Max's original post. On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > Would it be a good idea to change Python definition so that a[10, -1, -1] I presume you mean slice notation a[10:-1:-1]. > referred to the elements starting with position 10, going down to the > beginning? No, almost certainly not. Such a change would break backwards compatibility, and so would only be allowed under very unusual circumstances: the current behaviour would have to be a major problem, or the new behaviour a huge benefit, or both, to make up for: (1) the extra work needed to change the behaviour (probably involving a "from __future__ import ..." feature for the first version or two); (2) breaking people's existing code; and (3) forcing people to learn the new behaviour and unlearn the old. Even if the old behaviour is "wrong", the work needed to fix it may be more than the benefit. If this was going to be "fixed", the time was probably about three years ago, when Python3 was just starting. Now such a change will probably need to wait for the hypothetical Python 4000. > This would require disabling the "negative stop value means counting from > the end of the array" magic whenever the step value is negative. Which will hurt people who expect the current behaviour: >>> a[8:-8:-1] [8, 7, 6, 5, 4, 3] > The reason for this idea is that many people (me including) try to use > extended slices with negative step values, only to realize that they are > messed up. For example, if your stop value is reduced in a loop from a > positive number to -1, the behavior breaks whenever it hits -1. Yes, negative step values are unintuitive, especially if the step is not -1. The solution is, "Don't do that then!". The usual advice is to do your slicing twice, reversing it the second time: a[0:11][::-1] # Instead of a[10:-1:-1], which looks like it should work, but doesn't. (or use the reversed() built-in instead of the second slice), or to write a helper function to adjust the indexes and get whatever behaviour you like. Hint: >>> a[10:-11:-1] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] -- Steven From johnny.venter at zoho.com Sat Aug 20 19:51:29 2011 From: johnny.venter at zoho.com (Johnny Venter) Date: Sat, 20 Aug 2011 19:51:29 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? I found dcerpc might be the way to go. On Aug 20, 2011, at 1:39 PM, Kevin Walzer wrote: > On 8/19/11 4:02 PM, johnny.venter wrote: >> >> Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. >> > > You can certainly try to install them via easy_install, I supposed, but it's doubtful they would do anything, as the Mac does not support win32 API calls any more than Windows supports Cocoa/Objective-C calls. > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Aug 20 19:57:21 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 00:57:21 +0100 Subject: Python Windows Extensions for Mac In-Reply-To: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: On Sun, Aug 21, 2011 at 12:51 AM, Johnny Venter wrote: > Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? > The concept doesn't have meaning on a non-Windows computer, so I am going to take the liberty of assuming that you really want to query them from a different computer - some kind of network query. If that's not the case, can you clarify exactly what your setup is? Chris Angelico From greg.ewing at canterbury.ac.nz Sat Aug 20 20:37:34 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 21 Aug 2011 12:37:34 +1200 Subject: Replacement for the shelve module? In-Reply-To: <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9bb2ahFgjbU1@mid.individual.net> > Robert Kern wrote: > >>That's just incorrect. You shouldn't use (binary) floats for many >>*accounting* purposes, but for many financial/econometric analyses, floats >>are de rigeur and work much better than decimals There's a certain accounting package I work with that *does* use floats -- binary ones -- for accounting purposes, and somehow manages to get away with it. Not something I would recommend trying at home, though. -- Greg From rosuav at gmail.com Sat Aug 20 20:54:29 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 01:54:29 +0100 Subject: Replacement for the shelve module? In-Reply-To: <9bb2ahFgjbU1@mid.individual.net> References: <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com> <4e4ec962$0$29986$c3e8da3$5496439d@news.astraweb.com> <4e4f1004$0$29966$c3e8da3$5496439d@news.astraweb.com> <9bb2ahFgjbU1@mid.individual.net> Message-ID: On Sun, Aug 21, 2011 at 1:37 AM, Gregory Ewing wrote: > There's a certain accounting package I work with that *does* > use floats -- binary ones -- for accounting purposes, and > somehow manages to get away with it. Not something I would > recommend trying at home, though. > Probably quite a few, actually. It's not a very visible problem so long as you always have plenty of "spare precision", and you round everything off to two decimals (or however many for your currency). Eventually you'll start seeing weird results that are a cent off, but you won't notice them often. And hey. You store $1.23 as 1.23, and it just works! It must be the right thing to do! Me, I store dollars-and-cents currency in cents. Always. But that's because I never need fractional cents. I'm not sure what the best way to handle fractional cents is, but I'm fairly confident that this isn't it: http://thedailywtf.com/Articles/Price-in-Nonsense.aspx ChrisA From johnny.venter at zoho.com Sun Aug 21 01:38:24 2011 From: johnny.venter at zoho.com (Johnny Venter) Date: Sun, 21 Aug 2011 01:38:24 -0400 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: From my mac, I want to use python to access and read objects from a remote Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? On Aug 20, 2011, at 7:57 PM, Chris Angelico wrote: > On Sun, Aug 21, 2011 at 12:51 AM, Johnny Venter wrote: >> Thank you all for the replies. I would like to query various Windows' objects and resources from Mac and/or Linux such as Active Directory users, network shares, group members, etc... What module or methods can I use with python to accomplish this? >> > > The concept doesn't have meaning on a non-Windows computer, so I am > going to take the liberty of assuming that you really want to query > them from a different computer - some kind of network query. If that's > not the case, can you clarify exactly what your setup is? > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Aug 21 03:30:07 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 08:30:07 +0100 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: > Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: > > From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? > Then the "use Python" part is relatively immaterial; what you need to know is: What network protocol are you using to "access and read objects"? Start by researching that; once you know the details (is it even TCP/IP-based?), you can look into whether Python has facilities for speaking that protocol. ChrisA From yasar11732 at gmail.com Sun Aug 21 04:09:50 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 21 Aug 2011 11:09:50 +0300 Subject: Optimizing Text Similarity Algorithm Message-ID: Hi, I originally posted this question on stackoverflow, you can find it here: http://stackoverflow.com/q/7133350/886669 I just want people check what I am doing and express their opinion about the thing I am doing is acceptable, or are there some expects of it that could change. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jefflovejapan at gmail.com Sun Aug 21 06:03:09 2011 From: jefflovejapan at gmail.com (jefflovejapan) Date: Sun, 21 Aug 2011 03:03:09 -0700 (PDT) Subject: Installing numpy on 2.7 (OS X 10.7) Message-ID: I'm following the instructions given here, but it isn't working. Specifically, I'm getting: Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory even though I completed the two downloads from github successfully. Any ideas why this wouldn't be working, or any ideas where I can look for better instructions? From alec.taylor6 at gmail.com Sun Aug 21 06:13:07 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 21 Aug 2011 20:13:07 +1000 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: Perhaps you'd be better off with something like RunDeck (Free, Open-Source, Cross-Platform, CopyLeft) for this kind of problem. On Sun, Aug 21, 2011 at 5:30 PM, Chris Angelico wrote: > On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: >> Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: >> >> From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? >> > > Then the "use Python" part is relatively immaterial; what you need to > know is: What network protocol are you using to "access and read > objects"? Start by researching that; once you know the details (is it > even TCP/IP-based?), you can look into whether Python has facilities > for speaking that protocol. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin.kaplan at case.edu Sun Aug 21 09:39:36 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 21 Aug 2011 09:39:36 -0400 Subject: Installing numpy on 2.7 (OS X 10.7) In-Reply-To: References: Message-ID: On Sun, Aug 21, 2011 at 6:03 AM, jefflovejapan wrote: > I'm following the instructions given Installing_SciPy/Mac_OS_X">here, but it isn't working. > Specifically, I'm getting: > > Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ > Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such > file or directory > > even though I completed the two downloads from github successfully. > Any ideas why this wouldn't be working, or any ideas where I can look > for better instructions? > -- As the error says, it can't find the setup.py file. My guess would be you forgot to cd to the newly created directory. You have to "cd numpy" (or cd scipy if you're trying to install that) first to get into the directory with the install script. From irmen.NOSPAM at xs4all.nl Sun Aug 21 11:28:52 2011 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 21 Aug 2011 17:28:52 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: References: Message-ID: <4e512435$0$23850$e4fe514c@news2.news.xs4all.nl> On 21-8-2011 1:51, Johnny Venter wrote: > Thank you all for the replies. I would like to query various Windows' objects and > resources from Mac and/or Linux such as Active Directory users, network shares, group > members, etc... What module or methods can I use with python to accomplish this? A way to approach this problem is installing Python + windows extensions on the actual windows machine(s) you want to query. Then create some form of a server process that does the windows specific stuff locally, and exposes an interface with the functions you want to provide to your remote machine(s). Talk with the server process using some form of platform independent IPC, for instance Pyro: http://pypi.python.org/pypi/Pyro4/ Be careful what methods you expose this way though (security issues!) Irmen From emile at fenx.com Sun Aug 21 12:31:19 2011 From: emile at fenx.com (Emile van Sebille) Date: Sun, 21 Aug 2011 09:31:19 -0700 Subject: decorator issue with modules dbus & gobject In-Reply-To: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> References: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Message-ID: On 8/18/2011 5:02 AM Makiavelik said... > Hi, > Here is a sample code that reproduces the issue : Not really 'sample' enough to allow others to investigate... ImportError: No module named gobject ImportError: No module named dbus ImportError: No module named dbus.mainloop.glib Try to eliminate the non-standard dependencies. I wanted to check the default value set in timeout but there's too much crap to clean up. Emile From laurent.payot at gmail.com Sun Aug 21 12:52:23 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 09:52:23 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") Message-ID: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Hi Folks, I was arguing with a guy who was sure that incrementing a variable i with "i += 1" is faster than "i = i + 1". I couldn't tell if he was right or wrong so I did a little benchmark with the very useful timeit module. Here are the results on my little Linux Eeepc Netbook (using Python 3.2): Computing, please wait... Results for 1000000 times "i = i + 1": 0.37591004371643066 0.3827171325683594 0.37238597869873047 0.37305116653442383 0.3725881576538086 0.37294602394104004 0.3712761402130127 0.37357497215270996 0.371567964553833 0.37359118461608887 Total 3.7396 seconds. Results for 1000000 times "i += 1": 0.3821070194244385 0.3802030086517334 0.3828878402709961 0.3823058605194092 0.3801591396331787 0.38340115547180176 0.3795340061187744 0.38153910636901855 0.3835160732269287 0.381864070892334 Total 3.8175 seconds. ==> "i = i + 1" is 2.08% faster than "i += 1". I did many tests and "i = i + 1" always seems to be around 2% faster than "i += 1". This is no surprise as the += notation seems to be a syntaxic sugar layer that has to be converted to i = i + 1 anyway. Am I wrong in my interpretation? Btw here's the trivial Python 3.2 script I made for this benchmark: import timeit r = 10 n = 1000000 s1 = "i = i + 1" s2 = "i += 1" t1 = timeit.Timer(stmt=s1, setup="i = 0") t2 = timeit.Timer(stmt=s2, setup="i = 0") print("Computing, please wait...") results1 = t1.repeat(repeat=r, number=n) results2 = t2.repeat(repeat=r, number=n) print('\nResults for {} times "{}":'.format(n, s1)) sum1 = 0 for result in results1: print(result) sum1 += result print("Total {:.5} seconds.".format(sum1)) print('\nResults for {} times "{}":'.format(n, s2)) sum2 = 0 for result in results2: print(result) sum2 += result print("Total {:.5} seconds.".format(sum2)) print('\n==> "{}" is {:.3}% faster than "{}".'.format(s1,(sum2 / sum1) * 100 - 100, s2)) Comments are welcome... From woooee at gmail.com Sun Aug 21 12:59:11 2011 From: woooee at gmail.com (woooee) Date: Sun, 21 Aug 2011 09:59:11 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> as the += notation seems to be a syntaxic sugar layer that has to be converted to i = i + 1 anyway. That has always been my understanding. The faster way is to append to a list as concatenating usually, requires the original string, accessing an intermediate block of memory, and the memory for the final string. x_list.append(value) to_string = "".join(x_list) From laurent.payot at gmail.com Sun Aug 21 13:03:14 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 10:03:14 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> Message-ID: Well I agree with you about string concatenation, but here I'm talking about integers incrementation... From irmen at -NOSPAM-xs4all.nl Sun Aug 21 13:14:19 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Sun, 21 Aug 2011 19:14:19 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> Message-ID: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> On 21-08-11 19:03, Laurent wrote: > Well I agree with you about string concatenation, but here I'm talking about integers incrementation... Seems the two forms are not 100% identical: >>> import dis >>> def f1(x): ... x=x+1 ... >>> def f2(x): ... x+=1 ... >>> >>> dis.dis(f1) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 STORE_FAST 0 (x) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE >>> dis.dis(f2) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 INPLACE_ADD 7 STORE_FAST 0 (x) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE >>> What the precise difference (semantics and speed) is between the BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source code or maybe someone knows it from memory :-) Irmen From maxmoroz at gmail.com Sun Aug 21 13:27:26 2011 From: maxmoroz at gmail.com (Max) Date: Sun, 21 Aug 2011 10:27:26 -0700 (PDT) Subject: extended slicing and negative stop value problem References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> On Aug 20, 1:40?pm, Steven D'Aprano wrote: > Pardon me for breaking threading, but I don't have Max's original post. Not sure why; I also can't see it! I'll copy it at the end just in case. > On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: > > Would it be a good idea to change Python definition so that a[10, -1, -1] > > I presume you mean slice notation a[10:-1:-1]. > > > referred to the elements starting with position 10, going down to the > > beginning? > > If this was going to be "fixed", the time was probably > about three years ago, when Python3 was just starting. Now such a change > will probably need to wait for the hypothetical Python 4000. Yeah, I was surprised that it didn't bother anyone.. > The usual advice is to do your slicing twice, reversing it the second time: > > a[0:11][::-1] > # Instead of a[10:-1:-1], which looks like it should work, but doesn't. It works nicely, but it is 1.3 times slower in my code (I am surprised the interpreter doesn't optimize this). From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 13:27:38 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Sun, 21 Aug 2011 19:27:38 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> Message-ID: <1313947658.3424.3.camel@thegeorge> > What the precise difference (semantics and speed) is between the > BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source > code or maybe someone knows it from memory :-) > > Irmen > from Python/ceval.c: 1316 case BINARY_ADD: 1317 w = POP(); 1318 v = TOP(); 1319 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { 1320 /* INLINE: int + int */ 1321 register long a, b, i; 1322 a = PyInt_AS_LONG(v); 1323 b = PyInt_AS_LONG(w); 1324 /* cast to avoid undefined behaviour 1325 on overflow */ 1326 i = (long)((unsigned long)a + b); 1327 if ((i^a) < 0 && (i^b) < 0) 1328 goto slow_add; 1329 x = PyInt_FromLong(i); 1330 } 1331 else if (PyString_CheckExact(v) && 1332 PyString_CheckExact(w)) { 1333 x = string_concatenate(v, w, f, next_instr); 1334 /* string_concatenate consumed the ref to v */ 1335 goto skip_decref_vx; 1336 } 1337 else { 1338 slow_add: 1339 x = PyNumber_Add(v, w); 1340 } 1341 Py_DECREF(v); 1342 skip_decref_vx: 1343 Py_DECREF(w); 1344 SET_TOP(x); 1345 if (x != NULL) continue; 1346 break; 1532 case INPLACE_ADD: 1533 w = POP(); 1534 v = TOP(); 1535 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { 1536 /* INLINE: int + int */ 1537 register long a, b, i; 1538 a = PyInt_AS_LONG(v); 1539 b = PyInt_AS_LONG(w); 1540 i = a + b; 1541 if ((i^a) < 0 && (i^b) < 0) 1542 goto slow_iadd; 1543 x = PyInt_FromLong(i); 1544 } 1545 else if (PyString_CheckExact(v) && 1546 PyString_CheckExact(w)) { 1547 x = string_concatenate(v, w, f, next_instr); 1548 /* string_concatenate consumed the ref to v */ 1549 goto skip_decref_v; 1550 } 1551 else { 1552 slow_iadd: 1553 x = PyNumber_InPlaceAdd(v, w); 1554 } 1555 Py_DECREF(v); 1556 skip_decref_v: 1557 Py_DECREF(w); 1558 SET_TOP(x); 1559 if (x != NULL) continue; 1560 break; As for using Integers, the first case (line 1319 and 1535) are true and there is no difference in Code. However, Python uses a huge switch-case construct to execute it's opcodes and INPLACE_ADD cames after BINARY_ADD, hence the difference in speed. To be clear, this is nothing you should consider when writing fast code. Complexity wise they both are the same. From laurent.payot at gmail.com Sun Aug 21 13:48:48 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 10:48:48 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> Thanks for these explanations. So 2% speed difference just between "B..." and "I..." entries in a huge alphabetically-ordered switch case? Wow. Maybe there is some material for speed enhancement here... From hansmu at xs4all.nl Sun Aug 21 13:57:50 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 21 Aug 2011 19:57:50 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <4af56750-aae1-4e93-8100-3a913f9901bf@a10g2000prn.googlegroups.com> <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e51471e$0$23880$e4fe514c@news2.news.xs4all.nl> On 21/08/11 19:14:19, Irmen de Jong wrote: > What the precise difference (semantics and speed) is between the > BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source > code or maybe someone knows it from memory :-) There is a clear difference in semantics: BINARY_ADD always produces a new object, INPLACE_ADD may modify its left-hand operand in situ (if it's mutable). Integers are immutable, so for integers the semantics are the same, but for lists, for example, the two are different: >>> x = [2, 3, 5, 7] >>> y = [11, 13] >>> x+y [2, 3, 5, 7, 11, 13] >>> x [2, 3, 5, 7] # x still has its original value >>> x += y >>> x [2, 3, 5, 7, 11, 13] # x is now modified >>> For integers, I would not expect a measurable difference in speed. Hope this helps, -- HansM From laurent.payot at gmail.com Sun Aug 21 14:03:16 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 11:03:16 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <2885fd04-6cde-414c-8be9-67e6e1235c79@glegroupsg2000goo.googlegroups.com> Message-ID: <8530af1c-f723-47d6-afa9-2a8d9d3b17b1@glegroupsg2000goo.googlegroups.com> Well 2% more time after 1 million iterations so you're right I won't consider it. From lists at cheimes.de Sun Aug 21 14:24:17 2011 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Aug 2011 20:24:17 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: Am 21.08.2011 19:27, schrieb Andreas L?scher: > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. I don't think that's the reason. Modern compiles turn a switch statement into a jump or branch table rather than a linear search like chained elif statements. Python 3.2 on Linux should also be compiled with computed gotos. Christian From no.email at nospam.invalid Sun Aug 21 14:26:51 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 21 Aug 2011 11:26:51 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xty9ahb84.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> But there's no way to know what that minimum is. Python libraries throw >> all sorts of exceptions that their documentation doesn't mention. > > Yes, you're absolutely correct. But it's also irrelevant. Most of those > exceptions should not be caught, even if you know what they are, because > they represent either bugs that should be fixed, or bad data which should > raise an exception. A bare except, or except Exception, is hardly ever the > right approach. I'm not sure what to do instead. The exceptions I'm currently dealing with happen when certain network operations go wrong (e.g. network or remote host is down, connection fails, etc.) The remedy in each case is to catch the exception, log the error, and try the operation again later. But there's no guaranteed-to-be-complete list in the Python docs of all the exceptions that can be thrown. A new and surprising mode of network failure can lead to an unhandled exception, unless you catch everything. The Erlang approach is tempting. Don't catch the exception at all--just let the process crash, and restart it. But that's a more heavyweight operation in Python. > After all, unless you're writing > software for a nuclear reactor, or an aeroplane's autopilot, chances are > that *bugs don't really matter*. That is to say, if you release software > with a hidden bug, the consequences generally aren't very important. It's a retail application that would cause some business disruption and a pissed off customer if the program went down. Also it's in an embedded box on a customer site. It's not in Antarctica or anything like that, but it's a few towns over, and someone would have to drive there (probably through heavy traffic) if something went wrong that power cycling the box couldn't fix. > It took me a long time to realise that the world won't end if I write a > piece of software with a bug. It's not the end of the world if I get run over a truck, but such an event would be of enough consequence to me personally that I find it worth going to some trouble to avoid it. From roy at panix.com Sun Aug 21 14:52:50 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 14:52:50 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: In article , Christian Heimes wrote: > Am 21.08.2011 19:27, schrieb Andreas L?scher: > > As for using Integers, the first case (line 1319 and 1535) are true and > > there is no difference in Code. However, Python uses a huge switch-case > > construct to execute it's opcodes and INPLACE_ADD cames after > > BINARY_ADD, hence the difference in speed. > > I don't think that's the reason. Modern compiles turn a switch statement > into a jump or branch table rather than a linear search like chained > elif statements. This is true even for very small values of "modern". I remember the Unix v6 C compiler (circa 1977) was able to do this. From rosuav at gmail.com Sun Aug 21 15:17:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Aug 2011 20:17:59 +0100 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 21, 2011 at 7:26 PM, Paul Rubin wrote: > I'm not sure what to do instead. ?The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) ?The remedy in each case is > to catch the exception, log the error, and try the operation again > later. ?But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. ?A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. > A new and surprising mode of network failure would be indicated by a new subclass of IOError or EnvironmentError. If you catch one of those, you should catch it. That's the benefit of hierarchical exceptions. ChrisA From ethan at stoneleaf.us Sun Aug 21 15:22:47 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 21 Aug 2011 12:22:47 -0700 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4E515B07.70303@stoneleaf.us> Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever the >> right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. In a case like this I can see catching everything so long as (which you say you are doing) you log the error somehow -- what's really frustrating is when the error is simply tossed with no record whatsoever... what a pain to debug! ~Ethan~ From tjreedy at udel.edu Sun Aug 21 15:39:53 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 15:39:53 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313947658.3424.3.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: On 8/21/2011 1:27 PM, Andreas L?scher wrote: >> What the precise difference (semantics and speed) is between the >> BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source >> code or maybe someone knows it from memory :-) >> >> Irmen >> > from Python/ceval.c: > > 1316 case BINARY_ADD: > 1317 w = POP(); > 1318 v = TOP(); > 1319 if (PyInt_CheckExact(v)&& PyInt_CheckExact(w)) { > 1320 /* INLINE: int + int */ > 1321 register long a, b, i; > 1322 a = PyInt_AS_LONG(v); > 1323 b = PyInt_AS_LONG(w); > 1324 /* cast to avoid undefined behaviour > 1325 on overflow */ > 1326 i = (long)((unsigned long)a + b); > 1327 if ((i^a)< 0&& (i^b)< 0) > 1328 goto slow_add; > 1329 x = PyInt_FromLong(i); > 1330 } > 1331 else if (PyString_CheckExact(v)&& > 1332 PyString_CheckExact(w)) { > 1333 x = string_concatenate(v, w, f, next_instr); > 1334 /* string_concatenate consumed the ref to v */ > 1335 goto skip_decref_vx; > 1336 } > 1337 else { > 1338 slow_add: > 1339 x = PyNumber_Add(v, w); > 1340 } > 1341 Py_DECREF(v); > 1342 skip_decref_vx: > 1343 Py_DECREF(w); > 1344 SET_TOP(x); > 1345 if (x != NULL) continue; > 1346 break; > > 1532 case INPLACE_ADD: > 1533 w = POP(); > 1534 v = TOP(); > 1535 if (PyInt_CheckExact(v)&& PyInt_CheckExact(w)) { > 1536 /* INLINE: int + int */ > 1537 register long a, b, i; > 1538 a = PyInt_AS_LONG(v); > 1539 b = PyInt_AS_LONG(w); > 1540 i = a + b; > 1541 if ((i^a)< 0&& (i^b)< 0) > 1542 goto slow_iadd; > 1543 x = PyInt_FromLong(i); > 1544 } > 1545 else if (PyString_CheckExact(v)&& > 1546 PyString_CheckExact(w)) { > 1547 x = string_concatenate(v, w, f, next_instr); > 1548 /* string_concatenate consumed the ref to v */ > 1549 goto skip_decref_v; > 1550 } > 1551 else { > 1552 slow_iadd: > 1553 x = PyNumber_InPlaceAdd(v, w); > 1554 } > 1555 Py_DECREF(v); > 1556 skip_decref_v: > 1557 Py_DECREF(w); > 1558 SET_TOP(x); > 1559 if (x != NULL) continue; > 1560 break; > > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. > > To be clear, this is nothing you should consider when writing fast code. > Complexity wise they both are the same. With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with floats (0.0 and 1.0), 6% -- Terry Jan Reedy From tjreedy at udel.edu Sun Aug 21 15:52:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 15:52:28 -0400 Subject: try... except with unknown error types In-Reply-To: <7xty9ahb84.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: On 8/21/2011 2:26 PM, Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever the >> right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. I would expect that catching socket.error (or even IOError) should catch all of those. "exception socket.error A subclass of IOError, this exception is raised for socket-related errors. It is recommended that you inspect its errno attribute to discriminate between different kinds of errors." > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. -- Terry Jan Reedy From laurent.payot at gmail.com Sun Aug 21 15:53:04 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:53:04 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > floats (0.0 and 1.0), 6% For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. From laurent.payot at gmail.com Sun Aug 21 15:53:04 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:53:04 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > floats (0.0 and 1.0), 6% For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. From laurent.payot at gmail.com Sun Aug 21 15:55:00 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:55:00 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <01896ae1-1a6e-4458-b9a0-1a071f8ffbae@glegroupsg2000goo.googlegroups.com> Actually 6% between float themselves is just as not-understandable. From laurent.payot at gmail.com Sun Aug 21 15:55:00 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 12:55:00 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <01896ae1-1a6e-4458-b9a0-1a071f8ffbae@glegroupsg2000goo.googlegroups.com> Actually 6% between float themselves is just as not-understandable. From laurent.payot at gmail.com Sun Aug 21 16:04:24 2011 From: laurent.payot at gmail.com (Laurent) Date: Sun, 21 Aug 2011 13:04:24 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <3fa8a0a4-9321-4442-9133-ad44f7513486@glegroupsg2000goo.googlegroups.com> I did the test several times with floats on my machine and the difference is not as big as for integers: ==> "i = i + 1.0" is 0.732% faster than "i += 1.0". It seems normal as the float addition is supposed to be slower than integer addition, thus the syntaxic difference is comparatively less important. From nobody at nowhere.com Sun Aug 21 17:07:56 2011 From: nobody at nowhere.com (Nobody) Date: Sun, 21 Aug 2011 22:07:56 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, 21 Aug 2011 09:52:23 -0700, Laurent wrote: > I did many tests and "i = i + 1" always seems to be around 2% faster > than "i += 1". This is no surprise as the += notation seems to be a > syntaxic sugar layer that has to be converted to i = i + 1 anyway. Am I > wrong in my interpretation? It depends. If the value on the left has an __iadd__ method, that will be called; the value will be updated in-place, so all references to that object will be affected: > import numpy as np > a = np.zeros(3) > b = a > a array([ 0., 0., 0.]) > b array([ 0., 0., 0.]) > a += 1 > a array([ 1., 1., 1.]) > b array([ 1., 1., 1.]) If the value on the left doesn't have an __iadd__ method, then addition is performed and the name is re-bound to the result: > a = a + 1 > a array([ 2., 2., 2.]) > b array([ 1., 1., 1.]) If you're writing code which could reasonably be expected to work with arbitrary "numeric" values, you should decide which to use according to whether in-place modification is appropriate rather than trivial performance differences. If a difference of a few percent is significant, Python is probably the wrong language in the first place. From roy at panix.com Sun Aug 21 17:14:30 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 17:14:30 -0400 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: In article <7xty9ahb84.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. I would do something like this: try: do_some_network_stuff() except IOError: do_normal_recovery() except Exception: call_home() do_some_other_recovery() You are right, in an embedded/unattended application, you don't want to ever crash. If you ever get an error that you don't understand, you have no choice but to do the best you can to recover. I would also generate some kind of alert back to home base to tell somebody to take a look at it and make sure things are fine. I would expect that the whole application is wrapped in some kind of watchdog timer which will do a hard reset of the entire system. From clp2 at rebertia.com Sun Aug 21 18:16:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Aug 2011 15:16:21 -0700 Subject: extended slicing and negative stop value problem In-Reply-To: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> Message-ID: On Sun, Aug 21, 2011 at 10:27 AM, Max wrote: > On Aug 20, 1:40?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz wrote: >> > Would it be a good idea to change Python definition so that a[10, -1, -1] >> >> I presume you mean slice notation a[10:-1:-1]. >> >> > referred to the elements starting with position 10, going down to the >> > beginning? >> The usual advice is to do your slicing twice, reversing it the second time: >> >> a[0:11][::-1] >> # Instead of a[10:-1:-1], which looks like it should work, but doesn't. > > It works nicely, but it is 1.3 times slower in my code (I am surprised > the interpreter doesn't optimize this). That would require CPython to assume certain slicing semantics for all types (which it can't) or to check for this very specific case at runtime (which would slow down all other [list] slicing operations). A smarter implementation such as PyPy could indeed theoretically optimize this case though. Cheers, Chris From iamforufriends at gmail.com Sun Aug 21 19:07:39 2011 From: iamforufriends at gmail.com (kate for free dating) Date: Sun, 21 Aug 2011 16:07:39 -0700 (PDT) Subject: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm Message-ID: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm http://tinyurl.com/3d4x2hm From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 19:17:14 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 01:17:14 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <1313968634.3135.14.camel@thegeorge> Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: > In article , > Christian Heimes wrote: > > > Am 21.08.2011 19:27, schrieb Andreas Lscher: > > > As for using Integers, the first case (line 1319 and 1535) are true and > > > there is no difference in Code. However, Python uses a huge switch-case > > > construct to execute it's opcodes and INPLACE_ADD cames after > > > BINARY_ADD, hence the difference in speed. > > > > I don't think that's the reason. Modern compiles turn a switch statement > > into a jump or branch table rather than a linear search like chained > > elif statements. > > This is true even for very small values of "modern". I remember the > Unix v6 C compiler (circa 1977) was able to do this. What is the difference in speed between a jump table that is searched from top to bottom in comparison to an ordinary if-then-elif...? The difference can only be in the search algorithm regarding the table. Without optimization (linear search) both are the same. If the compiler applies some magic the difference can be relevant (linear complexity for if-then-elif... and O(1) if you would use a dictionary). Hence the executed code for integers is the same, there must be a slower path to the code of BINARY_ADD than to INPLACE_ADD. How would such an jump table work to behave the same liek a switch-case-statement? Beware, that things like case PRINT_NEWLINE_TO: 1802 w = stream = POP(); 1803 /* fall through to PRINT_NEWLINE */ 1804 1805 case PRINT_NEWLINE: must be supported. Bye the way: First line of ceval.c since at least Version 2.4 1 2 /* Execute compiled code */ 3 4 /* XXX TO DO: 5 XXX speed up searching for keywords by using a dictionary 6 XXX document it! 7 */ :-) From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 19:25:34 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 01:25:34 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <1313969134.3135.21.camel@thegeorge> Am Sonntag, den 21.08.2011, 12:53 -0700 schrieb Laurent: > > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with > > floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. It's not as bad as you think. The addition of two integers is a cheap task (in terms of computation power). If you have two way's to to it, every little think (jumps in the code etc. ) will have a larger impact on the execution time than on an expensive operation. But every improvement on your algorithm will easily result in a significant shorter execution time than replaceing a+=1 with a=a+1 will ever do. :-) From rosuav at gmail.com Sun Aug 21 19:37:45 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 00:37:45 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313968634.3135.14.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: 2011/8/22 Andreas L?scher : > How would such an jump table work to behave the same liek a > switch-case-statement? If your switch statement uses a simple integer enum with sequential values, then it can be done quite easily. Take this as an example: switch (argc) { case 0: printf("No args at all, this is weird\n"); break; case 1: printf("No args\n"); break; case 2: printf("Default for second arg\n"); case 3: printf("Two args\n"); break; default: printf("Too many args\n"); break; } I compiled this using Open Watcom C, looked at the disassembly, and hereby translate it into pseudocode (I'll email/post the full 80x86 disassembly if you like): 1) Check if argc > 3 (unsigned comparison), if so jump to default case. 2) Left shift argc two places, add a constant offset, fetch a pointer from there, and jump to it - that's the jump table. One JMP statement. 3) Code follows for each case. Incidentally, the Open Watcom compiler actually turned several of the cases into offset-load of the appropriate string pointer, and then a jump to the single call to printf. The fall-through from 'case 2' to 'case 3' works fine, although it means that 'case 2' has to be de-optimized from that one simplification. This type of optimization works best when the case values are sequential. (If I remove the 'case 0', the compiler decrements argc and proceeds to continue as above.) Otherwise, the jump table has to have a lot of copies of the "default" pointer. Chris Angelico From tjreedy at udel.edu Sun Aug 21 19:38:22 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 19:38:22 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313968634.3135.14.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: On 8/21/2011 7:17 PM, Andreas L?scher wrote: > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: >> In article, >> Christian Heimes wrote: >> >>> Am 21.08.2011 19:27, schrieb Andreas Lscher: >>>> As for using Integers, the first case (line 1319 and 1535) are true and >>>> there is no difference in Code. However, Python uses a huge switch-case >>>> construct to execute it's opcodes and INPLACE_ADD cames after >>>> BINARY_ADD, hence the difference in speed. >>> >>> I don't think that's the reason. Modern compiles turn a switch statement >>> into a jump or branch table rather than a linear search like chained >>> elif statements. >> >> This is true even for very small values of "modern". I remember the >> Unix v6 C compiler (circa 1977) was able to do this. > > What is the difference in speed between a jump table that is searched > from top to bottom in comparison to an ordinary if-then-elif...? The > difference can only be in the search algorithm regarding the table. > Without optimization (linear search) both are the same. If the compiler > applies some magic the difference can be relevant (linear complexity for > if-then-elif... and O(1) if you would use a dictionary). A jump or branch table is applicable when the case value values are all small ints, like bytes or less. For C, the table is simply an array of pointers (addressess, with entries for unused byte codes would be a void pointer). Hence, O(1) access. https://secure.wikimedia.org/wikipedia/en/wiki/Jump_table > Hence the executed code for integers is the same, there must be a slower > path to the code of BINARY_ADD than to INPLACE_ADD. > > How would such an jump table work to behave the same liek a > switch-case-statement? Beware, that things like > > case PRINT_NEWLINE_TO: > 1802 w = stream = POP(); > 1803 /* fall through to PRINT_NEWLINE */ add jump to address of the code for PRINT_NEWLINE > 1804 > 1805 case PRINT_NEWLINE: > > must be supported. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 21 19:41:43 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 00:41:43 +0100 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313969134.3135.21.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: 2011/8/22 Andreas L?scher : > But every improvement on your algorithm will easily result in a > significant shorter execution time than replaceing a+=1 with a=a+1 will > ever do. :-) > Agreed. If Python needed a faster alternative to "a=a+1", then I would recommend an "a.inc()" call or something; some way to avoid looking up the value of 1. (An equivalent to C's ++a operation, if you like.) But I think you'd be hard-pressed to find any situation where improving the speed of incrementing will be significant, that wouldn't be better served by algorithmic improvements (even just using "for a in range()") or dropping to C. ChrisA From laurent.payot at gmail.com Sun Aug 21 19:49:30 2011 From: laurent.payot at gmail.com (Laurent Payot) Date: Sun, 21 Aug 2011 16:49:30 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> I made Python my language of choice because of its readability and simpleness, and not because of its speed. But it's always good to know what is the fastest sometimes when you don't want to write a module in C. So I was just wondering if there was a difference. There is, of a few percent. Anyway I will keep on using the 2% slower "i += 1" because for me that's less prone to errors because you write the variable only once, and that's more important than speed. From andreas.loescher at s2005.tu-chemnitz.de Sun Aug 21 20:00:38 2011 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 22 Aug 2011 02:00:38 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: <1313971238.3713.0.camel@thegeorge> Am Sonntag, den 21.08.2011, 19:38 -0400 schrieb Terry Reedy: > On 8/21/2011 7:17 PM, Andreas L?scher wrote: > > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: > >> In article, > >> Christian Heimes wrote: > >> > >>> Am 21.08.2011 19:27, schrieb Andreas Lscher: > >>>> As for using Integers, the first case (line 1319 and 1535) are true and > >>>> there is no difference in Code. However, Python uses a huge switch-case > >>>> construct to execute it's opcodes and INPLACE_ADD cames after > >>>> BINARY_ADD, hence the difference in speed. > >>> > >>> I don't think that's the reason. Modern compiles turn a switch statement > >>> into a jump or branch table rather than a linear search like chained > >>> elif statements. > >> > >> This is true even for very small values of "modern". I remember the > >> Unix v6 C compiler (circa 1977) was able to do this. > > > > What is the difference in speed between a jump table that is searched > > from top to bottom in comparison to an ordinary if-then-elif...? The > > difference can only be in the search algorithm regarding the table. > > Without optimization (linear search) both are the same. If the compiler > > applies some magic the difference can be relevant (linear complexity for > > if-then-elif... and O(1) if you would use a dictionary). > > A jump or branch table is applicable when the case value values are all > small ints, like bytes or less. For C, the table is simply an array of > pointers (addressess, with entries for unused byte codes would be a void > pointer). Hence, O(1) access. > https://secure.wikimedia.org/wikipedia/en/wiki/Jump_table > > > Hence the executed code for integers is the same, there must be a slower > > path to the code of BINARY_ADD than to INPLACE_ADD. > > > > How would such an jump table work to behave the same liek a > > switch-case-statement? Beware, that things like > > > > case PRINT_NEWLINE_TO: > > 1802 w = stream = POP(); > > 1803 /* fall through to PRINT_NEWLINE */ > > add jump to address of the code for PRINT_NEWLINE > > > 1804 > > 1805 case PRINT_NEWLINE: > > > > must be supported. > :-) too easy or too late thanks From steve+comp.lang.python at pearwood.info Sun Aug 21 20:25:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 10:25:40 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e51a205$0$29974$c3e8da3$5496439d@news.astraweb.com> Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> >> Yes, you're absolutely correct. But it's also irrelevant. Most of those >> exceptions should not be caught, even if you know what they are, because >> they represent either bugs that should be fixed, or bad data which should >> raise an exception. A bare except, or except Exception, is hardly ever >> the right approach. > > I'm not sure what to do instead. The exceptions I'm currently dealing > with happen when certain network operations go wrong (e.g. network or > remote host is down, connection fails, etc.) The remedy in each case is > to catch the exception, log the error, and try the operation again > later. But there's no guaranteed-to-be-complete list in the Python docs > of all the exceptions that can be thrown. A new and surprising mode of > network failure can lead to an unhandled exception, unless you catch > everything. I was waiting for you to raise network errors :) Network errors are a particularly annoying case, because although rare and undocumented, they are legitimate errors that should be caught. I feel your pain. > The Erlang approach is tempting. Don't catch the exception at all--just > let the process crash, and restart it. But that's a more heavyweight > operation in Python. The Erland approach sounds good, but as I've never used it, I don't know how well it works in practice. >> After all, unless you're writing >> software for a nuclear reactor, or an aeroplane's autopilot, chances are >> that *bugs don't really matter*. That is to say, if you release software >> with a hidden bug, the consequences generally aren't very important. > > It's a retail application that would cause some business disruption and > a pissed off customer if the program went down. Also it's in an > embedded box on a customer site. It's not in Antarctica or anything > like that, but it's a few towns over, and someone would have to drive > there (probably through heavy traffic) if something went wrong that > power cycling the box couldn't fix. Customers are always pissed off when something goes wrong, but ask them to pay an extra $300 for a battery backup unit to the hardware RAID controller *they* insisted on against your advice, and they say no. But I'm not bitter... Customer gets pissed off. What's the consequences? Do they sue you? Leave? Are they locked into a five year contract and have to pay you even if they do leave? Do you have to fix the incident at no charge, or give them two hours free support? Are you competing with armour-plated mature software that never goes down, or is the field yours alone? How price sensitive are your customers? Will they pay an extra $100,000 for an extra 9 in the expected uptime? Without knowing the consequences to *you* of failure, I can't tell you where you should be spending your time: trying to predict errors ahead of time, or fixing them once they've been seen. This is a business problem, not a software problem. Don't misunderstand me, I'm not suggesting that you shouldn't try to avoid things going wrong. But it's a hard problem. Solving it is why they pay you the big bucks *cough*: http://www.joelonsoftware.com/items/2007/12/06.html and is the difference between version 0.4 of an application, and version 3.4. If you're trying to go straight to version 3.4 without putting the software through real-world testing, then your testing better be mean and tough. *Really* tough. http://www.codinghorror.com/blog/2011/04/working-with-the-chaos-monkey.html -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 21 20:30:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 10:30:37 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > A new and surprising mode of network failure would be indicated by a > new subclass of IOError or EnvironmentError. /s/would/should/ I don't see why you expect this, when *existing* network-related failures aren't: >>> import socket >>> issubclass(socket.error, EnvironmentError) False (Fortunately that specific example is fixed in Python 3.) Besides, there's a world of difference between "should be" and "are". -- Steven From tjreedy at udel.edu Sun Aug 21 20:35:32 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 20:35:32 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/21/2011 5:07 PM, Nobody wrote: > If the value on the left has an __iadd__ method, that will be called; Correct > the value will be updated in-place, Not necessarily correct. The target is rebound to the return from the __iadd__ method. Augmented *assignment* is always assignment. This trips up people who try t = (1, []) t[1] += [1,2] # which *does* extend the array, but raises TypeError: 'tuple' object does not support item assignment # instead of t[1].extend([1,2]) # which extends without raising an error *IF* (and only if) the target object is mutable, then the __iadd__ may optionally mutate the target object. But the rebinding takes place nonetheless. Numbers, the subject of this thread, are not mutable and are not 'updated in-place' class test: def __init__(self, n): self.n = n def __iadd__(self, other): return test(self.n + other.n) def __repr__(self): return repr(self.n) r = test(1) t = r t += r print(r, t) # 1,2 That said, there is normally no reason to write an __ixxx__ method unless instances are mutable and the operation can be and is done in place therein. So the class above is for illustrative purposes only. A saner example is the following, which treats test examples as mutable number containers rather than as immutable surrogates. class test: def __init__(self, n): self.n = n def __add__(self, other): return test(self.n + other.n) def __iadd__(self, other): n = self.n + other.n self.n = n return n def __repr__(self): return repr(self.n) r = test(1) t = r t += r print(r, t) # 2 2 The interpreter cannot enforce that 'x += a' have the same effect as 'x = x+a', but it would break normal expectations to make the two different. > so all references to that object will be affected: Only if the target object is mutable and is mutated by the optional augmented assignment __ixxx__ methods. > > import numpy as np > > a = np.zeros(3) Numpy arrays meet the qualification above. > If the value on the left doesn't have an __iadd__ method, then addition is > performed and the name is re-bound to the result: As is also done with the results of __ixxx__ methods. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 21 20:41:47 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 01:41:47 +0100 Subject: try... except with unknown error types In-Reply-To: <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 22, 2011 at 1:30 AM, Steven D'Aprano wrote: > /s/would/should/ > > I don't see why you expect this, when *existing* network-related failures > aren't Ehh, granted. Definitely a case of "should". But certainly, there won't be an infinite number of new exceptions invented; most of the runtime issues you'll have will fall into a fairly small number of exception types (either by subclassing or by parameters eg errno). ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 21 21:12:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 11:12:54 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> Message-ID: <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Laurent wrote: > >> With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with >> floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. > I would never have thought an interpreter would have differences like this > in syntax for something as fundamental as adding 1. Why? Python integers are rich objects, not native ints. Adding 1 is a moderately heavyweight operation far more complicated than the same operation in C. n=n+1 and n+=1 call different methods and do different things, they are *not* just different syntax. Your intuition about what should and shouldn't take the same time should not be trusted. But really, we're talking about tiny differences in speed. Such trivial differences are at, or beyond, the limit of what can realistically be measured on a noisy PC running multiple processes (pretty much all PCs these days). Here are three runs of each on my computer: [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.508 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.587 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.251 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.226 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.494 usec per loop [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.53 usec per loop Look at the variation between runs! About 130% variation between the fastest and slowest for each expression. And there's no reason to think that the fastest results shown is as fast as it can get. The time is dominated by noise, not the addition. For what it's worth, if I try it with a more recent Python: [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.221 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.202 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' 1000000 loops, best of 3: 0.244 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.49 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.176 usec per loop [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 1000000 loops, best of 3: 0.49 usec per loop I simply do not believe that we can justify making *any* claim about the relative speeds of n=n+1 and n+=1 other than "they are about the same". Any result you get, faster or slower, will depend more on chance than on any real or significant difference in the code. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 21 21:16:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 11:16:58 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: <4e51ae0a$0$29975$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > 2011/8/22 Andreas L?scher : >> But every improvement on your algorithm will easily result in a >> significant shorter execution time than replaceing a+=1 with a=a+1 will >> ever do. :-) >> > > Agreed. If Python needed a faster alternative to "a=a+1", then I would > recommend an "a.inc()" call or something; some way to avoid looking up > the value of 1. Keep in mind that ints in Python are objects, not memory locations, and can be shared. If you are hoping for an in-place increment, I invite you to consider the following code and try to predict what it would do: a = 42 b = a b.inc() print(a) -- Steven From jefflovejapan at gmail.com Sun Aug 21 21:27:33 2011 From: jefflovejapan at gmail.com (jefflovejapan) Date: Sun, 21 Aug 2011 18:27:33 -0700 (PDT) Subject: Installing numpy on 2.7 (OS X 10.7) References: Message-ID: <9f35a78c-6af9-4e47-be4d-aaa898ac4f03@p37g2000prp.googlegroups.com> On Aug 21, 10:39?pm, Benjamin Kaplan wrote: > On Sun, Aug 21, 2011 at 6:03 AM, jefflovejapan wrote: > > I'm following the instructions given > Installing_SciPy/Mac_OS_X">here, but it isn't working. > > Specifically, I'm getting: > > > Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/ > > Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such > > file or directory > > > even though I completed the two downloads from github successfully. > > Any ideas why this wouldn't be working, or any ideas where I can look > > for better instructions? > > -- > > As the error says, it can't find the setup.py file. My guess would be > you forgot to cd to the newly created directory. You have to "cd > numpy" (or cd scipy if you're trying to install that) first to get > into the directory with the install script. Of course! Thanks a lot. From timr at probo.com Sun Aug 21 22:02:56 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Aug 2011 19:02:56 -0700 Subject: Wait for a keypress before continuing? References: <4e3f2827$0$5826$c3e8da3$12bcf670@news.astraweb.com> <4e4ad039$0$9663$c3e8da3$76491128@news.astraweb.com> <4e4ae844$0$29730$c3e8da3$92d0a893@news.astraweb.com> Message-ID: <2vd357poedkl0icmu8m1dsmfq6aalujnpq@4ax.com> John Doe wrote: > >Tim Roberts wrote: > >> That exact code works perfectly for me. The function returns as >> soon as I press the escape key. You are running this from a >> console process, and not a GUI process, right? > >No. I am running this from within Windows, all sorts of Windows. > >So... Does that mean I will need something complex like a keyboard >hook? Or what? I see that this conversation took a nasty turn while I was on vacation. msvcrt.getch works with consoles. If you have an application where stdin and stdout are connected to a real, live console window (which looks just like a command line window), then msvcrt.getch will work. If not, then you have to use the Windows APIs. GetKeyboardState and GetKeyState can tell you if a specific key is currently being pressed. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From lists at cheimes.de Sun Aug 21 22:04:08 2011 From: lists at cheimes.de (Christian Heimes) Date: Mon, 22 Aug 2011 04:04:08 +0200 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <1313969134.3135.21.camel@thegeorge> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: Am 22.08.2011 01:25, schrieb Andreas L?scher: > It's not as bad as you think. The addition of two integers is a cheap > task (in terms of computation power). If you have two way's to to it, > every little think (jumps in the code etc. ) will have a larger impact > on the execution time than on an expensive operation. > > But every improvement on your algorithm will easily result in a > significant shorter execution time than replaceing a+=1 with a=a+1 will > ever do. :-) You can learn an important lesson here. Since Python is a high level language without a JIT (yet) integer operations are much slower than in C or other low level languages. In general it's not a problem for most people. However if your algorithm is speed bound to integer operations or has a tight inner for loop than you can gain a considerable amount of speedup with C code. Reference counting and Python object creation need several CPU cycles. Also a good algorithm and a modern C compiler can make use of SIMD instructions, too. If you ever feel the need to implement something fast e.g. an encryption algorithm then you'd better off with a C implementation. Cython is my favourite tool for the job. Christian From me+list/python at ixokai.io Sun Aug 21 22:08:22 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 19:08:22 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <4E51BA16.7090605@ixokai.io> On 8/21/11 12:53 PM, Laurent wrote: > >> With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with >> floats (0.0 and 1.0), 6% > > For floats it is understandable. But for integers, seriously, 4% is a lot. I would never have thought an interpreter would have differences like this in syntax for something as fundamental as adding 1. Its, seriously, not even kind of a lot at all. Percentages without context are meaningless: its 4% slower, sure -- but that is 4% of an incredibly small probably constant-time amount of time. Picking "i += 1" over "i = i + 1" based on one being 4% slower is sorta kinda crazy. The difference in speed is probably related to churn and cache as much as anything else (its not as consistent on my machine, for example): or the ceval loop doing a few more case-tests between them as others have mentioned. All in all, if 4% of a nanomicrofraction of a chunk of time is that meaningful, you're probably best served not using Python. :) That said: my advice is always to avoid += like a plague. It is magic and impossible to predict without intimate knowledge of exactly what's on the left-side. i += 1 n += x Those two things look very similar, but they may do -completely- different things depending on just what "n" is. It may or may not do something that is like: n = n + x Or, it may do something that's more akin to n.extend(x) n = n Those aren't even kind of equivalent actions. And things get more complicated if 'n' is say, n[0] (especially if something goes wrong between the extend and the rebinding). Python's usually all explicit and pretty well-defined in how its basic syntax and behaviors operate, and you usually don't really have to know details about how a data-type works to predict exactly what it's doing: in fact, its often beneficial to not pay too much attention to such details, and just assume the data type will work approximately as you'd expect. That way people can slip something-something to you and wink and say of /course/ its a dict, darling. Try it, you'll like it, okay? This sorta thing is encouraged, but it kinda depends on trusting objects to behave a certain way and for things to be predictable in both how they work and how they fail. With "i = i + 1", I know that generally speaking, my "i" is being assigned a new object and that's that, no matter what type "i" is. (Okay: I do know that you could modify __add__ to do something underhanded here, tweaking internal state and then returning self. People going out of their way to behave unpredictably is not my objection: supposedly easy and straight-forward normal Python-fu being inherently unpredictable is). For example: I just /know/ that it doesn't matter who or what may have their own binding to that object before I go and increment it, they won't be affected and everything just will work fine. With augmented assignment, I can't be sure of that. Now, while I admit, you generally do have to keep track in your head of which of your data-types are mutable vs immutable and take care with sharing mutables, the fact that "n += x" is described and generally thought of as merely syntactical sugar for: n = n + x ... lets one easily think that this should be entirely safe, even with mutable objects, because if += were merely syntactical sugar, it would be. But its not! Because += is wiggly. It can do more then one entirely different kind of behavior. Anyways. I've been kinda annoyed at augmented assignment for years now :P -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From roy at panix.com Sun Aug 21 22:09:19 2011 From: roy at panix.com (Roy Smith) Date: Sun, 21 Aug 2011 22:09:19 -0400 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a205$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e51a205$0$29974$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > http://www.codinghorror.com/blog/2011/04/working-with-the-chaos-monkey.html I *love* being the Chaos Monkey! A few jobs ago, I had already turned in my resignation and was a short-timer, counting down the days to when I was out of there. A new server had just come in and I was helping the guy who was going to replace me set it up. This was the first server we had gotten with RAID and redundant power supplies and I wanted to test them out. My accomplice was horrified, but technically I was still his boss, so I got to do what I wanted. I opened up the drive shelve and yanked out a drive. The console printed a nice neat warning about loss of media and kept chugging along, just like it should. Then I pulled out a second drive. Sure enough, the whole array failed, just like expected. Then, I decided to have a go at the redundant power supplies. We paid a lot of money for that, and I damn well was going to test them now, when there was no real risk. I grabbed the big handle on the front of one of the (hot swappable) power supplies and pulled. The whole thing went dark. Turns out there had been an configuration error and the second power supply had never been installed (just a faceplate that looked like a power supply). My buddy was pissed, but I figure I'd just done him a big favor. Better to find out about it now than when the supply failed at some critical juncture. From tjreedy at udel.edu Sun Aug 21 22:11:46 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 22:11:46 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <1313969134.3135.21.camel@thegeorge> Message-ID: On 8/21/2011 7:41 PM, Chris Angelico wrote: > Agreed. If Python needed a faster alternative to "a=a+1", then I would > recommend an "a.inc()" call or something But looking up the method name, creating a bound method wrapper, and making the call would probably be slower than the syntax;-). -- Terry Jan Reedy From tjreedy at udel.edu Sun Aug 21 22:15:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Aug 2011 22:15:07 -0400 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> References: <8c606fc1-0aa8-4113-b607-e46ad6f3d649@glegroupsg2000goo.googlegroups.com> <62dbc2b2-36bd-420c-a5f5-3a6aefcdc139@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/21/2011 7:49 PM, Laurent Payot wrote: > I made Python my language of choice because of its readability and > simpleness, and not because of its speed. But it's always good to > know what is the fastest sometimes when you don't want to write a > module in C. So I was just wondering if there was a difference. There > is, of a few percent. Anyway I will keep on using the 2% slower "i += > 1" because for me that's less prone to errors because you write the > variable only once, and that's more important than speed. For longer variable names, it is also easier and faster to read once one gets used to the idiom. number_of_chars += 1 # versus number_of_chars = number_of_chars + 1 Not repeating was a major reason for the addition. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Aug 22 00:01:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 14:01:55 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e51d4b3$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 10:41 am Chris Angelico wrote: > On Mon, Aug 22, 2011 at 1:30 AM, Steven D'Aprano > wrote: >> /s/would/should/ >> >> I don't see why you expect this, when *existing* network-related failures >> aren't > > Ehh, granted. Definitely a case of "should". But certainly, there > won't be an infinite number of new exceptions invented; most of the > runtime issues you'll have will fall into a fairly small number of > exception types (either by subclassing or by parameters eg errno). Er, you can't know that either. Except that all exceptions must be rooted at BaseException, there *can* be an infinite number of new exception types invented. Or functions could raise unexpected, but known, exceptions, whether built-in or not. Of course, the set of hypothetical exceptions that could theoretically be raised is much, much bigger than the set of exceptions which you can realistically expect to see, especially if you limit yourself to those that don't leave you wondering about the sanity of the developer ("WTF? Why is x+1 raising HTTPBadGatewayError?"). But still, as a general rule you should not be surprised to see any of: AttributeError TypeError ValueError (and likely others) The more important question is, if you get an exception, any exception, is that a bug in the function you are calling, a bug in your calling code (you supplied a bad argument), or an expected result that you should catch and work around? -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 22 00:14:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 14:14:32 +1000 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> Message-ID: <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 12:08 pm Stephen Hansen wrote: > Picking "i += 1" over "i = i + 1" based on one being 4% slower is sorta > kinda crazy. The difference in speed is probably related to churn and > cache as much as anything else (its not as consistent on my machine, for > example): or the ceval loop doing a few more case-tests between them as > others have mentioned. All in all, if 4% of a nanomicrofraction of a > chunk of time is that meaningful, you're probably best served not using > Python. :) Agreed. But... > That said: my advice is always to avoid += like a plague. It is magic > and impossible to predict without intimate knowledge of exactly what's > on the left-side. > > i += 1 > n += x > > Those two things look very similar, but they may do -completely- > different things depending on just what "n" is. Technically, the *exact same criticism* can be applied to: n = n + x since either n or x could override __add__ or __radd__ and do anything it bloody well likes. Including in-place modification of *either* argument (where possible). [...] > With "i = i + 1", I know that generally speaking, my "i" is being > assigned a new object and that's that, no matter what type "i" is. > (Okay: I do know that you could modify __add__ to do something > underhanded here, tweaking internal state and then returning self. What makes you think that's underhanded? To my mind, __add__ modifying self as a side-effect is unusual, but apart from breaking the general rule of thumb to avoid side-effects, not particularly evil. (But I would accept this is a code smell.) > People going out of their way to behave unpredictably is not my > objection: supposedly easy and straight-forward normal Python-fu being > inherently unpredictable is). > > For example: I just /know/ that it doesn't matter who or what may have > their own binding to that object before I go and increment it, they > won't be affected and everything just will work fine. But you can't /know/ that at all, unless you know that the object isn't "underhanded" (however you define that!). And given some arbitrary object, how can you know that? -- Steven From casevh at gmail.com Mon Aug 22 00:14:37 2011 From: casevh at gmail.com (casevh) Date: Sun, 21 Aug 2011 21:14:37 -0700 (PDT) Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <1313947658.3424.3.camel@thegeorge> Message-ID: <320f5fed-e32d-43a3-846a-5f0ed584c9e5@y8g2000prd.googlegroups.com> On Aug 21, 10:27?am, Andreas L?scher wrote: > > from Python/ceval.c: > > 1316 ? ? ? ? ? ?case BINARY_ADD: > 1317 ? ? ? ? ? ? ? ?w = POP(); > 1318 ? ? ? ? ? ? ? ?v = TOP(); > 1319 ? ? ? ? ? ? ? ?if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { > 1320 ? ? ? ? ? ? ? ? ? ?/* INLINE: int + int */ > 1321 ? ? ? ? ? ? ? ? ? ?register long a, b, i; > 1322 ? ? ? ? ? ? ? ? ? ?a = PyInt_AS_LONG(v); > 1323 ? ? ? ? ? ? ? ? ? ?b = PyInt_AS_LONG(w); > 1324 ? ? ? ? ? ? ? ? ? ?/* cast to avoid undefined behaviour > 1325 ? ? ? ? ? ? ? ? ? ? ? on overflow */ > 1326 ? ? ? ? ? ? ? ? ? ?i = (long)((unsigned long)a + b); > 1327 ? ? ? ? ? ? ? ? ? ?if ((i^a) < 0 && (i^b) < 0) > 1328 ? ? ? ? ? ? ? ? ? ? ? ?goto slow_add; > 1329 ? ? ? ? ? ? ? ? ? ?x = PyInt_FromLong(i); > 1330 ? ? ? ? ? ? ? ?} > 1331 ? ? ? ? ? ? ? ?else if (PyString_CheckExact(v) && > 1332 ? ? ? ? ? ? ? ? ? ? ? ? PyString_CheckExact(w)) { > 1333 ? ? ? ? ? ? ? ? ? ?x = string_concatenate(v, w, f, next_instr); > 1334 ? ? ? ? ? ? ? ? ? ?/* string_concatenate consumed the ref to v */ > 1335 ? ? ? ? ? ? ? ? ? ?goto skip_decref_vx; > 1336 ? ? ? ? ? ? ? ?} > 1337 ? ? ? ? ? ? ? ?else { > 1338 ? ? ? ? ? ? ? ? ?slow_add: > 1339 ? ? ? ? ? ? ? ? ? ?x = PyNumber_Add(v, w); > 1340 ? ? ? ? ? ? ? ?} > 1341 ? ? ? ? ? ? ? ?Py_DECREF(v); > 1342 ? ? ? ? ? ? ?skip_decref_vx: > 1343 ? ? ? ? ? ? ? ?Py_DECREF(w); > 1344 ? ? ? ? ? ? ? ?SET_TOP(x); > 1345 ? ? ? ? ? ? ? ?if (x != NULL) continue; > 1346 ? ? ? ? ? ? ? ?break; > > 1532 ? ? ? ? ? ?case INPLACE_ADD: > 1533 ? ? ? ? ? ? ? ?w = POP(); > 1534 ? ? ? ? ? ? ? ?v = TOP(); > 1535 ? ? ? ? ? ? ? ?if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { > 1536 ? ? ? ? ? ? ? ? ? ?/* INLINE: int + int */ > 1537 ? ? ? ? ? ? ? ? ? ?register long a, b, i; > 1538 ? ? ? ? ? ? ? ? ? ?a = PyInt_AS_LONG(v); > 1539 ? ? ? ? ? ? ? ? ? ?b = PyInt_AS_LONG(w); > 1540 ? ? ? ? ? ? ? ? ? ?i = a + b; > 1541 ? ? ? ? ? ? ? ? ? ?if ((i^a) < 0 && (i^b) < 0) > 1542 ? ? ? ? ? ? ? ? ? ? ? ?goto slow_iadd; > 1543 ? ? ? ? ? ? ? ? ? ?x = PyInt_FromLong(i); > 1544 ? ? ? ? ? ? ? ?} > 1545 ? ? ? ? ? ? ? ?else if (PyString_CheckExact(v) && > 1546 ? ? ? ? ? ? ? ? ? ? ? ? PyString_CheckExact(w)) { > 1547 ? ? ? ? ? ? ? ? ? ?x = string_concatenate(v, w, f, next_instr); > 1548 ? ? ? ? ? ? ? ? ? ?/* string_concatenate consumed the ref to v */ > 1549 ? ? ? ? ? ? ? ? ? ?goto skip_decref_v; > 1550 ? ? ? ? ? ? ? ?} > 1551 ? ? ? ? ? ? ? ?else { > 1552 ? ? ? ? ? ? ? ? ?slow_iadd: > 1553 ? ? ? ? ? ? ? ? ? ?x = PyNumber_InPlaceAdd(v, w); > 1554 ? ? ? ? ? ? ? ?} > 1555 ? ? ? ? ? ? ? ?Py_DECREF(v); > 1556 ? ? ? ? ? ? ?skip_decref_v: > 1557 ? ? ? ? ? ? ? ?Py_DECREF(w); > 1558 ? ? ? ? ? ? ? ?SET_TOP(x); > 1559 ? ? ? ? ? ? ? ?if (x != NULL) continue; > 1560 ? ? ? ? ? ? ? ?break; > > As for using Integers, the first case (line 1319 and 1535) are true and > there is no difference in Code. However, Python uses a huge switch-case > construct to execute it's opcodes and INPLACE_ADD cames after > BINARY_ADD, hence the difference in speed. That fragment of cevel.c is from a 2.x version. Python 2.x supports both a PyInt and PyLong type and the cevel loop optimized the PyInt case only. On my system, I could not measure a difference between binary and inplace addition. Python 3.x behaves differently: TARGET(BINARY_ADD) w = POP(); v = TOP(); if (PyUnicode_CheckExact(v) && PyUnicode_CheckExact(w)) { x = unicode_concatenate(v, w, f, next_instr); /* unicode_concatenate consumed the ref to v */ goto skip_decref_vx; } else { x = PyNumber_Add(v, w); } Py_DECREF(v); skip_decref_vx: Py_DECREF(w); SET_TOP(x); if (x != NULL) DISPATCH(); break; TARGET(INPLACE_ADD) w = POP(); v = TOP(); if (PyUnicode_CheckExact(v) && PyUnicode_CheckExact(w)) { x = unicode_concatenate(v, w, f, next_instr); /* unicode_concatenate consumed the ref to v */ goto skip_decref_v; } else { x = PyNumber_InPlaceAdd(v, w); } Py_DECREF(v); skip_decref_v: Py_DECREF(w); SET_TOP(x); if (x != NULL) DISPATCH(); break; cevel just calls PyNumber_Add or PyNumber_InPlaceAdd. If you look at the code for PyNumber_InPlaceAdd (in abstract.c), it calls an internal function binary_iop1 with pointers to nb_inplace_add and nb_add. binary_iop1 then checks if nb_inplace_add exists. The PyLong type does not implement nb_inplace_add so the check fails and binary_iop1 used nb_add. In recent version of gmpy and gmpy2, I implemented the nb_inplace_add function and performance (for the gmpy.mpz type) is much better for the in-place addition. For the adventuresome, gmpy2 implements a mutable integer type called xmpz. It isn't much faster until the values are so large that the memory copy times become significant. (Some old gmpy documentation implies that operations with mutable integers should be much faster. With agressive caching of deleted objects, the object creation overhead is very low. So the big win for mutable integers is reduced to avoiding memory copies.) casevh > > To be clear, this is nothing you should consider when writing fast code. > Complexity wise they both are the same. From jialiuonlineshoe02 at 163.com Mon Aug 22 00:19:47 2011 From: jialiuonlineshoe02 at 163.com (amy) Date: Sun, 21 Aug 2011 21:19:47 -0700 (PDT) Subject: paypal wholesale gucci (paypal payment)( http://www.24hour-buy.com/) Message-ID: paypal wholesale d&g shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale gucci shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale lv shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale NBA shoes (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale nike (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale adidas shoes (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale gucci shoes (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale bape hoody (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale antick jeans (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale diesel jeans (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale artful dudger (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale bag(lv gucci coach chanel d&g dior ed fendi ) (paypal payment)(http://www.24hour-buy.com/) paypal wholesale clothing (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale lrg,jeans,hoody, (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale evisu jeans,hoody,shirt (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Prada (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Puma (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Sand (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Shox (paypal payment)( http://www.24hour-buy.com/) paypal wholesale soccer (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale gucci (paypal payment)( http://www.24hour-buy.com/) paypal wholesale Versace (paypal payment) ( http://www.24hour-buy.com/ ) paypal wholesale Women (paypal payment) ( http://www.24hour-buy.com/) paypal wholesale Y-3 (paypal payment)( http://www.24hour-buy.com/ ) From me+list/python at ixokai.io Mon Aug 22 00:37:16 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 21:37:16 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E51DCFC.60106@ixokai.io> On 8/21/11 9:14 PM, Steven D'Aprano wrote: >> That said: my advice is always to avoid += like a plague. It is magic >> and impossible to predict without intimate knowledge of exactly what's >> on the left-side. >> >> i += 1 >> n += x >> >> Those two things look very similar, but they may do -completely- >> different things depending on just what "n" is. > > Technically, the *exact same criticism* can be applied to: > > n = n + x > > since either n or x could override __add__ or __radd__ and do anything it > bloody well likes. Including in-place modification of *either* argument > (where possible). I know: I addressed that. :P See, you know I addressed that, because: > [...] >> With "i = i + 1", I know that generally speaking, my "i" is being >> assigned a new object and that's that, no matter what type "i" is. >> (Okay: I do know that you could modify __add__ to do something >> underhanded here, tweaking internal state and then returning self. > > What makes you think that's underhanded? You quoted me addressing that very fact, and responded! :) Its underhanded outside of narrow, well-defined situations such as ORM's and the like where they're doing interesting and novel things with the object model. Underhanded doesn't mean there's no reason one should ever do it, but its very much an unusual thing and objects that do things like that should NOT freely interact with general Python objects: very surprising behavior will result. > To my mind, __add__ modifying self as a side-effect is unusual, but apart > from breaking the general rule of thumb to avoid side-effects, not > particularly evil. (But I would accept this is a code smell.) I didn't really say its evil, just that its underhanded: that's like, sketchy, not evil. :) There's good reasons to do it on occasion, but if an object does something like that then that is a very special kind of object and when using it, you need to be very aware of its unusual semantics. Having objects like that is fine. However, for the /language/ to have unusual (and unpredictable, from something of a distance at least) semantics, rubs me very much the wrong way. >> People going out of their way to behave unpredictably is not my >> objection: supposedly easy and straight-forward normal Python-fu being >> inherently unpredictable is). >> >> For example: I just /know/ that it doesn't matter who or what may have >> their own binding to that object before I go and increment it, they >> won't be affected and everything just will work fine. > > But you can't /know/ that at all, unless you know that the object > isn't "underhanded" (however you define that!). And given some arbitrary > object, how can you know that? I CAN know it with sufficient certainty that I can rely on it, and if I get messed up on it-- its never happened yet-- then I can fire someone or get a new library, after staring at an odd traceback and scratching my head for a minute. Python has very soft rules, I know that. Objects /can/ do all kinds of crazy things. I'm okay with that. But I can rely on certain behaviors being consistent: the basic behavior of the language is very straight-forward. It has hooks where you can do lots of Special stuff, and if objects are Special, they're described as Special. ORM's have a lot of Special objects, for example. That's fine: when messing with ORM objects, I know I have to take care with the operators I use against them, because I know I'm not using a /usual/ Python object. SQLAlchemy for example. This is not a criticism of SQLAlchemy: having magic objects lets it construct SQL in ways that are vastly easier then if they stuck to more regularly behaving objects. But, += is Python itself adding an unpredictable behavior into the core language, with its own base types behaving The *exact same criticism* can NOT be applied to n = n + x Because my criticism isn't about one choosing to do crazy stuff with the object model. I've never advocated Python be strict about rules. But for Python, all by itself, with nothing but built-in and basic types, to have a situation where: a = a + b a += b ... does two very distinctly different actions, even if in many or even most circumstances the end-result is probably the same and probably fine, is my criticism. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Mon Aug 22 00:49:03 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 21 Aug 2011 21:49:03 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4E51DCFC.60106@ixokai.io> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <747a8223-0a9b-4691-8886-0a04433e54dc@glegroupsg2000goo.googlegroups.com> <4e51d7a9$0$29992$c3e8da3$5496439d@news.astraweb.com> <4E51DCFC.60106@ixokai.io> Message-ID: <4E51DFBF.6030800@ixokai.io> On 8/21/11 9:37 PM, Stephen Hansen wrote: > But, += is Python itself adding an unpredictable behavior into the core > language, with its own base types behaving ... very differently to fundamental, basic appearing operators. Editing fail on my part. Similarly: > But for Python, all by itself, with nothing but built-in and basic > types, to have a situation where: > > a = a + b > a += b ... would be clearer if the second example were "x += y". > ... does two very distinctly different actions, even if in many or > even most circumstances the end-result is probably the same and probably > fine, is my criticism. > -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From research at johnohagan.com Mon Aug 22 01:04:45 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 22 Aug 2011 15:04:45 +1000 Subject: Adding modified methods from another class without subclassing Message-ID: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> I have a class like this: class MySeq(): def __init__(self, *seq, c=12): self.__c = c self.__pc = sorted(set([i % __c for i in seq])) self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) #other calculated attributes @property def pitches(self): return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] #other methods The "pitches" attribute initially reconstructs the "seq" arguments but can be modified by writing to the "order" attribute. The "pitches" attribute represents the instances and as such I found myself adding a lot of methods like: def __getitem__(self, index): return self.pitches[index] def __len__(self): return len(self.pitches) def __iter__(self): return iter(self.pitches) def __repr__(self): return str(self.pitches) and so on, and calling a lot of list methods on the "pitches" attribute of MySeq instances elsewhere. I thought of making MySeq a subclass of list with "pitches" as its contents, but then I would have had to override a lot of methods case-by-case, for example to ensure that any alterations to "pitches" were reflected in the other calculated attributes. So I wrote this function which takes a method, modifies it to apply to an instance attribute, and takes care of any quirks: def listmeth_to_attribute(meth, attr): def new_meth(inst, *args): #ensure comparison operators work: args = [getattr(i, attr) if isinstance(i, inst.__class__) else i for i in args] reference = getattr(inst, attr) test = reference[:] result = meth(test, *args) #ensure instance is reinitialised #if attribute has been changed: if test != reference: inst.__init__(*test) #ensure slices are of same class if isinstance(result, meth.__objclass__): result = inst.__class__(*result) return result return new_meth and this decorator to apply this function to all the list methods and add them to MySeq: def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): """Overides = any methods in target to override from source""" def decorator(target_cls): for name, meth in vars(source_cls).items(): if name not in dir(target_cls) or name in overrides: setattr(target_cls, name, modfunc(meth, *modfunc_args)) return target_cls return decorator a kind of DIY single inheritance, used like this: @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') class MySeq(): ..... Now I can call list methods transparently on MySeq instances, like subclassing but without all the overriding. If this works it will simplify a lot of code in my project. But the fact that I haven't seen this approach before increases the likelihood it may not be a good idea. I can almost hear the screams of "No, don't do that!" or the sound of me slapping my forehead when someone says "Why don't you just...". So before I put it in, I'd appreciate any comments, warnings, criticisms, alternatives etc.. Regards, John From steve+comp.lang.python at pearwood.info Mon Aug 22 01:27:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 15:27:36 +1000 Subject: Adding modified methods from another class without subclassing References: Message-ID: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 03:04 pm John O'Hagan wrote: > The "pitches" attribute represents the instances and as such I found > myself adding a lot of methods like: > > def __getitem__(self, index): > return self.pitches[index] > > def __len__(self): > return len(self.pitches) Looks like a call for (semi-)automatic delegation! Try something like this: # Untested class MySeq(object): methods_to_delegate = ('__getitem__', '__len__', ...) pitches = ... # make sure pitches is defined def __getattr__(self, name): if name in self.__class__.methods_to_delegate: return getattr(self.pitches, name) return super(MySeq, object).__getattr__(self, name) # will likely raise AttributeError > But the fact that I haven't seen this approach before increases the > likelihood it may not be a good idea. I can almost hear the screams of > "No, don't do that!" The general technique is called delegation and is perfectly legitimate. http://c2.com/cgi/wiki?WhatIsDelegation http://en.wikipedia.org/wiki/Delegation_(programming) -- Steven From usenet-nospam at seebs.net Mon Aug 22 01:33:28 2011 From: usenet-nospam at seebs.net (Seebs) Date: 22 Aug 2011 05:33:28 GMT Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <1313968634.3135.14.camel@thegeorge> Message-ID: On 2011-08-21, Andreas L?scher wrote: > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith: >> In article , >> Christian Heimes wrote: >> > I don't think that's the reason. Modern compiles turn a switch statement >> > into a jump or branch table rather than a linear search like chained >> > elif statements. >> This is true even for very small values of "modern". I remember the >> Unix v6 C compiler (circa 1977) was able to do this. > What is the difference in speed between a jump table that is searched > from top to bottom A jump table isn't searched, it's jumped into. You don't look through the table for a matching element, you grab the Nth element of the table. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From saraanderson24 at gmail.com Mon Aug 22 01:41:54 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Sun, 21 Aug 2011 22:41:54 -0700 (PDT) Subject: WATCH WORLD`S MOST FUNNIEST PRANK VIDEOS EVER. Message-ID: WATCH WORLD`S MOST BEAUTIFUL PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S MOST HILARIOUS FUNNIEST VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From tomas at liden-privat.net Mon Aug 22 02:37:42 2011 From: tomas at liden-privat.net (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Sun, 21 Aug 2011 23:37:42 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() Message-ID: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> In what order are the addresses returned by socket.gethostbyname_ex()? We know that gethostbyname() is indeterministic but hope that gethostbyname_ex() has a specified order. Best regards, Tomas From eudes.elie at gmail.com Mon Aug 22 04:04:54 2011 From: eudes.elie at gmail.com (Makiavelik) Date: Mon, 22 Aug 2011 01:04:54 -0700 (PDT) Subject: decorator issue with modules dbus & gobject References: <3278c5bb-0e58-4ce0-aecc-11b18984ec9f@b8g2000vbg.googlegroups.com> Message-ID: <3faf2fbf-120a-42c4-a4c3-29de89ae4a45@q1g2000vbj.googlegroups.com> On 21 ao?t, 18:31, Emile van Sebille wrote: > On 8/18/2011 5:02 AM Makiavelik said... > > > Hi, > > Here is a sample code that reproduces the issue : > > Not really 'sample' enough to allow others to investigate... > > ImportError: No module namedgobject > ImportError: No module nameddbus > ImportError: No module nameddbus.mainloop.glib > > Try to eliminate the non-standard dependencies. ?I wanted to check the > default value set in timeout but there's too much crap to clean up. > > Emile Yes that's right there is a dependency with both modules dbus and gobject (as mentionned in the subject of the thread). The fact is I am not able to quit the looping method of the gobject.Mainloop object without errors ... From steve+comp.lang.python at pearwood.info Mon Aug 22 04:15:52 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 18:15:52 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. Did you want a particular order, or just any deterministic order? Have you considered sorting the addresses yourself? -- Steven From przemolicc at poczta.fm Mon Aug 22 04:52:53 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 10:52:53 +0200 Subject: locale.format without trailing zeros Message-ID: <20110822085253.GA13228@host.pgf.com.pl> Hello, >>> import locale >>> locale.setlocale(locale.LC_ALL, "pl_PL") 'pl_PL' >>> i=0.20 >>> j=0.25 >>> locale.format('%f', i) '0,200000' >>> locale.format('%f', j) '0,250000' I need to print the numbers in the following format: '0,2' (i) '0,25' (j) So the last trailing zeros are not printed. Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From tomas.liden.privat at gmail.com Mon Aug 22 05:06:30 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 02:06:30 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 22 Aug, 10:15, Steven D'Aprano wrote: > On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: > > > In what order are the addresses returned by socket.gethostbyname_ex()? > > > We know that gethostbyname() is indeterministic but hope that > > gethostbyname_ex() has a specified order. > > Did you want a particular order, or just any deterministic order? > > Have you considered sorting the addresses yourself? > > -- > Steven In this particular case we have a host with several connections (LAN, WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare adapter but we wanted to get the LAN (or the "best" connection to our server). With gethostbyname_ex() the ordering seemed to become LAN, Wifi, etc and that's good for us. But we don't know if this holds on other platforms (we're running on Windows 7). A cross-platform deterministic order would be excellent for us. /Tomas From __peter__ at web.de Mon Aug 22 05:32:18 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 11:32:18 +0200 Subject: Adding modified methods from another class without subclassing References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> Message-ID: John O'Hagan wrote: > I have a class like this: > > class MySeq(): > def __init__(self, *seq, c=12): > self.__c = c > self.__pc = sorted(set([i % __c for i in seq])) > self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) > #other calculated attributes > > @property > def pitches(self): > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > > #other methods That makes me dizzy. Are there any maxims in the Zen of Python that this piece doesn't violate? > The "pitches" attribute initially reconstructs the "seq" arguments but can > be modified by writing to the "order" attribute. > > The "pitches" attribute represents the instances and as such I found > myself adding a lot of methods like: > > > def __getitem__(self, index): > return self.pitches[index] > > def __len__(self): > return len(self.pitches) > > def __iter__(self): > return iter(self.pitches) > > def __repr__(self): > return str(self.pitches) > > and so on, and calling a lot of list methods on the "pitches" attribute of > MySeq instances elsewhere. I thought of making MySeq a subclass of list > with "pitches" as its contents, but then I would have had to override a > lot of methods case-by-case, for example to ensure that any alterations to > "pitches" were reflected in the other calculated attributes. > > So I wrote this function which takes a method, modifies it to apply to an > instance attribute, and takes care of any quirks: > > def listmeth_to_attribute(meth, attr): > def new_meth(inst, *args): > #ensure comparison operators work: > args = [getattr(i, attr) if isinstance(i, inst.__class__) > else i for i in args] > reference = getattr(inst, attr) > test = reference[:] > result = meth(test, *args) > #ensure instance is reinitialised > #if attribute has been changed: > if test != reference: > inst.__init__(*test) > #ensure slices are of same class > if isinstance(result, meth.__objclass__): > result = inst.__class__(*result) > return result > return new_meth > > and this decorator to apply this function to all the list methods and add > them to MySeq: > > def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): > """Overides = any methods in target to override from source""" > def decorator(target_cls): > for name, meth in vars(source_cls).items(): > if name not in dir(target_cls) or name in overrides: > setattr(target_cls, name, modfunc(meth, *modfunc_args)) > return target_cls > return decorator > > a kind of DIY single inheritance, used like this: > > @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') > class MySeq(): > ..... > > Now I can call list methods transparently on MySeq instances, like > subclassing but without all the overriding. If this works it will simplify > a lot of code in my project. > > But the fact that I haven't seen this approach before increases the > likelihood it may not be a good idea. I can almost hear the screams of > "No, don't do that!" or the sound of me slapping my forehead when someone > says "Why don't you just...". So before I put it in, I'd appreciate any > comments, warnings, criticisms, alternatives etc.. In the standard library functools.total_ordering uses that technique and I find the implications hard to understand: http://bugs.python.org/issue10042 Your decorator looks even more complex; I'd only recommend using it if you're absolutely sure you're clever enough to debug it ;) From __peter__ at web.de Mon Aug 22 05:48:46 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 11:48:46 +0200 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm wrote: >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > 'pl_PL' >>>> i=0.20 >>>> j=0.25 >>>> locale.format('%f', i) > '0,200000' >>>> locale.format('%f', j) > '0,250000' > > I need to print the numbers in the following format: > '0,2' (i) > '0,25' (j) > So the last trailing zeros are not printed. >>> print locale.format("%g", 1.23) 1,23 >>> print locale.format("%g", 1.2345678) 1,23457 >>> print locale.format("%.10g", 1.2345678) 1,2345678 >>> print locale.format("%.15g", 0.1) 0,1 >>> print locale.format("%.17g", 0.1) 0,10000000000000001 From rdmoores at gmail.com Mon Aug 22 05:55:11 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Mon, 22 Aug 2011 02:55:11 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 21, 2011 at 18:12, Steven D'Aprano wrote: > But really, we're talking about tiny differences in speed. Such trivial > differences are at, or beyond, the limit of what can realistically be > measured on a noisy PC running multiple processes (pretty much all PCs > these days). Here are three runs of each on my computer: > > > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.508 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.587 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.251 usec per loop > > > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.226 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.494 usec per loop > [steve at sylar python]$ python2.5 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.53 usec per loop > > Look at the variation between runs! About 130% variation between the fastest > and slowest for each expression. And there's no reason to think that the > fastest results shown is as fast as it can get. The time is dominated by > noise, not the addition. > > > For what it's worth, if I try it with a more recent Python: > > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.221 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.202 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n = n+1' > 1000000 loops, best of 3: 0.244 usec per loop > > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.49 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.176 usec per loop > [steve at sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' > 1000000 loops, best of 3: 0.49 usec per loop > > > I simply do not believe that we can justify making *any* claim about the > relative speeds of n=n+1 and n+=1 other than "they are about the same". Any > result you get, faster or slower, will depend more on chance than on any > real or significant difference in the code. I couldn't resist giving it a try. Using Python 3.2.1 on a 64-bit Windows 7 machine with a 2.60 gigahertz AMD Athlon II X4 620 processor, I did 18 tests, alternating between n=n+1 and n+=1 (so 9 each). The fastest for n+=1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.0879 usec per loop The slowest for n+=1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.0902 usec per loop The fastest for n = n + 1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.0831 usec per loop The slowest for n = n + 1 was C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.0842 usec per loop Coincidence? All the data are pasted at http://pastebin.com/jArPSe56 Dick Moores From amirouche.boubekki at gmail.com Mon Aug 22 06:02:00 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Mon, 22 Aug 2011 03:02:00 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ Message-ID: I'm learning a bit of python internals lately and I'm trying to figure out the relationship between type, objects, class, callables and __getattribute__ resolution. While understanding Python mechanics/concepts, I'm trying to figure how it translates in CPython. This post is Python centric. Questions about the implementation of this concepts might be the subject of a future post [1]. I will proceed this way: I will write statements about each subject. Don't hesitate to pick one and provide more information or better phrasing, or explaining why it's not true. Be aware that I'm considering only new-style class. A) type vs object ----------------- 1) object is the base object, it has no bases : len(object.__bases__) == 0 2) every object in python inherit object : any_object_except_object.__bases__[-1] is object 3) object's type is type : object.__class__ is type 4) type parent object is object : type.__bases__ == (object,) B) type vs metaclass -------------------- 1) type is the first metaclass ? 2) type is its own metaclass : type(type) is type ? 3) object's metaclass is type ? 4) other metaclasses *MUST* inherit type ? 5) type(any_object) == last_metaclass_..., which is, most of the time, type ? C) type vs class ---------------- 1) Type is the metaclass of most classes 2) The class statement:: class MyClass(object): attribute = 1 def method(self): pass translates to:: MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def method: pass }) 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates to:: type(MyClass).__call__(MyClass, *args, **kwargs) This is due to __getattribute__ algorithm (see E) 4) It's in type.__call__ that happens calls to __new__ and __init__ 5) 3) => classes are instance of type 6) Since type.__call__ is used to instantiate instance of instance of type (rephrased: __call__ is used to instantiate classes) where is the code which is executed when we write ``type(myobject)`` or ``type('MyClass', bases, attributes)`` __getattribute__ resolution algorithm (see E) tells me that it should be type.__call__ but type.__call__ is already used to class instatiation. C') class vs class instances aka. objects ----------------------------------------- 1) A class type is a metaclass : issubclass(type(MyClass), type), MyClass.__class__ == type(MyClass) 2) An object type is a class : most of the time isinstance(type(my_object), type) generally issubclass(type(type(my_object)), type) D) builtin types ---------------- 1) builtin types are their own metaclass ? 2) why function builtin type can not be subclassed ? 3) how does builtin function type relate to callable objects ? 4) int(1) is the same as int.__call__(1), since type(int) is type, shouldn't int(1) translates to type.__call__(int, 1) ? E) __getattribute__ ------------------- 1) ``my_object.attribute`` always translates to ``my_object.__getattribute__('attribute')`` 2) Is the following algorithm describing __getattribute__ correct [2], beware that I've added a comment: a) If attrname is a special (i.e. Python-provided) attribute for objectname, return it. # what does it mean to be Python-provided ? b ) Check objectname.__class__.__dict__ for attrname. If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case. c) Check objectname.__dict__ for attrname, and return if found. d) If it is a class and a descriptor exists in it or its bases, return the descriptor result. d) Check objectname.__class__.__dict__ for attrname. If it exists and is a non-data descriptor, return the descriptor result. If it exists, and is not a descriptor, just return it. If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2. Search all bases of objectname.__class__ for same case. e) Raise AttributeError Thanks in advance, Regards, Amirouche [1] or maybe you can point me to the right direction before I ask stupid questions. I'm a bit familiar with Jython code, which seems to be easier than PyPy and CPython to read even if there is some magic due to the fact that Jython use some JVM API that hides somewhat how it works. [2] this is a rewritten version of http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#attribute-search-summary From cs at zip.com.au Mon Aug 22 06:06:46 2011 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 22 Aug 2011 20:06:46 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: Message-ID: <20110822100646.GA24782@cskk.homeip.net> On 22Aug2011 02:06, Tomas Lid?n wrote: | On 22 Aug, 10:15, Steven D'Aprano wrote: | > On Mon, 22 Aug 2011 04:37 pm Tomas Lid?n wrote: | > > In what order are the addresses returned by socket.gethostbyname_ex()? | > | > > We know that gethostbyname() is indeterministic but hope that | > > gethostbyname_ex() has a specified order. | > | > Did you want a particular order, or just any deterministic order? | > | > Have you considered sorting the addresses yourself? | | In this particular case we have a host with several connections (LAN, | WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare | adapter but we wanted to get the LAN (or the "best" connection to our | server). With gethostbyname_ex() the ordering seemed to become LAN, | Wifi, etc and that's good for us. But we don't know if this holds on | other platforms (we're running on Windows 7). | | A cross-platform deterministic order would be excellent for us. It would not surprise me if the order was related to the order a scan of the system interfaces yields information, and I would imagine that may be influenced by the order in which the interfaces were initialised. So getting the LAN first may merely be fortuitous. I wouldn't rely on it, especially if interfaces come and go. What if you queried your routing table instead? Usually there's just one default route, and hopefully it would be configured to use the "best" interface. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you give me six lines written by the most honest man, I will find something in them to hang him. - Cardinal Richilieu From rosuav at gmail.com Mon Aug 22 06:36:12 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 11:36:12 +0100 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: <20110822100646.GA24782@cskk.homeip.net> References: <20110822100646.GA24782@cskk.homeip.net> Message-ID: On Mon, Aug 22, 2011 at 11:06 AM, Cameron Simpson wrote: > What if you queried your routing table instead? Usually there's just one > default route, and hopefully it would be configured to use the "best" > interface. > I wouldn't necessarily trust even this, on Windows. I've lately had the most insane trouble getting my XP laptop to function properly as a proxy - LAN connection has the default gateway, wifi has only 192.168.* - and Windows kept on trying to send DNS queries out on the wireless connection, and then wondered why it didn't get a result. Explicit is better than implicit. Instead of using the order, have a config file that chooses the one(s) you want by name or IP address. Of course, if you're on Unix/Linux, you can use the interface name (eth0, eth1, etc) with a fair degree of reliability. ChrisA From as at sci.fi Mon Aug 22 06:59:54 2011 From: as at sci.fi (Anssi Saari) Date: Mon, 22 Aug 2011 13:59:54 +0300 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm writes: > Hello, > >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > 'pl_PL' >>>> i=0.20 >>>> j=0.25 >>>> locale.format('%f', i) > '0,200000' >>>> locale.format('%f', j) > '0,250000' > > I need to print the numbers in the following format: > '0,2' (i) > '0,25' (j) > So the last trailing zeros are not printed. That would be the %g conversion specifier. From przemolicc at poczta.fm Mon Aug 22 07:08:40 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 13:08:40 +0200 Subject: locale.format without trailing zeros In-Reply-To: References: Message-ID: <20110822110840.GB13228@host.pgf.com.pl> On Mon, Aug 22, 2011 at 11:48:46AM +0200, Peter Otten wrote: > przemolicc at poczta.fm wrote: > > >>>> import locale > >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > > 'pl_PL' > >>>> i=0.20 > >>>> j=0.25 > >>>> locale.format('%f', i) > > '0,200000' > >>>> locale.format('%f', j) > > '0,250000' > > > > I need to print the numbers in the following format: > > '0,2' (i) > > '0,25' (j) > > So the last trailing zeros are not printed. > > >>> print locale.format("%g", 1.23) > 1,23 > >>> print locale.format("%g", 1.2345678) > 1,23457 > >>> print locale.format("%.10g", 1.2345678) > 1,2345678 > >>> print locale.format("%.15g", 0.1) > 0,1 > >>> print locale.format("%.17g", 0.1) > 0,10000000000000001 Thank you very much :-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f2a0a From lighttn at googlemail.com Mon Aug 22 07:26:23 2011 From: lighttn at googlemail.com (Hyun-su) Date: Mon, 22 Aug 2011 04:26:23 -0700 (PDT) Subject: write() Message-ID: Hi, I have a file which is 3D data ([pixel_x, pixel_y, pixel_z]) I want to plot and write into other file as 1 dimension ([:, y_cut, z_cut]) How can I do it? From roy at panix.com Mon Aug 22 07:26:56 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 07:26:56 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: In article <356978ef-e9c1-48fd-bb87-849fe8e27a79 at p5g2000vbl.googlegroups.com>, Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. Why would you hope that? Or maybe a better question is, why would you expect that? In general, all name resolution calls return results in arbitrary order. In some cases, results are intentionally changed on every call (i.e. round-robin) in an attempt at load sharing. What kind of ordering were you hoping for? From ekh.johan at gmail.com Mon Aug 22 07:28:05 2011 From: ekh.johan at gmail.com (Johan Ekh) Date: Mon, 22 Aug 2011 13:28:05 +0200 Subject: Execute script from ipython In-Reply-To: References: Message-ID: Thanks Chris! I tried using "!" instead of "run". It works but with a significant performance penalty. Best regards, Johan On Fri, Aug 19, 2011 at 5:11 PM, Chris Rebert wrote: > On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > > Hi all, > > I have a script "myscript.py" located in "/usr/local/bin" on my linux > box. > > I can execute it in ipython with > > > > run /usr/local/bin/myscript.py > > > > but not with > > > > run myscript.py > > > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > > > What should I do to correct this? > > Given that %run takes a filename and not a module name, I doubt > PYTHONPATH matters. ipython's docs for %run don't seem to indicate > that a search of any kind is performed. So, I'd say you have to either > pass a valid absolute or relative path to myscript.py, or run > myscript.py from bash instead of ipython. > > Changing your script's shebang line to ipython might also work > (haven't tried it myself). Or you could try patching ipython's run() > function to add this search feature you desire. > > Cheers, > Chris > -- > http://rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomas.liden.privat at gmail.com Mon Aug 22 07:29:38 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:29:38 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: Message-ID: On 22 Aug, 12:06, Cameron Simpson wrote: > > It would not surprise me if the order was related to the order a scan of > the system interfaces yields information, and I would imagine that may > be influenced by the order in which the interfaces were initialised. > > So getting the LAN first may merely be fortuitous. > I wouldn't rely on it, especially if interfaces come and go. > We did try to disable/enable the interfaces in different orders, but always got the same return order from gethostbyname_ex(). So it looked pretty stable (on that specific OS). There's been some testing on Linux as well, but since this should be used in a general cross platform tool we wanted to check the exact behaviour of the method. > What if you queried your routing table instead? Usually there's just one > default route, and hopefully it would be configured to use the "best" > interface. > Hmm... perhaps. How would you do that? /Tomas From przemolicc at poczta.fm Mon Aug 22 07:29:58 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Mon, 22 Aug 2011 13:29:58 +0200 Subject: locale.format without trailing zeros In-Reply-To: References: Message-ID: <20110822112958.GC13228@host.pgf.com.pl> On Mon, Aug 22, 2011 at 11:48:46AM +0200, Peter Otten wrote: > przemolicc at poczta.fm wrote: > > >>>> import locale > >>>> locale.setlocale(locale.LC_ALL, "pl_PL") > > 'pl_PL' > >>>> i=0.20 > >>>> j=0.25 > >>>> locale.format('%f', i) > > '0,200000' > >>>> locale.format('%f', j) > > '0,250000' > > > > I need to print the numbers in the following format: > > '0,2' (i) > > '0,25' (j) > > So the last trailing zeros are not printed. > > >>> print locale.format("%g", 1.23) > 1,23 > >>> print locale.format("%g", 1.2345678) > 1,23457 > >>> print locale.format("%.10g", 1.2345678) > 1,2345678 > >>> print locale.format("%.15g", 0.1) > 0,1 > >>> print locale.format("%.17g", 0.1) > 0,10000000000000001 How about this format: ',1' (the local zero is also not printed) (I know this is strange but I need compatibility with local requirements) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Najwieksza baza najtanszych ofert mieszkaniowych http://linkint.pl/f2a0e From tomas.liden.privat at gmail.com Mon Aug 22 07:32:48 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:32:48 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <20110822100646.GA24782@cskk.homeip.net> Message-ID: On 22 Aug, 12:36, Chris Angelico wrote: > > Explicit is better than implicit. Instead of using the order, have a > config file that chooses the one(s) you want by name or IP address. Of > course, if you're on Unix/Linux, you can use the interface name (eth0, > eth1, etc) with a fair degree of reliability. > The config file solution is not suitable, I think. This code should run in a general cross platform application (Texttest), and we do not want each user of that system to be forced to edit a config file.. /Tomas From roy at panix.com Mon Aug 22 07:37:31 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 07:37:31 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Tomas Lid?n wrote: > In this particular case we have a host with several connections (LAN, > WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare > adapter but we wanted to get the LAN (or the "best" connection to our > server). Figuring out which is the best connection is a decidedly non-trivial problem. You could try some heuristic like "pick the address which has the same network number as me". But, what if you're multi-homed as well, and the target has addresses on more than one of the networks you're connected to? Not to mention that even enumerating all of your own connections is non-trivial. > With gethostbyname_ex() the ordering seemed to become LAN, > Wifi, etc and that's good for us. But we don't know if this holds on > other platforms (we're running on Windows 7). You can't count on the ordering being anything in particular. It's a lost cause. You may think you can find patterns, and then write your application to depend on those, and you will eventually get burned. > A cross-platform deterministic order would be excellent for us. "A cross-platform deterministic X would be excellent" is a true statement for almost any value of X. Many people have wasted much of their lives trying to achieve that goal, for various Xs. From tomas.liden.privat at gmail.com Mon Aug 22 07:39:39 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 04:39:39 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> On 22 Aug, 13:26, Roy Smith wrote: > In article > <356978ef-e9c1-48fd-bb87-849fe8e27... at p5g2000vbl.googlegroups.com>, > ?Tomas Lid?n wrote: > > > In what order are the addresses returned by socket.gethostbyname_ex()? > > > We know that gethostbyname() is indeterministic but hope that > > gethostbyname_ex() has a specified order. > > Why would you hope that? ?Or maybe a better question is, why would you > expect that? ?In general, all name resolution calls return results in > arbitrary order. ?In some cases, results are intentionally changed on > every call (i.e. round-robin) in an attempt at load sharing. > > What kind of ordering were you hoping for? See previous posts. Basically I was asking about the contract for this method.. hoping that it is deterministic. Our testing indicated that the interfaces are returned in a specific order, but we want to know if this is really the case (on all platforms). /Tomas From steve+comp.lang.python at pearwood.info Mon Aug 22 07:57:31 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 22 Aug 2011 21:57:31 +1000 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: Message-ID: <4e52442b$0$29975$c3e8da3$5496439d@news.astraweb.com> Amirouche B. wrote: > A) type vs object > ----------------- > > 1) object is the base object, it has no bases : len(object.__bases__) > == 0 Correct, but for reference, a more direct test is: object.__bases__ == () (no need for len). > 2) every object in python inherit object : > any_object_except_object.__bases__[-1] is object Excluding old-style objects, I believe you are correct. > 3) object's type is type : object.__class__ is type > 4) type parent object is object : type.__bases__ == (object,) The relationship between type and object is somewhat special, and needs to be bootstrapped by the CPython virtual machine. Arbitrary types (classes) inherit from object. That means the type is a subclass of object: >>> class K(object):pass ... >>> issubclass(K, object) True What's less obvious is that types are themselves objects, and therefore are instances of object: >>> isinstance(K, object) True Since classes are objects, they have a type, namely ``type``. This includes ``type`` itself: * type is an instance of object * object is an instance of type * type is a subclass of object * but object is NOT a subclass of type > B) type vs metaclass > -------------------- > > 1) type is the first metaclass ? Excluding old-style classes, yes, all custom classes (those you create with the class statement) have a default metaclass of type. > 2) type is its own metaclass : type(type) is type ? Yes. Another bit of bootstrapping that the compiler does. >>> type(type) is type True > 3) object's metaclass is type ? Yes. > 4) other metaclasses *MUST* inherit type ? No. Metaclasses can be anything that mimics type. >>> def meta(name, bases, dict): ... class X(object): ... pass ... return X ... >>> class K(object): ... __metaclass__ = meta ... a = 1 ... >>> >>> K They don't even need to return a type/class. Like decorators, they can return anything. >>> def meta(name, bases, dict): ... return "spam" ... >>> class K(object): ... __metaclass__ = meta ... >>> K 'spam' > 5) type(any_object) == last_metaclass_..., which is, most of the time, > type ? I'm not sure what you mean by "last_metaclass". But no. The type of an object is its class: type(42) => int type("spam") => str type(1.23) => float However, the type of a class is *usually* type. > C) type vs class > ---------------- > > 1) Type is the metaclass of most classes Yes. > 2) The class statement:: > > class MyClass(object): > attribute = 1 > > def method(self): > pass > > translates to:: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': > def method: pass }) Except that the syntax won't work, the idea is broadly correct. > 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates > to:: > > type(MyClass).__call__(MyClass, *args, **kwargs) Like any function call, MyClass(...) becomes type(MyClass).__call__(self, ...) with self=MyClass. Since type(MyClass) is usually ``type``, that gives: type.__call__(MyClass, ...) > This is due to __getattribute__ algorithm (see E) > > 4) It's in type.__call__ that happens calls to __new__ and __init__ If type were written in pure Python, it would probably look something like this: class Type(object): # ... # other methods # ... def __call__(cls, *args, **kwargs): instance = cls.__new__(cls, *args, **kwargs) if isinstance(instance, cls): instance.__init__(*args, **kwargs) return instance But see further on, for more complication. Note that __new__ is special-cased as a staticmethod, hence it needs the first argument to be passed directly. > 5) 3) => classes are instance of type > > 6) Since type.__call__ is used to instantiate instance of instance of > type > (rephrased: __call__ is used to instantiate classes) where is the > code which > is executed when we write ``type(myobject)`` or ``type('MyClass', > bases, attributes)`` You would need to check the C implementation of type, but if I were doing this in pure Python, I'd have something like this: class Type(object): def __call__(self, *args, **kwargs): if self is Type: if kwargs: raise TypeError('unexpected keyword arguments') # calling type(...) directly if len(args) == 1: # Single argument call, like type(x) return x.__class__ else: # Like type(name, bases, dict) name, bases, dict = *args cls = Type.__new__(Type, name, bases, dict) if isinstance(cls, Type): cls.__init__(name, bases, dict) else: # called from MyClass(...) # which becomes type(MyClass).__call__(MyClass, ...) # self here equals MyClass, which is an instance of type but # not type itself instance = self.__new__(self, *args, **kwargs) if isinstance(instance, self): instance.__init__(*args, **kwargs) return instance def __new__(cls, *args): # magic to actually create a new type object Note that this may not be how ``type`` actually does it. See the source code, and I hope you have better luck reading it than I did! http://hg.python.org/cpython/file/c8e73a89150e/Objects/typeobject.c -- Steven From roy at panix.com Mon Aug 22 08:14:10 2011 From: roy at panix.com (Roy Smith) Date: Mon, 22 Aug 2011 08:14:10 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> Message-ID: In article <034ff4bf-e3e4-47ff-9a6c-195412431e73 at s20g2000yql.googlegroups.com>, Tomas Lid?n wrote: > Basically I was asking about the contract for this method.. hoping > that it is deterministic. The contract for socket.gethostbyname_ex() is described at http://docs.python.org/library/socket.html#socket.gethostbyname_ex. It says: "Translate a host name to IPv4 address format, extended interface. Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4 addresses for the same interface on the same host (often but not always a single address). gethostbyname_ex() does not support IPv6 name resolution, and getaddrinfo() should be used instead for IPv4/v6 dual stack support." That's it. It says nothing about ordering, so nothing about ordering should be inferred. > Our testing indicated that the interfaces are returned in a specific > order, but we want to know if this is really the case (on all > platforms). No, it is not. From paul at subsignal.org Mon Aug 22 08:18:14 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Mon, 22 Aug 2011 14:18:14 +0200 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 22.08.2011 13:37, schrieb Roy Smith: > In article > , > Tomas Lid?n wrote: >> A cross-platform deterministic order would be excellent for us. > > "A cross-platform deterministic X would be excellent" is a true > statement for almost any value of X. Many people have wasted much of > their lives trying to achieve that goal, for various Xs. So true..., QOTW +1 From tomas.liden.privat at gmail.com Mon Aug 22 08:33:25 2011 From: tomas.liden.privat at gmail.com (=?ISO-8859-1?Q?Tomas_Lid=E9n?=) Date: Mon, 22 Aug 2011 05:33:25 -0700 (PDT) Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: OK - thank you all for your contributions. /T From __peter__ at web.de Mon Aug 22 08:53:41 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 14:53:41 +0200 Subject: Optimizing Text Similarity Algorithm References: Message-ID: Ya?ar Arabac? wrote: > I originally posted this question on stackoverflow, you can find it here: > http://stackoverflow.com/q/7133350/886669 > > I just want people check what I am doing and express their opinion about > the thing I am doing is acceptable, or are there some expects of it that > could change. You are using only word frequencies to calculate the similarity of the document pairs. You can calculate these frequencies before you enter the the expensive for documentA in ...: for documentB in ...: calculate_similarity(documentA, documentB) loops and therefore bring that portion of your could from O(n*n) to O(n). Here's is a sample where I applied that technique blindly to your code. I also had to remove the django dependency, so I've changed it to operate on text files. import sys import math import re from collections import Counter from itertools import combinations def get_words(text): # FIXME regex = re.compile("\W+", flags=re.UNICODE) return re.split(regex, text) def pairs(files): """Generate (title, wordlist) pairs. (filename is used as title) """ for filename in files: with open(filename) as f: text = f.read() yield filename, get_words(text) def process(pairs): triples = [] total = Counter() for title, words in pairs: c = Counter(words) total.update(c.iterkeys()) sigma = sum(math.log(freq, 1.6) for freq in c.itervalues()) triples.append((title, c, sigma)) for (title1, freq1, sum1), (title2, freq2, sum2) in combinations( triples, 2): upper_part = 0 for word in freq1 & freq2: adjusted1 = math.log(freq1[word], 1.6) adjusted2 = math.log(freq2[word], 1.6) upper_part += ( adjusted1 * adjusted2 * math.log(len(triples)/total[word])) lower_part = math.sqrt(sum1 * sum2) title1, title2 = sorted([title1, title2]) yield title1, title2, upper_part/lower_part def main(): files = sys.argv[1:] results = process(pairs(files)) results = sorted(results, key=lambda x: x[:2]) results.sort(key=lambda x: x[2], reverse=True) print "\n".join("%s and %s => %f" % xcv for xcv in results) if __name__ == "__main__": main() From ulrich.eckhardt at dominolaser.com Mon Aug 22 08:57:24 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 22 Aug 2011 14:57:24 +0200 Subject: write() References: Message-ID: Hyun-su wrote: > I have a file which is 3D data ([pixel_x, pixel_y, pixel_z]) > > I want to plot and write into other file as 1 dimension ([:, y_cut, > z_cut]) > > How can I do it? I'd write a loop along these lines: with open(outputfile, 'w') as o: for pixel_x, pixel_y, pixel_z in input_data: o.write(...) If you want a better suggestion, I'd suggest that you provide more info. Also, and that is very important, you should indicate which efforts you already too. In particular, I'd suggest the introductory tutorial on Python (see http://docs.python.org) and E.S. Raymonds essay on smart questions (search the web for it). If you don't show effort, people will assume you are lazy and just need someone to do your homework for you. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From __peter__ at web.de Mon Aug 22 09:01:51 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 15:01:51 +0200 Subject: locale.format without trailing zeros References: Message-ID: przemolicc at poczta.fm wrote: > How about this format: > ',1' > (the local zero is also not printed) > > (I know this is strange but I need compatibility with local requirements) I believe you have to do it yourself: >>> locale.format("%f", 0.123) '0,123000' >>> locale.format("%f", 0.123).strip("0") ',123' From neilc at norwich.edu Mon Aug 22 09:05:03 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Aug 2011 13:05:03 GMT Subject: Optimizing Text Similarity Algorithm References: Message-ID: <9bf2fvFer9U1@mid.individual.net> On 2011-08-22, Peter Otten <__peter__ at web.de> wrote: > Ya??ar Arabac?? wrote: >> I originally posted this question on stackoverflow, you can find it here: >> http://stackoverflow.com/q/7133350/886669 >> >> I just want people check what I am doing and express their opinion about >> the thing I am doing is acceptable, or are there some expects of it that >> could change. Perhaps check out difflib.SequenceMatcher.ratio to see if the library function is good enough. -- Neil Cerutti From johnny.venter at zoho.com Mon Aug 22 09:07:39 2011 From: johnny.venter at zoho.com (johnny.venter) Date: Mon, 22 Aug 2011 06:07:39 -0700 Subject: Python Windows Extensions for Mac In-Reply-To: References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> Message-ID: <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> Chris, thank you for the information. Focusing on Active Directory, I reviewed the info at the following site: http://technet.microsoft.com/en-us/library/cc961766.aspx Based on this, I need to find a module that implements the LDAP APIs. By default, it does not appear that Python can speak this language, I am using version 2.6.1. The module I found is Python-LDAP (http://www.python-ldap.org/). Does anyone have experience using this? ---- On Sun, 21 Aug 2011 00:30:07 -0700 Chris Angelico wrote ---- >On Sun, Aug 21, 2011 at 6:38 AM, Johnny Venter wrote: >> Yes, I want to make my queries from a remote non-Windows computer. Here is the scenario: >> >> From my mac, I want to use python to access and read objects from a remote ?Windows computer joined to a Windows 2003 functional level domain. Given this, what is the best way to accomplish this? >> > >Then the "use Python" part is relatively immaterial; what you need to >know is: What network protocol are you using to "access and read >objects"? Start by researching that; once you know the details (is it >even TCP/IP-based?), you can look into whether Python has facilities >for speaking that protocol. > >ChrisA >-- >http://mail.python.org/mailman/listinfo/python-list > From research at johnohagan.com Mon Aug 22 09:08:50 2011 From: research at johnohagan.com (John O'Hagan) Date: Mon, 22 Aug 2011 23:08:50 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> On Mon, 22 Aug 2011 15:27:36 +1000 Steven D'Aprano wrote: > On Mon, 22 Aug 2011 03:04 pm John O'Hagan wrote: > > > The "pitches" attribute represents the instances and as such I found > > myself adding a lot of methods like: > > > > def __getitem__(self, index): > > return self.pitches[index] > > > > def __len__(self): > > return len(self.pitches) > > > Looks like a call for (semi-)automatic delegation! > > Try something like this: > > > # Untested > class MySeq(object): > methods_to_delegate = ('__getitem__', '__len__', ...) > pitches = ... # make sure pitches is defined > def __getattr__(self, name): > if name in self.__class__.methods_to_delegate: > return getattr(self.pitches, name) > return super(MySeq, object).__getattr__(self, name) > # will likely raise AttributeError Thanks, this looks promising. I didn't know about __getattr__ or delegation. This example doesn't seem to work as is for special methods beginning with "__" (e.g.: "TypeError: object of type 'MyList' has no len()"). It seems that __getattr__ is not called for special methods. Also, it doesn't immediately suggest to me a way of modifying method calls (maybe __setattr__?). But it's certainly a neater way to get methods to operate on the attribute. I'm looking into it, and delegation generally. However, I don't understand what the super call is doing. If the method isn't delegated, shouldn't it just fall back to getattr(self, name)? Thanks and regards, John From abacau10 at gmail.com Mon Aug 22 09:21:35 2011 From: abacau10 at gmail.com (aba ca) Date: Mon, 22 Aug 2011 16:21:35 +0300 Subject: To cmd.exe Message-ID: Hi all! How can I send to cmd.exe "netstat -an"? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Mon Aug 22 09:29:33 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Aug 2011 14:29:33 +0100 Subject: To cmd.exe In-Reply-To: References: Message-ID: <4E5259BD.1050206@timgolden.me.uk> On 22/08/2011 14:21, aba ca wrote: > How can I send to cmd.exe "netstat -an"? Look at the subprocess module, and especially the .check_output convenience function: http://docs.python.org/library/subprocess.html#subprocess.check_output TJG From vlastimil.brom at gmail.com Mon Aug 22 09:59:16 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 22 Aug 2011 15:59:16 +0200 Subject: Help with regular expression in python In-Reply-To: <201108191555.53338.matze999@gmail.com> References: <201108181349.54727.matze999@gmail.com> <201108191555.53338.matze999@gmail.com> Message-ID: Sorry, if I missed some further specification in the earlier thread or if the following is oversimplification of the original problem (using 3 numbers instead of 32), would something like the following work for your data? >>> import re >>> data = """2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description""" >>> for res in re.findall(r"(?m)^(?:(?:[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+))?\s+){3}(?:.+)$", data): print res ... 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description 2.201000e+01 2.150000e+01 2.199000e+01 : (instance: 0) : some description >>> i.e. all parentheses are non-capturing (?:...) and there are extra anchors for line begining and end ^...$ with the multiline flag set via (?m) Each result is one matching line in this sample (if you need to acces single numbers, you could process these matches further or use the new regex implementation mentioned earlier by mrab (its developer) with the new match method captures() - using an appropriate pattern with the needed groupings). regards, vbr From k.sahithi2862 at gmail.com Mon Aug 22 10:18:49 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Mon, 22 Aug 2011 07:18:49 -0700 (PDT) Subject: TAMIL SEXY HOT GIRLS Message-ID: <31fb13a0-911a-4546-97b0-5154c1e4e916@e34g2000prn.googlegroups.com> v FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From research at johnohagan.com Mon Aug 22 10:20:09 2011 From: research at johnohagan.com (John O'Hagan) Date: Tue, 23 Aug 2011 00:20:09 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> Message-ID: <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> On Mon, 22 Aug 2011 11:32:18 +0200 Peter Otten <__peter__ at web.de> wrote: > John O'Hagan wrote: > > > I have a class like this: > > > > class MySeq(): > > def __init__(self, *seq, c=12): > > self.__c = c > > self.__pc = sorted(set([i % __c for i in seq])) > > self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) > > #other calculated attributes > > > > @property > > def pitches(self): > > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > > > > #other methods > > That makes me dizzy. Are there any maxims in the Zen of Python that this > piece doesn't violate? "Now is better than never"? I know it looks crazy to take something apart and put it back together, as in this simplified example, but it does have a meaningful use: reducing a series of musical notes to a unique irreducible form "__pc", ("prime form" in pitch-class set theory), but keeping track of the actual current manifestation of that form via the writeable "order" attribute. That's why "pitches" must be called with each reference, because it may change, unlike "__pc", which can only change if the instance is reinitialised. I am open to more elegant suggestions, of course. :) [...] > > > > So I wrote this function which takes a method, modifies it to apply to an > > instance attribute, and takes care of any quirks: > > > > def listmeth_to_attribute(meth, attr): > > def new_meth(inst, *args): > > #ensure comparison operators work: > > args = [getattr(i, attr) if isinstance(i, inst.__class__) > > else i for i in args] > > reference = getattr(inst, attr) > > test = reference[:] > > result = meth(test, *args) > > #ensure instance is reinitialised > > #if attribute has been changed: > > if test != reference: > > inst.__init__(*test) > > #ensure slices are of same class > > if isinstance(result, meth.__objclass__): > > result = inst.__class__(*result) > > return result > > return new_meth > > > > and this decorator to apply this function to all the list methods and add > > them to MySeq: > > > > def add_mod_methods(source_cls, modfunc, modfunc_args, *overrides): > > """Overides = any methods in target to override from source""" > > def decorator(target_cls): > > for name, meth in vars(source_cls).items(): > > if name not in dir(target_cls) or name in overrides: > > setattr(target_cls, name, modfunc(meth, *modfunc_args)) > > return target_cls > > return decorator > > > > a kind of DIY single inheritance, used like this: > > > > @add_mod_methods(list, listmeth_to_attribute, ('pitches',), '__repr__') > > class MySeq(): > > ..... [...] > > In the standard library functools.total_ordering uses that technique and I > find the implications hard to understand: > > http://bugs.python.org/issue10042 > > Your decorator looks even more complex; I'd only recommend using it if > you're absolutely sure you're clever enough to debug it ;) It looks to me like that total_ordering bug is a result of using comparison operators on objects which may not implement them; I'm pretty sure the listmeth_to_attribute function above can only allow comparing lists with lists or raising an exception. Although I must admit that this creates an unexpected bug/feature whereby lists and MySeqs can be successfully compared, so I take your point! Thanks for your reply, John From lzlu123 at gmail.com Mon Aug 22 10:31:55 2011 From: lzlu123 at gmail.com (lzlu123) Date: Mon, 22 Aug 2011 07:31:55 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> <7849d9ff-f472-49c3-a1ce-0f618a301f06@e7g2000vbw.googlegroups.com> Message-ID: <9ceeb1ea-f896-4e64-bad7-b544c329bc0a@k15g2000yqd.googlegroups.com> On Aug 19, 6:38?pm, aspineux wrote: > On Aug 19, 5:00?pm, lzlu123 wrote: > > > > > > > > > > > I have an instrument that has a RS232 type serial comm port and I need > > to connect to and control. I use Python 3.2 in Windows XP, plus > > pySerial module. I have a problem when I execute a script consisting > > of statements that open the comm port, configure it, write strings to > > and receive strings from it. Thoese strings aer either commands > > pertinent to the instrument (control) or responses from the instrument > > (response). > > > When those statements are executed in a python interpreter > > interactively (at >>>), I get what I expect and the results are good > > and correct. However, when I execute the script, either being invoked > > within the interpreter or run file, I don?t get what I want. The > > statements in the script is the same as what I use in the interactive > > interpreter. > > > Why do I get the strange behavior and how can I change the script to > > make it to behave like in interactive interpreter? > > > ----------------------script----------------------- > > def read(comport): > > > ? ? wrt_str=b'movt 3000'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? wrt_str=b'scan'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? rsp_str=comport.readlines() #########1 > > You use readlines() with a s at the end ! > > * Note that when the serial port was opened with no timeout, that > readline() > * blocks until it sees a newline (or the specified size is reached) > * and that readlines() would never return and therefore refuses to > work > * (it raises an exception in this case)! > > > > > > > > > > > > > ? ? wrt_str=b'hllo'+b'\r\n' > > ? ? ret_str=comport.write(wrt_str) > > > ? ? rsp_str=comport.readlines()#########2 > > ---------------------------------------------------------- > > > The problem is with the lines above with #######. In interactive mode, > > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > > correct responses there. However, if I execute the script above, there > > is no delay at all and I get incorrect results (garbage). I set the > > read timeout to 0 in comm port set up, as > > > comport.timeout=0 > > So the comport should be in blocking mode if it waits for the end of > > line or end of file. > > Wrong : > > ? ? timeout = None: wait forever > ? ? timeout = 0: non-blocking mode (return immediately on read) > ? ? timeout = x: set timeout to x seconds (float allowed) > > > > > > > > > > > > > I tried many things, like exec (execfile in 2.7), but at no avail. > > > I have an update to the original post I made a few days ago. I think I > > know what the problem is and want to know if anyone has a solution: > > > After putting "print" and "time.sleep(delay)" after every statement, I > > found when the script is running, it appears going around the pyserial > > statement, such as "comport.write(..)" or "comport.readlines(...)" > > while the pyserial command is executing (appearing as waiting and > > busying doing some thing, you know serial port is slow). So for > > example, when I exec all statements in a python interactive shell, I > > am not able to type and run a new statement if the previous one is not > > returned. Let's ay, if comport.readlines() is not returning, I can't > > type and run the next comport.write(...) statemtn. However, in a > > script that is running, if the comport.readlines() is busy reading, > > the next statement is running, if the next statement happens to be a > > comport.write() which will abort the reading. > > > Is there any way to force the python script to behave like running > > exactly sequentially? > > You have some new things to try I tried to set the timeout to different values other than 0, but still got same result -- ruuning script directly behaves differently from executing statements in interactive shell. I even tried using read instead of readline(s). From lzlu123 at gmail.com Mon Aug 22 10:33:26 2011 From: lzlu123 at gmail.com (lzlu123) Date: Mon, 22 Aug 2011 07:33:26 -0700 (PDT) Subject: How to make statements running in strictly sequential fashion like in an interactive shell References: <6a83366f-15e6-4cb3-9e63-27103ebf7422@b20g2000vbz.googlegroups.com> Message-ID: <2f3f84da-6f21-48a6-9f2d-ba0c916dbdde@f41g2000yqh.googlegroups.com> On Aug 19, 11:06?pm, Javier wrote: > Never used it, but I think you can try this: > > Pexpect - a Pure Python Expect-like module > Pexpect is a pure Python Expect-like module. Pexpect makes Python...www.noah.org/python/pexpect/ > > > > > > > > lzlu123 wrote: > > I have an instrument that has a RS232 type serial comm port and I need > > to connect to and control. I use Python 3.2 in Windows XP, plus > > pySerial module. I have a problem when I execute a script consisting > > of statements that open the comm port, configure it, write strings to > > and receive strings from it. Thoese strings aer either commands > > pertinent to the instrument (control) or responses from the instrument > > (response). > > > When those statements are executed in a python interpreter > > interactively (at >>>), I get what I expect and the results are good > > and correct. However, when I execute the script, either being invoked > > within the interpreter or run file, I don???t get what I want. The > > statements in the script is the same as what I use in the interactive > > interpreter. > > > Why do I get the strange behavior and how can I change the script to > > make it to behave like in interactive interpreter? > > > ----------------------script----------------------- > > def read(comport): > > > ? ?wrt_str=b'movt 3000'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?wrt_str=b'scan'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?rsp_str=comport.readlines() #########1 > > > ? ?wrt_str=b'hllo'+b'\r\n' > > ? ?ret_str=comport.write(wrt_str) > > > ? ?rsp_str=comport.readlines()#########2 > > ---------------------------------------------------------- > > > The problem is with the lines above with #######. In interactive mode, > > there is about 1 second delay at #1, and 9 seonds delay at #2. I get > > correct responses there. However, if I execute the script above, there > > is no delay at all and I get incorrect results (garbage). I set the > > read timeout to 0 in comm port set up, as > > > comport.timeout=0 > > So the comport should be in blocking mode if it waits for the end of > > line or end of file. > > > I tried many things, like exec (execfile in 2.7), but at no avail. > > > I have an update to the original post I made a few days ago. I think I > > know what the problem is and want to know if anyone has a solution: > > > After putting "print" and "time.sleep(delay)" after every statement, I > > found when the script is running, it appears going around the pyserial > > statement, such as "comport.write(..)" or "comport.readlines(...)" > > while the pyserial command is executing (appearing as waiting and > > busying doing some thing, you know serial port is slow). So for > > example, when I exec all statements in a python interactive shell, I > > am not able to type and run a new statement if the previous one is not > > returned. Let's ay, if comport.readlines() is not returning, I can't > > type and run the next comport.write(...) statemtn. However, in a > > script that is running, if the comport.readlines() is busy reading, > > the next statement is running, if the next statement happens to be a > > comport.write() which will abort the reading. > > > Is there any way to force the python script to behave like running > > exactly sequentially? I am using Python 3.2 in Windows in which Pexpect appeared problematic. From gnarlodious at gmail.com Mon Aug 22 11:28:41 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Aug 2011 08:28:41 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables Message-ID: In my last post I learned of the necessity of filtering CGI input, so what I want to do is set a dict of allowable variable names: allowedVariables = {'eeny':None, 'meeny':None, 'miny':None, 'mo':None} # Set up a FieldStorage object: import cgi inputVariables = cgi.FieldStorage() for name, value in {"eeny" : "value1", "meeny" : "value2", "miny" : "value3", "mofo" : "value4"}.items(): inputVariables.list.append(cgi.MiniFieldStorage(name, value)) allowedVariables.update(((key, inputVariables[key].value) for key in inputVariables)) allowedVariables As you can see, the variable 'mofo' gets added to allowedVariables, which is normal behavior. Is there an easy way to limit updates to ONLY variables in the allowedVariables dict? And in addition, maybe return an error so the attacker can be blocked? -- Gnarlie From miki.tebeka at gmail.com Mon Aug 22 11:39:47 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 22 Aug 2011 08:39:47 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables In-Reply-To: References: Message-ID: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> > Is there an easy way to limit updates to > ONLY variables in the allowedVariables dict? allowedVariables = ['eeny', 'meeny', 'miny', 'mo'] form = cgi.FieldStorage() safe_input = dict((key, form.getvalue(key)) for key in allowedVariables) > And in addition, maybe return an error so the attacker can be blocked? You can check if there is a "non-allowed variable" and then return HTTP error. if set(form) - set(allowedVariables): print('Status: 406\n\n') raise SystemExit() HTH -- Miki Tebeka http://pythonwise.blogspot.com From me+list/python at ixokai.io Mon Aug 22 11:41:38 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 08:41:38 -0700 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ In-Reply-To: References: Message-ID: <4E5278B2.1050504@ixokai.io> On 8/22/11 3:02 AM, Amirouche B. wrote: > A) type vs object > ----------------- > > 1) object is the base object, it has no bases : len(object.__bases__) > == 0 > 2) every object in python inherit object : > any_object_except_object.__bases__[-1] is object Not exactly. Python has two somewhat different object models, "old style classes" and "new style classes", with slightly different behavior and internal structure. class Foo: pass is an "old-style class", dated back to Python's ancient past. This all relates to the fact that 'type' and 'class' used to be two pretty different things, where one was something you mostly did only in C, and one was something you did (mostly) only in Python. They are largely the same now. > 3) object's type is type : object.__class__ is type > 4) type parent object is object : type.__bases__ == (object,) Saying "type" and "parent" and the like for new-style classes is something of a misnomer. For "type" and "object", these things aren't constructed like this. What you have here is technically true if you go poke at it in the interpreter, but it doesn't really /mean/ anything because its not how these objects came to be and is circular and a bit confusing. These fundamental objects are created special. > B) type vs metaclass > -------------------- > > 1) type is the first metaclass ? Type is the basic, default "metaclass", yes. A metaclass is a callable that constructs class objects. > 2) type is its own metaclass : type(type) is type ? Only in a purely theoretical way. It doesn't actually mean anything; moreover, type(something) is NOT how you determine somethings metaclass. Its how you determine somethings type. The two concepts may be very distinct. Lots of things don't have metaclasses. > 3) object's metaclass is type ? Again, only theoretically. > 4) other metaclasses *MUST* inherit type ? Absolutely not. Any callable can be a metaclasss. Despite its name, it doesn't have to be itself a class or anything. Just something you can call with er, 3 (I forget exactly) arguments, and which returns a constructed class object. > 5) type(any_object) == last_metaclass_..., which is, most of the time, > type ? Not necessarily at all. In fact, there is no way I'm aware of to determine if a metaclass was involved in a classes construction unless said metaclass wants to provide such a mechanism. Metaclasses are kind of a hack. They are a way to hook into the class construction that's normally done and do something, anything you want, (even hijack the whole procedure and NOT construct a class at all, but play a song if you want) before its all finished. For example, this is a metaclass I've used: PageTypes = {} class _PageRegistration(type): def __new__(cls, name, bases, dct): klass = type.__new__(cls, name, bases, dct) typename = name[:-9].lower() if not typename: typename = None PageTypes[typename] = klass klass.Type = typename return klass class QueuePage(sc.SizedPanel): __metaclass__ = _PageRegistration Note, the fact that my _PageRegistration metaclass inherits is itself a class which inherits from type is just one convenient way to write metaclasses. It could as simply have been just a function. Metaclasses are somewhat poorly named in that they are really, "creation hooks". > C) type vs class > ---------------- > > 1) Type is the metaclass of most classes Yes and no. Yes, in that most classes are created using the default mechanism inside CPython. The class body is executed in a scope, the resulting dictionary is bound to a new class object, bases and the like are set, and such. No in that it really just, IIUC, skips the whole "metaclass" part of the process because this 'default mechanism' doesn't need to call out into other code to do its job. At least, I think-- May be wrong here, metaclasses are something of a dark voodoo and I'm not 100% entirely familiar with the internal workings of CPython. But functionally, a metaclass is the chunk of code responsible for the actual physical construction of the class object. > 2) The class statement:: > > class MyClass(object): > attribute = 1 > > def method(self): > pass > > translates to:: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': > def method: pass }) Translates to, I don't know about that. Is functionally equivalent, yes. It is more or less what happens. > 3) Instantiation of any class ``MyClass(*args, **kwargs)`` translates > to:: > > type(MyClass).__call__(MyClass, *args, **kwargs) > > This is due to __getattribute__ algorithm (see E) > 4) It's in type.__call__ that happens calls to __new__ and __init__ Again, "translates to" is suggesting "this is what happens when you do X", which I don't know if is strictly true. CPython inside may be optimizing this whole process. Especially when it comes to "magic methods", __x__ and the like -- CPython rarely uses __get*_ for those. It just calls the methods directly on the class object. What you're doing here is functionally equivalent to what CPython does, but it may take a more direct route to get there. CPython has the advantage of not being Python and having direct access to internals. > 5) 3) => classes are instance of type > > 6) Since type.__call__ is used to instantiate instance of instance of > type > (rephrased: __call__ is used to instantiate classes) where is the > code which > is executed when we write ``type(myobject)`` or ``type('MyClass', > bases, attributes)`` > __getattribute__ resolution algorithm (see E) tells me that it > should be type.__call__ > but type.__call__ is already used to class instatiation. Python callables can have more then one argument, and more then one behavior, and can choose to do more then one thing based on the number of arguments. They don't have overloading, but they can do it themselves. You've already proven that, and you already know that -- you're sorta over-complicating this :) You said: MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def method: pass }) Type.__call__ does both. > C') class vs class instances aka. objects > ----------------------------------------- > > 1) A class type is a metaclass : issubclass(type(MyClass), type), > MyClass.__class__ == type(MyClass) An old-style classe's type is classobj. A new-style class's type is type. It may or may not be a "metaclass". type(foo) is not defined as 'the metaclass of foo', but 'the type of foo'. It often is the same thing, since most of the time type(myclass) is "type" itself and "type" is the default "metaclass". But mixing up the two concepts isn't really very helpful. > 2) An object type is a class : most of the time > isinstance(type(my_object), type) > generally issubclass(type(type(my_object)), type) Generally. > D) builtin types > ---------------- > > 1) builtin types are their own metaclass ? Builtin types are constructed by the interpreter, and may or may not involve themselves with the class/type hierarchy. Even when they do, they may only do so partially. > 2) why function builtin type can not be subclassed ? Because functions are not classes. They're discrete things of their own. That a function object has a __class__ attribute is an example of a builtin partially involving itself in the class/type hierarchy, largely just for introspection purposes-- since functions are first-class citizens, you need to be able to pass it around and test to determine what one thing or another actually is. Now, functions ARE indeed PyObjects, the internal CPython representation of an object, of which all things are. But that's not really the same thing as ultimately inheriting from and involving itself in "object" and types/classes. > 3) how does builtin function type relate to callable objects ? It doesn't, really. > 4) int(1) is the same as int.__call__(1), since type(int) is type, > shouldn't int(1) > translates to type.__call__(int, 1) ? You're overly focused on __call__, for one thing. For another, no, I'm not sure why you think one should "translate" to another (again: just because you've got the basic relationship of the meta-parts of Python down pat, doesn't mean Python internals actually goes through all those actual steps when doing things). int(1) translates into: int.__call__(1) int_inst = int.__new__(1) More or less. Now, "int" is itself a "class" (type), so it was, itself, constructed by a call to type (well, "type"'s internal C version of itself, Py_TYPE). type, the metaclass or class-constructor version, is only called to create /classes/, at class-creation-time. After "int" itself exists, its no longer involved. int has its own __new__ that's used to construct actual instances of itself. type is now out of the picture. > > > E) __getattribute__ > ------------------- > > 1) ``my_object.attribute`` always translates to > ``my_object.__getattribute__('attribute')`` No. __getattribute__ is a mechanism to hook into the attribute fetching mechanism. (As is __getattr__). It is NOT always invoked. Especially in the case of __*__ attributes, which by and large bypass such hooks, as the CPython internals is calling those functions directly on the class instances themselves. > 2) Is the following algorithm describing __getattribute__ correct This is broadly incorrect because it implies that __getattribute__ is an internal protocol that Python uses for attribute-resolution, which is simply untrue. Its a method you may define on new style classes which, if present, is called when an attribute is requested from an object (but NOT in the case of __*__ methods, usually, which are obtained internally by a direct struct access, i.e., mytype->tp_new gets mytype.__new__). If no such attribute exists, it goes along to do its default attribute-resolution process, including the descriptor protocol and dict checking and the like. __getattribute__ is an optional hook that you can define which allows a Python class to /bypass/ the normal mechanism for normal (non-magic) attributes. If you're asking what the normal mechanism is, its broadly: - Check to see if the object's base-classes have a descriptor of the attributes name. If so, call that. - Check to see if the object's instance dict has an attribute of the name. If so, return that. - Check to see if the object's base-classes have an attribute of the name. More or less. I think. I'm probably leaving something out there. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Mon Aug 22 11:57:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Aug 2011 16:57:51 +0100 Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ In-Reply-To: <4E5278B2.1050504@ixokai.io> References: <4E5278B2.1050504@ixokai.io> Message-ID: On Mon, Aug 22, 2011 at 4:41 PM, Stephen Hansen wrote: > Not exactly. Python has two somewhat different object models, "old style > classes" and "new style classes", with slightly different behavior and > internal structure. > > ? class Foo: pass > > is an "old-style class", dated back to Python's ancient past. This all > relates to the fact that 'type' and 'class' used to be two pretty > different things, where one was something you mostly did only in C, and > one was something you did (mostly) only in Python. They are largely the > same now. And "now" includes everything in Python 3, where a class implicitly derives from object if no other subclassing is given. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 22 12:09:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 02:09:50 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <4e521039$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e527f4e$0$29996$c3e8da3$5496439d@news.astraweb.com> Tomas Lid?n wrote: > In this particular case we have a host with several connections (LAN, > WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare > adapter but we wanted to get the LAN (or the "best" connection to our > server). Define "best" connection. If I tell you that my server has the following 6 connections: Wifi1, LAN4, LAN1, LAN2, Wifi2, LAN5 which one is "best"? Once you have an algorithm for deciding which connection is "best" for everybody, then you can check whether gethostbyname_ex uses that algorithm, or some other one. -- Steven From bob at passcal.nmt.edu Mon Aug 22 12:35:20 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 10:35:20 -0600 Subject: Setting the time in Win7 Message-ID: <2011082210352016807-bob@passcalnmtedu> Permissions! We're running in an account as an administrator (the only account on the laptops) and the program just calls system(time xxxx) and system(date xxxx) after reading it from a connected GPS receiver. I've fiddled with everything I could find in the registry and with the secpol.msc program and there doesn't seem to be any reason that it can't set the time, but it can't. Any ideas? Thanks! Bob From emile at fenx.com Mon Aug 22 12:35:56 2011 From: emile at fenx.com (Emile van Sebille) Date: Mon, 22 Aug 2011 09:35:56 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/22/2011 2:55 AM Richard D. Moores said... > I couldn't resist giving it a try. Using Python 3.2.1 on a 64-bit > Windows 7 machine with a 2.60 gigahertz AMD Athlon II X4 620 > processor, I did 18 tests, alternating between n=n+1 and n+=1 (so 9 > each). > > The fastest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0879 usec per loop > > The slowest for n+=1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.0902 usec per loop > > The fastest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0831 usec per loop > > The slowest for n = n + 1 was > C:\Windows\System32> python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.0842 usec per loop > > Coincidence? > Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :) Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1" 10000000 loops, best of 3: 0.108 usec per loop C:\Documents and Settings\Emile> From emile at fenx.com Mon Aug 22 13:22:25 2011 From: emile at fenx.com (Emile van Sebille) Date: Mon, 22 Aug 2011 10:22:25 -0700 Subject: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") In-Reply-To: References: <4e513ceb$0$23863$e4fe514c@news2.news.xs4all.nl> <1313947658.3424.3.camel@thegeorge> <4e51ad16$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/22/2011 9:35 AM Emile van Sebille said... > On 8/22/2011 2:55 AM Richard D. Moores said... >> Coincidence? >> > > Naaa.. I just ran it twice -- once per ... _this_ is coincidence. :) > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n=n+1" > 10000000 loops, best of 3: 0.108 usec per loop > > C:\Documents and Settings\Emile>python -m timeit -r 3 -s "n=0" "n += 1" > 10000000 loops, best of 3: 0.108 usec per loop Actually, it's more likely I hit a minimum resolution issue -- I ran it twenty more times and never got a different result. Emile From tjreedy at udel.edu Mon Aug 22 13:34:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Aug 2011 13:34:57 -0400 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> <034ff4bf-e3e4-47ff-9a6c-195412431e73@s20g2000yql.googlegroups.com> Message-ID: On 8/22/2011 7:39 AM, Tomas Lid?n wrote: > On 22 Aug, 13:26, Roy Smith wrote: >> In article >> <356978ef-e9c1-48fd-bb87-849fe8e27... at p5g2000vbl.googlegroups.com>, >> Tomas Lid?n wrote: >> >>> In what order are the addresses returned by socket.gethostbyname_ex()? >> >>> We know that gethostbyname() is indeterministic but hope that >>> gethostbyname_ex() has a specified order. >> >> Why would you hope that? Or maybe a better question is, why would you >> expect that? In general, all name resolution calls return results in >> arbitrary order. In some cases, results are intentionally changed on >> every call (i.e. round-robin) in an attempt at load sharing. >> >> What kind of ordering were you hoping for? > > See previous posts. > > Basically I was asking about the contract for this method.. The doc "Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4/v6 addresses for the same interface on the same host (most likely containing only a single address)." > hoping that it is deterministic. As far as I can see, that is not in the contract. > Our testing indicated that the interfaces are returned in a specific > order, but we want to know if this is really the case (on all > platforms). Even if it were so now, a patch could change things. -- Terry Jan Reedy From mail at timgolden.me.uk Mon Aug 22 13:41:45 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Aug 2011 18:41:45 +0100 Subject: Setting the time in Win7 In-Reply-To: <2011082210352016807-bob@passcalnmtedu> References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <4E5294D9.80408@timgolden.me.uk> If memory serves, you need to enable a specific privilege to set the time in Vista+. Just a moment... Have a look here: http://support.microsoft.com/kb/300022 and look for SeSystemtimePrivilege generally. Sorry; I'm a bit rushed at the moment. Feel free to post back if that isn't clear TJG On 22/08/2011 17:35, Bob Greschke wrote: > Permissions! > > We're running in an account as an administrator (the only account on the > laptops) and the program just calls system(time xxxx) and system(date > xxxx) after reading it from a connected GPS receiver. I've fiddled with > everything I could find in the registry and with the secpol.msc program > and there doesn't seem to be any reason that it can't set the time, but > it can't. Any ideas? > > Thanks! > > Bob > From fuentesej at gmail.com Mon Aug 22 13:43:54 2011 From: fuentesej at gmail.com (Edgar Fuentes) Date: Mon, 22 Aug 2011 10:43:54 -0700 (PDT) Subject: Help on PyQt4 QProcess References: <54614b21-2c80-444c-8ac5-89fc52b77121@fv14g2000vbb.googlegroups.com> <607dd6a4-7862-4df6-bd1e-e9f382739592@fv14g2000vbb.googlegroups.com> <9eb754a9-d002-4b05-98ed-afd242e2ee58@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 20, 4:36?am, Phil Thompson wrote: > On Fri, 19 Aug 2011 14:32:12 -0700 (PDT), Edgar Fuentes > > > > > > > > > > wrote: > > On Aug 19, 4:21?pm, Carl Banks wrote: > >> On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: > >> > On Aug 19, 1:56?pm, Phil Thompson > >> > ?wrote: > >> > > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > >> > > wrote: > >> > > > Dear friends, > > >> > > > I need execute an external program from a gui using PyQt4, to > avoid > >> > > > that hang the main thread, i must connect the signal > >> > > > "finished(int)" > >> > > > of a QProcess to work properly. > > >> > > > for example, why this program don't work? > > >> > > > ? ?from PyQt4.QtCore import QProcess > >> > > > ? ?pro = QProcess() # create QProcess object > >> > > > ? ?pro.connect(pro, SIGNAL('started()'), lambda > >> > > > x="started":print(x)) ? ? ? ?# connect > >> > > > ? ?pro.connect(pro, SIGNAL("finished(int)"), lambda > >> > > > x="finished":print(x)) > >> > > > ? ?pro.start('python',['hello.py']) ? ? ? ?# star hello.py > program > >> > > > (contain print("hello world!")) > >> > > > ? ?timeout = -1 > >> > > > ? ?pro.waitForFinished(timeout) > >> > > > ? ?print(pro.readAllStandardOutput().data()) > > >> > > > output: > > >> > > > ? ?started > >> > > > ? ?0 > >> > > > ? ?b'hello world!\n' > > >> > > > see that not emit the signal finished(int) > > >> > > Yes it is, and your lambda slot is printing "0" which is the return > >> > > code > >> > > of the process. > > >> > > Phil > > >> > Ok, but the output should be: > > >> > ? ? started > >> > ? ? b'hello world!\n' > >> > ? ? finished > > >> > no?. > > >> > thanks Phil > > >> Two issues. ?First of all, your slot for the finished function does not > >> have the correct prototype, and it's accidentally not throwing an > >> exception because of your unnecessary use of default arguments. > ?Anyway, > >> to fix that, try this: > > >> pro.connect(pro, SIGNAL("finished(int)"), lambda v, > >> x="finished":print(x)) > > >> Notice that it adds an argument to the lambda (v) that accepts the int > >> argument of the signal. ?If you don't have that argument there, the int > >> argument goes into x, which is why Python prints 0 instead of > "finished". > > >> Second, processess run asynchrously, and because of line-buffering, IO > >> can output asynchronously, and so there's no guarantee what order > output > >> occurs. ?You might try calling the python subprocess with the '-u' > switch > >> to force unbuffered IO, which might be enough to force synchronous > output > >> (depending on how signal/slot and subprocess semantics are > implemented). > > >> Carl Banks > > > Thanks Carl, your intervention was very helpful for me, this solve my > > semantic error. I need to study more about signal/slots and process. > > In which case you should look at the modern, Pythonic connection syntax > rather than the old one... > > ? ? pro.started.connect(lambda: print("started")) > ? ? pro.finished.connect(lambda: print("finished")) > > Phil Pythonic, great!, more straightforward. Thanks again Phil and Carl. best regards, Edgar Fuentes From smainklh at gmail.com Mon Aug 22 14:09:56 2011 From: smainklh at gmail.com (Smaine Kahlouch) Date: Mon, 22 Aug 2011 20:09:56 +0200 Subject: python apt help Message-ID: <4E529B74.8090706@gmail.com> Hi, I'm trying to use the apt_pkg module but it seems to me really hard and i didn't find samples for what i'm trying to do. Actually it should be simple : - Installing a package like 'aptitude install mypackage' - test if a package is already installed Thank you all for your help, Sam From __peter__ at web.de Mon Aug 22 14:38:30 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Aug 2011 20:38:30 +0200 Subject: Adding modified methods from another class without subclassing References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> Message-ID: John O'Hagan wrote: > On Mon, 22 Aug 2011 11:32:18 +0200 > Peter Otten <__peter__ at web.de> wrote: > >> John O'Hagan wrote: >> >> > I have a class like this: >> > >> > class MySeq(): >> > def __init__(self, *seq, c=12): >> > self.__c = c >> > self.__pc = sorted(set([i % __c for i in seq])) >> > self.order = ([[self.__pc.index(i % __c), i // __c] for i in >> > seq]) >> > #other calculated attributes >> > >> > @property >> > def pitches(self): >> > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] >> > >> > #other methods >> >> That makes me dizzy. Are there any maxims in the Zen of Python that this >> piece doesn't violate? > > "Now is better than never"? > > I know it looks crazy to take something apart and put it back together, as > in this *simplified* *example* emphasis mine ;) > , but it does have a meaningful use: reducing a > series of musical notes to a unique irreducible form "__pc", ("prime form" > in pitch-class set theory), but keeping track of the actual current > manifestation of that form via the writeable "order" attribute. That's why > "pitches" must be called with each reference, because it may change, > unlike "__pc", which can only change if the instance is reinitialised. > > I am open to more elegant suggestions, of course. :) > [...] Dunno. Maybe you could inherit from collections.(Mutable)Sequence and somewhat reduce the number of methods you'd have to implement. Or you introduce a Pitch (Python) class that knows about its pitch class, and put that into a normal list: >>> class Pitch(int): ... @property ... def pitch_class(self): ... return self % 12 ... def __repr__(self): ... return "Pitch(%s, pitch_class=%s)" % (self, self.pitch_class) ... >>> map(Pitch, [1,0,42]) [Pitch(1, pitch_class=1), Pitch(0, pitch_class=0), Pitch(42, pitch_class=6)] From bob at passcal.nmt.edu Mon Aug 22 14:46:04 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 12:46:04 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <2011082212460475249-bob@passcalnmtedu> Hi! Yup. I've been from one end of that article to the other with no luck. It must be something to do with the shell that the system() call creates not having permission to set the time, but I can't figure out how to get around it. Just using the GUI the account where the user is running the program from has permission to set the time. On 2011-08-22 11:41:45 -0600, Tim Golden said: > If memory serves, you need to enable a specific privilege to > set the time in Vista+. Just a moment... > > Have a look here: > > http://support.microsoft.com/kb/300022 > > and look for SeSystemtimePrivilege generally. Sorry; I'm > a bit rushed at the moment. Feel free to post back if > that isn't clear > > TJG > > On 22/08/2011 17:35, Bob Greschke wrote: >> Permissions! >> >> We're running in an account as an administrator (the only account on the >> laptops) and the program just calls system(time xxxx) and system(date >> xxxx) after reading it from a connected GPS receiver. I've fiddled with >> everything I could find in the registry and with the secpol.msc program >> and there doesn't seem to be any reason that it can't set the time, but >> it can't. Any ideas? >> >> Thanks! >> >> Bob From matthew.brett at gmail.com Mon Aug 22 14:51:13 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 11:51:13 -0700 (PDT) Subject: Error when deleting and reimporting subpackages Message-ID: Hi, I recently ran into this behavior: >>> import sys >>> import apkg.subpkg >>> del sys.modules['apkg'] >>> import apkg.subpkg as subpkg Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'subpkg' where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. Is this behavior expected? Best, Matthew From me+list/python at ixokai.io Mon Aug 22 15:06:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 12:06:44 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: <4E52A8C4.6080404@ixokai.io> On 8/22/11 11:51 AM, Matthew Brett wrote: > Hi, > > I recently ran into this behavior: > >>>> import sys >>>> import apkg.subpkg >>>> del sys.modules['apkg'] >>>> import apkg.subpkg as subpkg > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'subpkg' > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > Is this behavior expected? Yes. Doing an import of "apkg.subpkg" results in more then just "test1" being cached in sys.modules, and you're removing half of that so leaving Python in a weird state. You also want to del sys.modules["apkg.subpkg"], then you'll be able to re-import apkg.subpkg. I.e: Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import test1.test2 >>> del sys.modules['test1'] >>> del sys.modules['test1.test2'] >>> import test1.test2 as test2 >>> -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From nobody at nowhere.com Mon Aug 22 15:12:16 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 22 Aug 2011 20:12:16 +0100 Subject: Order of addresses returned by socket.gethostbyname_ex() References: <356978ef-e9c1-48fd-bb87-849fe8e27a79@p5g2000vbl.googlegroups.com> Message-ID: On Sun, 21 Aug 2011 23:37:42 -0700, Tomas Lid?n wrote: > In what order are the addresses returned by socket.gethostbyname_ex()? > > We know that gethostbyname() is indeterministic but hope that > gethostbyname_ex() has a specified order. It doesn't. In fact, the order of the IP addresses may have been deliberately randomised (by the resolver and/or DNS server) in order to provide a simple form of load balancing. From matthew.brett at gmail.com Mon Aug 22 15:14:50 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 12:14:50 -0700 (PDT) Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Monday, August 22, 2011 12:06:44 PM UTC-7, Stephen Hansen wrote: > On 8/22/11 11:51 AM, Matthew Brett wrote: > > Hi, > > > > I recently ran into this behavior: > > > >>>> import sys > >>>> import apkg.subpkg > >>>> del sys.modules['apkg'] > >>>> import apkg.subpkg as subpkg > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'module' object has no attribute 'subpkg' > > > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > > > Is this behavior expected? > > Yes. Doing an import of "apkg.subpkg" results in more then just "test1" > being cached in sys.modules, and you're removing half of that so leaving > Python in a weird state. > > You also want to del sys.modules["apkg.subpkg"], then you'll be able to > re-import apkg.subpkg. I.e: > > Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> import test1.test2 > >>> del sys.modules['test1'] > >>> del sys.modules['test1.test2'] > >>> import test1.test2 as test2 > >>> Yes, sorry, I should have mentioned that I explored these kind of variations. I think I see that there isn't an obvious way for del sys.modules['apkg'] to know to delete or modify 'apkg.subpkg', because sys.modules is just a dict. However, I could imagine the import machinery being able to recognize that 'apkg.subpkg' is broken, and re-import it without error. Is that reasonable? Best, Matthew From matthew.brett at gmail.com Mon Aug 22 15:14:50 2011 From: matthew.brett at gmail.com (Matthew Brett) Date: Mon, 22 Aug 2011 12:14:50 -0700 (PDT) Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Monday, August 22, 2011 12:06:44 PM UTC-7, Stephen Hansen wrote: > On 8/22/11 11:51 AM, Matthew Brett wrote: > > Hi, > > > > I recently ran into this behavior: > > > >>>> import sys > >>>> import apkg.subpkg > >>>> del sys.modules['apkg'] > >>>> import apkg.subpkg as subpkg > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'module' object has no attribute 'subpkg' > > > > where 'apkg' and 'subpkg' comprise empty __init__.py files to simplify the example. > > > > It appears then, that importing a subpackage, then deleting the containing package from sys.modules, orphans the subpackage in an unfixable state. > > > > I ran into this because the nose testing framework does exactly this kind of thing when loading test modules, causing some very confusing errors and failures. > > > > Is this behavior expected? > > Yes. Doing an import of "apkg.subpkg" results in more then just "test1" > being cached in sys.modules, and you're removing half of that so leaving > Python in a weird state. > > You also want to del sys.modules["apkg.subpkg"], then you'll be able to > re-import apkg.subpkg. I.e: > > Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> import test1.test2 > >>> del sys.modules['test1'] > >>> del sys.modules['test1.test2'] > >>> import test1.test2 as test2 > >>> Yes, sorry, I should have mentioned that I explored these kind of variations. I think I see that there isn't an obvious way for del sys.modules['apkg'] to know to delete or modify 'apkg.subpkg', because sys.modules is just a dict. However, I could imagine the import machinery being able to recognize that 'apkg.subpkg' is broken, and re-import it without error. Is that reasonable? Best, Matthew From bob at passcal.nmt.edu Mon Aug 22 15:42:28 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 22 Aug 2011 13:42:28 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> Message-ID: <2011082213422850073-bob@passcalnmtedu> Several people have been hacking away on this computer we are testing on, so I'm not sure what settings -- other than all of them -- have been messed with, but popen("time ...") seems to work, but system("time ...") does not. I'm going to restore the machine to its original state and see what happens. Bob On 2011-08-22 11:41:45 -0600, Tim Golden said: > If memory serves, you need to enable a specific privilege to > set the time in Vista+. Just a moment... > > Have a look here: > > http://support.microsoft.com/kb/300022 > > and look for SeSystemtimePrivilege generally. Sorry; I'm > a bit rushed at the moment. Feel free to post back if > that isn't clear > > TJG > > On 22/08/2011 17:35, Bob Greschke wrote: >> Permissions! >> >> We're running in an account as an administrator (the only account on the >> laptops) and the program just calls system(time xxxx) and system(date >> xxxx) after reading it from a connected GPS receiver. I've fiddled with >> everything I could find in the registry and with the secpol.msc program >> and there doesn't seem to be any reason that it can't set the time, but >> it can't. Any ideas? >> >> Thanks! >> >> Bob From chris at simplistix.co.uk Mon Aug 22 17:36:54 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 22 Aug 2011 14:36:54 -0700 Subject: MailingLogger 3.4.0 Released! In-Reply-To: <4E4CB31A.5090803@simplistix.co.uk> References: <4E4CB31A.5090803@simplistix.co.uk> Message-ID: <4E52CBF6.30905@simplistix.co.uk> Heh, of course, I forgot the setuptools-git extension to make "include_package_data=True" work, so this release was pretty useless, other than the docs on packages.python.org/testfixtures ;-) Anyway, 3.4.1 has now been released which fixes this! cheers, Chris On 17/08/2011 23:37, Chris Withers wrote: > I'm pleased to announce a new release of Mailinglogger. > > Mailinglogger provides two handlers for the standard python > logging framework that enable log entries to be emailed either as the > entries are logged or as a summary at the end of the running process. > > The handlers have the following features: > > - customisable and dynamic subject lines for emails sent > > - emails sent with a configurable headers for easy filtering > > - flood protection to ensure the number of emails sent is not excessive > > - support for SMTP servers that require authentication > > - fully documented and tested > > This release has no functional changes but finally ships with a full new > set of Sphinx docs: > > http://packages.python.org/mailinglogger/ > > For more information, please see: > http://www.simplistix.co.uk/software/python/mailinglogger > or > http://pypi.python.org/pypi/mailinglogger > > cheers, > > Chris > -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From me+list/python at ixokai.io Mon Aug 22 17:56:07 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 22 Aug 2011 14:56:07 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: On Mon, Aug 22, 2011 at 12:14 PM, Matthew Brett wrote: > Yes, sorry, I should have mentioned that I explored these kind of > variations. > > I think I see that there isn't an obvious way for del sys.modules['apkg'] > to know to delete or modify 'apkg.subpkg', because sys.modules is just a > dict. > > However, I could imagine the import machinery being able to recognize that > 'apkg.subpkg' is broken, and re-import it without error. > Is that reasonable? > Not really, no. Despite the fact that you can sorta do it, and that there's this "reload" function, Python doesn't really support reloading of modules / code. If you want to do it, you basically have to go out and _do_ it yourself. If you muck about in sys.modules, you need to do so completely. Python and the import stuff won't really do anything to help you (though it won't go out of its way to hinder you, either). Something like: def remove_module(name): for mod in sys.modules.keys(): if mod == name or name.startswith(name + "."): del sys.modules[mod] Then remove_module("apkg") may work for you. (Code above not tested at all, not even kinda) --Ix -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Mon Aug 22 18:46:36 2011 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 23 Aug 2011 08:46:36 +1000 Subject: Order of addresses returned by socket.gethostbyname_ex() In-Reply-To: References: Message-ID: <20110822224636.GA5704@cskk.homeip.net> On 22Aug2011 04:29, Tomas Lid?n wrote: | On 22 Aug, 12:06, Cameron Simpson wrote: | > It would not surprise me if the order was related to the order a scan of | > the system interfaces yields information, and I would imagine that may | > be influenced by the order in which the interfaces were initialised. | > | > So getting the LAN first may merely be fortuitous. | > I wouldn't rely on it, especially if interfaces come and go. | | We did try to disable/enable the interfaces in different orders, but | always got the same return order from gethostbyname_ex(). So it looked | pretty stable (on that specific OS). There's been some testing on | Linux as well, but since this should be used in a general cross | platform tool we wanted to check the exact behaviour of the method. | | > What if you queried your routing table instead? Usually there's just one | > default route, and hopefully it would be configured to use the "best" | > interface. | | Hmm... perhaps. How would you do that? On UNIX systems (and, I think, also Windows systems) you'd run the command: netstat -rn or use the "route" command. (This avoids using operating system calls directly - the command will know what to do itself.) I seem to recall that Windows has the netstat command as well (possibly because, IIRC, they pulled in the BSD UNIX IP stack for their first IP implementation). Anyway, by popening the netstat command you can pull the "default" (or "0.0.0.0") route from its output. Then see if the interface listed there corresponds to what you need to know. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Then again, it's probably really because your average Australian doesn't give a shit about anything that doesn't increase the price of beer. - Murray Chapman From tim at johnsons-web.com Mon Aug 22 19:47:04 2011 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 22 Aug 2011 15:47:04 -0800 Subject: Thoughts about documentation for non-python resource files Message-ID: <20110822234704.GD12101@johnsons-web.com> I'm looking for comments and/or URLs to discussions on this topic. I use my own MVC system. A component of this system generates documentation from python docstrings. Of course this system also comprises many non-python filetypes : css, html, txt, js, xml etc. Views, which are txt or html files can be handled by my system's built-in relationships between controllers and views. For other non-python files which are not found directly to controllers, css, js, html, xml all support comments and documentation can be (and is) build into the comments. Before I proceded and 'roll my own' protocol for generating documentations for these above-mention filetypes, I'd like to know if there is any such protocols being used already. Example : A pythonic way to generate documentations on a javascript file as well as its functions, objects etc. Any comments welcome. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com From Yingjie.Lin at mssm.edu Mon Aug 22 20:17:47 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Mon, 22 Aug 2011 20:17:47 -0400 Subject: Help on instance of closeable_response in module Mechanize Message-ID: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> Hi Python users, I have a question about the instance of closeable_response in module Mechanize. from mechanize import ParseResponse, urlopen url = "http://wwwsearch.sourceforge.net/mechanize/example.html" r = urlopen(url) forms = ParseResponse(r, backwards_compat=False) html_lines = r.read() If I call ParseResponse() before r.read(), then lforms would be a list containing one form instance, and html_lines would be an empty string. If I call r.read() first, then html_lines would be the HTML source code of the page, but forms would be an empty list. Therefore, I have to open the url twice, once for each function, like this: r = urlopen(url) forms = ParseResponse(r, backwards_compat=False) r = urlopen(url) html_lines = r.read() I believe this shouldn't be necessary. What is the proper way of doing it? Thank you. - Yingjie From crebert at ucsd.edu Mon Aug 22 20:27:18 2011 From: crebert at ucsd.edu (Chris Rebert) Date: Mon, 22 Aug 2011 17:27:18 -0700 Subject: Help on instance of closeable_response in module Mechanize In-Reply-To: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> References: <8199DBA0-5A00-4932-9B7C-A5BAD8EC6EEA@mssm.edu> Message-ID: On Mon, Aug 22, 2011 at 5:17 PM, Yingjie Lin wrote: > Hi Python users, > > I have a question about the instance of closeable_response in module Mechanize. > > ? ? ? ?from mechanize import ParseResponse, urlopen > ? ? ? ?url = "http://wwwsearch.sourceforge.net/mechanize/example.html" > ? ? ? ?r = urlopen(url) > ? ? ? ?forms = ParseResponse(r, backwards_compat=False) > ? ? ? ?html_lines = r.read() > > If I call ParseResponse() before r.read(), then lforms would be a list containing one form > instance, and html_lines would be an empty string. If I call r.read() first, then html_lines > would be the HTML source code of the page, but forms would be an empty list. > > Therefore, I have to open the url twice, once for each function, like this: > > ? ? ? ?r = urlopen(url) > ? ? ? ?forms = ParseResponse(r, backwards_compat=False) > ? ? ? ?r = urlopen(url) > ? ? ? ?html_lines = r.read() > > I believe this shouldn't be necessary. What is the proper way of doing it? Thank you. Untested speculation: from StringIO import StringIO r = urlopen(url) html = r.read() s = StringIO(html) forms = ParseResponse(s, backwards_compat=False) Cheers, Chris From research at johnohagan.com Mon Aug 22 20:55:26 2011 From: research at johnohagan.com (John O'Hagan) Date: Tue, 23 Aug 2011 10:55:26 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> Message-ID: <20110823105526.3032630855f69a716738095f@johnohagan.com> On Mon, 22 Aug 2011 23:08:50 +1000 John O'Hagan wrote: > On Mon, 22 Aug 2011 15:27:36 +1000 > Steven D'Aprano wrote: [..] > > Looks like a call for (semi-)automatic delegation! > > > > Try something like this: > > > > > > # Untested > > class MySeq(object): > > methods_to_delegate = ('__getitem__', '__len__', ...) > > pitches = ... # make sure pitches is defined > > def __getattr__(self, name): > > if name in self.__class__.methods_to_delegate: > > return getattr(self.pitches, name) > > return super(MySeq, object).__getattr__(self, name) > > # will likely raise AttributeError > [..] > > However, I don't understand what the super call is doing. If the method isn't delegated, shouldn't it just fall back to getattr(self, name)? On reading the __getattr__ docs properly, I see that AttributeError is what should generally happen. > Thanks and regards, > > John > From steve+comp.lang.python at pearwood.info Mon Aug 22 23:26:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 13:26:30 +1000 Subject: Adding modified methods from another class without subclassing References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <20110822230850.855c6f2ae90cdc57b05f7a74@johnohagan.com> Message-ID: <4e531de6$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Aug 2011 10:55 am John O'Hagan wrote: >> > # Untested >> > class MySeq(object): >> > methods_to_delegate = ('__getitem__', '__len__', ...) >> > pitches = ... ?# make sure pitches is defined >> > def __getattr__(self, name): >> > if name in self.__class__.methods_to_delegate: >> > return getattr(self.pitches, name) >> > return super(MySeq, object).__getattr__(self, name) >> > # will likely raise AttributeError >> > [..] >> >> However, I don't understand what the super call is doing. If the method >> isn't delegated, shouldn't it just fall back to getattr(self, name)? > > On reading the __getattr__ docs properly, I see that AttributeError is > what should generally happen. Which is what the call to super will accomplish, but if the behaviour ever changes (including the error message given), you won't have to change your class. -- Steven From gnarlodious at gmail.com Tue Aug 23 00:12:49 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 22 Aug 2011 21:12:49 -0700 (PDT) Subject: CGI input: Filter dict.update() unwanted variables References: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> Message-ID: <857a0816-108a-4add-b71f-d41593d2e83a@n35g2000yqf.googlegroups.com> On Aug 22, 9:39?am, Miki Tebeka wrote: > HTH Yes it helps, thank you! -- Gnarlie http://Gnarlodious.com From nagle at animats.com Tue Aug 23 00:54:58 2011 From: nagle at animats.com (John Nagle) Date: Mon, 22 Aug 2011 21:54:58 -0700 Subject: Error when deleting and reimporting subpackages In-Reply-To: References: Message-ID: <4e5332c7$0$2177$742ec2ed@news.sonic.net> On 8/22/2011 11:51 AM, Matthew Brett wrote: > Hi, > > I recently ran into this behavior: > >>>> import sys import apkg.subpkg del sys.modules['apkg'] import >>>> apkg.subpkg as subpkg > Traceback (most recent call last): File "", line 1, > in AttributeError: 'module' object has no attribute 'subpkg' > > where 'apkg' and 'subpkg' comprise empty __init__.py files to > simplify the example. > > It appears then, that importing a subpackage, then deleting the > containing package from sys.modules, orphans the subpackage in an > unfixable state. > > I ran into this because the nose testing framework does exactly this > kind of thing when loading test modules, causing some very confusing > errors and failures. > > Is this behavior expected? It's undefined behavior. You're dealing with CPython implementation semantics, not Python language semantics. John Nagle From 1248283536 at qq.com Tue Aug 23 01:10:10 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 23 Aug 2011 13:10:10 +0800 Subject: how to write the lambda expression in my tkinter ? Message-ID: from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(event,entries): for entry in entries: print 'Input => "%s"' % entry.get() # get text print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) # make a new row lab = Label(row, width=5, text=field) # add label, entry ent = Entry(row) row.pack(side=TOP, fill=X) # pack row on top lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) # grow horizontal entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', lambda event,entries=ents: fetch(event,entries)) Button(root, text='Fetch', command= lambda event:fetch(event,entries)).pack(side=LEFT) root.mainloop() when you run it ,press enter ,you can get the value in the entry;when you click the Button(Fetch),there is a wrong output ,i can't revise it,i know it is the 26 can't run ,how to fix it ? Button(root, text='Fetch', command= lambda event:fetch(event,entries)).pack(side=LEFT) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Aug 23 02:52:05 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Aug 2011 23:52:05 -0700 Subject: how to write the lambda expression in my tkinter ? In-Reply-To: References: Message-ID: 2011/8/22 ???? <1248283536 at qq.com>: > from?Tkinter?import?* > fields?=?'Name',?'Job',?'Pay' > > def?fetch(event,entries): > ???for?entry?in?entries: > ???????print?'Input?=>?"%s"'?%?entry.get()???????#?get?text > ???????print??event.widget > > > def?makeform(root,?fields): > ???entries?=?[] > ???for?field?in?fields: > ???????row?=?Frame(root)???????????????????????????#?make?a?new?row > ???????lab?=?Label(row,?width=5,?text=field)???????#?add?label,?entry > ???????ent?=?Entry(row) > ???????row.pack(side=TOP,?fill=X)??????????????????#?pack?row?on?top > ???????lab.pack(side=LEFT) > ???????ent.pack(side=RIGHT,?expand=YES,?fill=X)????#?grow?horizontal > ???????entries.append(ent) > ???return?entries > > if?__name__?==?'__main__': > ???root?=?Tk() > ???ents?=?makeform(root,?fields) > ???root.bind('',?lambda?event,entries=ents:?fetch(event,entries)) > ???Button(root,?text='Fetch',?command=?lambda?event:fetch(event,entries)).pack(side=LEFT) > ???root.mainloop() > > when you run it ,press enter ,you can get the value in the entry;when you > click the? Button(Fetch),there is a wrong output ,i can't revise it,i know > it is the? 26? can't run ,how to fix it ? > > Button(root,?text='Fetch',?command=?lambda?event:fetch(event,entries)).pack(side=LEFT) Problem 1: `entries` is undefined within the scope of the lambda; it's not a parameter of the lambda, nor is it defined in any outer scope that encloses the lambda. This will lead to a NameError. `ents` is / would be within scope however...(*wink*) Problem 2: Based on quick experimentation, Tkinter does not pass `command` any arguments, yet your lambda has 1 required argument (namely, `event`). This will cause a run-time error when the lambda is called. That should be enough to get you started. Cheers, Chris -- http://rebertia.com From no.email at nospam.invalid Tue Aug 23 03:21:45 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Aug 2011 00:21:45 -0700 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Chris Angelico writes: > Ehh, granted. Definitely a case of "should". But certainly, there > won't be an infinite number of new exceptions invented; Right, the number is finite, but the issue is that it's unknown. It's like never knowing whether you've fixed the last bug in a program. From steve+comp.lang.python at pearwood.info Tue Aug 23 03:25:22 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 17:25:22 +1000 Subject: Adding modified methods from another class without subclassing References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote: > On Mon, 22 Aug 2011 15:27:36 +1000 > Steven D'Aprano wrote: [...] >> # Untested >> class MySeq(object): >> methods_to_delegate = ('__getitem__', '__len__', ...) >> pitches = ... # make sure pitches is defined >> def __getattr__(self, name): >> if name in self.__class__.methods_to_delegate: >> return getattr(self.pitches, name) >> return super(MySeq, object).__getattr__(self, name) >> # will likely raise AttributeError > > Thanks, this looks promising. I didn't know about __getattr__ or > delegation. This example doesn't seem to work as is for special methods > beginning with "__" (e.g.: "TypeError: object of type 'MyList' has no > len()"). It seems that __getattr__ is not called for special methods. Ah yes, that would be a problem. This recipe may help. http://code.activestate.com/recipes/252151-generalized-delegates-and-proxies/ > Also, it doesn't immediately suggest to me a way of modifying method calls > (maybe __setattr__?). What do you mean, "modifying method calls"? __getattr__ doesn't know whether the method retrieved modifies the instance or not. That's irrelevant. __setattr__ is called when you say instance.attribute = value > But it's certainly a neater way to get methods to > operate on the attribute. I'm looking into it, and delegation generally. > > However, I don't understand what the super call is doing. If the method > isn't delegated, shouldn't it just fall back to getattr(self, name)? getattr(self, name) will just call self.__getattr__(name) again, which will call getattr, and so on... leading to RecursionError. -- Steven From rosuav at gmail.com Tue Aug 23 04:24:39 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 09:24:39 +0100 Subject: CGI input: Filter dict.update() unwanted variables In-Reply-To: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> References: <61cd88fa-1820-4667-9c01-11fc1b8b574f@glegroupsg2000goo.googlegroups.com> Message-ID: On Mon, Aug 22, 2011 at 4:39 PM, Miki Tebeka wrote: > You can check if there is a "non-allowed variable" and then return HTTP error. > if set(form) - set(allowedVariables): > ? ?print('Status: 406\n\n') > ? ?raise SystemExit() > I'd be disinclined to do this; ignore unrecognized query variables, but don't throw back an error. Sometimes it's convenient to let the browser send a "junk header" that the server will ignore - helps with integration with other systems. As long as you can be sure that the script won't do the wrong thing, it should be fine to have an extra bit of GET/POST data. ChrisA From rosuav at gmail.com Tue Aug 23 04:26:11 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 09:26:11 +0100 Subject: try... except with unknown error types In-Reply-To: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> <4e51a32d$0$29974$c3e8da3$5496439d@news.astraweb.com> <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Aug 23, 2011 at 8:21 AM, Paul Rubin wrote: > Chris Angelico writes: >> Ehh, granted. Definitely a case of "should". But certainly, there >> won't be an infinite number of new exceptions invented; > > Right, the number is finite, but the issue is that it's unknown. ?It's > like never knowing whether you've fixed the last bug in a program. > Yeah. Oh, I know when I've fixed the last bug in a program. It's the day the program gets deleted. Until then? Nope. ChrisA From mail at timgolden.me.uk Tue Aug 23 04:26:38 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Aug 2011 09:26:38 +0100 Subject: Setting the time in Win7 In-Reply-To: <2011082213422850073-bob@passcalnmtedu> References: <2011082210352016807-bob@passcalnmtedu> <2011082213422850073-bob@passcalnmtedu> Message-ID: <4E53643E.7030307@timgolden.me.uk> On 22/08/2011 20:42, Bob Greschke wrote: > Several people have been hacking away on this computer we are testing > on, so I'm not sure what settings -- other than all of them -- have been > messed with, but popen("time ...") seems to work, but system("time ...") > does not. I'm going to restore the machine to its original state and see > what happens. Hoping that this helps: you can programatically set the system time from within Python by using the pywin32 modules, or ctypes if you prefer. The code below works for an already-elevated command prompt by enabling the SystemTime privilege and (crudely) moving the time forward by five minutes by way of showing what's happening before resetting it back. I've commented out the actual SetSystemTime calls just in case anyone cuts-and-pastes indjudiciously. Ideally you should disable the privilege afterwards but I've left that out so as not to clutter the example. import os, sys import win32api import win32security import ntsecuritycon hToken = win32security.OpenProcessToken ( win32api.GetCurrentProcess (), ntsecuritycon.MAXIMUM_ALLOWED ) time_privilege = win32security.LookupPrivilegeValue (None, win32security.SE_SYSTEMTIME_NAME) win32security.AdjustTokenPrivileges ( hToken, 0, [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)] ) current_time = win32api.GetSystemTime () print "Current time:", current_time new_time = list (current_time) new_time[5] += 5 ## print win32api.SetSystemTime (*new_time) print "Current time:", win32api.GetSystemTime () ## print win32api.SetSystemTime (*current_time) print "Current time:", win32api.GetSystemTime () TJG From steve+comp.lang.python at pearwood.info Tue Aug 23 04:33:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 23 Aug 2011 18:33:06 +1000 Subject: try... except with unknown error types References: <4e4ec405$0$29994$c3e8da3$5496439d@news.astraweb.com> <7xipprsxha.fsf@ruckus.brouhaha.com> <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: <4e5365c2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Aug 2011 04:26 am Paul Rubin wrote: > The Erlang approach is tempting. Don't catch the exception at all--just > let the process crash, and restart it. But that's a more heavyweight > operation in Python. You might be interested in this paper: http://usenix.org/events/hotos03/tech/full_papers/candea/candea.pdf -- Steven From gheskett at wdtv.com Tue Aug 23 04:43:18 2011 From: gheskett at wdtv.com (gene heskett) Date: Tue, 23 Aug 2011 04:43:18 -0400 Subject: try... except with unknown error types In-Reply-To: References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: <201108230443.19007.gheskett@wdtv.com> On Tuesday, August 23, 2011 04:42:04 AM Chris Angelico did opine: > On Tue, Aug 23, 2011 at 8:21 AM, Paul Rubin wrote: > > Chris Angelico writes: > >> Ehh, granted. Definitely a case of "should". But certainly, there > >> won't be an infinite number of new exceptions invented; > > > > Right, the number is finite, but the issue is that it's unknown. It's > > like never knowing whether you've fixed the last bug in a program. > > Yeah. Oh, I know when I've fixed the last bug in a program. It's the > day the program gets deleted. Until then? Nope. > > ChrisA OTOH, ChrisA, I have it on good authority that no program is ever finished, until someone shoots the programmer. :) Cheers, gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Practice is the best of all instructors. -- Publilius From rosuav at gmail.com Tue Aug 23 05:07:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 10:07:28 +0100 Subject: try... except with unknown error types In-Reply-To: <201108230443.19007.gheskett@wdtv.com> References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> <201108230443.19007.gheskett@wdtv.com> Message-ID: On Tue, Aug 23, 2011 at 9:43 AM, gene heskett wrote: > OTOH, ChrisA, I have it on good authority that no program is ever finished, > until someone shoots the programmer. ?:) > Correct, although I've had projects that were killed by changes to requirements - such as my fantastic system for writing device drivers that leveraged DEBUG.EXE to translate assembly code into machine code, and a REXX script to handle jump labels and such. That project was quite thoroughly finished on the day that I met nasm :) But that's quite off-topic. ChrisA From wujackjp at gmail.com Tue Aug 23 05:48:00 2011 From: wujackjp at gmail.com (Jack) Date: Tue, 23 Aug 2011 02:48:00 -0700 (PDT) Subject: Why __slots__ slows down attribute access? Message-ID: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> People have illusion that it is faster to visit the attribute defined by __slots__ . http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be That is wrong. The following tests show it is slower. __slots__ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. It makes a little bit slower. So __slots__ just saves memory space by preventing creation of __dict__ and __weakref__ on each instance, while sacrifice performance and inheritance flexibility. http://groups.google.com/group/comp.lang.python/msg/6623e8b94b6d6934 D:\>d:\python-v3.1.2\python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.237 usec per loop D:\>d:\python-v3.1.2\python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5 inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.214 usec per loop D:\>d:\python-v2.6.4\python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.26 usec per loop D:\>d:\python-v2.6.4\python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.217 usec per loop From __peter__ at web.de Tue Aug 23 06:26:50 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Aug 2011 12:26:50 +0200 Subject: Why __slots__ slows down attribute access? References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ . > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. Not so fast. Here's what I get (python2.6.4, 64 bit): $ python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.324 usec per loop $ python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" 1000000 loops, best of 3: 0.393 usec per loop Now what? From johnjohn.tedro at gmail.com Tue Aug 23 06:57:05 2011 From: johnjohn.tedro at gmail.com (John-John Tedro) Date: Tue, 23 Aug 2011 12:57:05 +0200 Subject: Why __slots__ slows down attribute access? In-Reply-To: References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: On Tue, Aug 23, 2011 at 12:26 PM, Peter Otten <__peter__ at web.de> wrote: > Jack wrote: > > > People have illusion that it is faster to visit the attribute defined > > by __slots__ . > > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > > > That is wrong. The following tests show it is slower. > > Not so fast. Here's what I get (python2.6.4, 64 bit): > > $ python -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s > "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.324 usec per loop > > $ python -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; > inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.393 usec per loop > > Now what? > > -- > http://mail.python.org/mailman/listinfo/python-list > This is what I get on a 64 bit Linux 2.6.39 script: for v in 2.6 2.7 3.2; do python$v --version echo -n "(slots) = "; python$v -mtimeit -s "class A(object): __slots__ = ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7"; echo -n "(regular) = "; python$v -mtimeit -s "class A(object): pass" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7"; done output: Python 2.6.5 (slots) = 1000000 loops, best of 3: 0.219 usec per loop (regular) = 1000000 loops, best of 3: 0.231 usec per loop Python 2.7.2 (slots) = 1000000 loops, best of 3: 0.244 usec per loop (regular) = 1000000 loops, best of 3: 0.285 usec per loop Python 3.2 (slots) = 1000000 loops, best of 3: 0.193 usec per loop (regular) = 1000000 loops, best of 3: 0.224 usec per loop -- John-John Tedro -------------- next part -------------- An HTML attachment was scrubbed... URL: From askutt at gmail.com Tue Aug 23 07:26:10 2011 From: askutt at gmail.com (Adam Skutt) Date: Tue, 23 Aug 2011 04:26:10 -0700 (PDT) Subject: Why __slots__ slows down attribute access? References: <75441dbc-4fdc-449d-a08a-a8f836819c9e@s7g2000yqd.googlegroups.com> Message-ID: <920e68e2-58a6-4022-a333-7bd11f7295d7@h34g2000vbr.googlegroups.com> On Aug 23, 5:48?am, Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ .http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. No, they don't really show anything. The default clocks used by timeit lack the resolution to measure such things accurately; you're measuring various noise sources on your system. The range of 100 trials of 1million iterations on my system is 70.3 ms, which is 70ns when divided by a million, which is about the size of the difference you show. A 70ns average difference between iterations is trivially attributable to noise on a modern machine. Run enough trials or just wait for the moon to move a bit, and I wouldn't be terribly surprised if you got difference results. Rebooting your machine might be enough to do it. Adam > D:\>d:\python-v3.1.2\python ?-mtimeit -s "class A(object): __slots__ = > ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.237 usec per loop > > D:\>d:\python-v3.1.2\python ?-mtimeit -s "class A(object): pass" -s > "inst = A()" "inst.a=5 inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.214 usec per loop > > D:\>d:\python-v2.6.4\python ?-mtimeit -s "class A(object): __slots__ = > ('a', 'b', 'c')" -s "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.26 usec per loop > > D:\>d:\python-v2.6.4\python ?-mtimeit -s "class A(object): pass" -s > "inst = A()" "inst.a=5; inst.b=6; inst.c=7" > 1000000 loops, best of 3: 0.217 usec per loop From thinke365 at gmail.com Tue Aug 23 07:59:21 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 23 Aug 2011 19:59:21 +0800 Subject: is there any principle when writing python function Message-ID: i have heard that function invocation in python is expensive, but make lots of functions are a good design habit in many other languages, so is there any principle when writing python function? for example, how many lines should form a function? From __peter__ at web.de Tue Aug 23 08:20:50 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Aug 2011 14:20:50 +0200 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Five ;) From mwilson at the-wire.com Tue Aug 23 08:53:49 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 23 Aug 2011 08:53:49 -0400 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? It's hard to discuss in the abstract. A function should perform a recognizable step in solving the program's problem. If you prepared to write your program by describing each of several operations the program would have to perform, then you might go on to plan a function for each of the described operations. The high-level functions can then be analyzed, and will probably lead to functions of their own. Test-driven development encourages smaller functions that give you a better granularity of testing. Even so, the testable functions should each perform one meaningful step of a more general problem. > for example, how many lines should form a function? Maybe as few as one. def increase (x, a): return x+a is kind of stupid, but a more complicated line def expand_template (bitwidth, defs): '''Turn Run-Length-Encoded list into bits.''' return np.array (sum (([bit]*(count*bitwidth) for count, bit in defs), []), np.int8) is the epitome of intelligence. I wrote it myself. Even increase might be useful: def increase (x, a): return x + a * application_dependent_quantity `increase` has become a meaningful operation in the imaginary application we're discussing. For an upper bound, it's harder to say. If you read to the end of a function and can't remember how it started, or what it did in between, it's too big. If you're reading on your favourite screen, and the end and the beginning are more than one page-scroll apart, it might be too big. If it's too big, factoring it into sub-steps and making functions of some of those sub-steps is the fix. Mel. From roy at panix.com Tue Aug 23 08:55:19 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 08:55:19 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Enough lines to do what the function needs to do, but no more. Seriously, break up your program into functions based on logical groupings, and whatever makes your code easiest to understand. When you're all done, if your program is too slow, run it under the profiler. Use the profiling results to indicate which parts need improvement. It's very unlikely that function call overhead will be a significant issue. Don't worry about stuff like that unless the profiler shows its a bottleneck. Don't try to guess what's slow. My guesses are almost always wrong. Yours will be too. If your program runs fast enough as it is, don't even bother with the profiler. Be happy that you've got something useful and move on to the next thing you've got to do. From roy at panix.com Tue Aug 23 08:56:57 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 08:56:57 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > smith jack wrote: > > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example, how many lines should form a function? > > Five ;) Five is right out. From ulrich.eckhardt at dominolaser.com Tue Aug 23 09:00:47 2011 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Aug 2011 15:00:47 +0200 Subject: is there any principle when writing python function References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Don't compromise the design and clarity of your code just because you heard some rumors about performance. Also, for any performance question, please consult a profiler. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From yasar11732 at gmail.com Tue Aug 23 09:20:34 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Tue, 23 Aug 2011 16:20:34 +0300 Subject: Fwd: is there any principle when writing python function In-Reply-To: References: Message-ID: I accidentally sent below mail only to roy. Resending to groups. ---------- Y?nlendirilmi? ileti ---------- Kimden: Ya?ar Arabac? Tarih: 23 A?ustos 2011 16:19 Konu: Re: is there any principle when writing python function Kime: Roy Smith I don't see myself a good python programmer or anything, but just saying what I do. I create function for each of the biggest code blocks that is going to be executed more then once. 2011/8/23 Roy Smith > In article , Peter Otten <__peter__ at web.de> > wrote: > > > smith jack wrote: > > > > > i have heard that function invocation in python is expensive, but make > > > lots of functions are a good design habit in many other languages, so > > > is there any principle when writing python function? > > > for example, how many lines should form a function? > > > > Five ;) > > Five is right out. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://yasar.serveblog.net/ -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at tobiah.org Tue Aug 23 09:27:39 2011 From: toby at tobiah.org (Tobiah) Date: Tue, 23 Aug 2011 06:27:39 -0700 Subject: Hiding token information from users Message-ID: I am making QR codes that cell phone users scan in order to make use of an application. Part of the information is a token that needs to be passed on to the server, but I'd rather not allow a person examining the QR code to be able to see that plain bit of information. I'd like to scramble up the token so that the result: 1) takes up the same (near, or less) number of characters as the original token. 2) They key can be derived from the input, and vise versa. 3) The result is alphanumeric. 4) When one character changes in the source, many characters are likely to change in the result. So if my token is: mytoken2011 The result might be something like: xm23ffz4uuw Then mytoken2012 might yield something very different: d8ru3jdhvhd I was thinking of just stringing up all letters and numbers into a 'wheel' and doing an 18 char rotation on the chars in the token, but that fails #4. The secret is not like the key to Fort Knox. We would rather not have the plain token out there, as it's internal business information, but we don't have to protect the information at all costs. Just making it really inconvenient to extract is fine. Thanks, Tobiah From fzadrozny at appcelerator.com Tue Aug 23 09:36:23 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Tue, 23 Aug 2011 10:36:23 -0300 Subject: PyDev 2.2.2 Released Message-ID: Hi All, PyDev 2.2.2 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- **IPython / Interactive console** * IPython (0.10 or 0.11) is now used as the interactive console backend if PyDev can detect it in the PYTHONPATH. * While waiting for the output of a command, intermediary results are printed in the console. * ANSI color codes are supported in the interactive console. **Code Analysis** * Reporting variables that shadow builtins as warnings. * Fixed issue where __dict__ was not found. **Code completion** * Aliases have a better treatment (i.e.: unittest.assertEqual will show the proper type/parameters). * Improved support for analyzing function builtins where the return type is known (i.e.: open, str.split, etc). **Debugger** * When doing a remote debug session, if the files cannot be found in the local filesystem, PyDev will ask for files in the remote debugger. **Editor** * Files without extension that have a python shebang (e.g.: #!/usr/bin/python in the first line) are automatically opened with the PyDev editor (in the PyDev Package Explorer). **Django** * When the shell command is used in the django custom commands, PyDev no longer uses 100% cpu while it doesn't complete. **Others** * Fixed issue where the * operator was not properly formatted. * When the quick outline dialog is deactivated, it's closed. * Fixed heuristic for finding position for local import. * Fixed compare editor issue with Eclipse 3.2. * Fixed integration issue with latest PyLint. * Fixed deadlock issue on app engine manage window. * More options added to configure the automatic deletion of .pyc files (delete always, never delete, delete only on .py delete). What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From lists at cheimes.de Tue Aug 23 09:40:59 2011 From: lists at cheimes.de (Christian Heimes) Date: Tue, 23 Aug 2011 15:40:59 +0200 Subject: Python Windows Extensions for Mac In-Reply-To: <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> References: <03C16874-0DE8-49B4-A1B3-32E576D01357@zoho.com> <131f19a7e75.1894874194572815237.1558182944908462737@zoho.com> Message-ID: Am 22.08.2011 15:07, schrieb johnny.venter: > Chris, thank you for the information. Focusing on Active Directory, I reviewed the info at the following site: http://technet.microsoft.com/en-us/library/cc961766.aspx > > Based on this, I need to find a module that implements the LDAP APIs. By default, it does not appear that Python can speak this language, I am using version 2.6.1. The module I found is Python-LDAP (http://www.python-ldap.org/). > > Does anyone have experience using this? LDAP is a protocol, not a language. You are right, LDAP isn't part of the Python standard library. The python-ldap extensions works well with Active Directory. I've used it to write an authentication and authorisation layer for our application. A word of warning: LDAP isn't trivial and AD has its quirks, too. It's going to take you a while to understand its concepts. Christian From rvince99 at gmail.com Tue Aug 23 09:45:17 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 23 Aug 2011 06:45:17 -0700 (PDT) Subject: Directly executing from an egg Message-ID: I have created an egg file with one source file in it, hello.py (I just want to go through the entire uild/install/execute cycle using egg files). I create it fine, and now I want to execute the eg file directly (i.e. run it without unpacking or easy_install'ing it). So when I invoke it from the directory the egg is in with: python 'hello-1.0-py2.6.egg I get: can't find '__main__.py' in 'hello-1.0-py2.6.egg' How do I remedy this? I've looked through the docs but it seems ambiguous on this point to me. Below is the setup section from my setup.py which I used to create this egg. Thank you, RVince setup( name='hello', version='1.0', description='', author='', author_email='', install_requires=[ "SQLAlchemy>=0.4", "psycopg2", ], zip_safe=False, entry_points=""" [hello] hello = hello:hello_app """, ) From thinke365 at gmail.com Tue Aug 23 10:03:29 2011 From: thinke365 at gmail.com (smith jack) Date: Tue, 23 Aug 2011 22:03:29 +0800 Subject: why i cannot invoke python script using command line? Message-ID: but i can invoke it in eclipse, what's wrong? the script refered to another python script in eclipse project. f:\project\src\a.py f:\project\src\lib\b.py there is such lines in a.py from lib import b i can invoke a.py very well in eclipse but failed when using python f:\project\src\a.py, what's wrong? (the error msg shows a.py cannot find b.py) , what should i do in order to run a.py using command line? From Yingjie.Lin at mssm.edu Tue Aug 23 10:21:09 2011 From: Yingjie.Lin at mssm.edu (Yingjie Lin) Date: Tue, 23 Aug 2011 10:21:09 -0400 Subject: Methods on file-like objects can only used once on one object? Message-ID: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> Hi Python users, I just realize that my post yesterday shouldn't be specifically for mechanize. It should be a general question for file-like objects. >>> f = open('my_file.txt') >>> print f.readlines() ( prints a list of strings >>> print f.readlines() [] There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: f.readlines() f.read() ... What should I do? Thank you. - Yingjie From gordon at panix.com Tue Aug 23 10:21:29 2011 From: gordon at panix.com (John Gordon) Date: Tue, 23 Aug 2011 14:21:29 +0000 (UTC) Subject: why i cannot invoke python script using command line? References: Message-ID: In smith jack writes: > but i can invoke it in eclipse, what's wrong? > the script refered to another python script in eclipse project. > f:\project\src\a.py > f:\project\src\lib\b.py > there is such lines in a.py > from lib import b > i can invoke a.py very well in eclipse > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? What is your PYTHONPATH environment variable setting? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Tue Aug 23 10:25:56 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Aug 2011 15:25:56 +0100 Subject: why i cannot invoke python script using command line? In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 3:03 PM, smith jack wrote: > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? > >From the sound of things, your working directory is not f:\project\src. I recommend you either: 1) Change to that directory first: cd f:\project\src python a.py Or 2) Add to your import path inside a.py: import sys sys.path.append(r"f:\project\src") Either method should solve the problem. Chris Angelico From ian.g.kelly at gmail.com Tue Aug 23 11:08:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Aug 2011 09:08:00 -0600 Subject: Hiding token information from users In-Reply-To: References: Message-ID: How many of these codes do you need, and do they only need to be decrypted at a central server? You might be able to just create random strings of whatever form you want and associate them with the tokens in a database. Then they will be completely opaque. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peterirbizon at gmail.com Tue Aug 23 11:08:30 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Tue, 23 Aug 2011 17:08:30 +0200 Subject: incorporate png/ico to exe and use it in application Message-ID: hello, I am zsing py2exe to compile exe files. I would like to incorporate png and icon file into exe and then use it during program run (to show it in about dialog and system tray). How can I do it? For example now I use self.staticon.set_from_file(os.path.join(module_path(), "icon.ico")) but I would like to prevent user from changeing this icon. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Aug 23 11:22:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:22:19 +1000 Subject: is there any principle when writing python function References: Message-ID: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> smith jack wrote: > i have heard that function invocation in python is expensive, It's expensive, but not *that* expensive. Compare: [steve at sylar ~]$ python3.2 -m timeit 'x = "abc".upper()' 1000000 loops, best of 3: 0.31 usec per loop [steve at sylar ~]$ python3.2 -m timeit -s 'def f(): return "abc".upper()' 'f()' 1000000 loops, best of 3: 0.53 usec per loop So the function call is nearly as expensive as this (very simple!) sample code. But in absolute terms, that's not very expensive at all. If we make the code more expensive: [steve at sylar ~]$ python3.2 -m timeit '("abc"*1000)[2:995].upper().lower()' 10000 loops, best of 3: 32.3 usec per loop [steve at sylar ~]$ python3.2 -m timeit -s 'def f(): return ("abc"*1000 [2:995].upper().lower()' 'f()' 10000 loops, best of 3: 33.9 usec per loop the function call overhead becomes trivial. Cases where function call overhead is significant are rare. Not vanishingly rare, but rare enough that you shouldn't worry about them. > but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? About as long as a piece of string. A more serious answer: it should be exactly as long as needed to do the smallest amount of work that makes up one action, and no longer or shorter. If you want to maximise the programmer's efficiency, a single function should be short enough to keep the whole thing in your short-term memory at once. This means it should consist of no more than seven, plus or minus two, chunks of code. A chunk may be a single line, or a few lines that together make up a unit, or if the lines are particularly complex, *less* than a line. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two http://www.codinghorror.com/blog/2006/08/the-magical-number-seven-plus-or-minus-two.html (Don't be put off by the use of the term "magical" -- there's nothing literally magical about this. It's just a side-effect of the way human cognition works.) Anything longer than 7?2 chunks, and you will find yourself having to scroll backwards and forwards through the function, swapping information into your short-term memory, in order to understand it. Even 7?2 is probably excessive: I find that I'm most comfortable with functions that perform 4?1 chunks of work. An example from one of my classes: def find(self, prefix): """Find the item that matches prefix.""" prefix = prefix.lower() # Chunk #1 menu = self._cleaned_menu # Chunk #2 for i,s in enumerate(menu, 1): # Chunk #3 if s.lower().startswith(prefix): return i return None # Chunk #4 So that's three one-line chunks and one three-line chunk. -- Steven From darnold992000 at yahoo.com Tue Aug 23 11:24:11 2011 From: darnold992000 at yahoo.com (darnold) Date: Tue, 23 Aug 2011 08:24:11 -0700 (PDT) Subject: Methods on file-like objects can only used once on one object? References: Message-ID: On Aug 23, 9:21?am, Yingjie Lin wrote: > Hi Python users, > > I just realize that my post yesterday shouldn't be specifically for mechanize. It should be a general question for file-like objects. > > >>> f = open('my_file.txt') > >>> print f.readlines() > > ? ? ? ? ( prints a list of strings>>> print f.readlines() > > [] > > There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: > > f.readlines() > f.read() > ... > > What should I do? Thank you. > > - Yingjie Each of those calls consumes the entire file, leaving the file pointer at end-of-file. to reset the file pointer back to the beginning of the file and enable re-reading, use f.seek(0) . From steve+comp.lang.python at pearwood.info Tue Aug 23 11:25:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:25:06 +1000 Subject: Methods on file-like objects can only used once on one object? References: Message-ID: <4e53c651$0$29996$c3e8da3$5496439d@news.astraweb.com> Yingjie Lin wrote: > Hi Python users, > > I just realize that my post yesterday shouldn't be specifically for > mechanize. It should be a general question for file-like objects. > >>>> f = open('my_file.txt') >>>> print f.readlines() > ( prints a list of strings >>>> print f.readlines() > [] Once you've read the file, the file pointer is now at the end of the file. To go back to the beginning of the file and read it again, you have to use the seek method: f.seek(0) But better is to not read the file twice: f = open('my_file.txt') lines = f.readlines() print lines print lines print lines print lines f.close() There's no need to read the lines again unless you expect that the file has changed. -- Steven From paul at subsignal.org Tue Aug 23 11:28:11 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Tue, 23 Aug 2011 17:28:11 +0200 Subject: Methods on file-like objects can only used once on one object? In-Reply-To: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> References: <04416400-42EE-4135-A0A5-96CB8792554D@mssm.edu> Message-ID: Am 23.08.2011 16:21, schrieb Yingjie Lin: > Hi Python users, [snip] > There are quite a few methods for file-like objects that can only be used once on one object. If I prefer to use some of these methods on one object, one after another, like: > > f.readlines() > f.read() > ... > > What should I do? Thank you. use f.seek(0) between calls. The python documentation will educate you about the details. hth Paul From eric.lemings at gmail.com Tue Aug 23 11:29:58 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 08:29:58 -0700 (PDT) Subject: Windows No-Install Distribution? Message-ID: Hi, I would like to create/find a Python 3.x distribution that can be redeployed simply by copying a directory of required files; i.e. without the need for actually "installing" an MSI, modifying Windows registry entries, etc. First of all, will Python even work on Windows simply by copying files from one system to another? If so, does such a "no-install" distribution already exist? If not, what are the minimum set of Python 3.x files from a standard Windows Python installation required for proper/normal operation? Thanks, Eric. From redcat at streemit.net Tue Aug 23 11:31:48 2011 From: redcat at streemit.net (Redcat) Date: 23 Aug 2011 15:31:48 GMT Subject: Windows No-Install Distribution? References: Message-ID: <9bhvf4F5glU1@mid.individual.net> I haven't tried it myself yet, but might http://www.portablepython.com/ be what you're looking for? From steve+comp.lang.python at pearwood.info Tue Aug 23 11:34:26 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 01:34:26 +1000 Subject: why i cannot invoke python script using command line? References: Message-ID: <4e53c882$0$29986$c3e8da3$5496439d@news.astraweb.com> smith jack wrote: > but i can invoke it in eclipse, what's wrong? > the script refered to another python script in eclipse project. > > f:\project\src\a.py > f:\project\src\lib\b.py > > there is such lines in a.py > from lib import b > > i can invoke a.py very well in eclipse > > but failed when using python f:\project\src\a.py, what's wrong? > (the error msg shows a.py cannot find b.py) , what should i do in > order to run a.py using command line? The import statement doesn't search the entire hard drive. It only searches the places in sys.path. You can modify sys.path either programmatically, or by adding things to the environment variable PYTHONPATH. Eclipse may be modifying the path so that it works in Eclipse. My recommendation is to either: (1) Use a flatter layout, like: f:\project\src\a.py f:\project\src\b.py and cd into f:\project\src\ before executing python a.py OR (2) learn how to use packages, and put a and b into a package; OR (3) Inside script a.py, add this to the start of the file: import os import sys import __main__ location = os.path.split(__main__.__file__)[0] location = os.path.join(location, 'lib') sys.path.append(location) -- Steven From toby at tobiah.org Tue Aug 23 11:35:51 2011 From: toby at tobiah.org (Tobiah) Date: Tue, 23 Aug 2011 08:35:51 -0700 Subject: Hiding token information from users In-Reply-To: References: Message-ID: <4E53C8D7.3040606@tobiah.org> On 08/23/2011 08:08 AM, Ian Kelly wrote: > How many of these codes do you need, and do they only need to be > decrypted at a central server? You might be able to just create random > strings of whatever form you want and associate them with the tokens in > a database. Then they will be completely opaque. > The tokens have a year portion that increments each year, and the base portion of the token will be created newly in accordance with new accounts that we take on. I really need some sort of algorithm that will let me take an unknown string and generate the encrypted bit on the fly. Thanks, Tobiah From invalid at invalid.invalid Tue Aug 23 11:35:56 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Aug 2011 15:35:56 +0000 (UTC) Subject: Methods on file-like objects can only used once on one object? References: <4e53c651$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-23, Steven D'Aprano wrote: > Yingjie Lin wrote: > >> Hi Python users, >> >> I just realize that my post yesterday shouldn't be specifically for >> mechanize. It should be a general question for file-like objects. >> >>>>> f = open('my_file.txt') >>>>> print f.readlines() >> ( prints a list of strings >>>>> print f.readlines() >> [] > > Once you've read the file, the file pointer is now at the end of the file. > To go back to the beginning of the file and read it again, you have to use > the seek method: > > f.seek(0) It's too bad Python doesn't support the f.rewind() spelling for that operation. Rewinding disk files always made me smile... -- Grant Edwards grant.b.edwards Yow! Did I say I was at a sardine? Or a bus??? gmail.com From bob at passcal.nmt.edu Tue Aug 23 11:49:34 2011 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 23 Aug 2011 09:49:34 -0600 Subject: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> <2011082213422850073-bob@passcalnmtedu> Message-ID: <2011082309493416807-bob@passcalnmtedu> On 2011-08-23 02:26:38 -0600, Tim Golden said: > On 22/08/2011 20:42, Bob Greschke wrote: >> Several people have been hacking away on this computer we are testing >> on, so I'm not sure what settings -- other than all of them -- have been >> messed with, but popen("time ...") seems to work, but system("time ...") >> does not. I'm going to restore the machine to its original state and see >> what happens. > > Hoping that this helps: you can programatically set the system time > from within Python by using the pywin32 modules, or ctypes if you > prefer. The code below works for an already-elevated command prompt > by enabling the SystemTime privilege and (crudely) moving the time > forward by five minutes by way of showing what's happening before > resetting it back. > > I've commented out the actual SetSystemTime calls just in case anyone > cuts-and-pastes indjudiciously. Ideally you should disable the > privilege afterwards but I've left that out so as not to clutter > the example. > > > import os, sys > > import win32api > import win32security > import ntsecuritycon > > hToken = win32security.OpenProcessToken ( > win32api.GetCurrentProcess (), > ntsecuritycon.MAXIMUM_ALLOWED > ) > time_privilege = win32security.LookupPrivilegeValue (None, > win32security.SE_SYSTEMTIME_NAME) > win32security.AdjustTokenPrivileges ( > hToken, 0, > [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)] > ) > > current_time = win32api.GetSystemTime () > print "Current time:", current_time > new_time = list (current_time) > new_time[5] += 5 > ## print win32api.SetSystemTime (*new_time) > print "Current time:", win32api.GetSystemTime () > ## print win32api.SetSystemTime (*current_time) > print "Current time:", win32api.GetSystemTime () > > > > TJG Oooo. Now I can be dangerous. We kinda also solved the whole thing for us (just a few minutes ago) by checking the checkbutton "Run as administrator" in the Properties, Compatibility tab, for python.exe and pythonw.exe. The account is an Administrator, so it's OK for this. I thought there must be a way through pywin32, but I don't know much of anything about Windows API calls. I have a Windows Programming book collecting dust somewhere... Thanks! Bob From peterirbizon at gmail.com Tue Aug 23 11:52:36 2011 From: peterirbizon at gmail.com (Peter Irbizon) Date: Tue, 23 Aug 2011 17:52:36 +0200 Subject: aboutdialog space between program name/version and logo Message-ID: Hello, please how can i set space between program name/version and logo in this code? thanks about = gtk.AboutDialog() about.set_program_name("name") about.set_version("0.0.1") about.set_logo(gtk.gdk.pixbuf_new_from_file("file.png")) -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Tue Aug 23 11:59:23 2011 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 23 Aug 2011 10:59:23 -0500 Subject: Windows No-Install Distribution? In-Reply-To: References: Message-ID: <4E53CE5B.3040202@gmail.com> On 2011.08.23 10:29 AM, Eric Lemings wrote: > Hi, > > I would like to create/find a Python 3.x distribution that can be > redeployed simply by copying a directory of required files; i.e. > without the need for actually "installing" an MSI, modifying Windows > registry entries, etc. First of all, will Python even work on Windows > simply by copying files from one system to another? If so, does such > a "no-install" distribution already exist? If not, what are the > minimum set of Python 3.x files from a standard Windows Python > installation required for proper/normal operation? I unpacked the 32-bit version of CPython 3.2 from its installer into a folder and it seems to work. I haven't done any real testing, but it works for me (mainly I just need to have the files needed to build 32-bit frozen binaries with cx_Freeze). -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB From rvince99 at gmail.com Tue Aug 23 12:14:06 2011 From: rvince99 at gmail.com (RVince) Date: Tue, 23 Aug 2011 09:14:06 -0700 (PDT) Subject: Execute a method in a file in an egg Message-ID: Is there a way to do this from the command line? Thanks. From roy at panix.com Tue Aug 23 12:29:56 2011 From: roy at panix.com (Roy Smith) Date: Tue, 23 Aug 2011 09:29:56 -0700 (PDT) Subject: truncating strings Message-ID: I want to log a string but only the first bunch of it, and add "..." to the end if it got truncated. This certainly works: log_message = message if len(log_message) >= 50: log_message = log_message[:50] + '...' logger.error("FAILED: '%s', '%s', %s, %s" % (log_message, route, params, e.code)) but it bugs me that there should be some cleaner way to do this. I'm fantasizing about something along the lines of: logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, route, params, e.code)) does anything like this exist? From k.sahithi2862 at gmail.com Tue Aug 23 12:36:06 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 23 Aug 2011 09:36:06 -0700 (PDT) Subject: TOLLY WOOD HOT GIRLS Message-ID: <39592601-48cc-44d5-b7a4-da44d4d9ae7c@n19g2000prh.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From eric.lemings at gmail.com Tue Aug 23 12:46:43 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 09:46:43 -0700 (PDT) Subject: Windows No-Install Distribution? References: <9bhvf4F5glU1@mid.individual.net> Message-ID: <98dd0cad-1f08-4827-9569-0178696d0f8e@s7g2000yqk.googlegroups.com> On Aug 23, 9:31?am, Redcat wrote: > I haven't tried it myself yet, but mighthttp://www.portablepython.com/ > be what you're looking for? Almost except it contains additional Python packages that I'm not interested in. From usenet-nospam at seebs.net Tue Aug 23 12:53:40 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 16:53:40 GMT Subject: is there any principle when writing python function References: Message-ID: On 2011-08-23, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? Lots of them. None of them have to do with performance. > for example, how many lines should form a function? Between zero (which has to be written "pass") and a few hundred. Usually closer to the lower end of that range. Occasionally outside it. Which is to say: This is the wrong question. Let us give you the two laws of software optimization. Law #1: Don't do it. If you try to optimize stuff, you will waste a ton of time doing things that, it turns out, are unimportant. Law #2: (Experts only.) Don't do it yet. You don't know enough to "optimize" this yet. Write something that does what it is supposed to do and which you understand clearly. See how it looks. If it looks like it is running well enough, STOP. You are done. Now, if it is too slow, and you are running it on real data, NOW it is time to think about why it is slow. And the solution there is not to read abstract theories about your language, but to profile it -- actually time execution and find out where the time goes. I've been writing code, and making it faster, for some longish period of time. I have not yet ever in any language found cause to worry about function call overhead. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Tue Aug 23 12:55:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 02:55:11 +1000 Subject: Hiding token information from users References: Message-ID: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> Tobiah wrote: > I really need some sort of > algorithm that will let me take an unknown string and generate > the encrypted bit on the fly. Google broken for you? *wink* Seriously, there are about a bazillion algorithms for encrypting and obfuscating strings. Depending on your security requirements, that can be as simple as rot13 and as complex as blowfish (or even more so). If it helps, I have a module that implements a selection of classical (i.e. insecure) encryption algorithms: http://pypi.python.org/pypi/obfuscate Earlier, you said: > The secret is not like > the key to Fort Knox. ?We would rather not have the plain > token out there, as it's internal business information, > but we don't have to protect the information at all costs. > Just making it really inconvenient to extract is fine. I don't understand the point of this. What could your users do with the plain token that they shouldn't? I don't see why, if it's not worth encrypting properly, why it's worth obfuscating it at all. -- Steven From tobiah at teranews.com Tue Aug 23 13:00:33 2011 From: tobiah at teranews.com (Tobiah) Date: Tue, 23 Aug 2011 10:00:33 -0700 Subject: Hiding token information from users In-Reply-To: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4e53db6f$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/23/2011 09:55 AM, Steven D'Aprano wrote: > Tobiah wrote: > >> I really need some sort of >> algorithm that will let me take an unknown string and generate >> the encrypted bit on the fly. > > Google broken for you? *wink* I had some requirements in the OP that I could not find a solution for. > Seriously, there are about a bazillion algorithms for encrypting and > obfuscating strings. Depending on your security requirements, that can be > as simple as rot13 and as complex as blowfish (or even more so). > > If it helps, I have a module that implements a selection of classical (i.e. > insecure) encryption algorithms: > > http://pypi.python.org/pypi/obfuscate > > > Earlier, you said: > >> The secret is not like >> the key to Fort Knox. We would rather not have the plain >> token out there, as it's internal business information, >> but we don't have to protect the information at all costs. >> Just making it really inconvenient to extract is fine. > > I don't understand the point of this. What could your users do with the > plain token that they shouldn't? I don't see why, if it's not worth > encrypting properly, why it's worth obfuscating it at all. The token ends up translating into the name of a database on our server. With that information alone, it's difficult to imagine a serious vulnerability, yet we just thought it would be worth it to disguise the plain text. From rantingrick at gmail.com Tue Aug 23 13:02:41 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 23 Aug 2011 10:02:41 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> On Aug 23, 6:59?am, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Everyone here who is suggesting that function bodies should be confined to ANY length is an idiot. The length of a functions code block is inconsequential. Don't worry if it too small or too big. It's not the size that matters, it's the motion of the sources ocean! A good function can be one line, or a hundred lines. Always use comments to clarify code and NEVER EVER create more functions only for the sake of short function bodies, WHY, because all you do is move confusion OUT OF the function body and INTO the module/class body. """Energy can neither be created nor be destroyed: it can only be transformed from one state to another""" http://en.wikipedia.org/wiki/Conservation_of_energy https://sites.google.com/site/thefutureofpython/ From clp2 at rebertia.com Tue Aug 23 13:27:42 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 10:27:42 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 9:29 AM, Roy Smith wrote: > I want to log a string but only the first bunch of it, and add "..." > to the end if it got truncated. ?This certainly works: > > ? ? ? ? ?log_message = message > ? ? ? ? ?if len(log_message) >= 50: > ? ? ? ? ? ?log_message = log_message[:50] + '...' > ? ? ? ? ?logger.error("FAILED: '%s', '%s', %s, %s" % (log_message, > route, params, e.code)) > > but it bugs me that there should be some cleaner way to do this. ?I'm > fantasizing about something along the lines of: > > ? ? ? ? ?logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, > route, params, e.code)) > > does anything like this exist? You can specify a maximum width to truncate the string to, but I don't see any built-in way to add an elision indication (e.g. "..."). >>> "%.4s" % "spam and eggs" 'spam' >>> "{:.4s}".format("spam and eggs") 'spam' You could define something to wrap strings and override __format__() or similar, but that seems like overkill. Cheers, Chris -- http://rebertia.com From no.email at nospam.invalid Tue Aug 23 13:43:35 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Aug 2011 10:43:35 -0700 Subject: try... except with unknown error types References: <7xmxf0h9ti.fsf@ruckus.brouhaha.com> Message-ID: <7x62lo6n20.fsf@ruckus.brouhaha.com> gene heskett writes: > OTOH, ChrisA, I have it on good authority that no program is ever finished, > until someone shoots the programmer. :) The way I heard it was "software is never finished until the last user is dead". From ian.g.kelly at gmail.com Tue Aug 23 14:12:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Aug 2011 12:12:43 -0600 Subject: extended slicing and negative stop value problem In-Reply-To: <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> References: <4e501ba1$0$29970$c3e8da3$5496439d@news.astraweb.com> <7488461a-de1f-4e7c-ba7f-a15d85896e08@y39g2000prd.googlegroups.com> Message-ID: On Aug 21, 2011 1:34 PM, "Max" wrote: > > a[0:11][::-1] > > # Instead of a[10:-1:-1], which looks like it should work, but doesn't. > > It works nicely, but it is 1.3 times slower in my code (I am surprised > the interpreter doesn't optimize this). Have you tried reverse()? I haven't timed it, but since it merely creates an iterator rather than a second copy, you may get better performance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Aug 23 14:19:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 14:19:15 -0400 Subject: is there any principle when writing python function In-Reply-To: References: Message-ID: On 8/23/2011 7:59 AM, smith jack wrote: > i have heard that function invocation in python is expensive, That comes into play when chosing between list2 = map(lambda x: 2*x, list1) # versus list2 = [2*x for x in list1] It also comes into play when choosing between looping with recursion (function calls) versus looping with iteration (while/for). In Python, the iteration is faster, while some functional languages omit looping syntax constructs and perhaps auto-translate some recursion to iteration. > but makelots of functions are a good design habit in many other languages, Same for Python, with the exceptions noted above of avoiding trivial one-use functions when there is an alternative. > is there any principle when writing python function? Same as usual. Functions define new words and create new abstractions than encapsulate a unit of computation. > for example, how many lines should form a function? 1 to many, as long as the 1 is more complex than 2*x, unless the trivial function is required for a callback. I doubt the stdlib has many defs longer than 100 lines. Try the following: complex enough that the function call overhead does not matter; simple enough to be understood as a unit. I just came up with the following hypothesis: the complexity of a function is related to the number of *different* functions used to define it: x = a*b + c/d - e**f is more complex (harder to understand) than x = a + b + c + d + e + f For this purpose, different statememts count as functions (and indeed, they translate to bytecode functions. So: for i in iterable: if f(i): print i is more complex than a = 1 b = 2 c = 3 d = 4 People can retain at most about 10 different things in short term memory. So perhaps 10 different 'functions' within a function, or at least a commented block, is enough. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 23 14:29:38 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 14:29:38 -0400 Subject: is there any principle when writing python function In-Reply-To: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/23/2011 11:22 AM, Steven D'Aprano wrote: > Even 7?2 is probably excessive: I find that I'm most comfortable with > functions that perform 4?1 chunks of work. An example from one of my > classes: > > def find(self, prefix): > """Find the item that matches prefix.""" > prefix = prefix.lower() # Chunk #1 > menu = self._cleaned_menu # Chunk #2 > for i,s in enumerate(menu, 1): # Chunk #3 > if s.lower().startswith(prefix): > return i > return None # Chunk #4 > > So that's three one-line chunks and one three-line chunk. In terms of different functions performed (see my previous post), I see attribute lookup assignment enumerate sequence unpacking for-looping if-conditioning lower startswith return That is 9, which is enough. -- Terry Jan Reedy From adrian.monkas at bqn.com.uy Tue Aug 23 15:00:26 2011 From: adrian.monkas at bqn.com.uy (=?ISO-8859-1?Q?Adri=E1n_Monkas?=) Date: Tue, 23 Aug 2011 16:00:26 -0300 Subject: reading and writing files Message-ID: Hi. I`ve been trying to copy a long text from one file to another but it always copied me just a small part. I would be glad if you can help me or explain which is my error. Thanks ---------------------------------------------------------------------------------- def runMenu(): print "\nMENU" print " 1) Copiar" print " 0) Exit" response = int( raw_input().strip() ) if response == 1: print "Copiar" try: print "Abro Archivo Origen" archivo=open("D:\Boot.txt","r") print "Name of the file: ", archivo.name print "Closed or not : ", archivo.closed print "Opening mode : ", archivo.mode print "--------ORIGEN-----------" print archivo.read() print "-------------------------" archivo.seek(0, 0) print "Abro Archivo Destino" archivo2=open("D:\Copia.txt","w+") print "Name of the file: ", archivo2.name print "Closed or not : ", archivo2.closed print "Opening mode : ", archivo2.mode archivo2.write(archivo.read()) archivo2.seek(0, 0) print "---------DESTINO---------" print archivo2.read() print "-------------------------" archivo.close() archivo2.close() except IOError: print ("I/O Error de Lectura") else: print "Lectura OK" elif response == 0: #device.close() print "Exit" return response def main(): print "main" while(1): if runMenu() == 0: break main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Tue Aug 23 15:52:34 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 23 Aug 2011 12:52:34 -0700 Subject: Windows No-Install Distribution? In-Reply-To: References: Message-ID: <4E540502.2020905@ixokai.io> On 8/23/11 8:29 AM, Eric Lemings wrote: > I would like to create/find a Python 3.x distribution that can be > redeployed simply by copying a directory of required files; i.e. Just take the default installer, install it, and then check the Python directory: does it have the python DLL? If not, go look into the system32 directory, grab it, drop it in the Python directory. (If you installed for all-users this will happen, Now copy/zip/whatever that Python directory to another machine where it was not installed. It'll work fine. You'll have to explicitly provide the path to the Python.exe of course; you can't just double-click on a .py or run 'python blah.py', but if your shortcuts/whatever all do C:\Where\You\Installed\Python.exe, everything should just work. We do that at work and never run into any trouble. (We actually provide a MSI but only for convenience of customers who want to auto-install via Group Policy). In most situations, Python's good at "finding itself", i.e. where the python.exe is actually located -- and it boostraps the location of everything else based on that. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From mzummo at gmail.com Tue Aug 23 15:53:45 2011 From: mzummo at gmail.com (Mathew) Date: Tue, 23 Aug 2011 12:53:45 -0700 (PDT) Subject: Looking for python/pyramid developers for a project Message-ID: <7176109a-b899-41ef-9932-ae7821872ffd@t5g2000yqj.googlegroups.com> Hello, My company an ISP is looking to build an administrative webapp dashboard for our underlying systems. We are looking to hire a developer(s) immediately. We would prefer the application be built on python with a popular framework such as pyramid. This position is a contract position paid hourly (35-45$ based on experience). Please email me if you are interested and attach any relevant past projects/ screenshots that were built on pyramid/python. email: mzummo at [gmail.com] skype " mzummo " From amirouche.boubekki at gmail.com Tue Aug 23 16:13:40 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Tue, 23 Aug 2011 13:13:40 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: <4e52442b$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: <64707632-4eb6-493a-9c19-440df932e61c@d7g2000vbv.googlegroups.com> On Aug 22, 1:57 pm, Steven D'Aprano wrote: > The relationship between type and object is somewhat special, and needs to > be bootstrapped by the CPython virtual machine. Since you are talking about CPython, I'm wondering how it is bootstraped since you can easly reference PyType in PyObject that part is not hard. > > 2) type is its own metaclass : type(type) is type ? > > Yes. Another bit of bootstrapping that the compiler does. self reference is easy same as referencing PyType from PyObject and PyObject from PyType. > > 5) type(any_object) == last_metaclass_..., which is, most of the time, > > type ? > > I'm not sure what you mean by "last_metaclass". But no. The type of an > object is its class: see this code for example proove my point: class meta_a(type): def __new__(cls, *args, **kwargs): return type.__new__(cls, *args, **kwargs) # see (?) class meta_b(meta_a): def __new___(cls, *args, **kwargs): return meta_a.__new__(cls, *args, **kwargs) # same as above class ClassWithTypeMetaA(object): __metaclass__ = meta_a class ClassWithTypeMetaB(object): __metaclass__ = meta_b type(ClassWithTypeMetaA) == meta_a type(ClassWithTypeMetaB) == meta_b [?] super call doesn't work here, anyone can say why ? Regards, Amirouche From rantingrick at gmail.com Tue Aug 23 16:22:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 23 Aug 2011 13:22:46 -0700 (PDT) Subject: is there any principle when writing python function References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 23, 1:29?pm, Terry Reedy wrote: > In terms of different functions performed (see my previous post), I see > ? ?attribute lookup > ? ?assignment > ? ?enumerate > ? ?sequence unpacking > ? ?for-looping > ? ?if-conditioning > ? ?lower > ? ?startswith > ? ?return > That is 9, ?which is enough. attribute lookup -> inspection assignment -> ditto enumerate -> enumeration sequence unpacking -> parallel assignment for-looping -> cycling if-conditioning -> logic lower -> mutation (don't try to argue!) startswith -> boolean-logic return -> exiting (although all exits require an entrance!) omitted: documenting, referencing, -presumptuousness- pedantic-ly yours, rr ;-) From amirouche.boubekki at gmail.com Tue Aug 23 16:47:07 2011 From: amirouche.boubekki at gmail.com (Amirouche B.) Date: Tue, 23 Aug 2011 13:47:07 -0700 (PDT) Subject: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__ References: Message-ID: On Aug 22, 5:41 pm, Stephen Hansen wrote: > > 3) object's type is type : object.__class__ is type > > 4) type parent object is object : type.__bases__ == (object,) > > Saying "type" and "parent" and the like for new-style classes is > something of a misnomer. For "type" and "object", these things aren't > constructed like this. > > What you have here is technically true if you go poke at it in the > interpreter, but it doesn't really /mean/ anything because its not how > these objects came to be and is circular and a bit confusing. These > fundamental objects are created special. The code snippet is here to illustrate how it is visible in the interpreter. But you are right. > > 2) type is its own metaclass : type(type) is type ? > > Only in a purely theoretical way. It doesn't actually mean anything; > moreover, type(something) is NOT how you determine somethings metaclass. > Its how you determine somethings type. see the answer to Steven D'Aprano. type(class_object) == a_meta_class_object > The two concepts may be very distinct. Lots of things don't have > metaclasses. All object in new style class have a metaclass at least type. > > 3) object's metaclass is type ? > > Again, only theoretically. and again the famous "bootstrapping" make it like type created object. >From the outside world of the Python implementation object looks like a type instance. > > 5) type(any_object) == last_metaclass_..., which is, most of the time, > > type ? > > Not necessarily at all. In fact, there is no way I'm aware of to > determine if a metaclass was involved in a classes construction unless > said metaclass wants to provide such a mechanism. > > Metaclasses are kind of a hack. They are a way to hook into the class > construction that's normally done and do something, anything you want, > (even hijack the whole procedure and NOT construct a class at all, but > play a song if you want) before its all finished. > > For example, this is a metaclass I've used: > > PageTypes = {} > > class _PageRegistration(type): > def __new__(cls, name, bases, dct): > klass = type.__new__(cls, name, bases, dct) > typename = name[:-9].lower() > if not typename: > typename = None > > PageTypes[typename] = klass > klass.Type = typename > > return klass > > class QueuePage(sc.SizedPanel): > __metaclass__ = _PageRegistration > > Note, the fact that my _PageRegistration metaclass inherits is itself a > class which inherits from type is just one convenient way to write > metaclasses. It could as simply have been just a function. > > Metaclasses are somewhat poorly named in that they are really, "creation > hooks". It the same issue in django, views are only function, until you need complex behavior and you want a "namespace" to put everything in it. IMO that's why class based views exists for complex cases. That said being able to declare a metaclass only as a functions is neat. > > C) type vs class > > ---------------- > > > 1) Type is the metaclass of most classes > > Yes and no. Yes, in that most classes are created using the default > mechanism inside CPython. The class body is executed in a scope, the > resulting dictionary is bound to a new class object, bases and the like > are set, and such. > > No in that it really just, IIUC, skips the whole "metaclass" part of the > process because this 'default mechanism' doesn't need to call out into > other code to do its job. At least, I think-- May be wrong here, > metaclasses are something of a dark voodoo and I'm not 100% entirely > familiar with the internal workings of CPython. > > But functionally, a metaclass is the chunk of code responsible for the > actual physical construction of the class object. For me it takes some variables, namely ``bases``, ``class_dict`` and ``configuration class_name`` and do something with it, probably creating a class_object which behaviour is parametred with the context. I did not know Python before new-style class, so probably for most people explainning that metaclasses are a creation hook is easier for them... > > 4) It's in type.__call__ that happens calls to __new__ and __init__ > > Again, "translates to" is suggesting "this is what happens when you do > X", which I don't know if is strictly true. CPython inside may be > optimizing this whole process. > Especially when it comes to "magic > methods", __x__ and the like -- CPython rarely uses __get*_ for those. > It just calls the methods directly on the class object. IIUC the code of Jython tells me what I've written. If the first part of the algorithm is "lookup for special methods" (what you seem to say) then we both agree that we agree, isn't it ? Moreover I'm not looking in this part to understand how CPython works internally, but how Python works. Since I'm most proeffencient in Python I translate it to Python. *Translates* means "it's a shortcut for". > > 5) 3) => classes are instance of type > > > 6) Since type.__call__ is used to instantiate instance of instance of > > type > > (rephrased: __call__ is used to instantiate classes) where is the > > code which > > is executed when we write ``type(myobject)`` or ``type('MyClass', > > bases, attributes)`` > > __getattribute__ resolution algorithm (see E) tells me that it > > should be type.__call__ > > but type.__call__ is already used to class instatiation. > > Python callables can have more then one argument, and more then one > behavior, and can choose to do more then one thing based on the number > of arguments. > > They don't have overloading, but they can do it themselves. > > You've already proven that, and you already know that -- you're sorta > over-complicating this :) > You said: > > MyClass = type('MyClass', (object,), {'attribute': 1, 'method': def > method: pass }) > > Type.__call__ does both. Actually I missed that :/ > > D) builtin types > > ---------------- > > > 1) builtin types are their own metaclass ? > > Builtin types are constructed by the interpreter, and may or may not > involve themselves with the class/type hierarchy. Even when they do, > they may only do so partially. That's the part I don't understand. How can they possibly work differently. They surrely make their bussiness in the infrastructure/algorithm already in place in type and object to but I cant spot the right piece of code that will explain it. > > 2) why function builtin type can not be subclassed ? > > Because functions are not classes. They're discrete things of their own. > That a function object has a __class__ attribute is an example of a > builtin partially involving itself in the class/type hierarchy, largely > just for introspection purposes-- since functions are first-class > citizens, you need to be able to pass it around and test to determine > what one thing or another actually is. > > Now, functions ARE indeed PyObjects, the internal CPython representation > of an object, of which all things are. But that's not really the same > thing as ultimately inheriting from and involving itself in "object" and > types/classes. Coming with general idea about what are builtin type would make it easier to understand function objects. What I can tell is that function objects behave like the instances of a class, and the class takes (at least) runnable code as arguments. > > E) __getattribute__ > > ------------------- > > > 1) ``my_object.attribute`` always translates to > > ``my_object.__getattribute__('attribute')`` > > No. __getattribute__ is a mechanism to hook into the attribute fetching > mechanism. (As is __getattr__). It is NOT always invoked. > > Especially in the case of __*__ attributes, which by and large bypass > such hooks, as the CPython internals is calling those functions directly > on the class instances themselves. see my answer in the other response From usenet-nospam at seebs.net Tue Aug 23 16:52:55 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 20:52:55 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Roy Smith wrote: > I want to log a string but only the first bunch of it, and add "..." > to the end if it got truncated. This certainly works: > logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, > route, params, e.code)) > does anything like this exist? %.50s -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From eric.lemings at gmail.com Tue Aug 23 17:56:21 2011 From: eric.lemings at gmail.com (Eric Lemings) Date: Tue, 23 Aug 2011 14:56:21 -0700 (PDT) Subject: Windows No-Install Distribution? References: Message-ID: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> On Aug 23, 1:52?pm, Stephen Hansen wrote: > On 8/23/11 8:29 AM, Eric Lemings wrote: > > > I would like to create/find a Python 3.x distribution that can be > > redeployed simply by copying a directory of required files; i.e. > > Just take the default installer, install it, and then check the Python > directory: does it have the python DLL? If not, go look into the > system32 directory, grab it, drop it in the Python directory. (If you > installed for all-users this will happen, > > Now copy/zip/whatever that Python directory to another machine where it > was not installed. It'll work fine. > > You'll have to explicitly provide the path to the Python.exe of course; > you can't just double-click on a .py or run 'python blah.py', but if > your shortcuts/whatever all do C:\Where\You\Installed\Python.exe, > everything should just work. > > We do that at work and never run into any trouble. (We actually provide > a MSI but only for convenience of customers who want to auto-install via > Group Policy). > > In most situations, Python's good at "finding itself", i.e. where the > python.exe is actually located -- and it boostraps the location of > everything else based on that. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload Excellent start. Which files comprise the standard Python library? Only the files in the 'Lib' subdirectory or are more needed? From usenet-nospam at seebs.net Tue Aug 23 18:00:05 2011 From: usenet-nospam at seebs.net (Seebs) Date: 23 Aug 2011 22:00:05 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Ethan Furman wrote: > Seebs wrote: >> On 2011-08-23, Roy Smith wrote: >>> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >>> route, params, e.code)) >>> does anything like this exist? >> %.50s > That's not working in 2.7 or 3.2. Huh. Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print "%.5s" % ("hello there, truncate me!") hello -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ethan at stoneleaf.us Tue Aug 23 18:02:30 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Aug 2011 15:02:30 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: <4E542376.5020408@stoneleaf.us> Seebs wrote: > On 2011-08-23, Roy Smith wrote: >> I want to log a string but only the first bunch of it, and add "..." >> to the end if it got truncated. This certainly works: > >> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >> route, params, e.code)) > >> does anything like this exist? > > %.50s That's not working in 2.7 or 3.2. ~Ethan~ From bumbker at yahoo.com Tue Aug 23 18:09:42 2011 From: bumbker at yahoo.com (Ronald Reynolds) Date: Tue, 23 Aug 2011 15:09:42 -0700 (PDT) Subject: upgrade python Message-ID: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> What is recommended for upgrading python for windows? Do I just install the new versionDo I edit my system path? Should I uninstall the old version. ?Right now I have 2.7 and3.1 ?and 3.2 ?and I keep editing my system path when I install a new version but I'm notsure that's the right way to go. ?Is there an upgrade way? I only found downloads at Python.org ?thx ? ? 'Ron "bumpker" Reynolds'? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Aug 23 19:05:30 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Aug 2011 09:05:30 +1000 Subject: Looking for python/pyramid developers for a project References: <7176109a-b899-41ef-9932-ae7821872ffd@t5g2000yqj.googlegroups.com> Message-ID: <878vqjwwxx.fsf@benfinney.id.au> Mathew writes: > We are looking to hire a developer(s) immediately. Please don't use this Python discussion for recruitment. Instead, please use the Python Jobs Board for that purpose . -- \ ?It's a good thing we have gravity or else when birds died | `\ they'd just stay right up there. Hunters would be all | _o__) confused.? ?Steven Wright | Ben Finney From tjreedy at udel.edu Tue Aug 23 19:18:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 19:18:50 -0400 Subject: upgrade python In-Reply-To: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> References: <1314137382.45507.YahooMailClassic@web120116.mail.ne1.yahoo.com> Message-ID: On 8/23/2011 6:09 PM, Ronald Reynolds wrote: > What is recommended for upgrading python for windows? Do I just install > the new version I put each version in its own Pythonxy directory, as the installer wants. x.y.z bug fix releases replace the previous x.y release. > Do I edit my system path? However, I put all versions in my own 'Programs' directory (not at top-level, not in Program Files. On my old machine, I added that one directory to PATH. Then I copied Pythonxy/python to pyxy in that directory. I will do the same on my new machine when I have need. But I mostly execute from an IDLE editor window, so PATH and command prompts are mostly irrelevant for me. > Should I uninstall the old version. If and only if you are sure you have no further use for it. -- Terry Jan Reedy From tjreedy at udel.edu Tue Aug 23 19:28:47 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Aug 2011 19:28:47 -0400 Subject: Windows No-Install Distribution? In-Reply-To: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> References: <5204a1ee-70f5-4eec-9693-d915366b6fe4@d7g2000vbv.googlegroups.com> Message-ID: On 8/23/2011 5:56 PM, Eric Lemings wrote: > On Aug 23, 1:52 pm, Stephen Hansen wrote: >> On 8/23/11 8:29 AM, Eric Lemings wrote: >> >>> I would like to create/find a Python 3.x distribution that can be >>> redeployed simply by copying a directory of required files; i.e. >> >> Just take the default installer, install it, except do a custom install and leave out what you do not want. (Tools? tcl/tk/idle?). You can leave out tests, but then you might want that, at least once, to test your no-install copy. >> and then check the Python >> directory: does it have the python DLL? If not, go look into the >> system32 directory, grab it, drop it in the Python directory. (If you >> installed for all-users this will happen, For Python3, python3.dll in in Python3y\DLLs even for all users install. I believe this is per MS recommendation. So just copy the entire python3y directory. > Which files comprise the standard Python library? Only the files in > the 'Lib' subdirectory That only has Python-coded modules. > or are more needed? C-coded modules are in /DLLs. I presume /libs is needed too but I do not really know, and I will not experiment. Just limit your install to what you want and copy everything. -- Terry Jan Reedy From ethan at stoneleaf.us Tue Aug 23 19:44:29 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Aug 2011 16:44:29 -0700 Subject: truncating strings In-Reply-To: References: Message-ID: <4E543B5D.1090602@stoneleaf.us> Seebs wrote: > On 2011-08-23, Ethan Furman wrote: >> Seebs wrote: >>> On 2011-08-23, Roy Smith wrote: >>>> logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, >>>> route, params, e.code)) > >>>> does anything like this exist? > >>> %.50s > >> That's not working in 2.7 or 3.2. > > Huh. > > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> print "%.5s" % ("hello there, truncate me!") > hello Ah -- that's only part of it -- the OP wants '...' to print as well. :) ~Ethan~ From steve+comp.lang.python at pearwood.info Tue Aug 23 21:24:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 11:24:14 +1000 Subject: truncating strings References: Message-ID: <4e5452be$0$29984$c3e8da3$5496439d@news.astraweb.com> Seebs wrote: > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> print "%.5s" % ("hello there, truncate me!") > hello Well, whadda you know, I learned something new :) In any case, this doesn't solve the OP's problem, as he wants to truncate the input string, and append '...' if and only if it were truncated. The right solution is to wrap the functionality in a function. It's not hard, and is elegant. Not everything needs to be a built-in. # Untested. def truncate(s, maxwidth=50): if len(s) <= maxwidth: return s s = s[:maxwidth - 3] return s + '...' -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 23 21:44:14 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 11:44:14 +1000 Subject: is there any principle when writing python function References: <4e53c5ab$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e54576e$0$29980$c3e8da3$5496439d@news.astraweb.com> Terry Reedy wrote: > On 8/23/2011 11:22 AM, Steven D'Aprano wrote: > >> Even 7?2 is probably excessive: I find that I'm most comfortable with >> functions that perform 4?1 chunks of work. An example from one of my >> classes: >> >> def find(self, prefix): >> """Find the item that matches prefix.""" >> prefix = prefix.lower() # Chunk #1 >> menu = self._cleaned_menu # Chunk #2 >> for i,s in enumerate(menu, 1): # Chunk #3 >> if s.lower().startswith(prefix): >> return i >> return None # Chunk #4 >> >> So that's three one-line chunks and one three-line chunk. > > In terms of different functions performed (see my previous post), I see > attribute lookup > assignment > enumerate > sequence unpacking > for-looping > if-conditioning > lower > startswith > return > That is 9, which is enough. I think we have broad agreement, but we're counting different things. Analogy: you're counting atoms, I'm grouping atoms into molecules and counting them. It's a little like phone numbers: it's not an accident that we normally group phone numbers into groups of 2-4 digits: 011 23 4567 8901 In general, people can more easily memorise four chunks of four digits (give or take) than one chunk of 13 digits: 0112345678901. -- Steven From user at example.net Tue Aug 23 22:46:11 2011 From: user at example.net (User) Date: Tue, 23 Aug 2011 22:46:11 -0400 Subject: Learning Python Message-ID: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Hello all, Does anyone have any good resources for learning Python? I know basic Java and basic Python (loops, data types, if-then statements, etc), but I want to delve into Python further. If anyone knows of any good books, video tutorials, etc it would be greatly appreciated. Thanks, User From Johnny.Venter at zoho.com Tue Aug 23 22:55:12 2011 From: Johnny.Venter at zoho.com (Johnny Venter) Date: Tue, 23 Aug 2011 22:55:12 -0400 Subject: Learning Python In-Reply-To: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <9A6239EC-9CDE-4D28-9C87-22AF4905AF32@zoho.com> http://greenteapress.com/thinkpython/ On Aug 23, 2011, at 10:46 PM, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic Java and basic Python (loops, data types, if-then statements, etc), but I want to delve into Python further. If anyone knows of any good books, video tutorials, etc it would be greatly appreciated. > Thanks, > User > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Aug 23 23:05:18 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Aug 2011 20:05:18 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: <47c4c2ac-a6ea-4575-ba4f-473ca8ba4c6e@x21g2000prd.googlegroups.com> rantingrick wrote: > Everyone here who is suggesting that function bodies should be > confined to ANY length is an idiot. Or, more likely, is the sort of coder who has worked with other coders in the past and understands the value of readable code. > Don't worry if it too small or too big. It's > not the size that matters, it's the motion of the sources ocean! If only you spent as much time actually thinking about what you're saying as trying to find 'clever' ways to say it... > Always use > comments to clarify code and NEVER EVER create more functions only for > the sake of short function bodies This is quite likely the worst advice you've ever given. I can only assume you've never had to refactor the sort of code you're advocating here. From wuwei23 at gmail.com Tue Aug 23 23:08:44 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Aug 2011 20:08:44 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: rantingrick wrote: > https://sites.google.com/site/thefutureofpython/ "Very soon I will be hashing out a specification for python 4000." AHAHAHAHAhahahahahahahAHAHAHAHahahahahaaaaaaa. So rich. Anyone willing to bet serious money we won't see this before 4000AD? "Heck even our leader seems as a captain too drunk with vanity to care; and our members like a ship lost at sea left to sport of every troll-ish wind!" Quite frankly, you're a condescending, arrogant blow-hard that this community would be better off without. "We must constantly strive to remove multiplicity from our systems; lest it consumes us!" s/multiplicity/rantingrick/ and I'm in full agreement. From davea at ieee.org Wed Aug 24 00:05:40 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Aug 2011 00:05:40 -0400 Subject: reading and writing files In-Reply-To: References: Message-ID: <4E547894.2020308@ieee.org> On 01/-10/-28163 02:59 PM, Adri?n Monkas wrote: > Hi. > I`ve been trying to copy a long text from one file to another but it always > copied me just a small part. > I would be glad if you can help me or explain which is my error. > Thanks > > ---------------------------------------------------------------------------------- > def runMenu(): > > print "\nMENU" > print " 1) Copiar" > print " 0) Exit" > > response = int( raw_input().strip() ) > > if response == 1: > print "Copiar" > try: > print "Abro Archivo Origen" > archivo=open("D:\Boot.txt","r") > print "Name of the file: ", archivo.name > print "Closed or not : ", archivo.closed > print "Opening mode : ", archivo.mode > > print "--------ORIGEN-----------" > print archivo.read() > print "-------------------------" > archivo.seek(0, 0) > > print "Abro Archivo Destino" > archivo2=open("D:\Copia.txt","w+") > print "Name of the file: ", archivo2.name > print "Closed or not : ", archivo2.closed > print "Opening mode : ", archivo2.mode > > > > archivo2.write(archivo.read()) > > archivo2.seek(0, 0) > print "---------DESTINO---------" > print archivo2.read() > print "-------------------------" > archivo.close() > archivo2.close() > > except IOError: > print ("I/O Error de Lectura") > else: > print "Lectura OK" > > elif response == 0: > #device.close() > print "Exit" > > return response > > def main(): > print "main" > while(1): > if runMenu() == 0: break > > main() > What's your goal? If it's to write a small program to copy a file, try using shutil library. It'll save you lots of trouble. It can handle files that are bigger than available memory, it can fix up timestamps, etc. If it's to learn Python, then you need to learn about writing debuggable code. Part of that is doing things once. So if you read() the entire contents of the file, keep it in a variable and use that variable to write() to the other file, and also to print to the screen. Then if something's wrong, you can be sure it's the same both places. Never do something like y.write(x.read()) till you're sure everything's working. That's a kind of optimization which doesn't save any execution time, and only a few keystrokes. And you'll waste those keystrokes changing the code a dozen times to find out why it isn't working. You don't make clear just what is "just a small part." In other words, what is truncated? Is it the ORIGEN printout, the DESTINO printout, or the actual file contents ? And is the file involved a gigabyte or two, or is it 500 bytes? Did it display part of the file correctly, or by "small part" did you mean zero bytes? Show the actual stack trace if you got an error, or the program output if not. And in general, when you're asking questions, please specify the Python version and OS version you're running. Clearly, the latter is some kind of Windows, since you're using the D: drive. And the Python version is 2.x for some value of x. But sometimes it'll matter. Your filenames are incorrect, since you use the backslash without escaping it. So the source file has a backspace in it. I'm amazed you don't get an error, since it's unlikely you have a file with that kind of name. When I run it, I get "Abro Archivo Origen". I'm astounded you don't. When making a literal string out of a Windows filename, either double the backslashes, or use R"xxx" for raw strings, or just use forward slashes. HTH. DaveA From steve+comp.lang.python at pearwood.info Wed Aug 24 00:10:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 24 Aug 2011 14:10:49 +1000 Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <4e5479ca$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Aug 2011 12:46 pm User wrote: > Hello all, > Does anyone have any good resources for learning Python? http://duckduckgo.com/?q=python+tutorial -- Steven From larry at hastings.org Wed Aug 24 00:15:07 2011 From: larry at hastings.org (Larry Hastings) Date: Tue, 23 Aug 2011 21:15:07 -0700 Subject: Announcing a new podcast: Radio Free Python Message-ID: <4E547ACB.4040301@hastings.org> Radio Free Python is a new monthly podcast focused on Python and its community. Episode 1 has just been released! It features a panel discussion with the PythonLabs team: * Barry Warsaw, * Fred Drake, * Guido van Rossum, * Roger Masse, * and Tim Peters. You can find it at http://www.radiofreepython.com/ as of this very minute. Enjoy! /larry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Wed Aug 24 00:21:18 2011 From: usenet-nospam at seebs.net (Seebs) Date: 24 Aug 2011 04:21:18 GMT Subject: truncating strings References: Message-ID: On 2011-08-23, Ethan Furman wrote: > Ah -- that's only part of it -- the OP wants '...' to print as well. :) Ohhhh. Hmm. That's harder. I can't think of a pretty way, so I think I'd probably write a "prettytrunc(string, len)" or something similar. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From clp2 at rebertia.com Wed Aug 24 00:43:41 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 21:43:41 -0700 Subject: reading and writing files In-Reply-To: <4E547894.2020308@ieee.org> References: <4E547894.2020308@ieee.org> Message-ID: On Tue, Aug 23, 2011 at 9:05 PM, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Adri?n Monkas wrote: >> ? ? ? ? ? ? print "Abro Archivo Origen" >> ? ? ? ? ? ? archivo=open("D:\Boot.txt","r") > Your filenames are incorrect, since you use the backslash without escaping > it. ?So the source file has a backspace in it. ?I'm amazed you don't get an > error, since it's unlikely you have a file with that kind of name. Backslash escape sequences only work for lowercase characters: >>> '\b' '\x08' >>> '\B' '\\B' But yeah, I don't endorse relying on this. Just use forward slashes instead of backslashes in paths; Windows accepts them just fine. Cheers, Chris -- http://rebertia.com From saraanderson24 at gmail.com Wed Aug 24 01:11:55 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Tue, 23 Aug 2011 22:11:55 -0700 (PDT) Subject: WATCH WORLD`S MOST BEAUTIFUL CITYSCAPE PLACES EVER. Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S MOST HILARIOUS FUNNIEST VIDEOS. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From muresanalex.contact at gmail.com Wed Aug 24 02:29:41 2011 From: muresanalex.contact at gmail.com (Muresan Alexandru Mihai) Date: Wed, 24 Aug 2011 09:29:41 +0300 Subject: reading and writing files In-Reply-To: References: Message-ID: If you need an int isn't better to use input() instead of raw_input() ? On Tue, Aug 23, 2011 at 10:00 PM, Adri?n Monkas wrote: > Hi. > I`ve been trying to copy a long text from one file to another but it always > copied me just a small part. > I would be glad if you can help me or explain which is my error. > Thanks > > > ---------------------------------------------------------------------------------- > def runMenu(): > > print "\nMENU" > print " 1) Copiar" > print " 0) Exit" > > response = int( raw_input().strip() ) > > if response == 1: > print "Copiar" > try: > print "Abro Archivo Origen" > archivo=open("D:\Boot.txt","r") > print "Name of the file: ", archivo.name > print "Closed or not : ", archivo.closed > print "Opening mode : ", archivo.mode > > print "--------ORIGEN-----------" > print archivo.read() > print "-------------------------" > archivo.seek(0, 0) > > print "Abro Archivo Destino" > archivo2=open("D:\Copia.txt","w+") > print "Name of the file: ", archivo2.name > print "Closed or not : ", archivo2.closed > print "Opening mode : ", archivo2.mode > > > > archivo2.write(archivo.read()) > > archivo2.seek(0, 0) > print "---------DESTINO---------" > print archivo2.read() > print "-------------------------" > archivo.close() > archivo2.close() > > except IOError: > print ("I/O Error de Lectura") > else: > print "Lectura OK" > > elif response == 0: > #device.close() > print "Exit" > > return response > > def main(): > print "main" > while(1): > if runMenu() == 0: break > > main() > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Muresan Alexandru Web Developer 0740782921 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Aug 24 02:38:12 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Aug 2011 23:38:12 -0700 Subject: reading and writing files In-Reply-To: References: Message-ID: On Tue, Aug 23, 2011 at 11:29 PM, Muresan Alexandru Mihai wrote: > If you need an int isn't better to use input() instead of raw_input() ? Absolutely not! input() does an eval(), which is very dangerous security-wise and can also lead to rather strange behavior. input() is so bad that it was removed in Python 3 (confusingly, raw_input() was also simultaneously renamed to input(); the point is, there's no longer an equivalent built-in function). Cheers, Chris From bex.lewis at gmail.com Wed Aug 24 04:53:19 2011 From: bex.lewis at gmail.com (becky_lewis) Date: Wed, 24 Aug 2011 01:53:19 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: http://diveintopython.org/ is where you can get an online version of the dive into python book. I found it useful when learning python :) Becky Lewis On Aug 24, 3:46?am, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic > Java and basic Python (loops, data types, if-then statements, etc), but > I want to delve into Python further. If anyone knows of any good books, > video tutorials, etc it would be greatly appreciated. > Thanks, > User From muresanalex.contact at gmail.com Wed Aug 24 05:51:46 2011 From: muresanalex.contact at gmail.com (Muresan Alexandru Mihai) Date: Wed, 24 Aug 2011 12:51:46 +0300 Subject: Learning Python In-Reply-To: References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: http://www.youtube.com/watch?v=tKTZoB2Vjuk On Wed, Aug 24, 2011 at 11:53 AM, becky_lewis wrote: > http://diveintopython.org/ is where you can get an online version of > the dive into python book. I found it useful when learning python :) > > Becky Lewis > > On Aug 24, 3:46 am, User wrote: > > Hello all, > > Does anyone have any good resources for learning Python? I know basic > > Java and basic Python (loops, data types, if-then statements, etc), but > > I want to delve into Python further. If anyone knows of any good books, > > video tutorials, etc it would be greatly appreciated. > > Thanks, > > User > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Alexandru Muresan Web Developer -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Aug 24 06:04:45 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Aug 2011 07:04:45 -0300 Subject: Execute a method in a file in an egg References: Message-ID: En Tue, 23 Aug 2011 13:14:06 -0300, RVince escribi?: > Is there a way to do this from the command line? Thanks. Something like this? python -c "import the.module;the.module.someclass().method(arguments)" -- Gabriel Genellina From research at johnohagan.com Wed Aug 24 07:01:55 2011 From: research at johnohagan.com (John O'Hagan) Date: Wed, 24 Aug 2011 21:01:55 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: References: <20110822150445.d351f4761ac00559079f7edc@johnohagan.com> <20110823002009.5be9524e66d87949af45ede3@johnohagan.com> Message-ID: <20110824210155.fd069643aa9a4e66de3c6a9f@johnohagan.com> On Mon, 22 Aug 2011 20:38:30 +0200 Peter Otten <__peter__ at web.de> wrote: > John O'Hagan wrote: > > > On Mon, 22 Aug 2011 11:32:18 +0200 > > Peter Otten <__peter__ at web.de> wrote: > > > >> John O'Hagan wrote: > >> > >> > I have a class like this: > >> > > >> > class MySeq(): > >> > def __init__(self, *seq, c=12): > >> > self.__c = c > >> > self.__pc = sorted(set([i % __c for i in seq])) > >> > self.order = ([[self.__pc.index(i % __c), i // __c] for i in > >> > seq]) > >> > #other calculated attributes > >> > > >> > @property > >> > def pitches(self): > >> > return [self.__pc[i[0]] + i[1] * self.__c for i in self.order] > >> > > >> > #other methods > >> > >> That makes me dizzy. Are there any maxims in the Zen of Python that this > >> piece doesn't violate? > > > > "Now is better than never"? > > > > I know it looks crazy to take something apart and put it back together, as > > in this *simplified* *example* > > emphasis mine ;) > > > , but it does have a meaningful use: reducing a > > series of musical notes to a unique irreducible form "__pc", ("prime form" > > in pitch-class set theory), but keeping track of the actual current > > manifestation of that form via the writeable "order" attribute. That's why > > "pitches" must be called with each reference, because it may change, > > unlike "__pc", which can only change if the instance is reinitialised. > > > > I am open to more elegant suggestions, of course. :) > > [...] > > Dunno. Maybe you could inherit from collections.(Mutable)Sequence and > somewhat reduce the number of methods you'd have to implement. > Or you introduce a Pitch (Python) class that knows about its pitch class, > and put that into a normal list: > > >>> class Pitch(int): > ... @property > ... def pitch_class(self): > ... return self % 12 > ... def __repr__(self): > ... return "Pitch(%s, pitch_class=%s)" % (self, > self.pitch_class) > ... > >>> map(Pitch, [1,0,42]) > [Pitch(1, pitch_class=1), Pitch(0, pitch_class=0), Pitch(42, pitch_class=6)] > That's a good starting point for a neater solution, but there's more I have to solve. For completeness, here's the un-simplified __init__ of the class (yes, it gets worse!): class MySeq(): def __init__(self, *sequence, octave=12): pcset = sorted(set([i % octave for i in sequence])) steps = ([pcset[i] - pcset[i - 1] for i in range(1, len(pcset))] + [octave - pcset[-1]]) rotations = [steps[n:] + steps[:n] for n in range(len(steps))] prime_steps = min([i for i in rotations if i[-1] == max(steps)]) self.__prime = [0] for step in prime_steps: self.__prime.append(step + prime[-1]) self.__offset = pcset[rotations.index(prime_steps)] self.__order = Order([[prime.index((i - offset) % octave), (i - self.__offset) // octave] for i in sequence]) self.__octave = octave The __prime attribute is the one all the internal methods refer to, and it's not so much a collection of pitch classes as an interval structure. Accordingly, I'll follow your tip and look into the collections ABCs, many of which look applicable, and go back to the drawing board. Thanks, John From research at johnohagan.com Wed Aug 24 07:09:28 2011 From: research at johnohagan.com (John O'Hagan) Date: Wed, 24 Aug 2011 21:09:28 +1000 Subject: Adding modified methods from another class without subclassing In-Reply-To: <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e51e8c9$0$29981$c3e8da3$5496439d@news.astraweb.com> <4e5355e2$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110824210928.8a79a37a577f395780aa1f75@johnohagan.com> On Tue, 23 Aug 2011 17:25:22 +1000 Steven D'Aprano wrote: > On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote: > > > On Mon, 22 Aug 2011 15:27:36 +1000 > > Steven D'Aprano wrote: > [...] > >> # Untested > >> class MySeq(object): > >> methods_to_delegate = ('__getitem__', '__len__', ...) > >> pitches = ... # make sure pitches is defined > >> def __getattr__(self, name): > >> if name in self.__class__.methods_to_delegate: > >> return getattr(self.pitches, name) > >> return super(MySeq, object).__getattr__(self, name) > >> # will likely raise AttributeError > > [...] > > > Also, it doesn't immediately suggest to me a way of modifying method calls > > (maybe __setattr__?). > > What do you mean, "modifying method calls"? That was a rather badly-worded reference to a function in my original post which modified the action of list methods in ways specific to the new class. As I said, I re-read the docs on __getattr__, and now __setattr__, and I get what they do now. Thanks for your pointers, I'll get back to work. Regards, John From adam.jorgensen.za at gmail.com Wed Aug 24 08:21:18 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 24 Aug 2011 14:21:18 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... Message-ID: Hi all, I'm experiencing a weird issue with closuring of parameters and some nested functions I have inside two functions that return decorators. I think it's best illustrated with the actual code: # This decorator doesn't work. For some reason python refuses to closure the *decode_args parameter into the scope of the nested decorate and decorate_with_rest_wrapper functions # Renaming *decode_args has no effect def rest_wrapper(*decode_args, **deco_kwargs): def decorate(func): argspec = getfullargspec(func) decode_args = [argspec.args.index(decode_arg) for decode_arg in decode_args] def decorate_with_rest_wrapper(func, *args, **kwargs): if decode_args: args = list(args) for index in decode_args: args[index] = json.loads(args[index], cls=deco_kwargs.get('json_decoder')) return Response.ResponseString(json.dumps(func(*args, **kwargs), cls=deco_kwargs.get('json_encoder'))) return decorator(decorate_with_rest_wrapper, func) return decorate # If I modify rest_wrapper slightly and use the parameters from rest_wrapper as default value args for decorate it works. Why? def rest_wrapper(*decode_args, **deco_kwargs): def decorate(func, decode_args=decode_args, deco_kwargs=deco_kwargs): argspec = getfullargspec(func) decode_args = [argspec.args.index(decode_arg) for decode_arg in decode_args] def decorate_with_rest_wrapper(func, *args, **kwargs): if decode_args: args = list(args) for index in decode_args: args[index] = json.loads(args[index], cls=deco_kwargs.get('json_decoder')) return Response.ResponseString(json.dumps(func(*args, **kwargs), cls=deco_kwargs.get('json_encoder'))) return decorator(decorate_with_rest_wrapper, func) return decorate # Similarly, this decorator doesn't work. For some reason python refuses to closure the sa_session_class_lambda parameter into the scope of the nested decorate and decorate_with_sqlalchemy functions # Renaming the sa_session_class_lambda parameter does not work and neither does changing the order of the args list. def with_sqlalchemy(sa_session_parameter_name='sa_session', sa_session_class_lambda=None): def decorate(func): argspec = getfullargspec(func) sa_session_parameter_index = argspec.args.index(sa_session_parameter_name) if sa_session_class_lambda is None: if argspec.args[0] == 'self': sa_session_class_lambda = lambda obj, *args, **kwargs: obj.get_sa_session_class() else: sa_session_class_lambda = lambda *args, **kwargs: Alchemy.get_sa_session_class() def decorate_with_alchemy(func, *args, **kwargs): if args[sa_session_parameter_index]: raise Exception('%s parameter is not empty!' % sa_session_parameter_name) try: sa_session_class = sa_session_class_lambda(*args, **kwargs) sa_session = sa_session_class() args = list(args) args[sa_session_parameter_index] = sa_session retval = func(*args, **kwargs) sa_session.commit() return retval except Exception, e: sa_session.rollback() raise e finally: sa_session.close() return decorator(decorate_with_alchemy, func) return decorate # Again, if I modify decorate and use the parameters from with_sqlalchemy as default value args in decorate it works fine. What gives? def with_sqlalchemy(sa_session_parameter_name='sa_session', sa_session_class_lambda=None): def decorate(func, sa_session_parameter_name=sa_session_parameter_name, sa_session_class_lambda=sa_session_class_lambda): argspec = getfullargspec(func) sa_session_parameter_index = argspec.args.index(sa_session_parameter_name) if sa_session_class_lambda is None: if argspec.args[0] == 'self': sa_session_class_lambda = lambda obj, *args, **kwargs: obj.get_sa_session_class() else: sa_session_class_lambda = lambda *args, **kwargs: Alchemy.get_sa_session_class() def decorate_with_alchemy(func, *args, **kwargs): if args[sa_session_parameter_index]: raise Exception('%s parameter is not empty!' % sa_session_parameter_name) try: sa_session_class = sa_session_class_lambda(*args, **kwargs) sa_session = sa_session_class() args = list(args) args[sa_session_parameter_index] = sa_session retval = func(*args, **kwargs) sa_session.commit() return retval except Exception, e: sa_session.rollback() raise e finally: sa_session.close() return decorator(decorate_with_alchemy, func) return decorate Does anyone have any idea why the problem parameters are not being captured? When I try to run the code using the broken versions of the two decorators python fails claiming that the problem variables are being referenced before they are defined... What's more interesting is that PyCharm seems to know this is going to happen as well because the code insight marks the problem versions as having unused parameters (Specifically, the *decode_args and sa_session_class_lambda parameters). Does anyone know why this is happening and if there is a nicer fix than the one illustrated above? Thanks Adam From sdouche at gmail.com Wed Aug 24 08:22:12 2011 From: sdouche at gmail.com (Sebastien Douche) Date: Wed, 24 Aug 2011 14:22:12 +0200 Subject: Execute a method in a file in an egg In-Reply-To: References: Message-ID: On Wed, Aug 24, 2011 at 12:04, Gabriel Genellina wrote: >> Is there a way to do this from the command line? Thanks. > > Something like this? > > python -c "import the.module;the.module.someclass().method(arguments)" Or with console_scripts option in setup.py. -- Sebastien Douche Twitter : @sdouche From __peter__ at web.de Wed Aug 24 09:29:58 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Aug 2011 15:29:58 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... References: Message-ID: Adam Jorgensen wrote: > Hi all, I'm experiencing a weird issue with closuring of parameters > and some nested functions I have inside two functions that > return decorators. I think it's best illustrated with the actual code: You should have made an effort to reduce its size > # This decorator doesn't work. For some reason python refuses to > closure the *decode_args parameter into the scope of the nested > decorate and decorate_with_rest_wrapper functions > # Renaming *decode_args has no effect > def rest_wrapper(*decode_args, **deco_kwargs): > def decorate(func): > argspec = getfullargspec(func) > decode_args = [argspec.args.index(decode_arg) for decode_arg > in decode_args] I didn't read the whole thing, but: >>> def f(a): ... def g(): ... a = a + 42 ... return a ... return g ... >>> f(1)() Traceback (most recent call last): File "", line 1, in File "", line 3, in g UnboundLocalError: local variable 'a' referenced before assignment Python treats variables as local if you assign a value to them anywhere in the function. The fix is easy, just use another name: >>> def f(a): ... def g(): ... b = a + 42 ... return b ... return g ... >>> f(1)() 43 In Python 3 you can also use the nonlocal statement. From python.list at tim.thechases.com Wed Aug 24 09:41:17 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 24 Aug 2011 08:41:17 -0500 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: <4E54FF7D.7000602@tim.thechases.com> On 08/23/2011 11:15 PM, Larry Hastings wrote: > Episode 1 has just been released! > > You can find it at http://www.radiofreepython.com/ as of this very minute. No Podcast/RSS feed...seriously? Downloaded manually and will listen later, but best left to podcatchers :) -tkc From adam.jorgensen.za at gmail.com Wed Aug 24 10:30:13 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 24 Aug 2011 16:30:13 +0200 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... In-Reply-To: References: Message-ID: Thanks :-) Sorry about the size, I wasn't sure what was relevant... On 24 August 2011 15:29, Peter Otten <__peter__ at web.de> wrote: > Adam Jorgensen wrote: > >> Hi all, I'm experiencing a weird issue with closuring of parameters >> and some nested functions I have inside two functions that >> return decorators. I think it's best illustrated with the actual code: > > You should have made an effort to reduce its size >> # This decorator doesn't work. For some reason python refuses to >> closure the *decode_args parameter into the scope of the nested >> decorate and decorate_with_rest_wrapper functions >> # Renaming *decode_args has no effect >> def rest_wrapper(*decode_args, **deco_kwargs): >> ? ? def decorate(func): >> ? ? ? ? argspec = getfullargspec(func) >> ? ? ? ? decode_args = [argspec.args.index(decode_arg) for decode_arg >> in decode_args] > > I didn't read the whole thing, but: > >>>> def f(a): > ... ? ? def g(): > ... ? ? ? ? ? ? a = a + 42 > ... ? ? ? ? ? ? return a > ... ? ? return g > ... >>>> f(1)() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in g > UnboundLocalError: local variable 'a' referenced before assignment > > Python treats variables as local if you assign a value to them anywhere in > the function. The fix is easy, just use another name: > >>>> def f(a): > ... ? ? def g(): > ... ? ? ? ? ? ? b = a + 42 > ... ? ? ? ? ? ? return b > ... ? ? return g > ... >>>> f(1)() > 43 > > In Python 3 you can also use the nonlocal statement. > > -- > http://mail.python.org/mailman/listinfo/python-list > From cjw at ncf.ca Wed Aug 24 10:36:54 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Wed, 24 Aug 2011 10:36:54 -0400 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: On 24-Aug-11 00:15 AM, Larry Hastings wrote: > > > Radio Free Python is a new monthly podcast focused on Python and its > community. > > Episode 1 has just been released! It features a panel discussion with > the PythonLabs team: > > * Barry Warsaw, > * Fred Drake, > * Guido van Rossum, > * Roger Masse, > * and Tim Peters. > > > You can find it at http://www.radiofreepython.com/ as of this very minute. > > Enjoy! > > > /larry/ > > +1 Colin W. From k.sahithi2862 at gmail.com Wed Aug 24 11:04:13 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 24 Aug 2011 08:04:13 -0700 (PDT) Subject: HOT ACTRESS & DOOKUDU MOVIE STILLS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com FOR SEE 100 LINKS HOT PHOTOS SEE http://allyouwants.blogspot.com FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From patentsvnc at gmail.com Wed Aug 24 11:53:58 2011 From: patentsvnc at gmail.com (Den) Date: Wed, 24 Aug 2011 08:53:58 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> Message-ID: <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> On Aug 23, 7:46?pm, User wrote: > Hello all, > Does anyone have any good resources for learning Python? I know basic > Java and basic Python (loops, data types, if-then statements, etc), but > I want to delve into Python further. If anyone knows of any good books, > video tutorials, etc it would be greatly appreciated. > Thanks, > User Learning Python, and Programming in Python by Lutz. They worked for me. Den From kangshufan at hotmail.com Wed Aug 24 11:59:45 2011 From: kangshufan at hotmail.com (kangshufan at hotmail.com) Date: Wed, 24 Aug 2011 08:59:45 -0700 (PDT) Subject: there is a problem, holp someone could help me,thanks Message-ID: Hi everyone I just study python for a few time. Now I have a problem and I holp someone can help me. There is a piece of code: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) Could you explain how it works? Thanks for you help. Vince From kangshufan at hotmail.com Wed Aug 24 12:03:39 2011 From: kangshufan at hotmail.com (kangshufan at hotmail.com) Date: Wed, 24 Aug 2011 09:03:39 -0700 (PDT) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> Message-ID: <770aff9e-0879-40f5-ac86-f5098b9fd764@b9g2000prd.googlegroups.com> Hi all could some one help me? there is a piece of code: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) Could some one explain it for me? I can't understand how it works. From gordon at panix.com Wed Aug 24 12:46:39 2011 From: gordon at panix.com (John Gordon) Date: Wed, 24 Aug 2011 16:46:39 +0000 (UTC) Subject: there is a problem, holp someone could help me,thanks References: Message-ID: In kangshufan at hotmail.com writes: > Hi everyone > I just study python for a few time. > Now I have a problem and I holp someone can help me. > There is a piece of code: > def fib(x): > if x==0 or x==1: return 1 > else: return fib(x-1) + fib(x-2) > Could you explain how it works? > Thanks for you help. > Vince When a function calls itself, as fib() does, it's called recursion. http://en.wikipedia.org/wiki/Recursion_(computer_science) Basically the fib() method keeps calling itself with smaller and smaller arguments until it gets 1 or 0. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nobody at nowhere.com Wed Aug 24 13:47:37 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Aug 2011 18:47:37 +0100 Subject: Hiding token information from users References: Message-ID: On Tue, 23 Aug 2011 06:27:39 -0700, Tobiah wrote: > I am making QR codes that cell phone users scan in order to make use of an > application. Part of the information is a token that needs to be passed > on to the server, but I'd rather not allow a person examining the QR code > to be able to see that plain bit of information. I'd like to scramble up > the token so that the result: Can you not just encrypt the data with a fixed secret key? A fixed key satisfies #2. #3 can almost be satisfied by using base-64, or can be entirely satisfied by using base-36 or base-62 (these are less efficient, but that doesn't matter for small amounts of data). #1 can be satisfied by compressing the text beforehand; this should almost exactly compensate for the expansion caused by #3. Any block cipher in CBC mode will satisfy #4 (it will even be satisfied in ECB mode if the compressed token is smaller than the cipher block size). From nathan.huang.python at gmail.com Wed Aug 24 13:50:46 2011 From: nathan.huang.python at gmail.com (nathan huang) Date: Thu, 25 Aug 2011 01:50:46 +0800 Subject: there is a problem, holp someone could help me,thanks In-Reply-To: References: Message-ID: hi John it's simple, let's make a little modification for the scipt: def fib(x): if x==0 or x==1: return 1 else: return fib(x-1) + fib(x-2) for i in range(10): print 'fib(%s): ' % i, fib(i) result: fib(0): 1 fib(1): 1 fib(2): 2 fib(3): 3 fib(4): 5 fib(5): 8 fib(6): 13 fib(7): 21 fib(8): 34 fib(9): 55 you see, when we put 0 or 1 into fib, we definitely get 1 individually, if we put 2 into fib(), inside script we get two fib() result plus 1 + 1. If we put 9 into fib(), we get plus of two results of fib(7) and fib(8), that is 21 + 34, so we get 55. hope it can give you a little help. On Thu, Aug 25, 2011 at 12:46 AM, John Gordon wrote: > In > kangshufan at hotmail.com writes: > > > Hi everyone > > > I just study python for a few time. > > Now I have a problem and I holp someone can help me. > > There is a piece of code: > > > def fib(x): > > if x==0 or x==1: return 1 > > else: return fib(x-1) + fib(x-2) > > > Could you explain how it works? > > Thanks for you help. > > > Vince > > When a function calls itself, as fib() does, it's called recursion. > > http://en.wikipedia.org/wiki/Recursion_(computer_science) > > Basically the fib() method keeps calling itself with smaller and smaller > arguments until it gets 1 or 0. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From iamforufriends at gmail.com Wed Aug 24 14:34:20 2011 From: iamforufriends at gmail.com (hot girl) Date: Wed, 24 Aug 2011 11:34:20 -0700 (PDT) Subject: making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfri Message-ID: <84a2f2bb-99e7-40ab-8e79-4737b2388591@x14g2000prn.googlegroups.com> making girl friends is easy click bello like a girl, dn u can catch a girlfriend easy http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc http://adultfriendfinder.com/go/g1324422-ppc From rantingrick at gmail.com Wed Aug 24 14:39:21 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Aug 2011 11:39:21 -0700 (PDT) Subject: there is a problem, holp someone could help me,thanks References: Message-ID: <4dd3838c-8d6b-4957-b7c8-7b8b4669d058@a31g2000vbt.googlegroups.com> On Aug 24, 10:59?am, kangshu... at hotmail.com wrote: > Now I have a problem and I holp someone can help me. > > def fib(x): > ? ? if x==0 or x==1: return 1 > ? ? else: return fib(x-1) + fib(x-2) This must be from "How not to program". Was this a personal pick or recommendation? From gordon at panix.com Wed Aug 24 14:46:19 2011 From: gordon at panix.com (John Gordon) Date: Wed, 24 Aug 2011 18:46:19 +0000 (UTC) Subject: Learning Python References: <4e5465be$0$30265$c3e8da3$9b4ff22a@news.astraweb.com> <07ca03f3-e0a3-4ebf-9670-bad6f1cd0762@r40g2000prf.googlegroups.com> <770aff9e-0879-40f5-ac86-f5098b9fd764@b9g2000prd.googlegroups.com> Message-ID: In <770aff9e-0879-40f5-ac86-f5098b9fd764 at b9g2000prd.googlegroups.com> kangshufan at hotmail.com writes: > Hi all > could some one help me=EF=BC=9F > there is a piece of code: > def fib(x): > if x=3D=3D0 or x=3D=3D1: return 1 > else: return fib(x-1) + fib(x-2) > Could some one explain it for me? I can't understand how it works. Reposting the exact same question doesn't help us answer it. Perhaps you could explain why the previous responses weren't helpful. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From motoom at xs4all.nl Wed Aug 24 15:52:41 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 24 Aug 2011 21:52:41 +0200 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: On Aug 24, 2011, at 06:15, Larry Hastings wrote: > Radio Free Python is a new monthly podcast focused on Python and its community. Excellent initiative! I love to listen to podcasts about Open Source software and Python, on my MP3 player, while I take long walks in the countryside. I hope you'll have the same stamina as FLOSS Weekly (http://en.wikipedia.org/wiki/Floss_weekly). In the past years there have been some Python podcast initiatives, but most of them didn't last very long. I guess it takes a substantial amount of energy and commitment to produce regular podcasts over a long period of time. Do you need any input/ideas/feedback ? Greetings, Michiel Overtoom http://www.michielovertoom.com -- "Learn to value yourself, which means: fight for your happiness." - Ayn Rand From bsagert at gmail.com Wed Aug 24 16:45:09 2011 From: bsagert at gmail.com (Bill) Date: Wed, 24 Aug 2011 13:45:09 -0700 (PDT) Subject: I think I found 2 undocumented string format codes. Message-ID: My google-fu has failed me in finding info on %h and %l string formatting codes. >>> '%h' %'hello' exceptions.ValueError: incomplete format >>> '%l' %'hello' exceptions.ValueError: incomplete format Does anyone know what doing a "complete format" means? From rantingrick at gmail.com Wed Aug 24 17:22:21 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Aug 2011 14:22:21 -0700 (PDT) Subject: I think I found 2 undocumented string format codes. References: Message-ID: On Aug 24, 3:45?pm, Bill wrote: > My google-fu has failed me in finding info on %h and %l string > formatting codes. Did it ever occur to you to peruse the docs? http://docs.python.org/library/stdtypes.html#string-formatting-operations Stop using the limited deprecated string interpolation and use the new string format method. http://docs.python.org/library/string.html#format-string-syntax From alex.kapps at web.de Wed Aug 24 17:32:56 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 24 Aug 2011 23:32:56 +0200 Subject: I think I found 2 undocumented string format codes. In-Reply-To: References: Message-ID: <4E556E08.5050308@web.de> On 24.08.2011 22:45, Bill wrote: > My google-fu has failed me in finding info on %h and %l string > formatting codes. > >>>> '%h' %'hello' > exceptions.ValueError: incomplete format > >>>> '%l' %'hello' > exceptions.ValueError: incomplete format > > Does anyone know what doing a "complete format" means? See http://docs.python.org/library/stdtypes.html#string-formatting-operations The formatting codes have been borrowed from the C function sprintf(), where l and h are length modifier for integers (%hi, %li, ...) The Python docs (link above) say: "A length modifier (h, l, or L) may be present, but is ignored as it is not necessary for Python ? so e.g. %ld is identical to %d." From tjreedy at udel.edu Wed Aug 24 17:50:21 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Aug 2011 17:50:21 -0400 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E547ACB.4040301@hastings.org> References: <4E547ACB.4040301@hastings.org> Message-ID: <4E55721D.5090805@udel.edu> On 8/24/2011 12:15 AM, Larry Hastings wrote: > Radio Free Python is a new monthly podcast focused on Python and its > community. > > Episode 1 has just been released! It features a panel discussion with > the PythonLabs team: > > * Barry Warsaw, > * Fred Drake, > * Guido van Rossum, > * Roger Masse, > * and Tim Peters. > > You can find it at http://www.radiofreepython.com/ as of this very minute. What a treat. Thank you. Please announce the next one too. -- Terry Jan Reedy From davea at ieee.org Wed Aug 24 17:51:21 2011 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Aug 2011 17:51:21 -0400 Subject: Unspecified problem sending serial data In-Reply-To: References: <4E547894.2020308@ieee.org> Message-ID: <4E557259.5060702@ieee.org> Former subject line: reading and writing files On 08/24/2011 01:05 PM, Adri?n Monkas wrote: > Hi. thanks for answering so soon. > What i want to do is send around 180KBytes via Serial port. First of all i > have been trying to read from a file this amount of information and copy to > another file. That was a succesful test. After that the second test was > reading from a file and then send the info via serial, but it failed. > I have configured the serial port in both side of the connection. > thanks > Adrian > > Don't top-post. Put your response after the text you're quoting. OK, so you solved the first problem. Did you learn anything from my post? You're again not describing your (new) problem, your environment, nor in this case giving a clue as to what you've tried. Descriptions like "it failed" are usually useless. In this case, I can't help, because I don't know anything about doing serial on the Amiga. In any case, i wouldn't, since you didn't post to the forum. You sent it as a private reply to me. If you're reading this as a mailing list, the remember to do a reply-all, or at least make sure to use Python-list at python.org I'll forward the message for you, bu it would have been better if you had posted it directly, with an appropriate subject line. DaveA From tahoemph at gmail.com Wed Aug 24 18:01:28 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Wed, 24 Aug 2011 15:01:28 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E55721D.5090805@udel.edu> References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> Message-ID: On Wed, Aug 24, 2011 at 2:50 PM, Terry Reedy wrote: [...] >> You can find it at http://www.radiofreepython.com/ as of this very minute. > > What a treat. Thank you. Please announce the next one too. No, please don't announce the next one. There should be a RSS feed. But please do announce the feed at regular intervals. Michael > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > From ethan at stoneleaf.us Wed Aug 24 18:41:18 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 24 Aug 2011 15:41:18 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> Message-ID: <4E557E0E.7050602@stoneleaf.us> Michael Hunter wrote: > On Wed, Aug 24, 2011 at 2:50 PM, Terry Reedy wrote: > [...] >>> You can find it at http://www.radiofreepython.com/ as of this very minute. >> >> What a treat. Thank you. Please announce the next one too. > > No, please don't announce the next one. There should be a RSS feed. > But please do announce the feed at regular intervals. You're kidding, right? Instead of an alert for each podcast release which says, "Hey, there's something there right now!" you would rather have an alert that says, "Hey, check out this RSS feed, which may have nothing on it for another three weeks until the next podcast is ready!" ?? I vote with Terry. ~Ethan~ From tahoemph at gmail.com Wed Aug 24 18:51:28 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Wed, 24 Aug 2011 15:51:28 -0700 Subject: Announcing a new podcast: Radio Free Python In-Reply-To: <4E557E0E.7050602@stoneleaf.us> References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> <4E557E0E.7050602@stoneleaf.us> Message-ID: On Wed, Aug 24, 2011 at 3:41 PM, Ethan Furman wrote: [...] >> No, please don't announce the next one. ?There should be a RSS feed. >> But please do announce the feed at regular intervals. Note, I didn't say announce the feed each release. In fact, I didn't even say announce the feed in this channel. > > You're kidding, right? ?Instead of an alert for each podcast release which > says, "Hey, there's something there right now!" you would rather have an > alert that says, "Hey, check out this RSS feed, which may have nothing on it > for another three weeks until the next podcast is ready!" ?? No, you use the RSS feed to notify interested parties that a new podcast is available. You advertise the feed in a general way to get new users. Those are different things. > > I vote with Terry. Not sure how either of you was thinking but I do think the podcast author should use RSS. Michael > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Wed Aug 24 19:25:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Aug 2011 09:25:34 +1000 Subject: Announcing a new podcast: Radio Free Python References: <4E547ACB.4040301@hastings.org> <4E55721D.5090805@udel.edu> <4E557E0E.7050602@stoneleaf.us> Message-ID: <874o16wfwx.fsf@benfinney.id.au> Michael Hunter writes: > No, you use the RSS feed to notify interested parties that a new > podcast is available. You advertise the feed in a general way to get > new users. Those are different things. +1, except please make it a standard Atom feed instead of (or in addition to) the messy RSS. -- \ ?Very few things happen at the right time, and the rest do not | `\ happen at all. The conscientious historian will correct these | _o__) defects.? ?Mark Twain, _A Horse's Tale_ | Ben Finney From redjohn367 at gmail.com Wed Aug 24 19:29:26 2011 From: redjohn367 at gmail.com (Red John) Date: Wed, 24 Aug 2011 16:29:26 -0700 (PDT) Subject: is there any principle when writing python function References: <1ba7b65b-04b5-4b90-899a-f1a152d56023@fe21g2000vbb.googlegroups.com> Message-ID: > "We must constantly strive to remove multiplicity from our systems; > lest it consumes us!" > > s/multiplicity/rantingrick/ and I'm in full agreement. QFT From steve+comp.lang.python at pearwood.info Wed Aug 24 20:54:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 25 Aug 2011 10:54:55 +1000 Subject: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data... References: Message-ID: <4e559d60$0$29989$c3e8da3$5496439d@news.astraweb.com> Adam Jorgensen wrote: > Thanks :-) Sorry about the size, I wasn't sure what was relevant... We prefer that you don't top-post here, because it makes it hard to see context when people reply. In general, people asking questions should always try to reduce the problem to the simplest code that will demonstrate the problem. This has two huge advantages: (1) We're all volunteers here, none of us are paid to solve your problems. The more work needed to answer a question that we might not care that much about, the less likely it is that you will get good answers. The easier you make it for us, the more likely you will get many good, prompt answers. (2) Even more important... the process of cutting out all the irrelevant details and reducing the code to the smallest possible example may reveal to you what the problem is. As the old proverb goes, "solve a coder's problem, and you've solved one problem... teach a coder how to solve his own problems, and you've solved them all" *wink* I can't begin to count how many times I've started writing up a post to ask a question, and in the process of reducing the example code to the smallest it can be, I've solved it myself. -- Steven From 1248283536 at qq.com Wed Aug 24 23:34:04 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 25 Aug 2011 11:34:04 +0800 Subject: event :use command to replace bind Message-ID: here is my code ,it can run ,i want to make it simpler, to change three sentences to one, xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) i write: Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) that is to change code1 into code2 ,when you click the button"fetch",the output is : TypeError: fetch() takes exactly 2 arguments (1 given) how to revise it? code1:(it's ok) from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(event, entries): for entry in entries: print 'Input => "%s"' % entry.get() print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) lab = Label(row, width=5, text=field) ent = Entry(row) row.pack(side=TOP, fill=X) lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', partial(fetch, entries=ents)) xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) root.mainloop() code2: from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(event, entries): for entry in entries: print 'Input => "%s"' % entry.get() print event.widget def makeform(root, fields): entries = [] for field in fields: row = Frame(root) lab = Label(row, width=5, text=field) ent = Entry(row) row.pack(side=TOP, fill=X) lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) entries.append(ent) return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) root.bind('', partial(fetch, entries=ents)) Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsgroups at jiripik.com Thu Aug 25 02:26:36 2011 From: newsgroups at jiripik.com (Jiri Pik) Date: Thu, 25 Aug 2011 08:26:36 +0200 Subject: PythonAPI4FinancialData - Python code for grabbing the entire universe of Finance Yahoo tickers Message-ID: <1586553507.20110825082636@jiripik.com> Hello Python-list, for personal finance study, i found it critical to have as complete universe of yahoo tickers as possible. In fact, this seems to be a common problem if you google it. Thus, I have created a simple Python code (to be expanded shortly for all required functionality) which grabs all the tickers from Yahoo. In case you're interested, https://github.com/jiripik/PythonAPI4FinancialData. -- Jiri Pik, jiri at jiripik.com Web: http://jiripik.com, LinkedIn: http://www.linkedin.com/in/jiripik, Twitter: http://twitter.com/@JiriPik From motoom at xs4all.nl Thu Aug 25 02:27:46 2011 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 25 Aug 2011 08:27:46 +0200 Subject: Unspecified problem sending serial data In-Reply-To: <4E557259.5060702@ieee.org> References: <4E547894.2020308@ieee.org> <4E557259.5060702@ieee.org> Message-ID: On Aug 24, 2011, at 23:51, Dave Angel wrote: > On 08/24/2011 01:05 PM, Adri?n Monkas wrote: >> What I want to do is send around 180KBytes via Serial port. Also have a look at pySerial, http://pyserial.sourceforge.net/ Greetings, -- "If you don't know, the thing to do is not to get scared, but to learn." - Ayn Rand From steve+comp.lang.python at pearwood.info Thu Aug 25 03:13:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 25 Aug 2011 17:13:07 +1000 Subject: [OT-ish] Design principles: no bool arguments Message-ID: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> One design principle often mentioned here (with a certain degree of disagreement[1]) is the idea that as a general rule, you shouldn't write functions that take a bool argument to switch between two slightly different behaviours. This is a principle often championed by the BDFL, Guido van Rossum. Here's a Javascript-centric article which discusses the same idea, and gives it a name: the Boolean Trap. http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html No doubt there are counter arguments as well. The most obvious to me is if the flag=True and flag=False functions share a lot of code, it is poor practice to implement them as two functions with two copies of almost identical code. My solution to this is a technical violation of the "Avoid Boolean Trap" principle, but only in a private function: def spam_on(arg): _spam(arg, True) def spam_off(arg): _spam(arg, False) def _spam(arg, flag): do stuff if flag: a else: b more stuff [1] This is the Internet. There's *always* a certain amount of disagreement. -- Steven From maarten.sneep at knmi.nl Thu Aug 25 03:52:38 2011 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 25 Aug 2011 00:52:38 -0700 (PDT) Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> On Aug 25, 9:13?am, Steven D'Aprano wrote: > One design principle often mentioned here (with a certain degree of > disagreement[1]) is the idea that as a general rule, you shouldn't write > functions that take a bool argument to switch between two slightly > different behaviours. > > This is a principle often championed by the BDFL, Guido van Rossum. > > Here's a Javascript-centric article which discusses the same idea, and gives > it a name: the Boolean Trap. > > http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html > > No doubt there are counter arguments as well. The most obvious to me is if > the flag=True and flag=False functions share a lot of code, it is poor > practice to implement them as two functions with two copies of almost > identical code. A simple one: C and C-like languages only have arguments, not keyword- parameters. That alone makes a world of difference. Maarten From affdfsdfdsfsd at b.com Thu Aug 25 04:25:59 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 25 Aug 2011 08:25:59 GMT Subject: bash command, get stdErr Message-ID: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Hi all! i'ld like to execute via Python this simple bash command: sudo las las is intended to be a typo for "ls" the point is that i want to see in the terminal the stderr message (that is "sorry, try again" if i insert the wrong password or "sudo: las: command not found" otherwise) i can simply do it with subprocess.POpen() or subprocess.Call() but as far as i know i have two choice: 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) in this way i catch the stderr messages BUT they are not "printed" in the terminal 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) in this way i "print" the message in the terminal but i can retrieve they (the error messages) when the command is executed it's important for me to know if the user have inserted the wrong password or i've tryied to execute a wrong/unsupported command (for example yum install in a ubuntu environment, or a typo like "las") if i use stderr=subprocess.PIPE and the user insert a wrong password, he'll get a second request of insert password without the reason for doing it (because the error message isn't printed on the terminal). This is not a big problem, he will understand he haven't inserted the right password, and if he miss the password 3 times i'll pop-up a gtk alert windows to inform him of the problem. Still, it's not good to don't give feedback of the error to the user, so i'ld like to print the stderr on terminal AND get it after the command terminate to check the problem occurred (exit status is not enough). Is there a way to accomplish this? As usual sorry for my bad english MedeoTL From stefan_ml at behnel.de Thu Aug 25 04:29:41 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Aug 2011 10:29:41 +0200 Subject: Design principles: no bool arguments In-Reply-To: <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> Message-ID: Maarten, 25.08.2011 09:52: > On Aug 25, 9:13 am, Steven D'Aprano wrote: >> One design principle often mentioned here (with a certain degree of >> disagreement[1]) is the idea that as a general rule, you shouldn't write >> functions that take a bool argument to switch between two slightly >> different behaviours. >> >> This is a principle often championed by the BDFL, Guido van Rossum. >> >> Here's a Javascript-centric article which discusses the same idea, and gives >> it a name: the Boolean Trap. >> >> http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html >> >> No doubt there are counter arguments as well. The most obvious to me is if >> the flag=True and flag=False functions share a lot of code, it is poor >> practice to implement them as two functions with two copies of almost >> identical code. > > A simple one: C and C-like languages only have arguments, not keyword- > parameters. That alone makes a world of difference. Right. It's totally unreadable to find this in the code: data1.merge_with(data2, true); Requires you to either a) know the underlying signature by heart, or b) look it up before understanding the code. It's a lot harder to argue against this: data1.merge_with(data2, overwrite_duplicates=True) Stefan From clp2 at rebertia.com Thu Aug 25 04:52:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 01:52:25 -0700 Subject: bash command, get stdErr In-Reply-To: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: > Hi all! > i'ld like to execute via Python this simple bash command: > > sudo las > > las is intended to be a typo for "ls" > > the point is that i want to see in the terminal the stderr message (that > is "sorry, try again" if i insert the wrong password or "sudo: las: > command not found" otherwise) > > i can simply do it with subprocess.POpen() or subprocess.Call() but as > far as i know i have two choice: > 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) > > in this way i catch the stderr messages BUT they are not "printed" in the > terminal > > 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) > in this way i "print" the message in the terminal but i can retrieve they > (the error messages) when the command is executed > Still, it's not good to don't give > feedback of the error to the user, so i'ld like to print the stderr on > terminal AND get it after the command terminate to check the problem > occurred (exit status is not enough). Untested: from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, stderr=PIPE) tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) # Read from tee.stdout to get any error messages Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 Cheers, Chris -- http://rebertia.com From PointedEars at web.de Thu Aug 25 05:29:01 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 25 Aug 2011 11:29:01 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> Message-ID: <1660212.aK4W3vaeNJ@PointedEars.de> Stefan Behnel wrote: > Maarten, 25.08.2011 09:52: >> On Aug 25, 9:13 am, Steven D'Aprano wrote: >>> One design principle often mentioned here (with a certain degree of >>> disagreement[1]) is the idea that as a general rule, you shouldn't write >>> functions that take a bool argument to switch between two slightly >>> different behaviours. >>> >>> This is a principle often championed by the BDFL, Guido van Rossum. >>> >>> Here's a Javascript-centric article which discusses the same idea, and >>> gives it a name: the Boolean Trap. >>> >>> http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html >>> >>> No doubt there are counter arguments as well. The most obvious to me is >>> if the flag=True and flag=False functions share a lot of code, it is >>> poor practice to implement them as two functions with two copies of >>> almost identical code. >> >> A simple one: C and C-like languages only have arguments, not keyword- >> parameters. That alone makes a world of difference. The logic is flawed, for one because keyword arguments can be emulated. For example in C, you can (and would) OR-combine binary flag constants: open("foo", O_RDONLY); instead of open("foo", TRUE); (assuming the latter function existed). Other approaches can be found in C as well: fopen("foo", "r"); In ECMAScript implementations like JavaScript (which I count as C-like), you can define the API so that it accepts object references (as explained in the article): foo(bar, {baz: true}); instead of (or in addition to) foo(bar, true); (But this is a trade-off readability vs. runtime and memory efficiency, as each time the function is called an object needs to be created, if it is not cached, and an additional property access is necessary in the function/method. Python has much the same problem, see below.) And there can hardly be an argument that W3C DOM Level 3 Events init?Event() methods are *unnecessarily* FUBAR. Even OMG IDL supports constants (as showed by the HTMLElement interface of DOM Level 2 Core), and passing of object instances to methods. > Right. It's totally unreadable to find this in the code: > > data1.merge_with(data2, true); > > Requires you to either a) know the underlying signature by heart, or b) > look it up before understanding the code. > > It's a lot harder to argue against this: > > data1.merge_with(data2, overwrite_duplicates=True) Both variants work (even in Py3) if you only define class Data(object): def merge_with(self, bar, overwrite_duplicates): pass data1 = Data() data2 = Data() You have to define class Data(object): def merge_with(self, bar, **kwargs): # do something with kwargs['overwrite_duplicates'] pass data1 = Data() data2 = Data() so that data1.merge_with(data2, True); is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 given)"). IOW, this advantage of Python in readability is not only caused by API definition, but also by how the API is used. It might turn into a disadvantage if key lookups make the code expensive memory- and runtime wise. And you will still have to know the underlying signature to name the argument. Worse, with keyword arguments you *have to* look up the documentation (i. e., it needs to be well-documented as well) to know its name (as the compiler can only tell you "kwargs"). So no doubt there are advantages to keyword arguments, but there are disadvantages, too. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From moiurmohiuddin at gmail.com Thu Aug 25 06:40:31 2011 From: moiurmohiuddin at gmail.com (waner) Date: Thu, 25 Aug 2011 03:40:31 -0700 (PDT) Subject: world most interesting event is waiting Message-ID: <765c69bb-edf7-45cd-a614-711a39104e7d@y39g2000prd.googlegroups.com> This is really funny and useful for all ,to know the basic information of home equity. Learn More for details:http://usefulfitnesstips.com/ From anand.shashwat at gmail.com Thu Aug 25 07:07:50 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 16:37:50 +0530 Subject: PUT with proxy-support Message-ID: I want to make a PUT request. I need some headers of my own ( certificates etc ) and I need to mandatorily use a proxy. Also the url is of the form http://www.xyz.com/abc and I don't have permission to put data on http://www.xyz.com while I do have permission to put data on http://www.xyz.com/abc I tried httplib, httplib2, urllib2 with no avail. I managed to do this via command line curl: $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" Is there a way to do it in python apart from using command line curl in python. The machine is RHEL4 and is giving hard time installing pycurl. -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxc at me.com Thu Aug 25 07:18:33 2011 From: maxc at me.com (Max Countryman) Date: Thu, 25 Aug 2011 07:18:33 -0400 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> Check out the python Requests module: http://docs.python-requests.org/en/latest/index.html Sent from my iPhone On Aug 25, 2011, at 7:07, Shashwat Anand wrote: > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abc and I don't have permission to put data > on http://www.xyz.com while I do have permission to put data on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in python. > The machine is RHEL4 and is giving hard time installing pycurl. > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Thu Aug 25 07:18:49 2011 From: t at jollybox.de (Thomas Jollans) Date: Thu, 25 Aug 2011 13:18:49 +0200 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <4E562F99.1000301@jollybox.de> On 25/08/11 13:07, Shashwat Anand wrote: > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to > mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abc and I don't have > permission to put data > on http://www.xyz.com while I do have permission to put data > on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. What did you try? What problems did you run into? I'm sure there is a way in Python, and chances are you were already close to finding it -- show us what you tried, what actually happened, including any error messages in full, and what you wanted to happen. Thomas > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt > -T test.txt -H "sw-version: > 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H > "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in > python. > The machine is RHEL4 and is giving hard time installing pycurl. > > > From anand.shashwat at gmail.com Thu Aug 25 07:47:07 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:17:07 +0530 Subject: PUT with proxy-support In-Reply-To: <4E562F99.1000301@jollybox.de> References: <4E562F99.1000301@jollybox.de> Message-ID: On Thu, Aug 25, 2011 at 4:48 PM, Thomas Jollans wrote: > On 25/08/11 13:07, Shashwat Anand wrote: > > I want to make a PUT request. > > I need some headers of my own ( certificates etc ) and I need to > > mandatorily use a proxy. > > Also the url is of the form http://www.xyz.com/abc and I don't have > > permission to put data > > on http://www.xyz.com while I do have permission to put data > > on http://www.xyz.com/abc > > > > I tried httplib, httplib2, urllib2 with no avail. > > What did you try? What problems did you run into? > > I'm sure there is a way in Python, and chances are you were already > close to finding it -- show us what you tried, what actually happened, > including any error messages in full, and what you wanted to happen. > > Thomas > Hi Thomas, so one of my tries was: import urllib import urllib2 import httplib import httplib2 url = 'http://alatheia.zenfs.com/testing/shashwat' body_content = 'CONTENT GOES HERE' proxy = 'ca-proxy.corp.xyz.com:3128' params = { 'x-sws-version' : '1.0', 'x-sws-access' : 'public', 'User-Agent' : 'CacheSystem', 'Cache-Control' : 'public', 'Content-Type' : 'text/plain', 'App-Auth' : 'v=1;a=client.alatheia.prod;h=10.16.19.23;t=1316594650;s=AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--', } httplib2.debuglevel=4 h = httplib2.Http(proxy_info = httplib2.ProxyInfo(3, ' ca-proxy.corp.xyz.com:3128', 3128)) resp, content = h.request(url, "PUT", body=body_content, headers = params) print resp print content Output: connect: (alatheia.zenfs.com, 80) Traceback (most recent call last): File "test.py", line 29, in resp, content = h.request(url, "PUT", body=body_content, headers = params) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1436, in request (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1188, in _request (response, content) = self._conn_request(conn, request_uri, method, body, headers) File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 1123, in _conn_request conn.connect() File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 786, in connect self.sock.connect(sa) File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 381, in connect self.__negotiatehttp(destpair[0], destpair[1]) File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 347, in __negotiatehttp raise HTTPError((statuscode, statusline[2])) httplib2.socks.HTTPError: (403, 'Tunnel or SSL Forbidden') The reason I can trace it is because, I can use PUT on http://alatheia.zenfs.com/testing/shashwat but not on http://alatheia.zenfs.com/ however host is resolved. Again port 80 is used even when I use specific port (3128, in this case). -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Aug 25 07:49:56 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:19:56 +0530 Subject: PUT with proxy-support In-Reply-To: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> References: <7CAC2A46-EE68-467D-926B-53CB80438783@me.com> Message-ID: On Thu, Aug 25, 2011 at 4:48 PM, Max Countryman wrote: > Check out the python Requests module: > http://docs.python-requests.org/en/latest/index.html > > Python request module is not documented very well IMHO. I tried to figure how to make PUT calls, how to add proxy, how to add certificates in headers. Did not managed to find all of it. Am not sure is supports REST calls with proxy support. > Sent from my iPhone > > On Aug 25, 2011, at 7:07, Shashwat Anand wrote: > > I want to make a PUT request. > I need some headers of my own ( certificates etc ) and I need to > mandatorily use a proxy. > Also the url is of the form http://www.xyz.com/abcand I don't have permission to put data > on http://www.xyz.com while I do have permission to > put data on http://www.xyz.com/abc > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/ > xyz.com/testing/shashwat/test.txt -T test.txt -H "sw-version: 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > Is there a way to do it in python apart from using command line curl in > python. > The machine is RHEL4 and is giving hard time installing pycurl. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Thu Aug 25 07:52:11 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 25 Aug 2011 13:52:11 +0200 Subject: PUT with proxy-support In-Reply-To: References: Message-ID: <4E56376B.1080603@shopzeus.com> > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt > -T test.txt -H "sw-version: > 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H > "Content-Type:text/plain" If you can do it with command line curl then probably you can do it with pycurl. http://pycurl.sourceforge.net/ Best, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Aug 25 08:02:17 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 25 Aug 2011 17:32:17 +0530 Subject: PUT with proxy-support In-Reply-To: <4E56376B.1080603@shopzeus.com> References: <4E56376B.1080603@shopzeus.com> Message-ID: On Thu, Aug 25, 2011 at 5:22 PM, Laszlo Nagy wrote: > ** > > I tried httplib, httplib2, urllib2 with no avail. > I managed to do this via command line curl: > > $ curl http:/xyz.com/testing/shashwat/test.txt -T test.txt -H > "sw-version: 1.0" -H > "CA-Cert-Auth:v=1;a=yxyz.prod;h=10.10.0.1;t=1316594650;s=.AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--" > --proxy proxy.xyz.com:3128 -H "Content-Type:text/plain" > > If you can do it with command line curl then probably you can do it with > pycurl. > > http://pycurl.sourceforge.net/ > Yeah. I tried that. The system is RHEL 4. So it gave me this error : src/pycurl.c:42:20: Python.h: No such file or directory src/pycurl.c:43:22: pythread.h: No such file or directory src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile pycurl." src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to compile pycurl." Apparently we need python-devel package. Following http://fedoraproject.org/wiki/EPEL/FAQ#howtouse I added EPEL software repository. sh-3.00$ yum list | grep -i python-dev sh-3.00$ sudo yum -y install python-dev Password: Setting up Install Process Setting up repositories epel [1/1] epel 100% |=========================| 3.8 kB 00:00 Reading repository metadata in from local files b1f7bfef07466e9561644aba7 100% |=========================| 841 kB 00:06 epel : ################################################## 2583/2583 Added 2583 new packages, deleted 0 old in 4.51 seconds Parsing package install arguments No Match for argument: python-dev Nothing to do Turned out that python-curl is the required package which is already installed. Still no use. sh-3.00$ yum list | grep -i python-curl python-curl.x86_64 7.12.1-1.3.el4.rf installed sh-3.00$ python Python 2.6.4 (r264:75706, Nov 9 2009, 16:32:06) [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pycurl Traceback (most recent call last): File "", line 1, in ImportError: No module named pycurl >>> Tried installing via easy_install sh-3.00$ sudo easy_install pycurl Searching for pycurl Reading http://pypi.python.org/simple/pycurl/ Reading http://pycurl.sourceforge.net/ Reading http://pycurl.sourceforge.net/download/ Best match: pycurl 7.19.0 Downloading http://pycurl.sourceforge.net/download/pycurl-7.19.0.tar.gz Processing pycurl-7.19.0.tar.gz Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2ZCa8v/pycurl-7.19.0/egg-dist-tmp-DyHFls Using curl-config (libcurl 7.12.1) src/pycurl.c:42:20: Python.h: No such file or directory src/pycurl.c:43:22: pythread.h: No such file or directory src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile pycurl." src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to compile pycurl." [... Error Clipped] error: Setup script exited with error: command '/usr/bin/gcc' failed with exit status 1 > > Best, > > Laszlo > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrei.fokau at gmail.com Thu Aug 25 08:54:43 2011 From: andrei.fokau at gmail.com (Andrei) Date: Thu, 25 Aug 2011 05:54:43 -0700 (PDT) Subject: How to run a setup command with 'pip install'? Message-ID: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> Hello, I have a trouble installing the DMSL package with pip. The package doesn't have *.c files, which must be produced with Cython by 'pyhton setup.py build_ext' command. How do I run it with 'pip install'? Please see http://stackoverflow.com/questions/7189336/ for details. Regards, Andrei From boppanas at gmail.com Thu Aug 25 09:24:46 2011 From: boppanas at gmail.com (Sirisha) Date: Thu, 25 Aug 2011 06:24:46 -0700 (PDT) Subject: Immediate Requirement for a Data Warehouse Developer Message-ID: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> Position Profile ? Senior Data Warehouse Developer Location: Detroit, MI Contact: Please send resumes to resumes at rg-llc.com or call 313.254.4631 Purpose ? Assist with analysis, design, development and implementation of projects for the corporate data warehouse ? Partner with the DBA team and other data warehouse developers to achieve the best performance and efficiency possible for our internal business customers ? Act as the Subject Matter Expert in methods, best practices and standards related to data management, data movement, conceptual and physical database design, and data warehousing business intelligence technologies ? Basic Position Requirements: What do you need to qualify as a candidate for this position? ? You need to be organized, with an ability to multi-task and prioritize multiple requests ? You need to be able to demonstrate problem-solving skills and make quick decisions ? You need to be self-driven, motivated to help, and able to perform with minimal supervision in a team environment ? You need to be receptive to ongoing feedback aimed at improving the performance of you and your team Requirements: Experience and Education requirements. Required: ? Minimum of 5 years of data warehouse analysis, design and development experience ? Minimum of 10 years of overall Information Systems experience ? Practical expertise in full lifecycle database design, including 3NF and dimensional design concepts ? Proficiency in PL/SQL coding, troubleshooting, and performance tuning ? Experience with Oracle, preferably version 10/11 Preferred ? Experience in DW specific disciplines such as Data Quality and Cleansing, Data Governance, Metadata usage and management, and Master data management. ? Knowledge of ETL tools ? specifically Oracle Data Integrator Enterprise Edition ? Knowledge of Unix Scripting and job scheduling ? Bachelor?s degree Position Outcomes & Activities: You will be measured on your ability to perform the following activities effectively ? Gather requirements: You will need to meet with internal customers so you can provide analysis and solution design to meet their requirements. ? Provide time and cost estimates: You will be measured on your ability to estimate time and cost for architecture design and development on data warehouse projects ? Provide recommendations and Implement: As the Subject Matter Expert you will be expected to make recommendations on system and architecture changes to improve performance and efficiency and see these recommendation through to implementation ? Complete development: You will need to develop solutions using Oracle, PL/SQL, Oracle Data Integrator Enterprise Edition (ODIEE). Please send resumes to resumes at rg-llc.com or call 313.254.4631 From andrei.fokau at gmail.com Thu Aug 25 09:54:18 2011 From: andrei.fokau at gmail.com (Andrei) Date: Thu, 25 Aug 2011 06:54:18 -0700 (PDT) Subject: How to run a setup command with 'pip install'? In-Reply-To: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> References: <93444bea-46fa-4fbf-ac26-f25b3eeee83f@glegroupsg2000goo.googlegroups.com> Message-ID: <766f3c8b-364d-46aa-ba68-21aee38e38d8@glegroupsg2000goo.googlegroups.com> 'pip install pyrex' solved the problem (credit to @jezdez) From saraanderson24 at gmail.com Thu Aug 25 10:19:07 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Thu, 25 Aug 2011 07:19:07 -0700 (PDT) Subject: WATCH WORLD`S BEST BREAK DANCE PERFORMANCE. Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ WATCH WORLD`S BEST BREAK DANCE PERFORMANCE. http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From ting at thsu.org Thu Aug 25 10:30:31 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 07:30:31 -0700 (PDT) Subject: Run time default arguments Message-ID: What is the most common way to handle default function arguments that are set at run time, rather than at compile time? The snippet below is the current technique that I've been using, but it seems inelegant. defaults = { 'debug' : false } def doSomething (debug = None): debug = debug if debug != None else defaults['debug'] # blah blah blah Basically, I want to define a set of common defaults at the module and/ or class level but let them be overridden via function arguments. The simpler, naive approach does not work, because the argument gets set at compile time, rather than at run time. That is: def doSomething(debug = defaults['debug']) ends up being compiled into: def doSomething(debug = false) which is not the behavior I want, as I want to evaluate the argument at run time. Any better suggestions? -- // T.Hsu From arnodel at gmail.com Thu Aug 25 10:31:08 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 15:31:08 +0100 Subject: Getting a module's code object Message-ID: Hi all, In Python 3, a function f's code object can be accessed via f.__code__. I'm interested in getting a module's code object, i.e. the code that is executed when the module is run. I don't think it's accessible via the module object itself (although I would be glad if somebody proved me wrong :). In the marshal module docs [1] it is mentioned that: """ The marshal module exists mainly to support reading and writing the ?pseudo-compiled? code for Python modules of .pyc files. """ So it seems that the module's code object is marshalled into the .pyc file - so there may be a way to unmarshal it - but I can't easily find information about how to do this. Is this a good lead, or is there another way to obtained a module's code object? Thanks -- Arnaud [1] http://docs.python.org/py3k/library/marshal.html From arnodel at gmail.com Thu Aug 25 10:35:05 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 07:35:05 -0700 (PDT) Subject: Run time default arguments References: Message-ID: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> On Aug 25, 3:30?pm, t... at thsu.org wrote: > What is the most common way to handle default function arguments that > are set at run time, rather than at compile time? The snippet below is > the current technique that I've been using, but it seems inelegant. > > defaults = { 'debug' : false } > def doSomething (debug = None): > ? ? debug = debug if debug != None else defaults['debug'] > ? ? # blah blah blah You're close to the usual idiom: def doSomething(debug=None): if debug is None: debug = defaults['debug'] ... Note the use of 'is' rather than '==' HTH -- Arnaud From python at mrabarnett.plus.com Thu Aug 25 10:50:24 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Aug 2011 15:50:24 +0100 Subject: Run time default arguments In-Reply-To: References: Message-ID: <4E566130.1050409@mrabarnett.plus.com> On 25/08/2011 15:30, ting at thsu.org wrote: > What is the most common way to handle default function arguments that > are set at run time, rather than at compile time? The snippet below is > the current technique that I've been using, but it seems inelegant. > > defaults = { 'debug' : false } > def doSomething (debug = None): > debug = debug if debug != None else defaults['debug'] > # blah blah blah > > Basically, I want to define a set of common defaults at the module and/ > or class level but let them be overridden via function arguments. The > simpler, naive approach does not work, because the argument gets set > at compile time, rather than at run time. That is: > def doSomething(debug = defaults['debug']) > ends up being compiled into: > def doSomething(debug = false) > which is not the behavior I want, as I want to evaluate the argument > at run time. > > Any better suggestions? > The recommended way is: def doSomething (debug = None): if debug is None: debug = defaults['debug'] It's more lines, but clearer. From philip at semanchuk.com Thu Aug 25 10:56:17 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 25 Aug 2011 10:56:17 -0400 Subject: Immediate Requirement for a Data Warehouse Developer In-Reply-To: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> References: <64e14272-8bf6-428c-bb0b-0daf140bb084@m18g2000vbl.googlegroups.com> Message-ID: <5EFBF134-A4B2-4B0A-BDC6-CB6D6B0F7BF2@semanchuk.com> On Aug 25, 2011, at 9:24 AM, Sirisha wrote: > Position Profile ? Senior Data Warehouse Developer As was mentioned on the list less than 24 hours ago, please don't post job listings to this mailing list. Use the Python jobs board instead: http://www.python.org/community/jobs/ From tjreedy at udel.edu Thu Aug 25 11:03:41 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Aug 2011 11:03:41 -0400 Subject: [OT-ish] Design principles: no bool arguments In-Reply-To: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/25/2011 3:13 AM, Steven D'Aprano wrote: > One design principle often mentioned here (with a certain degree of > disagreement[1]) is the idea that as a general rule, you shouldn't write > functions that take a bool argument to switch between two slightly > different behaviours. > > This is a principle often championed by the BDFL, Guido van Rossum. You missed the essential caveat to his rule. See below. > Here's a Javascript-centric article which discusses the same idea, and gives > it a name: the Boolean Trap. > > http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html This was mostly about defining parameters as positional-only (which Python does not have) versus keyword-optional or keyword only. In Python, callers always have the 'keyword = BOOL' option. > No doubt there are counter arguments as well. The most obvious to me is if > the flag=True and flag=False functions share a lot of code, it is poor > practice to implement them as two functions with two copies of almost > identical code. > > My solution to this is a technical violation of the "Avoid Boolean Trap" > principle, but only in a private function: > > def spam_on(arg): > _spam(arg, True) > > def spam_off(arg): > _spam(arg, False) > > def _spam(arg, flag): > do stuff > if flag: > a > else: > b > more stuff As I think one of the comments pointed out, this now means that if I the user need to compute whether to turn off or on, I now have to write if expr: spam_on(arg) elses: spam_off(arg) (or put this on 4 lines if you prefer ;-) instead of spam_switch(expr, arg) so moving the conditional out of the function *pushes it onto every user*. Note that naming the function 'switch' and putting the bool as the first param makes it pretty obvious that True=='on', and False=='off'. As I remember, Guido only recommendeds splitting if the boolean arg is (would be) always (nearly) passed as a constant True or False. Of course, I am not sure how one forsees that at the design stage, prior to field use. -- Terry Jan Reedy From __peter__ at web.de Thu Aug 25 11:07:33 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Aug 2011 17:07:33 +0200 Subject: Getting a module's code object References: Message-ID: Arnaud Delobelle wrote: > In Python 3, a function f's code object can be accessed via f.__code__. > > I'm interested in getting a module's code object, i.e. the code that > is executed when the module is run. I don't think it's accessible via > the module object itself (although I would be glad if somebody proved > me wrong :). In the marshal module docs [1] it is mentioned that: > > """ > The marshal module exists mainly to support reading and writing the > ?pseudo-compiled? code for Python modules of .pyc files. > """ > > So it seems that the module's code object is marshalled into the .pyc > file - so there may be a way to unmarshal it - but I can't easily find > information about how to do this. > > Is this a good lead, or is there another way to obtained a module's code > object? Taken from pkgutil.py: def read_code(stream): # This helper is needed in order for the PEP 302 emulation to # correctly handle compiled files import marshal magic = stream.read(4) if magic != imp.get_magic(): return None stream.read(4) # Skip timestamp return marshal.load(stream) Alternatively you can compile the source yourself: module = compile(source, filename, "exec") From arnodel at gmail.com Thu Aug 25 11:33:55 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 25 Aug 2011 16:33:55 +0100 Subject: Getting a module's code object In-Reply-To: References: Message-ID: On 25 August 2011 16:07, Peter Otten <__peter__ at web.de> wrote: > Arnaud Delobelle wrote: > >> In Python 3, a function f's code object can be accessed via f.__code__. >> >> I'm interested in getting a module's code object, [...] > > Taken from pkgutil.py: > > def read_code(stream): > ? ?# This helper is needed in order for the PEP 302 emulation to > ? ?# correctly handle compiled files > ? ?import marshal > > ? ?magic = stream.read(4) > ? ?if magic != imp.get_magic(): > ? ? ? ?return None > > ? ?stream.read(4) # Skip timestamp > ? ?return marshal.load(stream) This works fine, thanks a lot! > Alternatively you can compile the source yourself: > > module = compile(source, filename, "exec") I don't necessarily have access to the source file. -- Arnaud From stefan_ml at behnel.de Thu Aug 25 13:01:22 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Aug 2011 19:01:22 +0200 Subject: Design principles: no bool arguments In-Reply-To: <1660212.aK4W3vaeNJ@PointedEars.de> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: Thomas 'PointedEars' Lahn, 25.08.2011 11:29: > Stefan Behnel wrote: >> It's totally unreadable to find this in the code: >> >> data1.merge_with(data2, true); >> >> Requires you to either a) know the underlying signature by heart, or b) >> look it up before understanding the code. >> >> It's a lot harder to argue against this: >> >> data1.merge_with(data2, overwrite_duplicates=True) >[...] > And you will still have to know the underlying signature to name the > argument. Worse, with keyword arguments you *have to* look up the > documentation (i. e., it needs to be well-documented as well) to know its > name (as the compiler can only tell you "kwargs"). Note that code is read more often than it gets written. Stefan From emortalwatts at gmail.com Thu Aug 25 14:43:24 2011 From: emortalwatts at gmail.com (Emory Watts) Date: Thu, 25 Aug 2011 14:43:24 -0400 Subject: Disable pop up menu that triggers upon pressing tab, Message-ID: Hello, I tried to find out how to do this on my own, but searching around turned up no results. And this is the only way I saw to get a question answered. I would like know how to disable the pop up predictions menu that appears when I press tab. I would much rather just be able to tab over, and I cannot figure out how to disable the menu. Thank you for your time. Emory -------------- next part -------------- An HTML attachment was scrubbed... URL: From claird271 at gmail.com Thu Aug 25 14:48:42 2011 From: claird271 at gmail.com (Cameron Laird) Date: Thu, 25 Aug 2011 11:48:42 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Aug 25) Message-ID: [Original draft by Gabriel Genellina.] QOTW: "Python is a programming language, not an ice cream shop." - Steven D'Aprano, 2011-08-10, on providing the language with just "more choices" Comparing the relative speed of `i += 1` and `i = i + 1` http://groups.google.com/group/comp.lang.python/browse_thread/thread/db68a23685eb03a9/ Efficiently split and process a large string: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f9122961559e747b/ Fastest way to do string concatenation: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f65e05cd3a230290/ An unexpected interaction between function scope and class namespace: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9c4435d56fdec152/ The GIL, once again: http://mail.python.org/pipermail/python-dev/2011-August/112813.html Three language proposals: allow line breaks at operators (very long thread!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/a80ffc70aeea2116/ repeat the right hand side value of assignment statements, as needed: http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cf460dc9d6262d1/ issue warnings when builtin names are hidden: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1b2dd8552aabf033/ How to generate and send mails: a step by step tutorial http://groups.google.com/group/comp.lang.python/browse_thread/thread/e0793c1007361398/ Best practices when dealing with unknown exceptions: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d8da925e6fa03ec6/ When using extended slicing, behavior of negative stop values is not fully intuitive: http://groups.google.com/group/comp.lang.python/browse_thread/thread/29193779abef5bfb/ It's not easy to check a folder for write access on Windows: http://groups.google.com/group/comp.lang.python/browse_thread/thread/122a47fce5571322/ Advice on how long a function should be: http://groups.google.com/group/comp.lang.python/browse_thread/thread/97076160ebf0f392/ It is relatively easy to confuse the import machinery and make import fail: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3199d1e000b135d/ Non-local variables and exec/eval: a clarification http://groups.google.com/group/comp.lang.python/browse_thread/thread/9f46a4b59f525f59/ An original idea: pure-python templates using the AST http://groups.google.com/group/comp.lang.python/browse_thread/thread/827f4345d4ad5672/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider-blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From PointedEars at web.de Thu Aug 25 16:10:06 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Thu, 25 Aug 2011 22:10:06 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: <9667176.GlLmdWzCzT@PointedEars.de> Stefan Behnel wrote: > Thomas 'PointedEars' Lahn, 25.08.2011 11:29: >> Stefan Behnel wrote: >>> It's totally unreadable to find this in the code: >>> >>> data1.merge_with(data2, true); >>> >>> Requires you to either a) know the underlying signature by heart, or b) >>> look it up before understanding the code. >>> >>> It's a lot harder to argue against this: >>> >>> data1.merge_with(data2, overwrite_duplicates=True) >>[...] >> And you will still have to know the underlying signature to name the >> argument. Worse, with keyword arguments you *have to* look up the >> documentation (i. e., it needs to be well-documented as well) to know its >> name (as the compiler can only tell you "kwargs"). > > Note that code is read more often than it gets written. It is not clear to me why you completely ignored the rest of my counter-argument. As it is, yours is a weak argument. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From clp2 at rebertia.com Thu Aug 25 16:34:24 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 13:34:24 -0700 Subject: Disable pop up menu that triggers upon pressing tab, In-Reply-To: References: Message-ID: On Thu, Aug 25, 2011 at 11:43 AM, Emory Watts wrote: > Hello, I tried to find out how to do this on my own, but searching around > turned up no results. And this is the only way I saw to get a question > answered. I would like know how to disable the pop up predictions menu that > appears when I press tab. I would much rather just be able to tab over, and > I cannot figure out how to disable the menu. Thank you for your time. Which of the myriad Python editors or interpreters is your question in regards to? Cheers, Chris From jenn.duerr at gmail.com Thu Aug 25 16:38:28 2011 From: jenn.duerr at gmail.com (noydb) Date: Thu, 25 Aug 2011 13:38:28 -0700 (PDT) Subject: Adding a ranking based on two fields Message-ID: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> Hello All, Looking for some advice/ideas on how to implement a ranking to a 'scores' field I have. So this scores field has values ranging from 1.00-4. There is also a count field. I want to add a rank field such that all the records have a unique ranking, 1 through the number of records (thousands). The rank is based on the score first, the count second. So, a record with a score of 4 and a count of 385 is ranked higher than a record with a score of 4 and a count of 213 AND higher than record with a score of 3.25 with a count of 4640. My thought was to add the unique score values to a list and loop thru the list... sort records with score=listItem, add ranking... not quite sure how to do this! Any help would be much appreciated! From clp2 at rebertia.com Thu Aug 25 16:53:34 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Aug 2011 13:53:34 -0700 Subject: Adding a ranking based on two fields In-Reply-To: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> References: <9b98790e-f482-48f9-93e9-80b32f6b4583@g31g2000yqh.googlegroups.com> Message-ID: On Thu, Aug 25, 2011 at 1:38 PM, noydb wrote: > Hello All, > > Looking for some advice/ideas on how to implement a ranking to a > 'scores' field I have. ?So this scores field has values ranging from > 1.00-4. ?There is also a count field. ?I want to add a rank field such > that all the records have a unique ranking, 1 through the number of > records (thousands). ?The rank is based on the score first, the count > second. ?So, a record with a score of 4 and a count of 385 is ranked > higher than a record with a score of 4 and a count of 213 AND higher > than record with a score of 3.25 with a count of 4640. > > My thought was to add the unique score values to a list and loop thru > the list... sort records with score=listItem, add ranking... not quite > sure how to do this! things = getListOfYourThings() things.sort(reverse=True, key=lambda item: (item.score, item.count)) for i, thing in enumerate(things): thing.rank = i + 1 Cheers, Chris -- http://rebertia.com From ting at thsu.org Thu Aug 25 16:54:35 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 13:54:35 -0700 (PDT) Subject: Run time default arguments References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> Message-ID: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> On Aug 25, 10:35?am, Arnaud Delobelle wrote: > You're close to the usual idiom: > > def doSomething(debug=None): > ? ? if debug is None: > ? ? ? ? debug = defaults['debug'] > ? ? ... > > Note the use of 'is' rather than '==' > HTH Hmm, from what you are saying, it seems like there's no elegant way to handle run time defaults for function arguments, meaning that I should probably write a sql-esc coalesce function to keep my code cleaner. I take it that most people who run into this situation do this? def coalesce(*args): for a in args: if a is not None: return a return None def doSomething(debug=None): debug = coalesce(debug,defaults['debug']) # blah blah blah -- // T.Hsu From navkirat.py at gmail.com Thu Aug 25 17:09:21 2011 From: navkirat.py at gmail.com (Navkirat Singh) Date: Fri, 26 Aug 2011 02:39:21 +0530 Subject: How to handle application level errors Message-ID: Hi Guys, Not sure if this is the place to ask, but I am trying find out a way to handle application level errors from a global config. Any help would be really appreciated. Regards, Nav -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 25 19:30:59 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 09:30:59 +1000 Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 6:54 AM, wrote: > def doSomething(debug=None): > ?debug = coalesce(debug,defaults['debug']) > ?# blah blah blah > It won't work with a True/False flag, but if you can guarantee that all real options will evaluate as True, you can use a simpler notation: def doSomething(option=None): option=option or defaults['option'] You can't explicitly set option to False/0 with this, but it is a bit cleaner (IMO - some may disagree). ChrisA From ian.g.kelly at gmail.com Thu Aug 25 20:50:37 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 25 Aug 2011 18:50:37 -0600 Subject: Design principles: no bool arguments In-Reply-To: <1660212.aK4W3vaeNJ@PointedEars.de> References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: On Thu, Aug 25, 2011 at 3:29 AM, Thomas 'PointedEars' Lahn wrote: > Both variants work (even in Py3) if you only define > > class Data(object): > ?def merge_with(self, bar, overwrite_duplicates): > ? ?pass > > data1 = Data() > data2 = Data() > > You have to define > > class Data(object): > ?def merge_with(self, bar, **kwargs): > ? ?# do something with kwargs['overwrite_duplicates'] > ? ?pass > > data1 = Data() > data2 = Data() > > so that > > data1.merge_with(data2, True); > > is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 > given)"). > > IOW, this advantage of Python in readability is not only caused by API > definition, but also by how the API is used. ?It might turn into a > disadvantage if key lookups make the code expensive memory- and runtime > wise. > > And you will still have to know the underlying signature to name the > argument. ?Worse, with keyword arguments you *have to* look up the > documentation (i. e., it needs to be well-documented as well) to know its > name (as the compiler can only tell you "kwargs"). Note though that Python 3 adds actual keyword-only arguments, which address all of your points: class Data: def merge_with(self, bar, *, overwrite_duplicates): pass >>> data1.merge_with(data2, True) TypeError: merge_with() takes exactly 2 positional arguments (3 given) >>> data1.merge_with(data2) TypeError: merge_with() needs keyword-only argument overwrite_duplicates >>> data1.merge_with(data2, overwrite_duplicates=True) >>> Of course, in Python 2 that definition would be a syntax error, so you can't really take advantage of it if you need compatibility. From roy at panix.com Thu Aug 25 21:56:31 2011 From: roy at panix.com (Roy Smith) Date: Thu, 25 Aug 2011 21:56:31 -0400 Subject: [OT-ish] Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e55f604$0$29973$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > [1] This is the Internet. There's *always* a certain amount of disagreement. No there's not. From chetan.harjani at gmail.com Thu Aug 25 23:31:16 2011 From: chetan.harjani at gmail.com (Chetan Harjani) Date: Fri, 26 Aug 2011 09:01:16 +0530 Subject: Learning python reading software source code Message-ID: Hello friends, I have learned the basic syntax of python through the book HOW TO THINK LIKE A COMPUTER SCIENTIST n by reading first 10-11 chapters of Apress-BEGINNING PROGRAMMING FROM NOVICE TO PROFESSIONAL. (btw it was really very boring) I am looking forward to learn further by understanding source code of applications built in python. I guess i will begin with reading the source code of MIRO http://www.getmiro.com/ . So I am looking for suggestions on how one can understand the code better. Any specific references I should look in as I stumble upon libraries n functions while reading or just the python official docs would be enough? thanking you -- Chetan H Harjani -------------- next part -------------- An HTML attachment was scrubbed... URL: From tahoemph at gmail.com Thu Aug 25 23:59:36 2011 From: tahoemph at gmail.com (Michael Hunter) Date: Thu, 25 Aug 2011 20:59:36 -0700 Subject: Learning python reading software source code In-Reply-To: References: Message-ID: On Thu, Aug 25, 2011 at 8:31 PM, Chetan Harjani wrote: [read book, picked miro to read through] > So I am looking for suggestions on how one can understand the code better. > Any specific references I should look in as I stumble upon libraries n > functions while reading or just the python official docs would be enough? Mess the code up. Make changes to it. Alternate between writing code, often reading code, and occasionally reading books. The act of having to mod the code and debug those modifications will lead you through many documents. But the documents on their own shouldn't usu. be your guide. A note on reading books. A book or two can be useful for learning a language. But beyond that books about specific language have quickly diminishing returns. Instead read books about high order concepts (e.g. software engineering, algorithms, problem domain specifics). Michael From saraanderson24 at gmail.com Fri Aug 26 01:11:12 2011 From: saraanderson24 at gmail.com (Sara Anderson) Date: Thu, 25 Aug 2011 22:11:12 -0700 (PDT) Subject: CNN Reports World`s First Pregnant Man Ever. (Watch it) Message-ID: WATCH WORLD`S MOST BEAUTIFUL CITY SCAPE PLACES. http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ http://wallpapers-stocks.blogspot.com/ CNN Reports World`s First Pregnant Man Ever. (Watch it) http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ http://funnyvideos-2011.blogspot.com/ From ting at thsu.org Fri Aug 26 01:20:29 2011 From: ting at thsu.org (ting at thsu.org) Date: Thu, 25 Aug 2011 22:20:29 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: On Aug 23, 7:59?am, smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? My suggestion is to think how you would test the function, in order to get 100% code coverage. The parts of the function that are difficult to test, those are the parts that you want to pull out into their own separate function. For example, a block of code within a conditional statement, where the test condition cannot be passed in, is a prime example of a block of code that should be pulled out into a separate function. Obviously, there are times where this is not practical - exception handling comes to mind - but that should be your rule of thumb. If a block of code is hard to test, pull it out into it's own function, so that it's easier to test. -- // T.Hsu From joho.smithury at gmail.com Fri Aug 26 01:21:56 2011 From: joho.smithury at gmail.com (John Smithury) Date: Fri, 26 Aug 2011 13:21:56 +0800 Subject: How cai i encode url Message-ID: Hi pythons. following is my code # -*- coding: utf8 -*- import urllib2 import urllib url = "http://a.shanting.mobi/????/???/list" print url p1=u"????".encode('utf8') p2=u"???".encode('utf8') encodeurl = "http://a.shanting.mobi/"+p1+"/"+p2+"/"+"list" print encodeurl mp3file = urllib2.urlopen(encodeurl) output = open("list1", "wb") output.write(mp3file.read()) output.close ----------------------------------- but error following, why? what can i encode the url? Traceback (most recent call last): File "D:/readurl.py", line 11, in mp3file = urllib2.urlopen(encodeurl) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 398, in open response = meth(req, response) File "C:\Python27\lib\urllib2.py", line 511, in http_response 'http', request, response, code, msg, hdrs) File "C:\Python27\lib\urllib2.py", line 436, in error return self._call_chain(*args) File "C:\Python27\lib\urllib2.py", line 370, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 519, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 404: Not Found -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Aug 26 01:50:48 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Aug 2011 07:50:48 +0200 Subject: How cai i encode url References: Message-ID: John Smithury wrote: > Hi pythons. > > following is my code > > # -*- coding: utf8 -*- > import urllib2 > import urllib > > url = "http://a.shanting.mobi/????/???/list" > print url > p1=u"????".encode('utf8') > p2=u"???".encode('utf8') > encodeurl = "http://a.shanting.mobi/"+p1+"/"+p2+"/"+"list" > print encodeurl > mp3file = urllib2.urlopen(encodeurl) > output = open("list1", "wb") > output.write(mp3file.read()) > output.close > > ----------------------------------- > but error following, why? what can i encode the url? The following seems to work: # -*- coding: utf-8 -*- import urllib2 url = u"http://a.shanting.mobi/????/???/list" encoded_url = urllib2.quote(url.encode("utf-8"), safe=":/") instream = urllib2.urlopen(encoded_url) with open("list1", "wb") as outstream: outstream.write(instream.read()) From k.sahithi2862 at gmail.com Fri Aug 26 02:32:39 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 25 Aug 2011 23:32:39 -0700 (PDT) Subject: NEW UPDATES Message-ID: <9b8cb42b-68b9-4322-9a52-9efe1bab8c5b@l8g2000prd.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From affdfsdfdsfsd at b.com Fri Aug 26 03:56:26 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 07:56:26 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: > On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >> Hi all! cut > Untested: > > from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, > stderr=PIPE) > tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) > # Read from tee.stdout to get any error messages > > Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 > > Cheers, > Chris mmm, it doesn't seem to work... any other hints guys? From clp2 at rebertia.com Fri Aug 26 04:20:02 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Aug 2011 01:20:02 -0700 Subject: bash command, get stdErr In-Reply-To: <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Message-ID: On Fri, Aug 26, 2011 at 12:56 AM, Tracubik wrote: > Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: >> On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >>> Hi all! > > cut > >> Untested: >> >> from subprocess import Popen, PIPE sudo = Popen("sudo las", shell=True, >> stderr=PIPE) >> tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) >> # Read from tee.stdout to get any error messages >> >> Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 > > mmm, it doesn't seem to work... How so? Seems to work in an admittedly dirt simple test where I do tee.stdout.read(). You might need to fiddle with buffering settings depending on how you're processing the output. Cheers, Chris From affdfsdfdsfsd at b.com Fri Aug 26 04:26:32 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 08:26:32 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> Message-ID: <4e5758b8$0$44208$4fafbaef@reader1.news.tin.it> Il Thu, 25 Aug 2011 08:25:59 +0000, Tracubik ha scritto: > Hi all! > i'ld like to execute via Python this simple bash command: > > sudo las > > las is intended to be a typo for "ls" > > the point is that i want to see in the terminal the stderr message (that > is "sorry, try again" if i insert the wrong password or "sudo: las: > command not found" otherwise) > > i can simply do it with subprocess.POpen() or subprocess.Call() but as > far as i know i have two choice: > 1) s = subprocess.Popen('sudo las', shell=True, stderr=subprocess.PIPE) > > in this way i catch the stderr messages BUT they are not "printed" in > the terminal > > 2) s = subprocess.Popen('sudo las', shell=True, stderr=none) > in this way i "print" the message in the terminal but i can retrieve > they (the error messages) when the command is executed maybe i've solved it: sudo las 2>&1 | tee tmp.txt in this way i redirect stderr to stdout (the terminal) and i tee it in tmp.txt. The only problem is the output and error messages are joined togheter but i think i can deal with it. :-D MedeoTL From affdfsdfdsfsd at b.com Fri Aug 26 05:20:02 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 26 Aug 2011 09:20:02 GMT Subject: bash command, get stdErr References: <4e560717$0$15665$4fafbaef@reader2.news.tin.it> <4e5751aa$0$44208$4fafbaef@reader1.news.tin.it> Message-ID: <4e576542$0$44208$4fafbaef@reader1.news.tin.it> Il Fri, 26 Aug 2011 01:20:02 -0700, Chris Rebert ha scritto: > On Fri, Aug 26, 2011 at 12:56 AM, Tracubik wrote: >> Il Thu, 25 Aug 2011 01:52:25 -0700, Chris Rebert ha scritto: >>> On Thu, Aug 25, 2011 at 1:25 AM, Tracubik wrote: >>>> Hi all! >> >> cut >> >>> Untested: >>> >>> from subprocess import Popen, PIPE sudo = Popen("sudo las", >>> shell=True, >>> stderr=PIPE) >>> tee = Popen(["tee", "/dev/stderr"], stdin=sudo.stderr, stdout=PIPE) >>> # Read from tee.stdout to get any error messages >>> >>> Further info: http://en.wikipedia.org/wiki/Tee_%28command%29 >> >> mmm, it doesn't seem to work... > > How so? Seems to work in an admittedly dirt simple test where I do > tee.stdout.read(). > You might need to fiddle with buffering settings depending on how you're > processing the output. oh, yeah! now it work thanks! don't really know why it wasn't working yesterday, i've retried today and it work very well :-D MedeoTL From gandalf at shopzeus.com Fri Aug 26 05:45:39 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Aug 2011 11:45:39 +0200 Subject: PUT with proxy-support In-Reply-To: References: <4E56376B.1080603@shopzeus.com> Message-ID: <4E576B43.3010501@shopzeus.com> Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2ZCa8v/pycurl-7.19.0/egg-dist-tmp-DyHFls > Using curl-config (libcurl 7.12.1) > src/pycurl.c:42:20: Python.h: No such file or directory > src/pycurl.c:43:22: pythread.h: No such file or directory > src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to > compile pycurl." > src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to > compile pycurl." > [... Error Clipped] > error: Setup script exited with error: command '/usr/bin/gcc' failed > with exit status 1 I'm not familiar with red hat. But looks like this is now a sysadmin problem. I could install pycurl under freebsd and ubuntu too. I have some code that might be able to PUT through a proxy for you. Please look at the attached file. You can setup a proxy this way: import MozzillaEmulator MozzillaEmulator.DEFAULT_PROXIES = { 'http':'http://user:password at proxy.host.com:3128', 'https':'http://user:password at proxy.host.com:3128', } And here is how you use it: dl = MozillaEmulator.MozillaEmulator() put_url = "http://some_url_to_put_to" headers = {'Content-Type':'application/xml;charset=UTF-8'} data = open("some_file","rb").read() response = dl.download(put_url,data,headers,put_method=True) If you don't set the put_method flag, then it will POST instead. (But in that case, post data must be a valid post data field fields and values.) If you don't give post_data then it will GET. The PUT method was tested without a proxy, and the GET and POST methods were tested with and without proxy. Actually I have tried to do PUT through a proxy, but it didn't work. But it was a restriction on the proxy side. (As far as I can recall, the error message came from the proxy server, something about unsupported request?). So it *might* work for you, with the right proxy server that supports PUT requests. Also be aware that this version uses urllib2. Although it can use https protocol, it doesn't check the server's certificate. Good luck, Laszlo -------------- next part -------------- A non-text attachment was scrubbed... Name: MozillaEmulator.py Type: text/x-python Size: 12093 bytes Desc: not available URL: From roy at panix.com Fri Aug 26 07:15:52 2011 From: roy at panix.com (Roy Smith) Date: Fri, 26 Aug 2011 07:15:52 -0400 Subject: is there any principle when writing python function References: Message-ID: In article , ting at thsu.org wrote: > On Aug 23, 7:59?am, smith jack wrote: > > i have heard that function invocation in python is expensive, but make > > lots of functions are a good design habit in many other languages, so > > is there any principle when writing python function? > > for example, how many lines should form a function? > > My suggestion is to think how you would test the function, in order to > get 100% code coverage. I'm not convinced 100% code coverage is an achievable goal for any major project. I was once involved in a serious code coverage program. We had a large body of code (100's of KLOC of C++) which we were licensing to somebody else. The customer was insisting that we do code coverage testing and set a standard of something like 80% coverage. There was a dedicated team of about 4 people working on this for the better part of a year. They never came close to 80%. More like 60%, and that was after radical surgery to eliminate dead code and branches that couldn't be reached. The hard parts are testing the code that deals with unusual error conditions caused by interfaces to the external world. The problem is, it's just damn hard to simulate all the different kinds of errors that can occur. This was network intensive code. Every call that touches the network can fail in all sorts of ways that are near impossible to simulate. We also had lots of code that tried to deal with memory exhaustion. Again, that's hard to simulate. I'm not saying code coverage testing is a bad thing. Many of the issues I mention above could have been solved with additional abstraction layers, but that adds complexity of its own. Certainly, designing a body of code to be testable from the get-go is a far superior to trying to retrofit tests to an existing code base (which is what we were doing). > The parts of the function that are difficult > to test, those are the parts that you want to pull out into their own > separate function. > > For example, a block of code within a conditional statement, where the > test condition cannot be passed in, is a prime example of a block of > code that should be pulled out into a separate function. Maybe. In general, it's certainly true that a bunch of smallish functions, each of which performs exactly one job, is easier to work with than a huge ball of spaghetti code. On the other hand, interfaces are a common cause of bugs. When you pull a hunk of code out into its own function, you create a new interface. Sometimes that adds complexity (and bugs) of its own. > Obviously, there are times where this is not practical - exception > handling comes to mind - but that should be your rule of thumb. If a > block of code is hard to test, pull it out into it's own function, so > that it's easier to test. In general, that's good advice. You'll also usually find that code which is easy to test is also easy to understand and easy to modify. From jehugaleahsa at gmail.com Fri Aug 26 08:33:29 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 05:33:29 -0700 (PDT) Subject: Mastering Python... Best Resources? Message-ID: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> I know the Python syntax pretty well. I know a lot of the libraries and tools. When I see professional Python programmer's code, I am often blown away with the code. I realized that even though I know the language, I know nothing about using it effectively. I would like to start using Python more in my professional career. Where can I find resources that will take my skills to the next level? I would prefer to watch a streaming video series, if possible. I've read quite a few books about Python. They cover a lot of topics, but none of them covered common conventions or hacks. I mean, I got good at C++ reading books by Scott Meyers, who concentrated on common idioms, things to avoid, the proper way to do things, etc. Right now, I am at that point where I know how to do write just about anything in the language. However, I still have that hesitation I get when I'm just not sure what's the right way. From rosuav at gmail.com Fri Aug 26 08:44:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 22:44:28 +1000 Subject: Mastering Python... Best Resources? In-Reply-To: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 10:33 PM, Travis Parks wrote: > I know the Python syntax pretty well. I know a lot of the libraries > and tools. When I see professional Python programmer's code, I am > often blown away with the code. I realized that even though I know the > language, I know nothing about using it effectively. I would say that there are three aspects to using Python effectively: 1) Understanding the syntax, which you've mastered. 2) Understanding the philosophy 3) Knowing algorithms. The second is more or less what you're asking for, but the language-independent third may be more useful to you. This is correct Python syntax (#1), and decently Pythonic style (#2), but a hopelessly flawed algorithm (#3): def fib(x): return fib(x-1) + fib(x-2) if x>2 else 1 Or: def fib(x): if x<3: return 1 return fib(x-1) + fib(x-2) Both versions are clean and easy to read, but neither would be what I'd call brilliant code. You can get books on algorithms from all sorts of places, and with a very few exceptions, everything you learn with apply to Python and also to every other language you use. ChrisA From anand.shashwat at gmail.com Fri Aug 26 08:51:54 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Aug 2011 18:21:54 +0530 Subject: PUT with proxy-support In-Reply-To: <4E576B43.3010501@shopzeus.com> References: <4E56376B.1080603@shopzeus.com> <4E576B43.3010501@shopzeus.com> Message-ID: On Fri, Aug 26, 2011 at 3:15 PM, Laszlo Nagy wrote: > Running pycurl-7.19.0/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-2ZCa8v/**pycurl-7.19.0/egg-dist-tmp-**DyHFls > >> Using curl-config (libcurl 7.12.1) >> src/pycurl.c:42:20: Python.h: No such file or directory >> src/pycurl.c:43:22: pythread.h: No such file or directory >> src/pycurl.c:58:4: #error "Need Python version 2.2 or greater to compile >> pycurl." >> src/pycurl.c:61:4: #error "Need libcurl version 7.19.0 or greater to >> compile pycurl." >> [... Error Clipped] >> error: Setup script exited with error: command '/usr/bin/gcc' failed with >> exit status 1 >> > I'm not familiar with red hat. But looks like this is now a sysadmin > problem. I could install pycurl under freebsd and ubuntu too. > > I have some code that might be able to PUT through a proxy for you. Please > look at the attached file. > > You can setup a proxy this way: > > import MozzillaEmulator > MozzillaEmulator.DEFAULT_**PROXIES = { > 'http':'http://user:password@**proxy.host.com:3128 > ', > 'https':'http://user:password@**proxy.host.com:3128 > ', > } > > And here is how you use it: > > dl = MozillaEmulator.**MozillaEmulator() > put_url = "http://some_url_to_put_to" > headers = {'Content-Type':'application/**xml;charset=UTF-8'} > data = open("some_file","rb").read() > response = dl.download(put_url,data,**headers,put_method=True) > > If you don't set the put_method flag, then it will POST instead. (But in > that case, post data must be a valid post data field fields and values.) If > you don't give post_data then it will GET. The PUT method was tested without > a proxy, and the GET and POST methods were tested with and without proxy. > > Actually I have tried to do PUT through a proxy, but it didn't work. But it > was a restriction on the proxy side. (As far as I can recall, the error > message came from the proxy server, something about unsupported request?). > So it *might* work for you, with the right proxy server that supports PUT > requests. > > Also be aware that this version uses urllib2. Although it can use https > protocol, it doesn't check the server's certificate. > > > Mozilla Emulator works like a charm. Also managed to install pycurl and the same works too. Thanks. :) ~Shashwat -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Fri Aug 26 08:58:46 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 05:58:46 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 26, 8:44?am, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:33 PM, Travis Parks wrote: > > I know the Python syntax pretty well. I know a lot of the libraries > > and tools. When I see professional Python programmer's code, I am > > often blown away with the code. I realized that even though I know the > > language, I know nothing about using it effectively. > > I would say that there are three aspects to using Python effectively: > > 1) Understanding the syntax, which you've mastered. > 2) Understanding the philosophy > 3) Knowing algorithms. > > The second is more or less what you're asking for, but the > language-independent third may be more useful to you. This is correct > Python syntax (#1), and decently Pythonic style (#2), but a hopelessly > flawed algorithm (#3): > > def fib(x): > ? ? return fib(x-1) + fib(x-2) if x>2 else 1 > > Or: > > def fib(x): > ? ? if x<3: return 1 > ? ? return fib(x-1) + fib(x-2) > > Both versions are clean and easy to read, but neither would be what > I'd call brilliant code. > > You can get books on algorithms from all sorts of places, and with a > very few exceptions, everything you learn with apply to Python and > also to every other language you use. > > ChrisA > > Well, I think I am going more for #2. I know about things like data structures and algorithms... in your case memoization. Here is a good example of what I am talking about. Someone took the time to write quicksort in a single line of code: def qsortr(list): return [] if list==[] else qsortr([x for x in list[1:] if x < list[0]]) + [list[0]] + qsortr([x for x in list[1:] if x >= list[0]]) I would never even think to use list comprehensions and splicing like that. I would write this code the same way I'd write it in C++/C#. I'm aware that writing code like the above example is probably bad practice (and that the implementation here has some major inefficiencies), but it is the "mentality" that goes into it. I haven't gotten to the point where I can truly use the language features to my full advantage. I haven't seen enough "tricks" to be effective. I feel like there is so much of the language I am not utilizing because I'm still thinking in terms of a less powerful language. I was hoping to find a series that would familiarize me with how real Python programmers get things done. From chetan.harjani at gmail.com Fri Aug 26 09:06:38 2011 From: chetan.harjani at gmail.com (Chetan Harjani) Date: Fri, 26 Aug 2011 18:36:38 +0530 Subject: Learning python reading software source code In-Reply-To: References: Message-ID: Thanks Michael :) . I will keep your suggestions in mind. On Fri, Aug 26, 2011 at 9:01 AM, Chetan Harjani wrote: > Hello friends, > > I have learned the basic syntax of python through the book HOW TO THINK > LIKE A COMPUTER SCIENTIST n by reading first 10-11 chapters of > Apress-BEGINNING PROGRAMMING FROM NOVICE TO PROFESSIONAL. > (btw it was really very boring) > > I am looking forward to learn further by understanding source code of > applications built in python. I guess i will begin with reading the source > code of MIRO http://www.getmiro.com/ . > > So I am looking for suggestions on how one can understand the code better. > Any specific references I should look in as I stumble upon libraries n > functions while reading or just the python official docs would be enough? > > thanking you > -- > Chetan H Harjani > > > -- Chetan H Harjani -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Fri Aug 26 09:08:45 2011 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Aug 2011 09:08:45 -0400 Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: Chris Angelico wrote: [ ... ] > You can get books on algorithms from all sorts of places, and with a > very few exceptions, everything you learn with apply to Python and > also to every other language you use. I liked _Programming Pearls_ by Jon Bentley. No reference to Python -- that would be the O.P.'s job. Mel. From rosuav at gmail.com Fri Aug 26 09:28:03 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Aug 2011 23:28:03 +1000 Subject: Mastering Python... Best Resources? In-Reply-To: References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks wrote: > I haven't gotten to the point where I can truly use the language > features to my full advantage. I haven't seen enough "tricks" to be > effective. I feel like there is so much of the language I am not > utilizing because I'm still thinking in terms of a less powerful > language. I was hoping to find a series that would familiarize me with > how real Python programmers get things done. > Ah! Then I recommend poking around with the standard library. No guarantees that it's ALL good code, but it probably will be. In any case, it sounds like you're well able to evaluate code in your own head and recognize the good from the ugly. In the source distribution (I'm looking at the latest straight from hg, but presumably it's the same everywhere), there's a whole lot of .py files in ./Lib - there's sure to be some good examples in there somewhere. ChrisA From dreyemi at gmail.com Fri Aug 26 09:44:21 2011 From: dreyemi at gmail.com (Kayode Odeyemi) Date: Fri, 26 Aug 2011 14:44:21 +0100 Subject: Mastering Python... Best Resources? In-Reply-To: References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: On Fri, Aug 26, 2011 at 2:28 PM, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks > wrote: > > I haven't gotten to the point where I can truly use the language > > features to my full advantage. I haven't seen enough "tricks" to be > > effective. I feel like there is so much of the language I am not > > utilizing because I'm still thinking in terms of a less powerful > > language. I was hoping to find a series that would familiarize me with > > how real Python programmers get things done. > > > > Ah! Then I recommend poking around with the standard library. No > guarantees that it's ALL good code, but it probably will be. In any > case, it sounds like you're well able to evaluate code in your own > head and recognize the good from the ugly. > > In the source distribution (I'm looking at the latest straight from > hg, but presumably it's the same everywhere), there's a whole lot of > .py files in ./Lib - there's sure to be some good examples in there > somewhere. > > ChrisA > As a rule of thumb, I have learnt to always make the python source my best resource. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Odeyemi 'Kayode O. http://www.sinati.com. t: @charyorde -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Fri Aug 26 10:10:34 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 07:10:34 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: <81eba77b-00b7-43bd-b8e4-988812716a51@hr10g2000vbb.googlegroups.com> On Aug 26, 9:28?am, Chris Angelico wrote: > On Fri, Aug 26, 2011 at 10:58 PM, Travis Parks wrote: > > I haven't gotten to the point where I can truly use the language > > features to my full advantage. I haven't seen enough "tricks" to be > > effective. I feel like there is so much of the language I am not > > utilizing because I'm still thinking in terms of a less powerful > > language. I was hoping to find a series that would familiarize me with > > how real Python programmers get things done. > > Ah! Then I recommend poking around with the standard library. No > guarantees that it's ALL good code, but it probably will be. In any > case, it sounds like you're well able to evaluate code in your own > head and recognize the good from the ugly. > > In the source distribution (I'm looking at the latest straight from > hg, but presumably it's the same everywhere), there's a whole lot of > .py files in ./Lib - there's sure to be some good examples in there > somewhere. > > ChrisA > > I've been thinking about going through the docs on the main website. Cool thing is it has links to the actual lib files. I was checking out string.py yesterday. I was searching all over youtube for good videos of some type. Google has an intro course, but it didn't really do much for me. Microsoft has these series called 'Going Deep' that occasionally runs something super in-depth. The videos on C++ and the STL are really excellent. I was hoping someone had taken the time to create a similar series for Python. I can't help but remember my one professor in college, who really made pointers, bitwise arithmetic and low level OS operations make sense. He explained to us a lot about how the STL worked and showed us tons of C++/STL hacks. I probably learned more in the 2 years I had classes with him than I have in all the time I've programmed. To get that type of insight into another language, like Python, would be the ultimate gift for someone like me. Personally, I am tired of working in languages that don't strongly support functional paradigms. From dboland9 at fastmail.fm Fri Aug 26 10:18:10 2011 From: dboland9 at fastmail.fm (Dave Boland) Date: Fri, 26 Aug 2011 10:18:10 -0400 Subject: Python IDE/Eclipse Message-ID: I'm looking for a good IDE -- easy to setup, easy to use -- for Python. Any suggestions? I use Eclipse for other projects and have no problem with using it for Python, except that I can't get PyDev to install. It takes forever, then produces an error that makes no sense. An error occurred while installing the items session context was:(profile=PlatformProfile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). Cannot connect to keystore. This trust engine is read only. The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. Any suggestions on getting this to work? Thanks, Dave From tdldev at gmail.com Fri Aug 26 10:43:04 2011 From: tdldev at gmail.com (Verde Denim) Date: Fri, 26 Aug 2011 10:43:04 -0400 Subject: dpkg Message-ID: I downloaded cx_oracle for installation to Ubuntu 11.04 64bit this morning, and the alien and dpkg operations worked fine, but on testing the import, the error msg shows that the oracle client lib is missing. I found a thread that mentioned installing the oracle instant client on 11.04 to resolve this, and alien and dpkg worked fine. Yet, when I go into python (runing 2.7) and import cx_Oracle, I get "ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory. Looking for this with find / -name libclntsh.so.11.1 -print produces /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 I'm confused as to why Python doesn't see it... -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Aug 26 11:12:32 2011 From: roy at panix.com (Roy Smith) Date: Fri, 26 Aug 2011 11:12:32 -0400 Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: In article <2309ec4b-e9a3-4330-9983-1c621ac16163 at ea4g2000vbb.googlegroups.com>, Travis Parks wrote: > I know the Python syntax pretty well. I know a lot of the libraries > and tools. When I see professional Python programmer's code, I am > often blown away with the code. I realized that even though I know the > language, I know nothing about using it effectively. In a sense, I'm in the same boat as you. I've been using Python since before the 2.0 series, and I tend to think of the language in much the same way as I did back then. Which is to say I don't use the language, as it currently exists, as effectively as I might. Here's some things I suggest you look at: Iterators. This is such a powerful concept. When I started with the language, iterators largely meant the difference between range() and xrange(). Now we've got a whole ecosystem which has grown up around them (x + " comprehension" for x in {'list', 'dictionary', 'set'}), not to mention generators and generator expressions. And the itertools library. Decorators. Another powerful concept. We use these in our web servers for all sorts of cool things. Adding cacheing. Imposing prerequisites on route calls. I still don't think of using these immediately, but I do see the notational convenience they provide for many things. Context Managers. One of the (very few) things that I always found lacking in Python compared to C++ was deterministic object destruction. Context managers give you this. I'm still exploring all the neat things you can do with them. The full range of containers. I started with lists, tuples, and dictionaries. Now we've got sets, frozensets, named tuples, deques, Counters, defaultdicts (I love those), heaps, and I'm sure a few others I've missed. List and dicts are such well designed containers, you can do almost anything with just those two, but all the other new ones often make things quicker, simpler, and more obvious. The profiler. Most people obsess about performance early on and don't realize that most of their guesses about what's fast and what's slow are probably wrong. Learn to use the profiler and understand what it's telling you. Unittest. Testing is, in general, a neglected practice in most software development shops, and that's a shame. Python has some really good capabilities to support testing which you should get familiar with. Unittest is just one of them. There's also doctest, nose, and a bunch of other contributed modules. Look at them all, learn at least one of them well, and use it for everything you write. > I've read quite a few books about Python. They cover a lot of topics, > but none of them covered common conventions or hacks. I mean, I got > good at C++ reading books by Scott Meyers, who concentrated on common > idioms, things to avoid, the proper way to do things, etc. Ugh. The problem with Meyers's books is that they are needed in the first place. C++ is such a horribly complicated language, you really can't use it without making a serious study of it. There's too many gotchas that you MUST know to avoid disaster with even the most basic programs. Python isn't that way. You can learn a small, basic subset of the language and get a lot done. You may not be doing things the most effective way, but you're also not going to be looking at memory corruption because you didn't understand the details of object lifetimes or how type promotion, function overloading, and implicit temporary object construction all interact. From zcdziura at gmail.com Fri Aug 26 11:17:02 2011 From: zcdziura at gmail.com (Zach Dziura) Date: Fri, 26 Aug 2011 08:17:02 -0700 (PDT) Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: <35acafee-2e39-4734-a270-2294d69e6a55@glegroupsg2000goo.googlegroups.com> I've honestly always used either PyDev or IDLE. However, Python is pretty easy to usd without a big IDE slowing you down, so you could also use a developer's text editor like Notepad++ or gedit and still be good. From kwatford at gmail.com Fri Aug 26 11:17:58 2011 From: kwatford at gmail.com (Ken Watford) Date: Fri, 26 Aug 2011 11:17:58 -0400 Subject: dpkg In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 10:43 AM, Verde Denim wrote: > Looking for this with find / -name libclntsh.so.11.1 -print produces > /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 > > I'm confused as to why Python doesn't see it... Try running "sudo ldconfig". From rantingrick at gmail.com Fri Aug 26 11:20:43 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 08:20:43 -0700 (PDT) Subject: is there any principle when writing python function References: Message-ID: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> On Aug 26, 6:15?am, Roy Smith wrote: > Maybe. ?In general, it's certainly true that a bunch of smallish > functions, each of which performs exactly one job, is easier to work > with than a huge ball of spaghetti code. ? Obviously you need to google the definition of "spaghetti code". When you move code out of one function and create another function you are contributing to the "spaghetti-ness" of the code. Think of plate of spaghetti and how the noodles are all intertwined and without order. Likewise when you go to one function and have to follow the trial of one or more helper functions you are creating a twisting and unordered progression of code -- sniff-sniff, do you smell what i smell? Furthermore: If you are moving code out of one function to ONLY be called by that ONE function then you are a bad programmer and should have your editor taken away for six months. You should ONLY create more func/methods if those func/methods will be called from two or more places in the code. The very essence of func/meths is the fact that they are reusable. It might still be spaghetti under that definition (of which ALL OOP code actually is!) however it will be as elegant as spaghetti can be. > On the other hand, interfaces > are a common cause of bugs. ?When you pull a hunk of code out into its > own function, you create a new interface. ?Sometimes that adds > complexity (and bugs) of its own. Which is it? You cannot have it both ways. You're straddling the fence here like a dirty politician. Yes, this subject IS black and white! From tdldev at gmail.com Fri Aug 26 11:25:12 2011 From: tdldev at gmail.com (Verde Denim) Date: Fri, 26 Aug 2011 11:25:12 -0400 Subject: dpkg In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 11:17 AM, Ken Watford wrote: > On Fri, Aug 26, 2011 at 10:43 AM, Verde Denim wrote: > > Looking for this with find / -name libclntsh.so.11.1 -print produces > > /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1 > > > > I'm confused as to why Python doesn't see it... > > Try running "sudo ldconfig". > That was the missing link - thanks! works fine now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From treleven.lloyd at gmail.com Fri Aug 26 11:35:30 2011 From: treleven.lloyd at gmail.com (lblake) Date: Fri, 26 Aug 2011 08:35:30 -0700 (PDT) Subject: Unit test failing please help Message-ID: Hi I am new to python I am at bit lost as to why my unit test is failing below is the code and the unit test: class Centipede(object): legs, stomach def __init__(self): def __str__(self): return ','.join(self.stomach) def __call__(self,*args): [self.stomach.append(arg) for arg in args] #self.stomach.append(args) def __repr__(self): return ','.join(self.legs) def __setattr__(self, key, value): print("setting %s to %s" % (key, repr(value))) if key in ([]): self.legs.append(key) super(Centipede, self).__setattr__(self, key,value) unit test code: import unittest from centipede import Centipede class TestBug(unittest.TestCase): def test_stomach(self): ralph = Centipede() ralph('chocolate') ralph('bbq') ralph('cookies') ralph('salad') self.assertEquals(ralph.__str__(), 'chocolate,bbq,cookies,salad') def test_legs(self): ralph = Centipede() ralph.friends = ['Steve', 'Daniel', 'Guido'] ralph.favorite_show = "Monty Python's Flying Circus" ralph.age = '31' self.assertEquals(ralph.__repr__(),'' ) if __name__ == "__main__": unittest.main() error message generated when running the test: AttributeError: 'Centipede' object has no attribute 'legs' AttributeError: 'Centipede' object has no attribute 'stomach' Any suggestions as to where I am going wrong? From mlindo at gmail.com Fri Aug 26 11:36:37 2011 From: mlindo at gmail.com (Moises Alberto Lindo Gutarra) Date: Fri, 26 Aug 2011 10:36:37 -0500 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: I like Aptana Studio http://www.aptana.com/products/studio3 2011/8/26 Dave Boland : > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any > suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, then > produces an error that makes no sense. > > An error occurred while installing the items > ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > ?Cannot connect to keystore. > ?This trust engine is read only. > ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > not found. > > > Any suggestions on getting this to work? > > Thanks, > Dave > -- > http://mail.python.org/mailman/listinfo/python-list > -- Atte. Mois?s Alberto Lindo Gutarra Asesor - Desarrollador Java / Open Source Linux Registered User #431131 - http://counter.li.org/ Cel: (511) 995081720 - Rpm: *548913 EMail: mlindo at gmail.com MSN: mlindo at tumisolutions.com From jehugaleahsa at gmail.com Fri Aug 26 11:36:54 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Fri, 26 Aug 2011 08:36:54 -0700 (PDT) Subject: Mastering Python... Best Resources? References: <2309ec4b-e9a3-4330-9983-1c621ac16163@ea4g2000vbb.googlegroups.com> Message-ID: <6087b517-23ef-4e86-948b-ea327eb19677@18g2000yqu.googlegroups.com> On Aug 26, 11:12?am, Roy Smith wrote: > In article > <2309ec4b-e9a3-4330-9983-1c621ac16... at ea4g2000vbb.googlegroups.com>, > ?Travis Parks wrote: > > > I know the Python syntax pretty well. I know a lot of the libraries > > and tools. When I see professional Python programmer's code, I am > > often blown away with the code. I realized that even though I know the > > language, I know nothing about using it effectively. > > In a sense, I'm in the same boat as you. ?I've been using Python since > before the 2.0 series, and I tend to think of the language in much the > same way as I did back then. ?Which is to say I don't use the language, > as it currently exists, as effectively as I might. > > Here's some things I suggest you look at: > > Iterators. ?This is such a powerful concept. ?When I started with the > language, iterators largely meant the difference between range() and > xrange(). ?Now we've got a whole ecosystem which has grown up around > them (x + " comprehension" for x in {'list', 'dictionary', 'set'}), not > to mention generators and generator expressions. ?And the itertools > library. > > Decorators. ?Another powerful concept. ?We use these in our web servers > for all sorts of cool things. ?Adding cacheing. ?Imposing prerequisites > on route calls. ?I still don't think of using these immediately, but I > do see the notational convenience they provide for many things. > > Context Managers. ?One of the (very few) things that I always found > lacking in Python compared to C++ was deterministic object destruction. ? > Context managers give you this. ?I'm still exploring all the neat things > you can do with them. > > The full range of containers. ?I started with lists, tuples, and > dictionaries. ?Now we've got sets, frozensets, named tuples, deques, > Counters, defaultdicts (I love those), heaps, and I'm sure a few others > I've missed. ?List and dicts are such well designed containers, you can > do almost anything with just those two, but all the other new ones often > make things quicker, simpler, and more obvious. > > The profiler. ?Most people obsess about performance early on and don't > realize that most of their guesses about what's fast and what's slow are > probably wrong. ?Learn to use the profiler and understand what it's > telling you. > > Unittest. ?Testing is, in general, a neglected practice in most software > development shops, and that's a shame. ?Python has some really good > capabilities to support testing which you should get familiar with. ? > Unittest is just one of them. ?There's also doctest, nose, and a bunch > of other contributed modules. ?Look at them all, learn at least one of > them well, and use it for everything you write. > > > I've read quite a few books about Python. They cover a lot of topics, > > but none of them covered common conventions or hacks. I mean, I got > > good at C++ reading books by Scott Meyers, who concentrated on common > > idioms, things to avoid, the proper way to do things, etc. > > Ugh. ?The problem with Meyers's books is that they are needed in the > first place. ?C++ is such a horribly complicated language, you really > can't use it without making a serious study of it. ?There's too many > gotchas that you MUST know to avoid disaster with even the most basic > programs. > > Python isn't that way. ?You can learn a small, basic subset of the > language and get a lot done. ?You may not be doing things the most > effective way, but you're also not going to be looking at memory > corruption because you didn't understand the details of object lifetimes > or how type promotion, function overloading, and implicit temporary > object construction all interact. > > Thanks for the input. I had been writing my Compass project (http://compass.codeplex.com) in Pythonese. I was planning on implementing a lot of the features of MS' LINQ in Python iterators, too. I am surprised that there aren't a ton of Python libraries for general purpose algorithms. "yield" is one of my favorite keywords. :-) I will take a look at decorators especially. I see them being used for properties and other coolness. I started playing with unittest the other day. unittest.main(exit=False) <-- took me a while to find I will look at the containers, too. I have been trying to push tuple syntax support in C# for years now. Named tuples are so useful. I agree that C++ is too complicated. Bjarne should have cared less about backward compatibility with C and fixed some of the issues with it. He should have also made some of the defaults more intuitive - like ctor initializers being reorganized to the same order as the backing fields... that'll getcha. Function argument order evaluation. Oh no! It might run .00001 seconds slower on a Sparc machine! I think anal programmers like me gravitate towards C++ because we like to show how smart we are by naming off some arbitrary fact. Sure, it doesn't make development any better, but it gives us something to waste memory with. I find myself getting super excited when I get to use words like 'readonly' in C# (Mwahahah! I used a keyword no one else uses!). What drives me nuts is that Bjarne defends his language to the death. It is nice to see Guido trying to fix things in Py3. From mateusz at loskot.net Fri Aug 26 11:40:13 2011 From: mateusz at loskot.net (Mateusz Loskot) Date: Fri, 26 Aug 2011 16:40:13 +0100 Subject: Why PyImport_ExecCodeModule takes char*? Message-ID: <4E57BE5D.3080306@loskot.net> Hi, I'm wondering, why PyImport_ExecCodeModule function takes char* instead of const char*? Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org Member of ACCU, http://accu.org From gordon at panix.com Fri Aug 26 11:40:40 2011 From: gordon at panix.com (John Gordon) Date: Fri, 26 Aug 2011 15:40:40 +0000 (UTC) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: In <7b47ca17-d3f1-4d91-91d1-98421e8708cd at ea4g2000vbb.googlegroups.com> rantingrick writes: > Furthermore: If you are moving code out of one function to ONLY be > called by that ONE function then you are a bad programmer and should > have your editor taken away for six months. You should ONLY create > more func/methods if those func/methods will be called from two or > more places in the code. The very essence of func/meths is the fact > that they are reusable. That's one very important aspect of functions, yes. But there's another: abstraction. If I'm writing a module that needs to fetch user details from an LDAP server, it might be worthwhile to put all of the LDAP-specific code in its own method, even if it's only used once. That way the main module can just contain a line like this: user_info = get_ldap_results("cn=john gordon,ou=people,dc=company,dc=com") The main module keeps a high level of abstraction instead of descending into dozens or even hundreds of lines of LDAP-specific code. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From eaglebalti at gmail.com Fri Aug 26 11:44:45 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 26 Aug 2011 08:44:45 -0700 (PDT) Subject: Hot Bollwood Actresses and Hot Football Players of Spain Soccer Team Message-ID: <187ef78f-ee84-481d-a72f-fc08243c4bdd@hr10g2000vbb.googlegroups.com> Hot Bollywood Actresses and Hot Football Players of Spain Nation Soccer Team. http://bollywoodactresseshotdresses.blogspot.com/ http://spainnationalfootballteamwallpapers.blogspot.com/ From benjamin.kaplan at case.edu Fri Aug 26 11:45:18 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Aug 2011 11:45:18 -0400 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: On Aug 26, 2011 11:39 AM, "Moises Alberto Lindo Gutarra" wrote: > > I like Aptana Studio > http://www.aptana.com/products/studio3 > FYI, Aptana is just a set of extensions for Eclipse. Aptana Studio is just Eclipse with all of the Aptana extensions (including PyDev) preinstalled. > 2011/8/26 Dave Boland : > > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. Any > > suggestions? > > > > I use Eclipse for other projects and have no problem with using it for > > Python, except that I can't get PyDev to install. It takes forever, then > > produces an error that makes no sense. > > > > An error occurred while installing the items > > session context was:(profile=PlatformProfile, > > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > > Cannot connect to keystore. > > This trust engine is read only. > > The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > > not found. > > > > > > Any suggestions on getting this to work? > > > > Thanks, > > Dave > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Atte. > Mois?s Alberto Lindo Gutarra > Asesor - Desarrollador Java / Open Source > Linux Registered User #431131 - http://counter.li.org/ > Cel: (511) 995081720 - Rpm: *548913 > EMail: mlindo at gmail.com > MSN: mlindo at tumisolutions.com > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tobiah at teranews.com Fri Aug 26 11:48:28 2011 From: tobiah at teranews.com (Tobiah) Date: Fri, 26 Aug 2011 08:48:28 -0700 Subject: is there any principle when writing python function In-Reply-To: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: > Furthermore: If you are moving code out of one function to ONLY be > called by that ONE function then you are a bad programmer and should > have your editor taken away for six months. You should ONLY create > more func/methods if those func/methods will be called from two or > more places in the code. The very essence of func/meths is the fact > that they are reusable. While I understand and agree with that basic tenet, I think that the capitalized 'ONLY' is too strong. I do split out code into function for readability, even when the function will only be called from the place from which I split it out. I don't think that this adds to the 'spaghetti' factor. It can make my life much easier when I go to debug my own code years later. In python, I use a small function to block out an idea as a sort of pseudo code, although it's valid python. Then I just define the supporting functions, and the task is done: def validate_registrants(): for dude in get_registrants(): id = get_id(dude) amount_paid = get_amount_paid(dude) amount_owed = get_amount_owed(dude) if amount_paid != amount_owed(): flag(dude) I get that this cries out for a 'dude' object, but I'm just making a point. When I go back to this code, I can very quickly see what the overall flow is, and jump to the problem area by function name. The above block might expand to a couple of hundred lines if I didn't split it out like this. From eaglebalti at gmail.com Fri Aug 26 11:51:47 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Fri, 26 Aug 2011 08:51:47 -0700 (PDT) Subject: Hot Bollwood Actresses and Hot Football Players of Spain Soccer Team Message-ID: <8cdcc8bd-0361-4609-94e2-9e21604e44f9@z18g2000yqb.googlegroups.com> Hot Bollywood Actresses and Hot Football Players of Spain Nation Soccer Team. http://bollywoodactresseshotdresses.blogspot.com/ http://spainnationalfootballteamwallpapers.blogspot.com/ From tim.wintle at teamrubber.com Fri Aug 26 11:52:43 2011 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 26 Aug 2011 16:52:43 +0100 Subject: Unit test failing please help In-Reply-To: References: Message-ID: <1314373963.9006.39.camel@tim-laptop> On Fri, 2011-08-26 at 08:35 -0700, lblake wrote: > Hi I am new to python I am at bit lost as to why my unit test is > failing below is the code and the unit test: > > class Centipede(object): > legs, stomach This doesn't do what you think it does. "legs, stomach" is a statement and is not defining any variables at all. Presumably you've also got variables named legs and stomach in the module's scope - as I'd expect to see a NameError : name 'legs' is not defined. (I'd also expect a SyntaxError from having an empty __init__ function body) You probably want do write something like this: class Centipede(object): def __init__(self): self.legs = [] self.stomach = [] From gordon at panix.com Fri Aug 26 11:58:05 2011 From: gordon at panix.com (John Gordon) Date: Fri, 26 Aug 2011 15:58:05 +0000 (UTC) Subject: Unit test failing please help References: Message-ID: In lblake writes: > Hi I am new to python I am at bit lost as to why my unit test is > failing below is the code and the unit test: > class Centipede(object): > legs, stomach You aren't assigning any values to "legs" or "stomach" here. From your later code, it seems like you intend these items to start out as empty lists. This code might work better: class Centipede(object): legs = [] stomach = [] (In fact, since you aren't *assigning* anything to legs or stomach but you're simply *referencing them*, this code should have been an error because those names do not yet exist.) > def __init__(self): This __init__() method does nothing at all. It doesn't even have a pass statement, which means it isn't legal python. Your code should have produced an error here. > def __setattr__(self, key, value): > print("setting %s to %s" % (key, repr(value))) > if key in ([]): > self.legs.append(key) > super(Centipede, self).__setattr__(self, key,value) How will this if statement ever be true? You're checking if 'key' is a member of an empty list. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From smackay at flagstonesoftware.com Fri Aug 26 12:00:48 2011 From: smackay at flagstonesoftware.com (smackay at flagstonesoftware.com) Date: Fri, 26 Aug 2011 17:00:48 +0100 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: <20110826170048.37748y08q3odsnjk@flagstonesoftware.com> You can get a lot done, if not everything, with a simple editor however for me an IDE is awesome for digging around in the django internals to see how it all works. I used PyDev initially then onto emacs but finally I settled on PyCharm - it's just like PyDev except that everything works. Stuart > I like Aptana Studio > http://www.aptana.com/products/studio3 > > 2011/8/26 Dave Boland : >> I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any >> suggestions? >> >> I use Eclipse for other projects and have no problem with using it for >> Python, except that I can't get PyDev to install. ?It takes forever, then >> produces an error that makes no sense. >> >> An error occurred while installing the items >> ?session context was:(profile=PlatformProfile, >> phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, >> operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, >> action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). >> ?Cannot connect to keystore. >> ?This trust engine is read only. >> ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was >> not found. >> >> >> Any suggestions on getting this to work? >> >> Thanks, >> Dave >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Atte. > Mois?s Alberto Lindo Gutarra > Asesor - Desarrollador Java / Open Source > Linux Registered User #431131 - http://counter.li.org/ > Cel: (511) 995081720 - Rpm: *548913 > EMail: mlindo at gmail.com > MSN: mlindo at tumisolutions.com > -- > http://mail.python.org/mailman/listinfo/python-list > From PointedEars at web.de Fri Aug 26 12:09:21 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 26 Aug 2011 18:09:21 +0200 Subject: Design principles: no bool arguments References: <4e55f604$0$29973$c3e8da3$5496439d@news.astraweb.com> <442262bf-89b4-4f90-8f91-42ac2b2302d8@h4g2000vbw.googlegroups.com> <1660212.aK4W3vaeNJ@PointedEars.de> Message-ID: <1391623.i9ryzFtX3L@PointedEars.de> Ian Kelly wrote: > Thomas 'PointedEars' Lahn wrote: >> Both variants work (even in Py3) if you only define [a named argument]. >> You have to define [a keyword argument, e.g. `kwargs']. >> >> so that >> >> data1.merge_with(data2, True); >> >> is a syntax error ("TypeError: merge_with() takes exactly 2 arguments (3 >> given)"). >> >> IOW, this advantage of Python in readability is not only caused by API >> definition, but also by how the API is used. It might turn into a >> disadvantage if key lookups make the code expensive memory- and runtime >> wise. >> >> And you will still have to know the underlying signature to name the >> argument. Worse, with keyword arguments you *have to* look up the >> documentation (i. e., it needs to be well-documented as well) to know its >> name (as the compiler can only tell you "kwargs"). > > Note though that Python 3 adds actual keyword-only arguments, which > address all of your points: > > class Data: > def merge_with(self, bar, *, overwrite_duplicates): > pass > >>>> data1.merge_with(data2, True) > TypeError: merge_with() takes exactly 2 positional arguments (3 given) >>>> data1.merge_with(data2) > TypeError: merge_with() needs keyword-only argument overwrite_duplicates >>>> data1.merge_with(data2, overwrite_duplicates=True) >>>> That's good to know. Thanks. > Of course, in Python 2 that definition would be a syntax error, so you > can't really take advantage of it if you need compatibility. ACK. Regards, -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rosuav at gmail.com Fri Aug 26 12:10:34 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 02:10:34 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 1:48 AM, Tobiah wrote: > While I understand and agree with that basic tenet, I think > that the capitalized 'ONLY' is too strong. ?I do split out > code into function for readability, even when the function > will only be called from the place from which I split it out. > This can be good and can be bad. It's good when it aids readability; it's bad when you need to pass practically the entire locals() as function arguments and/or return values. I would split the function only when both halves (caller and callee) can be given short and useful names - if you can't explain what a block of code does in a few words, it's probably a poor choice for splitting out into a function. ChrisA From PointedEars at web.de Fri Aug 26 12:37:44 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Fri, 26 Aug 2011 18:37:44 +0200 Subject: Python IDE/Eclipse References: Message-ID: <4258793.v1tGDxx7uL@PointedEars.de> Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > Any suggestions? PyDev (currently 2.2.1.2011073123, from the Aptana Studio 3.0.4 Plugin; but I can see that 2.2.2 has been released). > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. It takes forever, > then produces an error that makes no sense. > > An error occurred while installing the items > session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > Cannot connect to keystore. > This trust engine is read only. > The artifact file for > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > > Any suggestions on getting this to work? Your Eclipse version is apparently a bit old (note the build/sign date of the requested CVS package). Although PyDev is documented to work with Eclipse 3.2 to 3.7, try a newer version (but make a backup of your workspace before). Indigo (3.7) was released on 2011-06-22 CE. The corresponding CVS package version is (perhaps with updates) 3.3.400.I20110510-0800. If you use PyDev from Aptana, you have to uninstall standalone PyDev first. I can still recommend using Aptana for Eclipse 3.7 on GNU/Linux, where it is running without problems so far. However, in Eclipse 3.7 on Windows 7, after the latest Aptana update (3.0.4), PDT collided in their Content-Type settings with Aptana PHP Editor, so I had to uninstall the Aptana plugin in order to get any PHP editor working again. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From rantingrick at gmail.com Fri Aug 26 14:05:30 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 11:05:30 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 26, 10:40?am, John Gordon wrote: > In <7b47ca17-d3f1-4d91-91d1-98421e870... at ea4g2000vbb.googlegroups.com> rantingrick writes: > > > Furthermore: If you are moving code out of one function to ONLY be > > called by that ONE function then you are a bad programmer and should > > have your editor taken away for six months. You should ONLY create > > more func/methods if those func/methods will be called from two or > > more places in the code. The very essence of func/meths is the fact > > that they are reusable. > > That's one very important aspect of functions, yes. ?But there's another: > abstraction. > [...] > The main module keeps a high level of abstraction instead of descending > into dozens or even hundreds of lines of LDAP-specific code. Exactly. I am not arguing against creating intuitive and simplistically elegant interfaces. I mean, lists *could* have only one method called apply(process, *args, **kw) which takes an argument like ("append", "value") or ("index", 42) and has a long block of logic to handle the inputs however that would be a horrible interface. So in that respect i agree. We must weigh the entire interface from an empirical perspective. However i can be sure of one point: As you increase the number of methods you also increase the mental load required to understand that particular interface. An interface with a small number of methods will not suffer too terribly from one or two extra methods however at some point more methods just equals more confusion. It is a delicate balancing act that many programmers are not agile enough to juggle elegantly. Take for instance the interface for Grep, Search, and Replace dialogs in the idlelib which span two separate modules and have a mind numbing number of methods for such remedial things as creating buttons and entrys. All three dialogs look very similar and share many similarities. Now take a look at MY simple ONE module solution. It has JUST enough methods and NOT a single more! Yes the create widgets method is fairly long (weighing in at 80+ lines with comments!) however all of this code needs to be contained in ONE and ONLY one method. Heck if i wanted to get pendantic i could replace the five cb_*() methods with partials however MY interface is so intuitive there is no need. ############################################################ # START CODE ############################################################ class FindReplaceDialog(object): def __init__(self, textbox): [...] def create_widgets(self, type_): # Create toplevel dialog window. [...] # Create widgets belonging to both # search AND replace dialogs dialogs. [...] if type_ == 'replace': # Add widgets unique to replace # dialogs. [...] elif type_ == 'grep': # Add widgets unique to grep # dialogs. [...] # Load any initial values and states. [...] def show(self, type_='find'): self.create_widgets(type_) # Do any initial setup. def close(self, event=None): # destroy the dialog. def find_again(self, event=None): # Event callback bound to textbox. def find(self, target): # Search the buffer for target and # hilight if found. def replace(self, action='replace'): # Fetch the old and new strings and # mediate the work depending on the # action. [...] if action == 'replace+find': [...] elif action == 'replaceall': [...] def grep(): [...] def cb_grepbutton(self, event=None): self.grep(target.entry.get()) def cb_findbutton(self, event=None): self.find(target.entry.get()) def cb_replacebutton(self): self.replace(action='replace') def cb_replacefindbutton(self): self.replace(action='replace+find') def cb_replaceallbutton(self): self.replace(action='replaceall') ############################################################ # END CODE ############################################################ Now look at the three modules in idlelib (Grep Dialog, Search Dialog, and Replace Dialog) and ask yourself which is cleaner? Which is more intuiitve? Which is more professional? Which would you rather debug? *scholl-bell-rings* From steve+comp.lang.python at pearwood.info Fri Aug 26 14:16:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 04:16:30 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e57e2ff$0$29984$c3e8da3$5496439d@news.astraweb.com> Tobiah wrote: > >> Furthermore: If you are moving code out of one function to ONLY be >> called by that ONE function then you are a bad programmer and should >> have your editor taken away for six months. You should ONLY create >> more func/methods if those func/methods will be called from two or >> more places in the code. The very essence of func/meths is the fact >> that they are reusable. > > While I understand and agree with that basic tenet, I think > that the capitalized 'ONLY' is too strong. I do split out > code into function for readability, even when the function > will only be called from the place from which I split it out. In other words, you disagree. Which is good, because the text you quote is terrible advice, and it is ironic that the person you quote judges others as bad programmers when his advice is so bad. I can think of at least five reasons apart from re-use why it might be appropriate to pull out code into its own function or method even if it is used in one place only: (1) Extensibility. Just earlier today I turned one method into three: def select(self): response = input(self) if response: index = self.find(response) else: index = self.default return self.menuitems[index-1] turned into: def choose(self, response): if response: index = self.find(response) else: index = self.default return self.menuitems[index-1] def raw_select(self): return input(self) def select(self): return self.choose(self.raw_select()) I did this so that subclasses could override the behaviour of each component individually, even though the caller is not expected to call raw_select or choose directly. (I may even consider making them private.) (2) Testing. It is very difficult to reach into the middle of a function and test part of it. It is very difficult to get full test coverage of big monolithic blocks of code: to ensure you test each path through a big function, the number of test cases rises exponentially. By splitting it into functions, you can test each part in isolation, which requires much less work. (3) Fault isolation. If you have a 100 line function that fails on line 73, that failure may have been introduced way back in line 16. By splitting the function up into smaller functions, you can more easily isolate where the failure comes from, by checking for violated pre- and post-conditions. (4) Maintainability. It's just easier to document and reason about a function that does one thing, than one that tries to do everything. Which would you rather work with, individual functions for: buy_ingredients clean_kitchen_work_area wash_vegetables prepare_ingredients cook_main_course fold_serviettes make_desert serve_meal do_washing_up etc., or one massive function: prepare_and_serve_five_course_meal Even if each function is only called once, maintenance is simpler if the code is broken up into more easily understood pieces. (5) Machine efficiency. This can go either way. Code takes up memory too, and it may be easier for the compiler to work with 1000 small functions than 1 big function. I've actually seen somebody write a single function so big that Python couldn't import the module, because it ran out of memory trying to compile it! (This function was *huge* -- the source code was many megabytes in size.) I don't remember the details, but refactoring the source code into smaller functions fixed it. On the other hand, if you are tight for memory, 1 big function may have less overhead than 1000 small functions; and these days, with even entry level PCs often having a GB or more of memory, it is rare to come across a function so big that the size of code matters. Even a 10,000 line function is likely to be only a couple of hundred KB in size: >>> text = '\n'.join('print x+i' for i in range(1, 10001)) >>> code = compile(text, '', 'exec') >>> sys.getsizeof(code.co_code) # size in bytes 90028 So that's four really good reasons for splitting code into functions, and one borderline one, other than code re-use. There may be others. -- Steven From greymausg at mail.com Fri Aug 26 14:39:07 2011 From: greymausg at mail.com (greymaus) Date: 26 Aug 2011 18:39:07 GMT Subject: Record seperator Message-ID: Is there an equivelent for the AWK RS in Python? as in RS='\n\n' will seperate a file at two blank line intervals -- maus . . ... NO CARRIER From darcy at druid.net Fri Aug 26 15:02:21 2011 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Aug 2011 15:02:21 -0400 Subject: Record seperator In-Reply-To: References: Message-ID: <20110826150221.7e8b2d5a@dilbert> On 26 Aug 2011 18:39:07 GMT greymaus wrote: > > Is there an equivelent for the AWK RS in Python? > > > as in RS='\n\n' > will seperate a file at two blank line intervals open("file.txt").read().split("\n\n") -- 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+comp.lang.python at pearwood.info Fri Aug 26 15:56:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 05:56:12 +1000 Subject: Catch and name an exception in Python 2.5 + Message-ID: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> In Python 3, you can catch an exception and bind it to a name with: try: ... except ValueError, KeyError as error: pass In Python 2.5, that is written: try: ... except (ValueError, KeyError), error: pass and the "as error" form gives a SyntaxError. Python 2.6 and 2.7 accept either form. Is there any way to catch an exception and bind it to a name which will work across all Python versions from 2.5 onwards? I'm pretty sure there isn't, but I thought I'd ask just in case. -- Steven From t at jollybox.de Fri Aug 26 16:36:21 2011 From: t at jollybox.de (Thomas Jollans) Date: Fri, 26 Aug 2011 22:36:21 +0200 Subject: Catch and name an exception in Python 2.5 + In-Reply-To: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E5803C5.2080003@jollybox.de> On 26/08/11 21:56, Steven D'Aprano wrote: > In Python 3, you can catch an exception and bind it to a name with: > > try: > ... > except ValueError, KeyError as error: > pass > > In Python 2.5, that is written: > > try: > ... > except (ValueError, KeyError), error: > pass > > and the "as error" form gives a SyntaxError. > > Python 2.6 and 2.7 accept either form. > > Is there any way to catch an exception and bind it to a name which will work > across all Python versions from 2.5 onwards? > > I'm pretty sure there isn't, but I thought I'd ask just in case. It's not elegant, and I haven't actually tested this, but this should work: try: ... except (ValueError, KeyError): error = sys.exc_info()[2] -- Thomas From rosuav at gmail.com Fri Aug 26 17:45:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 07:45:53 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 4:05 AM, rantingrick wrote: > Now take a look at MY simple ONE module solution. It has JUST enough > methods and NOT a single more! I disagree - create_widgets() is completely unnecessary in the presence of show(), unless it's possible to show the dialog, hide it, and then re-show it without recreating the widgets. On Sat, Aug 27, 2011 at 4:16 AM, Steven D'Aprano wrote: > I can think of at least five reasons apart from re-use why it might be > appropriate to pull out code into its own function or method even if it is > used in one place only: I'm glad you say "might be", because your five reasons aren't always reasons for refactoring. I'll play devil's advocate for a moment, because discussion is both fun and informative: :) > (1) Extensibility. Just earlier today I turned one method into three: > I did this so that subclasses could override the behaviour of each component > individually, even though the caller is not expected to call raw_select or > choose directly. (I may even consider making them private.) Definitely, but it's no value if you make every tiny thing into your own function. Sometimes the best way to code is to use lower-level functionality directly (not wrapping input() inside raw_select() for instance), and letting someone monkey-patch if they want to change your code. A judgment call. > (2) Testing. It is very difficult to reach into the middle of a function and > test part of it. ... By splitting it > into functions, you can test each part in isolation, which requires much > less work. Yes, but 100% coverage isn't that big a deal. If the function does precisely one logical thing, then you don't _need_ to test parts in isolation - you can treat it as a black box and just ensure that it's doing the right thing under various circumstances. However, this ties in nicely with your next point... > (3) Fault isolation. If you have a 100 line function that fails on line 73, > that failure may have been introduced way back in line 16. By splitting the > function up into smaller functions, you can more easily isolate where the > failure comes from, by checking for violated pre- and post-conditions. ... and here's where #2 really shines. If you break your function in two, the natural thing to do is to test each half separately, with the correct preconditions, and examine its output. If your fault was on line 16, your test for that half of the function has a chance of detecting it. I don't have a Devil's Advocate put-down for this one, save the rather weak comment that it's possible to check pre- and post-conditions without refactoring. :) > (4) Maintainability. It's just easier to document and reason about a > function that does one thing, than one that tries to do everything. Which > would you rather work with, individual functions for: > ... omnomnom ... > Even if each function is only called once, maintenance is simpler if the > code is broken up into more easily understood pieces. Yes, as long as you do the job intelligently. Goes back to what I said about naming functions - in your kitchen example, every function has a self-documenting name, which means you've broken it out more-or-less correctly. (I'd still want to have prepare_and_serve_five_course_meal() of course, but it would be calling on all the others.) Breaking something out illogically doesn't help maintainability at all - in fact, it'll make it worse. "So this function does what, exactly? And if I need to add a line of code, ought I to do it here, or over there? Does anyone else actually call this function? MIGHT someone be reaching into my module and calling this function directly? I'd better keep it... ugh." > (5) Machine efficiency. This can go either way. And that's the very best thing to say about efficiency. Ever. In C, I can write static functions and let the compiler inline them; in Java, I tried to do the same thing, and found ridiculous overheads. Ended up making a monolith rather than go through Java's overhead. But if I'd changed what VM I was running it on, that might well have changed. Profile, profile, profile. > So that's four really good reasons for splitting code into functions, and > one borderline one, other than code re-use. There may be others. I'm sure there are. But let's face it: We're programming in PYTHON. Not C, not Erlang, not Pike, not PHP. Python. If this has been the right choice, then we should assume that efficiency isn't king, but readability and maintainability probably are; so the important considerations are not "will it take two extra nanoseconds to execute" but "can my successor understand what the code's doing" and "will he, if he edits my code, have a reasonable expectation that he's not breaking stuff". These are always important. ChrisA From arnodel at gmail.com Fri Aug 26 18:20:38 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 26 Aug 2011 23:20:38 +0100 Subject: The RAISE_VARARGS opcode in Python 3 Message-ID: Hi all, Here is an extract from the dis module doc [1] """ RAISE_VARARGS(argc) Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS. """ OTOH, looking at PEP 3109: """ In Python 3, the grammar for raise statements will change from [2] raise_stmt: 'raise' [test [',' test [',' test]]] to raise_stmt: 'raise' [test] """ So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python 3, whereas it could be up to 3 in Python 2. Can anyone confirm that this is the case? In this case, I guess the dis docs need to be updated. Thank you, Arnaud [1] http://docs.python.org/py3k/library/dis.html#opcode-RAISE_VARARGS [2] http://www.python.org/dev/peps/pep-3109/#grammar-changes From rantingrick at gmail.com Fri Aug 26 18:26:37 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 15:26:37 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <681242ae-33ed-4440-8918-c7e540e0bf8c@n35g2000yqf.googlegroups.com> On Aug 26, 4:45?pm, Chris Angelico wrote: > On Sat, Aug 27, 2011 at 4:05 AM, rantingrick wrote: > > Now take a look at MY simple ONE module solution. It has JUST enough > > methods and NOT a single more! > > I disagree - create_widgets() is completely unnecessary in the > presence of show(), Well since you cannot see the underlying code i won't be too harsh on you :), but yes, i can assure you that create widgets IS necessary for readability. show() calls "self.create_widgets()" then adds a special hit tag to the text widget and sets up a modal behavior of the dialog, it's only 5-7 lines of setup code but i think the separation is warranted. Could i have rolled all the create_widgets() code into the show() method? Of course, however i do see a good reason for separation here for the sake of readability. Although i must admit, had the interface been much larger i most assuredly would have rolled it together. > unless it's possible to show the dialog, hide it, > and then re-show it without recreating the widgets. Yes the instance lives on between session to save state. Also the "find_again" binding of the text widget calls the SearchReplaceDialog.find_again() method when {CONTROL+G} event fires. > I'm sure there are. But let's face it: We're programming in PYTHON. > Not C, not Erlang, not Pike, not PHP. Python. If this has been the > right choice, then we should assume that efficiency isn't king, but > readability and maintainability probably are; so the important > considerations are not "will it take two extra nanoseconds to > execute" but "can my successor understand what the code's doing" and > "will he, if he edits my code, have a reasonable expectation that > he's not breaking stuff". These are always important. Bravo! That has to be most lucid and intelligent statement from you to date. And i must say the warm fuzzies i got from imagining the defeat D'Aprano must have felt whist reading it left me with a nice feeling. How do like them apples, D'Aprano? :-) From rantingrick at gmail.com Fri Aug 26 18:37:11 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 26 Aug 2011 15:37:11 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e57e2ff$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <69798bf3-ce54-48e0-b08d-f5897862e57c@b20g2000vbz.googlegroups.com> On Aug 26, 1:16?pm, Steven D'Aprano wrote: > (3) Fault isolation. If you have a 100 line function that fails on line 73, > that failure may have been introduced way back in line 16. By splitting the > function up into smaller functions, you can more easily isolate where the > failure comes from, by checking for violated pre- and post-conditions. What's wrong Steven, are track backs too complicated for you? ############################################################ # START DUMMY SCRIPT ############################################################ def very_long_function(): max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(object) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) max(range(5)) # print 'blah' print 'blah' print 'blah-blah' very_long_function() ############################################################ # END DUMMY SCRIPT ############################################################ Traceback (most recent call last): File "C:/Python27/test33333.py", line 48, in very_long_function() File "C:/Python27/test33333.py", line 26, in very_long_function max(object) TypeError: 'type' object is not iterable Oh the humanity! From steve+comp.lang.python at pearwood.info Fri Aug 26 21:26:21 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 11:26:21 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sat, Aug 27, 2011 at 4:16 AM, Steven D'Aprano > wrote: >> I can think of at least five reasons apart from re-use why it might be >> appropriate to pull out code into its own function or method even if it >> is used in one place only: > > I'm glad you say "might be", because your five reasons aren't always > reasons for refactoring. I'll play devil's advocate for a moment, > because discussion is both fun and informative: :) Naturally :) I say "might be" because I mean it: these arguments have to be weighed up against the argument against breaking code out of functions. It's easy to imagine an extreme case where there are a billion *tiny* functions, each of which does one micro-operation: def f1(x): return x + 1 def f2(x): return 3*x def f3(x): return f2(f1(x)) # instead of 3*(x+1) ... If spaghetti code (GOTOs tangled all through the code with no structure) is bad, so is ravioli code (code bundled up into tiny parcels and then thrown together higgledy-piggledy). Both cases can lead to an unmaintainable mess. Nobody is arguing that "More Functions Is Always Good". Sensible coders understand that you should seek a happy medium and not introduce more functions just for the sake of having More! Functions!. But I'm not arguing with you, we're in agreement. One last comment though: [...] > Definitely, but it's no value if you make every tiny thing into your > own function. Sometimes the best way to code is to use lower-level > functionality directly (not wrapping input() inside raw_select() for > instance), and letting someone monkey-patch if they want to change > your code. A judgment call. I agree on the first part (don't split *everything* into functions) but I think that the monkey-patch idea is tricky and dangerous in practice. The first problem is, how do you know what needs to be monkey-patched? You may not have access to the source code to read, and it may not be as obvious as "oh, it gets input from the user, so it must be calling input()". Second, even if you know what to monkey-patch, it's really hard to isolate the modification to just the method you want. By their nature, monkey- patches apply globally to the module. And if you patch the builtins module, they apply *everywhere*. So while monkey-patching can work, it's tricky to get it right and it should be left as a last resort. -- Steven From rosuav at gmail.com Fri Aug 26 21:37:27 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 11:37:27 +1000 Subject: is there any principle when writing python function In-Reply-To: <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e5847bc$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 27, 2011 at 11:26 AM, Steven D'Aprano wrote: > I say "might be" because I mean it: these arguments have to be weighed up > against the argument against breaking code out of functions. It's easy to > imagine an extreme case where there are a billion *tiny* functions, each of > which does one micro-operation: > > def f1(x): return x + 1 > def f2(x): return 3*x > def f3(x): return f2(f1(x)) ?# instead of 3*(x+1) This fails the "give it a decent name" test. Can you name these functions according to what they do, as opposed to how they do it? For instance: def add_flagfall(x): return x + 1 # add a $1 flagfall to the price def add_tax(x): return 3*x # this is seriously nasty tax def real_price(x): return add_tax(add_flagfall(x)) ?# instead of 3*(x+1) This would be acceptable, because each micro-operation has real meaning. I'd prefer to do it as constants rather than functions, but at least they're justifying their names. And you're absolutely right about monkey-patching. ChrisA From steve+comp.lang.python at pearwood.info Fri Aug 26 23:45:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 13:45:29 +1000 Subject: Catch and name an exception in Python 2.5 + References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> Thomas Jollans wrote: > On 26/08/11 21:56, Steven D'Aprano wrote: >> Is there any way to catch an exception and bind it to a name which will >> work across all Python versions from 2.5 onwards? >> >> I'm pretty sure there isn't, but I thought I'd ask just in case. > > It's not elegant, and I haven't actually tested this, but this should > work: > > try: > ... > except (ValueError, KeyError): > error = sys.exc_info()[2] Great! Thanks for that, except I think you want to use [1], not [2]. -- Steven From __peter__ at web.de Sat Aug 27 02:49:53 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Aug 2011 08:49:53 +0200 Subject: The RAISE_VARARGS opcode in Python 3 References: Message-ID: Arnaud Delobelle wrote: > Here is an extract from the dis module doc [1] > > """ > RAISE_VARARGS(argc) > Raises an exception. argc indicates the number of parameters to the > raise statement, ranging from 0 to 3. The handler will find the > traceback as TOS2, the parameter as TOS1, and the exception as TOS. > """ > > OTOH, looking at PEP 3109: > > """ > In Python 3, the grammar for raise statements will change from [2] > > raise_stmt: 'raise' [test [',' test [',' test]]] > to > > raise_stmt: 'raise' [test] > """ > > So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python > 3, whereas it could be up to 3 in Python 2. It can be up to 2 in Python 3, >>> help("raise") The ``raise`` statement *********************** raise_stmt ::= "raise" [expression ["from" expression]] ... confirmed by a quick look into ceval.c: TARGET(RAISE_VARARGS) v = w = NULL; switch (oparg) { case 2: v = POP(); /* cause */ case 1: w = POP(); /* exc */ case 0: /* Fallthrough */ why = do_raise(w, v); break; default: PyErr_SetString(PyExc_SystemError, "bad RAISE_VARARGS oparg"); why = WHY_EXCEPTION; break; } break; > Can anyone confirm that > this is the case? In this case, I guess the dis docs need to be > updated. Indeed. From shenbakrishna86 at gmail.com Sat Aug 27 02:56:42 2011 From: shenbakrishna86 at gmail.com (shenba valli) Date: Fri, 26 Aug 2011 23:56:42 -0700 (PDT) Subject: comp.lang.python is a high-volume Usenet open (not moderated) newsgroup for general discussions and questions about Python. You can also access it as a ... Message-ID: comp.lang.python ? Discussions ? + new post ? About this group ? Subscribe to this group. This is a Usenet group - learn more. View this group in the new Google ... http://123maza.com/65/purple505/ From arnodel at gmail.com Sat Aug 27 03:00:34 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 08:00:34 +0100 Subject: The RAISE_VARARGS opcode in Python 3 In-Reply-To: References: Message-ID: On 27 August 2011 07:49, Peter Otten <__peter__ at web.de> wrote: > Arnaud Delobelle wrote: > >> Here is an extract from the dis module doc [1] >> >> """ >> RAISE_VARARGS(argc) >> Raises an exception. argc indicates the number of parameters to the >> raise statement, ranging from 0 to 3. The handler will find the >> traceback as TOS2, the parameter as TOS1, and the exception as TOS. >> """ >> >> OTOH, looking at PEP 3109: >> >> """ >> In Python 3, the grammar for raise statements will change from [2] >> >> raise_stmt: 'raise' [test [',' test [',' test]]] >> to >> >> raise_stmt: 'raise' [test] >> """ >> >> So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python >> 3, whereas it could be up to 3 in Python 2. > > It can be up to 2 in Python 3, > >>>> help("raise") > The ``raise`` statement > *********************** > > ? raise_stmt ::= "raise" [expression ["from" expression]] > ... > > confirmed by a quick look into ceval.c: > > ? ? ? ?TARGET(RAISE_VARARGS) > ? ? ? ? ? ?v = w = NULL; > ? ? ? ? ? ?switch (oparg) { > ? ? ? ? ? ?case 2: > ? ? ? ? ? ? ? ?v = POP(); /* cause */ > ? ? ? ? ? ?case 1: > ? ? ? ? ? ? ? ?w = POP(); /* exc */ > ? ? ? ? ? ?case 0: /* Fallthrough */ > ? ? ? ? ? ? ? ?why = do_raise(w, v); > ? ? ? ? ? ? ? ?break; > ? ? ? ? ? ?default: > ? ? ? ? ? ? ? ?PyErr_SetString(PyExc_SystemError, > ? ? ? ? ? ? ? ? ? ? ? ? ? "bad RAISE_VARARGS oparg"); > ? ? ? ? ? ? ? ?why = WHY_EXCEPTION; > ? ? ? ? ? ? ? ?break; > ? ? ? ? ? ?} > ? ? ? ? ? ?break; Thanks again, Peter! I'm out of Python practice, and I've forgotten some things like help("keyword"). Also PEP 3109 does indeed mention the raise .. from .. syntax in an example at the end. -- Arnaud From arnodel at gmail.com Sat Aug 27 03:08:20 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 08:08:20 +0100 Subject: how to format long if conditions Message-ID: Hi all, I'm wondering what advice you have about formatting if statements with long conditions (I always format my code to <80 colums) Here's an example taken from something I'm writing at the moment and how I've formatted it: if (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) What would you do? -- Arnaud From steve+comp.lang.python at pearwood.info Sat Aug 27 03:24:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 17:24:12 +1000 Subject: how to format long if conditions References: Message-ID: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Arnaud Delobelle wrote: > Hi all, > > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to <80 colums) > > Here's an example taken from something I'm writing at the moment and > how I've formatted it: > > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > What would you do? I believe that PEP 8 now suggests something like this: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): ) py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) I consider that hideous and would prefer to write this: if (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) Or even this: tmp = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) ) if tmp: py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) But perhaps the best solution is to define a helper function: def is_next(left, right): """Returns True if right is the next PyCompare to left.""" return (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) # PEP 8 version left as an exercise. # later... if is_next(left, right): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) -- Steven From hansmu at xs4all.nl Sat Aug 27 03:50:36 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 09:50:36 +0200 Subject: how to format long if conditions In-Reply-To: References: Message-ID: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> On 27/08/11 09:08:20, Arnaud Delobelle wrote: > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to<80 colums) > > Here's an example taken from something I'm writing at the moment and > how I've formatted it: > > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > What would you do? I would break after the '(' and indent the condition once and put the '):' bit on a separate line, aligned with the 'if': if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) It may look ugly, but it's very clear where the condition part ends and the 'then' part begins. -- HansM From andrei.lisnic at gmail.com Sat Aug 27 04:34:03 2011 From: andrei.lisnic at gmail.com (UncleLaz) Date: Sat, 27 Aug 2011 01:34:03 -0700 (PDT) Subject: Python IDE/Eclipse References: Message-ID: On Aug 26, 5:18?pm, Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > ? Any suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, > then produces an error that makes no sense. > > An error occurred while installing the items > ? ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). > ? ?Cannot connect to keystore. > ? ?This trust engine is read only. > ? ?The artifact file for > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > Any suggestions on getting this to work? > > Thanks, > Dave I use Aptana Studio 3, it's pretty good and it's based on eclipse From steve+comp.lang.python at pearwood.info Sat Aug 27 05:05:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 27 Aug 2011 19:05:25 +1000 Subject: how to format long if conditions References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> Hans Mulder wrote: [...] > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. Immediately after the colon, surely? -- Steven From t at jollybox.de Sat Aug 27 05:57:58 2011 From: t at jollybox.de (Thomas Jollans) Date: Sat, 27 Aug 2011 11:57:58 +0200 Subject: Catch and name an exception in Python 2.5 + In-Reply-To: <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e57fa5c$0$29968$c3e8da3$5496439d@news.astraweb.com> <4e586858$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E58BFA6.7080203@jollybox.de> On 27/08/11 05:45, Steven D'Aprano wrote: > Thomas Jollans wrote: > >> On 26/08/11 21:56, Steven D'Aprano wrote: > >>> Is there any way to catch an exception and bind it to a name which will >>> work across all Python versions from 2.5 onwards? >>> >>> I'm pretty sure there isn't, but I thought I'd ask just in case. >> >> It's not elegant, and I haven't actually tested this, but this should >> work: >> >> try: >> ... >> except (ValueError, KeyError): >> error = sys.exc_info()[2] > > Great! Thanks for that, except I think you want to use [1], not [2]. Ah, yes. Of course. From arnodel at gmail.com Sat Aug 27 06:24:33 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 27 Aug 2011 11:24:33 +0100 Subject: how to format long if conditions In-Reply-To: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 27 August 2011 08:24, Steven D'Aprano wrote: > Arnaud Delobelle wrote: > >> Hi all, >> >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to <80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> ? ? ? ? if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> ? ? ? ? ? ? ? ? and left.complist[-1] is right.complist[0]): >> ? ? ? ? ? ? py_and = PyCompare(left.complist + right.complist[1:]) >> ? ? ? ? else: >> ? ? ? ? ? ? py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I believe that PEP 8 now suggests something like this: > > ? ? ? ?if ( > ? ? ? ? ? ? ? ?isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ? ? ?and left.complist[-1] is right.complist[0]): > ? ? ? ? ? ?) > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > I consider that hideous and would prefer to write this: > > > ? ? ? ?if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ?and left.complist[-1] is right.complist[0]): > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > Or even this: > > ? ? ? ?tmp = ( > ? ? ? ? ? ?isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ? ? ?and left.complist[-1] is right.complist[0]) > ? ? ? ? ? ?) > ? ? ? ?if tmp: > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > > > But perhaps the best solution is to define a helper function: > > def is_next(left, right): > ? ?"""Returns True if right is the next PyCompare to left.""" > ? ?return (isinstance(left, PyCompare) and isinstance(right, PyCompare) > ? ? ? ?and left.complist[-1] is right.complist[0]) > ? ?# PEP 8 version left as an exercise. > > > # later... > ? ? ? ?if is_next(left, right): > ? ? ? ? ? ?py_and = PyCompare(left.complist + right.complist[1:] > ? ? ? ?else: > ? ? ? ? ? ?py_and = PyBooleanAnd(left, right) > Thanks Steven and Hans for you suggestions. For this particular instance I've decided to go for a hybrid approach: * Add two methods to PyCompare: class PyCompare(PyExpr): ... def extends(self, other): if not isinstance(other, PyCompare): return False else: return self.complist[0] == other.complist[-1] def chain(self, other): return PyCompare(self.complist + other.complist[1:]) * Rewrite the if as: if isinstance(right, PyCompare) and right.extends(left): py_and = left.chain(right) else: py_and = PyBooleanAnd(left, right) The additional benefit is to hide the implementation details of PyCompare (I suppose this could illustrate the thread on when to create functions). -- Arnaud From hansmu at xs4all.nl Sat Aug 27 06:51:16 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 12:51:16 +0200 Subject: how to format long if conditions In-Reply-To: <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e58b355$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e58cc24$0$2409$e4fe514c@news2.news.xs4all.nl> On 27/08/11 11:05:25, Steven D'Aprano wrote: > Hans Mulder wrote: > > [...] >> It may look ugly, but it's very clear where the condition part ends >> and the 'then' part begins. > > Immediately after the colon, surely? On the next line, actually :-) The point is, that this layout makes it very clear that the colon isn't in its usual position (at the end of the line that starts with 'if') and it is clearly visible. With the layout Arnaud originally propose, finding the colon takes longer. (Arnaud has since posted a better approach, in which the colon is back in its usual position.) -- HansM From pavlovevidence at gmail.com Sat Aug 27 07:35:21 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 27 Aug 2011 04:35:21 -0700 (PDT) Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: On Thursday, August 25, 2011 1:54:35 PM UTC-7, ti... at thsu.org wrote: > On Aug 25, 10:35?am, Arnaud Delobelle wrote: > > You're close to the usual idiom: > > > > def doSomething(debug=None): > > ? ? if debug is None: > > ? ? ? ? debug = defaults['debug'] > > ? ? ... > > > > Note the use of 'is' rather than '==' > > HTH > > Hmm, from what you are saying, it seems like there's no elegant way to > handle run time defaults for function arguments, meaning that I should > probably write a sql-esc coalesce function to keep my code cleaner. I > take it that most people who run into this situation do this? I don't; it seems kind of superfluous when "if arg is not None: arg = whatever" is just as easy to type and more straightforward to read. I could see a function like coalesce being helpful if you have a list of several options to check, though. Also, SQL doesn't give you a lot of flexibility, so coalesce is a lot more needed there. But for simple arguments in Python, I'd recommend sticking with "if arg is not None: arg = whatever" Carl Banks From ben+python at benfinney.id.au Sat Aug 27 08:04:19 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Aug 2011 22:04:19 +1000 Subject: how to format long if conditions References: <4e589b9b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874o13ukl8.fsf@benfinney.id.au> Steven D'Aprano writes: > I believe that PEP 8 now Specifically the ?Indentation? section contains:: When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line. > suggests something like this: > > if ( > isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > ) > py_and = PyCompare(left.complist + right.complist[1:] > else: > py_and = PyBooleanAnd(left, right) That gives a SyntaxError. I think you mean one of these possible PEP 8 compliant forms:: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) or maybe:: if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:] else: py_and = PyBooleanAnd(left, right) > I consider that hideous I think both of those (once modified to conform to both the Python syntax and the PEP 8 guidelines) look clear and readable. I mildy prefer the first for being a little more elegant, but the second is slightly better for maintainability and reducing diff noise. Either one makes me happy. > and would prefer to write this: > > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:] > else: > py_and = PyBooleanAnd(left, right) That one keeps tripping me up because the indentation doesn't make clear where subordinate clauses begin and end. The (current) PEP 8 rules are much better for readability in my eyes. Having said that, I'm only a recent convert to the current PEP 8 style for indentation of condition clauses. It took several heated arguments with colleagues before I was able to admit the superiority of clear indentation :-) -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From kwa at kuwata-lab.com Sat Aug 27 08:37:45 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sat, 27 Aug 2011 21:37:45 +0900 Subject: [ANN] Oktest 0.9.0 released - a new-style testing library Message-ID: Hi, I released Oktest 0.9.0. http://pypi.python.org/pypi/Oktest/ http://packages.python.org/Oktest/ Oktest is a new-style testing library for Python. :: from oktest import ok, NG ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo' # same as assertEqual(s, 'foo') ok (s) != 'foo' # same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode)) NG (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int)) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) NG ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) See http://packages.python.org/Oktest/ for details. NOTICE!! Oktest is a young project and specification may change in the future. Main Enhancements ----------------- * New '@test' decorator provided. It is simple but very powerful. Using @test decorator, you can write test description in free text instead of test method. ex:: class FooTest(unittest.TestCase): def test_1_plus_1_should_be_2(self): # not cool... self.assertEqual(2, 1+1) @test("1 + 1 should be 2") # cool! easy to read & write! def _(self): self.assertEqual(2, 1+1) * Fixture injection support by '@test' decorator. Arguments of test method are regarded as fixture names and they are injected by @test decorator automatically. Instance methods or global functions which name is 'provide_xxxx' are regarded as fixture provider (or builder) for fixture 'xxxx'. ex:: class SosTest(unittest.TestCase): ## ## fixture providers. ## def provide_member1(self): return {"name": "Haruhi"} def provide_member2(self): return {"name": "Kyon"} ## ## fixture releaser (optional) ## def release_member1(self, value): assert value == {"name": "Haruhi"} ## ## testcase which requires 'member1' and 'member2' fixtures. ## @test("validate member's names") def _(self, member1, member2): assert member1["name"] == "Haruhi" assert member2["name"] == "Kyon" Dependencies between fixtures are resolved automatically. ex:: class BarTest(unittest.TestCase): ## ## for example: ## - Fixture 'a' depends on 'b' and 'c'. ## - Fixture 'c' depends on 'd'. ## def provide_a(b, c): return b + c + ["A"] def provide_b(): return ["B"] def provide_c(d): return d + ["C"] def provide_d(): reutrn ["D"] ## ## Dependencies between fixtures are solved automatically. ## @test("dependency test") def _(self, a): assert a == ["B", "D", "C", "A"] If loop exists in dependency then @test reports error. If you want to integrate with other fixture library, see the following example:: class MyFixtureManager(object): def __init__(self): self.values = { "x": 100, "y": 200 } def provide(self, name): return self.values[name] def release(self, name, value): pass oktest.fixure_manager = MyFixtureResolver() Other Enhancements and Changes ------------------------------ * Supports command-line interface to execute test scripts. * Reporting style is changed. * New assertion method ``ok(x).attr(name, value)`` to check attribute. * New assertion method ``ok(x).length(n)``. * New feature``ok().should`` helps you to check boolean method. * 'ok(str1) == str2' displays diff if text1 != text2, even when using with unittest module. * Assertion ``raises()`` supports regular expression to check error message. * Helper functions in oktest.dummy module are now available as decorator. * 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'. * ``oktest.run()`` is changed to return number of failures and errors of tests. * ``before_each()`` and ``after_each()`` are now non-supported. * (Experimental) New function ``NOT()`` provided which is same as ``NG()``. * (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests:: See CHANGES.txt for details. http://packages.python.org/Oktest/CHANGES.txt Have a nice testing life! -- regards, makoto kuwata From k.sahithi2862 at gmail.com Sat Aug 27 09:28:44 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sat, 27 Aug 2011 06:28:44 -0700 (PDT) Subject: ADULT HOT PICS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From jason.swails at gmail.com Sat Aug 27 09:42:57 2011 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 27 Aug 2011 09:42:57 -0400 Subject: typing question Message-ID: Hello everyone, This is probably a basic question with an obvious answer, but I don't quite get why the type(foo).__name__ works differently for some class instances and not for others. If I have an "underived" class, any instance of that class is simply of type "instance". If I include an explicit base class, then its type __name__ is the name of the class. $ python Python 2.7.2 (default, Aug 26 2011, 22:35:24) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class MyClass: ... pass ... >>> foo = MyClass() >>> type(foo) >>> type(foo).__name__ 'instance' >>> class MyClass1(): ... pass ... >>> bar = MyClass1() >>> type(bar) >>> type(bar).__name__ 'instance' >>> class MyClass2(object): ... pass ... >>> foobar = MyClass2() >>> type(foobar) >>> type(foobar).__name__ 'MyClass2' I can't explain this behavior (since doesn't every class inherit from object by default? And if so, there should be no difference between any of my class definitions). I would prefer that every approach give me the name of the class (rather than the first 2 just return 'instance'). Why is this not the case? Also, is there any way to access the name of the of the class type foo or bar in the above example? Thanks! Jason P.S. I'll note that my "preferred" behavior is how python3.2 actually operates $ python3.2 Python 3.2.1 (default, Aug 26 2011, 23:20:19) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class MyClass: ... pass ... >>> foo = MyClass() >>> type(foo).__name__ 'MyClass' -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Aug 27 09:46:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Aug 2011 23:46:14 +1000 Subject: typing question In-Reply-To: References: Message-ID: On Sat, Aug 27, 2011 at 11:42 PM, Jason Swails wrote: > I can't explain this behavior (since doesn't every class inherit from object > by default? And if so, there should be no difference between any of my class > definitions). That is true in Python 3, but not in Python 2. That's why your example works perfectly in version 3.2. Be explicit about deriving from object and your code should work fine in both versions. Chris Angelico From 1jason.whatford at gmail.com Sat Aug 27 09:55:28 2011 From: 1jason.whatford at gmail.com (J) Date: Sat, 27 Aug 2011 06:55:28 -0700 (PDT) Subject: UnicodeEncodeError -- 'character maps to ' Message-ID: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> Hi there, I'm attempting to print a dictionary entry of some twitter data to screen but every now and then I get the following error: (, UnicodeEncodeError('charmap', u'RT @ciaraluvsjb26: BIEBER FEVER \u2665', 32, 33, 'character maps to '), ) I have googled this but haven't really found any way to overcome the error. Any ideas? J From steve+comp.lang.python at pearwood.info Sat Aug 27 11:00:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 01:00:20 +1000 Subject: UnicodeEncodeError -- 'character maps to ' References: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> Message-ID: <4e590684$0$29972$c3e8da3$5496439d@news.astraweb.com> J wrote: > Hi there, > > I'm attempting to print a dictionary entry of some twitter data to screen > but every now and then I get the following error: > > (, UnicodeEncodeError('charmap', > u'RT @ciaraluvsjb26: BIEBER FEVER \u2665', 32, 33, 'character maps to > '), ) Showing the actual traceback will help far more than a raw exception tuple. > I have googled this but haven't really found any way to overcome the > error. Any ideas? I can only try to guess what you are doing, since you haven't shown either any code or a traceback, but I can imagine that you're probably trying to encode a Unicode string into bytes, but using the wrong encoding. I can almost replicate the error: the exception is the same, the message is not, although it is similar. >>> s = u'BIEBER FEVER \u2665' >>> print s # Printing Unicode is fine. BIEBER FEVER ? >>> s.encode() # but encoding defaults to ASCII Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u2665' in position 13: ordinal not in range(128) The right way is to specify an encoding that includes all the characters you need. Unless you have some reason to choose another encoding, the best thing to do is to just use UTF-8. >>> s.encode('utf-8') 'BIEBER FEVER \xe2\x99\xa5' -- Steven From cjw at ncf.ca Sat Aug 27 11:16:51 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 11:16:51 -0400 Subject: how to format long if conditions In-Reply-To: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E590A63.3060906@ncf.ca> On 27-Aug-11 03:50 AM, Hans Mulder wrote: > On 27/08/11 09:08:20, Arnaud Delobelle wrote: >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to<80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0]): >> py_and = PyCompare(left.complist + right.complist[1:]) >> else: >> py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I would break after the '(' and indent the condition once and > put the '):' bit on a separate line, aligned with the 'if': > > > if ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > ): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. > > -- HansM What about: cond= isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] py_and= PyCompare(left.complist + right.complist[1:])if cond else: py_and = PyBooleanAnd(left, right) Colin W. From cjw at ncf.ca Sat Aug 27 11:16:51 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 11:16:51 -0400 Subject: how to format long if conditions In-Reply-To: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E590A63.3060906@ncf.ca> On 27-Aug-11 03:50 AM, Hans Mulder wrote: > On 27/08/11 09:08:20, Arnaud Delobelle wrote: >> I'm wondering what advice you have about formatting if statements with >> long conditions (I always format my code to<80 colums) >> >> Here's an example taken from something I'm writing at the moment and >> how I've formatted it: >> >> >> if (isinstance(left, PyCompare) and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0]): >> py_and = PyCompare(left.complist + right.complist[1:]) >> else: >> py_and = PyBooleanAnd(left, right) >> >> What would you do? > > I would break after the '(' and indent the condition once and > put the '):' bit on a separate line, aligned with the 'if': > > > if ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > ): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) > > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. > > -- HansM What about: cond= isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] py_and= PyCompare(left.complist + right.complist[1:])if cond else: py_and = PyBooleanAnd(left, right) Colin W. From hansmu at xs4all.nl Sat Aug 27 11:53:48 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 27 Aug 2011 17:53:48 +0200 Subject: how to format long if conditions In-Reply-To: References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> Message-ID: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> On 27/08/11 17:16:51, Colin J. Williams wrote: > What about: > cond= isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > py_and= PyCompare(left.complist + right.complist[1:])if cond > else: py_and = PyBooleanAnd(left, right) > Colin W. That's a syntax error. You need to add parenthesis. How about: cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) -- HansM From roy at panix.com Sat Aug 27 12:39:02 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 12:39:02 -0400 Subject: how to format long if conditions References: Message-ID: In article , Arnaud Delobelle wrote: > Hi all, > > I'm wondering what advice you have about formatting if statements with > long conditions (I always format my code to <80 colums) > [...] > if (isinstance(left, PyCompare) and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0]): > py_and = PyCompare(left.complist + right.complist[1:]) > else: > py_and = PyBooleanAnd(left, right) To tie this into the ongoing, "When should I write a new function?" discussion, maybe the right thing here is to refactor all of that mess into its own function, so the code looks like: if _needs_compare(left, right): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) and then def _needs_compare(left, right): "Decide if we need to call PyCompare" return isinstance(left, PyCompare) and \ isinstance(right, PyCompare) and \ left.complist[-1] is right.complist[0] This seems easier to read/understand than what you've got now. It's an even bigger win if this will get called from multiple places. From roy at panix.com Sat Aug 27 12:41:36 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 12:41:36 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: Chris Angelico wrote: > the important > considerations are not "will it take two extra nanoseconds to execute" > but "can my successor understand what the code's doing" and "will he, > if he edits my code, have a reasonable expectation that he's not > breaking stuff". These are always important. Forget about your successor. Will *you* be able to figure out what you did 6 months from now? I can't tell you how many times I've looked at some piece of code, muttered, "Who wrote this crap?" and called up the checkin history only to discover that *I* wrote it :-) From Joshua.R.English at gmail.com Sat Aug 27 12:42:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 09:42:44 -0700 (PDT) Subject: Understanding .pth files Message-ID: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> I am developing a library for Python 2.7. I'm on Windows XP. I am also learning the "proper" way to do this (per PyPi) but not in a linear fashion: I've built a prototype for the library, created my setup script, and run the install to make sure I had that bit working properly. Now I'm continuing to develop the library alongside my examples and applications that use this library. The source is at c:\Dev\XmlDB. The installed package in in c:\Python27\lib\site-packages\xmldb\ According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder. (Otherwise I have my dev folder, but end up doing actual library development in the site-packages folder) So my C:\Python27\lib\site-packages\xmldb.pth file has one line: c:\dev\XmlDB\xmldb (I've tried the slashes the other way, too, but it doesn't seem to work). Is the only solution to delete the installed library and add the dev folder to my site.py file? Josh From Joshua.R.English at gmail.com Sat Aug 27 12:56:40 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 09:56:40 -0700 (PDT) Subject: Understanding .pth in site-packages Message-ID: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> (This may be a shortened double post) I have a development version of a library in c:\dev\XmlDB\xmldb After testing the setup script I also have c:\python27\lib\site-packages\xmldb Now I'm continuing to develop it and simultaneously building an application with it. I thought I could plug into my site-packages directory a file called xmldb.pth with: c:\dev\XmlDB\xmldb which should redirect import statements to the development version of the library. This doesn't seem to work. Is there a better way to redirect import statements without messing with the system path or the PYTHONPATH variable? Josh From rosuav at gmail.com Sat Aug 27 12:57:50 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 02:57:50 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:41 AM, Roy Smith wrote: > Forget about your successor. ?Will *you* be able to figure out what you > did 6 months from now? ?I can't tell you how many times I've looked at > some piece of code, muttered, "Who wrote this crap?" and called up the > checkin history only to discover that *I* wrote it :-) Heh. In that case, you were your own successor :) I always word it as a different person to dodge the "But I'll remember!" excuse, but you are absolutely right, and I've had that exact same experience myself. Fred comes up to me and says, "How do I use FooMatic?" Me: "I dunno, ask Joe." Fred: "But didn't you write it?" Me: "Yeah, that was years ago, I've forgotten. Ask Joe, he still uses the program." ChrisA From greymausg at mail.com Sat Aug 27 12:59:52 2011 From: greymausg at mail.com (greymaus) Date: 27 Aug 2011 16:59:52 GMT Subject: Record seperator References: Message-ID: On 2011-08-26, D'Arcy J.M. Cain wrote: > On 26 Aug 2011 18:39:07 GMT > greymaus wrote: >> >> Is there an equivelent for the AWK RS in Python? >> >> >> as in RS='\n\n' >> will seperate a file at two blank line intervals > > open("file.txt").read().split("\n\n") > Ta!.. bit awkard. :)))))) -- maus . . ... NO CARRIER From Ric at rdo Sat Aug 27 13:03:45 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 13:03:45 -0400 Subject: Arrange files according to a text file Message-ID: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Hello, What would be the best way to accomplish this task? I have many files in separate directories, each file name contain a persons name but never in the same spot. I need to find that name which is listed in a large text file in the following format. Last name, comma and First name. The last name could be duplicate. Adler, Jack Smith, John Smith, Sally Stone, Mark etc. The file names don't necessary follow any standard format. Smith, John - 02-15-75 - business files.doc Random Data - Adler Jack - expenses.xls More Data Mark Stone files list.doc etc I need some way to pull the name from the file name, find it in the text list and then create a directory based on the name on the list "Smith, John" and move all files named with the clients name into that directory. From philip at semanchuk.com Sat Aug 27 13:18:38 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 13:18:38 -0400 Subject: Understanding .pth in site-packages In-Reply-To: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <7C05C625-CD4F-453F-AC3B-BD28516AAF37@semanchuk.com> On Aug 27, 2011, at 12:56 PM, Josh English wrote: > (This may be a shortened double post) > > I have a development version of a library in c:\dev\XmlDB\xmldb > > After testing the setup script I also have c:\python27\lib\site-packages\xmldb > > Now I'm continuing to develop it and simultaneously building an application with it. > > I thought I could plug into my site-packages directory a file called xmldb.pth with: > > c:\dev\XmlDB\xmldb > > which should redirect import statements to the development version of the library. > > This doesn't seem to work. xmldb.pth should contain the directory that contains xmldb: c:\dev\XmlDB Examining sys.path at runtime probably would have helped you to debug the effect of your .pth file. On another note, I don't know if the behavior of 'import xmldb' is defined when xmldb is present both as a directory in site-pacakges and also as a .pth file. You're essentially giving Python two choices from where to import xmldb, and I don't know which Python will choose. It may be arbitrary. I've looked for some sort of statement on this topic in the documentation, but haven't come across it yet. > Is there a better way to redirect import statements without messing with the system path or the PYTHONPATH variable? Personally I have never used PYTHONPATH. Hope this helps Philip From python at mrabarnett.plus.com Sat Aug 27 13:22:58 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Aug 2011 18:22:58 +0100 Subject: Arrange files according to a text file In-Reply-To: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E5927F2.1010906@mrabarnett.plus.com> On 27/08/2011 18:03, Ric at rdo.python.org wrote: > Hello, > > What would be the best way to accomplish this task? > I have many files in separate directories, each file name > contain a persons name but never in the same spot. > I need to find that name which is listed in a large > text file in the following format. Last name, comma > and First name. The last name could be duplicate. > > Adler, Jack > Smith, John > Smith, Sally > Stone, Mark > etc. > > > The file names don't necessary follow any standard > format. > > Smith, John - 02-15-75 - business files.doc > Random Data - Adler Jack - expenses.xls > More Data Mark Stone files list.doc > etc > > I need some way to pull the name from the file name, find it in the > text list and then create a directory based on the name on the list > "Smith, John" and move all files named with the clients name into that > directory. I would get a name from the text file, eg. "Adler, Jack", and then identify all the files which contain "Adler, Jack" or "Adler Jack" or "Jack Adler" in the filename, also checking the surrounding characters to ensure that I don't split a name, eg. that "John" isn't part of "Johnson". From steve+comp.lang.python at pearwood.info Sat Aug 27 13:24:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 03:24:34 +1000 Subject: Record seperator References: Message-ID: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> greymaus wrote: > On 2011-08-26, D'Arcy J.M. Cain wrote: >> On 26 Aug 2011 18:39:07 GMT >> greymaus wrote: >>> >>> Is there an equivelent for the AWK RS in Python? >>> >>> >>> as in RS='\n\n' >>> will seperate a file at two blank line intervals >> >> open("file.txt").read().split("\n\n") >> > > > Ta!.. bit awkard. :)))))) Er, is that meant to be a pun? "Awk[w]ard", as in awk-ward? In any case, no, the Python line might be a handful of characters longer than the AWK equivalent, but it isn't awkward. It is logical and easy to understand. It's embarrassingly easy to describe what it does: open("file.txt") # opens the file .read() # reads the contents of the file .split("\n\n") # splits the text on double-newlines. The only tricky part is knowing that \n means newline, but anyone familiar with C, Perl, AWK etc. should know that. The Python code might be "long" (but only by the standards of AWK, which can be painfully concise), but it is simple, obvious and readable. A few extra characters is the price you pay for making your language readable. At the cost of a few extra key presses, you get something that you will be able to understand in 10 years time. AWK is a specialist text processing language. Python is a general scripting and programming language. They have different values: AWK values short, concise code, Python is willing to pay a little more in source code. -- Steven From emile at fenx.com Sat Aug 27 13:27:48 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 10:27:48 -0700 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On 8/27/2011 9:41 AM Roy Smith said... > Chris Angelico wrote: > >> the important >> considerations are not "will it take two extra nanoseconds to execute" >> but "can my successor understand what the code's doing" and "will he, >> if he edits my code, have a reasonable expectation that he's not >> breaking stuff". These are always important. > > Forget about your successor. Will *you* be able to figure out what you > did 6 months from now? I can't tell you how many times I've looked at > some piece of code, muttered, "Who wrote this crap?" and called up the > checkin history only to discover that *I* wrote it :-) When you consider that you're looking at the code six months later it's likely for one of three reasons: you have to fix a bug; you need to add features; or the code's only now getting used. So you then take the extra 20-30 minutes, tease the code apart, refactor as needed and end up with better more readable debugged code. I consider that the right time to do this type of cleanup. For all the crap I write that works well for six months before needing to be cleaned up, there's a whole lot more crap that never gets looked at again that I didn't clean up and never spent the extra 20-30 minutes considering how my future self might view what I wrote. I'm not suggesting that you shouldn't develop good coding habits that adhere to established standards and result in well structured readable code, only that if that ugly piece of code works that you move on. You can bullet proof it after you uncover the vulnerabilities. Code is first and foremost written to be executed. Emile From __peter__ at web.de Sat Aug 27 13:29:07 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Aug 2011 19:29:07 +0200 Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > I have a development version of a library in c:\dev\XmlDB\xmldb > > After testing the setup script I also have > c:\python27\lib\site-packages\xmldb > > Now I'm continuing to develop it and simultaneously building an > application with it. > > I thought I could plug into my site-packages directory a file called > xmldb.pth with: > > c:\dev\XmlDB\xmldb > > which should redirect import statements to the development version of the > library. > > This doesn't seem to work. You have to put the directory containing the package into the pth-file. That's probably c:\dev\XmlDB in your case. Also, Python will stop at the first matching module or package; if you keep c:\python27\lib\site-packages\xmldb that will shadow c:\dev\XmlDB\xmldb. %APPDATA%/Python/Python26/site-packages may be a good place for the pth-file (I'm not on Windows and too lazy to figure out where %APPDATA% actually is. The PEP http://www.python.org/dev/peps/pep-0370/ may help) From rosuav at gmail.com Sat Aug 27 13:31:19 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 03:31:19 +1000 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 3:27 AM, Emile van Sebille wrote: > Code is first and foremost written to be executed. > +1 QOTW. Yes, it'll be read, and most likely read several times, by humans, but ultimately its purpose is to be executed. And in the case of some code, the programmer needs the same treatment, but that's a different issue... ChrisA From clp2 at rebertia.com Sat Aug 27 13:35:14 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Aug 2011 10:35:14 -0700 Subject: typing question In-Reply-To: References: Message-ID: On Sat, Aug 27, 2011 at 6:42 AM, Jason Swails wrote: > Hello everyone, > > This is probably a basic question with an obvious answer, but I don't quite > get why the type(foo).__name__ works differently for some class instances > and not for others.? If I have an "underived" class, any instance of that > class is simply of type "instance".? If I include an explicit base class, > then its type __name__ is the name of the class. > > $ python > Python 2.7.2 (default, Aug 26 2011, 22:35:24) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> class MyClass: > ...???? pass > ... >>>> foo = MyClass() >>>> type(foo) > >>>> type(foo).__name__ > 'instance' >>>> class MyClass1(): > ...???? pass > ... >>>> bar = MyClass1() >>>> type(bar) > >>>> type(bar).__name__ > 'instance' >>>> class MyClass2(object): > ...???? pass > ... >>>> foobar = MyClass2() >>>> type(foobar) > >>>> type(foobar).__name__ > 'MyClass2' > > I can't explain this behavior (since doesn't every class inherit from object > by default? That's only true in Python 3.x. Python 2.7.2 (default, Jul 27 2011, 04:14:23) >>> class Foo: ... pass ... >>> Foo.__bases__ () >>> class Bar(object): ... pass ... >>> Bar.__bases__ (,) > And if so, there should be no difference between any of my class > definitions).? I would prefer that every approach give me the name of the > class (rather than the first 2 just return 'instance').? Why is this not the > case? Classes directly or indirectly inheriting from `object` are "new-style"; classes which don't are "old-style". The two kinds of classes have different semantics (including whether they have a .__name__, but that's minor relative to the other changes). Old-style classes are deprecated and were removed in Python 3. See http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes Cheers, Chris From roy at panix.com Sat Aug 27 13:45:31 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 13:45:31 -0400 Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n") # splits the text on double-newlines. The biggest problem with this code is that read() slurps the entire file into a string. That's fine for moderately sized files, but will fail (or at least be grossly inefficient) for very large files. It's always annoyed me a little that while it's easy to iterate over the lines of a file, it's more complicated to iterate over a file character by character. You could write your own generator to do that: for c in getchar(open("file.txt")): whatever def getchar(f): for line in f: for c in line: yield c but that's annoyingly verbose (and probably not hugely efficient). Of course, the next problem for the specific problem at hand is that even with an iterator over the characters of a file, split() only works on strings. It would be nice to have a version of split which took an iterable and returned an iterator over the split components. Maybe there is such a thing and I'm just missing it? From Joshua.R.English at gmail.com Sat Aug 27 13:57:01 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 10:57:01 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Philip, Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. Why the egg file, which doesn't list any paths, would interfere I do not know. But with those changes, the xmldb.pth file is being read. So I think the preferred search order is: 1. a folder in the site-packages directory 2. an Egg file (still unsure why) 3. A .pth file It's a strange juju that I haven't figured out yet. Thanks for the hint. Josh From Joshua.R.English at gmail.com Sat Aug 27 13:57:01 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 10:57:01 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Philip, Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. Why the egg file, which doesn't list any paths, would interfere I do not know. But with those changes, the xmldb.pth file is being read. So I think the preferred search order is: 1. a folder in the site-packages directory 2. an Egg file (still unsure why) 3. A .pth file It's a strange juju that I haven't figured out yet. Thanks for the hint. Josh From emile at fenx.com Sat Aug 27 14:06:22 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 11:06:22 -0700 Subject: Arrange files according to a text file In-Reply-To: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 10:03 AM Ric at rdo.python.org said... > Hello, > > What would be the best way to accomplish this task? I'd do something like: usernames = """Adler, Jack Smith, John Smith, Sally Stone, Mark""".split('\n') filenames = """Smith, John - 02-15-75 - business files.doc Random Data - Adler Jack - expenses.xls More Data Mark Stone files list.doc""".split('\n') from difflib import SequenceMatcher as SM def ignore(x): return x in ' ,.' for filename in filenames: ratios = [SM(ignore,filename,username).ratio() for username in usernames] best = max(ratios) owner = usernames[ratios.index(best)] print filename,":",owner Emile > I have many files in separate directories, each file name > contain a persons name but never in the same spot. > I need to find that name which is listed in a large > text file in the following format. Last name, comma > and First name. The last name could be duplicate. > > Adler, Jack > Smith, John > Smith, Sally > Stone, Mark > etc. > > > The file names don't necessary follow any standard > format. > > Smith, John - 02-15-75 - business files.doc > Random Data - Adler Jack - expenses.xls > More Data Mark Stone files list.doc > etc > > I need some way to pull the name from the file name, find it in the > text list and then create a directory based on the name on the list > "Smith, John" and move all files named with the clients name into that > directory. From philip at semanchuk.com Sat Aug 27 14:07:02 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 14:07:02 -0400 Subject: Understanding .pth in site-packages In-Reply-To: <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: On Aug 27, 2011, at 1:57 PM, Josh English wrote: > Philip, > > Yes, the proper path should be c:\dev\XmlDB, which has the setup.py, xmldb subfolder, the docs subfolder, and example subfolder, and the other text files proscribed by the package development folder. > > I could only get it to work, though, by renaming the xmldb folder in the site-packages directory, and deleting the egg file created in the site-packages directory. > > Why the egg file, which doesn't list any paths, would interfere I do not know. > > But with those changes, the xmldb.pth file is being read. > > So I think the preferred search order is: > > 1. a folder in the site-packages directory > 2. an Egg file (still unsure why) > 3. A .pth file That might be implementation-dependent or it might even come down to something as simple as the in which order the operating system returns files/directories when asked for a listing. In other words, unless you can find something in the documentation (or Python's import implementation) that confirms your preferred search order observation, I would not count on it working the same way with all systems, all Pythons, or even all directory names. Good luck Philip From cbrown at cbrownsystems.com Sat Aug 27 14:40:09 2011 From: cbrown at cbrownsystems.com (ChasBrown) Date: Sat, 27 Aug 2011 11:40:09 -0700 (PDT) Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 27, 10:45?am, Roy Smith wrote: > In article <4e592852$0$29965$c3e8da3$54964... at news.astraweb.com>, > ?Steven D'Aprano wrote: > > > open("file.txt") ? # opens the file > > ?.read() ? ? ? ? ? # reads the contents of the file > > ?.split("\n\n") ? ?# splits the text on double-newlines. > > The biggest problem with this code is that read() slurps the entire file > into a string. ?That's fine for moderately sized files, but will fail > (or at least be grossly inefficient) for very large files. > > It's always annoyed me a little that while it's easy to iterate over the > lines of a file, it's more complicated to iterate over a file character > by character. ?You could write your own generator to do that: > > for c in getchar(open("file.txt")): > ? ?whatever > > def getchar(f): > ? ?for line in f: > ? ? ? for c in line: > ? ? ? ? ?yield c > > but that's annoyingly verbose (and probably not hugely efficient). read() takes an optional size parameter; so f.read(1) is another option... > > Of course, the next problem for the specific problem at hand is that > even with an iterator over the characters of a file, split() only works > on strings. ?It would be nice to have a version of split which took an > iterable and returned an iterator over the split components. ?Maybe > there is such a thing and I'm just missing it? I don't know if there is such a thing; but for the OP's problem you could read the file in chunks, e.g.: def readgroup(f, delim, buffsize=8192): tail='' while True: s = f.read(buffsize) if not s: yield tail break groups = (tail + s).split(delim) tail = groups[-1] for group in groups[:-1]: yield group for group in readgroup(open('file.txt'), '\n\n'): # do something Cheers - Chas From me+list/python at ixokai.io Sat Aug 27 14:48:03 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 11:48:03 -0700 Subject: Run time default arguments In-Reply-To: <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> References: <0512758d-d5d2-4c07-a4cd-bac747c47aa1@s2g2000vby.googlegroups.com> <65ce4c73-c3b0-4232-9783-1ccb9012780c@t3g2000vbe.googlegroups.com> Message-ID: <4E593BE3.8080905@ixokai.io> On 8/25/11 1:54 PM, ting at thsu.org wrote: > On Aug 25, 10:35 am, Arnaud Delobelle wrote: >> You're close to the usual idiom: >> >> def doSomething(debug=None): >> if debug is None: >> debug = defaults['debug'] >> ... >> >> Note the use of 'is' rather than '==' >> HTH > > Hmm, from what you are saying, it seems like there's no elegant way to > handle run time defaults for function arguments, Well, elegance is in the eye of the beholder: and the above idiom is generally considered elegant in Python, more or less. (The global nature of 'defaults' being a question) > meaning that I should > probably write a sql-esc coalesce function to keep my code cleaner. I > take it that most people who run into this situation do this? > > def coalesce(*args): > for a in args: > if a is not None: > return a > return None > > def doSomething(debug=None): > debug = coalesce(debug,defaults['debug']) > # blah blah blah Er, I'd say that most people don't do that, no. I'd guess that most do something more along the lines of "if debug is None: debug = default" as Arnaud said. Its very common Pythonic code. In fact, I'm not quite sure what you think you're getting out of that coalesce function. "Return the first argument that is not None, or return None"? That's a kind of odd thing to do, I think. In Python at least. Why not just: debug = defaults.get("debug", None) (Strictly speaking, providing None to get is not needed, but I always feel odd leaving it off.) That's generally how I spell it when I need to do run time defaults. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From dbigbear at gmail.com Sat Aug 27 15:24:33 2011 From: dbigbear at gmail.com (Xiong Deng) Date: Sun, 28 Aug 2011 03:24:33 +0800 Subject: How can I solve a equation like solve a function containint expressions like sqrt(log(x) - 1) = 2 and exp((log(x) - 1.5)**2 - 3) = 5 In-Reply-To: References: Message-ID: HI, Hi, I am trying to solve an equation containing both exp, log, erfc, and they may be embedded into each other....But sympy cannot handle this, as shown below: >>> from sympy import solve, exp, log, pi >>>from sympy.mpmath import * >>>from sympy import Symbol >>>x=Symbol('x') >>>sigma = 4 >>>mu = 1.5 >>>solve(x * ((1.0 / sqrt(2 * pi) * x * sigma) * exp(-0.5 * (log(x) - mu)**2 / sigma**2)) + 0.5 * erfc((mu - log(x)) / (sigma * sqrt(2))) - 1, x) Traceback (most recent call last): File "", line 1, in File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/functions/functions.py", line 287, in log return ctx.ln(x) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp_python.py", line 984, in f x = ctx.convert(x) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp_python.py", line 662, in convert return ctx._convert_fallback(x, strings) File "/home/work/local/python-2.7.1/lib/python2.7/site-packages/sympy/mpmath/ctx_mp.py", line 556, in _convert_fallback raise TypeError("cannot create mpf from " + repr(x)) TypeError: cannot create mpf from x But sqrt, log, exp, itself is OK, as shown as below: >>> solve((1.0 / sqrt(2 * pi) * x * sigma) - 1, x) [0.626657068657750] SO, How can I solve an equation containint expressions like sqrt(log(x) - 1)=0 or exp((log(x) - mu)**2 - 3) = 0??? If there are any other methods without Sympy, it is still OK. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From brenNOSPAMbarn at NObrenSPAMbarn.net Sat Aug 27 15:45:45 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 27 Aug 2011 19:45:45 +0000 (UTC) Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > Philip, > > Yes, the proper path should be c:\dev\XmlDB, which has the > setup.py, xmldb subfolder, the docs subfolder, and example > subfolder, and the other text files proscribed by the package > development folder. > > I could only get it to work, though, by renaming the xmldb folder > in the site-packages directory, and deleting the egg file created > in the site-packages directory. > > Why the egg file, which doesn't list any paths, would interfere I > do not know. > > But with those changes, the xmldb.pth file is being read. > > So I think the preferred search order is: > > 1. a folder in the site-packages directory > 2. an Egg file (still unsure why) > 3. A .pth file You say that the egg file was created by the setup script for the library. Are you sure that this script did not also create or modify a .pth file of its own, adding the egg to the path? .pth files do not "redirect" imports from site-packages; they add EXTRA directories to sys.path. Also note that this means the .pth file itself is not part of the search path; it's not like you shadow a package xyz by creating a .pth file xyz.pth "instead". A single .pth file can list multiple directories, and it's those directories that are added to the path. I'm not sure how your package is set up, but easy_install, for instance, creates an easy_install.pth file in site-packages. This file contains references to egg files (or, at least in my case, .egg directories created by unpacking the eggs) for each package installed with easy_install. As far as I'm aware, Python doesn't have special rules for putting egg files in the search path, so my guess is that it's something like that: the "setup script" is creating a .pth file (or modifying an existing .pth file) to add the egg to the path. Read http://docs.python.org/library/site.html for the description of how .PTH files work. I don't think there is a general way to globally "shadow" a package that exists in site-packages. However, according to the docs the .pth files are added in alphabetical order, so if it is indeed easy_install.pth that is adding your egg, you could hack around it by making a file with an alphabetically earlier name (e.g., a_xmldb.pth). -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From tjreedy at udel.edu Sat Aug 27 16:03:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:03:44 -0400 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/27/2011 1:45 PM, Roy Smith wrote: > In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> open("file.txt") # opens the file >> .read() # reads the contents of the file >> .split("\n\n") # splits the text on double-newlines. > > The biggest problem with this code is that read() slurps the entire file > into a string. That's fine for moderately sized files, but will fail > (or at least be grossly inefficient) for very large files. I read the above as separating the file into paragraphs, as indicated by blank lines. def paragraphs(file): para = [] for line in file: if line: para.append(line) else: yield para # or ''.join(para), as desired para = [] -- Terry Jan Reedy From rosuav at gmail.com Sat Aug 27 16:07:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 06:07:08 +1000 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 28, 2011 at 6:03 AM, Terry Reedy wrote: > ? ? ?yield para # or ''.join(para), as desired > Or possibly '\n'.join(para) if you want to keep the line breaks inside paragraphs. ChrisA From tjreedy at udel.edu Sat Aug 27 16:08:25 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:08:25 -0400 Subject: typing question In-Reply-To: References: Message-ID: On 8/27/2011 9:42 AM, Jason Swails wrote: > P.S. I'll note that my "preferred" behavior is how python3.2 actually > operates Python core developers agree. This is one of the reasons for breaking a bit from 2.x to make Python 3. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 27 16:14:15 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 16:14:15 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: On 8/27/2011 2:07 PM, Philip Semanchuk wrote: > > On Aug 27, 2011, at 1:57 PM, Josh English wrote: > >> Philip, >> >> Yes, the proper path should be c:\dev\XmlDB, which has the >> setup.py, xmldb subfolder, the docs subfolder, and example >> subfolder, and the other text files proscribed by the package >> development folder. >> >> I could only get it to work, though, by renaming the xmldb folder >> in the site-packages directory, and deleting the egg file created >> in the site-packages directory. >> >> Why the egg file, which doesn't list any paths, would interfere I >> do not know. >> >> But with those changes, the xmldb.pth file is being read. >> >> So I think the preferred search order is: >> >> 1. a folder in the site-packages directory 2. an Egg file (still >> unsure why) 3. A .pth file > > > That might be implementation-dependent or it might even come down to > something as simple as the in which order the operating system > returns files/directories when asked for a listing. Doc says first match, and I presume that includes first match within a directory. -- Terry Jan Reedy From Ric at rdo Sat Aug 27 16:15:44 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 16:15:44 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: Hello Emile , Thank you for the code below as I have not encountered SequenceMatcher before and would have to take a look at it closer. My question would it work for a text file list of names about 25k lines and a directory with say 100 files inside? Thank you once again. On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille wrote: >On 8/27/2011 10:03 AM Ric at rdo.python.org said... >> Hello, >> >> What would be the best way to accomplish this task? > >I'd do something like: > > >usernames = """Adler, Jack >Smith, John >Smith, Sally >Stone, Mark""".split('\n') > >filenames = """Smith, John - 02-15-75 - business files.doc >Random Data - Adler Jack - expenses.xls >More Data Mark Stone files list.doc""".split('\n') > >from difflib import SequenceMatcher as SM > > >def ignore(x): > return x in ' ,.' > > >for filename in filenames: > ratios = [SM(ignore,filename,username).ratio() for username in >usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner > > >Emile > > > >> I have many files in separate directories, each file name >> contain a persons name but never in the same spot. >> I need to find that name which is listed in a large >> text file in the following format. Last name, comma >> and First name. The last name could be duplicate. >> >> Adler, Jack >> Smith, John >> Smith, Sally >> Stone, Mark >> etc. >> >> >> The file names don't necessary follow any standard >> format. >> >> Smith, John - 02-15-75 - business files.doc >> Random Data - Adler Jack - expenses.xls >> More Data Mark Stone files list.doc >> etc >> >> I need some way to pull the name from the file name, find it in the >> text list and then create a directory based on the name on the list >> "Smith, John" and move all files named with the clients name into that >> directory. > From steve+comp.lang.python at pearwood.info Sat Aug 27 16:27:32 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 06:27:32 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > On Sun, Aug 28, 2011 at 3:27 AM, Emile van Sebille wrote: >> Code is first and foremost written to be executed. >> > > +1 QOTW. Yes, it'll be read, and most likely read several times, by > humans, but ultimately its purpose is to be executed. You've never noticed the masses of code written in text books, blogs, web pages, discussion forums like this one, etc.? Real world code for production is usually messy and complicated and filled with data validation and error checking code. There's a lot of code without that, because it was written explicitly to be read by humans, and the fact that it may be executed as well is incidental. Some code is even written in pseudo-code that *cannot* be executed. It's clear to me that a non-trivial amount of code is specifically written to be consumed by other humans, not by machines. It seems to me that, broadly speaking, there are languages designed with execution of code as the primary purpose: Fortran, C, Lisp, Java, PL/I, APL, Forth, ... and there are languages designed with *writing* of code as the primary purpose: Perl, AWK, sed, bash, ... and then there are languages where *reading* is the primary purpose: Python, Ruby, Hypertalk, Inform 7, Pascal, AppleScript, ... and then there are languages where the torment of the damned is the primary purpose: INTERCAL, Oook, Brainf*ck, Whitespace, Malbolge, ... and then there are languages with few, or no, design principles to speak of, or as compromise languages that (deliberately or accidentally) straddle the other categories. It all depends on the motivation and values of the language designer, and the trade-offs the language makes. Which category any specific language may fall into may be a matter of degree, or a matter of opinion, or both. -- Steven From philip at semanchuk.com Sat Aug 27 16:28:27 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 16:28:27 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <21BF439E-678A-4B07-9F6D-0CF60945691E@semanchuk.com> On Aug 27, 2011, at 4:14 PM, Terry Reedy wrote: > On 8/27/2011 2:07 PM, Philip Semanchuk wrote: >> >> On Aug 27, 2011, at 1:57 PM, Josh English wrote: >> >>> Philip, >>> >>> Yes, the proper path should be c:\dev\XmlDB, which has the >>> setup.py, xmldb subfolder, the docs subfolder, and example >>> subfolder, and the other text files proscribed by the package >>> development folder. >>> >>> I could only get it to work, though, by renaming the xmldb folder >>> in the site-packages directory, and deleting the egg file created >>> in the site-packages directory. >>> >>> Why the egg file, which doesn't list any paths, would interfere I >>> do not know. >>> >>> But with those changes, the xmldb.pth file is being read. >>> >>> So I think the preferred search order is: >>> >>> 1. a folder in the site-packages directory 2. an Egg file (still >>> unsure why) 3. A .pth file >> >> >> That might be implementation-dependent or it might even come down to >> something as simple as the in which order the operating system >> returns files/directories when asked for a listing. > > Doc says first match, and I presume that includes first match within a directory. First match using which ordering? Do the docs clarify that? Thanks Philip From rosuav at gmail.com Sat Aug 27 16:38:31 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 28 Aug 2011 06:38:31 +1000 Subject: is there any principle when writing python function In-Reply-To: <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 28, 2011 at 6:27 AM, Steven D'Aprano wrote: > You've never noticed the masses of code written in text books, blogs, web > pages, discussion forums like this one, etc.? > > Real world code for production is usually messy and complicated and filled > with data validation and error checking code. There's a lot of code without > that, because it was written explicitly to be read by humans, and the fact > that it may be executed as well is incidental. Some code is even written in > pseudo-code that *cannot* be executed. It's clear to me that a non-trivial > amount of code is specifically written to be consumed by other humans, not > by machines. Yes, I'm aware of the quantities of code that are primarily for human consumption. But in the original context, which was of editing code six months down the track, I still believe that such code is primarily for the machine. In that situation, there are times when it's not worth the hassle of writing beautiful code; you'd do better to just get that code generated and in operation. Same goes for lint tools and debuggers - sometimes, it's easier to just put the code into a live situation (or a perfect copy of) and see where it breaks, than to use a simulation/test harness. ChrisA From roy at panix.com Sat Aug 27 17:07:48 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 17:07:48 -0400 Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Terry Reedy wrote: > On 8/27/2011 1:45 PM, Roy Smith wrote: > > In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> open("file.txt") # opens the file > >> .read() # reads the contents of the file > >> .split("\n\n") # splits the text on double-newlines. > > > > The biggest problem with this code is that read() slurps the entire file > > into a string. That's fine for moderately sized files, but will fail > > (or at least be grossly inefficient) for very large files. > > I read the above as separating the file into paragraphs, as indicated by > blank lines. > > def paragraphs(file): > para = [] > for line in file: > if line: > para.append(line) > else: > yield para # or ''.join(para), as desired > para = [] Plus or minus the last paragraph in the file :-) From emile at fenx.com Sat Aug 27 17:08:17 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 14:08:17 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 1:15 PM Ric at rdo.python.org said... > > Hello Emile , > > Thank you for the code below as I have not encountered SequenceMatcher > before and would have to take a look at it closer. > > My question would it work for a text file list of names about 25k > lines and a directory with say 100 files inside? Sure. Emile > > Thank you once again. > > > On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille > wrote: > >> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>> Hello, >>> >>> What would be the best way to accomplish this task? >> >> I'd do something like: >> >> >> usernames = """Adler, Jack >> Smith, John >> Smith, Sally >> Stone, Mark""".split('\n') >> >> filenames = """Smith, John - 02-15-75 - business files.doc >> Random Data - Adler Jack - expenses.xls >> More Data Mark Stone files list.doc""".split('\n') >> >>from difflib import SequenceMatcher as SM >> >> >> def ignore(x): >> return x in ' ,.' >> >> >> for filename in filenames: >> ratios = [SM(ignore,filename,username).ratio() for username in >> usernames] >> best = max(ratios) >> owner = usernames[ratios.index(best)] >> print filename,":",owner >> >> >> Emile >> >> >> >>> I have many files in separate directories, each file name >>> contain a persons name but never in the same spot. >>> I need to find that name which is listed in a large >>> text file in the following format. Last name, comma >>> and First name. The last name could be duplicate. >>> >>> Adler, Jack >>> Smith, John >>> Smith, Sally >>> Stone, Mark >>> etc. >>> >>> >>> The file names don't necessary follow any standard >>> format. >>> >>> Smith, John - 02-15-75 - business files.doc >>> Random Data - Adler Jack - expenses.xls >>> More Data Mark Stone files list.doc >>> etc >>> >>> I need some way to pull the name from the file name, find it in the >>> text list and then create a directory based on the name on the list >>> "Smith, John" and move all files named with the clients name into that >>> directory. >> From roy at panix.com Sat Aug 27 17:09:51 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 17:09:51 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <4e595334$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e595334$0$30000$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > and then there are languages with few, or no, design principles to speak of Oh, like PHP? From cjw at ncf.ca Sat Aug 27 17:25:10 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 17:25:10 -0400 Subject: how to format long if conditions In-Reply-To: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E5960B6.1070901@ncf.ca> On 27-Aug-11 11:53 AM, Hans Mulder wrote: > On 27/08/11 17:16:51, Colin J. Williams wrote: > >> What about: >> cond= isinstance(left, PyCompare) >> and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0] >> py_and= PyCompare(left.complist + right.complist[1:])if cond >> else: py_and = PyBooleanAnd(left, right) >> Colin W. > > That's a syntax error. You need to add parenthesis. > > How about: > > cond = ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > } > py_and = ( > PyCompare(left.complist + right.complist[1:]) > if cond > else PyBooleanAnd(left, right) > ) > > -- HansM I like your 11:53 message but suggest indenting the if cond as below to make it clearer that it, with the preceding line, is all one statement. Colin W. #!/usr/bin/env python z= 1 class PyCompare: complist = [True, False] def __init__(self): pass left= PyCompare right= PyCompare def isinstance(a, b): return True def PyBooleanAnd(a, b): return True def PyCompare(a): return False z=2 def try1(): ''' Hans Mulder suggestion 03:50 ''' if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) def try2(): ''' cjw response - corrected 11:56 ''' cond= (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) py_and= (PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right)) def try3(): ''' Hans Mulder 11:53 ''' cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ) # not } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) def main(): try1() try2() try3() if __name__ == '__main__': main() pass From cjw at ncf.ca Sat Aug 27 17:25:10 2011 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 27 Aug 2011 17:25:10 -0400 Subject: how to format long if conditions In-Reply-To: <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> References: <4e58a1cc$0$2474$e4fe514c@news2.news.xs4all.nl> <4e59130d$0$2411$e4fe514c@news2.news.xs4all.nl> Message-ID: <4E5960B6.1070901@ncf.ca> On 27-Aug-11 11:53 AM, Hans Mulder wrote: > On 27/08/11 17:16:51, Colin J. Williams wrote: > >> What about: >> cond= isinstance(left, PyCompare) >> and isinstance(right, PyCompare) >> and left.complist[-1] is right.complist[0] >> py_and= PyCompare(left.complist + right.complist[1:])if cond >> else: py_and = PyBooleanAnd(left, right) >> Colin W. > > That's a syntax error. You need to add parenthesis. > > How about: > > cond = ( > isinstance(left, PyCompare) > and isinstance(right, PyCompare) > and left.complist[-1] is right.complist[0] > } > py_and = ( > PyCompare(left.complist + right.complist[1:]) > if cond > else PyBooleanAnd(left, right) > ) > > -- HansM I like your 11:53 message but suggest indenting the if cond as below to make it clearer that it, with the preceding line, is all one statement. Colin W. #!/usr/bin/env python z= 1 class PyCompare: complist = [True, False] def __init__(self): pass left= PyCompare right= PyCompare def isinstance(a, b): return True def PyBooleanAnd(a, b): return True def PyCompare(a): return False z=2 def try1(): ''' Hans Mulder suggestion 03:50 ''' if ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ): py_and = PyCompare(left.complist + right.complist[1:]) else: py_and = PyBooleanAnd(left, right) def try2(): ''' cjw response - corrected 11:56 ''' cond= (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) py_and= (PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right)) def try3(): ''' Hans Mulder 11:53 ''' cond = ( isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0] ) # not } py_and = ( PyCompare(left.complist + right.complist[1:]) if cond else PyBooleanAnd(left, right) ) def main(): try1() try2() try3() if __name__ == '__main__': main() pass From ben+python at benfinney.id.au Sat Aug 27 17:51:10 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Aug 2011 07:51:10 +1000 Subject: UnicodeEncodeError -- 'character maps to ' References: <32ed9303-96d6-4576-bb49-8b5fbefb0e30@glegroupsg2000goo.googlegroups.com> <4e590684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zkiuttf5.fsf@benfinney.id.au> Steven D'Aprano writes: > >>> s = u'BIEBER FEVER \u2665' > >>> print s # Printing Unicode is fine. > BIEBER FEVER ? You're a cruel man. Why do you hate me? -- \ ?If nature has made any one thing less susceptible than all | `\ others of exclusive property, it is the action of the thinking | _o__) power called an idea? ?Thomas Jefferson, 1813-08-13 | Ben Finney From ben+python at benfinney.id.au Sat Aug 27 17:57:48 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Aug 2011 07:57:48 +1000 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <87vctitt43.fsf@benfinney.id.au> Emile van Sebille writes: > Code is first and foremost written to be executed. ?1 QotW. I disagree, and have a counter-aphorism: ?Programs must be written for people to read, and only incidentally for machines to execute.? ?Abelson & Sussman, _Structure and Interpretation of Computer Programs_ Yes, the primary *function* of the code you write is for it to eventually execute. But the primary *audience* of the text you type into your buffer is not the computer, but the humans who will read it. That's what must be foremost in your mind while writing that text. -- \ ?If you can't beat them, arrange to have them beaten.? ?George | `\ Carlin | _o__) | Ben Finney From emile at fenx.com Sat Aug 27 18:21:06 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 15:21:06 -0700 Subject: is there any principle when writing python function In-Reply-To: <87vctitt43.fsf@benfinney.id.au> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: On 8/27/2011 2:57 PM Ben Finney said... > Emile van Sebille writes: > >> Code is first and foremost written to be executed. > > ?Programs must be written for people to read, and only incidentally for > machines to execute.? > ?Abelson& Sussman, _Structure and Interpretation of Computer Programs_ > That's certainly self-fulfilling -- code that doesn't execute will need to be read to be understood, and to be fixed so that it does run. Nobody cares about code not intended to be executed. Pretty it up as much as you have free time to do so to enlighten your intended audience. Code that runs from the offset may not ever again need to be read, so the only audience will ever be the processor. I find it much to easy to waste enormous amounts of time prettying up code that works. Pretty it up when it doesn't -- that's the code that needs the attention. Emile > Yes, the primary *function* of the code you write is for it to > eventually execute. But the primary *audience* of the text you type into > your buffer is not the computer, but the humans who will read it. That's > what must be foremost in your mind while writing that text. > From Joshua.R.English at gmail.com Sat Aug 27 18:39:24 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:39:24 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> Message-ID: <47945742-a04c-4eda-aee3-a0026c04e360@glegroupsg2000goo.googlegroups.com> OKB, The setup.py script created the egg, but not the .pth file. I created that myself. Thank you for clarifying about how .pth works. I know "redirect imports" was the wrong phrase, but it worked in my head at the time. It appears, at least on my system, that Python will find site-packages/foo before it finds and reads site-packages/foo.pth. At least this solution gives me a way to develop my libraries outside of site-packages. Josh From Joshua.R.English at gmail.com Sat Aug 27 18:41:58 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:41:58 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? Josh From Joshua.R.English at gmail.com Sat Aug 27 18:41:58 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:41:58 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? Josh From Joshua.R.English at gmail.com Sat Aug 27 18:49:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:49:44 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) I would guess Python is using os.listdir. Why wouldn't it? From Joshua.R.English at gmail.com Sat Aug 27 18:49:44 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 27 Aug 2011 15:49:44 -0700 (PDT) Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) I would guess Python is using os.listdir. Why wouldn't it? From rantingrick at gmail.com Sat Aug 27 19:01:47 2011 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Aug 2011 16:01:47 -0700 (PDT) Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: <6930db73-816a-44a9-be1f-0915ced571a3@p10g2000yqi.googlegroups.com> On Aug 27, 5:21?pm, Emile van Sebille wrote: > On 8/27/2011 2:57 PM Ben Finney said... > > > Emile van Sebille ?writes: > > >> Code is first and foremost written to be executed. > > > ? ? ??Programs must be written for people to read, and only incidentally for > > ? ? ?machines to execute.? > > ? ? ??Abelson& ?Sussman, _Structure and Interpretation of Computer Programs_ > > That's certainly self-fulfilling -- code that doesn't execute will need > to be read to be understood, and to be fixed so that it does run. > Nobody cares about code not intended to be executed. ?Pretty it up as > much as you have free time to do so to enlighten your intended audience. > > Code that runs from the offset may not ever again need to be read, so > the only audience will ever be the processor. WRONG! Code may need to be extended someday no matter HOW well it executes today. Also, code need to be readable so the readers can learn from it. From roy at panix.com Sat Aug 27 19:09:41 2011 From: roy at panix.com (Roy Smith) Date: Sat, 27 Aug 2011 19:09:41 -0400 Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: In article , Emile van Sebille wrote: > code that doesn't execute will need to be read to be understood, and > to be fixed so that it does run. That is certainly true, but it's not the whole story. Even code that works perfectly today will need to be modified in the future. Business requirements change. Your code will need to be ported to a new OS. You'll need to make it work for 64-bit. Or i18n. Or y2k (well, don't need to worry about that one any more). Or with a different run-time library. A new complier. A different database. Regulatory changes will impose new requirements Or, your company will get bought and you'll need to interface with a whole new system. Code is never done. At least not until the project is dead. From Ric at rdo Sat Aug 27 19:18:54 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 19:18:54 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: Thank you so much. The code worked perfectly. This is what I tried using Emile code. The only time when it picked wrong name from the list was when the file was named like this. Data Mark Stone.doc How can I fix this? Hope I am not asking too much? import os from difflib import SequenceMatcher as SM path = r'D:\Files ' txt_names = [] with open(r'D:/python/log1.txt') as f: for txt_name in f.readlines(): txt_names.append(txt_name.strip()) def ignore(x): return x in ' ,.' for filename in os.listdir(path): ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in txt_names] best = max(ratios) owner = txt_names[ratios.index(best)] print filename,":",owner On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille wrote: >On 8/27/2011 1:15 PM Ric at rdo.python.org said... >> >> Hello Emile , >> >> Thank you for the code below as I have not encountered SequenceMatcher >> before and would have to take a look at it closer. >> >> My question would it work for a text file list of names about 25k >> lines and a directory with say 100 files inside? > >Sure. > >Emile > > >> >> Thank you once again. >> >> >> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >> wrote: >> >>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>> Hello, >>>> >>>> What would be the best way to accomplish this task? >>> >>> I'd do something like: >>> >>> >>> usernames = """Adler, Jack >>> Smith, John >>> Smith, Sally >>> Stone, Mark""".split('\n') >>> >>> filenames = """Smith, John - 02-15-75 - business files.doc >>> Random Data - Adler Jack - expenses.xls >>> More Data Mark Stone files list.doc""".split('\n') >>> >>>from difflib import SequenceMatcher as SM >>> >>> >>> def ignore(x): >>> return x in ' ,.' >>> >>> >>> for filename in filenames: >>> ratios = [SM(ignore,filename,username).ratio() for username in >>> usernames] >>> best = max(ratios) >>> owner = usernames[ratios.index(best)] >>> print filename,":",owner >>> >>> >>> Emile >>> >>> >>> >>>> I have many files in separate directories, each file name >>>> contain a persons name but never in the same spot. >>>> I need to find that name which is listed in a large >>>> text file in the following format. Last name, comma >>>> and First name. The last name could be duplicate. >>>> >>>> Adler, Jack >>>> Smith, John >>>> Smith, Sally >>>> Stone, Mark >>>> etc. >>>> >>>> >>>> The file names don't necessary follow any standard >>>> format. >>>> >>>> Smith, John - 02-15-75 - business files.doc >>>> Random Data - Adler Jack - expenses.xls >>>> More Data Mark Stone files list.doc >>>> etc >>>> >>>> I need some way to pull the name from the file name, find it in the >>>> text list and then create a directory based on the name on the list >>>> "Smith, John" and move all files named with the clients name into that >>>> directory. >>> > From me+list/python at ixokai.io Sat Aug 27 19:27:16 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:27:16 -0700 Subject: is there any principle when writing python function In-Reply-To: References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <87vctitt43.fsf@benfinney.id.au> Message-ID: <4E597D54.5010605@ixokai.io> On 8/27/11 3:21 PM, Emile van Sebille wrote: > On 8/27/2011 2:57 PM Ben Finney said... >> Emile van Sebille writes: >> >>> Code is first and foremost written to be executed. >> > > >> ?Programs must be written for people to read, and only >> incidentally for >> machines to execute.? >> ?Abelson& Sussman, _Structure and Interpretation of Computer >> Programs_ >> > > That's certainly self-fulfilling -- code that doesn't execute will need > to be read to be understood, and to be fixed so that it does run. Nobody > cares about code not intended to be executed. Pretty it up as much as > you have free time to do so to enlighten your intended audience. Er, you're interpreting the quote... way overboard. No one's talking about code that isn't intended to be executed, I don't think; the quote includes, "and only incidentally for machines to execute." That's still the there, and its still important. It should just not be the prime concern while actually writing the code. The code has to actually do something. If not, obviously you'll have to change it. The Pythonic emphasis on doing readable, pretty code isn't JUST about making code that just looks good; its not merely an aesthetic that the community endorses. And although people often tout the very valid reason why readability counts-- that code is often read more then written, and that coming back to a chunk of code 6 months later and being able to understand fully what its doing is very important... that's not the only reason readability counts. Readable, pretty, elegantly crafted code is also far more likely to be *correct* code. However, this: > Code that runs from the offset may not ever again need to be read, so > the only audience will ever be the processor. > > I find it much to easy to waste enormous amounts of time prettying up > code that works. Pretty it up when it doesn't -- that's the code that > needs the attention. ... seems to me to be a rather significant self-fulfilling prophecy in its own right. The chances that the code does what its supposed to do, accurately, and without any bugs, goes down in my experience quite significantly the farther away from "pretty" it is. If you code some crazy, overly clever, poorly organized, messy chunk of something that /works/ -- that's fine and dandy. But unless you have some /seriously/ comprehensive test coverage then the chances that you can eyeball it and be sure it doesn't have some subtle bugs that will call you back to fix it later, is pretty low. In my experience. Its not that pretty code is bug-free, but code which is easily read and understood is vastly more likely to be functioning correctly and reliably. Also... it just does not take that much time to make "pretty code". It really doesn't. The entire idea that its hard, time-consuming, effort-draining or difficult to make code clean and "pretty" from the get-go is just wrong. You don't need to do a major "prettying up" stage after the fact. Sure, sometimes refactoring would greatly help a body of code as it evolves, but you can do that as it becomes beneficial for maintenance reasons and not just for pretty's sake. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Aug 27 19:31:15 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:31:15 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E597E43.6030702@ixokai.io> On 8/27/11 11:06 AM, Emile van Sebille wrote: > from difflib import SequenceMatcher as SM > > def ignore(x): > return x in ' ,.' > > for filename in filenames: > ratios = [SM(ignore,filename,username).ratio() for username in > usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner It amazes me that I can still find a surprising new tool in the stdlib after all these years. Neat. /pinboards -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Aug 27 19:44:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 27 Aug 2011 16:44:44 -0700 Subject: Understanding .pth in site-packages In-Reply-To: <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> <8600c2da-7d79-4e50-b032-9cbe03cf31bc@glegroupsg2000goo.googlegroups.com> Message-ID: <4E59816C.50403@ixokai.io> On 8/27/11 3:41 PM, Josh English wrote: > I have .egg files in my system path. The Egg file created by my setup script doesn't include anything but the introductory text. If I open other eggs I see the zipped data, but not for my own files. Sounds like your setup.py isn't actually including your source. > > Is having a zipped egg file any faster than a regular package? or does it just prevent people from seeing the code? IIUC, its nominally very slightly faster to use an egg, because it can skip a lot of filesystem calls. But I've only heard that and can't completely confirm it (internal testing at my day job did not conclusively support this, but our environments are uniquely weird). But that speed boost (if even true) isn't really the point of eggs-as-files -- eggs are just easy to deal with as files is all. They don't prevent people from seeing the code*, they're just regular zip files and can be unzipped fine. I almost always install unzip my eggs on a developer machine, because I inevitably want to go poke inside and see what's actually going on. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * Although you can make an egg and then go and remove all the .PY files from it, and leave just the compiled .PYC files, and Python will load it fine. At the day job, that's what we do. But, you have to be aware that this ties the egg to a specific version of Python, and its not difficult for someone industrious to disassemble and/or decompile the PYC back to effectively equivalent PY files to edit away if they want. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From python at mrabarnett.plus.com Sat Aug 27 19:48:20 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Aug 2011 00:48:20 +0100 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: <4E598244.2070400@mrabarnett.plus.com> On 28/08/2011 00:18, Ric at rdo.python.org wrote: > Thank you so much. The code worked perfectly. > > This is what I tried using Emile code. The only time when it picked > wrong name from the list was when the file was named like this. > > Data Mark Stone.doc > > How can I fix this? Hope I am not asking too much? > Have you tried the alternative word orders, "Mark Stone" as well as "Stone, Mark", picking whichever name has the best ratio for either? > > import os > from difflib import SequenceMatcher as SM > > path = r'D:\Files ' > txt_names = [] > > > with open(r'D:/python/log1.txt') as f: > for txt_name in f.readlines(): > txt_names.append(txt_name.strip()) > > def ignore(x): > return x in ' ,.' > > for filename in os.listdir(path): > ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in > txt_names] > best = max(ratios) > owner = txt_names[ratios.index(best)] > print filename,":",owner > > > > > > On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille > wrote: > >> On 8/27/2011 1:15 PM Ric at rdo.python.org said... >>> >>> Hello Emile , >>> >>> Thank you for the code below as I have not encountered SequenceMatcher >>> before and would have to take a look at it closer. >>> >>> My question would it work for a text file list of names about 25k >>> lines and a directory with say 100 files inside? >> >> Sure. >> >> Emile >> >> >>> >>> Thank you once again. >>> >>> >>> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >>> wrote: >>> >>>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>>> Hello, >>>>> >>>>> What would be the best way to accomplish this task? >>>> >>>> I'd do something like: >>>> >>>> >>>> usernames = """Adler, Jack >>>> Smith, John >>>> Smith, Sally >>>> Stone, Mark""".split('\n') >>>> >>>> filenames = """Smith, John - 02-15-75 - business files.doc >>>> Random Data - Adler Jack - expenses.xls >>>> More Data Mark Stone files list.doc""".split('\n') >>>> >>> >from difflib import SequenceMatcher as SM >>>> >>>> >>>> def ignore(x): >>>> return x in ' ,.' >>>> >>>> >>>> for filename in filenames: >>>> ratios = [SM(ignore,filename,username).ratio() for username in >>>> usernames] >>>> best = max(ratios) >>>> owner = usernames[ratios.index(best)] >>>> print filename,":",owner >>>> >>>> >>>> Emile >>>> >>>> >>>> >>>>> I have many files in separate directories, each file name >>>>> contain a persons name but never in the same spot. >>>>> I need to find that name which is listed in a large >>>>> text file in the following format. Last name, comma >>>>> and First name. The last name could be duplicate. >>>>> >>>>> Adler, Jack >>>>> Smith, John >>>>> Smith, Sally >>>>> Stone, Mark >>>>> etc. >>>>> >>>>> >>>>> The file names don't necessary follow any standard >>>>> format. >>>>> >>>>> Smith, John - 02-15-75 - business files.doc >>>>> Random Data - Adler Jack - expenses.xls >>>>> More Data Mark Stone files list.doc >>>>> etc >>>>> >>>>> I need some way to pull the name from the file name, find it in the >>>>> text list and then create a directory based on the name on the list >>>>> "Smith, John" and move all files named with the clients name into that >>>>> directory. >>>> >> From Ric at rdo Sat Aug 27 20:21:19 2011 From: Ric at rdo (Ric at rdo) Date: Sat, 27 Aug 2011 20:21:19 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On Sun, 28 Aug 2011 00:48:20 +0100, MRAB wrote: >On 28/08/2011 00:18, Ric at rdo.python.org wrote: >> Thank you so much. The code worked perfectly. >> >> This is what I tried using Emile code. The only time when it picked >> wrong name from the list was when the file was named like this. >> >> Data Mark Stone.doc >> >> How can I fix this? Hope I am not asking too much? >> >Have you tried the alternative word orders, "Mark Stone" as well as >"Stone, Mark", picking whichever name has the best ratio for either? >> Yes I tried and the result was the same. I will try to work out something. thank you. >> import os >> from difflib import SequenceMatcher as SM >> >> path = r'D:\Files ' >> txt_names = [] >> >> >> with open(r'D:/python/log1.txt') as f: >> for txt_name in f.readlines(): >> txt_names.append(txt_name.strip()) >> >> def ignore(x): >> return x in ' ,.' >> >> for filename in os.listdir(path): >> ratios = [SM(ignore,filename,txt_name).ratio() for txt_name in >> txt_names] >> best = max(ratios) >> owner = txt_names[ratios.index(best)] >> print filename,":",owner >> >> >> >> >> >> On Sat, 27 Aug 2011 14:08:17 -0700, Emile van Sebille >> wrote: >> >>> On 8/27/2011 1:15 PM Ric at rdo.python.org said... >>>> >>>> Hello Emile , >>>> >>>> Thank you for the code below as I have not encountered SequenceMatcher >>>> before and would have to take a look at it closer. >>>> >>>> My question would it work for a text file list of names about 25k >>>> lines and a directory with say 100 files inside? >>> >>> Sure. >>> >>> Emile >>> >>> >>>> >>>> Thank you once again. >>>> >>>> >>>> On Sat, 27 Aug 2011 11:06:22 -0700, Emile van Sebille >>>> wrote: >>>> >>>>> On 8/27/2011 10:03 AM Ric at rdo.python.org said... >>>>>> Hello, >>>>>> >>>>>> What would be the best way to accomplish this task? >>>>> >>>>> I'd do something like: >>>>> >>>>> >>>>> usernames = """Adler, Jack >>>>> Smith, John >>>>> Smith, Sally >>>>> Stone, Mark""".split('\n') >>>>> >>>>> filenames = """Smith, John - 02-15-75 - business files.doc >>>>> Random Data - Adler Jack - expenses.xls >>>>> More Data Mark Stone files list.doc""".split('\n') >>>>> >>>> >from difflib import SequenceMatcher as SM >>>>> >>>>> >>>>> def ignore(x): >>>>> return x in ' ,.' >>>>> >>>>> >>>>> for filename in filenames: >>>>> ratios = [SM(ignore,filename,username).ratio() for username in >>>>> usernames] >>>>> best = max(ratios) >>>>> owner = usernames[ratios.index(best)] >>>>> print filename,":",owner >>>>> >>>>> >>>>> Emile >>>>> >>>>> >>>>> >>>>>> I have many files in separate directories, each file name >>>>>> contain a persons name but never in the same spot. >>>>>> I need to find that name which is listed in a large >>>>>> text file in the following format. Last name, comma >>>>>> and First name. The last name could be duplicate. >>>>>> >>>>>> Adler, Jack >>>>>> Smith, John >>>>>> Smith, Sally >>>>>> Stone, Mark >>>>>> etc. >>>>>> >>>>>> >>>>>> The file names don't necessary follow any standard >>>>>> format. >>>>>> >>>>>> Smith, John - 02-15-75 - business files.doc >>>>>> Random Data - Adler Jack - expenses.xls >>>>>> More Data Mark Stone files list.doc >>>>>> etc >>>>>> >>>>>> I need some way to pull the name from the file name, find it in the >>>>>> text list and then create a directory based on the name on the list >>>>>> "Smith, John" and move all files named with the clients name into that >>>>>> directory. >>>>> >>> From suresh.amritapuri at gmail.com Sat Aug 27 20:52:32 2011 From: suresh.amritapuri at gmail.com (suresh) Date: Sat, 27 Aug 2011 17:52:32 -0700 (PDT) Subject: packaging a python application Message-ID: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> Hi I created a python application which consists of multiple python files and a configuration file. I am not sure, how can I distribute it. I read distutils2 documentation and a few blogs on python packaging. But I still have the following questions. 1. My package has a configuration file which has to be edited by the user. How do we achieve that? 2. Should the user directly edit the configuration file, or there would be an interface for doing it...?(I remember my sendmail installations in Debian/Ubuntu. It would ask a bunch of questions and the cfg file would be ready) I am just confused how to go about... thanks suresh From tjreedy at udel.edu Sat Aug 27 20:55:55 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Aug 2011 20:55:55 -0400 Subject: Record seperator In-Reply-To: References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/27/2011 5:07 PM, Roy Smith wrote: > In article, > Terry Reedy wrote: > >> On 8/27/2011 1:45 PM, Roy Smith wrote: >>> In article<4e592852$0$29965$c3e8da3$5496439d at news.astraweb.com>, >>> Steven D'Aprano wrote: >>> >>>> open("file.txt") # opens the file >>>> .read() # reads the contents of the file >>>> .split("\n\n") # splits the text on double-newlines. >>> >>> The biggest problem with this code is that read() slurps the entire file >>> into a string. That's fine for moderately sized files, but will fail >>> (or at least be grossly inefficient) for very large files. >> >> I read the above as separating the file into paragraphs, as indicated by >> blank lines. >> >> def paragraphs(file): >> para = [] >> for line in file: >> if line: >> para.append(line) >> else: >> yield para # or ''.join(para), as desired >> para = [] > > Plus or minus the last paragraph in the file :-) Or right, I forgot the last line, which is a repeat of the yield after the for loop finishes. -- Terry Jan Reedy From emile at fenx.com Sat Aug 27 21:10:07 2011 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Aug 2011 18:10:07 -0700 Subject: Arrange files according to a text file In-Reply-To: References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: On 8/27/2011 4:18 PM Ric at rdo.python.org said... > Thank you so much. The code worked perfectly. > > This is what I tried using Emile code. The only time when it picked > wrong name from the list was when the file was named like this. > > Data Mark Stone.doc > > How can I fix this? Hope I am not asking too much? What name did it pick? I imagine if you're picking a name from a list of 25000 names that some subset of combinations may yield like ratios. But, if you double up on the file name side you may get closer: for filename in filenames: ratios = [SM(ignore,filename+filename,username).ratio() for username in usernames] best = max(ratios) owner = usernames[ratios.index(best)] print filename,":",owner ... on the other hand, if you've only got a 100 files to sort out, you should already be done. :) Emile From drsalists at gmail.com Sat Aug 27 21:19:05 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 27 Aug 2011 18:19:05 -0700 Subject: Record seperator In-Reply-To: References: Message-ID: http://stromberg.dnsalias.org/svn/bufsock/trunk does it. $ cat double-file daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/bin/sh man:x:6:12:man:/var/cache/man:/bin/sh root:x:0:0:root:/root:/bin/bash lp:x:7:7:lp:/var/spool/lpd:/bin/sh mail:x:8:8:mail:/var/mail:/bin/sh news:x:9:9:news:/var/spool/news:/bin/sh uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh proxy:x:13:13:proxy:/bin:/bin/sh benchbox-dstromberg:~/src/home-svn/bufsock/trunk i686-pc-linux-gnu 8830 - above cmd done 2011 Sat Aug 27 06:19 PM $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import bufsock >>> file_ = open('double-file', 'rb') >>> bs = bufsock.bufsock(file_) >>> bs.readto('oo') 'daemon:x:1:1:daemon:/usr/sbin:/bin/sh\nbin:x:2:2:bin:/bin:/bin/sh\nsys:x:3:3:sys:/dev:/bin/sh\nsync:x:4:65534:sync:/bin:/bin/sync\ngames:x:5:60:games:/usr/games:/bin/sh\nman:x:6:12:man:/var/cache/man:/bin/sh\nroo' >>> bs.close() >>> Don't let the name fool you - it's not just for sockets anymore. On Fri, Aug 26, 2011 at 11:39 AM, greymaus wrote: > > Is there an equivelent for the AWK RS in Python? > > > as in RS='\n\n' > will seperate a file at two blank line intervals > > > -- > maus > . > . > ... NO CARRIER > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jphalip at gmail.com Sat Aug 27 21:59:10 2011 From: jphalip at gmail.com (Julien) Date: Sat, 27 Aug 2011 18:59:10 -0700 (PDT) Subject: Custom dict to prevent keys from being overridden Message-ID: Hi, With a simple dict, the following happens: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } >>> d {'a': 3, 'b': 2} ... i.e. the value for the 'a' key gets overridden. What I'd like to achieve is: >>> d = { ... 'a': 1, ... 'b': 2, ... 'a': 3 ... } Error: The key 'a' already exists. Is that possible, and if so, how? Many thanks! Kind regards, Julien From steve+comp.lang.python at pearwood.info Sat Aug 27 22:38:20 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 28 Aug 2011 12:38:20 +1000 Subject: Custom dict to prevent keys from being overridden References: Message-ID: <4e59aa1c$0$29977$c3e8da3$5496439d@news.astraweb.com> Julien wrote: > What I'd like to achieve is: > >>>> d = { > ... 'a': 1, > ... 'b': 2, > ... 'a': 3 > ... } > Error: The key 'a' already exists. > > Is that possible, and if so, how? Not if the requirements including using built-in dicts { }. But if you are happy enough to use a custom class, like this: d = StrictDict(('a', 1), ('b', 2'), ('a', 3)) then yes. Just subclass dict and have it validate items as they are added. Something like: # Untested class StrictDict(dict): def __init__(self, items): for key, value in items: self[key] = value def __setitem__(self, key, value): if key in self: raise KeyError('key %r already exists' % key) super(StrictDict, self).__setitem__(key, value) should more or less do it. -- Steven From philip at semanchuk.com Sat Aug 27 23:01:11 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Aug 2011 23:01:11 -0400 Subject: Understanding .pth in site-packages In-Reply-To: References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> Message-ID: <32FE080C-4C17-435A-BB32-DAFE901BE944@semanchuk.com> On Aug 27, 2011, at 6:49 PM, Josh English wrote: > When I run: os.listdir('c:\Python27\lib\site-packages') I get the contents in order, so the folders come before .pth files (as nothing comes before something.) That's one definition of "in order". =) > I would guess Python is using os.listdir. Why wouldn't it? If you mean that Python uses os.listdir() during import resolution, then yes I agree that's probable. And os.listdir() doesn't guarantee any consistent order. In fact, the documentation explicitly states that the list is returned in arbitrary order. Like a lot of things in Python, os.listdir() probably relies on the underlying C library which varies from system to system. (Case in point -- on my Mac, os.listdir() returns things in the same order as the 'ls' command, which is case-sensitive alphabetical, files & directories mixed -- different from Windows.) So if import relies on os.listdir(), then you're relying on arbitrary resolution when you have a .pth file that shadows a site-packages directory. Those rules will probably work consistently on your particular system, you're developing a habit around what is essentially an implementation quirk. Cheers Philip From research at johnohagan.com Sat Aug 27 23:45:05 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 13:45:05 +1000 Subject: Why do closures do this? Message-ID: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: funcs=[] for n in range(3): def f(): return n funcs.append(f) [i() for i in funcs] The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: def mkfnc(n): def fnc(): return n return fnc funcs=[] for n in range(3): funcs.append(mkfnc(n)) which seems roundabout, or take advantage of the "default values set at definition time" behaviour: funcs=[] for n in range(3): def f(n=n): return n funcs.append(f) which seems obscure, and a side-effect. My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? Regards, John From research at johnohagan.com Sun Aug 28 00:00:24 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 14:00:24 +1000 Subject: Get reference to parent class from subclass? Message-ID: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> class P(): pass class C(P): pass Can I get P from C? IOW, can I get a reference to the object P from the object C? This should be obvious one way or the other, but I haven't been able to find the answer. Regards, John From tjreedy at udel.edu Sun Aug 28 00:19:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 00:19:07 -0400 Subject: Why do closures do this? In-Reply-To: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: On 8/27/2011 11:45 PM, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: def f(): return n is a CONSTANT value. It is not a closure. Your code above is the same as def f(): return n funcs = [f,f,f] n = 2 [i() for i in funcs] > def mkfnc(n): > def fnc(): > return n > return fnc fnc is a closure and n in a nonlocal name. Since you only read it, no nonlocal declaration is needed. > funcs=[] > for n in range(3): > funcs.append(mkfnc(n)) > > which seems roundabout, or take advantage of the "default values set at definition time" behaviour: > > funcs=[] > for n in range(3): > def f(n=n): > return n > funcs.append(f) > > which seems obscure, and a side-effect. It was the standard idiom until nested functions were upgraded to enclose or capture the values of nonlocals. > My question is, is this an inescapable consequence of using closures, I cannot answer since I am not sure what you mean by 'this'. Closures are nested functions that access the locals of enclosing functions. To ensure that the access remains possible even after the enclosing function returns, the last value of such accessed names is preserved even after the enclosing function returns. (That is the tricky part.) -- Terry Jan Reedy From harmar at member.fsf.org Sun Aug 28 00:51:59 2011 From: harmar at member.fsf.org (harrismh777) Date: Sat, 27 Aug 2011 23:51:59 -0500 Subject: is there any principle when writing python function In-Reply-To: References: Message-ID: smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Once Abraham Lincoln was asked how long a man's legs should be. (Well, he was a tall man and had exceptionally long legs... his bed had to be specially made.) Old Abe said, "A man's legs ought to be long enough to reach from his body to the floor". One time the Austrian Emperor decided that one of Wolfgang Amadeus Mozart's masterpieces contained too many notes... when asked how many notes a masterpiece ought to contain it is reported that Mozart retorted, "I use precisely as many notes as the piece requires, not one note more, and not one note less". After starting the python interpreter import this: import this ... study carefully. If you're not Dutch, don't worry if some of it confuses you. ... apply liberally to your function praxis. kind regards, -- m harris FSF ...free as in freedom/ http://webpages.charter.net/harrismh777/gnulinux/gnulinux.htm From research at johnohagan.com Sun Aug 28 01:03:13 2011 From: research at johnohagan.com (John O'Hagan) Date: Sun, 28 Aug 2011 15:03:13 +1000 Subject: Why do closures do this? In-Reply-To: References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: <20110828150313.fa3e35c121380fd8dbbcf2bd@johnohagan.com> On Sun, 28 Aug 2011 00:19:07 -0400 Terry Reedy wrote: > On 8/27/2011 11:45 PM, John O'Hagan wrote: > > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > > > funcs=[] > > for n in range(3): > > def f(): > > return n > > funcs.append(f) > > > > > > > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. [...] > > def f(): return n > is a CONSTANT value. It is not a closure. Quite right: I originally encountered this inside a function, but removed the enclosing function to show the issue in minimal form. > Your code above is the same as > def f(): return n > funcs = [f,f,f] > n = 2 > [i() for i in funcs] > Also right, but I still find this surprising. [...] > > > My question is, is this an inescapable consequence of using closures, > > I cannot answer since I am not sure what you mean by 'this'. Ah, but you are and you have: > Closures are nested functions that access the locals of enclosing > functions. To ensure that the access remains possible even after the > enclosing function returns, the last value of such accessed names is > preserved even after the enclosing function returns. (That is the tricky > part.) > Thanks, John From brenNOSPAMbarn at NObrenSPAMbarn.net Sun Aug 28 01:20:23 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sun, 28 Aug 2011 05:20:23 +0000 (UTC) Subject: Understanding .pth in site-packages References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <47945742-a04c-4eda-aee3-a0026c04e360@glegroupsg2000goo.googlegroups.com> Message-ID: Josh English wrote: > OKB, > > The setup.py script created the egg, but not the .pth file. I > created that myself. > > Thank you for clarifying about how .pth works. I know "redirect > imports" was the wrong phrase, but it worked in my head at the > time. It appears, at least on my system, that Python will find > site-packages/foo before it finds and reads site-packages/foo.pth. > > At least this solution gives me a way to develop my libraries > outside of site-packages. Well, I'm still not totally sure what your setup is, but assuming site-packages/foo is a directory containing an __init__.py (that is, it is a package), then yes, it will be found before an alternative package in a directory named with a .pth file. Note that I don't say it will be found before the .pth file, because, again, the finding of the package (when you do "import foo") happens much later than the processing of the .pth file. So it doesn't find site-packages/foo before it reads foo.pth; it just finds site-packages/foo before it finds the other foo that foo.pth was trying to point to. Let's say your .pth file specifies the directory /elsewhere. The .pth file is processed by site.py when the interpreter starts up, and at that time /elsewhere will be appended to sys.path. Later, when you do the import, it searches sys.path in order. site-packages itself will be earlier in sys.path than /elsewhere, so a package site-packages/foo will be found before /elsewhere/foo. The key here is that the .pth file is processed at interpreter-start time, but the search for foo doesn't take place until you actually execute "import foo". If you want to make your /elsewhere "jump the line" and go to the front, look at easy_install.pth, which seems to have some magic code at the end that moves its eggs ahead of site-packages in sys.path. I'm not sure how this works, though, and it seems like a risky proposition. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From Ric at rdo Sun Aug 28 01:24:48 2011 From: Ric at rdo (Ric at rdo) Date: Sun, 28 Aug 2011 01:24:48 -0400 Subject: Arrange files according to a text file References: <6j8i57t6cgqunn3c1ci4p7u9mnpnvsrl8s@4ax.com> Message-ID: No, it turned out to be my mistake. Your code was correct and I appreciate it very much. Thank you again On Sat, 27 Aug 2011 18:10:07 -0700, Emile van Sebille wrote: >On 8/27/2011 4:18 PM Ric at rdo.python.org said... >> Thank you so much. The code worked perfectly. >> >> This is what I tried using Emile code. The only time when it picked >> wrong name from the list was when the file was named like this. >> >> Data Mark Stone.doc >> >> How can I fix this? Hope I am not asking too much? > >What name did it pick? I imagine if you're picking a name from a list >of 25000 names that some subset of combinations may yield like ratios. > >But, if you double up on the file name side you may get closer: > >for filename in filenames: > ratios = [SM(ignore,filename+filename,username).ratio() for >username in usernames] > best = max(ratios) > owner = usernames[ratios.index(best)] > print filename,":",owner > >... on the other hand, if you've only got a 100 files to sort out, you >should already be done. > >:) > >Emile From flebber.crue at gmail.com Sun Aug 28 03:56:03 2011 From: flebber.crue at gmail.com (flebber) Date: Sun, 28 Aug 2011 00:56:03 -0700 (PDT) Subject: Python IDE/Eclipse References: Message-ID: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> On Aug 27, 6:34?pm, UncleLaz wrote: > On Aug 26, 5:18?pm, Dave Boland wrote: > > > > > > > > > > > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. > > ? Any suggestions? > > > I use Eclipse for other projects and have no problem with using it for > > Python, except that I can't get PyDev to install. ?It takes forever, > > then produces an error that makes no sense. > > > An error occurred while installing the items > > ? ?session context was:(profile=PlatformProfile, > > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). > > ? ?Cannot connect to keystore. > > ? ?This trust engine is read only. > > ? ?The artifact file for > > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. > > > Any suggestions on getting this to work? > > > Thanks, > > Dave > > I use Aptana Studio 3, it's pretty good and it's based on eclipse Emacs with emacs-for-python makes the install and setup a breeze and emacs does a lot for you without much learning. http://gabrielelanaro.github.com/emacs-for-python/ geany is great I use it the most. http://www.geany.org/ Finally this is a fairly new project, but it could be pretty good. they are heavy in development of version 2. Ninja ide http://ninja-ide.org/ they provide packages for Debian/ubuntu fedora mandriva & windows and the developers are very helpful if you have any issues or questions jump on IRC for a chat. Sayth From mail at johnohagan.com Sun Aug 28 04:18:54 2011 From: mail at johnohagan.com (johnohagan) Date: Sun, 28 Aug 2011 18:18:54 +1000 Subject: Get reference to parent class from subclass? In-Reply-To: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> References: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> Message-ID: <20110828181854.6cf95fa850f0c7417cfc9d7a@johnohagan.com> On Sun, 28 Aug 2011 14:00:24 +1000 John O'Hagan wrote: > class P(): > pass > > class C(P): > pass > > Can I get P from C? > Never mind, it's __bases__ (not found in dir(C)) > > Regards, > > John From wxjmfauth at gmail.com Sun Aug 28 04:43:38 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 28 Aug 2011 01:43:38 -0700 (PDT) Subject: On re / regex replacement Message-ID: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> There is actually a discussion on the dev-list about the replacement of "re" by "regex". I'm not a regular expressions specialist, neither a regex user. However, there is in regex a point that is a little bit disturbing me. The regex module proposes a flag to select the "coding" (wrong word, just to be short): The global flags are: ASCII, LOCALE, NEW, REVERSE, UNICODE. If I can undestand the ASCII flag, ASCII being the "lingua franca" of almost all codings, I am more skeptical about the LOCALE/UNICODE flags. There is in my mind some kind of conflict here. What is 100% unicode compliant shoud be locale independent ("Unicode.org") and a locale depedency means a loss of unicode compliance. I'm fearing some potential problems here: Users or modules working in one mode, while some others are working in the other mode. Nothing technical here. It seems to me nobody has pointed this fact. jmf From greymausg at mail.com Sun Aug 28 06:03:13 2011 From: greymausg at mail.com (greymaus) Date: 28 Aug 2011 10:03:13 GMT Subject: Record seperator References: <4e592852$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-27, Steven D'Aprano wrote: > greymaus wrote: > >> On 2011-08-26, D'Arcy J.M. Cain wrote: >>> On 26 Aug 2011 18:39:07 GMT >>> greymaus wrote: >>>> >>>> Is there an equivelent for the AWK RS in Python? >>>> >>>> >>>> as in RS='\n\n' >>>> will seperate a file at two blank line intervals >>> >>> open("file.txt").read().split("\n\n") >>> >> >> >> Ta!.. bit awkard. :)))))) > > Er, is that meant to be a pun? "Awk[w]ard", as in awk-ward? Yup, mispelled it and realized th error :) > > In any case, no, the Python line might be a handful of characters longer > than the AWK equivalent, but it isn't awkward. It is logical and easy to > understand. It's embarrassingly easy to describe what it does: > > open("file.txt") # opens the file > .read() # reads the contents of the file > .split("\n\n") # splits the text on double-newlines. > > The only tricky part is knowing that \n means newline, but anyone familiar > with C, Perl, AWK etc. should know that. > > The Python code might be "long" (but only by the standards of AWK, which can > be painfully concise), but it is simple, obvious and readable. A few extra > characters is the price you pay for making your language readable. At the > cost of a few extra key presses, you get something that you will be able to > understand in 10 years time. > > AWK is a specialist text processing language. Python is a general scripting > and programming language. They have different values: AWK values short, > concise code, Python is willing to pay a little more in source code. > > RS, and its Perl equivelent, which I forget, mean that you can read in full multiline records. (I am coming into Python via Perl from AWK, and trying to get a grip on the language and its idions) Thanks to All Oh, Awk is far more than a text processing language, may be old (like me!) but useful (ditto) -- maus . . ... NO CARRIER From ombdalen at gmail.com Sun Aug 28 06:19:54 2011 From: ombdalen at gmail.com (=?UTF-8?Q?Ole_Martin_Bj=C3=B8rndalen?=) Date: Sun, 28 Aug 2011 12:19:54 +0200 Subject: inpipe and outpipe (and other useful functions) Message-ID: Hi! Please excuse me if this i common knowledge, or if I've one again re-implemented something that turned out to be in the standard library, but I think I came up with something rather neat. I'm writing a lot of programs that call external programs, and as much as I love subproces.Popen, I do get tired of writing rather wordy things like: args = ['cmd', 'arg1', 'arg2', 'etc'] p = subprocess.Popen(args, stdin=subprocess.PIPE) for line in p: line = line.decode('latin1') do_something_with(line) Bleh. so last week I had enough, and I sat down and wrote a few functions. No I can do: from lib import inpipe for line in inpipe(args, encoding='latin1'): do_something_with(line) and from lib import outpipe with outpipe(args, addnl=True) as write: write('Python is awesome!') write('') Some code from a program I'm writing: args = ['metaflac', '--show-total-samples', '--show-sample-rate', file] for line in stripped(inpipe(args)): (name, value) = line.split('=') # ... process tag Now, that is a lot more readable than what I had before! The library has a lot of other things in it as well, and is available here: https://github.com/olemb/lib I love Python! -- Ole Martin, http://nerdly.info/ole/ From aspineux at gmail.com Sun Aug 28 07:45:58 2011 From: aspineux at gmail.com (aspineux) Date: Sun, 28 Aug 2011 04:45:58 -0700 (PDT) Subject: pyzmail-0.9.0: high level mail library to read, write and send emails easily Message-ID: Python easy mail library pyzmail is a high level mail library for Python. It provides functions and classes that help to read, compose and send emails. pyzmail exists because their is no reasons that handling mails with Python would be more difficult than with popular mail clients like Outlook or Thunderbird. pyzmail hide the difficulties of the MIME structure and MIME encoding/decoding. It also hide the problem of the internationalized header encoding/decoding. More here http://www.magiksys.net/pyzmail/ You can get a lot of usage samples from the inside API documentation : http://www.magiksys.net/pyzmail/api/index.html This library is the result of 3 articles I wrote about sending mail using python - Parsing email using Python part 1 of 2 : The Header http://blog.magiksys.net/parsing-email-using-python-header - Parsing email using Python part 2 of 2 : The content http://blog.magiksys.net/parsing-email-using-python-content - Generate and send mail with python: tutorial http://blog.magiksys.net/generate-and-send-mail-with-python-tutorial pyzmail also include a very nice "pyzsendmail" command line utility to send the most complex email from the command line. "pyzsendmail -h" for more I'm waiting for your feedback From alec.taylor6 at gmail.com Sun Aug 28 08:53:21 2011 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 28 Aug 2011 22:53:21 +1000 Subject: Python IDE/Eclipse In-Reply-To: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> References: <614812b3-001c-46f3-adc4-4a9170197d11@u6g2000prc.googlegroups.com> Message-ID: Editra On Sun, Aug 28, 2011 at 5:56 PM, flebber wrote: > On Aug 27, 6:34?pm, UncleLaz wrote: >> On Aug 26, 5:18?pm, Dave Boland wrote: >> >> >> >> >> >> >> >> >> >> > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. >> > ? Any suggestions? >> >> > I use Eclipse for other projects and have no problem with using it for >> > Python, except that I can't get PyDev to install. ?It takes forever, >> > then produces an error that makes no sense. >> >> > An error occurred while installing the items >> > ? ?session context was:(profile=PlatformProfile, >> > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, >> > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, >> > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBu ndleAction). >> > ? ?Cannot connect to keystore. >> > ? ?This trust engine is read only. >> > ? ?The artifact file for >> > osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. >> >> > Any suggestions on getting this to work? >> >> > Thanks, >> > Dave >> >> I use Aptana Studio 3, it's pretty good and it's based on eclipse > > Emacs with emacs-for-python makes the install and setup a breeze and > emacs does a lot for you without much learning. > http://gabrielelanaro.github.com/emacs-for-python/ > > geany is great I use it the most. > http://www.geany.org/ > > Finally this is a fairly new project, but it could be pretty good. > they are heavy in development of version 2. Ninja ide > http://ninja-ide.org/ > they provide packages for Debian/ubuntu fedora mandriva & windows and > the developers are very helpful if you have any issues or questions > jump on IRC for a chat. > > Sayth > -- > http://mail.python.org/mailman/listinfo/python-list > From k.sahithi2862 at gmail.com Sun Aug 28 09:39:02 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sun, 28 Aug 2011 06:39:02 -0700 (PDT) Subject: LATEST HOT PICS Message-ID: <78c81bb1-a264-4aaf-a471-5e1f608906d2@x14g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From vlastimil.brom at gmail.com Sun Aug 28 09:40:05 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 28 Aug 2011 15:40:05 +0200 Subject: On re / regex replacement In-Reply-To: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: 2011/8/28 jmfauth : > There is actually a discussion on the dev-list about the replacement > of "re" by "regex". >... > If I can undestand the ASCII flag, ASCII being the "lingua franca" of > almost all codings, I am more skeptical about the LOCALE/UNICODE > flags. > > There is in my mind some kind of conflict here. What is 100% unicode > compliant shoud be locale independent ("Unicode.org") and a locale > depedency means a loss of unicode compliance. > > I'm fearing some potential problems here: ?Users or modules working > in one mode, while some others are working in the other mode. > >... > jmf > > -- > http://mail.python.org/mailman/listinfo/python-list > As I understand it, regex was designed to be as much compatible with re as possible, sometimes even some problematic (in some interpretation) behaviour is retained as default and "corrected" via the NEW flag (e.g. zero-width split). Also the LOCALE flag seems to be considered as legacy feature and kept with the same behaviour like re; cf.: http://code.google.com/p/mrab-regex-hg/issues/detail?id=6&can=1 In my opinon, the LOCALE flag is not reliable (in a way I would imagine) in either re or regex. In the area of flags regex should work the same way like re or it just adds more possibilities (REVERSE for backwards search, ASCII as the complement for unicode, NEW to enable some incompatible additions or corrections, where the original behaviour could be relied on). The only (understandable) incompatibility I encounter in regex are the new features requiring special syntax, which would obviously raise errors in re or which would be matched literally instead. see http://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails#Additional_features for an overview of the additions. Personally I am very happy with regex, both with its features as well as with the support and maintenance by its developer; however I am mostly using it for manually entered patterns, and less for hardcoded operation. regards, Vlastimil Brom From t at jollybox.de Sun Aug 28 10:04:56 2011 From: t at jollybox.de (Thomas Jollans) Date: Sun, 28 Aug 2011 16:04:56 +0200 Subject: Why do closures do this? In-Reply-To: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> Message-ID: <4E5A4B08.2050405@jollybox.de> On 28/08/11 05:45, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: either make a factory function: This does not do what you'd like it to do. But let's assume that, it did, that Python, when encountering a function definition inside a function, "froze" the values of nonlocal variables used in the new function, from the point of view of that function ? that *might* be more intuitive, at least in certain situations. However, what if you wanted a closure to access a nonlocal variable that changes - acting differently depending on what has since happened in the parent function. That may not be as common, but it is a perfectly plausible situation, and the hack required to support that behaviour in a Python that acts as you had expected it to, a surrogate namespace using a class, list, or dict, is infinitely more cryptic and ugly than the default-parametre hack. Thomas From amitjaluf at gmail.com Sun Aug 28 11:34:27 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Sun, 28 Aug 2011 08:34:27 -0700 (PDT) Subject: about if __name == '__main__': Message-ID: hello group i have one question about this if __name == '__main__': is it same as other languages like[c,c++] main function. because of i google and read faqs and also " http://docs.python.org/faq/programming#how-do-i-find-the-current-module-name" this and i am confused. thanks From tjreedy at udel.edu Sun Aug 28 12:26:18 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 12:26:18 -0400 Subject: Why do closures do this? In-Reply-To: <4E5A4B08.2050405@jollybox.de> References: <20110828134505.795cd32b8fc5ccc472f85ae3@johnohagan.com> <4E5A4B08.2050405@jollybox.de> Message-ID: On 8/28/2011 10:04 AM, Thomas Jollans wrote: > This does not do what you'd like it to do. But let's assume that, it > did, that Python, when encountering a function definition inside a > function, "froze" the values of nonlocal variables used in the new > function, from the point of view of that function ? that *might* be more > intuitive, at least in certain situations. However, what if you wanted a > closure to access a nonlocal variable that changes - acting differently > depending on what has since happened in the parent function. > > That may not be as common, but it is a perfectly plausible situation, > and the hack required to support that behaviour in a Python that acts as > you had expected it to, a surrogate namespace using a class, list, or > dict, is infinitely more cryptic and ugly than the default-parametre hack. Or, what if the nonlocal name is not even defined when the closure is. >>> def f(): def g(): print(a) a = 3 g() >>> f() 3 Note that global names also do not have to be defined when a function using them is compiled. The current situation is that nonlocal and global names are treated the same way. This makes normal and nested functions as much the same as possible. This is intentional. It would be extremely disconcerting if moving code that contains a def into or out of a wrapping function radically changed its behavior more than is absolutely necessary. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Aug 28 12:32:23 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 10:32:23 -0600 Subject: Understanding .pth files In-Reply-To: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> References: <5cc361da-b1e3-47eb-b4e2-b6d92b350fb2@glegroupsg2000goo.googlegroups.com> Message-ID: On Sat, Aug 27, 2011 at 10:42 AM, Josh English wrote: > According to the docs, I should be able to put a file in the site-packages directory called xmldb.pth pointing anywhere else on my drive to include the package. I'd like to use this to direct Python to include the version in the dev folder and not the site-packages folder. The name of the .pth file is not important. Python uses it to add locations to sys.path; it doesn't care what packages might be contained at those locations. > So my C:\Python27\lib\site-packages\xmldb.pth file has one line: > > c:\dev\XmlDB\xmldb The final xmldb is the actual package, yes? The directory in the .pth file should be one inside which Python can find packages, not a package itself. So the file should have just "c:\dev\XmlDB". Then when you do "import xmldb", Python will look inside the "c:\dev\XmlDB", find the xmldb package, and import it. > > (I've tried the slashes the other way, too, but it doesn't seem to work). > > Is the only solution to delete the installed library and add the dev folder to my site.py file? The preferred solution here is to use virtualenv to set up your development environment without having to modify the installed version in the system site-packages at all. HTH, Ian From ian.g.kelly at gmail.com Sun Aug 28 12:51:32 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 10:51:32 -0600 Subject: about if __name == '__main__': In-Reply-To: References: Message-ID: On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > hello group > > i have one question about this > > if __name == '__main__': First, it should be: if __name__ == '__main__': > is it same as other languages like[c,c++] ?main function. because of i > google and read faqs > and also " http://docs.python.org/faq/programming#how-do-i-find-the-current-module-name" > this and i am confused. No, that is not a main function. It's not even a function. When Python runs a script, it loads that script as a module, sets its name to be __main__, and then executes the entire module, starting from the top as normal. What that if statement defines is an ordinary branch that is only executed if the current module is the main module, as opposed to having been imported from some other module. Normally this will be at the end of the file so that all the definitions in the file will have already been executed. The usual idiom for this is: def main(argv): # parse arguments and begin program logic... pass if __name__ == '__main__': import sys main(sys.argv) This is also frequently used for unit testing of library modules, so that the module can be tested just by running it. # define library classes and functions here if __name__ == '__main__': # perform unit tests Cheers, Ian From yasar11732 at gmail.com Sun Aug 28 13:22:08 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 28 Aug 2011 20:22:08 +0300 Subject: A question about class as an iterator Message-ID: Hi, I got confused about classes as an iterator. I saw something like this: class foo(): __iter__(self): return self next(self): return something But then I saw a __next__ method on some code. So what is the deal, which one should I use and what is the difference? -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Aug 28 14:40:36 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Aug 2011 19:40:36 +0100 Subject: On re / regex replacement In-Reply-To: References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: <4E5A8BA4.4060200@mrabarnett.plus.com> On 28/08/2011 14:40, Vlastimil Brom wrote: > 2011/8/28 jmfauth: >> There is actually a discussion on the dev-list about the replacement >> of "re" by "regex". >> ... >> If I can undestand the ASCII flag, ASCII being the "lingua franca" of >> almost all codings, I am more skeptical about the LOCALE/UNICODE >> flags. >> >> There is in my mind some kind of conflict here. What is 100% unicode >> compliant shoud be locale independent ("Unicode.org") and a locale >> depedency means a loss of unicode compliance. >> >> I'm fearing some potential problems here: Users or modules working >> in one mode, while some others are working in the other mode. >> >> ... >> jmf >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > As I understand it, regex was designed to be as much compatible with > re as possible, sometimes even some problematic (in some > interpretation) behaviour is retained as default and "corrected" via > the NEW flag (e.g. zero-width split). Also the LOCALE flag seems to be > considered as legacy feature and kept with the same behaviour like re; > cf.: http://code.google.com/p/mrab-regex-hg/issues/detail?id=6&can=1 > In my opinon, the LOCALE flag is not reliable (in a way I would > imagine) in either re or regex. > In Python 2, re defaults to ASCII and you must use UNICODE for Unicode strings (the str type is a bytestring). In Python 3, re defaults to UNICODE and you must use ASCII for ASCII bytestrings (the str type is a Unicode string). The LOCALE flag is for locale-dependent 8-bit bytestrings. It uses the toupper and tolower functions of the underlying C library. The regex module tries to be drop-in compatible. It supports the LOCALE flag only because the re module has it. Even Perl has something similar. > In the area of flags regex should work the same way like re or it just > adds more possibilities (REVERSE for backwards search, ASCII as the > complement for unicode, NEW to enable some incompatible additions or > corrections, where the original behaviour could be relied on). > > The only (understandable) incompatibility I encounter in regex are the > new features requiring special syntax, which would obviously raise > errors in re or which would be matched literally instead. > see > http://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails#Additional_features > for an overview of the additions. > In the re module, unknown escape sequences are treated as literals, eg \K is treated as K. The regex module has more escape sequences, so that may break existing regexes, eg \X isn't treated as X, but matches a grapheme. Unknown escape sequences are still treated as literals, as in re. My view is that you shouldn't be relying on that behaviour. If it looks like an escape sequence, it may very well be one. It's like their use in strings literals for file paths on Windows. I would've preferred that a invalid escape sequence in a string literal raised an exception (either it's valid and has a meaning, or it's invalid/reserved for future use). It's a balancing act. Requiring the NEW flag for _any_ deviation from re would be very annoying. > Personally I am very happy with regex, both with its features as well > as with the support and maintenance by its developer; > however I am mostly using it for manually entered patterns, and less > for hardcoded operation. > And I'm very happy with your feedback. ;-) From woooee at gmail.com Sun Aug 28 14:56:40 2011 From: woooee at gmail.com (woooee) Date: Sun, 28 Aug 2011 11:56:40 -0700 (PDT) Subject: about if __name == '__main__': References: Message-ID: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Two main routines, __main__ and main(), is not the usual or the common way to do it. It is confusing and anyone looking at the end of the program for statements executed when the program is called will find an isolated call to main(), and then have to search the program for the statements that should have been at the bottom of the program. The only reason to use such a technique in Python is if you want to call the function if the program is run from the command line, and also call the same function if the program is imported from another. In which case, use a name that is descriptive, not "main". And be careful of anyone that gives you programming advice. Research these things for yourself. From paul.nospam at rudin.co.uk Sun Aug 28 15:18:11 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Sun, 28 Aug 2011 20:18:11 +0100 Subject: Processing a large string References: Message-ID: <87y5ydqr9o.fsf@no-fixed-abode.cable.virginmedia.net> goldtech writes: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and get a big array(?) I wondered if there's a way I could > read (stream?) the string from start to finish and read what's > delimited by the "3" into a variable, process the smaller string > variable then append/build a new string with the processed data? > > Would I loop it and read it char by char till a "3"...? Or? > > Thanks. s = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn" for k, subs in itertools.groupby(s, lambda x: x=="3"): print ''.join(subs) what you actually do in the body of the loop depends on what you want to do with the bits. From yasar11732 at gmail.com Sun Aug 28 15:52:23 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Sun, 28 Aug 2011 22:52:23 +0300 Subject: Fwd: Processing a large string In-Reply-To: References: <87y5ydqr9o.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: ---------- Y?nlendirilmi? ileti ---------- Kimden: Ya?ar Arabac? Tarih: 28 A?ustos 2011 22:51 Konu: Re: Processing a large string Kime: Paul Rudin Are you getting Overflow error or memory error? If you don't know what those means: Overflow error occurs when your lists gets bigger than sys.maxsize in size. Memory error occurs, when your objects take too much memory that no more memory can be allocated for you. For example, if you have only one item in your list, and that item consumes all your memory, you will get memory error. On the other hand, if you put so much items to the list that list index hits the sys.maxsize value, you will get Overflow error. Answer to your questions depends on spesifics of your needs and current situation. If you can read whole of the string without getting memory error, you wont get memory error when you split the string into a list (at least in my theory), but you can still get Overflowerror (in 2.6 at least.). If your string is in a file or buffer, I would do something like, file__ = open("big-string.txt","r") output__ = open("outputfile","w") temp__ = "" def process_string(string_): return processed_string while 1: new_char = file.read(1) if new_char == "": break elif new_char == "3": output__.write(process_string(temp__)) temp__ = "" else: temp__ = temp__ + new_char 2011/8/28 Paul Rudin > goldtech writes: > > > Hi, > > > > Say I have a very big string with a pattern like: > > > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn..... > > > > I want to split the sting into separate parts on the "3" and process > > each part separately. I might run into memory limitations if I use > > "split" and get a big array(?) I wondered if there's a way I could > > read (stream?) the string from start to finish and read what's > > delimited by the "3" into a variable, process the smaller string > > variable then append/build a new string with the processed data? > > > > Would I loop it and read it char by char till a "3"...? Or? > > > > Thanks. > > s = "akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn" > for k, subs in itertools.groupby(s, lambda x: x=="3"): > print ''.join(subs) > > > what you actually do in the body of the loop depends on what you want to > do with the bits. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://yasar.serveblog.net/ -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sun Aug 28 17:16:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Aug 2011 14:16:30 -0700 (PDT) Subject: Why do closures do this? In-Reply-To: References: Message-ID: On Saturday, August 27, 2011 8:45:05 PM UTC-7, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: .... > My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? It is the preferred behavior for the following case. def foo(): def printlocals(): print a,b,c,d a = 1; b = 4; c = 5; d = 0.1 printlocals() a = 2 printlocals() When seeing a nested function, there are strong expectations by most people that it will behave this way (not to mention it's a lot more useful). It's only for the less common and much more advanced case of creating a closure in a loop that the other behavior would be preferred. Carl Banks From pavlovevidence at gmail.com Sun Aug 28 17:16:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Aug 2011 14:16:30 -0700 (PDT) Subject: Why do closures do this? In-Reply-To: References: Message-ID: On Saturday, August 27, 2011 8:45:05 PM UTC-7, John O'Hagan wrote: > Somewhat apropos of the recent "function principle" thread, I was recently surprised by this: > > funcs=[] > for n in range(3): > def f(): > return n > funcs.append(f) > > [i() for i in funcs] > > The last expression, IMO surprisingly, is [2,2,2], not [0,1,2]. Google tells me I'm not the only one surprised, but explains that it's because "n" in the function "f" refers to whatever "n" is currently bound to, not what it was bound to at definition time (if I've got that right), and that there are at least two ways around it: .... > My question is, is this an inescapable consequence of using closures, or is it by design, and if so, what are some examples of where this would be the preferred behaviour? It is the preferred behavior for the following case. def foo(): def printlocals(): print a,b,c,d a = 1; b = 4; c = 5; d = 0.1 printlocals() a = 2 printlocals() When seeing a nested function, there are strong expectations by most people that it will behave this way (not to mention it's a lot more useful). It's only for the less common and much more advanced case of creating a closure in a loop that the other behavior would be preferred. Carl Banks From jehugaleahsa at gmail.com Sun Aug 28 17:20:11 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Sun, 28 Aug 2011 14:20:11 -0700 (PDT) Subject: Checking Signature of Function Parameter Message-ID: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> I am trying to write an algorithms library in Python. Most of the functions will accept functions as parameters. For instance, there is a function called any: def any(source, predicate): for item in source: if predicate(item): return true; return false; There are some things I want to make sure of. 1) I want to make sure that source is iterable. 2) More importantly, I want to make sure that predicate is callable, accepting a thing, returning a bool. This is what I have so far: if source is None: raise ValueError("") if not isinstanceof(source, collections.iterable): raise TypeError("") if not callable(predicate): raise TypeError("") The idea here is to check for issues up front. In some of the algorithms, I will be using iterators, so bad arguments might not result in a runtime error until long after the calls are made. For instance, I might implement a filter method like this: def where(source, predicate): for item in source: if predicate(item): yield item Here, an error will be delayed until the first item is pulled from the source. Of course, I realize that functions don't really have return types. Good thing is that virtually everything evaluates to a boolean. I am more concerned with the number of parameters. Finally, can I use decorators to automatically perform these checks, instead of hogging the top of all my methods? From tjreedy at udel.edu Sun Aug 28 17:26:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 17:26:11 -0400 Subject: A question about class as an iterator In-Reply-To: References: Message-ID: On 8/28/2011 1:22 PM, Ya?ar Arabac? wrote: > I got confused about classes as an iterator. I saw something like this: > > class foo(): > __iter__(self): > return self > next(self): > return something 2.x > But then I saw a __next__ method on some code. 3.x This might work in 2.6 or .7, but I do not really know. The next() builting was introduced in 2.6 so that *users* could write item = next(someiter) and have that work in 2.6+ and in 3.x without change. > which one should I use? Depends on your Python version. I recommend you use 3.2 unless you have a reason or need to use something else. -- Terry Jan Reedy From rosuav at gmail.com Sun Aug 28 17:31:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 07:31:52 +1000 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > if source is None: raise ValueError("") > if not isinstanceof(source, collections.iterable): raise TypeError("") > if not callable(predicate): raise TypeError("") > Easier: Just ignore the possibilities of failure and carry on with your code. If the source isn't iterable, you'll get an error raised by the for loop. If the predicate's not callable, you'll get an error raised when you try to call it. The only consideration you might need to deal with is that the predicate's not callable, and only if you're worried that consuming something from your source would be a problem (which it won't be with the normal iterables - strings, lists, etc, etc). Otherwise, just let the exceptions be raised! ChrisA From tjreedy at udel.edu Sun Aug 28 17:35:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 17:35:24 -0400 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: On 8/28/2011 2:56 PM, woooee wrote: > Two main routines, __main__ and main(), '__main__' in not a routine, it is the name of the initial module. > is not the usual or the common > way to do it. It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and then have to search the program for > the statements that should have been at the bottom of the program. > The only reason to use such a technique in Python is if you want to > call the function if the program is run from the command line, and > also call the same function if the program is imported from another. > In which case, use a name that is descriptive, not "main". And be > careful of anyone that gives you programming advice. Research these > things for yourself. As far as I know, all the Lib/test/test_xxx.py file have a test_main function, so one can write (in IDLE, for instance) from test.test_xxx import test_main as f; f() and run that test. Very handy. -- Terry Jan Reedy From timr at probo.com Sun Aug 28 18:52:10 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Aug 2011 15:52:10 -0700 Subject: Why PyImport_ExecCodeModule takes char*? References: Message-ID: Mateusz Loskot wrote: > >I'm wondering, why PyImport_ExecCodeModule function takes char* >instead of const char*? My guess is "history". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ian.g.kelly at gmail.com Sun Aug 28 19:55:39 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 17:55:39 -0600 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 12:56 PM, woooee wrote: > Two main routines, __main__ and main(), is not the usual or the common > way to do it. ?It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and then have to search the program for > the statements that should have been at the bottom of the program. Not a problem if you write them one after another. Besides which, any decent editor will have a command to go directly from the function call to the function definition, so I really don't see this as a problem. > The only reason to use such a technique in Python is if you want to > call the function if the program is run from the command line, and > also call the same function if the program is imported from another. Or if your main "routine" has variables, and you don't particularly want them polluting the module's global namespace. > In which case, use a name that is descriptive, not "main". "main" is descriptive in that it clearly designates the entry point of the script to anybody accustomed to such terminology. But there is certainly no reason it needs to be "main", and in fact I only used that for the example. In an actual script I would use whatever seems appropriate. From cs at zip.com.au Sun Aug 28 19:59:43 2011 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 29 Aug 2011 09:59:43 +1000 Subject: about if __name == '__main__': In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Message-ID: <20110828235943.GA12678@cskk.homeip.net> On 28Aug2011 11:56, woooee wrote: | Two main routines, __main__ and main(), is not the usual or the common | way to do it. It is confusing and anyone looking at the end of the | program for statements executed when the program is called will find | an isolated call to main(), and then have to search the program for | the statements that should have been at the bottom of the program. Firstly, as Terry remarked, __main__ is a name, not a function. Secondly, "search the program for the statements that should have been at the bottom of the program" isn't how I see it. If I have a module I expect to be usable from the command line easily it looks like this: def main(argv): ... command line program logic ... return exit_code ... all the other module contents ... if __name__ == '__main__': import sys sys.exit(main(sys.argv)) That way the top level command line program logic is at the top of the file where it is easy to find, not buried in the middle or at the bottom. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Anarchy is not lack of order. Anarchy is lack of ORDERS. From srehtvandy at gmail.com Sun Aug 28 20:00:03 2011 From: srehtvandy at gmail.com (luvspython) Date: Sun, 28 Aug 2011 17:00:03 -0700 (PDT) Subject: Unpickle error -- "object has no attribute ...." Message-ID: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> I have an application that needs to keep a history of the values of several attributes of each of many instances of many classes. The history-keeping logic is in a helper class, HistoryKeeper, that's inherited by classes like Vehicle in the example below. Pickling an instance of Vehicle works, but unpickling fails with: "Vehicle object has no attribute '_orderedArgNames'" (_orderedArgNames is an attribute in HistoryKeeper that tells the attributes for which history must be kept.) During unpickling, the exception occurs at the 2nd line in the __getattribute__ method: if item not in object.__getattribute__(self, '_orderedArgNames'): FWIW, cPickle fails the same way. Below is a stripped-down example that fails in unpickling. Can anyone explain why it fails and what I can do to fix it? MANY thanks. ========================================================= import datetime, bisect from collections import OrderedDict # define a class which helps keep date-history of attribute settings in inheriting classes class HistoryKeeper(object): """ Class to maintain a dated history of attribute settings in inheriting classes. The initialization arguments are in an OrderedDict.""" def __init__(self, orderedArgs): super(HistoryKeeper, self).__setattr__('_orderedArgNames', orderedArgs.keys()) #remember the order of unnamed args for arg, value in orderedArgs.items(): if arg != 'self': self.Set(arg, value) """ Get the current value of an attribute, optionally returning its entire history.""" def __getattribute__(self, item, returnHistory=False): value = object.__getattribute__(self, item) if item not in object.__getattribute__(self, '_orderedArgNames'): return value # not an attribute for which we maintain a change history elif returnHistory: return value # return the entire history else: return value[-1][0] # return only the latest value """ Set an attribute by appending the new value and date to existing history of that attribute. Unless a setting-date is supplied, default to today. Set the value only if it's different than the chronological immediately preceding value.""" def __setattr__(self, item, value, date=None): # avoid history keeping if this item isn't among those declared to require it if item not in self._orderedArgNames: super(HistoryKeeper, self).__setattr__(item, value) else: if not date: date = datetime.date.today() # if this attribute has already been set, add this value to that history try: history = self.__getattribute__(item, returnHistory=True) # if a date was supplied, ensure the history remains in chronological order dates = [val[1] for val in history] index = bisect.bisect_right(dates, date) # insert this value into the history unless it doesn't change an existing setting if index == 0 or history[index-1][0] != value: history.insert(index, (value,date)) except: history = [(value, date)] super(HistoryKeeper, self).__setattr__(item, history) def Set(self, item, value): self.__setattr__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): argDict = OrderedDict([('tag',tag),('make',make), ('model',model)]) super(Vehicle, self).__init__(argDict) if __name__ == "__main__": car = Vehicle('TAG123', 'FORD', 'Model A') import pickle pFile = open('car.pk1', 'wb') pickle.dump(car, pFile, -1) pFile.close() print "car pickled OK" pFile = open('car.pk1', 'rb') community = pickle.load(pFile) pFile.close() From tjreedy at udel.edu Sun Aug 28 20:02:39 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Aug 2011 20:02:39 -0400 Subject: Why PyImport_ExecCodeModule takes char*? In-Reply-To: References: Message-ID: On 8/28/2011 6:52 PM, Tim Roberts wrote: > Mateusz Loskot wrote: >> >> I'm wondering, why PyImport_ExecCodeModule function takes char* >> instead of const char*? > > My guess is "history". I believe some const tags have been added over the last few years. Another factory than mere history for some things is portability across platforms and the main compilers. -- Terry Jan Reedy From jehugaleahsa at gmail.com Sun Aug 28 20:20:30 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Sun, 28 Aug 2011 17:20:30 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> On Aug 28, 5:31?pm, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > > if source is None: raise ValueError("") > > if not isinstanceof(source, collections.iterable): raise TypeError("") > > if not callable(predicate): raise TypeError("") > > Easier: Just ignore the possibilities of failure and carry on with > your code. If the source isn't iterable, you'll get an error raised by > the for loop. If the predicate's not callable, you'll get an error > raised when you try to call it. The only consideration you might need > to deal with is that the predicate's not callable, and only if you're > worried that consuming something from your source would be a problem > (which it won't be with the normal iterables - strings, lists, etc, > etc). Otherwise, just let the exceptions be raised! > > ChrisA I guess my concern is mostly with the delayed exceptions. It is hard to find the source of an error when it doesn't happen immediately. I am writing this library so all of the calls can be chained together (composed). If this nesting gets really deep, finding the source is hard to do, even with a good debugger. Maybe I should give up on it, like you said. I am still familiarizing myself with the paradigm. I want to make sure I am developing code that is consistent with the industry standards. From niklasro at gmail.com Sun Aug 28 20:26:41 2011 From: niklasro at gmail.com (Niklas Rosencrantz) Date: Sun, 28 Aug 2011 17:26:41 -0700 (PDT) Subject: Why I need the parameter when the call doesn't use it? Message-ID: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: ---- class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): def is_submitter_human(self): cResponse = captcha.submit( self.request.get('recaptcha_challenge_field').encode('utf-8'), self.request.get('recaptcha_response_field').encode('utf-8'), CAPTCHA_PRV_KEY, os.environ['REMOTE_ADDR']) return cResponse.is_valid def post(self, view): logging.debug('starting recaptcha check') isHuman = self.is_submitter_human()# here I don't pass a parameter logging.debug('recaptcha check isHuman:' +str(isHuman)) if not isHuman:#failed captcha and can try again #Reprint the form -- It seems unlike other programming languages where the number of arguments in the call are the same as the number of arguments in the function head and python requires me to add one parameter to the function head and I wonder if you call tell me something about the background why? What's the story of using these parameters that are called "self"? Thank you From rosuav at gmail.com Sun Aug 28 20:27:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 10:27:53 +1000 Subject: Checking Signature of Function Parameter In-Reply-To: <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> <9c9c95ed-e2d6-4529-84e2-88b495e3f23e@dp9g2000vbb.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 10:20 AM, Travis Parks wrote: > Maybe I should give up on it, like you said. I am still familiarizing > myself with the paradigm. I want to make sure I am developing code > that is consistent with the industry standards. > In Python, the industry standard is "easier to ask forgiveness than permission" - that is, let the exceptions happen. It's not worth the hassle of error-checking when the result of not checking an error is exactly the same thing. ChrisA From cnchenji at gmail.com Sun Aug 28 20:35:58 2011 From: cnchenji at gmail.com (Gee Chen) Date: Sun, 28 Aug 2011 17:35:58 -0700 (PDT) Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 Message-ID: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> ---------------------------------- the Python environment on my mac is: Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664) Copyright (C) 2007 Free Software Foundation, Inc. --------------------------------------------------------------------- I found the download adresses of scipy and numpy from official website 'www.scipy.org'. After downloading 2 latest released dmg files, i directly installed them with double-click the dmg files. Then, i opened Python interpreter in Terminal, and tested whether scipy & numpy work. The result is disappointed! when i inputed ' import scipy' & 'import numpy', the output is : >>> import scipy Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/scipy/_init_.py", line 78, in from numpy import show_config as show_numpy_config File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/_init_.py", line 137, in import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/add_newdocs.py", line 9, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/_init_.py", line 4, in from type_check import * File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/type_check.py", line 8, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/_init_.py", line 5, in import multiarray ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/numpy/core/multiarray.so: no matching architecture in universal wrapper >>> >>> import numpy Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/_init_.py", line 137, in import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/add_newdocs.py", line 9, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/_init_.py", line 4, in from type_check import * File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/lib/type_check.py", line 8, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/numpy/core/_init_.py", line 5, in import multiarray ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- packages/numpy/core/multiarray.so: no matching architecture in universal wrapper >>> Is there anybody can tell me where the error exists? From ian.g.kelly at gmail.com Sun Aug 28 20:40:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 28 Aug 2011 18:40:22 -0600 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): > ? ?for item in source: > ? ? ? ?if predicate(item): > ? ? ? ? ? ?return true; > ? ?return false; Perhaps not the best name, since there is already a built-in called "any" that would be masked by this. Using the built-in, "any(source, predicate)" would be written as "any(predicate(x) for x in source)" > I guess my concern is mostly with the delayed exceptions. It is hard > to find the source of an error when it doesn't happen immediately. I > am writing this library so all of the calls can be chained together > (composed). If this nesting gets really deep, finding the source is > hard to do, even with a good debugger. Agreed that there are cases where it is useful to do this. But there is no delayed execution in the example you've given, so the exceptions will happen immediately (or at least, within the same stack frame). The stack traces will still come from the "any" function and will look basically the same as the stack traces you'll get from raising the exceptions by hand. HTH, Ian From clp2 at rebertia.com Sun Aug 28 21:14:27 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:14:27 -0700 Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 In-Reply-To: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> References: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 5:35 PM, Gee Chen wrote: > ---------------------------------- > the Python environment on my mac is: > > Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin For future reference, when on OS X, it's very helpful to include how you installed your Python, and whether it's 32-bit or 64-bit. > I found the download adresses of scipy and numpy from official website > 'www.scipy.org'. After downloading 2 latest released dmg files, i > directly installed them with double-click the dmg files. > > Then, i opened Python interpreter in Terminal, and tested whether > scipy & numpy work. The result is disappointed! > > when i inputed ' import scipy' & 'import numpy', the output is : > > >>>> import scipy > Traceback (most recent call last): > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > site-packages/numpy/core/_init_.py", line 5, in > import multiarray > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable > image found. Did find: > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- > packages/numpy/core/multiarray.so: no matching architecture in > universal wrapper > Is there anybody can tell me where the error exists? I believe you've installed 32-bit libraries for a 64-bit Python (or possibly vice-versa). It appears that NumPy & SciPy official releases are 32-bit-only. So, you can either use the alternate, unofficial 64-bit releases of those packages, or install a 32-bit Python (via Fink, MacPorts, a Python.org installer, etc.). A third option is to install the Enthought Python Distribution (http://www.enthought.com/products/epd.php ) or similar, which bundles Python together with SciPy, NumPy, and other libraries in a single install. Cheers, Chris -- http://rebertia.com From russ.paielli at gmail.com Sun Aug 28 21:15:56 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 18:15:56 -0700 (PDT) Subject: killing a script Message-ID: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> I have a Python (2.6.x) script on Linux that loops through many directories and does processing for each. That processing includes several "os.system" calls for each directory (some to other Python scripts, others to bash scripts). Occasionally something goes wrong, and the top-level script just keeps running with a stack dump for each case. When I see that, I want to just kill the whole thing and fix the bug. However, when I hit Control- C, it apparently just just kills whichever script happens to be running at that instant, and the top level script just moves to the next line and keeps running. If I hit Control-C repeatedly, I eventually get "lucky" and kill the top-level script. Is there a simple way to ensure that the first Control-C will kill the whole darn thing, i.e, the top-level script? Thanks. --Russ P. From clp2 at rebertia.com Sun Aug 28 21:21:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:21:57 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): > ? ?for item in source: > ? ? ? ?if predicate(item): > ? ? ? ? ? ?return true; > ? ?return false; > > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > I am more concerned with the number of parameters. That can be introspected using the `inspect` module: http://docs.python.org/library/inspect.html#inspect.getargspec > Finally, can I use decorators to automatically perform these checks, > instead of hogging the top of all my methods? Certainly. Although, as others have said, the cost-benefit ratio of adding code to perform such somewhat-redundant checks might make it not worth the trouble. Cheers, Chris From praveen.venkata at gmail.com Sun Aug 28 21:30:00 2011 From: praveen.venkata at gmail.com (Ven) Date: Sun, 28 Aug 2011 18:30:00 -0700 (PDT) Subject: Button Label change on EVT_BUTTON in wxpython!!! Message-ID: Some system info before proceeding further: Platform: Mac OS X 10.7.1 Python Version: ActiveState Python 2.7.1 wxPython Version: [url=http://downloads.sourceforge.net/wxpython/ wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/ url] I want the button label to be changed while performing a task So, here is what I did/want: self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) def OnRun(self,evt): self.run_button.SetLabel('Installing..') #call a function that does the installation task installation_task() #After task completion, set the button label back to "Install" self.run_button.SetLabel('Install') When I try doing this, it doesn't set the label to "Installing" while the task is being performed. Any suggestions how do I achieve this? From ben+python at benfinney.id.au Sun Aug 28 21:32:22 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 11:32:22 +1000 Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87mxett32x.fsf@benfinney.id.au> Niklas Rosencrantz writes: > I modularize code for a webapp and I want to know what python makes > that a need to define an argument called self? Because, when calling a method on an instance, the instance is a parameter to the call. That is, foo = Thribble() foo.bar("spam") is usually syntactic sugar for foo = Thribble() foo.__class__.bar(foo, "spam") and so the definition of that function on the Thribble class needs to accept both parameters. > Here's some code where I'm modularizing a recaptcha test to a function > and the I must add the parameter "self" to the function > is_submitter_human Yes, because the code of ?is_submitter_human? needs to know *which* instance has been passed. That instance is bound to the first parameter, which is conventionally named ?self?. > It seems unlike other programming languages where the number of > arguments in the call are the same as the number of arguments in the > function head and python requires me to add one parameter to the > function head and I wonder if you call tell me something about the > background why? I hope that explains. See also: -- \ ?Nullius in verba? (?Take no-one's word for it?) ?motto of the | `\ Royal Society, since 1663-06-30 | _o__) | Ben Finney From chris at gonnerman.org Sun Aug 28 21:42:32 2011 From: chris at gonnerman.org (Chris Gonnerman) Date: Sun, 28 Aug 2011 20:42:32 -0500 Subject: [Python] Why I need the parameter when the call doesn't use it? In-Reply-To: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <4E5AEE88.1000000@gonnerman.org> On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: > I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: > > ---- > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > def is_submitter_human(self): is_submitter_human() isn't a function, it's a method. Methods are always called with a reference to the class instance (i.e. the object) that the method belongs to; this reference is the first argument, and is conventionally called "self". Though I've hacked it out, your code sample includes calls to other methods of the object, by calling self.methodname(). Without the first parameter, how else would you do it? -- Chris. From clp2 at rebertia.com Sun Aug 28 21:52:03 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 18:52:03 -0700 Subject: Why I need the parameter when the call doesn't use it? In-Reply-To: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 5:26 PM, Niklas Rosencrantz wrote: > I modularize code for a webapp and I want to know what python makes that a need to define an argument called self? Here's some code where I'm modularizing a recaptcha test to a function and the I must add the parameter "self" to the function is_submitter_human: > > ---- > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > ? ?def is_submitter_human(self): > ? ? ? ?cResponse = captcha.submit( ? ? ? ? ? ? ? ? ? ? self.request.get('recaptcha_challenge_field').encode('utf-8'), ? ? ? ? ? ? ? ? ? ? self.request.get('recaptcha_response_field').encode('utf-8'), > ? ? ? ? ? ? ? ? ? ? CAPTCHA_PRV_KEY, > ? ? ? ? ? ? ? ? ? ? os.environ['REMOTE_ADDR']) > ? ? ? ?return cResponse.is_valid > > ? ?def post(self, view): > ? ? ? ?logging.debug('starting recaptcha check') > ? ? ? ?isHuman = self.is_submitter_human()# here I don't pass a parameter > ? ? ? ?logging.debug('recaptcha check isHuman:' +str(isHuman)) > ? ? ? ?if not isHuman:#failed captcha and can try again > ? ? ? ? ? ?#Reprint the form > > -- > It seems unlike other programming languages where the number of arguments in the call are the same as the number of arguments in the function head and python requires me to add one parameter to the function head and I wonder if you call tell me something about the background why? > > What's the story of using these parameters that are called "self"? Some other languages name the analogous parameter "this" instead of "self", and basically declare it implicitly for you. In both cases, said variable is used to refer to the object that the current method is being called on (e.g. if `w` is a list and I do w.append(v), the list `w` is `self` in the context of the .append() method call). Since Python's object-orientation is slightly impure, you are required to declare `self` explicitly in the parameter list, unlike most other languages. Technically, you are free to name the parameter something else instead of "self"; naming it "self" is merely a convention. However, no matter its name, the first parameter to a method will always receive the current object as its argument value. So, given: x = Foo() Then: x.bar(y, z) is approximately equivalent to: Foo.bar(x, y, z) # perfectly legal working code So the number of arguments actually /does/ match the number of parameters; `x`/`self` is just passed implicitly via the semantics of the dot (".") operator. Cheers, Chris From python at mrabarnett.plus.com Sun Aug 28 21:52:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Aug 2011 02:52:22 +0100 Subject: killing a script In-Reply-To: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4E5AF0D6.3010901@mrabarnett.plus.com> On 29/08/2011 02:15, Russ P. wrote: > I have a Python (2.6.x) script on Linux that loops through many > directories and does processing for each. That processing includes > several "os.system" calls for each directory (some to other Python > scripts, others to bash scripts). > > Occasionally something goes wrong, and the top-level script just keeps > running with a stack dump for each case. When I see that, I want to > just kill the whole thing and fix the bug. However, when I hit Control- > C, it apparently just just kills whichever script happens to be > running at that instant, and the top level script just moves to the > next line and keeps running. If I hit Control-C repeatedly, I > eventually get "lucky" and kill the top-level script. Is there a > simple way to ensure that the first Control-C will kill the whole darn > thing, i.e, the top-level script? Thanks. > You could look at the return value of os.system, which may tell you the exit status of the process. From ben+python at benfinney.id.au Sun Aug 28 22:34:23 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 12:34:23 +1000 Subject: [Python] Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87fwklt07k.fsf@benfinney.id.au> Chris Gonnerman writes: > On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: > > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): > > def is_submitter_human(self): > is_submitter_human() isn't a function, it's a method. No, that's not true and may lead to future confusion. Rather, it is a function *and* a method. Not all functions are methods, but all methods are functions. > Methods are always called with a reference to the class instance Also not true, but perhaps too subtle an issue to explore in this thread. > Though I've hacked it out, your code sample includes calls to other > methods of the object, by calling self.methodname(). Without the first > parameter, how else would you do it? Yes, that's exactly the reason. Thanks. -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From philip at semanchuk.com Sun Aug 28 22:34:49 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 28 Aug 2011 22:34:49 -0400 Subject: Button Label change on EVT_BUTTON in wxpython!!! In-Reply-To: References: Message-ID: <5C9EC16C-48EE-4BA3-A3E8-AB72D0271C7F@semanchuk.com> On Aug 28, 2011, at 9:30 PM, Ven wrote: > Some system info before proceeding further: > > Platform: Mac OS X 10.7.1 > Python Version: ActiveState Python 2.7.1 > wxPython Version: [url=http://downloads.sourceforge.net/wxpython/ > wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/ > url] > > I want the button label to be changed while performing a task > > So, here is what I did/want: > > self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') > self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) > > def OnRun(self,evt): > self.run_button.SetLabel('Installing..') > #call a function that does the installation task > installation_task() > #After task completion, set the button label back to "Install" > self.run_button.SetLabel('Install') > > When I try doing this, it doesn't set the label to "Installing" while > the task is being performed. Any suggestions how do I achieve this? Suggestion #1: After you set the label to "Installing...", try adding self.run_button.Refresh() and/or self.run_button.Update(). Suggestion #2: Ask wxPython questions on the wxPython mailing list. Good luck Philip From russ.paielli at gmail.com Sun Aug 28 22:41:25 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 19:41:25 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 6:52?pm, MRAB wrote: > On 29/08/2011 02:15, Russ P. wrote:> I have a Python (2.6.x) script on Linux that loops through many > > directories and does processing for each. That processing includes > > several "os.system" calls for each directory (some to other Python > > scripts, others to bash scripts). > > > Occasionally something goes wrong, and the top-level script just keeps > > running with a stack dump for each case. When I see that, I want to > > just kill the whole thing and fix the bug. However, when I hit Control- > > C, it apparently just just kills whichever script happens to be > > running at that instant, and the top level script just moves to the > > next line and keeps running. If I hit Control-C repeatedly, I > > eventually get "lucky" and kill the top-level script. Is there a > > simple way to ensure that the first Control-C will kill the whole darn > > thing, i.e, the top-level script? Thanks. > > You could look at the return value of os.system, which may tell you the > exit status of the process. Thanks for the suggestion. Yeah, I guess I could do that, but it seems that there should be a simpler way to just kill the "whole enchilada." Hitting Control-C over and over is a bit like whacking moles. --Russ P. From rosuav at gmail.com Sun Aug 28 22:51:13 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 12:51:13 +1000 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > On Aug 28, 6:52?pm, MRAB wrote: >> You could look at the return value of os.system, which may tell you the >> exit status of the process. > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. I believe the idea of this suggestion is for the outer script to notice that the inner script terminated via Ctrl-C, and would then immediately choose to terminate itself - thus avoiding the whack-a-mole effect. ChrisA From no.email at nospam.invalid Sun Aug 28 22:53:02 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Aug 2011 19:53:02 -0700 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <7xr545vshd.fsf@ruckus.brouhaha.com> "Russ P." writes: > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. Hit Ctrl-Z, which stops execution of the subprogram but doesn't kill it. Then kill both the subprogram and the control program from a terminal window. From kwa at kuwata-lab.com Sun Aug 28 23:07:16 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 29 Aug 2011 12:07:16 +0900 Subject: [ANN] Oktest 0.9.0 released - a new-style testing library In-Reply-To: References: Message-ID: I published presentation slide about Oktest. If you have interested in testing, check it out. http://www.slideshare.net/kwatch/oktest-a-new-style-testing-library-for-python -- regards, makoto kuwata On Sat, Aug 27, 2011 at 9:37 PM, Makoto Kuwata wrote: > Hi, > > I released Oktest 0.9.0. > http://pypi.python.org/pypi/Oktest/ > http://packages.python.org/Oktest/ > > Oktest is a new-style testing library for Python. > :: > > ? ?from oktest import ok, NG > ? ?ok (x) > 0 ? ? ? ? ? ? ? ? # same as assert_(x > 0) > ? ?ok (s) == 'foo' ? ? ? ? ? ?# same as assertEqual(s, 'foo') > ? ?ok (s) != 'foo' ? ? ? ? ? ?# same as assertNotEqual(s, 'foo') > ? ?ok (f).raises(ValueError) ?# same as assertRaises(ValueError, f) > ? ?ok (u'foo').is_a(unicode) ?# same as assert_(isinstance(u'foo', unicode)) > ? ?NG (u'foo').is_a(int) ? ? ?# same as assert_(not isinstance(u'foo', int)) > ? ?ok ('A.txt').is_file() ? ? # same as assert_(os.path.isfile('A.txt')) > ? ?NG ('A.txt').is_dir() ? ? ?# same as assert_(not os.path.isdir('A.txt')) > > See http://packages.python.org/Oktest/ for details. > > NOTICE!! Oktest is a young project and specification may change in the future. > > > Main Enhancements > ----------------- > > * New '@test' decorator provided. It is simple but very powerful. > ?Using @test decorator, you can write test description in free text > ?instead of test method. > ?ex:: > > ? ?class FooTest(unittest.TestCase): > > ? ? ? ?def test_1_plus_1_should_be_2(self): ?# not cool... > ? ? ? ? ? ?self.assertEqual(2, 1+1) > > ? ? ? ?@test("1 + 1 should be 2") ? ?# cool! easy to read & write! > ? ? ? ?def _(self): > ? ? ? ? ? ?self.assertEqual(2, 1+1) > > * Fixture injection support by '@test' decorator. > ?Arguments of test method are regarded as fixture names and > ?they are injected by @test decorator automatically. > ?Instance methods or global functions which name is 'provide_xxxx' are > ?regarded as fixture provider (or builder) for fixture 'xxxx'. > ?ex:: > > ? ?class SosTest(unittest.TestCase): > > ? ? ? ?## > ? ? ? ?## fixture providers. > ? ? ? ?## > ? ? ? ?def provide_member1(self): > ? ? ? ? ? ?return {"name": "Haruhi"} > > ? ? ? ?def provide_member2(self): > ? ? ? ? ? ?return {"name": "Kyon"} > > ? ? ? ?## > ? ? ? ?## fixture releaser (optional) > ? ? ? ?## > ? ? ? ?def release_member1(self, value): > ? ? ? ? ? ?assert value == {"name": "Haruhi"} > > ? ? ? ?## > ? ? ? ?## testcase which requires 'member1' and 'member2' fixtures. > ? ? ? ?## > ? ? ? ?@test("validate member's names") > ? ? ? ?def _(self, member1, member2): > ? ? ? ? ? ?assert member1["name"] == "Haruhi" > ? ? ? ? ? ?assert member2["name"] == "Kyon" > > ?Dependencies between fixtures are resolved automatically. > ?ex:: > > ? ?class BarTest(unittest.TestCase): > > ? ? ? ?## > ? ? ? ?## for example: > ? ? ? ?## - Fixture 'a' depends on 'b' and 'c'. > ? ? ? ?## - Fixture 'c' depends on 'd'. > ? ? ? ?## > ? ? ? ?def provide_a(b, c): ?return b + c + ["A"] > ? ? ? ?def provide_b(): ? ? ?return ["B"] > ? ? ? ?def provide_c(d): ? ? return d + ["C"] > ? ? ? ?def provide_d(): ? ? ?reutrn ["D"] > > ? ? ? ?## > ? ? ? ?## Dependencies between fixtures are solved automatically. > ? ? ? ?## > ? ? ? ?@test("dependency test") > ? ? ? ?def _(self, a): > ? ? ? ? ? ?assert a == ["B", "D", "C", "A"] > > ?If loop exists in dependency then @test reports error. > > ?If you want to integrate with other fixture library, see the following > ?example:: > > ? ? ?class MyFixtureManager(object): > ? ? ? ? ?def __init__(self): > ? ? ? ? ? ? ?self.values = { "x": 100, "y": 200 } > ? ? ? ? ?def provide(self, name): > ? ? ? ? ? ? ?return self.values[name] > ? ? ? ? ?def release(self, name, value): > ? ? ? ? ? ? ?pass > > ? ? ?oktest.fixure_manager = MyFixtureResolver() > > > > Other Enhancements and Changes > ------------------------------ > > * Supports command-line interface to execute test scripts. > * Reporting style is changed. > * New assertion method ``ok(x).attr(name, value)`` to check attribute. > * New assertion method ``ok(x).length(n)``. > * New feature``ok().should`` helps you to check boolean method. > * 'ok(str1) == str2' displays diff if text1 != text2, even when using > ?with unittest module. > * Assertion ``raises()`` supports regular expression to check error message. > * Helper functions in oktest.dummy module are now available as decorator. > * 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'. > * ``oktest.run()`` is changed to return number of failures and errors of tests. > * ``before_each()`` and ``after_each()`` are now non-supported. > * (Experimental) New function ``NOT()`` provided which is same as ``NG()``. > * (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests:: > > See CHANGES.txt for details. > http://packages.python.org/Oktest/CHANGES.txt > > > Have a nice testing life! > > -- > regards, > makoto kuwata > From russ.paielli at gmail.com Sun Aug 28 23:08:25 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 20:08:25 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 7:51?pm, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > > On Aug 28, 6:52?pm, MRAB wrote: > >> You could look at the return value of os.system, which may tell you the > >> exit status of the process. > > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > > that there should be a simpler way to just kill the "whole enchilada." > > Hitting Control-C over and over is a bit like whacking moles. > > I believe the idea of this suggestion is for the outer script to > notice that the inner script terminated via Ctrl-C, and would then > immediately choose to terminate itself - thus avoiding the > whack-a-mole effect. > > ChrisA Yes, but if I am not mistaken, that will require me to put a line or two after each os.system call. That's almost like whack-a-mole at the code level rather than the Control-C level. OK, not a huge deal for one script, but I was hoping for something simpler. I was hoping I could put one line at the top of the script and be done with it. --Russ P. From clp2 at rebertia.com Sun Aug 28 23:16:17 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Aug 2011 20:16:17 -0700 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > On Aug 28, 7:51?pm, Chris Angelico wrote: >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: >> > On Aug 28, 6:52?pm, MRAB wrote: >> >> You could look at the return value of os.system, which may tell you the >> >> exit status of the process. >> >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems >> > that there should be a simpler way to just kill the "whole enchilada." >> > Hitting Control-C over and over is a bit like whacking moles. >> >> I believe the idea of this suggestion is for the outer script to >> notice that the inner script terminated via Ctrl-C, and would then >> immediately choose to terminate itself - thus avoiding the >> whack-a-mole effect. >> >> ChrisA > > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. Er, just write a wrapper for os.system(), e.g.: def mysystem(cmd): if os.system(cmd): sys.exit() Also, you may want to switch to using the `subprocess` module instead. Cheers, Chris From russ.paielli at gmail.com Sun Aug 28 23:22:10 2011 From: russ.paielli at gmail.com (Russ P.) Date: Sun, 28 Aug 2011 20:22:10 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Aug 28, 8:16?pm, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > > On Aug 28, 7:51?pm, Chris Angelico wrote: > >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > >> > On Aug 28, 6:52?pm, MRAB wrote: > >> >> You could look at the return value of os.system, which may tell you the > >> >> exit status of the process. > > >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > >> > that there should be a simpler way to just kill the "whole enchilada." > >> > Hitting Control-C over and over is a bit like whacking moles. > > >> I believe the idea of this suggestion is for the outer script to > >> notice that the inner script terminated via Ctrl-C, and would then > >> immediately choose to terminate itself - thus avoiding the > >> whack-a-mole effect. > > >> ChrisA > > > Yes, but if I am not mistaken, that will require me to put a line or > > two after each os.system call. > > Er, just write a wrapper for os.system(), e.g.: > > def mysystem(cmd): > ? ? if os.system(cmd): > ? ? ? ? sys.exit() > > Also, you may want to switch to using the `subprocess` module instead. > > Cheers, > Chris Sounds like a good idea. I'll give it a try. Thanks. --Russ P. From gordon at panix.com Sun Aug 28 23:27:17 2011 From: gordon at panix.com (John Gordon) Date: Mon, 29 Aug 2011 03:27:17 +0000 (UTC) Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: In <66a3f64c-d35e-40c7-be69-ddf708e37ba7 at glegroupsg2000goo.googlegroups.com> Niklas Rosencrantz writes: > What's the story of using these parameters that are called "self"? "self" is a reference to the class object, and it allows the method to access other methods and variables within the class. For example, say you have this class: class MyClass(object): def method1(self, x): self.x = x self.say_hello() def say_hello(self): self.x = self.x + 1 print "hello" Without the "self" reference, method1 wouldn't be able to access instance variable x and it wouldn't be able to call say_hello(). If you have a method that doesn't need to access other variables or methods within the class, you can declare it with the @staticmethod decorator. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From amitjaluf at gmail.com Sun Aug 28 23:42:26 2011 From: amitjaluf at gmail.com (Amit Jaluf) Date: Sun, 28 Aug 2011 20:42:26 -0700 (PDT) Subject: about if __name == '__main__': References: Message-ID: On Aug 28, 12:51?pm, Ian Kelly wrote: > On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > > hello group > > > i have one question about this > > > if __name == '__main__': sorry dear for this and thanks all of you for this................ From anand.ibmgsi at gmail.com Mon Aug 29 00:01:29 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Mon, 29 Aug 2011 09:31:29 +0530 Subject: packaging a python application In-Reply-To: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> References: <6f15fd9f-1818-40db-ba92-ceb4118b9263@glegroupsg2000goo.googlegroups.com> Message-ID: Hi all, This is interesting. Do we have the distribute/setuptools equivalent of postinstall (with ncurses interface) from Debian? My limited foray into setuptools, indicate it doesn't have . Is it a planned feature either? i would like to contribute in that case. ============================================== Anand Jeyahar https://sites.google.com/site/ anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie On Sun, Aug 28, 2011 at 06:22, suresh wrote: > Hi > I created a python application which consists of multiple python files and > a configuration file. I am not sure, how can I distribute it. > > I read distutils2 documentation and a few blogs on python packaging. But I > still have the following questions. > > 1. My package has a configuration file which has to be edited by the user. > How do we achieve that? > > 2. Should the user directly edit the configuration file, or there would be > an interface for doing it...?(I remember my sendmail installations in > Debian/Ubuntu. It would ask a bunch of questions and the cfg file would be > ready) > > I am just confused how to go about... > > thanks > suresh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Aug 29 00:40:38 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Aug 2011 14:40:38 +1000 Subject: [Python] Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> <87fwklt07k.fsf@benfinney.id.au> Message-ID: <4e5b1847$0$30004$c3e8da3$5496439d@news.astraweb.com> On Mon, 29 Aug 2011 12:34 pm Ben Finney wrote: > Chris Gonnerman writes: > >> On 08/28/2011 07:26 PM, Niklas Rosencrantz wrote: >> > class A(BaseHandler, blobstore_handlers.BlobstoreUploadHandler): >> > def is_submitter_human(self): > >> is_submitter_human() isn't a function, it's a method. > > No, that's not true and may lead to future confusion. > > Rather, it is a function *and* a method. Not all functions are methods, > but all methods are functions. Wouldn't it be more accurate to say that methods *wrap* functions? >>> class C(object): ... def spam(self): ... pass ... >>> C().spam > >>> C().spam.im_func (At least for pure Python methods... those written in C, such as for the built-in types, don't.) >> Methods are always called with a reference to the class instance > > Also not true, but perhaps too subtle an issue to explore in this thread. But for the record, you have "normal" instance methods, class methods, static methods, and any other sort of method you can create using the descriptor protocol, such as this one: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ But as Ben hints at, this is getting into fairly advanced territory. -- Steven From samzielkeryner at gmail.com Mon Aug 29 00:49:34 2011 From: samzielkeryner at gmail.com (Sascha) Date: Sun, 28 Aug 2011 21:49:34 -0700 (PDT) Subject: Interact with SQL Database using Python 2.4 or lower Message-ID: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> Hello I have an website on an Australian webhost. I have designed my website to allow people to login & their login details are stored in an SQLite3 database. I interact with the SQLite3 database using pythons SQLite3 module(found only in python2.5 & up) My Problem: the webhost runs Python 2.4 so I cannot communicate with(query or modify) my SQLite3 database. The webhost will not allow me to install my own version of python or upload modules unless I upgrade to VPS. What do you think are my options to still be able to work/interface with my SQL database? Do you know of way to interact with a SQL database using python modules from Python 2.4 or earlier? Do you know of a python 2.4 module that will let me interact with an SQL database(can be MySQL, SQLite, etc.)? From me+list/python at ixokai.io Mon Aug 29 01:09:51 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:09:51 -0700 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> Message-ID: <4E5B1F1F.8070604@ixokai.io> On 8/28/11 9:49 PM, Sascha wrote: > My Problem: the webhost runs Python 2.4 so I cannot communicate > with(query or modify) my SQLite3 database. The webhost will not allow > me to install my own version of python or upload modules unless I > upgrade to VPS. Get a new webhost. Seriously. This is a seriously absurd requirement -- it goes past absurd into malicious incompetence, frankly. Not being able to upload your own modules? There has to be another option. Personally, I'm a major fan of Webfaction -- from price to plans to what's supported to actual effectiveness of their tech support. But I don't know if they have a warehouse in Australia, if their latency with any of their various data centers is suitable for you. Maybe, maybe not -- but there /has/ to be a better option then this site... Good hosts these days are not all that uncommon and are fairly competitive. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Mon Aug 29 01:23:53 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 15:23:53 +1000 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <4E5B1F1F.8070604@ixokai.io> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: On Mon, Aug 29, 2011 at 3:09 PM, Stephen Hansen wrote: > Get a new webhost. ... > > But I don't know if they have a warehouse in Australia, if their latency > with any of their various data centers is suitable for you. Maybe, maybe > not -- but there /has/ to be a better option then this site... Good > hosts these days are not all that uncommon and are fairly competitive. Having burnt my fingers with a couple of web hosts, and finally decided to host my own web site, I have one major piece of advice regarding this: Get a personal recommendation. Don't sign up with any hosting service unless you have advice from someone you trust who has used that service and been happy with it. I'm sure good hosts aren't uncommon, but nor are bad hosts, and it's easy to get caught up with a lot of hassles and outages. BTW, don't take the fact that I host my own site as a negative recommendation for every hosting company out there. My requirements are somewhat unusual - I want to host a MUD, not just a web site. Hosts that let you do THAT much are usually quite expensive :) ChrisA From me+list/python at ixokai.io Mon Aug 29 01:39:49 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:39:49 -0700 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: <4E5B2625.4080503@ixokai.io> On 8/28/11 10:23 PM, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 3:09 PM, Stephen Hansen > wrote: >> Get a new webhost. ... >> >> But I don't know if they have a warehouse in Australia, if their latency >> with any of their various data centers is suitable for you. Maybe, maybe >> not -- but there /has/ to be a better option then this site... Good >> hosts these days are not all that uncommon and are fairly competitive. > > Having burnt my fingers with a couple of web hosts, and finally > decided to host my own web site, I have one major piece of advice > regarding this: > > Get a personal recommendation. This is good advice, though with prices as they are in many cases -- provided you don't need to start out immediately solid and have some development wiggle-room -- its not a bad thing to experiment. Just don't get too tied to a certain host until you feel them out. Sending them emails with detailed questions before you sign up is a good thing, for example. Good hosts will respond with detailed, specific answers, from real people. Bad hosts will point you to a vague website or stock reply. Real people, reading your real questions, and answering with real answers is a major, major sign of the kind of company I want to do business with. (Bonus points if they respond to complex, technical and legal questions with specific answers within 24 hours -- bonus++ points if the non-legal questions usually get responses in 1, at absurd times even). > BTW, don't take the fact that I host my own site as a negative > recommendation for every hosting company out there. My requirements > are somewhat unusual - I want to host a MUD, not just a web site. > Hosts that let you do THAT much are usually quite expensive :) Hehe, I don't want to get overly advertising in my comments (so I'm so not including a referrer link anywhere), but amusingly enough, my first Webfaction account was signed up for the MUD reason. They officially don't give a rats ass what you run in the background, provided you're just not using more then your RAM allotment and that its not spiking the CPU to a point that affects the rest of the system. I have one account that runs a mud, one that does often semi-significant background processing regularly via cron jobs (which they mailed me about once when it got out of hand-- but they were entirely professional and nice about it, and I fixed it with some controls so it behaved in a more friendly way towards the rest of the system), and one for my personal site where I run an IRC bouncer on, and all is cool. (Why three accounts? One is paid for by a client, one half by me, one by me -- it was just easier, and no way it all would fit under a single plan) Anyways. I shall not further ramble as a satisfied-customer. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wxjmfauth at gmail.com Mon Aug 29 01:40:42 2011 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 28 Aug 2011 22:40:42 -0700 (PDT) Subject: On re / regex replacement References: <8e5b2e1c-bb7a-45a3-a0a3-23d25c3d16a7@w28g2000yqw.googlegroups.com> Message-ID: <5651b3de-40ae-4fda-b7d2-b59d06bd1e97@o26g2000vbi.googlegroups.com> On 28 ao?t, 20:40, MRAB wrote: > ... > The regex module tries to be drop-in compatible. It supports the LOCALE > flag only because the re module has it. Even Perl has something similar. > ... Ok. That's quite logical. jmf From rosuav at gmail.com Mon Aug 29 01:52:51 2011 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Aug 2011 15:52:51 +1000 Subject: Web hosting when you need to install your own modules (was Re: Interact with SQL Database using Python 2.4 or lower) Message-ID: On Mon, Aug 29, 2011 at 3:39 PM, Stephen Hansen wrote: > Just don't get too tied to a certain host until you feel them out. > Sending them emails with detailed questions before you sign up is a good > thing, for example. > That helps a lot, but the problems I had with my most recent pay-for web host were less obvious: * Outages that were scheduled, but not notified in a way that I had noticed (it was on their web site, but they didn't mail my registered other email address) * Fine print on their uptime policy that explicitly excluded scheduled outages, and considerably lengthier and more numerous scheduled outages than I would have normally considered reasonable * DNS record changes required a support ticket (this was shared web hosting, so I didn't have control over the BIND files - that's what they said, anyway) * Some sort of weird lack of internal communication that meant that they didn't ever close our account. I still, to this day, am getting emails from their server saying "Hey, you have some package-installed software that's out of date, you should log in and update it". I cannot log in as our account has been suspended for non-payment. I cannot close the account as it is suspended. They somehow didn't get the message four months before the suspension, following their policy strictly, requesting closure. So... yeah. Hopefully, this is a rare situation, but that's why I would look for a personal reference. ChrisA From me+list/python at ixokai.io Mon Aug 29 01:59:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 28 Aug 2011 22:59:44 -0700 Subject: Web hosting when you need to install your own modules (was Re: Interact with SQL Database using Python 2.4 or lower) In-Reply-To: References: Message-ID: <4E5B2AD0.3050900@ixokai.io> On 8/28/11 10:52 PM, Chris Angelico wrote: > * DNS record changes required a support ticket (this was shared web > hosting, so I didn't have control over the BIND files - that's what > they said, anyway) Ouch: I never let a webhost near my domain names. I was burned somewhere around that a long time ago, and now always keep the jobs of managing my DNS record and hosting my sites /totally/ separate. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Mon Aug 29 02:15:34 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Aug 2011 16:15:34 +1000 Subject: Why I need the parameter when the call doesn't use it? References: <66a3f64c-d35e-40c7-be69-ddf708e37ba7@glegroupsg2000goo.googlegroups.com> Message-ID: <87bov8u4jd.fsf@benfinney.id.au> John Gordon writes: > In <66a3f64c-d35e-40c7-be69-ddf708e37ba7 at glegroupsg2000goo.googlegroups.com> Niklas Rosencrantz writes: > > > What's the story of using these parameters that are called "self"? > > "self" is a reference to the class object, and it allows the method to > access other methods and variables within the class. No, ?self? (in an instance method, which is where it's normally used) is bound to the instance object. The class object is a different thing. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From nobody at nowhere.com Mon Aug 29 02:30:37 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Aug 2011 07:30:37 +0100 Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. The "callable" part is do-able, the rest isn't. The predicate may accept an arbitrary set of arguments via the "*args" and/or "**kwargs" syntax, and pass these on to some other function. Exactly *which* function may be the result of an arbitrarily complex expression. Or it may not even call another function, but just use the arbitrary set of arguments in an arbitrarily complex manner. IOW, determining in advance what will or won't work is actually impossible. From mimran774 at gmail.com Mon Aug 29 02:51:54 2011 From: mimran774 at gmail.com (mohammed imran) Date: Sun, 28 Aug 2011 23:51:54 -0700 (PDT) Subject: mohammedimran Message-ID: <3e075a70-5e60-43ce-9626-e608ffb63a3a@s35g2000prm.googlegroups.com> http://123maza.com/65/fun564/ From nobody at nowhere.com Mon Aug 29 02:52:46 2011 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Aug 2011 07:52:46 +0100 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, 28 Aug 2011 18:15:56 -0700, Russ P. wrote: > Is there a > simple way to ensure that the first Control-C will kill the whole darn > thing, i.e, the top-level script? Thanks. You might try using subprocess.Popen() or subprocess.call() rather than os.system(). os.system() calls the platform's system() function. On Unix, this specifically ignores SIGINT and SIGQUIT for the duration of the call, ensuring that Ctrl-C and Ctrl-\ only affect the child process and not the parent. subprocess.Popen() doesn't perform any implicit signal handling; it's implemented in Python in terms of os.fork() and os.execvp[e](). It also has a better interface (i.e. you get to directly control the argument list passed to the child process, rather than having to construct a shell command and hope that you got the quoting/escaping correct). This may not suffice if any of the descendent processes are moved into their own process group, as signals generated by the tty driver are sent only to the foreground process group. However, this is unlikely to be an issue for simple non-interactive programs (e.g. standard Unix "commands"). From t at jollybox.de Mon Aug 29 03:49:26 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 29 Aug 2011 09:49:26 +0200 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4E5B4486.1080300@jollybox.de> On 2011-08-29 05:08, Russ P. wrote: > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. That's almost like whack-a-mole at the > code level rather than the Control-C level. OK, not a huge deal for > one script, but I was hoping for something simpler. I was hoping I > could put one line at the top of the script and be done with it. It's perfectly normal error-handling procedure. In Python, errors are usually handled by exceptions, but if you embed a system that doesn't support exceptions, e.g. external processes or a C library via ctypes, you will of course have to write a little more code in order to handle errors correctly. T From __peter__ at web.de Mon Aug 29 05:02:27 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Aug 2011 11:02:27 +0200 Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: luvspython wrote: > I have an application that needs to keep a history of the values of > several attributes of each of many instances of many classes. The > history-keeping logic is in a helper class, HistoryKeeper, that's > inherited by classes like Vehicle in the example below. > > Pickling an instance of Vehicle works, but unpickling fails with: > "Vehicle object has no attribute > '_orderedArgNames'" (_orderedArgNames is an attribute in > HistoryKeeper that tells the attributes for which history must be > kept.) > > During unpickling, the exception occurs at the 2nd line in the > __getattribute__ method: > if item not in object.__getattribute__(self, > '_orderedArgNames'): > > FWIW, cPickle fails the same way. > > Below is a stripped-down example that fails in unpickling. > > Can anyone explain why it fails and what I can do to fix it? By default unpickling an object does *not* invoke its __init__() method; instead it creates an instance and then updates the __dict__ attribute of that instance. You intercept attribute access with __getattribute__, so to get hold of __dict__ you need to know __dict__["_orderedArgNames"] first, i. e. you run into a bootstrap problem. To fix the error I'd try special-casing "__dict__" def __getattribute__(self, item, ...): if item == "__dict__": return super(HistoryKeeper, self).__getattribute__(item) ... or making _orderedArgNames a class attribute: class HistoryKeeper(object): def __init__(self, orderedArgs): for arg, value in orderedArgs.items(): if arg != 'self': self.Set(arg, value) ... class Vehicle(HistoryKeeper): _orderedArgNames = "tag", "make", "model" ... If that doesn't work out you can write your own __reduce_ex__() method to customise pickling, see http://docs.python.org/library/pickle.html#object.__reduce_ex__ By the way, docstrings belong below the def not above: def f(): """Explain f() here""" From sathish at solitontech.com Mon Aug 29 06:40:06 2011 From: sathish at solitontech.com (Sathish S) Date: Mon, 29 Aug 2011 16:10:06 +0530 Subject: Calling Script from Command line not working Message-ID: Hi Ppl, We created a DLL using cygwin and have written a class based python module for the same. We have created a sample script for the class based python module, that creates an object of the class and calls various methods in the class. This Test script works fine while I run it from IDLE. However when I run it from command prompt it either hangs or just returns without executing the functions. When it returns I do not get a error trace. When I tried to findout where exactly the issue is happening. the issue occurs when I try to call the *cygwin_dll_init* method of the cygwin1.dll . This cygwin1.dll is actualy a dependency to the DLL we have built. So we have to load this DLL and call this *cygwin_dll_init* method before loading my DLL. cyg = cdll.LoadLibrary("cygwin1.dll") cyg.*cygwin_dll_init() #hangs or returns here* *mydll=**cdll.LoadLibrary("my.dll") * *mydll.func1()* * * *I'm trying to understand what exactly is the difference, when we call it IDLE and when we call it from command prompt using the python command. I will have to get the script working from command prompt as well.* * * Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Mon Aug 29 09:09:08 2011 From: python at bdurham.com (python at bdurham.com) Date: Mon, 29 Aug 2011 09:09:08 -0400 Subject: Interact with SQL Database using Python 2.4 or lower In-Reply-To: <4E5B1F1F.8070604@ixokai.io> References: <3299fca8-7b39-4ddd-89d1-03e0d4f1ef84@z1g2000prf.googlegroups.com> <4E5B1F1F.8070604@ixokai.io> Message-ID: <1314623348.23664.140258134885497@webmail.messagingengine.com> > Personally, I'm a major fan of Webfaction -- from price to plans to what's supported to actual effectiveness of their tech support. +1 Malcolm From ramapraba2653 at gmail.com Mon Aug 29 09:30:36 2011 From: ramapraba2653 at gmail.com (SUPREME) Date: Mon, 29 Aug 2011 06:30:36 -0700 (PDT) Subject: ONLY FOR HOT GUYS Message-ID: <5b263734-1b40-40bf-98ab-f97f9c026178@e34g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com PRIYANKA CHOPRA HOT STILLS http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html SAMEERA REDDY HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/sameera-reddy.html HOT ACTRESS WET ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/actress-hot-wet-photos.html TRISHA HOT BATHROOM PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/trisha-hot.html ANUSHKA SHETTY HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT SEXY PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html PRANITHA LATEST BEAUTIFUL PHOTOS http://southactresstou.blogspot.com/2011/06/about-pranitha-praneetha-is-beautiful.html FOR ONLY HOT GUYS SEE THIS TOP 20 HOT ACTRESS PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/hot-actrsess.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html ARTHI CHABRIA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/aarti-chabria-hot.html DIYA MIRZA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/diya-mirza-hot.html KATRINA KAIF HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html DEEPIKA PADUKONE HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/deepika-padukone-hot.html NAMITHA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/namitha-hot-photos.html From steve+comp.lang.python at pearwood.info Mon Aug 29 09:56:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 29 Aug 2011 23:56:16 +1000 Subject: A tale of yak shaving Message-ID: <4e5b9a81$0$29968$c3e8da3$5496439d@news.astraweb.com> This is not exactly fresh (it was written back in March), but it's the first time I saw it and I thought I'd share. Barry Warsaw, one of the lead Python developers, describes one of his most ... interesting ... debugging experiences. http://www.wefearchange.org/2011/03/charming-snakes-and-shaving-yaks.html [quote] Everyone who reported the problem said the TypeError was getting thrown on the for-statement line. The exception message indicated that Python was getting some object that it was trying to convert to an integer, but was failing. How could you possible get that exception when either making a copy of a list or iterating over that copy? Was the list corrupted? Was it not actually a list but some list-like object that was somehow returning non-integers for its min and max indexes? [end quote] -- Steven From jacktradespublic at gmail.com Mon Aug 29 10:41:51 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 09:41:51 -0500 Subject: Returning a value from exec or a better solution Message-ID: I'm writing a Scheme interpreter and I need to be able to create and return a Python function from a string. This is a port of another Scheme interpreter I wrote in Scheme. What I'm trying to do looked like this: (define (scheme-syntax expr) (hash-table-set! global-syntax (car expr) (eval (cadr expr)))) Where expr was of the form (symbol (lambda (exp) ...)). This added a new special form handler. I came up with a very ugly solution in Python: def add_special_form_handler(expr): exec(expr.cdr.car) special_forms[expr.car] = f Where expr.car = the symbol to be dispatched on and expr.cdr.car = a string of Python code defining a function that must be named f. I wanted to use an anonymous function here, but with the limitations of Python's lambda that would probably make things more complicated. Failing that I wanted to allow the user to manually return the function from the string, like this: a = exec(""" def double(x): return x * 2 double """) However it seems that exec does not return a value as it produces a SyntaxError whenever I try to assign it. Is there a better way to do this? -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Aug 29 10:52:40 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Aug 2011 14:52:40 GMT Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> Message-ID: <9c1ndoFj9iU10@mid.individual.net> On 2011-08-26, Chris Angelico wrote: > On Sat, Aug 27, 2011 at 1:48 AM, Tobiah > wrote: >> While I understand and agree with that basic tenet, I think >> that the capitalized 'ONLY' is too strong. ?I do split out >> code into function for readability, even when the function >> will only be called from the place from which I split it out. > > This can be good and can be bad. It's good when it aids > readability; it's bad when you need to pass practically the > entire locals() as function arguments and/or return values. Even when lots of context is needed, defining the context with function calls is a big improvement over directly using names in a module's global namespace. Sometimes repeatedly reused context suggests that creating new classes of objects might be a good idea. > I would split the function only when both halves (caller and > callee) can be given short and useful names - if you can't > explain what a block of code does in a few words, it's probably > a poor choice for splitting out into a function. I agree, except for the implied unconditional preference for short names. I believe the length of a name should usually be proportional to the scope of the object it represents. In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil Cerutti, and in the global scope I have to use a meaningless unique identifier. Hopefully no Python namespace ever gets that big. -- Neil Cerutti From drsalists at gmail.com Mon Aug 29 11:14:43 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 29 Aug 2011 08:14:43 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > You can check a lot of this stuff very inexpensively by using pylint, pychecker or pyflakes. I use pylint quite a bit. Along with many kinds of type errors (except almost anything can be legitimately used in a boolean context), it'll detect when you define an any(), hiding the builtin one. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cnchenji at gmail.com Mon Aug 29 11:32:30 2011 From: cnchenji at gmail.com (Gee Chen) Date: Mon, 29 Aug 2011 08:32:30 -0700 (PDT) Subject: Some problems refer to install 3rd party package of Python on mac OS 10.6.8 References: <07970388-04d2-463f-b550-ad233b2ad404@r40g2000prf.googlegroups.com> Message-ID: <7cfdd69e-fbea-47e7-8a88-8a977c4736df@b34g2000prf.googlegroups.com> On Aug 29, 9:14?am, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 5:35 PM, Gee Chen wrote: > > ---------------------------------- > > the Python environment on my mac is: > > > Python 2.6.4 (r264:75706, Aug 28 2011, 22:29:24) > > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > > For future reference, when on OS X, it's very helpful to include how > you installed your Python, and whether it's 32-bit or 64-bit. > > > > > > > > > > > > > I found the download adresses of scipy and numpy from official website > > 'www.scipy.org'. After downloading 2 latest released dmg files, i > > directly installed them with double-click the dmg files. > > > Then, i opened Python interpreter in Terminal, and tested whether > > scipy & numpy work. The result is disappointed! > > > when i inputed ' import scipy' & 'import numpy', the output is : > > >>>> import scipy > > Traceback (most recent call last): > > > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > > site-packages/numpy/core/_init_.py", line 5, in > > import multiarray > > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/ > > lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable > > image found. Did find: > > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site- > > packages/numpy/core/multiarray.so: no matching architecture in > > universal wrapper > > > Is there anybody can tell me where the error exists? > > I believe you've installed 32-bit libraries for a 64-bit Python (or > possibly vice-versa). It appears that NumPy & SciPy official releases > are 32-bit-only. So, you can either use the alternate, unofficial > 64-bit releases of those packages, or install a 32-bit Python (via > Fink, MacPorts, a Python.org installer, etc.). A third option is to > install the Enthought Python Distribution > (http://www.enthought.com/products/epd.php) or similar, which bundles > Python together with SciPy, NumPy, and other libraries in a single > install. > > Cheers, > Chris > --http://rebertia.com thanks for your help. the problem was solved.. From srehtvandy at gmail.com Mon Aug 29 12:22:52 2011 From: srehtvandy at gmail.com (luvspython) Date: Mon, 29 Aug 2011 09:22:52 -0700 (PDT) Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: On Aug 29, 5:02?am, Peter Otten <__pete... at web.de> wrote: > luvspython wrote: > > I have an application that needs to keep a history of the values of > > several attributes of each of many instances of many classes. ?The > > history-keeping logic is in a helper class, HistoryKeeper, that's > > inherited by classes like Vehicle in the example below. > > > Pickling an instance of Vehicle works, but unpickling fails with: > > ?"Vehicle object has no attribute > > '_orderedArgNames'" ? (_orderedArgNames is an attribute in > > HistoryKeeper that tells the attributes for which history must be > > kept.) > > > During unpickling, the exception occurs at the 2nd line in the > > __getattribute__ method: > > ? ? ? ? if item not in object.__getattribute__(self, > > '_orderedArgNames'): > > > FWIW, cPickle fails the same way. > > > Below is a stripped-down example that fails in unpickling. > > > Can anyone explain why it fails and what I can do to fix it? > > By default unpickling an object does *not* invoke its __init__() method; > instead it creates an instance and then updates the __dict__ attribute of > that instance. You intercept attribute access with __getattribute__, so to > get hold of __dict__ you need to know __dict__["_orderedArgNames"] first, i. > e. you run into a bootstrap problem. > > To fix the error I'd try special-casing "__dict__" > > def __getattribute__(self, item, ...): > ? ? if item == "__dict__": > ? ? ? ? return super(HistoryKeeper, self).__getattribute__(item) > ? ? ... > > or making _orderedArgNames a class attribute: > > class HistoryKeeper(object): > ? ? def __init__(self, orderedArgs): > ? ? ? ? for arg, value in orderedArgs.items(): > ? ? ? ? ? ? if arg != 'self': > ? ? ? ? ? ? ? ? self.Set(arg, value) > ? ? ... > > class Vehicle(HistoryKeeper): > ? ? _orderedArgNames = "tag", "make", "model" > ? ? ... > > If that doesn't work out you can write your own __reduce_ex__() method to > customise pickling, seehttp://docs.python.org/library/pickle.html#object.__reduce_ex__ > > By the way, docstrings belong below the def not above: > > def f(): > ? ? """Explain f() here"""- Hide quoted text - > > - Show quoted text - THANK YOU! Special-casing "__dict__" did the trick. Not sure I'd have ever figured that out, which leads to a different question: I can figure out most things, though perhaps very slowly and painfully, if I can trace through code. I use WingIDE (love it), but the execution of the C code is of course hidden, which helped stymie on this problem. Is there another tool y'all might use and you can suggest that deals with that problem and would have helped me with this case? Or is one's ability to figure out this sort of problem largely dependent on really understanding the system's internals? From jehugaleahsa at gmail.com Mon Aug 29 12:45:51 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Mon, 29 Aug 2011 09:45:51 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Aug 29, 2:30?am, Nobody wrote: > On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > > More importantly, I want to make sure that > > predicate is callable, accepting a thing, returning a bool. > > The "callable" part is do-able, the rest isn't. > > The predicate may accept an arbitrary set of arguments via the "*args" > and/or "**kwargs" syntax, and pass these on to some other function. > Exactly *which* function may be the result of an arbitrarily complex > expression. Or it may not even call another function, but just use the > arbitrary set of arguments in an arbitrarily complex manner. > > IOW, determining in advance what will or won't work is actually impossible. > > Thanks for everyone's input. I decided that I will put some basic checks up front, like "is it None", "is it Iterable" and "is it callable". Other than that, I am letting things slide. Asking for forgiveness is always easier anyway. Just so everyone knows, I am defining these methods inside a class called IterableExtender: class IterableExtender(collections.Iterable):... I wanted to allow for calls like this: extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == 0).first(lambda x: x % 7 == 0) It allows me to compose method calls similarly to LINQ in C#. I think this looks better than: first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, lambda x : x % 7 == 0))) Internally to the class, there are "private" static methods taking raw inputs and performing no checks. The public instance methods are responsible for checking input arguments and wrapping results. Eventually, I will start working on algorithms that work on MutableSequences, but for now I am just doing Iterables. This is turning out to be a great learning experience. From rtw at rtw.me.uk Mon Aug 29 13:30:53 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Mon, 29 Aug 2011 17:30:53 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOg=GtFGPmTB=1OJNvNRPdYUcxDoKN1WJQMOMv9gx0+fZA at mail.gmail.com in gmane.comp.python.general: > ... I wanted to allow the user to manually return the > function from the string, like this: > > a = exec(""" > def double(x): > return x * 2 > double > """) > > However it seems that exec does not return a value as it produces a > SyntaxError whenever I try to assign it. def test(): src = ( "def double(x):" " return x * 2" ) globals = {} exec( src, globals ) return globals[ "double" ] print( test() ) The a bove works on 2.7 (I tested it) on earlier versions you may need to use: exec src in globals Rob. From ian.g.kelly at gmail.com Mon Aug 29 13:42:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Aug 2011 11:42:51 -0600 Subject: Checking Signature of Function Parameter In-Reply-To: References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > I wanted to allow for calls like this: > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > 0).first(lambda x: x % 7 == 0) > > It allows me to compose method calls similarly to LINQ in C#. I think > this looks better than: > > first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, > lambda x : x % 7 == 0))) FWIW, I would be inclined to write that in Python like this: def first(iterable): try: return next(iter(iterable)) except StopIteration: raise ValueError("iterable was empty") squares = (x * x for x in range(0, 1000)) first(x for x in squares if x % 14 == 0) It does a bit too much to comfortably be a one-liner no matter which way you write it, so I split it into two. Cheers, Ian From rtw at rtw.me.uk Mon Aug 29 13:46:49 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Mon, 29 Aug 2011 17:46:49 +0000 (UTC) Subject: Button Label change on EVT_BUTTON in wxpython!!! References: Message-ID: Ven wrote in news:aa1212bb-35e5-4bf9-b8ad-7a3c083749c2 @x2g2000yql.googlegroups.com in gmane.comp.python.general: > So, here is what I did/want: > > self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install') > self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON) > > def OnRun(self,evt): > self.run_button.SetLabel('Installing..') > #call a function that does the installation task > installation_task() > #After task completion, set the button label back to "Install" > self.run_button.SetLabel('Install') > > When I try doing this, it doesn't set the label to "Installing" while > the task is being performed. Any suggestions how do I achieve this? > http://wiki.wxpython.org/CallAfter Using this your OnRun will become somthing like: def OnRun( self, evt ): def after(): installation_task() self.run_button.SetLabel('Install') self.run_button.SetLabel('Installing..') wx.Callafter( after ) However if installation_task takes a long time you will need to use threads, something like (untested): def OnRun( self, evt ): def after(): self.run_button.SetLabel('Install') def task(): installation_task() wx.Callafter( after ) self.run_button.SetLabel('Installing..') import threading threading.Thread( target = task ).start() Rob. From roy at panix.com Mon Aug 29 13:53:35 2011 From: roy at panix.com (Roy Smith) Date: Mon, 29 Aug 2011 10:53:35 -0700 (PDT) Subject: Help me understand this logging config Message-ID: I'm using django 1.3 and python 2.6. My logging config is: LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(asctime)s: %(name)s %(levelname)s % (funcName)s %(message)s' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose', }, }, 'loggers': { 'django.request': {'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'djfront': {'handlers': ['console'], 'propagate': True, }, 'djfront.view': {'level': 'INFO'}, 'djfront.auth': {'level': 'INFO'}, 'djfront.auth.user': {'level': 'INFO'}, 'djfront.api': {'level': 'WARN'}, } } In my code, I do: logger = logging.getLogger('djfront.auth.facebook') Since I haven't configured a 'djfront.auth.facebook' logger, it should inherit the 'djfront.auth' config, which means the logging level should be set to INFO. But, when I do: logger.debug('redirecting to "%s"' % url) it emits a message: 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init redirecting to [...] I'm confused. Why is the debug level message not getting filtered out? From jehugaleahsa at gmail.com Mon Aug 29 14:04:55 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Mon, 29 Aug 2011 11:04:55 -0700 (PDT) Subject: Checking Signature of Function Parameter References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: On Aug 29, 1:42?pm, Ian Kelly wrote: > On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > > I wanted to allow for calls like this: > > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > > 0).first(lambda x: x % 7 == 0) > > > It allows me to compose method calls similarly to LINQ in C#. I think > > this looks better than: > > > first(where(map(range(0, 1000), lambda x: x * x, lambda x: x % 2 == 0, > > lambda x : x % 7 == 0))) > > FWIW, I would be inclined to write that in Python like this: > > def first(iterable): > ? ? try: > ? ? ? ? return next(iter(iterable)) > ? ? except StopIteration: > ? ? ? ? raise ValueError("iterable was empty") > > squares = (x * x for x in range(0, 1000)) > first(x for x in squares if x % 14 == 0) Python's comprehensions make the need for many of the methods I am writing unnecessary. Which probably explains why no ones really bothered to write one before. The only problem I have above is either the composition causes complex method calls first(where(map(range(..., it requires complex comprehensions or it requires breaking the code into steps. Even my approach has problems, such as the overhead of carrying an invisible wrapper around. > > It does a bit too much to comfortably be a one-liner no matter which > way you write it, so I split it into two. > > Cheers, > Ian > > Yeah. I have already seen a lot of better ways of writing my code based solely on your example. I didn't know about iter as a built-in function. I have been calling __iter__ directly. I also need to think more about whether methods like "where" and "map" are going to be beneficial. The good thing is that someone will be able to use my wrapper in any context where an Iterable can be used. It will allow someone to switch between styles on the fly. I'm still not convinced that this library is going to be very "pythony". I wrote a post a few days ago about how I know the syntax and libraries fairly well, but I don't have the "philosophy". I haven't seen a lot of tricks and I am never sure what is the "norm" in Python. I am sure if an experienced Python programmer looked at my code, they'd immediately know I was missing a few things. From rosuav at gmail.com Mon Aug 29 14:20:49 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 04:20:49 +1000 Subject: is there any principle when writing python function In-Reply-To: <9c1ndoFj9iU10@mid.individual.net> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> Message-ID: On Tue, Aug 30, 2011 at 12:52 AM, Neil Cerutti wrote: >> I would split the function only when both halves (caller and >> callee) can be given short and useful names - if you can't >> explain what a block of code does in a few words, it's probably >> a poor choice for splitting out into a function. > > I agree, except for the implied unconditional preference for > short names. I believe the length of a name should usually be > proportional to the scope of the object it represents. Oh,I definitely prefer short names to this: http://thedailywtf.com/Articles/Double-Line.aspx "Short" is a relative term. If the function's name is 20 characters long and meaningful, that's fine. > In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil > Cerutti, and in the global scope I have to use a meaningless > unique identifier. Hopefully no Python namespace ever gets that > big. Chorus? Does that imply that you sing? Neat :) What you have, I think, is a module named Cerutti, in which you have a class of which Neil is an instance. Inside method functions, you can be referenced by "self" (which is to code what pronouns are to English); outside of them, you are referred to as Neil; and outside the module, Cerutti.Neil is the cleanest way to reference you. But your name is still Neil, no matter how you're referenced. Chris Angelico whose name is sometimes Chris, sometimes Rosuav, and sometimes "Chris or Michael" by people who can't distinguish him from his brother From noreply at domain.invalid Mon Aug 29 14:21:48 2011 From: noreply at domain.invalid (William Gill) Date: Mon, 29 Aug 2011 14:21:48 -0400 Subject: Help parsing a text file Message-ID: I haven't done much with Python for a couple years, bouncing around between other languages and scripts as needs suggest, so I have some minor difficulty keeping Python functionality Python functionality in my head, but I can overcome that as the cobwebs clear. Though I do seem to keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard). I have a text file with XML like records that I need to parse. By XML like I mean records have proper opening and closing tags. but fields don't have closing tags (they rely on line ends). Not all fields appear in all records, but they do adhere to a defined sequence. My initial passes into Python have been very unfocused (a scatter gun of too many possible directions, yielding very messy results), so I'm asking for some suggestions, or algorithms (possibly even examples)that may help me focus. I'm not asking anyone to write my code, just to nudge me toward a more disciplined approach to a common task, and I promise to put in the effort to understand the underlying fundamentals. From rosuav at gmail.com Mon Aug 29 14:27:14 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 04:27:14 +1000 Subject: Unpickle error -- "object has no attribute ...." In-Reply-To: References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: On Tue, Aug 30, 2011 at 2:22 AM, luvspython wrote: > I can figure out most things, though perhaps very slowly and > painfully, if I can trace through code. ?I use WingIDE (love it), but > the execution > of the C code is of course hidden, which helped stymie on this > problem. ?Is there another tool y'all might use and you can suggest > that deals with that problem and would have helped me with this case? > Or is one's ability to figure out this sort of problem largely > dependent on really understanding the system's internals? In terms of debugging, it's hard to ignore the old favorite stand-by: If In Doubt, Print It Out. Pepper your code with console-output calls and manually trace your code using those. Every other debugging tool you'll ever use is a bonus on top of that; if you accustom yourself to IIDPIO debugging, you'll be able to solve problems in any environment. Python does have a number of other debugging tools, though. I'd recommend looking at pylint, for a start. It's not technically a debugger, but it may be of value. ChrisA From philip at semanchuk.com Mon Aug 29 14:31:13 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 29 Aug 2011 14:31:13 -0400 Subject: Help parsing a text file In-Reply-To: References: Message-ID: <3BC2BAF2-0293-4773-8FD7-40FA2614299D@semanchuk.com> On Aug 29, 2011, at 2:21 PM, William Gill wrote: > I haven't done much with Python for a couple years, bouncing around between other languages and scripts as needs suggest, so I have some minor difficulty keeping Python functionality Python functionality in my head, but I can overcome that as the cobwebs clear. Though I do seem to keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard). > > I have a text file with XML like records that I need to parse. By XML like I mean records have proper opening and closing tags. but fields don't have closing tags (they rely on line ends). Not all fields appear in all records, but they do adhere to a defined sequence. > > My initial passes into Python have been very unfocused (a scatter gun of too many possible directions, yielding very messy results), so I'm asking for some suggestions, or algorithms (possibly even examples)that may help me focus. > > I'm not asking anyone to write my code, just to nudge me toward a more disciplined approach to a common task, and I promise to put in the effort to understand the underlying fundamentals. If the syntax really is close to XML, would it be all that difficult to convert it to proper XML? Then you have nice libraries like ElementTree to use for parsing. Cheers Philip From neilc at norwich.edu Mon Aug 29 14:40:24 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Aug 2011 18:40:24 GMT Subject: is there any principle when writing python function References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> Message-ID: <9c24onF3ktU2@mid.individual.net> On 2011-08-29, Chris Angelico wrote: >> In my house, I'm dad. In my chorus, I'm Neil. In town I'm Neil >> Cerutti, and in the global scope I have to use a meaningless >> unique identifier. Hopefully no Python namespace ever gets that >> big. > > Chorus? Does that imply that you sing? Neat :) Wait... not all Python programmers sing? > What you have, I think, is a module named Cerutti, in which you > have a class of which Neil is an instance. Inside method > functions, you can be referenced by "self" (which is to code > what pronouns are to English); outside of them, you are > referred to as Neil; and outside the module, Cerutti.Neil is > the cleanest way to reference you. But your name is still Neil, > no matter how you're referenced. The problem with that scenario is that, in real life, there's more than one Cerutti.Neil, and they like to move around. ;) -- Neil Cerutti From nospam at domain.invalid Mon Aug 29 14:56:05 2011 From: nospam at domain.invalid (William Gill) Date: Mon, 29 Aug 2011 14:56:05 -0400 Subject: Help parsing a text file In-Reply-To: References: Message-ID: On 8/29/2011 2:31 PM, Philip Semanchuk wrote: > > If the syntax really is close to XML, would it be all that difficult to convert it to proper XML? Then you have nice libraries like ElementTree to use for parsing. > Possibly, but I would still need the same search algorithms to find the opening tag for the field, then find and replace the next line end with a matching closing tag. So it seems to me that the starting point is the same, and then it's my choice to either process the substrings myself or employ something like ElementTree. From rosuav at gmail.com Mon Aug 29 15:02:52 2011 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Aug 2011 05:02:52 +1000 Subject: is there any principle when writing python function In-Reply-To: <9c24onF3ktU2@mid.individual.net> References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> <9c24onF3ktU2@mid.individual.net> Message-ID: On Tue, Aug 30, 2011 at 4:40 AM, Neil Cerutti wrote: > Wait... not all Python programmers sing? I do, and there seems to be more than coincidental overlap between musos and coders. > The problem with that scenario is that, in real life, there's > more than one Cerutti.Neil, and they like to move around. ;) Yes indeed; which means that your Cerutti module is in a package: from norwich import Cerutti It's always possible to make a locally-unique identifier into a more globally unique one by prepending another tag to it. Alternatively, you need to be duck-typed: you're the Neil Cerutti who writes code, and if some other Neil Cerutti is asked to write code, he will throw an exception. That's probably the easiest way to deal with it - but I don't know of a way to implement it in a coded way. Maybe all names actually point to lists of objects, and whenever you try to do something with a name, the system goes through the elements of the list until one doesn't fail? Going back to the original question, the length of function name required for it to be "meaningful" is, obviously, a variable quantity. But I think it's still reasonable to use that as a rule of thumb for dividing functions - if you can sanely name both halves, without putting the entire code into the function name, then you have a case for refactoring. ChrisA From brunoandrade_13 at hotmail.com Mon Aug 29 15:10:22 2011 From: brunoandrade_13 at hotmail.com (Bruno Andrade) Date: Mon, 29 Aug 2011 16:10:22 -0300 Subject: =?iso-8859-1?Q?Institui=E7=F5?= =?iso-8859-1?Q?es_que_uti?= =?iso-8859-1?Q?lizam_Pyth?= =?iso-8859-1?Q?on.?= Message-ID: Ol?, boa tarde! Eu, estou entrando em contato com voc?s, pois eu gostaria de saber quais institui??es brasileiras usam regularmente Python para o desenvolvimento de suas atividades. Essas institui??es podem ser usu?rios de sistemas desenvolvidos usando a linguagem Python, ou podem ser institui??es que criam aplica??es para terceiros usando a linguagem Python. Acredito que talvez, voc?s contenham uma lista com essas institui??es que utilizam Python. Desde j? agrade?o a sua aten??o; Muito Obrigado; Att; Bruno Andrade. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Mon Aug 29 16:55:55 2011 From: jason.swails at gmail.com (Jason Swails) Date: Mon, 29 Aug 2011 16:55:55 -0400 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On Sun, Aug 28, 2011 at 10:41 PM, Russ P. wrote: > > > You could look at the return value of os.system, which may tell you the > > exit status of the process. > > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > that there should be a simpler way to just kill the "whole enchilada." > Hitting Control-C over and over is a bit like whacking moles. > Agreed. I had written a program that had a similar problem. As others have suggested, you need to either wrap os.system in another function that analyzes the return value of the call or use another approach in which the Python program itself sees the SIGINT (I ended up changing to subprocess.Popen classes since they are more customizable and SIGINT is captured by the Python program itself rather than the child process). Another thing you can consider doing is to define your scripts' behavior if it captures a SIGINT. (Untested) import signal, sys def sigint_handler(): sys.stdout.write('Caught an interruption signal!') sys.exit(1) signal.signal(signal.SIGINT, sigint_handler) **rest of your program** Of course, the SIGINT signal won't be caught if it isn't seen by the main Python process, so this still won't do anything if you use an unprotected/unwrapped os.system command. HTH, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Mon Aug 29 17:05:23 2011 From: t at jollybox.de (Thomas Jollans) Date: Mon, 29 Aug 2011 23:05:23 +0200 Subject: Help parsing a text file In-Reply-To: References: Message-ID: <4E5BFF13.2070408@jollybox.de> On 29/08/11 20:21, William Gill wrote: > I haven't done much with Python for a couple years, bouncing around > between other languages and scripts as needs suggest, so I have some > minor difficulty keeping Python functionality Python functionality in my > head, but I can overcome that as the cobwebs clear. Though I do seem to > keep tripping over the same Py2 -> Py3 syntax changes (old habits die > hard). > > I have a text file with XML like records that I need to parse. By XML > like I mean records have proper opening and closing tags. but fields > don't have closing tags (they rely on line ends). Not all fields appear > in all records, but they do adhere to a defined sequence. > > My initial passes into Python have been very unfocused (a scatter gun of > too many possible directions, yielding very messy results), so I'm > asking for some suggestions, or algorithms (possibly even examples)that > may help me focus. > > I'm not asking anyone to write my code, just to nudge me toward a more > disciplined approach to a common task, and I promise to put in the > effort to understand the underlying fundamentals. A name that is often thrown around on this list for this kind of question is pyparsing. Now, I don't know anything about it myself, but it may be worth looking into. Otherwise, if you say it's similar to XML, you might want to take a cue from XML processing when it comes to dealing with the file. You could emulate the stream-based approach taken by SAX or eXpat - have methods that handle the different events that can occur - for XML this is "start tag", "end tag", "text node", "processing instruction", etc., in your case, it might be "start/end record", "field data", etc. That way, you could separate the code that keeps track of the current record, and how the data fits together to make an object structure, and the parsing code, that knows how to convert a line of data into something meaningful. Thomas From russ.paielli at gmail.com Mon Aug 29 17:26:20 2011 From: russ.paielli at gmail.com (Russ P.) Date: Mon, 29 Aug 2011 14:26:20 -0700 (PDT) Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <01954f13-f3b4-4be1-8038-e452b06b2c7b@fv14g2000vbb.googlegroups.com> On Aug 28, 8:16?pm, Chris Rebert wrote: > On Sun, Aug 28, 2011 at 8:08 PM, Russ P. wrote: > > On Aug 28, 7:51?pm, Chris Angelico wrote: > >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: > >> > On Aug 28, 6:52?pm, MRAB wrote: > >> >> You could look at the return value of os.system, which may tell you the > >> >> exit status of the process. > > >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems > >> > that there should be a simpler way to just kill the "whole enchilada." > >> > Hitting Control-C over and over is a bit like whacking moles. > > >> I believe the idea of this suggestion is for the outer script to > >> notice that the inner script terminated via Ctrl-C, and would then > >> immediately choose to terminate itself - thus avoiding the > >> whack-a-mole effect. > > >> ChrisA > > > Yes, but if I am not mistaken, that will require me to put a line or > > two after each os.system call. > > Er, just write a wrapper for os.system(), e.g.: > > def mysystem(cmd): > ? ? if os.system(cmd): > ? ? ? ? sys.exit() > > Also, you may want to switch to using the `subprocess` module instead. > > Cheers, > Chris I ended up with this: def systemx(cmd): if system(cmd): exit("\nERROR: " + cmd + " failed\n") This is good enough for my purposes in this case. Thanks for all the suggestions. --Russ P. From jacktradespublic at gmail.com Mon Aug 29 18:14:11 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 17:14:11 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Mon, Aug 29, 2011 at 12:30 PM, Rob Williscroft wrote: > Jack Trades wrote in > > ... I wanted to allow the user to manually return the > > function from the string, like this: > > > > a = exec(""" > > def double(x): > > return x * 2 > > double > > """) > > > > However it seems that exec does not return a value as it produces a > > SyntaxError whenever I try to assign it. > > def test(): > src = ( > "def double(x):" > " return x * 2" > ) > globals = {} > exec( src, globals ) > return globals[ "double" ] > > print( test() ) > I looked into doing it that way but it still requires that the user use a specific name for the function they are defining. The docs on exec say that an implementation may populate globals or locals with whatever they want so that also rules out doing a simple "for item in globals", as there may be more than just the one function in there (though I suppose I may be able to work around that). -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Aug 29 18:17:35 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 30 Aug 2011 08:17:35 +1000 Subject: For some value of =?utf-8?B?4oCcc2luZ+KAnQ==?= (was: is there any principle when writing python function) References: <7b47ca17-d3f1-4d91-91d1-98421e8708cd@ea4g2000vbb.googlegroups.com> <9c1ndoFj9iU10@mid.individual.net> <9c24onF3ktU2@mid.individual.net> Message-ID: <87ty8zsw00.fsf_-_@benfinney.id.au> Neil Cerutti writes: > On 2011-08-29, Chris Angelico wrote: > > Chorus? Does that imply that you sing? Neat :) > > Wait... not all Python programmers sing? All Python programmers sing. Some of them should not. -- \ ?To be is to do? ?Plato | `\ ?To do is to be? ?Aristotle | _o__) ?Do be do be do? ?Sinatra | Ben Finney From timothy.c.delaney at gmail.com Mon Aug 29 18:43:17 2011 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 30 Aug 2011 08:43:17 +1000 Subject: =?UTF-8?Q?Re=3A_Institui=C3=A7=C3=B5es_que_utilizam_Python=2E?= In-Reply-To: References: Message-ID: 2011/8/30 Bruno Andrade > Ol?, boa tarde! > > Eu, estou entrando em contato com voc?s, pois eu gostaria de saber quais > institui??es brasileiras usam regularmente Python para o desenvolvimento de > suas atividades. Essas institui??es podem ser usu?rios de sistemas > desenvolvidos usando a linguagem Python, ou podem ser institui??es que criam > aplica??es para terceiros usando a linguagem Python. Acredito que talvez, > voc?s contenham uma lista com essas institui??es que utilizam Python. > Pode come?ar com http://www.python.org.br/. Al?m disso, http://www.google.com.au/search?q=python+brasil. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Mon Aug 29 18:50:46 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 29 Aug 2011 23:50:46 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 29 August 2011 23:14, Jack Trades wrote: > On Mon, Aug 29, 2011 at 12:30 PM, Rob Williscroft wrote: >> >> Jack Trades wrote in >> > ... I wanted to allow the user to manually return the >> > function from the string, like this: >> > >> > a = exec(""" >> > def double(x): >> > ? return x * 2 >> > double >> > """) >> > >> > However it seems that exec does not return a value as it produces a >> > SyntaxError whenever I try to assign it. >> >> def test(): >> ?src = ( >> ? ? ?"def double(x):" >> ? ? ?" ?return x * 2" >> ? ?) >> ?globals ?= {} >> ?exec( src, globals ) >> ?return globals[ "double" ] >> >> print( test() ) > > I looked into doing it that way but it still requires that the user use a > specific name for the function they are defining.? The docs on exec say that > an implementation may populate globals or locals with whatever they want so > that also rules out doing a simple "for item in globals", as there may be > more than just the one function in there (though I suppose I may be able to > work around that). Hi Jack, Here is a possible solution for your problem (Python 3): >>> class CapturingDict(dict): ... def __setitem__(self, key, val): ... self.key, self.val = key, val ... dict.__setitem__(self, key, val) ... >>> c = CapturingDict() >>> exec("def myfunction(x): return 1", c) >>> c.key 'myfunction' >>> c.val HTH, -- Arnaud From arnodel at gmail.com Mon Aug 29 18:53:13 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 29 Aug 2011 23:53:13 +0100 Subject: killing a script In-Reply-To: References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: On 29 August 2011 04:08, Russ P. wrote: > On Aug 28, 7:51?pm, Chris Angelico wrote: >> On Mon, Aug 29, 2011 at 12:41 PM, Russ P. wrote: >> > On Aug 28, 6:52?pm, MRAB wrote: >> >> You could look at the return value of os.system, which may tell you the >> >> exit status of the process. >> >> > Thanks for the suggestion. Yeah, I guess I could do that, but it seems >> > that there should be a simpler way to just kill the "whole enchilada." >> > Hitting Control-C over and over is a bit like whacking moles. >> >> I believe the idea of this suggestion is for the outer script to >> notice that the inner script terminated via Ctrl-C, and would then >> immediately choose to terminate itself - thus avoiding the >> whack-a-mole effect. >> >> ChrisA > > Yes, but if I am not mistaken, that will require me to put a line or > two after each os.system call. That's almost like whack-a-mole at the > code level rather than the Control-C level. OK, not a huge deal for > one script, but I was hoping for something simpler. I was hoping I > could put one line at the top of the script and be done with it. Write a function! That's what they're for after all :) -- Arnaud From ethan at stoneleaf.us Mon Aug 29 19:36:12 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Aug 2011 16:36:12 -0700 Subject: Checking Signature of Function Parameter In-Reply-To: References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Message-ID: <4E5C226C.7080801@stoneleaf.us> Travis Parks wrote: > I wrote a post a few days ago about how I know the syntax and > libraries fairly well, but I don't have the "philosophy". I haven't > seen a lot of tricks and I am never sure what is the "norm" in Python. > I am sure if an experienced Python programmer looked at my code, > they'd immediately know I was missing a few things. The best thing to do now is pick something and run with it. (Sounds like you have.) Expect to redesign and reimplement three or four times as you get a feel for what's pythonic. And have fun! ~Ethan~ From jacktradespublic at gmail.com Mon Aug 29 19:39:36 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Mon, 29 Aug 2011 18:39:36 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Mon, Aug 29, 2011 at 5:50 PM, Arnaud Delobelle wrote: > > Hi Jack, > > Here is a possible solution for your problem (Python 3): > > > >>> class CapturingDict(dict): > ... def __setitem__(self, key, val): > ... self.key, self.val = key, val > ... dict.__setitem__(self, key, val) > ... > >>> c = CapturingDict() > >>> exec("def myfunction(x): return 1", c) > >>> c.key > 'myfunction' > >>> c.val > > > HTH, > > -- > Arnaud > That's brilliant and works flawlessly. Thank you very much! -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-nospam at seebs.net Mon Aug 29 21:22:33 2011 From: usenet-nospam at seebs.net (Seebs) Date: 30 Aug 2011 01:22:33 GMT Subject: A tale of yak shaving References: <4e5b9a81$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-29, Steven D'Aprano wrote: > This is not exactly fresh (it was written back in March), but it's the first > time I saw it and I thought I'd share. Barry Warsaw, one of the lead Python > developers, describes one of his most ... interesting ... debugging > experiences. That is a truly excellent debugging story. I also like the term "yak shaving", and I suspect I'll be using that for future such endeavors. Of which there are a fair number in my line of work. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From steve+comp.lang.python at pearwood.info Tue Aug 30 00:13:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 30 Aug 2011 14:13:41 +1000 Subject: killing a script References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> Message-ID: <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: [...] >> Yes, but if I am not mistaken, that will require me to put a line or >> two after each os.system call. That's almost like whack-a-mole at the >> code level rather than the Control-C level. OK, not a huge deal for >> one script, but I was hoping for something simpler. I was hoping I >> could put one line at the top of the script and be done with it. > > Write a function! That's what they're for after all :) I'm not sure that this is actually as simple as that, especially using os.system. As I understand it, the scenario is this: The main script looks something like this: for x in whatever: os.system('something.py x') Each time through the loop, a new Python process is started. Each process runs in the foreground, capturing standard input, and so hitting Ctrl-C kills *that* process, not the main script. Unless, by chance, the Ctrl-C happens after the system call returns, but before the next one starts, it is completely invisible to the parent process (the main script). Wrapping os.system in a function does nothing to fix that. Possibly using the subprocess module may help. Otherwise, the only way around this I can think of is to ensure that the 'something.py' script (or scripts!) each return an error code for "User Cancelled": for x in whatever: result = os.system('something.py x') if result == 3: # User Cancelled break But if the 'something.py' scripts are arbitrary scripts, I don't think you have any easy way around it. Perhaps use threads, and have the main script ask the thread to kill the child process? Regardless, this is a hard problem, and it isn't possible to just have some magic switch at the top of your script to make it work. You actually have to do the work yourself. (But of course you can do the work inside a function, and re-use it elsewhere.) -- Steven From rtw at rtw.me.uk Tue Aug 30 03:28:41 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 07:28:41 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOh1+oE4g9Frjp3pucbHUtWcN34KK35a-Xs2YqkZH9X5=w at mail.gmail.com in gmane.comp.python.general: >> def test(): >> src = ( >> "def double(x):" >> " return x * 2" >> ) >> globals = {} >> exec( src, globals ) >> return globals[ "double" ] >> >> print( test() ) >> > > I looked into doing it that way but it still requires that the user > use a specific name for the function they are defining. The docs on > exec say that an implementation may populate globals or locals with > whatever they want so that also rules out doing a simple "for item in > globals", as there may be more than just the one function in there > (though I suppose I may be able to work around that). > > Why not just get the name from the user, or use a regular expression to extract the first (or last, maybe) definition from the source string. Rob. From rtw at rtw.me.uk Tue Aug 30 03:37:37 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 07:37:37 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Jack Trades wrote in news:CAG5udOiOAge3uHrGSDTZ412GAg+CC- 6u8iGOyJ0Lnf3HnwUVzA at mail.gmail.com in gmane.comp.python.general: >> >>> class CapturingDict(dict): >> ... def __setitem__(self, key, val): >> ... self.key, self.val = key, val >> ... dict.__setitem__(self, key, val) >> ... >> >>> c = CapturingDict() >> >>> exec("def myfunction(x): return 1", c) >> >>> c.key >> 'myfunction' >> >>> c.val >> >> >> HTH, >> >> -- >> Arnaud >> > > That's brilliant and works flawlessly. Thank you very much! If an impementation (as you say up thread) can populate globals or locals with whatever they want, then how do you know that last item added was the function definition the user supplied ? Rob. From exhuma at gmail.com Tue Aug 30 04:53:17 2011 From: exhuma at gmail.com (Michel Albert) Date: Tue, 30 Aug 2011 01:53:17 -0700 (PDT) Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? Message-ID: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Hi, I use python oftentimes to write automation scripts on Linux servers. And there's a big pattern in my scripts: - I *always* use `logging` instead of `print` statements. - I *always* create two stream handlers. One for `sys.stdout` with level `INFO` and one for `sys.stderr` with level `WARN` Well, the levels may variate occasionally, but that's only the rare exception. The reason I do this is simple: Most automation tasks are run via cron. With this setup, I can redirect `stdout` to `/dev/null` and still receive e-mails if things go wrong. And having two handlers gives me more flexibility in my scripts. In one case, I used a different color for error messages for example as this script is run primarily from the shell and having errors stand out has proven to be a good thing. Unfortunately this setup makes `logging.basicConfig` pretty useless. However, I believe that this is something that more people could benefit from. I also believe, that it just "makes sense" to send warnings (and above) to `stderr`, the rest to `stdout`. So I was thinking: "Why does `logging.basicConfig` not behave that way". Naturally, I was thinking of writing a patch against the python codebase and submit it as a suggestion. But before doing so, I would like to hear your thoughts on this. Does it make sense to you too or am I on the wrong track? Are there any downsides I am missing? From __peter__ at web.de Tue Aug 30 05:24:44 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 11:24:44 +0200 Subject: Help me understand this logging config References: Message-ID: Roy Smith wrote: > I'm using django 1.3 and python 2.6. Isn't dictConfig() new in 2.7? It looks like that is what you are using... > My logging config is: > > > LOGGING = { > 'version': 1, > 'disable_existing_loggers': False, > 'formatters': { > 'verbose': { > 'format': '%(asctime)s: %(name)s %(levelname)s % > (funcName)s %(message)s' > } > }, > 'handlers': { > 'mail_admins': { > 'level': 'ERROR', > 'class': 'django.utils.log.AdminEmailHandler' > }, > 'console': { > 'level': 'DEBUG', > 'class': 'logging.StreamHandler', > 'formatter': 'verbose', > }, > }, > 'loggers': { > 'django.request': {'handlers': ['mail_admins'], > 'level': 'ERROR', > 'propagate': True, > }, > 'djfront': {'handlers': ['console'], > 'propagate': True, > }, > 'djfront.view': {'level': 'INFO'}, > 'djfront.auth': {'level': 'INFO'}, > 'djfront.auth.user': {'level': 'INFO'}, > 'djfront.api': {'level': 'WARN'}, > } > } > > In my code, I do: > > logger = logging.getLogger('djfront.auth.facebook') > > Since I haven't configured a 'djfront.auth.facebook' logger, it should > inherit the 'djfront.auth' config, which means the logging level > should be set to INFO. But, when I do: > > logger.debug('redirecting to "%s"' % url) > > it emits a message: > > 2011-08-29 13:31:03,321: djfront.auth.facebook DEBUG oauth_init > redirecting to [...] > > I'm confused. Why is the debug level message not getting filtered > out? I tried your setup with the django-specific handler replaced by another StreamHandler $ cat tmp_logging.py import logging import logging.config LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(asctime)s: %(name)s %(levelname)s %(funcName)s %(message)s' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'logging.StreamHandler' #'django.utils.log.AdminEmailHandler' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose', }, }, 'loggers': { 'django.request': {'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'djfront': {'handlers': ['console'], 'propagate': True, }, 'djfront.view': {'level': 'INFO'}, 'djfront.auth': {'level': 'INFO'}, 'djfront.auth.user': {'level': 'INFO'}, 'djfront.api': {'level': 'WARN'}, } } logging.config.dictConfig(LOGGING) logger = logging.getLogger('djfront.auth.facebook') logger.info("info-test") logger.debug("debug-test") and got what $ python2.7 tmp_logging.py 2011-08-30 11:18:33,160: djfront.auth.facebook INFO info-test $ which seems to be what you expected. So I'm confused, too... From __peter__ at web.de Tue Aug 30 05:45:53 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 11:45:53 +0200 Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? References: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Message-ID: Michel Albert wrote: > I use python oftentimes to write automation scripts on Linux servers. > And there's a big pattern in my scripts: > > - I *always* use `logging` instead of `print` statements. > - I *always* create two stream handlers. One for `sys.stdout` with > level `INFO` and one for `sys.stderr` with level `WARN` > > Well, the levels may variate occasionally, but that's only the rare > exception. How would a call to basicConfig() look like that produces this setup? From hansmu at xs4all.nl Tue Aug 30 06:40:26 2011 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 30 Aug 2011 12:40:26 +0200 Subject: killing a script In-Reply-To: <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <22a0dae6-8a60-4e68-82a5-31a949bd69d5@y8g2000prd.googlegroups.com> <4e5c6376$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5cbe1a$0$2468$e4fe514c@news2.news.xs4all.nl> On 30/08/11 06:13:41, Steven D'Aprano wrote: > On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: > > [...] >>> Yes, but if I am not mistaken, that will require me to put a line or >>> two after each os.system call. That's almost like whack-a-mole at the >>> code level rather than the Control-C level. OK, not a huge deal for >>> one script, but I was hoping for something simpler. I was hoping I >>> could put one line at the top of the script and be done with it. >> >> Write a function! That's what they're for after all :) > > > I'm not sure that this is actually as simple as that, especially using > os.system. > > As I understand it, the scenario is this: > > The main script looks something like this: > > for x in whatever: > os.system('something.py x') > > Each time through the loop, a new Python process is started. Each process > runs in the foreground, capturing standard input, and so hitting Ctrl-C > kills *that* process, not the main script. Unless, by chance, the Ctrl-C > happens after the system call returns, but before the next one starts, it > is completely invisible to the parent process (the main script). Wrapping > os.system in a function does nothing to fix that. > > Possibly using the subprocess module may help. Using the subprocess module is likely to help, because unlike os.system, subprocess does not set control-C to 'ignore' in the parent process > Otherwise, the only way around this I can think of is to ensure that > the 'something.py' script (or scripts!) each return an error code for "User > Cancelled": > > for x in whatever: > result = os.system('something.py x') > if result == 3: # User Cancelled > break On my system, os.system returns 2 if the subprocess was killed by a control-C. The portable way is to use the constant SIGINT from the signal module. Not that os.system does not return 2 if the child ended by doing sys.exit(2); in that case, os.system in the parent returns 2<<8. > But if the 'something.py' scripts are arbitrary scripts, I don't think you > have any easy way around it. If the arbitrary script does not trap SIGINT, then os.system will return the number of the signal that kill the script, i.e. signal.SIGINT. If the script traps SIGINT and does some cleanup and then exits, the best you can hope for, is that in the error case, the script exits with a special value. And you have to remember the <<8 issue. > Perhaps use threads, and have the main script > ask the thread to kill the child process? How would that help? The problem is that the parent process ignores control-C while os.system is running (by design). If the parent uses threads, it still won't receive the signal, because signal state is global. > Regardless, this is a hard problem, and it isn't possible to just have some > magic switch at the top of your script to make it work. You actually have > to do the work yourself. You could monkey-patch the os module and replace os.system by (untested): def sub_system(command): pr = subprocess.Popen(command, shell=True) status = os.waitpid(pr.pid, 0)[1] return status That should have the same effect as os.system, except it does not ignore control-C. > (But of course you can do the work inside a function, and re-use it > elsewhere.) Even if you don't re-use it, you should still do it in a function, if only for readability. Hope this helps, -- HansM From anand.ibmgsi at gmail.com Tue Aug 30 07:31:42 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Tue, 30 Aug 2011 17:01:42 +0530 Subject: Help me understand this logging config In-Reply-To: References: Message-ID: Hi, I took a look at the logging source code. getLogger checks for existing loggers with the given name and if it doesn't creates one. def getLogger(self, name): """ Get a logger with the specified name (channel name), creating it if it doesn't yet exist. This name is a dot-separated hierarchical name, such as "a", "a.b", "a.b.c" or similar. If a PlaceHolder existed for the specified name [i.e. the logger didn't exist but a child of it did], replace it with the created logger and fix up the parent/child references which pointed to the placeholder to now point to the logger. """ rv = None _acquireLock() try: if name in self.loggerDict: rv = self.loggerDict[name] if isinstance(rv, PlaceHolder): ph = rv rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupChildren(ph, rv) self._fixupParents(rv) else: rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupParents(rv) finally: _releaseLock() return rv ============================================== Anand Jeyahar https://sites.google.com/site/ anandjeyahar ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From wm at localhost.localdomain Tue Aug 30 07:50:42 2011 From: wm at localhost.localdomain (Waldek M.) Date: Tue, 30 Aug 2011 13:50:42 +0200 Subject: Help parsing a text file References: Message-ID: <1mpbiyq718zub.dlg@localhost.localdomain> On Mon, 29 Aug 2011 23:05:23 +0200, Thomas Jollans wrote: > A name that is often thrown around on this list for this kind of > question is pyparsing. Now, I don't know anything about it myself, but > it may be worth looking into. Definitely. I did use it and even though it's not perfect - it's very useful indeed. Due to it's nature it is not a demon of speed when parsing complex and big structures, so you might want to keep it in mind. But I whole-heartedly recommend it. Br. Waldek From exhuma at gmail.com Tue Aug 30 07:59:32 2011 From: exhuma at gmail.com (Michel Albert) Date: Tue, 30 Aug 2011 04:59:32 -0700 (PDT) Subject: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? References: <7f46ab8f-710c-4463-a072-fa80c49f90de@ea4g2000vbb.googlegroups.com> Message-ID: On Aug 30, 11:45?am, Peter Otten <__pete... at web.de> wrote: > Michel Albert wrote: > > I use python oftentimes to write automation scripts on Linux servers. > > And there's a big pattern in my scripts: > > > - I *always* use `logging` instead of `print` statements. > > - I *always* create two stream handlers. One for `sys.stdout` with > > level `INFO` and one for `sys.stderr` with level `WARN` > > > Well, the levels may variate occasionally, but that's only the rare > > exception. > > How would a call to basicConfig() look like that produces this setup? I personally see this happen by default (i.e. no additional parameters). And in case the `stream` parameter is set, /then/ you would send all to that stream only. In my point of view, the call to `basicConfig` is either something used in only the most mundane usages of the logging package, or it's mainly used by people that have not yet grokked the logging package (correct me if I'm wrong). In both cases, I find it useful to redirect warnings and errors to `stderr` by default. However, this would also mean that existing code calling this method would result in different behavior. But only /slightly/ different. Meaning, you still see the output on the console as expected. But it gives you the possibility to use standard shell redirection in a way that "makes sense". From jacktradespublic at gmail.com Tue Aug 30 08:31:26 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Tue, 30 Aug 2011 07:31:26 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: > > That's brilliant and works flawlessly. Thank you very much! > > If an impementation (as you say up thread) can populate globals > or locals with whatever they want, then how do you know that last > item added was the function definition the user supplied ? > > Rob. > > -- > http://mail.python.org/mailman/listinfo/python-list > I spoke a bit too soon with the "works flawlessly" post. In addition to your issue, there is also the problem that supplying an empty environment does not allow the user to call necessary functions (like scheme_eval). Why not just get the name from the user > That's probably what I'll end up doing, something similar to: special_forms = {} def exec_func_def(symbol, def_string, name=None): exec(def_string) if name is None: special_forms[symbol] = f else: special_forms[symbol] = eval(name) It just feels kind of hackish to me, when what I really want to do here is eval an anonymous function. -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Tue Aug 30 08:39:26 2011 From: roy at panix.com (Roy Smith) Date: Tue, 30 Aug 2011 08:39:26 -0400 Subject: Help me understand this logging config References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Roy Smith wrote: > > > I'm using django 1.3 and python 2.6. > > Isn't dictConfig() new in 2.7? It looks like that is what you are using... Oh, my, it turns out that django includes: # This is a copy of the Python logging.config.dictconfig module, # reproduced with permission. It is provided here for backwards # compatibility for Python versions prior to 2.7. Comparing the django copy to lib/logging/config.py from Python 2.7.2, they're not identical. It's likely they grabbed something earlier in the 2.7 series. I'll check 2.7.0 and 2.7.1 to see. > I tried your setup with the django-specific handler replaced by another > StreamHandler > [...] > and got what > > $ python2.7 tmp_logging.py > 2011-08-30 11:18:33,160: djfront.auth.facebook INFO info-test > $ > > which seems to be what you expected. So I'm confused, too... I'll need to dig deeper. Not that I realize this may not be a Python issue per-se, I'll do some more experimentation and ask on the django mailing list. Thanks for your help. From __peter__ at web.de Tue Aug 30 10:21:27 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Aug 2011 16:21:27 +0200 Subject: Unpickle error -- "object has no attribute ...." References: <45c360d7-899d-4496-88dc-2112979f36ab@eb1g2000vbb.googlegroups.com> Message-ID: luvspython wrote: > THANK YOU! Special-casing "__dict__" did the trick. Not sure I'd > have ever figured that out, which leads to a different question: > > I can figure out most things, though perhaps very slowly and > painfully, if I can trace through code. I use WingIDE (love it), but > the execution > of the C code is of course hidden, which helped stymie on this > problem. Is there another tool y'all might use and you can suggest > that deals with that problem and would have helped me with this case? > Or is one's ability to figure out this sort of problem largely > dependent on really understanding the system's internals? I'm with Chris here, I make do with some understanding of Python and a generous amount of print statements. My other secret weapon is that I try to keep the complexity of my code low ;) As Python is yet another C program you can of course step through its code (debug build) with an appropriate debugger, but I've never done that. My guess is that you wouldn't have seen the forest for the trees. From phd at phdru.name Tue Aug 30 12:04:17 2011 From: phd at phdru.name (Oleg Broytman) Date: Tue, 30 Aug 2011 20:04:17 +0400 Subject: SQLObject 1.1.3 Message-ID: <20110830160417.GD19217@iskra.aviel.ru> Hello! I'm pleased to announce version 1.1.3, a bugfix release of branch 1.1 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.1.3 News and changes: http://sqlobject.org/News.html What's New ========== Features & Interface -------------------- * Fixed a bug with Postgres - add quotes in "SET client_encoding" query. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From k.sahithi2862 at gmail.com Tue Aug 30 12:25:36 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 30 Aug 2011 09:25:36 -0700 (PDT) Subject: 2011 HOT PICS Message-ID: <1855dc30-bb22-466d-8e62-17f83e3e03f8@c8g2000prn.googlegroups.com> FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS TAMANNA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/tamanna-hot.html PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From johanna.royer at gmail.com Tue Aug 30 12:41:32 2011 From: johanna.royer at gmail.com (Johanna) Date: Tue, 30 Aug 2011 18:41:32 +0200 Subject: can't create instance of pythoncom server Message-ID: Hi all, I am trying to consume a Pythoncom server from 3ds max. I need this to be able to call some mysql queries in python script from maxscript. I tried to follow the steps in this article. I created a small pythoncom server import sys, os def getWorkingDirectory() : return os.path.dirname(sys.argv[0]) sys.path.append('tubeBDD') from Database import Database import selectBDD as select db = Database() # A simple Python COM server. class PythonComUtilities: _public_methods_ = ['getProjects'] _reg_progid_ = 'PythonCom.Utilities' # Class ID must be new/unique for every server you create _reg_clsid_ = '{BAC62D37-EEDF-46B3-8DED-11E842225B0E}' def getProjects(self, string): # self.db = Database() projects = select.getProjects(db) proj = "" for p in projects: if proj == "": proj = p[0] else: proj = proj + "," + p[0] return proj if (__name__ == '__main__'): print 'Registering COM server...' import win32com.server.register as comReg comReg.UseCommandLine(PythonComUtilities) Then I try to call it in a maxscript (in a 3D soft): comObj = createOLEObject "PythonCom.Utilities" It gives me this error : -- Runtime error: createOLEObject: can't create instance PythonCom.Utilities Any idea what I'm doing wrong ? Or any idea of how I could test it other than in the 3D soft ? Cheers, Johanna -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Aug 30 14:19:52 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 11:19:52 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D29C8.8010206@stoneleaf.us> Jack Trades wrote: > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? Because the implementation will add things before the exec is processed. Then when the exec actually runs, any assignments, definitions, etc, from the user supplied string will be added. > I spoke a bit too soon with the "works flawlessly" post. In addition to > your issue, there is also the problem that supplying an empty > environment does not allow the user to call necessary functions (like > scheme_eval). So, just like an implementation, add the functions to the CapturingDict before the exec. One thing to keep in mind: the CapturingDict only remembers the *last* thing created/assigned... so if the user code has more than one def/class/name assignment, you won't have ready access to the first items, only that last one. ~Ethan~ From rtw at rtw.me.uk Tue Aug 30 15:28:52 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 19:28:52 +0000 (UTC) Subject: Returning a value from exec or a better solution References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: Ethan Furman wrote in news:4E5D29C8.8010206 at stoneleaf.us in gmane.comp.python.general: > Jack Trades wrote: >> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>> If an impementation (as you say up thread) can populate globals >>> or locals with whatever they want, then how do you know that last >>> item added was the function definition the user supplied ? > > Because the implementation will add things before the exec is processed. How do you know this ?, it isn't what the docs say. http://docs.python.org/reference/simple_stmts.html#the-exec-statement Rob. From fnautaNO at SPAMsolfon.nl Tue Aug 30 16:00:48 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Tue, 30 Aug 2011 22:00:48 +0200 Subject: Installing WebDAV server Message-ID: <9c4trjFcfmU1@mid.individual.net> Hi all, I am completely new to Python, but I'm confronted with a problem I can't solve. This is my question: I'm running a PC with XP Pro32, which acts as a file server/print server/FTP server and web server. The web server is facilitated by the Aprelium Abyss X2 server, and has Perl and PHP support on http and https. It all works fine. To do some research with some calender systems and to share the Outlook calendar I need a WebDAV server. After googling I found the Python WebDAV server. I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and PyXML-0.8.4. In the PyWebDAV README it says: Installation and setup of server can be as easy as follows: $ easy_install PyWebDAV $ davserver -D /tmp -n -J But of course it doesn't work like that. When I start up Python GUI I see the ">>>" prompt instead of the "$" prompt. But where do I place the two directories? And there is no easy_install script in the PyXML-0.8.4 directory, only a setup.py and ez_setup.py script. I guess the latter is the one to use. But how? How do I proceed next? Any help will be appreciated. Thanks in advance. With regards, Fokke Nauta From PointedEars at web.de Tue Aug 30 16:31:11 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 30 Aug 2011 22:31:11 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> Message-ID: <6545843.yvFAXZvWTv@PointedEars.de> Fokke Nauta wrote: > I'm running a PC with XP Pro32, [?] > To do some research with some calender systems and to share the Outlook > calendar I need a WebDAV server. After googling I found the Python WebDAV > server. > I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. > Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 > and PyXML-0.8.4. In the PyWebDAV README it says: > > Installation and setup of server can be as easy as follows: > > $ easy_install PyWebDAV > $ davserver -D /tmp -n -J > > But of course it doesn't work like that. When I start up Python GUI That is really not a *G*raphical User Interface, but the (text-based) Python shell. > I see the ">>>" prompt instead of the "$" prompt. "Doctor, my arm hurts when I move it." ? "Don't move it, then." The Python shell executes Python code. The above obviously is not Python code, but *system* shell commands. So let the *system* command shell execute them (as indicated by the `$' prompt, which is customary for a sh-based UNIX/Linux shell prompt). Since you use Windows XP, type `cmd' to get the command shell (if you knew MS-DOS, which I doubt, you are at home now). However, you appear to have found the *UNIX/Linux* README (and the corresponding version?) of that server: the second command is usually how you would run a program as daemon on Unices (run through an init script), while on Windows NT (like XP) you would have a setup program install a service for you (maybe to execute that command when the service is started). Look for the Windows version. > But where do I place the two directories? You do not; let easy_install place them in the correct packages directory (hence *easy* *install*). That is very likely what the setup.py and ez_setup.py scripts are for (spell "ez" in English). > And there is no easy_install script in the PyXML-0.8.4 > directory, only a setup.py and ez_setup.py script. I guess the latter is > the one to use. But how? RTFM. > How do I proceed next? Look for the Windows version. If there is none, get easy_install and use it as described. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From philip at semanchuk.com Tue Aug 30 16:34:48 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Aug 2011 16:34:48 -0400 Subject: Python Tools for Visual Studio - anyone using it? Message-ID: Hi all, I was reminded today (via Slashdot) of Python Tools for Visual Studio which was discussed on this list back in March (http://mail.python.org/pipermail/python-list/2011-March/1267662.html) and has reached version 1.0. Is anyone here using it? Care to share pros & cons? Here's the URL for those who haven't heard of it before: http://pytools.codeplex.com/ Thanks Philip From aww.dev at googlemail.com Tue Aug 30 16:42:29 2011 From: aww.dev at googlemail.com (Andreas) Date: Tue, 30 Aug 2011 22:42:29 +0200 Subject: Usage of PyDateTime_FromTimestamp Message-ID: Hi, I'm working on a c-extension of python and want to create an instance of python datetime object with a unix timestamp in c. On the documentation site ( http://docs.python.org/c-api/datetime.html ) I found the function PyDateTime_FromTimestamp() which returns a new reference based on an input parameter. The description is as follows: Create and return a new datetime.datetime object given an argument tuple suitable for passing to datetime.datetime.fromtimestamp(). I tried out to call the function with a PyFloat_Object but the function always returns NULL (even if I simply put in 0). Does somebody have an example how I have to call the function or can give a hint what kind of parameter tuple is required to get it work? Thanks! From ethan at stoneleaf.us Tue Aug 30 16:59:34 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 13:59:34 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: <4E5D4F36.1030209@stoneleaf.us> Rob Williscroft wrote: > Ethan Furman wrote in news:4E5D29C8.8010206 at stoneleaf.us in > gmane.comp.python.general: > >> Jack Trades wrote: >>> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>>> If an impementation (as you say up thread) can populate globals >>>> or locals with whatever they want, then how do you know that last >>>> item added was the function definition the user supplied ? >> Because the implementation will add things before the exec is processed. > > How do you know this ?, it isn't what the docs say. > > http://docs.python.org/reference/simple_stmts.html#the-exec-statement The docs don't say when, true -- so I don't know for sure that all additions happen before the exec since I haven't delved into the source code... Okay, just perused builtin_exec in bltinmodule.c, and I can say that cPython (somewhere in 3.2-3.3 land) only adds __builtins__ if not already there, and that it does it first. Which makes sense -- after all, what's the point of adding stuff to globals() *after* the code has been run? ~Ethan~ From arnodel at gmail.com Tue Aug 30 17:05:07 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 30 Aug 2011 22:05:07 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 30 August 2011 13:31, Jack Trades wrote: > > > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: > >> >> > That's brilliant and works flawlessly. ?Thank you very much! >> >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? That's not an issue. The last statement that is executed will be the "def" statement. >> Rob. > > I spoke a bit too soon with the "works flawlessly" post.? In addition to > your issue, there is also the problem that supplying an empty environment > does not allow the user to call necessary functions (like scheme_eval). You could simply prepend the function definition string with whatever imports are needed. -- Arnaud From fnautaNO at SPAMsolfon.nl Tue Aug 30 17:16:12 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Tue, 30 Aug 2011 23:16:12 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> Message-ID: <9c528rFi5aU1@mid.individual.net> "Thomas 'PointedEars' Lahn" wrote in message news:6545843.yvFAXZvWTv at PointedEars.de... > Fokke Nauta wrote: > >> I'm running a PC with XP Pro32, [.] >> To do some research with some calender systems and to share the Outlook >> calendar I need a WebDAV server. After googling I found the Python WebDAV >> server. >> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >> Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 >> and PyXML-0.8.4. In the PyWebDAV README it says: >> >> Installation and setup of server can be as easy as follows: >> >> $ easy_install PyWebDAV >> $ davserver -D /tmp -n -J >> >> But of course it doesn't work like that. When I start up Python GUI > > That is really not a *G*raphical User Interface, but the (text-based) > Python > shell. Yes, I noticed. But the application has the name of Python GUI. >> I see the ">>>" prompt instead of the "$" prompt. > > "Doctor, my arm hurts when I move it." - "Don't move it, then." I don't see the point here ... > The Python shell executes Python code. The above obviously is not Python > code, but *system* shell commands. So let the *system* command shell > execute them (as indicated by the `$' prompt, which is customary for a > sh-based UNIX/Linux shell prompt). I know. I worked with SCO Unix and various sorts of Linux. But never with Python, so I hadn't got a clue about the prompt. > Since you use Windows XP, type `cmd' to get the command shell (if you knew > MS-DOS, which I doubt, you are at home now). I know MSDOS. I even worked with CP/M > However, you appear to have > found the *UNIX/Linux* README (and the corresponding version?) of that > server: the second command is usually how you would run a program as > daemon > on Unices (run through an init script), while on Windows NT (like XP) you > would have a setup program install a service for you (maybe to execute > that > command when the service is started). Look for the Windows version. There is no other Windows version except the packages I mentioned, PyWebDAV and PyXML. The only Windows thing I got was the Python interpreter itself. >> But where do I place the two directories? > > You do not; let easy_install place them in the correct packages directory > (hence *easy* *install*). That is very likely what the setup.py and > ez_setup.py scripts are for (spell "ez" in English). > >> And there is no easy_install script in the PyXML-0.8.4 >> directory, only a setup.py and ez_setup.py script. I guess the latter is >> the one to use. But how? > > RTFM. Which fucking manual? >> How do I proceed next? > > Look for the Windows version. If there is none, get easy_install and use > it > as described. > Thanks for your quick reply. This means "Show over"? Fokke From ramit.prasad at jpmorgan.com Tue Aug 30 17:26:24 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 30 Aug 2011 17:26:24 -0400 Subject: Get reference to parent class from subclass? In-Reply-To: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> References: <20110828140024.f945cf73052f0c39b0a22a99@johnohagan.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F1628DD19@EMARC112VS01.exchad.jpmchase.net> -----Original Message----- From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of John O'Hagan Sent: Saturday, August 27, 2011 11:00 PM To: python-list at python.org Subject: Get reference to parent class from subclass? class P(): pass class C(P): pass Can I get P from C? IOW, can I get a reference to the object P from the object C? This should be obvious one way or the other, but I haven't been able to find the answer. Regards, John -- You should be able to access what you need via the super() built-in. I am not entirely sure what you are trying to do...but I think usage of super is probably better than trying to access the base classes manually. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jdriselvato at gmail.com Tue Aug 30 17:32:51 2011 From: jdriselvato at gmail.com (John Riselvato) Date: Tue, 30 Aug 2011 17:32:51 -0400 Subject: Access LDAP with Django Message-ID: Would Django be a good framework to use if i wanted to take directories of LDAP and make a list of users on a website? I have seen it done in php, but what about trying to manage this with django? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtw at rtw.me.uk Tue Aug 30 17:48:11 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 30 Aug 2011 21:48:11 +0000 (UTC) Subject: Returning a value from exec or a better solution References: Message-ID: Arnaud Delobelle wrote in news:CAJ6cK1YVi3NQgdZOUdhAESf133pUkdazM1PkSP=p6xFaYVOHYA at mail.gmail.com in gmane.comp.python.general: > On 30 August 2011 13:31, Jack Trades wrote: >> >> >> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> >>> >>> > That's brilliant and works flawlessly. ??Thank you very much! >>> >>> If an impementation (as you say up thread) can populate globals >>> or locals with whatever they want, then how do you know that last >>> item added was the function definition the user supplied ? > That's not an issue. The last statement that is executed will be the > "def" statement. You don't know that, an implementation may for example set __bultins__ to None, prior to returning, its not an unreasonable thing to do and the docs don't say they can't. Rob. From python at mrabarnett.plus.com Tue Aug 30 17:49:04 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Aug 2011 22:49:04 +0100 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: References: Message-ID: <4E5D5AD0.9070408@mrabarnett.plus.com> On 30/08/2011 21:42, Andreas wrote: > Hi, > > I'm working on a c-extension of python and want to create an instance of > python datetime object with a unix timestamp in c. > > On the documentation site ( http://docs.python.org/c-api/datetime.html ) > I found the function PyDateTime_FromTimestamp() which returns a new > reference based on an input parameter. > > The description is as follows: Create and return a new datetime.datetime > object given an argument tuple suitable for passing to > datetime.datetime.fromtimestamp(). > > I tried out to call the function with a PyFloat_Object but the function > always returns NULL (even if I simply put in 0). > > Does somebody have an example how I have to call the function or can > give a hint what kind of parameter tuple is required to get it work? > The key phrase is "argument tuple". The arguments passed to a Python call are always a tuple, not PyFloat_Object. You can build a tuple from the PyFloat_Object using: Py_BuildValue("(O)", float_object) The "(O)" says to build a tuple ("(...)") containing a single object ("O"). From ethan at stoneleaf.us Tue Aug 30 18:28:16 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 15:28:16 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D6400.90003@stoneleaf.us> Rob Williscroft wrote: > Arnaud Delobelle wrote: >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. Yet another excellent reason to have unit tests! ~Ethan~ From ethan at stoneleaf.us Tue Aug 30 18:31:42 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 30 Aug 2011 15:31:42 -0700 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: <4E5D64CE.3060303@stoneleaf.us> Rob Williscroft wrote: > Arnaud Delobelle wrote: > >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. Actually, I think it is unreasonable -- by modifying the globals or locals objects *after* the code has been exec'd, information is being removed about the environment the code ran in, making introspection (if nothing else) more difficult. Good reasons are required to make life difficult (at least with Python). ~Ethan~ From jacktradespublic at gmail.com Tue Aug 30 18:45:58 2011 From: jacktradespublic at gmail.com (Jack Trades) Date: Tue, 30 Aug 2011 17:45:58 -0500 Subject: Returning a value from exec or a better solution In-Reply-To: <4E5D29C8.8010206@stoneleaf.us> References: <4E5D29C8.8010206@stoneleaf.us> Message-ID: On Tue, Aug 30, 2011 at 1:19 PM, Ethan Furman wrote: > > I spoke a bit too soon with the "works flawlessly" post. In addition to >> your issue, there is also the problem that supplying an empty environment >> does not allow the user to call necessary functions (like scheme_eval). >> > > > So, just like an implementation, add the functions to the CapturingDict > before the exec. > > I will probably do that a bit down the road, that also allows exporting only the things that are absolutely necessary, which is a huge plus. Right now I'm trying to keep the code as simple as possible as this Scheme interpreter is being written as a tutorial in a similar fashion to "An Incremental Approach to Compiler Construction". I'll add a note about this method of implementation and link to this discussion. In the off chance anyone is interested, the series is hereand the github is here . It's still very much in draft form and will probably undergo a number of rewrites, but criticism is always welcome. -- Nick Zarczynski Pointless Programming Blog -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabiofz at gmail.com Tue Aug 30 19:44:43 2011 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 30 Aug 2011 20:44:43 -0300 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: On Fri, Aug 26, 2011 at 11:18 AM, Dave Boland wrote: > I'm looking for a good IDE -- easy to setup, easy to use -- for Python. ?Any > suggestions? > > I use Eclipse for other projects and have no problem with using it for > Python, except that I can't get PyDev to install. ?It takes forever, then > produces an error that makes no sense. > > An error occurred while installing the items > ?session context was:(profile=PlatformProfile, > phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, > operand=null --> [R]org.eclipse.cvs 1.0.400.v201002111343, > action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). > ?Cannot connect to keystore. > ?This trust engine is read only. > ?The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was > not found. > > > Any suggestions on getting this to work? In the install dialog, uncheck the 'contact all update sites during install to find required software'. Another option would be getting Aptana Studio 3, which has PyDev preinstalled (see: http://pydev.org/download.html ) Cheers, Fabio From PointedEars at web.de Tue Aug 30 20:00:33 2011 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 31 Aug 2011 02:00:33 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> Message-ID: <4761603.ypaU67uLZW@PointedEars.de> Fokke Nauta wrote: > "Thomas 'PointedEars' Lahn" wrote in message > news:6545843.yvFAXZvWTv at PointedEars.de... It's attribution _line_, not attribution novel. Your quotes are hardly legible, too ? >> Fokke Nauta wrote: >>> I'm running a PC with XP Pro32, [.] >>> [?] In the PyWebDAV README it says: >>> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_install PyWebDAV >>> $ davserver -D /tmp -n -J >>> >>> But of course it doesn't work like that. When I start up Python GUI >> That is really not a *G*raphical User Interface, but the (text-based) >> Python shell. > > Yes, I noticed. But the application has the name of Python GUI. ACK. Admittedly I cannot remember having used Python on Windows (XP) except via Cygwin. >>> I see the ">>>" prompt instead of the "$" prompt. >> "Doctor, my arm hurts when I move it." - "Don't move it, then." > > I don't see the point here ... Do not run `python' or the "Python GUI", then. >> The Python shell executes Python code. The above obviously is not Python >> code, but *system* shell commands. So let the *system* command shell >> execute them (as indicated by the `$' prompt, which is customary for a >> sh-based UNIX/Linux shell prompt). > > I know. I worked with SCO Unix and various sorts of Linux. > But never with Python, so I hadn't got a clue about the prompt. Come on, with that experience you see a `$' and those commands and don't realize it is (ba)sh? >> Since you use Windows XP, type `cmd' to get the command shell (if you >> knew MS-DOS, which I doubt, you are at home now). > > I know MSDOS. I even worked with CP/M Good for you. >> However, you appear to have found the *UNIX/Linux* README (and the >> corresponding version?) of that server: the second command is usually how >> you would run a program as daemon on Unices (run through an init script), >> while on Windows NT (like XP) you would have a setup program install a >> service for you (maybe to execute that command when the service is >> started). Look for the Windows version. > > There is no other Windows version except the packages I mentioned, > PyWebDAV and PyXML. The only Windows thing I got was the Python > interpreter itself. Has it not occurred to you to STFW for "easy_install" first? >>> And there is no easy_install script in the PyXML-0.8.4 >>> directory, only a setup.py and ez_setup.py script. I guess the latter is >>> the one to use. But how? >> RTFM. > > Which fucking manual? That of the server, on Windows-related information. Or that of easy_install. Or Python. Whichever comes first. >>> How do I proceed next? >> Look for the Windows version. If there is none, get easy_install and use >> it as described. > > Thanks for your quick reply. > This means "Show over"? No, it means "Do your homework". -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. From jehugaleahsa at gmail.com Tue Aug 30 21:43:21 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Tue, 30 Aug 2011 18:43:21 -0700 (PDT) Subject: Handling 2.7 and 3.0 Versions of Dict Message-ID: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> I am writing a simple algorithms library that I want to work for both Python 2.7 and 3.x. I am writing some functions like distinct, which work with dictionaries under the hood. The problem I ran into is that I am calling itervalues or values depending on which version of the language I am working in. Here is the code I wrote to overcome it: import sys def getDictValuesFoo(): if sys.version_info < (3,): return dict.itervalues else: return dict.values getValues = getDictValuesFoo() def distinct(iterable, keySelector = (lambda x: x)): lookup = {} for item in iterable: key = keySelector(item) if key not in lookup: lookup[key] = item return getValues(lookup) I was surprised to learn that getValues CANNOT be called as if it were a member of dict. I figured it was more efficient to determine what getValues was once rather than every time it was needed. First, how can I make the method getValues "private" _and_ so it only gets evaluated once? Secondly, will the body of the distinct method be evaluated immediately? How can I delay building the dict until the first value is requested? I noticed that hashing is a lot different in Python than it is in .NET languages. .NET supports custom "equality comparers" that can override a type's Equals and GetHashCode functions. This is nice when you can't change the class you are hashing. That is why I am using a key selector in my code, here. Is there a better way of overriding the default hashing of a type without actually modifying its definition? I figured a requesting a key was the easiest way. From tjreedy at udel.edu Tue Aug 30 23:33:37 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Aug 2011 23:33:37 -0400 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> Message-ID: On 8/30/2011 9:43 PM, Travis Parks wrote: > I am writing a simple algorithms library that I want to work for both > Python 2.7 and 3.x. I am writing some functions like distinct, which > work with dictionaries under the hood. The problem I ran into is that > I am calling itervalues or values depending on which version of the > language I am working in. Here is the code I wrote to overcome it: > > import sys > def getDictValuesFoo(): > if sys.version_info< (3,): > return dict.itervalues > else: > return dict.values One alternative is to use itervalues and have 2to3 translate for you. -- Terry Jan Reedy From aww.dev at googlemail.com Tue Aug 30 23:39:33 2011 From: aww.dev at googlemail.com (Andreas) Date: Wed, 31 Aug 2011 05:39:33 +0200 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: <4E5D5AD0.9070408@mrabarnett.plus.com> References: <4E5D5AD0.9070408@mrabarnett.plus.com> Message-ID: Am 30.08.2011 23:49, schrieb MRAB: > The key phrase is "argument tuple". The arguments passed to a Python > call are always a tuple, not PyFloat_Object. > > You can build a tuple from the PyFloat_Object using: > > Py_BuildValue("(O)", float_object) > > The "(O)" says to build a tuple ("(...)") containing a single object > ("O"). Thank you very much! That solved my problem. Here the full working example: static double doubleValue = 1314761451; PyObject *floatObj = NULL; PyObject *timeTuple = NULL; PyObject *dateTime = NULL; floatObj = PyFloat_FromDouble(doubleValue); timeTuple = Py_BuildValue("(O)", floatObj); dateTime = PyDateTime_FromTimestamp(timeTuple); From adam.jorgensen.za at gmail.com Wed Aug 31 00:53:26 2011 From: adam.jorgensen.za at gmail.com (Adam Jorgensen) Date: Wed, 31 Aug 2011 06:53:26 +0200 Subject: Python IDE/Eclipse In-Reply-To: References: Message-ID: I recommend PyCharm. Best Python IDE ever :-) If you can't afford to pay for it in the long run, then PyDev is the next best bet. I would recommend downloading the most minimal Eclipse you can get (Usually the Eclipse RCP Runtime) and install the necessary plugins as you go. This prevents you from falling into the overloaded eclipse problem as quickly. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 31 01:37:14 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 30 Aug 2011 22:37:14 -0700 Subject: Help parsing a text file References: Message-ID: William Gill wrote: > >My initial passes into Python have been very unfocused (a scatter gun of >too many possible directions, yielding very messy results), so I'm >asking for some suggestions, or algorithms (possibly even examples)that >may help me focus. > >I'm not asking anyone to write my code, just to nudge me toward a more >disciplined approach to a common task, and I promise to put in the >effort to understand the underlying fundamentals. Python includes "sgmllib", which was designed to parse SGML-based files, including both neat XML and slimy HTML, and "htmllib", which derives from it. I have used "htmllib" to parse HTML files where the tags were not properly closed. Perhaps you could start from "htmllib" and modify it to handle the quirks in your particular format. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From arnodel at gmail.com Wed Aug 31 02:35:45 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 31 Aug 2011 07:35:45 +0100 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On 30 August 2011 22:48, Rob Williscroft wrote: > Arnaud Delobelle wrote in > news:CAJ6cK1YVi3NQgdZOUdhAESf133pUkdazM1PkSP=p6xFaYVOHYA at mail.gmail.com in > gmane.comp.python.general: > >> On 30 August 2011 13:31, Jack Trades wrote: >>> >>> >>> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >>> >>>> >>>> > That's brilliant and works flawlessly. ??Thank you very much! >>>> >>>> If an impementation (as you say up thread) can populate globals >>>> or locals with whatever they want, then how do you know that last >>>> item added was the function definition the user supplied ? > >> That's not an issue. The last statement that is executed will be the >> "def" statement. > > You don't know that, an implementation may for example set __bultins__ > to None, prior to returning, its not an unreasonable thing to do and > the docs don't say they can't. I haven't studied the docs but I'm certain that such an implementation would break a lot of code. -- Arnaud From paul at subsignal.org Wed Aug 31 04:52:45 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Wed, 31 Aug 2011 10:52:45 +0200 Subject: Installing WebDAV server In-Reply-To: <9c4trjFcfmU1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> Message-ID: Hi, Am 30.08.2011 22:00, schrieb Fokke Nauta: > Hi all, > > I am completely new to Python, but I'm confronted with a problem I can't > solve. Welcome to python. > This is my question: [snip] > I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. Now > I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and > PyXML-0.8.4. In the PyWebDAV README it says: > > Installation and setup of server can be as easy as follows: > > $ easy_install PyWebDAV > $ davserver -D /tmp -n -J > > But of course it doesn't work like that. When I start up Python GUI I see > the ">>>" prompt instead of the "$" prompt. But where do I place the two > directories? And there is no easy_install script in the PyXML-0.8.4 > directory, only a setup.py and ez_setup.py script. I guess the latter is the > one to use. But how? You dont install from "Python GUI", use normal cmd, navigate to the folder you downloaded PyXML and PyWebDAV and run "python setup.py install" (python.exe has to be in your PATH). Then you have to find the startup-script "davserver". Find your python installation directory and look into /Tools/Scripts, in my computer this is E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the site-packages folder i.e. E:\python27\Lib/site-packages. You might have to look for "davserver" there... hth Paul From fnautaNO at SPAMsolfon.nl Wed Aug 31 05:27:36 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 11:27:36 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de> Message-ID: <9c6d4cFa54U1@mid.individual.net> "Thomas 'PointedEars' Lahn" wrote in message news:4761603.ypaU67uLZW at PointedEars.de... > Fokke Nauta wrote: > >> "Thomas 'PointedEars' Lahn" wrote in message >> news:6545843.yvFAXZvWTv at PointedEars.de... > > It's attribution _line_, not attribution novel. Your quotes are hardly > legible, too ? > >>> Fokke Nauta wrote: >>>> I'm running a PC with XP Pro32, [.] >>>> [.] In the PyWebDAV README it says: >>>> >>>> Installation and setup of server can be as easy as follows: >>>> >>>> $ easy_install PyWebDAV >>>> $ davserver -D /tmp -n -J >>>> >>>> But of course it doesn't work like that. When I start up Python GUI >>> That is really not a *G*raphical User Interface, but the (text-based) >>> Python shell. >> >> Yes, I noticed. But the application has the name of Python GUI. > > ACK. Admittedly I cannot remember having used Python on Windows (XP) > except > via Cygwin. > >>>> I see the ">>>" prompt instead of the "$" prompt. >>> "Doctor, my arm hurts when I move it." - "Don't move it, then." >> >> I don't see the point here ... > > Do not run `python' or the "Python GUI", then. > >>> The Python shell executes Python code. The above obviously is not >>> Python >>> code, but *system* shell commands. So let the *system* command shell >>> execute them (as indicated by the `$' prompt, which is customary for a >>> sh-based UNIX/Linux shell prompt). >> >> I know. I worked with SCO Unix and various sorts of Linux. >> But never with Python, so I hadn't got a clue about the prompt. > > Come on, with that experience you see a `$' and those commands and don't > realize it is (ba)sh? Ofcourse I realized it was Unix/Linux. I already could tell that as the packages I downloaded were tar.gz files. So I unpacked them and expected to run a Python installer script from the Python command line. Hence my question "How do I do that", but perhaps I did not make myself clear enough. Tried to run the Python installer script from the DOS command line but that resulted in an error. As I have Cygwin running as well, I could try to install it there instead of in Windows. >>> Since you use Windows XP, type `cmd' to get the command shell (if you >>> knew MS-DOS, which I doubt, you are at home now). >> >> I know MSDOS. I even worked with CP/M > > Good for you. > >>> However, you appear to have found the *UNIX/Linux* README (and the >>> corresponding version?) of that server: the second command is usually >>> how >>> you would run a program as daemon on Unices (run through an init >>> script), >>> while on Windows NT (like XP) you would have a setup program install a >>> service for you (maybe to execute that command when the service is >>> started). Look for the Windows version. >> >> There is no other Windows version except the packages I mentioned, >> PyWebDAV and PyXML. The only Windows thing I got was the Python >> interpreter itself. > > Has it not occurred to you to STFW for "easy_install" first? What do you mean by STFW? I wasn't aware that easy_install was a utility. Downloaded and installed the Windows version and run easy_install pywebdav. It downloaded something, installed something and finished something. But, once again, don't know how to proceed. Otherwise I'll give it a try under Cygwin. >>>> And there is no easy_install script in the PyXML-0.8.4 >>>> directory, only a setup.py and ez_setup.py script. I guess the latter >>>> is >>>> the one to use. But how? >>> RTFM. >> >> Which fucking manual? > > That of the server, on Windows-related information. Or that of > easy_install. Or Python. Whichever comes first. It's my own server and I didn't write a manual for it. In the manual of Easy_install it says how to install packaged etc and I did sucessfully. There is no furter information as how to proceed. That's why I posted my question here. >>>> How do I proceed next? >>> Look for the Windows version. If there is none, get easy_install and >>> use >>> it as described. I did and it worked. What's next? Fokke From martin at v.loewis.de Wed Aug 31 05:55:39 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 31 Aug 2011 11:55:39 +0200 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> Message-ID: <4E5E051B.8060002@v.loewis.de> Am 31.08.2011 03:43, schrieb Travis Parks: > I am writing a simple algorithms library that I want to work for both > Python 2.7 and 3.x. I am writing some functions like distinct, which > work with dictionaries under the hood. The problem I ran into is that > I am calling itervalues or values depending on which version of the > language I am working in. Here is the code I wrote to overcome it: > > import sys > def getDictValuesFoo(): > if sys.version_info < (3,): > return dict.itervalues > else: > return dict.values > > getValues = getDictValuesFoo() > > def distinct(iterable, keySelector = (lambda x: x)): > lookup = {} > for item in iterable: > key = keySelector(item) > if key not in lookup: > lookup[key] = item > return getValues(lookup) > > I was surprised to learn that getValues CANNOT be called as if it were > a member of dict. I figured it was more efficient to determine what > getValues was once rather than every time it was needed. > > First, how can I make the method getValues "private" _and_ so it only > gets evaluated once? Not sure what "private" means here. Having the logic selected only once goes like this if sys.version_info < (3,): def getDictValues(dict): return dict.itervalues() else: def getDictValues(dict): return dict.values() > Secondly, will the body f the distinct method be > evaluated immediately? Yes. > How can I delay building the dict until the first value is requested? Make it a generator: def distinct(iterable, keySelector = (lambda x: x)): lookup = {} for item in iterable: key = keySelector(item) if key not in lookup: lookup[key] = item for v in getValues(lookup): yield v This delays *building* the dictionary until the *first* value is requested. I.e. it completes building the dictionary before the first value is returned. If you also want to interleave iteration over iterable with fetching distinct values, write it like that: def distinct(iterable, keySelector = (lambda x: x)): seen = {} for item in iterable: key = keySelector(item) if key not in seen: yield item seen[key] = item > I noticed that hashing is a lot different in Python than it is in .NET > languages. .NET supports custom "equality comparers" that can override > a type's Equals and GetHashCode functions. This is nice when you can't > change the class you are hashing. That is why I am using a key > selector in my code, here. Is there a better way of overriding the > default hashing of a type without actually modifying its definition? I > figured a requesting a key was the easiest way. You could provide a Key class that takes a hash function and a value function: class Key: def __init__(self, value, hash, eq): self.value, self.hash, self.eq = value, hash, eq def __hash__(self): return self.hash(self.value) def __eq__(self, other_key): return self.eq(self.value, other_key.value) This class would then be used instead of your keySelector. With that, you could change the dictionary to a set. Actually, you could already do so in the second generator version: def distinct(iterable, keySelector = (lambda x: x)): seen = set() for item in iterable: key = keySelector(item) if key not in seen: yield item seen.add(key) # item is not needed anymore HTH, Martin From yasar11732 at gmail.com Wed Aug 31 07:43:50 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 14:43:50 +0300 Subject: Subclassing str object Message-ID: H?, I originally posted my question to here: http://stackoverflow.com/q/7255655/886669 Could you people please look at it and enlighten me a little bit? I would appreciate an answer either from here or at stackoverflow. Thanks in advance. -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Wed Aug 31 07:48:42 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 31 Aug 2011 13:48:42 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6d4cFa54U1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de> <9c6d4cFa54U1@mid.individual.net> Message-ID: <4E5E1F9A.6010602@shopzeus.com> > What do you mean by STFW? Search The Fucking Web ? > I wasn't aware that easy_install was a utility. Downloaded and installed the > Windows version and run easy_install pywebdav. > It downloaded something, installed something and finished something. Then it's installed! > But, once again, don't know how to proceed. Is that so hard? I have never used pywebdav but the first page I hit through Google search is: http://code.google.com/p/pywebdav/ Where it says: > Installation and setup of server can be as easy as follows: > > $ easy_installPyWebDAV > $ davserver-D/tmp-n-J > Starting upPyWebDAV server(version0.9.2-dev) > >> ATTENTION: Authentication disabled! > >> Serving datafrom /tmp > >> Listening on localhost(8008) So you successfully ran easy_install. Then I guess you will have to look for a program named "davserver" and start it up. I suspect that searching for "davserver.*" under your site-packages dir or Python installation dir will do. L From chris at simplistix.co.uk Wed Aug 31 07:57:04 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Aug 2011 12:57:04 +0100 Subject: argparse: showing full help for subparsers Message-ID: <4E5E2190.6090006@simplistix.co.uk> Hi All, If I have subparsers set up and do: myscript.py --help I get the summary for each of the top-level commands, but to get the help for each sub-command I have to do: myscript.py subcommand --help Is there any way I can get "myscript.py --help" to show the help hierarchically, including all options for all subcommands? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From fnautaNO at SPAMsolfon.nl Wed Aug 31 08:18:00 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 14:18:00 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> Message-ID: <9c6n4oFsnbU1@mid.individual.net> "Paul K?lle" wrote in message news:mailman.595.1314780791.27778.python-list at python.org... > Hi, > > Am 30.08.2011 22:00, schrieb Fokke Nauta: >> Hi all, >> >> I am completely new to Python, but I'm confronted with a problem I can't >> solve. > Welcome to python. > >> This is my question: > [snip] > >> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >> Now >> I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and >> PyXML-0.8.4. In the PyWebDAV README it says: >> >> Installation and setup of server can be as easy as follows: >> >> $ easy_install PyWebDAV >> $ davserver -D /tmp -n -J >> >> But of course it doesn't work like that. When I start up Python GUI I see >> the ">>>" prompt instead of the "$" prompt. But where do I place the two >> directories? And there is no easy_install script in the PyXML-0.8.4 >> directory, only a setup.py and ez_setup.py script. I guess the latter is >> the >> one to use. But how? > You dont install from "Python GUI", use normal cmd, navigate to the folder > you downloaded PyXML and PyWebDAV and run "python setup.py install" > (python.exe has to be in your PATH). Then you have to find the > startup-script "davserver". Find your python installation directory and > look into /Tools/Scripts, in my computer this is > E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the > site-packages folder i.e. E:\python27\Lib/site-packages. You might have to > look for "davserver" there... > Thanks, Paul. I ran "python setup.py install" in both the PyXML and PyWebDAV directories. A lot of things happened and are added into those directories and I guess it will be OK. Next step, the startup-script "davserver". There is no script as such, also not in \python27\tools\scripts. I found 2 similar scripts: 1. server.py in D:\Python27\WebDAV\PyWebDAV\DAVServer 2. WebDAVServer.py in D:\Python27\WebDAV\PyWebDAV\DAV Which one is the one to use? I also configured config.ini in D:\Python27\WebDAV\PyWebDAV\DAVServer In this file it says: "# Auth Database Table, Must exists in database prior to firstrun dbtable=webDav # Create User Database Table and Insert system user" I created in MySQL a database called webDav. I can create a table called User, but how many fields? With regards, Fokke From steve+comp.lang.python at pearwood.info Wed Aug 31 08:33:15 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 31 Aug 2011 22:33:15 +1000 Subject: PC locks up with list operations Message-ID: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 script that tries to create a list that is insanely too big. In the first case, I (stupidly) did something like: mylist = [0]*12345678901234 After leaving the machine for THREE DAYS (!!!) I eventually was able to get to a console and kill the Python process. Amazingly, it never raised MemoryError in that time. The second time was a little less stupid, but not much: mylist = [] for x in itertools.combinations_with_replacement(some_big_list, 20): mylist.append(func(x)) After three hours, the desktop is still locked up. I'm waiting to see what happens in the morning before rebooting. Apart from "Then don't do that!", is there anything I can do to prevent this sort of thing in the future? Like instruct Python not to request more memory than my PC has? I am using Linux desktops; both incidents were with Python 2.5. Do newer versions of Python respond to this sort of situation more gracefully? -- Steven From fnautaNO at SPAMsolfon.nl Wed Aug 31 08:35:26 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 14:35:26 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> Message-ID: <9c6o4eF5h7U1@mid.individual.net> "Laszlo Nagy" wrote in message news:mailman.597.1314791334.27778.python-list at python.org... > >> What do you mean by STFW? > Search The Fucking Web ? OK, the modern version of RTFM. >> I wasn't aware that easy_install was a utility. Downloaded and installed >> the >> Windows version and run easy_install pywebdav. >> It downloaded something, installed something and finished something. > Then it's installed! >> But, once again, don't know how to proceed. > Is that so hard? I have never used pywebdav but the first page I hit > through Google search is: > > http://code.google.com/p/pywebdav/ I've been there. > Where it says: > >> Installation and setup of server can be as easy as follows: >> >> $ easy_installPyWebDAV >> $ davserver-D/tmp-n-J >> Starting upPyWebDAV server(version0.9.2-dev) >> >> ATTENTION: Authentication disabled! >> >> Serving datafrom /tmp >> >> Listening on localhost(8008) Yes, but that's Unix/Linux again. But I'm in Windows, without experience with Python. > So you successfully ran easy_install. Then I guess you will have to look > for a program named "davserver" and start it up. I suspect that searching > for "davserver.*" under your site-packages dir or Python installation dir > will do. > Fokke From chris at simplistix.co.uk Wed Aug 31 08:40:43 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Aug 2011 13:40:43 +0100 Subject: PC locks up with list operations In-Reply-To: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4E5E2BCB.5090903@simplistix.co.uk> On 31/08/2011 13:33, Steven D'Aprano wrote: > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? Ironically, Windows does better here and dumps you out with a MemoryError before slowly recovering. Linux seems to fair badly when programs use more memory than physically available. Perhaps there's some per-process thing that can be used to limit things on Linux? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve+comp.lang.python at pearwood.info Wed Aug 31 08:47:59 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 31 Aug 2011 22:47:59 +1000 Subject: PC locks up with list operations References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> Chris Withers wrote: > On 31/08/2011 13:33, Steven D'Aprano wrote: >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a > MemoryError before slowly recovering. > > Linux seems to fair badly when programs use more memory than physically > available. Perhaps there's some per-process thing that can be used to > limit things on Linux? As far as I know, ulimit ("user limit") won't help. It can limit the amount of RAM available to a process, but that just makes the process start using virtual memory more quickly. It can also limit the amount of virtual memory used by the shell, but not of other processes. In other words, Linux will try really, really, really hard to give you the 84 gigabytes you've asked for on a 2 GB system, even if it means DOSing your system for a month. Of course, I would be very happy to learn I'm wrong. -- Steven From benjamin.kaplan at case.edu Wed Aug 31 08:49:24 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 31 Aug 2011 08:49:24 -0400 Subject: PC locks up with list operations In-Reply-To: <4E5E2BCB.5090903@simplistix.co.uk> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4E5E2BCB.5090903@simplistix.co.uk> Message-ID: On Wed, Aug 31, 2011 at 8:40 AM, Chris Withers wrote: > > On 31/08/2011 13:33, Steven D'Aprano wrote: >> >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a MemoryError before slowly recovering. > > Linux seems to fair badly when programs use more memory than physically available. Perhaps there's some per-process thing that can be used to limit things on Linux? > > cheers, > > Chris > > -- 32-bit or 64-bit Python? A 32-bit program will crash once memory hits 2GB. A 64-bit program will just keep consuming RAM until your computer starts thrashing. The problem isn't your program using more RAM than you have, just more RAM than you have free. Last time I faced a situation like this, I just decided it was better to stick to the 32-bit program and let it crash if it got too big. > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ?- http://www.simplistix.co.uk > -- > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Wed Aug 31 08:56:07 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Aug 2011 14:56:07 +0200 Subject: PC locks up with list operations References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345678901234 > > After leaving the machine for THREE DAYS (!!!) I eventually was able to > get to a console and kill the Python process. Amazingly, it never raised > MemoryError in that time. > > The second time was a little less stupid, but not much: > > mylist = [] > for x in itertools.combinations_with_replacement(some_big_list, 20): > mylist.append(func(x)) > > After three hours, the desktop is still locked up. I'm waiting to see what > happens in the morning before rebooting. > > Apart from "Then don't do that!", is there anything I can do to prevent > this sort of thing in the future? Like instruct Python not to request more > memory than my PC has? > > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? If you are starting these scripts from the shell, how about ulimit? $ ulimit -v 40000 $ python -c'print range(10**5)[-1]' 99999 $ python -c'print range(10**6)[-1]' Traceback (most recent call last): File "", line 1, in MemoryError $ From king6cong at gmail.com Wed Aug 31 09:35:11 2011 From: king6cong at gmail.com (king6cong at gmail.com) Date: Wed, 31 Aug 2011 21:35:11 +0800 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? Message-ID: hi, This is a question not specific to Python,but its related somehow,and I believe I can get some help from your fellow:) I am doing my work on a server service program on Linux that processes the packages sent to the socket it listens.Their is already a old such service listening on the port doing its job,and I can't stop the old server service, and I need to get the packages sent to the old server and send them to my new server service to make sure it works well .How can I get the package and resent them to my new service? Is there such a tool or is there some functionality that tools such as tcpdump already provides? Thanks:) -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Wed Aug 31 09:36:44 2011 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 31 Aug 2011 15:36:44 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6o4eF5h7U1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> <9c6o4eF5h7U1@mid.individual.net> Message-ID: <4E5E38EC.4070303@shopzeus.com> >> Where it says: >> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_installPyWebDAV >>> $ davserver-D/tmp-n-J >>> Starting upPyWebDAV server(version0.9.2-dev) >>>>> ATTENTION: Authentication disabled! >>>>> Serving datafrom /tmp >>>>> Listening on localhost(8008) > Yes, but that's Unix/Linux again. > But I'm in Windows, without experience with Python. Not really... The "easy_install" command is the same on windows. Maybe the command prompt is different, but the command itself is the same. Same is true with the "davserver" command. If you can find a "davserver.exe" or "davserver.py" or "davserver.pyw" file under site-packages or tools/scripts, then that will be the program that you need to start up. No magic. L From spamtrap at arumes.com Wed Aug 31 10:06:43 2011 From: spamtrap at arumes.com (Robert Spanjaard) Date: Wed, 31 Aug 2011 16:06:43 +0200 Subject: PC locks up with list operations In-Reply-To: References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/31/2011 02:40 PM, Chris Withers wrote: > On 31/08/2011 13:33, Steven D'Aprano wrote: >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps you out with a > MemoryError before slowly recovering. I think it's a little premature to make such a statement based on a single user experience. I've used Linux for six years now, and it NEVER locked up, even when a program leaks memory like hell. I can't duplicate the OP's behaviour because my Python (2.6.5, 64 bit) does generate an instant MemoryError (which answers the question, ofcourse), but I've used a VLC version that had a nasty leak. My swap space is on a SSD, and VLC filled it completely in about 10 seconds. But then, VLC got killed automatically, and the system recovered gracefully. On a system with the swapspace on a regular HD, the same will happen, but it'll take more time. And while VLC is filling the swap space, the system does not lock up at all. You can still keep working, and (for example) fire up the process manager and kill VLC yourself. >>> mylist = [0]*12345678901234 Traceback (most recent call last): File "", line 1, in MemoryError -- Regards, Robert http://www.arumes.com From rodrick.brown at gmail.com Wed Aug 31 10:13:02 2011 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 31 Aug 2011 10:13:02 -0400 Subject: PC locks up with list operations In-Reply-To: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <534EAA9D-B7CB-4A1A-A166-BA336EB42004@gmail.com> $ man limits.conf Sent from my iPhone On Aug 31, 2011, at 8:33 AM, Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345678901234 > > After leaving the machine for THREE DAYS (!!!) I eventually was able to get > to a console and kill the Python process. Amazingly, it never raised > MemoryError in that time. > > The second time was a little less stupid, but not much: > > mylist = [] > for x in itertools.combinations_with_replacement(some_big_list, 20): > mylist.append(func(x)) > > After three hours, the desktop is still locked up. I'm waiting to see what > happens in the morning before rebooting. > > Apart from "Then don't do that!", is there anything I can do to prevent this > sort of thing in the future? Like instruct Python not to request more > memory than my PC has? > > I am using Linux desktops; both incidents were with Python 2.5. Do newer > versions of Python respond to this sort of situation more gracefully? > > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list From msarro at gmail.com Wed Aug 31 10:22:20 2011 From: msarro at gmail.com (Matty Sarro) Date: Wed, 31 Aug 2011 10:22:20 -0400 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: Its possible using TCPDUMP and wireshark. however its a bit of a manual process (open the pcap in wireshark, select the correct tcp stream, and extract the file). I did this to show a vulnerability in how medical images were transmitted in a university hospital once :) Here are some guides, maybe it can serve as a jumping off point? http://packetlife.net/blog/2009/jul/13/quick-packet-capture-data-extraction/ http://wiki.wireshark.org/TCP_Reassembly There are some C# libraries specifically for this: http://www.codeproject.com/KB/IP/TcpRecon.aspx Not sure if anything exists explicitly for python though. -Matty On Wed, Aug 31, 2011 at 9:35 AM, king6cong at gmail.com wrote: > hi, > ? This is a question not specific to Python,but its related somehow,and I > believe I can get some help from your fellow:) > ? I am doing my work on a server service program on Linux that processes the > packages sent to the socket it listens.Their is already a old such service > listening on the port doing its job,and > I can't stop the old server service, and I need to get the packages sent to > the old server and send them to my new server service to make sure it works > well .How can I get the package and resent them to my new service? Is there > such a tool or is there some functionality that tools such as tcpdump > already provides? > Thanks:) > > -- > http://mail.python.org/mailman/listinfo/python-list > > From ian.g.kelly at gmail.com Wed Aug 31 10:25:43 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 08:25:43 -0600 Subject: Returning a value from exec or a better solution In-Reply-To: References: Message-ID: On Wed, Aug 31, 2011 at 12:35 AM, Arnaud Delobelle wrote: >> You don't know that, an implementation may for example set __bultins__ >> to None, prior to returning, its not an unreasonable thing to do and >> the docs don't say they can't. > > I haven't studied the docs but I'm certain that such an implementation > would break a lot of code. For example: a = 42 exec "a += 1729" print(a) ...since print would no longer be available in the global namespace. Cheers, Ian From kgmerk at gmail.com Wed Aug 31 10:34:30 2011 From: kgmerk at gmail.com (merk) Date: Wed, 31 Aug 2011 07:34:30 -0700 (PDT) Subject: Creating python egg including pre-built libraries Message-ID: I have a set of complex libraries that I have wrapped with swig. I would like to create a python egg of the swig generated python files and the pre-built libraries. The libraries have a lot of dependencies and I don't want to force the user to get all the dependencies to try to build the libraries from source. I just want to distribute some python files and the libraries for a given platform. Does anyone have a recipe for doing something like this? Thanks, Karl From tgoodchild at gmail.com Wed Aug 31 10:35:36 2011 From: tgoodchild at gmail.com (T. Goodchild) Date: Wed, 31 Aug 2011 07:35:36 -0700 (PDT) Subject: Why do class methods always need 'self' as the first parameter? Message-ID: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> I?m new to Python, and I love it. The philosophy of the language (and of the community as a whole) is beautiful to me. But one of the things that bugs me is the requirement that all class methods have 'self' as their first parameter. On a gut level, to me this seems to be at odds with Python?s dedication to simplicity. For example, consider Python?s indent-sensitive syntax. Although other languages didn?t use indentation to specify scope, programmers always used indentation anyways. Making indentation took a common practice, made it a rule, and the result was a significantly improved signal-to-noise ratio in the readability of Python code. So why is 'self' necessary on class methods? It seems to me that the most common practice is that class methods *almost always* operate on the instance that called them. It would make more sense to me if this was assumed by default, and for "static" methods (methods that are part of a class, but never associated with a specific instance) to be labelled instead. Just curious about the rationale behind this part of the language. From invalid at invalid.invalid Wed Aug 31 10:36:16 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Aug 2011 14:36:16 +0000 (UTC) Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? References: Message-ID: On 2011-08-31, Matty Sarro wrote: > Its possible using TCPDUMP and wireshark. however its a bit of a > manual process (open the pcap in wireshark, select the correct tcp > stream, and extract the file). Presumably the OP knows the port IP address and port number on which the server is listening, so wouldn't it be simpler to just capture TCP traffic to/from that IP/port? Then you can play it back using tcprewrite, tcpreplay, et al. But, I don't see how that's going to work. The OP seems to want to capture a TCP session and then "replay it" so that the client from the session ends up talking to a different server during the replay. The chances of the new server starting up a connection with the same ACK sequence number is practially nil isn't it? >> ?? This is a question not specific to Python,but its related >> somehow,and I believe I can get some help from your fellow:) ?? I am >> doing my work on a server service program on Linux that processes the >> packages sent to the socket it listens.Their is already a old such >> service listening on the port doing its job,and I can't stop the old >> server service, and I need to get the packages sent to the old server >> and send them to my new server service to make sure it works well >> .How can I get the package and resent them to my new service? Is >> there such a tool or is there some functionality that tools such as >> tcpdump already provides? Thanks:) -- Grant Edwards grant.b.edwards Yow! ... this must be what at it's like to be a COLLEGE gmail.com GRADUATE!! From fnautaNO at SPAMsolfon.nl Wed Aug 31 10:37:00 2011 From: fnautaNO at SPAMsolfon.nl (Fokke Nauta) Date: Wed, 31 Aug 2011 16:37:00 +0200 Subject: Installing WebDAV server References: <9c4trjFcfmU1@mid.individual.net> <6545843.yvFAXZvWTv@PointedEars.de> <9c528rFi5aU1@mid.individual.net> <4761603.ypaU67uLZW@PointedEars.de><9c6d4cFa54U1@mid.individual.net> <9c6o4eF5h7U1@mid.individual.net> Message-ID: <9c6v8dF1ngU1@mid.individual.net> "Laszlo Nagy" wrote in message news:mailman.603.1314797809.27778.python-list at python.org... > >>> Where it says: >>> >>>> Installation and setup of server can be as easy as follows: >>>> >>>> $ easy_installPyWebDAV >>>> $ davserver-D/tmp-n-J >>>> Starting upPyWebDAV server(version0.9.2-dev) >>>>>> ATTENTION: Authentication disabled! >>>>>> Serving datafrom /tmp >>>>>> Listening on localhost(8008) >> Yes, but that's Unix/Linux again. >> But I'm in Windows, without experience with Python. > Not really... The "easy_install" command is the same on windows. Maybe the > command prompt is different, but the command itself is the same. Same is > true with the "davserver" command. If you can find a "davserver.exe" or > "davserver.py" or "davserver.pyw" file under site-packages or > tools/scripts, then that will be the program that you need to start up. No > magic. > Actually, I installed easy_install setuptools for Windows (setuptools-0.6c11.win32-py2.7.exe). Running easy_install generated an error message: "Setuptools version 0.6c9 or greater has been installed. (Run "ez_setup.py -U setuptools" to reinstall or upgrade.)" I did, quite something happened but the same error message came back when retrying. So, I installed it another way, indicated by Paul K?lle: "navigate to the folder you downloaded PyXML and PyWebDAV and run "python setup.py install" (python.exe has to be in your PATH). " That worked fine, but: There is no davserver script or executable. Please read my response to Paul K?lle. Fokke From emile at fenx.com Wed Aug 31 10:54:20 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 07:54:20 -0700 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: On 8/31/2011 6:35 AM king6cong at gmail.com said... > hi, > This is a question not specific to Python,but its related somehow,and > I believe I can get some help from your fellow:) > I am doing my work on a server service program on Linux that > processes the packages sent to the socket it listens.Their is already a > old such service listening on the port doing its job,and > I can't stop the old server service, and I need to get the packages sent > to the old server and send them to my new server service to make sure it > works well .How can I get the package and resent them to my new service? > Is there such a tool or is there some functionality that tools such as > tcpdump already provides? I recently set up a standby spare fax server on a network that I also needed to test, and was able to tee the source transmissions to both systems. That may be an option, particularly as it sounds like you've written a consumer of info and are not replying and interacting with the source. Emile From gordon at panix.com Wed Aug 31 10:54:25 2011 From: gordon at panix.com (John Gordon) Date: Wed, 31 Aug 2011 14:54:25 +0000 (UTC) Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: In <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> "T. Goodchild" writes: > So why is 'self' necessary on class methods? It seems to me that the > most common practice is that class methods *almost always* operate on > the instance that called them. It would make more sense to me if this > was assumed by default, and for "static" methods (methods that are > part of a class, but never associated with a specific instance) to be > labelled instead. > Just curious about the rationale behind this part of the language. How would a method access instance variables without 'self'? They probably could have made 'self' a magical attribute that just appears out of thin air instead of being passed as an argument, like 'this' in C++. But would that really provide any benefit? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From emile at fenx.com Wed Aug 31 11:01:01 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 08:01:01 -0700 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: On 8/31/2011 7:35 AM T. Goodchild said... > Just curious about the rationale behind this part of the language. http://docs.python.org/faq/design.html From neilc at norwich.edu Wed Aug 31 11:05:41 2011 From: neilc at norwich.edu (Neil Cerutti) Date: 31 Aug 2011 15:05:41 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <9c70u5FckrU2@mid.individual.net> On 2011-08-31, T. Goodchild wrote: > I?m new to Python, and I love it. The philosophy of the > language (and of the community as a whole) is beautiful to me. > > But one of the things that bugs me is the requirement that all > class methods have 'self' as their first parameter. On a gut > level, to me this seems to be at odds with Python?s dedication > to simplicity. Think it through carefully, and you'll probably agree with Python's design. But not necessarily. In any case, this is a very common complaint, so check out the Python FAQ. http://docs.python.org/faq/design.html#why-self -- Neil Cerutti "A politician is an arse upon which everyone has sat except a man." e. e. cummings From javier.collado at gmail.com Wed Aug 31 11:10:45 2011 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 31 Aug 2011 17:10:45 +0200 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: Hello, 2011/8/31 T. Goodchild : > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter. ?On a gut level, to me > this seems to be at odds with Python?s dedication to simplicity. I think the answer to this question is part of the zen of python: <> http://www.python.org/dev/peps/pep-0020/ Regards, Javier From king6cong at gmail.com Wed Aug 31 11:37:23 2011 From: king6cong at gmail.com (king6cong at gmail.com) Date: Wed, 31 Aug 2011 23:37:23 +0800 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: In fact,UDP is enough for me,I heared that tcpdump and netcat can store and resend the udp packages to get the replay effect,but I don't know how, or is there some better way? I am working on a Linux server and only some basic terminal tools are available :) 2011/8/31 Emile van Sebille > On 8/31/2011 6:35 AM king6cong at gmail.com said... > > hi, >> This is a question not specific to Python,but its related somehow,and >> I believe I can get some help from your fellow:) >> I am doing my work on a server service program on Linux that >> processes the packages sent to the socket it listens.Their is already a >> old such service listening on the port doing its job,and >> I can't stop the old server service, and I need to get the packages sent >> to the old server and send them to my new server service to make sure it >> works well .How can I get the package and resent them to my new service? >> Is there such a tool or is there some functionality that tools such as >> tcpdump already provides? >> > > I recently set up a standby spare fax server on a network that I also > needed to test, and was able to tee the source transmissions to both > systems. That may be an option, particularly as it sounds like you've > written a consumer of info and are not replying and interacting with the > source. > > Emile > > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 31 11:41:27 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 01:41:27 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> T. Goodchild wrote: > So why is 'self' necessary on class methods? I assume you are talking about the declaration in the method signature: def method(self, args): ... rather than why methods have to be called using self.method. If not, there's already a FAQ for that second question: http://docs.python.org/faq/design.html#why-self > It seems to me that the > most common practice is that class methods *almost always* operate on > the instance that called them. By the way, what you're calling "class methods" are actually *instance* methods, because they receive the instance "self" as the first parameter. Python does have class methods, which receive the class, not the instance, as the first parameter. These are usually written something like this: class K(object): @classmethod def spam(cls, args): print cls # always prints "class K", never the instance Just like self, the name cls is a convention only. Class methods are usually used for alternate constructors. There are also static methods, which don't receive any special first argument, plus any other sort of method you can invent, by creating descriptors... but that's getting into fairly advanced territory. They're generally specialised, and don't see much use. As you can see, the terminology is not exactly the same as Java. > It would make more sense to me if this > was assumed by default, ... Well here's the thing. Python methods are wrappers around function objects. The method wrapper knows which instance is involved (because of the descriptor magic which I alluded to above), but the function doesn't and can't. Or at least not without horrible run-time hacks. By treating "self" as an ordinary parameter which needs to be declared, you can do cool stuff like bound and unbound methods: f = "instance".upper # this is a bound method g = str.upper # this is an unbound method The bound method f already has the instance "self" filled in, so to speak. So you can now just call it, and it will work: f() => returns "INSTANCE" The unbound method still needs the instance supplied. This makes it perfect for code like this: for instance in ("hello", "world"): print g(instance) especially if you don't know what g will be until run-time. (E.g. will it be str.upper, str.lower, str.title?) Because methods require that first argument to be given explicitly, unbound methods are practically ordinary functions. They're so like functions that in Python 3, they're done away with altogether, and the unwrapped function object will be returned instead. You can also do nifty stuff like dynamic method injections: >>> def func(a, b): ... print(a, b) ... >>> class K(object): ... pass ... >>> K.func = func # dynamically inject a method >>> instance = K() >>> instance.func(23) (<__main__.K object at 0xb7f0a4cc>, 23) and it all just works. You can even inject a method onto the instance, although it takes a bit more effort to make that work. All this is possible without nasty hacks because self is treated as just an ordinary parameter of functions. Otherwise, the compiler would need to know whether the function was being called from inside a method wrapper or not, and change the function signature appropriately, and that just gets too ugly and messy for words. So for the cost of having to declare self as an argument, we get: * instant visual recognition of what's intended as a method ("the first argument is called self") and what isn't * a nicely consistent treatment of function signatures at all times * clean semantics for the local variable namespace * the same mechanism (with minor adjustments) can be used for class and static methods * bound and unbound methods semantics plus as a bonus, plenty of ongoing arguments about whether or not having to explicitly list "self" as a parameter is a good thing or not, thus keeping people busy arguing on mailing lists instead of coding -- Steven From k.sahithi2862 at gmail.com Wed Aug 31 11:41:57 2011 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 31 Aug 2011 08:41:57 -0700 (PDT) Subject: HOT ACTRESS PHOTOS AND VIDEOS Message-ID: FOR GOOD JOBS SITES TO YOU http://goodjobssites.blogspot.com/ FOR HOT PHOTO&VIDEOS HOT SOUTH ACTRESS IN DIFFERENT DRESSES http://southactresstou.blogspot.com/2011/08/south-actress.html KATRINA KAIF RARE PHOTOS http://southactresstou.blogspot.com/2011/07/katrina-kaif-wallpapers.html DOOKUDU LATEST MOVIE STILLS http://southactresstou.blogspot.com/2011/08/dookudu-movie-stills.html KAJAL LATEST ROMANTIC STILLS http://southactresstou.blogspot.com/2011/07/kajal-agarwal-in-naperu-shiva.html TAMANNA HOT PHOTOS & VIDEOS http://southactresstou.blogspot.com/2011/07/tamanna-wallpapers.html FOR ONLY HOT GUYS SEE THIS TAMANNA HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/tamanna-hot.html PRIYANKA CHOPRA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyanka-chopra-hot.html KAJAL AGARWAL LATEST HOT http://hotactress-kalyani.blogspot.com/2011/08/kajal-agarwal-hot-photos.html LATEST AMISHA PATEL HOT PICS http://hotactress-kalyani.blogspot.com/2011/08/amisha-patel-hot.html TAPSEE DIFFERENT STILLS http://hotactress-kalyani.blogspot.com/2011/08/tapsee-hot.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/priyamani-hot.html FOR FAST UPDATES IN TELUGU FILM INDUSTRY TAMIL ACTRESS HOT PHOTO SHOOT http://allyouwants.blogspot.com/2011/08/tamil-actress.html SOUTH INDIAN HOT ACTRESS PICS http://allyouwants.blogspot.com/2011/08/hot-actress.html DEEPIKA PADUKONE IN DUM MARO DUM MOVIE http://allyouwants.blogspot.com/2011/08/deepika-in-dum-maro-dum.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html PRIYAMANI SPICY PHOTOS IN COW GIRL http://allyouwants.blogspot.com/2011/02/priyamani-spicy-photo-shoot-cow-girl.html KAJAL HOT PHOTOS IN SAREE http://allyouwants.blogspot.com/2011/06/kajal-very-spice-pics.html From ian.g.kelly at gmail.com Wed Aug 31 11:44:47 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 09:44:47 -0600 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: <4E5E051B.8060002@v.loewis.de> References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> Message-ID: On Wed, Aug 31, 2011 at 3:55 AM, Martin v. Loewis wrote: > if sys.version_info < (3,): > def getDictValues(dict): > return dict.itervalues() > else: > def getDictValues(dict): > return dict.values() The extra level of function call indirection is unnecessary here. Better to write it as: if sys.version_info < (3,): getDictValues = dict.itervalues else: getDictValues = dict.values (which is basically what the OP was doing in the first place). >> I noticed that hashing is a lot different in Python than it is in .NET >> languages. .NET supports custom "equality comparers" that can override >> a type's Equals and GetHashCode functions. This is nice when you can't >> change the class you are hashing. That is why I am using a key >> selector in my code, here. Is there a better way of overriding the >> default hashing of a type without actually modifying its definition? I >> figured a requesting a key was the easiest way. > > You could provide a Key class that takes a hash function and a value > function: > > class Key: > ?def __init__(self, value, hash, eq): > ? ?self.value, self.hash, self.eq = value, hash, eq > ?def __hash__(self): > ? ?return self.hash(self.value) > ?def __eq__(self, other_key): > ? ?return self.eq(self.value, other_key.value) > > This class would then be used instead of your keySelector. For added value, you can make it a class factory so you don't have to specify hash and eq over and over: def Key(keyfunc): class Key: def __init__(self, value): self.value = value def __hash__(self): return hash(keyfunc(self.value)) def __eq__(self, other): return keyfunc(self) == keyfunc(other) return Key KeyTypeAlpha = Key(lambda x: x % 7) items = set(KeyTypeAlpha(value) for value in sourceIterable) Cheers, Ian From dalist0 at gmail.com Wed Aug 31 11:51:45 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 08:51:45 -0700 (PDT) Subject: fun with nested loops Message-ID: Dear All, I have some complicated loops of the following form for c in configurations: # loop 1 while nothing_bad_happened: # loop 2 while step1_did_not_work: # loop 3 for substeps in step1 # loop 4a # at this point, we may have to -leave loop 1 -restart loop 4 -skip a step in loop 4 -continue on to loop 4b while step2_did_not_work: # loop 4b for substeps in step2: # at this point, we may have to -leave loop 1 -restart loop 2 -restart loop 4b ... ...many more loops... I don't see any way to reduce these nested loops logically, they describe pretty well what the software has to do. This is a data acquisition application, so on ever line there is a lot of IO that might fail or make subsequent steps useless or require a retry. Now every step could need to break out of any of the enclosing loops. So basically I have to transform every loop to be of the following horror: # general transformation of # "for c in configurations..." # to provide restart, break and continue # callable from any nesting level inside of the loop class loop1_restart(Exception): pass class loop1_break(Exception): pass class loop1_continue(Exception): pass while True: try: for c in configurations: while True: try: # inner loops go here, of course, they would have to get # all the boilerplate added, too while nothing_bad_happened: while step1_did_not_work: if cond1: raise loop1_restart() elif cond3: raise loop1_break() elif cond3: raise loop1_continue() break except loop1_continue: pass break except loop1_restart: pass except loop1_break: break Of course this is extremely tedious and error prone. If Python had named loops (PEP 3136, unfortunately rejected), this would be trivial: In Fortran I can continue (cycle), break (exit) and redo (goto label) arbitrary loops, which results in neat code: 10 loop1: do I=1,3 loop2: do J=1,4 print *,I,J goto 10 cycle loop1 exit loop1 enddo loop2 enddo loop1 My question is, how do I obtain something that implements the following logic: @named_loop(fred) # I wish this would be possible for i in range(10): for j in range(10): break fred # breaks out of outer loop continue fred # continues outer loop redo fred # resets outer loop and restarts with i=0 The best solution would be something along the Proposal D - Explicit iterators in PEP 3136, in this case it would even be possible to peek at the next i or advance/reverse the iterator a few steps. Has anyone an idea on a nice way to write breaks/continues/redos for deeply nested loops? Dan From yasar11732 at gmail.com Wed Aug 31 12:03:11 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 19:03:11 +0300 Subject: Subclassing str object In-Reply-To: References: Message-ID: I made a class like this (I shortened it just to show the point), what do you think about it, do you think it is the python way of subclassing str (or unicode in this case) # -*- coding:utf-8 -*-class kelime(unicode): def __init__(self,sozcuk): self._sozcuk = sozcuk def __getattribute__(self, isim): att = super(kelime, self).__getattribute__(isim) if not callable(att): return att def sonra_cagir(*args, **kwargs): sonuc = att(*args, **kwargs) if isinstance(sonuc, basestring): return kelime(sonuc) return sonuc return sonra_cagir def cogul(self): for harf in reversed(self._sozcuk): if harf in kalin: return kelime(self._sozcuk + u"lar") elif harf in ince: return kelime(self._sozcuk + u"ler") return kelime(self._sozcuk + u"lar") 31 A?ustos 2011 14:43 tarihinde Ya?ar Arabac? yazd?: > H?, > > I originally posted my question to here: > http://stackoverflow.com/q/7255655/886669 Could you people please look at > it and enlighten me a little bit? I would appreciate an answer either from > here or at stackoverflow. Thanks in advance. > > -- > http://yasar.serveblog.net/ > > -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 31 12:06:50 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 02:06:50 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <4e5e5c1b$0$29974$c3e8da3$5496439d@news.astraweb.com> John Gordon wrote: > In <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> "T. > Goodchild" writes: > >> So why is 'self' necessary on class methods? It seems to me that the >> most common practice is that class methods *almost always* operate on >> the instance that called them. It would make more sense to me if this >> was assumed by default, and for "static" methods (methods that are >> part of a class, but never associated with a specific instance) to be >> labelled instead. > >> Just curious about the rationale behind this part of the language. > > How would a method access instance variables without 'self'? If Python had compile time declarations, the compiler could know whether x=1 was referring to a local variable x or an attribute x. The reader might not, but the compiler would :) By the way, although the Python docs are a little inconsistent, the usual term here is "attribute" rather than "instance variable". Attributes need not live on the instance: they can also live on the class, a superclass, or be computed at run-time via at least three different mechanisms I can think of (__getattribute__, __getattr__, properties). Local variables are treated a bit differently from attributes, but broadly speaking, if you need a dot to access something, it's an attribute, if you don't, it's a name binding (or variable). Python even has two different sorts of errors for "variable" lookup failures: NameError (or UnboundLocalError) for un-dotted names, and AttributeError for dotted names. > They probably could have made 'self' a magical attribute that just > appears out of thin air instead of being passed as an argument, like > 'this' in C++. But would that really provide any benefit? Well obviously the C++ people thought so :) The effort to type "self, " in method signatures is pretty low. I don't think it is a problem. But other languages are free to choose differently. Cobra, for example, is explicitly derived from Python in many ways, but it drops the "self" (as well as other changes). http://cobra-language.com/docs/python/ -- Steven From emile at fenx.com Wed Aug 31 12:20:21 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Aug 2011 09:20:21 -0700 Subject: How to save the packages received by a network interface or some port in a file and resend the packages received when needed? In-Reply-To: References: Message-ID: On 8/31/2011 8:37 AM king6cong at gmail.com said... > In fact,UDP is enough for me,I heared that tcpdump and netcat can store > and resend the udp packages to get the replay effect,but I don't know > how, That may be, but I've never tried that. > or is there some better way? I am working on a Linux server and > only some basic terminal tools are available :) If appropriate, I'd try the iptables --tee option. Emile From invalid at invalid.invalid Wed Aug 31 12:20:51 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Aug 2011 16:20:51 +0000 (UTC) Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5c1b$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2011-08-31, Steven D'Aprano wrote: > Well obviously the C++ people thought so :) Well _that's_ certainly a ringing endorsement in the context of designing a language that's easy to understand and use. ;) -- Grant Edwards grant.b.edwards Yow! Where's SANDY DUNCAN? at gmail.com From tjreedy at udel.edu Wed Aug 31 12:30:59 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 12:30:59 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: On 8/31/2011 10:35 AM, T. Goodchild wrote: > But one of the things that bugs me is the requirement that all class > methods have 'self' as their first parameter. On a gut level, to me > this seems to be at odds with Python?s dedication to simplicity. Actually, it is a consequence of Python's dedication to simplicity. A method is simply a function that is an attribute of a class. (This is even clearer in Py 3.) Hence, there is no special syntax for methods. Consider def double(obj): return 2*obj.value class C: def __init__(self, val): self.value = val c = C(3) C.double = double c.doub = double # not c.double as that would mask access to C.double in c.double() below print(double(c), C.double(c), c.double(), c.doub(c)) # 6 6 6 6 -- Terry Jan Reedy From aspineux at gmail.com Wed Aug 31 12:35:45 2011 From: aspineux at gmail.com (aspineux) Date: Wed, 31 Aug 2011 09:35:45 -0700 (PDT) Subject: fun with nested loops References: Message-ID: On Aug 31, 5:51?pm, Daniel wrote: > Dear All, > > I have some complicated loops of the following form > > for c in configurations: # loop 1 > ? ? while nothing_bad_happened: # loop 2 > ? ? ? ? while step1_did_not_work: # loop 3 > ? ? ? ? ? ? for substeps in step1 # loop 4a > ? ? ? ? ? ? ? ? # at this point, we may have to > ? ? ? ? ? ? ? ? -leave loop 1 > ? ? ? ? ? ? ? ? -restart loop 4 > ? ? ? ? ? ? ? ? -skip a step in loop 4 > ? ? ? ? ? ? ? ? -continue on to loop 4b > > ? ? ? ? while step2_did_not_work: # loop 4b > ? ? ? ? ? ? for substeps in step2: > ? ? ? ? ? ? ? ? # at this point, we may have to > ? ? ? ? ? ? ? ? -leave loop 1 > ? ? ? ? ? ? ? ? -restart loop 2 > ? ? ? ? ? ? ? ? -restart loop 4b > ? ? ? ? ? ? ? ? ... > ? ? ? ? ...many more loops... > > I don't see any way to reduce these nested loops logically, they > describe pretty well what the software has to do. > This is a data acquisition application, so on ever line there is > a lot of IO that might fail or make subsequent steps useless or > require a > retry. > > Now every step could need to break out of any of the enclosing loops. > So basically I have to transform every loop to be of the following > horror: > > # general transformation of > # "for c in configurations..." > # to provide restart, break and continue > # callable from any nesting level inside of the loop > > class loop1_restart(Exception): pass > class loop1_break(Exception): pass > class loop1_continue(Exception): pass > > while True: > ? ? try: > ? ? ? ? for c in configurations: > ? ? ? ? ? ? while True: > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? # inner loops go here, of course, they would have > to get > ? ? ? ? ? ? ? ? ? ? # all the boilerplate added, too > ? ? ? ? ? ? ? ? ? ? while nothing_bad_happened: > ? ? ? ? ? ? ? ? ? ? ? ? while step1_did_not_work: > ? ? ? ? ? ? ? ? ? ? ? ? ? ?if cond1: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_restart() > ? ? ? ? ? ? ? ? ? ? ? ? ? ?elif cond3: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_break() > ? ? ? ? ? ? ? ? ? ? ? ? ? ?elif cond3: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise loop1_continue() > > ? ? ? ? ? ? ? ? ? ? break > > ? ? ? ? ? ? ? ? except loop1_continue: > ? ? ? ? ? ? ? ? ? ? pass > ? ? ? ? break > ? ? except loop1_restart: > ? ? ? ? pass > ? ? except loop1_break: > ? ? ? ? break > > Of course this is extremely tedious and error prone. > If Python had named loops (PEP 3136, unfortunately rejected), this > would be trivial: > In Fortran I can continue (cycle), break (exit) and redo (goto label) > arbitrary > loops, which results in neat code: > > 10 loop1: do I=1,3 > ? ? loop2: do J=1,4 > ? ? ? ? print *,I,J > ? ? ? ? goto 10 > ? ? ? ? cycle loop1 > ? ? ? ? exit loop1 > ? ? enddo loop2 > enddo loop1 > > My question is, how do I obtain something that implements the > following logic: > > @named_loop(fred) # I wish this would be possible > for i in range(10): > ? ? for j in range(10): > ? ? ? ? break fred # breaks out of outer loop > ? ? ? ? continue fred # continues outer loop > ? ? ? ? redo fred # resets outer loop and restarts with i=0 > > The best solution would be something along the Proposal D - Explicit > iterators > in PEP 3136, in this case it would even be possible to peek at the > next i or > advance/reverse the iterator a few steps. > > Has anyone an idea on a nice way to write breaks/continues/redos for > deeply > nested loops? Hi Dan, it looks like you have already answered all your questions. one more idea, a kind of named loop: ic=0 op='what to do' while ic > Dan From python at mrabarnett.plus.com Wed Aug 31 12:41:55 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Aug 2011 17:41:55 +0100 Subject: Usage of PyDateTime_FromTimestamp In-Reply-To: References: <4E5D5AD0.9070408@mrabarnett.plus.com> Message-ID: <4E5E6453.60300@mrabarnett.plus.com> On 31/08/2011 04:39, Andreas wrote: > Am 30.08.2011 23:49, schrieb MRAB: > >> The key phrase is "argument tuple". The arguments passed to a Python >> call are always a tuple, not PyFloat_Object. >> >> You can build a tuple from the PyFloat_Object using: >> >> Py_BuildValue("(O)", float_object) >> >> The "(O)" says to build a tuple ("(...)") containing a single object >> ("O"). > Some other points: Py_BuildValue defaults to building a tuple if the format string contains multiple items, eg "OO" means the same as "(OO)". In your case, there is only one, so the (...) is required. The object returned will have a reference count of 1, and any Python object passed to the function will have its reference count incremented. > Thank you very much! That solved my problem. > Here the full working example: > > static double doubleValue = 1314761451; > PyObject *floatObj = NULL; > PyObject *timeTuple = NULL; > PyObject *dateTime = NULL; > > floatObj = PyFloat_FromDouble(doubleValue); > timeTuple = Py_BuildValue("(O)", floatObj); > dateTime = PyDateTime_FromTimestamp(timeTuple); > PyFloat_FromDouble returns an object with a reference count of 1 and Py_BuildValue increments that reference count, so you should probably be decrementing it afterwards, otherwise you'll have a memory leak. The usual rule is that you create it, use it, then 'decref' it. Also, you should be doing some error-checking, seeing if Py_BuildValue, etc, is returning NULL, indicating an error. From jehugaleahsa at gmail.com Wed Aug 31 12:45:28 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 09:45:28 -0700 (PDT) Subject: Closures and Partial Function Application Message-ID: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> I was a little disappointed the other day when I realized that closures were read-only. I like to use closures quite a bit. Can someone explain why this limitation exists? Secondly, since I can cheat by wrapping the thing being closure-ified, how can I write a simple wrapper that has all the same members as the thing (decorator), that then applies them to the underlying thing? I also like partial function application. What is the easiest way of achieving this in Python? Would it look something like this: def foo(x, y): return x + y xFoo = lambda y: foo(10, y) From arnodel at gmail.com Wed Aug 31 12:55:34 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 31 Aug 2011 17:55:34 +0100 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On 31 August 2011 17:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. > > Can someone explain why this limitation exists? Secondly, since I can > cheat by wrapping the thing being closure-ified, how can I write a > simple wrapper that has all the same members as the thing (decorator), > that then applies them to the underlying thing? I don't understand. Can you give an example? > I also like partial function application. What is the easiest way of > achieving this in Python? Would it look something like this: > > def foo(x, y): > ? ?return x + y > > xFoo = lambda y: foo(10, y) from functools import partial foo10 = partial(foo, 10) HTH Arnaud From mperzel at gmail.com Wed Aug 31 12:58:15 2011 From: mperzel at gmail.com (mfperzel) Date: Wed, 31 Aug 2011 09:58:15 -0700 (PDT) Subject: Python Tools for Visual Studio - anyone using it? References: Message-ID: On Aug 30, 1:34?pm, Philip Semanchuk wrote: > Hi all, > I was reminded today (via Slashdot) of Python Tools for Visual Studio which was discussed on this list back in March (http://mail.python.org/pipermail/python-list/2011-March/1267662.html) and has reached version 1.0. Is anyone here using it? Care to share pros & cons? > > Here's the URL for those who haven't heard of it before:http://pytools.codeplex.com/ > > Thanks > Philip I have been using it for a few days now. I really like it. It doesn't have all of the features of other python specific IDEs but the core features are done very well. It feels very complete. It seems to have all the features I need and they feel rock solid. Pros: Seemed very snappy compared to other Python IDEs I have used Debugger is very well done. Price( Free when using the VS 2010 Shell ) **Subjective: The editor just feels really nice. Cons: "Basic" compared to other IDES. By this I mean it doesn't have some of the nice-to-have features like explicit Django support. Have to download and install a 180mb "Shell" version of VS to use it if you don't already have VS installed. Personally I was very surprised at how good this plugin is. It has quickly become my python IDE of choice on Windows( or anywhere else ) From tjreedy at udel.edu Wed Aug 31 13:07:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 13:07:48 -0400 Subject: Subclassing str object In-Reply-To: References: Message-ID: On 8/31/2011 7:43 AM, Ya?ar Arabac? wrote: > H?, > > I originally posted my question to here: > http://stackoverflow.com/q/7255655/886669 Could you people please look > at it and enlighten me a little bit? I would appreciate an answer either > from here or at stackoverflow. I believe two people already gave my answer. If 'a' is bound to a str() object, "a.capitalize() will return a standard, unmodified str, not your custom class, so a.capitalize().mycustommethod() will fail.". If you reject that enlightenment, there is not much more to say. (And if you accept it, I am not sure what you still need.) To put is a different way, if you want to chain together existing string methods and your new methods, you must start with objects of your new subclass and wrap every string method that you want to chain. class mystr(str): ... def capitalize(s): return mystr(str.capitalize(s)) You ended up doing something like this in your edit #3, except you perhaps should not have the __init__ method (depending on what 'sozcuk' is) and you do the wrapping on every call instead of just once and use the generalized signature *arg,**kwds for every method, which will make tracebacks much less informative. -- Terry Jan Reedy From ian.g.kelly at gmail.com Wed Aug 31 13:11:16 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 11:11:16 -0600 Subject: Subclassing str object In-Reply-To: References: Message-ID: 2011/8/31 Ya?ar Arabac? : > I made a class like this (I shortened it just to show the point), what do > you think about it, do you think it is the python way of subclassing str (or > unicode in this case) You don't need the _sozcuk attribute at all here. It's just the same as the value of the unicode object itself. The code could be simplified to: class kelime(unicode): def __getattribute__(self, isim): att = super(kelime, self).__getattribute__(isim) if not callable(att): return att def sonra_cagir(*args, **kwargs): sonuc = att(*args, **kwargs) if isinstance(sonuc, basestring): return kelime(sonuc) return sonuc return sonra_cagir def cogul(self): for harf in reversed(self): if harf in kalin: return kelime(self + u"lar") elif harf in ince: return kelime(self + u"ler") return kelime(self + u"lar") Also, "isinstance(sonuc, basestring)" should probably be "isinstance(sonuc, unicode)". Otherwise you'll break the encode method. If you want "kelime(u'one') + kelime(u'two')" to return a kelime instance, you'll need to override the __add__ special method as well. Likewise for "kelime(u'repeat') * 20" and the __mul__ method. You'll also want to override __getitem__ so that slicing returns a kelime instance as expected. Finally, I gather that the goal of this is not to modify the behavior of the unicode class at all, but just to add custom methods? I would strongly recommend that you not use a subclass for this, and instead just write some functions that take a string to operate on as an argument. Subclassing built-in types tends to be tricky as you can see, and this doesn't seem like a good reason to attempt it. Cheers, Ian From ramit.prasad at jpmorgan.com Wed Aug 31 13:12:48 2011 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 31 Aug 2011 13:12:48 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> Message-ID: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> >def double(obj): return 2*obj.value > >class C: > def __init__(self, val): > self.value = val > >c = C(3) >C.double = double >c.doub = double ># not c.double as that would mask access to C.double in c.double() below >print(double(c), C.double(c), c.double(), c.doub(c)) Sorry if I get some of the following terminology wrong, I get a bit confused on Python terms. I hope the following is still coherent. (Is there a dictionary of Python terminology?) Given the above example I get this >>> print c.double(c) TypeError: double() takes exactly 1 argument (2 given) >>> print c.doub(c) 6 It seems to me that if I add a function to the list of class attributes it will automatically wrap with "self" but adding it to the object directly will not wrap the function as a method. Can somebody explain why? I would have thought that any function added to an object would be a method (unless decorated as a class method). Hmm, or does the decoration just tell Python not to turn an object's function into a method? I.e. Is the decorator basically just the syntactic sugar for doing the above? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From paul at subsignal.org Wed Aug 31 13:14:24 2011 From: paul at subsignal.org (=?ISO-8859-1?Q?Paul_K=F6lle?=) Date: Wed, 31 Aug 2011 19:14:24 +0200 Subject: Installing WebDAV server In-Reply-To: <9c6n4oFsnbU1@mid.individual.net> References: <9c4trjFcfmU1@mid.individual.net> <9c6n4oFsnbU1@mid.individual.net> Message-ID: Hi, answers below... Am 31.08.2011 14:18, schrieb Fokke Nauta: > "Paul K?lle" wrote in message > news:mailman.595.1314780791.27778.python-list at python.org... >> Hi, >> >> Am 30.08.2011 22:00, schrieb Fokke Nauta: >>> Hi all, >>> >>> I am completely new to Python, but I'm confronted with a problem I can't >>> solve. >> Welcome to python. >> >>> This is my question: >> [snip] >> >>> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. >>> Now >>> I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and >>> PyXML-0.8.4. In the PyWebDAV README it says: >>> >>> Installation and setup of server can be as easy as follows: >>> >>> $ easy_install PyWebDAV >>> $ davserver -D /tmp -n -J >>> >>> But of course it doesn't work like that. When I start up Python GUI I see >>> the ">>>" prompt instead of the "$" prompt. But where do I place the two >>> directories? And there is no easy_install script in the PyXML-0.8.4 >>> directory, only a setup.py and ez_setup.py script. I guess the latter is >>> the >>> one to use. But how? >> You dont install from "Python GUI", use normal cmd, navigate to the folder >> you downloaded PyXML and PyWebDAV and run "python setup.py install" >> (python.exe has to be in your PATH). Then you have to find the >> startup-script "davserver". Find your python installation directory and >> look into/Tools/Scripts, in my computer this is >> E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the >> site-packages folder i.e. E:\python27\Lib/site-packages. You might have to >> look for "davserver" there... >> > > Thanks, Paul. > > I ran "python setup.py install" in both the PyXML and PyWebDAV directories. > A lot of things happened and are added into those directories and I guess it > will be OK. > Next step, the startup-script "davserver". There is no script as such, also > not in \python27\tools\scripts. > I found 2 similar scripts: > 1. server.py in D:\Python27\WebDAV\PyWebDAV\DAVServer > 2. WebDAVServer.py in D:\Python27\WebDAV\PyWebDAV\DAV > > Which one is the one to use? Your install locations look odd, but it might work nevertheless. The server is in DAVServer\server.py, you can look at the file and you will see: if __name__ == '__main__': run() at the bottom. This is the "entry point" of a python script if called from the command line. My install looks a bit different but I can start the server as follows: python.exe E:\Python27\Lib\site-packages\pywebdav-0.9.4.1-py2.7.egg\DAVServer\server.py -D c:\home -n WARNING:pywebdav:Authentication disabled! Listening on localhost (8008) > > I also configured config.ini in D:\Python27\WebDAV\PyWebDAV\DAVServer I would use a config file outside the program directory and use the -c or --config switch, run server.py without arguments to see possible startup options. > > In this file it says: > "# Auth Database Table, Must exists in database prior to firstrun > dbtable=webDav > > # Create User Database Table and Insert system user" > > I created in MySQL a database called webDav. > I can create a table called User, but how many fields? Don't know if that's documented somewhere but you can just look at the code in mysqlauth.py in the same directory as server.py. Seems it needs three columns, (User,Pass,can_write<0|1>) but I haven't tried. cheers Paul From clp2 at rebertia.com Wed Aug 31 13:18:57 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 10:18:57 -0700 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. Assuming I'm intuiting your question correctly, then you're incorrect; they are "read/write". You just need a `nonlocal` declaration for the variables in question. See http://www.python.org/dev/peps/pep-3104/ and http://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonlocal for details. Cheers, Chris From eaglebalti at gmail.com Wed Aug 31 13:22:36 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Wed, 31 Aug 2011 10:22:36 -0700 (PDT) Subject: Please visit the following link to watch Cristiano Ronaldo New Pics. Message-ID: Hello Friends. I brought nice, beautiful, amazing and attracive Pics of Cristiano Ronaldo.Please Visit the following link for more detail http://cristianoronaldopics2011.blogspot.com/ From yasar11732 at gmail.com Wed Aug 31 13:49:20 2011 From: yasar11732 at gmail.com (=?ISO-8859-9?Q?Ya=FEar_Arabac=FD?=) Date: Wed, 31 Aug 2011 20:49:20 +0300 Subject: Subclassing str object In-Reply-To: References: Message-ID: @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at all, so I deleted it. My class's addition and multiplication works without overwriting __add__ and __mul__ because, this class uses unicode's __add__ and __mul__ than creates a new kelime instance with return value of those methods in __getattribute__. I didn't get a good grasp on how using basestring there might broke encoding, could you explain a little bit more, or provide a reading material? And, as with the purpose, yes, it is intended to add some methods on unicode. But the bigger purpose is to learn how to work with builtin objects, or more spesifically, immutable ones. Therefore I value much to make this simple example work, and make it work in a python way. @Terry: yes, my *args **kwargs method made tracebacks much less informative. I agree on that. I am still trying to implement a better way. @all: So the thing I wonder, when creating new instance in for example capitalize() method, does str use something like self.__new__() or unicode.__new__()? Because, in latter case, I could override the __new__ method on my class, so that every method would create my class's instance, instead of unicode's 31 A?ustos 2011 20:11 tarihinde Ian Kelly yazd?: > 2011/8/31 Ya?ar Arabac? : > > I made a class like this (I shortened it just to show the point), what do > > you think about it, do you think it is the python way of subclassing str > (or > > unicode in this case) > > You don't need the _sozcuk attribute at all here. It's just the same > as the value of the unicode object itself. The code could be > simplified to: > > class kelime(unicode): > > def __getattribute__(self, isim): > att = super(kelime, self).__getattribute__(isim) > if not callable(att): > return att > def sonra_cagir(*args, **kwargs): > sonuc = att(*args, **kwargs) > if isinstance(sonuc, basestring): > return kelime(sonuc) > return sonuc > return sonra_cagir > > def cogul(self): > for harf in reversed(self): > if harf in kalin: > return kelime(self + u"lar") > elif harf in ince: > return kelime(self + u"ler") > return kelime(self + u"lar") > > Also, "isinstance(sonuc, basestring)" should probably be > "isinstance(sonuc, unicode)". Otherwise you'll break the encode > method. > > If you want "kelime(u'one') + kelime(u'two')" to return a kelime > instance, you'll need to override the __add__ special method as well. > Likewise for "kelime(u'repeat') * 20" and the __mul__ method. You'll > also want to override __getitem__ so that slicing returns a kelime > instance as expected. > > Finally, I gather that the goal of this is not to modify the behavior > of the unicode class at all, but just to add custom methods? I would > strongly recommend that you not use a subclass for this, and instead > just write some functions that take a string to operate on as an > argument. Subclassing built-in types tends to be tricky as you can > see, and this doesn't seem like a good reason to attempt it. > > Cheers, > Ian > -- http://yasar.serveblog.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jehugaleahsa at gmail.com Wed Aug 31 13:51:37 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 10:51:37 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> On Aug 31, 1:18?pm, Chris Rebert wrote: > On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > > I was a little disappointed the other day when I realized that > > closures were read-only. I like to use closures quite a bit. > > Assuming I'm intuiting your question correctly, then you're incorrect; > they are "read/write". You just need a `nonlocal` declaration for the > variables in question. Seehttp://www.python.org/dev/peps/pep-3104/ > andhttp://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonl... > for details. > > Cheers, > Chris > > Cool. So I just need to put "nonlocal" in front of the variable name. From jehugaleahsa at gmail.com Wed Aug 31 14:02:41 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 11:02:41 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: On Aug 31, 1:51?pm, Travis Parks wrote: > On Aug 31, 1:18?pm, Chris Rebert wrote: > > > On Wed, Aug 31, 2011 at 9:45 AM, Travis Parks wrote: > > > I was a little disappointed the other day when I realized that > > > closures were read-only. I like to use closures quite a bit. > > > Assuming I'm intuiting your question correctly, then you're incorrect; > > they are "read/write". You just need a `nonlocal` declaration for the > > variables in question. Seehttp://www.python.org/dev/peps/pep-3104/ > > andhttp://docs.python.org/release/3.1.3/reference/simple_stmts.html#nonl... > > for details. > > > Cheers, > > Chris > > Cool. So I just need to put "nonlocal" in front of the variable name. Am I doing something wrong, here? nonlocal isn't registering. Which version did this get incorporated? From bruno.desthuilliers at gmail.com Wed Aug 31 14:03:49 2011 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 31 Aug 2011 11:03:49 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: <0d66c6c7-fbbb-4030-8d00-9f260f4c0e22@h11g2000vbc.googlegroups.com> On 31 ao?t, 18:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. They are not _strictly_ read only, but Python being first and foremost an OO language, it's usually way simpler to use OO instead of closures when you start needing such features. From rosuav at gmail.com Wed Aug 31 14:13:22 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 04:13:22 +1000 Subject: fun with nested loops In-Reply-To: References: Message-ID: On Thu, Sep 1, 2011 at 1:51 AM, Daniel wrote: > > Has anyone an idea on a nice way to write breaks/continues/redos for > deeply > nested loops? > Do you only ever have one top-level loop that you would be naming? If so, put that loop into a function and use return instead of break. Unfortunately that doesn't work for continue. ChrisA From ian.g.kelly at gmail.com Wed Aug 31 14:18:30 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 12:18:30 -0600 Subject: Closures and Partial Function Application In-Reply-To: References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: On Wed, Aug 31, 2011 at 12:02 PM, Travis Parks wrote: > Am I doing something wrong, here? nonlocal isn't registering. Which > version did this get incorporated? 3.0 From jehugaleahsa at gmail.com Wed Aug 31 14:26:00 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 11:26:00 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <426395c1-f4ec-4ba2-ad3e-8aaa52148c55@z15g2000yqk.googlegroups.com> Message-ID: <84d38b41-5137-401d-b3c3-b6cf44451c73@gz5g2000vbb.googlegroups.com> On Aug 31, 2:18?pm, Ian Kelly wrote: > On Wed, Aug 31, 2011 at 12:02 PM, Travis Parks wrote: > > Am I doing something wrong, here? nonlocal isn't registering. Which > > version did this get incorporated? > > 3.0 Ah, okay. It would be really useful for unit testing. Unfortunately, I want to make the code I am writing compatible with 2.x and 3.x. I will just deal with it until 3.x takes over. Glad to know Guido sees the importance. From clp2 at rebertia.com Wed Aug 31 14:31:21 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 11:31:21 -0700 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Aug 31, 2011 at 10:12 AM, Prasad, Ramit wrote: >>def double(obj): return 2*obj.value >> >>class C: >> ? ? def __init__(self, val): >> ? ? ? ? self.value = val >> >>c = C(3) >>C.double = double >>c.doub = double >># not c.double as that would mask access to C.double in c.double() below >>print(double(c), C.double(c), c.double(), c.doub(c)) > > Sorry if I get some of the following terminology wrong, I get a bit confused on Python terms. I hope the following is still coherent. (Is there a dictionary of Python terminology?) The documentation has a glossary: http://docs.python.org/glossary.html It's not entirely comprehensive though. Cheers, Chris From dalist0 at gmail.com Wed Aug 31 14:40:05 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 11:40:05 -0700 (PDT) Subject: fun with nested loops References: Message-ID: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> > one more idea, a kind of named loop: interesting idea, thanks. > > When it become too complicate, I use state machine:http://en.wikipedia.org/wiki/Finite-state_machine I unsuccessfully played a bit with a FSM, but there is a lot of data that is passed around between the states and a lot of counting (like trying a certain step n times), so the FSM turned out to be even more complex. And I have to keep the code simple for non CS people to run the actual experiment. The loops are kind of self-explanatory, this is exactly how you would specify the experiment, even though I am really hitting a wall at the moment. Maybe I am really missing an obvious solution, because breaking out of nested loops really doesn't seem like anything fancy. Fortran/c/c++/ Ruby/Perl all have that facility, even Java has named loops. From dalist0 at gmail.com Wed Aug 31 15:07:03 2011 From: dalist0 at gmail.com (Daniel) Date: Wed, 31 Aug 2011 12:07:03 -0700 (PDT) Subject: fun with nested loops References: Message-ID: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> > Do you only ever have one top-level loop that you would be naming? If no, unfortunately not. The rough structure is several loops deep, and I need to break/continue/restart many of them. Continue is used more than break, because most of the time that I find some strange value, I'd just _continue_ a few levels up to restart the current measurements. for some configurations while not enough data collected while not in the right state for steps in steps to bring the system to the right state if the system is bad, break out of all loops if it just need to be reset, just redo the steps if it is ok, go to the next while loop while in the right state steps to do some measurements ... From rosuav at gmail.com Wed Aug 31 15:15:42 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 05:15:42 +1000 Subject: fun with nested loops In-Reply-To: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> References: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> Message-ID: On Thu, Sep 1, 2011 at 5:07 AM, Daniel wrote: >> Do you only ever have one top-level loop that you would be naming? If > no, unfortunately not. The rough structure is several loops deep, and > I need to break/continue/restart many of them. > Continue is used more than break, because most of the time that I find > some strange value, I'd just _continue_ a few levels up > to restart the current measurements. > Ah well, was worth a try. Raising exceptions smells wrong for this, but peppering your code with sentinel checks isn't much better. I don't really know what would be a good solution to this... except maybe this, which was proposed a few years ago and which I'd never heard of until Google showed it to me just now: http://entrian.com/goto/ ChrisA From lists at andros.org.uk Wed Aug 31 15:29:27 2011 From: lists at andros.org.uk (Andrew McLean) Date: Wed, 31 Aug 2011 20:29:27 +0100 Subject: Python Tools for Visual Studio - anyone using it? In-Reply-To: References: Message-ID: <4E5E8B97.8050402@andros.org.uk> I understand that Python Tools for Visual Studio doesn't work with VS Express, but does work with the (free) VS 2010 Shell. Does anyone know if you can install VS Express and VS Shell on the same machine? From jehugaleahsa at gmail.com Wed Aug 31 15:33:14 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 12:33:14 -0700 (PDT) Subject: Closures and Partial Function Application References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> <0d66c6c7-fbbb-4030-8d00-9f260f4c0e22@h11g2000vbc.googlegroups.com> Message-ID: On Aug 31, 2:03?pm, "bruno.desthuilli... at gmail.com" wrote: > On 31 ao?t, 18:45, Travis Parks wrote: > > > I was a little disappointed the other day when I realized that > > closures were read-only. I like to use closures quite a bit. > > They are not _strictly_ read only, but Python being first and foremost > an OO language, it's usually way simpler to use OO instead of closures > when you start needing such features. I like to leave OO to large-scale architectures and leave functional paradigms for implementation details. Writing an entire class for wrapping an int seems excessive. Especially if that code is limited to a small scope. I agree, though, that there is a time and a place for everything. From brian.curtin at gmail.com Wed Aug 31 15:33:38 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 31 Aug 2011 14:33:38 -0500 Subject: Python Tools for Visual Studio - anyone using it? In-Reply-To: <4E5E8B97.8050402@andros.org.uk> References: <4E5E8B97.8050402@andros.org.uk> Message-ID: On Wed, Aug 31, 2011 at 14:29, Andrew McLean wrote: > I understand that Python Tools for Visual Studio doesn't work with VS > Express, but does work with the (free) VS 2010 Shell. Does anyone know if > you can install VS Express and VS Shell on the same machine? Yes, because the shell and Express work together. -------------- next part -------------- An HTML attachment was scrubbed... URL: From zdoor at xs4all.nl Wed Aug 31 15:37:11 2011 From: zdoor at xs4all.nl (Alex van der Spek) Date: Wed, 31 Aug 2011 21:37:11 +0200 Subject: Text file with mixed end-of-line terminations Message-ID: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> I have a text file that uses both '\r' and '\r\n' end-of-line terminations. The '\r' terminates the first 25 lines or so, the remainder is termiated with '\r\n' Reading this file like this: ++++++++ for line in open(filename,'r'): line= #Do whatever needs doing... ++++++++ The first line read is actually a string consiting of the first 25 lines. The readline() method does the same thing. Is there a way to make it read one line at a time, regardless of the line termination? By the way, the newlines attribute reports None after reading a few lines. I tried on Linux and Windows. I use the standard binaries as distributed. Thanks in advance, Alex van der Spek From clp2 at rebertia.com Wed Aug 31 15:58:36 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Aug 2011 12:58:36 -0700 Subject: Text file with mixed end-of-line terminations In-Reply-To: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> References: <4e5e8d71$0$2554$e4fe514c@news2.news.xs4all.nl> Message-ID: On Wed, Aug 31, 2011 at 12:37 PM, Alex van der Spek wrote: > I have a text file that uses both '\r' and '\r\n' end-of-line terminations. > > The '\r' terminates the first 25 lines or so, the remainder is termiated > with '\r\n' > Is there a way to make it read one line at a time, regardless of the line > termination? Universal Newline Support http://www.python.org/dev/peps/pep-0278/ http://docs.python.org/library/functions.html#open (Modes involving "U") Cheers, Chris From nospam at torek.net Wed Aug 31 16:15:44 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 20:15:44 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >In article <0dc26f12-2541-4d41-8678-4fa53f347acf at g9g2000yqb.googlegroups.com> T. Goodchild asked, in part: >>... One of the things that bugs me is the requirement that all class >>methods have 'self' as their first parameter. In article <4e5e5628$0$29977$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: [Comprehensive reply, noting that these are actually instance methods, and that there are class and static methods as well]: >Python does have class methods, which receive the class, not the instance, >as the first parameter. These are usually written something like this: > >class K(object): > @classmethod > def spam(cls, args): > print cls # always prints "class K", never the instance > >Just like self, the name cls is a convention only. Class methods are usually >used for alternate constructors. > >There are also static methods, which don't receive any special first >argument, plus any other sort of method you can invent, by creating >descriptors... but that's getting into fairly advanced territory. ... [rest snipped] I am not sure whether T. Goodchild was asking any of the above or perhaps also one other possible question: if an instance method is going to receive an automatic first "self" parameter, why require the programmer to write that parameter in the "def"? For instance we *could* have: class K(object): def meth1(arg1, arg2): self.arg1 = arg1 # self is "magically available" self.arg2 = arg2 @classmethod def meth2(arg): use(cls) # cls is "magically available" and so on. This would work fine. It just requires a bit of implicit sneakiness in the compiler: an instance method magically creates a local variable named "self" that binds to the invisible first parameter, and a class method magically creates a local variable named "cls" that binds to the invisible first parameter, and so on. Instead, we have a syntax where you, the programmer, write out the name of the local variable that binds to the first parameter. This means the first parameter is visible. Except, it is only visible at the function definition -- when you have the instance and call the instance or class method: black_knight = K() black_knight.meth1('a', 1) black_knight.meth2(2) the first parameters (black_knight, and black_knight.__class__, respectively) are magic, and invisible. Thus, Python is using the "explicit is better than implicit" rule in the definition, but not at the call site. I have no problem with this. Sometimes I think implicit is better than explicit. In this case, there is no need to distinguish, at the calls to meth1() and meth2(), as to whether they are "class" or "instance" methods. At the *calls* they would just be distractions. At the *definitions*, they are not as "distraction-y" since it is important to know, during the definition, whether you are operating on an instance (meth1) or the class itself (meth2), or for that matter on neither (static methods). One could determine this from the absence or presence of "@classmethod" or "@staticmethod", but the minor redundancy in the "def" statement seems, well, minor. Also, as a bonus, it lets you obfuscate the code by using a name other than "self" or "cls". :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Wed Aug 31 17:01:34 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 21:01:34 GMT Subject: try... except with unknown error types References: <4e5015ad$0$29986$c3e8da3$5496439d@news.astraweb.com> <7xty9ahb84.fsf@ruckus.brouhaha.com> Message-ID: In article , Terry Reedy wrote: >I would expect that catching socket.error (or even IOError) should catch >all of those. > >"exception socket.error >A subclass of IOError ... Except that, as Steven D'Aprano almost noted elsethread, it isn't (a subclass of IOError -- the note was that it is not a subclass of EnvironmentError). In 2.x anyway: >>> import socket >>> isinstance(socket.error, IOError) False >>> isinstance(socket.error, EnvironmentError) False >>> (I just catch socket.error directly for this case.) (I have also never been sure whether something is going to raise an IOError or an OSError for various OS-related read or write operation failures -- such as exceeding a resource limit, for instance -- so most places that do I/O operations on OS files, I catch both. Still, it sure would be nice to have a static analysis tool that could answer questions about potential exceptions. :-) ) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nospam at torek.net Wed Aug 31 17:30:12 2011 From: nospam at torek.net (Chris Torek) Date: 31 Aug 2011 21:30:12 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: (I realize this thread is old. I have been away for a few weeks. I read through the whole thread, though, and did not see anyone bring up this one particular point: there is already a linting script that handles this.) >On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert > wrote: >> With surprising regularity, I see program postings (eg. on StackOverflow) >> from inexperienced Python users accidentally re-assigning built-in names. >> >> For example, they'll innocently call some variable, `list', and assign a >> list of items to it. In article Chris Angelico wrote: >It's actually masking, not reassigning. That may make it easier or >harder to resolve the issue. > >If you want a future directive that deals with it, I'd do it the other >way - from __future__ import mask_builtin_warning or something - so >the default remains as it currently is. But this may be a better job >for a linting script. The pylint program already does this: $ cat shado.py "module doc" def func(list): "func doc" return list $ pylint shado.py ************* Module shado W0622: 2:func: Redefining built-in 'list' ... Your code has been rated at 6.67/10 If your shadowing is done on purpose, you can put in a pylint comment directive to suppress the warning. Pylint is the American Express Card of Python coding: "don't leave $HOME without it!" :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From ian.g.kelly at gmail.com Wed Aug 31 17:52:48 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 15:52:48 -0600 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On Wed, Aug 31, 2011 at 11:12 AM, Prasad, Ramit wrote: > It seems to me that if I add a function to the list of class attributes it will automatically wrap with "self" but adding it to the object directly will not wrap the function as a method. Can somebody explain why? I would have thought that any function added to an object would be a method (unless decorated as a class method). Because things stored on the class are generally viewed as part of the class definition, whereas things stored on an instance are generally viewed as data -- a function stored on an object instance is usually just meant to be a function. Consider the following code: class Sorter(object): def __init__(self, keyfunc): self.keyfunc = keyfunc def sort(self, item_list): item_list.sort(key=self.keyfunc) sorter = Sorter(lambda x: x.id) sorter.sort(some_list_of_items) If adding keyfunc as an attribute to the object wrapped it up as a method, it would break, since the function is not expecting a "self" argument. More technically, because descriptors are only invoked when they're stored on the class. > Hmm, or does the decoration just tell Python not to turn an object's function into a method? I.e. Is the decorator basically just the syntactic sugar for doing the above? If you mean the staticmethod decorator, yes, it pretty much just wraps the function as a "staticmethod" instance to prevent it from being wrapped into an ordinary method when it's accessed. Cheers, Ian From usenet-nospam at seebs.net Wed Aug 31 17:57:06 2011 From: usenet-nospam at seebs.net (Seebs) Date: 31 Aug 2011 21:57:06 GMT Subject: Why no warnings when re-assigning builtin names? References: Message-ID: On 2011-08-31, Chris Torek wrote: > (I realize this thread is old. I have been away for a few weeks. > I read through the whole thread, though, and did not see anyone > bring up this one particular point: there is already a linting > script that handles this.) Yes. I've found pylint... A weird mix of "very helpful, thanks" and "oh, come off it". A thread about pylint is where I got my example of the natural Python way to express a parabola: theValueRepresentingTheYAxisLocationOfThePoint = theValueRepresentingTheXAxisLocationOfThe Point * theValueRepresentingTheXAxisLocationOfThe Point I still say that there are times when short names are natural and idiomatic, and much clearer than long names. :P But I do think that, given the basic assumption that pylint is a core tool for vetting code, it is probably adequate for it to provide the warnings. -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. From ian.g.kelly at gmail.com Wed Aug 31 18:16:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 31 Aug 2011 16:16:54 -0600 Subject: Subclassing str object In-Reply-To: References: Message-ID: 2011/8/31 Ya?ar Arabac? : > @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at > all, so I deleted it. My class's addition and multiplication works without > overwriting __add__ and __mul__ because, this class uses unicode's __add__ > and __mul__ than creates a new kelime instance with return value of those > methods in __getattribute__. I think if you try it, you'll find that the result is an ordinary unicode object, not a kelime instance, because __getattribute__ is *not* invoked when Python looks up special method names on the class object. > I didn't get a good grasp on how using basestring there might broke > encoding, could you explain a little bit more, or provide a reading > material? The unicode.encode method takes a unicode object and encodes it into a byte string (a str object). If you then wrap that up in a kelime object, which is a unicode subclass, it has to decode the string back to unicode (using the default ascii codec, since it isn't specified). Thus the result of the call is no longer an encoded byte string as would be expected. If you're lucky, you'll get a UnicodeDecodeError since it's just using the ascii codec. If you're unlucky, it will silently return a result of the wrong type. > So the thing I wonder, when creating new instance in for example > capitalize() method, does str use something like self.__new__() or > unicode.__new__()? Because, in latter case, I could override the __new__ > method on my class, so that every method would create my class's instance, > instead of unicode's No, that doesn't work. From tjreedy at udel.edu Wed Aug 31 18:21:06 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 18:21:06 -0400 Subject: Closures and Partial Function Application In-Reply-To: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> References: <9cd48486-acd9-4888-9677-0e54fd1eedfd@k15g2000yqd.googlegroups.com> Message-ID: On 8/31/2011 12:45 PM, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. 'Were', in 2.x. The standard 2.x workaround for a single nonlocal is to wrap it in a list. def f(): i = [0] def g(): i[0] += 1 for j in range(5): g() print(i) f() # 5 -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 31 18:40:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Aug 2011 18:40:26 -0400 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F163CD332@EMARC112VS01.exchad.jpmchase.net> Message-ID: On 8/31/2011 1:12 PM, Prasad, Ramit wrote: >> def double(obj): return 2*obj.value >> >> class C: >> def __init__(self, val): >> self.value = val >> >> c = C(3) >> C.double = double >> c.doub = double >> # not c.double as that would mask access to C.double in c.double() >> print(double(c), >> C.double(c), c.double(), c.doub(c)) Above is 3.2 code. To be exactly equivalent with 2.x, you need class C(object): > Sorry if I get some of the following terminology wrong, I get a bit > confused on Python terms. I hope the following is still coherent. (Is > there a dictionary of Python terminology?) > Given the above example I get this >>>> print c.double(c) > TypeError: double() takes exactly 1 argument (2 given) Right, because c.double() translates to C.double(c), and c.double(x) translates to C.double(c,x), which is not valid. >>>> print c.doub(c) > 6 > > It seems to me that if I add a function to the list of class > attributes it will automatically wrap with "self" When accessed via an instance of the class, the instance is automagically added as the first argument to be bound to the first parameter. The name 'self' is a convention, not a requirement. > but adding it to > the object directly will not wrap the function as a method. Can > somebody explain why? Someone else did. Not wrapping is normal, wrapping is a special case. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Wed Aug 31 19:31:26 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2011 11:31:26 +1200 Subject: PC locks up with list operations In-Reply-To: <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9c7uihF6feU1@mid.individual.net> Steven D'Aprano wrote: > As far as I know, ulimit ("user limit") won't help. It can limit the amount > of RAM available to a process, but that just makes the process start using > virtual memory more quickly. ulimit -v is supposed to set the maximum amount of virtual memory the process can use. > It can also limit the amount of virtual memory > used by the shell, but not of other processes. That doesn't sound right. Not sure about Linux, but the man page for sh on Darwin says: Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The Python process should also be able to set its own limits using resource.setrlimit(). -- Greg From greg.ewing at canterbury.ac.nz Wed Aug 31 19:37:32 2011 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 01 Sep 2011 11:37:32 +1200 Subject: Handling 2.7 and 3.0 Versions of Dict In-Reply-To: References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> Message-ID: <9c7utuF8q8U1@mid.individual.net> Ian Kelly wrote: > if sys.version_info < (3,): > getDictValues = dict.itervalues > else: > getDictValues = dict.values > > (which is basically what the OP was doing in the first place). And which he seemed to think didn't work for some reason, but it seems fine as far as I can tell: Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> gv = dict.itervalues >>> d = {1:'a', 2:'b'} >>> gv(d) % python3.1 Python 3.1.2 (r312:79147, Mar 2 2011, 17:43:12) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> gv = dict.values >>> d = {1:'a', 2:'b'} >>> gv(d) dict_values(['a', 'b']) -- Greg From steve+comp.lang.python at pearwood.info Wed Aug 31 20:11:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:11:57 +1000 Subject: fun with nested loops References: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> Message-ID: <4e5ecdcf$0$29967$c3e8da3$5496439d@news.astraweb.com> Daniel wrote: > And I have to keep the code simple for non CS people to run > the actual experiment. Do you think the software in the Apple iPod is "simple"? Or Microsoft Windows? No. You need to keep the *interface* simple. The internal details can be as complicated as they are needed to be. Same applies to your data acquisition application. Unless you expect these non-CS people to be hacking the source code, they only interact with the interface, not the internals. Earlier, back in your initial post, you said: "I don't see any way to reduce these nested loops logically, they describe pretty well what the software has to do. This is a data acquisition application, so on ever line there is a lot of IO that might fail or make subsequent steps useless or require a retry." Do you think you're the first person to have written a data acquisition application in Python? Almost certainly you can simplify the structure of the code by splitting it into functions appropriately, instead of the spaghetti code you have (apparently) written with jumps all over the place. To take the most obvious, simple example: any time you have a loop that you might want to redo, the right solution is to put the loop inside a function, and then "redo the loop" becomes "call the function again". I suppose that, just possibly, your application really would benefit from named labels to jump to. But if so, you've stumbled across something rarer than iridium. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:18:34 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:18:34 +1000 Subject: fun with nested loops References: <0cc53b0e-d05b-42fd-96f2-8df6f767e66c@en1g2000vbb.googlegroups.com> Message-ID: <4e5ecf5c$0$29994$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > Ah well, was worth a try. Raising exceptions smells wrong for this, > but peppering your code with sentinel checks isn't much better. I > don't really know what would be a good solution to this... except > maybe this, which was proposed a few years ago and which I'd never > heard of until Google showed it to me just now: > http://entrian.com/goto/ You're a wicked, wicked man. :) -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:48:46 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:48:46 +1000 Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Chris Torek wrote: >>There are also static methods, which don't receive any special first >>argument, plus any other sort of method you can invent, by creating >>descriptors... but that's getting into fairly advanced territory. ... > [rest snipped] > > I am not sure whether T. Goodchild was asking any of the above or > perhaps also one other possible question: if an instance method > is going to receive an automatic first "self" parameter, why require > the programmer to write that parameter in the "def"? Er, yes, just like I suggested in my opening paragraph, and as I answered following the bit you marked as snipped :) > For instance > we *could* have: > > class K(object): > def meth1(arg1, arg2): > self.arg1 = arg1 # self is "magically available" > self.arg2 = arg2 > > @classmethod > def meth2(arg): > use(cls) # cls is "magically available" > > and so on. This would work fine. It just requires a bit of implicit > sneakiness in the compiler: an instance method magically creates > a local variable named "self" that binds to the invisible first > parameter, and a class method magically creates a local variable > named "cls" that binds to the invisible first parameter, and so > on. It would need more than "a bit", because methods are just wrappers around functions. One way would be for Python to give that up, and require methods to be special built-in types like functions. That adds complexity to the compiler, and (very likely) would decrease the level of dynamism possible. Another way would be for the compiler to perform darkest black magic to determine whether the function was being called from inside a method or not. That would be complicated and fragile. [...] > At the *definitions*, they are not as "distraction-y" since it is > important to know, during the definition, whether you are operating > on an instance (meth1) or the class itself (meth2), or for that > matter on neither (static methods). One could determine this from > the absence or presence of "@classmethod" or "@staticmethod" classmethod and staticmethod are functions, not declarations. You can't assume that @classmethod is the only way to get a class method: the metaclass could do it, or you could inject one in from the outside. You can dynamically change the state of a method from instance method to class method and back again at run-time. Python classes have a lot of dynamism made possible by the fact that methods are just wrappers around functions with an explicitly declared "self". That dynamism is rarely used, but not *that* rarely, and is very useful when used. Implicit self would likely negate all that. -- Steven From steve+comp.lang.python at pearwood.info Wed Aug 31 20:50:54 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 01 Sep 2011 10:50:54 +1000 Subject: fun with nested loops References: <9dc99e77-af2e-4d28-b563-e1a66236318e@er4g2000vbb.googlegroups.com> <4e5ecdcf$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e5ed6ef$0$29981$c3e8da3$5496439d@news.astraweb.com> Steven D'Aprano wrote: [...] > Do you think you're the first person to have written a data acquisition > application in Python? Hmmm, on re-reading that it comes across as much harsher than it sounded in my head. Sorry about that Daniel. -- Steven From python.list at tim.thechases.com Wed Aug 31 20:53:48 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 31 Aug 2011 19:53:48 -0500 Subject: PC locks up with list operations In-Reply-To: <9c7uihF6feU1@mid.individual.net> References: <4e5e2a0c$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e5e2d81$0$29991$c3e8da3$5496439d@news.astraweb.com> <9c7uihF6feU1@mid.individual.net> Message-ID: <4E5ED79C.5070701@tim.thechases.com> On 08/31/11 18:31, Gregory Ewing wrote: > The Python process should also be able to set its own > limits using resource.setrlimit(). A new corner of stdlib that I've never poked at. Thanks for the suggestion. Disappointed though that it doesn't seem to have docstrings on the functions, so I had to wade back out to the online docs to probe at it. Granted, after the fact, they were pretty obvious, but it would be nice if "help(resource.getrlimit)" gave me a hint as to what that one expected parameter should have been. -tim import resource as r token = "RLIMIT_" for item in dir(r): if item.startswith(token): print "%s:" % item[len(token):], print "%s hard/%s soft" % r.getrlimit(getattr(r, item)) From jehugaleahsa at gmail.com Wed Aug 31 21:28:09 2011 From: jehugaleahsa at gmail.com (Travis Parks) Date: Wed, 31 Aug 2011 18:28:09 -0700 (PDT) Subject: Handling 2.7 and 3.0 Versions of Dict References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> <9c7utuF8q8U1@mid.individual.net> Message-ID: <93c5378e-03f8-4764-96e8-2c3e8568baec@z8g2000yqe.googlegroups.com> On Aug 31, 7:37?pm, Gregory Ewing wrote: > Ian Kelly wrote: > > if sys.version_info < (3,): > > ? ? getDictValues = dict.itervalues > > else: > > ? ? getDictValues = dict.values > > > (which is basically what the OP was doing in the first place). > > And which he seemed to think didn't work for some > reason, but it seems fine as far as I can tell: > > Python 2.7 (r27:82500, Oct 15 2010, 21:14:33) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > ?>>> gv = dict.itervalues > ?>>> d = {1:'a', 2:'b'} > ?>>> gv(d) > > > % python3.1 > Python 3.1.2 (r312:79147, Mar ?2 2011, 17:43:12) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > ?>>> gv = dict.values > ?>>> d = {1:'a', 2:'b'} > ?>>> gv(d) > dict_values(['a', 'b']) > > -- > Greg My problem was that I didn't understand the scoping rules. It is still strange to me that the getValues variable is still in scope outside the if/else branches. From mrinalini at edss.co.in Wed Aug 31 21:46:54 2011 From: mrinalini at edss.co.in (mrinalini at edss.co.in) Date: Thu, 01 Sep 2011 07:16:54 +0530 Subject: Help required accessing dictionary Message-ID: <54e7c93d35c11cdf72cee56a8a1c5abc@edss.co.in> Hi I need to access the dictionary of the script that I am running through my vc++ application by embedding python. I am linking to python dynamically. I want to obtain the dictionary of the script and access the variables declared in the script. However, with the PyObject * that I get from the dictionary, I am not able to find the type of the object. The reason being that GetProcAddress to PyInt_Check returns a NULL. The same thing with PyFloat_Check and so on. I think this is because they are macros and not exported functions. What can be done to be able to perform these checks without statically linking to the pyhon lib ? Thanks, Abhaya From rosuav at gmail.com Wed Aug 31 21:47:28 2011 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Sep 2011 11:47:28 +1000 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano wrote: > Python classes have a lot of dynamism made possible by the fact that methods > are just wrappers around functions with an explicitly declared "self". That > dynamism is rarely used, but not *that* rarely, and is very useful when > used. Implicit self would likely negate all that. > Hmm. Got any examples sitting around? I'm curious as to what you can do with this. I'm like a kid with a new chemistry set - "what happens if I mix a little of everything together?"... ChrisA From ericsnowcurrently at gmail.com Wed Aug 31 22:07:42 2011 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Wed, 31 Aug 2011 20:07:42 -0600 Subject: Why do class methods always need 'self' as the first parameter? In-Reply-To: References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 31, 2011 at 7:47 PM, Chris Angelico wrote: > On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano > wrote: >> Python classes have a lot of dynamism made possible by the fact that methods >> are just wrappers around functions with an explicitly declared "self". That >> dynamism is rarely used, but not *that* rarely, and is very useful when >> used. Implicit self would likely negate all that. >> > > Hmm. Got any examples sitting around? I'm curious as to what you can > do with this. I'm like a kid with a new chemistry set - "what happens > if I mix a little of everything together?"... First thing that comes to mind is calling a base class's implementation of a method: class X(Y): def __init__(self, value): Y.__init__(self) self.value = value -eric > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From nospam at torek.net Wed Aug 31 22:20:56 2011 From: nospam at torek.net (Chris Torek) Date: 1 Sep 2011 02:20:56 GMT Subject: Why do class methods always need 'self' as the first parameter? References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <4e5e5628$0$29977$c3e8da3$5496439d@news.astraweb.com> <4e5ed670$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4e5ed670$0$29981$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano wrote: >Er, yes, just like I suggested in my opening paragraph, and as I answered >following the bit you marked as snipped :) Oops, so you did (went back and re-read it). Must have gotten interrupted and lost track. :-) >> [A different hack would] requires a bit of implicit >> sneakiness in the compiler: an instance method magically creates >> a local variable named "self" that binds to the invisible first >> parameter, and a class method magically creates a local variable >> named "cls" that binds to the invisible first parameter, and so >> on. >It would need more than "a bit", because methods are just wrappers >around functions. Well, depends on how the hack would be done. :-) For instance, the @decorator might turn on something that "undoes" or "replaces" the "self" parameter. That is, with ordinary class functions and methods: class HackyNotQuitePythonVersion: def ordinary(arg): self.arg = arg would compile to (approximately): class PythonVersion: def __mrap(self, *args, **kwargs): def ordinary(arg): self.arg = arg ordinary(*args, **kwargs) ordinary = __mrap (add the usual other manipulations to suit here, i.e., all the stuff for making introspection work right, i.e., @functools.wraps). @staticmethod would suppress the wrapper entirely, while @classmethod would change it to one that binds the "cls" argument. (Any function without some appropriate @whatever gets the Method Wrapper __mrap. @staticmethod tells the class builder not to add any wrapper, and @classmethod tells it to add the Class Wrapper __crap. [The name tells you what I think of the above code. :-) ]) (Note subtle ground for bugs here: if you then actually define a "self" parameter, it shadows the outer-scope one from the wrapper. So while I am not even proposing that anyone should do this in the first place, it has more downsides than mere implementation complexity.) >Another way would be for the compiler to perform darkest black magic to >determine whether the function was being called from inside a method or >not. That would be complicated and fragile. Yes, even worse than my outlined implementation above, I think. >classmethod and staticmethod are functions, not declarations. They are decorator functions, but to someone *reading the code* they are also "declarations" of sort. This is all I meant: they tell the (human) reader/programmer which "secret arguments" to expect. >You can't assume that @classmethod is the only way to get a >class method: the metaclass could do it, or you could inject >one in from the outside. Yes, but that would all still work, as in this not-quite-Python (worsened-Python) language, whoever writes those metaclasses and other decorators would continue to do whatever icky stuff was required (e.g., __mrap and __crap above). It would mean yet more things for people to know about, but then, metaclasses and decorators *always* mean that: @hmm def spam(): return magic Is "magic" something supplied by the decorator? You have to look at the decorator to find out, as the rather horrid example I have attached shows. (Note: I am doing all this is python 2.x on the laptop. Using global, in @hmm, is evil, but it works. I did not bother trying to write a metaclass that inserts __mrap, etc., but I believe it can be done.) >Python classes have a lot of dynamism made possible by the fact that methods >are just wrappers around functions with an explicitly declared "self". That >dynamism is rarely used, but not *that* rarely, and is very useful when >used. Implicit self would likely negate all that. I do not believe it would *negate* it, just *complicate* it. But that is not a good thing either. :-) ----- horrible example / test code below import functools def hmm(func): @functools.wraps(func) def wrapper(*args, **kwargs): global magic, rlevel try: save = magic, rlevel restore = True rlevel += 1 except NameError: restore = False rlevel = 1 magic = func.__name__ + " and eggs" ret = func(*args, **kwargs) if restore: magic, rlevel = save else: del magic, rlevel return ret return wrapper @hmm def ham(): if rlevel < 2: print spam() return magic @hmm def spam(): return magic print ham() try: print magic except NameError: print 'name "magic" is not available here, as desired' try: print rlevel except NameError: print 'name "rlevel" is not available here, as desired' class X(object): def __mrap(self, *args, **kwargs): def xset(arg): self.arg = arg xset(*args, **kwargs) xset = __mrap def __mrap(self, *args, **kwargs): def show(): print self.arg show(*args, **kwargs) show = __mrap x = X() x.xset('value') x.show() -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40?39.22'N, 111?50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html From nemjain2 at gmail.com Wed Aug 31 23:16:07 2011 From: nemjain2 at gmail.com (babbu Pehlwan) Date: Wed, 31 Aug 2011 20:16:07 -0700 (PDT) Subject: How to daemonize a HTTPServer Message-ID: <594e0376-3a1d-4430-bf47-d1e0f856c4dd@f31g2000prj.googlegroups.com> I have written a http server using BaseHTTPServer module. Now I want to instantiate it through another python script. The issue here is after instantiate the control doesn't come back till the server is running. Please suggest.