From kroger at pedrokroger.net Wed Aug 1 00:31:48 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Wed, 1 Aug 2012 01:31:48 -0300 Subject: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way. In-Reply-To: References: Message-ID: <555CACC6-11E7-4897-ACEF-8CCEFF07F9F0@pedrokroger.net> On Aug 1, 2012, at 12:19 AM, Peter Billam wrote: > I'll check it out. It probably fits into a whole software > ecosystem that you're putting together ? yes, I use it for my book, Music for Geeks and Nerds and for teaching. > It's a crowded area, e.g. my midi stuff is at: > http://www.pjb.com.au/midi/index.html You have very interesting stuff, I'll check them out. > and I'd probably do the above example by: > ~> muscript -midi <demo.mid > | 3/4 2.0 > =1 treble 4 D 8 [F# A] 4 Bb > EOT Nice. This reminded me to include a less simple example. After all, the whole point of pyknon is to be able to generate music programmatically using Python: http://kroger.github.com/pyknon/ > You could consider posting Pyknon to comp.music.midi ; > it's very low traffic, but some real gurus lurk there. Good idea, thanks for the suggestion. Cheers, Pedro ----- http://pedrokroger.net http://musicforgeeksandnerds.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From levinie001 at gmail.com Wed Aug 1 00:45:17 2012 From: levinie001 at gmail.com (levi nie) Date: Wed, 1 Aug 2012 12:45:17 +0800 Subject: why the different output in Eclipse and Python Shell? Message-ID: my code in Eclipse: dict.fromkeys(['China','America']) print "dict is",dict output: dict is my code in Python Shell: dict.fromkeys(['China','America']) output:{'America': None, 'China': None} Output in Python Shell is what i wanna,but why not in Eclipse? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Aug 1 02:39:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Aug 2012 02:39:07 -0400 Subject: why the different output in Eclipse and Python Shell? In-Reply-To: References: Message-ID: On 8/1/2012 12:45 AM, levi nie wrote: > my code in Eclipse: > > dict.fromkeys(['China','America']) In Eclipse, I presume this prints nothing, as is normal for an editor. > print "dict is",dict > > output: dict is This is red herring. The shell does the same with that line. It is not relevant to your question. > dict.fromkeys(['China','America']) > > output:{'America': None, 'China': None} The interactive interpreter echoes the result of evaluating expressions. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Wed Aug 1 04:06:43 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 01 Aug 2012 09:06:43 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 01/08/2012 00:31, David wrote: > On 01/08/2012, lipska the kat wrote: >> On 31/07/12 14:52, David wrote: >>> >>> [1] as in beer >>> [2] for research purposes >> >> There's one (as in 1 above) in the pump for you. > > Great, more beer => better research => \o/\o/\o/ > But, "pump" sounds a bit extreme .. I usually sip contentedly from a glass :p > You complete ignoramus, if it gets poured in advance that's no good to anybody as it'll go flat. Has to stay in the pump until you're ready to drink it from the glass. Don't you know anything about the importance of process and timing? :) -- Cheers. Mark Lawrence. From lipska at yahoo.co.uk Wed Aug 1 04:15:54 2012 From: lipska at yahoo.co.uk (lipska the kat) Date: Wed, 01 Aug 2012 09:15:54 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 01/08/12 09:06, Mark Lawrence wrote: > On 01/08/2012 00:31, David wrote: >> On 01/08/2012, lipska the kat wrote: >>> On 31/07/12 14:52, David wrote: >>>> >>>> [1] as in beer >>>> [2] for research purposes >>> >>> There's one (as in 1 above) in the pump for you. >> >> Great, more beer => better research => \o/\o/\o/ >> But, "pump" sounds a bit extreme .. I usually sip contentedly from a >> glass :p >> > > You complete ignoramus, if it gets poured in advance that's no good to > anybody as it'll go flat. Has to stay in the pump until you're ready to > drink it from the glass. Don't you know anything about the importance of > process and timing? :) > Heh heh, obviously never got drunk ... er I mean served behind the bar at uni/college/pub %-} lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From gandalf at shopzeus.com Wed Aug 1 04:19:19 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 10:19:19 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <5018E687.9000105@shopzeus.com> > > As I wrote "I found many nice things (Pipe, Manager and so on), but > actually even > this seems to work:" yes I did read the documentation. Sorry, I did not want be offensive. > > I was just surprised that it worked better than I expected even > without Pipes and Queues, but now I understand why.. > > Anyway now I would like to be able to detach subprocesses to avoid the > nasty code reloading that I was talking about in another thread, but > things get more tricky, because I can't use queues and pipes to > communicate with a running process that it's noit my child, correct? > Yes, I think that is correct. Instead of detaching a child process, you can create independent processes and use other frameworks for IPC. For example, Pyro. It is not as effective as multiprocessing.Queue, but in return, you will have the option to run your service across multiple servers. The most effective IPC is usually through shared memory. But there is no OS independent standard Python module that can communicate over shared memory. Except multiprocessing of course, but AFAIK it can only be used to communicate between fork()-ed processes. From andrea.crotti.0 at gmail.com Wed Aug 1 05:50:38 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 10:50:38 +0100 Subject: Pass data to a subprocess In-Reply-To: <5018E687.9000105@shopzeus.com> References: <5017EFB0.6080608@shopzeus.com> <5018E687.9000105@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : >> I was just surprised that it worked better than I expected even >> without Pipes and Queues, but now I understand why.. >> >> Anyway now I would like to be able to detach subprocesses to avoid the >> nasty code reloading that I was talking about in another thread, but >> things get more tricky, because I can't use queues and pipes to >> communicate with a running process that it's noit my child, correct? >> > Yes, I think that is correct. Instead of detaching a child process, you can > create independent processes and use other frameworks for IPC. For example, > Pyro. It is not as effective as multiprocessing.Queue, but in return, you > will have the option to run your service across multiple servers. > > The most effective IPC is usually through shared memory. But there is no OS > independent standard Python module that can communicate over shared memory. > Except multiprocessing of course, but AFAIK it can only be used to > communicate between fork()-ed processes. Thanks, there is another thing which is able to interact with running processes in theory: https://github.com/lmacken/pyrasite I don't know though if it's a good idea to use a similar approach for production code, as far as I understood it uses gdb.. In theory though I could be able to set up every subprocess with all the data they need, so I might not even need to share data between them. Anyway now I had another idea to avoid to be able to stop the main process without killing the subprocesses, using multiple forks. Does the following makes sense? I don't really need these subprocesses to be daemons since they should quit when done, but is there anything that can go wrong with this approach? from os import fork from time import sleep from itertools import count from sys import exit from multiprocessing import Process, Queue class LongProcess(Process): def __init__(self, idx, queue): Process.__init__(self) # self.daemon = True self.queue = queue self.idx = idx def run(self): for i in count(): self.queue.put("%d: %d" % (self.idx, i)) print("adding %d: %d" % (self.idx, i)) sleep(2) if __name__ == '__main__': qu = Queue() # how do I do a multiple fork? for i in range(5): pid = fork() # if I create here all the data structures I should still be able to do things if pid == 0: lp = LongProcess(1, qu) lp.start() lp.join() exit(0) else: print("started subprocess with pid ", pid) From d at davea.name Wed Aug 1 06:07:43 2012 From: d at davea.name (Dave Angel) Date: Wed, 01 Aug 2012 06:07:43 -0400 Subject: why the different output in Eclipse and Python Shell? In-Reply-To: References: Message-ID: <5018FFEF.3000203@davea.name> On 08/01/2012 12:45 AM, levi nie wrote: > my code in Eclipse: > > dict.fromkeys(['China','America']) > print "dict is",dict > > output: dict is > > my code in Python Shell: > > dict.fromkeys(['China','America']) > > output:{'America': None, 'China': None} > > Output in Python Shell is what i wanna,but why not in Eclipse? > > The Python Shell is an interactive debugger, and prints the repr() of expressions that you don't assign anywhere. I don't know Eclipse, but I suspect what you want to do is something like: print "dict is", repr(dict) -- DaveA From gandalf at shopzeus.com Wed Aug 1 06:16:53 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 12:16:53 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> <5018E687.9000105@shopzeus.com> Message-ID: <50190215.7080608@shopzeus.com> > > Thanks, there is another thing which is able to interact with running > processes in theory: > https://github.com/lmacken/pyrasite > > I don't know though if it's a good idea to use a similar approach for > production code, as far as I understood it uses gdb.. In theory > though I could be able to set up every subprocess with all the data > they need, so I might not even need to share data between them. > > Anyway now I had another idea to avoid to be able to stop the main > process without killing the subprocesses, using multiple forks. Does > the following makes sense? I don't really need these subprocesses to > be daemons since they should quit when done, but is there anything > that can go wrong with this approach? On thing is sure: os.fork() doesn't work under Microsoft Windows. Under Unix, I'm not sure if os.fork() can be mixed with multiprocessing.Process.start(). I could not find official documentation on that. This must be tested on your actual platform. And don't forget to use Queue.get() in your test. :-) From andrea.crotti.0 at gmail.com Wed Aug 1 06:32:58 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 11:32:58 +0100 Subject: Pass data to a subprocess In-Reply-To: <50190215.7080608@shopzeus.com> References: <5017EFB0.6080608@shopzeus.com> <5018E687.9000105@shopzeus.com> <50190215.7080608@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : > On thing is sure: os.fork() doesn't work under Microsoft Windows. Under > Unix, I'm not sure if os.fork() can be mixed with > multiprocessing.Process.start(). I could not find official documentation on > that. This must be tested on your actual platform. And don't forget to use > Queue.get() in your test. :-) > Yes I know we don't care about Windows for this particular project.. I think mixing multiprocessing and fork should not harm, but probably is unnecessary since I'm already in another process after the fork so I can just make it run what I want. Otherwise is there a way to do same thing only using multiprocessing? (running a process that is detachable from the process that created it) From andrea.crotti.0 at gmail.com Wed Aug 1 06:39:57 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 11:39:57 +0100 Subject: CRC-checksum failed in gzip Message-ID: We're having some really obscure problems with gzip. There is a program running with python2.7 on a 2.6.18-128.el5xen (red hat I think) kernel. Now this program does the following: if filename == 'out2.txt': out2 = open('out2.txt') elif filename == 'out2.txt.gz' out2 = open('out2.txt.gz') text = out2.read() out2.close() very simple right? But sometimes we get a checksum error. Reading the code I got the following: - CRC is at the end of the file and is computed against the whole file (last 8 bytes) - after the CRC there is the \0000 marker for the EOF - readline() doesn't trigger the checksum generation in the beginning, but only when the EOF is reached - until a file is flushed or closed you can't read the new content in it but the problem is that we can't reproduce it, because doing it manually on the same files it works perfectly, and the same files some time work some time don't work. The files are on a shared NFS drive, I'm starting to think that it's a network/fs problem, which might truncate the file adding an EOF before the end and thus making the checksum fail.. But is it possible? Or what else could it be? From gandalf at shopzeus.com Wed Aug 1 06:40:17 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 12:40:17 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> <5018E687.9000105@shopzeus.com> <50190215.7080608@shopzeus.com> Message-ID: <50190791.9070407@shopzeus.com> > Yes I know we don't care about Windows for this particular project.. > I think mixing multiprocessing and fork should not harm, but probably > is unnecessary since I'm already in another process after the fork so > I can just make it run what I want. > > Otherwise is there a way to do same thing only using multiprocessing? > (running a process that is detachable from the process that created it) > I'm afraid there is no way to do that. I'm not even sure if multiprocessing.Queue will work if you detach a forked process. From gandalf at shopzeus.com Wed Aug 1 06:47:00 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 12:47:00 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: Message-ID: <50190924.4030605@shopzeus.com> On 2012-08-01 12:39, andrea crotti wrote: > We're having some really obscure problems with gzip. > There is a program running with python2.7 on a 2.6.18-128.el5xen (red > hat I think) kernel. > > Now this program does the following: > if filename == 'out2.txt': > out2 = open('out2.txt') > elif filename == 'out2.txt.gz' > out2 = open('out2.txt.gz') Gzip file is binary. You should open it in binary mode. out2 = open('out2.txt.gz',"b") Otherwise carriage return and newline characters will be converted (depending on the platform). From andrea.crotti.0 at gmail.com Wed Aug 1 06:58:10 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 11:58:10 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <50190924.4030605@shopzeus.com> References: <50190924.4030605@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : > On 2012-08-01 12:39, andrea crotti wrote: >> >> We're having some really obscure problems with gzip. >> There is a program running with python2.7 on a 2.6.18-128.el5xen (red >> hat I think) kernel. >> >> Now this program does the following: >> if filename == 'out2.txt': >> out2 = open('out2.txt') >> elif filename == 'out2.txt.gz' >> out2 = open('out2.txt.gz') > > Gzip file is binary. You should open it in binary mode. > > out2 = open('out2.txt.gz',"b") > > Otherwise carriage return and newline characters will be converted > (depending on the platform). > > > -- > http://mail.python.org/mailman/listinfo/python-list Ah no sorry I just wrote wrong that part of the code, it was otu2 = gzip.open('out2.txt.gz') because otherwise nothing would possibly work.. From roy at panix.com Wed Aug 1 06:59:37 2012 From: roy at panix.com (Roy Smith) Date: Wed, 01 Aug 2012 06:59:37 -0400 Subject: Pass data to a subprocess References: <5017EFB0.6080608@shopzeus.com> Message-ID: In article , Laszlo Nagy wrote: > Yes, I think that is correct. Instead of detaching a child process, you > can create independent processes and use other frameworks for IPC. For > example, Pyro. It is not as effective as multiprocessing.Queue, but in > return, you will have the option to run your service across multiple > servers. You might want to look at beanstalk (http://kr.github.com/beanstalkd/). We've been using it in production for the better part of two years. At a 30,000 foot level, it's an implementation of queues over named pipes over TCP, but it takes care of a zillion little details for you. Setup is trivial, and there's clients for all sorts of languages. For a Python client, go with beanstalkc (pybeanstalk appears to be abandonware). > > The most effective IPC is usually through shared memory. But there is no > OS independent standard Python module that can communicate over shared > memory. It's true that shared memory is faster than serializing objects over a TCP connection. On the other hand, it's hard to imagine anything written in Python where you would notice the difference. From gandalf at shopzeus.com Wed Aug 1 07:07:23 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 13:07:23 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <50190DEB.4060303@shopzeus.com> >> The most effective IPC is usually through shared memory. But there is no >> OS independent standard Python module that can communicate over shared >> memory. > It's true that shared memory is faster than serializing objects over a > TCP connection. On the other hand, it's hard to imagine anything > written in Python where you would notice the difference. Well, except in response times. ;-) The TCP stack likes to wait after you call send() on a socket. Yes, you can use setsockopt/TCP_NOWAIT, but my experience is that response times with TCP can be long, especially when you have to do many request-response pairs. It also depends on the protocol design - if you can reduce the number of request-response pairs then it helps a lot. From gandalf at shopzeus.com Wed Aug 1 07:11:18 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 13:11:18 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: Message-ID: <50190ED6.1040100@shopzeus.com> > very simple right? But sometimes we get a checksum error. Do you have a traceback showing the actual error? > > - CRC is at the end of the file and is computed against the whole > file (last 8 bytes) > - after the CRC there is the \0000 marker for the EOF > - readline() doesn't trigger the checksum generation in the > beginning, but only when the EOF is reached > - until a file is flushed or closed you can't read the new content in it How do you write the file? Is it written from another Python program? Can we see the source code of that? > > but the problem is that we can't reproduce it, because doing it > manually on the same files it works perfectly, > and the same files some time work some time don't work. The problem might be with the saved file. Once you get an error for a given file, can you reproduce the error using the same file? > > The files are on a shared NFS drive, I'm starting to think that it's a > network/fs problem, which might truncate the file > adding an EOF before the end and thus making the checksum fail.. > But is it possible? > Or what else could it be? Can your try to run the same program on a local drive? From gandalf at shopzeus.com Wed Aug 1 07:26:17 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 13:26:17 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <50191259.8060607@shopzeus.com> On 2012-08-01 12:59, Roy Smith wrote: > In article , > Laszlo Nagy wrote: > >> Yes, I think that is correct. Instead of detaching a child process, you >> can create independent processes and use other frameworks for IPC. For >> example, Pyro. It is not as effective as multiprocessing.Queue, but in >> return, you will have the option to run your service across multiple >> servers. > You might want to look at beanstalk (http://kr.github.com/beanstalkd/). > We've been using it in production for the better part of two years. At > a 30,000 foot level, it's an implementation of queues over named pipes > over TCP, but it takes care of a zillion little details for you. Looks very simple to use. Too bad that it doesn't work on Windows systems. From damon.w.register at lmco.com Wed Aug 1 07:47:43 2012 From: damon.w.register at lmco.com (Damon Register) Date: Wed, 01 Aug 2012 07:47:43 -0400 Subject: EXTERNAL: Re: missing python-config and building python on Windows In-Reply-To: <5018A755.60609@gmail.com> References: <50187CF7.3080706@clear.net> <5018A755.60609@gmail.com> Message-ID: <5019175F.8010404@lmco.com> On 7/31/2012 11:49 PM, Mark Hammond wrote: > On 1/08/2012 10:48 AM, Damon Register wrote: >> 1. though I have looked in a few readme files, I don't see instructions for >> installing what I have just built using MSVC. Where can I find the >> instructions for installing after building with MSVC? > > There is no such process. In general, you can just run directly from the built tree. That is a bummer. That makes me more curious about how the Windows installer was made and how all the pieces were gathered together. > I'm afraid I don't know what python-config is. It appears it might be a reflection of how Python > was configured and build on *nix systems - if that is the case then it is expected that one does not > exist for Windows (as it doesn't use the *nix build chain). which means, I guess, that mingw is barely supported if at all. While it may be Windows, mingw/msys is a nice way to build many programs that are unix oriented. I suppose that just for fun I should try to build python on SuSE to see how it goes. >> 3. It seems that MSVC doesn't produce the .a library files needed for >> linking >> into a mingw built program. Do I have to do that fun trick to >> create the >> .a from the dll? > > I'm surprised MSVC *can* build .a files for mingw - but AFAIK, even if MSVC could do that, I believe > Python makes no attempt to build with support for linking into mingw programs. I don't know that MSVC can do this. The only process of which I am aware is a two step process using pexports and dlltool to generate the .a file from a dll. One reason I was using the python.org installer is that it already had the python27.a file. Now I am even more curious about what was used to build python and create that installer. The python.org installer provided all I needed for build most python dependent apps with mingw until I ran into one that needed python-config. I suppose that if python-config does what I suspect it does (produce cflags and ldflags as does pkg-config) then perhaps I could just fake it by replacing use of python-config with what the cflags and ldflags should be for where I have python. Damon Register From bouncingcats at gmail.com Wed Aug 1 07:59:09 2012 From: bouncingcats at gmail.com (David) Date: Wed, 1 Aug 2012 21:59:09 +1000 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 01/08/2012, lipska the kat wrote: > On 01/08/12 09:06, Mark Lawrence wrote: >> >> You complete ignoramus, if it gets poured in advance that's no good to >> anybody as it'll go flat. Has to stay in the pump until you're ready to >> drink it from the glass. Don't you know anything about the importance of >> process and timing? :) > > Heh heh, obviously never got drunk ... er I mean served behind the bar > at uni/college/pub %-} Nah, obviously *is* drunk ;p From bv8bv8bv8 at gmail.com Wed Aug 1 08:16:49 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Wed, 1 Aug 2012 05:16:49 -0700 (PDT) Subject: YOU MUST KNOW THIS MAN Message-ID: In The Name Of Allah, Most Gracious, Most Merciful YOU MUST KNOW THIS MAN MUHAMMAD Follow this link http://www.youtube.com/watch?v=9rwYrXbZTM8 Thank you From stefan_ml at behnel.de Wed Aug 1 08:32:57 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Aug 2012 14:32:57 +0200 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: David, 01.08.2012 13:59: > On 01/08/2012, lipska the kat wrote: >> On 01/08/12 09:06, Mark Lawrence wrote: >>> >>> You complete ignoramus, if it gets poured in advance that's no good to >>> anybody as it'll go flat. Has to stay in the pump until you're ready to >>> drink it from the glass. Don't you know anything about the importance of >>> process and timing? :) >> >> Heh heh, obviously never got drunk ... er I mean served behind the bar >> at uni/college/pub %-} > > Nah, obviously *is* drunk ;p Would you mind taking this slightly off-topic discussion off the list? Thanks. Stefan From andrea.crotti.0 at gmail.com Wed Aug 1 09:01:45 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 14:01:45 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <50190ED6.1040100@shopzeus.com> References: <50190ED6.1040100@shopzeus.com> Message-ID: Full traceback: Exception in thread Thread-8: Traceback (most recent call last): File "/user/sim/python/lib/python2.7/threading.py", line 530, in __bootstrap_inner self.run() File "/user/sim/tests/llif/AutoTester/src/AutoTester2.py", line 67, in run self.processJobData(jobData, logger) File "/user/sim/tests/llif/AutoTester/src/AutoTester2.py", line 204, in processJobData self.run_simulator(area, jobData[1] ,log) File "/user/sim/tests/llif/AutoTester/src/AutoTester2.py", line 142, in run_simulator report_file, percentage, body_text = SimResults.copy_test_batch(log, area) File "/user/sim/tests/llif/AutoTester/src/SimResults.py", line 274, in copy_test_batch out2_lines = out2.read() File "/user/sim/python/lib/python2.7/gzip.py", line 245, in read self._read(readsize) File "/user/sim/python/lib/python2.7/gzip.py", line 316, in _read self._read_eof() File "/user/sim/python/lib/python2.7/gzip.py", line 338, in _read_eof hex(self.crc))) IOError: CRC check failed 0x4f675fba != 0xa9e45aL - The file is written with the linux gzip program. - no I can't reproduce the error with the same exact file that did failed, that's what is really puzzling, there seems to be no clear pattern and just randmoly fails. The file is also just open for read from this program, so in theory no way that it can be corrupted. I also checked with lsof if there are processes that opened it but nothing appears.. - can't really try on the local disk, might take ages unfortunately (we are rewriting this system from scratch anyway) From andrea.crotti.0 at gmail.com Wed Aug 1 09:25:02 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 14:25:02 +0100 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: 2012/8/1 Roy Smith : > In article , > Laszlo Nagy wrote: > >> Yes, I think that is correct. Instead of detaching a child process, you >> can create independent processes and use other frameworks for IPC. For >> example, Pyro. It is not as effective as multiprocessing.Queue, but in >> return, you will have the option to run your service across multiple >> servers. > > You might want to look at beanstalk (http://kr.github.com/beanstalkd/). > We've been using it in production for the better part of two years. At > a 30,000 foot level, it's an implementation of queues over named pipes > over TCP, but it takes care of a zillion little details for you. > > Setup is trivial, and there's clients for all sorts of languages. For a > Python client, go with beanstalkc (pybeanstalk appears to be > abandonware). >> >> The most effective IPC is usually through shared memory. But there is no >> OS independent standard Python module that can communicate over shared >> memory. > > It's true that shared memory is faster than serializing objects over a > TCP connection. On the other hand, it's hard to imagine anything > written in Python where you would notice the difference. > -- > http://mail.python.org/mailman/listinfo/python-list That does look nice and I would like to have something like that.. But since I have to convince my boss of another external dependency I think it might be worth to try out zeromq instead, which can also do similar things and looks more powerful, what do you think? From gandalf at shopzeus.com Wed Aug 1 09:27:26 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 15:27:26 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> Message-ID: <50192EBE.3060404@shopzeus.com> - The file is written with the linux gzip program. - no I can't reproduce the error with the same exact file that did failed, that's what is really puzzling, How do you make sure that no process is reading the file before it is fully flushed to disk? Possible way of testing for this kind of error: before you open a file, use os.stat to determine its size, and write out the size and the file path into a log file. Whenever an error occurs, compare the actual size of the file with the logged value. If they are different, then you have tried to read from a file that was growing at that time. Suggestion: from the other process, write the file into a different file (for example, "file.gz.tmp"). Once the file is flushed and closed, use os.rename() to give its final name. On POSIX systems, the rename() operation is atomic. > there seems to be no clear pattern and just randmoly fails. The file > is also just open for read from this program, > so in theory no way that it can be corrupted. Yes, there is. Gzip stores CRC for compressed *blocks*. So if the file is not flushed to the disk, then you can only read a fragment of the block, and that changes the CRC. > > I also checked with lsof if there are processes that opened it but > nothing appears.. lsof doesn't work very well over nfs. You can have other processes on different computers (!) writting the file. lsof only lists the processes on the system it is executed on. > > - can't really try on the local disk, might take ages unfortunately > (we are rewriting this system from scratch anyway) > From andrea.crotti.0 at gmail.com Wed Aug 1 09:52:59 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 14:52:59 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <50192EBE.3060404@shopzeus.com> References: <50190ED6.1040100@shopzeus.com> <50192EBE.3060404@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : >> there seems to be no clear pattern and just randmoly fails. The file >> is also just open for read from this program, >> so in theory no way that it can be corrupted. > > Yes, there is. Gzip stores CRC for compressed *blocks*. So if the file is > not flushed to the disk, then you can only read a fragment of the block, and > that changes the CRC. > >> >> I also checked with lsof if there are processes that opened it but >> nothing appears.. > > lsof doesn't work very well over nfs. You can have other processes on > different computers (!) writting the file. lsof only lists the processes on > the system it is executed on. > >> >> - can't really try on the local disk, might take ages unfortunately >> (we are rewriting this system from scratch anyway) >> > Thanks a lotl, someone that writes on the file while reading might be an explanation, the problem is that everyone claims that they are only reading the file. Apparently this file is generated once and a long time after only read by two different tools (in sequence), so this could not be possible either in theory.. I'll try to investigate more in this sense since it's the only reasonable explation I've found so far. From invalid at invalid.invalid Wed Aug 1 10:16:52 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 1 Aug 2012 14:16:52 +0000 (UTC) Subject: Pass data to a subprocess References: <5017EFB0.6080608@shopzeus.com> Message-ID: On 2012-08-01, Laszlo Nagy wrote: >> >> As I wrote "I found many nice things (Pipe, Manager and so on), but >> actually even >> this seems to work:" yes I did read the documentation. > Sorry, I did not want be offensive. >> >> I was just surprised that it worked better than I expected even >> without Pipes and Queues, but now I understand why.. >> >> Anyway now I would like to be able to detach subprocesses to avoid the >> nasty code reloading that I was talking about in another thread, but >> things get more tricky, because I can't use queues and pipes to >> communicate with a running process that it's noit my child, correct? >> > Yes, I think that is correct. I don't understand why detaching a child process on Linux/Unix would make IPC stop working. Can somebody explain? -- Grant Edwards grant.b.edwards Yow! My vaseline is at RUNNING... gmail.com From gandalf at shopzeus.com Wed Aug 1 10:17:25 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 16:17:25 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <50192EBE.3060404@shopzeus.com> Message-ID: <50193A75.8050107@shopzeus.com> > > Thanks a lotl, someone that writes on the file while reading might be > an explanation, the problem is that everyone claims that they are only > reading the file. If that is true, then make that file system read only. Soon it will turn out who is writing them. ;-) > > Apparently this file is generated once and a long time after only read > by two different tools (in sequence), so this could not be possible > either in theory.. I'll try to investigate more in this sense since > it's the only reasonable explation I've found so far. > Safe solution would be to develop a system where files go through "states" in a predefined order: * allow programs to write into files with .incomplete extension. * allow them to rename the file to .complete. * create a single program that renames .complete files to .gz files AFTER making them read-only for everybody else. * readers should only read .gz file * .gz files are then guaranteed to be complete. From gandalf at shopzeus.com Wed Aug 1 10:32:04 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 16:32:04 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <50193DE4.3030404@shopzeus.com> >>> things get more tricky, because I can't use queues and pipes to >>> communicate with a running process that it's noit my child, correct? >>> >> Yes, I think that is correct. > I don't understand why detaching a child process on Linux/Unix would > make IPC stop working. Can somebody explain? > It is implemented with shared memory. I think (although I'm not 100% sure) that shared memory is created *and freed up* (shm_unlink() system call) by the parent process. It makes sense, because the child processes will surely die with the parent. If you detach a child process, then it won't be killed with its original parent. But the shared memory will be freed by the original parent process anyway. I suspect that the child that has mapped that shared memory segment will try to access a freed up resource, do a segfault or something similar. From gandalf at shopzeus.com Wed Aug 1 10:42:44 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 16:42:44 +0200 Subject: Pass data to a subprocess In-Reply-To: <50193DE4.3030404@shopzeus.com> References: <5017EFB0.6080608@shopzeus.com> <50193DE4.3030404@shopzeus.com> Message-ID: <50194064.9050906@shopzeus.com> >>> Yes, I think that is correct. >> I don't understand why detaching a child process on Linux/Unix would >> make IPC stop working. Can somebody explain? >> > It is implemented with shared memory. I think (although I'm not 100% > sure) that shared memory is created *and freed up* (shm_unlink() > system call) by the parent process. It makes sense, because the child > processes will surely die with the parent. If you detach a child > process, then it won't be killed with its original parent. But the > shared memory will be freed by the original parent process anyway. I > suspect that the child that has mapped that shared memory segment will > try to access a freed up resource, do a segfault or something similar. So detaching the child process will not make IPC stop working. But exiting from the original parent process will. (And why else would you detach the child?) From chris at simplistix.co.uk Wed Aug 1 11:01:56 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 01 Aug 2012 16:01:56 +0100 Subject: xlrd 0.8.0 released! Message-ID: <501944E4.2090902@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.8.0: http://pypi.python.org/pypi/xlrd/0.8.0 This release finally lands the support for both .xls and .xlsx files. Many thanks to John Machin for all his work on making this happen. Opening of .xlsx files is seamless, just use xlrd as you did before and it all should "just work". xlrd 0.8.0 is also the first release that that targets Python 2.6 and 2.7, but no Python 3 just yet. Python 2.5 and below may work but are not supported. If you need to use Python 2.5 or earlier, please stick to xlrd 0.7.x. Speaking of xlrd 0.7.x, that's now in "requested maintenance only" mode ;-) That means, if possible, use 0.8.x. If you have a really good reason for sticking with 0.7.x, and you find a bug that you can't work around, then please make this clear on the python-excel at googlegroups.com and we'll see what we can do. If you find any problems, please ask about them on the list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From matthew.smith at g2-inc.com Wed Aug 1 11:06:48 2012 From: matthew.smith at g2-inc.com (Matthew Smith) Date: Wed, 1 Aug 2012 11:06:48 -0400 Subject: [pyxl] xlrd 0.8.0 released! In-Reply-To: <501944E4.2090902@simplistix.co.uk> References: <501944E4.2090902@simplistix.co.uk> Message-ID: Thank you guys so much! I am so excited to finally have xlsx so my users don't have extra steps! On Wed, Aug 1, 2012 at 11:01 AM, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlrd 0.8.0: > > http://pypi.python.org/pypi/**xlrd/0.8.0 > > This release finally lands the support for both .xls and .xlsx files. > Many thanks to John Machin for all his work on making this happen. > Opening of .xlsx files is seamless, just use xlrd as you did before and it > all should "just work". > > xlrd 0.8.0 is also the first release that that targets Python 2.6 and 2.7, > but no Python 3 just yet. Python 2.5 and below may work but are not > supported. If you need to use Python 2.5 or earlier, please stick to xlrd > 0.7.x. > > Speaking of xlrd 0.7.x, that's now in "requested maintenance only" mode > ;-) That means, if possible, use 0.8.x. If you have a really good reason > for sticking with 0.7.x, and you find a bug that you can't work around, > then please make this clear on the python-excel at googlegroups.com and > we'll see what we can do. > > If you find any problems, please ask about them on the list, or submit an > issue on GitHub: > > https://github.com/python-**excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > You received this message because you are subscribed to the Google Groups > "python-excel" group. > To post to this group, send an email to python-excel at googlegroups.com. > To unsubscribe from this group, send email to python-excel+unsubscribe@** > googlegroups.com . > For more options, visit this group at http://groups.google.com/** > group/python-excel?hl=en-GB > . > > -- Matthew Smith Software Engineer at G2, Inc Follow us on Twitter @G2_inc -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Wed Aug 1 11:24:43 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 16:24:43 +0100 Subject: Pass data to a subprocess In-Reply-To: <50194064.9050906@shopzeus.com> References: <5017EFB0.6080608@shopzeus.com> <50193DE4.3030404@shopzeus.com> <50194064.9050906@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : > > So detaching the child process will not make IPC stop working. But exiting > from the original parent process will. (And why else would you detach the > child?) > > -- > http://mail.python.org/mailman/listinfo/python-list Well it makes perfect sense if it stops working to me, so or - I use zeromq or something similar to communicate - I make every process independent without the need to further communicate with the parent.. From ramit.prasad at jpmorgan.com Wed Aug 1 11:26:40 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 1 Aug 2012 15:26:40 +0000 Subject: why the different output in Eclipse and Python Shell? In-Reply-To: <5018FFEF.3000203@davea.name> References: <5018FFEF.3000203@davea.name> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741659B48C@SCACMX008.exchad.jpmchase.net> > > my code in Eclipse: > > > > dict.fromkeys(['China','America']) > > print "dict is",dict > > > > output: dict is > > > > my code in Python Shell: > > > > dict.fromkeys(['China','America']) > > > > output:{'America': None, 'China': None} > > > > Output in Python Shell is what i wanna,but why not in Eclipse? > > > > > > The Python Shell is an interactive debugger, and prints the repr() of > expressions that you don't assign anywhere. I don't know Eclipse, but I > suspect what you want to do is something like: > > print "dict is", repr(dict) I think you mean print "dict is", repr(dict.fromkeys(['China','America'])) Otherwise you are just printing the repr of the dict type and not the dictionary created. I would really store the output and then print it. d = dict.fromkeys(['China','America']) print "dict is", d Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Wed Aug 1 11:31:20 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 1 Aug 2012 15:31:20 +0000 Subject: EXTERNAL: Re: missing python-config and building python on Windows In-Reply-To: <5019175F.8010404@lmco.com> References: <50187CF7.3080706@clear.net> <5018A755.60609@gmail.com> <5019175F.8010404@lmco.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741659B4D9@SCACMX008.exchad.jpmchase.net> > On 7/31/2012 11:49 PM, Mark Hammond wrote: > > On 1/08/2012 10:48 AM, Damon Register wrote: > >> 1. though I have looked in a few readme files, I don't see instructions for > >> installing what I have just built using MSVC. Where can I find the > >> instructions for installing after building with MSVC? > > > > There is no such process. In general, you can just run directly from the > built tree. > That is a bummer. That makes me more curious about how the Windows > installer was made and how all the pieces were gathered together. > > > I'm afraid I don't know what python-config is. It appears it might be a > reflection of how Python > > was configured and build on *nix systems - if that is the case then it is > expected that one does not > > exist for Windows (as it doesn't use the *nix build chain). > which means, I guess, that mingw is barely supported if at all. > While it may be Windows, mingw/msys is a nice way to build many > programs that are unix oriented. I suppose that just for fun I > should try to build python on SuSE to see how it goes. > > >> 3. It seems that MSVC doesn't produce the .a library files needed for > >> linking > >> into a mingw built program. Do I have to do that fun trick to > >> create the > >> .a from the dll? > > > > I'm surprised MSVC *can* build .a files for mingw - but AFAIK, even if MSVC > could do that, I believe > > Python makes no attempt to build with support for linking into mingw > programs. > I don't know that MSVC can do this. The only process of which I am aware is a > two step process using pexports and dlltool to generate the .a file from a > dll. > One reason I was using the python.org installer is that it already had the > python27.a file. Now I am even more curious about what was used to build > python > and create that installer. > > The python.org installer provided all I needed for build most python dependent > apps with mingw until I ran into one that needed python-config. I suppose > that > if python-config does what I suspect it does (produce cflags and ldflags as > does pkg-config) then perhaps I could just fake it by replacing use of > python-config with what the cflags and ldflags should be for where I have > python. I have no knowledge about building Python but does this help? http://wiki.python.org/moin/Building%20Python%20with%20the%20free%20MS%20C%20Toolkit Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Wed Aug 1 11:53:40 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 01 Aug 2012 08:53:40 -0700 Subject: NameError vs AttributeError In-Reply-To: References: Message-ID: <50195104.108@stoneleaf.us> Terry Reedy wrote: > On 7/31/2012 4:49 PM, Chris Kaynor wrote: >> On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy wrote: >>> Another example: KeyError and IndexError are both subscript errors, >>> but there is no SubscriptError superclass, even though both work >>> thru the same mechanism -- __getitem__. The reason is that there is >>> no need for one. In 'x[y]', x is usually intented to be either a >>> sequence or mapping, but not possibly both. In the rare cases when >>> one wants to catch both errors, one can easily enough. To continue >>> the example above, popping an empty list and empty set produce >>> IndexError and KeyError respectively: >>> >>> try: >>> while True: >>> process(pop()) >>> except (KeyError, IndexError): >>> pass # empty collection means we are done >>> >> There is a base type for KeyError and IndexError: LookupError. >> >> http://docs.python.org/library/exceptions.html#exception-hierarchy > > Oh, so there is. Added in 1.5 strictly as a never-directly-raised base > class for the above pair, now also directly raised in codecs.lookup. I > have not decided if I want to replace the tuple in the code in my book. I think I'd stick with the tuple -- LookupError could just as easily encompass NameError and AttributeError. From steve+comp.lang.python at pearwood.info Wed Aug 1 12:17:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Aug 2012 16:17:44 GMT Subject: CRC-checksum failed in gzip References: <50190ED6.1040100@shopzeus.com> Message-ID: <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Aug 2012 14:01:45 +0100, andrea crotti wrote: > Full traceback: > > Exception in thread Thread-8: "DANGER DANGER DANGER WILL ROBINSON!!!" Why didn't you say that there were threads involved? That puts a completely different perspective on the problem. I *was* going to write back and say that you probably had either file system corruption, or network errors. But now that I can see that you have threads, I will revise that and say that you probably have a bug in your thread handling code. I must say, Andrea, your initial post asking for help was EXTREMELY misleading. You over-simplified the problem to the point that it no longer has any connection to the reality of the code you are running. Please don't send us on wild goose chases after bugs in code that you aren't actually running. > there seems to be no clear pattern and just randmoly fails. When you start using threads, you have to expect these sorts of intermittent bugs unless you are very careful. My guess is that you have a bug where two threads read from the same file at the same time. Since each read shares state (the position of the file pointer), you're going to get corruption. Because it depends on timing details of which threads do what at exactly which microsecond, the effect might as well be random. Example: suppose the file contains three blocks A B and C, and a checksum. Thread 8 starts reading the file, and gets block A and B. Then thread 2 starts reading it as well, and gets half of block C. Thread 8 gets the rest of block C, calculates the checksum, and it doesn't match. I recommend that you run a file system check on the remote disk. If it passes, you can eliminate file system corruption. Also, run some network diagnostics, to eliminate corruption introduced in the network layer. But I expect that you won't find anything there, and the problem is a simple thread bug. Simple, but really, really hard to find. Good luck. -- Steven From andrea.crotti.0 at gmail.com Wed Aug 1 12:38:56 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 17:38:56 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2012/8/1 Steven D'Aprano : > On Wed, 01 Aug 2012 14:01:45 +0100, andrea crotti wrote: > >> Full traceback: >> >> Exception in thread Thread-8: > > "DANGER DANGER DANGER WILL ROBINSON!!!" > > Why didn't you say that there were threads involved? That puts a > completely different perspective on the problem. > > I *was* going to write back and say that you probably had either file > system corruption, or network errors. But now that I can see that you > have threads, I will revise that and say that you probably have a bug in > your thread handling code. > > I must say, Andrea, your initial post asking for help was EXTREMELY > misleading. You over-simplified the problem to the point that it no > longer has any connection to the reality of the code you are running. > Please don't send us on wild goose chases after bugs in code that you > aren't actually running. > > >> there seems to be no clear pattern and just randmoly fails. > > When you start using threads, you have to expect these sorts of > intermittent bugs unless you are very careful. > > My guess is that you have a bug where two threads read from the same file > at the same time. Since each read shares state (the position of the file > pointer), you're going to get corruption. Because it depends on timing > details of which threads do what at exactly which microsecond, the effect > might as well be random. > > Example: suppose the file contains three blocks A B and C, and a > checksum. Thread 8 starts reading the file, and gets block A and B. Then > thread 2 starts reading it as well, and gets half of block C. Thread 8 > gets the rest of block C, calculates the checksum, and it doesn't match. > > I recommend that you run a file system check on the remote disk. If it > passes, you can eliminate file system corruption. Also, run some network > diagnostics, to eliminate corruption introduced in the network layer. But > I expect that you won't find anything there, and the problem is a simple > thread bug. Simple, but really, really hard to find. > > Good luck. > Thanks a lot, that makes a lot of sense.. I haven't given this detail before because I didn't write this code, and I forgot that there were threads involved completely, I'm just trying to help to fix this bug. Your explanation makes a lot of sense, but it's still surprising that even just reading files without ever writing them can cause troubles using threads :/ From tjreedy at udel.edu Wed Aug 1 12:59:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Aug 2012 12:59:32 -0400 Subject: NameError vs AttributeError In-Reply-To: <50195104.108@stoneleaf.us> References: <50195104.108@stoneleaf.us> Message-ID: On 8/1/2012 11:53 AM, Ethan Furman wrote: > Terry Reedy wrote: >> On 7/31/2012 4:49 PM, Chris Kaynor wrote: >>> On Tue, Jul 31, 2012 at 1:21 PM, Terry Reedy wrote: >>>> one wants to catch both errors, one can easily enough. To continue >>>> the example above, popping an empty list and empty set produce >>>> IndexError and KeyError respectively: >>>> >>>> try: >>>> while True: >>>> process(pop()) >>>> except (KeyError, IndexError): >>>> pass # empty collection means we are done >>>> >>> There is a base type for KeyError and IndexError: LookupError. >>> >>> http://docs.python.org/library/exceptions.html#exception-hierarchy >> >> Oh, so there is. Added in 1.5 strictly as a never-directly-raised base >> class for the above pair, now also directly raised in codecs.lookup. I >> have not decided if I want to replace the tuple in the code in my book. > > I think I'd stick with the tuple -- LookupError could just as easily > encompass NameError and AttributeError. Thank you. Having to remember exactly which lookup error is encompassed by LookupError illustrates my point about the cost of adding entities without necessity. It also illustrates the importance of carefull naming. SubscriptError might have been better. -- Terry Jan Reedy From gandalf at shopzeus.com Wed Aug 1 13:05:11 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 19:05:11 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501961C7.1050405@shopzeus.com> > Thanks a lot, that makes a lot of sense.. I haven't given this detail > before because I didn't write this code, and I forgot that there were > threads involved completely, I'm just trying to help to fix this bug. > > Your explanation makes a lot of sense, but it's still surprising that > even just reading files without ever writing them can cause troubles > using threads :/ Make sure that file objects are not shared between threads. If that is possible. It will probably solve the problem (if that is related to threads). From tjreedy at udel.edu Wed Aug 1 13:09:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Aug 2012 13:09:18 -0400 Subject: EXTERNAL: Re: missing python-config and building python on Windows In-Reply-To: <5019175F.8010404@lmco.com> References: <50187CF7.3080706@clear.net> <5018A755.60609@gmail.com> <5019175F.8010404@lmco.com> Message-ID: On 8/1/2012 7:47 AM, Damon Register wrote: > On 7/31/2012 11:49 PM, Mark Hammond wrote: >> On 1/08/2012 10:48 AM, Damon Register wrote: >>> 1. though I have looked in a few readme files, I don't see >>> instructions for >>> installing what I have just built using MSVC. Where can I find the >>> instructions for installing after building with MSVC? >> >> There is no such process. In general, you can just run directly from >> the built tree. > That is a bummer. That makes me more curious about how the Windows > installer was made and how all the pieces were gathered together. All I know is that the Windows installer is a .msi file created by a script that uses msilib. I don't know whether that script is in the repository. -- Terry Jan Reedy From andrea.crotti.0 at gmail.com Wed Aug 1 13:17:56 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 1 Aug 2012 18:17:56 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <501961C7.1050405@shopzeus.com> References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501961C7.1050405@shopzeus.com> Message-ID: 2012/8/1 Laszlo Nagy : > >> Thanks a lot, that makes a lot of sense.. I haven't given this detail >> before because I didn't write this code, and I forgot that there were >> threads involved completely, I'm just trying to help to fix this bug. >> >> Your explanation makes a lot of sense, but it's still surprising that >> even just reading files without ever writing them can cause troubles >> using threads :/ > > Make sure that file objects are not shared between threads. If that is > possible. It will probably solve the problem (if that is related to > threads). Well I just have to create a lock I guess right? with lock: # open file # read content From gandalf at shopzeus.com Wed Aug 1 13:57:19 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 01 Aug 2012 19:57:19 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501961C7.1050405@shopzeus.com> Message-ID: <50196DFF.8090206@shopzeus.com> >> Make sure that file objects are not shared between threads. If that is >> possible. It will probably solve the problem (if that is related to >> threads). > > Well I just have to create a lock I guess right? That is also a solution. You need to call file.read() inside an acquired lock. > with lock: > # open file > # read content > But not that way! Your example will keep the lock acquired for the lifetime of the file, so it cannot be shared between threads. More likely: ## Open file lock = threading.Lock() fin = gzip.open(file_path...) # Now you can share the file object between threads. # and do this inside any thread: ## data needed. block until the file object becomes usable. with lock: data = fin.read(....) # other threads are blocked while I'm reading ## use your data here, meanwhile other threads can read From davea at dejaviewphoto.com Wed Aug 1 14:42:16 2012 From: davea at dejaviewphoto.com (Dave Angel) Date: Wed, 01 Aug 2012 14:42:16 -0400 Subject: why the different output in Eclipse and Python Shell? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741659B48C@SCACMX008.exchad.jpmchase.net> References: <5018FFEF.3000203@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659B48C@SCACMX008.exchad.jpmchase.net> Message-ID: <50197888.3050400@dejaviewphoto.com> On 08/01/2012 11:26 AM, Prasad, Ramit wrote: >>> my code in Eclipse: >>> >>> dict.fromkeys(['China','America']) >>> print "dict is",dict >>> >>> output: dict is >>> >>> my code in Python Shell: >>> >>> dict.fromkeys(['China','America']) >>> >>> output:{'America': None, 'China': None} >>> >>> Output in Python Shell is what i wanna,but why not in Eclipse? >>> >>> >> The Python Shell is an interactive debugger, and prints the repr() of >> expressions that you don't assign anywhere. I don't know Eclipse, but I >> suspect what you want to do is something like: >> >> print "dict is", repr(dict) > I think you mean > print "dict is", repr(dict.fromkeys(['China','America'])) > > Otherwise you are just printing the repr of the dict type > and not the dictionary created. I would really store the output and > then print it. > > d = dict.fromkeys(['China','America']) > print "dict is", d > > Ramit > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. Absolutely right. I meant to refer to the name bound to the dict, not the dict class itself. From roy at panix.com Wed Aug 1 15:07:18 2012 From: roy at panix.com (Roy Smith) Date: Wed, 1 Aug 2012 15:07:18 -0400 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <7A59DAEE-B2B0-49F7-9672-F48FF6DFA58A@panix.com> On Aug 1, 2012, at 9:25 AM, andrea crotti wrote: > [beanstalk] does look nice and I would like to have something like that.. > But since I have to convince my boss of another external dependency I > think it might be worth > to try out zeromq instead, which can also do similar things and looks > more powerful, what do you think? I'm afraid I have no experience with zeromq, so I can't offer an opinion. -- Roy Smith roy at panix.com From invalid at invalid.invalid Wed Aug 1 15:48:16 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 1 Aug 2012 19:48:16 +0000 (UTC) Subject: Pass data to a subprocess References: <5017EFB0.6080608@shopzeus.com> Message-ID: On 2012-08-01, Laszlo Nagy wrote: > >>>> things get more tricky, because I can't use queues and pipes to >>>> communicate with a running process that it's noit my child, correct? >>>> >>> Yes, I think that is correct. >> I don't understand why detaching a child process on Linux/Unix would >> make IPC stop working. Can somebody explain? > > It is implemented with shared memory. I think (although I'm not 100% > sure) that shared memory is created *and freed up* (shm_unlink() system > call) by the parent process. It makes sense, because the child processes > will surely die with the parent. If you detach a child process, then it > won't be killed with its original parent. But the shared memory will be > freed by the original parent process anyway. I suspect that the child > that has mapped that shared memory segment will try to access a freed up > resource, do a segfault or something similar. I still don't get it. shm_unlink() works the same way unlink() does. The resource itself doesn't cease to exist until all open file handles are closed. From the shm_unlink() man page on Linux: The operation of shm_unlink() is analogous to unlink(2): it removes a shared memory object name, and, once all processes have unmapped the object, de-allocates and destroys the contents of the associated memory region. After a successful shm_unlink(), attempts to shm_open() an object with the same name will fail (unless O_CREAT was specified, in which case a new, distinct object is created). Even if the parent calls shm_unlink(), the shared-memory resource will continue to exist (and be usable) until all processes that are holding open file handles unmap/close them. So not only will detached children not crash, they'll still be able to use the shared memory objects to talk to each other. -- Grant Edwards grant.b.edwards Yow! Why is it that when at you DIE, you can't take gmail.com your HOME ENTERTAINMENT CENTER with you?? From livingstonemark at gmail.com Wed Aug 1 22:15:20 2012 From: livingstonemark at gmail.com (Mark Livingstone) Date: Thu, 2 Aug 2012 12:15:20 +1000 Subject: [Pythonmac-SIG] Py2app error In-Reply-To: References: <1B26E03E-9503-49F6-9D12-EDE83E001E6B@mac.com> Message-ID: Hi Guys, OK, taking Chris' advice, I installed on a Snow Leopard machine: cheyenne:dist marklivingstone$ ls ~/Downloads/ About Downloads.lpdf numpy-1.6.2-py2.7-python.org-macosx10.3.dmg wxMac-2.8.12.tar matplotlib-1.1.0-py2.7-python.org-macosx10.3.dmg python-2.7.3-macosx10.6.dmg wxPython2.8-osx-docs-demos-2.8.12.1-universal-py2.7.dmg mercurial-2.2.3_20120707-py2.7-macosx10.7 scipy-0.11.0rc1-py2.7-python.org-macosx10.6.dmg wxPython2.8-osx-unicode-2.8.12.1-universal-py2.7.dmg Then I went to Ronald's Bitbucket and built a current py2app setup. I tried a build but got this: python ../mac-setup/setup_py2app.py py2app Traceback (most recent call last): File "../mac-setup/setup_py2app.py", line 1, in import wx File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/__init__.py", line 45, in from wx._core import * File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 4, in import _core_ ImportError: dlopen(/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core_.so, 2): no suitable image found. Did find: /usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core_.so: no matching architecture in universal wrapper cheyenne:src marklivingstone$ I then did "python-32 ../mac-setup/setup_py2app.py py2app" , and built using py2app my Salstat.app which built fine and created a dist/Salstat.app However, when I try to run the app, I get the following in the console log: 2/08/12 12:06:23.340 PM [0x0-0x421421].com.SalStat.SalStat: /Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/salstat.py:585: SyntaxWarning: import * only allowed at module level 2/08/12 12:06:23.372 PM [0x0-0x421421].com.SalStat.SalStat: argvemulator warning: fetching events failed 2/08/12 12:06:23.372 PM [0x0-0x421421].com.SalStat.SalStat: Traceback (most recent call last): 2/08/12 12:06:23.372 PM [0x0-0x421421].com.SalStat.SalStat: File "/Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/__boot__.py", line 319, in 2/08/12 12:06:23.373 PM [0x0-0x421421].com.SalStat.SalStat: _run('salstat.py') 2/08/12 12:06:23.373 PM [0x0-0x421421].com.SalStat.SalStat: File "/Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/__boot__.py", line 311, in _run 2/08/12 12:06:23.374 PM [0x0-0x421421].com.SalStat.SalStat: exec(compile(source, path, 'exec'), globals(), globals()) 2/08/12 12:06:23.374 PM [0x0-0x421421].com.SalStat.SalStat: File "/Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/salstat.py", line 9, in 2/08/12 12:06:23.374 PM [0x0-0x421421].com.SalStat.SalStat: import wx 2/08/12 12:06:23.374 PM [0x0-0x421421].com.SalStat.SalStat: File "wx/__init__.pyc", line 45, in 2/08/12 12:06:23.374 PM [0x0-0x421421].com.SalStat.SalStat: File "wx/_core.pyc", line 4, in 2/08/12 12:06:23.375 PM [0x0-0x421421].com.SalStat.SalStat: File "wx/_core_.pyc", line 18, in 2/08/12 12:06:23.375 PM [0x0-0x421421].com.SalStat.SalStat: File "wx/_core_.pyc", line 11, in __load 2/08/12 12:06:23.375 PM [0x0-0x421421].com.SalStat.SalStat: ImportError: dlopen(/Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/lib/python2.7/lib-dynload/wx/_core_.so, 2): no suitable image found. Did find: 2/08/12 12:06:23.375 PM [0x0-0x421421].com.SalStat.SalStat: /Users/marklivingstone/Documents/workspace/salstat-statistics-package-2/src/dist/SalStat.app/Contents/Resources/lib/python2.7/lib-dynload/wx/_core_.so: no matching architecture in universal wrapper 2/08/12 12:06:23.479 PM SalStat: SalStat Error 2/08/12 12:06:25.919 PM com.apple.launchd.peruser.501: ([0x0-0x421421].com.SalStat.SalStat[76293]) Exited with code: 255 Is it just not possible to use py2app to create an app for the Mac based on wx? Also, the final result turns in at 184MB in size. Are there any common things that may be being pulled in that I should exclude? Thanks in advance, MarkL From bouncingcats at gmail.com Wed Aug 1 23:10:38 2012 From: bouncingcats at gmail.com (David) Date: Thu, 2 Aug 2012 13:10:38 +1000 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 01/08/2012, Stefan Behnel wrote: > > Would you mind taking this slightly off-topic discussion off the list? I always strive to stay on-topic. In fact immediately this thread went off topic, 4 messages back, I did try to go off list, but got this result from the OP: Delivery to the following recipient failed permanently: lipska at yahoo.co.uk Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 554 554 delivery error: dd This user doesn't have a yahoo.co.uk account (lipska at yahoo.co.uk) [-5] - mta1050.mail.ukl.yahoo.com (state 17). Date: Wed, 1 Aug 2012 09:31:43 +1000 Subject: Re: Is Python a commercial proposition ? From: David To: lipska the kat Then, if someone is going to call me an ignoramus on a public list, they will receive a response in the same forum. So, I apologise to the list, but please note the unusual circumstances. Thanks. From gandalf at shopzeus.com Thu Aug 2 02:10:59 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 02 Aug 2012 08:10:59 +0200 Subject: Pass data to a subprocess In-Reply-To: References: <5017EFB0.6080608@shopzeus.com> Message-ID: <501A19F3.5040201@shopzeus.com> > I still don't get it. shm_unlink() works the same way unlink() does. > The resource itself doesn't cease to exist until all open file handles > are closed. From the shm_unlink() man page on Linux: > > The operation of shm_unlink() is analogous to unlink(2): it > removes a shared memory object name, and, once all processes > have unmapped the object, de-allocates and destroys the > contents of the associated memory region. After a successful > shm_unlink(), attempts to shm_open() an object with the same > name will fail (unless O_CREAT was specified, in which case a > new, distinct object is created). > > Even if the parent calls shm_unlink(), the shared-memory resource will > continue to exist (and be usable) until all processes that are holding > open file handles unmap/close them. So not only will detached > children not crash, they'll still be able to use the shared memory > objects to talk to each other. > I stand corrected. It should still be examined, what kind shared memory is used under non-linux systems. System V on AIX? And what about Windows? So maybe the general answer is still no. But I guess that the OP wanted this to work on a specific system. Dear Andrea Crotti! Please try to detach two child processes, exit from the main process, and communicate over a multiprocessing queue. It will possibly work. Sorry for my bad advice. From breamoreboy at yahoo.co.uk Thu Aug 2 04:09:09 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 02 Aug 2012 09:09:09 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 02/08/2012 04:10, David wrote: > On 01/08/2012, Stefan Behnel wrote: >> >> Would you mind taking this slightly off-topic discussion off the list? > > I always strive to stay on-topic. In fact immediately this thread went > off topic, 4 messages back, I did try to go off list, but got this > result from the OP: > > Delivery to the following recipient failed permanently: > lipska at yahoo.co.uk > Technical details of permanent failure: > Google tried to deliver your message, but it was rejected by the > recipient domain. We recommend contacting the other email provider for > further information about the cause of this error. The error that the > other server returned was: 554 554 delivery error: dd This user > doesn't have a yahoo.co.uk account (lipska at yahoo.co.uk) [-5] - > mta1050.mail.ukl.yahoo.com (state 17). > Date: Wed, 1 Aug 2012 09:31:43 +1000 > Subject: Re: Is Python a commercial proposition ? > From: David > To: lipska the kat > > Then, if someone is going to call me an ignoramus on a public list, > they will receive a response in the same forum. > > So, I apologise to the list, but please note the unusual circumstances. Thanks. > I'm in stuck record mode here, but one of the things I really enjoy about reading here is the way things do go off topic. IMHO makes for a far more interesting experience. YMMV. -- Cheers. Mark Lawrence. From lipskathekat at yahoo.co.uk Thu Aug 2 04:17:35 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 02 Aug 2012 09:17:35 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: On 02/08/12 04:10, David wrote: > On 01/08/2012, Stefan Behnel wrote: >> >> Would you mind taking this slightly off-topic discussion off the list? > > I always strive to stay on-topic. In fact immediately this thread went > off topic, 4 messages back, I did try to go off list, but got this > result from the OP: > > Delivery to the following recipient failed permanently: > lipska at yahoo.co.uk snip This is my fault, I set the reply to address incorrectly. You HAVE corresponded successfully with me in the past however... I apologise for the inconvenience. JFTR I did not call you an ignoramus (it's a funny word though isn't it, makes me smile anyway). lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From ulrich.eckhardt at dominolaser.com Thu Aug 2 04:49:07 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 02 Aug 2012 10:49:07 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501961C7.1050405@shopzeus.com> Message-ID: <3hrpe9-hbi.ln1@satorlaser.homedns.org> Am 01.08.2012 19:57, schrieb Laszlo Nagy: > ## Open file > lock = threading.Lock() > fin = gzip.open(file_path...) > # Now you can share the file object between threads. > > # and do this inside any thread: > ## data needed. block until the file object becomes usable. > with lock: > data = fin.read(....) # other threads are blocked while I'm reading > ## use your data here, meanwhile other threads can read Technically, that is correct, but IMHO its complete nonsense to share the file object between threads in the first place. If you need the data in two threads, just read the file once and then share the read-only, immutable content. If the file is small or too large to be held in memory at once, just open and read it on demand. This also saves you from having to rewind the file every time you read it. Am I missing something? Uli From rahul03535 at gmail.com Thu Aug 2 04:57:27 2012 From: rahul03535 at gmail.com (rahul) Date: Thu, 2 Aug 2012 01:57:27 -0700 (PDT) Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Message-ID: I am implementing a C extension module, during this I saw that when I set the global error indicator and error message through PyErr_SetString() API and return false. But it doesn't throw any error when I tried to check the error through sys.exc_info() then it returns (NULL, NULL, NULL) tuple. When I return NULL through the C extension module's function then it works correctly and throws the exception as expected. The skeleton looks like: static PyObject* check(PyObject* sef, PyObject* args) { PyObject* input = NULL; if (!PyArg_ParseTuple(args, "O", &input)){ return NULL; } ..... ..... PyErr_SetString(PyExc_Exception, "Throwing Error through check function"); Py_RETURN_FALSE; } Any idea on why this is happening? Any help will be appreciated. Thanks, Rahul From mail at timgolden.me.uk Thu Aug 2 05:06:29 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 02 Aug 2012 10:06:29 +0100 Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: <501A4315.1030101@timgolden.me.uk> On 02/08/2012 09:57, rahul wrote: > I am implementing a C extension module, during this I saw that when I > set the global error indicator and error message through > PyErr_SetString() API and return false. > > But it doesn't throw any error when I tried to check the error > through sys.exc_info() then it returns (NULL, NULL, NULL) tuple. > > When I return NULL through the C extension module's function then it > works correctly and throws the exception as expected. > > The skeleton looks like: > > static PyObject* check(PyObject* sef, PyObject* args) { PyObject* > input = NULL; if (!PyArg_ParseTuple(args, "O", &input)){ return > NULL; } ..... ..... PyErr_SetString(PyExc_Exception, "Throwing Error > through check function"); Py_RETURN_FALSE; } > > Any idea on why this is happening? Any help will be appreciated. Because you're returning False. You should be returning NULL. Which is why it works when you do :) Have a look at the first line of this page: http://docs.python.org/py3k/extending/extending.html#intermezzo-errors-and-exceptions Which piece of documentation led you to think that returning False was the thing to do here? Perhaps there's a doc that needs fixing? TJG From rahul03535 at gmail.com Thu Aug 2 05:21:28 2012 From: rahul03535 at gmail.com (rahul) Date: Thu, 2 Aug 2012 02:21:28 -0700 (PDT) Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: Hi TJG, The above link also doesn't strictly said that return value should be NULL only, it only said that usually NULL pointer used. No where I saw that it is nessasory t At http://docs.python.org/c-api/exceptions.html. it is written that "Most functions also return an error indicator, usually NULL if they are supposed to return a pointer, or -1 if they return an integer (exception: the PyArg_*() functions return 1 for success and 0 for failure)." this also told that usually NULL is used but we can change the return error indicator to any value. As like PyArg_*() used 0 for error value. Thanks, Rahul From rahul03535 at gmail.com Thu Aug 2 05:21:28 2012 From: rahul03535 at gmail.com (rahul) Date: Thu, 2 Aug 2012 02:21:28 -0700 (PDT) Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: Hi TJG, The above link also doesn't strictly said that return value should be NULL only, it only said that usually NULL pointer used. No where I saw that it is nessasory t At http://docs.python.org/c-api/exceptions.html. it is written that "Most functions also return an error indicator, usually NULL if they are supposed to return a pointer, or -1 if they return an integer (exception: the PyArg_*() functions return 1 for success and 0 for failure)." this also told that usually NULL is used but we can change the return error indicator to any value. As like PyArg_*() used 0 for error value. Thanks, Rahul From andrea.crotti.0 at gmail.com Thu Aug 2 05:26:51 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 2 Aug 2012 10:26:51 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2012/8/1 Steven D'Aprano : > > When you start using threads, you have to expect these sorts of > intermittent bugs unless you are very careful. > > My guess is that you have a bug where two threads read from the same file > at the same time. Since each read shares state (the position of the file > pointer), you're going to get corruption. Because it depends on timing > details of which threads do what at exactly which microsecond, the effect > might as well be random. > > Example: suppose the file contains three blocks A B and C, and a > checksum. Thread 8 starts reading the file, and gets block A and B. Then > thread 2 starts reading it as well, and gets half of block C. Thread 8 > gets the rest of block C, calculates the checksum, and it doesn't match. > > I recommend that you run a file system check on the remote disk. If it > passes, you can eliminate file system corruption. Also, run some network > diagnostics, to eliminate corruption introduced in the network layer. But > I expect that you won't find anything there, and the problem is a simple > thread bug. Simple, but really, really hard to find. > > Good luck. One last thing I would like to do before I add this fix is to actually be able to reproduce this behaviour, and I thought I could just do the following: import gzip import threading class OpenAndRead(threading.Thread): def run(self): fz = gzip.open('out2.txt.gz') fz.read() fz.close() if __name__ == '__main__': for i in range(100): OpenAndRead().start() But no matter how many threads I start, I can't reproduce the CRC error, any idea how I can try to help it happening? The code in run should be shared by all the threads since there are no locks, right? From mail at timgolden.me.uk Thu Aug 2 05:37:08 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 02 Aug 2012 10:37:08 +0100 Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: <501A4A44.8060807@timgolden.me.uk> On 02/08/2012 10:21, rahul wrote: > > Hi TJG, > > The above link also doesn't strictly said that return value should be > NULL only, it only said that usually NULL pointer used. No where I > saw that it is nessasory t > > At http://docs.python.org/c-api/exceptions.html. it is written that > "Most functions also return an error indicator, usually NULL if they > are supposed to return a pointer, or -1 if they return an integer > (exception: the PyArg_*() functions return 1 for success and 0 for > failure)." this also told that usually NULL is used but we can change > the return error indicator to any value. As like PyArg_*() used 0 for > error value. The docs you quote are very slightly confusing because they're combining the standard practice (return NULL), the uncommon alternative (return -1) and a few special cases present in the core functions. In short, any function you expose in an extension module will be returning a PyObject* and should return NULL if it is setting or cascading an exception. I'm not convinced that the docs need altering here: this is the first time I've come across anyone who was confused. But if you think some different wording might help, feel free to propose something. TJG From ulrich.eckhardt at dominolaser.com Thu Aug 2 05:49:27 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 02 Aug 2012 11:49:27 +0200 Subject: consistent input() for Python 2 and 3 Message-ID: <72vpe9-kki.ln1@satorlaser.homedns.org> Hi! I'm trying to write some code that should work with both Python 2 and 3. One of the problems there is that the input() function has different meanings, I just need the raw_input() behaviour of Python 2. My approach is to simply do this: try: # redirect input() to raw_input() like Python 3 input = raw_input except NameError: # no raw input, probably running Python 3 already pass What do you think? Any better alternatives? Uli From rahul03535 at gmail.com Thu Aug 2 05:50:21 2012 From: rahul03535 at gmail.com (rahul) Date: Thu, 2 Aug 2012 02:50:21 -0700 (PDT) Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this like below code: ... ... b = None try: a = testModule.check(None) except: b = sys.exc_info() then code execution doesn't come to except block. But when I add one statement after calling check function then code execution goes into except block. ... ... b = None try: a = testModule.check(None) print( a ) except: b = sys.exc_info() On Thursday, 2 August 2012 15:07:08 UTC+5:30, Tim Golden wrote: > On 02/08/2012 10:21, rahul wrote: > > > > > > Hi TJG, > > > > > > The above link also doesn't strictly said that return value should be > > > NULL only, it only said that usually NULL pointer used. No where I > > > saw that it is nessasory t > > > > > > At http://docs.python.org/c-api/exceptions.html. it is written that > > > "Most functions also return an error indicator, usually NULL if they > > > are supposed to return a pointer, or -1 if they return an integer > > > (exception: the PyArg_*() functions return 1 for success and 0 for > > > failure)." this also told that usually NULL is used but we can change > > > the return error indicator to any value. As like PyArg_*() used 0 for > > > error value. > > > > The docs you quote are very slightly confusing because they're combining > > the standard practice (return NULL), the uncommon alternative (return > > -1) and a few special cases present in the core functions. > > > > In short, any function you expose in an extension module will be > > returning a PyObject* and should return NULL if it is setting or > > cascading an exception. > > > > I'm not convinced that the docs need altering here: this is the first > > time I've come across anyone who was confused. But if you think some > > different wording might help, feel free to propose something. > > > > TJG From rahul03535 at gmail.com Thu Aug 2 05:50:21 2012 From: rahul03535 at gmail.com (rahul) Date: Thu, 2 Aug 2012 02:50:21 -0700 (PDT) Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this like below code: ... ... b = None try: a = testModule.check(None) except: b = sys.exc_info() then code execution doesn't come to except block. But when I add one statement after calling check function then code execution goes into except block. ... ... b = None try: a = testModule.check(None) print( a ) except: b = sys.exc_info() On Thursday, 2 August 2012 15:07:08 UTC+5:30, Tim Golden wrote: > On 02/08/2012 10:21, rahul wrote: > > > > > > Hi TJG, > > > > > > The above link also doesn't strictly said that return value should be > > > NULL only, it only said that usually NULL pointer used. No where I > > > saw that it is nessasory t > > > > > > At http://docs.python.org/c-api/exceptions.html. it is written that > > > "Most functions also return an error indicator, usually NULL if they > > > are supposed to return a pointer, or -1 if they return an integer > > > (exception: the PyArg_*() functions return 1 for success and 0 for > > > failure)." this also told that usually NULL is used but we can change > > > the return error indicator to any value. As like PyArg_*() used 0 for > > > error value. > > > > The docs you quote are very slightly confusing because they're combining > > the standard practice (return NULL), the uncommon alternative (return > > -1) and a few special cases present in the core functions. > > > > In short, any function you expose in an extension module will be > > returning a PyObject* and should return NULL if it is setting or > > cascading an exception. > > > > I'm not convinced that the docs need altering here: this is the first > > time I've come across anyone who was confused. But if you think some > > different wording might help, feel free to propose something. > > > > TJG From gandalf at shopzeus.com Thu Aug 2 06:14:14 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 02 Aug 2012 12:14:14 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: <3hrpe9-hbi.ln1@satorlaser.homedns.org> References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501961C7.1050405@shopzeus.com> <3hrpe9-hbi.ln1@satorlaser.homedns.org> Message-ID: <501A52F6.5000709@shopzeus.com> > Technically, that is correct, but IMHO its complete nonsense to share > the file object between threads in the first place. If you need the > data in two threads, just read the file once and then share the > read-only, immutable content. If the file is small or too large to be > held in memory at once, just open and read it on demand. This also > saves you from having to rewind the file every time you read it. > > Am I missing something? We suspect that his program reads the same file object from different threads. At least this would explain his problem. I agree with you - usually it is not a good idea to share a file object between threads. This is what I told him the first time. But it is not in our hands - he already has a program that needs to be fixed. It might be easier for him to protect read() calls with a lock. Because it can be done automatically, without thinking too much. From gandalf at shopzeus.com Thu Aug 2 06:21:24 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 02 Aug 2012 12:21:24 +0200 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501A54A4.4030006@shopzeus.com> > One last thing I would like to do before I add this fix is to actually > be able to reproduce this behaviour, and I thought I could just do the > following: > > import gzip > import threading > > > class OpenAndRead(threading.Thread): > def run(self): > fz = gzip.open('out2.txt.gz') > fz.read() > fz.close() > > > if __name__ == '__main__': > for i in range(100): > OpenAndRead().start() > > > But no matter how many threads I start, I can't reproduce the CRC > error, any idea how I can try to help it happening? Your example did not share the file object between threads. Here an example that does that: class OpenAndRead(threading.Thread): def run(self): global fz fz.read(100) if __name__ == '__main__': fz = gzip.open('out2.txt.gz') for i in range(10): OpenAndRead().start() Try this with a huge file. And here is the one that should never throw CRC error, because the file object is protected by a lock: class OpenAndRead(threading.Thread): def run(self): global fz global fl with fl: fz.read(100) if __name__ == '__main__': fz = gzip.open('out2.txt.gz') fl = threading.Lock() for i in range(2): OpenAndRead().start() > > The code in run should be shared by all the threads since there are no > locks, right? The code is shared but the file object is not. In your example, a new file object is created, every time a thread is started. From shanthulinux at gmail.com Thu Aug 2 06:28:10 2012 From: shanthulinux at gmail.com (Shanth Kumar) Date: Thu, 2 Aug 2012 15:58:10 +0530 Subject: attribute is accessed from Nonetype Message-ID: Hi ,All, I am Shanthkumar. Good to see the mailing list for python programmers. Please find my query below, In my source code in a python file e.g xyz.py couple of classes are defined also there is a wrapper class, a none object is declared in the file e.g temp=None from temp some attributes are being accessed in the files that are importing xyz.py even though temp is not initialised to any other object still it is none object attributes are being accessed from None object.Is there any significance of wrapper class here..? Can you please help me. -- Regards..., Shanthkumara O.D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu Aug 2 06:45:47 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 02 Aug 2012 11:45:47 +0100 Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: <501A5A5B.2020308@timgolden.me.uk> On 02/08/2012 10:50, rahul wrote: > When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this > > like below code: > ... > ... > b = None > try: > a = testModule.check(None) > except: > b = sys.exc_info() > then code execution doesn't come to except block. > But when I add one statement after calling check function then code execution goes into except block. > > ... > ... > b = None > try: > a = testModule.check(None) > print( a ) > except: > b = sys.exc_info() Sounds like you're entering into undefined behaviour. If you set an exception and don't return NULL, you're leaving Python's internals in an inconsistent state. I don't know the internal code paths, but presumably in one version it just ignored the exception state while in the other it noticed it but in a different point in the code at which point it raised the exception. Or something. Long-and-short: return NULL from an extension module function once you've raised (or are cascading) an exception condition. Anything else is undefined unless you know *exactly* what you're doing. TJG From stefan_ml at behnel.de Thu Aug 2 06:54:54 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 02 Aug 2012 12:54:54 +0200 Subject: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() In-Reply-To: References: Message-ID: rahul, 02.08.2012 11:50: > When I use same code base for Python 3.x, then behavior is different. You might want to take a look at Cython. It moves most of these "funny" little details off your shoulders. Stefan From andrea.crotti.0 at gmail.com Thu Aug 2 06:57:06 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 2 Aug 2012 11:57:06 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: <501A54A4.4030006@shopzeus.com> References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501A54A4.4030006@shopzeus.com> Message-ID: 2012/8/2 Laszlo Nagy : > > Your example did not share the file object between threads. Here an example > that does that: > > class OpenAndRead(threading.Thread): > def run(self): > global fz > fz.read(100) > > if __name__ == '__main__': > > fz = gzip.open('out2.txt.gz') > for i in range(10): > OpenAndRead().start() > > Try this with a huge file. And here is the one that should never throw CRC > error, because the file object is protected by a lock: > > class OpenAndRead(threading.Thread): > def run(self): > global fz > global fl > with fl: > fz.read(100) > > if __name__ == '__main__': > > fz = gzip.open('out2.txt.gz') > fl = threading.Lock() > for i in range(2): > OpenAndRead().start() > > >> >> The code in run should be shared by all the threads since there are no >> locks, right? > > The code is shared but the file object is not. In your example, a new file > object is created, every time a thread is started. > Ok sure that makes sense, but then this explanation is maybe not right anymore, because I'm quite sure that the file object is *not* shared between threads, everything happens inside a thread.. I managed to get some errors doing this with a big file class OpenAndRead(threading.Thread): def run(self): global fz fz.read(100) if __name__ == '__main__': fz = gzip.open('bigfile.avi.gz') for i in range(20): OpenAndRead().start() and it doesn't fail without the *global*, but this is definitively not what the code does, because every thread gets a new file object, it's not shared.. Anyway we'll read once for all the threads or add the lock, and hopefully it should solve the problem, even if I'm not convinced yet that it was this. From danielashiloh at googlemail.com Thu Aug 2 06:58:20 2012 From: danielashiloh at googlemail.com (danielashiloh at googlemail.com) Date: Thu, 2 Aug 2012 03:58:20 -0700 (PDT) Subject: Error help Message-ID: Hi all This error has been bugging me for days. I know it's minor, but it's really getting in the way of my programming. I'm programming a data analysis programme for a psychology experiment which takes pickled data from the experiment and produces averages. For some reason python is insisting there is an indentation error on line 18. I have untabified and retabified and nothing seems to work. Here is the full code: import cPickle, pickle print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST' file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ') pickle_file=open(file, 'r') data=cPickle.load(pickle_file) file_name=file-'pck' + 'txt' partifipant_info=data'Participant Info'] first_block_data=data['First block data'] second_block_data=data['Second block data'] first_block_estimates=first_block_data['Estimated times'] first_block_times=first_block_data['Actual times'] second_block_estimates=second_block_data['Estimated times'] second_block_times=second_block_data['Actual times'] def firstBlockDifferences(): print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' count=0 first_block_differences=[] total=0 while count= 180: differences-=360 elif differences <=-180: differences+=360 total+=differences differences=[differences] first_block_differences+=differences count+=1 average_diff_first_block=total/len(first_block_estimates) text_file.write('\nAverage differences for block 1: ', average_diff_first_block) def secondBlockDifferences(): print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2' count=0 second_block_differences=[] total=0 while count= 180: differences-=360 elif differences <=-180: differences+=360 total+=differences differences=[differences] second_block_differences+=differences count+=1 average_diff_second_block=total/len(second_block_estimates) text_file.write('\nAverage differences for block 2: ', average_diff_second_block) text_file=open(file_name, 'w') text_file.write('\nParticipant info: ', participant_info) firstBlockDifferences() secondBlockDifferences() I apologise for the lack of annotation and it may be a little inefficient, but I am really only after a solution to the error on line 18. Thanks. From andrea.crotti.0 at gmail.com Thu Aug 2 06:59:28 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 2 Aug 2012 11:59:28 +0100 Subject: CRC-checksum failed in gzip In-Reply-To: References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501A54A4.4030006@shopzeus.com> Message-ID: 2012/8/2 andrea crotti : > > Ok sure that makes sense, but then this explanation is maybe not right > anymore, because I'm quite sure that the file object is *not* shared > between threads, everything happens inside a thread.. > > I managed to get some errors doing this with a big file > class OpenAndRead(threading.Thread): > def run(self): > global fz > fz.read(100) > > if __name__ == '__main__': > > fz = gzip.open('bigfile.avi.gz') > for i in range(20): > OpenAndRead().start() > > and it doesn't fail without the *global*, but this is definitively not > what the code does, because every thread gets a new file object, it's > not shared.. > > Anyway we'll read once for all the threads or add the lock, and > hopefully it should solve the problem, even if I'm not convinced yet > that it was this. Just for completeness as suggested this also does not fail: class OpenAndRead(threading.Thread): def __init__(self, lock): threading.Thread.__init__(self) self.lock = lock def run(self): global fz with self.lock: fz.read(100) if __name__ == '__main__': lock = threading.Lock() fz = gzip.open('bigfile.avi.gz') for i in range(20): OpenAndRead(lock).start() From d at davea.name Thu Aug 2 07:04:15 2012 From: d at davea.name (Dave Angel) Date: Thu, 02 Aug 2012 07:04:15 -0400 Subject: attribute is accessed from Nonetype In-Reply-To: References: Message-ID: <501A5EAF.9090501@davea.name> On 08/02/2012 06:28 AM, Shanth Kumar wrote: > Hi ,All, > I am Shanthkumar. Good to see the mailing list for python programmers. Welcome to the list. > Please find my query below, > > In my source code in a python file e.g xyz.py couple of classes are defined > also there is a wrapper class, a none object is declared in the file e.g > temp=None > from temp some attributes are being accessed in the files that are > importing xyz.py > even though temp is not initialised to any other object still it is none > object attributes are being accessed from None object.Is there any > significance of wrapper class here..? > Can you please help me. > > Once you actually supply some code. Build a small example illustrating your problem, and explain better what is wrong/unexpected with how it works. If an import of xyz.py is necessary, then show both files. Are you surprised that the None object has attributes? It has at least 15 in Python 2.7. Or are you surprised that temp is different in other modules than it is in xyz.py ? Or are you surprised that wrapping a NoneType is possible? Also, please use the names correctly and consistently. The None object (yes, there is only one) is not the same as a none object. And there is no standard type called Nonetype. Finally, please avoid runon sentences. By the time we parse where the periods are supposed to be, we just may lose the meaning you had in mind. -- DaveA From phihag at phihag.de Thu Aug 2 07:07:59 2012 From: phihag at phihag.de (Philipp Hagemeister) Date: Thu, 02 Aug 2012 13:07:59 +0200 Subject: consistent input() for Python 2 and 3 In-Reply-To: <72vpe9-kki.ln1@satorlaser.homedns.org> References: <72vpe9-kki.ln1@satorlaser.homedns.org> Message-ID: <501A5F8F.9010504@phihag.de> On 08/02/2012 11:49 AM, Ulrich Eckhardt wrote: > try: > # redirect input() to raw_input() like Python 3 > input = raw_input > except NameError: > # no raw input, probably running Python 3 already > pass > What do you think? Any better alternatives? That's the generic solution, see http://python3porting.com/differences.html#input-and-raw-input . In my experience, it seems that input's main function is to allow beginners to learn the language, or to be used in short scripts. For a serious application, either curses or moving the input to the invocation arguments is often a better choice. - Philipp -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From __peter__ at web.de Thu Aug 2 07:18:59 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Aug 2012 13:18:59 +0200 Subject: Error help References: Message-ID: danielashiloh at googlemail.com wrote: > This error has been bugging me for days. I know it's minor, but it's > really getting in the way of my programming. I'm programming a data > analysis programme for a psychology experiment which takes pickled data > from the experiment and produces averages. For some reason python is > insisting there is an indentation error on line 18. I can't confirm that, I get an error in line 8 > partifipant_info=data'Participant Info'] where you forgot the opening '['. Please post your actual code and don't forget to include a cut-and-paste version of the traceback you get. From marmata at gmail.com Thu Aug 2 07:23:39 2012 From: marmata at gmail.com (marmata at gmail.com) Date: Thu, 2 Aug 2012 04:23:39 -0700 (PDT) Subject: Error help In-Reply-To: References: Message-ID: Hi, > This error has been bugging me for days. Doesn't look like a tab error but: > partifipant_info=data'Participant Info'] This line is wrong, it should be: partifipant_info=data['Participant Info'] That's probably what's triggering the error! Cheers, ]\/[arco From d at davea.name Thu Aug 2 07:27:19 2012 From: d at davea.name (Dave Angel) Date: Thu, 02 Aug 2012 07:27:19 -0400 Subject: Error help In-Reply-To: References: Message-ID: <501A6417.4030902@davea.name> On 08/02/2012 06:58 AM, danielashiloh at googlemail.com wrote: > Hi all > > This error has been bugging me for days. I know it's minor, but it's really getting in the way of my programming. I'm programming a data analysis programme for a psychology experiment which takes pickled data from the experiment and produces averages. For some reason python is insisting there is an indentation error on line 18. I have untabified and retabified and nothing seems to work. Here is the full code: > > > import cPickle, pickle > > print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST' > file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ') > pickle_file=open(file, 'r') > data=cPickle.load(pickle_file) > file_name=file-'pck' + 'txt' > partifipant_info=data'Participant Info'] > first_block_data=data['First block data'] > second_block_data=data['Second block data'] > first_block_estimates=first_block_data['Estimated times'] > first_block_times=first_block_data['Actual times'] > second_block_estimates=second_block_data['Estimated times'] > second_block_times=second_block_data['Actual times'] > > > def firstBlockDifferences(): > print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' > count=0 > first_block_differences=[] > total=0 > while count differences=float(first_block_estimates[count])-float(first_block_times[count]) > if differences >= 180: > differences-=360 > elif differences <=-180: > differences+=360 > total+=differences > differences=[differences] > first_block_differences+=differences > count+=1 > average_diff_first_block=total/len(first_block_estimates) > text_file.write('\nAverage differences for block 1: ', average_diff_first_block) > > def secondBlockDifferences(): > print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2' > count=0 > second_block_differences=[] > total=0 > while count differences=float(second_block_estimates[count])-float(second_block_times[count]) > if differences >= 180: > differences-=360 > elif differences <=-180: > differences+=360 > total+=differences > differences=[differences] > second_block_differences+=differences > count+=1 > average_diff_second_block=total/len(second_block_estimates) > text_file.write('\nAverage differences for block 2: ', average_diff_second_block) > > > text_file=open(file_name, 'w') > text_file.write('\nParticipant info: ', participant_info) > firstBlockDifferences() > secondBlockDifferences() > > I apologise for the lack of annotation and it may be a little inefficient, but I am really only after a solution to the error on line 18. > > Thanks. You didn't include the error message, so how are we supposed to know which line is #18 ? if I take your message literally, it's a blank line. Even better, you could have reduced the code down to a minimum which still shows the error. As your code stands now, I get an error on line 10: File "daniel.py", line 10 partifipant_info=data'Participant Info'] ^ SyntaxError: invalid syntax It appears you're missing a left bracket. That line also has a strange spelling for participant, so you'd get an error later when you tried to use participant_info. Did you by any chance retype your program into the message? If you don't use copy/paste, it's useless for us to study your code. Finally, in case it matters, just what version of python did you use, and on what OS? -- DaveA From phihag at phihag.de Thu Aug 2 07:34:50 2012 From: phihag at phihag.de (Philipp Hagemeister) Date: Thu, 02 Aug 2012 13:34:50 +0200 Subject: Error help In-Reply-To: References: Message-ID: <501A65DA.4040103@phihag.de> Let's go thorugh this program: On 08/02/2012 12:58 PM, danielashiloh at googlemail.com wrote: > import cPickle, pickle you probably want to transparently fall back to pickle if cPickle is not available. > print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST' > file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ') This should be a command-line option. Look for optparse, or use sys.argv[1] > pickle_file=open(file, 'r') > data=cPickle.load(pickle_file) You're opening a file in text mode, and leaking the handle. > file_name=file-'pck' + 'txt' You cannot subtract strings. You probably want to use + . Also, move this assignment down to where it's needed > partifipant_info=data'Participant Info'] You later use participant_info. typo? > first_block_data=data['First block data'] > second_block_data=data['Second block data'] > first_block_estimates=first_block_data['Estimated times'] > first_block_times=first_block_data['Actual times'] > second_block_estimates=second_block_data['Estimated times'] > second_block_times=second_block_data['Actual times'] This is not a useful data structure. You want: blocks = [{ 'estimates': data[name]['Estimated times'], 'actuals': data[name]['Actual Times'], } for name in ["First block data", "Second block data"}] or better yet, a sane pickle format. > def firstBlockDifferences(): This method should be called blockDifferences, and take a block as an argument, and return differenes. See http://docs.python.org/tutorial/controlflow.html#defining-functions for an introduction. > print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' This belongs in the calling method. > count=0 > first_block_differences=[] > total=0 > while count differences=float(first_block_estimates[count])-float(first_block_times[count]) > if differences >= 180: > differences-=360 > elif differences <=-180: > differences+=360 What if the value is larger than 540 or smaller than -540? > total+=differences > differences=[differences] This line looks strange. Please use another variable name for values of another type. > first_block_differences+=differences If that's all there is to this function, have a look at writing a generator. If you delete the previous line, you can also write jsut first_block_differences.append(differences) > count+=1 Not required if you use zip above. > average_diff_first_block=total/len(first_block_estimates) > text_file.write('\nAverage differences for block 1: ', average_diff_first_block) These two lines don't look as if they belong in this method. Better write another one that wraps the calculation and outputs stuff. > > def secondBlockDifferences(): Instead of writing two methods to do the same thing, write one with arguments. > (...) > text_file=open(file_name, 'w') You're leaking the handle. Use with(open(file_name, 'w')) as text_file: . > text_file.write('\nParticipant info: ', participant_info) > firstBlockDifferences() > secondBlockDifferences() - Philipp -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From jason.swails at gmail.com Thu Aug 2 08:34:11 2012 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 2 Aug 2012 08:34:11 -0400 Subject: consistent input() for Python 2 and 3 In-Reply-To: <72vpe9-kki.ln1@satorlaser.homedns.org> References: <72vpe9-kki.ln1@satorlaser.homedns.org> Message-ID: On Thu, Aug 2, 2012 at 5:49 AM, Ulrich Eckhardt < ulrich.eckhardt at dominolaser.com> wrote: > Hi! > > I'm trying to write some code that should work with both Python 2 and 3. > One of the problems there is that the input() function has different > meanings, I just need the raw_input() behaviour of Python 2. > > > My approach is to simply do this: > > try: > # redirect input() to raw_input() like Python 3 > input = raw_input > except NameError: > # no raw input, probably running Python 3 already > pass > > > What do you think? Any better alternatives? > Depending on how much user input is needed in your application, you can always use the 'cmd' module: http://docs.python.org/library/cmd.html It is present in both Python 2 and Python 3 and should just 'do the right thing'. It also seamlessly integrates readline (if present), command-completion, and provides a built-in help menu for defined commands. It's written in pure Python, and in my opinion, the best form of documentation for that module is the source code itself. I haven't used it in Python 3, but I imagine it can be used in a way that easily supports Python 2 and 3. If you have only one or two places where you need user-input, this is probably overkill. HTH, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From danielashiloh at googlemail.com Thu Aug 2 09:12:21 2012 From: danielashiloh at googlemail.com (danielashiloh at googlemail.com) Date: Thu, 2 Aug 2012 06:12:21 -0700 (PDT) Subject: Error help In-Reply-To: References: Message-ID: On Thursday, 2 August 2012 12:18:59 UTC+1, Peter Otten wrote: > danielashiloh at googlemail.com wrote: > > > > > This error has been bugging me for days. I know it's minor, but it's > > > really getting in the way of my programming. I'm programming a data > > > analysis programme for a psychology experiment which takes pickled data > > > from the experiment and produces averages. For some reason python is > > > insisting there is an indentation error on line 18. > > > > I can't confirm that, I get an error in line 8 > > > > > partifipant_info=data'Participant Info'] > > > > where you forgot the opening '['. > > > > Please post your actual code and don't forget to include a cut-and-paste > > version of the traceback you get. Thank you, everyone, for the replies. It does seem to stem from that missing bracket, indeed the error did start coming up when I first included that line. Do I feel silly! Incidentally, the error message I got was for an unexpected indent. All is resolved now. From danielashiloh at googlemail.com Thu Aug 2 09:12:21 2012 From: danielashiloh at googlemail.com (danielashiloh at googlemail.com) Date: Thu, 2 Aug 2012 06:12:21 -0700 (PDT) Subject: Error help In-Reply-To: References: Message-ID: On Thursday, 2 August 2012 12:18:59 UTC+1, Peter Otten wrote: > danielashiloh at googlemail.com wrote: > > > > > This error has been bugging me for days. I know it's minor, but it's > > > really getting in the way of my programming. I'm programming a data > > > analysis programme for a psychology experiment which takes pickled data > > > from the experiment and produces averages. For some reason python is > > > insisting there is an indentation error on line 18. > > > > I can't confirm that, I get an error in line 8 > > > > > partifipant_info=data'Participant Info'] > > > > where you forgot the opening '['. > > > > Please post your actual code and don't forget to include a cut-and-paste > > version of the traceback you get. Thank you, everyone, for the replies. It does seem to stem from that missing bracket, indeed the error did start coming up when I first included that line. Do I feel silly! Incidentally, the error message I got was for an unexpected indent. All is resolved now. From invalid at invalid.invalid Thu Aug 2 10:29:09 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Aug 2012 14:29:09 +0000 (UTC) Subject: Pass data to a subprocess References: <5017EFB0.6080608@shopzeus.com> Message-ID: On 2012-08-02, Laszlo Nagy wrote: > >> I still don't get it. shm_unlink() works the same way unlink() does. >> The resource itself doesn't cease to exist until all open file >> handles are closed. From the shm_unlink() man page on Linux: >> >> The operation of shm_unlink() is analogous to unlink(2): it >> removes a shared memory object name, and, once all processes >> have unmapped the object, de-allocates and destroys the >> contents of the associated memory region. After a successful >> shm_unlink(), attempts to shm_open() an object with the same >> name will fail (unless O_CREAT was specified, in which case a >> new, distinct object is created). >> >> Even if the parent calls shm_unlink(), the shared-memory resource >> will continue to exist (and be usable) until all processes that are >> holding open file handles unmap/close them. So not only will >> detached children not crash, they'll still be able to use the shared >> memory objects to talk to each other. Note that when I say the detached children will still be able to talk to each other using shared memory after the parent calls shm_unlink() and exit(), I'm talking about the general case -- not specifically about the multiprocessing module. There may be something else going on with the multiprocessing module. > I stand corrected. It should still be examined, what kind shared > memory is used under non-linux systems. System V on AIX? And what > about Windows? So maybe the general answer is still no. But I guess > that the OP wanted this to work on a specific system. > > Dear Andrea Crotti! Please try to detach two child processes, exit > from the main process, and communicate over a multiprocessing queue. > It will possibly work. Sorry for my bad advice. I'm not claiming it will work, since I don't know how the IPC in the multiprocessing module works. It may indeed break when a child process is detatched (which I'm assuming means being removed from the process group and/or detached from the controlling tty). But, I'm not aware of any underlying Unix IPC mechanism that breaks when a child is detached, so I was curious about what would cause multiprocessing's IPC to break. -- Grant Edwards grant.b.edwards Yow! I didn't order any at WOO-WOO ... Maybe a YUBBA gmail.com ... But no WOO-WOO! From ethan at stoneleaf.us Thu Aug 2 11:55:48 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Aug 2012 08:55:48 -0700 Subject: dbf.py API question Message-ID: <501AA304.3090000@stoneleaf.us> SQLite has a neat feature where if you give it a the file-name of ':memory:' the resulting table is in memory and not on disk. I thought it was a cool feature, but expanded it slightly: any name surrounded by colons results in an in-memory table. I'm looking at the same type of situation with indices, but now I'm wondering if the :name: method is not pythonic and I should use a flag (in_memory=True) when memory storage instead of disk storage is desired. Thoughts? ~Ethan~ From magguru.anilkumar at gmail.com Thu Aug 2 12:35:25 2012 From: magguru.anilkumar at gmail.com (devi) Date: Thu, 2 Aug 2012 09:35:25 -0700 (PDT) Subject: KAJOL SEX VIDEOS''''''''''''''''''' Message-ID: KAJAL SEX VIDEOS http://maxworkerds.co.cc From smaran.harihar at gmail.com Thu Aug 2 14:20:41 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Thu, 2 Aug 2012 11:20:41 -0700 Subject: Creating a simple CGI Script Message-ID: Hi, I am trying to create a simple CGI Script and following this tutorialsbut unfortunately my output is only printing the cgi file as it is on the browser. I have already provided the py scripts with the executable functions. This is my server.py and this is my test_cgi.py -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From csanyipal at gmail.com Thu Aug 2 14:24:36 2012 From: csanyipal at gmail.com (Csanyi Pal) Date: Thu, 02 Aug 2012 20:24:36 +0200 Subject: The way to develope a graphical application to manage a Postgres database Message-ID: <877gthqhi3.fsf@gmail.com> Hi, I'm new to python. I'm searching for a way to develope a Python graphical application for a Postgresql database. I have installed on my Debian GNU/Linux testing/sid system many python packages, among others: eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7, python-easygui, python-forgetsql, python-gasp, python-glade2, python-gobject-2, python-gtk2, python-pip, python-pygresql, python-pyside.qtsql, python-subversion, python-tk, python-wxglade, spyder, python3-psycopg2, python-psycopg2, XRCed. I did search in the Google but can't find any good tutorial except for wxpython tutorial: http://wiki.wxpython.org/FrontPage, wxGlade tutorial: http://wiki.wxpython.org/WxGladeTutorial There is a tutorial for using python-psycopg2 here: http://wiki.postgresql.org/wiki/Psycopg2_Tutorial Still I don't know how to put these all together? XRCed is the most interesting way for me. Can one advices me where to go? -- Regards from Pal From xavier.combelle at free.fr Thu Aug 2 14:44:04 2012 From: xavier.combelle at free.fr (Xavier Combelle) Date: Thu, 02 Aug 2012 20:44:04 +0200 Subject: Creating a simple CGI Script In-Reply-To: References: Message-ID: <501ACA74.6040502@free.fr> In server.py you made a mistake in the declaration of the cgi directory it should be handler.cgi_directories = ["/"] Le 02/08/2012 20:20, Smaran Harihar a ?crit : > Hi, > > I am trying to create a simple CGI Script and following this tutorials > > but unfortunately my output is only printing the cgi file as it is on > the browser. > > I have already provided the py scripts with the executable functions. > > This is my server.py and this is > mytest_cgi.py > > -- > Thanks & Regards > Smaran Harihar > > > > This body part will be downloaded on demand. -------------- next part -------------- An HTML attachment was scrubbed... URL: From smaran.harihar at gmail.com Thu Aug 2 15:19:17 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Thu, 2 Aug 2012 12:19:17 -0700 Subject: Creating a simple CGI Script In-Reply-To: <501ACA74.6040502@free.fr> References: <501ACA74.6040502@free.fr> Message-ID: Thanks a lot Xavier, that was exactly what was needed. On Thu, Aug 2, 2012 at 11:44 AM, Xavier Combelle wrote: > In server.py you made a mistake in the declaration of the cgi directory > it should be > handler.cgi_directories = ["/"] > > > Le 02/08/2012 20:20, Smaran Harihar a ?crit : > > Hi, > > I am trying to create a simple CGI Script and following this tutorialsbut unfortunately my output is only printing the cgi file as it is on the > browser. > > I have already provided the py scripts with the executable functions. > > This is my server.py and this is my test_cgi.py > > -- > Thanks & Regards > Smaran Harihar > > > > This body part will be downloaded on demand. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From smaran.harihar at gmail.com Thu Aug 2 15:26:46 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Thu, 2 Aug 2012 12:26:46 -0700 Subject: unable to get simple html file up Message-ID: Hi, I am following this tutorial and i am not able to get the link.py up and running. I should be looking at Html file with link directing to the cgi script. But strangely i can't even see the page itself. Any idea why it is like this? I have made link.py executable. Here is the server.py . -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tdldev at gmail.com Thu Aug 2 15:53:37 2012 From: tdldev at gmail.com (Verde Denim) Date: Thu, 2 Aug 2012 15:53:37 -0400 Subject: The way to develope a graphical application to manage a Postgres database In-Reply-To: <877gthqhi3.fsf@gmail.com> References: <877gthqhi3.fsf@gmail.com> Message-ID: Sounds like you have enough pieces-parts... is it a question of the development process? On Aug 2, 2012 3:08 PM, "Csanyi Pal" wrote: > Hi, > > I'm new to python. > > I'm searching for a way to develope a Python graphical application for a > Postgresql database. > > I have installed on my Debian GNU/Linux testing/sid system many python > packages, among others: > eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7, > python-easygui, python-forgetsql, python-gasp, python-glade2, > python-gobject-2, python-gtk2, python-pip, python-pygresql, > python-pyside.qtsql, python-subversion, python-tk, python-wxglade, > spyder, python3-psycopg2, python-psycopg2, XRCed. > > I did search in the Google but can't find any good tutorial except for > wxpython tutorial: http://wiki.wxpython.org/FrontPage, > wxGlade tutorial: http://wiki.wxpython.org/WxGladeTutorial > > There is a tutorial for using python-psycopg2 here: > http://wiki.postgresql.org/wiki/Psycopg2_Tutorial > > Still I don't know how to put these all together? > > XRCed is the most interesting way for me. > > Can one advices me where to go? > > -- > Regards from Pal > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From csanyipal at gmail.com Thu Aug 2 17:13:52 2012 From: csanyipal at gmail.com (Csanyi Pal) Date: Thu, 02 Aug 2012 23:13:52 +0200 Subject: The way to develope a graphical application to manage a Postgres database References: <877gthqhi3.fsf@gmail.com> Message-ID: <873945q9nz.fsf@gmail.com> Verde Denim writes: > Sounds like you have enough pieces-parts... is it a question of the > development process? Yes, it is. First question is about GUI. Say I start to create a GUI with XRCed for such an application for managing a concrete postgresql database. On a Frame (window) which object should I draw to get a Table of the database when I write the code? If I want to use say python-pygresql to connect to the database then I must study the http://www.pygresql.org/pg.html documentation and after that I must to write code to connect it with the GUI. Is on the Internet such a tutorial that can help me in this effort? -- Regards from Pal From breamoreboy at yahoo.co.uk Thu Aug 2 17:40:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 02 Aug 2012 22:40:12 +0100 Subject: The way to develope a graphical application to manage a Postgres database In-Reply-To: <873945q9nz.fsf@gmail.com> References: <877gthqhi3.fsf@gmail.com> <873945q9nz.fsf@gmail.com> Message-ID: On 02/08/2012 22:13, Csanyi Pal wrote: > Verde Denim writes: > >> Sounds like you have enough pieces-parts... is it a question of the >> development process? > > Yes, it is. > > First question is about GUI. > > Say I start to create a GUI with XRCed for such an application for > managing a concrete postgresql database. > > On a Frame (window) which object should I draw to get a Table of the > database when I write the code? > > If I want to use say python-pygresql to connect to the database then I > must study the http://www.pygresql.org/pg.html documentation and after > that I must to write code to connect it with the GUI. > > Is on the Internet such a tutorial that can help me in this effort? > Start here? http://zetcode.com/ -- Cheers. Mark Lawrence. From csanyipal at gmail.com Thu Aug 2 17:42:48 2012 From: csanyipal at gmail.com (Csanyi Pal) Date: Thu, 02 Aug 2012 23:42:48 +0200 Subject: The way to develope a graphical application to manage a Postgres database References: <877gthqhi3.fsf@gmail.com> Message-ID: <874nol7yxz.fsf@gmail.com> Dennis Lee Bieber writes: > On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal > declaimed the following in gmane.comp.python.general: >> >> I'm searching for a way to develope a Python graphical application for a >> Postgresql database. >> > A predefined database, or a general access module? A predefined, already existing database. >> I have installed on my Debian GNU/Linux testing/sid system many python >> packages, among others: >> eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7, >> python-easygui, python-forgetsql, python-gasp, python-glade2, >> python-gobject-2, python-gtk2, python-pip, python-pygresql, >> python-pyside.qtsql, python-subversion, python-tk, python-wxglade, >> spyder, python3-psycopg2, python-psycopg2, XRCed. >> > Well... I'd suggest figuring out which GUI toolkit you want to > use... You have GTK, Tk, I'd say Wx but you didn't list wxpython. You > also have two competing PostgreSQL adapters -- pick one... I just installed wxpython packages: wx2.8-i18n, python-wxgtk2.8, python-wxtools. > Eric, geany, and idle are all editor/development environments and > not directly related to what the application itself runs. > > For a predefined database, you may just want to explore Dabo. For a > general access (eg; one where you tell the program which PostgreSQL > database to connect to, and it extracts the schema information from the > database at run-time) you'll need to study the advanced features of the > database engine and adapter. I'm exploring now Dabo. -- Regards from Pal From rosuav at gmail.com Thu Aug 2 17:58:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Aug 2012 07:58:12 +1000 Subject: The way to develope a graphical application to manage a Postgres database In-Reply-To: <877gthqhi3.fsf@gmail.com> References: <877gthqhi3.fsf@gmail.com> Message-ID: On Fri, Aug 3, 2012 at 4:24 AM, Csanyi Pal wrote: > I'm searching for a way to develope a Python graphical application for a > Postgresql database. There's two quite separate parts to this: * Develop a Python graphical application * Develop a Python application [to access] a PostgreSQL database. I recommend you tackle them separately, and only put them together once you're confident with each part on its own. Pick a GUI toolkit and make a "Hello, world". That might take you quite a while, and it isn't helped by trying to mix in an unfamiliar database. That said, I do commend your choices of language and DB. :) All the best! ChrisA From ramit.prasad at jpmorgan.com Fri Aug 3 02:51:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 3 Aug 2012 06:51:25 +0000 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741659DD90@SCACMX008.exchad.jpmchase.net> > I'm in stuck record mode here, but one of the things I really enjoy > about reading here is the way things do go off topic. IMHO makes for a > far more interesting experience. YMMV. +1 Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Aug 3 03:01:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 3 Aug 2012 07:01:29 +0000 Subject: attribute is accessed from Nonetype In-Reply-To: <501A5EAF.9090501@davea.name> References: <501A5EAF.9090501@davea.name> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> > Also, please use the names correctly and consistently. The None object > (yes, there is only one) is not the same as a none object. And there is > no standard type called Nonetype. To be fair, this is not very clear to a beginner. >>> len(None) # Python 2.6 TypeError: object of type 'NoneType' has no len() Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From __peter__ at web.de Fri Aug 3 05:03:13 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 03 Aug 2012 11:03:13 +0200 Subject: dbf.py API question References: <501AA304.3090000@stoneleaf.us> Message-ID: Ethan Furman wrote: > SQLite has a neat feature where if you give it a the file-name of > ':memory:' the resulting table is in memory and not on disk. I thought > it was a cool feature, but expanded it slightly: any name surrounded by > colons results in an in-memory table. > > I'm looking at the same type of situation with indices, but now I'm > wondering if the :name: method is not pythonic and I should use a flag > (in_memory=True) when memory storage instead of disk storage is desired. For SQLite it seems OK because you make the decision once per database. For dbase it'd be once per table, so I would prefer the flag. Random > Thoughts? - Do you really want your users to work with multiple dbf files? I think I'd rather convert to SQLite, perform the desired operations using sql, then convert back. - Are names required to manipulate the table? If not you could just omit them to make the table "in-memory". - How about a connection object that may either correspond to a directory or RAM: db = dbf.connect(":memory:") table = db.Table("foo", ...) From stefan_ml at behnel.de Fri Aug 3 05:34:41 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 03 Aug 2012 11:34:41 +0200 Subject: Is Python a commercial proposition ? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741659DD90@SCACMX008.exchad.jpmchase.net> References: <-1016624622349492799@unknownmsgid> <5B80DD153D7D744689F57F4FB69AF4741659DD90@SCACMX008.exchad.jpmchase.net> Message-ID: Prasad, Ramit, 03.08.2012 08:51: >> I'm in stuck record mode here, but one of the things I really enjoy >> about reading here is the way things do go off topic. IMHO makes for a >> far more interesting experience. YMMV. > > +1 > > Ramit > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. Huh? Who's still trying to sell viruses these days? I thought they came for free? Stefan From lipskathekat at yahoo.co.uk Fri Aug 3 07:34:36 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 03 Aug 2012 12:34:36 +0100 Subject: Eclipse and the Python plugin Message-ID: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> A while ago someone asked me what I thought of the Eclipse plugin for python, well I just downloaded and installed the latest version of Eclipse for Java (Juno) followed by the Python plugin. After a while messing about with it I can only say ... phew, what a relief. The plugin looks like it automates a whole bunch of tasks such as packaging and you can configure it to use Jython, Iron Python (neither of which I have used) and some other stuff I have never heard of I installed all this on Ubuntu Linux 12.04 with no problems whatsoever. There's a debugger (which I haven't tried), code completion, error highlighting and much more. Installing the plugin is documented here http://www.rose-hulman.edu/class/csse/resources/Eclipse/eclipse-python-configuration.htm And the most amazing thing of all is it's all completely free. I can now create, debug and test a simple IRC server written in Java and an IRC Bot that I am attempting to build in Python side by side in the same IDE simply by switching profiles (click one button). Astonishing. You might like to try it Just FYI so please don't tell me off (again). lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From subhabangalore at gmail.com Fri Aug 3 07:49:46 2012 From: subhabangalore at gmail.com (Subhabrata) Date: Fri, 3 Aug 2012 04:49:46 -0700 (PDT) Subject: Calling Values Message-ID: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Dear Group, I am trying to call the values of one function in the another function in the following way: def func1(): num1=10 num2=20 print "The Second Number is:",num2 return def func2(): num3=num1+num2 num4=num3+num1 print "New Number One is:",num3 print "New Number Two is:",num4 return I am preferring not to use argument passing or using class? Is there any alternate way? Thanking in Advance, Regards, Subhabrata. From breamoreboy at yahoo.co.uk Fri Aug 3 08:07:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Aug 2012 13:07:38 +0100 Subject: Calling Values In-Reply-To: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: On 03/08/2012 12:49, Subhabrata wrote: > Dear Group, > > I am trying to call the values of one function in the another function in the following way: > def func1(): > num1=10 > num2=20 > print "The Second Number is:",num2 > return > > def func2(): > num3=num1+num2 > num4=num3+num1 > print "New Number One is:",num3 > print "New Number Two is:",num4 > return > > I am preferring not to use argument passing or using class? Is there any alternate way? > > Thanking in Advance, > Regards, > Subhabrata. > I think you've got the wrong group, but I don't know the best one for psychiatrists :) Seriously I can't see what you're trying to achieve with this approach. Can you explain it and I'm certain that we'll come up with a decent solution to your problem, whatever that may be. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Aug 3 08:10:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Aug 2012 13:10:07 +0100 Subject: Eclipse and the Python plugin In-Reply-To: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On 03/08/2012 12:34, lipska the kat wrote: > A while ago someone asked me what I thought of the Eclipse plugin for > python, well I just downloaded and installed the latest version of > Eclipse for Java (Juno) followed by the Python plugin. After a while > messing about with it I can only say ... phew, what a relief. The plugin > looks like it automates a whole bunch of tasks such as packaging and you > can configure it to use Jython, Iron Python (neither of which I have > used) and some other stuff I have never heard of > > I installed all this on Ubuntu Linux 12.04 with no problems whatsoever. > > There's a debugger (which I haven't tried), code completion, error > highlighting and much more. > > Installing the plugin is documented here > http://www.rose-hulman.edu/class/csse/resources/Eclipse/eclipse-python-configuration.htm > > > And the most amazing thing of all is it's all completely free. > > I can now create, debug and test a simple IRC server written in Java > and an IRC Bot that I am attempting to build in Python side by side in > the same IDE simply by switching profiles (click one button). Astonishing. > > You might like to try it > > Just FYI so please don't tell me off (again). > > lipska > My opinion of Eclipse is unchanged by your words, it's like trying to run a legless carthorse in the Grand National or the Derby. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Aug 3 08:15:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Aug 2012 13:15:04 +0100 Subject: ANN: dbf.py 0.94 In-Reply-To: <5009F0D9.1050900@stoneleaf.us> References: <5009F0D9.1050900@stoneleaf.us> Message-ID: On 21/07/2012 00:59, Ethan Furman wrote: > Getting closer to a stable release. > > Latest version has a simpler, cleaner API, and works on PyPy (and > hopefully the other implementations as well ;), as well as CPython. > > Get your copy at http://python.org/pypi/dbf. > > Bug reports, comments, and kudos welcome! ;) > > ~Ethan~ Will this work with Recital software on VMS? :) -- Cheers. Mark Lawrence. From lipskathekat at yahoo.co.uk Fri Aug 3 08:23:37 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 03 Aug 2012 13:23:37 +0100 Subject: Eclipse and the Python plugin In-Reply-To: References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On 03/08/12 13:10, Mark Lawrence wrote: > On 03/08/2012 12:34, lipska the kat wrote: >> A while ago someone asked me what I thought of the Eclipse plugin for >> python, snip >> > > My opinion of Eclipse is unchanged by your words, it's like trying to > run a legless carthorse in the Grand National or the Derby. :-)) There's this image in my mind ... jeez, get a grip. I'm sorry to hear that, what would you recommend. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From ulrich.eckhardt at dominolaser.com Fri Aug 3 08:32:57 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 03 Aug 2012 14:32:57 +0200 Subject: Calling Values In-Reply-To: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: Am 03.08.2012 13:49, schrieb Subhabrata: > I am trying to call the values of one function in the > another function in the following way: > > def func1(): > num1=10 > num2=20 > print "The Second Number is:",num2 > return > > def func2(): > num3=num1+num2 > num4=num3+num1 > print "New Number One is:",num3 > print "New Number Two is:",num4 > return > > I am preferring not to use argument passing or using class? You could make those variables global, see the "global" statement in the documentation of the language. However: I don't think that is a good idea and it will make your program more confusing to read than necessary, but go ahead and make that experience yourself. ;) If you want, you can post your code here when done so that others might give you hints how to do things easier and cleaner, like e.g. putting spaces around operators and using four spaces indention (See PEP 8) or dropping the implied return from functions that return nothing. Apart from that, the above code is too short and with too little info what it's supposed to achieve, I can't really give you better advise. Good luck! Uli From breamoreboy at yahoo.co.uk Fri Aug 3 08:40:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Aug 2012 13:40:34 +0100 Subject: Eclipse and the Python plugin In-Reply-To: References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On 03/08/2012 13:23, lipska the kat wrote: > On 03/08/12 13:10, Mark Lawrence wrote: >> On 03/08/2012 12:34, lipska the kat wrote: >>> A while ago someone asked me what I thought of the Eclipse plugin for >>> python, > > snip > >>> >> >> My opinion of Eclipse is unchanged by your words, it's like trying to >> run a legless carthorse in the Grand National or the Derby. > > :-)) There's this image in my mind ... jeez, get a grip. > > I'm sorry to hear that, what would you recommend. > > lipska > Sorry I can't recommend anything as I use Python for small personal projects, so I find a combination of Notepad++ and PythonWin totally adequate for my needs. Eclipse is also popular, so simply because I don't like it speed wise doesn't mean that it's not for you. Picking an IDE often gets down to your own preferences and perhaps budget. -- Cheers. Mark Lawrence. From nobody at nowhere.com Fri Aug 3 08:44:31 2012 From: nobody at nowhere.com (Nobody) Date: Fri, 03 Aug 2012 13:44:31 +0100 Subject: Calling Values References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: On Fri, 03 Aug 2012 04:49:46 -0700, Subhabrata wrote: > I am trying to call the values of one function in the another function > in the following way: > def func1(): > num1=10 > num2=20 > print "The Second Number is:",num2 > return > > def func2(): > num3=num1+num2 > num4=num3+num1 A function's local variables only exist while that function is being executed[1]. It's meaningless to try to access them from outside the function. [1] There is an exception (closures), but it doesn't have any bearing on this particular problem. From sscc at mweb.co.za Fri Aug 3 08:50:34 2012 From: sscc at mweb.co.za (Alex Strickland) Date: Fri, 03 Aug 2012 14:50:34 +0200 Subject: ANN: dbf.py 0.94 In-Reply-To: References: <5009F0D9.1050900@stoneleaf.us> <500B17D4.8040702@mweb.co.za> Message-ID: <501BC91A.3030007@mweb.co.za> On 2012/07/21 11:49 PM, Mark Lawrence wrote: > and PS is spelt p.s. :) Ahem, the absolutely authoritative reference on the subject: http://en.wikipedia.org/wiki/Postscript says PS or P.S. -- Regards Alex From breamoreboy at yahoo.co.uk Fri Aug 3 09:04:59 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Aug 2012 14:04:59 +0100 Subject: ANN: dbf.py 0.94 In-Reply-To: <501BC91A.3030007@mweb.co.za> References: <5009F0D9.1050900@stoneleaf.us> <500B17D4.8040702@mweb.co.za> <501BC91A.3030007@mweb.co.za> Message-ID: On 03/08/2012 13:50, Alex Strickland wrote: > On 2012/07/21 11:49 PM, Mark Lawrence wrote: > >> and PS is spelt p.s. :) > > Ahem, the absolutely authoritative reference on the subject: > > http://en.wikipedia.org/wiki/Postscript > > says PS or P.S. I'm sorry but you can't read my writing[1]. [1] another Python sketch for the uninitiated but on album only possibly? -- Cheers. Mark Lawrence. From ethan at stoneleaf.us Fri Aug 3 09:11:59 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Aug 2012 06:11:59 -0700 Subject: dbf.py API question In-Reply-To: References: <501AA304.3090000@stoneleaf.us> Message-ID: <501BCE1F.6050001@stoneleaf.us> Peter Otten wrote: > Ethan Furman wrote: > >> SQLite has a neat feature where if you give it a the file-name of >> ':memory:' the resulting table is in memory and not on disk. I thought >> it was a cool feature, but expanded it slightly: any name surrounded by >> colons results in an in-memory table. >> >> I'm looking at the same type of situation with indices, but now I'm >> wondering if the :name: method is not pythonic and I should use a flag >> (in_memory=True) when memory storage instead of disk storage is desired. > > For SQLite it seems OK because you make the decision once per database. For > dbase it'd be once per table, so I would prefer the flag. So far all feedback is for the flag, so that's what I'll do. > Random > >> Thoughts? > > - Do you really want your users to work with multiple dbf files? I think I'd > rather convert to SQLite, perform the desired operations using sql, then > convert back. Seems like that would be quite a slow-down (although if a user wants to do that, s/he certainly could). > - Are names required to manipulate the table? If not you could just omit > them to make the table "in-memory". At one point I had thought to make tables singletons (so only one copy of /user/bob/scores.dbf) but that hasn't happened and is rather low priority, so at this point the name is not required for anything beside initial object creation. > - How about a connection object that may either correspond to a directory or > RAM: > > db = dbf.connect(":memory:") > table = db.Table("foo", ...) dbf.py does not support the DB-API interface, so no connection objects. Tables are opened directly and dealt with directly. All interesting thoughts that made me think. Thank you. ~Ethan~ From ethan at stoneleaf.us Fri Aug 3 09:17:56 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Aug 2012 06:17:56 -0700 Subject: ANN: dbf.py 0.94 In-Reply-To: References: <5009F0D9.1050900@stoneleaf.us> Message-ID: <501BCF84.2000700@stoneleaf.us> Mark Lawrence wrote: > On 21/07/2012 00:59, Ethan Furman wrote: >> Getting closer to a stable release. >> >> Latest version has a simpler, cleaner API, and works on PyPy (and >> hopefully the other implementations as well ;), as well as CPython. >> >> Get your copy at http://python.org/pypi/dbf. >> >> Bug reports, comments, and kudos welcome! ;) > > Will this work with Recital software on VMS? :) Does Recital use dBase III, Foxbase, Foxpro, or Visual Foxpro compatible files? Does Python run on VMS? If yes to both of those, then it should. :) ~Ethan~ From lipskathekat at yahoo.co.uk Fri Aug 3 09:32:29 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 03 Aug 2012 14:32:29 +0100 Subject: Eclipse and the Python plugin In-Reply-To: References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On 03/08/12 13:40, Mark Lawrence wrote: > On 03/08/2012 13:23, lipska the kat wrote: >> On 03/08/12 13:10, Mark Lawrence wrote: >>> On 03/08/2012 12:34, lipska the kat wrote: >>>> A while ago someone asked me what I thought of the Eclipse plugin for >>>> python, snip >>> it's like trying to >>> run a legless carthorse in the Grand National or the Derby. >> >> :-)) There's this image in my mind ... jeez, get a grip. >> >> I'm sorry to hear that, what would you recommend. > > Sorry I can't recommend anything as I use Python for small personal > projects, so I find a combination of Notepad++ and PythonWin totally > adequate for my needs. Eclipse is also popular, so simply because I > don't like it speed wise doesn't mean that it's not for you. I've been using it for years for Java, I just recently found the Python plugin. > Picking an IDE often gets down to your own preferences and perhaps budget. It's free ... good enough reason for me. I'm Always interested to hear of alternatives though. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From rustompmody at gmail.com Fri Aug 3 09:54:04 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 3 Aug 2012 06:54:04 -0700 (PDT) Subject: Eclipse and the Python plugin References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On Aug 3, 4:34?pm, lipska the kat wrote: > A while ago someone asked me what I thought of the Eclipse plugin for > python, well I just downloaded and installed the latest version of > Eclipse for Java (Juno) followed by the Python plugin. Thanks Lipska for reporting back. I personally find the eclipse UI frightening but I am unwilling to conclude that its eclipse and not me. By comparison, when I first heard of emacs, (about 20 years ago) the local guru would come in the morning and start emacs then go out for a smoke. When he came back it had finished started up. So the acronym: Eight Megabytes And Constantly Swapping made a lot of sense then. I guess today it would have to be Eight-hundred to make any sense. More to the point, it seems to me that eclipse was today what emacs was then -- seemingly too large but in time I expect it will not seem so large. So one more request from me: Can you try the refactoring support and tell us how it fares? From pruebauno at latinmail.com Fri Aug 3 10:14:03 2012 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 3 Aug 2012 07:14:03 -0700 (PDT) Subject: xlrd 0.8.0 released! In-Reply-To: References: Message-ID: On Wednesday, August 1, 2012 11:01:56 AM UTC-4, Chris Withers wrote: > Hi All, > > > > I'm pleased to announce the release of xlrd 0.8.0: > > > > http://pypi.python.org/pypi/xlrd/0.8.0 > > > > This release finally lands the support for both .xls and .xlsx files. > > Many thanks to John Machin for all his work on making this happen. > > Opening of .xlsx files is seamless, just use xlrd as you did before and > > it all should "just work". > > > > xlrd 0.8.0 is also the first release that that targets Python 2.6 and > > 2.7, but no Python 3 just yet. Python 2.5 and below may work but are not > > supported. If you need to use Python 2.5 or earlier, please stick to > > xlrd 0.7.x. > > > > Speaking of xlrd 0.7.x, that's now in "requested maintenance only" mode > > ;-) That means, if possible, use 0.8.x. If you have a really good reason > > for sticking with 0.7.x, and you find a bug that you can't work around, > > then please make this clear on the python-excel at googlegroups.com and > > we'll see what we can do. > > > > If you find any problems, please ask about them on the list, or submit > > an issue on GitHub: > > > > https://github.com/python-excel/xlrd/issues > > > > Full details of all things Python and Excel related can be found here: > > > > http://www.python-excel.org/ > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > - http://www.simplistix.co.uk Congrats! Being able to read Office 2007 files will be very useful. Looking forward to the Python 3 support. From subhabangalore at gmail.com Fri Aug 3 10:38:45 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Fri, 3 Aug 2012 07:38:45 -0700 (PDT) Subject: Calling Values In-Reply-To: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com> On Friday, August 3, 2012 5:19:46 PM UTC+5:30, Subhabrata wrote: > Dear Group, > > > > I am trying to call the values of one function in the another function in the following way: > > def func1(): > > num1=10 > > num2=20 > > print "The Second Number is:",num2 > > return > > > > def func2(): > > num3=num1+num2 > > num4=num3+num1 > > print "New Number One is:",num3 > > print "New Number Two is:",num4 > > return > > > > I am preferring not to use argument passing or using class? Is there any alternate way? > > > > Thanking in Advance, > > Regards, > > Subhabrata. Dear Group, def func1(): num1=10 num2=20 print "The Second Number is:",num2 return def func2(): func1() num3=num1+num2 num4=num3+num1 print "New Number One is:",num3 print "New Number Two is:",num4 This works. Even you can incoportate some conditionals over func1() in func2() and run. My question can I call its values of func1() too? What it is the big deal in experimenting we may come up with some new code or a new need? Indentation slightly differs while you post, I agree. Return I just like too use. Mark you are too concerned for me, thanks. Regards, Subhabrata. From atmb4u at gmail.com Fri Aug 3 11:12:35 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Fri, 3 Aug 2012 20:42:35 +0530 Subject: Demise of Mr. Kenneth Gonsalves Message-ID: With my heartfelt condolence, I'd like to inform you all the unfortunate demise of Mr.Kenneth Gonsalves (KG - lawgon at thenilgiris.com), who was a strong advocate of Python, Django and Free Software in India. He had served as the President of IPSS(Indian Python Software Society), which initiated the PyCon India, done a lot of workshops on Python and was an active member in the Django user group. Anoop Thomas Mathew -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.tustin at gmail.com Fri Aug 3 11:15:49 2012 From: marcin.tustin at gmail.com (Marcin Tustin) Date: Fri, 3 Aug 2012 11:15:49 -0400 Subject: Demise of Mr. Kenneth Gonsalves In-Reply-To: References: Message-ID: What happened to him? He was posting on this list in the last week? On Fri, Aug 3, 2012 at 11:12 AM, Anoop Thomas Mathew wrote: > With my heartfelt condolence, I'd like to inform you all the unfortunate > demise of Mr.Kenneth Gonsalves (KG - lawgon at thenilgiris.com), who was a > strong advocate of Python, Django and Free Software in India. > He had served as the President of IPSS(Indian Python Software Society), > which initiated the PyCon India, done a lot of workshops on Python and was > an active member in the Django user group. > > Anoop Thomas Mathew > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users at googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscribe at googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- Marcin Tustin Tel: 07773 787 105 -------------- next part -------------- An HTML attachment was scrubbed... URL: From atmb4u at gmail.com Fri Aug 3 11:20:20 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Fri, 3 Aug 2012 20:50:20 +0530 Subject: Demise of Mr. Kenneth Gonsalves In-Reply-To: References: Message-ID: Chronic Asthma. He was hospitalized yesterday, and passed away today. On 3 August 2012 20:45, Marcin Tustin wrote: > What happened to him? He was posting on this list in the last week? > > On Fri, Aug 3, 2012 at 11:12 AM, Anoop Thomas Mathew wrote: > >> With my heartfelt condolence, I'd like to inform you all the unfortunate >> demise of Mr.Kenneth Gonsalves (KG - lawgon at thenilgiris.com), who was a >> strong advocate of Python, Django and Free Software in India. >> He had served as the President of IPSS(Indian Python Software Society), >> which initiated the PyCon India, done a lot of workshops on Python and was >> an active member in the Django user group. >> >> >> Anoop Thomas Mathew >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-users at googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscribe at googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > > > -- > Marcin Tustin > Tel: 07773 787 105 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users at googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscribe at googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Fri Aug 3 11:30:41 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 3 Aug 2012 15:30:41 +0000 Subject: Calling Values In-Reply-To: <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com> References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741659E8DC@SCACMX008.exchad.jpmchase.net> > def func1(): > > num1=10 > > num2=20 > > print "The Second Number is:",num2 > > return > > > def func2(): > > func1() > num3=num1+num2 > > num4=num3+num1 > > print "New Number One is:",num3 > > print "New Number Two is:",num4 > > > This works. Even you can incoportate some conditionals over func1() in func2() > and run. This does not work. Python does not get "compiled" in the same manner as other languages (C, Java etc). Since you never call func2(), there is no error. Once you try calling func2() you will see it does not work. func1() does work. The Second Number is: 20 Traceback (most recent call last): File "subha.py", line 24, in func2() File "subha.py", line 15, in func2 num3=num1+num2 NameError: global name 'num1' is not defined > My question can I call its values of func1() too? > What it is the big deal in experimenting we may come up with some new code or > a new need? It is not a big deal, that is how you learn. You are just writing code that neither works nor really shows enough to tell us why or what you are trying to do. Not much I can do to guide or help you because I am completely lost at your goal. The best I can do at the moment is say. func2 will not work. You could return num1 and num2 from func1() and then it would work. def func1(): num1=10 num2=20 print "The Second Number is:",num2 return num1, num2 def func2(): num1, num2 = func1() num3=num1+num2 num4=num3+num1 print "New Number One is:",num3 print "New Number Two is:",num4 func2() Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Aug 3 11:37:52 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Aug 2012 08:37:52 -0700 Subject: Calling Values In-Reply-To: <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com> References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com> Message-ID: <501BF050.7080102@stoneleaf.us> subhabangalore at gmail.com wrote: > On Friday, August 3, 2012 5:19:46 PM UTC+5:30, Subhabrata wrote: >> Dear Group, >> >> >> >> I am trying to call the values of one function in the another function in the following way: >> >> def func1(): >> >> num1=10 >> >> num2=20 >> >> print "The Second Number is:",num2 >> >> return >> >> >> >> def func2(): >> >> num3=num1+num2 >> >> num4=num3+num1 >> >> print "New Number One is:",num3 >> >> print "New Number Two is:",num4 >> >> return >> >> >> >> I am preferring not to use argument passing or using class? Is there any alternate way? >> >> >> >> Thanking in Advance, >> >> Regards, >> >> Subhabrata. > > Dear Group, > > def func1(): > > num1=10 > > num2=20 > > print "The Second Number is:",num2 > > return > > > def func2(): > > func1() > num3=num1+num2 > > num4=num3+num1 > > print "New Number One is:",num3 > > print "New Number Two is:",num4 > > > This works. No, it doesn't. If it does work for you then you have code you aren't showing us. ~Ethan~ From lipskathekat at yahoo.co.uk Fri Aug 3 11:51:26 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 03 Aug 2012 16:51:26 +0100 Subject: Eclipse and the Python plugin In-Reply-To: References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On 03/08/12 14:54, rusi wrote: > On Aug 3, 4:34 pm, lipska the kat wrote: >> A while ago someone asked me what I thought of the Eclipse plugin for >> python, well I just downloaded and installed the latest version of >> Eclipse for Java (Juno) followed by the Python plugin. > > Thanks Lipska for reporting back. > I personally find the eclipse UI frightening but I am unwilling to > conclude that its eclipse and not me. snip. I have no vested interest in Eclipse but I don't believe that you would feel the same once you got your head around the basics. I don't pretend to be an expert, far from it, but I have taught myself enough to go into a contract and hit the ground running, loading the source tree into Eclipse is a great way to start to understand the code and the libraries it uses. Well it works for me anyway. > More to the point, it seems to me that eclipse was today what emacs > was then -- seemingly too large but in time I expect it will not seem > so large. It can be bewildering I agree but the basics are not too intimidating. I remember early versions of IBMs VisualAge for Java ... guaranteed to give you brain damage. > So one more request from me: > > Can you try the refactoring support and tell us how it fares? Well, I don't really have enough Python code to refactor anything at the moment however I did try something that may or may not prove to be informative. If I create a Java class and right click in the code window and select refactor from the context menu there is a HUGE list of things I can do. Why I might want to do some of them I have no idea, but there they are. In contrast if I create a Python class and select refactor I get a significantly smaller list of things I can do. Inline local variable, Extract local variable, Extract method, Rename, Generate constructors, Generate properties and Override/Implement methods. I think this may be a result of Pythons different (from Java) grammar rules. I can write a Python class and call it Foo and save it in a file called Bar and it's no big deal (at least Eclipse doesn't get excited) If I try that in Java the sky falls in. Of course I'm about as far away from being a Python expert as it's possible to be. Anyway, if and when I find out more I'll let you know. It will be a while though. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From steve+comp.lang.python at pearwood.info Fri Aug 3 12:24:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Aug 2012 16:24:57 GMT Subject: Calling Values References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: <501bfb59$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Aug 2012 04:49:46 -0700, Subhabrata wrote: > I am preferring not to use argument passing It's not 1964 any more and you're not programming in BASIC. What you have just told us is that you prefer not to write good quality programs, and that you prefer to write buggy, hard to maintain code. Of course that is your right to make such a foolish choice, but you shouldn't expect people to help you. There is enough terrible code in the world without encouraging people to write more. If you would like to learn good coding techniques, please stay around here and pay attention to modern practices for writing good quality code. If you would rather stick to worst-practices from the 1960s, don't expect any encouragement. -- Steven From musatovatattdotnet at gmail.com Fri Aug 3 12:28:57 2012 From: musatovatattdotnet at gmail.com (Martin Michael Musatov) Date: Fri, 3 Aug 2012 09:28:57 -0700 (PDT) Subject: avlhqw avlhqeavlhqino ovfqalmw avlhqei avlhqeaivscunqw Message-ID: Thanks to technology, a memorandum of understanding (thanks from Tel Aviva / s, F `u / n (I [I TO rotate HM), and try to think, nature is" E | .. (no offense to kiloton preparation. .. has C, E (Visor / s Chest on Tuesday Kin \ 2 I "auto. Hi Lasso, Wilson vest / Na` martin / NH MW `. brought / \ n VIEW goals WT /" NH, RAN, not (I all, or [that load / Samoa ...) I think the WT DR 3 ??? | ..... gown or some [even in auto Cayman S (j eventual auto Arabia will not bar / threw / a) "L" 4 Oh, BAG, Gen auto, n (oil. raj Anatole?s auto / threw HM / s (Tao, she vest (EDA Kai May that | Hall and hold LEIA ovum .. \ 5] 505 A thru / |? auto / ton, John (avlhqw / DVDs eggs MAY Tues | H, the pH of WAIT May / U / Eyelet) EN May two | gown or some [aunt EN his / | even \ "LO 6` EN aunt BAG / | .. I over Ni (Kama?s evoke / NO perinea, U (and auto [Peripatetic To /) 7 Adelaide (n ovum Ventolin.n akin graphite, F I '/ S (all Ventolin.n Palau an (10] not PULL arch / s \ "from" H vesting Vent Olin not clear, Greek] is Zhukov PULL arch / d) eight times a year, Lin Ventolin.n akin No Thanks, I `F u / n (or [vesting avlhqe.j EN aunt / | .. (EDA Mr. Kai N / A \ [paragraph` t Scottie (oil. F / 500 .. for avlhqino NH, N DH SIP) Get 9 or "50", BAG EN WT / ... | wit Chennai is = (oil. ton Adolfo.n auto / miss / s (EN and / | Scottie |. vest to [WK with RS) agape or 10 "/ n ton Adolfo auto n / EDA (VA / |. wit I (EDA Yolanda aunt Kai Ski / | ovum resist ...) The 11-misw / s ton Adolfo.n auto / (EN and / |. of Scottie | vest (EN and Kai / |. Scottie, |. reputation / (1000 = ovum want and / u-PA Gay (or [`t Scottie in veto, flues you?d goalmouth auto / s) 12 degrees , F U "/ (technical., 1 (or [I AVE, entail I` u / n Martin, all comments. what auto .. N / A 13 ?), F U "I / O (open, RE ( or [cover even. PULL arch n / graphite), F MIL `U / N (, SK spin (or [enrich coverage ton poncho, B) from 14 degrees, F" u / n (payment (or [I even , violation of ton, CA), Ms. Gray MIL / V (e, RE (or [even. PULL arch n / d) and covering gray / 500 (rotation of the earth (or [I chiaroscuro, vest (Okay., May Beautiful / U / u `EN MIL / n, the game will cover (.. Kai does not enrich poncho n .. n), BR 15 agape / O. MADE EN dispute a / VA |. SEW PM | ) Eva agape / | ton difference (ovum times are eggs, the pH can parent / EN aunt J / |. \ 16 or [/ n, EN VA / |. KB, SEW | (MK pique / and Nark. CK (b pique-Kai, has / the ovfqalmw N / S (H Kai emblazon "organic unity / straight (and keep .. ovum EVE, May / June protection. all SAP or requests vest Additional Protocol to the Agreement), I 17 "He was not, smog parameters, Get (oil. pique` H, E and auto / \ O `poi / s .. May LAMA / U / read evil ton avid / N) 18 (escape, O [ RA vest (oil. Kama?s Zhukov, and sat down, or [O `ante, God. retail (Shoat. / ante there, students Ego Crista, however, and \ or R [N and gown or some [escape you [PR vest, n), '19 VEX MW / n vex / lion (San all ovum VEX H = H ', w / w \ AV garb San VEX = "b, w / w (moment, An Keenan me B MW / n \ all I [/ Na fawner or sin [e-IT ovum ease net VEX-In. MW / N) 20, I / cry / of ADM. whales ... digestive ALPO Director / ovum `, (O Kai, gave permission, s) and -21 000 Gray `u / n (or [O ovum given than all, wean (all or O [which aunt, N (or Kai. [PA-IT / Tao n / EVE and avlhqei M / d, and AGE tablespoons ovum). March 22 vesting of Tao, she (IV US memo avenue # in Visor [u / ovum, hold, or God, or S *, where he was the Messiah ante vesting (avenue, memo ton GS, I think. HO N) 23 AP / avenue onion. memo is ovule. ton food and energy \ 'O' or 'swimming mellow / s. No, I think. ton food, and RA, ICE) 24 "B / ovum J] Zhukov, PULL is arch / s or EN / N, I, you) even miles EN` u / n, New Hampshire | no] PULL arch / d Zhukov ('You / I EN WT / | .. HO `w / |. EN Kai WT / | .. Heritage Manor / h) 25, I think [Stevie. NH Evangelic P.D., Ah] and' I. hip hungers auto barn / (no, a thousand degrees avid help when. N) 26 t / h is the salary my gray / WT / n plan, known Sat K / day) I think 27 - true / cry / or MA] VELA , Beta PULL ... auto / EN mail `u / n, we have (CRED VIEW and, and ... [the color of nature, SH |. children` s / \ Tao salary / M (BRED `Kai caw. I . C `Q Dale all auto MA / color is finally Skein /, known (oil. avlhqe, vest (Kai ovum and cry / day (Tourism / DR aunt / |.) 28, I think now / is not (technically, ( EDA that Nate aunt / |. \ I [or Narcotics Anonymous [Only fawner / | E Miscellaneous / parish space (oil. aivscunqw / male PULL auto / (EN and / |. Peruse, | auto /) 29 even avid or and / [u, Kayo, vest (gown, Barker, or [AP / 50 poi / s than Dionysus, NAN (VEX. auto / Gage, Naphtali) M a r t i n M u s a t o v 8 1 8 4 3 0 4 5 8 6 S M S m u s a t o v a t a t t d o t n e t From smaran.harihar at gmail.com Fri Aug 3 12:40:44 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Fri, 3 Aug 2012 09:40:44 -0700 Subject: Fwd: unable to get simple html file up In-Reply-To: References: Message-ID: guys i m still waiting for a reply ---------- Forwarded message ---------- From: Smaran Harihar Date: Thu, Aug 2, 2012 at 12:26 PM Subject: unable to get simple html file up To: python-list at python.org Hi, I am following this tutorial and i am not able to get the link.py up and running. I should be looking at Html file with link directing to the cgi script. But strangely i can't even see the page itself. Any idea why it is like this? I have made link.py executable. Here is the server.py . -- Thanks & Regards Smaran Harihar -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 3 12:40:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Aug 2012 16:40:59 GMT Subject: Eclipse and the Python plugin References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: <501bff1b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Aug 2012 16:51:26 +0100, lipska the kat wrote: > I can write a > Python class and call it Foo and save it in a file called Bar and it's > no big deal (at least Eclipse doesn't get excited) If I try that in Java > the sky falls in. :) Correct. Python does not require, or even encourage, the one-class-per- file rule of Java. You are encouraged to encapsulate related code into related units, for whatever is appropriate according to the situation. Whether than means one class in a module or ten will depend on the classes in question. And although it was quite prevalent in the past, these days the convention is avoid having the module and class name to be identical, as in time.time, unless you really have to. Preferred is something like decimal.Decimal. What I consider close to the extreme of what is comfortable in Python is the decimal module, which includes 19 classes and 21 module-level functions. It's not quite as scary as it seems -- many of those classes and functions are only a few lines each, and most of those are documentation. *Short* lines at that, this isn't Perl. The bulk of the module is only two classes, Decimal and Context. Mind you, both of those are seriously large, Decimal has 117 methods and Context around 70-80 (I stopped counting). So as I said, that's about the upper limit for what I consider reasonable in a single module. -- Steven From rodperson at rodperson.com Fri Aug 3 12:45:09 2012 From: rodperson at rodperson.com (Rod Person) Date: Fri, 3 Aug 2012 12:45:09 -0400 Subject: unable to get simple html file up In-Reply-To: References: Message-ID: <20120803124509.00001cac@unknown> On Fri, 3 Aug 2012 09:40:44 -0700 Smaran Harihar wrote: > guys i m still waiting for a reply > > ---------- Forwarded message ---------- > From: Smaran Harihar > Date: Thu, Aug 2, 2012 at 12:26 PM > Subject: unable to get simple html file up > To: python-list at python.org > > > Hi, > > I am following this > tutorial > and > i am not able to get the link.py up and > running. I should be looking at Html file with link directing to the > cgi script. > > But strangely i can't even see the page itself. Any idea why it is > like this? I have made link.py executable. Here is the > server.py > . > looks like the closing """ are missing from link.py -- Rod Person http://www.rodperson.com rodperson at rodperson.com From rosuav at gmail.com Fri Aug 3 12:54:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Aug 2012 02:54:28 +1000 Subject: unable to get simple html file up In-Reply-To: References: Message-ID: On Sat, Aug 4, 2012 at 2:40 AM, Smaran Harihar wrote: > guys i m still waiting for a reply You may get more helpful results if you add more information to your question. Also, be aware that you're asking volunteers to donate their time to you; according to the timestamps, it's less than a day since your original post. Granted, python-list IS a heavily-trafficked and fast-responding list (unlike several others I'm on, on which a week's delay is entirely possible), but even so, prodding should probably be left off until it's been rather longer. On the other hand, if your follow-up is adding a pile of additional (useful!) information, it won't look like a ping, and it actually will improve your chances of a reply. Here's a helpful resource on asking questions on these sorts of lists: http://www.catb.org/~esr/faqs/smart-questions.html Keep in mind that nobody's paid to help you, so you have to make us _want_ to respond. One of the best ways to do that is to make it easy for us to help you. ChrisA From lipskathekat at yahoo.co.uk Fri Aug 3 13:04:19 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 03 Aug 2012 18:04:19 +0100 Subject: Eclipse and the Python plugin In-Reply-To: <501bff1b$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> <501bff1b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/08/12 17:40, Steven D'Aprano wrote: > On Fri, 03 Aug 2012 16:51:26 +0100, lipska the kat wrote: > >> I can write a >> Python class and call it Foo and save it in a file called Bar and it's >> no big deal (at least Eclipse doesn't get excited) If I try that in Java >> the sky falls in. > > :) > > Correct. Python does not require, or even encourage, the one-class-per- > file rule of Java. snip Well it's actually one public class per file, you can have as many package visible classes as you like not to mention inner classes and anonymous classes, but I know what you mean. I used to know a developer who though that any file (class) that contained more lines of code than could fit on an A4 sheet of paper at 10 points was too large ... a little extreme perhaps. > Mind you, both of those are seriously large, Decimal has 117 methods and > Context around 70-80 (I stopped counting). So as I said, that's about the > upper limit for what I consider reasonable in a single module. 117 methods seems a lot doesn't it. I'm still trying to get my head around Python packages, I think Eclipse will help me with this and the whole module mix of functions and classes is taking a while to get used to. The standard included libraries are pretty impressive though and it is certainly easier to write quick throwaway prototypes in Python. I guess this will become even quicker once I understand the language better. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From javier at guerrag.com Fri Aug 3 13:17:31 2012 From: javier at guerrag.com (Javier Guerra Giraldez) Date: Fri, 3 Aug 2012 12:17:31 -0500 Subject: Demise of Mr. Kenneth Gonsalves In-Reply-To: References: Message-ID: On Fri, Aug 3, 2012 at 10:12 AM, Anoop Thomas Mathew wrote: > With my heartfelt condolence, I'd like to inform you all the unfortunate > demise of Mr.Kenneth Gonsalves (KG - lawgon at thenilgiris.com), who was a > strong advocate of Python, Django and Free Software in India. certainly sad news. i'm bad at remembering who did what; but i don't have to check the list to remember him as a very positive presence. thanks for sharing. -- Javier From subhabangalore at gmail.com Fri Aug 3 14:23:58 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Fri, 3 Aug 2012 11:23:58 -0700 (PDT) Subject: Calling Values In-Reply-To: References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: <0ddd0d5d-1b56-4eed-8f27-f01a54c7ced6@googlegroups.com> On Friday, August 3, 2012 10:50:52 PM UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 3 Aug 2012 04:49:46 -0700 (PDT), Subhabrata > > declaimed the following in > > gmane.comp.python.general: > > > > > Dear Group, > > > > > > I am trying to call the values of one function in the another function in the following way: > > > > Technically, "the values of one function" are whatever it RETURNS; > > > > > def func1(): > > > num1=10 > > > num2=20 > > > print "The Second Number is:",num2 > > > return > > > > > This function returns None. > > > > Recommended software design practices are that any thing inside the > > function should be local to just that function -- a function should be a > > black box -- you call it with some data, and you obtain some results > > when it returns; what it does internally should be "invisible" and have > > no effect on any other code. > > > > Read: > > http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29 > > (what you are attempting falls into "content coupling" if you change the > > use of "module" to "function") > > > > However, Python lets you declare names to be global (to the > > module/file). This is primarily meant to be used when a function must > > rebind a module level entity. (This would be "common coupling") > > > > def func1(): > > global num1, num2 > > ... > > > > But, as mentioned, that now makes num1 and num2 names that are known > > outside the functions. > > > > > def func2(): > > > num3=num1+num2 > > > num4=num3+num1 > > > print "New Number One is:",num3 > > > print "New Number Two is:",num4 > > > return > > > > > Misleading print statements, as you are NOT changing "number one" or > > "number two"; you've just created two NEW names (num3, num4). > > > > > I am preferring not to use argument passing or using class? Is there any alternate way? > > > > > > > Well, if you end func1 with > > > > return num1, num2 > > > > you can change func2 into: > > > > def func2(): > > n1, n2 = func1() > > num3 = n1 + n2 > > num4 = num3 + n1 > > ... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Dear Group, Absolutely brilliant, Ramit. Dennis also came with almost same answer. Using global may not give clean results everytime. I wanted to say, >>> def func1(): num1=10 num2=20 print "The Second Number is:",num2 >>> def func2(): func1() num3=50 print "The New Number is:",num3 >>> func2() The Second Number is: 20 The New Number is: 50 The post went slightly wrong sorry. No, I experiment myself on idle evenings to experiment with coding etc so I think of problems, practice on them and try to see if any better code evolves. Nothing else. I posted and Steve did not comment perhaps never happens. He rebukes me so much from my early days here, I just enjoy it. Regards and best wishes, Subhabrata. From subhabangalore at gmail.com Fri Aug 3 14:23:58 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Fri, 3 Aug 2012 11:23:58 -0700 (PDT) Subject: Calling Values In-Reply-To: References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: <0ddd0d5d-1b56-4eed-8f27-f01a54c7ced6@googlegroups.com> On Friday, August 3, 2012 10:50:52 PM UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 3 Aug 2012 04:49:46 -0700 (PDT), Subhabrata > > declaimed the following in > > gmane.comp.python.general: > > > > > Dear Group, > > > > > > I am trying to call the values of one function in the another function in the following way: > > > > Technically, "the values of one function" are whatever it RETURNS; > > > > > def func1(): > > > num1=10 > > > num2=20 > > > print "The Second Number is:",num2 > > > return > > > > > This function returns None. > > > > Recommended software design practices are that any thing inside the > > function should be local to just that function -- a function should be a > > black box -- you call it with some data, and you obtain some results > > when it returns; what it does internally should be "invisible" and have > > no effect on any other code. > > > > Read: > > http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29 > > (what you are attempting falls into "content coupling" if you change the > > use of "module" to "function") > > > > However, Python lets you declare names to be global (to the > > module/file). This is primarily meant to be used when a function must > > rebind a module level entity. (This would be "common coupling") > > > > def func1(): > > global num1, num2 > > ... > > > > But, as mentioned, that now makes num1 and num2 names that are known > > outside the functions. > > > > > def func2(): > > > num3=num1+num2 > > > num4=num3+num1 > > > print "New Number One is:",num3 > > > print "New Number Two is:",num4 > > > return > > > > > Misleading print statements, as you are NOT changing "number one" or > > "number two"; you've just created two NEW names (num3, num4). > > > > > I am preferring not to use argument passing or using class? Is there any alternate way? > > > > > > > Well, if you end func1 with > > > > return num1, num2 > > > > you can change func2 into: > > > > def func2(): > > n1, n2 = func1() > > num3 = n1 + n2 > > num4 = num3 + n1 > > ... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Dear Group, Absolutely brilliant, Ramit. Dennis also came with almost same answer. Using global may not give clean results everytime. I wanted to say, >>> def func1(): num1=10 num2=20 print "The Second Number is:",num2 >>> def func2(): func1() num3=50 print "The New Number is:",num3 >>> func2() The Second Number is: 20 The New Number is: 50 The post went slightly wrong sorry. No, I experiment myself on idle evenings to experiment with coding etc so I think of problems, practice on them and try to see if any better code evolves. Nothing else. I posted and Steve did not comment perhaps never happens. He rebukes me so much from my early days here, I just enjoy it. Regards and best wishes, Subhabrata. From bc at freeuk.com Fri Aug 3 16:04:41 2012 From: bc at freeuk.com (BartC) Date: Fri, 3 Aug 2012 21:04:41 +0100 Subject: simplified Python parsing question In-Reply-To: References: <5015C58D.4040101@harvee.org> <50165308.5060708@shopzeus.com><50165A94.5050906@harvee.org> <5016A140.7010106@shopzeus.com><50173aea$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Eric S. Johansson" wrote in message news:mailman.2752.1343700723.4697.python-list at python.org... > On 7/30/2012 9:54 PM, Steven D'Aprano wrote: > It would please me greatly if you would be willing to try an experiment. > live my life for a while. Sit in a chair and tell somebody what to type > and where to move the mouse without moving your hands. keep your hands > gripping the arms or the sides of the chair. The rule is you can't touch > the keyboard you can't touch the mice, you can't point at the screen. I > suspect you would have a hard time surviving half a day with these > limitations. no embarrassment in that, most people wouldn't make it as far > as a half a day. Just using speech? Probably more people than you might think have had such experiences: anyone who's done software support over the telephone for a start! And in that scenario, they are effectively 'blind' too. -- Bartc From lamialily at cleverpun.com Fri Aug 3 16:05:50 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 03 Aug 2012 13:05:50 -0700 Subject: Eclipse and the Python plugin References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: On Fri, 3 Aug 2012 06:54:04 -0700 (PDT), rusi wrote: >On Aug 3, 4:34?pm, lipska the kat wrote: >> A while ago someone asked me what I thought of the Eclipse plugin for >> python, well I just downloaded and installed the latest version of >> Eclipse for Java (Juno) followed by the Python plugin. > >Thanks Lipska for reporting back. >I personally find the eclipse UI frightening but I am unwilling to >conclude that its eclipse and not me. > >By comparison, when I first heard of emacs, (about 20 years ago) the >local guru would come in the morning and start emacs then go out for a >smoke. When he came back it had finished started up. >So the acronym: Eight Megabytes And Constantly Swapping made a lot of >sense then. I guess today it would have to be Eight-hundred to make >any sense. > >More to the point, it seems to me that eclipse was today what emacs >was then -- seemingly too large but in time I expect it will not seem >so large. > >So one more request from me: > >Can you try the refactoring support and tell us how it fares? Having used PyDev for Eclipse for a while, I can honestly say its memory consumption, while definitely rather large for the task, isn't so large as to cause any trouble for most modern systems. I'm able to keep it in the background with no notable performance impact, and if I do have to reopen it for whatever reason, it only takes about ten seconds. A small price to pay for easy code completion, docstrings in tooltips, and a more user-friendly debugger (though some things like weakref containers will happily fool it and make debugging a little more difficult). ~Temia -- Invective! Verb your expletive nouns! From daniel at roseman.org.uk Fri Aug 3 16:39:50 2012 From: daniel at roseman.org.uk (Daniel Roseman) Date: Fri, 3 Aug 2012 13:39:50 -0700 (PDT) Subject: Demise of Mr. Kenneth Gonsalves In-Reply-To: References: Message-ID: <2fa5ee85-1896-4821-9883-e2d4929a8d96@googlegroups.com> On Friday, 3 August 2012 16:12:35 UTC+1, atm wrote: > > With my heartfelt condolence, I'd like to inform you all the unfortunate > demise of Mr.Kenneth Gonsalves (KG - lawgon at thenilgiris.com), who was a > strong advocate of Python, Django and Free Software in India. > He had served as the President of IPSS(Indian Python Software Society), > which initiated the PyCon India, done a lot of workshops on Python and was > an active member in the Django user group. > > Anoop Thomas Mathew > That's a shock. He was a valued contributor to this list and to the Django community in general. Please pass on condolences to his family and friends. -- Daniel. -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at tobiah.org Fri Aug 3 16:48:08 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 03 Aug 2012 13:48:08 -0700 Subject: Deciding inheritance at instantiation? Message-ID: I have a bunch of classes from another library (the html helpers from web2py). There are certain methods that I'd like to add to every one of them. So I'd like to put those methods in a class, and pass the parent at the time of instantiation. Web2py has a FORM class for instance. I'd like to go: my_element = html_factory(FORM) Then my_element would be an instance of my class, and also a child of FORM. I started messing with decorators, but it became difficult for me to visualise how to do this. Thanks! Toby From tjreedy at udel.edu Fri Aug 3 17:55:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 03 Aug 2012 17:55:33 -0400 Subject: Deciding inheritance at instantiation? In-Reply-To: References: Message-ID: On 8/3/2012 4:48 PM, Tobiah wrote: > I have a bunch of classes from another library (the html helpers > from web2py). There are certain methods that I'd like to add to > every one of them. So I'd like to put those methods in a class, > and pass the parent at the time of instantiation. Web2py has > a FORM class for instance. I'd like to go: > > my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also > a child of FORM. > > I started messing with decorators, but it became difficult > for me to visualise how to do this. Use type(name, bases, content) for dynamic class creation. -- Terry Jan Reedy From d at davea.name Fri Aug 3 18:20:33 2012 From: d at davea.name (Dave Angel) Date: Fri, 03 Aug 2012 18:20:33 -0400 Subject: attribute is accessed from Nonetype In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> Message-ID: <501C4EB1.80003@davea.name> On 08/03/2012 03:01 AM, Prasad, Ramit wrote: >> Also, please use the names correctly and consistently. The None object >> (yes, there is only one) is not the same as a none object. And there is >> no standard type called Nonetype. > To be fair, this is not very clear to a beginner. > >>>> len(None) # Python 2.6 > TypeError: object of type 'NoneType' has no len() > I'm sorry, what's not clear? Nonetype is not the same as NoneType. Python is case sensitive. -- DaveA From rosuav at gmail.com Fri Aug 3 18:41:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Aug 2012 08:41:20 +1000 Subject: attribute is accessed from Nonetype In-Reply-To: <501C4EB1.80003@davea.name> References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> <501C4EB1.80003@davea.name> Message-ID: On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: > I'm sorry, what's not clear? Nonetype is not the same as NoneType. > Python is case sensitive. There isn't a NoneType either. I get a NameError. ChrisA From dark.kase at gmail.com Fri Aug 3 18:50:29 2012 From: dark.kase at gmail.com (dark.kase at gmail.com) Date: Fri, 3 Aug 2012 15:50:29 -0700 (PDT) Subject: python pynotify with textbox input Message-ID: <6a92314c-beb9-486b-9ed1-cb00b0e73e4a@googlegroups.com> how can i made a notification for gnome-shell with a textbox input ?? library: pynotify? From d at davea.name Fri Aug 3 19:03:20 2012 From: d at davea.name (Dave Angel) Date: Fri, 03 Aug 2012 19:03:20 -0400 Subject: attribute is accessed from Nonetype In-Reply-To: References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> <501C4EB1.80003@davea.name> Message-ID: <501C58B8.8080607@davea.name> On 08/03/2012 06:41 PM, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >> Python is case sensitive. > There isn't a NoneType either. I get a NameError. > > ChrisA NoneType isn't in the builtin namespace. It's in the types module. import types a = types.Nonetype It's still special, because None is a singleton. In any case there are a number of places where the string "NoneType" is produced, >>> type(None) >>> None + 3 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' >>> None[3] Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not subscriptable etc. and it's in the docs, at least on page: http://docs.python.org/library/constants.html -- DaveA From cousinstanley at gmail.com Fri Aug 3 19:29:55 2012 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 3 Aug 2012 23:29:55 +0000 (UTC) Subject: Eclipse and the Python plugin References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: lipska the kat wrote: > .... > I can now create, debug and test a simple IRC server > written in Java and an IRC Bot that I am attempting > to build in Python > .... For a bit of inspiration python-irc-bot-wise you might look at supybot .... It's currently available in debian wheezy so probably also available in ubuntu .... # apt-cache show supybot A few years back I ran it 24/7 for several months on a very low spec debian box and was impressed with its performance, configurability, and plugin usage .... However, I haven't looked at or used recent versions .... -- Stanley C. Kitching Human Being Phoenix, Arizona From nobody at nowhere.com Fri Aug 3 19:52:53 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 04 Aug 2012 00:52:53 +0100 Subject: Deciding inheritance at instantiation? References: Message-ID: On Fri, 03 Aug 2012 13:48:08 -0700, Tobiah wrote: > I have a bunch of classes from another library (the html helpers > from web2py). There are certain methods that I'd like to add to > every one of them. So I'd like to put those methods in a class, > and pass the parent at the time of instantiation. Web2py has > a FORM class for instance. I'd like to go: > > my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also > a child of FORM. You can use type() to create classes dynamically. E.g.: class my_base_class(object): # extra methods subclasses = {} def html_factory(cls, *args, **kwargs): name = "my_" + cls.__name__ if name not in subclasses: subclasses[name] = type(name, (cls, my_base_class), {}) return subclasses[name](*args, **kwargs) From steve+comp.lang.python at pearwood.info Fri Aug 3 20:23:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 00:23:26 GMT Subject: attribute is accessed from Nonetype References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> <501C4EB1.80003@davea.name> Message-ID: <501c6b7e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 08:41:20 +1000, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >> Python is case sensitive. > > There isn't a NoneType either. I get a NameError. Shame on you :-P Ramit Prasad showed exactly how you can see NoneType in action in the part of the post you snipped from your reply. py> len(None) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'NoneType' has no len() NoneType *is* a standard type. It's just not bound to a publicly accessible name in the built-ins. But you can easily get access to the class using either: type(None) None.__class__ or in Python 2.6 at least, import types types.NoneType (although it has been removed from Python 3.2 for some reason). -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 3 21:14:48 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 01:14:48 GMT Subject: Deciding inheritance at instantiation? References: Message-ID: <501c7787$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Aug 2012 13:48:08 -0700, Tobiah wrote: > I have a bunch of classes from another library (the html helpers from > web2py). There are certain methods that I'd like to add to every one of > them. So I'd like to put those methods in a class, and pass the parent > at the time of instantiation. Web2py has a FORM class for instance. > I'd like to go: > > my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also a child of > FORM. I cannot understand what you are actually trying to do here because you aren't giving enough information and the description you give is misleading. But from what little I can grasp, I think it sounds like an unclean, confusing design and you would be better off with either mixins, composition, or code injection. What is html_factory? By the name, it should return some HTML. But you're assigning the output to something called "my_element", which suggests it is returning only a single element of HTML. To me, I would expect that to be a string. Consequently, it isn't clear to me what you actually want, and I'm forced to make some wild guesses, and I can see a number of different alternative approaches. === Mixins === You state: There are certain methods that I'd like to add to every one of [my classes]. So I'd like to put those methods in a class, and pass the parent at the time of instantiation Don't pass the utility class at instantiation time. Use it as a mixin class. class UtilityMixin: # add "those methods" to this class pass class MyClassA(MyParentClass, UtilityMixin): pass class MyClassB(AnotherClass, UtilityMixin): pass class MyClassC(MyClassB): # already inherits from UtilityMixin pass === Composition === This frankly sounds like an abuse of inheritance. Inheritance is for modelling "is-a" relationships, not just for sticking arbitrary lumps of unrelated code together. If I can understand what you are trying to do, then you need to model a "has-a" relationship. For example: The Contact Us page is not a html form, it HAS a html form; therefore the instance which creates the Contact Us page is not a html form either, and should not inherit from FormClass; but it should have a FormClass instance it can delegate the creation of the form to. Something like this, perhaps: contact_page_designer = PageDesigner() contact_page_designer.form_designer = FormClass() This can be wrapped inside the __init__ method, of course. The FormClass instance can be passed as a generic argument. Then, your PageDesigner methods which need to create a form simply delegate the work to the form_designer attribute. Instead of this: self.make_form() which depends on self having ten different methods to do with making forms, you do this: self.form_designer.make_form() and all the form-related methods are encapsulated in one place, out of the way. This general technique is known as composition, or delegation, and you use it every time you do something like this: result = self.name.upper() # delegating upper method to the string name And yet, somehow people forget it in favour of inheritance once they move beyond the primitive built-in types. === Code injection === You talk about deciding inheritance at instantiation time, which implies that each instance will get different methods. If so, then so long as you aren't changing dunder methods (double leading and trailing underscore special methods like __init__ and friends), you can inject methods directly onto an instance, either to add new functionality or override existing functionality on a per-instance basis. py> class Parrot: ... def speak(self): ... print "Polly wants a cracker!" ... py> class KillBot: ... def speak(self): ... print "Crush! Kill! Destroy!" ... py> p = Parrot() py> p.speak() Polly wants a cracker! py> p.speak = KillBot().speak py> p.speak() Crush! Kill! Destroy! === Dynamic class creation === Forget about using type(), there's an easier way. def factory(name, parent_class): class MyClass(parent_class): def method(self): print "Called method" return 42 MyClass.__name__ = name return MyClass Much easier than the equivalent using type. def method(self): print "Called method" return 42 type(name, (parent_class,), {'method': method}) -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 3 21:35:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 01:35:45 GMT Subject: attribute is accessed from Nonetype References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> <501C4EB1.80003@davea.name> Message-ID: <501c7c71$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Aug 2012 19:03:20 -0400, Dave Angel wrote: > On 08/03/2012 06:41 PM, Chris Angelico wrote: >> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >>> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >>> Python is case sensitive. >> There isn't a NoneType either. I get a NameError. >> >> ChrisA > > NoneType isn't in the builtin namespace. It's in the types module. > > import types > a = types.Nonetype ^^^^^^^^ Oh the irony. After criticising a beginner for getting the case wrong, you have done exactly the same thing. A form of Muphry's Law (the Iron Law of Nitpicking) perhaps? http://en.wikipedia.org/wiki/Muphry%27s_law -- Steven From d at davea.name Fri Aug 3 21:58:28 2012 From: d at davea.name (Dave Angel) Date: Fri, 03 Aug 2012 21:58:28 -0400 Subject: attribute is accessed from Nonetype In-Reply-To: <501c7c71$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501A5EAF.9090501@davea.name> <5B80DD153D7D744689F57F4FB69AF4741659DDF5@SCACMX008.exchad.jpmchase.net> <501C4EB1.80003@davea.name> <501c7c71$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501C81C4.7050405@davea.name> On 08/03/2012 09:35 PM, Steven D'Aprano wrote: > On Fri, 03 Aug 2012 19:03:20 -0400, Dave Angel wrote: > >> On 08/03/2012 06:41 PM, Chris Angelico wrote: >>> On Sat, Aug 4, 2012 at 8:20 AM, Dave Angel wrote: >>>> I'm sorry, what's not clear? Nonetype is not the same as NoneType. >>>> Python is case sensitive. >>> There isn't a NoneType either. I get a NameError. >>> >>> ChrisA >> NoneType isn't in the builtin namespace. It's in the types module. >> >> import types >> a = types.Nonetype > ^^^^^^^^ > > Oh the irony. After criticising a beginner for getting the case wrong, > you have done exactly the same thing. > > A form of Muphry's Law (the Iron Law of Nitpicking) perhaps? > > http://en.wikipedia.org/wiki/Muphry%27s_law > You are, of course right; I blew it. Thanks for pointing it out with humor. -- DaveA From python.list at tim.thechases.com Fri Aug 3 23:08:42 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 03 Aug 2012 22:08:42 -0500 Subject: dbf.py API question In-Reply-To: <501BCE1F.6050001@stoneleaf.us> References: <501AA304.3090000@stoneleaf.us> <501BCE1F.6050001@stoneleaf.us> Message-ID: <501C923A.3060205@tim.thechases.com> On 08/03/12 08:11, Ethan Furman wrote: > So far all feedback is for the flag, so that's what I'll do. I agree with the flag, though would also be reasonably content with using None for the filename to indicate in-memory rather than on-disk storage. -tkc From einazaki668 at yahoo.com Fri Aug 3 23:12:45 2012 From: einazaki668 at yahoo.com (Eric) Date: Fri, 3 Aug 2012 20:12:45 -0700 (PDT) Subject: trouble with pyplot in os x Message-ID: <3a2464ec-8fbc-4c45-8509-6861031f9204@googlegroups.com> I'm just starting to futz around with matplotlib and I tried to run this example from the matplotlib doc page (it's the imshow() example): import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt delta = 0.025 x = y = np.arange(-3.0, 3.0, delta) X, Y = np.meshgrid(x, y) Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) Z = Z2-Z1 # difference of Gaussians im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, origin='lower', extent=[-3,3,-3,3]) plt.show() I get the following error: Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ return self.func(*args) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 248, in resize self.show() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 252, in draw tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 19, in blit tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array)) TclError I'm using Python 2.7.3 on OS X 10.6.8 and I'm invoking python by doing "arch -i386 python" because matplotlib doesn't do 64-bit. Has anyone else seen this? Does anyone know why this is happening? It looks like a problem with tkinter but beyond that I haven't a clue. And, finally, any ideas as to how to make it behave? TIA, eric From steveo at syslang.net Fri Aug 3 23:14:11 2012 From: steveo at syslang.net (Steven W. Orr) Date: Fri, 03 Aug 2012 23:14:11 -0400 Subject: Deciding inheritance at instantiation? In-Reply-To: References: Message-ID: <501C9383.7060509@syslang.net> On 8/3/2012 4:48 PM, Tobiah wrote: > I have a bunch of classes from another library (the html helpers > from web2py). There are certain methods that I'd like to add to > every one of them. So I'd like to put those methods in a class, > and pass the parent at the time of instantiation. Web2py has > a FORM class for instance. I'd like to go: > > my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also > a child of FORM. > > I started messing with decorators, but it became difficult > for me to visualise how to do this. > > Thanks! > > Toby Your class inherits from whatever is in the class statement. class Foo(object): pass Here, Foo inherits from object, but you can replace object with any tuple of classes which can be redefined before instantiation. class Base1(object): pass class Base2(object): pass Now we can define Foo2 to inherit from something that better be a tuple of classes at instantiation time. class Foo2(bases): pass bases = (Base1,) foo2 = Foo2() # foo2 is a Foo2 which inherits from Base1. bases = (Base1, Bace2) foob1b2 = Foo2() # foob1b2 is a Foo2 which inherits from Base1 and Base2. Who was it who said: "Give a man a shovel and he'll dig himself one helluva hole"? -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From alelee96 at gmail.com Fri Aug 3 23:54:04 2012 From: alelee96 at gmail.com (sistema) Date: Fri, 3 Aug 2012 20:54:04 -0700 (PDT) Subject: test Message-ID: test From rustompmody at gmail.com Sat Aug 4 00:54:12 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 3 Aug 2012 21:54:12 -0700 (PDT) Subject: Eclipse and the Python plugin References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> <501bff1b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <178b6396-ed3c-47cc-8b6e-c4c002063de7@hq10g2000pbc.googlegroups.com> On Aug 3, 10:04?pm, lipska the kat wrote: > > 117 methods seems a lot doesn't it. I'm still trying to get my head > around Python packages, I think Eclipse will help me with this and the > whole module mix of functions and classes is taking a while to get used > to. The standard included libraries are pretty impressive though and it > is certainly easier to write quick throwaway prototypes in Python. Good that you get this early. The python libraries are well crafted and well documented. They are also not over engineered so that you can get to what you want without a loooong: org.dada.lang.servlet.dada... (Which is also why 117 can be ok) The thing about python that experienced C++ and Java programmers are most likely to miss is a mode of playful working in which trying out small pieces in the interpreter is a key part of the development process. (and which is why functions are ok, not just classes) If eclipse supports this well I'd be interested to know. If not you need to supplement eclipse with (something like) - python inside shell - ipython inside shell - python inside python-mode inside emacs [The first turns out to be a pain because import wont work more than once, reload wont work the first time, and if you do import * nothing will work after the first time] From steve+comp.lang.python at pearwood.info Sat Aug 4 02:15:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 06:15:20 GMT Subject: On-topic: alternate Python implementations Message-ID: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Most people are aware, if only vaguely, of the big Four Python implementations: CPython, or just Python, the reference implementation written in C. IronPython, written in .NET. Jython, written in Java. PyPy, the optimizing implementation written in Python (actually, it's written in a subset of Python, RPython). But the Python ecosystem is a lot bigger than just those four. Here are just a few other implementations that you might be interested in: Stackless - the "forgetten Python", Stackless is, I believe, the oldest implementation behind only CPython itself. It's a fork of CPython with the calling stack removed and fast and lightweight microthreads, and is used extensively in EVE Online. http://www.stackless.com/ Nuitka - optimising Python compiler written in C++, supports Python 2.6 and 2.7, claims to be up to twice as fast as CPython. http://nuitka.net/pages/overview.html WPython - another optimizing version of Python with wordcodes instead of bytecodes. http://code.google.com/p/wpython/ CLPython, an implementation of Python written in Common Lisp. http://common-lisp.net/project/clpython/ CapPython is an experimental restricted version of Python with capabilities. http://plash.beasts.org/wiki/CapPython http://en.wikipedia.org/wiki/Object-capability_model Berp - a compiler which works by translating Python to Haskell and compiling that. https://github.com/bjpop/berp/wiki Give them some love! -- Steven From rosuav at gmail.com Sat Aug 4 02:34:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Aug 2012 16:34:17 +1000 Subject: On-topic: alternate Python implementations In-Reply-To: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano wrote: > CLPython, an implementation of Python written in Common Lisp. > > Berp - a compiler which works by translating Python to Haskell and > compiling that. Okay. WHY? CLPython gives some reason, but how often do you need to bridge that particular pair of languages? And why compile Python via Haskell, when C is available as a "high level assembly language"? The mind boggles... ChrisA From stefan_ml at behnel.de Sat Aug 4 02:40:16 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 08:40:16 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 04.08.2012 08:15: > Most people are aware, if only vaguely, of the big Four Python > implementations: > > CPython, or just Python, the reference implementation written in C. > IronPython, written in .NET. > Jython, written in Java. > PyPy, the optimizing implementation written in Python (actually, it's > written in a subset of Python, RPython). > > But the Python ecosystem is a lot bigger than just those four. Here are > just a few other implementations that you might be interested in: > > > Stackless - the "forgetten Python", Stackless is, I believe, the oldest > implementation behind only CPython itself. It's a fork of CPython with > the calling stack removed and fast and lightweight microthreads, and is > used extensively in EVE Online. > > http://www.stackless.com/ > > > Nuitka - optimising Python compiler written in C++, supports Python 2.6 > and 2.7, claims to be up to twice as fast as CPython. > > http://nuitka.net/pages/overview.html > > > WPython - another optimizing version of Python with wordcodes instead of > bytecodes. > > http://code.google.com/p/wpython/ > > > CLPython, an implementation of Python written in Common Lisp. > > http://common-lisp.net/project/clpython/ > > > CapPython is an experimental restricted version of Python with > capabilities. > > http://plash.beasts.org/wiki/CapPython > http://en.wikipedia.org/wiki/Object-capability_model > > > Berp - a compiler which works by translating Python to Haskell and > compiling that. > > https://github.com/bjpop/berp/wiki And not to forget Cython, which is the only static Python compiler that is widely used. Compiles and optimises Python to C code that uses the CPython runtime and allows for easy manual optimisations to get C-like performance out of it. http://cython.org/ Stefan From lipskathekat at yahoo.co.uk Sat Aug 4 03:46:41 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Sat, 04 Aug 2012 08:46:41 +0100 Subject: Eclipse and the Python plugin In-Reply-To: References: <-rSdnaVYT4PNKobNnZ2dnUVZ7r2dnZ2d@bt.com> Message-ID: <7KadnUMhoMb_ToHNnZ2dnUVZ8h2dnZ2d@bt.com> On 04/08/12 00:29, Cousin Stanley wrote: > lipska the kat wrote: > >> .... >> I can now create, debug and test a simple IRC server >> written in Java and an IRC Bot that I am attempting >> to build in Python >> .... > > For a bit of inspiration python-irc-bot-wise > you might look at supybot .... > Yep, it's there (here). Thanks for the heads up lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From steve+comp.lang.python at pearwood.info Sat Aug 4 03:49:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 07:49:53 GMT Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote: > And not to forget Cython, which is the only static Python compiler that > is widely used. Compiles and optimises Python to C code that uses the > CPython runtime and allows for easy manual optimisations to get C-like > performance out of it. > > http://cython.org/ Cython is great, but I question that it is a *Python* implementation. That's not a criticism of Cython, but it is different from Python. Take this example code from the tutorial: from libc.math cimport sin cdef double f(double x): return sin(x*x) If that's Python code, then I'm Ethel the Aardvark. Cython is very Python-like, but there is no doubt in my mind that it is a superset of Python and therefore a different language. -- Steven From breamoreboy at yahoo.co.uk Sat Aug 4 05:09:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Aug 2012 10:09:16 +0100 Subject: python pynotify with textbox input In-Reply-To: <6a92314c-beb9-486b-9ed1-cb00b0e73e4a@googlegroups.com> References: <6a92314c-beb9-486b-9ed1-cb00b0e73e4a@googlegroups.com> Message-ID: On 03/08/2012 23:50, dark.kase at gmail.com wrote: > how can i made a notification for gnome-shell with a textbox input ?? > > library: pynotify? > Write some code and when you get problems with it post the code here and we'll gladly answer your questions. -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Sat Aug 4 05:10:40 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 11:10:40 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 04.08.2012 09:49: > On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote: >> And not to forget Cython, which is the only static Python compiler that >> is widely used. Compiles and optimises Python to C code that uses the >> CPython runtime and allows for easy manual optimisations to get C-like >> performance out of it. >> >> http://cython.org/ > > Cython is great, but I question that it is a *Python* implementation. > That's not a criticism of Cython, but it is different from Python. Take > this example code from the tutorial: > > from libc.math cimport sin > > cdef double f(double x): > return sin(x*x) > > If that's Python code, then I'm Ethel the Aardvark. We never met in person, so I can't comment on the last part. However, the above is Cython code and, yes, that's a different language. Note that it uses a different file extension: ".pyx". Try putting the above code into a .py file and compiling that. Cython will reject it and tell you that "cimport" is not valid Python syntax. > Cython is very Python-like, but there is no doubt in my mind that it is a > superset of Python and therefore a different language. As long as you don't use any features of the Cython language, it's plain Python. That makes it a Python compiler in my eyes. The fact that you can easily use C features to optimise your code (also in Python syntax, BTW) doesn't impact that. You mentioned a couple of other implementations and I'm sure they have features (and bugs) that CPython doesn't have. Interaction with Lisp code in CLPython, for example. I don't think additional features or language implementation bugs make a Python implementation non-Python per se. Also note that most of the less widely known "alternative Python implementations" do not even publish their results of running the CPython test suite, so how do you actually know they can run Python code? Stefan From breamoreboy at yahoo.co.uk Sat Aug 4 06:05:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Aug 2012 11:05:24 +0100 Subject: On-topic: alternate Python implementations In-Reply-To: <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/08/2012 08:49, Steven D'Aprano wrote: > On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote: > >> And not to forget Cython, which is the only static Python compiler that >> is widely used. Compiles and optimises Python to C code that uses the >> CPython runtime and allows for easy manual optimisations to get C-like >> performance out of it. >> >> http://cython.org/ > > Cython is great, but I question that it is a *Python* implementation. > That's not a criticism of Cython, but it is different from Python. Take > this example code from the tutorial: > > from libc.math cimport sin > > cdef double f(double x): > return sin(x*x) > > If that's Python code, then I'm Ethel the Aardvark. > > Cython is very Python-like, but there is no doubt in my mind that it is a > superset of Python and therefore a different language. > > I agree so it's off topic and can't be discussed here. Isn't that right, Stefan? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Sat Aug 4 06:54:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Aug 2012 10:54:27 GMT Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 16:34:17 +1000, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano > wrote: >> CLPython, an implementation of Python written in Common Lisp. >> >> Berp - a compiler which works by translating Python to Haskell and >> compiling that. > > Okay. WHY? CLPython gives some reason, but how often do you need to > bridge that particular pair of languages? And why compile Python via > Haskell, when C is available as a "high level assembly language"? For much the same reason that PyPy uses RPython when C is available. Because Haskell is available as a high level non-assembly language. Berp is based on the Glasgow Haskell Compiler, which is a modern, efficient, optimizing compiler capable of producing excellent quality machine code on Windows, Mac, Linux and many Unixes. It gives you all the advantages of a high-level language with high-level data structures, type inference, and a compiler capable of generating optimized, fast, machine code. Who would want to deal with C's idiosyncrasies, low-powered explicit type system, difficult syntax, and core-dumps, when you could use something better? Apart from C programmers, of course. -- Steven From stefan_ml at behnel.de Sat Aug 4 06:59:02 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 12:59:02 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mark Lawrence, 04.08.2012 12:05: > I agree so it's off topic and can't be discussed here. Isn't that right, > Stefan? Hmm, in case you are referring to a recent friendly and diplomatic request of mine regarding a couple of people who were burdening a public high volume mailing list with a purely private back-and-forth chat about having beer and getting drunk - then, no, I don't think the discussion in this thread qualifies as yet another example for that so far. Stefan From stefan-usenet at bytereef.org Sat Aug 4 07:18:02 2012 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sat, 4 Aug 2012 13:18:02 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120804111802.GA13537@sleipnir.bytereef.org> Steven D'Aprano wrote: > Who would want to deal with C's idiosyncrasies, low-powered explicit type > system, difficult syntax, and core-dumps, when you could use something > better? In the free software world, apparently many people like C. C is also quite popular in the zero-fault software world: Several verification tools do exist and Leroy et al. are writing a certified compiler for C to plug the hole between the verified source code and the generated assembly. Stefan Krah From stefan_ml at behnel.de Sat Aug 4 07:32:22 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 13:32:22 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 04.08.2012 12:54: > Berp is based on the Glasgow Haskell Compiler, which is a modern, > efficient, optimizing compiler capable of producing excellent quality > machine code on Windows, Mac, Linux and many Unixes. It gives you all the > advantages of a high-level language with high-level data structures, type > inference, and a compiler capable of generating optimized, fast, machine > code. Although all those optimisations don't mean that Python code would run fast on top of it. Just because you translate Python to another language and platform doesn't mean that there's any benefit from the underlying platform optimisations. Both PyPy and Cython run Python code faster than CPython, but not because they eventually translate it into machine code but because they optimise and specialise it along the way, based on its high-level code constructs. One big success of the Unladen Swallow project was to show that bare JIT compilation is mostly worthless for high level languages. > Who would want to deal with C's idiosyncrasies, low-powered explicit type > system, difficult syntax, and core-dumps, when you could use something > better? The core developers of both CPython and Cython aim for exactly that. They write C so you don't have to. But keep in mind that C is still *the* lingua franca of software development. A major reason why Python is (slowly) catching up these days is that the main implementation is written in C and makes it easy to interface with C code. Stefan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sat Aug 4 08:51:27 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sat, 04 Aug 2012 14:51:27 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 04.08.2012 11:10 schrieb Stefan Behnel: > As long as you don't use any features of the Cython language, it's plain > Python. That makes it a Python compiler in my eyes. Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C and C++ are distinct languages and so are Python and Cython. Thomas From maniandram01 at gmail.com Sat Aug 4 09:10:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 4 Aug 2012 18:40:39 +0530 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: The first time I did reply not 'reply all', so I'm posting again. ;-) I think Cython is a Python implementation because you can only use the Python features, not the extra features. C++ is different because of the different rules (C was in a time of assembly and costly computers, C++ was made in the time of (relatively) cheaper computers and computers doing more things) On 4 August 2012 18:21, Thomas Rachel < nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de> wrote: > Am 04.08.2012 11:10 schrieb Stefan Behnel: > > > As long as you don't use any features of the Cython language, it's plain >> Python. That makes it a Python compiler in my eyes. >> > > Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C > and C++ are distinct languages and so are Python and Cython. > > > Thomas > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wrw at mac.com Sat Aug 4 09:11:44 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Sat, 04 Aug 2012 09:11:44 -0400 Subject: trouble with pyplot in os x In-Reply-To: <3a2464ec-8fbc-4c45-8509-6861031f9204@googlegroups.com> References: <3a2464ec-8fbc-4c45-8509-6861031f9204@googlegroups.com> Message-ID: On Aug 3, 2012, at 11:12 PM, Eric wrote: > I'm just starting to futz around with matplotlib and I tried to run this > example from the matplotlib doc page (it's the imshow() example): > > import numpy as np > import matplotlib.cm as cm > import matplotlib.mlab as mlab > import matplotlib.pyplot as plt > > delta = 0.025 > x = y = np.arange(-3.0, 3.0, delta) > X, Y = np.meshgrid(x, y) > Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) > Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) > Z = Z2-Z1 # difference of Gaussians > > im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, > origin='lower', extent=[-3,3,-3,3]) > > plt.show() > > OK > > I get the following error: > > Exception in Tkinter callback > Traceback (most recent call last): > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ > return self.func(*args) > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 248, in resize > self.show() > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 252, in draw > tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2) > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 19, in blit > tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array)) > TclError > > This looks as though you are running the latest python from python.org, not the pre-installed python from Apple (that's good). > > I'm using Python 2.7.3 on OS X 10.6.8 and I'm invoking python by doing > "arch -i386 python" because matplotlib doesn't do 64-bit. Has anyone > else seen this? Does anyone know why this is happening? It looks > like a problem with tkinter but beyond that I haven't a clue. And, > finally, any ideas as to how to make it behave? > I DON'T know how tk is getting mixed into this, it shouldn't be. But I think I can tell you how to get matplotlib working... Matplotlib DOES do 64-bit, the problem is numpy, which as you download in binary form does not. But, if you copy the bash script here: https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh it will download the sources and build a 64-bit numpy, which will then give you a default 64-bit full package of python, numpy, and matplotlib. That's what I've done, and my system runs the demo you listed in your post with no problems. > TIA, > eric > -- > http://mail.python.org/mailman/listinfo/python-list Good luck, -Bill From maniandram01 at gmail.com Sat Aug 4 09:22:24 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 4 Aug 2012 18:52:24 +0530 Subject: avlhqw avlhqeavlhqino ovfqalmw avlhqei avlhqeaivscunqw In-Reply-To: References: Message-ID: Is this spam? If not, can you please explain the message better (I don't get it) and *Please* change the title, it look like spam. On 3 August 2012 21:58, Martin Michael Musatov wrote: > Thanks to technology, a memorandum of understanding (thanks from Tel > Aviva / s, F `u / n (I [I TO rotate HM), and try to think, nature is" > E | .. (no offense to kiloton preparation. .. has C, E (Visor / s > Chest on Tuesday Kin \ 2 I "auto. Hi Lasso, Wilson vest / Na` martin / > NH MW `. brought / \ n VIEW goals WT /" NH, RAN, not (I all, or [that > load / Samoa ...) I think the WT DR 3 ??? | ..... gown or some [even > in auto Cayman S (j eventual auto Arabia will not bar / threw / a) "L" > 4 Oh, BAG, Gen auto, n (oil. raj Anatole?s auto / threw HM / s (Tao, > she vest (EDA Kai May that | Hall and hold LEIA ovum .. \ 5] 505 A > thru / |? auto / ton, John (avlhqw / DVDs eggs MAY Tues | H, the pH of > WAIT May / U / Eyelet) EN May two | gown or some [aunt EN his / | even > \ "LO 6` EN aunt BAG / | .. I over Ni (Kama?s evoke / NO perinea, U > (and auto [Peripatetic To /) 7 Adelaide (n ovum Ventolin.n akin > graphite, F I '/ S (all Ventolin.n Palau an (10] not PULL arch / s \ > "from" H vesting Vent Olin not clear, Greek] is Zhukov PULL arch / d) > eight times a year, Lin Ventolin.n akin No Thanks, I `F u / n (or > [vesting avlhqe.j EN aunt / | .. (EDA Mr. Kai N / A \ [paragraph` t > Scottie (oil. F / 500 .. for avlhqino NH, N DH SIP) Get 9 or "50", BAG > EN WT / ... | wit Chennai is = (oil. ton Adolfo.n auto / miss / s (EN > and / | Scottie |. vest to [WK with RS) agape or 10 "/ n ton Adolfo > auto n / EDA (VA / |. wit I (EDA Yolanda aunt Kai Ski / | ovum > resist ...) The 11-misw / s ton Adolfo.n auto / (EN and / |. of > Scottie | vest (EN and Kai / |. Scottie, |. reputation / (1000 = ovum > want and / u-PA Gay (or [`t Scottie in veto, flues you?d goalmouth > auto / s) 12 degrees , F U "/ (technical., 1 (or [I AVE, entail I` u / > n Martin, all comments. what auto .. N / A 13 ?), F U "I / O (open, RE > ( or [cover even. PULL arch n / graphite), F MIL `U / N (, SK spin (or > [enrich coverage ton poncho, B) from 14 degrees, F" u / n (payment (or > [I even , violation of ton, CA), Ms. Gray MIL / V (e, RE (or [even. > PULL arch n / d) and covering gray / 500 (rotation of the earth (or [I > chiaroscuro, vest (Okay., May Beautiful / U / u `EN MIL / n, the game > will cover (.. Kai does not enrich poncho n .. n), BR 15 agape / O. > MADE EN dispute a / VA |. SEW PM | ) Eva agape / | ton difference > (ovum times are eggs, the pH can parent / EN aunt J / |. \ 16 or [/ n, > EN VA / |. KB, SEW | (MK pique / and Nark. CK (b pique-Kai, has / the > ovfqalmw N / S (H Kai emblazon "organic unity / straight (and keep .. > ovum EVE, May / June protection. all SAP or requests vest Additional > Protocol to the Agreement), I 17 "He was not, smog parameters, Get > (oil. pique` H, E and auto / \ O `poi / s .. May LAMA / U / read evil > ton avid / N) 18 (escape, O [ RA vest (oil. Kama?s Zhukov, and sat > down, or [O `ante, God. retail (Shoat. / ante there, students Ego > Crista, however, and \ or R [N and gown or some [escape you [PR vest, > n), '19 VEX MW / n vex / lion (San all ovum VEX H = H ', w / w \ AV > garb San VEX = "b, w / w (moment, An Keenan me B MW / n \ all I [/ Na > fawner or sin [e-IT ovum ease net VEX-In. MW / N) 20, I / cry / of > ADM. whales ... digestive ALPO Director / ovum `, (O Kai, gave > permission, s) and -21 000 Gray `u / n (or [O ovum given than all, > wean (all or O [which aunt, N (or Kai. [PA-IT / Tao n / EVE and > avlhqei M / d, and AGE tablespoons ovum). March 22 vesting of Tao, she > (IV US memo avenue # in Visor [u / ovum, hold, or God, or S *, where > he was the Messiah ante vesting (avenue, memo ton GS, I think. HO N) > 23 AP / avenue onion. memo is ovule. ton food and energy \ 'O' or > 'swimming mellow / s. No, I think. ton food, and RA, ICE) 24 "B / ovum > J] Zhukov, PULL is arch / s or EN / N, I, you) even miles EN` u / n, > New Hampshire | no] PULL arch / d Zhukov ('You / I EN WT / | .. HO > `w / |. EN Kai WT / | .. Heritage Manor / h) 25, I think [Stevie. NH > Evangelic P.D., Ah] and' I. hip hungers auto barn / (no, a thousand > degrees avid help when. N) 26 t / h is the salary my gray / WT / n > plan, known Sat K / day) I think 27 - true / cry / or MA] VELA , Beta > PULL ... auto / EN mail `u / n, we have (CRED VIEW and, and ... [the > color of nature, SH |. children` s / \ Tao salary / M (BRED `Kai caw. > I . C `Q Dale all auto MA / color is finally Skein /, known (oil. > avlhqe, vest (Kai ovum and cry / day (Tourism / DR aunt / |.) 28, I > think now / is not (technically, ( EDA that Nate aunt / |. \ I [or > Narcotics Anonymous [Only fawner / | E Miscellaneous / parish space > (oil. aivscunqw / male PULL auto / (EN and / |. Peruse, | auto /) 29 > even avid or and / [u, Kayo, vest (gown, Barker, or [AP / 50 poi / s > than Dionysus, NAN (VEX. auto / Gage, Naphtali) M a r t i n M u s a > t o v 8 1 8 4 3 0 4 5 8 6 S M S m u s a t o v a t a t t d o t n > e t > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sat Aug 4 09:53:41 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 15:53:41 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thomas Rachel, 04.08.2012 14:51: > Am 04.08.2012 11:10 schrieb Stefan Behnel: >> As long as you don't use any features of the Cython language, it's plain >> Python. That makes it a Python compiler in my eyes. > > Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C > and C++ are distinct languages and so are Python and Cython. So, if a C++ compiler takes a .c file and compiles it with C language semantics, it doesn't qualify as a C compiler? That implies a rather weird definition of a C compiler, I'd say. Stefan From stefan_ml at behnel.de Sat Aug 4 10:03:30 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 16:03:30 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Stefan Behnel, 04.08.2012 15:53: > Thomas Rachel, 04.08.2012 14:51: >> Am 04.08.2012 11:10 schrieb Stefan Behnel: >>> As long as you don't use any features of the Cython language, it's plain >>> Python. That makes it a Python compiler in my eyes. >> >> Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C >> and C++ are distinct languages and so are Python and Cython. > > So, if a C++ compiler takes a .c file and compiles it with C language > semantics, it doesn't qualify as a C compiler? That implies a rather weird > definition of a C compiler, I'd say. Ah, sorry. Got it. You were again talking about Cython the language. Sure, Cython the language is different from Python the language. Cython the compiler can compile both. Stefan From vshanker.88 at gmail.com Sat Aug 4 10:48:07 2012 From: vshanker.88 at gmail.com (vijay shanker) Date: Sat, 4 Aug 2012 07:48:07 -0700 (PDT) Subject: keyerror '__repr__' Message-ID: hi i have this class book class book: def __init__(self,name,price): self.name = name self.price = price def __getattr__(self,attr): if attr == '__str__': print 'intercepting in-built method call ' return '%s:%s' % (object.__getattribute__(self,'name'),object.__getattribute___(self,'price')) else: return self.__dict__[attr] >>>b = book('the tempest',234) >>>b Traceback (most recent call last): File "", line 1, in File "", line 11, in __getattr__ KeyError: '__repr__' i am missing on a concept here. please enlighten me. From clp2 at rebertia.com Sat Aug 4 11:31:34 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 4 Aug 2012 08:31:34 -0700 Subject: keyerror '__repr__' In-Reply-To: References: Message-ID: On Sat, Aug 4, 2012 at 7:48 AM, vijay shanker wrote: > hi > i have this class book > > class book: > def __init__(self,name,price): > self.name = name > self.price = price > > def __getattr__(self,attr): > if attr == '__str__': > print 'intercepting in-built method call ' > return '%s:%s' % > (object.__getattribute__(self,'name'),object.__getattribute___(self,'price')) > else: > return self.__dict__[attr] > >>>>b = book('the tempest',234) >>>>b > Traceback (most recent call last): > File "", line 1, in > File "", line 11, in __getattr__ > KeyError: '__repr__' > > i am missing on a concept here. please enlighten me. A. You ought to be subclassing the `object` class so that your class is new-style (see http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes ); "classic" classes are deprecated. Incidentally, you can't intercept special method lookups on new-style classes like you do in your code snippet (see http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes ). You'll need to define actual __repr__() and/or __str__() methods. B. The interactive interpreter uses repr(), rather than str(), to stringify results. $ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) >>> class Foo(object): ... def __str__(self): return "bar" ... def __repr__(self): return "qux" ... >>> Foo() qux >>> See http://docs.python.org/reference/datamodel.html#object.__repr__ Cheers, Chris -- http://rebertia.com From jeandubois314 at gmail.com Sat Aug 4 11:49:36 2012 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sat, 4 Aug 2012 08:49:36 -0700 (PDT) Subject: [newbie] Looking for a good introduction to object oriented programming with Python Message-ID: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> I'm looking for a good introduction to object oriented programming with Python. I am looking for an introduction which only refers to Python. I have seen introductions where the authors make comparisons to other languages such as C++ and Java, but as I don't know these languages that doesn't help me further much, it rather confuses me. I also found an introduction in which the author started by telling that "object oriented programming is weird", such a statement did stop me reading further as I think an author should at least believe in the topic he is going to present as being logical. If someone here has a link or title to such an intro, I'd appreciate that very much regards, Jean p.s. People who don't like my style of asking questions, please neglect this message From no.email at nospam.invalid Sat Aug 4 11:59:18 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Aug 2012 08:59:18 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x1ujmabs9.fsf@ruckus.brouhaha.com> Stefan Krah writes: > In the free software world, apparently many people like C. C is also > quite popular in the zero-fault software world: Several verification > tools do exist and Leroy et al. are writing a certified compiler for > C to plug the hole between the verified source code and the generated > assembly. C is pretty poor as a compiler target: how would you translate Python generators into C, for example? How would you handle garbage collection? C isn't so great for high-assurance stuff either, compared to (say) Ada. People do use it in critical apps, but that's just because it is (or anyway used to be) so ubiquitous. I'm wondering what you mean about verification tools, other than analyzers like Coverity that mainly check for bugs that in a safer language would be caught by the compiler. Compcert is not all that C-specific it has been adapted to compile a Haskell-derived language (Habit). Haskell doesn't sound all that great as a translation target for Python either, unfortunately, because its execution semantics are so different. GHC is a very powerful compiler but it was made to compile Haskell code that people actually write, and may do less good of a job with compiler output from an imperative language like Python. Compiling Python to Scheme and then using a Scheme compiler might be a more natural fit. But, compiling to Haskell was probably pretty convenient for that particular project. Finally, Python itself isn't all that well suited for compilation, given its high dynamicity. It will be interesting to see if the language evolves due to PyPy. From stefan_ml at behnel.de Sat Aug 4 12:55:03 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 18:55:03 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <7x1ujmabs9.fsf@ruckus.brouhaha.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 04.08.2012 17:59: > Stefan Krah writes: >> In the free software world, apparently many people like C. C is also >> quite popular in the zero-fault software world: Several verification >> tools do exist and Leroy et al. are writing a certified compiler for >> C to plug the hole between the verified source code and the generated >> assembly. > > C is pretty poor as a compiler target: how would you translate Python > generators into C, for example? Depends. If you have CPython available, that'd be a straight forward extension type. Otherwise, I guess you'd either have a class for them in C++ or a struct in C. Not exactly complex. For the yielding, you can use labels and goto. Given that you generate the code, that's pretty straight forward as well. > How would you handle garbage collection? CPython does it automatically for us at least. Lacking that, you'd use one of the available garbage collection implementations, or provide none at all. > Haskell doesn't sound all that great as a translation target for Python > either, unfortunately, because its execution semantics are so different. > GHC is a very powerful compiler but it was made to compile Haskell code > that people actually write, and may do less good of a job with compiler > output from an imperative language like Python. Compiling Python to > Scheme and then using a Scheme compiler might be a more natural fit. > But, compiling to Haskell was probably pretty convenient for that > particular project. You'd have some kind of emulation layer that does most of the translation at runtime. That's why I said that you shouldn't expect too much of a performance gain from what the platform gives you for the underlying implementation. It can optimise the emulator, but it won't see enough of the Python code to make anything efficient out of it. Jython is an example for that. > Finally, Python itself isn't all that well suited for compilation, given > its high dynamicity. You can get pretty far with static code analysis, optimistic optimisations and code specialisation. We've decided against whole program analysis in Cython not only for compiler complexity reasons but also because it would let the normal compilation time explode for gains that you can much easier get by manual optimisation. Obviously, optimising JIT compilers can do much more here (because they actually have to do less), although they won't always be able to figure out the right thing to do either. That's where manual optimisation wins again. Stefan From miki.tebeka at gmail.com Sat Aug 4 13:01:53 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 4 Aug 2012 10:01:53 -0700 (PDT) Subject: python pynotify with textbox input In-Reply-To: <6a92314c-beb9-486b-9ed1-cb00b0e73e4a@googlegroups.com> References: <6a92314c-beb9-486b-9ed1-cb00b0e73e4a@googlegroups.com> Message-ID: > how can i made a notification for gnome-shell with a textbox input ?? > library: pynotify? You can do it in many ways. You can use one of the Python GUI frameworks - Qt, wx, GTK ... You can use utilities like zenity ... From no.email at nospam.invalid Sat Aug 4 14:18:57 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Aug 2012 11:18:57 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> Message-ID: <7x1ujm1pwu.fsf@ruckus.brouhaha.com> Stefan Behnel writes: >> C is pretty poor as a compiler target: how would you translate Python >> generators into C, for example? > Depends. If you have CPython available, that'd be a straight forward > extension type. Calling CPython hardly counts as compiling Python into C. > For the yielding, you can use labels and goto. Given that you generate > the code, that's pretty straight forward as well. You're going to compile the whole Python program into a single C function so that you can do gotos inside of it? What happens if the program imports a generator? >> How would you handle garbage collection? > CPython does it automatically for us at least. You mean you're going to have all the same INCREF/DECREF stuff on every operation in compiled data? Ugh. > Lacking that, you'd use one of the available garbage collection > implementations, What implementations would those be? There's the Boehm GC which is useful for some purposes but not really suitable at large scale, from what I can tell. Is there something else? > or provide none at all. You're going to let the program just leak memory until it crashes?? > you shouldn't expect too much of a performance gain from what the > platform gives you for the underlying implementation. It can optimise > the emulator, but it won't see enough of the Python code to make > anything efficient out of it. Jython is an example for that. Compare that to the performance gain of LuaJIT and it starts to look like something is wrong with that approach, or maybe some issue inherent in Python itself. > You can get pretty far with static code analysis, optimistic > optimisations and code specialisation. It seems very hard to do reasonable optimizations in the presence of standard Python techniques like dynamically poking class instance attributes. I guess some optimizations are still possible, like storing attributes named as literals in the program in fixed slots, saving some dictionary lookups even though the slot contents would have to still be mutable. From breamoreboy at yahoo.co.uk Sat Aug 4 14:24:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Aug 2012 19:24:12 +0100 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/08/2012 11:59, Stefan Behnel wrote: > Mark Lawrence, 04.08.2012 12:05: >> I agree so it's off topic and can't be discussed here. Isn't that right, >> Stefan? > > Hmm, in case you are referring to a recent friendly and diplomatic request > of mine regarding a couple of people who were burdening a public high > volume mailing list with a purely private back-and-forth chat about having > beer and getting drunk - then, no, I don't think the discussion in this > thread qualifies as yet another example for that so far. > > Stefan > > With arrogance like that German by any chance? -- Cheers. Mark Lawrence. From lamialily at cleverpun.com Sat Aug 4 14:34:27 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Sat, 04 Aug 2012 11:34:27 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 04 Aug 2012 19:24:12 +0100, Mark Lawrence wrote: >On 04/08/2012 11:59, Stefan Behnel wrote: >> Mark Lawrence, 04.08.2012 12:05: >>> I agree so it's off topic and can't be discussed here. Isn't that right, >>> Stefan? >> >> Hmm, in case you are referring to a recent friendly and diplomatic request >> of mine regarding a couple of people who were burdening a public high >> volume mailing list with a purely private back-and-forth chat about having >> beer and getting drunk - then, no, I don't think the discussion in this >> thread qualifies as yet another example for that so far. >> >> Stefan >> >> > >With arrogance like that German by any chance? Hey now, cool it with the passive-aggression. We're here to discuss code, right? If you want to fight it out, you can gladly do it by e-mail. ~Temia -- Invective! Verb your expletive nouns! From schesis at gmail.com Sat Aug 4 14:42:04 2012 From: schesis at gmail.com (Zero Piraeus) Date: Sat, 4 Aug 2012 14:42:04 -0400 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: : On 4 August 2012 14:24, Mark Lawrence wrote: > > With arrogance like that German by any chance? I didn't give a monkeys about the beer conversation personally, but can we leave the national stereotypes out of it? -[]z. From breamoreboy at yahoo.co.uk Sat Aug 4 14:50:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 4 Aug 2012 19:50:34 +0100 (BST) Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1344106234.37925.YahooMailNeo@web29606.mail.ird.yahoo.com> ________________________________ From: Zero Piraeus To: Mark Lawrence Cc: python-list at python.org Sent: Saturday, 4 August 2012, 19:42 Subject: Re: On-topic: alternate Python implementations : On 4 August 2012 14:24, Mark Lawrence wrote: > > With arrogance like that German by any chance? I didn't give a monkeys about the beer conversation personally, but can we leave the national stereotypes out of it? -[]z. No.? Next question? -------------- next part -------------- An HTML attachment was scrubbed... URL: From schesis at gmail.com Sat Aug 4 14:56:05 2012 From: schesis at gmail.com (Zero Piraeus) Date: Sat, 4 Aug 2012 14:56:05 -0400 Subject: On-topic: alternate Python implementations In-Reply-To: <1344106234.37925.YahooMailNeo@web29606.mail.ird.yahoo.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> <1344106234.37925.YahooMailNeo@web29606.mail.ird.yahoo.com> Message-ID: : On 4 August 2012 14:50, Mark Lawrence wrote: > > No. Next question? *plonk* -[]z. From stefan_ml at behnel.de Sat Aug 4 15:06:04 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 21:06:04 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <7x1ujm1pwu.fsf@ruckus.brouhaha.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <7x1ujm1pwu.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 04.08.2012 20:18: > Stefan Behnel writes: >>> C is pretty poor as a compiler target: how would you translate Python >>> generators into C, for example? >> Depends. If you have CPython available, that'd be a straight forward >> extension type. > > Calling CPython hardly counts as compiling Python into C. CPython is written in C, though. So anything that CPython does can be done in C. It's not like the CPython project used a completely unusual way of writing C code. Besides, I find your above statement questionable. You will always need some kind of runtime infrastructure when you "compile Python into C", so you can just as well use CPython for that instead of reimplementing it completely from scratch. Both Cython and Nuitka do exactly that, and one of the major advantages of that approach is that they can freely interact with arbitrary code (Python or not) that was written for CPython, regardless of its native dependencies. What good would it be to throw all of that away, just for the sake of having "pure C code generation"? >> For the yielding, you can use labels and goto. Given that you generate >> the code, that's pretty straight forward as well. > > You're going to compile the whole Python program into a single C > function so that you can do gotos inside of it? What happens if the > program imports a generator? No, you are going to compile only the generator function into a function that uses gotos, maybe with an additional in-out struct parameter that holds its state. Then, on entry, you read the label (or its ID) from the previous state, reset local variables and jump to the label. On exit, you store the state back end return. Cython does it that way. Totally straight forward, as I said. >>> How would you handle garbage collection? >> CPython does it automatically for us at least. > > You mean you're going to have all the same INCREF/DECREF stuff on every > operation in compiled data? Ugh. If you don't like that, you can experiment with anything from a dedicated GC to transactional memory. >> Lacking that, you'd use one of the available garbage collection >> implementations, > > What implementations would those be? There's the Boehm GC which is > useful for some purposes but not really suitable at large scale, from > what I can tell. Is there something else? No idea - I'll look it up when I need one. Last I heard, PyPy had a couple of GCs to choose from, but I don't know how closely the are tied into its infrastructure. >> or provide none at all. > > You're going to let the program just leak memory until it crashes?? Well, it's not like CPython leaks memory until it crashes, now does it? And it's written in C. So there must be ways to handle this also in C. Remember that CPython didn't even have a GC before something around 2.0, IIRC. That worked quite ok in most cases and simply left the tricky cases to the programmers. It really depends on what your requirements are. Small embedded systems, time critical code and real-time systems are often much better off without garbage collection. It's pure convenience, after all. >> you shouldn't expect too much of a performance gain from what the >> platform gives you for the underlying implementation. It can optimise >> the emulator, but it won't see enough of the Python code to make >> anything efficient out of it. Jython is an example for that. > > Compare that to the performance gain of LuaJIT and it starts to look > like something is wrong with that approach, or maybe some issue inherent > in Python itself. Huh? LuaJIT is a reimplementation of Lua that uses an optimising JIT compiler specifically for Lua code. How is that similar to the Jython runtime that runs *on top of* the JVM with its generic byte code based JIT compiler? Basically, LuaJIT's JIT compiler works at the same level as the one in PyPy, which is why both can theoretically provide the same level of performance gains. >> You can get pretty far with static code analysis, optimistic >> optimisations and code specialisation. > > It seems very hard to do reasonable optimizations in the presence of > standard Python techniques like dynamically poking class instance > attributes. I guess some optimizations are still possible, like storing > attributes named as literals in the program in fixed slots, saving some > dictionary lookups even though the slot contents would have to still be > mutable. Sure. Even when targeting the CPython runtime with the generated C code (like Cython or Nuitka), you can still do a lot. And sure, static code analysis will never be able to infer everything that a JIT compiler can see. Stefan From franck at ditter.org Sat Aug 4 15:20:36 2012 From: franck at ditter.org (Franck Ditter) Date: Sat, 04 Aug 2012 21:20:36 +0200 Subject: when an iterable object is exhausted or not Message-ID: Two similar iterable objects but with a different behavior : $$$ i = range(2,5) $$$ for x in i : print(x,end=' ') 2 3 4 $$$ for x in i : print(x,end=' ') # i is not exhausted 2 3 4 --------- Compare with : $$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') $$$ for x in i : print(x,end=' ') 1 2 3 $$$ for x in i : print(x,end=' ') # i is exhausted $$$ IMHO, this should not happen in Py3k. What is the rationale of this (bad ?) design, which forces the programmer to memorize which one is exhaustable and which one is not ?... franck From python at mrabarnett.plus.com Sat Aug 4 15:24:53 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Aug 2012 20:24:53 +0100 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <7x1ujm1pwu.fsf@ruckus.brouhaha.com> Message-ID: <501D7705.8050705@mrabarnett.plus.com> On 04/08/2012 20:06, Stefan Behnel wrote: > Paul Rubin, 04.08.2012 20:18: >> Stefan Behnel writes: >>>> C is pretty poor as a compiler target: how would you translate Python >>>> generators into C, for example? >>> Depends. If you have CPython available, that'd be a straight forward >>> extension type. >> >> Calling CPython hardly counts as compiling Python into C. > > CPython is written in C, though. So anything that CPython does can be done > in C. It's not like the CPython project used a completely unusual way of > writing C code. > > Besides, I find your above statement questionable. You will always need > some kind of runtime infrastructure when you "compile Python into C", so > you can just as well use CPython for that instead of reimplementing it > completely from scratch. Both Cython and Nuitka do exactly that, and one of > the major advantages of that approach is that they can freely interact with > arbitrary code (Python or not) that was written for CPython, regardless of > its native dependencies. What good would it be to throw all of that away, > just for the sake of having "pure C code generation"? > > >>> For the yielding, you can use labels and goto. Given that you generate >>> the code, that's pretty straight forward as well. >> >> You're going to compile the whole Python program into a single C >> function so that you can do gotos inside of it? What happens if the >> program imports a generator? > > No, you are going to compile only the generator function into a function > that uses gotos, maybe with an additional in-out struct parameter that > holds its state. Then, on entry, you read the label (or its ID) from the > previous state, reset local variables and jump to the label. On exit, you > store the state back end return. Cython does it that way. Totally straight > forward, as I said. > > >>>> How would you handle garbage collection? >>> CPython does it automatically for us at least. >> >> You mean you're going to have all the same INCREF/DECREF stuff on every >> operation in compiled data? Ugh. > > If you don't like that, you can experiment with anything from a dedicated > GC to transactional memory. > > >>> Lacking that, you'd use one of the available garbage collection >>> implementations, >> >> What implementations would those be? There's the Boehm GC which is >> useful for some purposes but not really suitable at large scale, from >> what I can tell. Is there something else? > > No idea - I'll look it up when I need one. Last I heard, PyPy had a couple > of GCs to choose from, but I don't know how closely the are tied into its > infrastructure. > > >>> or provide none at all. >> >> You're going to let the program just leak memory until it crashes?? > > Well, it's not like CPython leaks memory until it crashes, now does it? And > it's written in C. So there must be ways to handle this also in C. > > Remember that CPython didn't even have a GC before something around 2.0, > IIRC. That worked quite ok in most cases and simply left the tricky cases > to the programmers. It really depends on what your requirements are. Small > embedded systems, time critical code and real-time systems are often much > better off without garbage collection. It's pure convenience, after all. > [snip] CPython relied entirely on reference counting, so memory could leak you if inadvertently created a cycle of memory references. That problem was fixed when a mark-and-sweep mechanism was added (it's called occasionally to collect any unreachable cycles). From timr at probo.com Sat Aug 4 15:44:07 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 04 Aug 2012 12:44:07 -0700 Subject: when an iterable object is exhausted or not References: Message-ID: Franck Ditter wrote: > >Two similar iterable objects but with a different behavior : > >$$$ i = range(2,5) >$$$ for x in i : print(x,end=' ') > >2 3 4 >$$$ for x in i : print(x,end=' ') # i is not exhausted > >2 3 4 > >--------- Compare with : > >$$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') >$$$ for x in i : print(x,end=' ') > >1 2 3 >$$$ for x in i : print(x,end=' ') # i is exhausted > >$$$ > >IMHO, this should not happen in Py3k. It's interesting that it DOESN'T happen in Python 2. The first "i" is of type list, the second "i" is of type string, and both are restartable. What's the type of "i" in the second case in Python 3? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Aug 4 16:07:58 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 04 Aug 2012 13:07:58 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > >Most people are aware, if only vaguely, of the big Four Python >implementations: > >CPython, or just Python, the reference implementation written in C. >IronPython, written in .NET. Technicality: .NET is not a language, it is a run-time framework. IronPython is written in C#. It generates code that runs in the .NET Framework. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sat Aug 4 16:11:56 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Aug 2012 21:11:56 +0100 Subject: when an iterable object is exhausted or not In-Reply-To: References: Message-ID: <501D820C.2000609@mrabarnett.plus.com> On 04/08/2012 20:20, Franck Ditter wrote: > Two similar iterable objects but with a different behavior : > > $$$ i = range(2,5) > $$$ for x in i : print(x,end=' ') > > 2 3 4 > $$$ for x in i : print(x,end=' ') # i is not exhausted > > 2 3 4 > > --------- Compare with : > > $$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') > $$$ for x in i : print(x,end=' ') > > 1 2 3 > $$$ for x in i : print(x,end=' ') # i is exhausted > > $$$ > > IMHO, this should not happen in Py3k. > What is the rationale of this (bad ?) design, which forces the programmer > to memorize which one is exhaustable and which one is not ?... > 'range' returns a 'range' object: >>> i = range(2,5) >>> i range(2, 5) The 'for' loop passes it to 'iter' to get an iterator: >>> iter(i) More importantly: >>> iter(i) is i False In other words, when asked for an iterator, the 'range' object always creates a new one. On the other hand, 'filter' returns a 'filter' object: >>> i = filter(lambda c : c.isdigit(), 'a1b2c3') >>> i The 'for' loop passes it to 'iter' to get an iterator: >>> iter(i) More importantly: >>> iter(i) is i True In other words, the 'filter' object returns _itself_ as the iterator. From python.list at tim.thechases.com Sat Aug 4 16:24:02 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 04 Aug 2012 15:24:02 -0500 Subject: when an iterable object is exhausted or not In-Reply-To: References: Message-ID: <501D84E2.6000404@tim.thechases.com> On 08/04/12 14:20, Franck Ditter wrote: > Two similar iterable objects but with a different behavior : > > $$$ i = range(2,5) > $$$ for x in i : print(x,end=' ') > > 2 3 4 > $$$ for x in i : print(x,end=' ') # i is not exhausted > > 2 3 4 > > --------- Compare with : > > $$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') > $$$ for x in i : print(x,end=' ') > > 1 2 3 > $$$ for x in i : print(x,end=' ') # i is exhausted > > $$$ > > IMHO, this should not happen in Py3k. > What is the rationale of this (bad ?) design, which forces the programmer > to memorize which one is exhaustable and which one is not ?... I can't speak to the rationale, but it seems that a range() object has some extra features that a normal iter doesn't: >>> i = iter(range(2,5)) >>> for x in i: print (x, end=' ') ... 2 3 4 >>> for x in i: print (x, end=' ') ... (your 2nd behavior, and what I'd expect). So my guess would be that the "for {var} in {thing}" triggers a re-calling of range.__iter__ since it's not an iterator to begin with. -tkc From no.email at nospam.invalid Sat Aug 4 16:43:29 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Aug 2012 13:43:29 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <7x1ujm1pwu.fsf@ruckus.brouhaha.com> Message-ID: <7xsjc2l766.fsf@ruckus.brouhaha.com> Stefan Behnel writes: >> Calling CPython hardly counts as compiling Python into C. > CPython is written in C, though. So anything that CPython does can be > done in C. It's not like the CPython project used a completely unusual > way of writing C code. CPython is a relatively simple interpreter, and executing code by invoking such an interpreter IMHO doesn't count as "compiling" it in any meaningful way. > You will always need some kind of runtime infrastructure when you > "compile Python into C", so you can just as well use CPython for that > instead of reimplementing it completely from scratch. Maybe there's parts of Cpython you can re-use, but having the CPython interpreter be the execution engine for "compiled" Python generators again fails the seriousness test of what it means to compile code. If you mean something other than that, you might explain more clearly. > Both Cython and Nuitka do exactly that, I didn't know about Nuitka; it looks interesting but (at least after a few minutes looking) I don't have much sense of how it works. > No, you are going to compile only the generator function into a function > that uses gotos, maybe with an additional in-out struct parameter that > holds its state. Yeah, ok, I guess that can work, given python generators are limited to returning through just one stack level. You might want to avoid copying locals by just putting everything into a struct, that has to be retained across entries/exits. > If you don't like that, you can experiment with anything from a dedicated > GC to transactional memory. OK, but then CPython is no longer managing the memory. > Last I heard, PyPy had a couple of GCs to choose from, PyPy doesn't compile to C, but I guess compiling to C doesn't preclude precise GC, as long as the generated C code carefully tracks what C objects can contain GC-able pointers, and follows some constraints about when the GC can run. Some other compilers do this so it's not as big a deal as it sounded like at first. OK. > >>> or provide none at all. >> You're going to let the program just leak memory until it crashes?? > Well, it's not like CPython leaks memory until it crashes... I was counting CPython's reference counting as a rudimentary form of GC, though I guess that's terminology that not everyone agrees on. > Huh? LuaJIT is a reimplementation of Lua that uses an optimising JIT > compiler specifically for Lua code. How is that similar to the Jython > runtime that runs *on top of* the JVM with its generic byte code based > JIT compiler? I thought LuaJIT compiles the existing Lua VM code, but I haven't looked at it closely or used it. >> It seems very hard to do reasonable optimizations in the presence of >> standard Python techniques > > Sure. Even when targeting the CPython runtime with the generated C > code (like Cython or Nuitka), you can still do a lot. And sure, static > code analysis will never be able to infer everything that a JIT > compiler can see. I think even a JIT can't avoid a lot of pain and slowdown, without complex whole-program analysis and requiring the application to follow some special conventions, like never importing at "runtime". From einazaki668 at yahoo.com Sat Aug 4 16:45:48 2012 From: einazaki668 at yahoo.com (Eric) Date: Sat, 4 Aug 2012 13:45:48 -0700 (PDT) Subject: trouble with pyplot in os x In-Reply-To: References: <3a2464ec-8fbc-4c45-8509-6861031f9204@googlegroups.com> Message-ID: On Saturday, August 4, 2012 8:11:44 AM UTC-5, William R. Wing (Bill Wing) wrote: > On Aug 3, 2012, at 11:12 PM, Eric wrote: > > > > > I'm just starting to futz around with matplotlib and I tried to run this > > > example from the matplotlib doc page (it's the imshow() example): > > > > > > import numpy as np > > > import matplotlib.cm as cm > > > import matplotlib.mlab as mlab > > > import matplotlib.pyplot as plt > > > > > > delta = 0.025 > > > x = y = np.arange(-3.0, 3.0, delta) > > > X, Y = np.meshgrid(x, y) > > > Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) > > > Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) > > > Z = Z2-Z1 # difference of Gaussians > > > > > > im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, > > > origin='lower', extent=[-3,3,-3,3]) > > > > > > plt.show() > > > > > > > > > > OK > > > > > > > > I get the following error: > > > > > > Exception in Tkinter callback > > > Traceback (most recent call last): > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ > > > return self.func(*args) > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 248, in resize > > > self.show() > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 252, in draw > > > tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2) > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 19, in blit > > > tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array)) > > > TclError > > > > > > > > > > This looks as though you are running the latest python from python.org, not the pre-installed python from Apple (that's good). > > > > > > > > I'm using Python 2.7.3 on OS X 10.6.8 and I'm invoking python by doing > > > "arch -i386 python" because matplotlib doesn't do 64-bit. Has anyone > > > else seen this? Does anyone know why this is happening? It looks > > > like a problem with tkinter but beyond that I haven't a clue. And, > > > finally, any ideas as to how to make it behave? > > > > > > > I DON'T know how tk is getting mixed into this, it shouldn't be. But I think I can tell you how to get matplotlib working... > > > > Matplotlib DOES do 64-bit, the problem is numpy, which as you download in binary form does not. But, if you copy the bash script here: > > > > https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh > > > > it will download the sources and build a 64-bit numpy, which will then give you a default 64-bit full package of python, numpy, and matplotlib. > > > > That's what I've done, and my system runs the demo you listed in your post with no problems. > > > > > TIA, > > > eric > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Good luck, > > -Bill Yes, I got the Python 2.7 (and 3.2) distributions from python.org and I also got Tcl/Tk per their directions. I still have all the old Apple installed stuff too plus some older Tcl/Tk. Doesn't matplotlib use Tk (Tkinter) to do its graphs and what-not? I also have at least two different versions of Tcl/Tk (8.5.7 and 8.5.12) and I'm wondering if that may not be causing problems. I'll give that bash script a try. Thanks, eric From einazaki668 at yahoo.com Sat Aug 4 16:45:48 2012 From: einazaki668 at yahoo.com (Eric) Date: Sat, 4 Aug 2012 13:45:48 -0700 (PDT) Subject: trouble with pyplot in os x In-Reply-To: References: <3a2464ec-8fbc-4c45-8509-6861031f9204@googlegroups.com> Message-ID: On Saturday, August 4, 2012 8:11:44 AM UTC-5, William R. Wing (Bill Wing) wrote: > On Aug 3, 2012, at 11:12 PM, Eric wrote: > > > > > I'm just starting to futz around with matplotlib and I tried to run this > > > example from the matplotlib doc page (it's the imshow() example): > > > > > > import numpy as np > > > import matplotlib.cm as cm > > > import matplotlib.mlab as mlab > > > import matplotlib.pyplot as plt > > > > > > delta = 0.025 > > > x = y = np.arange(-3.0, 3.0, delta) > > > X, Y = np.meshgrid(x, y) > > > Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) > > > Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) > > > Z = Z2-Z1 # difference of Gaussians > > > > > > im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, > > > origin='lower', extent=[-3,3,-3,3]) > > > > > > plt.show() > > > > > > > > > > OK > > > > > > > > I get the following error: > > > > > > Exception in Tkinter callback > > > Traceback (most recent call last): > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ > > > return self.func(*args) > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 248, in resize > > > self.show() > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 252, in draw > > > tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2) > > > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 19, in blit > > > tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array)) > > > TclError > > > > > > > > > > This looks as though you are running the latest python from python.org, not the pre-installed python from Apple (that's good). > > > > > > > > I'm using Python 2.7.3 on OS X 10.6.8 and I'm invoking python by doing > > > "arch -i386 python" because matplotlib doesn't do 64-bit. Has anyone > > > else seen this? Does anyone know why this is happening? It looks > > > like a problem with tkinter but beyond that I haven't a clue. And, > > > finally, any ideas as to how to make it behave? > > > > > > > I DON'T know how tk is getting mixed into this, it shouldn't be. But I think I can tell you how to get matplotlib working... > > > > Matplotlib DOES do 64-bit, the problem is numpy, which as you download in binary form does not. But, if you copy the bash script here: > > > > https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh > > > > it will download the sources and build a 64-bit numpy, which will then give you a default 64-bit full package of python, numpy, and matplotlib. > > > > That's what I've done, and my system runs the demo you listed in your post with no problems. > > > > > TIA, > > > eric > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Good luck, > > -Bill Yes, I got the Python 2.7 (and 3.2) distributions from python.org and I also got Tcl/Tk per their directions. I still have all the old Apple installed stuff too plus some older Tcl/Tk. Doesn't matplotlib use Tk (Tkinter) to do its graphs and what-not? I also have at least two different versions of Tcl/Tk (8.5.7 and 8.5.12) and I'm wondering if that may not be causing problems. I'll give that bash script a try. Thanks, eric From tjreedy at udel.edu Sat Aug 4 17:04:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Aug 2012 17:04:51 -0400 Subject: when an iterable object is exhausted or not In-Reply-To: <501D84E2.6000404@tim.thechases.com> References: <501D84E2.6000404@tim.thechases.com> Message-ID: On 8/4/2012 4:24 PM, Tim Chase wrote: > On 08/04/12 14:20, Franck Ditter wrote: >> Two similar iterable objects but with a different behavior : >> >> $$$ i = range(2,5) >> $$$ for x in i : print(x,end=' ') >> >> 2 3 4 >> $$$ for x in i : print(x,end=' ') # i is not exhausted >> >> 2 3 4 >> >> --------- Compare with : >> >> $$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') >> $$$ for x in i : print(x,end=' ') >> >> 1 2 3 >> $$$ for x in i : print(x,end=' ') # i is exhausted >> >> $$$ >> >> IMHO, this should not happen in Py3k. >> What is the rationale of this (bad ?) design, which forces the programmer >> to memorize which one is exhaustable and which one is not ?... > > I can't speak to the rationale, but it seems that a range() object > has some extra features that a normal iter doesn't: > > >>> i = iter(range(2,5)) > >>> for x in i: print (x, end=' ') > ... > 2 3 4 >>> for x in i: print (x, end=' ') > ... > > (your 2nd behavior, and what I'd expect). > > So my guess would be that the "for {var} in {thing}" triggers a > re-calling of range.__iter__ since it's not an iterator to begin with. range produces a re-iterable range object because it can. The result is self-contained with 3 data attributes, so it can create rangeiterators on demand. filter, on the other hand, depends on an external iterable and it cannot depend on that external object being re-iterable. So even if we programmed filter() to produce a filter object that produced filteriterators, the latter would often only work for the first. Also, If you want the filtered collection more than once, you should just save it. On the other hand, reproducing counts with a rangeiterator is nearly as fast as looking them up in a saved list, and much more memory efficient. -- Terry Jan Reedy From stefan_ml at behnel.de Sat Aug 4 17:24:08 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 04 Aug 2012 23:24:08 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <7xsjc2l766.fsf@ruckus.brouhaha.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <7x1ujm1pwu.fsf@ruckus.brouhaha.com> <7xsjc2l766.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 04.08.2012 22:43: > Stefan Behnel writes: >>> Calling CPython hardly counts as compiling Python into C. >> CPython is written in C, though. So anything that CPython does can be >> done in C. It's not like the CPython project used a completely unusual >> way of writing C code. > > CPython is a relatively simple interpreter, and executing code > by invoking such an interpreter IMHO doesn't count as "compiling" it in > any meaningful way. Oh, CPython is substantially more than an interpreter. The eval loop is only *one* way to use the runtime environment. Remember that it has many builtin types and functions as well as a huge standard library. Much of the runtime environment is already written in C or can be compiled down to C. If you compile Python code into C code that avoids the eval loop and only uses the CPython runtime environment (which is what Cython does), I think that qualifies as compiling Python code to C. It's definitely the most practical and user friendly way to do it. >> You will always need some kind of runtime infrastructure when you >> "compile Python into C", so you can just as well use CPython for that >> instead of reimplementing it completely from scratch. > > Maybe there's parts of Cpython you can re-use, but having the CPython > interpreter be the execution engine for "compiled" Python generators > again fails the seriousness test of what it means to compile code. If > you mean something other than that, you might explain more clearly. See above. >> Both Cython and Nuitka do exactly that, > > I didn't know about Nuitka; it looks interesting but (at least after a > few minutes looking) I don't have much sense of how it works. It's mostly like Cython but without the type system, i.e. without all the stuff that makes it useful in real life. Just a bare Python-to-C++-in-CPython compiler, without much of a way to make it do what you want. >> Last I heard, PyPy had a couple of GCs to choose from, > > PyPy doesn't compile to C RPython (usually) does, though, and my guess is that the memory management part of the runtime is written in RPython. > but I guess compiling to C doesn't preclude > precise GC, as long as the generated C code carefully tracks what C > objects can contain GC-able pointers, and follows some constraints about > when the GC can run. Some other compilers do this so it's not as big a > deal as it sounded like at first. OK. Yep, C really becomes a lot nicer when you generate it. >> Huh? LuaJIT is a reimplementation of Lua that uses an optimising JIT >> compiler specifically for Lua code. How is that similar to the Jython >> runtime that runs *on top of* the JVM with its generic byte code based >> JIT compiler? > > I thought LuaJIT compiles the existing Lua VM code, but I haven't > looked at it closely or used it. Ok. It obviously reuses code, but the VM part of it is really different from standard Lua. Stefan From james.pye at gmail.com Sat Aug 4 18:05:33 2012 From: james.pye at gmail.com (jwp) Date: Sat, 4 Aug 2012 15:05:33 -0700 (PDT) Subject: On-topic: alternate Python implementations In-Reply-To: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4915429c-ce7d-4e2b-8694-1dd7b34de9c6@googlegroups.com> On Friday, August 3, 2012 11:15:20 PM UTC-7, Steven D'Aprano wrote: > WPython - another optimizing version of Python with wordcodes instead of > bytecodes. > > http://code.google.com/p/wpython/ I remember reading about this a while ago. I thought this was eventually going to be committed to CPython... =\ From jae+python at jaerhard.com Sat Aug 4 19:25:10 2012 From: jae+python at jaerhard.com (=?iso-8859-1?B?SvxyZ2VuIEEu?= Erhard) Date: Sun, 5 Aug 2012 01:25:10 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120804232510.GA23550@jaerhard.com> On Sat, Aug 04, 2012 at 08:40:16AM +0200, Stefan Behnel wrote: > Steven D'Aprano, 04.08.2012 08:15: > > Most people are aware, if only vaguely, of the big Four Python > > implementations: > > > > And not to forget Cython, which is the only static Python compiler that is > widely used. Compiles and optimises Python to C code that uses the CPython > runtime and allows for easy manual optimisations to get C-like performance > out of it. Cython is certainly *not* a Python *implementation*, since it always uses the CPython runtime (and compiling Cython C files requires Python.h). None of the other implementations require Python for actually compiling or running Python source. Oh, yes, you can create a stand-alone... wait, a "stand-alone" app. By embedding the Python runtime (dynamic linking with libpythonX.Y... maybe static too? Didn't test, because it's irrelevant for making the point). Grits, J From shearichard at gmail.com Sat Aug 4 20:04:38 2012 From: shearichard at gmail.com (shearichard at gmail.com) Date: Sat, 4 Aug 2012 17:04:38 -0700 (PDT) Subject: Object Models - decoupling data access - good examples ? Message-ID: I'm interested in best practice approaches to : decoupling data access code from application code; and translations between database structures and domain objects. For some time I've done database access by in a particular way and while I think it's OK it's not very pythonic so I'd be interested in hearing of other approaches - even better if there are open source examples whose code might be read. I should say I'm talking relational database here and, for various reasons, ORMs are not involved. So this is what I do (in a one class project call 'bar') in order to allow objects of type foo to be fetched/inserted/updated bar/foo.py bar/bardb/bardbConnection.py bar/bardb/BusinessLogic/fooManager.py bar/bardb/BusinessObject/foo.py bar/bardb/DataAccess/fooDB.py And this is what they actually do : bar/foo.py The class as the outside world knows it bar/bardb/bardbConnection.py Manages database connection bar/bardb/BusinessLogic/fooManager.py Exposes methods used by bar/foo.py such as 'save'/'update' etc and implements necessary validation etc bar/bardb/BusinessObject/foo.py A collection of getters/setters which does any translation between types necessary on the way to/from the rdbms bar/bardb/DataAccess/fooDB.py Implements the actual SQL necessary for the relevant interactions with the database As I say this works OK for me but I'd be interested to hear of what others do. Thanks Richard. From shearichard at gmail.com Sat Aug 4 20:11:09 2012 From: shearichard at gmail.com (shearichard at gmail.com) Date: Sat, 4 Aug 2012 17:11:09 -0700 (PDT) Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ... Could do worse than this : http://www.diveintopython.net/object_oriented_framework/index.html and this http://docs.python.org/tutorial/classes.html read together. Judging by your question this is a probably a little advanced for now but you could bookmark it for the future: http://www.catonmat.net/blog/learning-python-design-patterns-through-video-lectures/ Here's the corresponding PDF to go with the video: http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns%20Presentation.pdf From steve+comp.lang.python at pearwood.info Sat Aug 4 20:47:02 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 00:47:02 GMT Subject: when an iterable object is exhausted or not References: Message-ID: <501dc286$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 12:44:07 -0700, Tim Roberts wrote: >>$$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') >>$$$ for x in i : print(x,end=' ') >>1 2 3 >>$$$ for x in i : print(x,end=' ') # i is exhausted >>$$$ >> >>IMHO, this should not happen in Py3k. > > It's interesting that it DOESN'T happen in Python 2. The first "i" is > of type list, the second "i" is of type string, and both are > restartable. > > What's the type of "i" in the second case in Python 3? In Python 3, filter returns a lazy iterator, a "filter object". It generates items on demand. In Python 2, filter is eager, not lazy, and generates items all up-front. If the input is a string, it generates a string; if the input is a tuple, it generates a tuple; otherwise it generates a list. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 4 20:54:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 00:54:57 GMT Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> Message-ID: <501dc461$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 08:59:18 -0700, Paul Rubin wrote: > C isn't so great for high-assurance stuff either, compared to (say) Ada. > People do use it in critical apps, but that's just because it is (or > anyway used to be) so ubiquitous. And then they are shocked, SHOCKED I say!, when their app has enough buffer overflow security vulnerabilities to sink a battleship. [half a wink] > Haskell doesn't sound all that great as a translation target for Python > either, unfortunately, because its execution semantics are so different. I have no opinion on that either way, except to say that if some developer wants to experiment with Python-in-Haskell, good on him or her. Trying something new is how progress is made. [...] > Finally, Python itself isn't all that well suited for compilation, given > its high dynamicity. It will be interesting to see if the language > evolves due to PyPy. Python is a dynamic language, but most Python code is relatively static. Runtime optimizations that target the common case, but fall back to unoptimized code in the rare cases that the optimization doesn't apply, offer the opportunity of big speedups for most code at the cost of trivial slowdowns when you do something unusual. -- Steven From roy at panix.com Sat Aug 4 21:17:21 2012 From: roy at panix.com (Roy Smith) Date: Sat, 04 Aug 2012 21:17:21 -0400 Subject: Object Models - decoupling data access - good examples ? References: Message-ID: In article , shearichard at gmail.com wrote: > I should say I'm talking relational database here and, for various reasons, > ORMs are not involved. Just out of curiosity, why do you eschew ORMs? On the other hand, you really haven't. All you've done is rolled your own. So, the real question is, why do you want to roll your own ORM instead of using some existing one? From no.email at nospam.invalid Sat Aug 4 21:38:33 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Aug 2012 18:38:33 -0700 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <501dc461$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x1ujm9kyu.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Runtime optimizations that target the common case, but fall back to > unoptimized code in the rare cases that the optimization doesn't apply, > offer the opportunity of big speedups for most code at the cost of > trivial slowdowns when you do something unusual. The problem is you can't always tell if the unusual case is being exercised without an expensive dynamic check, which in some cases must be repeated in every iteration of a critical inner loop, even though it turns out that the program never actually uses the unusual case. From steve+comp.lang.python at pearwood.info Sat Aug 4 22:13:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 02:13:17 GMT Subject: when an iterable object is exhausted or not References: Message-ID: <501dd6bd$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 21:20:36 +0200, Franck Ditter wrote: > Two similar iterable objects but with a different behavior : [...] > IMHO, this should not happen in Py3k. What is the rationale of this (bad > ?) design, which forces the programmer to memorize which one is > exhaustable and which one is not ?... What makes you say that they are "similar" iterable objects? Except that they are both iterable, they are very different. You might as well say that lists and dicts are "similar iterable objects". filter objects are iterators, and so obey the intentionally simple iterator protocol. range objects are iterable but not iterators, and do not obey the iterator protocol. py> it = filter(lambda x: x, set('abc')) py> iter(it) is it True py> x = range(1, 15, 2) py> iter(x) is x False filter relies on its input, which it consumes as it does. Since the input may not be restartable, filter cannot be restartable either. For simplicity, filter does not try to be "clever" and guess when the input argument is restartable. Instead, it simply and consistently behaves the same for any iterable input. range is a specialist iterable data structure that does not consume anything. It computes its output lazily, but that is the only similarity with iterators. There's no need to limit range objects to the simple iterator protocol, since they don't consume their input -- a single object can easily compute its output as often as you want. range objects are indexable and sliceable: py> x = range(1, 15, 2) py> x[4] 9 py> x[2:4] range(5, 9, 2) Why artificially make range objects unrestartable just to satisfy compatibility with iterators? The caller already has to remember that range and filter take different arguments, do different things, and return different objects. Why is it hard to remember that range is restartable and filter is not? -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 4 22:19:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 02:19:26 GMT Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <501dc461$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujm9kyu.fsf@ruckus.brouhaha.com> Message-ID: <501dd82e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 18:38:33 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Runtime optimizations that target the common case, but fall back to >> unoptimized code in the rare cases that the optimization doesn't apply, >> offer the opportunity of big speedups for most code at the cost of >> trivial slowdowns when you do something unusual. > > The problem is you can't always tell if the unusual case is being > exercised without an expensive dynamic check, which in some cases must > be repeated in every iteration of a critical inner loop, even though it > turns out that the program never actually uses the unusual case. I never said optimizing Python was easy :) Obviously if the check is expensive enough, the optimization isn't going to be worth doing. But often the check is not so expensive, or is just a matter of tedious and careful book-keeping. I don't wish to dispute that optimizing Python is hard, but it's not a Hard Problem like factorizing huge integers, or solving the Palestine/ Israeli conflict. It's hard like cleaning your house after a gang of drunken frat boys have partied all weekend. -- Steven From ombdalen at gmail.com Sat Aug 4 23:04:36 2012 From: ombdalen at gmail.com (=?UTF-8?Q?Ole_Martin_Bj=C3=B8rndalen?=) Date: Sun, 5 Aug 2012 05:04:36 +0200 Subject: dbf.py API question In-Reply-To: <501AA304.3090000@stoneleaf.us> References: <501AA304.3090000@stoneleaf.us> Message-ID: On Thu, Aug 2, 2012 at 5:55 PM, Ethan Furman wrote: > SQLite has a neat feature where if you give it a the file-name of ':memory:' > the resulting table is in memory and not on disk. I thought it was a cool > feature, but expanded it slightly: any name surrounded by colons results in > an in-memory table. > > I'm looking at the same type of situation with indices, but now I'm > wondering if the :name: method is not pythonic and I should use a flag > (in_memory=True) when memory storage instead of disk storage is desired. > > Thoughts? I agree that the flag would be more pythonic in dbf.py. I was not aware that you are adding sqlite functionality to your library. This is very cool! I have been through the same questions with my own DBF library, and I've come to some conclusions: First, I decided to make the library read-only and in-memory. That is all we need in-house anyway. Second, I decided to make an external tool for converting DBF files to sqlite: https://github.com/olemb/dbfget/blob/master/extras/dbf2sqlite (To anyone reading: I have not yet made a public announcement of dbfget, but I will shortly. Consider this an informal announcement: https://github.com/olemb/dbfget/ ) I am considering adding a "streaming=True" flag which would make the table class a record generator, and a "save()" method which would allow you to save data back to the file, or to a new file if you provide an optional file name. In fact, I had this functionality in earlier versions, but decided to chuck it out in order to make the API as clean as possible. I hope this can help you somehow in your decision making process. From shearichard at gmail.com Sat Aug 4 23:26:25 2012 From: shearichard at gmail.com (shearichard at gmail.com) Date: Sat, 4 Aug 2012 20:26:25 -0700 (PDT) Subject: Object Models - decoupling data access - good examples ? In-Reply-To: References: Message-ID: > > Just out of curiosity, why do you eschew ORMs? > Good question ! I'm not anti-ORM (in fact in many circs I'm quite pro-ORM) but for some time I've been working with a client who doesn't want ORMs used (they do have quite good reasons for this although probably not as good as they think). I was interested to know, given that was the case, how you might - in Python, go about structuring an app which didn't use an ORM but which did use a RDBMS fairly intensively. I take your point about having "rolled my own ORM" - lol - but I can assure you what's in that 'bardb' is a pretty thin layer over the SQL and nothing like the, pretty amazing, functionality of, for instance, SQLAlchemy. From ngcbmy at gmail.com Sun Aug 5 00:16:04 2012 From: ngcbmy at gmail.com (JW Huang) Date: Sat, 4 Aug 2012 21:16:04 -0700 (PDT) Subject: conditional running of code portion Message-ID: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> Hi, How can I implement something like C++'s conditional compile. if VERBOSE_MODE: print debug information else: do nothing But I don't want this condition to be checked during runtime as it will slow down the code. Thanks in advance. From maniandram01 at gmail.com Sun Aug 5 00:43:43 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 5 Aug 2012 10:13:43 +0530 Subject: conditional running of code portion In-Reply-To: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> Message-ID: Try pypreprocessor . Better idea: You should be using the loggingmodule if you want to print debug information quickly.It uses threads and is optimized to run fast. On 5 August 2012 09:46, JW Huang wrote: > Hi, > > How can I implement something like C++'s conditional compile. > > if VERBOSE_MODE: print debug information > else: do nothing > > But I don't want this condition to be checked during runtime as it > will slow down the code. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sun Aug 5 00:56:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sun, 5 Aug 2012 10:26:04 +0530 Subject: when an iterable object is exhausted or not In-Reply-To: <501dd6bd$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501dd6bd$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: An important use of range repeating. one_to_10 = range(1,10) one_to_5 = range(1,5) for x in one_to_5: for x in one_to_10:pass if range wasn't repeatable, range would have to be called 5 times compared with 1! On 5 August 2012 07:43, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Sat, 04 Aug 2012 21:20:36 +0200, Franck Ditter wrote: > > > Two similar iterable objects but with a different behavior : > [...] > > IMHO, this should not happen in Py3k. What is the rationale of this (bad > > ?) design, which forces the programmer to memorize which one is > > exhaustable and which one is not ?... > > What makes you say that they are "similar" iterable objects? Except that > they are both iterable, they are very different. You might as well say > that lists and dicts are "similar iterable objects". > > filter objects are iterators, and so obey the intentionally simple > iterator protocol. range objects are iterable but not iterators, and do > not obey the iterator protocol. > > py> it = filter(lambda x: x, set('abc')) > py> iter(it) is it > True > py> x = range(1, 15, 2) > py> iter(x) is x > False > > > filter relies on its input, which it consumes as it does. Since the input > may not be restartable, filter cannot be restartable either. For > simplicity, filter does not try to be "clever" and guess when the input > argument is restartable. Instead, it simply and consistently behaves the > same for any iterable input. > > range is a specialist iterable data structure that does not consume > anything. It computes its output lazily, but that is the only similarity > with iterators. There's no need to limit range objects to the simple > iterator protocol, since they don't consume their input -- a single > object can easily compute its output as often as you want. range objects > are indexable and sliceable: > > py> x = range(1, 15, 2) > py> x[4] > 9 > py> x[2:4] > range(5, 9, 2) > > > Why artificially make range objects unrestartable just to satisfy > compatibility with iterators? > > The caller already has to remember that range and filter take different > arguments, do different things, and return different objects. Why is it > hard to remember that range is restartable and filter is not? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Aug 5 01:37:48 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Aug 2012 07:37:48 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <7x1ujm9kyu.fsf@ruckus.brouhaha.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <501dc461$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujm9kyu.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 05.08.2012 03:38: > Steven D'Aprano writes: >> Runtime optimizations that target the common case, but fall back to >> unoptimized code in the rare cases that the optimization doesn't apply, >> offer the opportunity of big speedups for most code at the cost of >> trivial slowdowns when you do something unusual. > > The problem is you can't always tell if the unusual case is being > exercised without an expensive dynamic check, which in some cases must > be repeated in every iteration of a critical inner loop, even though it > turns out that the program never actually uses the unusual case. Cython does a lot of optimistic optimisations. That's where a large part of that huge C file comes from that Cython generates from even simple Python code. For example, in CPython, C function calls are so ridiculously faster than Python function calls that it's worth some effort if it saves you from packing an argument tuple to call into a Python function. In fact, we've been thinking about ways to export C signatures from Python function objects, so that code implemented in C (or a C compatible language) can be called directly from other code implemented in C. That's very common in the CPython ecosystem. There are a lot of simple things that quickly add up into a much better performance on average. Stefan From stefan_ml at behnel.de Sun Aug 5 01:46:59 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Aug 2012 07:46:59 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <20120804232510.GA23550@jaerhard.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120804232510.GA23550@jaerhard.com> Message-ID: J?rgen A. Erhard, 05.08.2012 01:25: > On Sat, Aug 04, 2012 at 08:40:16AM +0200, Stefan Behnel wrote: >> Steven D'Aprano, 04.08.2012 08:15: >>> Most people are aware, if only vaguely, of the big Four Python >>> implementations: >> >> And not to forget Cython, which is the only static Python compiler that is >> widely used. Compiles and optimises Python to C code that uses the CPython >> runtime and allows for easy manual optimisations to get C-like performance >> out of it. > > Cython is certainly *not* a Python *implementation*, since it always > uses the CPython runtime (and compiling Cython C files requires > Python.h). Yes, it avoids an unnecessary duplication of effort as well as a substantial loss of compatibility that all non-CPython based implementations suffer from. You'd be surprised to see how much of Python we implement, though, including some of the builtins. You might want to revise your opinion once you start digging into it. It's always easy to disagree at the surface. > None of the other implementations require Python for actually > compiling or running Python source. Nuitka was on the list as well. > Oh, yes, you can create a stand-alone... wait, a "stand-alone" app. > By embedding the Python runtime (dynamic linking with libpythonX.Y... > maybe static too? Sure, that works. Stefan From steve+comp.lang.python at pearwood.info Sun Aug 5 02:30:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 06:30:49 GMT Subject: conditional running of code portion References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> Message-ID: <501e1319$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Aug 2012 21:16:04 -0700, JW Huang wrote: > Hi, > > How can I implement something like C++'s conditional compile. > > if VERBOSE_MODE: print debug information else: do nothing > > But I don't want this condition to be checked during runtime as it will > slow down the code. You've profiled your code and found that checking a flag is a bottleneck in your application? I'd hate to think you were wasting your time trying to avoid "slowing down" your code by an insignificant amount that nobody will ever notice. In general, the way to do C-like conditional compiles is to use C, or at least to use another language that isn't Python. Almost everything happens at runtime in Python. Possibly PyPy can optimise away unnecessary checks, but CPython doesn't. One of the very few exceptions: you can disable code at compile time like this: if __debug__: do_something() compiles to the byte-code equivalent of: do_something() under normal circumstances, and to nothing at all if Python is running with the -O optimize flag. If you are working in a tight loop, you can do this: if VERBOSE_FLAG: for item in loop: print(DEBUG_INFORMATION) do_actual_work(item) else: for item in loop: do_actual_work(item) -- Steven From stefan_ml at behnel.de Sun Aug 5 03:51:08 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Aug 2012 09:51:08 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120804232510.GA23550@jaerhard.com> Message-ID: Stefan Behnel, 05.08.2012 07:46: > J?rgen A. Erhard, 05.08.2012 01:25: >> None of the other implementations require Python for actually >> compiling or running Python source. > > Nuitka was on the list as well. Oh, and Stackless was also on Steven's list, as well as WPython. That means that 50% of the "other implementations" that Steven presented are not "implementations" according to your apparent definition. BTW, what is you definition? Stefan From feliphil at gmx.net Sun Aug 5 07:44:48 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 5 Aug 2012 13:44:48 +0200 Subject: The way to develope a graphical application to manage a Postgres database References: Message-ID: <20120805134448.08d5a9172912430da2a3a0b4@gmx.net> > Can one advices me where to go? There are a number of Python frameworks for GUI database applications: - Dabo (wxPython) - Sqlkit (PyGTK & SQLalchemy) - Pypapi (PyQt & SQLalchemy) - Camelot (PyQt & SQLalchemy) - Qtalchemy (PyQt & SQLalchemy) - Openobject (PyGTK) - Defis (wxPython & SQLalchemy), Russian only - Kiwi (PyGTK) Not sure whether these are still active: - Gnuenterprise (wxPython) - Pythoncard (wxPython) Sincerely, Wolfgang Keller From jae+python at jaerhard.com Sun Aug 5 08:28:07 2012 From: jae+python at jaerhard.com (=?iso-8859-1?B?SvxyZ2VuIEEu?= Erhard) Date: Sun, 5 Aug 2012 14:28:07 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120804232510.GA23550@jaerhard.com> Message-ID: <20120805122806.GB23550@jaerhard.com> On Sun, Aug 05, 2012 at 07:46:59AM +0200, Stefan Behnel wrote: > J?rgen A. Erhard, 05.08.2012 01:25: > > On Sat, Aug 04, 2012 at 08:40:16AM +0200, Stefan Behnel wrote: > >> Steven D'Aprano, 04.08.2012 08:15: > >>> Most people are aware, if only vaguely, of the big Four Python > >>> implementations: > >> > >> And not to forget Cython, which is the only static Python compiler that is > >> widely used. Compiles and optimises Python to C code that uses the CPython > >> runtime and allows for easy manual optimisations to get C-like performance > >> out of it. > > > > Cython is certainly *not* a Python *implementation*, since it always > > uses the CPython runtime (and compiling Cython C files requires > > Python.h). > > Yes, it avoids an unnecessary duplication of effort as well as a > substantial loss of compatibility that all non-CPython based > implementations suffer from. But it's not an Python *implementation*, "just" an extension. Mind you, this is not intended as a slight of Cython as such. I really like it, though I haven't had need for it yet, but I sure prefer it to writing extensions in pure C. *brrrr* > > None of the other implementations require Python for actually > > compiling or running Python source. > > Nuitka was on the list as well. True, which I realized only after my missive. But doesn't change much, only that the list is wrong. > > Oh, yes, you can create a stand-alone... wait, a "stand-alone" app. > > By embedding the Python runtime (dynamic linking with libpythonX.Y... > > maybe static too? > > Sure, that works. My definition, to also answer your following post, is "does not rely on any executable part of the CPython source (which includes .c files and executable code in header files if any, but of course can exclude the stdlib)". Not sure that's precise enough, but... if it can't run/work on a system that has no shred of CPython installed, it's not an alternative *implementation*. The big three don't need CPython (except PyPy for building, and even it can use a precompile PyPy I think). Grits, J From jeandubois314 at gmail.com Sun Aug 5 08:38:26 2012 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sun, 5 Aug 2012 05:38:26 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: <62867318-098a-4f35-9582-5c9084e595d6@u17g2000yqa.googlegroups.com> On 5 aug, 02:11, shearich... at gmail.com wrote: > One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ... > > Could do worse than this : > > http://www.diveintopython.net/object_oriented_framework/index.html > > and this > > http://docs.python.org/tutorial/classes.html > > read together. > > Judging by your question this is a probably a little advanced for now but you could bookmark it for the future: > > http://www.catonmat.net/blog/learning-python-design-patterns-through-... > > Here's the corresponding PDF to go with the video: > > http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns... Thanks a lot for this information, I'll check it out the following days best regards, Jean From roy at panix.com Sun Aug 5 09:04:24 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 09:04:24 -0400 Subject: Object Models - decoupling data access - good examples ? References: Message-ID: In article , shearichard at gmail.com wrote: > > Just out of curiosity, why do you eschew ORMs? > > > Good question ! > > I'm not anti-ORM (in fact in many circs I'm quite pro-ORM) but for some time > I've been working with a client who doesn't want ORMs used (they do have > quite good reasons for this although probably not as good as they think). OK, I'll re-ask the question. What are the reasons? > I take your point about having "rolled my own ORM" - lol - but I can assure > you what's in that 'bardb' is a pretty thin layer over the SQL and nothing > like the, pretty amazing, functionality of, for instance, SQLAlchemy. So, you're opposed to ORMs in general because you find SQLAlchemy too heavyweight. I don't blame you; every time I look at SQLAlchemy, I go screaming in the other direction. But, there are other ORMs. See, for example, http://lmgtfy.com/?q=python+orm. From ethan at stoneleaf.us Sun Aug 5 10:09:38 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Aug 2012 07:09:38 -0700 Subject: dbf.py API question In-Reply-To: References: <501AA304.3090000@stoneleaf.us> Message-ID: <501E7EA2.1060408@stoneleaf.us> Ole Martin Bj?rndalen wrote: > On Thu, Aug 2, 2012 at 5:55 PM, Ethan Furman wrote: >> SQLite has a neat feature where if you give it a the file-name of ':memory:' >> the resulting table is in memory and not on disk. I thought it was a cool >> feature, but expanded it slightly: any name surrounded by colons results in >> an in-memory table. >> >> I'm looking at the same type of situation with indices, but now I'm >> wondering if the :name: method is not pythonic and I should use a flag >> (in_memory=True) when memory storage instead of disk storage is desired. >> >> Thoughts? > > I agree that the flag would be more pythonic in dbf.py. > > I was not aware that you are adding sqlite functionality to your > library. This is very cool! Actually, I'm not. I had stumbled across that one tidbit and thought it was cool, but cool is not always pythonic. ;) > I am considering adding a "streaming=True" flag which would make the > table class a record generator, You can do this by implementing either __getitem__ or __iter__, unless the streaming flag would also make your table not in memory. > I hope this can help you somehow in your decision making process. All comments appreciated. Thanks! ~Ethan~ From ethan at stoneleaf.us Sun Aug 5 10:27:44 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Aug 2012 07:27:44 -0700 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501E82E0.5010201@stoneleaf.us> Mark Lawrence wrote: > With arrogance like that German by any chance? Comments like that are not appropriate on this list. Please don't make them. ~Ethan~ From ben+python at benfinney.id.au Sun Aug 5 11:21:12 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Aug 2012 01:21:12 +1000 Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d335l5zr.fsf@benfinney.id.au> Mark Lawrence writes: > With arrogance like that German by any chance? Please keep derogatory national stereotypes off this forum and out of our community. They are counter to our goals of diversity ; you don't have to subscribe to that, but if not then you thereby exclude yourself. -- \ ?You can stand tall without standing on someone. You can be a | `\ victor without having victims.? ?Harriet Woods, 1927?2007 | _o__) | Ben Finney From walterhurry at lavabit.com Sun Aug 5 11:47:31 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 5 Aug 2012 15:47:31 +0000 (UTC) Subject: The way to develope a graphical application to manage a Postgres database References: Message-ID: On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal wrote: > I'm searching for a way to develope a Python graphical application for a > Postgresql database. I use wxGlade/wxPython to build the GUI, and then hand code the database access using psycopg2 into the generated application. Works very well for me, but I do know SQL and Postgres. From csanyipal at gmail.com Sun Aug 5 11:58:46 2012 From: csanyipal at gmail.com (Csanyi Pal) Date: Sun, 05 Aug 2012 17:58:46 +0200 Subject: The way to develope a graphical application to manage a Postgres database References: Message-ID: <87txwhfhzd.fsf@gmail.com> Walter Hurry writes: > On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal wrote: > >> I'm searching for a way to develope a Python graphical application for a >> Postgresql database. > > I use wxGlade/wxPython to build the GUI, and then hand code the database > access using psycopg2 into the generated application. Works very well for > me, but I do know SQL and Postgres. Well, I tried out many adviced ways but none of them works on my Debian GNU/Linux testing/sid system. Always get some error in one of the part of the software. Can you give a short tutorial for newbies how to start to develope with tools you used successfully? -- Regards from Pal From walterhurry at lavabit.com Sun Aug 5 12:25:33 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 5 Aug 2012 16:25:33 +0000 (UTC) Subject: The way to develope a graphical application to manage a Postgres database References: Message-ID: On Sun, 05 Aug 2012 17:58:46 +0200, Csanyi Pal wrote: > Well, I tried out many adviced ways but none of them works on my Debian > GNU/Linux testing/sid system. Always get some error in one of the part > of the software. > > Can you give a short tutorial for newbies how to start to develope with > tools you used successfully? I'm afraid I'm not about to write a tutorial - there are better ones out there than I could produce; easily found. I just DuckDuckGo'ed, followed the tutorials and read the documentation. From storchaka at gmail.com Sun Aug 5 12:40:40 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 05 Aug 2012 19:40:40 +0300 Subject: conditional running of code portion In-Reply-To: <501e1319$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> <501e1319$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05.08.12 09:30, Steven D'Aprano wrote: > If you are working in a tight loop, you can do this: > > if VERBOSE_FLAG: > for item in loop: > print(DEBUG_INFORMATION) > do_actual_work(item) > else: > for item in loop: > do_actual_work(item) Or this: if VERBOSE_FLAG: def do_work(item): print(DEBUG_INFORMATION) do_actual_work(item) else: do_work = do_actual_work for item in loop: do_work(item) From jeandubois314 at gmail.com Sun Aug 5 14:04:36 2012 From: jeandubois314 at gmail.com (Jean Dubois) Date: Sun, 5 Aug 2012 11:04:36 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> On 5 aug, 02:11, shearich... at gmail.com wrote: > One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ... > > Could do worse than this : > > http://www.diveintopython.net/object_oriented_framework/index.html > This example seems to tell you need the concept of dictionaries to explain object oriented programming, is this really necessary? > and this > > http://docs.python.org/tutorial/classes.html Unfortunately, the trouble with this explanation is exactly what made me ask the original question: it starts from concepts in c++ making it very hard to understand for someone who does not know that language already. > > read together. > > Judging by your question this is a probably a little advanced for now but you could bookmark it for the future: > > http://www.catonmat.net/blog/learning-python-design-patterns-through-... > > Here's the corresponding PDF to go with the video: > > http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns... Can someone here on this list give a trivial example of what object oriented programming is, using only Python? thanks in advance Jean From breamoreboy at yahoo.co.uk Sun Aug 5 14:21:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 19:21:16 +0100 Subject: The way to develope a graphical application to manage a Postgres database In-Reply-To: <87txwhfhzd.fsf@gmail.com> References: <87txwhfhzd.fsf@gmail.com> Message-ID: On 05/08/2012 16:58, Csanyi Pal wrote: > Walter Hurry writes: > >> On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal wrote: >> >>> I'm searching for a way to develope a Python graphical application for a >>> Postgresql database. >> >> I use wxGlade/wxPython to build the GUI, and then hand code the database >> access using psycopg2 into the generated application. Works very well for >> me, but I do know SQL and Postgres. > > Well, I tried out many adviced ways but none of them works on my Debian > GNU/Linux testing/sid system. Always get some error in one of the part > of the software. If you give precise details by cutting and pasting the error people will be able to help. > > Can you give a short tutorial for newbies how to start to develope with > tools you used successfully? > Seek and ye shall find!!! -- Cheers. Mark Lawrence. From csanyipal at gmail.com Sun Aug 5 14:26:55 2012 From: csanyipal at gmail.com (Csanyi Pal) Date: Sun, 05 Aug 2012 20:26:55 +0200 Subject: The way to develope a graphical application to manage a Postgres database References: <87txwhfhzd.fsf@gmail.com> Message-ID: <87628xfb4g.fsf@gmail.com> Mark Lawrence writes: > On 05/08/2012 16:58, Csanyi Pal wrote: >> Walter Hurry writes: >> >>> On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal wrote: >>> >>>> I'm searching for a way to develope a Python graphical application for a >>>> Postgresql database. >>> >>> I use wxGlade/wxPython to build the GUI, and then hand code the database >>> access using psycopg2 into the generated application. Works very well for >>> me, but I do know SQL and Postgres. >> >> Well, I tried out many adviced ways but none of them works on my Debian >> GNU/Linux testing/sid system. Always get some error in one of the part >> of the software. > > If you give precise details by cutting and pasting the error people > will be able to help. I shall do that later. >> Can you give a short tutorial for newbies how to start to develope with >> tools you used successfully? >> > Seek and ye shall find!!! Ye, if I find spare time I shall do that certainly. -- Regards from Pal From breamoreboy at yahoo.co.uk Sun Aug 5 14:28:56 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 19:28:56 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: On 05/08/2012 19:04, Jean Dubois wrote: > On 5 aug, 02:11, shearich... at gmail.com wrote: >> One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ... >> >> Could do worse than this : >> >> http://www.diveintopython.net/object_oriented_framework/index.html >> > This example seems to tell you need the concept of dictionaries to > explain object oriented programming, is this really necessary? >> and this >> >> http://docs.python.org/tutorial/classes.html > Unfortunately, the trouble with this explanation is exactly what made > me ask the original question: it starts from concepts in c++ making it > very hard to understand for someone who does not know that language > already. >> >> read together. >> >> Judging by your question this is a probably a little advanced for now but you could bookmark it for the future: >> >> http://www.catonmat.net/blog/learning-python-design-patterns-through-... >> >> Here's the corresponding PDF to go with the video: >> >> http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns... > Can someone here on this list give a trivial example of what object > oriented programming is, using only Python? > > thanks in advance > Jean > Try this http://www.voidspace.org.uk/python/articles/OOP.shtml ??? -- Cheers. Mark Lawrence. From roy at panix.com Sun Aug 5 14:39:10 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 14:39:10 -0400 Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: In article <8f1b60a5-0411-4aae-9ee6-0025b493ca2d at m13g2000vbd.googlegroups.com>, Jean Dubois wrote: > Can someone here on this list give a trivial example of what object > oriented programming is, using only Python? OOP seems to mean different things to different people. What OOP means to you is usually a strong function of whatever OOP language you learned first. That being said, I think the fundamental, universal, core principle of OOP is that an object contains some data, and some code that knows how to do something with that data. So, to give you a simple (but real-life) example, the system I'm working in now has User objects. A user is a pretty complicated class, but here's some simple methods from it: def __eq__(self, other): return isinstance(other, (User, AnonymousUser)) \ and self.user_id == other.user_id def __unicode__(self): return self.username def __repr__(self): return '' % (self.user_id, self.username) This defines a few basic behaviors for User objects. First, it defines how to tell if something is equal to a given User object. The something must itself be a User (ignore the minor complication about AnonymousUser for the moment), and it must have the same user_id as this one. I could easily imagine lots of other possible ways two users could be considered equal (same username, for example), but we're using user_id. This means I can write: if user1 == user2: print "they're the same" and I don't have to worry about (or even know about) the details. In fact, sometime long after I've written that code, somebody could define some new kind of HighSecurityUser which tests for equality by comparing the scanned retina images for both of them. My code wouldn't have to change; it would magically just start enforcing retina matching. Likewise, I can write: print user or logger.warning("%r did something interesting", user) and I don't have to know anything about how to print a User. The User knows how to print itself. From iftecan2000 at gmail.com Sun Aug 5 14:43:10 2012 From: iftecan2000 at gmail.com (Ifthikhan Nazeem) Date: Sun, 5 Aug 2012 20:43:10 +0200 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: I would recommend Bruce Eckel's Thining in Python. Check it out here http://www.mindview.net/Books/TIPython/ On Sun, Aug 5, 2012 at 8:28 PM, Mark Lawrence wrote: > On 05/08/2012 19:04, Jean Dubois wrote: > >> On 5 aug, 02:11, shearich... at gmail.com wrote: >> >>> One reason you may be having difficulty is that unlike some languages >>> (C++/Java) object-orientation is not a be all and end all in Python, in >>> fact you could work with Python for a long time without really 'doing it' >>> at all (well other than calling methods/properties on existing API's). >>> Having said that here's what I would suggest ... >>> >>> Could do worse than this : >>> >>> http://www.diveintopython.net/**object_oriented_framework/**index.html >>> >>> This example seems to tell you need the concept of dictionaries to >> explain object oriented programming, is this really necessary? >> >>> and this >>> >>> http://docs.python.org/**tutorial/classes.html >>> >> Unfortunately, the trouble with this explanation is exactly what made >> me ask the original question: it starts from concepts in c++ making it >> very hard to understand for someone who does not know that language >> already. >> >>> >>> read together. >>> >>> Judging by your question this is a probably a little advanced for now >>> but you could bookmark it for the future: >>> >>> http://www.catonmat.net/blog/**learning-python-design-** >>> patterns-through-. >>> .. >>> >>> Here's the corresponding PDF to go with the video: >>> >>> http://assets.en.oreilly.com/**1/event/45/Practical%20Python%** >>> 20Patterns. >>> .. >>> >> Can someone here on this list give a trivial example of what object >> oriented programming is, using only Python? >> >> thanks in advance >> Jean >> >> > Try this http://www.voidspace.org.uk/**python/articles/OOP.shtml??? > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Aug 5 14:53:01 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 19:53:01 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: On 05/08/2012 19:43, Ifthikhan Nazeem wrote: [top posting fixed] > > On Sun, Aug 5, 2012 at 8:28 PM, Mark Lawrence wrote: > >> On 05/08/2012 19:04, Jean Dubois wrote: >> >>> On 5 aug, 02:11, shearich... at gmail.com wrote: >>> >>>> One reason you may be having difficulty is that unlike some languages >>>> (C++/Java) object-orientation is not a be all and end all in Python, in >>>> fact you could work with Python for a long time without really 'doing it' >>>> at all (well other than calling methods/properties on existing API's). >>>> Having said that here's what I would suggest ... >>>> >>>> Could do worse than this : >>>> >>>> http://www.diveintopython.net/**object_oriented_framework/**index.html >>>> >>>> This example seems to tell you need the concept of dictionaries to >>> explain object oriented programming, is this really necessary? >>> >>>> and this >>>> >>>> http://docs.python.org/**tutorial/classes.html >>>> >>> Unfortunately, the trouble with this explanation is exactly what made >>> me ask the original question: it starts from concepts in c++ making it >>> very hard to understand for someone who does not know that language >>> already. >>> >>>> >>>> read together. >>>> >>>> Judging by your question this is a probably a little advanced for now >>>> but you could bookmark it for the future: >>>> >>>> http://www.catonmat.net/blog/**learning-python-design-** >>>> patterns-through-. >>>> .. >>>> >>>> Here's the corresponding PDF to go with the video: >>>> >>>> http://assets.en.oreilly.com/**1/event/45/Practical%20Python%** >>>> 20Patterns. >>>> .. >>>> >>> Can someone here on this list give a trivial example of what object >>> oriented programming is, using only Python? >>> >>> thanks in advance >>> Jean >>> >>> >> Try this http://www.voidspace.org.uk/**python/articles/OOP.shtml??? >> >> -- >> Cheers. >> >> Mark Lawrence. >> >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > I would recommend Bruce Eckel's Thining in Python. Check it out here > http://www.mindview.net/Books/TIPython/ > > I'd forgotten about that so thanks for the reminder. -- Cheers. Mark Lawrence. From dncarac at gmail.com Sun Aug 5 14:59:55 2012 From: dncarac at gmail.com (dncarac at gmail.com) Date: Sun, 5 Aug 2012 11:59:55 -0700 (PDT) Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: <696267e8-996a-45ac-97d9-b1d4d2453466@googlegroups.com> I found Mark Lutz's book Learning Python had two or three chapters on object oriented programming from starting principles to more involved Python object programming. It helped me immensely. From jdildy85 at gmail.com Sun Aug 5 15:29:30 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 12:29:30 -0700 (PDT) Subject: Intermediate Python user needed help Message-ID: I am currently using python 2.6 and am not going to install the newer versions of python and i am looking for people that are still using ver 2.6 in python to help with with the code line: sentence = "All good things come to those who wait." then im getting this error message when i dont see the problem with it: File "ex26.py", line 77 sentence = "All good things come to those who wait." ^ SyntaxError: invalid syntax Please help me Email me at Jdildy85 at gmail.com if you have any help for me From john_ladasky at sbcglobal.net Sun Aug 5 15:34:33 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 5 Aug 2012 12:34:33 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: Check line 76 of your code for errors. If line 76 is incorrectly formed, Python may see line 77 as a continuation of line 76 and throw the SyntaxError because of that. From jdildy85 at gmail.com Sun Aug 5 15:44:03 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 12:44:03 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <6fcd2078-8ceb-4b6f-99f7-44f604a97bd4@googlegroups.com> Well 75 and 76 is a blank line of text but i will see if i can take out those lines to see if it is the problem thanks John From lipskathekat at yahoo.co.uk Sun Aug 5 15:46:23 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Sun, 05 Aug 2012 20:46:23 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On 04/08/12 16:49, Jean Dubois wrote: > I'm looking for a good introduction to object oriented programming > with Python. Object Oriented programming is a mindset, a way of looking at that particular part of our world that you are trying to encapsulate in computer language. The language you use is (should be) irrelevant. The ONLY concept that you should never try to encapsulate is/are human beings or their aliases. So Person, User, Human etc should not exist in any way shape or form in your design. There is an argument that User is ok but I don't subscribe to that. If you want to represent human interaction in your software design use Account or Session or some other non human noun. Actually it should really be called Class Oriented programming as classes are the units of encapsulation. I really don't think python is a good language to learn OO programming, the problem is that Python doesn't enforce OO so you are never going to learn what is 'OO' and what isn't. Before I get told off/flamed/shouted at I've just started learning Python and I think it is a great language with a fantastic standard library. I've already managed to write meaningful code but I haven't invented a single class yet. Apologies if this sound negative, it's not meant to be it's meant to be constructive. There is a book you could try, it's a bit dry and I read it when I can't sleep, about 30 mins usually does it :-) It's called Design Patterns by Gamma, Helm, Johnson and Vlissides ISBN 0-201-63361-2. They do use C++ code in examples but as they say, this is just a convenience and shouldn't colour your view of the subject I still read the introduction and get something out of it after several years. You should be able to implement the patterns in Python although I must admit I haven't tried that yet Learn Python by all means, the interactive mode is particularly fun,just try and get a good idea of what OO is all about before you start. Just my opinion lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jdildy85 at gmail.com Sun Aug 5 15:51:31 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 12:51:31 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> Ive tried to delete the spaces in 75 and 76 to see if it made a change but it has not made a difference to it. Here is the full code and the thing is i know there is things wrong with it but the thing is im fixing a code for a friend to help him getting with the coding: def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return words def sort_words(words): """Sorts the words.""" return sorted(words) def print_first_word(words): """Prints the first word after popping it off.""" word = words.pop(0) print word def print_last_word(words): """Prints the last word after popping it off.""" word = words.pop(-1) print word def sort_sentence(sentence): """Takes in a full sentence and returns the sorted words.""" words = break_words(sentence) return sort_words(words) def print_first_and_last(sentence): """Prints the first and last words of the sentence.""" words = break_words(sentence) print_first_word(words) print_last_word(words) def print_first_and_last_sorted(sentence): """Sorts the words then prints the first and last one.""" words = sort_sentence(sentence) print_first_word(words) print_last_word(words) print "Let's practice everything." print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.' poem = """ \tThe lovely world with logic so firmly planted cannot discern \n the needs of love nor comprehend passion from intuition and requires an explantion \n\t\twhere there is none. """ print "--------------" print poem print "--------------" five = 10 - 2 + 3 - 5 print "This should be five: %s" % five def secret_formula(started): jelly_beans = started * 500 jars = jelly_beans / 1000 crates = jars / 100 return jelly_beans, jars, crates start_point = 10000 beans, jars, crates == secret_formula(start-point) print "With a starting point of: %d" % start_point print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates) start_point = start_point / 10 print "We can also do that this way:" print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont sentence = "All good things come to those who wait." words = ex25.break_words(sentence) sorted_words = ex25.sort_words(words) print_first_word(words) print_last_word(words) .print_first_word(sorted_words) print_last_word(sorted_words) sorted_words = ex25.sort_sentence(sentence) prin sorted_words print_irst_and_last(sentence) print_first_a_last_sorted(senence) Thank you in advance to anyone that can help me with this code From bahamutzero8825 at gmail.com Sun Aug 5 16:09:51 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 05 Aug 2012 15:09:51 -0500 Subject: Intermediate Python user needed help In-Reply-To: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> References: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> Message-ID: <501ED30F.9030208@gmail.com> On 8/5/2012 2:51 PM, John Mordecai Dildy wrote: > print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont > sentence = "All good things come to those who wait." You are missing a parenthesis at the end of the previous line. > .print_first_word(sorted_words) That dot will make this line raise an error. You should use an IDE or something to highlight syntax errors. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 From thudfoo at gmail.com Sun Aug 5 16:15:10 2012 From: thudfoo at gmail.com (xDog Walker) Date: Sun, 5 Aug 2012 13:15:10 -0700 Subject: Intermediate Python user needed help In-Reply-To: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> References: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> Message-ID: <201208051315.10563.thudfoo@gmail.com> On Sunday 2012 August 05 12:51, John Mordecai Dildy wrote: > print "We'd have %d beans, %d jars, and %d crabapples." % > secret_formula(start_pont Add a ) to the end of the line quoted above. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From jdildy85 at gmail.com Sun Aug 5 16:16:13 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 13:16:13 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <2977cceb-17d8-408f-8e4e-1aa47060350c@googlegroups.com> well that work on mac though? im asking because i see the Windows NT at the bottom of your reply and plus im using 2.6 python not 3.3 From jdildy85 at gmail.com Sun Aug 5 16:17:45 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 13:17:45 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: <2977cceb-17d8-408f-8e4e-1aa47060350c@googlegroups.com> References: <2977cceb-17d8-408f-8e4e-1aa47060350c@googlegroups.com> Message-ID: <105114b5-e09f-4aaa-aed8-d45a6b099a29@googlegroups.com> On Sunday, August 5, 2012 4:16:13 PM UTC-4, John Mordecai Dildy wrote: > well that work on mac though? > > im asking because i see the Windows NT at the bottom of your reply and plus im using 2.6 python not 3.3 i see the ) problem i have it fixed From jdildy85 at gmail.com Sun Aug 5 16:19:59 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 13:19:59 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <93e8e878-f0cf-4d20-bb35-d3c302561639@googlegroups.com> File "ex26.py", line 84 .print_first_word(sorted_words) ^ SyntaxError: invalid syntax is what i have now and i dont see the problem like usual (i only post problems that i cant fix). From steve+comp.lang.python at pearwood.info Sun Aug 5 16:24:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 20:24:45 GMT Subject: Intermediate Python user needed help References: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> Message-ID: <501ed68c$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 12:51:31 -0700, John Mordecai Dildy wrote: > Ive tried to delete the spaces in 75 and 76 to see if it made a change > but it has not made a difference to it. What made you think that the problem could be fixed by deleting *spaces*? In general, making random changes to code in the hope that syntax errors will just go away is not the right way to fix broken code. Even if you succeed, since you don't know what you did to fix it, how do you know that your next change won't break it again? Almost always, when you have a mysterious syntax error on a line that appears to be perfectly fine, the reason is a missing bracket of some sort on a previous line. (For Americans, I mean parentheses, brackets or braces; for Britons and Australians, round square or curly brackets; for everyone else, whatever you call them.) -- Steven From jdildy85 at gmail.com Sun Aug 5 16:31:18 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 13:31:18 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: <501ed68c$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <566c9ebc-5d93-4b5f-94c3-d5710bc01583@googlegroups.com> <501ed68c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8df16187-8ca5-4be8-a9f9-6e121aaad96d@googlegroups.com> On Sunday, August 5, 2012 4:24:45 PM UTC-4, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 12:51:31 -0700, John Mordecai Dildy wrote: > > > > > Ive tried to delete the spaces in 75 and 76 to see if it made a change > > > but it has not made a difference to it. > > > > What made you think that the problem could be fixed by deleting *spaces*? > > > > In general, making random changes to code in the hope that syntax errors > > will just go away is not the right way to fix broken code. Even if you > > succeed, since you don't know what you did to fix it, how do you know > > that your next change won't break it again? > > > > Almost always, when you have a mysterious syntax error on a line that > > appears to be perfectly fine, the reason is a missing bracket of some > > sort on a previous line. (For Americans, I mean parentheses, brackets or > > braces; for Britons and Australians, round square or curly brackets; for > > everyone else, whatever you call them.) > > > > > > -- > > Steven Well i have put the spaces back into the code after i did that and had no hope it worked though. thank you steven for giving me some input From jdildy85 at gmail.com Sun Aug 5 16:52:35 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 13:52:35 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Current Problem at the moment Traceback (most recent call last): File "ex26.py", line 66, in beans, jars, crates = secret_formula(start-point) NameError: name 'start' is not defined anyone know how to make start defined From roy at panix.com Sun Aug 5 17:01:20 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 17:01:20 -0400 Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: In article <506eb405-eb07-4175-9efb-40475cabacf1 at googlegroups.com>, John Mordecai Dildy wrote: > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined You gotta give us more to go on than that. Adding a line: start = 0 right before line 66 will make it defined, but it's almost certainly not what you want. Give us a little context. What value did you expect start would have? From python.list at tim.thechases.com Sun Aug 5 17:03:50 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Aug 2012 16:03:50 -0500 Subject: Intermediate Python user needed help In-Reply-To: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <501EDFB6.3050507@tim.thechases.com> On 08/05/12 15:52, John Mordecai Dildy wrote: > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined "start-point" is not a valid identifier as the "-" isn't permitted in a variable name. This is the case for just about every language out there. HTML/XML & CSS are the only languages that come to my mind in which the dash is considered a valid part of an identifier. You either mean something like "start_point" (with an underscore instead of a minus), or you're performing a subtraction of "start minus point", in which case you'd have to assign those values before you use them. -tkc From vlastimil.brom at gmail.com Sun Aug 5 17:06:49 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 5 Aug 2012 23:06:49 +0200 Subject: Intermediate Python user needed help In-Reply-To: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: 2012/8/5 John Mordecai Dildy : > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined > -- > http://mail.python.org/mailman/listinfo/python-list Hi, you would need to assign something to the name "start", e.g. start = 3 the next error would probably be undefined "point", which should get subtracted from "start" according to the code ... However, in your case, this is likely another typo in the code, you probably want "start_point", which is defined in the script already. hth, vbr From schesis at gmail.com Sun Aug 5 17:07:43 2012 From: schesis at gmail.com (Zero Piraeus) Date: Sun, 5 Aug 2012 17:07:43 -0400 Subject: Intermediate Python user needed help In-Reply-To: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: : On 5 August 2012 16:52, John Mordecai Dildy wrote: > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined I think you could help yourself by reading a good tutorial or two ... so far, the problems you've raised suggest quite strongly that you either aren't reading the code with anything like the care that you need to, or just don't understand Python at all. Hint: if the offending line were written like this, would it be more obvious what's wrong? beans, jars, crates = secret_formula(start - point) -[]z. From python at mrabarnett.plus.com Sun Aug 5 17:08:39 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Aug 2012 22:08:39 +0100 Subject: Intermediate Python user needed help In-Reply-To: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <501EE0D7.5080106@mrabarnett.plus.com> On 05/08/2012 21:52, John Mordecai Dildy wrote: > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined > You have "start-point", but I think that should be "start_point", judging by the previous line. From jdildy85 at gmail.com Sun Aug 5 17:09:38 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 14:09:38 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <516d59a7-425b-4b96-82b2-b1f634f089c7@googlegroups.com> Thanks everyone that has put input into this its working on out error by error On Sunday, August 5, 2012 5:03:50 PM UTC-4, Tim Chase wrote: > On 08/05/12 15:52, John Mordecai Dildy wrote: > > > Current Problem at the moment > > > > > > Traceback (most recent call last): > > > File "ex26.py", line 66, in > > > beans, jars, crates = secret_formula(start-point) > > > NameError: name 'start' is not defined > > > > > > anyone know how to make start defined > > > > "start-point" is not a valid identifier as the "-" isn't permitted > > in a variable name. This is the case for just about every language > > out there. HTML/XML & CSS are the only languages that come to my > > mind in which the dash is considered a valid part of an identifier. > > > > You either mean something like "start_point" (with an underscore > > instead of a minus), or you're performing a subtraction of "start > > minus point", in which case you'd have to assign those values before > > you use them. > > > > -tkc From python at mrabarnett.plus.com Sun Aug 5 17:12:52 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Aug 2012 22:12:52 +0100 Subject: Intermediate Python user needed help In-Reply-To: <501EDFB6.3050507@tim.thechases.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> Message-ID: <501EE1D4.4080809@mrabarnett.plus.com> On 05/08/2012 22:03, Tim Chase wrote: > On 08/05/12 15:52, John Mordecai Dildy wrote: >> Current Problem at the moment >> >> Traceback (most recent call last): >> File "ex26.py", line 66, in >> beans, jars, crates = secret_formula(start-point) >> NameError: name 'start' is not defined >> >> anyone know how to make start defined > > "start-point" is not a valid identifier as the "-" isn't permitted > in a variable name. This is the case for just about every language > out there. HTML/XML & CSS are the only languages that come to my > mind in which the dash is considered a valid part of an identifier. > I believe that Cobol allows "-" in names. From jdildy85 at gmail.com Sun Aug 5 17:14:09 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 14:14:09 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> Message-ID: Im using Textwrangler and thats the only text editor that im using just saying for everyone From jdildy85 at gmail.com Sun Aug 5 17:14:09 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 14:14:09 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> Message-ID: Im using Textwrangler and thats the only text editor that im using just saying for everyone From andre at ramaciotti.com Sun Aug 5 17:22:12 2012 From: andre at ramaciotti.com (Andre Ramaciotti) Date: Sun, 05 Aug 2012 18:22:12 -0300 Subject: Intermediate Python user needed help In-Reply-To: <501EE1D4.4080809@mrabarnett.plus.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: <501EE404.8060302@ramaciotti.com> On 08/05/2012 06:12 PM, MRAB wrote: > On 05/08/2012 22:03, Tim Chase wrote: >> On 08/05/12 15:52, John Mordecai Dildy wrote: >>> Current Problem at the moment >>> >>> Traceback (most recent call last): >>> File "ex26.py", line 66, in >>> beans, jars, crates = secret_formula(start-point) >>> NameError: name 'start' is not defined >>> >>> anyone know how to make start defined >> >> "start-point" is not a valid identifier as the "-" isn't permitted >> in a variable name. This is the case for just about every language >> out there. HTML/XML & CSS are the only languages that come to my >> mind in which the dash is considered a valid part of an identifier. >> > I believe that Cobol allows "-" in names. > Lisp certainly does. From roy at panix.com Sun Aug 5 17:32:26 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 17:32:26 -0400 Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: In article , Tim Chase wrote: > On 08/05/12 15:52, John Mordecai Dildy wrote: > > Current Problem at the moment > > > > Traceback (most recent call last): > > File "ex26.py", line 66, in > > beans, jars, crates = secret_formula(start-point) > > NameError: name 'start' is not defined > > > > anyone know how to make start defined > > "start-point" is not a valid identifier as the "-" isn't permitted > in a variable name. This is the case for just about every language > out there. HTML/XML & CSS are the only languages that come to my > mind in which the dash is considered a valid part of an identifier. > > You either mean something like "start_point" (with an underscore > instead of a minus), or you're performing a subtraction of "start > minus point", in which case you'd have to assign those values before > you use them. Or he meant to pass an optional parameter: beans, jars, crates = secret_formula(start=point) or an element access: beans, jars, crates = secret_formula(start.point) or a bunch of other possibilities. From jdildy85 at gmail.com Sun Aug 5 18:00:47 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 15:00:47 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: since when did we start talking about lisp? From jdildy85 at gmail.com Sun Aug 5 18:00:47 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 15:00:47 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: since when did we start talking about lisp? From breamoreboy at yahoo.co.uk Sun Aug 5 18:11:46 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 23:11:46 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On 05/08/2012 20:46, lipska the kat wrote: [snip] > There is a book you could try, it's a bit dry and I read it when I can't > sleep, about 30 mins usually does it :-) > It's called Design Patterns by Gamma, Helm, Johnson and Vlissides > ISBN 0-201-63361-2. > They do use C++ code in examples but as they say, this is just a > convenience and shouldn't colour your view of the subject > I still read the introduction and get something out of it after several > years. You should be able to implement the patterns in Python > although I must admit I haven't tried that yet > Please no, that's the worst possible book for someone trying to learn OOD in Python. It's mostly if not completely irrelevant, jumping through hoops that you don't need in Python because of its dynamic nature. Start with the factory pattern and I hope you'll understand why I say this. Search for "design patterns alex martelli" and you'll get all you need and more. > lipska > > > -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Aug 5 18:15:42 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 23:15:42 +0100 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: On 05/08/2012 22:32, Roy Smith wrote: > In article , > Tim Chase wrote: > >> On 08/05/12 15:52, John Mordecai Dildy wrote: >>> Current Problem at the moment >>> >>> Traceback (most recent call last): >>> File "ex26.py", line 66, in >>> beans, jars, crates = secret_formula(start-point) >>> NameError: name 'start' is not defined >>> >>> anyone know how to make start defined >> >> "start-point" is not a valid identifier as the "-" isn't permitted >> in a variable name. This is the case for just about every language >> out there. HTML/XML & CSS are the only languages that come to my >> mind in which the dash is considered a valid part of an identifier. >> >> You either mean something like "start_point" (with an underscore >> instead of a minus), or you're performing a subtraction of "start >> minus point", in which case you'd have to assign those values before >> you use them. > > Or he meant to pass an optional parameter: > > beans, jars, crates = secret_formula(start=point) > > or an element access: > > beans, jars, crates = secret_formula(start.point) > > or a bunch of other possibilities. > Like it, marks out of 10, 15 :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Aug 5 18:17:10 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Aug 2012 23:17:10 +0100 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: On 05/08/2012 23:00, John Mordecai Dildy wrote: > since when did we start talking about lisp? > Just about anything is on topic here. -- Cheers. Mark Lawrence. From jdildy85 at gmail.com Sun Aug 5 18:39:31 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Sun, 5 Aug 2012 15:39:31 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: oh From steve+comp.lang.python at pearwood.info Sun Aug 5 18:51:48 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Aug 2012 22:51:48 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 18:45:47 -0400, Dennis Lee Bieber wrote: > Don't look for Object-Oriented Programming -- since the first widely > popular OOP language was C++ (Smalltalk was earlier, but rather > specialized, whereas C++ started as a preprocessor for C). > > Rather look for Object-Oriented Analysis and Design (OOAD). An OOAD > textbook /should/ be language neutral and, these days, likely using the > constructs/notation of UML [which derived from a merger of two or three > separate proposals for OOAD tools] Good lord. I'd rather read C++ than UML. And I can't read C++. -- Steven From roy at panix.com Sun Aug 5 18:53:45 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 18:53:45 -0400 Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On 05/08/2012 20:46, lipska the kat wrote: > Design Patterns by Gamma, Helm, Johnson and Vlissides In article , Mark Lawrence wrote: > Please no, that's the worst possible book for someone trying to learn > OOD in Python. +1 what Mark said. It's certainly the classic patterns book, but most of it is about clever ways to work around the C++/Java style of type bondage. Trying to learn OO from that book is like learning to paint by reading a textbook on the chemical properties of oil pigments. From roy at panix.com Sun Aug 5 19:12:35 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 19:12:35 -0400 Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <501ef904$0$29867$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 18:45:47 -0400, Dennis Lee Bieber wrote: > > > Don't look for Object-Oriented Programming -- since the first widely > > popular OOP language was C++ (Smalltalk was earlier, but rather > > specialized, whereas C++ started as a preprocessor for C). > > > > Rather look for Object-Oriented Analysis and Design (OOAD). An OOAD > > textbook /should/ be language neutral and, these days, likely using the > > constructs/notation of UML [which derived from a merger of two or three > > separate proposals for OOAD tools] > > Good lord. I'd rather read C++ than UML. And I can't read C++. UML is under-rated. I certainly don't have any love of the 47 different flavors of diagram, but the basic idea of having a common graphical language for describing how objects and classes interact is pretty useful. Just don't ask me to remember which kind of arrowhead I'm supposed to use in which situation. From python.list at tim.thechases.com Sun Aug 5 19:19:55 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Aug 2012 18:19:55 -0500 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: <501EFF9B.7030207@tim.thechases.com> On 08/05/12 17:00, John Mordecai Dildy wrote: > since when did we start talking about lisp? Though not a lisper, the Python tie-in was my reply: Python (among many other languages) doesn't allow a "-" as a character in identifiers as you appeared to use it in your code. Unlike HTML, XML, CSS, and apparently lisp and COBOL (thanks, MRAB, for ripping open that scab after years of trying to repress those COBOL memories :-) where identifiers may contain the dash. -tkc From python.list at tim.thechases.com Sun Aug 5 19:27:47 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Aug 2012 18:27:47 -0500 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <501F0173.8070809@tim.thechases.com> On 08/05/12 16:32, Roy Smith wrote: > Tim Chase wrote: >> You either mean something like "start_point" (with an underscore >> instead of a minus), or you're performing a subtraction of "start >> minus point", in which case you'd have to assign those values before >> you use them. > > Or he meant to pass an optional parameter: > > beans, jars, crates = secret_formula(start=point) > > or an element access: > > beans, jars, crates = secret_formula(start.point) Or pass a boolean beans, jars, crates = secret_formula(start>point) Or subscript with an also-missing close-bracket beans, jars, crates = secret_formula(start[point]) Or call a function with an also-missing close-paren beans, jars, crates = secret_formula(start(point)) Or it was just a finger-flub beans, jars, crates = secret_formula(startpoint) :-) -tkc From breamoreboy at yahoo.co.uk Sun Aug 5 19:30:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Aug 2012 00:30:13 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/08/2012 00:12, Roy Smith wrote: > In article <501ef904$0$29867$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> On Sun, 05 Aug 2012 18:45:47 -0400, Dennis Lee Bieber wrote: >> >>> Don't look for Object-Oriented Programming -- since the first widely >>> popular OOP language was C++ (Smalltalk was earlier, but rather >>> specialized, whereas C++ started as a preprocessor for C). >>> >>> Rather look for Object-Oriented Analysis and Design (OOAD). An OOAD >>> textbook /should/ be language neutral and, these days, likely using the >>> constructs/notation of UML [which derived from a merger of two or three >>> separate proposals for OOAD tools] >> >> Good lord. I'd rather read C++ than UML. And I can't read C++. > > UML is under-rated. I certainly don't have any love of the 47 different > flavors of diagram, but the basic idea of having a common graphical > language for describing how objects and classes interact is pretty > useful. Just don't ask me to remember which kind of arrowhead I'm > supposed to use in which situation. > Ask nicely and I'll lend you my copy of Martin Fowler's UML Distilled which covers "version 1.2 OMG UML standard". What's it up to now, version 17.38? -- Cheers. Mark Lawrence. From roy at panix.com Sun Aug 5 19:32:26 2012 From: roy at panix.com (Roy Smith) Date: Sun, 05 Aug 2012 19:32:26 -0400 Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: In article , Tim Chase wrote: > On 08/05/12 17:00, John Mordecai Dildy wrote: > > since when did we start talking about lisp? > > Though not a lisper, the Python tie-in was my reply: Python (among > many other languages) doesn't allow a "-" as a character in > identifiers as you appeared to use it in your code. Unlike HTML, > XML, CSS, and apparently lisp and COBOL (thanks, MRAB, for ripping > open that scab after years of trying to repress those COBOL memories > :-) where identifiers may contain the dash. > > -tkc Does BNF count as a language? From wrw at mac.com Sun Aug 5 19:38:58 2012 From: wrw at mac.com (William R. Wing) Date: Sun, 05 Aug 2012 19:38:58 -0400 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> Message-ID: On Aug 5, 2012, at 5:14 PM, John Mordecai Dildy wrote: > Im using Textwrangler and thats the only text editor that im using just saying for everyone > -- > http://mail.python.org/mailman/listinfo/python-list (With apologies, I initially sent this privately to John, and not to the list.) As I'm sure you are aware, TextWrangler is the free baby brother of BBEdit which, although not free, contains automatic syntax highlighting for exactly the sort of error you made. It would have signaled "unmatched parentheses" the instant you finished inputting that line in your original bit of code. If you value your time, I think you will find it more than pays for itself. Just saying? -Bill From ojlise at gmail.com Sun Aug 5 19:46:54 2012 From: ojlise at gmail.com (PeterSo) Date: Sun, 5 Aug 2012 16:46:54 -0700 (PDT) Subject: Getting started with IDLE and Python - no highlighting and no execution Message-ID: I am just starting to learn Python, and I like to use the editor instead of the interactive shell. So I wrote the following little program in IDLE # calculating the mean data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] def mean(data): return sum(data)/len(data) mean(data1) There is no syntax highlighting and when I ran it F5, I got the following in the shell window. >>> ================================ RESTART ================================ >>> >>> Any ideas? If I added print mean(data1), it gave me a invalid syntax # calculating the mean data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] data2=[1,2,3,4,5] def mean(data): return sum(data)/len(data) mean(data1) print mean(data1) From sg552 at hotmail.co.uk Sun Aug 5 20:09:30 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 06 Aug 2012 01:09:30 +0100 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: Message-ID: On 06/08/2012 00:46, PeterSo wrote: > I am just starting to learn Python, and I like to use the editor > instead of the interactive shell. So I wrote the following little > program in IDLE > > # calculating the mean > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > def mean(data): > return sum(data)/len(data) > > mean(data1) > > > There is no syntax highlighting and when I ran it F5, I got the > following in the shell window. > > > >>> ================================ RESTART > ================================ >>>> >>>> > > > Any ideas? I don't know what editor you're using or how it works, but I'm guessing that pressing f5 runs what you've written as a script, right? In that case the interpreter doesn't automatically print the result of expressions in the same way that the interactive interpreter does; you didn't tell it to print anything, so it didn't. > If I added print mean(data1), it gave me a invalid syntax > > # calculating the mean > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > data2=[1,2,3,4,5] > > def mean(data): > return sum(data)/len(data) > > mean(data1) > print mean(data1) If you're using Python 3.x, you'll need to replace print mean(data1) with print(mean(data1)) since the print statement has been replaced with the print function in Python 3. If you're instead using Python 2.x then I don't know what the problem is, but in that case your mean() function won't work properly - the forward slash operator between a pair of ints gives you floor division by default, so you should instead have it return something like float(sum(data))/len(data). -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From steve+comp.lang.python at pearwood.info Sun Aug 5 20:22:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Aug 2012 00:22:34 GMT Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: > > Object Oriented programming is a mindset, a way of looking at that > particular part of our world that you are trying to encapsulate in > computer language. The language you use is (should be) irrelevant. That depends on how you define OOP, and in particular, which aspects of OOP your language supports. There are lots of differences between styles and implementations of OOP languages, and no two languages have exactly the same feature set, but in general most OOP languages involve most of the following features: - Dynamic dispatch when making method calls - Encapsulation, or multi-methods - Subtype polymorphism - Object inheritance, or delegation See here for more detail: http://en.wikipedia.org/wiki/Object-oriented_programming#Fundamental_features_and_concepts But beyond those fundamentals, the details of OOP can differ greatly from language to language. Some languages treat classes as static, some as dynamic. Some languages treat classes as objects themselves, others treat them as non-objects. Syntax varies (although the dot operator has become almost completely ubiquitous, there are still some exceptions). In particularly, terminology varies -- I personally despise with the heat of a thousand suns the terms "instance variable" and "class variable" for attributes or members. Since a "string variable" is a variable holding a string, and a "float variable" is a variable holding a float, an instance variable should be a variable holding an instance, and a class variable should be a variable holding a class. > The ONLY concept that you should never try to encapsulate is/are human > beings or their aliases. So Person, User, Human etc should not exist in > any way shape or form in your design. There is an argument that User is > ok but I don't subscribe to that. > > If you want to represent human interaction in your software design use > Account or Session or some other non human noun. Is this some sort of mystical "humans aren't objects, they're SPECIAL!!!" rubbish? Because it sure sounds like it. Can you give some non-religious reasons why you should not implement human beings or aliases as objects? If not, let me just say that I reject your prohibition and leave it at that. > Actually it should really be called Class Oriented programming as > classes are the units of encapsulation. Incorrect. You don't even need classes to have objects. You can have class-based OOP, and prototype-based OOP, as in Javascript, Actionscript, Io, and the language which invented the term, Self. http://en.wikipedia.org/wiki/Prototype-based_programming > I really don't think python is a > good language to learn OO programming, the problem is that Python > doesn't enforce OO so you are never going to learn what is 'OO' and what > isn't. I think that's exactly why Python *is* a good language to learn OOP, because you can be productive even while learning. You can start off by just adding a little bit of OOP syntax to your programs: response = raw_input("What do you want to do? ") response = response.lower() # Look ma, I'm using OOP! while still being primarily procedural. Then you can gradually learn the terminology ("what's an instance?"), graduate to writing your own classes, and then finally move on to OOP techniques which some languages don't even allow, like metaclasses. > Before I get told off/flamed/shouted at I've just started learning > Python and I think it is a great language with a fantastic standard > library. I've already managed to write meaningful code but I haven't > invented a single class yet. And why do you think this is a problem? Classes are one possible solution to problems that actually matter. What matters is the solution, not the mechanism of the solution. "Writing classes" is just a means to an end (the solution), not the end itself. > There is a book you could try, it's a bit dry and I read it when I can't > sleep, about 30 mins usually does it :-) It's called Design Patterns by > Gamma, Helm, Johnson and Vlissides ISBN 0-201-63361-2. > They do use C++ code in examples but as they say, this is just a > convenience and shouldn't colour your view of the subject I still read > the introduction and get something out of it after several years. You > should be able to implement the patterns in Python although I must admit > I haven't tried that yet Two problems with "Design Patterns" is that many of them are excessively abstract, and that often they only exist to work around limitations in the source language (usually C++ or Java). The first problem means that any half-decent programmer has probably been using "Design Patterns" for years without realising it, or knowing the name. I remember writing an "Object Pool" in procedural Pascal in the 1980s to recycle resources, long before the concept was given a name. Not that I claim to have invented the concept -- I merely copied it from someone else, who described the technique without giving it a name. Not that he invented it either. The emphasis on *names* is just jargon, design patterns are actually just problem-solving techniques. Sometimes it's useful to have jargon that everyone recognises, e.g. "factory function" and "singleton" are two I consistently remember (and I use the first *all the time* and the second *never*), but often Design Pattern proponents become side-tracked into finer and finer differences of greater and greater abstraction, at the expense of clarity. In my not-so-humble opinion, the popularity of Design Patterns has a lot to do with the fact that they are so abstract and jargon-ridden that they have become a badge of membership into an elite. Shorn of their excessive abstractness, they're not very special. People were writing helper functions to assemble complex data long before the Builder pattern was named, and a Facade is just an interface layer. > Learn Python by all means, the interactive mode is particularly fun,just > try and get a good idea of what OO is all about before you start. As far as I am concerned, any language without an interactive interpreter is incomplete. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 5 20:27:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Aug 2012 00:27:43 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 19:12:35 -0400, Roy Smith wrote: >> Good lord. I'd rather read C++ than UML. And I can't read C++. > > UML is under-rated. I certainly don't have any love of the 47 different > flavors of diagram, but the basic idea of having a common graphical > language for describing how objects and classes interact is pretty > useful. Just don't ask me to remember which kind of arrowhead I'm > supposed to use in which situation. I frequently draw diagrams to understand the relationships between my classes and the problem I am trying to solve. I almost invariably use one type of box and one type of arrowhead. Sometimes if I'm bored I draw doodles on the diagram. If only I could remember to be consistent about what doodle I draw where, I too could be an UML guru. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 5 20:42:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Aug 2012 00:42:40 GMT Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: <501f1300$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 18:19:55 -0500, Tim Chase wrote: > On 08/05/12 17:00, John Mordecai Dildy wrote: >> since when did we start talking about lisp? > > Though not a lisper, the Python tie-in was my reply: Python (among many > other languages) doesn't allow a "-" as a character in identifiers as > you appeared to use it in your code. Unlike HTML, XML, CSS, and > apparently lisp and COBOL (thanks, MRAB, for ripping open that scab > after years of trying to repress those COBOL memories :-) where > identifiers may contain the dash. And Forth. Generally speaking, concatenative languages like Forth can use any symbols they wish in identifiers, apart from the token separator (usually whitespace), since they don't have syntax as we know it in more traditional languages. E.g. in Forth : is the word (command) to start defining a new word, but this does not stop you from defining a word called ::: or "foo:bar" (with or without the quotes!). -- Steven From dan at tombstonezero.net Sun Aug 5 20:50:19 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 5 Aug 2012 17:50:19 -0700 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120806005019.GB3731@particle> On 2012-08-06 at 00:27:43 +0000, Steven D'Aprano wrote: > I frequently draw diagrams to understand the relationships between my > classes and the problem I am trying to solve. I almost invariably use one > type of box and one type of arrowhead. Sometimes if I'm bored I draw > doodles on the diagram. If only I could remember to be consistent about > what doodle I draw where, I too could be an UML guru. +1 From breamoreboy at yahoo.co.uk Sun Aug 5 20:52:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Aug 2012 01:52:30 +0100 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: Message-ID: On 06/08/2012 00:46, PeterSo wrote: > I am just starting to learn Python, and I like to use the editor > instead of the interactive shell. So I wrote the following little > program in IDLE > [snip] I can't comment on IDLE as I've never used it, but you're doing yourself a big disservice if you don't use the interactive shell. Trying code snippets at the interactive prompt is one of the big benefits of using Python, ignore it at your peril :) -- Cheers. Mark Lawrence. From python at mrabarnett.plus.com Sun Aug 5 20:58:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Aug 2012 01:58:28 +0100 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: Message-ID: <501F16B4.8020306@mrabarnett.plus.com> On 06/08/2012 01:09, Rotwang wrote: > On 06/08/2012 00:46, PeterSo wrote: >> I am just starting to learn Python, and I like to use the editor >> instead of the interactive shell. So I wrote the following little >> program in IDLE >> >> # calculating the mean >> >> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] >> >> def mean(data): >> return sum(data)/len(data) >> >> mean(data1) >> >> >> There is no syntax highlighting and when I ran it F5, I got the >> following in the shell window. >> >> >> >>> ================================ RESTART >> ================================ >>>>> >>>>> >> >> >> Any ideas? > > I don't know what editor you're using or how it works, but I'm guessing > that pressing f5 runs what you've written as a script, right? In that > case the interpreter doesn't automatically print the result of > expressions in the same way that the interactive interpreter does; you > didn't tell it to print anything, so it didn't. > It looks like it's IDLE. > >> If I added print mean(data1), it gave me a invalid syntax >> Which suggests to me that it's Python 3. >> # calculating the mean >> >> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] >> data2=[1,2,3,4,5] >> >> def mean(data): >> return sum(data)/len(data) >> >> mean(data1) >> print mean(data1) > > If you're using Python 3.x, you'll need to replace > > print mean(data1) > > with > > print(mean(data1)) > > since the print statement has been replaced with the print function in > Python 3. > > If you're instead using Python 2.x then I don't know what the problem > is, but in that case your mean() function won't work properly - the > forward slash operator between a pair of ints gives you floor division > by default, so you should instead have it return something like > float(sum(data))/len(data). > From mrabarnett at mrabarnett.plus.com Sun Aug 5 21:01:47 2012 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Mon, 06 Aug 2012 02:01:47 +0100 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: <501F16B4.8020306@mrabarnett.plus.com> References: <501F16B4.8020306@mrabarnett.plus.com> Message-ID: <501F177B.80707@mrabarnett.plus.com> On 06/08/2012 01:58, MRAB wrote: > On 06/08/2012 01:09, Rotwang wrote: >> On 06/08/2012 00:46, PeterSo wrote: >>> I am just starting to learn Python, and I like to use the editor >>> instead of the interactive shell. So I wrote the following little >>> program in IDLE >>> >>> # calculating the mean >>> >>> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] >>> >>> def mean(data): >>> return sum(data)/len(data) >>> >>> mean(data1) >>> >>> >>> There is no syntax highlighting and when I ran it F5, I got the >>> following in the shell window. >>> >>> >>> >>> ================================ RESTART >>> ================================ >>>>>> >>>>>> >>> >>> >>> Any ideas? >> >> I don't know what editor you're using or how it works, but I'm guessing >> that pressing f5 runs what you've written as a script, right? In that >> case the interpreter doesn't automatically print the result of >> expressions in the same way that the interactive interpreter does; you >> didn't tell it to print anything, so it didn't. >> > It looks like it's IDLE. Actually, he does say that it's IDLE at the start. [snip] From breamoreboy at yahoo.co.uk Sun Aug 5 21:02:47 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Aug 2012 02:02:47 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/08/2012 01:22, Steven D'Aprano wrote: [snipped to death] > > In my not-so-humble opinion, the popularity of Design Patterns has a lot > to do with the fact that they are so abstract and jargon-ridden that they > have become a badge of membership into an elite. Shorn of their excessive > abstractness, they're not very special. People were writing helper > functions to assemble complex data long before the Builder pattern was > named, and a Facade is just an interface layer. > Design patterns being abstract and jargon ridden puts them alongside many other aspects of ICT, CS, call it what you like. Especially beloved by consultants as it means they can talk crap for hours and charge a fortune for it. -- Cheers. Mark Lawrence. From sg552 at hotmail.co.uk Sun Aug 5 21:13:10 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 06 Aug 2012 02:13:10 +0100 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: <501F16B4.8020306@mrabarnett.plus.com> Message-ID: On 06/08/2012 02:01, Matthew Barnett wrote: > On 06/08/2012 01:58, MRAB wrote: >> On 06/08/2012 01:09, Rotwang wrote: >>> On 06/08/2012 00:46, PeterSo wrote: >>>> I am just starting to learn Python, and I like to use the editor >>>> instead of the interactive shell. So I wrote the following little >>>> program in IDLE >>>> >>>> [...] >>>> >>> I don't know what editor you're using or how it works, but I'm guessing >>> that pressing f5 runs what you've written as a script, right? In that >>> case the interpreter doesn't automatically print the result of >>> expressions in the same way that the interactive interpreter does; you >>> didn't tell it to print anything, so it didn't. >>> >> It looks like it's IDLE. > > Actually, he does say that it's IDLE at the start. > [snip] Doh! Not sure how I missed that, sorry. -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From python.list at tim.thechases.com Sun Aug 5 21:27:07 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Aug 2012 20:27:07 -0500 Subject: Intermediate Python user needed help In-Reply-To: References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> <501EE1D4.4080809@mrabarnett.plus.com> Message-ID: <501F1D6B.9080303@tim.thechases.com> On 08/05/12 20:15, Dennis Lee Bieber wrote: > On Sun, 05 Aug 2012 19:32:26 -0400, Roy Smith declaimed >>> Though not a lisper, the Python tie-in was my reply: Python (among >>> many other languages) doesn't allow a "-" as a character in >>> identifiers as you appeared to use it in your code. Unlike HTML, >>> XML, CSS, and apparently lisp and COBOL (thanks, MRAB, for ripping >>> open that scab after years of trying to repress those COBOL memories >>> :-) where identifiers may contain the dash. >> >> Does BNF count as a language? > > It's a meta-language I see what you did there, using a dash in your identifier... -tkc From tjreedy at udel.edu Sun Aug 5 21:32:36 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Aug 2012 21:32:36 -0400 Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: Message-ID: On 8/5/2012 7:46 PM, PeterSo wrote: > I am just starting to learn Python, and I like to use the editor > instead of the interactive shell. So I wrote the following little > program in IDLE > > # calculating the mean > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > def mean(data): > return sum(data)/len(data) > > mean(data1) > > > There is no syntax highlighting If properly installed and working, IDLE does syntax highliting if and only if you name the file with a .py, .pyw, .pyo extension. I have a 'play around' directory with a tem.py file that is always in the recent files lists. I use it for short shippets that are two long to directly type into the shell. -- Terry Jan Reedy From ojlise at gmail.com Sun Aug 5 22:17:54 2012 From: ojlise at gmail.com (PeterSo) Date: Sun, 5 Aug 2012 19:17:54 -0700 (PDT) Subject: Getting started with IDLE and Python - no highlighting and no execution References: Message-ID: <89c5285b-5f3a-4195-9dcb-f24a098cb670@p8g2000yqa.googlegroups.com> On Aug 5, 7:09?pm, Rotwang wrote: > On 06/08/2012 00:46, PeterSo wrote: > > > > > > > > > > > I am just starting to learn Python, and I like to use the editor > > instead of the interactive shell. So I wrote the following little > > program in IDLE > > > # calculating the mean > > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > > def mean(data): > > ? ?return sum(data)/len(data) > > > mean(data1) > > > There is no syntax highlighting and when I ran it F5, I got the > > following in the shell window. > > > ? >>> ================================ RESTART > > ================================ > > > Any ideas? > > I don't know what editor you're using or how it works, but I'm guessing > that pressing f5 runs what you've written as a script, right? In that > case the interpreter doesn't automatically print the result of > expressions in the same way that the interactive interpreter does; you > didn't tell it to print anything, so it didn't. > > > If I added print mean(data1), it gave me a invalid syntax > > > # calculating the mean > > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > data2=[1,2,3,4,5] > > > def mean(data): > > ? ?return sum(data)/len(data) > > > mean(data1) > > print mean(data1) > > If you're using Python 3.x, you'll need to replace > > print mean(data1) > > with > > print(mean(data1)) > > since the print statement has been replaced with the print function in > Python 3. > > If you're instead using Python 2.x then I don't know what the problem > is, but in that case your mean() function won't work properly - the > forward slash operator between a pair of ints gives you floor division > by default, so you should instead have it return something like > float(sum(data))/len(data). > > -- > I have made a thing that superficially resembles music: > > http://soundcloud.com/eroneity/we-berated-our-own-crapiness Your right, it is v 3 so print(mean(data1)) worked. Thanks. I still do not have any highlighting in the IDLE editor. From wuwei23 at gmail.com Sun Aug 5 22:44:31 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Aug 2012 19:44:31 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 6, 10:22?am, Steven D'Aprano wrote: > In my not-so-humble opinion, the popularity of Design Patterns has a lot > to do with the fact that they are so abstract and jargon-ridden that they > have become a badge of membership into an elite. Shorn of their excessive > abstractness, they're not very special. People were writing helper > functions to assemble complex data long before the Builder pattern was > named, and a Facade is just an interface layer. I think you've entirely missed the point of Design Patterns. No one claims that the Go4 DP book introduced Builders, Singletons, Facades. The point was to identify _and name_ such patterns, so programmers could actually talk about repeated behaviour. Design patterns are an attempt to encapsulate and express experience, that's it. There's nothing mystical or special about them at all, and to be honest I never ever such claims come from proponents of them, only their critics. Why is it an "elitist" action to want to be able to share experience and learn from that of others? If anything, I find the problem is with the insular nature of most developers and the preponderance of NIH attitudes. From wuwei23 at gmail.com Sun Aug 5 22:49:38 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Aug 2012 19:49:38 -0700 (PDT) Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> <501EDFB6.3050507@tim.thechases.com> Message-ID: <7da28dee-0767-4da2-b70b-5f85804ce727@sn4g2000pbc.googlegroups.com> On Aug 6, 7:14?am, John Mordecai Dildy wrote: > Im using Textwrangler and thats the only text editor that im using just saying for everyone Why bother using an actual development tool when you can get an entire mailing list to be your syntax checker, right? From steveo at syslang.net Sun Aug 5 22:50:02 2012 From: steveo at syslang.net (Steven W. Orr) Date: Sun, 05 Aug 2012 22:50:02 -0400 Subject: conditional running of code portion In-Reply-To: References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> Message-ID: <501F30DA.1020002@syslang.net> On 8/5/2012 12:43 AM, Ramchandra Apte wrote: > Try pypreprocessor . > Better idea: > You should be using the logging > module if you want to print debug information quickly.It uses threads and is > optimized to run fast. I never saw pypreprocessor. Looks interesting. I have experience with Ned's cog preprocessor. http://nedbatchelder.com/code/cog/ I used this in something that was operating at the packet socket level. I had no time to test if debug was true. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From wuwei23 at gmail.com Sun Aug 5 22:56:57 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Aug 2012 19:56:57 -0700 (PDT) Subject: Calling Values References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Message-ID: On Aug 3, 9:49?pm, Subhabrata wrote: > I am preferring not to use argument passing or using class? Is there any alternate way? If you don't want to program in Python, don't use Python. From wuwei23 at gmail.com Sun Aug 5 23:40:25 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Aug 2012 20:40:25 -0700 (PDT) Subject: On-topic: alternate Python implementations References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 4, 4:15?pm, Steven D'Aprano wrote: > But the Python ecosystem is a lot bigger than just those four. Here are > just a few other implementations that you might be interested in: There's also HotPy: http://code.google.com/p/hotpy/ http://www.hotpy.org/ From steve+comp.lang.python at pearwood.info Mon Aug 6 02:08:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Aug 2012 06:08:38 GMT Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <501f5f65$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 21:14:04 -0400, Dennis Lee Bieber wrote: > While I've probably used singletons (usually as sentinels in queues, I don't know your code, but if I were to take a wild guess, I would say that apart from None, and True/False, you probably haven't. NotImplemented and Ellipsis are two other singletons in Python. It is possible to program a Singleton class in pure Python, but most people don't bother, because 1) singleton is probably the most over-used Design Pattern of them all and 2) it's quite trivial to bypass the singleton-ness of classes written in Python and create a second instance. Or they use a module, which is not really a singleton but behaves like one. Or if they want to show off their Pythonicity, they use the Borg pattern. The common sentinel idiom in Python is to do this: SENTINEL = object() # and later... if value is SENTINEL: pass but of course that's not a singleton because it's only one instance out of a vast number, and anyone can create another instance. Also it misses the point of the Singleton pattern, that the (lone) instance should hold state. The sentinel does not usually hold state. > I suspect), but can't say that I've ever used a "factory function"... If you've ever used an ordinary function decorator, you almost certainly have. If you've every created a closure, you definitely have. -- Steven From news4 at mystrobl.de Mon Aug 6 02:18:12 2012 From: news4 at mystrobl.de (Wolfgang Strobl) Date: Mon, 06 Aug 2012 08:18:12 +0200 Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: Dennis Lee Bieber : > Don't look for Object-Oriented Programming -- since the first widely >popular OOP language was C++ (Smalltalk was earlier, but rather >specialized, whereas C++ started as a preprocessor for C). Well, C++ did to C what Simula 67 did to Algol 60, much earlier. Simula was quite popular at its time. -- Thank you for observing all safety precautions From stefan_ml at behnel.de Mon Aug 6 02:21:19 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Aug 2012 08:21:19 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: alex23, 06.08.2012 05:40: > On Aug 4, 4:15 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> But the Python ecosystem is a lot bigger than just those four. Here are >> just a few other implementations that you might be interested in: > > There's also HotPy: > > http://code.google.com/p/hotpy/ > http://www.hotpy.org/ And just in case anyone was wondering where the others are: http://wiki.python.org/moin/PythonImplementations Stefan From stefan_ml at behnel.de Mon Aug 6 02:46:19 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 06 Aug 2012 08:46:19 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: <20120805122806.GB23550@jaerhard.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120804232510.GA23550@jaerhard.com> <20120805122806.GB23550@jaerhard.com> Message-ID: J?rgen A. Erhard, 05.08.2012 14:28: > On Sun, Aug 05, 2012 at 07:46:59AM +0200, Stefan Behnel wrote: >> J?rgen A. Erhard, 05.08.2012 01:25: >>> None of the other implementations require Python for actually >>> compiling or running Python source. >> >> Nuitka was on the list as well. > > True, which I realized only after my missive. But doesn't change > much, only that the list is wrong. Agreed. > My definition, to also answer your following post, is "does not rely > on any executable part of the CPython source (which includes .c files > and executable code in header files if any, but of course can exclude > the stdlib)". Not sure that's precise enough, but... if it can't > run/work on a system that has no shred of CPython installed, it's not > an alternative *implementation*. I can live with that definition. Cython is (by design) not an independent reimplementation of Python. Stefan From no.email at nospam.invalid Mon Aug 6 03:25:16 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Aug 2012 00:25:16 -0700 Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <501f5f65$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x1ujka3dv.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> I suspect), but can't say that I've ever used a "factory function"... > If you've ever used an ordinary function decorator, you almost certainly > have. > If you've every created a closure, you definitely have. Or anything with a __iter__ method... From lipskathekat at yahoo.co.uk Mon Aug 6 03:43:08 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 08:43:08 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/08/12 23:51, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 18:45:47 -0400, Dennis Lee Bieber wrote: > >> Don't look for Object-Oriented Programming -- since the first widely >> popular OOP language was C++ (Smalltalk was earlier, but rather >> specialized, whereas C++ started as a preprocessor for C). >> Rather look for Object-Oriented Analysis and Design (OOAD). An OOAD >> textbook /should/ be language neutral and, these days, likely using the >> constructs/notation of UML [which derived from a merger of two or three >> separate proposals for OOAD tools] > > Good lord. I'd rather read C++ than UML. And I can't read C++. This reminds me of a consultant I once worked with. He had worked on government projects for a decade or more and was a staunch supporter of the 'big bang' approach to software development. I asked him how many of these had been a success ... deafening silence. His attitude to UML was 'I'd rather cut my right arm off than waste time with that new fangled nonsense' UML works, non technical 'stakeholders' (yuk) can understand it at a high level and in my HUMBLE opinion the sequence diagram is the single most important piece of documentation in the entire software project jeez lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From lipskathekat at yahoo.co.uk Mon Aug 6 03:48:02 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 08:48:02 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7LWdncgebNUu64LNnZ2dnUVZ8vydnZ2d@bt.com> On 06/08/12 01:27, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 19:12:35 -0400, Roy Smith wrote: > >>> Good lord. I'd rather read C++ than UML. And I can't read C++. >> >> UML is under-rated. I certainly don't have any love of the 47 different >> flavors of diagram, but the basic idea of having a common graphical >> language for describing how objects and classes interact is pretty >> useful. Just don't ask me to remember which kind of arrowhead I'm >> supposed to use in which situation. > > > I frequently draw diagrams to understand the relationships between my > classes and the problem I am trying to solve. I almost invariably use one > type of box and one type of arrowhead. Sometimes if I'm bored I draw > doodles on the diagram. If only I could remember to be consistent about > what doodle I draw where, I too could be an UML guru. > Yea, it can be tricky. But if you persevere you will gain enlightenment. It does take a bit of application though. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From lipskathekat at yahoo.co.uk Mon Aug 6 04:55:24 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 09:55:24 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/08/12 01:22, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: > >> >> Object Oriented programming is a mindset, a way of looking at that >> particular part of our world that you are trying to encapsulate in >> computer language. The language you use is (should be) irrelevant. > > That depends on how you define OOP, and in particular, which aspects of > OOP your language supports. The clue is in the name 'Object Oriented' ... anything else is (or should be) implementation detail. [large snip] > > In particularly, terminology varies -- I personally despise with the heat > of a thousand suns the terms "instance variable" and "class variable" for > attributes or members. This is an implementation detail and describes the difference between certain types of attributes. A class variable is static and can be accessed without instantiation an instance variable is accessed via an instance ... again the clue is in the name. > Since a "string variable" is a variable holding a > string, and a "float variable" is a variable holding a float, an instance > variable should be a variable holding an instance, and a class variable > should be a variable holding a class. Class variable and instance variable are higher level abstractions. >> The ONLY concept that you should never try to encapsulate is/are human >> beings or their aliases. snip > Is this some sort of mystical "humans aren't objects, they're SPECIAL!!!" > rubbish? Because it sure sounds like it. > > Can you give some non-religious reasons why you should not implement > human beings or aliases as objects? You have answered your own question.... I would be glad to debate my assertion at length with you however the 'moderators' are listening. > If not, let me just say that I reject your prohibition and leave it at > that. > > >> Actually it should really be called Class Oriented programming as >> classes are the units of encapsulation. > > Incorrect. You don't even need classes to have objects. You can have > class-based OOP, and prototype-based OOP, as in Javascript, Actionscript, > Io, and the language which invented the term, Self. > > http://en.wikipedia.org/wiki/Prototype-based_programming Interesting article, I withdraw my 'classed based' assertion however the concept of a unit of encapsulation still exists. Where unit of encapsulation is different from a unit of function or method. >> I really don't think python is a >> good language to learn OO programming, the problem is that Python >> doesn't enforce OO so you are never going to learn what is 'OO' and what >> isn't. > > I think that's exactly why Python *is* a good language to learn OOP, > because you can be productive even while learning. You can start off by > just adding a little bit of OOP syntax to your programs: Well I'm afraid I can't agree with this. OO is a state if mind (again) you can't successfully be a 'little bit OO' IMHO > response = raw_input("What do you want to do? ") > response = response.lower() # Look ma, I'm using OOP! Infantile but funny snip >> I've already managed to write meaningful code but I haven't >> invented a single class yet. > > And why do you think this is a problem? A problem? I wasn't aware that I'd stated it was a problem it just underlines my belief that Python, however useful it is, is not the ideal language to learn about Object Oriented software development. > Classes are one possible solution to problems that actually matter. What > matters is the solution, not the mechanism of the solution. "Writing > classes" is just a means to an end (the solution), not the end itself. I couldn't agree more, the point is that they are a good solution. I learned very early on that there is more than one way to skin a cat. I have never said that Python is a bad language, I LIKE Python. I certainly prefer it to Java for on the fly development and it sure is more fun at times. >> There is a book you could try, it's a bit dry and I read it when I can't >> sleep, about 30 mins usually does it :-) It's called Design Patterns snippety snip > > In my not-so-humble opinion, the popularity of Design Patterns has a lot > to do with the fact that they are so abstract and jargon-ridden that they > have become a badge of membership into an elite. Hmm, I feel a rant coming on about elitism ... snip and a Facade is just an interface layer. Well as you seem to be so concerned with terminology I'd have to disagree with you here. An interface (in computing) has any number of meanings, hardware interfaces, software interfaces the HCI etc etc. In some languages an interface is a non functional unit of compilation that describes the methods an implementing class must provide. A facade on the other hand aggregates a number of fine grained operations that often implement the business logic of an application into coarser grained methods that can be called further up the implementation stack. More importantly, what goes on behind a facade can be completely changed without affecting anything that uses the facade thereby enhancing maintainability. (I'm trying really hard not to use buzzwords here). I could go on but there seems little point. >> Learn Python by all means, the interactive mode is particularly fun,just >> try and get a good idea of what OO is all about before you start. > > As far as I am concerned, any language without an interactive interpreter > is incomplete. Well possibly. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From djc at news.invalid Mon Aug 6 05:20:51 2012 From: djc at news.invalid (DJC) Date: Mon, 06 Aug 2012 11:20:51 +0200 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> <501f0f7e$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/08/12 02:27, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 19:12:35 -0400, Roy Smith wrote: > >>> Good lord. I'd rather read C++ than UML. And I can't read C++. >> >> UML is under-rated. I certainly don't have any love of the 47 different >> flavors of diagram, but the basic idea of having a common graphical >> language for describing how objects and classes interact is pretty >> useful. Just don't ask me to remember which kind of arrowhead I'm >> supposed to use in which situation. > > > I frequently draw diagrams to understand the relationships between my > classes and the problem I am trying to solve. I almost invariably use one > type of box and one type of arrowhead. Sometimes if I'm bored I draw > doodles on the diagram. If only I could remember to be consistent about > what doodle I draw where, I too could be an UML guru. > > Flow Charts redux From lipskathekat at yahoo.co.uk Mon Aug 6 05:24:10 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 10:24:10 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/08/12 09:55, lipska the kat wrote: > On 06/08/12 01:22, Steven D'Aprano wrote: >> On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: >> >>> snip > Well as you seem to be so concerned with terminology I'd have to > disagree with you here. An interface (in computing) has any number of > meanings, hardware interfaces, software interfaces the HCI etc etc. In > some languages an interface is a non functional unit of compilation that > describes the methods an implementing class must provide. A facade on > the other hand aggregates a number of fine grained operations that often > implement the business logic of an application into coarser grained > methods that can be called further up the implementation stack. > More importantly, what goes on behind a facade can be completely changed > without affecting anything that uses the facade thereby enhancing > maintainability. (I'm trying really hard not to use buzzwords here). er, the point I was trying to make is that when you say 'interface' it could mean so many things. If you say 'facade' everyone knows exactly what you are talking about. And that is EXACTLY the point. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From bobjohnbowles at gmail.com Mon Aug 6 06:13:46 2012 From: bobjohnbowles at gmail.com (Bob Bowles) Date: Mon, 6 Aug 2012 03:13:46 -0700 (PDT) Subject: distutils bdist_wininst failure on Linux In-Reply-To: <4f46de87$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4f4647dd$0$29986$c3e8da3$5496439d@news.astraweb.com> <4f46d59f$0$29986$c3e8da3$5496439d@news.astraweb.com> <4f46de87$0$29986$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1344248026005-4984209.post@n6.nabble.com> Steven D'Aprano-11 wrote > > And I have a work-around that seems to work for me. Put this at the top > of your setup.py install script: > > > > # Work around mbcs bug in distutils. > # http://bugs.python.org/issue10945 > import codecs > try: > codecs.lookup('mbcs') > except LookupError: > ascii = codecs.lookup('ascii') > func = lambda name, enc=ascii: {True: enc}.get(name=='mbcs') > codecs.register(func) > > Nice one, worked first time! Thanks! -- View this message in context: http://python.6.n6.nabble.com/distutils-bdist-wininst-failure-on-Linux-tp4498729p4984209.html Sent from the Python - python-list mailing list archive at Nabble.com. From rustompmody at gmail.com Mon Aug 6 08:19:14 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 05:19:14 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On Aug 6, 12:46?am, lipska the kat wrote: > On 04/08/12 16:49, Jean Dubois wrote: > > > I'm looking for a good introduction to object oriented programming > > with Python. > > Object Oriented programming is a mindset, a way of looking at that > particular part of our world that you are trying to encapsulate > in computer language. The language you use is (should be) irrelevant. > > Actually it should really be called Class Oriented programming as > classes are the units of encapsulation. > I really don't think python is a good language to learn OO programming, > the problem is that Python doesn't enforce OO so you are never going to > learn what is 'OO' and what isn't. > > Learn Python by all means, the interactive mode is particularly fun,just > try and get a good idea of what OO is all about before you start. I suggest this http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html Particularly useful if you are a bit drunk on snake-oil From maniandram01 at gmail.com Mon Aug 6 08:48:03 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 6 Aug 2012 18:18:03 +0530 Subject: conditional running of code portion In-Reply-To: <501F30DA.1020002@syslang.net> References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> <501F30DA.1020002@syslang.net> Message-ID: I just googled the OP's question and found a StackOverflow question. That question's solution mentions pypreprocessor. On 6 August 2012 08:20, Steven W. Orr wrote: > On 8/5/2012 12:43 AM, Ramchandra Apte wrote: > >> Try pypreprocessor > >> . >> Better idea: >> You should be using the logging > library/logging.html > >> >> module if you want to print debug information quickly.It uses threads and >> is >> optimized to run fast. >> > > I never saw pypreprocessor. Looks interesting. I have experience with > Ned's cog preprocessor. > > http://nedbatchelder.com/code/**cog/ > > I used this in something that was operating at the packet socket level. I > had no time to test if debug was true. > > > > -- > Time flies like the wind. Fruit flies like a banana. Stranger things have > .0. > happened but none stranger than this. Does your driver's license say Organ > ..0 > Donor?Black holes are where God divided by zero. Listen to me! We are all- > 000 > individuals! What if this weren't a hypothetical question? > steveo at syslang.net > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Aug 6 09:16:56 2012 From: roy at panix.com (Roy Smith) Date: Mon, 06 Aug 2012 09:16:56 -0400 Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <501ef904$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , lipska the kat wrote: > UML works, non technical 'stakeholders' (yuk) can understand it at a > high level and in my HUMBLE opinion the sequence diagram is the single > most important piece of documentation in the entire software project Yup. Sequence diagrams are the most common one I draw. I'm sure I use the wrong kinds of arrowheads and such, but the general idea is pretty powerful. I find they can be useful for figuring out some horrible piece of code you've never worked with before. Just sit down and start reading the code, drawing the diagram as you go. Sometimes things start to make sense that way when just staring at the code isn't doing it for you. My most successful experiment with UML was when trying to understand some big hunk of C++ somebody had thrown at me. I imported the whole thing into some UML tool, which not only found all the classes, but also sorted out how they were related. Pushing boxes around in the GUI tool turned out to be a useful way to get my head around how the code worked. The problem with UML is that, like so many good ideas, it has developed a mystique around it. With layers of gurus who know progressively more and more about the esoteric details. And who make a living writing books and giving seminars about it. Kind of like patterns, and agile, and scrum, and XP, and so on. From hyperboogie at gmail.com Mon Aug 6 09:32:13 2012 From: hyperboogie at gmail.com (S.B) Date: Mon, 6 Aug 2012 06:32:13 -0700 (PDT) Subject: Pickle file and send via socket Message-ID: Hello friends Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: First host pickles a file object and writes the pickled file object to a client socket. Second host reads the pickled file object from the server socket and un-pickles it. Can anyone provide a simple code example of the client and server sides? Thanks From maniandram01 at gmail.com Mon Aug 6 09:47:47 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 6 Aug 2012 19:17:47 +0530 Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: This is *absolutely* possible. Did you know that IDLE uses this very method when run in sub-process mode! On 6 August 2012 19:02, S.B wrote: > Hello friends > > Does anyone know if it's possible to pickle and un-pickle a file across a > network socket. i.e: > First host pickles a file object and writes the pickled file object to a > client socket. > Second host reads the pickled file object from the server socket and > un-pickles it. > > Can anyone provide a simple code example of the client and server sides? > > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Mon Aug 6 09:49:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 6 Aug 2012 19:19:29 +0530 Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: You can use pickle.dumps and pickle.loads On 6 August 2012 19:17, Ramchandra Apte wrote: > This is *absolutely* possible. > Did you know that IDLE uses this very method when run in sub-process mode! > > > On 6 August 2012 19:02, S.B wrote: > >> Hello friends >> >> Does anyone know if it's possible to pickle and un-pickle a file across a >> network socket. i.e: >> First host pickles a file object and writes the pickled file object to a >> client socket. >> Second host reads the pickled file object from the server socket and >> un-pickles it. >> >> Can anyone provide a simple code example of the client and server sides? >> >> Thanks >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mablanga2010 at gmail.com Mon Aug 6 09:55:44 2012 From: mablanga2010 at gmail.com (Mario Blanco) Date: Mon, 6 Aug 2012 06:55:44 -0700 Subject: cant upload the python window popup Message-ID: I delete by error the python window inteface and now i cant reupload again some advice is apreciated thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From lipskathekat at yahoo.co.uk Mon Aug 6 10:27:22 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 15:27:22 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On 06/08/12 13:19, rusi wrote: > On Aug 6, 12:46 am, lipska the kat wrote: >> On 04/08/12 16:49, Jean Dubois wrote: >> >>> I'm looking for a good introduction to object oriented programming >>> with Python. >> > >> Object Oriented programming is a mindset, a way of looking at that >> particular part of our world that you are trying to encapsulate >> in computer language. The language you use is (should be) irrelevant. snip >> Learn Python by all means, the interactive mode is particularly fun,just >> try and get a good idea of what OO is all about before you start. > > I suggest this > http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html > > Particularly useful if you are a bit drunk on snake-oil You take out the garbage. I've got automatic garbage collection lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jeandubois314 at gmail.com Mon Aug 6 10:56:35 2012 From: jeandubois314 at gmail.com (Jean Dubois) Date: Mon, 6 Aug 2012 07:56:35 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> Message-ID: <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> On 5 aug, 20:28, Mark Lawrence wrote: > On 05/08/2012 19:04, Jean Dubois wrote: > > > > > > > > > > > On 5 aug, 02:11, shearich... at gmail.com wrote: > >> One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ... > > >> Could do worse than this : > > >>http://www.diveintopython.net/object_oriented_framework/index.html > > > This example seems to tell you need the concept of dictionaries to > > explain object oriented programming, is this really necessary? > >> and this > > >>http://docs.python.org/tutorial/classes.html > > Unfortunately, the trouble with this explanation is exactly what made > > me ask the original question: it starts from concepts in c++ making it > > very hard to understand for someone who does not know that language > > already. > > >> read together. > > >> Judging by your question this is a probably a little advanced for now but you could bookmark it for the future: > > >>http://www.catonmat.net/blog/learning-python-design-patterns-through-... > > >> Here's the corresponding PDF to go with the video: > > >>http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns... > > Can someone here on this list give a trivial example of what object > > oriented programming is, using only Python? > > > thanks in advance > > Jean > > Try thishttp://www.voidspace.org.uk/python/articles/OOP.shtml??? > > -- > Cheers. > > Mark Lawrence. Thanks, this one is a lot better. Could you just tell me what the use is of the following lines: """Class docstring.""" """Method docstring.""" """Method docstring.""" Taken from the following code fragment (I really want to understand every bit of code, and the author doesn't mention this) class OurClass(object): """Class docstring.""" def __init__(self, arg1, arg2): """Method docstring.""" self.arg1 = arg1 self.arg2 = arg2 def printargs(self): """Method docstring.""" print self.arg1 print self.arg2 thanks in advance jean From maniandram01 at gmail.com Mon Aug 6 11:38:30 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 6 Aug 2012 21:08:30 +0530 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> Message-ID: Its a docstring - it documents the function/class Did you know that docstrings can be used for testing - look at the doctest standard library module! try: class A: def method(self): '''Sample method This method does the difficult task X. Call this method with no arguments.'''#docstring pass then type : help(A.method) And viola! On 6 August 2012 20:26, Jean Dubois wrote: > On 5 aug, 20:28, Mark Lawrence wrote: > > On 05/08/2012 19:04, Jean Dubois wrote: > > > > > > > > > > > > > > > > > > > > > On 5 aug, 02:11, shearich... at gmail.com wrote: > > >> One reason you may be having difficulty is that unlike some languages > (C++/Java) object-orientation is not a be all and end all in Python, in > fact you could work with Python for a long time without really 'doing it' > at all (well other than calling methods/properties on existing API's). > Having said that here's what I would suggest ... > > > > >> Could do worse than this : > > > > >>http://www.diveintopython.net/object_oriented_framework/index.html > > > > > This example seems to tell you need the concept of dictionaries to > > > explain object oriented programming, is this really necessary? > > >> and this > > > > >>http://docs.python.org/tutorial/classes.html > > > Unfortunately, the trouble with this explanation is exactly what made > > > me ask the original question: it starts from concepts in c++ making it > > > very hard to understand for someone who does not know that language > > > already. > > > > >> read together. > > > > >> Judging by your question this is a probably a little advanced for now > but you could bookmark it for the future: > > > > >>http://www.catonmat.net/blog/learning-python-design-patterns-through-. > .. > > > > >> Here's the corresponding PDF to go with the video: > > > > >>http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns. > .. > > > Can someone here on this list give a trivial example of what object > > > oriented programming is, using only Python? > > > > > thanks in advance > > > Jean > > > > Try thishttp://www.voidspace.org.uk/python/articles/OOP.shtml??? > > > > -- > > Cheers. > > > > Mark Lawrence. > Thanks, this one is a lot better. Could you just tell me what the use > is of the following lines: > """Class docstring.""" > """Method docstring.""" > """Method docstring.""" > Taken from the following code fragment (I really want to understand > every bit of code, and the author doesn't mention this) > > > class OurClass(object): > """Class docstring.""" > > def __init__(self, arg1, arg2): > """Method docstring.""" > self.arg1 = arg1 > self.arg2 = arg2 > > def printargs(self): > """Method docstring.""" > print self.arg1 > print self.arg2 > > > > thanks in advance > jean > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Mon Aug 6 11:39:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 6 Aug 2012 21:09:17 +0530 Subject: cant upload the python window popup In-Reply-To: References: Message-ID: Please explain the problem like this: 1. What you expected 2. What happened 3. Other info. On 6 August 2012 19:25, Mario Blanco wrote: > I delete by error the python window inteface and now i cant reupload again > some advice is apreciated > thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Aug 6 11:40:53 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Aug 2012 08:40:53 -0700 Subject: dbf.py API question In-Reply-To: References: <501AA304.3090000@stoneleaf.us> <501E7EA2.1060408@stoneleaf.us> Message-ID: <501FE585.1050107@stoneleaf.us> [redirecting back to list] Ole Martin Bj?rndalen wrote: > On Sun, Aug 5, 2012 at 4:09 PM, Ethan Furman wrote: >> Ole Martin Bj?rndalen wrote: >> You can do this by implementing either __getitem__ or __iter__, unless the >> streaming flag would also make your table not in memory. > > Cool! > > Wow! I realize now that this could in fact be fairly easy to > implement. I just have to shuffle around the code a bit to make both > possible. The API would be: > > # Returns table object which is a subclass of list > table = dbfget.read('cables.dbf') > for rec in table: > print rec > > # Return a table object which behaves like an iterator > table = dbfget.read('cables.dbf', iter=True) > for rec in table: > print rec > > I have a lot of questions in my mind about how to get this to work, > but I feel like it's the right thing to do. I will make an attempt at > a rewrite and get back to you all later. > > One more API question: I am uncomfortable with: > > > dbfget.read() > > Should it just be: > > dbfget.get() > > ? > > - Ole `dbfget` is the package name, and `read()` or `get` is the class/function that loads the table into memory and returns it? Maybe `load()`? ~Ethan~ From werotizy at freent.dd Mon Aug 6 11:52:31 2012 From: werotizy at freent.dd (Tom P) Date: Mon, 06 Aug 2012 17:52:31 +0200 Subject: looking for a neat solution to a nested loop problem Message-ID: consider a nested loop algorithm - for i in range(100): for j in range(100): do_something(i,j) Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some other values i = N and j = M, and I want to iterate through all 10,000 values in sequence - is there a neat python-like way to this? I realize I can do things like use a variable for k in range(10000): and then derive values for i and j from k, but I'm wondering if there's something less clunky. From oscar.benjamin at bristol.ac.uk Mon Aug 6 12:00:29 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Mon, 6 Aug 2012 17:00:29 +0100 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: Are you familiar with the itertools module? itertools.product is designed for this purpose: http://docs.python.org/library/itertools#itertools.product Oscar. On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all 10,000 > values in sequence - is there a neat python-like way to this? I realize I > can do things like use a variable for k in range(10000): and then derive > values for i and j from k, but I'm wondering if there's something less > clunky. > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Mon Aug 6 12:02:13 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 6 Aug 2012 17:02:13 +0100 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all 10,000 > values in sequence - is there a neat python-like way to this? I realize I > can do things like use a variable for k in range(10000): and then derive > values for i and j from k, but I'm wondering if there's something less > clunky. > -- > http://mail.python.org/**mailman/listinfo/python-list > Are you familiar with the itertools module? itertools.product is designed for this purpose: http://docs.python.org/library/itertools#itertools.product -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Aug 6 12:03:50 2012 From: gordon at panix.com (John Gordon) Date: Mon, 6 Aug 2012 16:03:50 +0000 (UTC) Subject: looking for a neat solution to a nested loop problem References: Message-ID: In Tom P writes: > consider a nested loop algorithm - > for i in range(100): > for j in range(100): > do_something(i,j) > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 values in sequence - is there a neat python-like way to this? I > realize I can do things like use a variable for k in range(10000): and > then derive values for i and j from k, but I'm wondering if there's > something less clunky. You could define your own generator function that yields values in whatever order you want: def my_generator(): yield 9 yield 100 for i in range(200, 250): yield i yield 5 -- 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 Mon Aug 6 12:05:50 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Aug 2012 09:05:50 -0700 Subject: Intermediate Python user needed help In-Reply-To: References: Message-ID: <501FEB5E.6050506@stoneleaf.us> John Mordecai Dildy wrote: > I am currently using python 2.6 and am not going to install the newer versions of python and i am looking for people that are still using ver 2.6 in python to help with with the code line: > > sentence = "All good things come to those who wait." > > then im getting this error message when i dont see the problem with it: > > File "ex26.py", line 77 > sentence = "All good things come to those who wait." > ^ > SyntaxError: invalid syntax John Mordecai Dildy wrote: > Current Problem at the moment > > Traceback (most recent call last): > File "ex26.py", line 66, in > beans, jars, crates = secret_formula(start-point) > NameError: name 'start' is not defined > > anyone know how to make start defined In your subject line you state that you are an intermediate Python user. These are not the errors an intermediate user would make, nor the questions an intermediate user would ask. These are the errors that somebody who doesn't know Python would make. Please do not misrepresent yourself. ~Ethan~ P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced -> Master Are there scales out there that would put these types of questions in the "intermediate" category? From mal at egenix.com Mon Aug 6 12:06:52 2012 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 06 Aug 2012 18:06:52 +0200 Subject: Script to easily install eGenix PyRun in a target directory Message-ID: <501FEB9C.1010600@egenix.com> Hello, in case you haven't heard of eGenix PyRun yet, this is a new simple to install Python runtime that can be used independently of a system installed Python version and is very small compared to a regular Python installation. See http://www.egenix.com/products/python/PyRun/ for details. We're using this runtime in our mxODBC Connect Server product and also internally as virtualenv replacement. At EuroPython we've release it as open source product. To make it easy to install eGenix PyRun, we've now added a script to our download server which lets you install PyRun just as easy as virtualenv (but without its dependency on a possible system installation of Python): https://downloads.egenix.com/python/install-pyrun Per default, the script will download the PyRun binary for the target platform and install distribute as well as pip in the given target directory. Usage is simple: install-pyrun targetdir Try install-pyrun --help for a list of options. Running the script will leave you with a targetdir setup with bin/, lib/ and include/ dir as runtime environment. You can then immediately start using PyRun via bin/pyrun or install additional software using bin/pip. The installation script is brand new and we'd appreciate any feedback you can provide to enhance it. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 06 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-08-25: FrOSCon, St. Augustin, Germany ... 19 days to go ::: 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 ian at feete.org Mon Aug 6 12:07:19 2012 From: ian at feete.org (Ian Foote) Date: Mon, 06 Aug 2012 17:07:19 +0100 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: <501FEBB7.6080509@feete.org> The function range can be called with more than one argument. For example: for i in range(N, N + 10): for j in range(M, M + 100): do_something(i, j) You can also call range with 3 arguments, if want a step size different to 1: for k in range(2, 11, 3): print(k) 2 5 8 Hope this is clear, Ian On 06/08/12 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, > but some other values i = N and j = M, and I want to iterate through > all 10,000 values in sequence - is there a neat python-like way to > this? I realize I can do things like use a variable for k in > range(10000): and then derive values for i and j from k, but I'm > wondering if there's something less clunky. From nobody at nowhere.com Mon Aug 6 12:11:56 2012 From: nobody at nowhere.com (Nobody) Date: Mon, 06 Aug 2012 17:11:56 +0100 Subject: Pickle file and send via socket References: Message-ID: On Mon, 06 Aug 2012 06:32:13 -0700, S.B wrote: > Does anyone know if it's possible to pickle and un-pickle a file across > a network socket. i.e: First host pickles a file object and writes the > pickled file object to a client socket. Second host reads the pickled > file object from the server socket and un-pickles it. Yes, provided that the socket is a stream socket (e.g. TCP, Unix), not a datagram socket (e.g. UDP). > Can anyone provide a simple code example of the client and server sides? Pickling via a socket is no different to pickling via a file. For a socket, the .makefile() method will return a suitable file object. From alec.taylor6 at gmail.com Mon Aug 6 12:13:54 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 7 Aug 2012 02:13:54 +1000 Subject: Intermediate Python user needed help In-Reply-To: <501FEB5E.6050506@stoneleaf.us> References: <501FEB5E.6050506@stoneleaf.us> Message-ID: On Tue, Aug 7, 2012 at 2:05 AM, Ethan Furman wrote: > John Mordecai Dildy wrote: >> >> I am currently using python 2.6 and am not going to install the newer >> versions of python and i am looking for people that are still using ver 2.6 >> in python to help with with the code line: >> >> sentence = "All good things come to those who wait." >> >> then im getting this error message when i dont see the problem with it: >> >> File "ex26.py", line 77 >> sentence = "All good things come to those who wait." >> ^ >> SyntaxError: invalid syntax > > > John Mordecai Dildy wrote: >> Current Problem at the moment >> >> Traceback (most recent call last): >> File "ex26.py", line 66, in >> beans, jars, crates = secret_formula(start-point) >> NameError: name 'start' is not defined >> >> anyone know how to make start defined > > In your subject line you state that you are an intermediate Python user. > These are not the errors an intermediate user would make, nor the questions > an intermediate user would ask. These are the errors that somebody who > doesn't know Python would make. > > Please do not misrepresent yourself. +1 > > ~Ethan~ > > P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced -> > Master What, no n00b before Novice? :P > > Are there scales out there that would put these types of questions in the > "intermediate" category? > -- > http://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Mon Aug 6 12:15:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Aug 2012 09:15:58 -0700 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: <501FEDBE.8010908@stoneleaf.us> Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 values in sequence - is there a neat python-like way to this? I > realize I can do things like use a variable for k in range(10000): and > then derive values for i and j from k, but I'm wondering if there's > something less clunky. for i in range(N, N+100): for j in range(M, M+100): do_something(i, j) ~Ethan~ From breamoreboy at yahoo.co.uk Mon Aug 6 12:17:33 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Aug 2012 17:17:33 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> Message-ID: Please see my comment at the bottom hint hint :) On 06/08/2012 16:38, Ramchandra Apte wrote: > Its a docstring - it documents the function/class > Did you know that docstrings can be used for testing - look at the doctest > standard library module! > try: > > class A: > def method(self): > '''Sample method > This method does the difficult task X. > Call this method with no arguments.'''#docstring > pass > > then type : > > help(A.method) > > And viola! > On 6 August 2012 20:26, Jean Dubois wrote: > >> On 5 aug, 20:28, Mark Lawrence wrote: >>> On 05/08/2012 19:04, Jean Dubois wrote: >>> >>> >>> >>> >>> >>> >>> >>> >>> >>>> On 5 aug, 02:11, shearich... at gmail.com wrote: >>>>> One reason you may be having difficulty is that unlike some languages >> (C++/Java) object-orientation is not a be all and end all in Python, in >> fact you could work with Python for a long time without really 'doing it' >> at all (well other than calling methods/properties on existing API's). >> Having said that here's what I would suggest ... >>> >>>>> Could do worse than this : >>> >>>>> http://www.diveintopython.net/object_oriented_framework/index.html >>> >>>> This example seems to tell you need the concept of dictionaries to >>>> explain object oriented programming, is this really necessary? >>>>> and this >>> >>>>> http://docs.python.org/tutorial/classes.html >>>> Unfortunately, the trouble with this explanation is exactly what made >>>> me ask the original question: it starts from concepts in c++ making it >>>> very hard to understand for someone who does not know that language >>>> already. >>> >>>>> read together. >>> >>>>> Judging by your question this is a probably a little advanced for now >> but you could bookmark it for the future: >>> >>>>> http://www.catonmat.net/blog/learning-python-design-patterns-through-. >> .. >>> >>>>> Here's the corresponding PDF to go with the video: >>> >>>>> http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns. >> .. >>>> Can someone here on this list give a trivial example of what object >>>> oriented programming is, using only Python? >>> >>>> thanks in advance >>>> Jean >>> >>> Try thishttp://www.voidspace.org.uk/python/articles/OOP.shtml??? >>> >>> -- >>> Cheers. >>> >>> Mark Lawrence. >> Thanks, this one is a lot better. Could you just tell me what the use >> is of the following lines: >> """Class docstring.""" >> """Method docstring.""" >> """Method docstring.""" >> Taken from the following code fragment (I really want to understand >> every bit of code, and the author doesn't mention this) >> >> >> class OurClass(object): >> """Class docstring.""" >> >> def __init__(self, arg1, arg2): >> """Method docstring.""" >> self.arg1 = arg1 >> self.arg2 = arg2 >> >> def printargs(self): >> """Method docstring.""" >> print self.arg1 >> print self.arg2 >> >> >> >> thanks in advance >> jean >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > Ramchandra Apte will you please stop top posting. In your native language you may well but from bottom to top, but this news group prefers reading top to bottom :) Thanks. -- Cheers. Mark Lawrence. From nobody at nowhere.com Mon Aug 6 12:18:09 2012 From: nobody at nowhere.com (Nobody) Date: Mon, 06 Aug 2012 17:18:09 +0100 Subject: looking for a neat solution to a nested loop problem References: Message-ID: On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 values in sequence - is there a neat python-like way to this? for i in range(N,N+100): for j in range(M,M+100): do_something(i,j) Or did you mean something else? Alternatively: import itertools for i, j in itertools.product(range(N,N+100),range(M,M+100)): do_something(i,j) This can be preferable to deeply-nested loops. Also: in 2.x, use xrange() in preference to range(). From lipskathekat at yahoo.co.uk Mon Aug 6 12:23:19 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 06 Aug 2012 17:23:19 +0100 Subject: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python) In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On 06/08/12 13:19, rusi wrote: > On Aug 6, 12:46 am, lipska the kat wrote: >> On 04/08/12 16:49, Jean Dubois wrote: >> >>> I'm looking for a good introduction to object oriented programming >>> with Python. >> snip > > I suggest this > http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html http://bpfurtado.livejournal.com/2006/10/21/ lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From rustompmody at gmail.com Mon Aug 6 12:34:57 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 09:34:57 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On Aug 6, 7:27?pm, lipska the kat wrote: > You take out the garbage. > I've got automatic garbage collection :-) BTW in "automatic garbage collection" which of the three words is most important? Least? Heres another take on nouns (and therefore OO): http://hilgart.org/enformy/dma-verb.htm From lists at cheimes.de Mon Aug 6 12:45:58 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 06 Aug 2012 18:45:58 +0200 Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: Am 06.08.2012 15:32, schrieb S.B: > Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: > First host pickles a file object and writes the pickled file object to a client socket. > Second host reads the pickled file object from the server socket and un-pickles it. Have you read the warning in the first paragraph of the pickle docs? Pickles are a major security risk unless both hosts are trustworthy and are either inside a protected network or are connected over a secure line. http://docs.python.org/library/pickle.html#module-pickle Warning The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source. Christian Heimes From dieter at handshake.de Mon Aug 6 13:02:24 2012 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 06 Aug 2012 19:02:24 +0200 Subject: conditional running of code portion References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> <501e1319$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hasg0x9b.fsf@handshake.de> Serhiy Storchaka writes: > On 05.08.12 09:30, Steven D'Aprano wrote: >> If you are working in a tight loop, you can do this: >> >> if VERBOSE_FLAG: >> for item in loop: >> print(DEBUG_INFORMATION) >> do_actual_work(item) >> else: >> for item in loop: >> do_actual_work(item) > > Or this: > > if VERBOSE_FLAG: > def do_work(item): > print(DEBUG_INFORMATION) > do_actual_work(item) > else: > do_work = do_actual_work > > for item in loop: > do_work(item) Be warned: a function call is *much* more expensive than an "if variable:". From jeanmichel at sequans.com Mon Aug 6 13:05:17 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 06 Aug 2012 19:05:17 +0200 Subject: Intermediate Python user needed help In-Reply-To: <501FEB5E.6050506@stoneleaf.us> References: <501FEB5E.6050506@stoneleaf.us> Message-ID: <501FF94D.4000001@sequans.com> Ethan Furman wrote: > > ~Ethan~ > > P.S. The scale I am accustomed to is Novice -> Intermediate -> > Advanced -> Master > > Are there scales out there that would put these types of questions in > the "intermediate" category? Troll -> Novice -> Intermediate -> Advanced Trolls are quite specific, they're able to spread over all upper levels, in disguise. :o) JM From werotizy at freent.dd Mon Aug 6 13:14:57 2012 From: werotizy at freent.dd (Tom P) Date: Mon, 06 Aug 2012 19:14:57 +0200 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 08/06/2012 06:18 PM, Nobody wrote: > On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: > >> consider a nested loop algorithm - >> >> for i in range(100): >> for j in range(100): >> do_something(i,j) >> >> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >> some other values i = N and j = M, and I want to iterate through all >> 10,000 values in sequence - is there a neat python-like way to this? > > for i in range(N,N+100): > for j in range(M,M+100): > do_something(i,j) > > Or did you mean something else? no, I meant something else .. j runs through range(M, 100) and then range(0,M), and i runs through range(N,100) and then range(0,N) .. apologies if I didn't make that clear enough. > > Alternatively: > > import itertools > > for i, j in itertools.product(range(N,N+100),range(M,M+100)): > do_something(i,j) > > This can be preferable to deeply-nested loops. > > Also: in 2.x, use xrange() in preference to range(). > From werotizy at freent.dd Mon Aug 6 13:16:45 2012 From: werotizy at freent.dd (Tom P) Date: Mon, 06 Aug 2012 19:16:45 +0200 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 08/06/2012 06:03 PM, John Gordon wrote: > In Tom P writes: > >> consider a nested loop algorithm - > >> for i in range(100): >> for j in range(100): >> do_something(i,j) > >> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >> some other values i = N and j = M, and I want to iterate through all >> 10,000 values in sequence - is there a neat python-like way to this? I >> realize I can do things like use a variable for k in range(10000): and >> then derive values for i and j from k, but I'm wondering if there's >> something less clunky. > > You could define your own generator function that yields values > in whatever order you want: > > def my_generator(): > yield 9 > yield 100 > for i in range(200, 250): > yield i > yield 5 > > Thanks, I'll look at that but I think it just moves the clunkiness from one place in the code to another. From oscar.benjamin at bristol.ac.uk Mon Aug 6 13:35:40 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Mon, 6 Aug 2012 18:35:40 +0100 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 6 August 2012 18:14, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: > >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >>> some other values i = N and j = M, and I want to iterate through all >>> 10,000 values in sequence - is there a neat python-like way to this? >>> >> >> for i in range(N,N+100): >> for j in range(M,M+100): >> do_something(i,j) >> >> Or did you mean something else? >> > > no, I meant something else .. > > j runs through range(M, 100) and then range(0,M), and i runs through > range(N,100) and then range(0,N) > > .. apologies if I didn't make that clear enough. How about range(N, 100) + range(0, N)? Example (Python 2.x): >>> range(3, 10) [3, 4, 5, 6, 7, 8, 9] >>> range(0, 3) [0, 1, 2] >>> range(3, 10) + range(0, 3) [3, 4, 5, 6, 7, 8, 9, 0, 1, 2] In Python 3.x you'd need to do list(range(...)) + list(range(...)) or use itertools.chain. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at tobiah.org Mon Aug 6 13:42:09 2012 From: toby at tobiah.org (Tobiah) Date: Mon, 06 Aug 2012 10:42:09 -0700 Subject: Deciding inheritance at instantiation? In-Reply-To: References: Message-ID: On 08/03/2012 02:55 PM, Terry Reedy wrote: > On 8/3/2012 4:48 PM, Tobiah wrote: >> I have a bunch of classes from another library (the html helpers >> from web2py). There are certain methods that I'd like to add to >> every one of them. So I'd like to put those methods in a class, >> and pass the parent at the time of instantiation. Web2py has >> a FORM class for instance. I'd like to go: >> >> my_element = html_factory(FORM) >> >> Then my_element would be an instance of my class, and also >> a child of FORM. >> >> I started messing with decorators, but it became difficult >> for me to visualise how to do this. > > Use type(name, bases, content) for dynamic class creation. > Very cool. Just what I was after. Thanks. Tobiah From emile at fenx.com Mon Aug 6 14:11:11 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 06 Aug 2012 11:11:11 -0700 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 8/6/2012 10:14 AM Tom P said... > On 08/06/2012 06:18 PM, Nobody wrote: >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >>> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >>> some other values i = N and j = M, and I want to iterate through all >>> 10,000 values in sequence - is there a neat python-like way to this? >> >> for i in range(N,N+100): >> for j in range(M,M+100): >> do_something(i,j) >> >> Or did you mean something else? > > no, I meant something else .. > > j runs through range(M, 100) and then range(0,M), and i runs through > range(N,100) and then range(0,N) > > .. apologies if I didn't make that clear enough. > for i in range(N,N+100): for j in range(M,M+100): do_something(i % 100 ,j % 100) Emile From ndparker at gmail.com Mon Aug 6 14:19:08 2012 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Mon, 06 Aug 2012 20:19:08 +0200 Subject: looking for a neat solution to a nested loop problem References: Message-ID: <11795205.embGBpUICj@news.perlig.de> * Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through all > 10,000 values in sequence - is there a neat python-like way to this? I > realize I can do things like use a variable for k in range(10000): and > then derive values for i and j from k, but I'm wondering if there's > something less clunky. you mean: do_something((i + N) % 100, (j + M) % 100) ? I'd define my own range function doing exactly that. def rrange(count, start=0): for j in xrange(count): yield (j + start) % count (untested) Or use some itertools magic for that. It might be faster. nd -- "Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)" -- aus einer Rezension From invalid at invalid.invalid Mon Aug 6 14:25:01 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Aug 2012 18:25:01 +0000 (UTC) Subject: looking for a neat solution to a nested loop problem References: Message-ID: On 2012-08-06, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >>> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >>> some other values i = N and j = M, and I want to iterate through all >>> 10,000 values in sequence - is there a neat python-like way to this? >> >> for i in range(N,N+100): >> for j in range(M,M+100): >> do_something(i,j) >> >> Or did you mean something else? > > no, I meant something else .. > > j runs through range(M, 100) and then range(0,M), and i runs through > range(N,100) and then range(0,N) In 2.x: for i in range(M,100)+range(0,M): for j in range(N,100)+range(0,N): do_something(i,j) Dunno if that still works in 3.x. I doubt it, since I think in 3.x range returns an iterator, not? -- Grant Edwards grant.b.edwards Yow! I wish I was on a at Cincinnati street corner gmail.com holding a clean dog! From invalid at invalid.invalid Mon Aug 6 14:29:31 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Aug 2012 18:29:31 +0000 (UTC) Subject: looking for a neat solution to a nested loop problem References: Message-ID: On 2012-08-06, Grant Edwards wrote: > On 2012-08-06, Tom P wrote: >> On 08/06/2012 06:18 PM, Nobody wrote: >>> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >>> >>>> consider a nested loop algorithm - >>>> >>>> for i in range(100): >>>> for j in range(100): >>>> do_something(i,j) >>>> >>>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >>>> some other values i = N and j = M, and I want to iterate through all >>>> 10,000 values in sequence - is there a neat python-like way to this? >>> >>> for i in range(N,N+100): >>> for j in range(M,M+100): >>> do_something(i,j) >>> >>> Or did you mean something else? >> >> no, I meant something else .. >> >> j runs through range(M, 100) and then range(0,M), and i runs through >> range(N,100) and then range(0,N) > > In 2.x: > > for i in range(M,100)+range(0,M): > for j in range(N,100)+range(0,N): > do_something(i,j) > > Dunno if that still works in 3.x. I doubt it, since I think in 3.x > range returns an iterator, not? Indeed it doesn't work in 3.x, but this does: from itertools import chain for i in chain(range(M,100),range(0,M)): for j in chain(range(N,100),range(0,N)): do_something(i,j) -- Grant Edwards grant.b.edwards Yow! People humiliating at a salami! gmail.com From werotizy at freent.dd Mon Aug 6 15:03:30 2012 From: werotizy at freent.dd (Tom P) Date: Mon, 06 Aug 2012 21:03:30 +0200 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 08/06/2012 08:29 PM, Grant Edwards wrote: > On 2012-08-06, Grant Edwards wrote: >> On 2012-08-06, Tom P wrote: >>> On 08/06/2012 06:18 PM, Nobody wrote: >>>> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >>>> >>>>> consider a nested loop algorithm - >>>>> >>>>> for i in range(100): >>>>> for j in range(100): >>>>> do_something(i,j) >>>>> >>>>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but >>>>> some other values i = N and j = M, and I want to iterate through all >>>>> 10,000 values in sequence - is there a neat python-like way to this? >>>> >>>> for i in range(N,N+100): >>>> for j in range(M,M+100): >>>> do_something(i,j) >>>> >>>> Or did you mean something else? >>> >>> no, I meant something else .. >>> >>> j runs through range(M, 100) and then range(0,M), and i runs through >>> range(N,100) and then range(0,N) >> >> In 2.x: >> >> for i in range(M,100)+range(0,M): >> for j in range(N,100)+range(0,N): >> do_something(i,j) >> >> Dunno if that still works in 3.x. I doubt it, since I think in 3.x >> range returns an iterator, not? > > Indeed it doesn't work in 3.x, but this does: > > from itertools import chain > > for i in chain(range(M,100),range(0,M)): > for j in chain(range(N,100),range(0,N)): > do_something(i,j) > > ah, that looks good - I guess it works in 2.x as well? From invalid at invalid.invalid Mon Aug 6 15:22:55 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Aug 2012 19:22:55 +0000 (UTC) Subject: looking for a neat solution to a nested loop problem References: Message-ID: On 2012-08-06, Tom P wrote: >>>> no, I meant something else .. >>>> >>>> j runs through range(M, 100) and then range(0,M), and i runs through >>>> range(N,100) and then range(0,N) >>> >>> In 2.x: >>> >>> for i in range(M,100)+range(0,M): >>> for j in range(N,100)+range(0,N): >>> do_something(i,j) >>> >>> Dunno if that still works in 3.x. I doubt it, since I think in 3.x >>> range returns an iterator, not? >> >> Indeed it doesn't work in 3.x, but this does: >> >> from itertools import chain >> >> for i in chain(range(M,100),range(0,M)): >> for j in chain(range(N,100),range(0,N)): >> do_something(i,j) > > ah, that looks good - I guess it works in 2.x as well? I don't know. Let me test that for you... $ python Python 2.6.8 (unknown, May 18 2012, 11:56:26) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import chain >>> for i in chain(range(0,5),range(5,10)): ... print i ... 0 1 2 3 4 5 6 7 8 9 >>> Yes, it works in 2.x as well. -- Grant Edwards grant.b.edwards Yow! ... bleakness at ... desolation ... plastic gmail.com forks ... From mok-kong.shen at t-online.de Mon Aug 6 15:50:13 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 06 Aug 2012 21:50:13 +0200 Subject: A difficulty with lists Message-ID: I ran the following code: def xx(nlist): print("begin: ",nlist) nlist+=[999] print("middle:",nlist) nlist=nlist[:-1] print("final: ",nlist) u=[1,2,3,4] print(u) xx(u) print(u) and obtained the following result: [1, 2, 3, 4] begin: [1, 2, 3, 4] middle: [1, 2, 3, 4, 999] final: [1, 2, 3, 4] [1, 2, 3, 4, 999] As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. Could someone kindly help? M. K. Shen From emile at fenx.com Mon Aug 6 15:52:46 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 06 Aug 2012 12:52:46 -0700 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 8/6/2012 12:22 PM Grant Edwards said... > On 2012-08-06, Tom P wrote: >> ah, that looks good - I guess it works in 2.x as well? > > I don't know. Let me test that for you... > > > Yes, it works in 2.x as well. > :) And from the docs, all the way back to 2.3! 9.7. itertools Functions creating iterators for efficient looping New in version 2.3. Emile From ckaynor at zindagigames.com Mon Aug 6 16:12:38 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 6 Aug 2012 13:12:38 -0700 Subject: A difficulty with lists In-Reply-To: References: Message-ID: On Mon, Aug 6, 2012 at 12:50 PM, Mok-Kong Shen wrote: > I ran the following code: > > def xx(nlist): > print("begin: ",nlist) > nlist+=[999] > This is modifying the list in-place - the actual object is being changed to append 999. This can happen because lists are mutable data types in Python, for some other data types (such as integers), this line will copy the integer, increment it, then set the name back to the new value. > print("middle:",nlist) > nlist=nlist[:-1] > Here, you are making a new list, containing all but the last item of the list, then assigning that new list to the name nlist. This does not mutate the passed-in object, just reassigns the name in the local namespace. As an alternative, you can use the list mutation methods, namely pop, to modify the list in place here instead. You could also using a slice assignment to assign to the pre-exisitng list for similar effect. Either of the following will produce the result you are expecting: nlist.pop() # Pops the last item from the list. More efficient and clearer than the following: nlist[:] = nlist[:-1] # Assigns the entire contents of the list to all but the last item of the list. > print("final: ",nlist) > > u=[1,2,3,4] > print(u) > xx(u) > print(u) > > and obtained the following result: > > [1, 2, 3, 4] > begin: [1, 2, 3, 4] > middle: [1, 2, 3, 4, 999] > final: [1, 2, 3, 4] > [1, 2, 3, 4, 999] > > As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. > Could someone kindly help? > The basic concept is that Python uses a pass-by-object system. When you call a function with an object, a reference to that object gets passed into the function. Mutations of that object will affect the original object, but you can assign new objects to the same name as the parameter without affecting the caller. > > M. K. Shen > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Mon Aug 6 16:14:25 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 6 Aug 2012 21:14:25 +0100 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but some > other values i = N and j = M, and I want to iterate through all 10,000 > values in sequence - is there a neat python-like way to this? I realize I > can do things like use a variable for k in range(10000): and then derive > values for i and j from k, but I'm wondering if there's something less > clunky. For example: for i in range(100): for j in range(100): do_something((i + N)%100, (j + N)%100) Cheers, -- Arnaud From python at mrabarnett.plus.com Mon Aug 6 16:19:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Aug 2012 21:19:01 +0100 Subject: A difficulty with lists In-Reply-To: References: Message-ID: <502026B5.9080605@mrabarnett.plus.com> On 06/08/2012 20:50, Mok-Kong Shen wrote: > I ran the following code: > > def xx(nlist): > print("begin: ",nlist) > nlist+=[999] > print("middle:",nlist) > nlist=nlist[:-1] > print("final: ",nlist) > > u=[1,2,3,4] > print(u) > xx(u) > print(u) > > and obtained the following result: > > [1, 2, 3, 4] > begin: [1, 2, 3, 4] > middle: [1, 2, 3, 4, 999] > final: [1, 2, 3, 4] > [1, 2, 3, 4, 999] > > As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. > Could someone kindly help? > This: nlist+=[999] appends to the list, making it [1, 2, 3, 4, 999]. This: nlist=nlist[:-1] gets a slice of the list and then binds it to the local name 'nlist'. From mok-kong.shen at t-online.de Mon Aug 6 16:46:38 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 06 Aug 2012 22:46:38 +0200 Subject: [newbie] String to binary conversion Message-ID: If I have a string "abcd" then, with 8-bit encoding of each character, there is a corresponding 32-bit binary integer. How could I best obtain that integer and from that integer backwards again obtain the original string? Thanks in advance. M. K. Shen From gelonida at gmail.com Mon Aug 6 16:48:13 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 06 Aug 2012 22:48:13 +0200 Subject: find out whether a module exists (without importing it) Message-ID: Is this possible. let's say I'd like to know whether I could import the module 'mypackage.mymodule', meaning, whther this module is located somewhere in sys.path i tried to use imp.find_module(), but it didn't find any module name containing a '.' Am I doing anything wrong? Is there another existing implementation, that helps. I could do this manually, but this is something I'd just like to do if necessary. From toby at tobiah.org Mon Aug 6 16:59:40 2012 From: toby at tobiah.org (Tobiah) Date: Mon, 06 Aug 2012 13:59:40 -0700 Subject: [newbie] String to binary conversion In-Reply-To: References: Message-ID: <0fWTr.70$Bw1.65@newsfe05.iad> The binascii module looks like it might have something for you. I've never used it. Tobiah http://docs.python.org/library/binascii.html On 08/06/2012 01:46 PM, Mok-Kong Shen wrote: > > If I have a string "abcd" then, with 8-bit encoding of each character, > there is a corresponding 32-bit binary integer. How could I best > obtain that integer and from that integer backwards again obtain the > original string? Thanks in advance. > > M. K. Shen From storchaka at gmail.com Mon Aug 6 16:59:59 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Aug 2012 23:59:59 +0300 Subject: conditional running of code portion In-Reply-To: <87hasg0x9b.fsf@handshake.de> References: <0a61aed2-bd14-4022-bf59-a3bb3af55b3c@sn4g2000pbc.googlegroups.com> <501e1319$0$29978$c3e8da3$5496439d@news.astraweb.com> <87hasg0x9b.fsf@handshake.de> Message-ID: On 06.08.12 20:02, Dieter Maurer wrote: > Serhiy Storchaka writes: >> On 05.08.12 09:30, Steven D'Aprano wrote: >>> If you are working in a tight loop, you can do this: >>> >>> if VERBOSE_FLAG: >>> for item in loop: >>> print(DEBUG_INFORMATION) >>> do_actual_work(item) >>> else: >>> for item in loop: >>> do_actual_work(item) >> >> Or this: >> >> if VERBOSE_FLAG: >> def do_work(item): >> print(DEBUG_INFORMATION) >> do_actual_work(item) >> else: >> do_work = do_actual_work >> >> for item in loop: >> do_work(item) > > Be warned: a function call is *much* more expensive than an > "if variable:". As any actual work. As iteration. Yet one way: def verbose_iter(it): for i in it: print(DEBUG_INFORMATION) yield i ... if VERBOSE_FLAG: loop = verbose_iter(loop) for item in loop: do_work(item) From toby at tobiah.org Mon Aug 6 17:01:02 2012 From: toby at tobiah.org (Tobiah) Date: Mon, 06 Aug 2012 14:01:02 -0700 Subject: [newbie] String to binary conversion In-Reply-To: <0fWTr.70$Bw1.65@newsfe05.iad> References: <0fWTr.70$Bw1.65@newsfe05.iad> Message-ID: On 08/06/2012 01:59 PM, Tobiah wrote: > The binascii module looks like it might have > something for you. I've never used it. Having actually read some of that doc, I see it's not what you want at all. Sorry. From mok-kong.shen at t-online.de Mon Aug 6 17:33:13 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Mon, 06 Aug 2012 23:33:13 +0200 Subject: [newbie] String to binary conversion In-Reply-To: <0fWTr.70$Bw1.65@newsfe05.iad> References: <0fWTr.70$Bw1.65@newsfe05.iad> Message-ID: Am 06.08.2012 22:59, schrieb Tobiah: > The binascii module looks like it might have > something for you. I've never used it. Thanks for the hint, but if I don't err, the module binascii doesn't seem to work. I typed: import binascii and a line that's given as example in the document: crc = binascii.crc32("hello") but got the following error message: TypeError: 'str' does not support the buffer interface. The same error message appeared when I tried the other functions. M. K. Shen From python at mrabarnett.plus.com Mon Aug 6 17:56:04 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Aug 2012 22:56:04 +0100 Subject: [newbie] String to binary conversion In-Reply-To: References: Message-ID: <50203D74.8090709@mrabarnett.plus.com> On 06/08/2012 21:46, Mok-Kong Shen wrote: > > If I have a string "abcd" then, with 8-bit encoding of each character, > there is a corresponding 32-bit binary integer. How could I best > obtain that integer and from that integer backwards again obtain the > original string? Thanks in advance. > Try this (Python 3, in which strings are Unicode): >>> import struct >>> # For a little-endian integer >>> struct.unpack(">> hex(_) '0x64636261' or this (Python 2, in which strings are bytestrings): >>> import struct >>> # For a little-endian integer >>> struct.unpack(">> hex(_) '0x64636261' From miki.tebeka at gmail.com Mon Aug 6 17:58:24 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 6 Aug 2012 14:58:24 -0700 (PDT) Subject: find out whether a module exists (without importing it) In-Reply-To: References: Message-ID: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> > imp.find_module(), but > it didn't find any module name containing a '.' The docs (http://docs.python.org/library/imp.html#imp.find_module) clearly say: "This function does not handle hierarchical module names (names containing dots). In order to find P.M, that is, submodule M of package P, use find_module() and load_module() to find and load package P, and then use find_module() with the path argument set to P.__path__. When P itself has a dotted name, apply this recipe recursively." See https://gist.github.com/3278829 for possible implementation. From miki.tebeka at gmail.com Mon Aug 6 17:58:24 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 6 Aug 2012 14:58:24 -0700 (PDT) Subject: find out whether a module exists (without importing it) In-Reply-To: References: Message-ID: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> > imp.find_module(), but > it didn't find any module name containing a '.' The docs (http://docs.python.org/library/imp.html#imp.find_module) clearly say: "This function does not handle hierarchical module names (names containing dots). In order to find P.M, that is, submodule M of package P, use find_module() and load_module() to find and load package P, and then use find_module() with the path argument set to P.__path__. When P itself has a dotted name, apply this recipe recursively." See https://gist.github.com/3278829 for possible implementation. From rosuav at gmail.com Mon Aug 6 17:59:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Aug 2012 07:59:44 +1000 Subject: Intermediate Python user needed help In-Reply-To: <8i4028d5rlcjbv73jra8sg2c2bgg7n6u1o@invalid.netcom.com> References: <501FEB5E.6050506@stoneleaf.us> <8i4028d5rlcjbv73jra8sg2c2bgg7n6u1o@invalid.netcom.com> Message-ID: On Tue, Aug 7, 2012 at 5:22 AM, Dennis Lee Bieber wrote: > So am I beginner, intermediate, advanced, expert? I wonder would this sort of a scale help: http://www.geekcode.com/geek.html#perl Novice: P Intermediate: P+ or P++ Advanced: P+++ Master: P++++ ChrisA From gelonida at gmail.com Mon Aug 6 18:40:49 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 07 Aug 2012 00:40:49 +0200 Subject: find out whether a module exists (without importing it) In-Reply-To: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> References: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> Message-ID: On 08/06/2012 11:58 PM, Miki Tebeka wrote: >> imp.find_module(), but >> it didn't find any module name containing a '.' > The docs (http://docs.python.org/library/imp.html#imp.find_module) clearly say: > > "This function does not handle hierarchical module names(names > containing dots). Thanks, Well this explains. > In order to find P.M, that is, submodule M of package P, use find_module() and load_module() to find and load package P, and then use find_module() with the path argument set to P.__path__. When P itself has a dotted name, apply this recipe recursively." > > See https://gist.github.com/3278829 for possible implementation. > Using imp and then iterating (as you suggested) is probably the fastest solution. This is what I will do. Thanks again. From rosuav at gmail.com Mon Aug 6 18:44:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Aug 2012 08:44:15 +1000 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: On Tue, Aug 7, 2012 at 2:34 AM, rusi wrote: > BTW in "automatic garbage collection" which of the three words is most > important? Least? Most important is "garbage". I sure don't want any language I use to automatically collect non-garbage!! But in seriousness, the definition of "garbage" is one of the trickier things to work out, hence the variety of schemes (mark/sweep, refcount, various forms of cycle detection, etc). ChrisA From emile at fenx.com Mon Aug 6 18:45:50 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 06 Aug 2012 15:45:50 -0700 Subject: [newbie] String to binary conversion In-Reply-To: References: Message-ID: On 8/6/2012 1:46 PM Mok-Kong Shen said... > > If I have a string "abcd" then, with 8-bit encoding of each character, > there is a corresponding 32-bit binary integer. How could I best > obtain that integer and from that integer backwards again obtain the > original string? Thanks in advance. It's easy to write one: def str2val(str,_val=0): if len(str)>1: return str2val(str[1:],256*_val+ord(str[0])) return 256*_val+ord(str[0]) def val2str(val,_str=""): if val>256: return val2str(int(val/256),_str)+chr(val%256) return _str+chr(val) print str2val("abcd") print val2str(str2val("abcd")) print val2str(str2val("good")) print val2str(str2val("longer")) print val2str(str2val("verymuchlonger")) Flavor to taste. Emile From steve+comp.lang.python at pearwood.info Mon Aug 6 21:12:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 01:12:34 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> Message-ID: <50206b82$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 17:17:33 +0100, Mark Lawrence wrote: > Please see my comment at the bottom hint hint :) Please trim unnecessary quoted text. We don't need to see the entire thread of comment/reply/reply-to-reply duplicated in *every* email. -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 6 21:16:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 01:16:21 GMT Subject: Intermediate Python user needed help References: Message-ID: <50206c65$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 09:05:50 -0700, Ethan Furman wrote: > These are not the errors an intermediate user would make, nor the > questions an intermediate user would ask. These are the errors that > somebody who doesn't know Python would make. > P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced > -> Master > > Are there scales out there that would put these types of questions in > the "intermediate" category? http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect Or to put it another way: http://www.quickmeme.com/meme/359ofp/ http://www.quickmeme.com/meme/3q8648/ -- Steven From ben+python at benfinney.id.au Mon Aug 6 21:23:27 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Aug 2012 11:23:27 +1000 Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> <50206b82$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a9y7jy0g.fsf@benfinney.id.au> Steven D'Aprano writes: > Please trim unnecessary quoted text. > > We don't need to see the entire thread of comment/reply/reply-to-reply > duplicated in *every* email. s/every/any/ -- \ ?If you make people think they're thinking, they'll love you; | `\ but if you really make them think, they'll hate you.? ?Donald | _o__) Robert Perry Marquis | Ben Finney From steve+comp.lang.python at pearwood.info Mon Aug 6 21:27:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 01:27:07 GMT Subject: looking for a neat solution to a nested loop problem References: Message-ID: <50206eeb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 19:16:45 +0200, Tom P wrote: >> def my_generator(): >> yield 9 >> yield 100 >> for i in range(200, 250): >> yield i >> yield 5 >> >> > Thanks, I'll look at that but I think it just moves the clunkiness from > one place in the code to another. And if there was a built-in command that did exactly what you wanted, it too would also move the clunkiness from one place in the code to another. What you are asking for is clunky: [quote] j runs through range(M, 100) and then range(0,M), and i runs through range(N,100) and then range(0,N) [end quote] There's no magic pixie dust that you can sprinkle on it to make it elegant. Assuming M and N are small (under 100), you can do this: values = range(100) # or list(range(100)) in Python 3. for j in (values[M:] + values[:M]): for i in (values[N:] + values[:N]): ... which isn't too bad. If you have to deal with much large ranges, you can use itertools to chain them together: import itertools jvalues = itertools.chain(xrange(M, 1000000), xrange(M)) # or just range ivalues = itertools.chain(xrange(N, 2500000), xrange(N)) # in Python 3 for j in jvalues: for i in ivalues: ... -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 6 22:01:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 02:01:05 GMT Subject: [newbie] String to binary conversion References: Message-ID: <502076e1$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 22:46:38 +0200, Mok-Kong Shen wrote: > If I have a string "abcd" then, with 8-bit encoding of each character, > there is a corresponding 32-bit binary integer. How could I best obtain > that integer and from that integer backwards again obtain the original > string? Thanks in advance. First you have to know the encoding, as that will define the integers you get. There are many 8-bit encodings, but of course they can't all encode arbitrary 4-character strings. Since there are tens of thousands of different characters, and an 8-bit encoding can only code for 256 of them, there are many strings that an encoding cannot handle. For those, you need multi-byte encodings like UTF-8, UTF-16, etc. Sticking to one-byte encodings: since most of them are compatible with ASCII, examples with "abcd" aren't very interesting: py> 'abcd'.encode('latin1') b'abcd' Even though the bytes object b'abcd' is printed as if it were a string, it is actually treated as an array of one-byte ints: py> b'abcd'[0] 97 Here's a more interesting example, using Python 3: it uses at least one character (the Greek letter ?) which cannot be encoded in Latin1, and two which cannot be encoded in ASCII: py> "a??d".encode('iso-8859-7') b'a\xf0\xa9d' Most encodings will round-trip successfully: py> text = 'a??Z!' py> data = text.encode('iso-8859-7') py> data.decode('iso-8859-7') == text True (although the ability to round-trip is a property of the encoding itself, not of the encoding system). Naturally if you encode with one encoding, and then decode with another, you are likely to get different strings: py> text = 'a??Z!' py> data = text.encode('iso-8859-7') py> data.decode('latin1') 'a??Z!' py> data.decode('iso-8859-14') 'a??Z!' Both the encode and decode methods take an optional argument, errors, which specify the error handling scheme. The default is errors='strict', which raises an exception. Others include 'ignore' and 'replace'. py> 'a????Z!'.encode('ascii', 'ignore') b'aZ!' py> 'a????Z!'.encode('ascii', 'replace') b'a????Z!' -- Steven From wuwei23 at gmail.com Mon Aug 6 22:53:53 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 6 Aug 2012 19:53:53 -0700 (PDT) Subject: Deciding inheritance at instantiation? References: Message-ID: <41f5bfb2-852c-4748-af09-445958471bbd@sn4g2000pbc.googlegroups.com> On Aug 4, 6:48?am, Tobiah wrote: > I have a bunch of classes from another library (the html helpers > from web2py). ?There are certain methods that I'd like to add to > every one of them. ?So I'd like to put those methods in a class, > and pass the parent at the time of instantiation. ?Web2py has > a FORM class for instance. ?I'd like to go: > > ? ? ? ? my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also > a child of FORM. I've lately begun to prefer composition over inheritance for situations like this: class MyElementFormAdapter(object): def __init__(self, form): self.form = form def render_form(self): self.form.render() my_element = MyElementFormAdapter(FORM) my_element.render_form() my_element.form.method_on_form() Advantages include being more simple and obvious than multiple inheritance, and avoiding namespace clashes: class A(object): def foo(self): print 'a' class B(object): def foo(self): print 'b' class InheritFromAB(A, B): pass class AdaptAB(object): def __init__(self, a, b): self.a = a self.b = b >>> inherit = InheritFromAB() >>> inherit.foo() a >>> adapt = AdaptAB(A(), B()) >>> adapt.a.foo() a >>> adapt.b.foo() b From jugurtha.hadjar at gmail.com Mon Aug 6 23:06:03 2012 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Tue, 07 Aug 2012 04:06:03 +0100 Subject: Intermediate Python user needed help In-Reply-To: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <5020861B.5080905@gmail.com> On 08/05/2012 09:52 PM, John Mordecai Dildy wrote: > NameError: name 'start' is not defined > > anyone know how to make start defined Maybe rename it "defined_start" ;) I wonder how someone can get to the point of writing more than 76 lines of code while not only still making this kind of errors, but not even knowing what these errors mean and how to correct them. It's impossible. You can't write programs that are more than 10 lines without having encountered these errors and learnt how to deal with them. Unless you're reading exercises from a book, and feeling that you're "intermediate", you started reading from chapter 28 in a 29 chapters book. -- ~Jugurtha Hadjar, From rustompmody at gmail.com Mon Aug 6 23:52:42 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 20:52:42 -0700 (PDT) Subject: Intermediate Python user needed help References: <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com> Message-ID: <65361ea4-9740-49b1-93cc-29573ac8c27a@r2g2000pbn.googlegroups.com> On Aug 7, 8:06?am, Jugurtha Hadjar wrote: > On 08/05/2012 09:52 PM, John Mordecai Dildy wrote: > > > NameError: name 'start' is not defined > > > anyone know how to make start defined > > Maybe rename it "defined_start" ;) > > I wonder how someone can get to the point of writing more than 76 lines > of code while not only still making this kind of errors, but not even > knowing what these errors mean and how to correct them. It's impossible. > You can't write programs that are more than 10 lines without having > encountered these errors and learnt how to deal with them. > > Unless you're reading exercises from a book, and feeling that you're > "intermediate", you started reading from chapter 28 in a 29 chapters book. > > -- > ~Jugurtha Hadjar, If you've ever taught programming in a formal teaching setup, you would not be surprised when students submit C 'projects' that wont even compile (leave aside segfault). On a more personal note, the first program I wrote was in Cobol. I got only 350 errors before the compiler copped out. It was a bit traumatic. Later on I found I forgot to write PROCEDURE DIVISION. So its good to remember how spoilt we are on python that we can test out 10 lines at a time. From rustompmody at gmail.com Mon Aug 6 23:55:02 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 20:55:02 -0700 (PDT) Subject: Intermediate Python user needed help References: <50206c65$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3a170ee8-e375-4d38-8f44-751c2889384b@t6g2000pbp.googlegroups.com> On Aug 7, 6:16?am, Steven D'Aprano wrote: > On Mon, 06 Aug 2012 09:05:50 -0700, Ethan Furman wrote: > > ? These are not the errors an intermediate user would make, nor the > > questions an intermediate user would ask. ?These are the errors that > > somebody who doesn't know Python would make. > > P.S. ?The scale I am accustomed to is Novice -> Intermediate -> Advanced > > -> Master > > > Are there scales out there that would put these types of questions in > > the "intermediate" category? > > http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect Thanks for that link -- I'd been looking for it. > > Or to put it another way: > > http://www.quickmeme.com/meme/359ofp/http://www.quickmeme.com/meme/3q8648/ From orgnut at yahoo.com Tue Aug 7 00:02:33 2012 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 06 Aug 2012 21:02:33 -0700 Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: On 08/06/2012 11:11 AM, Emile van Sebille wrote: > > for i in range(N,N+100): > for j in range(M,M+100): > do_something(i % 100 ,j % 100) > > Emile How about... for i in range(100): for j in range(100): do_something((i + N) % 100, (j + M) % 100) -=- Larry -=- From rustompmody at gmail.com Tue Aug 7 00:03:46 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 21:03:46 -0700 (PDT) Subject: The way to develope a graphical application to manage a Postgres database References: <87txwhfhzd.fsf@gmail.com> Message-ID: <542cc24b-c2df-4aba-b01b-b9b2e2e95546@iw9g2000pbc.googlegroups.com> On Aug 5, 11:26?pm, Csanyi Pal wrote: > Mark Lawrence writes: > > On 05/08/2012 16:58, Csanyi Pal wrote: > >> Walter Hurry writes: > > >>> On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal wrote: > > >>>> I'm searching for a way to develope a Python graphical application for a > >>>> Postgresql database. > > >>> I use wxGlade/wxPython to build the GUI, and then hand code the database > >>> access using psycopg2 into the generated application. Works very well for > >>> me, but I do know SQL and Postgres. > > >> Well, I tried out many adviced ways but none of them works on my Debian > >> GNU/Linux testing/sid system. Always get some error in one of the part > >> of the software. > > > If you give precise details by cutting and pasting the error people > > will be able to help. > > I shall do that later. Chris already suggested that you try GUI without DBMS and DBMS without GUI first before trying the two together. One way of subverting the DBMS-stage (its called mocking nowadays!) is to use sqlite instead of a full-scale DBMS like postgres. After that works you can switch to postgres. From rustompmody at gmail.com Tue Aug 7 00:23:49 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 6 Aug 2012 21:23:49 -0700 (PDT) Subject: Alternate Python extensions (was alternate Python implementations) References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9efbb19a-45ef-413b-b12f-6a59137bcf47@r2g2000pbn.googlegroups.com> On Aug 4, 11:15?am, Steven D'Aprano wrote: > Most people are aware, if only vaguely, of the big Four Python > implementations: I think the question about where Cython fits into this, raises the need for a complementary list to Steven's. What are the different ways in which python can be extended/embedded. eg 1. 'Classic' extending/embedding 2. SCXX 3. PyCXX 4. Boost 5. Cython 6. Swig 7. Sip 8. ctypes Is such a list maintained somewhere? From stefan_ml at behnel.de Tue Aug 7 01:09:37 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 07 Aug 2012 07:09:37 +0200 Subject: Alternate Python extensions (was alternate Python implementations) In-Reply-To: <9efbb19a-45ef-413b-b12f-6a59137bcf47@r2g2000pbn.googlegroups.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <9efbb19a-45ef-413b-b12f-6a59137bcf47@r2g2000pbn.googlegroups.com> Message-ID: rusi, 07.08.2012 06:23: > On Aug 4, 11:15 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Most people are aware, if only vaguely, of the big Four Python >> implementations: > > I think the question about where Cython fits into this, raises the > need for a complementary list to Steven's. What are the different > ways in which python can be extended/embedded. eg > > 1. 'Classic' extending/embedding > 2. SCXX > 3. PyCXX > 4. Boost > 5. Cython > 6. Swig > 7. Sip > 8. ctypes > > Is such a list maintained somewhere? Hijacking this page would be a good place to start it IMHO: http://wiki.python.org/moin/Embedding%20and%20Extending Stefan From steve+comp.lang.python at pearwood.info Tue Aug 7 01:19:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 05:19:00 GMT Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 09:55:24 +0100, lipska the kat wrote: > On 06/08/12 01:22, Steven D'Aprano wrote: >> On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: >> >>> >>> Object Oriented programming is a mindset, a way of looking at that >>> particular part of our world that you are trying to encapsulate in >>> computer language. The language you use is (should be) irrelevant. >> >> That depends on how you define OOP, and in particular, which aspects of >> OOP your language supports. > > The clue is in the name 'Object Oriented' ... anything else is (or > should be) implementation detail. So your argument is that any programming which is "oriented" (meaning what?) towards "objects" (which are...?) is OOP, and everything else is "implementation detail". Well now I'm enlightened. That certainly clears that up for me. > [large snip] > > >> In particularly, terminology varies -- I personally despise with the >> heat of a thousand suns the terms "instance variable" and "class >> variable" for attributes or members. > > This is an implementation detail and describes the difference between > certain types of attributes. Not everything is an "implementation detail". The difference between a so- called "class variable" (what Python calls a class attribute) and a "instance variable" (instance attribute) is not an implementation detail, it is a difference in semantics and function. As you go on to explain: > A class variable is static and can be > accessed without instantiation an instance variable is accessed via an > instance which are semantic differences, differences in meaning and function. >> Since a "string variable" is a variable holding a string, and a "float >> variable" is a variable holding a float, an instance variable should be >> a variable holding an instance, and a class variable should be a >> variable holding a class. > > Class variable and instance variable are higher level abstractions. Of what? Of variables? "Class variables are an abstraction of variables"... even if true, that's a crappy way to speak. Why should you use the same word for higher level abstractions that is already used for lower level abstractions? I understand that in Java, classes are not first-class (no pun intended) objects. You can't say: x = MyClass and hence talk about x being a variable that holds a class, hence "class variable". But that's no excuse to overload the term "variable" for something where there are at least three good names: attribute member property none of which clash with the normal use of the word "variable". (Smalltalk gets a pass here -- it was very early days in OOP, and the terminology wasn't available. But by the time that Java came along, there was no longer any good justification for overloading a perfectly good word like variable to mean something different.) Simply put, the choice of terminology is crap -- attributes of a class/ instance have subtle but real semantic differences from local/global variables. Attributes belong to an entity (an instance, or a class); variables do not. If they were just implementation differences ("local variables live on the stack, attributes live in the instance struct") it wouldn't matter. But the semantics are different, and the "instance variable" terminology is misleading. But what *really* gets me is not the existence of poor terminology. I couldn't care less what terminology Java programmers use among themselves. What gets me is that the ubiquity of them means that substandard terminology spreads into other languages, like dryrot. >>> The ONLY concept that you should never try to encapsulate is/are human >>> beings or their aliases. > > snip > >> Is this some sort of mystical "humans aren't objects, they're >> SPECIAL!!!" rubbish? Because it sure sounds like it. >> >> Can you give some non-religious reasons why you should not implement >> human beings or aliases as objects? > > You have answered your own question.... I'm afraid I have no idea what you mean here. Do you mean that you *don't* have any non-religious reasons for avoiding Person and User objects? How do you feel about Person and User structs, records or fields? > I would be glad to debate my > assertion at length with you however the 'moderators' are listening. There are no moderators on this list. People are free to try using peer pressure to discourage off-topic discussion, but they can't enforce it. >>> I've already managed to write meaningful code but I haven't invented a >>> single class yet. >> >> And why do you think this is a problem? > > A problem? I wasn't aware that I'd stated it was a problem it just You said "BUT [emphasis added] I haven't invented a single class yet", which implies that this is a bad thing in contrast to the good thing that you became productive in Python very quickly. > underlines my belief that Python, however useful it is, is not the ideal > language to learn about Object Oriented software development. I guess that depends on whether you learn best from a gentle learning curve with incremental gains in knowledge, or by immersing yourself in an entirely unfamiliar environment with a steep learning curve to "sink or swim". > > and a Facade is just an interface layer. > > Well as you seem to be so concerned with terminology I'd have to > disagree with you here. An interface (in computing) has any number of > meanings, hardware interfaces, software interfaces the HCI etc etc. All of which have in common that they are a layer (hardware, software, or something else) between two entities (objects, hardware components, people, substances, environments, etc.). Which is exactly what a facade is. > In > some languages an interface is a non functional unit of compilation that > describes the methods an implementing class must provide. And even in those languages (Pascal, for example) an interface is also an interface, not just an instruction to the compiler stating what interface elements are required. > A facade on > the other hand aggregates a number of fine grained operations that often > implement the business logic of an application into coarser grained > methods that can be called further up the implementation stack. Which makes it an interface to those fine-grained operations. Just because the word "interface" is a reserved word in Pascal with a specific technical meaning and "facade" is not does not mean that the general term "interface" does not also apply to facades. > More > importantly, what goes on behind a facade can be completely changed > without affecting anything that uses the facade thereby enhancing > maintainability. (I'm trying really hard not to use buzzwords here). Which is exactly the point of an interface. You can change the implementation behind the interface (the fine-grained operations) without needing to change the higher-level facade operations. I'm not arguing against the usefulness of "facades". I am questioning why they need to be singled out as a named "design pattern" instead of just one mere example of a more general, less specific technique of building an interface to another system. You have a complicated, fine-grained system which is difficult to use? Write an interface, then talk to the interface. You have a simple, but buggy, system, and need a layer of code to work around the bugs? Write an interface, then talk to the interface. You have a system which changes rapidly? Write an interface, and talk to the interface. There's no need to teach multiple different design patterns in isolation: "facade", "adaptor", "bridge", "connector", "proxy"... They're all the same pattern. If you learn the general idea of an interface, the rest are obvious. Or at least more clear and less jargon. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 7 01:35:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 05:35:00 GMT Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5020a903$0$29867$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 10:24:10 +0100, lipska the kat wrote: > er, the point I was trying to make is that when you say 'interface' it > could mean so many things. If you say 'facade' everyone knows exactly > what you are talking about. And that is EXACTLY the point. The whole point of design patterns is to avoid getting stuck in incidental implementation details of a particular library or class and look for higher-level design patterns. The same applies to facade -- it's just a special case of the interface pattern. Why get stuck in incidental implementation details of the particular *kind* of interface layer you need? Obviously the person writing the interface/facade/adaptor/whatever needs to understand the implementation details. But the people using the interface don't. Why waste brain CPUs trying to decide whether a particular interface is a facade, an adaptor, a bridge, a proxy, ... ? Especially since in real- life code, any such interface is going to include elements of all of the above. Take this example from Wikipedia's article on Facade pattern: ========= ======== Pattern Intent ========= ======== Adapter Converts one interface to another so that it matches what the client is expecting Decorator Adds responsibility to the interface without altering it Facade Provides a simplified interface ========= ======== It's rare that the intent is as pure as that. Normally it will be: "Simplify the interface, oh and also change the API of these three methods to match this other library, and add a couple of helper methods, and while you're at it, this method has a bug that upstream refuses to patch, do something about that." So is that a facade or an adaptor, or something else? -- Steven From nagle at animats.com Tue Aug 7 01:57:59 2012 From: nagle at animats.com (John Nagle) Date: Mon, 06 Aug 2012 22:57:59 -0700 Subject: On-topic: alternate Python implementations In-Reply-To: <501dd82e$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cff63$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujmabs9.fsf@ruckus.brouhaha.com> <501dc461$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x1ujm9kyu.fsf@ruckus.brouhaha.com> <501dd82e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/4/2012 7:19 PM, Steven D'Aprano wrote: > On Sat, 04 Aug 2012 18:38:33 -0700, Paul Rubin wrote: > >> Steven D'Aprano writes: >>> Runtime optimizations that target the common case, but fall back to >>> unoptimized code in the rare cases that the optimization doesn't apply, >>> offer the opportunity of big speedups for most code at the cost of >>> trivial slowdowns when you do something unusual. >> >> The problem is you can't always tell if the unusual case is being >> exercised without an expensive dynamic check, which in some cases must >> be repeated in every iteration of a critical inner loop, even though it >> turns out that the program never actually uses the unusual case. There are other approaches. PyPy uses two interpreters and a JIT compiler to handle the hard cases. When code does something unexpected to other code, the backup interpreter is used to get control out of the trouble spot so that the JIT compiler can then recompile the code. (I think; I've read the paper but haven't looked at the internals.) This is hard to implement and hard to get right. John Nagle From Iryna.Feuerstein at FernUni-Hagen.de Tue Aug 7 02:19:00 2012 From: Iryna.Feuerstein at FernUni-Hagen.de (Iryna Feuerstein) Date: Tue, 07 Aug 2012 08:19:00 +0200 Subject: dictionary comprehensions with Python 2.4/2.5 Message-ID: Hello, for the program developed and maintained by our company the compatibility with Python 2.5 is desired. I'm developing with Python 2.7, though I would like to use dictionary comprehensions in my code. The dictionary comprehensions were added to Python in version 2.7 at first time. Is it possible to make it compatible with Python 2.5 anyway? Perhaps by using the __future__ module? Thank you in advance! With regards, Iryna. From michael.poeltl at univie.ac.at Tue Aug 7 02:43:31 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Tue, 7 Aug 2012 08:43:31 +0200 Subject: find out whether a module exists (without importing it) In-Reply-To: References: Message-ID: <20120807064331.GA31774@terra.cms.at> in my opinion, "without importing it" makes it unnecessarily complicated. You just want to know it module xyz exists, or better said can be found (sys.path). why not try - except[ - else ] try: import mymodule except ImportError: # NOW YOU KNOW it does not exist #+ and you may react properly ?? * Gelonida N [2012-08-06 22:49]: > Is this possible. > > let's say I'd like to know whether I could import the module > 'mypackage.mymodule', meaning, > whther this module is located somewhere in sys.path > > i tried to use > > imp.find_module(), but > it didn't find any module name containing a '.' > > Am I doing anything wrong? > > Is there another existing implementation, that helps. > > I could do this manually, but this is something I'd just like to do > if necessary. > > > -- > 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 ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From no.email at nospam.invalid Tue Aug 7 02:58:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Aug 2012 23:58:02 -0700 Subject: dictionary comprehensions with Python 2.4/2.5 References: Message-ID: <7xehnjb345.fsf@ruckus.brouhaha.com> Iryna Feuerstein writes: > code. The dictionary comprehensions were added to Python in version > 2.7 at first time. Is it possible to make it compatible with Python > 2.5 anyway? Perhaps by using the __future__ module? Not back to 2.5, but they're not that important anyway. Just use: d = dict((k, v) for k,v in ... ) From Iryna.Feuerstein at FernUni-Hagen.de Tue Aug 7 03:41:30 2012 From: Iryna.Feuerstein at FernUni-Hagen.de (Iryna Feuerstein) Date: Tue, 07 Aug 2012 09:41:30 +0200 Subject: dictionary comprehensions with Python 2.4/2.5 In-Reply-To: <7xehnjb345.fsf@ruckus.brouhaha.com> References: <7xehnjb345.fsf@ruckus.brouhaha.com> Message-ID: > > Not back to 2.5, but they're not that important anyway. Just use: > d = dict((k, v) for k,v in ... ) > Thank you very much! It is the perfect solution for me. Regards, Iryna. From breamoreboy at yahoo.co.uk Tue Aug 7 03:49:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 07 Aug 2012 08:49:07 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <50206b82$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <8f1b60a5-0411-4aae-9ee6-0025b493ca2d@m13g2000vbd.googlegroups.com> <94492584-4446-47ff-85c4-749de850561e@b10g2000vbj.googlegroups.com> <50206b82$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/08/2012 02:12, Steven D'Aprano wrote: > On Mon, 06 Aug 2012 17:17:33 +0100, Mark Lawrence wrote: > >> Please see my comment at the bottom hint hint :) > > Please trim unnecessary quoted text. > > We don't need to see the entire thread of comment/reply/reply-to-reply > duplicated in *every* email. > > Point taken, sorry. -- Cheers. Mark Lawrence. From gelonida at gmail.com Tue Aug 7 04:00:16 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 07 Aug 2012 10:00:16 +0200 Subject: find out whether a module exists (without importing it) In-Reply-To: <20120807064331.GA31774@terra.cms.at> References: <20120807064331.GA31774@terra.cms.at> Message-ID: <5020CB10.2020608@gmail.com> Hi Michael, On 08/07/2012 08:43 AM, Michael Poeltl wrote: > in my opinion, "without importing it" makes it unnecessarily complicated. It does, but I think this is what I want, thus my question. I tried to keep my question simple without explaining too much. Well now here's a little more context. There's two reasons why I sepcified the without importing it. Some modules may have side effects when being imported,and sometimes I just want to check for a module's existence Second: Sometimes I only want to know, whether a module exists. I do not want to know whether a module is syntactically correct or whether a module if imported is capable of importing all it's submodules What I'd like to achieve at the moment is to distinguish three situations: - a module with a given name does not exist - a module with a given name exists and produces errors (might be ImportErors) - a module with a given name exists and can be imported In fact what I really want to achieve is: import a module if it exists (and fail if it is broken) if it doesn't exist import a 'default' module and go on. The name of the module is stored in a variable and is not known prior to running the script so the code, that you suggested would be something like. modulename = 'my.module' cmd = 'import %s as amodule' try: exec(cmd) print "imported successfully" except ImportError: print "module doesn't exist or the module tries to " \ "import another module that doesn't exist" # if the module doesn't exist I'd like to import a 'fallback' module # otherwise I'd like to abort. except Exception as exc: print "module exists, but is broken" raise exc amodule.do_something() > You just want to know it module xyz exists, or better said can be found > (sys.path). > > why not try - except[ - else ] > > try: > import mymodule > except ImportError: > # NOW YOU KNOW it does not exist > #+ and you may react properly > ?? > * Gelonida N [2012-08-06 22:49]: >> Is this possible. >> >> let's say I'd like to know whether I could import the module >> 'mypackage.mymodule', meaning, >> whther this module is located somewhere in sys.path >> >> i tried to use >> >> imp.find_module(), but >> it didn't find any module name containing a '.' >> >> Am I doing anything wrong? >> >> Is there another existing implementation, that helps. >> >> I could do this manually, but this is something I'd just like to do >> if necessary. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list From lipskathekat at yahoo.co.uk Tue Aug 7 04:16:48 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 09:16:48 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <5020a903$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a903$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/08/12 06:35, Steven D'Aprano wrote: > On Mon, 06 Aug 2012 10:24:10 +0100, lipska the kat wrote: > >> er, the point I was trying to make is that when you say 'interface' it >> could mean so many things. If you say 'facade' everyone knows exactly >> what you are talking about. And that is EXACTLY the point. > > The whole point of design patterns is to avoid getting stuck in > incidental implementation details of a particular library or class and > look for higher-level design patterns. > > The same applies to facade -- it's just a special case of the interface > pattern. So you AGREE with me, fantastic, what are we arguing about then (it's great fun though isn't it) facade is a SPECIAL case of interface. You seem to be missing this point. I may not be as smart or experienced as you but in my fairly wide experience of software projects of all sizes the biggest problem is one of communication. Design patterns, in my experience help with communication. I have designed and implemented many facades, I have also designed many interfaces. I do not think Java is the be all and end all of programming languages but it has paid off my mortgage and provided me with a good living. Python interests me because it is different. As far as I can see if I'm talking with a Pythonista or a Java developer or a hardware engineer (possibly) or a C++ guru or a university lecturer or an Eiffel developer and I say 'interface' they will all visualise something slightly different, if I say 'facade' they will all (hopefully) know EXACTLY what I am talking about. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From __peter__ at web.de Tue Aug 7 04:27:46 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Aug 2012 10:27:46 +0200 Subject: find out whether a module exists (without importing it) References: Message-ID: Gelonida N wrote: > Is this possible. > > let's say I'd like to know whether I could import the module > 'mypackage.mymodule', meaning, > whther this module is located somewhere in sys.path > > i tried to use > > imp.find_module(), but > it didn't find any module name containing a '.' You could look for the toplevel name and then look for modules in the corresponding directory. This is not always reliable as a package may not correspond to a directory (e. g.: os and os.path), but I don't think you can get any closer without performing an actual import. From rosuav at gmail.com Tue Aug 7 05:08:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Aug 2012 19:08:08 +1000 Subject: find out whether a module exists (without importing it) In-Reply-To: <5020CB10.2020608@gmail.com> References: <20120807064331.GA31774@terra.cms.at> <5020CB10.2020608@gmail.com> Message-ID: On Tue, Aug 7, 2012 at 6:00 PM, Gelonida N wrote: > modulename = 'my.module' > cmd = 'import %s as amodule' > try: > exec(cmd) > print "imported successfully" Someone will doubtless correct me if I'm wrong, but I think you can avoid exec here with: amodule=__import__(modulename) ChrisA From lipskathekat at yahoo.co.uk Tue Aug 7 05:19:31 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 10:19:31 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> On 07/08/12 06:19, Steven D'Aprano wrote: > On Mon, 06 Aug 2012 09:55:24 +0100, lipska the kat wrote: > >> On 06/08/12 01:22, Steven D'Aprano wrote: >>> On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: >>> [snip] >> >> The clue is in the name 'Object Oriented' ... anything else is (or >> should be) implementation detail. > > So your argument is that any programming which is "oriented" (meaning > what?) towards "objects" (which are...?) is OOP, and everything else is > "implementation detail". > > Well now I'm enlightened. That certainly clears that up for me. Glad I could help :-) [snip] > > As you go on to explain: > >> A class variable is static and can be >> accessed without instantiation an instance variable is accessed via an >> instance > > which are semantic differences, differences in meaning and function. Yes but when we TALK about these things a String variable is a String variable is a String variable. The words 'Class variable' and 'instance variable' are 'abstractions'. It saves us saying, 'this is a variable that can only be accessed from an instance and may hold values of the type Integer or String or Weak Reference ... (and so on ad nauseum) ... but only of one type unless you count runtime polymorphism in which case the runtime type may be different from the compile time type ... etc etc' or 'this is a variable that can be accessed without instantiating a class (see above)' If you don't like the term abstraction then perhaps we can agree on something else. >>> Since a "string variable" is a variable holding a string, and a "float >>> variable" is a variable holding a float, an instance variable should be >>> a variable holding an instance, and a class variable should be a >>> variable holding a class. See above >> Class variable and instance variable are higher level abstractions. > > Of what? Of variables? Exactly, now you're getting the hang of it [snip] > Simply put, the choice of terminology is crap -- possibly but it's the best we've got. > But what *really* gets me is not the existence of poor terminology. I > couldn't care less what terminology Java programmers use among > themselves. I'd be most grateful if you could park the whole 'This person is a 'Java developer so must be a moron thing' it's getting a bit wearing. As I said in a previous post, Java has indeed been good to me but my brain IS capable of dealing with more than one language. > What gets me is that the ubiquity of them means that > substandard terminology spreads into other languages, like dryrot. Yea well welcome to the world of spin, if you can't fight it then learn to roll with it. >>>> The ONLY concept that you should never try to encapsulate is/are human >>>> beings or their aliases. >> >> snip >> >>> Is this some sort of mystical "humans aren't objects, they're >>> SPECIAL!!!" rubbish? Because it sure sounds like it. [snip] Well now this is a personal thing born of bitter experience. In my experience, when you have an entity called 'Person' or some such in your Class model it soon becomes what we 'in the trade' call a 'God Object' The name should be self explanatory but hold tight, here comes some more jargon. Objects can have a 'has a' relationship with other Objects or an 'is a' relationship with other objects The 'has a' relationship means that an Object 'owns' another object, the 'is a' relationship means that an Object 'is of a particular type' Of course in an 'Object Oriented' language such as Java an Object reference can have a different type at runtime than it does at compile time. In Python too. Anyway, this Person thing soon ends up with a 'has a' relationship with everything in sight. a Person 'has a[n]' Address, a Person 'has a[n]' account, a Person 'has a' Doughnut etc etc etc Also, inevitably a Person 'is a' Customer, a Person 'is a' Contact, a Person 'is a' security risk, well you get the idea. Of course this is a problem with the actual design process itself and yes, the identification of the 'nouns in the language of the domain' is an important part of the process. Sorry, but it just works when it's done properly, I know it works as I used this technique to turn around this 'Person as God' design from a failing money pit into a working system that delivered (almost) on time. The very first thing I did was to exorcise Person from the design. >>>> I've already managed to write meaningful code but I haven't invented a >>>> single class yet. >>> >>> And why do you think this is a problem? >> >> A problem? I wasn't ware that I'd stated it was a problem it just > > You said "BUT [emphasis added] I haven't invented a single class yet", > which implies that this is a bad thing [snip] No it implies that I noticed it was possible to do meaningful work in Python without writing a class. Well this HAS been fun, I look forward to your reply but at the moment I have to go and pick some runner beans as it's been a fantastic year for beans and the freezer awaits. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From steve+comp.lang.python at pearwood.info Tue Aug 7 05:44:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 09:44:22 GMT Subject: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python) References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> Message-ID: <5020e376$0$29867$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Aug 2012 17:23:19 +0100, lipska the kat wrote: > On 06/08/12 13:19, rusi wrote: >> I suggest this >> http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of- nouns.html > > http://bpfurtado.livejournal.com/2006/10/21/ Unfortunately the author (Bruno Furtado) has missed the point. He seems to think that Kingdom of Nouns ("the Rant") is an anti-OO screed. It is not. There is more to OO than Java, and criticism of Java does not mean "objects are bad". Nor is it that Kingdom of Nouns believes the problem is "Two lines per source code file!!!". It isn't just that two extra lines when you declare a function. It is the extraneous, unnecessary extra layer each time you read (or write, but mostly read) the method, and the ever-more abstract, deep layers of Builders, Getters, Setters, Doers and so forth. In Python, occasionally you will come across code like this: value = time.time() which is the time function in the time module. Pretty skanky, right? It's not likely that you have a whole bunch of spam.time, foo.time, physics.time etc. in your code base, right? If you do, then maybe this is justified, but how often does that happen? Having that duplicated time.time is a code smell that says "you might have too many code layers here, better look at this a bit more closely". Now imagine if this was a more Java-ish language: value = time.time.time() where you have method time of class time in module time. And you have to call it that way *all the time* (pun not intended). That's not so much a "might" have too many layers, as "almost certainly". In Java, all those dot look-ups happen at compile time and are fast. In Python, they happen at runtime, and while they're still often fast, sometimes they can be slow. But that's not the real problem. The real problem is reading and writing it. Python solves that two ways: 1) Modules, classes, methods and functions are first-class objects, so you can do this: from time import time # or if you prefer, "import time; time = time.time" value = time() 2) It doesn't force you to use the same number of layers for *everything*. If you have code that will benefit from two, or three, or seventeen, layers, you are free to do so: value = (time.time() + spacetime.Time.time() - Spam.time.flavour() + Cube.time()) And if not, then don't: value = time() + spacetime.time() - flavour() + Cube.time() It is this which is the point of Kingdom of Nouns. It is not an anti-OO screed. It is not an argument against namespaces, or encapsulation, or especially not that Java methods take an extra "Two lines per source file". It is that Java forces a single mental model on you, all the time, whether it makes for better, more readable code or not. -- Steven From jarausch at igpm.rwth-aachen.de Tue Aug 7 06:13:09 2012 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 7 Aug 2012 10:13:09 GMT Subject: Procedure to request adding a module to the standard library - or initiating a vote on it Message-ID: Hi, I'd like to request adding the module http://pypi.python.org/pypi/regex to Python's standard library in the (near) future or to even replace the current 're' module by it. Personally I'm in need for fuzzy regular expressions and I don't see how to do this easily and efficiently without this module. For a long term project I also need some "guarantee" that this functionality will exist in future. So, is there a (formal) procedure for such a request or for initiating some sort of vote on it? I know there is a "Benevolent Dictator" for Python. Should I try to contact him personally? Many thanks for a hint, Helmut Jarausch RWTH Aachen University Germany From lipskathekat at yahoo.co.uk Tue Aug 7 06:23:35 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 11:23:35 +0100 Subject: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python) In-Reply-To: <5020e376$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <5020e376$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/08/12 10:44, Steven D'Aprano wrote: > On Mon, 06 Aug 2012 17:23:19 +0100, lipska the kat wrote: > >> On 06/08/12 13:19, rusi wrote: > >>> I suggest this >>> http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of- > nouns.html >> >> http://bpfurtado.livejournal.com/2006/10/21/ > > Unfortunately the author (Bruno Furtado) has missed the point. He seems Steve, chill out, you seem to have this whole Javahate thing going at the moment. It's just a language, like Python. You can write crap code in Java just like you can write crap code in any language. Just for the record 'Time' is way too complex a concept to encapsulate in a single class (we can debate that if you like although it all gets a bit philosophical) If you MUST have a Time Object in Java you can instantiate java.sql.Time, not really that complicated is it ? I do enjoy debating with you but really, lighten up a bit, it really isn't that important, mankind existed for millenia before computers and programming languages. If we want to exist for millenia after their invention then we need to get off this planet. If you want to get excited about something then get excited about our apparent inability to exceed the speed of light. Until we solve that one we are doomed. I'm thinking of adding a line to my sig for this group that says "I don't hate Python, I like it for it's differences" ;-) lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From __peter__ at web.de Tue Aug 7 07:15:29 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Aug 2012 13:15:29 +0200 Subject: Procedure to request adding a module to the standard library - or initiating a vote on it References: Message-ID: Helmut Jarausch wrote: > I'd like to request adding the module > > http://pypi.python.org/pypi/regex > > to Python's standard library in the (near) future or to even replace the > current 're' module by it. > > Personally I'm in need for fuzzy regular expressions and I don't see how > to do this easily and efficiently without this module. > > For a long term project I also need some "guarantee" that this > functionality will exist in future. There has been a discussion about that particular module, and it would have gone into 3.3 if it were not for the low "bus count" (only the author having working knowledge of the code). > So, is there a (formal) procedure for such a request or for initiating > some sort of vote on it? > > I know there is a "Benevolent Dictator" for Python. > Should I try to contact him personally? I don't think that will help. From PEP 408: """ As part of the same announcement, Guido explicitly accepted Matthew Barnett's 'regex' module [4] as a provisional addition to the standard library for Python 3.3 (using the 'regex' name, rather than as a drop-in replacement for the existing 're' module). """ From hyperboogie at gmail.com Tue Aug 7 07:21:14 2012 From: hyperboogie at gmail.com (S.B) Date: Tue, 7 Aug 2012 04:21:14 -0700 (PDT) Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: <02cdd15c-2517-48fc-96e5-24a094b0b850@googlegroups.com> On Monday, August 6, 2012 4:32:13 PM UTC+3, S.B wrote: > Hello friends > > > > Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: > > First host pickles a file object and writes the pickled file object to a client socket. > > Second host reads the pickled file object from the server socket and un-pickles it. > > > > Can anyone provide a simple code example of the client and server sides? > > > > Thanks Lot's of conflicting answers :-( Can anyone provide a simple code example? From maniandram01 at gmail.com Tue Aug 7 08:40:18 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 7 Aug 2012 18:10:18 +0530 Subject: find out whether a module exists (without importing it) In-Reply-To: References: <20120807064331.GA31774@terra.cms.at> <5020CB10.2020608@gmail.com> Message-ID: You are correct. On 7 August 2012 14:38, Chris Angelico wrote: > On Tue, Aug 7, 2012 at 6:00 PM, Gelonida N wrote: > > modulename = 'my.module' > > cmd = 'import %s as amodule' > > try: > > exec(cmd) > > print "imported successfully" > > Someone will doubtless correct me if I'm wrong, but I think you can > avoid exec here with: > > amodule=__import__(modulename) > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Tue Aug 7 09:00:25 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 07 Aug 2012 09:00:25 -0400 Subject: Object Models - decoupling data access - good examples ? In-Reply-To: References: Message-ID: <1344344425.3456.2.camel@linux-nysu.site> On Sat, 2012-08-04 at 20:26 -0700, shearichard at gmail.com wrote: > > > > Just out of curiosity, why do you eschew ORMs? > Good question ! > I'm not anti-ORM (in fact in many circs I'm quite pro-ORM) but for > some time I've been working with a client who doesn't want ORMs used > (they do have quite good reasons for this although probably not as > good as they think). So call the ORM something else. > I was interested to know, given that was the case, how you might - in > Python, go about structuring an app which didn't use an ORM but which > did use a RDBMS fairly intensively. You'd reinvent the ORM calling it something else - because an ORM is what you are describing. This is just a case of those-who-will-not-use-are-doomed-to-recreate. > I take your point about having "rolled my own ORM" - lol - but I can > assure you what's in that 'bardb' is a pretty thin layer over the SQL > and nothing like the, pretty amazing, functionality of, for instance, > >SQLAlchemy. This implies that SQLAlchemy is 'fat'. I don't see any evidence of that. It is comprehensive so when you encounter something you can be confident it is up to the challange. -------------- 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 lipskathekat at yahoo.co.uk Tue Aug 7 09:07:11 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 14:07:11 +0100 Subject: Pickle file and send via socket In-Reply-To: <02cdd15c-2517-48fc-96e5-24a094b0b850@googlegroups.com> References: <02cdd15c-2517-48fc-96e5-24a094b0b850@googlegroups.com> Message-ID: On 07/08/12 12:21, S.B wrote: >> >> >> >> Can anyone provide a simple code example of the client and server sides? Working on it lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From ben+python at benfinney.id.au Tue Aug 7 09:12:43 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Aug 2012 23:12:43 +1000 Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> Message-ID: <87y5lqj16c.fsf@benfinney.id.au> lipska the kat writes: > >>>> The ONLY concept that you should never try to encapsulate is/are > >>>> human beings or their aliases. You stated this in absolute, dogmatic terms. I thought at first you were being hyperbolic for effect, but the situation that you present to support this dogma is one where I can't see anyone rationally concluding the dogma applies. > Well now this is a personal thing born of bitter experience. In my > experience, when you have an entity called 'Person' or some such in > your Class model it soon becomes what we 'in the trade' call a 'God > Object' The name should be self explanatory but hold tight, here comes > some more jargon. God objects are a code smell (another term of art, meaning a symptom in the code that tends to indicate poor design or some other fundamental flaw). But what you're describing below doesn't fit. > Objects can have a 'has a' relationship with other Objects or an 'is a' > relationship with other objects > > The 'has a' relationship means that an Object 'owns' another object, > the is a' relationship means that an Object 'is of a particular type' > Of course in an 'Object Oriented' language such as Java an Object > reference can have a different type at runtime than it does at compile > time. In Python too. > > Anyway, this Person thing soon ends up with a 'has a' relationship > with everything in sight. a Person 'has a[n]' Address, a Person 'has > a[n]' account, a Person 'has a' Doughnut etc etc etc > > Also, inevitably a Person 'is a' Customer, a Person 'is a' Contact, a > Person 'is a' security risk, well you get the idea. This accurately reflects the reality that ?person? is a real-world entity very frequently involved in just about anything a typical system needs to model. > Of course this is a problem with the actual design process itself What problem? If the real-world entity really exists and the ?has-a? and ?is-a? relationships really exist, then it's *good* design to model whatever ones of those are significant to the operation of the program. Indeed, it would be *bad* design to avoid modelling the real world merely because of dogma against modelling persons and their relationships to other entities. If there were entities or relationships that were needlessly cumbersome ? if indeed the object was trying to encapsulate the majority of the whole world in itself ? then those should be removed from the object, and perhaps even from the design. But that's not what you describe. A Person entity in inheritance or composition relationships with other classes and objects is not a god object, since it is sensibly delegating specific jobs to places other than itself. That's very good, modular design. And when the real domain to be modelled almost certainly has people as a central entity in complex interactions, removing Person from the design entirely is poor work grounded in irrationality. -- \ ?I am amazed, O Wall, that you have not collapsed and fallen, | `\ since you must bear the tedious stupidities of so many | _o__) scrawlers.? ?anonymous graffiti, Pompeii, 79 CE | Ben Finney From roy at panix.com Tue Aug 7 09:18:26 2012 From: roy at panix.com (Roy Smith) Date: Tue, 07 Aug 2012 09:18:26 -0400 Subject: I thought I understood how import worked... Message-ID: I've been tracking down some weird import problems we've been having with django. Our settings.py file is getting imported twice. It has some non-idempotent code in it, and we blow up on the second import. I thought modules could not get imported twice. The first time they get imported, they're cached, and the second import just gets you a reference to the original. Playing around, however, I see that it's possible to import a module twice if you refer to it by different names. Here's a small-ish test case which demonstrates what I'm talking about (python 2.6.5): In directory /home/roy/play/import/foo, I've got: __init__.py (empty file) try.py broken.py $ cat broken.py print __file__ $ cat try.py import broken import foo.broken import sys for m in sys.modules.items(): if m[0].endswith('broken'): print m And when I run try.py (with foo as the current directory): $ PYTHONPATH=/home/roy/play/import python try.py /home/roy/play/import/foo/broken.pyc /home/roy/play/import/foo/broken.pyc ('broken', ) ('foo.broken', ) So, it appears that you *can* import a module twice, if you refer to it by different names! This is surprising. It means that having non-idempotent code which is executed at import time is a Bad Thing. It also means that you could have multiple copies of a module's global namespace, depending on how your users imported the module. Which is kind of mind-blowing. From clickfirm2007 at gmail.com Tue Aug 7 09:19:51 2012 From: clickfirm2007 at gmail.com (Mohamed Gad) Date: Tue, 7 Aug 2012 06:19:51 -0700 (PDT) Subject: ~~** The Truth About Abs >> Download Now.!! **~~ Message-ID: The Truth About Abs review site is your guide to the truth about six pack abs #1 program created for both men and women who are looking to get ripped. It is especially good for those individuals seeking a program which will show them how to get 6 pack abs. ==> http://www.book-mall.com/truth-about-abs-review/ We will take a look at the pros and cons of this unique program that combines Fat Loss with Muscle Building. I will also be adding regular updated info on weight loss and muscle building to help you get the kind of Abs you have always wanted. Don't miss this offer . ==> http://www.book-mall.com/truth-about-abs-review/ From maniandram01 at gmail.com Tue Aug 7 09:28:20 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 7 Aug 2012 18:58:20 +0530 Subject: I thought I understood how import worked... In-Reply-To: References: Message-ID: I don't think the modules are actually imported twice. The entry is just doubled;that's all On 7 August 2012 18:48, Roy Smith wrote: > I've been tracking down some weird import problems we've been having with > django. Our settings.py file is getting imported twice. It has some > non-idempotent code in it, and we blow up on the second import. > > I thought modules could not get imported twice. The first time they get > imported, they're cached, and the second import just gets you a reference > to the > original. Playing around, however, I see that it's possible to import a > module > twice if you refer to it by different names. Here's a small-ish test case > which > demonstrates what I'm talking about (python 2.6.5): > > In directory /home/roy/play/import/foo, I've got: > > __init__.py (empty file) > try.py > broken.py > > > $ cat broken.py > print __file__ > > > $ cat try.py > import broken > import foo.broken > > import sys > for m in sys.modules.items(): > if m[0].endswith('broken'): > print m > > > And when I run try.py (with foo as the current directory): > > $ PYTHONPATH=/home/roy/play/import python try.py > /home/roy/play/import/foo/broken.pyc > /home/roy/play/import/foo/broken.pyc > ('broken', ) > ('foo.broken', '/home/roy/play/import/foo/broken.pyc'>) > > > So, it appears that you *can* import a module twice, if you refer to it by > different names! This is surprising. It means that having non-idempotent > code > which is executed at import time is a Bad Thing. > > It also means that you could have multiple copies of a module's global > namespace, depending on how your users imported the module. Which is kind > of > mind-blowing. > -- > 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 7 09:52:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 13:52:59 GMT Subject: I thought I understood how import worked... References: Message-ID: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Aug 2012 09:18:26 -0400, Roy Smith wrote: > I thought modules could not get imported twice. The first time they get > imported, they're cached, and the second import just gets you a > reference to the original. Playing around, however, I see that it's > possible to import a module twice if you refer to it by different names. Yes. You've found a Python gotcha. The most common example of this is when a single file acts as both an importable module, and as a runnable script. When run as a script, it is known as "__main__". When imported, it is known by the file name. Unless you take care, it is easy to end up with the module imported twice. The usual advice is "never have one module used as both script and importable module". I think *never* is a bit strong, but if you do so, you need to take extra care. > Here's a small-ish test case which demonstrates what I'm talking about > (python 2.6.5): > > In directory /home/roy/play/import/foo, I've got: > > __init__.py (empty file) > try.py > broken.py Aside: calling a module "try.py" is asking for trouble, because you can't do this: import try > $ cat broken.py > print __file__ > > > $ cat try.py > import broken > import foo.broken Which are two names for the same module. > So, it appears that you *can* import a module twice, if you refer to it > by different names! This is surprising. It means that having > non-idempotent code which is executed at import time is a Bad Thing. Well yes. In general, you should avoid non-idempotent code. You should doubly avoid it during imports, and triply avoid it on days ending with Y. The rest of the time, it is perfectly safe to have non-idempotent code. :) I kid, of course, but only half. Side-effects are bad, non-idempotent code is bad, and you should avoid them as much as possible, and unless you have no other reasonable choice. > It also means that you could have multiple copies of a module's global > namespace, depending on how your users imported the module. Which is > kind of mind-blowing. Oh that part is trivial. Module namespaces are just dicts, there's nothing special about them. py> import math # for example py> import copy py> namespace = copy.deepcopy(math.__dict__) py> math.__dict__ == namespace True py> math.__dict__ is namespace False It are modules which should be special, and Python tries really hard to ensure that they are singletons. (Multitons?) But not superhumanly hard. -- Steven From ben+python at benfinney.id.au Tue Aug 7 09:55:16 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Aug 2012 23:55:16 +1000 Subject: I thought I understood how import worked... References: Message-ID: <87txweiz7f.fsf@benfinney.id.au> Roy Smith writes: > So, it appears that you *can* import a module twice, if you refer to > it by different names! This is surprising. The tutorial is misleading on this. It it says plainly: A module can contain executable statements as well as function definitions. [?] They are executed only the *first* time the module is imported somewhere. but it doesn't make clear that a module can exist in the ?sys.modules? list multiple times under different names. Care to file a documentation bug describing this? > It means that having non-idempotent code which is executed at import > time is a Bad Thing. This is true whether or not the above about module imports is true. A well-designed module should have top level code that performs idempotent actions. Be thankful that you've discovered this, and apply it well :-) -- \ ?See, in my line of work you gotta keep repeating things over | `\ and over and over again, for the truth to sink in; to kinda | _o__) catapult the propaganda.? ?George W. Bush, 2005-05 | Ben Finney From breamoreboy at yahoo.co.uk Tue Aug 7 10:03:51 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 07 Aug 2012 15:03:51 +0100 Subject: Procedure to request adding a module to the standard library - or initiating a vote on it In-Reply-To: References: Message-ID: On 07/08/2012 11:13, Helmut Jarausch wrote: > Hi, > > I'd like to request adding the module > > http://pypi.python.org/pypi/regex > > to Python's standard library in the (near) future or to even replace the > current 're' module by it. > > Personally I'm in need for fuzzy regular expressions and I don't see how > to do this easily and efficiently without this module. > > For a long term project I also need some "guarantee" that this > functionality will exist in future. > > So, is there a (formal) procedure for such a request or for initiating > some sort of vote on it? > > I know there is a "Benevolent Dictator" for Python. > Should I try to contact him personally? > > Many thanks for a hint, > > Helmut Jarausch > > RWTH Aachen University > Germany > My understanding is that the main stumbling block is there's no one committed to being the maintainer of the code. If that commitment is not made, and I belive it's required to be several (10?) years, then the code may never get into the standard library. I'll happily stand corrected if anyone knows any better. -- Cheers. Mark Lawrence. From jdildy85 at gmail.com Tue Aug 7 10:09:37 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Tue, 7 Aug 2012 07:09:37 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <501FEB5E.6050506@stoneleaf.us> <8i4028d5rlcjbv73jra8sg2c2bgg7n6u1o@invalid.netcom.com> Message-ID: <2ee42d8f-4378-41c5-9c6a-bc5364da34e6@googlegroups.com> On Monday, August 6, 2012 11:39:45 PM UTC-4, Dennis Lee Bieber wrote: > On Tue, 7 Aug 2012 07:59:44 +1000, Chris Angelico > > declaimed the following in gmane.comp.python.general: > > > > > On Tue, Aug 7, 2012 at 5:22 AM, Dennis Lee Bieber wrote: > > > > So am I beginner, intermediate, advanced, expert? > > > > > > I wonder would this sort of a scale help: > > > > > > http://www.geekcode.com/geek.html#perl > > > > > > Novice: P > > > Intermediate: P+ or P++ > > > Advanced: P+++ > > > Master: P++++ > > > > > Surely we can rise above mere "pluses" and rank using "stars" (*) -- > > a four-star Pythoneer (or whatever the preferred term is)? > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ No matter what level you are in python you will still make mistakes every once in a while but if your like a expert you just notice it faster From jdildy85 at gmail.com Tue Aug 7 10:09:37 2012 From: jdildy85 at gmail.com (John Mordecai Dildy) Date: Tue, 7 Aug 2012 07:09:37 -0700 (PDT) Subject: Intermediate Python user needed help In-Reply-To: References: <501FEB5E.6050506@stoneleaf.us> <8i4028d5rlcjbv73jra8sg2c2bgg7n6u1o@invalid.netcom.com> Message-ID: <2ee42d8f-4378-41c5-9c6a-bc5364da34e6@googlegroups.com> On Monday, August 6, 2012 11:39:45 PM UTC-4, Dennis Lee Bieber wrote: > On Tue, 7 Aug 2012 07:59:44 +1000, Chris Angelico > > declaimed the following in gmane.comp.python.general: > > > > > On Tue, Aug 7, 2012 at 5:22 AM, Dennis Lee Bieber wrote: > > > > So am I beginner, intermediate, advanced, expert? > > > > > > I wonder would this sort of a scale help: > > > > > > http://www.geekcode.com/geek.html#perl > > > > > > Novice: P > > > Intermediate: P+ or P++ > > > Advanced: P+++ > > > Master: P++++ > > > > > Surely we can rise above mere "pluses" and rank using "stars" (*) -- > > a four-star Pythoneer (or whatever the preferred term is)? > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ No matter what level you are in python you will still make mistakes every once in a while but if your like a expert you just notice it faster From breamoreboy at yahoo.co.uk Tue Aug 7 10:10:35 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 07 Aug 2012 15:10:35 +0100 Subject: I thought I understood how import worked... In-Reply-To: References: Message-ID: On 07/08/2012 14:28, Ramchandra Apte wrote: > I don't think the modules are actually imported twice. The entry is just > doubled;that's all > Please don't top post, this is the third time of asking. -- Cheers. Mark Lawrence. From lipskathekat at yahoo.co.uk Tue Aug 7 10:13:05 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 15:13:05 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <87y5lqj16c.fsf@benfinney.id.au> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <87y5lqj16c.fsf@benfinney.id.au> Message-ID: On 07/08/12 14:12, Ben Finney wrote: > lipska the kat writes: > >>>>>> The ONLY concept that you should never try to encapsulate is/are >>>>>> human beings or their aliases. > > You stated this in absolute, dogmatic terms. I thought at first you were > being hyperbolic for effect, but the situation that you present to > support this dogma is one where I can't see anyone rationally concluding > the dogma applies. Ah, you mean you don't agree. >> Well now this is a personal thing born of bitter experience. [snip] >> Also, inevitably a Person 'is a' Customer, a Person 'is a' Contact, a >> Person 'is a' security risk, well you get the idea. > > This accurately reflects the reality that ?person? is a real-world > entity very frequently involved in just about anything a typical system > needs to model. No, you are wrong. Having a Person class is profoundly and fundamentally wrong. If we follow this argument then every system ever modelled would have a Person at it's heart. I think you are missing the point here. You say. > This accurately reflects the reality that ?person? is a real-world > entity very frequently involved in just about anything a typical stem > needs to model. that a "person" is a real-world entity very >frequently Have asserted that you are profoundly wrong I now have to say that I couldn't agree more BUT with the crucial modifier that a person is an "actor" I don't care if you like or dislike the terminology, you get the general idea. An actor exists outside the system. Having a Person in the Class model tends to blur the boundaries between system and users. I know it does, I've seen it happen so many times. It's all about how we think about a system in the early stages of design The moment we introduce a Person (or alias for a Person) we confuse our thinking, are we thinking about Person as actor or are we thinking about Person as entity in our system. This is not some nebulous flight of fancy, this is born of real world, stand at the whiteboard and thrash out a design experience. I have been ridiculed before, strangely enough, once the Person has been expunged from the system mind things go a whole lot more smoothly. >> Of course this is a problem with the actual design process itself > > What problem? If the real-world entity really exists and the ?has-a? and > ?is-a? relationships really exist, then it's *good* design to model > whatever ones of those are significant to the operation of the program. > > Indeed, it would be *bad* design to avoid modelling the real world > merely because of dogma against modelling persons and their > relationships to other entities. Dogma is an emotive word that you are using to belittle the idea. That's fine, you asked me to explain myself and I have done so. [snip] > And when the real domain to be modelled almost certainly has people as a > central entity in complex interactions, removing Person from the design > entirely is poor work grounded in irrationality. Well I say it's sound judgment grounded in experience and most if not all my employers seem to agree. I have thousands of lines of code 'in the wild' operating without fault day after week after year and not one single line refers to, implies or otherwise represents a "Person" in any way whatsoever. Just one tiny point, I NEVER have to 'remove' a Person from my designs as they never get through the door in the first place. The only time I have ever had to agree that a "Person" belongs in a computer is when I saw Tron. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From gandalf at shopzeus.com Tue Aug 7 10:14:15 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 07 Aug 2012 16:14:15 +0200 Subject: I thought I understood how import worked... In-Reply-To: <87txweiz7f.fsf@benfinney.id.au> References: <87txweiz7f.fsf@benfinney.id.au> Message-ID: <502122B7.3040008@shopzeus.com> On 2012-08-07 15:55, Ben Finney wrote: > Roy Smith writes: > >> So, it appears that you *can* import a module twice, if you refer to >> it by different names! This is surprising. > The tutorial is misleading on this. It it says plainly: > > A module can contain executable statements as well as function > definitions. [?] They are executed only the *first* time the module > is imported somewhere. > > > > but it doesn't make clear that a module can exist in the ?sys.modules? > list multiple times under different names. sys.modules is a dict. But yes, there can be multiple "instances" of the same module loaded. What I do with bigger projects is that I always use absolute module names. For example, when I develop a project called "project1" that has several sub packages, then I always do these kinds of imports: from project1.package1.subpackage2.submodule3 import * from project1.package1.subpackage2 import submodule3 from project1.package1.subpackage2.submodule3 import some_class Even from a source file that is inside project1.package1.subpackage2, I tend to import them the same way. This makes sure that every module is imported under the same package path. You just need to make sure that the main project has a unique name (which is usually the case) and that it is on your sys path (which is usually the case, especially when the script is started in the project's directory). The cost is that you have to type more. The benefit is that you can be sure that you are importing the thing that you want to import, and there will be no multiple imports for the same module. Mabye somebody will give method that works even better. For small projects without sub-packages, it is not a problem. Best, Laszlo From steve+comp.lang.python at pearwood.info Tue Aug 7 10:14:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 14:14:39 GMT Subject: [newbie] Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> Message-ID: <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Aug 2012 10:19:31 +0100, lipska the kat wrote: > On 07/08/12 06:19, Steven D'Aprano wrote: [...] >> But what *really* gets me is not the existence of poor terminology. I >> couldn't care less what terminology Java programmers use among >> themselves. > > I'd be most grateful if you could park the whole 'This person is a 'Java > developer so must be a moron thing' it's getting a bit wearing. Lipska, it's not always about you. I've been hanging around this forum for, oh, at least six years now. Trust me, you're not the first Java developer brave enough to poke their head up :) Java coders who come here tend to talk about "instance variables". C++ coders tend to talk about "members". Haskell people don't tend to talk much about objects at all. And PHP coders tend to talk about how they saw Spot run. (I kid. Sorry PHP coders, I couldn't resist.) It's not about being a moron. Anyone new to a language is going to carry across preconceptions from their previous language, and use the terminology they're used to. I've seen more than one Lisper assume that Python lists are linked lists and wonder how to call car and cdr, and nobody is accusing Lispers of being dumb. And I'm not going to even try to describe the misconceptions I had learning Python, coming from a background of Pascal, RPN and Hypertalk -- the first two languages weren't OOP, and Hypertalk's OOP model was *very* different from Python's. Don't think that every time I mention Java it's a dig at you. -- Steven From lipskathekat at yahoo.co.uk Tue Aug 7 10:34:59 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 15:34:59 +0100 Subject: [newbie] Looking for a good introduction to object oriented programming with Python In-Reply-To: <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/08/12 15:14, Steven D'Aprano wrote: > On Tue, 07 Aug 2012 10:19:31 +0100, lipska the kat wrote: > >> On 07/08/12 06:19, Steven D'Aprano wrote: > [...] >>> But what *really* gets me is not the existence of poor terminology. I >>> couldn't care less what terminology Java programmers use among >>> themselves. >> >> I'd be most grateful if you could park the whole 'This person is a 'Java >> developer so must be a moron thing' it's getting a bit wearing. > > Lipska, it's not always about you. Never thought so for a moment, good to know you can be reasonable as well as misguided ;-) lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jarausch at skynet.be Tue Aug 7 10:47:57 2012 From: jarausch at skynet.be (Helmut Jarausch) Date: 07 Aug 2012 14:47:57 GMT Subject: Procedure to request adding a module to the standard library - or initiating a vote on it References: Message-ID: <50212a9d$0$3115$ba620e4c@news.skynet.be> On Tue, 07 Aug 2012 13:15:29 +0200, Peter Otten wrote: > I don't think that will help. From PEP 408: > > """ > As part of the same announcement, Guido explicitly accepted Matthew > Barnett's 'regex' module [4] as a provisional addition to the standard > library for Python 3.3 (using the 'regex' name, rather than as a drop-in > replacement for the existing 're' module). > """ What is a "provisional addition"? Python-3.3 (20120708) doesn't have such a module. Many thanks, Helmut. From rustompmody at gmail.com Tue Aug 7 11:04:33 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 7 Aug 2012 08:04:33 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 7, 7:34?pm, lipska the kat wrote: > > Never thought so for a moment, good to know you can be reasonable as > well as misguided ;-) Well Lipska I must say that I find something resonant about the 'no- person' thing, though I am not sure what. You also said something about 'user' being more acceptable. From a different (opposite?) angle Dijkstra seems to be saying the same thing, here: http://www.cs.utexas.edu/~EWD/transcriptions/EWD06xx/EWD618.html Wonder what you make of it? From breamoreboy at yahoo.co.uk Tue Aug 7 11:04:56 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 07 Aug 2012 16:04:56 +0100 Subject: Procedure to request adding a module to the standard library - or initiating a vote on it In-Reply-To: <50212a9d$0$3115$ba620e4c@news.skynet.be> References: <50212a9d$0$3115$ba620e4c@news.skynet.be> Message-ID: On 07/08/2012 15:47, Helmut Jarausch wrote: > On Tue, 07 Aug 2012 13:15:29 +0200, Peter Otten wrote: > >> I don't think that will help. From PEP 408: >> >> """ >> As part of the same announcement, Guido explicitly accepted Matthew >> Barnett's 'regex' module [4] as a provisional addition to the standard >> library for Python 3.3 (using the 'regex' name, rather than as a drop-in >> replacement for the existing 're' module). >> """ > > What is a "provisional addition"? Python-3.3 (20120708) doesn't have > such a module. > > Many thanks, > Helmut. > This is a new concept, as an example see http://bugs.python.org/issue14814#msg164795 which refers to the implementation of PEP 3144, the ipaddress module. -- Cheers. Mark Lawrence. From __peter__ at web.de Tue Aug 7 11:07:02 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Aug 2012 17:07:02 +0200 Subject: Procedure to request adding a module to the standard library - or initiating a vote on it References: <50212a9d$0$3115$ba620e4c@news.skynet.be> Message-ID: Helmut Jarausch wrote: > On Tue, 07 Aug 2012 13:15:29 +0200, Peter Otten wrote: > >> I don't think that will help. From PEP 408: >> >> """ >> As part of the same announcement, Guido explicitly accepted Matthew >> Barnett's 'regex' module [4] as a provisional addition to the standard >> library for Python 3.3 (using the 'regex' name, rather than as a drop-in >> replacement for the existing 're' module). >> """ > > What is a "provisional addition"? My understanding is that Guido agreed for it to be added under a different name (i. e. as regex, not re) and with no guarantees that it will remain in Python versions above 3.3. > Python-3.3 (20120708) doesn't have such a module. Indeed. Guido allowed adding the module, but some core devs remained skeptical and no one put in the legwork to add it. It may still be added in 3.4 if a core developer is willing to familiarise with the codebase and promises to help with maintenance, but the chances seem low by now. From roy at panix.com Tue Aug 7 11:25:43 2012 From: roy at panix.com (Roy Smith) Date: Tue, 7 Aug 2012 08:25:43 -0700 (PDT) Subject: I thought I understood how import worked... In-Reply-To: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1fca6543-2c01-4f31-8ca7-a81b42b2e4a5@googlegroups.com> On Tuesday, August 7, 2012 9:52:59 AM UTC-4, Steven D'Aprano wrote: > In general, you should avoid non-idempotent code. You should > doubly avoid it during imports, and triply avoid it on days ending with Y. I don't understand your aversion to non-idempotent code as a general rule. Most code is non-idempotent. Surely you're not saying we should never write: >>> foo += 1 or >>> my_list.pop() ??? Making top-level module code idempotent, I can understand (given this new-found revelation that modules aren't really singletons), but you seem to be arguing something stronger and more general. From tgdrape at gmail.com Tue Aug 7 11:30:15 2012 From: tgdrape at gmail.com (Thomas Draper) Date: Tue, 7 Aug 2012 08:30:15 -0700 (PDT) Subject: Unexpected behavior using contextmanager on a class method Message-ID: I want to use with..as in a "reversible circuit generator". However, it seems that @contextmanager changes the expected nature of the class. I tried to distill the problem down to a simple example. import contextlib class SymList: def __init__(self, L=[]): self.L = L @contextlib.contextmanager def SymAdd(self, a): self.L.append(a) yield self.L.append(a) SL = SymList() with SL.SymAdd(3): SL.L.append(5) print(SL.L) # Expect and see [3, 5, 3] SL2 = SymList() # New object. Should have default values. print(SL2.L) # Expect [] and see [3, 5, 3] Why is the data member SL2.L referring to the data member SL.L? Has the @contextmanager somehow made all instantions of the class related? From roy at panix.com Tue Aug 7 11:32:50 2012 From: roy at panix.com (Roy Smith) Date: Tue, 7 Aug 2012 08:32:50 -0700 (PDT) Subject: I thought I understood how import worked... In-Reply-To: <87txweiz7f.fsf@benfinney.id.au> References: <87txweiz7f.fsf@benfinney.id.au> Message-ID: On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote: > The tutorial is misleading on this. It it says plainly: > > A module can contain executable statements as well as function > definitions. [?] They are executed only the *first* time the module > is imported somewhere. > > That's more than misleading. It's plain wrong. The example I gave demonstrates the "print __file__" statement getting executed twice. The footnote to that is wrong too: > [1] In fact function definitions are also ?statements? that are ?executed?; the execution of a > module-level function enters the function name in the module?s global symbol table. I think what it's supposed to say is "... the execution of a module-level def statement ..." > Care to file a documentation bug > describing this? Sure, once I understand how it's really supposed to work :-) From nobody at nowhere.com Tue Aug 7 11:32:55 2012 From: nobody at nowhere.com (Nobody) Date: Tue, 07 Aug 2012 16:32:55 +0100 Subject: looking for a neat solution to a nested loop problem References: Message-ID: On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: >> for i in range(N,N+100): >> for j in range(M,M+100): >> do_something(i % 100 ,j % 100) >> >> Emile > > How about... > > for i in range(100): > for j in range(100): > do_something((i + N) % 100, (j + M) % 100) Both of these approaches move the modifications to the sequence into the body of the loop. It may be preferable to iterate over the desired sequence directly. E.g. for i in ((N + ii) % 100 for ii in xrange(100)): for j in ((M + jj) % 100 for jj in xrange(100)): do_something(i, j) From fred.sells at adventistcare.org Tue Aug 7 11:46:44 2012 From: fred.sells at adventistcare.org (Sells, Fred) Date: Tue, 7 Aug 2012 15:46:44 +0000 Subject: Object Models - decoupling data access - good examples ? In-Reply-To: References: Message-ID: Given that "the customer is always right": In the past I've dealt with this situation by creating one or more "query" classes and one or more edit classes. I found it easier to separate these. I would then create basic methods like EditStaff.add_empooyee(**kwargs) inside of which I would drop into (in my case) MySQLdb. In retrospect, I'm not sure that the generick use of **kwargs was a good solution in that it masked what I was passing in, requiring me to go back to the calling code when debugging. OTOH it allowed me to be pretting generic by using Sql = sql_template % kwargs On the query side. I would convert the returned list of dictionaries to a list of objects using something like Class DBrecord: Def __init__(self, **kwargs): Self.__dict__.update(kwargs) So that I did not have to use the record['fieldname'] syntax but could use record.fieldname. I would describe myself as more of a survivalist programmer, lacking some of the sophisticated techniques of others on the mailing list so take that into account. Fred. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org] On Behalf Of shearichard at gmail.com Sent: Saturday, August 04, 2012 11:26 PM To: python-list at python.org Subject: Re: Object Models - decoupling data access - good examples ? > > Just out of curiosity, why do you eschew ORMs? > Good question ! I'm not anti-ORM (in fact in many circs I'm quite pro-ORM) but for some time I've been working with a client who doesn't want ORMs used (they do have quite good reasons for this although probably not as good as they think). I was interested to know, given that was the case, how you might - in Python, go about structuring an app which didn't use an ORM but which did use a RDBMS fairly intensively. I take your point about having "rolled my own ORM" - lol - but I can assure you what's in that 'bardb' is a pretty thin layer over the SQL and nothing like the, pretty amazing, functionality of, for instance, SQLAlchemy. -- http://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Tue Aug 7 11:53:10 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Aug 2012 08:53:10 -0700 Subject: I thought I understood how import worked... References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> <1fca6543-2c01-4f31-8ca7-a81b42b2e4a5@googlegroups.com> Message-ID: <7xa9y6bswp.fsf@ruckus.brouhaha.com> Roy Smith writes: >> In general, you should avoid non-idempotent code. > I don't understand your aversion to non-idempotent code as a general > rule. Most code is non-idempotent. Surely you're not saying we > should never write: >>>> foo += 1 > or >>>> my_list.pop() > ??? I don't think "in general avoid" means the same thing as "never write". One of the tenets of the functional-programming movement is that it is in fact reasonable to write in a style that avoids "foo += 1" and "my_list.pop()" most of the time, leading to cleaner, more reliable code. In Python it's not possible to get rid of ALL of the data mutation without horrendous contortions, but it's pretty easy (and IMHO of worthwhile benefit) to avoid quite a lot of it. From __peter__ at web.de Tue Aug 7 12:04:29 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Aug 2012 18:04:29 +0200 Subject: Unexpected behavior using contextmanager on a class method References: Message-ID: Thomas Draper wrote: > I want to use with..as in a "reversible circuit generator". However, it > seems that @contextmanager changes the expected nature of the class. I > tried to distill the problem down to a simple example. > > import contextlib > > class SymList: The problem you experience has nothing to do with context managers, you have a mutable default argument in your __init__(). > def __init__(self, L=[]): L is initialised with an empty list exactly once, when the method is defined; any changes you make to the list will be seen by all instances that use the default. The fix is def __init__(self, L=None): if L is None: L = [] > self.L = L > > @contextlib.contextmanager > def SymAdd(self, a): > self.L.append(a) > yield > self.L.append(a) > > SL = SymList() > with SL.SymAdd(3): > SL.L.append(5) > print(SL.L) # Expect and see [3, 5, 3] > SL2 = SymList() # New object. Should have default values. > print(SL2.L) # Expect [] and see [3, 5, 3] > > Why is the data member SL2.L referring to the data member SL.L? Has the > @contextmanager somehow made all instantions of the class related? From benjamin.kaplan at case.edu Tue Aug 7 12:38:41 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 7 Aug 2012 09:38:41 -0700 Subject: I thought I understood how import worked... In-Reply-To: References: <87txweiz7f.fsf@benfinney.id.au> Message-ID: On Aug 7, 2012 8:41 AM, "Roy Smith" wrote: > > On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote: > > > The tutorial is misleading on this. It it says plainly: > > > > A module can contain executable statements as well as function > > definitions. [?] They are executed only the *first* time the module > > is imported somewhere. > > > > > > That's more than misleading. It's plain wrong. The example I gave demonstrates the "print __file__" statement getting executed twice. > > The footnote to that is wrong too: > > > [1] In fact function definitions are also ?statements? that are ?executed?; the execution of a > > module-level function enters the function name in the module?s global symbol table. > > I think what it's supposed to say is "... the execution of a module-level def statement ..." > > > Care to file a documentation bug > > describing this? > > Sure, once I understand how it's really supposed to work :-) > > -- Each module only gets imported once. But if the same module can be accessed as two different names, python doesn't recognize that they are the same module. Along the same lines, if you create a symlink to the file, you'll be able to import the same module twice. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Aug 7 12:49:21 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Aug 2012 12:49:21 -0400 Subject: I thought I understood how import worked... In-Reply-To: References: Message-ID: On 8/7/2012 9:28 AM, Ramchandra Apte wrote: > I don't think the modules are actually imported twice. This is incorrect as Roy's original unposted example showed. Modify one of the two copies and it will be more obvious. PS. I agree with Mark about top posting. I often just glance as such postings rather that go look to find out the context. However, this one is wrong on its own ;-). -- Terry Jan Reedy From lipskathekat at yahoo.co.uk Tue Aug 7 13:00:25 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Tue, 07 Aug 2012 18:00:25 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> On 07/08/12 16:04, rusi wrote: > On Aug 7, 7:34 pm, lipska the kat wrote: >> >> Never thought so for a moment, good to know you can be reasonable as >> well as misguided ;-) > > Well Lipska I must say that I find something resonant about the 'no- > person' thing, though I am not sure what. > > You also said something about 'user' being more acceptable. From a > different (opposite?) angle Dijkstra seems to be saying the same > thing, here: > http://www.cs.utexas.edu/~EWD/transcriptions/EWD06xx/EWD618.html > > Wonder what you make of it? This text is often quoted in discussions I have had on this subject on Usenet and other forums. Professor Dijkstra is far more eloquent that I could ever hope to be. I don't profess to be an academic nor do I have the rhetorical ability of some of the people in this group, having said that I think the professor may be equally as indignant about the word elbowing it's way into his native language as he is about the way the word is used in the computing industry but here is my rationale for thinking that there is a case for a class called User. A 'User' of a computer system can be another computer system, equally a Person can be a user of a computer system. Denying the use of the concept User may inhibit certain thought processes. At the very least 'User' can be used as a place holder indicating that we are aware that we are dealing with something that will eventually need to communicate outside of it's boundaries. Abstracting away an entire 'class' of concepts into a single 4 letter word can be wonderfully liberating. When you tell a group of struggling software developers to ignore external influences but be aware that there is this thing called 'User' that will eventually have to communicate with the thing we are inventing they breath a huge sigh of relief and start to focus on what is important, namely the business logic of the entity that is employing them. Once a basic design has been thrashed out we can start thinking about how external systems (and 'People') interface with the representation of the business we have invented. We then iterate and re-iterate as external influences invariably affect our design, however the core design remains and acts as an anchor to our thinking. In the past, when we have got confused and frustrated with these external influences we have gone back to our original design to ground ourselves again. Having said all this it has never been my experience that we actually end up with a User Class in any design I have been involved in. Eventually we just find ourselves in a place where the 'User' has transmogrified into a collection of facades and interfaces that present a view of the system to the outside world. I'm still undecided over the whole 'User' thing actually, I don't think I can see a time when I will have a User Class in one of my systems but as I don't want to get 'dogmatic' about this I remain open to any ideas that might include such a Class. Person however is an entirely different matter and will never appear in my systems in any way shape or form ...this is not dogma, it's a fact. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From regex at mrabarnett.plus.com Tue Aug 7 13:12:06 2012 From: regex at mrabarnett.plus.com (MRAB) Date: Tue, 07 Aug 2012 18:12:06 +0100 Subject: Q on regex In-Reply-To: <1344336754.13108.2@numa-i> References: <1344336754.13108.2@numa-i> Message-ID: <50214C66.20902@mrabarnett.plus.com> On 07/08/2012 11:52, Helmut Jarausch wrote:> Hi Matthew, > > how to fix the code below to match 'Hellmuth' instead of ' Hellmut' ? > > A negative look behind in front of the pattern doesn't help since it > counts > as an error. One would need a means to mix a required match with a > fuzzy match. > > > #!/usr/bin/python3 > import regex > > Author= regex.compile(r'(?:Helmut){e<=2}') > > R=Author.search('Jarausch Hellmuth') > if R : > print("matching string : |{0}|".format(R.group())) > # matches ' Hellmut' > else : > print("nothing matched") > There are two ways you could do it. One way is to put word boundaries outside the fuzzy match: Author = regex.compile(r'\b(?:Helmut){e<=2}\b') The other way is to use the 'ENHANCEMATCH' flag (or '(?e)' in the pattern), which tells it to 'enhance' the match by reducing the number of errors: Author = regex.compile(r'(?e)(?:Helmut){e<=2}') > > Many thanks for a hint, > Helmut. > > P.S. I've tried to initiate a discussion on adding your module to the > current standard library on C.L.P. > The problem with adding it to the standard library is that any releases would be tied to Python's releases and I would have much less leeway in making changes. There are a number of other modules which remain outside the standard library for just that reason. From tjreedy at udel.edu Tue Aug 7 13:15:37 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Aug 2012 13:15:37 -0400 Subject: I thought I understood how import worked... In-Reply-To: References: <87txweiz7f.fsf@benfinney.id.au> Message-ID: On 8/7/2012 11:32 AM, Roy Smith wrote: > On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote: > >> The tutorial is misleading on this. It it says plainly: >> >> A module can contain executable statements as well as function >> definitions. [?] They are executed only the *first* time the >> module is imported somewhere. The last sentence should be more like "They are executed only the *first* time the module is imported anywhere with a particular name. (One should avoid importing a module under different names.) >> >> [1] In fact function definitions are also ?statements? that are >> ?executed?; the execution of a module-level function enters the >> function name in the module?s global symbol table. > > I think what it's supposed to say is "... the execution of a > module-level def statement ..." right >> Care to file a documentation bug >> describing this? > > Sure, once I understand how it's really supposed to work :-) You don't need a final solution to file. Anyway, I think the change above might be enough. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Tue Aug 7 13:44:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 07 Aug 2012 18:44:49 +0100 Subject: I thought I understood how import worked... In-Reply-To: References: Message-ID: On 07/08/2012 14:18, Roy Smith wrote: > I've been tracking down some weird import problems we've been having with > django. Our settings.py file is getting imported twice. It has some > non-idempotent code in it, and we blow up on the second import. > > I thought modules could not get imported twice. The first time they get > imported, they're cached, and the second import just gets you a reference to the > original. Playing around, however, I see that it's possible to import a module > twice if you refer to it by different names. Here's a small-ish test case which > demonstrates what I'm talking about (python 2.6.5): > > In directory /home/roy/play/import/foo, I've got: > > __init__.py (empty file) > try.py > broken.py > > > $ cat broken.py > print __file__ > > > $ cat try.py > import broken > import foo.broken > > import sys > for m in sys.modules.items(): > if m[0].endswith('broken'): > print m > > > And when I run try.py (with foo as the current directory): > > $ PYTHONPATH=/home/roy/play/import python try.py > /home/roy/play/import/foo/broken.pyc > /home/roy/play/import/foo/broken.pyc > ('broken', ) > ('foo.broken', ) > > > So, it appears that you *can* import a module twice, if you refer to it by > different names! This is surprising. It means that having non-idempotent code > which is executed at import time is a Bad Thing. > > It also means that you could have multiple copies of a module's global > namespace, depending on how your users imported the module. Which is kind of > mind-blowing. > Maybe not directly applicable to what you're saying, but Brett Cannon ought to know something about the import mechanism. I believe he's been working on it on and off for several years. See http://docs.python.org/dev/whatsnew/3.3.html for a starter on the gory details. -- Cheers. Mark Lawrence. From tjreedy at udel.edu Tue Aug 7 13:45:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Aug 2012 13:45:03 -0400 Subject: Procedure to request adding a module to the standard library - or initiating a vote on it In-Reply-To: References: Message-ID: On 8/7/2012 6:13 AM, Helmut Jarausch wrote: > I'd like to request adding the module > http://pypi.python.org/pypi/regex > to Python's standard library in the (near) future As near as I can tell, the author is lukewarm about the prospect. To respond the general question: The author of a module should be warm to hot about the idea and must be willing to move development into the stdlib source tree and conform to Python's release schedule, which may be too slow for actively developed modules. (If the module wraps a well-known and maintained external C library, the wrapper must go into the source tree. Then the docs says that the stdlib module wraps something we are not responsible for.) There should be community support for the module as one of the best of its kind. Someone has to write a PEP. There must be developer support to review the code, api, and documentation. Author must allow changes. (The new ipaddress module has had changes to all three, including considerable doc expansion. Some were to make it accessible to beginners rather than only ip experts, others to make it conform to current 3.x stdlib standards and best practices. For instance, 2.x style list returns were changed to 3.x style iterator returns. ) There must be commitment for the author or substitute for maintenance. > For a long term project I also need some "guarantee" that this > functionality will exist in future. That is the point of the last requirement. > > So, is there a (formal) procedure for such a request or for initiating > some sort of vote on it? 'voting' is fuzzy. Community support. Some support from developers. Best no strong opposition from a senior core developer, or at least more that one. Final decision is always by GvR, but he often delegates decisions to other developers, especially in an area of his non-expertise. > I know there is a "Benevolent Dictator" for Python. > Should I try to contact him personally? No. If there is author and community support, the next step is a PEP or discussion on python-ideas list (which Guido reads even if he does not write much). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Aug 7 13:45:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 17:45:26 GMT Subject: Unexpected behavior using contextmanager on a class method References: Message-ID: <50215436$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Aug 2012 08:30:15 -0700, Thomas Draper wrote: > I want to use with..as in a "reversible circuit generator". However, it > seems that @contextmanager changes the expected nature of the class. I > tried to distill the problem down to a simple example. Nothing to do with contextmanager. That's a red-herring. Your error is here: class SymList: def __init__(self, L=[]): self.L = L The default value for L is only set *once*, when the function is defined, NOT every time the function is called. Later on, in the SymAdd method you modify that list in place. So naturally later instances see the changes, because you have changed the default list. You can see this "early binding" of the default value in action with this simple example: import time def test(x=time.ctime()): # Default values are set *once*, not each time. print(x) test() => always prints Wed Aug 8 03:40:32 2012 (or whatever time the function is defined). In this example, the default value is a string, and cannot be changed; but in your code it is a list, and can be modified in place. Either way, the result is the same: you get the same object used as the default, each and every time. In your case, you can fix this problem and get the effect of "late binding" like this: class SymList: def __init__(self, L=None): if L is None: L = [] self.L = L Now each time the method body runs, you get a different empty list. -- Steven From toby at tobiah.org Tue Aug 7 13:52:35 2012 From: toby at tobiah.org (Tobiah) Date: Tue, 07 Aug 2012 10:52:35 -0700 Subject: Deciding inheritance at instantiation? In-Reply-To: <41f5bfb2-852c-4748-af09-445958471bbd@sn4g2000pbc.googlegroups.com> References: <41f5bfb2-852c-4748-af09-445958471bbd@sn4g2000pbc.googlegroups.com> Message-ID: Interesting stuff. Thanks. On 08/06/2012 07:53 PM, alex23 wrote: > On Aug 4, 6:48 am, Tobiah wrote: >> I have a bunch of classes from another library (the html helpers >> from web2py). There are certain methods that I'd like to add to >> every one of them. So I'd like to put those methods in a class, >> and pass the parent at the time of instantiation. Web2py has >> a FORM class for instance. I'd like to go: >> >> my_element = html_factory(FORM) >> >> Then my_element would be an instance of my class, and also >> a child of FORM. > > I've lately begun to prefer composition over inheritance for > situations like this: > > class MyElementFormAdapter(object): > def __init__(self, form): > self.form = form > > def render_form(self): > self.form.render() > > my_element = MyElementFormAdapter(FORM) > my_element.render_form() > my_element.form.method_on_form() > > Advantages include being more simple and obvious than multiple > inheritance, and avoiding namespace clashes: > > class A(object): > def foo(self): > print 'a' > > class B(object): > def foo(self): > print 'b' > > class InheritFromAB(A, B): > pass > > class AdaptAB(object): > def __init__(self, a, b): > self.a = a > self.b = b > > >>> inherit = InheritFromAB() > >>> inherit.foo() > a > >>> adapt = AdaptAB(A(), B()) > >>> adapt.a.foo() > a > >>> adapt.b.foo() > b From steve+comp.lang.python at pearwood.info Tue Aug 7 13:54:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 17:54:19 GMT Subject: I thought I understood how import worked... References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> <1fca6543-2c01-4f31-8ca7-a81b42b2e4a5@googlegroups.com> Message-ID: <5021564b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Aug 2012 08:25:43 -0700, Roy Smith wrote: > On Tuesday, August 7, 2012 9:52:59 AM UTC-4, Steven D'Aprano wrote: > >> In general, you should avoid non-idempotent code. You should doubly >> avoid it during imports, and triply avoid it on days ending with Y. You seem to have accidentally deleted my smiley. > I don't understand your aversion to non-idempotent code as a general > rule. Most code is non-idempotent. That doesn't necessarily make it a good thing. Most code is also buggy. > Surely you're not saying we should never write: > >>>> foo += 1 > > or > >>>> my_list.pop() > > ??? Of course not. I'm not going so far as to say that we should always, without exception, write purely functional code. I like my list.append as much as anyone :) But at the level of larger code units, functions and modules, it is a useful property to have where possible. A function is free to increment an integer, or pop items from a list, as much as it likes -- so long as they are *local* to the function, and get reset to their initial state each time the function is called with the same arguments. I realise that many problems are most easily satisfied by non-idempotent tactics. "Customer orders widget" is not naturally idempotent, since if the customer does it twice, they get two widgets, not one. But such behaviour should be limited to the parts of your code which must be non- idempotent. In short, non-idempotent code is hard to get right, hard to test, and hard to debug, so we should use as little of it as possible. -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 7 15:02:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Aug 2012 19:02:35 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Aug 2012 19:44:31 -0700, alex23 wrote: > I think you've entirely missed the point of Design Patterns. Perhaps I have. Or perhaps I'm just (over-)reacting to the abuse of Patterns: http://c2.com/cgi/wiki?DesignPatternsConsideredHarmful or maybe I'm just not convinced that Design Patterns as described by the Go4 are as important and revolutionary as so many people seem to believe: http://perl.plover.com/yak/design/ or that they are a crutch for underpowered languages: http://c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatures I haven't read the Gang of Four book itself, but I've spent plenty of time being perplexed by over-engineered, jargon-filled code, articles, posts and discussions by people who use Design Patterns as an end to themselves rather than a means to an end. (Singleton is notoriously bad in that way.) On the other hand, as I think I've stated before, the design patterns themselves aren't *necessarily* bad. They're just problem solving techniques and common idioms. I think that as languages get more powerful, "Design Patterns" just become language features, and people stop talking about them. Nobody talks about Function Pattern, but everyone uses it. In Python, we don't talk about the Iterator Pattern. We just use iterators. > No one claims that the Go4 DP book introduced Builders, Singletons, > Facades. The point was to identify _and name_ such patterns, so > programmers could actually talk about repeated behaviour. I'm pretty sure that people could talk about good coding design before the Gof4. As you say, they didn't invent the patterns. So people obviously wrote code, and talked about algorithms, without the Gof4 terminology. I don't think that "Memento Pattern" is any more clear than "save and restore". When you have a few standard patterns, everyone can know what they are. When you start getting into multiple dozens, it's not so clear to me that they are all *standard* any more. http://c2.com/cgi/wiki?CategoryPattern And the ever-finer distinctions between variations on patterns. Without looking them up, what are the difference between Default Visitor, Extrinsic Visitor, Acyclic Visitor, Hierarchical Visitor, Null Object And Visitor, and regular old Visitor patterns? -- and no, I did not make any of them up. -- Steven From dihedral88888 at googlemail.com Tue Aug 7 16:17:37 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 7 Aug 2012 13:17:37 -0700 (PDT) Subject: [newbie] String to binary conversion In-Reply-To: <502076e1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502076e1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ce1aafc-7cf2-4687-ab0a-7aa42d01173b@googlegroups.com> Steven D'Aprano? 2012?8?7????UTC+8??10?01?05???? > On Mon, 06 Aug 2012 22:46:38 +0200, Mok-Kong Shen wrote: > > > > > If I have a string "abcd" then, with 8-bit encoding of each character, > > > there is a corresponding 32-bit binary integer. How could I best obtain > > > that integer and from that integer backwards again obtain the original > > > string? Thanks in advance. > > > > First you have to know the encoding, as that will define the integers you > > get. There are many 8-bit encodings, but of course they can't all encode > > arbitrary 4-character strings. Since there are tens of thousands of > > different characters, and an 8-bit encoding can only code for 256 of > > them, there are many strings that an encoding cannot handle. > > > > For those, you need multi-byte encodings like UTF-8, UTF-16, etc. > > > > Sticking to one-byte encodings: since most of them are compatible with > > ASCII, examples with "abcd" aren't very interesting: > > > > py> 'abcd'.encode('latin1') > > b'abcd' > > > > Even though the bytes object b'abcd' is printed as if it were a string, > > it is actually treated as an array of one-byte ints: > > > > py> b'abcd'[0] > > 97 > > > > Here's a more interesting example, using Python 3: it uses at least one > > character (the Greek letter ?) which cannot be encoded in Latin1, and two > > which cannot be encoded in ASCII: > > > > py> "a??d".encode('iso-8859-7') > > b'a\xf0\xa9d' > > > > Most encodings will round-trip successfully: > > > > py> text = 'a??Z!' > > py> data = text.encode('iso-8859-7') > > py> data.decode('iso-8859-7') == text > > True > > > > > > (although the ability to round-trip is a property of the encoding itself, > > not of the encoding system). > > > > Naturally if you encode with one encoding, and then decode with another, > > you are likely to get different strings: > > > > py> text = 'a??Z!' > > py> data = text.encode('iso-8859-7') > > py> data.decode('latin1') > > 'a??Z!' > > py> data.decode('iso-8859-14') > > 'a??Z!' > > > > > > Both the encode and decode methods take an optional argument, errors, > > which specify the error handling scheme. The default is errors='strict', > > which raises an exception. Others include 'ignore' and 'replace'. > > > > py> 'a????Z!'.encode('ascii', 'ignore') > > b'aZ!' > > py> 'a????Z!'.encode('ascii', 'replace') > > b'a????Z!' > > > > > > > > -- > > Steven Steven D'Aprano? 2012?8?7????UTC+8??10?01?05???? > On Mon, 06 Aug 2012 22:46:38 +0200, Mok-Kong Shen wrote: > > > > > If I have a string "abcd" then, with 8-bit encoding of each character, > > > there is a corresponding 32-bit binary integer. How could I best obtain > > > that integer and from that integer backwards again obtain the original > > > string? Thanks in advance. > > > > First you have to know the encoding, as that will define the integers you > > get. There are many 8-bit encodings, but of course they can't all encode > > arbitrary 4-character strings. Since there are tens of thousands of > > different characters, and an 8-bit encoding can only code for 256 of > > them, there are many strings that an encoding cannot handle. > > > > For those, you need multi-byte encodings like UTF-8, UTF-16, etc. > > > > Sticking to one-byte encodings: since most of them are compatible with > > ASCII, examples with "abcd" aren't very interesting: > > > > py> 'abcd'.encode('latin1') > > b'abcd' > > > > Even though the bytes object b'abcd' is printed as if it were a string, > > it is actually treated as an array of one-byte ints: > > > > py> b'abcd'[0] > > 97 > > > > Here's a more interesting example, using Python 3: it uses at least one > > character (the Greek letter ?) which cannot be encoded in Latin1, and two > > which cannot be encoded in ASCII: > > > > py> "a??d".encode('iso-8859-7') > > b'a\xf0\xa9d' > > > > Most encodings will round-trip successfully: > > > > py> text = 'a??Z!' > > py> data = text.encode('iso-8859-7') > > py> data.decode('iso-8859-7') == text > > True > > > > > > (although the ability to round-trip is a property of the encoding itself, > > not of the encoding system). > > > > Naturally if you encode with one encoding, and then decode with another, > > you are likely to get different strings: > > > > py> text = 'a??Z!' > > py> data = text.encode('iso-8859-7') > > py> data.decode('latin1') > > 'a??Z!' > > py> data.decode('iso-8859-14') > > 'a??Z!' > > > > > > Both the encode and decode methods take an optional argument, errors, > > which specify the error handling scheme. The default is errors='strict', > > which raises an exception. Others include 'ignore' and 'replace'. > > > > py> 'a????Z!'.encode('ascii', 'ignore') > > b'aZ!' > > py> 'a????Z!'.encode('ascii', 'replace') > > b'a????Z!' > > > > > > > > -- > > Steven I think UTF-8 CODEC or UTF-16 is necessary, just recall those MS encoding codecs of Win98, and NT that collected taxes all over the world. Actually for each kind of some character encoding, please develop a codec to UTF-8 or UTF-16. It means one can make conversions between any two of the qualified character sets. From ralf at systemexit.de Tue Aug 7 16:21:06 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Tue, 07 Aug 2012 22:21:06 +0200 Subject: [ANNOUNCE] pypiserver 0.6.1 - minimal private pypi server Message-ID: <874noe1mj1.fsf@debian.lan> Hi, I've just uploaded pypiserver 0.6.1 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just easy_install pypiserver). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 0.6.1 ------------------------ - make 'python setup.py register' work - added init scripts to start pypiserver on ubuntu/opensuse -- Cheers Ralf From rosuav at gmail.com Tue Aug 7 17:57:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Aug 2012 07:57:52 +1000 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: On Wed, Aug 8, 2012 at 3:00 AM, lipska the kat wrote: > I'm still undecided over the whole 'User' thing actually, I don't think I > can see a time when I will have a User Class in one of my systems but as I > don't want to get 'dogmatic' about this I remain open to any ideas that > might include such a Class. > > Person however is an entirely different matter and will never appear in my > systems in any way shape or form ...this is not dogma, it's a fact. This makes little sense to my mind. If you can have a "class User:", why can you not have a "class Person:" ? Now, that said, I can't remember the last time I actually had a class called "Person" in anything other than a demo. But that's merely because of terminology; I've had classes representing human beings, but named according to what part these people play in the system (Customer, Employee (haven't done that one, actually, but there's no reason not to), User, Etcetera, Etcetera, Etcetera... is an Etceterer someone who practices Etcetery?), and these classes are as well-defined as any others. Perhaps it would help to think about these things not as turning a person into an entity, but as "retaining the data related to a Person". The Person class details what data you store about a person, a Person instance stores that data about one particular person. This works for other things; a QueueEntry isn't actually standing in queue, but it holds the data you store about the thing that is. Or maybe that doesn't help, in which case just ignore it. ChrisA From tjreedy at udel.edu Tue Aug 7 18:37:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Aug 2012 18:37:00 -0400 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/7/2012 3:02 PM, Steven D'Aprano wrote: > On Sun, 05 Aug 2012 19:44:31 -0700, alex23 wrote: > >> I think you've entirely missed the point of Design Patterns. > > Perhaps I have. Or perhaps I'm just (over-)reacting to the abuse of > Patterns: > > http://c2.com/cgi/wiki?DesignPatternsConsideredHarmful > > or that they are a crutch for underpowered languages: I still remember reading an article something like "Implementing the Composite Pattern in C++". The example for the discussion was Pictures that could contain sub-Pictures as well as Graphic elements. I eventually realized that a) this is trivial in Python, b) the article was really about how to lie to a C++ compiler, so it would accept recursive heterogenous structures, and c) I preferred Python. > http://c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatures > I think that as languages get more powerful, "Design Patterns" just > become language features, and people stop talking about them. Nobody > talks about Function Pattern, but everyone uses it. In Python, we don't > talk about the Iterator Pattern. We just use iterators. In pre 2.2 Python, there was talk about the pattern (but not with Capitals) and how to lie to the interpreter with a fake __getitem__ method. > I'm pretty sure that people could talk about good coding design before > the Gof4. As you say, they didn't invent the patterns. So people > obviously wrote code, and talked about algorithms, without the Gof4 > terminology. 'Divide and conquer' is an old, descriptive name for an algorithm action pattern. It is only incidentally about static structures. 'Dynamic programming' is a rather opaque name for a) an action patter for using the optimality principle* (when applicable) and b) not disposing of data one still needs. * the best path from A to B that passes through C is the best path from A to C plus the best path from C to B. Lisp is based on a simple data pattern (or is it a principle): collection (of dicrete items) = one item + remainder, used to both construct and deconstruct. Python iterator embody the the same principle. next(iterator) = iterator: return one item and mutate yourself to represent the rest -- or raise StopIteration. -- Terry Jan Reedy From cs at zip.com.au Tue Aug 7 18:47:36 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 8 Aug 2012 08:47:36 +1000 Subject: I thought I understood how import worked... In-Reply-To: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120807224736.GA11645@cskk.homeip.net> On 07Aug2012 13:52, Steven D'Aprano wrote: | On Tue, 07 Aug 2012 09:18:26 -0400, Roy Smith wrote: | > I thought modules could not get imported twice. The first time they get | > imported, they're cached, and the second import just gets you a | > reference to the original. Playing around, however, I see that it's | > possible to import a module twice if you refer to it by different names. | | Yes. You've found a Python gotcha. [...] | > $ cat try.py | > import broken | > import foo.broken | | Which are two names for the same module. [...] This, I think, is a core issue in this misunderstanding. (I got bitten by this too, maybe a year ago. My error, and I'm glad to have improved my understanding.) All of you are saying "two names for the same module", and variations thereof. And that is why the doco confuses. I would expect less confusion if the above example were described as _two_ modules, with the same source code. Make it clear that these are _two_ modules (because they have two names), who merely happen to have been obtained from the same "physical" filesystem object due to path search effects i.e. change the doco wording to describe a module as the in-memory result of reading a "file" found from an import name. So I think I'm arguing for a small change in terminology in the doco with no change in Python semantics. Is a module a set of files on the disc, or an in-memory Python notion with a name? I would argue for the latter. With such a change, the "a module can't be imported twice" would then be true (barring hacking around in sys.modules between imports). Cheers, -- Cameron Simpson As you can see, unraveling even a small part of 'sendmail' can introduce more complexity than answers. - Brian Costales, _sendmail_ From roy at panix.com Tue Aug 7 19:05:32 2012 From: roy at panix.com (Roy Smith) Date: Tue, 07 Aug 2012 19:05:32 -0400 Subject: I thought I understood how import worked... References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Cameron Simpson wrote: > This, I think, is a core issue in this misunderstanding. (I got bitten > by this too, maybe a year ago. My error, and I'm glad to have improved > my understanding.) > > All of you are saying "two names for the same module", and variations > thereof. And that is why the doco confuses. > > I would expect less confusion if the above example were described as > _two_ modules, with the same source code. +1 From wuwei23 at gmail.com Tue Aug 7 20:07:59 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 7 Aug 2012 17:07:59 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 8, 5:02?am, Steven D'Aprano wrote: > I haven't read the Gang of Four book itself, but I've spent plenty of > time being perplexed by over-engineered, jargon-filled code, articles, > posts and discussions by people who use Design Patterns as an end to > themselves rather than a means to an end. (Singleton is notoriously bad > in that way.) The Go4 book isn't perfect, and I don't agree with all of their patterns. But they themselves made it very clear that _you're not supposed to_. It's meant to provide a mechanism for discussion and debate. It's _just another tool for development_; it's not a silver bullet, and anyone who claims otherwise is just a desperate marketing shill. _Not_ using a pattern should be as much a part of any conversation as using it. (But then, I love the word "synergy" too. Just because something has been driven into the ground through marketing misuse or overeager misapplication doesn't make the basic concept itself worthless.) > I think that as languages get more powerful, "Design Patterns" just > become language features, and people stop talking about them. Nobody > talks about Function Pattern, but everyone uses it. In Python, we don't > talk about the Iterator Pattern. We just use iterators. I'm not making the distinction between "iterator pattern" and "iterators". Talking about one is talking about the other. That's _all_ I see design patterns as: naming and defining commonly re-used aspects of functionality. Not invention, recognition. > I'm pretty sure that people could talk about good coding design before > the Gof4. As you say, they didn't invent the patterns. So people > obviously wrote code, and talked about algorithms, without the Gof4 > terminology. So what did people call Singletons before the pattern was named? If I was talking about "global uniques" and you were talking about "single instantiation", would we even recognise we were discussing the same thing? The Go4 book was as much about the approach of naming and documenting patterns as describing the patterns they saw. It was just an attempt at formally approaching what we were previously doing anyway. > I don't think that "Memento Pattern" is any more clear than "save and > restore". And I don't think that everyone making up their own terminology helps with the _communicativeness_ of code. > And the ever-finer distinctions between variations on patterns. Without > looking them up, what are the difference between Default Visitor, > Extrinsic Visitor, Acyclic Visitor, Hierarchical Visitor, Null Object And > Visitor, and regular old Visitor patterns? -- and no, I did not make any > of them up. Why wouldn't I look them up? The point is that they represent experience with solving certain problems. _Someone_ felt the distinction was necessary; by their documenting it I can read it and decide whether the distinction is relevant to me. Maybe they considered edge cases I didn't. But telling me _not_ to look at the definition of a design pattern and just "intuit" it's meaning is, again, missing the point of having a means of communicating experience with specific problem domains. From ed at leafe.com Tue Aug 7 21:10:07 2012 From: ed at leafe.com (Ed Leafe) Date: Tue, 7 Aug 2012 20:10:07 -0500 Subject: dbf.py API question In-Reply-To: <501AA304.3090000@stoneleaf.us> References: <501AA304.3090000@stoneleaf.us> Message-ID: On Aug 2, 2012, at 10:55 AM, Ethan Furman wrote: > SQLite has a neat feature where if you give it a the file-name of ':memory:' the resulting table is in memory and not on disk. I thought it was a cool feature, but expanded it slightly: any name surrounded by colons results in an in-memory table. > > I'm looking at the same type of situation with indices, but now I'm wondering if the :name: method is not pythonic and I should use a flag (in_memory=True) when memory storage instead of disk storage is desired. When converting from paradigms in other languages, I've often been tempted to follow the accepted pattern for that language, and I've almost always regretted it. When in doubt, make it as Pythonic as possible. -- Ed Leafe From dihedral88888 at googlemail.com Tue Aug 7 21:42:50 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 7 Aug 2012 18:42:50 -0700 (PDT) Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j) Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j) This is a good example to be tuned into some example such that this kind of loops by iterators of parameters in python wich do not use any division at all. But I am getting lazy recently for non-critical parts. From steve+comp.lang.python at pearwood.info Tue Aug 7 22:14:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Aug 2012 02:14:01 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5021cb68$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Aug 2012 17:07:59 -0700, alex23 wrote: >> I'm pretty sure that people could talk about good coding design before >> the Gof4. As you say, they didn't invent the patterns. So people >> obviously wrote code, and talked about algorithms, without the Gof4 >> terminology. > > So what did people call Singletons before the pattern was named? If I > was talking about "global uniques" and you were talking about "single > instantiation", would we even recognise we were discussing the same > thing? But are we? If we're comparing code written in two languages, we don't even know if "global" means the same -- it could be global to a single module, or global to the entire program. Singletons encompass many different behaviours under a single name. If I delete the single instance, and recreate it, will it necessarily have the same state? Calling it a singleton doesn't answer that question. We still have to agree on what behaviour this particular singleton has. NoneType raises an error if you try to create a second instance. bool just returns one of the two singletons (doubletons?) again. py> type(None)() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances py> type(False)() is False True And modules are singletons, even though there is no upper limit to the number of distinct module objects you can get. So if I tell you that X is a singleton, you don't even know something as fundamental as whether or not X is the only instance of its type. > The Go4 book was as much about the approach of naming and documenting > patterns as describing the patterns they saw. It was just an attempt at > formally approaching what we were previously doing anyway. > >> I don't think that "Memento Pattern" is any more clear than "save and >> restore". > > And I don't think that everyone making up their own terminology helps > with the _communicativeness_ of code. Are you saying that Go4 shouldn't have made up their own terminology? "Save and restore" is plain English which predates "Memento Pattern". I was writing code in the 1980s like: save := something; do_stuff_to(something); something := save; {restore old value} which is the Memento pattern in non-OOP Pascal. >> And the ever-finer distinctions between variations on patterns. Without >> looking them up, what are the difference between Default Visitor, >> Extrinsic Visitor, Acyclic Visitor, Hierarchical Visitor, Null Object >> And Visitor, and regular old Visitor patterns? -- and no, I did not >> make any of them up. > > Why wouldn't I look them up? You claim that named Patterns simplify and clarify communication. If you have to look the terms up, they aren't simplifying and clarifying communication, they are obfuscating it. The time I save in writing "Foo Visitor" is lost a dozen times over for every one of my readers who has to look it up to find out what I mean. And if somebody else uses "Foo Visitor" to mean something different to what I mean, we now have a communication mismatch. The finer the distinction between Foo and Bar Visitor, the more likely that people will misunderstand or fail to see the distinction, and the less useful the terminology gets. There is a point of diminishing returns in terminology, where finer distinctions lead to less clarity rather than more, and in my opinion that point was already passed when Go4 wrote their book, and it's just got worse since. -- Steven From rosuav at gmail.com Tue Aug 7 22:24:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Aug 2012 12:24:02 +1000 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <5021cb68$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> <5021cb68$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 8, 2012 at 12:14 PM, Steven D'Aprano wrote: > NoneType raises an error if you try to create a second instance. bool > just returns one of the two singletons (doubletons?) again. > > py> type(None)() > Traceback (most recent call last): > File "", line 1, in > TypeError: cannot create 'NoneType' instances > py> type(False)() is False > True This is necessitated by the use of bool(x) as a means of boolifying ("casting to bool", if you like) x. I wouldn't want that to change, and since type(False) is bool, what you see is bound to occur. ChrisA From wuwei23 at gmail.com Tue Aug 7 23:20:50 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 7 Aug 2012 20:20:50 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5021664b$0$29978$c3e8da3$5496439d@news.astraweb.com> <5021cb68$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2436e0c0-8d60-4a34-a236-898abbb23646@k21g2000vbn.googlegroups.com> On Aug 8, 12:14?pm, Steven D'Aprano wrote: > You claim that named Patterns simplify and clarify communication. If you > have to look the terms up, they aren't simplifying and clarifying > communication, they are obfuscating it. By that argument, an encyclopaedia is useless because if you have to look up the meaning of something by its name... Names are identifiers for exactly that reason, to make look up easier. Names aren't meant to encode every aspect of what they represent. Or why distinguish between quick sort & merge sort? Let's just talk about "sort", that's simpler. > The time I save in writing "Foo Visitor" is lost a dozen times over for > every one of my readers who has to look it up to find out what I mean. What would you call it that would remove the need for _anyone_ to look up/ask you what it meant? > And if somebody else uses "Foo Visitor" to mean something different to > what I mean, we now have a communication mismatch. Do we just not use names at all? How do you communicate what you're doing in this instance? > There is a point of diminishing returns in terminology, where finer > distinctions lead to less clarity rather than more, and in my opinion > that point was already passed when Go4 wrote their book, and it's just > got worse since. Can you please point me to a standardised way for talking about abstract patterns of behaviour across languages? From ben+python at benfinney.id.au Wed Aug 8 00:14:13 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Aug 2012 14:14:13 +1000 Subject: I thought I understood how import worked... References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hasehvfu.fsf@benfinney.id.au> Cameron Simpson writes: > All of you are saying "two names for the same module", and variations > thereof. And that is why the doco confuses. > > I would expect less confusion if the above example were described as > _two_ modules, with the same source code. That's not true though, is it? It's the same module object with two different references, I thought. Also, even if what you say were true, ?source code? implies the module was loaded from source code, when Python allows loading modules with no source code available. So that implication just seems to be inviting different confusion. -- \ ?I'm not a bad guy! I work hard, and I love my kids. So why | `\ should I spend half my Sunday hearing about how I'm going to | _o__) Hell?? ?Homer Simpson | Ben Finney From gandalf at shopzeus.com Wed Aug 8 02:40:46 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 08 Aug 2012 08:40:46 +0200 Subject: I thought I understood how import worked... In-Reply-To: <87hasehvfu.fsf@benfinney.id.au> References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> <87hasehvfu.fsf@benfinney.id.au> Message-ID: <502209EE.1060800@shopzeus.com> On 2012-08-08 06:14, Ben Finney wrote: > Cameron Simpson writes: > >> All of you are saying "two names for the same module", and variations >> thereof. And that is why the doco confuses. >> >> I would expect less confusion if the above example were described as >> _two_ modules, with the same source code. > That's not true though, is it? It's the same module object with two > different references, I thought. They are not the same. Proof: $ mkdir test $ cd test $ touch __init__.py $ touch m.py $ cd .. $ python Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append('test') >>> import m >>> from test import m >>> import m >>> from test import m as m2 >>> m is m2 False >>> m.a = 3 >>> m2.a Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'a' So it is still true that top level code gets executed only once, when the module is first imported. The trick is that a module is not a file. It is a module object that is created from a file, with a name. If you change the name, then you create ("import") a new module. You can also use the reload() function to execute module level code again, but it won't create a new module object. It will just update the contents of the very same module object: What is more interesting is how the reload() function works: Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import test.m >>> a = test.m >>> import os >>> test.m is a True >>> os.system("echo \"import sys\" >> test/m.py") 0 >>> reload(test.m) # Updates the module object >>> test.m is a # They are still the same True >>> a.sys # So a.sys is a exist >>> From ulrich.eckhardt at dominolaser.com Wed Aug 8 04:29:11 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 08 Aug 2012 10:29:11 +0200 Subject: On-topic: alternate Python implementations In-Reply-To: References: <501cbdf8$0$29978$c3e8da3$5496439d@news.astraweb.com> <501cd421$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 04.08.2012 15:53, schrieb Stefan Behnel: > So, if a C++ compiler takes a .c file and compiles it with C language > semantics, it doesn't qualify as a C compiler? That implies a rather weird > definition of a C compiler, I'd say. I'd say that even a brainfuck compiler compiling a .py file with C language semantics can shamelessly call itself a C compiler. :P If a C++ compiler is given C code, it may or may not produce equivalent executables. In most non-trivial cases it will just barf on the valid C / invalid C++ code and refuse to compile it. In few rare cases, it will compile the code and produce different behaviour at runtime (e.g. for "sizeof 'a'"). Uli From jeanmichel at sequans.com Wed Aug 8 04:47:14 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Aug 2012 10:47:14 +0200 Subject: I thought I understood how import worked... In-Reply-To: References: Message-ID: <50222792.6070107@sequans.com> Roy Smith wrote: > So, it appears that you *can* import a module twice, if you refer to it by > different names! This is surprising. It means that having non-idempotent code > which is executed at import time is a Bad Thing. > Not exactly, it means that one module is different from another if its path is different. That means you need to be extra careful about how you reference a module. Content is not used to discriminate modules. JM From lipskathekat at yahoo.co.uk Wed Aug 8 05:51:45 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 08 Aug 2012 10:51:45 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: On 07/08/12 22:57, Chris Angelico wrote: > On Wed, Aug 8, 2012 at 3:00 AM, lipska the kat wrote: >> I'm still undecided over the whole 'User' thing actually, [snip] > This makes little sense to my mind. If you can have a "class User:", > why can you not have a "class Person:" ? User and Person are entirely different concepts, surely you can see that. A User can be anything that interacts with our system, not necessarily a Person. > Now, that said, I can't remember the last time I actually had a class > called "Person" in anything other than a demo. But that's merely > because of terminology; I've had classes representing human beings, > but named according to what part these people play in the system > (Customer, Employee (haven't done that one, actually, but there's no > reason not to), Customer is a 'business Class'. Businesses without Customers don't exist, at least I don't know of any. A Customer however can be many things, Organisations can be customers of other organisations. Is a LampPost a Customer of the Electricity company that supplies it with power ? possibly, it depends on your business model. A LampPost sure isn't a Person though. Limiting the Customer class to representing human beings is exactly that, limiting. [snip] > The Person class details what data you store about a person, > a Person instance stores that data about one particular person. This > works for other things; > a QueueEntry isn't actually standing in queue, Ah but it is, that's exactly what we are doing when we encapsulate a Human concept, where do you think the idea comes from, why is it called a queue, because it's analogous to what we do when we go to the cinema, go to the bank, do queuing type things. In fact it's a very precise, well defined encapsulation, First in, First out. We enforce our ideas of what it means to stand in a queue by writing the code in such a way that is impossible for anything other than thing at the head of the queue to get out first. If we change the concept we change the name, PriorityQueue ? Highest priority out first regardless of position. This is an extension of the original concept that exists in the real world, the casualty department for example, triage sorts the urgent cases from the non urgent, you get seen depending on the urgency of your case not depending on when you arrived at the hospital. The point I'm obviously struggling to make is that words convey concepts The word Person conveys a whole lifetime of experience of People and as imperfect human beings many of us are unable to tease out 'bits of being a person' that are relevant to the system we are developing. Inevitably other seemingly irreversibly entwined bits keep popping up to cloud our thinking. This is my experience, not an isolated case but one that has popped up again and again. > but it holds the data you store about the thing that is. > > Or maybe that doesn't help, in which case just ignore it. I don't need any help with this but thank you for contributing lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From biofobico at gmail.com Wed Aug 8 07:44:34 2012 From: biofobico at gmail.com (couto) Date: Wed, 8 Aug 2012 04:44:34 -0700 (PDT) Subject: Todo app help Message-ID: Can someone point me a good tutorial about making a Todo app or similar apps? I starting learning python and i think that building these small apps will help me understanding better the language. P.S Just finish reading A Byte of Python book. Thanks in advance From lipskathekat at yahoo.co.uk Wed Aug 8 08:48:43 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 08 Aug 2012 13:48:43 +0100 Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: On 06/08/12 14:32, S.B wrote: > Hello friends > > Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: > First host pickles a file object and writes the pickled file object to a client socket. > Second host reads the pickled file object from the server socket and un-pickles it. > > Can anyone provide a simple code example of the client and server sides? > > Thanks > Hi Firstly I am a raw beginner at Python and I don't publish this code as a good example of anything. It works for me on Ubuntu Linux 12.04 and Python3.2 As usual I welcome constructive comments but I will be working on this more to help me understand exactly what is going on http://pastebin.com/iFzK7fuk SpaceTravellers.py http://pastebin.com/TdqPwMGi NetworkPickler.py http://pastebin.com/DF5DtYRZ NetworkUnpickler.py lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From roy at panix.com Wed Aug 8 09:12:47 2012 From: roy at panix.com (Roy Smith) Date: Wed, 08 Aug 2012 09:12:47 -0400 Subject: I thought I understood how import worked... References: <50211dba$0$29978$c3e8da3$5496439d@news.astraweb.com> <87hasehvfu.fsf@benfinney.id.au> Message-ID: In article <87hasehvfu.fsf at benfinney.id.au>, Ben Finney wrote: > Cameron Simpson writes: > > > All of you are saying "two names for the same module", and variations > > thereof. And that is why the doco confuses. > > > > I would expect less confusion if the above example were described as > > _two_ modules, with the same source code. > > That's not true though, is it? It's the same module object with two > different references, I thought. Nope. I modified my test case to print out the id of the module: ('broken', ) 140608299115512 ('foo.broken', ) 140608299116232 > Also, even if what you say were true, ???source code??? implies the module > was loaded from source code, when Python allows loading modules with no > source code available. This is true. In fact, when I first started chasing this down, one import was finding the .py file, and the other the .pyc file (created during the first import). I originally assumed that the .py/.pyc distinction was the critical piece of the puzzle (and went down a rathole exploring that). Then I went down a different rathole when I noticed that one code path was doing "import settings", while the other was doing "__import__(module_name)", thinking import and __import__ were somehow doing different things. From rohitkav123 at gmail.com Wed Aug 8 09:19:06 2012 From: rohitkav123 at gmail.com (rohitkav123 at gmail.com) Date: Wed, 8 Aug 2012 06:19:06 -0700 (PDT) Subject: [ANN] CubicWeb 3.8 released In-Reply-To: References: Message-ID: <7ff87e59-5fb8-44b8-80cb-ad4191478338@googlegroups.com> Hi Sylvain, I was trying to install Cubicweb on my Ubuntu 12.04. I believe it got installed, but I do get this error. ~$ cubicweb-ctl Traceback (most recent call last): File "/usr/local/bin/cubicweb-ctl", line 4, in import pkg_resources File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2707, in working_set.require(__requires__) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 686, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 584, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: Twisted rohit at rohit-Aspire-4720Z:~$ Could you help me On Wednesday, April 28, 2010 4:05:20 PM UTC+5:30, Sylvain Th?nault wrote: > CubicWeb 3.8.0 went out last week, but now we have tested it, produced > a 3.8.1, it's show time! > > > What's new in CubicWeb 3.8? > > > One of the most important change is http server update to move from deadend > twisted.web2 to twisted.web. With this change come the possibility to configure > the maximum size of POST request in the configuration file (was hard-coded to > 100Mo before). > > Other changes include: > > * CubicWeb should now be installable through **pip** or **easy_install**. > This is still experimental, and we don't use it that much so please, > give us some feedback! Some cubes are now also pipable (comment, blog...), > but more will come with new releases. > > * .execute() function lost is cache key argument. This is a great news since > it was a pain to explain and most cubicweb users didn't know how to handle > it well (and I'm thre greatest beneficer since I won't have to explain over > and over again) > > * nicer schema and workflow views > > * refactored web session handling, which should now be cleaner, clearer, hence > less buggy... > > * nicer skeleton generation for new cubes, cleaner __pkginfo__ (you don't have > to define both __depends__ / __depends_cubes__ or __recommends__ / > __recommends_cubes__ in the general case, and other cleanups) > > Enjoy! > -- > Sylvain Th?nault LOGILAB, Paris (France) > Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations > D?veloppement logiciel sur mesure: http://www.logilab.fr/services > CubicWeb, the semantic web framework: http://www.cubicweb.org From hyperboogie at gmail.com Wed Aug 8 09:50:40 2012 From: hyperboogie at gmail.com (S.B) Date: Wed, 8 Aug 2012 06:50:40 -0700 (PDT) Subject: Pickle file and send via socket In-Reply-To: References: Message-ID: <674b1cd4-5f7d-47ce-924d-76f5306746bc@googlegroups.com> On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: > On 06/08/12 14:32, S.B wrote: > > > Hello friends > > > > > > Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: > > > First host pickles a file object and writes the pickled file object to a client socket. > > > Second host reads the pickled file object from the server socket and un-pickles it. > > > > > > Can anyone provide a simple code example of the client and server sides? > > > > > > Thanks > > > > > > > Hi > > > > Firstly I am a raw beginner at Python and I don't publish this code > > as a good example of anything. It works for me on Ubuntu Linux 12.04 and > > Python3.2 > > > > As usual I welcome constructive comments but I will be working on this > > more to help me understand exactly what is going on > > > > http://pastebin.com/iFzK7fuk SpaceTravellers.py > > http://pastebin.com/TdqPwMGi NetworkPickler.py > > http://pastebin.com/DF5DtYRZ NetworkUnpickler.py > > > > lipska > > > > -- > > Lipska the Kat: Troll hunter, sandbox destroyer > > and farscape dreamer of Aeryn Sun Thank you so much ! The examples are very helpful. What happens if I have a regular text file I want to send via the network. Do I need to read the file and then dump it into the "stargate" file object? From lipskathekat at yahoo.co.uk Wed Aug 8 11:07:33 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 08 Aug 2012 16:07:33 +0100 Subject: Pickle file and send via socket In-Reply-To: <674b1cd4-5f7d-47ce-924d-76f5306746bc@googlegroups.com> References: <674b1cd4-5f7d-47ce-924d-76f5306746bc@googlegroups.com> Message-ID: <37mdnchk-JMqHb_NnZ2dnUVZ7tidnZ2d@bt.com> On 08/08/12 14:50, S.B wrote: > On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: >> On 06/08/12 14:32, S.B wrote: >> [snip] > Thank you so much ! > The examples are very helpful. > What happens if I have a regular text file I want to send via the network. > Do I need to read the file and then dump it into the "stargate" file object? Well according to the documentation at http://docs.python.org/py3k/tutorial/inputoutput.html#reading-and-writing-files it should be straightforward to read and write pickled files Not sure why you want to pickle a text file over the network when you could just stream it between ports ! however ... I'm currently getting a Unicode decode error on the first byte in the stream when it gets to the other end, no idea why so I guess I have to continue searching, read the documentation above and see if you can figure it out, that's what I'm doing. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From ethan at stoneleaf.us Wed Aug 8 11:18:20 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 08 Aug 2012 08:18:20 -0700 Subject: dbf.py API question In-Reply-To: References: <501AA304.3090000@stoneleaf.us> Message-ID: <5022833C.9060803@stoneleaf.us> Ed Leafe wrote: > When converting from paradigms in other languages, I've often been tempted to follow the accepted pattern for that language, and I've almost always regretted it. +1 > > When in doubt, make it as Pythonic as possible. +1 QOTW ~Ethan~ From maniandram01 at gmail.com Wed Aug 8 11:29:31 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 8 Aug 2012 20:59:31 +0530 Subject: [ANN] CubicWeb 3.8 released In-Reply-To: <7ff87e59-5fb8-44b8-80cb-ad4191478338@googlegroups.com> References: <7ff87e59-5fb8-44b8-80cb-ad4191478338@googlegroups.com> Message-ID: You need to install Twisted(google for links) On 8 August 2012 18:49, wrote: > Hi Sylvain, > > I was trying to install Cubicweb on my Ubuntu 12.04. I believe it got > installed, but I do get this error. > > ~$ cubicweb-ctl > Traceback (most recent call last): > File "/usr/local/bin/cubicweb-ctl", line 4, in > import pkg_resources > File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2707, in > > working_set.require(__requires__) > File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 686, in > require > needed = self.resolve(parse_requirements(requirements)) > File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 584, in > resolve > raise DistributionNotFound(req) > pkg_resources.DistributionNotFound: Twisted > rohit at rohit-Aspire-4720Z:~$ > > > Could you help me > > > On Wednesday, April 28, 2010 4:05:20 PM UTC+5:30, Sylvain Th?nault wrote: > > CubicWeb 3.8.0 went out last week, but now we have tested it, produced > > a 3.8.1, it's show time! > > > > > > What's new in CubicWeb 3.8? > > > > > > One of the most important change is http server update to move from > deadend > > twisted.web2 to twisted.web. With this change come the possibility to > configure > > the maximum size of POST request in the configuration file (was > hard-coded to > > 100Mo before). > > > > Other changes include: > > > > * CubicWeb should now be installable through **pip** or **easy_install**. > > This is still experimental, and we don't use it that much so please, > > give us some feedback! Some cubes are now also pipable (comment, > blog...), > > but more will come with new releases. > > > > * .execute() function lost is cache key argument. This is a great news > since > > it was a pain to explain and most cubicweb users didn't know how to > handle > > it well (and I'm thre greatest beneficer since I won't have to explain > over > > and over again) > > > > * nicer schema and workflow views > > > > * refactored web session handling, which should now be cleaner, clearer, > hence > > less buggy... > > > > * nicer skeleton generation for new cubes, cleaner __pkginfo__ (you > don't have > > to define both __depends__ / __depends_cubes__ or __recommends__ / > > __recommends_cubes__ in the general case, and other cleanups) > > > > Enjoy! > > -- > > Sylvain Th?nault LOGILAB, Paris (France) > > Formations Python, Debian, M?th. Agiles: > http://www.logilab.fr/formations > > D?veloppement logiciel sur mesure: http://www.logilab.fr/services > > CubicWeb, the semantic web framework: http://www.cubicweb.org > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ombdalen at gmail.com Wed Aug 8 12:21:11 2012 From: ombdalen at gmail.com (=?UTF-8?Q?Ole_Martin_Bj=C3=B8rndalen?=) Date: Wed, 8 Aug 2012 18:21:11 +0200 Subject: dbf.py API question In-Reply-To: <5022833C.9060803@stoneleaf.us> References: <501AA304.3090000@stoneleaf.us> <5022833C.9060803@stoneleaf.us> Message-ID: On Wed, Aug 8, 2012 at 5:18 PM, Ethan Furman wrote: > Ed Leafe wrote: >> When converting from paradigms in other languages, I've often been >> tempted to follow the accepted pattern for that language, and I've almost >> always regretted it. > +1 >> When in doubt, make it as Pythonic as possible. > +1 QOTW > ~Ethan~ +2 from me as well. Totally in spirit with the Zen of Python! From rustompmody at gmail.com Wed Aug 8 12:27:40 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 8 Aug 2012 09:27:40 -0700 (PDT) Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: <65e77682-00ab-4e86-b3cb-2046d6e5c628@r2g2000pbn.googlegroups.com> On Aug 8, 2:51?pm, lipska the kat wrote: > The point I'm obviously struggling to make is that words convey concepts > The word Person conveys a whole lifetime of experience of People and as > imperfect human beings many of us are unable to tease out 'bits of being > a person' that are relevant to the system we are developing. Inevitably > other seemingly irreversibly entwined bits keep popping up to cloud our > thinking. This is my experience, not an isolated case but one that has > popped up again and again. I once sat for a presentation of a wannabe university teacher. The subject she chose was object-orientation. She spent some time on the usual dope about employee, manager etc. Finally she reached the base-class: Person. Or so we thought... Then suddenly she started 'extending' the bases: Person inherits from mammal inherits from vertebrate inherits from animal Now in principle one could perhaps find an app where this whole inheritance hierarchy makes sense. But I cannot think of one. (Maybe something from Orwell??) In any case this is the incident that makes me side with your "NO PERSON" dictum. From steve+comp.lang.python at pearwood.info Wed Aug 8 13:28:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Aug 2012 17:28:27 GMT Subject: Looking for a good introduction to object oriented programming with Python References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> <65e77682-00ab-4e86-b3cb-2046d6e5c628@r2g2000pbn.googlegroups.com> Message-ID: <5022a1bb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Aug 2012 09:27:40 -0700, rusi wrote: > I once sat for a presentation of a wannabe university teacher. The > subject she chose was object-orientation. > > She spent some time on the usual dope about employee, manager etc. > Finally she reached the base-class: Person. > > Or so we thought... > > Then suddenly she started 'extending' the bases: Person inherits from > mammal inherits from vertebrate inherits from animal > > Now in principle one could perhaps find an app where this whole > inheritance hierarchy makes sense. Presumably female managers who breast-feed their children inherit that method from Mammal. And if you were modelling a futuristic space station with both human and non-human beings (perhaps for a game?), then distinguishing between those that inherit a breathe_oxygen() method from Animal versus those that inherit absorb_magnetic_energy() from Acturian_Magnevore might be useful. I wasn't at this talk, but I would be willing to bet that she wasn't suggesting that any specific application needs to encompass the entire inheritance hierarchy from Animal to Junior Manager Of Pencil Sharpeners, only that the Inheritance design pattern was capable of doing so. > But I cannot think of one. (Maybe something from Orwell??) > > In any case this is the incident that makes me side with your "NO > PERSON" dictum. The problem with this dictum is that while it recognises that (e.g.) a Customer is not necessarily a person (it can be another business unit or a company), that's more the exception than the rule. A Student is always a person. So is an Employee or Employer, a Surgeon or Patient, or the subject of birth, death and marriage records. (As they say: I'll believe that corporations are people when Texas executes one.) You can, of course, ban the name "Person" from your classes and databases. But that's a mere cosmetic quirk -- you're still modelling people as objects and/or database records, whether you use the word or not. -- Steven From miki.tebeka at gmail.com Wed Aug 8 15:17:51 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 8 Aug 2012 12:17:51 -0700 (PDT) Subject: Todo app help In-Reply-To: References: Message-ID: > Can someone point me a good tutorial about making a Todo app or similar apps? What do you mean by "app"? For a web app - there are many frameworks out there. Django is the big kid in the block but there are many others (flask, bottle, cherrypy, ...) For GUI application, look at PyQt, wxPython, Tkinter ... There's no support (that I know of) to writing phone (iPhone, Android ...) python application. From lipskathekat at yahoo.co.uk Wed Aug 8 15:31:57 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 08 Aug 2012 20:31:57 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: On 08/08/12 17:42, Dennis Lee Bieber wrote: > On Wed, 08 Aug 2012 10:51:45 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > >> >> The point I'm obviously struggling to make is that words convey concepts >> The word Person conveys a whole lifetime of experience of People and as >> imperfect human beings many of us are unable to tease out 'bits of being >> a person' that are relevant to the system we are developing. Inevitably >> other seemingly irreversibly entwined bits keep popping up to cloud our >> thinking. This is my experience, not an isolated case but one that has >> popped up again and again. >> > You've never considered writing a genealogy program, have you? One > that never acknowledges "Person"? > Before I start let me say that this thread really has been the most enormous fun and I can take any amount of ridicule so don't hold back. Normally when I have a bath I think of the best way to stop the mice from feasting on my herb patch without killing them. This evening I lay there thinking about this outwardly tricky problem when I realised that what we have here, at it's most basic, is a Tree. I am not a genealogy expert, the nearest I've been to a family tree is the ones my old mum thrusts under my nose at Christmas, Sunday lunch, birthdays,funerals etc etc . They are increasing large, beautifully hand drawn and most definitely a Tree So here is my off the cuff, in the bath design for a genealogy system A Tree consists of Node(s) and Leaf(s), relationships are modelled by following the Line(s) in the Tree diagram and that is it. Line may be a class as in 'the patriarchal line' I'm not sure, it would come out in the iterative wash. We can infer whatever we want from this simple model. A Leaf is a child, until it becomes a parent when it becomes a Node. To anthropomorphize a bit more (I love that word) and introduce non species specific words and concepts, a Node can be a father or mother (simple to implement by virtue of an enumeration e.g enum Gender{MALE, FEMALE, HERMAPHRODITE, NON_GENDER_SPECIFIC_CHIMERA, ...}) A male sibling of a parent is an uncle, a female an aunt and a cousin is ...I have no idea but hopefully you can see where I'm going with this. Furthermore our system can work for Horses and Dogs and Zoomorphs and Epiphytes, Parasites and Zygomorphs and Fungi and Parrots and anything else you can possibly think of ... But what of all the ephemeral data that goes with a sentient existance on this planet such as birth certificates, newspaper articles, christenings, death certificates, photographs etc etc, what about pegigree certificates, innoculation records and any other trivia, information and flotsam that goes with a pedigree Dog or Horse or indeed Parrot. Well you don't need me to answer this one do you, we could have a class called Ephemera ... but then I prefer the Just In Time concept to loading data, I'd store the gubbins in a 'database' (don't get me started on databases) or I may decide to pickle the data out to disk and pull it out when someone requests it and probably charge them a small fortune for the privilige of looking at their own families historical information. And not a 'Person' in sight Of course you may be a genealogy expert and just waiting to shoot me down in flames, go ahead, I'll have a good smile about it next time I'm in the bath. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From h.goebel at goebel-consult.de Wed Aug 8 16:03:35 2012 From: h.goebel at goebel-consult.de (Hartmut Goebel) Date: Wed, 08 Aug 2012 22:03:35 +0200 Subject: [ANN] PyInstaller 2.0 Message-ID: Hello, on behalf of the PyInstaller development team I'm happy to announce PyInstaller 2.0. http://www.pyinstaller.org Special thanks to Martin Zibricky who did most of the development work for this release. === What it is === PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with any version of Python since 2.3, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility. The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. === Changes === Major changes for this release are: * Minimum suported Python version is now 2.3. * Support for Mac OS X 64-bit, Mac OS X 10.7 (Lion) and 10.8 (Mountain Lion) has been added. * For OS X, application bundles (.app) can be created automatically. * Experimental support for AIX (thanks to Martin Gamwell Dawids). * Experimental support for Solaris (thanks to Hywel Richards). * A Multipackage function has been added to create a collection of packages to avoid library duplication. See documentation for more details. * A new, symplified command line interface. Configure.py, Makespec.py and Build.py replaced by pyinstaller.py. See documentation for more details. * Added or improved import hooks, most notable: - PyUSB (thanks to Chien-An "Zero" Cho). - wx.lib.pubsub (thanks to Daniel Hyams). - PyQT4, win32com, pyttsx, The full changelog for this release can be found at: http://www.pyinstaller.org/export/v2.0/project/doc/CHANGES.txt === Feedback === We're eager to listen to your feedback on using PyInstaller: Ticketing system: http://www.pyinstaller.org/newticket Mailing list: http://groups.google.com/group/PyInstaller === Features === * Packaging of Python programs into standard executables, that work on computers without Python installed. * Multiplatform: works under Windows (32-bit and 64-bit), Linux (32-bit and 64-bit) and Mac OS X (32-bit only). * Multiversion: works under any version of Python from 2.2 up to 2.7. * Flexible packaging mode: * Single directory: build a directory containing an executable plus all the external binary modules (.dll, .pyd, .so) used by the program. * Single file: build a single executable file, totally self-contained, which runs without any external dependency. * Custom: you can automate !PyInstaller to do whatever packaging mode you want through a simple script file in Python. * Explicit intelligent support for many 3rd-packages (for hidden imports, external data files, etc.), to make them work with !PyInstaller out-of-the-box. * Full single-file EGG support: required .egg files are automatically inspected for dependencies and bundled, and all the egg-specific features are supported at runtime as well (entry points, etc.). * Partial directory EGG support: required .egg directories are automatically inspected for dependencies and bundled, but egg-specific features will not work at runtime. * Automatic support for binary libraries used through ctypes. * Support for automatic binary packing through the well-known UPX compressor. * Optional console mode (see standard output and standard error at runtime). * '''Windows-specific features''': * Support for code-signing executables. * Full automatic support for CRTs: no need to manually distribute MSVCR*.DLL, redist installers, manifests, or anything else; '''true''' one-file applications that work everywhere! * Selectable executable icon. * Fully configurable version resource section and manifests in executable. * Support for building COM servers. * '''Mac-specific features''': * Support for bundles -- Sch?nen Gru? Hartmut Goebel Dipl.-Informatiker (univ), CISSP, CSSLP Goebel Consult http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/2011-02-fleisige-datensammler-fur-lukratives-geschaeftsmodell-gesucht Blog: http://www.goebel-consult.de/blog/20050401 Goebel Consult ist Mitglied bei http://www.7-it.de/ From iftecan2000 at gmail.com Wed Aug 8 16:23:59 2012 From: iftecan2000 at gmail.com (Ifthikhan Nazeem) Date: Wed, 8 Aug 2012 22:23:59 +0200 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: Who could have predicted that a request for suggesting books on OOP can come so far! On Wed, Aug 8, 2012 at 9:31 PM, lipska the kat wrote: > On 08/08/12 17:42, Dennis Lee Bieber wrote: > >> On Wed, 08 Aug 2012 10:51:45 +0100, lipska the kat >> declaimed the following in >> gmane.comp.python.general: >> >> >>> The point I'm obviously struggling to make is that words convey concepts >>> The word Person conveys a whole lifetime of experience of People and as >>> imperfect human beings many of us are unable to tease out 'bits of being >>> a person' that are relevant to the system we are developing. Inevitably >>> other seemingly irreversibly entwined bits keep popping up to cloud our >>> thinking. This is my experience, not an isolated case but one that has >>> popped up again and again. >>> >>> You've never considered writing a genealogy program, have you? >> One >> that never acknowledges "Person"? >> >> Before I start let me say that this thread really has been the most > enormous fun and I can take any amount of ridicule so don't hold back. > > Normally when I have a bath I think of the best way to stop the mice from > feasting on my herb patch without killing them. This evening I lay there > thinking about this outwardly tricky problem when I realised that what we > have here, at it's most basic, is a Tree. > > I am not a genealogy expert, the nearest I've been to a family tree is the > ones my old mum thrusts under my nose at Christmas, Sunday lunch, > birthdays,funerals etc etc . They are increasing large, beautifully hand > drawn and most definitely a Tree > > So here is my off the cuff, in the bath design for a genealogy system > > A Tree consists of Node(s) and Leaf(s), relationships are modelled by > following the Line(s) in the Tree diagram and that is it. Line may be a > class as in 'the patriarchal line' I'm not sure, it would come out in the > iterative wash. > > We can infer whatever we want from this simple model. A Leaf is a child, > until it becomes a parent when it becomes a Node. To anthropomorphize a bit > more (I love that word) and introduce non species specific words and > concepts, a Node can be a father or mother (simple to implement by virtue > of an enumeration e.g enum Gender{MALE, FEMALE, HERMAPHRODITE, > NON_GENDER_SPECIFIC_CHIMERA, ...}) A male sibling of a parent is an uncle, > a female an aunt and a cousin is ...I have no idea but hopefully you can > see where I'm going with this. Furthermore our system can work for Horses > and Dogs and Zoomorphs and Epiphytes, Parasites and Zygomorphs and Fungi > and Parrots and anything else you can possibly think of ... > > But what of all the ephemeral data that goes with a sentient existance on > this planet such as birth certificates, newspaper articles, christenings, > death certificates, photographs etc etc, what about pegigree certificates, > innoculation records and any other trivia, information and flotsam that > goes with a pedigree Dog or Horse or indeed Parrot. > > Well you don't need me to answer this one do you, we could have a class > called Ephemera ... but then I prefer the Just In Time concept to loading > data, I'd store the gubbins in a 'database' (don't get me started on > databases) or I may decide to pickle the data out to disk and pull it out > when someone requests it and probably charge them a small fortune for the > privilige of looking at their own families historical information. > > And not a 'Person' in sight > > Of course you may be a genealogy expert and just waiting to shoot me down > in flames, go ahead, I'll have a good smile about it next time I'm in the > bath. > > lipska > > -- > Lipska the Kat: Troll hunter, sandbox destroyer > and farscape dreamer of Aeryn Sun > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.benjamin at bristol.ac.uk Wed Aug 8 17:38:28 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Wed, 8 Aug 2012 22:38:28 +0100 Subject: Pickle file and send via socket In-Reply-To: <37mdnchk-JMqHb_NnZ2dnUVZ7tidnZ2d@bt.com> References: <674b1cd4-5f7d-47ce-924d-76f5306746bc@googlegroups.com> <37mdnchk-JMqHb_NnZ2dnUVZ7tidnZ2d@bt.com> Message-ID: On 8 August 2012 16:07, lipska the kat wrote: > On 08/08/12 14:50, S.B wrote: > >> On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: >> >>> On 06/08/12 14:32, S.B wrote: >>> >>> > [snip] > > > Thank you so much ! >> The examples are very helpful. >> What happens if I have a regular text file I want to send via the network. >> Do I need to read the file and then dump it into the "stargate" file >> object? >> > Lipska's example code is a good demonstration of how to use sockets and how to pickle/unpickle objects in order to send them as bytes over a socket. However, I don't think you really want to pickle the file object (i.e. you don't want to use the pickle module). It seems that you want to send the content of the file, which already is bytes, to the other computer. If that's the case then you can read the bytes of a file with: filename = 'myfile.txt' fileobject = open(filename, 'rb') # We use 'rb' to get bytes, not unicode filecontents = fileobject.read() # Reads the whole content of the file and returns a bytes object fileobject.close() stargate.write(filecontents) # Actually send the data In the server program, you can do: filecontents_received = stargate.read() Now you have the bytes object and can write it to a file with filename_server = 'myserverfile.txt' fileobject_server = open(filename, 'wb') fileobject_server.write(filecontents_received) fileobject_server.close() Notice the difference between the fileobject variable and the filecontents variable. The subject of your post suggests that you want to send the fileobject variable (which doesn't make much sense) but your last message suggests that you're more interested in transferring the filecontents variable. This has already been said but if you are planning to have this server program connected to the internet, don't use the pickle module on the data that you receive. It would make your server vulnerable to being hacked. > Well according to the documentation at > > http://docs.python.org/py3k/**tutorial/inputoutput.html#** > reading-and-writing-files > > it should be straightforward to read and write pickled files > Not sure why you want to pickle a text file over the network when you > could just stream it between ports ! > > however ... > > I'm currently getting a Unicode decode error on the first byte in the > stream when it gets to the other end, no idea why so I guess I have to > continue searching, read the documentation above and see if you can figure > it out, that's what I'm doing. Lipska, are you getting the UnicodeDecodeError during the call to pickle.load? If stargate is opened with the binary flag there shouldn't be any decoding during the reading of the socket. pickle expects its input to be binary format so I guess it should only decode when trying to unpickle a string (I assume these are simply encoded in utf-8). Try just using stargate.read to see what data arrives. pickled data is often almost human readable so you might be able to make an educated guess at what it's trying to do. Also, the code you posted looks good, but I have one suggestion. Python has a nicer way of formatting strings using the str.format method. With this you can replace "I'm a " + self.name + " class spaceship and I have " + str(self.engines) + " engines") with "I'm a {0} class spaceship and I have {1} engines".format(self.name, self.engines) The advantages of this method are that 1) You keep the template string together so it's easier to read. 2) You don't need to call str() on any of your arguments. 3) It's also more efficient (in some cases). You can also use named parameters in the format string: "I'm a {name} class spaceship and I have {number} engines".format(name= self.name, number=self.engines) There is also the older, deprecated (but not about to be removed) method: "I'm a %s class spaceship and I have %i engines" % (self.name, self.engines) Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tsrdatatech at gmail.com Wed Aug 8 19:58:56 2012 From: tsrdatatech at gmail.com (Tom Russell) Date: Wed, 8 Aug 2012 19:58:56 -0400 Subject: Beautiful Soup Table Parsing Message-ID: I am parsing out a web page at http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar using BeautifulSoup. My problem is that I can parse into the table where the data I want resides but I cannot seem to figure out how to go about grabbing the contents of the cell next to my row header I want. For instance this code below: soup = BeautifulSoup(urlopen('http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar')) table = soup.find("table",{"class": "mdcTable"}) for row in table.findAll("tr"): for cell in row.findAll("td"): print cell.findAll(text=True) brings in a list that looks like this: [u'NYSE'] [u'Latest close'] [u'Previous close'] [u'Week ago'] [u'Issues traded'] [u'3,114'] [u'3,136'] [u'3,134'] [u'Advances'] [u'1,529'] [u'1,959'] [u'1,142'] [u'Declines'] [u'1,473'] [u'1,070'] [u'1,881'] [u'Unchanged'] [u'112'] [u'107'] [u'111'] [u'New highs'] [u'141'] [u'202'] [u'222'] [u'New lows'] [u'15'] [u'11'] [u'42'] [u'Adv. volume*'] [u'375,422,072'] [u'502,402,887'] [u'345,372,893'] [u'Decl. volume*'] [u'245,106,870'] [u'216,507,612'] [u'661,578,907'] [u'Total volume*'] [u'637,047,653'] [u'728,170,765'] [u'1,027,754,710'] [u'Closing tick'] [u'+131'] [u'+102'] [u'-505'] [u'Closing Arms (TRIN)\x86'] [u'0.62'] [u'0.77'] [u'1.20'] [u'Block trades*'] [u'3,874'] [u'4,106'] [u'4,463'] [u'Adv. volume'] [u'1,920,440,454'] [u'2,541,919,125'] [u'1,425,279,645'] [u'Decl. volume'] [u'1,149,672,387'] [u'1,063,007,504'] [u'2,812,073,564'] [u'Total volume'] [u'3,186,154,537'] [u'3,643,871,536'] [u'4,322,541,539'] [u'Nasdaq'] [u'Latest close'] [u'Previous close'] [u'Week ago'] [u'Issues traded'] [u'2,607'] [u'2,604'] [u'2,554'] [u'Advances'] [u'1,085'] [u'1,596'] [u'633'] [u'Declines'] [u'1,390'] [u'880'] [u'1,814'] [u'Unchanged'] [u'132'] [u'128'] [u'107'] [u'New highs'] [u'67'] [u'87'] [u'41'] [u'New lows'] [u'36'] [u'36'] [u'83'] [u'Closing tick'] [u'+225'] [u'+252'] [u'+588'] [u'Closing Arms (TRIN)\x86'] [u'0.48'] [u'0.46'] [u'0.69'] [u'Block trades'] [u'10,790'] [u'8,961'] [u'5,890'] [u'Adv. volume'] [u'1,114,620,628'] [u'1,486,955,619'] [u'566,904,549'] [u'Decl. volume'] [u'692,473,754'] [u'377,852,362'] [u'1,122,931,683'] [u'Total volume'] [u'1,856,979,279'] [u'1,883,468,274'] [u'1,714,837,606'] [u'NYSE Amex'] [u'Latest close'] [u'Previous close'] [u'Week ago'] [u'Issues traded'] [u'434'] [u'432'] [u'439'] [u'Advances'] [u'185'] [u'204'] [u'202'] [u'Declines'] [u'228'] [u'202'] [u'210'] [u'Unchanged'] [u'21'] [u'26'] [u'27'] [u'New highs'] [u'10'] [u'12'] [u'29'] [u'New lows'] [u'4'] [u'7'] [u'13'] [u'Adv. volume*'] [u'2,365,755'] [u'5,581,737'] [u'11,992,771'] [u'Decl. volume*'] [u'4,935,335'] [u'4,619,515'] [u'15,944,286'] [u'Total volume*'] [u'7,430,052'] [u'10,835,106'] [u'28,152,571'] [u'Closing tick'] [u'+32'] [u'+24'] [u'+24'] [u'Closing Arms (TRIN)\x86'] [u'1.63'] [u'0.64'] [u'1.12'] [u'Block trades*'] [u'75'] [u'113'] [u'171'] [u'NYSE Arca'] [u'Latest close'] [u'Previous close'] [u'Week ago'] [u'Issues traded'] [u'1,188'] [u'1,205'] [u'1,176'] [u'Advances'] [u'580'] [u'825'] [u'423'] [u'Declines'] [u'562'] [u'361'] [u'730'] [u'Unchanged'] [u'46'] [u'19'] [u'23'] [u'New highs'] [u'17'] [u'45'] [u'42'] [u'New lows'] [u'5'] [u'25'] [u'12'] [u'Adv. volume*'] [u'72,982,336'] [u'140,815,734'] [u'73,868,550'] [u'Decl. volume*'] [u'58,099,822'] [u'31,998,976'] [u'185,213,281'] [u'Total volume*'] [u'146,162,965'] [u'175,440,329'] [u'260,075,071'] [u'Closing tick'] [u'+213'] [u'+165'] [u'+83'] [u'Closing Arms (TRIN)\x86'] [u'0.86'] [u'0.73'] [u'1.37'] [u'Block trades*'] [u'834'] [u'1,043'] [u'1,593'] What I want to do is only be getting the data for NYSE and nothing else so I do not know if that's possible or not. Also I want to do something like: If cell.contents[0] == "Advances": Advances = next cell or whatever??---> this part I am not sure how to do. Can someone help point me in the right direction to get the first data point for the Advances row? I have others I will get as well but figure once I understand how to do this I can do the rest. Thanks, Tom From bruceg113355 at gmail.com Wed Aug 8 20:41:22 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Wed, 8 Aug 2012 17:41:22 -0700 (PDT) Subject: Is there a clever way to pass arguments Message-ID: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Is there a way in Python to pass arguments without listing each argument? For example, my program does the following: testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? I cannot change the function definition. Thanks, Bruce From amc96 at cam.ac.uk Wed Aug 8 20:47:35 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Thu, 09 Aug 2012 01:47:35 +0100 Subject: Is there a clever way to pass arguments In-Reply-To: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: On 09/08/2012 01:41, bruceg113355 at gmail.com wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce > testData(*z) assuming that there are exactly 8 entries in z see http://docs.python.org/dev/tutorial/controlflow.html#more-on-defining-functions ~Andrew From d at davea.name Wed Aug 8 21:07:04 2012 From: d at davea.name (Dave Angel) Date: Wed, 08 Aug 2012 21:07:04 -0400 Subject: Is there a clever way to pass arguments In-Reply-To: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: <50230D38.2050709@davea.name> On 08/08/2012 08:41 PM, bruceg113355 at gmail.com wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce If a function is expecting exactly 8 arguments, and z is a list of length 8, you can call the function like: testData(*z) if z is longer, then you'd need something like (untested) testData(*z[:8]) The * basically turns a list into separate arguments, and these are then applied to the formal parameters. -- DaveA From bruceg113355 at gmail.com Wed Aug 8 21:20:40 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Wed, 8 Aug 2012 18:20:40 -0700 (PDT) Subject: Is there a clever way to pass arguments In-Reply-To: References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: <8a815fe6-4f2f-438e-84ac-04063eb592ba@googlegroups.com> On Wednesday, August 8, 2012 9:07:04 PM UTC-4, Dave Angel wrote: > On 08/08/2012 08:41 PM, bruceg113355 at gmail.com wrote: > > > Is there a way in Python to pass arguments without listing each argument? > > > For example, my program does the following: > > > > > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > > > > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > > > I cannot change the function definition. > > > > > > Thanks, > > > Bruce > > If a function is expecting exactly 8 arguments, and z is a list of > > length 8, you can call the function like: > > > > testData(*z) > > > > if z is longer, then you'd need something like (untested) > > testData(*z[:8]) > > > > The * basically turns a list into separate arguments, and these are then > > applied to the formal parameters. > > > > -- > > > > DaveA Dave, your solution works! def testData (z0, z1, z2, z3, z4, z5, z6, z7): print (z0, z1, z2, z3, z4, z5, z6, z7) z = [] z.append(0) z.append(1) z.append(2) z.append(3) z.append(4) z.append(5) z.append(6) z.append(7) testData(*z[:8]) Thank you, Bruce From bruceg113355 at gmail.com Wed Aug 8 21:20:40 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Wed, 8 Aug 2012 18:20:40 -0700 (PDT) Subject: Is there a clever way to pass arguments In-Reply-To: References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: <8a815fe6-4f2f-438e-84ac-04063eb592ba@googlegroups.com> On Wednesday, August 8, 2012 9:07:04 PM UTC-4, Dave Angel wrote: > On 08/08/2012 08:41 PM, bruceg113355 at gmail.com wrote: > > > Is there a way in Python to pass arguments without listing each argument? > > > For example, my program does the following: > > > > > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > > > > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > > > I cannot change the function definition. > > > > > > Thanks, > > > Bruce > > If a function is expecting exactly 8 arguments, and z is a list of > > length 8, you can call the function like: > > > > testData(*z) > > > > if z is longer, then you'd need something like (untested) > > testData(*z[:8]) > > > > The * basically turns a list into separate arguments, and these are then > > applied to the formal parameters. > > > > -- > > > > DaveA Dave, your solution works! def testData (z0, z1, z2, z3, z4, z5, z6, z7): print (z0, z1, z2, z3, z4, z5, z6, z7) z = [] z.append(0) z.append(1) z.append(2) z.append(3) z.append(4) z.append(5) z.append(6) z.append(7) testData(*z[:8]) Thank you, Bruce From rosuav at gmail.com Wed Aug 8 21:32:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Aug 2012 11:32:00 +1000 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: <5022a1bb$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> <65e77682-00ab-4e86-b3cb-2046d6e5c628@r2g2000pbn.googlegroups.com> <5022a1bb$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 9, 2012 at 3:28 AM, Steven D'Aprano wrote: > (As they say: I'll believe that corporations are people when Texas > executes one.) If proper excuse you can trump any, You may wind up a Limited Company You cannot conveniently blow it up! -- WS Gilbert, "Utopia, Ltd" But not every "is-a" relationship needs to be represented as class inheritance. So what if all your Customers are Persons? Do you _really_ need a Person base class? In a lot of systems, you don't. If anything, you might have a generic base class for every entity that has an Address (which would include corporations), but that's more likely to want to be composition than inheritance (the customer Has-An Address rather than the customer Is-An AddressibleEntity). Flat is better than nested. Of course, if you don't need an actual use-case, I could invent several ridiculous base classes. Why not have one for Body, which would be subclassed by Person and Corporation (after all, a corporation is a body, that's where the name comes from), but not Ghost. And then you could have a mixin called Intelligence which is used by Corporation and Army (everyone knows what Business Intelligence and Military Intelligence are), sometimes used by Person, but never used by ClassDesign. ChrisA From steve+comp.lang.python at pearwood.info Wed Aug 8 21:34:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Aug 2012 01:34:31 GMT Subject: Is there a clever way to pass arguments References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: <502313a7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Aug 2012 18:20:40 -0700, bruceg113355 wrote: > z = [] > z.append(0) > z.append(1) > z.append(2) > z.append(3) > z.append(4) > z.append(5) > z.append(6) > z.append(7) That can be written as: z = [0, 1, 2, 3, 4, 5, 6, 7] Or better still: z = range(8) # In Python 3, use list(range(8)) instead. -- Steven From simoncropper at fossworkflowguides.com Wed Aug 8 23:51:23 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Thu, 09 Aug 2012 13:51:23 +1000 Subject: Geneology Packages -- WAS: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: <502333BB.4040305@fossworkflowguides.com> On 09/08/12 12:59, Dennis Lee Bieber wrote: > On Wed, 08 Aug 2012 20:31:57 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > >> A Tree consists of Node(s) and Leaf(s), relationships are modelled by >> following the Line(s) in the Tree diagram and that is it. Line may be a >> class as in 'the patriarchal line' I'm not sure, it would come out in >> the iterative wash. >> >> We can infer whatever we want from this simple model. A Leaf is a child, >> until it becomes a parent when it becomes a Node. To anthropomorphize a >> bit more (I love that word) and introduce non species specific words and >> concepts, a Node can be a father or mother (simple to implement by > > If a "node" is a father or mother, and it takes one of each to > produce a "leaf", your "tree" has just collapsed. > > In genealogy, a "tree" is merely the representation -- in one > direction -- of relationships from a single Person to either all > ancestors, or to all descendents. > > "Father", "mother", "son", "daughter" (or to simplify, "parent", > "child") are merely roles taken on by a person in relationship to > another person. A Person can exist even if we do not know who the > parents were, nor if there are any children. > >> But what of all the ephemeral data that goes with a sentient existance >> on this planet such as birth certificates, newspaper articles, >> christenings, death certificates, photographs etc etc, what about >> pegigree certificates, innoculation records and any other trivia, >> information and flotsam that goes with a pedigree Dog or Horse or indeed >> Parrot. >> > Those documents are the /evidence/ used to prove the linkages of the > Person. > > Granted, the most popular genealogy program tends to be the least > capable -- it won't let one add a person without creating a "family" > first; and most all evidence is recorded as just a text memo. > > In contrast, TMG, provides for "Sources" (the documents), > "Citations" (references to sources, used in the events in the person's > life), "Repositories" (where the source can be found). Events cover > things like "Birth", "Marriage", "Death", "Graduation", etc. [one can > create custom events too]. Events have a date, a location, and can have > multiple citations to the source the provides evidence that the event > took place and involved the person to which it is linked. In TMG, there > is no "family" as such -- only the linkages from relationship events (a > "birth" event does not link a child to its parents; that is done via a > pair of parent-child relationships [father-relationship, > mother-relationship] and TMG supports having multiples -- only the pair > marked a "primary" is used to produce "tree-like" reports, but the > system supports having birth-parents and adoptive-parents at the same > time in the data). It even supports having multiple "Birth" events too, > if one finds conflicting evidence and can not determine if some is > invalid. > > I'm not going to go into depth, but the TMG (v8) database consists > of 29 tables, and the user interface centers on displaying a list of > events for a person. Oh, and the person can have more than one name too, > though only one can be listed as primary (shows at the top of the page) > -- the others appear as name events. > > The absolute minimum to define a person in TMG is an ID number (the > internal primary key) and preferably a "primary" name (and the name > could be all blanks -- though having multiple people with no names, just > ID numbers, makes for difficulty when later adding relationships: does > this person connect to "(---unknown---)(---unknown---)" #2718 or to > "(---unknown---)(---unknown---)" #3145 ) > Since we have graduated to a completely different topic I have renamed the thread. If people are interested in a totally python-based open source FREE (as in no $$) package that can do all the above try gramps... http://gramps-project.org/ I have used this package for a few years now and it is fantastic. Check out the features page to see what I mean. http://gramps-project.org/features/ -- Cheers Simon Simon Cropper - Open Content Creator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From ben+python at benfinney.id.au Thu Aug 9 00:00:25 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Aug 2012 14:00:25 +1000 Subject: Geneology Packages References: <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: <87lihohfza.fsf_-_@benfinney.id.au> Simon Cropper writes: > Since we have graduated to a completely different topic I have renamed > the thread. Thank you. > If people are interested in a totally python-based open source FREE > (as in no $$) package that can do all the above try gramps... > > http://gramps-project.org/ In addition to being open source and zero-cost, more importantly it is free software. > I have used this package for a few years now and it is fantastic. I'm glad to hear this; I have seen Gramps mentioned for many years and it's great to see a mature (> 10 years) Python project that's still going strong and meeting a specialised need with free software. -- \ ?I object to doing things that computers can do.? ?Olin Shivers | `\ | _o__) | Ben Finney From dieter at handshake.de Thu Aug 9 01:43:51 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 09 Aug 2012 07:43:51 +0200 Subject: Beautiful Soup Table Parsing References: Message-ID: <87ehng62nc.fsf@handshake.de> Tom Russell writes: > I am parsing out a web page at > http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar > using BeautifulSoup. > > My problem is that I can parse into the table where the data I want > resides but I cannot seem to figure out how to go about grabbing the > contents of the cell next to my row header I want. > > For instance this code below: > > soup = BeautifulSoup(urlopen('http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar')) > > table = soup.find("table",{"class": "mdcTable"}) > for row in table.findAll("tr"): > for cell in row.findAll("td"): > print cell.findAll(text=True) > > brings in a list that looks like this: > > [u'NYSE'] > [u'Latest close'] > [u'Previous close'] > ... > > What I want to do is only be getting the data for NYSE and nothing > else so I do not know if that's possible or not. I am quite confident that it is possible (though I do not know the details). First thing to note: you can use the "break" statement in order to leave a loop "before time". As you have a nested loop, you might need a "break" on both levels, the outer loop's "break" probably controlled by a variable which indicates "success". Second thing to note: the "BeautifulSoup" documentation might tell you something about the return values of its methods. I assume "BeautifulSoup" builds upon "lxml" and the return values are "lxml" related. Then the "lxml" documentation would tell you how to inspect further details about the html structure. From cs at zip.com.au Thu Aug 9 01:52:22 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 9 Aug 2012 15:52:22 +1000 Subject: I thought I understood how import worked... In-Reply-To: <87hasehvfu.fsf@benfinney.id.au> References: <87hasehvfu.fsf@benfinney.id.au> Message-ID: <20120809055222.GA32358@cskk.homeip.net> On 08Aug2012 14:14, Ben Finney wrote: | Cameron Simpson writes: | > All of you are saying "two names for the same module", and variations | > thereof. And that is why the doco confuses. | > | > I would expect less confusion if the above example were described as | > _two_ modules, with the same source code. | | That's not true though, is it? It's the same module object with two | different references, I thought. No. They're two in-memory module instantiations with distinct module names. ISTR that when this got me I had imported the a module in one place with its full name and elsewhere with a bad relative reference; I forget the details now. But anyway, that got me the same module code loaded twice, distinctly named. | Also, even if what you say were true, ?source code? implies the module | was loaded from source code, when Python allows loading modules with no | source code available. So that implication just seems to be inviting | different confusion. Please let's nail one thing first. We can always quibble about the term "source code" to prefer "source code or byte code" or something of that ilki, later. But the confusion comes from calling these things the "same module". Which breaks the "modules are only loaded once" mental image. The confusion would often be avoided if the doco took the line that it is two modules because they were obtained using two names. Their original might be the same physical/logical place (such as a module source code file), but the end result is two modules. The point is that the "module" term would be better if it referred to the in-memory Python module, and didn't do double time as meaning the (typically) source file from which the Python code comes. Cheers, -- Cameron Simpson We had the experience, but missed the meaning. - T.S. Eliot From andipersti at gmail.com Thu Aug 9 03:25:49 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Thu, 09 Aug 2012 09:25:49 +0200 Subject: Beautiful Soup Table Parsing In-Reply-To: References: Message-ID: <502365FD.9030503@gmail.com> On 09.08.2012 01:58, Tom Russell wrote: > For instance this code below: > > soup = BeautifulSoup(urlopen('http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar')) > > table = soup.find("table",{"class": "mdcTable"}) > for row in table.findAll("tr"): > for cell in row.findAll("td"): > print cell.findAll(text=True) > > brings in a list that looks like this: [snip] > What I want to do is only be getting the data for NYSE and nothing > else so I do not know if that's possible or not. Also I want to do > something like: > > If cell.contents[0] == "Advances": > Advances = next cell or whatever??---> this part I am not sure how to do. > > Can someone help point me in the right direction to get the first data > point for the Advances row? I have others I will get as well but > figure once I understand how to do this I can do the rest. To get the header row you could do something like: header_row = table.find(lambda tag: tag.td.string == "NYSE") From there you can look for the next row you are interested in: advances_row = header_row.findNextSibling(lambda tag: tag.td.string == "Advances") You could also iterate through all next siblings of the header_row: for row in header_row.findNextSiblings("tr"): # do something Bye, Andreas From lipskathekat at yahoo.co.uk Thu Aug 9 03:29:38 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 08:29:38 +0100 Subject: Looking for a good introduction to object oriented programming with Python In-Reply-To: References: <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> Message-ID: On 09/08/12 03:59, Dennis Lee Bieber wrote: > On Wed, 08 Aug 2012 20:31:57 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > [snip] > > If a "node" is a father or mother, and it takes one of each to > produce a "leaf", your "tree" has just collapsed. This would come out in the iterative wash and I'm sure it could be resolved without resorting to a Person class People are starting to get annoyed by this thread now (I'm surprised it has taken so long) so it's probably best to move on. lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jeanmichel at sequans.com Thu Aug 9 05:05:30 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 09 Aug 2012 11:05:30 +0200 Subject: Is there a clever way to pass arguments In-Reply-To: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> Message-ID: <50237D5A.6000108@sequans.com> bruceg113355 at gmail.com wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce > testData(*z) or better (imo) testData(z) and make testData handle a list (8 parameters, that's a lot of parameters). JM From rosuav at gmail.com Thu Aug 9 05:13:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Aug 2012 19:13:31 +1000 Subject: Is there a clever way to pass arguments In-Reply-To: <50237D5A.6000108@sequans.com> References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <50237D5A.6000108@sequans.com> Message-ID: On Thu, Aug 9, 2012 at 7:05 PM, Jean-Michel Pichavant wrote: > bruceg113355 at gmail.com wrote: >> >> I cannot change the function definition. > > or better (imo) > testData(z) and make testData handle a list (8 parameters, that's a lot of > parameters). He can't change the function definition. ChrisA From jeanmichel at sequans.com Thu Aug 9 05:50:42 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 09 Aug 2012 11:50:42 +0200 Subject: Is there a clever way to pass arguments In-Reply-To: References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <50237D5A.6000108@sequans.com> Message-ID: <502387F2.2010104@sequans.com> Chris Angelico wrote: > On Thu, Aug 9, 2012 at 7:05 PM, Jean-Michel Pichavant > wrote: > >> bruceg113355 at gmail.com wrote: >> >>> I cannot change the function definition. >>> >> or better (imo) >> testData(z) and make testData handle a list (8 parameters, that's a lot of >> parameters). >> > > He can't change the function definition. > > ChrisA > my bad JM From jldunn2000 at gmail.com Thu Aug 9 07:30:22 2012 From: jldunn2000 at gmail.com (loial) Date: Thu, 9 Aug 2012 04:30:22 -0700 (PDT) Subject: pycups Message-ID: I am looking to monitor print jobs on linux via python. pycups looks a possibility, but I cannot find any useful tutorial, examples of how to use it. Can anyone help? From soloflyr at gmail.com Thu Aug 9 09:36:34 2012 From: soloflyr at gmail.com (soloflyr at gmail.com) Date: Thu, 9 Aug 2012 06:36:34 -0700 (PDT) Subject: Getting started with IDLE and Python - no highlighting and no execution In-Reply-To: References: Message-ID: <5094008e-1df3-4b6d-9d50-6a7a4751dcf7@googlegroups.com> On Sunday, August 5, 2012 7:46:54 PM UTC-4, PeterSo wrote: > I am just starting to learn Python, and I like to use the editor > > instead of the interactive shell. So I wrote the following little > > program in IDLE > > > > # calculating the mean > > > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > > > def mean(data): > > return sum(data)/len(data) > > > > mean(data1) > > > > > > There is no syntax highlighting and when I ran it F5, I got the > > following in the shell window. > > > > > > >>> ================================ RESTART > > ================================ > > >>> > > >>> > > > > > > Any ideas? > > If I added print mean(data1), it gave me a invalid syntax > > > > # calculating the mean > > > > data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] > > data2=[1,2,3,4,5] > > > > def mean(data): > > return sum(data)/len(data) > > > > mean(data1) > > print mean(data1) did you call you file xxx.py IDLE looks for the .py extension to identify the program as python code. From dthomas86 at me.com Thu Aug 9 10:38:32 2012 From: dthomas86 at me.com (David Thomas) Date: Thu, 9 Aug 2012 07:38:32 -0700 (PDT) Subject: Python and OSX 10.8 Message-ID: <0dee63e3-a4ca-4d2e-85ae-81ccc4d411c1@googlegroups.com> Im looking to upgrade my Mac to 10.8 and I'm worried if Python and IDLE may not run on it. When I try to run this command in Terminal: python -m idlelib.idle I can not launch IDLE which comes bundled on Mac. On Lion it's been fine but I've tried it on my friend's copy of Mountain Lion and it will not work. From wrw at mac.com Thu Aug 9 11:06:32 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Thu, 09 Aug 2012 11:06:32 -0400 Subject: Python and OSX 10.8 In-Reply-To: <0dee63e3-a4ca-4d2e-85ae-81ccc4d411c1@googlegroups.com> References: <0dee63e3-a4ca-4d2e-85ae-81ccc4d411c1@googlegroups.com> Message-ID: On Aug 9, 2012, at 10:38 AM, David Thomas wrote: > Im looking to upgrade my Mac to 10.8 and I'm worried if Python and IDLE may not run on it. > When I try to run this command in Terminal: python -m idlelib.idle > I can not launch IDLE which comes bundled on Mac. On Lion it's been fine but I've tried it on my friend's copy of Mountain Lion and it will not work. > -- > http://mail.python.org/mailman/listinfo/python-list It is almost certainly because on your friend's ML system the Python being invoked is still Apple's installation in /System/Library/Frameworks. If you download and install the default 2.7 from python.org (which will go in /Library/Frameworks?) it will work. I just tested your command and it works fine on my ML system. If you want, I'll send you my python path off line. -Bill From lipskathekat at yahoo.co.uk Thu Aug 9 11:15:33 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 16:15:33 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs Message-ID: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> First of all sincere apologies if this is blindingly obvious and I just missed it In the documentation at http://docs.python.org/py3k/library/socketserver.html mention is made more than once of a class socketserver.StreamRequestHandler in the examples in this chapter we see usage examples for socketserver.BaseRequestHandler I am trying to find documentation for these two classes as I would like to use the former and, well I'd just like to learn more aout the latter. I've looked in the general index and used Google. The problem is that however hard I look I just cannot find it !!! In Eclipse I have the entire standard library mounted on an explorer node. When I find socketserver.py I can navigate to the BaseRequestHandler and StreamRequestHandler classes but I can't find the (documented) class [socketserver].RequestHandler class in socketserver.py nor can I find any explicit documentation for the classes socketserver.StreamRequestHandler and socketserver.BaseRequestHandler. I'm probably being INCREDIBLY dense here but what am I missing ? Incidently if I read the code for these two classes I CAN understand what they do but this is not always the case and anyway, how many other potentially useful classes are lurking undocumented in the library This is NOT intended as a criticism but it is frustrating. many thanks lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From alister.ware at ntlworld.com Thu Aug 9 13:14:25 2012 From: alister.ware at ntlworld.com (Alister) Date: Thu, 09 Aug 2012 17:14:25 GMT Subject: Is there a clever way to pass arguments References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <50237D5A.6000108@sequans.com> Message-ID: On Thu, 09 Aug 2012 19:13:31 +1000, Chris Angelico wrote: > On Thu, Aug 9, 2012 at 7:05 PM, Jean-Michel Pichavant > wrote: >> bruceg113355 at gmail.com wrote: >>> >>> I cannot change the function definition. >> >> or better (imo) >> testData(z) and make testData handle a list (8 parameters, that's a lot >> of parameters). > > He can't change the function definition. > > ChrisA True but it is still worth highlighting that the function definition may not be ideal depending on the requirements of the function. some people read these threads to learn general concepts & not to find answers to a single explicit case. -- I want to so HAPPY, the VEINS in my neck STAND OUT!! From lipskathekat at yahoo.co.uk Thu Aug 9 14:08:36 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 19:08:36 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: On 09/08/12 18:39, Dennis Lee Bieber wrote: > On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > > >> in the examples in this chapter we see usage examples for >> socketserver.BaseRequestHandler >> > So far as I can tell, all RequestHandler objects are covered in > section "20.19.3 RequestHandler Objects" > >> >> In Eclipse I have the entire standard library mounted on an explorer >> node. When I find socketserver.py I can navigate to the >> BaseRequestHandler and StreamRequestHandler classes >> but I can't find the (documented) class [socketserver].RequestHandler >> class in socketserver.py nor can I find any explicit documentation for >> the classes socketserver.StreamRequestHandler >> and socketserver.BaseRequestHandler. >> > > There is no "RequestHandler" class. The section is general to all > RequestHandler OBJECTS (Base, Stream, and Datagram). > > Stream and Datagram request handlers are subclasses of Base, in > which the setup/finish methods handle the creation/destruction of > "file-like" attributes -- allowing one to just do read/write operations > within the core handle() method, instead of having to be concerned with > the type of connection and performing actual socket recv()/send() > operations. They are documented in the second paragraph of the .handle() > method in sectin 20.19.3 > > In all cases, you are responsible for providing the contents of the > handle() method. > > > -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From lipskathekat at yahoo.co.uk Thu Aug 9 14:37:31 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 19:37:31 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: On 09/08/12 18:39, Dennis Lee Bieber wrote: > On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > > >> in the examples in this chapter we see usage examples for >> socketserver.BaseRequestHandler >> > So far as I can tell, all RequestHandler objects are covered in > section "20.19.3 RequestHandler Objects" Yes, I know, I've read it. Thank you. > There is no "RequestHandler" class. The section is general to all > RequestHandler OBJECTS (Base, Stream, and Datagram). Yes I know, I've read socketserver.py. Thank you. Why do I find myself getting annoyed here ? This is hard work but I'll try again. socketserver.RequestHandler is EXPLICITLY documented in section "20.19.3 RequestHandler Objects" yet does not exist in socketserver.py Does this not strike you as odd. I certainly strikes me as odd. Maybe it should be socketserver.BaseRequestHandler that is documented here. The CLASSES socketserver.StreamRequestHandler and socketserver.DatagramRequestHandler are DEFINED in socketserver.py They are NOT Objects, they are CLASSES yet they are NOT EXPLICITLY documented in section 20.19.3 or any other section as far as I can tell. This is the question I was asking. I am quite capable of extracting the slightly obtuse documentation in the section and confirming my assumptions by reading the code. So, I'll try again. Is there anywhere that documents EXPLICITLY all the publicly visible classes in the standard library. If there is I'd be most grateful if you could point me to it as I can't find it If there isn't how does one go about contributing to the documentation. Thank you for taking the time to reply lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From dihedral88888 at googlemail.com Thu Aug 9 14:39:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 9 Aug 2012 11:39:56 -0700 (PDT) Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: <6b530f50-27ff-4cf0-b5f3-dae4b9c2fded@googlegroups.com> Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j) Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)) list(range(N,100))+list(range(1,N)) //good for i I contribute my python code here to avoid any divison. From dihedral88888 at googlemail.com Thu Aug 9 14:46:48 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 9 Aug 2012 11:46:48 -0700 (PDT) Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j) list(range(N,100))+ list(range(0,N)) //good for j Well, this is the way! From breamoreboy at yahoo.co.uk Thu Aug 9 14:55:39 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Aug 2012 19:55:39 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: On 09/08/2012 19:37, lipska the kat wrote: > On 09/08/12 18:39, Dennis Lee Bieber wrote: >> On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat >> declaimed the following in >> gmane.comp.python.general: >> >> >>> in the examples in this chapter we see usage examples for >>> socketserver.BaseRequestHandler >>> >> So far as I can tell, all RequestHandler objects are covered in >> section "20.19.3 RequestHandler Objects" > > Yes, I know, I've read it. Thank you. > >> There is no "RequestHandler" class. The section is general to all >> RequestHandler OBJECTS (Base, Stream, and Datagram). > > Yes I know, I've read socketserver.py. Thank you. > Why do I find myself getting annoyed here ? > > This is hard work but I'll try again. > > socketserver.RequestHandler is EXPLICITLY documented in section "20.19.3 > RequestHandler Objects" yet does not exist in socketserver.py > Does this not strike you as odd. I certainly strikes me as odd. Maybe it > should be socketserver.BaseRequestHandler that is documented here. > > The CLASSES socketserver.StreamRequestHandler and > socketserver.DatagramRequestHandler are DEFINED in socketserver.py > They are NOT Objects, they are CLASSES yet they are NOT EXPLICITLY > documented in section 20.19.3 or any other section as far as I can tell. > > This is the question I was asking. I am quite capable of extracting the > slightly obtuse documentation in the section and confirming my > assumptions by reading the code. > > So, I'll try again. > > Is there anywhere that documents EXPLICITLY all the publicly visible > classes in the standard library. > > If there is I'd be most grateful if you could point me to it as I can't > find it > > If there isn't how does one go about > contributing to the documentation. > > Thank you for taking the time to reply > > lipska > Dennis was only trying to help so please don't shout, thanks. -- Cheers. Mark Lawrence. From __peter__ at web.de Thu Aug 9 15:07:18 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Aug 2012 21:07:18 +0200 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: lipska the kat wrote: > If there isn't how does one go about > contributing to the documentation. http://docs.python.org/dev/py3k/bugs.html A similar link should be right there in the footer of the socketserver documentation. From lipskathekat at yahoo.co.uk Thu Aug 9 15:20:59 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 20:20:59 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: On 09/08/12 19:55, Mark Lawrence wrote: > On 09/08/2012 19:37, lipska the kat wrote: >> On 09/08/12 18:39, Dennis Lee Bieber wrote: >>> On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat >>> declaimed the following in >>> gmane.comp.python.general: >>> >>> >>>> in the examples in this chapter we see usage examples for >>>> socketserver.BaseRequestHandler >>>> >>> So far as I can tell, all RequestHandler objects are covered in >>> section "20.19.3 RequestHandler Objects" >> >> Yes, I know, I've read it. Thank you. > > Dennis was only trying to help so please don't shout, thanks. I appreciate that he was trying to help but quoting entire sections of text that I have already stated that I have read is pointless and wastes everybody's time. I asked a specific question which he failed to answer. I also thanked him for his time lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From lipskathekat at yahoo.co.uk Thu Aug 9 15:23:29 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 09 Aug 2012 20:23:29 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: On 09/08/12 20:07, Peter Otten wrote: > lipska the kat wrote: > >> If there isn't how does one go about >> contributing to the documentation. > > http://docs.python.org/dev/py3k/bugs.html > > A similar link should be right there in the footer of the socketserver > documentation. It is indeed, thank you. lipska. -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From GangGreene at invalid.com Thu Aug 9 15:39:34 2012 From: GangGreene at invalid.com (GangGreene) Date: Thu, 09 Aug 2012 15:39:34 -0400 Subject: Is there a clever way to pass arguments References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <50237D5A.6000108@sequans.com> Message-ID: Alister wrote: [putolin] > some people read these threads to learn general concepts & not to find > answers to a single explicit case. Some people (me) don't know the first thing about python and are in the learning/exploratory phase. From tjreedy at udel.edu Thu Aug 9 15:45:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Aug 2012 15:45:56 -0400 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: <1os7281s5ad5e10f5v3tku0j7g9hjnsbuu@invalid.netcom.com> References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> <1os7281s5ad5e10f5v3tku0j7g9hjnsbuu@invalid.netcom.com> Message-ID: On 8/9/2012 1:39 PM, Dennis Lee Bieber wrote: > On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat > declaimed the following in > gmane.comp.python.general: > > >> in the examples in this chapter we see usage examples for >> socketserver.BaseRequestHandler >> > So far as I can tell, all RequestHandler objects are covered in > section "20.19.3 RequestHandler Objects" > >> >> In Eclipse I have the entire standard library mounted on an explorer >> node. When I find socketserver.py I can navigate to the >> BaseRequestHandler and StreamRequestHandler classes >> but I can't find the (documented) class [socketserver].RequestHandler >> class in socketserver.py nor can I find any explicit documentation for >> the classes socketserver.StreamRequestHandler >> and socketserver.BaseRequestHandler. >> > > There is no "RequestHandler" class. The section is general to all > RequestHandler OBJECTS (Base, Stream, and Datagram). > > Stream and Datagram request handlers are subclasses of Base, in > which the setup/finish methods handle the creation/destruction of > "file-like" attributes -- allowing one to just do read/write operations > within the core handle() method, instead of having to be concerned with > the type of connection and performing actual socket recv()/send() > operations. They are documented in the second paragraph of the .handle() > method in sectin 20.19.3 > > In all cases, you are responsible for providing the contents of the > handle() method. I think the doc can be improved a bit and opened an issue to "Improve socketserver doc" http://bugs.python.org/issue15608 -- Terry Jan Reedy From d at davea.name Thu Aug 9 15:45:57 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 15:45:57 -0400 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> Message-ID: <50241375.4060608@davea.name> On 08/09/2012 02:37 PM, lipska the kat wrote: > On 09/08/12 18:39, Dennis Lee Bieber wrote: >> On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat >> declaimed the following in >> gmane.comp.python.general: >> >> >>> in the examples in this chapter we see usage examples for >>> socketserver.BaseRequestHandler >>> > I don't know this module at all, so I'll make more generic comments. > socketserver.RequestHandler is EXPLICITLY documented in section > "20.19.3 RequestHandler Objects" yet does not exist in socketserver.py > Does this not strike you as odd. I certainly strikes me as odd. Maybe > it should be socketserver.BaseRequestHandler that is documented here. > The question should not be "is it in socketserver.py," but "does it work as documented" ? Some of the code is likely in C modules, and thus not visible in any py file. > The CLASSES socketserver.StreamRequestHandler and > socketserver.DatagramRequestHandler are DEFINED in socketserver.py > They are NOT Objects, they are CLASSES yet they are NOT EXPLICITLY > documented in section 20.19.3 or any other section as far as I can tell. > > The documentation is for the elements that the library authors expected and intended people to be able to use. Reasons for not documenting a particular class or a particular function/method might include the fact that it's considered obscure, it's unsupported and may not be available in the future, it's there only for compatibility with an older version and shouldn't be used in new code, or it's an implementation detail and/or might not be visible on other platforms. A single leading underscore should normally be used for that last case. > Is there anywhere that documents EXPLICITLY all the publicly visible > classes in the standard library. >> Just because it's publicly visible doesn't necessarily mean it's part of the intended interface. Now, for this particular module, perhaps none of my arguments apply, and/or there's a flawed or incomplete documentation. -- DaveA From tjreedy at udel.edu Thu Aug 9 15:48:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Aug 2012 15:48:00 -0400 Subject: Is there a clever way to pass arguments In-Reply-To: <502387F2.2010104@sequans.com> References: <0aaad6e4-8751-4073-bf9c-14285c1f3422@googlegroups.com> <50237D5A.6000108@sequans.com> <502387F2.2010104@sequans.com> Message-ID: On 8/9/2012 5:50 AM, Jean-Michel Pichavant wrote: > Chris Angelico wrote: >> On Thu, Aug 9, 2012 at 7:05 PM, Jean-Michel Pichavant >> wrote: >>> bruceg113355 at gmail.com wrote: >>>> I cannot change the function definition. >>> or better (imo) >>> testData(z) and make testData handle a list (8 parameters, that's a >>> lot of >>> parameters). >> >> He can't change the function definition. One can always wrap a function with an adaptor if the signature is too awful. -- Terry Jan Reedy From giuseppe.amatulli at gmail.com Thu Aug 9 16:06:01 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Thu, 9 Aug 2012 13:06:01 -0700 (PDT) Subject: no data exclution and unique combination. In-Reply-To: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> References: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> Message-ID: Terry and MRAB, thanks for yours suggestions, in the end i found this solution mask=( a != 0 ) & ( b != 0 ) a_mask=a[mask] b_mask=b[mask] array2D = np.array(zip(a_mask,b_mask)) unique=dict() for row in array2D : row = tuple(row) if row in unique: unique[row] += 1 else: unique[row] = 1 print unique {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} I choose this solution because i could not install "from collections import Counter". Anyway how i can print to a file the unique results without the brackets and obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2 Thanks in advance Best regards. Giuseppe On Tuesday, 24 July 2012 13:27:05 UTC-5, giuseppe... at gmail.com wrote: > Hi, > > would like to take eliminate a specific number in an array and its correspondent in an other array, and vice-versa. > > > > given > > > > a=np.array([1,2,4,4,5,4,1,4,1,1,2,4]) > > b=np.array([1,2,3,5,4,4,1,3,2,1,3,4]) > > > > no_data_a=1 > > no_data_b=2 > > > > a_clean=array([4,4,5,4,4,4]) > > b_clean=array([3,5,4,4,3,4]) > > > > after i need to calculate unique combination in pairs to count the observations > > and obtain > > (4,3,2) > > (4,5,1) > > (5,4,1) > > (4,4,2) > > > > For the fist task i did > > > > a_No_data_a = a[a != no_data_a] > > b_No_data_a = b[a != no_data_a] > > > > b_clean = b_No_data_a[b_No_data_a != no_data_b] > > a_clean = a_No_data_a[a_No_data_a != no_data_b] > > > > but the results are not really stable. > > > > For the second task > > The np.unique would solve the problem if it can be apply to a two arrays. > > > > Any idea? > > thanks in advance > > Giuseppe From giuseppe.amatulli at gmail.com Thu Aug 9 16:11:19 2012 From: giuseppe.amatulli at gmail.com (giuseppe.amatulli at gmail.com) Date: Thu, 9 Aug 2012 13:11:19 -0700 (PDT) Subject: save dictionary to a file without brackets. Message-ID: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2 Any ideas? Thanks in advance Giuseppe From vashkevichrb at gmail.com Thu Aug 9 16:22:57 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 00:22:57 +0400 Subject: save dictionary to a file without brackets. In-Reply-To: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: for key in dict: print key[0], key[1], dict[key] 10.08.2012, ? 0:11, giuseppe.amatulli at gmail.com ???????(?): > Hi, > I have a dict() unique > like this > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > Any ideas? > Thanks in advance > Giuseppe > -- > http://mail.python.org/mailman/listinfo/python-list From oscar.j.benjamin at gmail.com Thu Aug 9 16:25:46 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 9 Aug 2012 21:25:46 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: On Aug 9, 2012 9:17 PM, wrote: > > Hi, > I have a dict() unique > like this > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > Any ideas? > Thanks in advance How's this? from __future__ import print_function output = open("out.txt", "w") for (a, b), c in d.items(): print(a, b, c, file=output) output.close() Oscar. > -- > 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 9 16:35:32 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Aug 2012 15:35:32 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: <50241F14.2060209@tim.thechases.com> On 08/09/12 15:22, Roman Vashkevich wrote: >> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >> 4 5 1 >> 5 4 1 >> 4 4 2 >> 2 3 1 >> 4 3 2 > > for key in dict: > print key[0], key[1], dict[key] This might read more cleanly with tuple unpacking: for (edge1, edge2), cost in d.iteritems(): # or .items() print edge1, edge2, cost (I'm making the assumption that this is a edge/cost graph...use appropriate names according to what they actually mean) -tkc From gelonida at gmail.com Thu Aug 9 16:35:49 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 09 Aug 2012 22:35:49 +0200 Subject: save dictionary to a file without brackets. In-Reply-To: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: On 08/09/2012 10:11 PM, giuseppe.amatulli at gmail.com wrote: > Hi, > I have a dict() unique > like this > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > Any ideas? > Thanks in advance > Giuseppe > Boring explicit solution: d = {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} for key, val in d.items(): v1,v2 = key fout.write("%d %d %d\n" % (v1, v2, val)) From giuseppe.amatulli at gmail.com Thu Aug 9 16:35:54 2012 From: giuseppe.amatulli at gmail.com (Giuseppe Amatulli) Date: Thu, 9 Aug 2012 15:35:54 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: thanks for the fast replies my testing were very closed to yours but i did not know how On 9 August 2012 15:25, Oscar Benjamin wrote: > > On Aug 9, 2012 9:17 PM, wrote: >> >> Hi, >> I have a dict() unique >> like this >> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >> and i want to print to a file without the brackets comas and semicolon in >> order to obtain something like this? >> 4 5 1 >> 5 4 1 >> 4 4 2 >> 2 3 1 >> 4 3 2 >> Any ideas? >> Thanks in advance > > How's this? > > from __future__ import print_function > > output = open("out.txt", "w") > > for (a, b), c in d.items(): > print(a, b, c, file=output) > > output.close() > > Oscar. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Giuseppe Amatulli Web: www.spatial-ecology.net From giuseppe.amatulli at gmail.com Thu Aug 9 16:38:50 2012 From: giuseppe.amatulli at gmail.com (Giuseppe Amatulli) Date: Thu, 9 Aug 2012 15:38:50 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> Message-ID: thanks for the fast replies my testing were very closed to yours but i did not know how to print the the number after the semicolon! thanks! On 9 August 2012 15:25, Oscar Benjamin wrote: > > On Aug 9, 2012 9:17 PM, wrote: >> >> Hi, >> I have a dict() unique >> like this >> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >> and i want to print to a file without the brackets comas and semicolon in >> order to obtain something like this? >> 4 5 1 >> 5 4 1 >> 4 4 2 >> 2 3 1 >> 4 3 2 >> Any ideas? >> Thanks in advance > > How's this? > > from __future__ import print_function > > output = open("out.txt", "w") > > for (a, b), c in d.items(): > print(a, b, c, file=output) > > output.close() > > Oscar. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Giuseppe Amatulli Web: www.spatial-ecology.net From vashkevichrb at gmail.com Thu Aug 9 16:41:32 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 00:41:32 +0400 Subject: save dictionary to a file without brackets. In-Reply-To: <50241F14.2060209@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> Message-ID: <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> dict.items() is a list - linear access time whereas with 'for key in dict:' access time is constant: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 10.08.2012, ? 0:35, Tim Chase ???????(?): > On 08/09/12 15:22, Roman Vashkevich wrote: >>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>> 4 5 1 >>> 5 4 1 >>> 4 4 2 >>> 2 3 1 >>> 4 3 2 >> >> for key in dict: >> print key[0], key[1], dict[key] > > This might read more cleanly with tuple unpacking: > > for (edge1, edge2), cost in d.iteritems(): # or .items() > print edge1, edge2, cost > > (I'm making the assumption that this is a edge/cost graph...use > appropriate names according to what they actually mean) > > -tkc > > > From breamoreboy at yahoo.co.uk Thu Aug 9 17:17:50 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Aug 2012 22:17:50 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> Message-ID: On 09/08/2012 21:41, Roman Vashkevich wrote: > dict.items() is a list - linear access time whereas with 'for key in dict:' access time is constant: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 > > 10.08.2012, ? 0:35, Tim Chase ???????(?): > >> On 08/09/12 15:22, Roman Vashkevich wrote: >>>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>>> 4 5 1 >>>> 5 4 1 >>>> 4 4 2 >>>> 2 3 1 >>>> 4 3 2 >>> >>> for key in dict: >>> print key[0], key[1], dict[key] >> >> This might read more cleanly with tuple unpacking: >> >> for (edge1, edge2), cost in d.iteritems(): # or .items() >> print edge1, edge2, cost >> >> (I'm making the assumption that this is a edge/cost graph...use >> appropriate names according to what they actually mean) >> >> -tkc >> >> >> > I'm impressed, the OP gives a dict with five entries and already we're optimising, a cunning plan if ever there was one. Hum, I think I'll start on the blast proof ferro-concrete bunker tonight just in case WWIII starts tomorrow. -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Thu Aug 9 17:21:07 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Aug 2012 16:21:07 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> Message-ID: <502429C3.5000600@tim.thechases.com> On 08/09/12 15:41, Roman Vashkevich wrote: > 10.08.2012, ? 0:35, Tim Chase ???????(?): >> On 08/09/12 15:22, Roman Vashkevich wrote: >>>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>>> 4 5 1 >>>> 5 4 1 >>>> 4 4 2 >>>> 2 3 1 >>>> 4 3 2 >>> >>> for key in dict: >>> print key[0], key[1], dict[key] >> >> This might read more cleanly with tuple unpacking: >> >> for (edge1, edge2), cost in d.iteritems(): # or .items() >> print edge1, edge2, cost >> >> (I'm making the assumption that this is a edge/cost graph...use >> appropriate names according to what they actually mean) > > dict.items() is a list - linear access time whereas with 'for > key in dict:' access time is constant: > http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 That link doesn't actually discuss dict.{iter}items() Both are O(N) because you have to touch each item in the dict--you can't iterate over N entries in less than O(N) time. For small data-sets, building the list and then iterating over it may be faster faster; for larger data-sets, the cost of building the list overshadows the (minor) overhead of a generator. Either way, the iterate-and-fetch-the-associated-value of .items() & .iteritems() can (should?) be optimized in Python's internals to the point I wouldn't think twice about using the more readable version. -tkc From d at davea.name Thu Aug 9 17:23:30 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 17:23:30 -0400 Subject: no data exclution and unique combination. In-Reply-To: References: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> Message-ID: <50242A52.2070609@davea.name> On 08/09/2012 04:06 PM, giuseppe.amatulli at gmail.com wrote: > > > print unique > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > > I choose this solution because i could not install "from collections import Counter". Nothing to install, at least for Python 2.7. collections is in the standard library, and Counter is in collections (new in version 2.7) > Anyway how i can print to a file the unique results without the brackets and obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > > To print out a dict in an explicit format, you want a loop. for key, val in unique.items(): print key[0], key[1], val Note that you cannot guarantee the order they will print out, once stored in a dict. You may want to sort them, or otherwise order them if it matters. Note I added my responses after the parts of your message that I was quoting. To put the response first is called top-posting, and against policy here. -- DaveA From tjreedy at udel.edu Thu Aug 9 17:33:58 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Aug 2012 17:33:58 -0400 Subject: no data exclution and unique combination. In-Reply-To: References: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> Message-ID: On 8/9/2012 4:06 PM, giuseppe.amatulli at gmail.com wrote: > Terry and MRAB, > thanks for yours suggestions, > in the end i found this solution > > > mask=( a != 0 ) & ( b != 0 ) > > a_mask=a[mask] > b_mask=b[mask] > > array2D = np.array(zip(a_mask,b_mask)) > > unique=dict() > for row in array2D : > row = tuple(row) > if row in unique: > unique[row] += 1 > else: > unique[row] = 1 I believe the 4 lines above are equivalent to unique[row] = unique.get(row, 0) + 1 -- Terry Jan Reedy From vashkevichrb at gmail.com Thu Aug 9 17:34:05 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 01:34:05 +0400 Subject: save dictionary to a file without brackets. In-Reply-To: <502429C3.5000600@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and this is why it's O(1). 10.08.2012, ? 1:21, Tim Chase ???????(?): > On 08/09/12 15:41, Roman Vashkevich wrote: >> 10.08.2012, ? 0:35, Tim Chase ???????(?): >>> On 08/09/12 15:22, Roman Vashkevich wrote: >>>>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>>>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>>>> 4 5 1 >>>>> 5 4 1 >>>>> 4 4 2 >>>>> 2 3 1 >>>>> 4 3 2 >>>> >>>> for key in dict: >>>> print key[0], key[1], dict[key] >>> >>> This might read more cleanly with tuple unpacking: >>> >>> for (edge1, edge2), cost in d.iteritems(): # or .items() >>> print edge1, edge2, cost >>> >>> (I'm making the assumption that this is a edge/cost graph...use >>> appropriate names according to what they actually mean) >> >> dict.items() is a list - linear access time whereas with 'for >> key in dict:' access time is constant: >> http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 > > That link doesn't actually discuss dict.{iter}items() > > Both are O(N) because you have to touch each item in the dict--you > can't iterate over N entries in less than O(N) time. For small > data-sets, building the list and then iterating over it may be > faster faster; for larger data-sets, the cost of building the list > overshadows the (minor) overhead of a generator. Either way, the > iterate-and-fetch-the-associated-value of .items() & .iteritems() > can (should?) be optimized in Python's internals to the point I > wouldn't think twice about using the more readable version. > > -tkc > > From tjreedy at udel.edu Thu Aug 9 17:46:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Aug 2012 17:46:29 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: <502429C3.5000600@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: On 8/9/2012 5:21 PM, Tim Chase wrote: > On 08/09/12 15:41, Roman Vashkevich wrote: >> 10.08.2012, ? 0:35, Tim Chase ???????(?): >>> On 08/09/12 15:22, Roman Vashkevich wrote: >>>>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>>>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>>>> 4 5 1 >>>>> 5 4 1 >>>>> 4 4 2 >>>>> 2 3 1 >>>>> 4 3 2 >>>> >>>> for key in dict: >>>> print key[0], key[1], dict[key] >>> >>> This might read more cleanly with tuple unpacking: >>> >>> for (edge1, edge2), cost in d.iteritems(): # or .items() >>> print edge1, edge2, cost >>> >>> (I'm making the assumption that this is a edge/cost graph...use >>> appropriate names according to what they actually mean) >> >> dict.items() is a list - linear access time whereas with 'for >> key in dict:' access time is constant: >> http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 > > That link doesn't actually discuss dict.{iter}items() > > Both are O(N) because you have to touch each item in the dict--you > can't iterate over N entries in less than O(N) time. For small > data-sets, building the list and then iterating over it may be > faster faster; for larger data-sets, the cost of building the list > overshadows the (minor) overhead of a generator. Either way, the > iterate-and-fetch-the-associated-value of .items() & .iteritems() > can (should?) be optimized in Python's internals to the point I > wouldn't think twice about using the more readable version. In 3.x, .keys, .values, and .items are set-like read-only views specifically designed for iteration. So in 3.x they are THE way to do so for whichever alternative is appropriate. Iterating by keys and then looking up values instead of yielding the values at the same time is extra work. -- Terry Jan Reedy From d at davea.name Thu Aug 9 17:47:45 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 17:47:45 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: <50243001.5030903@davea.name> On 08/09/2012 05:34 PM, Roman Vashkevich wrote: > Actually, they are different. > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > Dict uses hashing to get a value from the dict and this is why it's O(1). Sure, that's why for key in dict: print key[0], key[1], dict[key] is probably slower than for (edge1, edge2), cost in d.iteritems(): # or .items() print edge1, edge2, cost So, the latter is both faster and easier to read. Why are you arguing against it? Also, please stop top-posting. It's impolite here, and makes it much harder to figure out who is saying what, in what order. -- DaveA From ckaynor at zindagigames.com Thu Aug 9 17:49:03 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 9 Aug 2012 14:49:03 -0700 Subject: save dictionary to a file without brackets. In-Reply-To: <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: On Thu, Aug 9, 2012 at 2:34 PM, Roman Vashkevich wrote: > > Actually, they are different. > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > Dict uses hashing to get a value from the dict and this is why it's O(1). > Using "in" as an operator such as: "if key in dict" or "result = key in dict" is O(1) as you say. Iterating on the dictionary requires touching every item, and so is O(n), even though it also using "in" in the command. Here are a few quick timing tests I just ran with Python 2.6: >>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(1))') 0.078683853332734088 >>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(10))') 0.17451784110969015 >>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(100))') 1.1708168159579486 >>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(1))') 0.14186911440299355 >>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(10))') 0.33836512561802579 >>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(100))') 2.2544262854249268 >>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(1))') 0.10009793211446549 >>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(10))') 0.38825072496723578 >>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(100))') 3.3020098061049339 As can be seen here, a 1-item dictionary iterated in 0.07 seconds, 10 items in 0.17 seconds, and 100 items in 1.17 seconds. That is fairly close to linear, especially when considering the overhead of a complete no-op Using iteritems, it appears to actually scale slightly better than linear, though it is slower than just the plain iteration. Doing a plain iteration, then looking up the keys to get the values also appears to be linear, and is even slower than iteritems. From ckaynor at zindagigames.com Thu Aug 9 17:51:17 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 9 Aug 2012 14:51:17 -0700 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: I realized, I should have done 10, 100, 1000 rather than 1, 10, 100 for better results, so here are the results for 1000 items. It still maintains the same pattern: >>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(1000))') 10.166595947685153 >>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(1000))') 19.922474218828711 >>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(1000))') 31.007666660415282 Chris On Thu, Aug 9, 2012 at 2:49 PM, Chris Kaynor wrote: > On Thu, Aug 9, 2012 at 2:34 PM, Roman Vashkevich wrote: >> >> Actually, they are different. >> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >> Dict uses hashing to get a value from the dict and this is why it's O(1). >> > > Using "in" as an operator such as: "if key in dict" or "result = key > in dict" is O(1) as you say. Iterating on the dictionary requires > touching every item, and so is O(n), even though it also using "in" in > the command. > > Here are a few quick timing tests I just ran with Python 2.6: > >>>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(1))') > 0.078683853332734088 >>>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(10))') > 0.17451784110969015 >>>> timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(100))') > 1.1708168159579486 > >>>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(1))') > 0.14186911440299355 >>>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(10))') > 0.33836512561802579 >>>> timeit.timeit('for i in d.iteritems(): pass', 'd=dict.fromkeys(range(100))') > 2.2544262854249268 > >>>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(1))') > 0.10009793211446549 >>>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(10))') > 0.38825072496723578 >>>> timeit.timeit('for i in d: v=d[i]', 'd=dict.fromkeys(range(100))') > 3.3020098061049339 > > > As can be seen here, a 1-item dictionary iterated in 0.07 seconds, 10 > items in 0.17 seconds, and 100 items in 1.17 seconds. That is fairly > close to linear, especially when considering the overhead of a > complete no-op > > Using iteritems, it appears to actually scale slightly better than > linear, though it is slower than just the plain iteration. > > Doing a plain iteration, then looking up the keys to get the values > also appears to be linear, and is even slower than iteritems. From smaran.harihar at gmail.com Thu Aug 9 17:52:15 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Thu, 9 Aug 2012 14:52:15 -0700 Subject: trying to create simple py script Message-ID: Hi Guys, I am trying to create a simple cgi-script to receive a Ajax call, manipulate the string received and send it back as JSON. Most of the people I have spoken to, seemed to be against using the cgi script, but most of the documentation and tutorials seem to point to cgi for AJAX calls. They said, it makes more sense to use django or bottle which are python web framework. So I am confused and wanted some guidance as to which should I chose? Should I go with cgi or django/bottle? -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From giuseppe.amatulli at gmail.com Thu Aug 9 17:53:49 2012 From: giuseppe.amatulli at gmail.com (Giuseppe Amatulli) Date: Thu, 9 Aug 2012 16:53:49 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: Thanks a lot for the clarification. Actually my problem is giving to raster dataset in geo-tif format find out unique pair combination, count the number of observation unique combination in rast1, count the number of observation unique combination in rast2, count the number of observation I try different solution and this seems to me the faster Rast00=dsRast00.GetRasterBand(1).ReadAsArray() Rast10=dsRast10.GetRasterBand(1).ReadAsArray() mask=( Rast00 != 0 ) & ( Rast10 != 0 ) # may be this masking operation can be included in the for loop Rast00_mask= Rast00[mask] # may be this masking operation can be included in the for loop Rast10_mask= Rast10[mask] # may be this masking operation can be included in the for loop array2D = np.array(zip( Rast00_mask,Rast10_mask)) unique_u=dict() unique_k1=dict() unique_k2=dict() for key1,key2 in array2D : row = tuple((key1,key2)) if row in unique_u: unique_u[row] += 1 else: unique_u[row] = 1 if key1 in unique_k1: unique_k1[key1] += 1 else: unique_k1[key1] = 1 if key2 in unique_k2: unique_k2[key2] += 1 else: unique_k2[key2] = 1 output = open(dst_file_rast0010, "w") for (a, b), c in unique_u.items(): print(a, b, c, file=output) output.close() output = open(dst_file_rast00, "w") for (a), b in unique_k1.items(): print(a, b, file=output) output.close() output = open(dst_file_rast10, "w") for (a), b in unique_k2.items(): print(a, b, file=output) output.close() What do you think? is there a way to speed up the process? Thanks Giuseppe On 9 August 2012 16:34, Roman Vashkevich wrote: > Actually, they are different. > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > Dict uses hashing to get a value from the dict and this is why it's O(1). > > 10.08.2012, ? 1:21, Tim Chase ???????(?): > >> On 08/09/12 15:41, Roman Vashkevich wrote: >>> 10.08.2012, ? 0:35, Tim Chase ???????(?): >>>> On 08/09/12 15:22, Roman Vashkevich wrote: >>>>>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>>>>> and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? >>>>>> 4 5 1 >>>>>> 5 4 1 >>>>>> 4 4 2 >>>>>> 2 3 1 >>>>>> 4 3 2 >>>>> >>>>> for key in dict: >>>>> print key[0], key[1], dict[key] >>>> >>>> This might read more cleanly with tuple unpacking: >>>> >>>> for (edge1, edge2), cost in d.iteritems(): # or .items() >>>> print edge1, edge2, cost >>>> >>>> (I'm making the assumption that this is a edge/cost graph...use >>>> appropriate names according to what they actually mean) >>> >>> dict.items() is a list - linear access time whereas with 'for >>> key in dict:' access time is constant: >>> http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 >> >> That link doesn't actually discuss dict.{iter}items() >> >> Both are O(N) because you have to touch each item in the dict--you >> can't iterate over N entries in less than O(N) time. For small >> data-sets, building the list and then iterating over it may be >> faster faster; for larger data-sets, the cost of building the list >> overshadows the (minor) overhead of a generator. Either way, the >> iterate-and-fetch-the-associated-value of .items() & .iteritems() >> can (should?) be optimized in Python's internals to the point I >> wouldn't think twice about using the more readable version. >> >> -tkc >> >> > -- Giuseppe Amatulli Web: www.spatial-ecology.net From vashkevichrb at gmail.com Thu Aug 9 18:02:00 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 02:02:00 +0400 Subject: save dictionary to a file without brackets. In-Reply-To: <50243001.5030903@davea.name> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> <50243001.5030903@davea.name> Message-ID: <783556B4-BB18-4E1D-8F76-A3CDDC0289AF@gmail.com> 10.08.2012, ? 1:47, Dave Angel ???????(?): > On 08/09/2012 05:34 PM, Roman Vashkevich wrote: >> Actually, they are different. >> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >> Dict uses hashing to get a value from the dict and this is why it's O(1). > > Sure, that's why > > for key in dict: > print key[0], key[1], dict[key] > > is probably slower than > > for (edge1, edge2), cost in d.iteritems(): # or .items() > print edge1, edge2, cost > > > So, the latter is both faster and easier to read. Why are you arguing against it? > > Also, please stop top-posting. It's impolite here, and makes it much harder to figure out who is saying what, in what order. > > > > -- > > DaveA > I'm not arguing at all. Sorry if it sounded like I was arguing. Thanks for notifying me of the way messages should be sent. Roman From amc96 at cam.ac.uk Thu Aug 9 18:03:26 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Thu, 09 Aug 2012 23:03:26 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: On 09/08/2012 22:34, Roman Vashkevich wrote: > Actually, they are different. > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > Dict uses hashing to get a value from the dict and this is why it's O(1). > Sligtly off topic, but looking up a value in a dictionary is actually O(n) for all other entries in the dict which suffer a hash collision with the searched entry. True, a sensible choice of hash function will reduce n to 1 in common cases, but it becomes an important consideration for larger datasets. ~Andrew From d at davea.name Thu Aug 9 18:26:53 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 18:26:53 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: <5024392D.3010306@davea.name> On 08/09/2012 06:03 PM, Andrew Cooper wrote: > On 09/08/2012 22:34, Roman Vashkevich wrote: >> Actually, they are different. >> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >> Dict uses hashing to get a value from the dict and this is why it's O(1). >> > Sligtly off topic, but looking up a value in a dictionary is actually > O(n) for all other entries in the dict which suffer a hash collision > with the searched entry. > > True, a sensible choice of hash function will reduce n to 1 in common > cases, but it becomes an important consideration for larger datasets. > > ~Andrew I'm glad you're wrong for CPython's dictionaries. The only time the lookup would degenerate to O[n] would be if the hash table had only one slot. CPython sensibly increases the hash table size when it becomes too small for efficiency. Where have you seen dictionaries so poorly implemented? -- DaveA From ckaynor at zindagigames.com Thu Aug 9 18:37:59 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 9 Aug 2012 15:37:59 -0700 Subject: save dictionary to a file without brackets. In-Reply-To: <5024392D.3010306@davea.name> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> Message-ID: On Thu, Aug 9, 2012 at 3:26 PM, Dave Angel wrote: > On 08/09/2012 06:03 PM, Andrew Cooper wrote: >> On 09/08/2012 22:34, Roman Vashkevich wrote: >>> Actually, they are different. >>> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >>> Dict uses hashing to get a value from the dict and this is why it's O(1). >>> >> Sligtly off topic, but looking up a value in a dictionary is actually >> O(n) for all other entries in the dict which suffer a hash collision >> with the searched entry. >> >> True, a sensible choice of hash function will reduce n to 1 in common >> cases, but it becomes an important consideration for larger datasets. >> >> ~Andrew > > I'm glad you're wrong for CPython's dictionaries. The only time the > lookup would degenerate to O[n] would be if the hash table had only one > slot. CPython sensibly increases the hash table size when it becomes > too small for efficiency. > > > Where have you seen dictionaries so poorly implemented? There are plenty of ways to make a pathological hash function that will have that issue in CPython. The very simple (and stupid): class O(object): def __hash__(self): return 0 def __eq__(self, other): # I am aware this is the default equals method. return self is other Start adding those to a dictionary to get O(n) lookups. Any case the hash return values modulus the dictionary hash table size is constant will have similar results; powers of 2 are likely to result in such behavior as well. > > -- > > DaveA > > -- > http://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Thu Aug 9 18:39:22 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Aug 2012 17:39:22 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: <5024392D.3010306@davea.name> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> Message-ID: <50243C1A.4030901@tim.thechases.com> On 08/09/12 17:26, Dave Angel wrote: > On 08/09/2012 06:03 PM, Andrew Cooper wrote: > I'm glad you're wrong for CPython's dictionaries. The only time the > lookup would degenerate to O[n] would be if the hash table had only one > slot. CPython sensibly increases the hash table size when it becomes > too small for efficiency. > > Where have you seen dictionaries so poorly implemented? PHP? http://www.phpclasses.org/blog/post/171-PHP-Vulnerability-May-Halt-Millions-of-Servers.html -tkc From rosuav at gmail.com Thu Aug 9 18:53:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 08:53:43 +1000 Subject: save dictionary to a file without brackets. In-Reply-To: <5024392D.3010306@davea.name> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> Message-ID: On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel wrote: > On 08/09/2012 06:03 PM, Andrew Cooper wrote: >> O(n) for all other entries in the dict which suffer a hash collision >> with the searched entry. >> >> True, a sensible choice of hash function will reduce n to 1 in common >> cases, but it becomes an important consideration for larger datasets. > > I'm glad you're wrong for CPython's dictionaries. The only time the > lookup would degenerate to O[n] would be if the hash table had only one > slot. CPython sensibly increases the hash table size when it becomes > too small for efficiency. > > Where have you seen dictionaries so poorly implemented? In vanilla CPython up to version (I think) 3.3, where it's possible to DoS the hash generator. Hash collisions are always possible, just ridiculously unlikely unless deliberately exploited. (And yes, I know an option was added to older versions to randomize the hashes there too. It's not active by default, so "vanilla CPython" is still vulnerable.) ChrisA From amc96 at cam.ac.uk Thu Aug 9 18:54:20 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Thu, 09 Aug 2012 23:54:20 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: On 09/08/2012 23:26, Dave Angel wrote: > On 08/09/2012 06:03 PM, Andrew Cooper wrote: >> On 09/08/2012 22:34, Roman Vashkevich wrote: >>> Actually, they are different. >>> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >>> Dict uses hashing to get a value from the dict and this is why it's O(1). >>> >> Sligtly off topic, but looking up a value in a dictionary is actually >> O(n) for all other entries in the dict which suffer a hash collision >> with the searched entry. >> >> True, a sensible choice of hash function will reduce n to 1 in common >> cases, but it becomes an important consideration for larger datasets. >> >> ~Andrew > > I'm glad you're wrong for CPython's dictionaries. The only time the > lookup would degenerate to O[n] would be if the hash table had only one > slot. CPython sensibly increases the hash table size when it becomes > too small for efficiency. > > > Where have you seen dictionaries so poorly implemented? > Different n, which I should have made more clear. I was using it for consistency with O() notation. My statement was O(n) where n is the number of hash collisions. The choice of hash algorithm (or several depending on the implementation) should specifically be chosen to reduce collisions to aid in efficient space utilisation and lookup times, but any implementation must allow for collisions. There are certainly runtime methods of improving efficiency using amortized operations. As for poor implementations, class Foo(object): ... def __hash__(self): return 0 I seriously found that in some older code I had the misfortune of reading. It didn't remain in that state for long. ~Andrew From rosuav at gmail.com Thu Aug 9 19:01:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 09:01:17 +1000 Subject: save dictionary to a file without brackets. In-Reply-To: <50243C1A.4030901@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> <50243C1A.4030901@tim.thechases.com> Message-ID: On Fri, Aug 10, 2012 at 8:39 AM, Tim Chase wrote: > On 08/09/12 17:26, Dave Angel wrote: >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: >> I'm glad you're wrong for CPython's dictionaries. The only time the >> lookup would degenerate to O[n] would be if the hash table had only one >> slot. CPython sensibly increases the hash table size when it becomes >> too small for efficiency. >> >> Where have you seen dictionaries so poorly implemented? > > PHP? > > http://www.phpclasses.org/blog/post/171-PHP-Vulnerability-May-Halt-Millions-of-Servers.html That's the same hash collision attack that I alluded to above, and it strikes *many* language implementations. Most released a patch fairly quickly and quietly (Pike, Lua, V8 (JavaScript/ECMAScript), PHP), but CPython dared not, on account of various applications depending on hash order (at least for tests). It's not (for once) an indictment of PHP (maybe that should be an "inarrayment"?), it's a consequence of a hashing algorithm that favored simplicity over cryptographic qualities. (It feels weird to be defending PHP...) ChrisA From roy at panix.com Thu Aug 9 19:05:38 2012 From: roy at panix.com (Roy Smith) Date: Thu, 09 Aug 2012 19:05:38 -0400 Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: In article , Andrew Cooper wrote: > As for poor implementations, > > class Foo(object): > def __hash__(self): > return 0 > > I seriously found that in some older code I had the misfortune of > reading. Python assumes you are a consenting adult. If you wish to engage in activities which are hazardous to your health, so be it. But then again, you could commit this particular stupidity just as easily in C++ or any other language which lets you define your own hash() function. From oscar.j.benjamin at gmail.com Thu Aug 9 19:09:55 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 10 Aug 2012 00:09:55 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: > What do you think? is there a way to speed up the process? > Thanks > Giuseppe Which part is slow? How slow is it? A simple test to find the slow part of your code is to print messages between the commands so that you can see how long it takes between each message. Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Aug 9 19:14:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 09:14:30 +1000 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith wrote: > Python assumes you are a consenting adult. If you wish to engage in > activities which are hazardous to your health, so be it. ... you mean, Python lets you make a hash of it? *ducks for cover* ChrisA From roy at panix.com Thu Aug 9 19:24:22 2012 From: roy at panix.com (Roy Smith) Date: Thu, 09 Aug 2012 19:24:22 -0400 Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: In article , Chris Angelico wrote: > On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith wrote: > > Python assumes you are a consenting adult. If you wish to engage in > > activities which are hazardous to your health, so be it. > > ... you mean, Python lets you make a hash of it? > Only if you order it with spam, spam, spam, spam, spam, spam, and spam. From breamoreboy at yahoo.co.uk Thu Aug 9 19:33:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Aug 2012 00:33:04 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: On 10/08/2012 00:24, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith wrote: >>> Python assumes you are a consenting adult. If you wish to engage in >>> activities which are hazardous to your health, so be it. >> >> ... you mean, Python lets you make a hash of it? >> > > Only if you order it with spam, spam, spam, spam, spam, spam, and spam. > Now now gentlemen we're getting slightly off topic here and wouldn't want to upset the people who insist on staying on topic. Or would we? :) -- Cheers. Mark Lawrence. From d at davea.name Thu Aug 9 19:38:13 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 19:38:13 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: <502449E5.8090500@davea.name> On 08/09/2012 06:54 PM, Andrew Cooper wrote: > On 09/08/2012 23:26, Dave Angel wrote: >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: >>> On 09/08/2012 22:34, Roman Vashkevich wrote: >>>> Actually, they are different. >>>> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >>>> Dict uses hashing to get a value from the dict and this is why it's O(1). >>>> >>> Sligtly off topic, but looking up a value in a dictionary is actually >>> O(n) for all other entries in the dict which suffer a hash collision >>> with the searched entry. >>> >>> True, a sensible choice of hash function will reduce n to 1 in common >>> cases, but it becomes an important consideration for larger datasets. >>> >>> ~Andrew >> I'm glad you're wrong for CPython's dictionaries. The only time the >> lookup would degenerate to O[n] would be if the hash table had only one >> slot. CPython sensibly increases the hash table size when it becomes >> too small for efficiency. >> >> >> Where have you seen dictionaries so poorly implemented? >> > Different n, which I should have made more clear. I was using it for > consistency with O() notation. My statement was O(n) where n is the > number of hash collisions. That's a little like doing a survey, and reporting the results as showing that 100% of the women hit their husbands, among the population of women who hit their husbands. In your original message, you already stated the assumption that a proper hash algorithm would be chosen, then went on to apparently claim that large datasets would still have an order n problem. That last is what I was challenging. The rest of your message here refers to client code, not the system. > The choice of hash algorithm (or several depending on the > implementation) should specifically be chosen to reduce collisions to > aid in efficient space utilisation and lookup times, but any > implementation must allow for collisions. There are certainly runtime > methods of improving efficiency using amortized operations. > > As for poor implementations, > > class Foo(object): > > ... > > def __hash__(self): > return 0 > > I seriously found that in some older code I had the misfortune of > reading. It didn't remain in that state for long. > > ~Andrew -- DaveA From d at davea.name Thu Aug 9 19:42:48 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 19:42:48 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> Message-ID: <50244AF8.6070909@davea.name> On 08/09/2012 06:53 PM, Chris Angelico wrote: > On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel wrote: >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: >>> O(n) for all other entries in the dict which suffer a hash collision >>> with the searched entry. >>> >>> True, a sensible choice of hash function will reduce n to 1 in common >>> cases, but it becomes an important consideration for larger datasets. >> I'm glad you're wrong for CPython's dictionaries. The only time the >> lookup would degenerate to O[n] would be if the hash table had only one >> slot. CPython sensibly increases the hash table size when it becomes >> too small for efficiency. >> >> Where have you seen dictionaries so poorly implemented? > In vanilla CPython up to version (I think) 3.3, where it's possible to > DoS the hash generator. Hash collisions are always possible, just > ridiculously unlikely unless deliberately exploited. > > (And yes, I know an option was added to older versions to randomize > the hashes there too. It's not active by default, so "vanilla CPython" > is still vulnerable.) > > ChrisA Thank you to you and others, who have corrected my over-general response. I was not intending to claim anything about either a deliberate DOS, nor a foolishly chosen hash function. But the message I was replying to seemed to me to claim that for large datasets, even a good hash algorithm would end up giving O(n) performance. -- DaveA From oscar.j.benjamin at gmail.com Thu Aug 9 20:03:26 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 10 Aug 2012 01:03:26 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: On Aug 10, 2012 12:34 AM, "Giuseppe Amatulli" wrote: > > Ciao, > is 12 minutes for 5000x5000 pixel image. half of the time is for > reading the arrays. > and the other half for making the loop. > I will try again to incorporate the mask action in the loop > and > read the image line by line. > Thanks > ciao That does seem slow. I'm sure it can be a lot faster than that. Did you also write the code for reading the arrays? The loop can certainly be made faster but if you can't make the array reading faster there's not much point spending a long time trying to speed up the rest. Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Aug 9 20:16:58 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Aug 2012 19:16:58 -0500 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: <502452FA.9040801@tim.thechases.com> On 08/09/12 18:33, Mark Lawrence wrote: > On 10/08/2012 00:24, Roy Smith wrote: >>> ... you mean, Python lets you make a hash of it? >> >> Only if you order it with spam, spam, spam, spam, spam, spam, and spam. > > Now now gentlemen we're getting slightly off topic here and wouldn't > want to upset the people who insist on staying on topic. Or would we? :) We apologise for the off-topicness in the thread. Those responsible have been sacked... -tkc From d at davea.name Thu Aug 9 20:27:23 2012 From: d at davea.name (Dave Angel) Date: Thu, 09 Aug 2012 20:27:23 -0400 Subject: save dictionary to a file without brackets. In-Reply-To: <502452FA.9040801@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <502452FA.9040801@tim.thechases.com> Message-ID: <5024556B.1040300@davea.name> On 08/09/2012 08:16 PM, Tim Chase wrote: > On 08/09/12 18:33, Mark Lawrence wrote: >> On 10/08/2012 00:24, Roy Smith wrote: >>>> ... you mean, Python lets you make a hash of it? >>> Only if you order it with spam, spam, spam, spam, spam, spam, and spam. >> Now now gentlemen we're getting slightly off topic here and wouldn't >> want to upset the people who insist on staying on topic. Or would we? :) > We apologise for the off-topicness in the thread. Those responsible > have been sacked... > > -tkc > > > Paper or plastic? -- DaveA From rosuav at gmail.com Thu Aug 9 20:31:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 10:31:59 +1000 Subject: save dictionary to a file without brackets. In-Reply-To: <502452FA.9040801@tim.thechases.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <502452FA.9040801@tim.thechases.com> Message-ID: On Fri, Aug 10, 2012 at 10:16 AM, Tim Chase wrote: > We apologise for the off-topicness in the thread. Those responsible > have been sacked... So if you take every mapping variable in your program and name them "dFoo", "dBar", "dQuux", etc, for "dict"... would that be a dirty Hungarian dictionary? Excuse me, I'll go and sack myself now. ChrisA From dihedral88888 at googlemail.com Fri Aug 10 01:35:27 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 9 Aug 2012 22:35:27 -0700 (PDT) Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: Andrew Cooper? 2012?8?10????UTC+8??6?03?26???? > On 09/08/2012 22:34, Roman Vashkevich wrote: > > > Actually, they are different. > > > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > > > Dict uses hashing to get a value from the dict and this is why it's O(1). > > > > > > > Sligtly off topic, but looking up a value in a dictionary is actually > > O(n) for all other entries in the dict which suffer a hash collision > > with the searched entry. > > > > True, a sensible choice of hash function will reduce n to 1 in common > > cases, but it becomes an important consideration for larger datasets. > > > > ~Andrew This is the classical problem of storing the hash collision items one by one. Those items should be stored by some order. From lutz.horn at fastmail.fm Fri Aug 10 02:35:26 2012 From: lutz.horn at fastmail.fm (Lutz Horn) Date: Fri, 10 Aug 2012 08:35:26 +0200 Subject: trying to create simple py script In-Reply-To: References: Message-ID: <1344580526.9686.140661113054561.4DD1CBB5@webmail.messagingengine.com> Hi Smaran, Am Do, 9. Aug 2012, um 23:52, schrieb Smaran Harihar: > I am trying to create a simple cgi-script to receive a Ajax > call, manipulate the string received and send it back as JSON. I can recommend bottle. The following example manipulates a JSON request body and returns it. That is *much* easier than using CGI. #!/usr/bin/env python from bottle import request, post, run @post('/hello') def index(): if request.headers.get('X-Requested-With') == 'XMLHttpRequest': body = request.json body["baz"] = "qux" return body else: return 'This is a normal HTTP Post request.' run(host='localhost', port=8080) Lutz From lipskathekat at yahoo.co.uk Fri Aug 10 03:46:38 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 10 Aug 2012 08:46:38 +0100 Subject: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs In-Reply-To: References: <34WdnQ8_38yFSb7NnZ2dnUVZ8qCdnZ2d@bt.com> <1os7281s5ad5e10f5v3tku0j7g9hjnsbuu@invalid.netcom.com> Message-ID: On 09/08/12 20:45, Terry Reedy wrote: > On 8/9/2012 1:39 PM, Dennis Lee Bieber wrote: >> On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat >> declaimed the following in >> gmane.comp.python.general: >> >> >>> in the examples in this chapter we see usage examples for >>> socketserver.BaseRequestHandler [snip] > > I think the doc can be improved a bit and opened an issue to "Improve > socketserver doc" > http://bugs.python.org/issue15608 Thank you for your reasonable responses I have sent an email to docs at python.org politely suggesting a couple of improvements to the socketserver documentation lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From iftecan2000 at gmail.com Fri Aug 10 03:49:54 2012 From: iftecan2000 at gmail.com (Ifthikhan Nazeem) Date: Fri, 10 Aug 2012 09:49:54 +0200 Subject: trying to create simple py script In-Reply-To: <1344580526.9686.140661113054561.4DD1CBB5@webmail.messagingengine.com> References: <1344580526.9686.140661113054561.4DD1CBB5@webmail.messagingengine.com> Message-ID: I have been using Flask for a while and it's been a positive experience so far. It's simplicity helps you to get things done faster. On Fri, Aug 10, 2012 at 8:35 AM, Lutz Horn wrote: > Hi Smaran, > > Am Do, 9. Aug 2012, um 23:52, schrieb Smaran Harihar: > > I am trying to create a simple cgi-script to receive a Ajax > > call, manipulate the string received and send it back as JSON. > > I can recommend bottle. The following example manipulates a JSON request > body and returns it. That is *much* easier than using CGI. > > #!/usr/bin/env python > > from bottle import request, post, run > > @post('/hello') > def index(): > if request.headers.get('X-Requested-With') == 'XMLHttpRequest': > body = request.json > body["baz"] = "qux" > return body > else: > return 'This is a normal HTTP Post request.' > > run(host='localhost', port=8080) > > Lutz > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From giacomo.alzetta at gmail.com Fri Aug 10 04:20:00 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Fri, 10 Aug 2012 01:20:00 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. Message-ID: I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. Here's the code for the in-place addition: #define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType)) [...] static PyObject * ModPoly_InPlaceAdd(PyObject *self, PyObject *other) { if (!ModPoly_Check(self)) { // This should never occur for in-place addition, am I correct? if (!ModPoly_Check(other)) { PyErr_SetString(PyExc_TypeError, "Neither argument is a ModPolynomial."); return NULL; } return ModPoly_InPlaceAdd(other, self); } else { if (!PyInt_Check(other) && !PyLong_Check(other)) { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } } ModPoly *Tself = (ModPoly *)self; PyObject *tmp, *tmp2; tmp = PyNumber_Add(Tself->ob_item[0], other); tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus); Py_DECREF(tmp); tmp = Tself->ob_item[0]; Tself->ob_item[0] = tmp2; Py_DECREF(tmp); printf("%d\n", (int)ModPoly_Check(self)); return self; } And here's an example usage: >>> from algebra import polynomials >>> pol = polynomials.ModPolynomial(3,17) >>> pol += 5 1 >>> pol >>> Now, how come my ModPolynomial suddenly becomes a read-only buffer, even though that last printf tells us that the object returned is of the correct type? If I raise an exception instead of returning self, the ModPolynomial gets incremented correctly. If I use the Py_RETURN_NONE macro, the ModPolynomial is correctly replaced by None. From hansmu at xs4all.nl Fri Aug 10 04:47:02 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 10 Aug 2012 10:47:02 +0200 Subject: no data exclution and unique combination. In-Reply-To: References: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> Message-ID: <5024ca87$0$6986$e4fe514c@news2.news.xs4all.nl> On 9/08/12 23:33:58, Terry Reedy wrote: > On 8/9/2012 4:06 PM, giuseppe.amatulli at gmail.com wrote: [...] >> unique=dict() >> for row in array2D : >> row = tuple(row) >> if row in unique: >> unique[row] += 1 >> else: >> unique[row] = 1 > > I believe the 4 lines above are equivalent to > unique[row] = unique.get(row, 0) + 1 I would write that bit as: from collections import defaultdict unique = defaultdict(int) for row in array2D: unique[row] += 1 Hope this helps, -- HansM From steve+comp.lang.python at pearwood.info Fri Aug 10 04:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Aug 2012 08:54:42 GMT Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> Message-ID: <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: > On 08/09/12 18:33, Mark Lawrence wrote: >> On 10/08/2012 00:24, Roy Smith wrote: >>>> ... you mean, Python lets you make a hash of it? >>> >>> Only if you order it with spam, spam, spam, spam, spam, spam, and >>> spam. >> >> Now now gentlemen we're getting slightly off topic here and wouldn't >> want to upset the people who insist on staying on topic. Or would we? >> :) > > We apologise for the off-topicness in the thread. Those responsible > have been sacked... Sacked? They were beaten to death with a large halibut! -- Steven From mok-kong.shen at t-online.de Fri Aug 10 05:19:36 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Fri, 10 Aug 2012 11:19:36 +0200 Subject: [newbie] A question about lists and strings Message-ID: In an earlier question about lists, I was told about the issue of creation of local names in a function. However, I still can't understand why the program below outputs: [999] sss [999] and not two identical lines of output. For both operators "+=" should anyway work in similar manner in the function xx in my view. Thanks for your help in advance. M. K. Shen ---------------------------------------------------------- def xx(list,str): list+=[999] str+="sss" lista=[] stra="" lista+=[999] stra+="sss" print(lista,stra) listb=[] strb="" xx(listb,strb) print(listb,strb) From hansmu at xs4all.nl Fri Aug 10 05:22:13 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 10 Aug 2012 11:22:13 +0200 Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: <5024d2c6$0$6850$e4fe514c@news2.news.xs4all.nl> On 10/08/12 10:20:00, Giacomo Alzetta wrote: > I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). > At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. > > Here's the code for the in-place addition: > > #define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType)) > [...] > static PyObject * > ModPoly_InPlaceAdd(PyObject *self, PyObject *other) > { > > if (!ModPoly_Check(self)) { > // This should never occur for in-place addition, am I correct? > if (!ModPoly_Check(other)) { > PyErr_SetString(PyExc_TypeError, "Neither argument is a ModPolynomial."); > return NULL; > } > return ModPoly_InPlaceAdd(other, self); > } else { > if (!PyInt_Check(other) && !PyLong_Check(other)) { > Py_INCREF(Py_NotImplemented); > return Py_NotImplemented; > } > } > > ModPoly *Tself = (ModPoly *)self; > PyObject *tmp, *tmp2; > tmp = PyNumber_Add(Tself->ob_item[0], other); > tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus); > > Py_DECREF(tmp); > tmp = Tself->ob_item[0]; > Tself->ob_item[0] = tmp2; > Py_DECREF(tmp); > > printf("%d\n", (int)ModPoly_Check(self)); > return self; > > } I have no experience writing extensions in C, but as I see it, you're returning a new reference to self, so you'd need: Py_INCREF(self); If you don't, then a Py_DECREF inside the assignment operator causes your polynomial to be garbage collected. Its heap slot is later used for the unrelated buffer object you're seeing. Hope this helps, -- HansM From giacomo.alzetta at gmail.com Fri Aug 10 05:25:36 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Fri, 10 Aug 2012 02:25:36 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: <5024d2c6$0$6850$e4fe514c@news2.news.xs4all.nl> References: <5024d2c6$0$6850$e4fe514c@news2.news.xs4all.nl> Message-ID: <96b8b7f7-7523-44a8-bdc8-4e63e9041771@googlegroups.com> Il giorno venerd? 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: > On 10/08/12 10:20:00, Giacomo Alzetta wrote: > > > I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). > > > At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. > > > > > > Here's the code for the in-place addition: > > > > > > #define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType)) > > > [...] > > > static PyObject * > > > ModPoly_InPlaceAdd(PyObject *self, PyObject *other) > > > { > > > > > > if (!ModPoly_Check(self)) { > > > // This should never occur for in-place addition, am I correct? > > > if (!ModPoly_Check(other)) { > > > PyErr_SetString(PyExc_TypeError, "Neither argument is a ModPolynomial."); > > > return NULL; > > > } > > > return ModPoly_InPlaceAdd(other, self); > > > } else { > > > if (!PyInt_Check(other) && !PyLong_Check(other)) { > > > Py_INCREF(Py_NotImplemented); > > > return Py_NotImplemented; > > > } > > > } > > > > > > ModPoly *Tself = (ModPoly *)self; > > > PyObject *tmp, *tmp2; > > > tmp = PyNumber_Add(Tself->ob_item[0], other); > > > tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus); > > > > > > Py_DECREF(tmp); > > > tmp = Tself->ob_item[0]; > > > Tself->ob_item[0] = tmp2; > > > Py_DECREF(tmp); > > > > > > printf("%d\n", (int)ModPoly_Check(self)); > > > return self; > > > > > > } > > > > I have no experience writing extensions in C, but as I see it, > > you're returning a new reference to self, so you'd need: > > > > Py_INCREF(self); > > > > If you don't, then a Py_DECREF inside the assignment operator > > causes your polynomial to be garbage collected. Its heap slot > > is later used for the unrelated buffer object you're seeing. > > > > Hope this helps, > > > > -- HansM Yes, you're right. I didn't thought the combined operator would do a Py_DECREF if the iadd operation was implemented, but it obviosuly makes sense. From vashkevichrb at gmail.com Fri Aug 10 05:28:57 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 13:28:57 +0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> 10.08.2012, ? 13:19, Mok-Kong Shen ???????(?): > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both operators "+=" should > anyway work in similar manner in the function xx in my view. > > Thanks for your help in advance. > > M. K. Shen > > ---------------------------------------------------------- > > def xx(list,str): > list+=[999] > str+="sss" > > lista=[] > stra="" > lista+=[999] > stra+="sss" > print(lista,stra) > > listb=[] > strb="" > xx(listb,strb) > print(listb,strb) > -- > http://mail.python.org/mailman/listinfo/python-list It seems like your xx() function doesn't return local str parameter and prints the global empty str, whereas it mutates the global list. Roman From breamoreboy at yahoo.co.uk Fri Aug 10 05:37:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Aug 2012 10:37:12 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/08/2012 09:54, Steven D'Aprano wrote: > On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: > >> On 08/09/12 18:33, Mark Lawrence wrote: >>> On 10/08/2012 00:24, Roy Smith wrote: >>>>> ... you mean, Python lets you make a hash of it? >>>> >>>> Only if you order it with spam, spam, spam, spam, spam, spam, and >>>> spam. >>> >>> Now now gentlemen we're getting slightly off topic here and wouldn't >>> want to upset the people who insist on staying on topic. Or would we? >>> :) >> >> We apologise for the off-topicness in the thread. Those responsible >> have been sacked... > > > Sacked? They were beaten to death with a large halibut! > > Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. -- Cheers. Mark Lawrence. From vashkevichrb at gmail.com Fri Aug 10 05:48:14 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 13:48:14 +0400 Subject: [newbie] A question about lists and strings In-Reply-To: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: <50D09205-34F0-4024-914E-318066F114EC@gmail.com> 10.08.2012, ? 13:28, Roman Vashkevich ???????(?): > 10.08.2012, ? 13:19, Mok-Kong Shen ???????(?): > >> >> In an earlier question about lists, I was told about the issue of >> creation of local names in a function. However, I still can't >> understand why the program below outputs: >> >> [999] sss >> [999] >> >> and not two identical lines of output. For both operators "+=" should >> anyway work in similar manner in the function xx in my view. >> >> Thanks for your help in advance. >> >> M. K. Shen >> >> ---------------------------------------------------------- >> >> def xx(list,str): >> list+=[999] >> str+="sss" >> >> lista=[] >> stra="" >> lista+=[999] >> stra+="sss" >> print(lista,stra) >> >> listb=[] >> strb="" >> xx(listb,strb) >> print(listb,strb) >> -- >> http://mail.python.org/mailman/listinfo/python-list > > It seems like your xx() function doesn't return local str parameter and prints the global empty str, whereas it mutates the global list. > > Roman Excuse me for the mess I just did in my message:) The function doesn't print anything of cause. It takes list by reference and creates a new local str. When it's called with listb and strb arguments, listb is passed by reference and mutated. A string "sss" is concatenated with an empty local str. Nothing more happens. Since local str is not returned by xx(), it can not be expected to be printed out in the statement that follows. What is printed out in the print statement is the mutated listb and the global strb. RV From __peter__ at web.de Fri Aug 10 05:59:43 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Aug 2012 11:59:43 +0200 Subject: [newbie] A question about lists and strings References: Message-ID: Mok-Kong Shen wrote: > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both operators "+=" should > anyway work in similar manner in the function xx in my view. > > Thanks for your help in advance. > > M. K. Shen > > ---------------------------------------------------------- > > def xx(list,str): > list+=[999] > str+="sss" a += b is internally translated into to a = a.__iadd__(b) If the 'list' class were implemented in Python it would look like class list: def __iadd__(self, other): for item in other: self.append(item) return self i. e. the original list is modified when you perform += and you'll see the modification when you look at any name bound to that original list: b = a = [1, 2] a += [3, 4] print a # [1, 2, 3, 4] print b # [1, 2, 3, 4] Strings on the other hand are "immutable" -- they cannot be altered after the initial creation. The hypothetical __iadd__() implementation is class str: def __iadd__(self, other): return self + other So += rebinds a name to a new string: b = a = "first" a += "second" print b # first print a # firstsecond Armed with this knowledge > lista=[] > stra="" > lista+=[999] [999] is appended to lista and lista is rebound to itself. > stra+="sss" A new string "" + "sss" is created and stra is bound to that new string. > print(lista,stra) > listb=[] > strb="" > xx(listb,strb) Inside xx() (1) 999 is appended to listb and the local variable list is rebound. (2) A new string "" + "sss" is created and bound to the local variable str. > print(listb,strb) If you have understood the above here's a little brain teaser: >>> a = ([1,2,3],) >>> a[0] += [4, 5] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> a[0] What are the contents of a[0] now? From d at davea.name Fri Aug 10 06:07:50 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 06:07:50 -0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: <5024DD76.40101@davea.name> On 08/10/2012 05:19 AM, Mok-Kong Shen wrote: > > In an earlier question about lists, I was told about the issue of > creation of local names in a function. However, I still can't > understand why the program below outputs: > > [999] sss > [999] > > and not two identical lines of output. For both operators "+=" should > anyway work in similar manner in the function xx in my view. > > Thanks for your help in advance. > > M. K. Shen > > ---------------------------------------------------------- > > def xx(list,str): > list+=[999] > str+="sss" > > lista=[] > stra="" > lista+=[999] > stra+="sss" > print(lista,stra) > > listb=[] > strb="" > xx(listb,strb) > print(listb,strb) I'm rewriting your xx function so it doesn't overwrite reserved words, list and str. def xx(mylist, mystring): mylist += [999] mystring += "xxx" There are a couple of effects you need to understand in order to see what's happening. First, some terminology. You don't assign values in Python, you bind a name or another lvalue to an object. a=650 builds an object of type int, and binds it to the name a. if you then say b=a, you bind b to the *SAME* object, the previously created int object of value 650. It can be useful to print the id() of an object, to convince yourself that they're actually the same. So if you print id(a) and id(b), you'll get the same value. But if you said c=651 and d=651, you'd have two objects, and the two names would be bound to different objects, with different ids. The += operator is an example of an augmented assignment operator. Others that behave the same way include *= -= and so on. The += operator tries to modify the object referred to by the left hand side, by modifying that object in place. If that fails, perhaps because the object is immutable, then it builds a new object, and binds the left side to that new object. So, if you have a list, and you use += to append to it, you still have the same list object, but it's longer now. If you have a string, or an int, or ... that's immutable, then it builds a new one, and binds it to the left side. Now, put those two operations inside a function, and what do we have ? Let's go through the function, looking at what happens. Local parameter mylist gets bound to the list object bound to listb. The object is not copied, it's now bound to new names, one in the global space, one local. When the mylist += statement is executed, it modifies that object, and instantly the global "variable" listb is modified. Local parameter mystring gets bound to the string object bound to strb. We still only have one (immutable) object. When the mystring += statement is executed, it creates a new string object by concatenating the old one and the "xxx" string. At this point, we can print id(mystring) and see that it changed. When the function returns, the local symbols are unbound, and the new string object is discarded since there are no longer any refs. At this point, in top-level code, the listb object has been modified, and the strb one has not; it still is bound to the old value. -- DaveA From mok-kong.shen at t-online.de Fri Aug 10 06:12:12 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Fri, 10 Aug 2012 12:12:12 +0200 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: Am 10.08.2012 11:48, schrieb Roman Vashkevich: >[snip] >The function .... It takes list by reference and creates a new local > str. When it's called with listb and strb arguments, listb is passed > by reference and mutated. A string "sss" is concatenated with an > empty local str. Nothing more happens. Since local str is not > returned by xx(), it can not be expected to be printed out in the > statement that follows. What is printed out in the print statement is > the mutated listb and the global strb. Thanks for the explanation of the output obtained. But this means nonetheless that parameters of types lists and strings are dealt with in "inherently" (semantically) different ways by Python, right? M. K. Shen From mok-kong.shen at t-online.de Fri Aug 10 06:31:08 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Fri, 10 Aug 2012 12:31:08 +0200 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: Am 10.08.2012 12:07, schrieb Dave Angel: [snip] > At this point, in top-level code, the listb object has been modified, > and the strb one has not; it still is bound to the old value. This means there is no way of modifying a string at the top level via a function, excepting through returning a new value and assigning that to the string name at the top level. Please again correct me, if I am wrong. M. K. Shen From rosuav at gmail.com Fri Aug 10 06:37:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 20:37:24 +1000 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen wrote: > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? It's nothing to do with parameters, but yes, lists are mutable and strings are immutable. A tuple will behave the same way a string does: >>> a (1, 2, 3, 4) >>> b=a >>> a+=5, # note that "5," is a one-element tuple >>> a (1, 2, 3, 4, 5) >>> b (1, 2, 3, 4) By the way: On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: > But if you said c=651 and d=651, you'd have two > objects, and the two names would be bound to different objects, with > different ids. To be more accurate, you *may* have two different objects. It's possible for things to be optimized (eg with small numbers, or with constants compiled at the same time). ChrisA From d at davea.name Fri Aug 10 06:37:26 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 06:37:26 -0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: <5024E466.20902@davea.name> On 08/10/2012 06:12 AM, Mok-Kong Shen wrote: > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function .... It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is concatenated with an > > empty local str. Nothing more happens. Since local str is not > > returned by xx(), it can not be expected to be printed out in the > > statement that follows. What is printed out in the print statement is > > the mutated listb and the global strb. > > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? > > M. K. Shen > Nothing to do with parameters. Lists are mutable, and strings are immutable, so += behaves differently. -- DaveA From rosuav at gmail.com Fri Aug 10 06:40:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 20:40:01 +1000 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: On Fri, Aug 10, 2012 at 8:31 PM, Mok-Kong Shen wrote: > This means there is no way of modifying a string at the top level > via a function, excepting through returning a new value and assigning > that to the string name at the top level. Please again correct me, if > I am wrong. Yes, but you can (ab)use a one-element list as a pointer. >>> foo=["Hello"] >>> def mutate(ptr): ptr[0]="World" >>> mutate(foo) >>> print(foo[0]) World But it's probably worth thinking about exactly why you're wanting to change that string, and what you're really looking to accomplish. There may well be a better way. Chris Angelico From mok-kong.shen at t-online.de Fri Aug 10 06:48:31 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Fri, 10 Aug 2012 12:48:31 +0200 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: Am 10.08.2012 12:40, schrieb Chris Angelico: > But it's probably worth thinking about exactly why you're wanting to > change that string, and what you're really looking to accomplish. > There may well be a better way. My problem is the following: I have at top level 3 lists and 3 strings: lista, listb, listc and stra, strb, strc. I can with a single function call change all 3 list values. How could I realize similar changes of the 3 string values with a single function call? Thanks in advance. M. K. Shen From d at davea.name Fri Aug 10 06:53:19 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 06:53:19 -0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: <5024E81F.3020201@davea.name> On 08/10/2012 06:31 AM, Mok-Kong Shen wrote: > Am 10.08.2012 12:07, schrieb Dave Angel: > [snip] >> At this point, in top-level code, the listb object has been modified, >> and the strb one has not; it still is bound to the old value. > > This means there is no way of modifying a string at the top level > via a function, excepting through returning a new value and assigning > that to the string name at the top level. Please again correct me, if > I am wrong. > > M. K. Shen > You're close. There are three ways I can think of. The "right" way is to return a value, which the caller can use any way he wants, including binding it to a global. Second is to declare the name as global, rather than taking the object as a formal parameter. In this case, you're taking on the responsibility for managing that particular global, by its correct name. def yy(): global strb strb += "whatever" Third is to hold the string in some more complex structure which is mutable. (untested, may contain typos) def zz(mydict): mydict["key1"] += "text" called as: globaldict = {"key1": "initial ", "key2": "init"} -- DaveA From d at davea.name Fri Aug 10 06:56:12 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 06:56:12 -0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: <5024E8CC.9020703@davea.name> On 08/10/2012 06:37 AM, Chris Angelico wrote: > On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen > wrote: >> Thanks for the explanation of the output obtained. But this means >> nonetheless that parameters of types lists and strings are dealt with >> in "inherently" (semantically) different ways by Python, right? > It's nothing to do with parameters, but yes, lists are mutable and > strings are immutable. A tuple will behave the same way a string does: > >>>> a > (1, 2, 3, 4) >>>> b=a >>>> a+=5, # note that "5," is a one-element tuple >>>> a > (1, 2, 3, 4, 5) >>>> b > (1, 2, 3, 4) > > > By the way: > > On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: >> But if you said c=651 and d=651, you'd have two >> objects, and the two names would be bound to different objects, with >> different ids. > To be more accurate, you *may* have two different objects. It's > possible for things to be optimized (eg with small numbers, or with > constants compiled at the same time). > > ChrisA You're right, of course. But I picked the value of 650+ deliberately, as I believe CPython doesn't currently optimize ints over 256. -- DaveA From vashkevichrb at gmail.com Fri Aug 10 06:56:23 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 14:56:23 +0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: 10.08.2012, ? 14:12, Mok-Kong Shen ???????(?): > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function .... It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is concatenated with an > > empty local str. Nothing more happens. Since local str is not > > returned by xx(), it can not be expected to be printed out in the > > statement that follows. What is printed out in the print statement is > > the mutated listb and the global strb. > > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? > > M. K. Shen > > -- > http://mail.python.org/mailman/listinfo/python-list I am not sure I understand your question. Can you rephrase it or make it more explicit? RV From d at davea.name Fri Aug 10 06:58:47 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 06:58:47 -0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: <5024E967.1000704@davea.name> On 08/10/2012 06:48 AM, Mok-Kong Shen wrote: > Am 10.08.2012 12:40, schrieb Chris Angelico: > >> But it's probably worth thinking about exactly why you're wanting to >> change that string, and what you're really looking to accomplish. >> There may well be a better way. > > My problem is the following: I have at top level 3 lists and 3 strings: > lista, listb, listc and stra, strb, strc. I can with a single function > call change all 3 list values. How could I realize similar changes > of the 3 string values with a single function call? > > Thanks in advance. > > M. K. Shen > > Make sure your function returns the values, rather than just trying to mutate them in place. def aa(mystring1, mystring2, mystring3): mystring1 += "something" mystring2 += "otherthing" mystring3 += "nobody" return mystring1, mystring2, mystring3 str1, str2, str3 = aa(str1, str2, str3) -- DaveA From rosuav at gmail.com Fri Aug 10 07:00:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Aug 2012 21:00:40 +1000 Subject: [newbie] A question about lists and strings In-Reply-To: <5024E8CC.9020703@davea.name> References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> <5024E8CC.9020703@davea.name> Message-ID: On Fri, Aug 10, 2012 at 8:56 PM, Dave Angel wrote: >> On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel wrote: >>> But if you said c=651 and d=651, you'd have two >>> objects, and the two names would be bound to different objects, with >>> different ids. >> To be more accurate, you *may* have two different objects. It's >> possible for things to be optimized (eg with small numbers, or with >> constants compiled at the same time). > > You're right, of course. But I picked the value of 650+ deliberately, > as I believe CPython doesn't currently optimize ints over 256. Yep. Also: >>> a=651; b=651 >>> a is b True >>> a=651 >>> a is b False Same thing occurs (or at least, appears to) with constants in the same module. Could potentially be a fairly hefty optimization, if you use the same numbers all the time (bit flags, scale factors, modulo divisors, etc, etc, etc). Still doesn't alter your fundamental point of course. ChrisA From vashkevichrb at gmail.com Fri Aug 10 07:06:14 2012 From: vashkevichrb at gmail.com (Roman Vashkevich) Date: Fri, 10 Aug 2012 15:06:14 +0400 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: <271C20BC-EF03-47FD-BEE2-FC878AB4F6F5@gmail.com> 10.08.2012, ? 14:12, Mok-Kong Shen ???????(?): > Am 10.08.2012 11:48, schrieb Roman Vashkevich: >> [snip] > >The function .... It takes list by reference and creates a new local > > str. When it's called with listb and strb arguments, listb is passed > > by reference and mutated. A string "sss" is concatenated with an > > empty local str. Nothing more happens. Since local str is not > > returned by xx(), it can not be expected to be printed out in the > > statement that follows. What is printed out in the print statement is > > the mutated listb and the global strb. > > Thanks for the explanation of the output obtained. But this means > nonetheless that parameters of types lists and strings are dealt with > in "inherently" (semantically) different ways by Python, right? > > M. K. Shen > > -- > http://mail.python.org/mailman/listinfo/python-list DaveA provided a very explicit explanation of how py handles list and string objects. Parameters are handled "inherently" by functions... RV From mok-kong.shen at t-online.de Fri Aug 10 07:08:33 2012 From: mok-kong.shen at t-online.de (Mok-Kong Shen) Date: Fri, 10 Aug 2012 13:08:33 +0200 Subject: [newbie] A question about lists and strings In-Reply-To: References: <39A401F0-12DD-464F-A0D1-639C56FA48A0@gmail.com> Message-ID: Am 10.08.2012 12:56, schrieb Roman Vashkevich: > I am not sure I understand your question. Can you rephrase it or make it more explicit? I have just detailed my problem and Dave Angel has shown how to solve it properly. M. K. Shen From hansmu at xs4all.nl Fri Aug 10 08:21:50 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 10 Aug 2012 14:21:50 +0200 Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: <96b8b7f7-7523-44a8-bdc8-4e63e9041771@googlegroups.com> References: <5024d2c6$0$6850$e4fe514c@news2.news.xs4all.nl> <96b8b7f7-7523-44a8-bdc8-4e63e9041771@googlegroups.com> Message-ID: <5024fcde$0$6907$e4fe514c@news2.news.xs4all.nl> On 10/08/12 11:25:36, Giacomo Alzetta wrote: > Il giorno venerd? 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: [...] > Yes, you're right. I didn't thought the combined operator would do a Py_DECREF > if the iadd operation was implemented, but it obviosuly makes sense. The += operator cannot know if the iadd returns self or a newly created object. Mutable types usually do the former; non-mutable types must do the latter. Come to think of it: why are your polynomials mutable? As a mathematician, I would think of polynomials as elements of some kind of ring, and I'd expect them to be non-mutable. -- HansM From roy at panix.com Fri Aug 10 08:29:32 2012 From: roy at panix.com (Roy Smith) Date: Fri, 10 Aug 2012 08:29:32 -0400 Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Mark Lawrence wrote: > On 10/08/2012 09:54, Steven D'Aprano wrote: > > On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: > > > >> On 08/09/12 18:33, Mark Lawrence wrote: > >>> On 10/08/2012 00:24, Roy Smith wrote: > >>>>> ... you mean, Python lets you make a hash of it? > >>>> > >>>> Only if you order it with spam, spam, spam, spam, spam, spam, and > >>>> spam. > >>> > >>> Now now gentlemen we're getting slightly off topic here and wouldn't > >>> want to upset the people who insist on staying on topic. Or would we? > >>> :) > >> > >> We apologise for the off-topicness in the thread. Those responsible > >> have been sacked... > > > > > > Sacked? They were beaten to death with a large halibut! > > > > > > Well whatever you do *DON'T* mention Cython. I mentioned it just now but > I think I've got away with it. What if I spell it Kython? From jldunn2000 at gmail.com Fri Aug 10 09:01:25 2012 From: jldunn2000 at gmail.com (loial) Date: Fri, 10 Aug 2012 06:01:25 -0700 (PDT) Subject: Threads and sockets Message-ID: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> I am writing an application to send data to a printer port(9100) and then recieve PJL responses back on that port. Because of the way PJL works I have to do both in the same process(script). At the moment I do not start to read responses until the data has been sent to the printer. However it seems I am missing some responses from the printer whilst sending the data, so I need to be able to do the 2 things at the same time. Can I open a port once and then use 2 different threads, one to write to the post and one to read the responses)? From rosuav at gmail.com Fri Aug 10 10:00:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Aug 2012 00:00:01 +1000 Subject: [GENERAL] Postgres and Upstart In-Reply-To: References: Message-ID: On Fri, Aug 10, 2012 at 11:56 PM, Albe Laurenz wrote: > Chris Angelico wrote: >> I'm looking for a reliable way to be sure that Postgres has finished >> its initialization and is ready to rumble. > > The normal way to test this is a connection attempt. > You could also look into the server logs for the > appropriate message, but that seems more fragile and difficult. Yeah, I can poll it, and that's what I do in a couple of places; but somewhere in the code, it probably "knows" that it's ready. I can keep doing what I'm doing, but was hoping for an event-driven approach. Thanks! ChrisA From th982a at googlemail.com Fri Aug 10 10:02:31 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Fri, 10 Aug 2012 16:02:31 +0200 Subject: dictionary into desired variable.... Message-ID: <50251477.7010507@googlemail.com> Hi! suppose you have a dictionary that looks like this: x = [1,3,6,1,1] which should represent a certain other variable. in reality it would represent: y[1][3][6][1][1] Now, how do I write a python routine, that points in this dictionary, where I should receive or set other values. Tamer From rosuav at gmail.com Fri Aug 10 10:31:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Aug 2012 00:31:07 +1000 Subject: dictionary into desired variable.... In-Reply-To: <50251477.7010507@googlemail.com> References: <50251477.7010507@googlemail.com> Message-ID: On Sat, Aug 11, 2012 at 12:02 AM, Tamer Higazi wrote: > Hi! > suppose you have a dictionary that looks like this: > > x = [1,3,6,1,1] which should represent a certain other variable. > > in reality it would represent: > > y[1][3][6][1][1] > > Now, how do I write a python routine, that points in this dictionary, > where I should receive or set other values. For a start, that looks like a list, not a dictionary. A dict in Python is a mapping, eg a hashtable - an unordered pairing of keys and values. But this might do what you want: value = y for idx in x: value = value[idx] At the end of that, 'value' will be the same as 'y[1][3][6][1][1]'. If that's not what you mean, you may want to clarify your question some. Hope that helps! Chris Angelico From schesis at gmail.com Fri Aug 10 10:36:44 2012 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 10 Aug 2012 10:36:44 -0400 Subject: dictionary into desired variable.... In-Reply-To: <50251477.7010507@googlemail.com> References: <50251477.7010507@googlemail.com> Message-ID: : > suppose you have a dictionary that looks like this: > > x = [1,3,6,1,1] which should represent a certain other variable. That's a list, not a dict. > in reality it would represent: > > y[1][3][6][1][1] > > Now, how do I write a python routine, that points in this dictionary, > where I should receive or set other values. >>> x = [1, 3, 6, 1, 1] >>> y = [0, [0, 1, 2, [0, 1, 2, 3, 4, 5, [0, [0, 'bingo!']]]]] >>> def drill(tree, path): ... target = tree ... for step in path: ... target = target[step] ... return target ... >>> drill(y, x) 'bingo!' >>> -[]z. From breamoreboy at yahoo.co.uk Fri Aug 10 10:47:59 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Aug 2012 15:47:59 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/08/2012 13:29, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> On 10/08/2012 09:54, Steven D'Aprano wrote: >>> On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: >>> >>>> On 08/09/12 18:33, Mark Lawrence wrote: >>>>> On 10/08/2012 00:24, Roy Smith wrote: >>>>>>> ... you mean, Python lets you make a hash of it? >>>>>> >>>>>> Only if you order it with spam, spam, spam, spam, spam, spam, and >>>>>> spam. >>>>> >>>>> Now now gentlemen we're getting slightly off topic here and wouldn't >>>>> want to upset the people who insist on staying on topic. Or would we? >>>>> :) >>>> >>>> We apologise for the off-topicness in the thread. Those responsible >>>> have been sacked... >>> >>> >>> Sacked? They were beaten to death with a large halibut! >>> >>> >> >> Well whatever you do *DON'T* mention Cython. I mentioned it just now but >> I think I've got away with it. > > What if I spell it Kython? > What a silly bunt!!! -- Cheers. Mark Lawrence. From sg552 at hotmail.co.uk Fri Aug 10 11:12:20 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 10 Aug 2012 16:12:20 +0100 Subject: [newbie] A question about lists and strings In-Reply-To: References: Message-ID: On 10/08/2012 10:59, Peter Otten wrote: > [...] > > If you have understood the above here's a little brain teaser: > >>>> a = ([1,2,3],) >>>> a[0] += [4, 5] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'tuple' object does not support item assignment > >>>> a[0] > > What are the contents of a[0] now? Ha, nice. -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From d at davea.name Fri Aug 10 11:14:05 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 11:14:05 -0400 Subject: dictionary into desired variable.... In-Reply-To: <50251477.7010507@googlemail.com> References: <50251477.7010507@googlemail.com> Message-ID: <5025253D.9060705@davea.name> On 08/10/2012 10:02 AM, Tamer Higazi wrote: > Hi! > suppose you have a dictionary that looks like this: > > x = [1,3,6,1,1] which should represent a certain other variable. > > in reality it would represent: > > y[1][3][6][1][1] > > Now, how do I write a python routine, that points in this dictionary, > where I should receive or set other values. > Others have pointed out how you could "receive" a value from that. Doing a setter would be tricker. But I'd want to start with the question of just what you're really looking for. Is this an assignment, so it doesn't have to actually make sense? If so, could we please have the actual wording. x is not a dictionary, and Python doesn't have routines nor pointers. Perhaps it's a generic programming class, and the student gets to choose the language. If it's indeed intended to model some kind of useful data, could we know a bit more about the constraints? is y supposed to be a nested list, or a nested dictioary, or something else? How is this nested list/dict first created? Do you need to have other parts of the code access the raw, nested Something. Are there always going to be 5 subscripts, and are each constrained to be in a fixed range? If it's a nested dictionary, are the keys always integers? Since a python function or method can't return a pointer, presumably you mean for a function or method to fetch or store a value. Sounds like what you want is a class, where the __init__ method takes a nested something, y and saves it as an attribute _y. And there are at least two more methods in that class, fetch() that takes a list of ints, and returns a value. And store() that takes a list of ints and a value, and mutates the _y, returning None. The store() method is a good bit trickier to write, depending on the assumptions above. -- DaveA From th982a at googlemail.com Fri Aug 10 11:31:48 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Fri, 10 Aug 2012 17:31:48 +0200 Subject: dictionary into desired variable.... In-Reply-To: References: <50251477.7010507@googlemail.com> Message-ID: <50252964.6030307@googlemail.com> Sorry, I ment of course list.... what I exaclty ment is that if I assign value = Number that I automaticly assign y[1][3][6][1][1] a new number. more detailled explained: let us say a would be x = [2,5,4] y = a[3] if I change y to [] I want the result to be x = [2,5,[]] and that's automaticly independently how deep i dig. Sorry for the inconvenience. Tamer Am 10.08.2012 16:31, schrieb Chris Angelico: > On Sat, Aug 11, 2012 at 12:02 AM, Tamer Higazi wrote: >> Hi! >> suppose you have a dictionary that looks like this: >> >> x = [1,3,6,1,1] which should represent a certain other variable. >> >> in reality it would represent: >> >> y[1][3][6][1][1] >> >> Now, how do I write a python routine, that points in this dictionary, >> where I should receive or set other values. > > For a start, that looks like a list, not a dictionary. A dict in > Python is a mapping, eg a hashtable - an unordered pairing of keys and > values. But this might do what you want: > > value = y > for idx in x: > value = value[idx] > > At the end of that, 'value' will be the same as 'y[1][3][6][1][1]'. > > If that's not what you mean, you may want to clarify your question some. > > Hope that helps! > > Chris Angelico From dieter at handshake.de Fri Aug 10 12:38:37 2012 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 10 Aug 2012 18:38:37 +0200 Subject: Threads and sockets References: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> Message-ID: <87k3x6og6q.fsf@handshake.de> loial writes: > I am writing an application to send data to a printer port(9100) and then recieve PJL responses back on that port. Because of the way PJL works I have to do both in the same process(script). > > At the moment I do not start to read responses until the data has been sent to the printer. However it seems I am missing some responses from the printer whilst sending the data, so I need to be able to do the 2 things at the same time. > > Can I open a port once and then use 2 different threads, one to write to the post and one to read the responses)? That should be possible. Alternatively, you could use "asyncore" -- a mini framework to facilitate asynchronous communication. From giacomo.alzetta at gmail.com Fri Aug 10 12:51:20 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Fri, 10 Aug 2012 09:51:20 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: <5024fcde$0$6907$e4fe514c@news2.news.xs4all.nl> References: <5024d2c6$0$6850$e4fe514c@news2.news.xs4all.nl> <96b8b7f7-7523-44a8-bdc8-4e63e9041771@googlegroups.com> <5024fcde$0$6907$e4fe514c@news2.news.xs4all.nl> Message-ID: <42a2c74f-758a-4f56-b019-6b75da4f759b@googlegroups.com> Il giorno venerd? 10 agosto 2012 14:21:50 UTC+2, Hans Mulder ha scritto: > On 10/08/12 11:25:36, Giacomo Alzetta wrote: > > > Il giorno venerd? 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto: > > [...] > > > Yes, you're right. I didn't thought the combined operator would do a Py_DECREF > > > if the iadd operation was implemented, but it obviosuly makes sense. > > > > The += operator cannot know if the iadd returns self or a newly created > > object. Mutable types usually do the former; non-mutable types must do > > the latter. > > > > Come to think of it: why are your polynomials mutable? > > > > As a mathematician, I would think of polynomials as elements of > > some kind of ring, and I'd expect them to be non-mutable. > > > > -- HansM Usually non-mutable types simply do not implement the iadd operation, and the interpreter tries the simple add after(see intobject.c, longobject.c etc.). I've decided to make my polynomials mutable for efficiency. I want to implement the AKS primality tests, and if I want to use it with big numbers the number of coefficients of a polynomial can easily go up to 1k-10k-100k and using non-mutable polynomials would mean to allocate and free that much memory for almost every operation. Like this I have to allocate/free less frequently. [even though I must admit that this is a premature optimization :s, since I've not profile anything, but untill I do not implement them I wont be able to see how much time I gain.] From woooee at gmail.com Fri Aug 10 13:04:41 2012 From: woooee at gmail.com (woooee at gmail.com) Date: Fri, 10 Aug 2012 10:04:41 -0700 (PDT) Subject: dictionary into desired variable.... In-Reply-To: References: <50251477.7010507@googlemail.com> Message-ID: On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote: > let us say a would be x = [2,5,4] > > y = a[3] > > if I change y to [] > > I want the result to be x = [2,5,[]] and that's automaticly There is no such thing as a[3] if a=[2,4,5]. And this is a list not a dictionary, so I would suggest a tutorial from the Python wiki page. You have to use a mutable container. Integers are not mutable. Lists, for example are. y=[4] x = [2,5,y] print x y[0]=10 print x From woooee at gmail.com Fri Aug 10 13:04:41 2012 From: woooee at gmail.com (woooee at gmail.com) Date: Fri, 10 Aug 2012 10:04:41 -0700 (PDT) Subject: dictionary into desired variable.... In-Reply-To: References: <50251477.7010507@googlemail.com> Message-ID: On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote: > let us say a would be x = [2,5,4] > > y = a[3] > > if I change y to [] > > I want the result to be x = [2,5,[]] and that's automaticly There is no such thing as a[3] if a=[2,4,5]. And this is a list not a dictionary, so I would suggest a tutorial from the Python wiki page. You have to use a mutable container. Integers are not mutable. Lists, for example are. y=[4] x = [2,5,y] print x y[0]=10 print x From smaran.harihar at gmail.com Fri Aug 10 13:14:42 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Fri, 10 Aug 2012 10:14:42 -0700 Subject: Unable to execute the script Message-ID: Hi, I have set executable permissions for my py script (cgi-script) but for some reason rather than executing it, the browser simply downloads the py script. Here is the link. Before it was working on another server. I migrated it to this new domain and it is having this issue. Where am I going wrong? -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From fal at togliquesto.fastwebnet.it Fri Aug 10 13:37:16 2012 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Fri, 10 Aug 2012 19:37:16 +0200 Subject: lpod-python Message-ID: I'm trying to use the lpod-python module to programmatically read data from Open Document files. My problem is: i can't download the module from its authors' site, http://download.lpod-project.org/lpod-python/lpod-python-0.9.3.tar.gz. It seems the download site is unavailable, while the main site is working. I also tried to install the module with pip (I read on the site that it's now available), but again, no luck. Do somebody know what's happening to download.lpod-project.org ? It doesn't even ping... Please let me know, thank you very much. Francesco From dihedral88888 at googlemail.com Fri Aug 10 13:46:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 10 Aug 2012 10:46:09 -0700 (PDT) Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: <0786dd35-b624-4dfc-bbbb-a3e33aa43ae1@googlegroups.com> Dave Angel? 2012?8?10????UTC+8??5?47?45???? > On 08/09/2012 05:34 PM, Roman Vashkevich wrote: > > > Actually, they are different. > > > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > > > Dict uses hashing to get a value from the dict and this is why it's O(1). > > > > Sure, that's why > > > > for key in dict: > > print key[0], key[1], dict[key] > > > > is probably slower than > > > > for (edge1, edge2), cost in d.iteritems(): # or .items() > > print edge1, edge2, cost > > > > > > So, the latter is both faster and easier to read. Why are you arguing against it? > > > > Also, please stop top-posting. It's impolite here, and makes it much harder to figure out who is saying what, in what order. > > > > > > > > -- > > > > DaveA OK, lets estimate the hash colision rate first. For those items hashed to the same key, I'll store a sorted list with a known lenth m to be accessed in O(LOG(M)). Of couse another hash can be attatched. From dihedral88888 at googlemail.com Fri Aug 10 13:46:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 10 Aug 2012 10:46:09 -0700 (PDT) Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> Message-ID: <0786dd35-b624-4dfc-bbbb-a3e33aa43ae1@googlegroups.com> Dave Angel? 2012?8?10????UTC+8??5?47?45???? > On 08/09/2012 05:34 PM, Roman Vashkevich wrote: > > > Actually, they are different. > > > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. > > > Dict uses hashing to get a value from the dict and this is why it's O(1). > > > > Sure, that's why > > > > for key in dict: > > print key[0], key[1], dict[key] > > > > is probably slower than > > > > for (edge1, edge2), cost in d.iteritems(): # or .items() > > print edge1, edge2, cost > > > > > > So, the latter is both faster and easier to read. Why are you arguing against it? > > > > Also, please stop top-posting. It's impolite here, and makes it much harder to figure out who is saying what, in what order. > > > > > > > > -- > > > > DaveA OK, lets estimate the hash colision rate first. For those items hashed to the same key, I'll store a sorted list with a known lenth m to be accessed in O(LOG(M)). Of couse another hash can be attatched. From d at davea.name Fri Aug 10 14:38:19 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 14:38:19 -0400 Subject: Unable to execute the script In-Reply-To: References: Message-ID: <5025551B.10107@davea.name> On 08/10/2012 01:14 PM, Smaran Harihar wrote: > Hi, > > I have set executable permissions for my py script (cgi-script) but for > some reason rather than executing it, the browser simply downloads the py > script. > > Here is the link. > Before it was working on another server. I migrated it to this new domain > and it is having this issue. Where am I going wrong? > > Lots of possibilities, though I can't think of any relating to Python. So I didn't try to read your source file. Is the location of this script acceptable to your web host? Some hosts deliberately restrict scripts to be in certain places (like /cgi-bin) in order to thwart a certain type of cracker. Next question, is the python installation actually at the place where your shebang points? -- DaveA From drsalists at gmail.com Fri Aug 10 14:40:02 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 10 Aug 2012 18:40:02 +0000 Subject: trying to create simple py script In-Reply-To: References: Message-ID: CGI's old stuff. Sure it's easy to find doc about it - it's been around longer. I'd recommend either CherryPy or Bottle - because these are the two (that I know of) that support Python 3 today. Here's a nice comparison of Python REST frameworks: http://www.youtube.com/watch?v=AYjPIMe0BhA I'm using CherryPy on Python 2.7 with the ruby-on-rails-like "Routes" dispatcher. Bottle does sound pretty nice. On Thu, Aug 9, 2012 at 9:52 PM, Smaran Harihar wrote: > Hi Guys, > > I am trying to create a simple cgi-script to receive a Ajax > call, manipulate the string received and send it back as JSON. > Most of the people I have spoken to, seemed to be against using the cgi > script, but most of the documentation and tutorials seem to point to cgi > for AJAX calls. They said, it makes more sense to use django or bottle > which are python web framework. > > So I am confused and wanted some guidance as to which should I chose? > Should I go with cgi or django/bottle? > > -- > Thanks & Regards > Smaran Harihar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 10 14:43:04 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 10 Aug 2012 18:43:04 +0000 Subject: Threads and sockets In-Reply-To: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> References: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> Message-ID: A select() loop should work. On Fri, Aug 10, 2012 at 1:01 PM, loial wrote: > I am writing an application to send data to a printer port(9100) and then > recieve PJL responses back on that port. Because of the way PJL works I > have to do both in the same process(script). > > At the moment I do not start to read responses until the data has been > sent to the printer. However it seems I am missing some responses from the > printer whilst sending the data, so I need to be able to do the 2 things at > the same time. > > Can I open a port once and then use 2 different threads, one to write to > the post and one to read the responses)? > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Aug 10 14:50:08 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Aug 2012 20:50:08 +0200 Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: Giacomo Alzetta, 10.08.2012 10:20: > I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). > At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. You should take a look at Cython. It makes these things way easier and safer than with manually written C code. It will save you a lot of code, debugging and general hassle. Stefan From smaran.harihar at gmail.com Fri Aug 10 14:51:39 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Fri, 10 Aug 2012 11:51:39 -0700 Subject: trying to create simple py script In-Reply-To: References: <1344580526.9686.140661113054561.4DD1CBB5@webmail.messagingengine.com> Message-ID: Sorry forgot to update. I did change the port to 8000 and now server is running but I am getting a 404 page. http://128.196.142.94:8000/bottle/hello.py I have the server up right now you can see. Thanks, Smaran On Fri, Aug 10, 2012 at 11:35 AM, Smaran Harihar wrote: > Hi Lutz, > > Sorry forgot to update. I did change the port to 8000 and now server is > running but I am getting a 404 page. > > http://128.196.142.94:8000/bottle/hello.py > > I have the server up right now you can see. > > Thanks, > Smaran > > > On Fri, Aug 10, 2012 at 11:28 AM, Lutz Horn wrote: > >> Hi, >> >> Am 10.08.2012 um 19:10 schrieb Smaran Harihar: >> > python hello.py but I got this traceback error. >> >> Use a different port in this line: >> >> > run(host='localhost', port=8080) >> >> For example 8090 or 8081 or ? >> >> Lutz > > > > > -- > Thanks & Regards > Smaran Harihar > > -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From galois271 at gmail.com Fri Aug 10 14:52:54 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 11:52:54 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" Message-ID: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Hi all, I cannot figure why I keep getting this error. It is my understanding that all methods need a self argument when designing a class. Here is my code: import random class ElementsQuiz: elements = {'H' : 'Hydrogen', 'He' : 'Helium', 'Li' : 'Lithium', 'Be' : 'Beryllium', 'B' : 'Boron', 'C' : 'Carbon', 'N' : 'Nitrogen', 'O' : 'Oxygen', 'F' : 'Fluorine', 'Ne' : 'Neon', 'Na' : 'Sodium', 'Mg' : 'Magnesium', 'Al' : 'Aluminium', 'Si' : 'Silicon', 'P' : 'Phosphorus', 'S' : 'Sulfur', 'Cl' : 'Chlorine', 'Ar' : 'Argon', 'K' : 'Potassium', 'Ca' : 'Calcium', 'Sc' : 'Scandium', 'Ti' : 'Titanium', 'V' : 'Vanadium', 'Cr' : 'Chromium', 'Mn' : 'Manganese', 'Fe' : 'Iron', 'Co' : 'Cobalt', 'Ni' : 'Nickel', 'Cu' : 'Copper', 'Zn' : 'Zinc', 'Ga' : 'Gallium', 'Ge' : 'Germanium', 'As' : 'Arsenic', 'Se' : 'Selenium', 'Br' : 'Bromine', 'Kr' : 'Krypton', 'Rb' : 'Rubidium', 'Sr' : 'Strontium', 'Y' : 'Yttrium', 'Zr' : 'Zirconium', 'Nb' : 'Niobium', 'Mo' : 'Molybdenum', 'Tc' : 'Technetium', 'Ru' : 'Ruthenium', 'Rh' : 'Rhodium', 'Pd' : 'Palladium', 'Ag' : 'Silver', 'Cd' : 'Cadmium', 'In' : 'Indium', 'Sn' : 'Tin', 'Sb' : 'Antimony', 'Te' : 'Tellurium', 'I' : 'Iodine', 'Xe' : 'Xenon', 'Cs' : 'Caesium', 'Ba' : 'Barium', 'La' : 'Lanthanum', 'Ce' : 'Cerium', 'Pr' : 'Praseodymium', 'Nd' : 'Neodymium', 'Pm' : 'Promethium', 'Sm' : 'Samarium', 'Eu' : 'Europium', 'Gd' : 'Gadolinium', 'Tb' : 'Terbium', 'Dy' : 'Dysprosium', 'Ho' : 'Holmium', 'Er' : 'Erbium', 'Tm' : 'Thulium', 'Yb' : 'Ytterbium', 'Lu' : 'Lutetium', 'Hf' : 'Hafnium', 'Ta' : 'Tantalum', 'W' : 'Tungsten', 'Re' : 'Rhenium', 'Os' : 'Osmium', 'Ir' : 'Iridium', 'Pt' : 'Platinum', 'Au' : 'Gold', 'Hg' : 'Mercury', 'Tl' : 'Thallium', 'Pb' : 'Lead', 'Bi' : 'Bismuth', 'Po' : 'Polonium', 'At' : 'Astatine', 'Rn' : 'Radon', 'Fr' : 'Francium', 'Ra' : 'Radium', 'Ac' : 'Actinium', 'Th' : 'Thorium', 'Pa' : 'Protactinium', 'U' : 'Uranium', 'Np' : 'Neptunium', 'Pu' : 'Plutonium', 'Am' : 'Americium', 'Cm' : 'Curium', 'Bk' : 'Berkelium', 'Cf' : 'Californium', 'Es' : 'Einsteinium', 'Fm' : 'Fermium', 'Md' : 'Mendelevium', 'No' : 'Nobelium', 'Lr' : 'Lawrencium', 'Rf' : 'Rutherfordium', 'Db' : 'Dubnium', 'Sg' : 'Seaborgium', 'Bh' : 'Bohrium', 'Hs' : 'Hassium', 'Mt' : 'Meitnerium', 'Ds' : 'Darmstadtium', 'Rg' : 'Roentgenium', 'Cn' : 'Copernicium', 'Uut' : 'Ununtrium', 'Fl' : 'Flerovium', 'Uup' : 'Ununpentium', 'Lv' : 'Livermorium', 'Uus' : 'Ununseptium', 'Uuo' : 'Ununoctium' } def __init__(self): self.quiz() def quiz(self): self.reply = ('Moron', 'Dummy', 'Idiot', 'Embecile', 'Half-wit') self.numCorrect = 0 self.question = random.choice(self.elements.keys()) print self.question self.ans = raw_input('Answer: ') if self.ans == self.elements(self.question): self.numCorrect += 1 else: self.insult = random.choice(self.reply) print 'Incorrect %s' % self.insult if __name__ == '__main__': quiz() Thanks for any help! From kroger at pedrokroger.net Fri Aug 10 15:05:36 2012 From: kroger at pedrokroger.net (Pedro Kroger) Date: Fri, 10 Aug 2012 16:05:36 -0300 Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: On Aug 10, 2012, at 3:52 PM, Chuck wrote: > if __name__ == '__main__': > > quiz() > > You need to instantiate your class: foo = ElementsQuiz() foo.quiz() Pedro ----- http://pedrokroger.net http://musicforgeeksandnerds.com From python.list at tim.thechases.com Fri Aug 10 15:10:15 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 10 Aug 2012 14:10:15 -0500 Subject: Unable to execute the script In-Reply-To: <5025551B.10107@davea.name> References: <5025551B.10107@davea.name> Message-ID: <50255C97.3050105@tim.thechases.com> On 08/10/12 13:38, Dave Angel wrote: > On 08/10/2012 01:14 PM, Smaran Harihar wrote: >> Hi, >> >> I have set executable permissions for my py script (cgi-script) but for >> some reason rather than executing it, the browser simply downloads the py >> script. >> >> Here is the link. >> Before it was working on another server. I migrated it to this new domain >> and it is having this issue. Where am I going wrong? >> >> > Lots of possibilities, though I can't think of any relating to Python. > So I didn't try to read your source file. > > Is the location of this script acceptable to your web host? Some hosts > deliberately restrict scripts to be in certain places (like /cgi-bin) in > order to thwart a certain type of cracker. > > Next question, is the python installation actually at the place where > your shebang points? And, if the file is on a *nix-like machine (Linux, BSD, Mac, Solaris, etc), have the executable bits been set? -tkc From smaran.harihar at gmail.com Fri Aug 10 15:14:37 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Fri, 10 Aug 2012 12:14:37 -0700 Subject: Unable to execute the script In-Reply-To: <50255C97.3050105@tim.thechases.com> References: <5025551B.10107@davea.name> <50255C97.3050105@tim.thechases.com> Message-ID: The file is on Ubuntu Server 12.04 and not sure how to set the executable bits? If you mean chmod +x then yes it has been set. On Fri, Aug 10, 2012 at 12:10 PM, Tim Chase wrote: > On 08/10/12 13:38, Dave Angel wrote: > > On 08/10/2012 01:14 PM, Smaran Harihar wrote: > >> Hi, > >> > >> I have set executable permissions for my py script (cgi-script) but for > >> some reason rather than executing it, the browser simply downloads the > py > >> script. > >> > >> Here is the link< > http://128.196.142.94/geo/iplantgeo_cgi.py?get=env&from=latlon&lat=42,45,54&lon=-123,-65,-100 > >. > >> Before it was working on another server. I migrated it to this new > domain > >> and it is having this issue. Where am I going wrong? > >> > >> > > Lots of possibilities, though I can't think of any relating to Python. > > So I didn't try to read your source file. > > > > Is the location of this script acceptable to your web host? Some hosts > > deliberately restrict scripts to be in certain places (like /cgi-bin) in > > order to thwart a certain type of cracker. > > > > Next question, is the python installation actually at the place where > > your shebang points? > > And, if the file is on a *nix-like machine (Linux, BSD, Mac, > Solaris, etc), have the executable bits been set? > > -tkc > > > > -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Aug 10 15:19:14 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 10 Aug 2012 19:19:14 +0000 Subject: Unable to execute the script In-Reply-To: References: Message-ID: This sounds like a ScriptAlias thing: http://httpd.apache.org/docs/2.2/howto/cgi.html On Fri, Aug 10, 2012 at 5:14 PM, Smaran Harihar wrote: > Hi, > > I have set executable permissions for my py script (cgi-script) but for > some reason rather than executing it, the browser simply downloads the py > script. > > Here is the link. > Before it was working on another server. I migrated it to this new domain > and it is having this issue. Where am I going wrong? > > -- > Thanks & Regards > Smaran Harihar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Aug 10 15:20:26 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 10 Aug 2012 14:20:26 -0500 Subject: Unable to execute the script In-Reply-To: References: <5025551B.10107@davea.name> <50255C97.3050105@tim.thechases.com> Message-ID: <50255EFA.2080105@tim.thechases.com> On 08/10/12 14:14, Smaran Harihar wrote: > If you mean chmod +x > > then yes it has been set. I'm not sure how Ubuntu defaults if you don't specify *who* should receive those +x permissions. I'd make sure they've been set for everybody: $ chmod ugo+x myfile.py You can check this by doing an "ls -lsF myfile.py" and you should see 3 "x"s in the permission column, something like 123 rwxr-xr-x 1 smaran smaran 31415 Apr 27 2012 myfile.py ^ ^ ^ If those are set properly, then Dave's suggestions are the next to try. -tkc From galois271 at gmail.com Fri Aug 10 15:23:37 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 12:23:37 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: <1598e0ea-bb92-46ca-9626-87e99bd37ec6@googlegroups.com> On Friday, August 10, 2012 2:05:36 PM UTC-5, Pedro Kroger wrote: > On Aug 10, 2012, at 3:52 PM, Chuck wrote: > > > > > if __name__ == '__main__': > > > > > > quiz() > > > > > > > > > > You need to instantiate your class: > > > > foo = ElementsQuiz() > > foo.quiz() > > > > > > Pedro > > ----- > > http://pedrokroger.net > > http://musicforgeeksandnerds.com That doesn't work either for some reason. I keep getting "NameError: name 'ElementsQuiz' is not defined" From galois271 at gmail.com Fri Aug 10 15:23:37 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 12:23:37 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: <1598e0ea-bb92-46ca-9626-87e99bd37ec6@googlegroups.com> On Friday, August 10, 2012 2:05:36 PM UTC-5, Pedro Kroger wrote: > On Aug 10, 2012, at 3:52 PM, Chuck wrote: > > > > > if __name__ == '__main__': > > > > > > quiz() > > > > > > > > > > You need to instantiate your class: > > > > foo = ElementsQuiz() > > foo.quiz() > > > > > > Pedro > > ----- > > http://pedrokroger.net > > http://musicforgeeksandnerds.com That doesn't work either for some reason. I keep getting "NameError: name 'ElementsQuiz' is not defined" From d at davea.name Fri Aug 10 15:29:48 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 15:29:48 -0400 Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: <5025612C.7090005@davea.name> On 08/10/2012 02:52 PM, Chuck wrote: > Hi all, I cannot figure why I keep getting this error. It is my understanding that all methods need a self argument when designing a class. Here is my code: It'd be much more useful if you'd actually quote the entire error. > import random > > class ElementsQuiz: > > elements = {'H' : 'Hydrogen', > 'He' : 'Helium', > 'Li' : 'Lithium', > 'Be' : 'Beryllium', > 'B' : 'Boron', > 'C' : 'Carbon', > 'N' : 'Nitrogen', > 'O' : 'Oxygen', > 'F' : 'Fluorine', > 'Ne' : 'Neon', > 'Na' : 'Sodium', > 'Mg' : 'Magnesium', > 'Al' : 'Aluminium', > 'Si' : 'Silicon', > 'P' : 'Phosphorus', > 'S' : 'Sulfur', > 'Cl' : 'Chlorine', > 'Ar' : 'Argon', > 'K' : 'Potassium', > 'Ca' : 'Calcium', > 'Sc' : 'Scandium', > 'Ti' : 'Titanium', > 'V' : 'Vanadium', > 'Cr' : 'Chromium', > 'Mn' : 'Manganese', > 'Fe' : 'Iron', > 'Co' : 'Cobalt', > 'Ni' : 'Nickel', > 'Cu' : 'Copper', > 'Zn' : 'Zinc', > 'Ga' : 'Gallium', > 'Ge' : 'Germanium', > 'As' : 'Arsenic', > 'Se' : 'Selenium', > 'Br' : 'Bromine', > 'Kr' : 'Krypton', > 'Rb' : 'Rubidium', > 'Sr' : 'Strontium', > 'Y' : 'Yttrium', > 'Zr' : 'Zirconium', > 'Nb' : 'Niobium', > 'Mo' : 'Molybdenum', > 'Tc' : 'Technetium', > 'Ru' : 'Ruthenium', > 'Rh' : 'Rhodium', > 'Pd' : 'Palladium', > 'Ag' : 'Silver', > 'Cd' : 'Cadmium', > 'In' : 'Indium', > 'Sn' : 'Tin', > 'Sb' : 'Antimony', > 'Te' : 'Tellurium', > 'I' : 'Iodine', > 'Xe' : 'Xenon', > 'Cs' : 'Caesium', > 'Ba' : 'Barium', > 'La' : 'Lanthanum', > 'Ce' : 'Cerium', > 'Pr' : 'Praseodymium', > 'Nd' : 'Neodymium', > 'Pm' : 'Promethium', > 'Sm' : 'Samarium', > 'Eu' : 'Europium', > 'Gd' : 'Gadolinium', > 'Tb' : 'Terbium', > 'Dy' : 'Dysprosium', > 'Ho' : 'Holmium', > 'Er' : 'Erbium', > 'Tm' : 'Thulium', > 'Yb' : 'Ytterbium', > 'Lu' : 'Lutetium', > 'Hf' : 'Hafnium', > 'Ta' : 'Tantalum', > 'W' : 'Tungsten', > 'Re' : 'Rhenium', > 'Os' : 'Osmium', > 'Ir' : 'Iridium', > 'Pt' : 'Platinum', > 'Au' : 'Gold', > 'Hg' : 'Mercury', > 'Tl' : 'Thallium', > 'Pb' : 'Lead', > 'Bi' : 'Bismuth', > 'Po' : 'Polonium', > 'At' : 'Astatine', > 'Rn' : 'Radon', > 'Fr' : 'Francium', > 'Ra' : 'Radium', > 'Ac' : 'Actinium', > 'Th' : 'Thorium', > 'Pa' : 'Protactinium', > 'U' : 'Uranium', > 'Np' : 'Neptunium', > 'Pu' : 'Plutonium', > 'Am' : 'Americium', > 'Cm' : 'Curium', > 'Bk' : 'Berkelium', > 'Cf' : 'Californium', > 'Es' : 'Einsteinium', > 'Fm' : 'Fermium', > 'Md' : 'Mendelevium', > 'No' : 'Nobelium', > 'Lr' : 'Lawrencium', > 'Rf' : 'Rutherfordium', > 'Db' : 'Dubnium', > 'Sg' : 'Seaborgium', > 'Bh' : 'Bohrium', > 'Hs' : 'Hassium', > 'Mt' : 'Meitnerium', > 'Ds' : 'Darmstadtium', > 'Rg' : 'Roentgenium', > 'Cn' : 'Copernicium', > 'Uut' : 'Ununtrium', > 'Fl' : 'Flerovium', > 'Uup' : 'Ununpentium', > 'Lv' : 'Livermorium', > 'Uus' : 'Ununseptium', > 'Uuo' : 'Ununoctium' > } > > def __init__(self): > self.quiz() Why would you do all the work from a call inside the initializer? What's the point of having instance attributes if you're not going to use it a second time? > def quiz(self): > self.reply = ('Moron', 'Dummy', 'Idiot', 'Embecile', 'Half-wit') > self.numCorrect = 0 > self.question = random.choice(self.elements.keys()) > print self.question > self.ans = raw_input('Answer: ') > > if self.ans == self.elements(self.question): > self.numCorrect += 1 > else: > self.insult = random.choice(self.reply) > print 'Incorrect %s' % self.insult > > > if __name__ == '__main__': > quiz() > Any reason why you put those two lines inside the class? That's your mainline code, and should be start at the left margin. Once you move the if __name__ stuff to the margin, and instantiated an object as Pedro mentions, and removed the call to quiz() from inside the initializer, it might work. I assume this is in a class because that was how it's assiged? -- DaveA From smaran.harihar at gmail.com Fri Aug 10 15:35:06 2012 From: smaran.harihar at gmail.com (Smaran Harihar) Date: Fri, 10 Aug 2012 12:35:06 -0700 Subject: Unable to execute the script In-Reply-To: <50255EFA.2080105@tim.thechases.com> References: <5025551B.10107@davea.name> <50255C97.3050105@tim.thechases.com> <50255EFA.2080105@tim.thechases.com> Message-ID: Hi Tim, this is the output for the ls -lsF filename 8 -rwxr-xr-x 1 root root 5227 Jul 30 13:54 iplantgeo_cgi.py* On Fri, Aug 10, 2012 at 12:20 PM, Tim Chase wrote: > On 08/10/12 14:14, Smaran Harihar wrote: > > If you mean chmod +x > > > > then yes it has been set. > > I'm not sure how Ubuntu defaults if you don't specify *who* should > receive those +x permissions. I'd make sure they've been set for > everybody: > > $ chmod ugo+x myfile.py > > You can check this by doing an "ls -lsF myfile.py" and you should > see 3 "x"s in the permission column, something like > > > 123 rwxr-xr-x 1 smaran smaran 31415 Apr 27 2012 myfile.py > ^ ^ ^ > > If those are set properly, then Dave's suggestions are the next to try. > > -tkc > > > > -- Thanks & Regards Smaran Harihar -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Fri Aug 10 16:00:35 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 16:00:35 -0400 Subject: Unable to execute the script In-Reply-To: References: <5025551B.10107@davea.name> Message-ID: <50256863.6050009@davea.name> You posted privately to me, so I'm sending it back to the list. Don't forget to do reply-all, or equivalent. On 08/10/2012 02:44 PM, Smaran Harihar wrote: > Is the location of this script acceptable to your web host? > > How can I check that? By asking your web host tech support, or reading their help faq's. > > Next question, is the python installation actually at the place where > your shebang points? > > Not sure what 'shebang' is!! I m a newbie so bit more explanation will be > helpful. if the first line of the script starts with a #! (pronounced she-bang) then the shell uses the rest of the line to launch the interpreter for the script. If it doesn't, then Linux won't have a clue what you want with this file. You also have been doing top-post in your replies, which is not the way this forum works. Put your remarks AFTER the part you're quoting, and remove the stuff your reader doesn't need. In the above section you've successfully confused most readers as to which parts I said and which parts you said. If you had simply put your remarks in the right place (with an before and after), all the quote bars would automatically be right. > > Thanks, > Smaran > > -- DaveA From tjreedy at udel.edu Fri Aug 10 16:27:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 Aug 2012 16:27:46 -0400 Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: On 8/10/2012 2:52 PM, Chuck wrote: > Hi all, I cannot figure why I keep getting this error. To supplement Dave's answer (post entire traceback, dedent last two lines), here are the essentials of your code that show the problem. >>> class C: def f(self): pass f() Traceback (most recent call last): File "", line 1, in class C: File "", line 3, in C f() TypeError: f() missing 1 required positional argument: 'self' You problem is that you are calling the function during the execution of the class statement, *before* the class is created. Rather unusual ;-). -- Terry Jan Reedy From galois271 at gmail.com Fri Aug 10 16:28:37 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 13:28:37 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Thanks for the help guys! I finally got it working. Shouldn't I technically call quiz() through the constructor, though? Otherwise, the constructor is pointless. I just put in pass for now. (Also, I always thought that if __name__ == '__main__': went IN the class. Why wouldn't it be apart of the class? ) Thanks again! From galois271 at gmail.com Fri Aug 10 16:28:37 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 13:28:37 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> Message-ID: <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Thanks for the help guys! I finally got it working. Shouldn't I technically call quiz() through the constructor, though? Otherwise, the constructor is pointless. I just put in pass for now. (Also, I always thought that if __name__ == '__main__': went IN the class. Why wouldn't it be apart of the class? ) Thanks again! From d at davea.name Fri Aug 10 16:50:26 2012 From: d at davea.name (Dave Angel) Date: Fri, 10 Aug 2012 16:50:26 -0400 Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Message-ID: <50257412.8000109@davea.name> On 08/10/2012 04:28 PM, Chuck wrote: > Thanks for the help guys! I finally got it working. Shouldn't I technically call quiz() through the constructor, though? Otherwise, the constructor is pointless. > > Thanks again! > What language did you use before trying Python? Was it java, by any chance, where everything has to be in a class? If you're going to do everything from the "constructor", then why on earth would you make it a class? (Incidentally, __init__() is the initializer, not the constructor, which is called __new__() ) If you want to make a proper class out of it, you'd move the initalization code into the __init__(), call, the stuff that only needs to be called once per instance. On the other hand, you have a class attribute 'elements, which gets initialized outside of any mmthod. And everything else is just locals. > I just put in pass for now. (Also, I always thought that > if __name__ == '__main__': went IN the class. Why wouldn't > it be apart of the class? ) Seems like you're arguing both sides. Anyway, the if __name__ stuff does not belong inside any class. This is Python. -- DaveA From galois271 at gmail.com Fri Aug 10 16:54:58 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 13:54:58 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Message-ID: <4f849e85-a14a-4cbb-b317-ee38a94827fa@googlegroups.com> Yeah, I am mostly a Java guy. Just starting with Python. :) From galois271 at gmail.com Fri Aug 10 16:54:58 2012 From: galois271 at gmail.com (Chuck) Date: Fri, 10 Aug 2012 13:54:58 -0700 (PDT) Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Message-ID: <4f849e85-a14a-4cbb-b317-ee38a94827fa@googlegroups.com> Yeah, I am mostly a Java guy. Just starting with Python. :) From pozzugno at gmail.com Fri Aug 10 17:25:51 2012 From: pozzugno at gmail.com (pozz) Date: Fri, 10 Aug 2012 23:25:51 +0200 Subject: [Newbie] How to wait for asyncronous input Message-ID: I'm new to Python and I'm trying to code something to learn the language details. I'm in trouble with asyncronous events, like asyncronous inputs (from serial port, from socket and so on). Let's consider a simple monitor of the traffic on a serial port. I'm using pyserial and I looked at the miniterm example: http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/serial/tools/miniterm.py The strategy is to create a thread that continuously call read() method while a couple of flags (alive and _reader_alive) are set: def reader(self): try: while self.alive and self._reader_alive: data = character(self.serial.read(1)) Is it an optimized strategy to wait for asyncronous input from serial port? I think in this way we have a thread that is always running and that always asks for new bytes from serial port. In C I should have used the select() on the serial port file descriptor. I think the select() put the thread in a sleep state and wake it up when some bytes are received on the file descriptor specified. It seems the "low-level" approach of select() is more optimized then the "high-level" approach of miniterm. From invalid at invalid.invalid Fri Aug 10 18:38:23 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 10 Aug 2012 22:38:23 +0000 (UTC) Subject: Threads and sockets References: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> Message-ID: On 2012-08-10, loial wrote: > At the moment I do not start to read responses until the data has > been sent to the printer. However it seems I am missing some > responses from the printer whilst sending the data, so I need to be > able to do the 2 things at the same time. > > Can I open a port once and then use 2 different threads, one to write > to the post and one to read the responses)? By "port" I assume you mean a TCP connection using the 'socket' module? If so, then yes you can write using one thread and read using a second thread. I do that all the time. Sometimes it's simpler to use a single thread that uses select or poll, and sometimes it's simpler to use multiple threads. And you never know which way is best until you're half way down the wrong road... From orgnut at yahoo.com Fri Aug 10 23:11:55 2012 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 10 Aug 2012 20:11:55 -0700 Subject: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)" In-Reply-To: <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> References: <8524ac60-2ff1-47d1-89e4-8ed2b7154268@googlegroups.com> <7717b41c-e81f-4751-9e10-b8d7115dd189@googlegroups.com> Message-ID: <2dadnbMjX_XmULjNnZ2dnUVZ5t-dnZ2d@giganews.com> On 08/10/2012 01:28 PM, Chuck wrote: > Thanks for the help guys! I finally got it working. Shouldn't I technically call quiz() through the constructor, though? Otherwise, the constructor is pointless. I just put in pass for now. For this particular example, frankly, a class doesn't make sense. Just write it as a set of independent functions. A class would make more sense if you wanted to make this a generic Quiz class, then you could change the actual quiz simply by passing an appropriate dictionary to it when it's instantiated. But even that could be done with simple functions as well. > (Also, I always thought that if __name__ == '__main__': went IN the class. Why wouldn't it be apart of the class? ) No way! That's nonsense also. You need to go through some introductory tutorials. Just keep in mind that Python and Java are VERY different languages. (I don't know Java myself, my (hobby) programming background has been with C, and I'm still just starting to learn Python, too.) > > Thanks again! > -=- Larry -=- PS. On another subject... You need to check your newsreader -- all your responses have been double-posted. From giacomo.alzetta at gmail.com Sat Aug 11 02:21:06 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Fri, 10 Aug 2012 23:21:06 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: Il giorno venerd? 10 agosto 2012 20:50:08 UTC+2, Stefan Behnel ha scritto: > Giacomo Alzetta, 10.08.2012 10:20: > > > I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). > > > At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. > > > > You should take a look at Cython. It makes these things way easier and > > safer than with manually written C code. It will save you a lot of code, > > debugging and general hassle. > > > > Stefan I already know Cython, but I hope to learn a bit how python works from the C-side writing this extension. Also this work is going to be included in a research work I'm doing, so I'd prefer to stick to Python and C, without having to put cython sources or cython-generated c modules(which I know are almost completely unreadable from a human point of view. Or at least the ones I saw). Anyway thank you for the suggestion. From giacomo.alzetta at gmail.com Sat Aug 11 02:21:06 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Fri, 10 Aug 2012 23:21:06 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: Il giorno venerd? 10 agosto 2012 20:50:08 UTC+2, Stefan Behnel ha scritto: > Giacomo Alzetta, 10.08.2012 10:20: > > > I'm trying to implement a c-extension which defines a new class(ModPolynomial on the python side, ModPoly on the C-side). > > > At the moment I'm writing the in-place addition, but I get a *really* strange behaviour. > > > > You should take a look at Cython. It makes these things way easier and > > safer than with manually written C code. It will save you a lot of code, > > debugging and general hassle. > > > > Stefan I already know Cython, but I hope to learn a bit how python works from the C-side writing this extension. Also this work is going to be included in a research work I'm doing, so I'd prefer to stick to Python and C, without having to put cython sources or cython-generated c modules(which I know are almost completely unreadable from a human point of view. Or at least the ones I saw). Anyway thank you for the suggestion. From stefan_ml at behnel.de Sat Aug 11 02:40:18 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Aug 2012 08:40:18 +0200 Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: Giacomo Alzetta, 11.08.2012 08:21: > I'd prefer to stick to Python and C, without having to put cython > sources or cython-generated c modules (which I know are almost > completely unreadable from a human point of view. Or at least the ones I > saw). And the cool thing is: you don't have to read them. :) Stefan From hansmu at xs4all.nl Sat Aug 11 02:59:11 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 11 Aug 2012 08:59:11 +0200 Subject: Unable to execute the script In-Reply-To: References: <5025551B.10107@davea.name> <50255C97.3050105@tim.thechases.com> <50255EFA.2080105@tim.thechases.com> Message-ID: <502602c0$0$6945$e4fe514c@news2.news.xs4all.nl> On 11/08/12 00:48:38, Dennis Lee Bieber wrote: > On Fri, 10 Aug 2012 12:35:06 -0700, Smaran Harihar > declaimed the following in > gmane.comp.python.general: > >> Hi Tim, >> >> this is the output for the ls -lsF filename >> >> 8 -rwxr-xr-x 1 root root 5227 Jul 30 13:54 iplantgeo_cgi.py* >> > > > A CGI script owned by root? Why not? It's not setuid, so being owned by root does not give it any special privileges. > What "user" does your web server run as? > I'd recommend setting that user as the owner of the CGI script. That's definitely a bad idea. More so if it's writeable by its owner, as is the case here. It would mean that if a security hole allows intruders to write to arbitrary files, then they can overwrite this script and that would allow them to execute arbitrary code. -- HansM From pozzugno at gmail.com Sat Aug 11 03:07:51 2012 From: pozzugno at gmail.com (pozz) Date: Sat, 11 Aug 2012 09:07:51 +0200 Subject: [Newbie] How to wait for asyncronous input In-Reply-To: References: Message-ID: Il 11/08/2012 01:12, Dennis Lee Bieber ha scritto: > What you apparently missed is that serial.read() BLOCKs until data > is available (unless the port was opened with a read timeout set). > [...] > > serial.read() may, there for, be using select() behind the scenes. Hmm..., so I could open the serial port with timeout=0 so the read(), that runs in a different thread, would block forever, so putting the thread in a sleep state until some bytes arrive. When the main thread wants to close the serial port, the receiving thread can be killed (I don't know why, but I think it will be possible). From giacomo.alzetta at gmail.com Sat Aug 11 04:55:09 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sat, 11 Aug 2012 01:55:09 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: <2eb5eab7-15c1-47e9-9b33-15c5cc9f7558@googlegroups.com> Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto: > Giacomo Alzetta, 11.08.2012 08:21: > > > I'd prefer to stick to Python and C, without having to put cython > > > sources or cython-generated c modules (which I know are almost > > > completely unreadable from a human point of view. Or at least the ones I > > > saw). > > > > And the cool thing is: you don't have to read them. :) > > > > Stefan Yes, but since all this code will end-up in the hands of some examiner, he'll have to read them. :) From giacomo.alzetta at gmail.com Sat Aug 11 04:55:09 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sat, 11 Aug 2012 01:55:09 -0700 (PDT) Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: References: Message-ID: <2eb5eab7-15c1-47e9-9b33-15c5cc9f7558@googlegroups.com> Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto: > Giacomo Alzetta, 11.08.2012 08:21: > > > I'd prefer to stick to Python and C, without having to put cython > > > sources or cython-generated c modules (which I know are almost > > > completely unreadable from a human point of view. Or at least the ones I > > > saw). > > > > And the cool thing is: you don't have to read them. :) > > > > Stefan Yes, but since all this code will end-up in the hands of some examiner, he'll have to read them. :) From stefan_ml at behnel.de Sat Aug 11 05:12:36 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Aug 2012 11:12:36 +0200 Subject: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place. In-Reply-To: <2eb5eab7-15c1-47e9-9b33-15c5cc9f7558@googlegroups.com> References: <2eb5eab7-15c1-47e9-9b33-15c5cc9f7558@googlegroups.com> Message-ID: Giacomo Alzetta, 11.08.2012 10:55: > Il giorno sabato 11 agosto 2012 08:40:18 UTC+2, Stefan Behnel ha scritto: >> Giacomo Alzetta, 11.08.2012 08:21: >> >>> I'd prefer to stick to Python and C, without having to put cython >>> sources or cython-generated c modules (which I know are almost >>> completely unreadable from a human point of view. Or at least the ones I >>> saw). >> >> And the cool thing is: you don't have to read them. :) > > Yes, but since all this code will end-up in the hands of some examiner, he'll have to read them. :) I'd just ask him what he prefers: beautiful Python code with a couple of static type declarations in it, or verbose C code with lots of C-isms and C-API-isms all over the place. If he's smart enough, he'll force you into writing the code in Cython. Stefan From clickfirm2007 at gmail.com Sat Aug 11 05:23:26 2012 From: clickfirm2007 at gmail.com (Mohamed Gad) Date: Sat, 11 Aug 2012 02:23:26 -0700 (PDT) Subject: ~~** Unique Floral, Neckline, 4x4 Ornament Embroidery Designs F.R.E.E.!! **~~ Message-ID: <15a23338-f820-499e-a8d2-29b0842f548e@h5g2000vbl.googlegroups.com> Unique Floral Design .. F.R.E.E http://www.embroworld.com/embroidery/4x4-floral-design-132/ Unique Neckline Embroidery Design .. F.R.E.E http://www.theembroidery.com/unique-neckline-embroidery-design-136/ 4x4 Ornament Embroidery Design .. F.R.E.E http://www.embrohome.com/details.php?image_id=74 Enjoy Our New F.R.E.E.B.I.E.S. SUPPORT ME!! Nanees http://www.book-mall.com From hansmu at xs4all.nl Sat Aug 11 05:24:48 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 11 Aug 2012 11:24:48 +0200 Subject: [Newbie] How to wait for asyncronous input In-Reply-To: References: Message-ID: <502624e0$0$6946$e4fe514c@news2.news.xs4all.nl> On 11/08/12 09:07:51, pozz wrote: > Il 11/08/2012 01:12, Dennis Lee Bieber ha scritto: >> What you apparently missed is that serial.read() BLOCKs until data >> is available (unless the port was opened with a read timeout set). >> [...] >> >> serial.read() may, there for, be using select() behind the scenes. > > Hmm..., so I could open the serial port with timeout=0 so the read(), > that runs in a different thread, would block forever, so putting the > thread in a sleep state until some bytes arrive. > > When the main thread wants to close the serial port, the receiving > thread can be killed How would you do that? IFAIK, there is no way in Python to kill a thread. The usual work-around is to have a global flag that you'd set to True when the main thread wants to close the port. The read would have a timeout of 1 second of so, so that the reading thread is woken up every second, so it can check that flag and wind up when the flag is set. Hope this helps, -- HansM From rfflrccrd at gmail.com Sat Aug 11 05:53:37 2012 From: rfflrccrd at gmail.com (Raffaele Ricciardi) Date: Sat, 11 Aug 2012 10:53:37 +0100 Subject: Xlib: watching key presses without trapping them Message-ID: Hello there, I'm writing a X Windows program to perform some actions when modifier keys have been released. After looking into the Pykeylogger project (pykeylogger.sourceforge.net), I've gone as far as detecting all events related to modifiers, but then such events get trapped by the program and do not reach other applications. I'm using Python 2.7.3. Thanks for your help. Here it is the program: #! /usr/bin/env python from Xlib.display import Display from Xlib import X Control_R = 64 # Keycode for right Control. Control_L = 108 # Keycode for left Control. # Keycodes we are listening for. I've left out Right Control # to be able to stop the program. keycodes = [Control_L] # Handle X events. def handle_event(event): # Let us know whether this event is about a Key Release of # one of the keys in which we are interested. if event.type == X.KeyRelease: keycode = event.detail if keycode in keycodes: print "KeyRelease" # Objects needed to call Xlib. display = Display() root = display.screen().root # Tell the X server we want to catch KeyRelease events. root.change_attributes(event_mask = X.KeyReleaseMask) # Grab those keys. for keycode in keycodes: root.grab_key(keycode, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync) # Event loop. while 1: event = root.display.next_event() handle_event(event) # End of program. From steve+comp.lang.python at pearwood.info Sat Aug 11 05:56:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Aug 2012 09:56:30 GMT Subject: [Newbie] How to wait for asyncronous input References: <502624e0$0$6946$e4fe514c@news2.news.xs4all.nl> Message-ID: <50262c4e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Aug 2012 11:24:48 +0200, Hans Mulder wrote: > On 11/08/12 09:07:51, pozz wrote: >> When the main thread wants to close the serial port, the receiving >> thread can be killed > > > How would you do that? > > IFAIK, there is no way in Python to kill a thread. Correct. > The usual work-around is to have a global flag that you'd set to True > when the main thread wants to close the port. The read would have a > timeout of 1 second of so, so that the reading thread is woken up every > second, so it can check that flag and wind up when the flag is set. It doesn't need to be a global flag. You can make the flag an attribute of the thread, and then have the thread check self.flag. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 11 07:26:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Aug 2012 11:26:37 GMT Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> Message-ID: <5026416d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote: > On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel wrote: >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: >>> O(n) for all other entries in the dict which suffer a hash collision >>> with the searched entry. >>> >>> True, a sensible choice of hash function will reduce n to 1 in common >>> cases, but it becomes an important consideration for larger datasets. >> >> I'm glad you're wrong for CPython's dictionaries. The only time the >> lookup would degenerate to O[n] would be if the hash table had only one >> slot. CPython sensibly increases the hash table size when it becomes >> too small for efficiency. >> >> Where have you seen dictionaries so poorly implemented? > > In vanilla CPython up to version (I think) 3.3, where it's possible to > DoS the hash generator. Hash collisions are always possible, just > ridiculously unlikely unless deliberately exploited. Not so unlikely actually. py> hash(3) 3 py> hash(2**64 + 2) 3 py> hash(-1) -2 py> hash(-2) -2 By its very nature, a hash function cannot fail to have collisions. The problem is that in general you have an essentially unlimited number of objects being mapped to a large but still finite number of hash values. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 11 07:40:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Aug 2012 11:40:35 GMT Subject: Xlib: watching key presses without trapping them References: Message-ID: <502644b3$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Aug 2012 10:53:37 +0100, Raffaele Ricciardi wrote: > Hello there, > > I'm writing a X Windows program to perform some actions when modifier > keys have > been released. After looking into the Pykeylogger project > (pykeylogger.sourceforge.net), I've gone as far as detecting all events > related > to modifiers, but then such events get trapped by the program and do not > reach > other applications. Questions about specialised modules like Pykeylogger will have a much better chance of being answered if you ask in a dedicated Pykeylogger forum. If there is none, try emailing the author. If you do get an answer elsewhere, please consider passing it on here so others can learn about it too. Have you looked at how GUIs like wxPython and Tkinter handle key events? That might help. -- Steven From animelovin at gmail.com Sat Aug 11 11:15:10 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Sat, 11 Aug 2012 11:15:10 -0400 Subject: [ANNOUNCE] Campaign to support the notmm project! Message-ID: <502676FE.3040600@gmail.com> Hi All, I'm raising a campaign to support the notmm project, a freely accessible open source project i created to develop an advanced web framework for Django. Furthermore the project is using ConfigObj internally for allowing flexible configuration and Cython for extending Django apps in C. If you would like thus supporting the time and work I invested into the project I would really appreciate a small donation, as I'm now really poor and cannot even finance the server hosting. Your donation would therefore be used to put back the website online and continue active development of an alternative web framework for Python which doesn't necessarily force its users to log in Facebook or Twitter for commenting, or syndication purposes.. Lastly if you have any comments on this letter or would like further info before making a donation it will be my pleasure to help.. Kind regards, Etienne http://pledgie.com/campaigns/16268 -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org ?It is easy to fly into a passion... anybody can do that, but to be angry with the right person to the right extent and at the right time and in the right way that is not easy.? -Aristotle ?You have to accept whatever comes and the only important thing is that you meet it with courage and with the best that you have to give.? - Eleanor Roosevelt From giacomo.alzetta at gmail.com Sat Aug 11 12:54:56 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sat, 11 Aug 2012 09:54:56 -0700 (PDT) Subject: in-place exponentiation incongruities Message-ID: I've noticed some incongruities regarding in-place exponentiation. On the C side nb_inplace_power is a ternary function, like nb_power (see here: http://docs.python.org/c-api/typeobj.html?highlight=numbermethods#PyNumberMethods). Obviously you can't pass the third argument using the usual in-place syntax "**=". Nevertheless I'd expect to be able to provide the third argument using operator.ipow. But the operator module accept only the two parameter variant. The Number Protocol specify that the ipow operation ""is the equivalent of the Python statement o1 **= o2 when o3 is Py_None, or an in-place variant of pow(o1, o2, o3) otherwise."" Since "operator" claims to be contain a "function port" of the operators, I'd expect it to implement ipow with three arguments. I don't see any problem in adding the third argument to it(I mean, sure right now any code that calls ipow(a,b,c) [if exists] is broken, because it will just raise a TypeError, thus adding the argument will not break any code, and would provide more functionality. Also, I don't think there are many objects in the build-ins or standardlib which implement an in-place exponentiation, so this means there wont be much code to change. So my question is: why are there this incongruities? Is there any chance to see this fixed? (in the operator module, or changing the documentation) By the way: I'm asking this because I'm implementing a C-extension and I'd like to implement both pow and ipow. And since it's about polynomials on (Z/nZ)[x]/x^r-1, using the third argument always makes sense. From john_ladasky at sbcglobal.net Sat Aug 11 18:30:21 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 11 Aug 2012 15:30:21 -0700 (PDT) Subject: Arithmetic with Boolean values Message-ID: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> I have gotten used to switching back and forth between Boolean algebra and numerical values. Python generally makes this quite easy. I just found a case that surprises me. Here is what I want to accomplish: I want to process a list. If the length of the list L is odd, I want to process it once. If len(L) is even, I want to process it twice. I thought I would set up a loop as follows: for x in range(1 + not(len(L) % 2)): # Do stuff This provoked a SyntaxError. I investigated this further with my interpreter (ipython). In [1]: L = range(5) In [2]: L Out[2]: [0, 1, 2, 3, 4] In [3]: len(L) Out[3]: 5 In [4]: len(L) % 2 Out[4]: 1 In [5]: not(1) Out[5]: False In [6]: not(len(L) % 2) Out[6]: False In [7]: 1 + not(len(L) % 2) ------------------------------------------------------------ File "", line 1 1 + not(len(L) % 2) ^ SyntaxError: invalid syntax So as you can see, every thing is working fine until I attempt to add 1 and False. However: In [8]: 0 == False Out[8]: True In [9]: 1 == True Out[9]: True So, 0 and False do pass an equivalency test, as do 1 and True. Furthermore: In [10]: 1 + (len(L) % 2 == 0) Out[10]: 1 Why is using a logical "not" function, as shown in [7], returning a different result than the test for equivalency as shown in [10]? Of course I'm just going to use [10] in my program, but I'd like to understand the reason that I'm getting that SyntaxError. I've been reading Python style guides, and at least one of them states a preference for using the "not" syntax over the "== 0" syntax. I'm using Python 2.7, in case it matters. From opiney597 at yahoo.com Sat Aug 11 19:09:16 2012 From: opiney597 at yahoo.com (Opap-OJ) Date: Sat, 11 Aug 2012 16:09:16 -0700 (PDT) Subject: Idle no longer works Message-ID: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> I can no longer open the Idle IDE for Python on Windows 7. For 3-5 years I used Idle for all my python work. But in January this happens: When I right click on a python file and choose "open with Idle" nothing happens. If I double-click on the file itself, it briefly opens an MS-DOS looking window, then closes it immediately. I tried installing Eclipse with PyDev. It opens the file, but will not run it in Python. Any idea why? From gelonida at gmail.com Sat Aug 11 19:09:23 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 12 Aug 2012 01:09:23 +0200 Subject: Does anyone have an activate script for portable python? Message-ID: Hi, In Pythons installed with virtualenv there is on windows an activate.bat script, that can be used to setup the cmd-shell such, that the search path for python and pythor elated tools (pip / easy_install) is setup properly. Further there is the deactivate script to set the environment back to it's state before calling activate. Do such a scripts also exist for Portable python? If anybody wrote already such scripts, then couldn't they be added to the official portable python release? I never used portable python so far but can't imagine, that I'm the only one who'd like such a script. From rosuav at gmail.com Sat Aug 11 19:13:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Aug 2012 09:13:15 +1000 Subject: Arithmetic with Boolean values In-Reply-To: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky wrote: > In [7]: 1 + not(len(L) % 2) > ------------------------------------------------------------ > File "", line 1 > 1 + not(len(L) % 2) > ^ > SyntaxError: invalid syntax This appears to be a limitation of the parser; it's trying to interpret "not" as a binary operator. 1 + (not(len(L) % 2)) Works just fine with parentheses to enforce the correct interpretation. This also works in Python 3.2, fwiw (except that you need list(range(5)) to create the sample list). ChrisA From clp2 at rebertia.com Sat Aug 11 19:53:06 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 11 Aug 2012 16:53:06 -0700 Subject: Arithmetic with Boolean values In-Reply-To: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: On Sat, Aug 11, 2012 at 3:30 PM, John Ladasky wrote: > for x in range(1 + not(len(L) % 2)): > # Do stuff > > This provoked a SyntaxError. I investigated this further with my interpreter (ipython). > In [5]: not(1) > Out[5]: False > > In [6]: not(len(L) % 2) > Out[6]: False > > In [7]: 1 + not(len(L) % 2) > ------------------------------------------------------------ > File "", line 1 > 1 + not(len(L) % 2) > ^ > SyntaxError: invalid syntax > Why is using a logical "not" function, as shown in [7], returning a different result than the test for equivalency as shown in [10]? Note that, in Python, `not` is an unary operator (it's a language keyword in fact), as opposed to a function: Python 2.7.2 (default, Jun 20 2012, 16:23:33) >>> len("abc") 3 >>> # functions are first-class entities in Python, so we can reference them >>> len >>> not(1) False >>> # but `not` isn't a function >>> not File "", line 1 not ^ SyntaxError: invalid syntax >>> # hence why we don't need to call it >>> not 1 False The parentheses in `not(foo)` are just grouping the `foo` subexpression; they're not indicating a function call. Therefore, in idiomatic Python, such parentheses are omitted whenever possible (which is the majority of the time), and when they are absolutely necessary, a space is included before the opening paren, because we're not making a function call. Thus, you're simply running into an operator precedence issue, which, as Chris A. explained, can be remedied by adding grouping parens around the entire `not` expression; e.g. `(not foo)` Cheers, Chris R. From nospam at nospam.com Sat Aug 11 20:03:33 2012 From: nospam at nospam.com (Gilles) Date: Sun, 12 Aug 2012 02:03:33 +0200 Subject: Running Python web apps on shared ASO servers? Message-ID: Hello I use A Small Orange (ASO) as my web provider. Asking the question in their forum so far didn't work, so I figured I might have a faster answer by asking here. Support replied this in an old thread: "Just a CGI option. We don't have enough users to justify adding mod_python support." http://forums.asmallorange.com/topic/4672-python-support/page__hl__python http://forums.asmallorange.com/topic/4918-python-fcgi-verses-mod-python/ Does it mean that ASO only supports writing Python web apps as long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded Python ? la PHP? If that's the case, which smallest tool would you recomment to write basic apps, eg. handling forms, etc.? Thank you. From tjreedy at udel.edu Sat Aug 11 20:25:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 Aug 2012 20:25:51 -0400 Subject: Arithmetic with Boolean values In-Reply-To: References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: On 8/11/2012 7:13 PM, Chris Angelico wrote: > On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky > wrote: >> In [7]: 1 + not(len(L) % 2) >> ------------------------------------------------------------ >> File "", line 1 >> 1 + not(len(L) % 2) >> ^ >> SyntaxError: invalid syntax > > This appears to be a limitation of the parser; it's trying to > interpret "not" as a binary operator. I think not. It is lower precedence than all arithmetic operators. The following is worth knowing about and occasionally reviewing. http://docs.python.org/py3k/reference/expressions.html#summary () around % is not needed; not len(L) % 2 works same. So parser sees 1 + not len(L) % 2 with + given higher precedence than not, So it parses as (1 + not) and croaks, as indicated by caret. (We humans see that that is impossible and may boost the precedence in context.) > 1 + (not(len(L) % 2)) == 1 + (not len(L) % 2) > > Works just fine with parentheses to enforce the correct interpretation. > > This also works in Python 3.2, fwiw (except that you need > list(range(5)) to create the sample list). -- Terry Jan Reedy From benjamin.kaplan at case.edu Sat Aug 11 20:30:55 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 11 Aug 2012 17:30:55 -0700 Subject: Idle no longer works In-Reply-To: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> References: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> Message-ID: On Sat, Aug 11, 2012 at 4:09 PM, Opap-OJ wrote: > I can no longer open the Idle IDE for Python on Windows 7. > > For 3-5 years I used Idle for all my python work. But in January this happens: > > When I right click on a python file and choose "open with Idle" nothing happens. > > If I double-click on the file itself, it briefly opens an MS-DOS looking window, then closes it immediately. > > I tried installing Eclipse with PyDev. It opens the file, but will not run it in Python. > > Any idea why? > -- Have you tried launching Python from the Command Prompt? Open up command prompt and run C:\Python32\python.exe or whatever corresponds to your version of Python. From rosuav at gmail.com Sat Aug 11 20:31:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Aug 2012 10:31:22 +1000 Subject: Arithmetic with Boolean values In-Reply-To: References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: On Sun, Aug 12, 2012 at 10:25 AM, Terry Reedy wrote: > On 8/11/2012 7:13 PM, Chris Angelico wrote: >> This appears to be a limitation of the parser; it's trying to >> interpret "not" as a binary operator. > > I think not. It is lower precedence than all arithmetic operators. > (We humans see that that is impossible and > may boost the precedence in context.) Ah, I stand corrected. And once again, I kinda expected Python to follow the rules of my mental parser :) Anyway, point stands that parens will fix the issue. ChrisA From python at mrabarnett.plus.com Sat Aug 11 20:36:45 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 12 Aug 2012 01:36:45 +0100 Subject: Arithmetic with Boolean values In-Reply-To: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: <5026FA9D.8070900@mrabarnett.plus.com> On 11/08/2012 23:30, John Ladasky wrote: > I have gotten used to switching back and forth between Boolean algebra and numerical values. Python generally makes this quite easy. I just found a case that surprises me. > > Here is what I want to accomplish: I want to process a list. If the length of the list L is odd, I want to process it once. If len(L) is even, I want to process it twice. I thought I would set up a loop as follows: > > for x in range(1 + not(len(L) % 2)): > # Do stuff > > This provoked a SyntaxError. I investigated this further with my interpreter (ipython). > > In [1]: L = range(5) > > In [2]: L > Out[2]: [0, 1, 2, 3, 4] > > In [3]: len(L) > Out[3]: 5 > > In [4]: len(L) % 2 > Out[4]: 1 > > In [5]: not(1) > Out[5]: False > > In [6]: not(len(L) % 2) > Out[6]: False > > In [7]: 1 + not(len(L) % 2) > ------------------------------------------------------------ > File "", line 1 > 1 + not(len(L) % 2) > ^ > SyntaxError: invalid syntax > > So as you can see, every thing is working fine until I attempt to add 1 and False. However: > > In [8]: 0 == False > Out[8]: True > > In [9]: 1 == True > Out[9]: True > > So, 0 and False do pass an equivalency test, as do 1 and True. Furthermore: > > In [10]: 1 + (len(L) % 2 == 0) > Out[10]: 1 > > Why is using a logical "not" function, as shown in [7], returning a different result than the test for equivalency as shown in [10]? > > Of course I'm just going to use [10] in my program, but I'd like to understand the reason that I'm getting that SyntaxError. I've been reading Python style guides, and at least one of them states a preference for using the "not" syntax over the "== 0" syntax. > > I'm using Python 2.7, in case it matters. > I think the problem is that "not" isn't a function as such - it doesn't require parentheses, for example. The relevant syntax rules are: a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr | m_expr "%" u_expr u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr power ::= primary ["**" u_expr] primary ::= atom | attributeref | subscription | slicing | call atom ::= identifier | literal | enclosure enclosure ::= parenth_form | list_display | dict_display | set_display | generator_expression | yield_atom call ::= primary "(" [argument_list [","] | comprehension] ")" In order for your code to work I think we would need to have something like this: primary ::= atom | attributeref | subscription | slicing | call | not_expr not_expr ::= "not" parenth_form From gelonida at gmail.com Sat Aug 11 20:49:40 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 12 Aug 2012 02:49:40 +0200 Subject: suggesting a launcher wrapper script for portable python Message-ID: I just started looking at portable Python and was rather surprised, that I didn't find any recommended method in the documentation of how to launch scripts with portable python. Creating py2exe scripts on ones own USB drive seems to be kind of overkill. So here my own thoughts / suggestsions. I'm interestted in feedback of how others use portable pythons and how they run their scripts from a USB stick. Let's assume I install portable python on my USB drive and then I'd like to store self written python scripts on this drive. It would of course be greate if I could just click on the script and they'd be started. However under windows this would not be the case. The python script would either not be started at all or if the PC had his own python installed, then the script would be started with the PC's version of python. Thus a tiny wrapper script would be needed. Suggestion: -------------- The current directory structore for portable python (2.7) is (assuming that %PP% is the base directory) %PP%/Python-Portable.exe # launches the python interactive shell %PP%/PyScripter-Portable.exe # launches some IDE %PP%/App Let's assume I add two more directories: %PP%/myscripts # location of all callable scripts %PP%/launchers # location with icons one can click on # to start the scripts in myscripts if I wrote a script named %PP%/myscripts/test1.py, and I created an aproprriate named %PP%/launchers/test1.bat then I could just click on test1.bat and the Python script test1.py would be started. If the wrapper script is written properly, then it can look at its own base name and call the related python script. If I dragged and dropped some filenames on the bat file, then they would be passed to sys.argv of the script. Running the script from command line would also work and the present working directory would be preserved (which might be useful in some cases) If the script name would not be .py, but .pyw then it woudl be started with pythonw. T Below suggested script: @echo off REM ========================================================================= REM script to start a python file with portable python REM ========================================================================= REM basepath of this .bat file set basepath=%~dp0 REM create the name of the python file related to this bat file REM Unfortunately I do not know how to normalyze %pyfile%, REM so we got stuck with the '..' set pyfile=%basepath%..\myscripts\%~n0.py If EXIST "%pyfile%" ( REM a normal console python file with .py suffix "%basepath%\..\App\python.exe" "%pyfile%" %* ) ELSE ( If EXIST "%pyfile%w" ( REM a non console python file with .pyw suffix start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w" %* ) ELSE ( REM found neither a .py nor a .pyw file echo found no python file %pyfile% ) ) REM ========================================================================= REM end of script REM ========================================================================= One minor drawback of my suggested script would be, that a console window pops up for a few seconds when starting a .pyw file. This could be avoided by using either a small compiled C-file (which sounds like overkill though) or by writing a windows scripting host .wsf file. However I don't know this well enough to replicate my batch file. AN article on SO mentions how to write such a script. However it does not parse command line arguments nor does it automatically determine the scripts file name. So any help for creating a .wsf file starting a .pyw file with command line arguments would be appreciated. An alternativce approach could be to provide a scipt named mk_wrapper.bat If one drags and drops a python script on it, then an apropriate wrapper file would be created in the launcher directory. If well done, then this could be implemented such, that the script may be located in an arbitrary location on the same USB drive. I think it would be great if the official portable python release contained some upport for launching scripts. Perhaps it exists alrady and I just didn't find it? If not,then I wouldn't mind if my script or a similiar sand a related README.txt cript were added to the official release From no.email at nospam.invalid Sat Aug 11 20:54:40 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 11 Aug 2012 17:54:40 -0700 Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: <7x4no96ib3.fsf@ruckus.brouhaha.com> John Ladasky writes: > I have gotten used to switching back and forth between Boolean algebra > and numerical values. Python generally makes this quite easy. Generally ugly though, at least to my tastes. "Explicit is better than implicit" as the saying goes. > If the length of the list L is odd, I want to process it once. If > len(L) is even, I want to process it twice.... > for x in range(1 + not(len(L) % 2)): If you really have to do something like that, I'd say for x in range(1 + (len(L) & 1)): or for x in range(2 - len(L) % 2): are simpler and avoid those bogus bool conversions. I'd prefer to just say the intention: for x in range(1 if len(L)%2==1 else 2): > This provoked a SyntaxError. "not" is a syntactic keyword and "1 + not" is syntactically invalid. You could write "1 + (not ...)" as you discovered, but really, it's hackish. From tjreedy at udel.edu Sat Aug 11 21:59:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 Aug 2012 21:59:22 -0400 Subject: Idle no longer works In-Reply-To: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> References: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> Message-ID: On 8/11/2012 7:09 PM, Opap-OJ wrote: > I can no longer open the Idle IDE for Python on Windows 7. > > For 3-5 years I used Idle for all my python work. But in January > this happens: > > When I right click on a python file and choose "open with Idle" > nothing happens. > > If I double-click on the file itself, it briefly opens an MS-DOS > looking window, then closes it immediately. That should run the file and discard the output. Above is typical > Any idea why? *Something* very specific to your system changed. Either registry associations for .py are screwed, or your Python installation is damaged. Easiest fix is to uninstall and re-install Python. But download a more recent version first. Uninstall might not be needed, but makes process more like to work. In the regular interactive command prompt interpreter import idlelib.idle should start idle. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sun Aug 12 00:28:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Aug 2012 04:28:10 GMT Subject: in-place exponentiation incongruities References: Message-ID: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Aug 2012 09:54:56 -0700, Giacomo Alzetta wrote: > I've noticed some incongruities regarding in-place exponentiation. > > On the C side nb_inplace_power is a ternary function, like nb_power (see > here: > http://docs.python.org/c-api/typeobj.html? highlight=numbermethods#PyNumberMethods). > > Obviously you can't pass the third argument using the usual in-place > syntax "**=". Nevertheless I'd expect to be able to provide the third > argument using operator.ipow. But the operator module accept only the > two parameter variant. Why? The operator module implements the ** operator, not the pow() function. If you want the pow() function, you can just use it directly, no need to use operator.pow or operator.ipow. Since ** is a binary operator, it can only accept two arguments. > The Number Protocol specify that the ipow operation ""is the equivalent > of the Python statement o1 **= o2 when o3 is Py_None, or an in-place > variant of pow(o1, o2, o3) otherwise."" Where is that from? -- Steven From dieter at handshake.de Sun Aug 12 01:56:26 2012 From: dieter at handshake.de (Dieter Maurer) Date: Sun, 12 Aug 2012 07:56:26 +0200 Subject: Running Python web apps on shared ASO servers? References: Message-ID: <87mx20k60l.fsf@handshake.de> Gilles writes: > ... > Support replied this in an old thread: "Just a CGI option. We don't > have enough users to justify adding mod_python support." > http://forums.asmallorange.com/topic/4672-python-support/page__hl__python > http://forums.asmallorange.com/topic/4918-python-fcgi-verses-mod-python/ > > Does it mean that ASO only supports writing Python web apps as > long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded > Python ? la PHP? It looks as if you could use CGI to activate Python scripts. There seems to be no mod_python" support. You should probably read the mentioned forum resources to learn details about the Python support provided by your web site hoster. From giacomo.alzetta at gmail.com Sun Aug 12 03:14:27 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sun, 12 Aug 2012 00:14:27 -0700 (PDT) Subject: in-place exponentiation incongruities In-Reply-To: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> Il giorno domenica 12 agosto 2012 06:28:10 UTC+2, Steven D'Aprano ha scritto: > On Sat, 11 Aug 2012 09:54:56 -0700, Giacomo Alzetta wrote: > > > > > I've noticed some incongruities regarding in-place exponentiation. > > > > > > On the C side nb_inplace_power is a ternary function, like nb_power (see > > > here: > > > http://docs.python.org/c-api/typeobj.html? > > highlight=numbermethods#PyNumberMethods). > > > > > > Obviously you can't pass the third argument using the usual in-place > > > syntax "**=". Nevertheless I'd expect to be able to provide the third > > > argument using operator.ipow. But the operator module accept only the > > > two parameter variant. > > > > Why? The operator module implements the ** operator, not the pow() > > function. If you want the pow() function, you can just use it directly, > > no need to use operator.pow or operator.ipow. > > > > Since ** is a binary operator, it can only accept two arguments. > > > > > > > The Number Protocol specify that the ipow operation ""is the equivalent > > > of the Python statement o1 **= o2 when o3 is Py_None, or an in-place > > > variant of pow(o1, o2, o3) otherwise."" > > > > Where is that from? > > > > > > -- > > Steven >From The Number Protocol(http://docs.python.org/c-api/number.html). The full text is: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3) Return value: New reference. **See the built-in function pow().** Returns NULL on failure. The operation is done in-place when o1 supports it. This is the equivalent of the Python statement o1 **= o2 when o3 is Py_None, or an in-place variant of pow(o1, o2, o3) otherwise. If o3 is to be ignored, pass Py_None in its place (passing NULL for o3 would cause an illegal memory access). The first thing that this text does is referring to the **function** pow, which takes three arguments. And since the documentation of the operator module states that "The operator module exports a set of efficient functions corresponding to the intrinsic operators of Python.", I'd expect the ipow to have three arguments, the third being optional. With normal exponentiation you have ** referring to the 2-argument variant, and "pow" providing the ability to use the third argument. At the moment in-place exponentiation you have "**=" referring to the 2-argument variant(and this is consistent), while operator.ipow also referring to it. So providing an ipow with the third argument would just increase consistency in the language, and provide a feature that at the moment is not present. (well if the designers of python care really much about consistency they'd probably add an "ipow" built-in function, so that you don't have to import it from "operator"). I understand that it's not a feature often used, but I can't see why not allowing it. At the moment you can do that from the C side, because you can call PyNumber_InPlacePower directly, but from the python side you have no way to do that, except for writing a C-extension that wraps the PyNumber_InPlacePower function. From steve+comp.lang.python at pearwood.info Sun Aug 12 07:03:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Aug 2012 11:03:08 GMT Subject: in-place exponentiation incongruities References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> Message-ID: <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Aug 2012 00:14:27 -0700, Giacomo Alzetta wrote: > From The Number Protocol(http://docs.python.org/c-api/number.html). The > full text is: > > PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject > *o3) > Return value: New reference. > > **See the built-in function pow().** Returns NULL on failure. The > operation is done in-place when o1 supports it. This is the > equivalent of the Python statement o1 **= o2 when o3 is Py_None, or > an in-place variant of pow(o1, o2, o3) otherwise. If o3 is to be > ignored, pass Py_None in its place (passing NULL for o3 would cause > an illegal memory access). > > The first thing that this text does is referring to the **function** > pow, which takes three arguments. And since the documentation of the > operator module states that "The operator module exports a set of > efficient functions corresponding to the intrinsic operators of > Python.", I'd expect the ipow to have three arguments, the third being > optional. Why? There is no three-argument operator. There is a three-argument function, pow, but you don't need the operator module for that, it is built-in. There is no in-place three-argument operator, and no in-place three-argument function in the operator module. Arguing from "consistency" is not going to get you very far, since it is already consistent: In-place binary operator: **= In-place binary function: operator.ipow In-place three-argument operator: none In-place three-argument function: none If you decide to make a feature-request, you need to argue from usefulness, not consistency. http://bugs.python.org Remember that the Python 2.x branch is now in feature-freeze, so new features only apply to Python 3.x. > With normal exponentiation you have ** referring to the 2-argument > variant, and "pow" providing the ability to use the third argument. Correct. > At the moment in-place exponentiation you have "**=" referring to the > 2-argument variant(and this is consistent), while operator.ipow also > referring to it. Correct. Both **= and ipow match the ** operator, which only takes two arguments. > So providing an ipow with the third argument would just > increase consistency in the language, Consistency with something other than **= would be inconsistency. > and provide a feature that at the > moment is not present. (well if the designers of python care really much > about consistency they'd probably add an "ipow" built-in function, so > that you don't have to import it from "operator"). Not everything needs to be a built-in function. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 12 07:22:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Aug 2012 11:22:19 GMT Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> Message-ID: <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Aug 2012 17:54:40 -0700, Paul Rubin wrote: > John Ladasky writes: [...] >> If the length of the list L is odd, I want to process it once. If >> len(L) is even, I want to process it twice.... >> for x in range(1 + not(len(L) % 2)): > > If you really have to do something like that, I'd say > > for x in range(1 + (len(L) & 1)): [snip] I'd simplify it even more: for x in (0,) if len(L)%2 else (0, 1): ... which is even more explicit and simpler to read even though it is longer. -- Steven From roy at panix.com Sun Aug 12 07:40:30 2012 From: roy at panix.com (Roy Smith) Date: Sun, 12 Aug 2012 07:40:30 -0400 Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <502791ea$0$29978$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > for x in (0,) if len(L)%2 else (0, 1): > ... > > which is even more explicit and simpler to read even though it is longer. Ugh. do_stuff() if len(L) % 2 == 0: do_stuff() # reprocess even-length list Sure, it's 3 lines instead of one, but dead-obvious what the intention is. I might even go for: if len(L) % 2: do_stuff() else: do_stuff() do_stuff() There's two problems with all the looping suggestions people have given. One is that the computation of whether you need to do it once or twice is messy. But, but bigger issue is you're trying to warp what's fundamentally a boolean value into a looping construct. That's a cognitive mismatch. From giacomo.alzetta at gmail.com Sun Aug 12 07:55:19 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sun, 12 Aug 2012 04:55:19 -0700 (PDT) Subject: in-place exponentiation incongruities In-Reply-To: <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> Il giorno domenica 12 agosto 2012 13:03:08 UTC+2, Steven D'Aprano ha scritto: > On Sun, 12 Aug 2012 00:14:27 -0700, Giacomo Alzetta wrote: > > > > > From The Number Protocol(http://docs.python.org/c-api/number.html). The > > > full text is: > > > > > > PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject > > > *o3) > > > Return value: New reference. > > > > > > **See the built-in function pow().** Returns NULL on failure. The > > > operation is done in-place when o1 supports it. This is the > > > equivalent of the Python statement o1 **= o2 when o3 is Py_None, or > > > an in-place variant of pow(o1, o2, o3) otherwise. If o3 is to be > > > ignored, pass Py_None in its place (passing NULL for o3 would cause > > > an illegal memory access). > > > > > > The first thing that this text does is referring to the **function** > > > pow, which takes three arguments. And since the documentation of the > > > operator module states that "The operator module exports a set of > > > efficient functions corresponding to the intrinsic operators of > > > Python.", I'd expect the ipow to have three arguments, the third being > > > optional. > > > > Why? There is no three-argument operator. There is a three-argument > > function, pow, but you don't need the operator module for that, it is > > built-in. There is no in-place three-argument operator, and no in-place > > three-argument function in the operator module. > > > > Arguing from "consistency" is not going to get you very far, since it is > > already consistent: > > > > In-place binary operator: **= > > In-place binary function: operator.ipow > > > > In-place three-argument operator: none > > In-place three-argument function: none > > > > If you decide to make a feature-request, you need to argue from > > usefulness, not consistency. > > > > http://bugs.python.org > > > > Remember that the Python 2.x branch is now in feature-freeze, so new > > features only apply to Python 3.x. > > > > > > > With normal exponentiation you have ** referring to the 2-argument > > > variant, and "pow" providing the ability to use the third argument. > > > > Correct. > > > > > > > At the moment in-place exponentiation you have "**=" referring to the > > > 2-argument variant(and this is consistent), while operator.ipow also > > > referring to it. > > > > Correct. Both **= and ipow match the ** operator, which only takes two > > arguments. > > > > > > > So providing an ipow with the third argument would just > > > increase consistency in the language, > > > > Consistency with something other than **= would be inconsistency. > > > > > > > > > and provide a feature that at the > > > moment is not present. (well if the designers of python care really much > > > about consistency they'd probably add an "ipow" built-in function, so > > > that you don't have to import it from "operator"). > > > > Not everything needs to be a built-in function. > > > > > > > > -- > > Steven Probably I've mixed things up. What I mean is: when you implement a new type as a C extension you have to provide special methods through the NumberMethods struct. In this struct both the power and in-place power operations have three arguments. Now, suppose I implement the three argument variant of the in-place power in a class. No user would be able to call my C function with a non-None third argument, while he would be able to call the normal version with the third argument. This is what I find inconsistent. either provide a way to call also the in-place exponentiation with three arguments, or define it as a binary function. Having it as a ternary function, but only from the C-side is quite strange. From dihedral88888 at googlemail.com Sun Aug 12 07:59:53 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 12 Aug 2012 04:59:53 -0700 (PDT) Subject: save dictionary to a file without brackets. In-Reply-To: <5026416d$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> <5026416d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano? 2012?8?11????UTC+8??7?26?37???? > On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote: > > > > > On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel wrote: > > >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: > > >>> O(n) for all other entries in the dict which suffer a hash collision > > >>> with the searched entry. > > >>> > > >>> True, a sensible choice of hash function will reduce n to 1 in common > > >>> cases, but it becomes an important consideration for larger datasets. > > >> > > >> I'm glad you're wrong for CPython's dictionaries. The only time the > > >> lookup would degenerate to O[n] would be if the hash table had only one > > >> slot. CPython sensibly increases the hash table size when it becomes > > >> too small for efficiency. > > >> > > >> Where have you seen dictionaries so poorly implemented? > > > > > > In vanilla CPython up to version (I think) 3.3, where it's possible to > > > DoS the hash generator. Hash collisions are always possible, just > > > ridiculously unlikely unless deliberately exploited. > > > > Not so unlikely actually. > > > > py> hash(3) > > 3 > > py> hash(2**64 + 2) > > 3 > > > > py> hash(-1) > > -2 > > py> hash(-2) > > -2 > > > > > > By its very nature, a hash function cannot fail to have collisions. The > > problem is that in general you have an essentially unlimited number of > > objects being mapped to a large but still finite number of hash values. > > > > > > > > -- > > Steven Steven D'Aprano? 2012?8?11????UTC+8??7?26?37???? > On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote: > > > > > On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel wrote: > > >> On 08/09/2012 06:03 PM, Andrew Cooper wrote: > > >>> O(n) for all other entries in the dict which suffer a hash collision > > >>> with the searched entry. > > >>> > > >>> True, a sensible choice of hash function will reduce n to 1 in common > > >>> cases, but it becomes an important consideration for larger datasets. > > >> > > >> I'm glad you're wrong for CPython's dictionaries. The only time the > > >> lookup would degenerate to O[n] would be if the hash table had only one > > >> slot. CPython sensibly increases the hash table size when it becomes > > >> too small for efficiency. > > >> > > >> Where have you seen dictionaries so poorly implemented? > > > > > > In vanilla CPython up to version (I think) 3.3, where it's possible to > > > DoS the hash generator. Hash collisions are always possible, just > > > ridiculously unlikely unless deliberately exploited. > > > > Not so unlikely actually. > > > > py> hash(3) > > 3 > > py> hash(2**64 + 2) > > 3 > > > > py> hash(-1) > > -2 > > py> hash(-2) > > -2 > > > > > > By its very nature, a hash function cannot fail to have collisions. The > > problem is that in general you have an essentially unlimited number of > > objects being mapped to a large but still finite number of hash values. > > > > > > > > -- > > Steven Lets check the basic operations of a hash table or so-called a dictionary first. If the dictionary is implemented toward faster in searching items, then it is slightly different in the insertion and the deletion operations of (key, value) pairs. From steve+comp.lang.python at pearwood.info Sun Aug 12 10:06:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Aug 2012 14:06:10 GMT Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Aug 2012 07:40:30 -0400, Roy Smith wrote: > In article <502791ea$0$29978$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> for x in (0,) if len(L)%2 else (0, 1): >> ... >> >> which is even more explicit and simpler to read even though it is >> longer. > > Ugh. > > do_stuff() > if len(L) % 2 == 0: > do_stuff() # reprocess even-length list > > Sure, it's 3 lines instead of one, but dead-obvious what the intention > is. Well, sure, for that specific case that would work too. Using a for-loop to do something once is a little icky. But only a little. Also, it scales to situations like "repeat 37 times when even, or 82 times when odd" (or any other values). > There's two problems with all the looping suggestions people have given. > One is that the computation of whether you need to do it once or twice > is messy. But, but bigger issue is you're trying to warp what's > fundamentally a boolean value into a looping construct. That's a > cognitive mismatch. Really? You've never used a while loop? while not finished: do_something() There's nothing wrong with having a for-loop which iterates over a computed set of values: if len(L)%2: items = range(len(L)//2 + 1) else: items = range(len(L)//2) for x in items: ... which can be simplified to: for x in range(len(L)//2 + len(L)%2): ... -- Steven From georg at python.org Sun Aug 12 11:01:36 2012 From: georg at python.org (Georg Brandl) Date: Sun, 12 Aug 2012 17:01:36 +0200 Subject: [RELEASED] Python 3.3.0 beta 2 Message-ID: <5027C550.6070700@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second beta release of Python 3.3.0 -- a little later than originally scheduled, but much better for it. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlAnxVAACgkQN9GcIYhpnLAECACcDeE+N2AfYVnuwMkq682znfDU ODAAn0J87+MVA9WHEV5iYZd3ub9ZhbpC =LvY0 -----END PGP SIGNATURE----- From no.email at nospam.invalid Sun Aug 12 12:59:54 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Aug 2012 09:59:54 -0700 Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x393sxcz9.fsf@ruckus.brouhaha.com> > which can be simplified to: > for x in range(len(L)//2 + len(L)%2): for x in range(sum(divmod(len(L), 2))): ... From Bernd.Nawothnig at t-online.de Sun Aug 12 13:21:06 2012 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sun, 12 Aug 2012 19:21:06 +0200 Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x393sxcz9.fsf@ruckus.brouhaha.com> Message-ID: <295lf9-aga.ln1@bernd.nawothnig.dialin.t-online.de> On 2012-08-12, Paul Rubin wrote: >> which can be simplified to: >> for x in range(len(L)//2 + len(L)%2): > > for x in range(sum(divmod(len(L), 2))): ... nice solution. Bernd -- "Die Antisemiten vergeben es den Juden nicht, dass die Juden Geist haben - und Geld." [Friedrich Nietzsche] From breamoreboy at yahoo.co.uk Sun Aug 12 14:20:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 12 Aug 2012 19:20:26 +0100 Subject: Arithmetic with Boolean values In-Reply-To: <7x393sxcz9.fsf@ruckus.brouhaha.com> References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x393sxcz9.fsf@ruckus.brouhaha.com> Message-ID: On 12/08/2012 17:59, Paul Rubin wrote: >> which can be simplified to: >> for x in range(len(L)//2 + len(L)%2): > > for x in range(sum(divmod(len(L), 2))): ... > So who's going to be first in with "and thou shalt not count to 4..."? -- Cheers. Mark Lawrence. From roy at panix.com Sun Aug 12 14:45:12 2012 From: roy at panix.com (Roy Smith) Date: Sun, 12 Aug 2012 14:45:12 -0400 Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x393sxcz9.fsf@ruckus.brouhaha.com> Message-ID: In article , Mark Lawrence wrote: > On 12/08/2012 17:59, Paul Rubin wrote: > >> which can be simplified to: > >> for x in range(len(L)//2 + len(L)%2): > > > > for x in range(sum(divmod(len(L), 2))): ... > > > > So who's going to be first in with "and thou shalt not count to 4..."? You, apparently. From t at jollybox.de Sun Aug 12 15:05:24 2012 From: t at jollybox.de (Thomas Jollans) Date: Sun, 12 Aug 2012 21:05:24 +0200 Subject: suggesting a launcher wrapper script for portable python In-Reply-To: References: Message-ID: <5027FE74.6030806@jollybox.de> On 08/12/2012 02:49 AM, Gelonida N wrote: > > One minor drawback of my suggested script would be, that a console > window pops up for a few seconds when starting a .pyw file. (I'm no expert but) This should be avoidable if you use the Windows Script Host instead of DOS command scripts to write the launchers. I.e. use JScript or VBScript to do exactly the same thing. I don't know much about Windows shortcut (*.lnk) files; if they can contain relative paths, you could just create shortcuts that launch portable python with the script. Thomas From agonh at freenet.de Sun Aug 12 15:45:49 2012 From: agonh at freenet.de (Agon Hajdari) Date: Sun, 12 Aug 2012 19:45:49 +0000 (UTC) Subject: lpod-python References: Message-ID: On Fri, 10 Aug 2012 19:37:16 +0200, Francesco wrote: > I'm trying to use the lpod-python module to programmatically read data > from Open Document files. My problem is: i can't download the module > from its authors' site, > http://download.lpod-project.org/lpod-python/lpod-python-0.9.3.tar.gz. > It seems the download site is unavailable, while the main site is > working. > I also tried to install the module with pip (I read on the site that > it's now available), but again, no luck. > Do somebody know what's happening to download.lpod-project.org ? It > doesn't even ping... > > Please let me know, thank you very much. > Francesco It seems that they are hosting their project at gitorious.org via git. Try this: git clone git://gitorious.org/lpod-project/lpod-python.git (u need the git client of course) Agon From breamoreboy at yahoo.co.uk Sun Aug 12 15:52:54 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 12 Aug 2012 20:52:54 +0100 Subject: suggesting a launcher wrapper script for portable python In-Reply-To: References: Message-ID: On 12/08/2012 01:49, Gelonida N wrote: > I just started looking at portable Python and was rather surprised, that > I didn't find any recommended method in the documentation of how to > launch scripts with portable python. > Creating py2exe scripts on ones own USB drive seems to be kind of overkill. > > So here my own thoughts / suggestsions. > I'm interestted in feedback of how others use portable pythons > and how they run their scripts from a USB stick. > > > Let's assume I install portable python on my USB drive and then I'd like > to store self written python scripts on this drive. > > It would of course be greate if I could just click on the script and > they'd be started. > > > However under windows this would not be the case. > The python script would either not be started at all or if the PC had > his own python installed, then the script would be started with the PC's > version of python. > > Thus a tiny wrapper script would be needed. > > > Suggestion: > -------------- > The current directory structore for portable python (2.7) is (assuming > that %PP% is the base directory) > > %PP%/Python-Portable.exe # launches the python interactive shell > %PP%/PyScripter-Portable.exe # launches some IDE > %PP%/App > > Let's assume I add two more directories: > %PP%/myscripts # location of all callable scripts > %PP%/launchers # location with icons one can click on > # to start the scripts in myscripts > > > > > if I wrote a script named %PP%/myscripts/test1.py, > and I created an aproprriate named %PP%/launchers/test1.bat > > then I could just click on test1.bat and the Python script test1.py > would be started. If the wrapper script is written properly, then it can > look at its own base name and call the related python script. > > If I dragged and dropped some filenames on the bat file, then they would > be passed to sys.argv of the script. > > Running the script from command line would also work and the present > working directory would be preserved (which might be useful in some cases) > > If the script name would not be .py, but .pyw then it woudl be started > with pythonw. > T > > Below suggested script: > > > > @echo off > REM > ========================================================================= > REM script to start a python file with portable python > REM > ========================================================================= > > REM basepath of this .bat file > set basepath=%~dp0 > > REM create the name of the python file related to this bat file > REM Unfortunately I do not know how to normalyze %pyfile%, > REM so we got stuck with the '..' > set pyfile=%basepath%..\myscripts\%~n0.py > > If EXIST "%pyfile%" ( > REM a normal console python file with .py suffix > "%basepath%\..\App\python.exe" "%pyfile%" %* > ) ELSE ( > If EXIST "%pyfile%w" ( > REM a non console python file with .pyw suffix > start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w" %* > ) ELSE ( > REM found neither a .py nor a .pyw file > echo found no python file %pyfile% > ) > ) > REM > ========================================================================= > REM end of script > REM > ========================================================================= > > > One minor drawback of my suggested script would be, that a console > window pops up for a few seconds when starting a .pyw file. > > This could be avoided by using either a small compiled C-file (which > sounds like overkill though) > or by writing a windows scripting host .wsf file. > However I don't know this well enough to replicate my batch file. > AN article on SO mentions how to write such a script. > However it does not parse command line arguments nor does it > automatically determine the scripts file name. > So any help for creating a .wsf file starting a .pyw file with command > line arguments would be appreciated. > > > > An alternativce approach could be to provide a scipt named > mk_wrapper.bat > If one drags and drops a python script on it, then an apropriate wrapper > file would be created in the launcher directory. > > If well done, then this could be implemented such, that the script may > be located in an arbitrary location on the same USB drive. > > > > I think it would be great if the official portable python release > contained some upport for launching scripts. > Perhaps it exists alrady and I just didn't find it? > > If not,then I wouldn't mind if my script or a similiar sand a related > README.txt cript were added to the official release > This might be a complete waste of time but can you use the new windows launcher described here http://www.python.org/dev/peps/pep-0397/ ??? -- Cheers. Mark Lawrence. From alister.ware at ntlworld.com Sun Aug 12 16:13:20 2012 From: alister.ware at ntlworld.com (Alister) Date: Sun, 12 Aug 2012 20:13:20 GMT Subject: Arithmetic with Boolean values References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x393sxcz9.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 12 Aug 2012 19:20:26 +0100, Mark Lawrence wrote: > On 12/08/2012 17:59, Paul Rubin wrote: >>> which can be simplified to: >>> for x in range(len(L)//2 + len(L)%2): >> >> for x in range(sum(divmod(len(L), 2))): ... >> >> > So who's going to be first in with "and thou shalt not count to 4..."? Five is right out -- Insanity is the final defense ... It's hard to get a refund when the salesman is sniffing your crotch and baying at the moon. From nospam at nospam.com Sun Aug 12 16:52:07 2012 From: nospam at nospam.com (Gilles) Date: Sun, 12 Aug 2012 22:52:07 +0200 Subject: Running Python web apps on shared ASO servers? References: Message-ID: <4i5g2890hj3d1tuqe21o0dssh39tair3s2@4ax.com> On Sun, 12 Aug 2012 07:56:26 +0200, Dieter Maurer wrote: >You should probably read the mentioned forum resources to learn >details about the Python support provided by your web site hoster. Yup, but so far, no answer, so I figured someone here might now. Those articles seem to indicate that CGI isn't a good solution when mod_python isn't available, so it looks like I'll have to investigate FastCGI, WSGI, etc. http://docs.python.org/howto/webservers.html http://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together Thank you. From mail at timgolden.me.uk Sun Aug 12 17:26:19 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 12 Aug 2012 22:26:19 +0100 Subject: Running Python web apps on shared ASO servers? In-Reply-To: <4i5g2890hj3d1tuqe21o0dssh39tair3s2@4ax.com> References: <4i5g2890hj3d1tuqe21o0dssh39tair3s2@4ax.com> Message-ID: <50281F7B.8020906@timgolden.me.uk> On 12/08/2012 21:52, Gilles wrote: > On Sun, 12 Aug 2012 07:56:26 +0200, Dieter Maurer > wrote: >> You should probably read the mentioned forum resources to learn >> details about the Python support provided by your web site hoster. > > Yup, but so far, no answer, so I figured someone here might now. > > Those articles seem to indicate that CGI isn't a good solution when > mod_python isn't available Just to make a point: one person's "isn't a good solution" is another person's "works perfectly well for me". Modern servers are really quite quick: the cost of starting up a Python process and generating an HTML page can be really quite low. I've certainly had low-traffic production websites running for years on CGI without anyone complaining. If speed was an issue or if I thought that I'd be getting more requests than I am then I'd consider a more sophisticated solution. TJG From tjreedy at udel.edu Sun Aug 12 17:53:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 12 Aug 2012 17:53:46 -0400 Subject: in-place exponentiation incongruities In-Reply-To: <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> Message-ID: On 8/12/2012 7:55 AM, Giacomo Alzetta wrote: > What I mean is: when you implement a new type as a C extension you > have to provide special methods through the NumberMethods struct. In > this struct both the power and in-place power operations have three > arguments. I am not really sure why the latter is true. Probably 'consistency' at the special method level, with __pow__. As Steven points out, it is not needed to implement normal Python code. This is one area of Python where the design is a bit messy. I believe the very existence of __ipow__ is a matter of consistency than of known use cases. Guido was not sure which __ixxx__ would ever be needed (for mutable objects), so he just put them all in. At the Python level, both __pow__ and __ipow__ are also documented in the manual as having an optional, third, modulo parameter. __rpow__ is defined as binary, but that is a mistake >>> int.__rpow__(3, 5, 4) 1 > Now, suppose I implement the three argument variant of the > in-place power in a class. Are you actually planning to do this, or is this purely theoretical? > No user would be able to call my C > function with a non-None third argument, Not true. Whether the function is coded in Python or C cls.__ipow__(base, exp, mod) # or base.__ipow__(exp, mod) > while he would be able to > call the normal version with the third argument. That can also be done directly >>> int.__pow__(5, 3, 4) 1 -- Terry Jan Reedy From gelonida at gmail.com Sun Aug 12 19:02:33 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 13 Aug 2012 01:02:33 +0200 Subject: suggesting a launcher wrapper script for portable python In-Reply-To: <5027FE74.6030806@jollybox.de> References: <5027FE74.6030806@jollybox.de> Message-ID: Hi Thomas, On 08/12/2012 09:05 PM, Thomas Jollans wrote: > On 08/12/2012 02:49 AM, Gelonida N wrote: >> >> One minor drawback of my suggested script would be, that a console >> window pops up for a few seconds when starting a .pyw file. > > (I'm no expert but) This should be avoidable if you use the Windows > Script Host instead of DOS command scripts to write the launchers. > I.e. use JScript or VBScript to do exactly the same thing. I don't know > much about Windows shortcut (*.lnk) files; if they can contain relative > paths, you could just create shortcuts that launch portable python with > the script. > You're absolutely right and I was rather sure, that I posted a link to an SO article with a wsf script avoiding this problem. Only drawback of this script was, that it did not detect the name of it's own script and that it did not pass command line arguments down to the python script. Well here is the link: http://preview.tinyurl.com/bu9rda5 The suggested script was: The question is how to extend it such, that it detects it's own name (nice to have) and that it passes command line args down to python (essential) I know absolutely nothing about windows scripting. > > From gelonida at gmail.com Sun Aug 12 19:05:59 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 13 Aug 2012 01:05:59 +0200 Subject: suggesting a launcher wrapper script for portable python In-Reply-To: References: Message-ID: On 08/12/2012 09:52 PM, Mark Lawrence wrote: > On 12/08/2012 01:49, Gelonida N wrote: >> >> >> >> I think it would be great if the official portable python release >> contained some upport for launching scripts. >> Perhaps it exists alrady and I just didn't find it? >> >> If not,then I wouldn't mind if my script or a similiar sand a related >> README.txt cript were added to the official release >> > > This might be a complete waste of time but can you use the new windows > launcher described here http://www.python.org/dev/peps/pep-0397/ ??? > > This might be interesting and I have to read a little more. However on a very first glance I'd assume it had to be stalled on the PC, so it would not really be a portable solution (meaning self contained on a USB key),that can be executed on any WIndows host. From no.email at please.post Sun Aug 12 19:06:19 2012 From: no.email at please.post (kj) Date: Sun, 12 Aug 2012 23:06:19 +0000 (UTC) Subject: Official reason for omitting inspect.currentcallable() ? Message-ID: Is there an *explicitly stated* reason (e.g. in a PEP, or in some python dev list message) for why the inspect module (at least for Python 2.7) does not include anything like a "currentcallable()" function that would *stably*[1] return the currently executing callable object? (It seems unlikely that the absence in the inspect module of anything even remotely like such a currentcallable is merely an oversight, considering how many introspection facilities the inspect module provides. It seems far more likely that this absence is either due to some fundamental limitation of Python that makes it impossible to fully specify such a function, or it is the result of a deliberate policy against including such a function in inspect.) Thanks! [1] By "stably" above I mean, e.g., that the value returned by the top-level function (object) defined by def spam(): return inspect.currentcallable() is *invariant*, in contrast to the value returned by the top-level function (object) defined by def ham(): return ham which is whatever the current value of the 'ham' global happens to be. From james.pye at gmail.com Sun Aug 12 19:07:14 2012 From: james.pye at gmail.com (jwp) Date: Sun, 12 Aug 2012 16:07:14 -0700 (PDT) Subject: ANN: visage (interfaces) In-Reply-To: <0ac6c039-9cad-4cef-86d8-25e597996225@googlegroups.com> References: <0ac6c039-9cad-4cef-86d8-25e597996225@googlegroups.com> Message-ID: <2986a837-65a4-4590-9c52-6abd1712448a@googlegroups.com> On Sunday, July 29, 2012 10:18:23 PM UTC-7, jwp wrote: > What's c.l.py's perspective on managing interfaces and implementations? I pushed another version with support for IID references, so you can refer to implementations in annotations. The ultimate point of this is to give registry queries the ability to check for implementations with particular features: @visage.lib.implementation('foo') class Imp(object): def meth(self) -> visage.lib.reference('bar'): ... Imp.meth making a statement that a 'bar' implementation will be returned. That is, consider code that is not aware of the modules that "Imp" is stored in but wants a 'foo' implementation whose "meth" method returns a 'bar' instance. Registry queries pave the way for supporting IID based implementation resolution. There is also the potential that registry information could be extracted on package installation for the purpose of an implementation index. Implementations could be imported on demand by modules that have no knowledge of the implementation. From wuwei23 at gmail.com Sun Aug 12 20:12:59 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 12 Aug 2012 17:12:59 -0700 (PDT) Subject: Does anyone have an activate script for portable python? References: Message-ID: On Aug 12, 9:09?am, Gelonida N wrote: > In Pythons installed with virtualenv there is on windows an activate.bat > script, that can be used to setup the cmd-shell such, that the search > path for python and pythor elated tools (pip / easy_install) is setup > properly. > Do such a scripts also exist for Portable python? Portable Python is just Python with some helper scripts for not requiring a system installation. So "command-line-command-to-run-portable-python virtualenv " should be all you need. From wuwei23 at gmail.com Sun Aug 12 20:15:12 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 12 Aug 2012 17:15:12 -0700 (PDT) Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> On Aug 10, 7:37?pm, Mark Lawrence wrote: > Well whatever you do *DON'T* mention Cython. I mentioned it just now but > I think I've got away with it. While I'm not against threads straying off topic, you're beginning to come across as a bit of an asshole now. Just let it go. From gheskett at wdtv.com Sun Aug 12 20:29:16 2012 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 12 Aug 2012 20:29:16 -0400 Subject: Arithmetic with Boolean values In-Reply-To: References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> Message-ID: <201208122029.17032.gheskett@wdtv.com> On Sunday 12 August 2012 20:27:13 Alister did opine: > On Sun, 12 Aug 2012 19:20:26 +0100, Mark Lawrence wrote: > > On 12/08/2012 17:59, Paul Rubin wrote: > >>> which can be simplified to: > >> > >>> for x in range(len(L)//2 + len(L)%2): > >> for x in range(sum(divmod(len(L), 2))): ... > > > > So who's going to be first in with "and thou shalt not count to 4..."? > > Five is right out Can some smart ass (like me) suggest 69! If it doesn't get summarily tossed, it could take a week or so to run. :-) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! e-credibility: the non-guaranteeable likelihood that the electronic data you're seeing is genuine rather than somebody's made-up crap. -- Karl Lehenbauer From richard at pyweek.org Sun Aug 12 21:28:17 2012 From: richard at pyweek.org (Richard Jones) Date: Mon, 13 Aug 2012 11:28:17 +1000 Subject: Python Game Programming Challenge (PyWeek) #15 is coming! Message-ID: The 15th Python Game Programming Challenge (PyWeek) is coming. It'll run from the 9th to the 16th of September: http://pyweek.org/ The PyWeek challenge: 1. Invites entrants to write a game in one week from scratch either as an individual or in a team, 2. Is intended to be challenging and fun, 3. Will increase the public body of game tools, code and expertise, 4. Will let a lot of people actually finish a game, and 5. May inspire new projects (with ready made teams!) Check out the help page for how to compete and the growing resources message board post: http://pyweek.org/s/help/ http://pyweek.org/d/4008/ Richard From tjreedy at udel.edu Mon Aug 13 01:15:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Aug 2012 01:15:39 -0400 Subject: Official reason for omitting inspect.currentcallable() ? In-Reply-To: References: Message-ID: On 8/12/2012 7:06 PM, kj wrote: > > > Is there an *explicitly stated* reason (e.g. in a PEP, or in some > python dev list message) for why the inspect module (at least for > Python 2.7) 2.7 is over two years old. Things have been added to the inspect module since. So when asking about 'why feature x is not present', you should be asking about 3.3. Enhancement requests should be directed to 3.4. > does not include anything like a "currentcallable()" 3.x include currentframe() (see below), though it is not guaranteed for anything other than CPython. 2.x and 3.x have more general functions to get the entire call stack. Details are certainly implementation specific. > function that would *stably*[1] return the currently executing > callable object? The concepts 'callable' and 'executable' are not the same. Callables have a .__call__ method that initiates the execution of an executable. Python-coded functions have a __call__ method that knows how to initiate the execution of the attached (byte)code object that was compiled from the Python code. C-coded function wrappers have a __call__ method that knows how to initiate the execution of object code compiled from C functions. Other implementations have other __call__ methods. Once the executable is executing, there is no need for the function and its call method. So getting the current callable has to be indirect frame to code object to name to function object looked up in the parent calling frame. A direct link would create an unnecessary circular reference. > [1] By "stably" above I mean, e.g., that the value returned by the > top-level function (object) defined by > > def spam(): > return inspect.currentcallable() > > is *invariant*, in contrast to the value returned by the top-level > function (object) defined by There have been various proposals and a rejected PEP for accessing 'this function' from within a function. I do not know if that particular spelling has been proposed or not. > def ham(): > return ham > > which is whatever the current value of the 'ham' global happens to > be. if the def statement is in global scope. There is no difference unless someone rebind the name, which is normally done intentionally, for a purpose. Names do not just randomly mutate. The advantage of access by name is that if someone, whether the original author or not, wraps the function (say to log calls), then the function continues to work with the wrapped version. -- Terry Jan Reedy From asif.jamadar at rezayat.net Mon Aug 13 02:54:51 2012 From: asif.jamadar at rezayat.net (Asif Jamadar) Date: Mon, 13 Aug 2012 06:54:51 +0000 Subject: combine modelformset and inlineformset in django views Message-ID: I have two models class A(models.Model): name = models.CharField(50) type = models.CharField(50) class B(models.Model): field1 = ForeignKeyField(A) value = IntegerField() I need to generate both formsets and inline formsets using the above models. For class A I will generate model formset, but i'm not getting how to bind inline formset for model B to modelformsets How can I combine both modelformsets from model A and inline formsets from model A and model B on save method in django views? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jussij at zeusedit.com Mon Aug 13 03:11:06 2012 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Mon, 13 Aug 2012 00:11:06 -0700 (PDT) Subject: Idle no longer works In-Reply-To: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> References: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> Message-ID: <6ab35ebc-8069-4f07-9ce9-f591bd7163e2@googlegroups.com> On Saturday, August 11, 2012 4:09:16 PM UTC-7, Opap-OJ wrote: > I can no longer open the Idle IDE for Python on Windows 7. > .. > Any idea why? It looks like your registry has changed. To fix this just use the Windows Explorer, click on a Python file and use the 'Open with, Choose default program' menu and then select the Idle IDE as the default program. From ulrich.eckhardt at dominolaser.com Mon Aug 13 03:15:53 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 13 Aug 2012 09:15:53 +0200 Subject: Threads and sockets In-Reply-To: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> References: <775f30ad-1f04-4653-95c4-b0dfdd27ca49@googlegroups.com> Message-ID: <96mmf9-7t.ln1@satorlaser.homedns.org> Am 10.08.2012 15:01, schrieb loial: > I am writing an application to send data to a printer port(9100) and > then recieve PJL responses back on that port. Because of the way PJL > works I have to do both in the same process(script). If I understand that right, you are opening a TCP connection, so obviously this must be done in the same process, regardless of what PJL (whatever that exactly is) does. > At the moment I do not start to read responses until the data has > been sent to the printer. However it seems I am missing some > responses from the printer whilst sending the data, so I need to be > able to do the 2 things at the same time. Using TCP, that shouldn't happen, so I really wonder what exactly you are doing here. > Can I open a port once and then use 2 different threads, one to write > to the post and one to read the responses)? Yes, definitely, take a look at the select() function of the select module. This basically looks like this: (r, w, x) = select(...) if r: # read and handle incoming data ... if w: # write pending output data ... if x: # handle connection failure ... If all this is not what you are doing and what you want (which I'm not 100% sure of) then please elaborate a bit what you're doing and what kind of connection you are using. Happy hacking! Uli From steve+comp.lang.python at pearwood.info Mon Aug 13 04:05:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Aug 2012 08:05:34 GMT Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> Message-ID: <5028b54e$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Aug 2012 17:15:12 -0700, alex23 wrote: > On Aug 10, 7:37?pm, Mark Lawrence wrote: >> Well whatever you do *DON'T* mention Cython. I mentioned it just now >> but I think I've got away with it. > > While I'm not against threads straying off topic, you're beginning to > come across as a bit of an asshole now. > > Just let it go. Chill out Alex, it's all good. Mark was channelling a famous scene from "Fawlty Towers", staring Monty Python's own John Cleese, hence it is on- topic, for the sillier definitions of on-topic. After making a German tourist cry with his repeated insensitive comments about World War Two, Basil Fawlty (Cleese) -- who is an obnoxious git at the best of times but is currently suffering from a concussion -- remarks to his staff, "Don't mention the war, I mentioned it once but I think I got away with it." http://www.youtube.com/watch?v=7xnNhzgcWTk -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 13 04:24:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Aug 2012 08:24:46 GMT Subject: Official reason for omitting inspect.currentcallable() ? References: Message-ID: <5028b9ce$0$29867$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Aug 2012 23:06:19 +0000, kj wrote: > Is there an *explicitly stated* reason (e.g. in a PEP, or in some python > dev list message) for why the inspect module (at least for Python 2.7) > does not include anything like a "currentcallable()" function that would > *stably*[1] return the currently executing callable object? I doubt it. Should there be? "currentcallable" is not a standard function in any language I'm familiar with, although I may be missing something obvious. -- Steven From chris at simplistix.co.uk Mon Aug 13 04:26:24 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Aug 2012 09:26:24 +0100 Subject: testfixtures 2.3.5 Released! Message-ID: <5028BA30.80104@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 2.3.5. testfixtures is a collection of helpers for writing succinct unit tests including help for: - Comparing objects and sequences Better feedback when the results aren't as you expected along with support for comparison of objects that don't normally support comparison. - Mocking out objects and methods Easy to use ways of stubbing out objects, classes or individual methods for both doc tests and unit tests. Special helpers are provided for testing with dates and times. - Testing logging Helpers for capturing logging output in both doc tests and unit tests. - Testing stream output Helpers for capturing stream output, such as that from print statements, and making assertion about it. - Testing with files and directories Support for creating and checking files and directories in sandboxes for both doc tests and unit tests. - Testing exceptions Easy to use ways of checking that a certain exception is raised, even down the to the parameters the exception is raised with. This release fixes a small bug that meant failures in dictionary comparison didn't always produce the same output. (It was correct, just partly unsorted) 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 Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Mon Aug 13 04:51:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Aug 2012 18:51:40 +1000 Subject: Official reason for omitting inspect.currentcallable() ? In-Reply-To: <5028b9ce$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <5028b9ce$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 13, 2012 at 6:24 PM, Steven D'Aprano wrote: > On Sun, 12 Aug 2012 23:06:19 +0000, kj wrote: > >> Is there an *explicitly stated* reason (e.g. in a PEP, or in some python >> dev list message) for why the inspect module (at least for Python 2.7) >> does not include anything like a "currentcallable()" function that would >> *stably*[1] return the currently executing callable object? > > I doubt it. Should there be? "currentcallable" is not a standard function > in any language I'm familiar with, although I may be missing something > obvious. I'm not familiar with it by that name, but Pike's this_function is what the OP's describing. (Yes, I'm citing Pike again. Sorry.) It's a useful construct in theory when you want to write in recursion, which was part of the rationale behind PEP 3130 (btw, Terry, it would have been nice if you'd mentioned the number instead of sending me to the index to try to figure out which one you were referring to, but anyway). But how often is it actually useful in practice? I've never actually used this_function other than in writing a crazy recursive lambda (was testing different languages' handling of infinite recursion - high level languages shouldn't segfault, one much-maligned language DOES). ChrisA From rt5 at bk.ru Mon Aug 13 06:18:49 2012 From: rt5 at bk.ru (Xantipius) Date: Mon, 13 Aug 2012 03:18:49 -0700 (PDT) Subject: How to uncompress a VOB file? (Win XP) Message-ID: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> subj From noname at nowhere.com Mon Aug 13 06:36:44 2012 From: noname at nowhere.com (Blind Anagram) Date: Mon, 13 Aug 2012 11:36:44 +0100 Subject: Threading KeyError in Python 3.3 beta 2? Message-ID: I thought I would try out Python 3.3 beta 2. This works well so far but I keep getting the message: Exception KeyError: KeyError(6308,) in ignored after some of my python code completes. Is this an issue worth reporting? From steve+comp.lang.python at pearwood.info Mon Aug 13 06:52:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Aug 2012 10:52:35 GMT Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: <5028dc73$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 03:18:49 -0700, Xantipius wrote: > subj The same way as you compressed it, only in reverse. When you ask a sensible question, I'm sure that somebody will give you a sensible answer. -- Steven From rosuav at gmail.com Mon Aug 13 07:13:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Aug 2012 21:13:24 +1000 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: References: Message-ID: On Mon, Aug 13, 2012 at 8:36 PM, Blind Anagram wrote: > I thought I would try out Python 3.3 beta 2. > This works well so far but I keep getting the message: > > Exception KeyError: KeyError(6308,) in 'c:\\Program Files\\Python33\\lib\\threading.py'> ignored > > after some of my python code completes. > Is this an issue worth reporting? It might be, but it depends on what your code is and is doing. Can you put together a minimal test case? ChrisA From noname at nowhere.com Mon Aug 13 07:24:55 2012 From: noname at nowhere.com (Blind Anagram) Date: Mon, 13 Aug 2012 12:24:55 +0100 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: References: Message-ID: "Chris Angelico" wrote in message news:mailman.3222.1344856408.4697.python-list at python.org... On Mon, Aug 13, 2012 at 8:36 PM, Blind Anagram wrote: > I thought I would try out Python 3.3 beta 2. > This works well so far but I keep getting the message: > > Exception KeyError: KeyError(6308,) in 'c:\\Program Files\\Python33\\lib\\threading.py'> ignored > > after some of my python code completes. > Is this an issue worth reporting? It might be, but it depends on what your code is and is doing. Can you put together a minimal test case? =========== Thank you for your response. Here is a fairly short bit of code which produces the exception: for pre in ('12', '13', '14', '15', '21' ): n = int(pre + '543') s = str(n * n) if len(set(s)) == 9: print(n, s) From nospam at nospam.com Mon Aug 13 07:28:28 2012 From: nospam at nospam.com (Gilles) Date: Mon, 13 Aug 2012 13:28:28 +0200 Subject: Running Python web apps on shared ASO servers? References: <4i5g2890hj3d1tuqe21o0dssh39tair3s2@4ax.com> Message-ID: On Sun, 12 Aug 2012 22:26:19 +0100, Tim Golden wrote: >Just to make a point: one person's "isn't a good solution" is another >person's "works perfectly well for me". Modern servers are really quite >quick: the cost of starting up a Python process and generating an HTML >page can be really quite low. I've certainly had low-traffic production >websites running for years on CGI without anyone complaining. Thanks Tim for the input. I'll try the different solutions available and see if CGI is good enough for my needs. From steve+comp.lang.python at pearwood.info Mon Aug 13 07:38:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Aug 2012 11:38:53 GMT Subject: Threading KeyError in Python 3.3 beta 2? References: Message-ID: <5028e74d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 12:24:55 +0100, Blind Anagram wrote: > Here is a fairly short bit of code which produces the exception: > > for pre in ('12', '13', '14', '15', '21' ): > n = int(pre + '543') > s = str(n * n) > if len(set(s)) == 9: > print(n, s) Um, I don't think so. >>> for pre in ('12', '13', '14', '15', '21' ): ... n = int(pre + '543') ... s = str(n * n) ... if len(set(s)) == 9: ... print(n, s) ... 12543 157326849 Since your code doesn't even import threading, let alone use it, I can't imagine how you get an error in threading. -- Steven From rosuav at gmail.com Mon Aug 13 07:39:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Aug 2012 21:39:13 +1000 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: References: Message-ID: On Mon, Aug 13, 2012 at 9:24 PM, Blind Anagram wrote: > > Here is a fairly short bit of code which produces the exception: > > for pre in ('12', '13', '14', '15', '21' ): > n = int(pre + '543') > s = str(n * n) > if len(set(s)) == 9: > print(n, s) Interesting. I just downloaded a clean 3.3 onto this Windows box, saved your script to a file ("booom.py" hehe), and ran it - no exception. Same thing pasting that code into the interactive interpreter or idle. Did you import anything before running that code? If not, it may be a site.py problem or something. ChrisA From ben+python at benfinney.id.au Mon Aug 13 07:45:59 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 13 Aug 2012 21:45:59 +1000 Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: <87ipcnf214.fsf@benfinney.id.au> Xantipius writes: > subj resp -- \ ?What is needed is not the will to believe but the will to find | `\ out, which is the exact opposite.? ?Bertrand Russell, _Free | _o__) Thought and Official Propaganda_, 1928 | Ben Finney From rosuav at gmail.com Mon Aug 13 07:47:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Aug 2012 21:47:52 +1000 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: <5028e74d$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <5028e74d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 13, 2012 at 9:38 PM, Steven D'Aprano wrote: > Since your code doesn't even import threading, let alone use it, I can't > imagine how you get an error in threading. Hey, I try not to get scornful until at least the sixth post :) ChrisA From noname at nowhere.com Mon Aug 13 07:51:10 2012 From: noname at nowhere.com (Blind Anagram) Date: Mon, 13 Aug 2012 12:51:10 +0100 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: References: Message-ID: "Chris Angelico" wrote in message news:mailman.3223.1344857956.4697.python-list at python.org... On Mon, Aug 13, 2012 at 9:24 PM, Blind Anagram wrote: > > Here is a fairly short bit of code which produces the exception: > > for pre in ('12', '13', '14', '15', '21' ): > n = int(pre + '543') > s = str(n * n) > if len(set(s)) == 9: > print(n, s) Interesting. I just downloaded a clean 3.3 onto this Windows box, saved your script to a file ("booom.py" hehe), and ran it - no exception. Same thing pasting that code into the interactive interpreter or idle. Did you import anything before running that code? If not, it may be a site.py problem or something. =============== Thanks to you both for your responses. Its an IDE issue of some kind (I am using WING). When I run under a command prompt (or IDLE) all is well. Sorry to have bothered you. From strong.drug at gmail.com Mon Aug 13 07:55:20 2012 From: strong.drug at gmail.com (strong.drug at gmail.com) Date: Mon, 13 Aug 2012 04:55:20 -0700 (PDT) Subject: decoding a byte array that is unicode escaped? In-Reply-To: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> References: <77a0e01e-b52c-4576-8078-12a8b6509995@y10g2000prg.googlegroups.com> Message-ID: <2ac73d70-a6a2-405c-a0f2-80ba58b7b82c@googlegroups.com> ???????, 6 ?????? 2009??., 12:48:47 UTC+4 ???????????? sam ???????: > I am simply trying to display this copyright symbol on a webpage, so > how do I encode the byte array to utf-8 given that it is 'escape > encoded' in the above way? I tried: > > responseByteArray.decode('utf-8') > and responseByteArray.decode('unicode_escape') > and str(responseByteArray). > > I am using Python 3.1. I had some problem with reading zip archive in raw (binary) mode. I solve it this way .... open (filename, 'rb').read ().encode('string_escape') # now we had strings with strange symbols are escaped # than we can handle it without decoding excepions for example: body = '\r\n'.join (lines) .... # if we have unescaped strings we can get an exception there # after opertions, we needed we must unescape all content # and drop it out to network (in my case) body = body.decode('string-escape') .... # then we can send so to the server connection.request('POST', upload_url, body, headers) BR) From rosuav at gmail.com Mon Aug 13 07:59:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Aug 2012 21:59:19 +1000 Subject: Threading KeyError in Python 3.3 beta 2? In-Reply-To: References: Message-ID: On Mon, Aug 13, 2012 at 9:51 PM, Blind Anagram wrote: > Thanks to you both for your responses. > > Its an IDE issue of some kind (I am using WING). > > When I run under a command prompt (or IDLE) all is well. Next time, do mention that sort of environmental consideration in the original post :) As a general rule, be careful of threading and windowing toolkits; quite a few of them have restrictions on what you can and can't do, or even completely do not support threads. ChrisA From breamoreboy at yahoo.co.uk Mon Aug 13 08:37:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Aug 2012 13:37:04 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> Message-ID: On 13/08/2012 01:15, alex23 wrote: > On Aug 10, 7:37 pm, Mark Lawrence wrote: >> Well whatever you do *DON'T* mention Cython. I mentioned it just now but >> I think I've got away with it. > > While I'm not against threads straying off topic, you're beginning to > come across as a bit of an asshole now. > > Just let it go. > Why on your say so? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Aug 13 08:40:51 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Aug 2012 13:40:51 +0100 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: On 13/08/2012 11:18, Xantipius wrote: > subj > Either a) write some code and when and if it fails give us a small code snippet that demonstates the problem with the complete traceback. or b) state how much you are willing to pay for someone here to come up with a solution for you. -- Cheers. Mark Lawrence. From python at rgbaz.eu Mon Aug 13 09:42:05 2012 From: python at rgbaz.eu (PythonAB) Date: Mon, 13 Aug 2012 15:42:05 +0200 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: <505805CB-AA1A-4D3B-B35A-BA46CE255326@rgbaz.eu> On 13 aug 2012, at 14:40, Mark Lawrence wrote: > On 13/08/2012 11:18, Xantipius wrote: >> subj >> > > Either > > a) write some code and when and if it fails give us a small code snippet that demonstates the problem with the complete traceback. > > or > > b) state how much you are willing to pay for someone here to come up with a solution for you. > > -- > Cheers. > > Mark Lawrence. > or... go out and buy the DVD it's ripped from... ;) From miki.tebeka at gmail.com Mon Aug 13 10:03:36 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 13 Aug 2012 07:03:36 -0700 (PDT) Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: Have a look at PyMedia. From g.rodola at gmail.com Mon Aug 13 10:06:54 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Mon, 13 Aug 2012 16:06:54 +0200 Subject: ANN: psutil 0.6.0 released Message-ID: Hi folks, I'm pleased to announce the 0.6.0 release of psutil: http://code.google.com/p/psutil/ This is one of the best releases so far as it addresses two important issues: system memory functions management and permission errors occurring on Windows and OSX. === Memory functions === psutil.phymem_usage() and psutil.virtmem_usage() are deprecated. Instead we now have psutil.virtual_memory() and psutil.swap_memory(), which should provide all the necessary pieces to monitor the actual system memory usage, both physical and swap/disk related. The refactoring was modeled after Zabbix, see: http://code.google.com/p/psutil/issues/detail?id=311 http://blog.zabbix.com/when-alexei-isnt-looking/#vm.memory.size http://www.zabbix.com/documentation/2.0/manual/appendix/items/vm.memory.size_params If you don't want to read how and why I did that, the bottom line is: if you want to monitor actual system memory usage in a cross platform fashion use: >>> psutil.virtual_memory().available === No more AccessDenied exceptions when querying processes === On Windows and OSX the Process methods below were always raising AccessDenied for any process owned by another user: OSX - name - get_memory_info() - get_memory_percent() - get_cpu_times() - get_cpu_percent() - get_num_threads() WINDOWS - create_time - get_children() - get_cpu_times() - get_cpu_percent() - get_memory_info() - get_memory_percent() - get_num_handles() - get_io_counters() Especially on OSX this made psutil basically unusable as a limited user, even for determining basic process information such as CPU percent or memory usage. Now this is no longer the case. For further details see: http://code.google.com/p/psutil/issues/detail?id=297 http://code.google.com/p/psutil/issues/detail?id=303 === Other major enhancements === - per-process extended memory stats. - per-process number of voluntary and involuntary context switches. - per-process connections: added UNIX sockets support. - (BSD) Process.get_connections() rewritten in C and no longer requiring lsof. - (OSX) added support for process cwd - psutil.network_io_counters() now provides the number of in/out packets dropped and with errors. - new example scripts: example/meminfo.py example/free.py example/netstat.py example/pmap.py === New features by example === >>> import psutil, os >>> p = psutil.Process(os.getpid()) >>> >>> p.get_num_ctx_switches() amount(voluntary=78, involuntary=19) >>> >>> p.get_ext_memory_info() meminfo(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0) >>> >>> p.get_connections(kind='unix') [connection(fd=8, family=1, type=1, local_address='/tmp/unix_socket.sock', remote_address=None, status='')] >>> >>> >>> psutil.virtual_memory() vmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L, free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L, cached=1251086336) >>> >>> psutil.swap_memory() swap(total=2097147904L, used=296128512L, free=1801019392L, percent=14.1, sin=304193536, sout=677842944) >>> === Compatitility notes === 0.6.0 version does not introduce any backward incompatibility. Nevertheless it introduces some deprecations warnings: - psutil.phymem_usage() is deprecated in favor of psutil.virtual_memory() - psutil.virmem_usage() is deprecated in favor of psutil.swap_memory() - psutil.cached_phymem() is deprecated in favor of psutil.virtual_memory().cached - psutil.phymem_buffers() is deprecated in favor of psutil.virtual_memory().buffers The deprecated functions will be removed in next 1.0.0 version. === Links === * Home page: http://code.google.com/p/psutil * Source tarball: http://psutil.googlecode.com/files/psutil-0.6.0.tar.gz * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance. --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From no.email at please.post Mon Aug 13 10:16:39 2012 From: no.email at please.post (kj) Date: Mon, 13 Aug 2012 14:16:39 +0000 (UTC) Subject: Official reason for omitting inspect.currentcallable() ? References: <5028b9ce$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Chris Angelico writes: >I'm not familiar with it by that name, but Pike's this_function is >what the OP's describing. You got it. >It's a useful construct in theory when you want to write in recursion, >which was part of the rationale behind PEP 3130 Thank you! kj From jarausch at skynet.be Mon Aug 13 11:16:17 2012 From: jarausch at skynet.be (Helmut Jarausch) Date: 13 Aug 2012 15:16:17 GMT Subject: print(....,file=sys.stderr) buffered? Message-ID: <50291a41$0$3122$ba620e4c@news.skynet.be> Hi, for tracing purposes I have added some print outs like print('+++ before calling foo',file=sys.stderr) x=foo(..) print('--- after calling foo', and within 'foo' print('>>> entering foo ...',file=sys.stderr) Now, when executing this, I always get +++ before calling foo --- after calling foo >>> entering foo ... When outputting to stderr from C/C++ it's guaranteed that the different outputs appear in the same order as they have been generated. Is this guarantee no more valid in Python 3.2 ? Many thanks for a comment, Helmut. (That's a single-threaded application) From maniandram01 at gmail.com Mon Aug 13 11:21:51 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 13 Aug 2012 20:51:51 +0530 Subject: [ANNOUNCE] Campaign to support the notmm project! In-Reply-To: <502676FE.3040600@gmail.com> References: <502676FE.3040600@gmail.com> Message-ID: > I'm now really poor and cannot even finance the server hosting. You can use Google Code hosting for the project - even many Python Core Dev's stuff are done on it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Mon Aug 13 11:25:27 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 13 Aug 2012 20:55:27 +0530 Subject: print(....,file=sys.stderr) buffered? In-Reply-To: <50291a41$0$3122$ba620e4c@news.skynet.be> References: <50291a41$0$3122$ba620e4c@news.skynet.be> Message-ID: As far as I know, stdout is usually buffered (not necessary) in both C++ and Python stderr is non-buffered in both C++ and Python (I can't imagine the point of stderr if it were buffered) Even with this, stdout usually come immediately - the situation you have shouldn't happen. Are you using an IDE? If so, which one? On 13 August 2012 20:46, Helmut Jarausch wrote: > Hi, > > for tracing purposes I have added some print outs like > > print('+++ before calling foo',file=sys.stderr) > x=foo(..) > print('--- after calling foo', > > and within 'foo' > print('>>> entering foo ...',file=sys.stderr) > > Now, when executing this, I always get > > +++ before calling foo > --- after calling foo > >>> entering foo ... > > When outputting to stderr from C/C++ it's guaranteed that the different > outputs appear in the same order as they have been generated. > > Is this guarantee no more valid in Python 3.2 ? > > Many thanks for a comment, > Helmut. > > (That's a single-threaded application) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Mon Aug 13 11:30:19 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Mon, 13 Aug 2012 21:00:19 +0530 Subject: Does anyone have an activate script for portable python? In-Reply-To: References: Message-ID: PS:virtualenv is added to the stdlib in Python 3.3 On 13 August 2012 05:42, alex23 wrote: > On Aug 12, 9:09 am, Gelonida N wrote: > > In Pythons installed with virtualenv there is on windows an activate.bat > > script, that can be used to setup the cmd-shell such, that the search > > path for python and pythor elated tools (pip / easy_install) is setup > > properly. > > Do such a scripts also exist for Portable python? > > > Portable Python is just Python with some helper scripts for not > requiring a system installation. > > So "command-line-command-to-run-portable-python virtualenv name>" should be all you need. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Mon Aug 13 11:43:31 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 13 Aug 2012 15:43:31 +0000 (UTC) Subject: print(....,file=sys.stderr) buffered? References: <50291a41$0$3122$ba620e4c@news.skynet.be> Message-ID: On 2012-08-13, Helmut Jarausch wrote: > Hi, > > for tracing purposes I have added some print outs like > > print('+++ before calling foo',file=sys.stderr) > x=foo(..) > print('--- after calling foo', > > and within 'foo' > print('>>> entering foo ...',file=sys.stderr) > > Now, when executing this, I always get > > +++ before calling foo > --- after calling foo >>>> entering foo ... > > When outputting to stderr from C/C++ it's guaranteed that the different > outputs appear in the same order as they have been generated. You're not printing to stderr in the second print() call -- you're printing to stdout. The two file objects have separate buffers and may even be using two different buffering modes (e.g. line vs. block). You can't interleave writes to stderr and stdout and assume order is preserved unless you take specific steps (such as forcing them both to be unbuffered or flushing them at certain points). > Is this guarantee no more valid in Python 3.2 ? If you write to stderr all three times, it should work the way you want it to. -- Grant Edwards grant.b.edwards Yow! ... I'm IMAGINING a at sensuous GIRAFFE, CAVORTING gmail.com in the BACK ROOM of a KOSHER DELI -- From rustompmody at gmail.com Mon Aug 13 11:55:33 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 13 Aug 2012 08:55:33 -0700 (PDT) Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <5028b54e$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 13, 1:05?pm, Steven D'Aprano wrote: > > Chill out Alex, it's all good. Mark was channelling a famous scene from > "Fawlty Towers", staring Monty Python's own John Cleese, hence it is on- > topic, for the sillier definitions of on-topic. Ha! Thanks for that connection. Watched and enjoyed Fawlty towers as a kid but have never seen a Monty Python. From wuwei23 at gmail.com Mon Aug 13 12:14:13 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 13 Aug 2012 09:14:13 -0700 (PDT) Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> Message-ID: <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> On Aug 13, 10:37?pm, Mark Lawrence wrote: > Why on your say so? My mistake, I didn't realise you wanted to sound so tedious. Knock yourself out. From wuwei23 at gmail.com Mon Aug 13 12:16:46 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 13 Aug 2012 09:16:46 -0700 (PDT) Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <5028b54e$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 13, 6:05?pm, Steven D'Aprano wrote: > Chill out Alex, it's all good. Mark was channelling a famous scene from > "Fawlty Towers", staring Monty Python's own John Cleese, hence it is on- > topic, for the sillier definitions of on-topic. Thank you, yes, I get that. However, Mark has repeatedly been directing this dickishness at Stefan Behnel ever since he was asked to not stray off topic. While Mark doesn't have to listen to anyone else about his behaviour, he can't expect not to be called a dick when acting like one. From jarausch at skynet.be Mon Aug 13 12:29:45 2012 From: jarausch at skynet.be (Helmut Jarausch) Date: 13 Aug 2012 16:29:45 GMT Subject: print(....,file=sys.stderr) buffered? References: <50291a41$0$3122$ba620e4c@news.skynet.be> Message-ID: <50292b78$0$3122$ba620e4c@news.skynet.be> On Mon, 13 Aug 2012 15:43:31 +0000, Grant Edwards wrote: > On 2012-08-13, Helmut Jarausch wrote: >> Hi, >> >> for tracing purposes I have added some print outs like >> >> print('+++ before calling foo',file=sys.stderr) >> x=foo(..) >> print('--- after calling foo', Sorry, this is a cut'n paste error. I did use print('--- after calling foo',file=sys.stderr) >> >> and within 'foo' >> print('>>> entering foo ...',file=sys.stderr) >> >> Now, when executing this, I always get >> >> +++ before calling foo --- after calling foo >>>>> entering foo ... >> >> When outputting to stderr from C/C++ it's guaranteed that the different >> outputs appear in the same order as they have been generated. > > You're not printing to stderr in the second print() call -- you're > printing to stdout. The two file objects have separate buffers and may > even be using two different buffering modes (e.g. line vs. block). > You can't interleave writes to stderr and stdout and assume order is > preserved unless you take specific steps (such as forcing them both to > be unbuffered or flushing them at certain points). > >> Is this guarantee no more valid in Python 3.2 ? > > If you write to stderr all three times, it should work the way you want > it to. It seems it doesn't do so in my case. Thanks, Helmut. From malaclypse2 at gmail.com Mon Aug 13 12:49:27 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 13 Aug 2012 12:49:27 -0400 Subject: print(....,file=sys.stderr) buffered? In-Reply-To: <50291a41$0$3122$ba620e4c@news.skynet.be> References: <50291a41$0$3122$ba620e4c@news.skynet.be> Message-ID: On Mon, Aug 13, 2012 at 11:16 AM, Helmut Jarausch wrote: > Now, when executing this, I always get > > +++ before calling foo > --- after calling foo >>>> entering foo ... Can you give us a piece of code we can run that produces this output for you? You gave us an outline in your original post, but it would be useful to have a self contained example that you can say reliably produces the unexpected output for you. Also, what environment, OS, and exact python version is this? Is the code being run in an IDE of some sort? Does the behavior change if you call your code directly from the command line? -- Jerry From andrea.crotti.0 at gmail.com Mon Aug 13 12:53:32 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Mon, 13 Aug 2012 17:53:32 +0100 Subject: Sharing code between different projects? Message-ID: I am in the situation where I am working on different projects that might potentially share a lot of code. I started to work on project A, then switched completely to project B and in the transiction I copied over a lot of code with the corresponding tests, and I started to modify it. Now it's time to work again on project A, but I don't want to copy things over again. I would like to design a simple and nice way to share between projects, where the things I want to share are simple but useful things as for example: class TempDirectory: """Create a temporary directory and cd to it on enter, cd back to the original position and remove it on exit """ def __init__(self): self.oldcwd = getcwd() self.temp_dir = mkdtemp() def __enter__(self): logger.debug("create and move to temp directory %s" % self.temp_dir) return self.temp_dir def __exit__(self, type, value, traceback): # I first have to move out chdir(self.oldcwd) logger.debug("removing the temporary directory and go back to the original position %s" % self.temp_dir) rmtree(self.temp_dir) The problem is that there are functions/classes from many domains, so it would not make much sense to create a real project, and the only name I could give might be "utils or utilities".. In plus the moment the code is shared I must take care of versioning and how to link different pieces together (we use perforce by the way). If then someone else except me will want to use these functions then of course I'll have to be extra careful, designing really good API's and so on, so I'm wondering where I should set the trade-off between ability to share and burden to maintain.. Anyone has suggestions/real world experiences about this? From breamoreboy at yahoo.co.uk Mon Aug 13 13:07:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Aug 2012 18:07:26 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> Message-ID: On 13/08/2012 17:14, alex23 wrote: > On Aug 13, 10:37 pm, Mark Lawrence wrote: >> Why on your say so? > > My mistake, I didn't realise you wanted to sound so tedious. Knock > yourself out. > > Yes m'lud. Do I lick your boots or polish them? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Aug 13 13:43:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Aug 2012 18:43:40 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> Message-ID: On 13/08/2012 01:15, alex23 wrote: > On Aug 10, 7:37 pm, Mark Lawrence wrote: >> Well whatever you do *DON'T* mention Cython. I mentioned it just now but >> I think I've got away with it. > > While I'm not against threads straying off topic, you're beginning to > come across as a bit of an asshole now. > > Just let it go. > http://mail.python.org/pipermail/pypy-dev/2012-February/009277.html -- Cheers. Mark Lawrence. From tjreedy at udel.edu Mon Aug 13 14:14:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Aug 2012 14:14:35 -0400 Subject: Idle no longer works In-Reply-To: <68ei2892hd5cm32pp9e6bnqf6govflujn6@invalid.netcom.com> References: <94cc6490-ef15-4835-88c1-fa17347e03f4@googlegroups.com> <6ab35ebc-8069-4f07-9ce9-f591bd7163e2@googlegroups.com> <68ei2892hd5cm32pp9e6bnqf6govflujn6@invalid.netcom.com> Message-ID: On 8/13/2012 1:43 PM, Dennis Lee Bieber wrote: > On Mon, 13 Aug 2012 00:11:06 -0700 (PDT), jussij at zeusedit.com declaimed > the following in gmane.comp.python.general: > >> On Saturday, August 11, 2012 4:09:16 PM UTC-7, Opap-OJ wrote: >> >>> I can no longer open the Idle IDE for Python on Windows 7. >>> .. >>> Any idea why? >> >> It looks like your registry has changed. Most likely, or the Python installation has be damaged. >> To fix this just use the Windows Explorer, click on a Python file >> and use the 'Open with, Choose default program' menu and then >> select the Idle IDE as the default program. > > That is probably the worst choice to make -- since what you've > defined means double clicking on ANY .py file will NOT RUN IT -- but > rather attempt to open it with the editor (IDLE)... But since IDLE > itself is a .py file, it may fail to start at all. > > If double-clicking an IDLE.py file does not start it, then the > registry has lost the association of .py to python.exe, not to IDLE. OR > -- .py IS associated to python.exe but the association (the "run > command" is not passing the .py file name to the python executable). > > On WinXP (with ActiveState 2.5.x version) my associations are as: > > E:\UserData\Wulfraed\My Documents>assoc .py > .py=py_auto_file > > E:\UserData\Wulfraed\My Documents>ftype py_auto_file > py_auto_file="E:\Python25\python.exe" "%1" %* > > E:\UserData\Wulfraed\My Documents> > > (with similar entries for .pyw to hook into pythonw.exe) > {Just booted the Win7 laptop with Python 2.7.x: The only real difference > is that it uses Python.File where the above has py_auto_file} Re-installing, as I suggested in the first response, is much easier, especially for someone not familiar with the above. -- Terry Jan Reedy From gelonida at gmail.com Mon Aug 13 15:15:51 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 13 Aug 2012 21:15:51 +0200 Subject: Does anyone have an activate script for portable python? In-Reply-To: References: Message-ID: <50295267.9070403@gmail.com> On 08/13/2012 02:12 AM, alex23 wrote: > On Aug 12, 9:09 am, Gelonida N wrote: >> In Pythons installed with virtualenv there is on windows an activate.bat >> script, that can be used to setup the cmd-shell such, that the search >> path for python and pythor elated tools (pip / easy_install) is setup >> properly. >> Do such a scripts also exist for Portable python? > > > Portable Python is just Python with some helper scripts for not > requiring a system installation. > > So "command-line-command-to-run-portable-python virtualenv name>" should be all you need. > Hmm I guess I didn't express myself very well. The idea is to easily create a cmd window, that the path is setup in order to point to portably python by default. At a first glance at Portable Python it seemed to me, that this doesn't exist. Having a small icon to click at, that opens a cmd window with the right setup or just a .bat file, that could be called to adapt the setup of an existing cmd window. It's not too difficult to write such scipts, but I though it would be interesting to see whether I'm the only one missing such feature in portable Python. From gelonida at gmail.com Mon Aug 13 15:15:51 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 13 Aug 2012 21:15:51 +0200 Subject: Does anyone have an activate script for portable python? In-Reply-To: References: Message-ID: <50295267.9070403@gmail.com> On 08/13/2012 02:12 AM, alex23 wrote: > On Aug 12, 9:09 am, Gelonida N wrote: >> In Pythons installed with virtualenv there is on windows an activate.bat >> script, that can be used to setup the cmd-shell such, that the search >> path for python and pythor elated tools (pip / easy_install) is setup >> properly. >> Do such a scripts also exist for Portable python? > > > Portable Python is just Python with some helper scripts for not > requiring a system installation. > > So "command-line-command-to-run-portable-python virtualenv name>" should be all you need. > Hmm I guess I didn't express myself very well. The idea is to easily create a cmd window, that the path is setup in order to point to portably python by default. At a first glance at Portable Python it seemed to me, that this doesn't exist. Having a small icon to click at, that opens a cmd window with the right setup or just a .bat file, that could be called to adapt the setup of an existing cmd window. It's not too difficult to write such scipts, but I though it would be interesting to see whether I'm the only one missing such feature in portable Python. From robert.day at merton.oxon.org Mon Aug 13 18:02:59 2012 From: robert.day at merton.oxon.org (Rob Day) Date: Mon, 13 Aug 2012 23:02:59 +0100 Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: I'd just create a module - called shared_utils.py or similar - and import that in both projects. It might be a bit messy if there's no 'unifying theme' to the module - but surely it'd be a lot less messy than your TempDirectory class, and anyone else who knows Python will understand 'import shared_utils' much more easily. I realise you might not want to say, but if you could give some idea what sort of projects these are, and what sorts of code you're trying to share, it might make things a bit clearer. I'm not really sure what your concerns about 'versioning and how to link different pieces together' are - what d you think could go wrong here? On 13 August 2012 17:53, andrea crotti wrote: > I am in the situation where I am working on different projects that > might potentially share a lot of code. > > I started to work on project A, then switched completely to project B > and in the transiction I copied over a lot of code with the > corresponding tests, and I started to modify it. > > Now it's time to work again on project A, but I don't want to copy > things over again. > > I would like to design a simple and nice way to share between projects, > where the things I want to share are simple but useful things as for > example: > > class TempDirectory: > """Create a temporary directory and cd to it on enter, cd back to > the original position and remove it on exit > """ > def __init__(self): > self.oldcwd = getcwd() > self.temp_dir = mkdtemp() > > def __enter__(self): > logger.debug("create and move to temp directory %s" % > self.temp_dir) > return self.temp_dir > > def __exit__(self, type, value, traceback): > # I first have to move out > chdir(self.oldcwd) > logger.debug("removing the temporary directory and go back to > the original position %s" % self.temp_dir) > rmtree(self.temp_dir) > > > The problem is that there are functions/classes from many domains, so it > would not make much sense to create a real project, and the only name I > could give might be "utils or utilities".. > > In plus the moment the code is shared I must take care of versioning and > how to link different pieces together (we use perforce by the way). > > If then someone else except me will want to use these functions then of > course I'll have to be extra careful, designing really good API's and so > on, so I'm wondering where I should set the trade-off between ability to > share and burden to maintain.. > > Anyone has suggestions/real world experiences about this? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Robert K. Day robert.day at merton.oxon.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Aug 13 18:16:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Aug 2012 08:16:28 +1000 Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: On Tue, Aug 14, 2012 at 2:53 AM, andrea crotti wrote: > The problem is that there are functions/classes from many domains, so it > would not make much sense to create a real project, and the only name I > could give might be "utils or utilities".. There's actually much merit in a generic utilities module. Keep things nicely segregated (ideally such that you know what things depend on what other, but at very least keep track of where one ends and another begins - that's trivial if everything's "one function" or "one class", but less so when you have a family of related functions), and then you can consider promoting one block of code to stand-alone module. But in the meantime, you have a single module used in two places, even if it doesn't have a very clear definition as yet. ChrisA From rt5 at bk.ru Mon Aug 13 19:00:01 2012 From: rt5 at bk.ru (Xantipius) Date: Mon, 13 Aug 2012 16:00:01 -0700 (PDT) Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> Message-ID: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> On Aug 13, 3:40?pm, Mark Lawrence wrote: > On 13/08/2012 11:18, Xantipius wrote: > > > subj > > Either > > a) write some code and when and if it fails give us a small code snippet > that demonstates the problem with the complete traceback. > > or > > b) state how much you are willing to pay for someone here to come up > with a solution for you. > > -- > Cheers. > > Mark Lawrence. Mark, in regard your last remark: it's just a recreation for me. Nothing more in it. I like to put some weird and useless problems before myself. Cheers. From rosuav at gmail.com Mon Aug 13 19:52:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Aug 2012 09:52:41 +1000 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> Message-ID: On Tue, Aug 14, 2012 at 9:00 AM, Xantipius wrote: > Mark, in regard your last remark: > it's just a recreation for me. Nothing more in it. > I like to put some weird and useless problems before myself. In that case, I strongly recommend that you write some code instead of throwing zero-effort questions onto a mailing list. Though this sort of request does tend to have amusement value. Thanks Ben! ChrisA From breamoreboy at yahoo.co.uk Mon Aug 13 20:34:46 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 01:34:46 +0100 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> Message-ID: On 14/08/2012 00:00, Xantipius wrote: > On Aug 13, 3:40 pm, Mark Lawrence wrote: >> On 13/08/2012 11:18, Xantipius wrote: >> >>> subj >> >> Either >> >> a) write some code and when and if it fails give us a small code snippet >> that demonstates the problem with the complete traceback. >> >> or >> >> b) state how much you are willing to pay for someone here to come up >> with a solution for you. >> >> -- >> Cheers. >> >> Mark Lawrence. > > Mark, in regard your last remark: > it's just a recreation for me. Nothing more in it. > I like to put some weird and useless problems before myself. > > Cheers. > Is it your normal practice to communicate with yourself via a public mailing list/news group? When did you seek my permission to call me by my forename? -- Cheers. Mark Lawrence. From wuwei23 at gmail.com Mon Aug 13 21:32:48 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 13 Aug 2012 18:32:48 -0700 (PDT) Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> Message-ID: <616b2868-f167-44e7-a6f2-d13e65bb2a07@nc9g2000pbc.googlegroups.com> On Aug 14, 3:43?am, Mark Lawrence wrote: > On 13/08/2012 01:15, alex23 wrote: > > > On Aug 10, 7:37 pm, Mark Lawrence wrote: > >> Well whatever you do *DON'T* mention Cython. I mentioned it just now but > >> I think I've got away with it. > > > While I'm not against threads straying off topic, you're beginning to > > come across as a bit of an asshole now. > > > Just let it go. > > http://mail.python.org/pipermail/pypy-dev/2012-February/009277.html > > -- > Cheers. > > Mark Lawrence. Yeah, you're really coming across as holding the moral high ground here. Plonk. From steve+comp.lang.python at pearwood.info Mon Aug 13 22:54:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 02:54:53 GMT Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> Message-ID: <5029bdfd$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: > On 13/08/2012 17:14, alex23 wrote: >> On Aug 13, 10:37 pm, Mark Lawrence wrote: >>> Why on your say so? >> >> My mistake, I didn't realise you wanted to sound so tedious. Knock >> yourself out. >> >> >> > Yes m'lud. Do I lick your boots or polish them? Children children, if you won't play nice don't play at all. You're scaring away the people who are here to learn about Python. -- Steven From steve+comp.lang.python at pearwood.info Mon Aug 13 23:00:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 03:00:11 GMT Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> Message-ID: <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Aug 2012 01:34:46 +0100, Mark Lawrence wrote: > When did you seek my permission to call me by my forename? Sheesh. It's 2012, not 1812. If you sign your posts with your full name, you have to expect that people will call you "Mark" rather than "Mr Lawrence" or "Lord High Mucky-Muck Grand Poohbar Lawrence" -- even if they haven't been formally introduced. Mark, we're all human and the occasional snark is only to be expected, but demanding that people ask permission to call you by your first name in an informal forum like this crosses the line to total dickishness. Chill out before you get yourself kill-filed into irrelevance. -- Steven From mullapervez at gmail.com Tue Aug 14 01:12:48 2012 From: mullapervez at gmail.com (mullapervez at gmail.com) Date: Mon, 13 Aug 2012 22:12:48 -0700 (PDT) Subject: how to call perl script from html using python Message-ID: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Hi, I wanna call perl script in HTML form n store that data in DB using Python. How can i do this.......?? Please help me Thank you Pervez From simoncropper at fossworkflowguides.com Tue Aug 14 01:22:18 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 14 Aug 2012 15:22:18 +1000 Subject: how to call perl script from html using python In-Reply-To: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Message-ID: <5029E08A.8080906@fossworkflowguides.com> On 14/08/12 15:12, mullapervez at gmail.com wrote: > Hi, > > I wanna call perl script in HTML form n store that data in DB using Python. > > How can i do this.......?? > > Please help me > > Thank you > Pervez > Google you question. Many solutions already exist on the Internet. -- Cheers Simon Simon Cropper - Open Content Creator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From mullapervez at gmail.com Tue Aug 14 01:31:49 2012 From: mullapervez at gmail.com (mullapervez at gmail.com) Date: Mon, 13 Aug 2012 22:31:49 -0700 (PDT) Subject: how to call perl script from html using python In-Reply-To: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Message-ID: <194f8d12-3c5d-422a-b5a7-98948ccbc1ae@googlegroups.com> On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, mulla... at gmail.com wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez Hey Simon, Thank You for your mail and time, Yest I spent entire day for this , But I didn't get any solution for this problem .I google it but am not able to get any solution for this From simoncropper at fossworkflowguides.com Tue Aug 14 01:44:43 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 14 Aug 2012 15:44:43 +1000 Subject: how to call perl script from html using python In-Reply-To: <194f8d12-3c5d-422a-b5a7-98948ccbc1ae@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> <194f8d12-3c5d-422a-b5a7-98948ccbc1ae@googlegroups.com> Message-ID: <5029E5CB.6090907@fossworkflowguides.com> On 14/08/12 15:31, mullapervez at gmail.com wrote: > On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, mulla... at gmail.com wrote: >> Hi, >> >> >> >> I wanna call perl script in HTML form n store that data in DB using Python. >> >> >> >> How can i do this.......?? >> >> >> >> Please help me >> >> >> >> Thank you >> >> Pervez > > Hey Simon, > > Thank You for your mail and time, > > Yest I spent entire day for this , But I didn't get any solution for this problem .I google it but am not able to get any solution for this > Then you should outline what you have tried and what the problems you encountered that way people can help. -- Cheers Simon Simon Cropper - Open Content Creator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From steve+comp.lang.python at pearwood.info Tue Aug 14 02:00:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 06:00:06 GMT Subject: how to call perl script from html using python References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Message-ID: <5029e966$0$29867$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 22:12:48 -0700, mullapervez wrote: > Hi, > > I wanna call perl script in HTML form n store that data in DB using > Python. > > How can i do this.......?? > > Please help me Okay, let me give you some general advice first, then some programming advice If your question looks like you have put no thought into the question, you will get answers that also have no thought put into them. Try to write proper English sentences. We will make allowances for non- native English speakers, and simple typos, but if u cnt b bothrd 2 rite gd we cnt b bothrd 2 answr gd ethr. To solve your programming problem, break it up into smaller pieces: 1) write some code to get a perl script from some HTML; 2) write some more code to take a perl script and run it, collecting the results; 3) write some more code to take those results and put them into a database; 4) finally write some code to put the first three pieces together. Do you need help on any of these? If so, please tell us: - What is your experience with Python? Complete newbie, beginner, intermediate, advanced, expert, guru. Do you know any other programming languages? - What you have already tried? Show us your code. - Show us some *simple* sample data. The more you help us, the more we can help you. -- Steven From mullapervez at gmail.com Tue Aug 14 02:21:34 2012 From: mullapervez at gmail.com (Pervez Mulla) Date: Mon, 13 Aug 2012 23:21:34 -0700 (PDT) Subject: how to call perl script from html using python In-Reply-To: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Message-ID: <8138ce19-e3a6-4a69-bb07-89af0b327c56@googlegroups.com> On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, Pervez Mulla wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez Thank you for your advice steven, I am beginner to this language, I have exp in JAVA and C.... I wanna call perl objects using Python . I checked in internet ,I can make use of inline function for this, But in HTML......?? Thank You From simoncropper at fossworkflowguides.com Tue Aug 14 02:34:01 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 14 Aug 2012 16:34:01 +1000 Subject: pylagiarism -- Need help now! Please provide code... Message-ID: <5029F159.5090802@fossworkflowguides.com> Hi Everyone, I just had a great idea for a new python module. I haven't bothered googling it or doing any research. I need help putting together some code; today preferably, my boss is on my back. Can someone please contribute a functioning module showing me how to do it? Once I have all your submissions, I will compile a functioning package, which I hope to sell. Don't worry, no one will be at risk of being sued, I don't intend to credit you with the code and you will not know anything about what I have done because I don't intend to post and feedback to the list. Licenses are not a problem either, I don't believe in them and even if you find out I have plagiarized your stuff you have bub-kiss chance of suing me as I am in another jurisdiction. So, now you know where I am coming from, I would like to thank you for all your help. Remember though, I need help now, so please stop what you are doing and submit something quickly. I'm waiting... Still waiting... Hey, stop reading and get on with writing some code, I don't have all day! -- Simon Disclaimer :) Please don't flame me, I have written this with my tongue in my cheek and a light hearted take on some people request for assistance on a range of mail lists. It was not meant to target anyone in particular only to exaggerate how some people's requests appear to lurkers and contributors on many fora I frequent. From sscc at mweb.co.za Tue Aug 14 02:59:18 2012 From: sscc at mweb.co.za (Alex Strickland) Date: Tue, 14 Aug 2012 08:59:18 +0200 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: <5029F159.5090802@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> Message-ID: <5029F746.8050505@mweb.co.za> cn tell itz a fraud - sp 2 gd! lolz On 2012/08/14 08:34 AM, Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > > I need help putting together some code; today preferably, my boss is on > my back. Can someone please contribute a functioning module showing me > how to do it? > > Once I have all your submissions, I will compile a functioning package, > which I hope to sell. Don't worry, no one will be at risk of being sued, > I don't intend to credit you with the code and you will not know > anything about what I have done because I don't intend to post and > feedback to the list. Licenses are not a problem either, I don't believe > in them and even if you find out I have plagiarized your stuff you have > bub-kiss chance of suing me as I am in another jurisdiction. > > So, now you know where I am coming from, I would like to thank you for > all your help. Remember though, I need help now, so please stop what you > are doing and submit something quickly. I'm waiting... > > Still waiting... > > Hey, stop reading and get on with writing some code, I don't have all day! > From fgnu32 at yahoo.com Tue Aug 14 03:03:05 2012 From: fgnu32 at yahoo.com (Fg Nu) Date: Tue, 14 Aug 2012 00:03:05 -0700 (PDT) Subject: pylagiarism -- Need help now! Please provide code... Message-ID: <1344927785.96992.YahooMailNeo@web122402.mail.ne1.yahoo.com> Haha. Best listserv ever.? I've been on this list a day, and run me over with a lawnmower if I've written more than 200 lines of Python code, but this list is totally worth it. From ben+python at benfinney.id.au Tue Aug 14 03:04:15 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 14 Aug 2012 17:04:15 +1000 Subject: pylagiarism -- Need help now! Please provide code... References: Message-ID: <87boieeyz4.fsf@benfinney.id.au> Simon Cropper writes: > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. That's the perfect time: everyone knows that ideas and enthusiasm are the key to a successful project. Show them early, and people will flock to you. Mind you, it's best if you show even *more* enthusiasm by telling us that you've been searching all day. Don't waste your time with a better description of what you're looking for, though. > I need help putting together some code; today preferably, my boss is > on my back. Can someone please contribute a functioning module showing > me how to do it? You have exactly the right approach. I'm sure this is just how you learned to program in your tertiary school: ask who has already done your work, without wasting time thinking about the problem. > So, now you know where I am coming from, I would like to thank you for > all your help. Remember though, I need help now, so please stop what > you are doing and submit something quickly. I'm waiting... How can this approach fail! I anticipate you will have a working program interfrastically. -- \ ?If you always want the latest and greatest, then you have to | `\ buy a new iPod at least once a year.? ?Steve Jobs, MSNBC | _o__) interview 2006-05-25 | Ben Finney From steve+comp.lang.python at pearwood.info Tue Aug 14 03:04:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 07:04:22 GMT Subject: pylagiarism -- Need help now! Please provide code... References: Message-ID: <5029f876$0$29867$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Aug 2012 16:34:01 +1000, Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > > I need help putting together some code; today preferably, my boss is on > my back. Can someone please contribute a functioning module showing me > how to do it? [snip] Ha ha, very amusing :) -- Steven From rosuav at gmail.com Tue Aug 14 03:08:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Aug 2012 17:08:58 +1000 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: <5029F159.5090802@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> Message-ID: On Tue, Aug 14, 2012 at 4:34 PM, Simon Cropper wrote: > I need help putting together some code; today preferably, my boss is on my > back. Can someone please contribute a functioning module showing me how to > do it? > Sure, old man, we'll help you out! *throws Maurice out of the tavern* ChrisA From atmb4u at gmail.com Tue Aug 14 03:11:14 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Tue, 14 Aug 2012 12:41:14 +0530 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: <5029F159.5090802@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> Message-ID: On 14 August 2012 12:04, Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > > I need help putting together some code; today preferably, my boss is on my > back. Can someone please contribute a functioning module showing me how to > do it? > > Once I have all your submissions, I will compile a functioning package, > which I hope to sell. Don't worry, no one will be at risk of being sued, I > don't intend to credit you with the code and you will not know anything > about what I have done because I don't intend to post and feedback to the > list. Licenses are not a problem either, I don't believe in them and even > if you find out I have plagiarized your stuff you have bub-kiss chance of > suing me as I am in another jurisdiction. > > So, now you know where I am coming from, I would like to thank you for all > your help. Remember though, I need help now, so please stop what you are > doing and submit something quickly. I'm waiting... > > Still waiting... > > Hey, stop reading and get on with writing some code, I don't have all day! Let the boss wait. Learn some mailing list etiquette first. It will help you for sure. > > > -- > Simon > > Disclaimer :) Please don't flame me, I have written this with my tongue > in my cheek and a light hearted take on some people request for assistance > on a range of mail lists. It was not meant to target anyone in particular > only to exaggerate how some people's requests appear to lurkers and > contributors on many fora I frequent. > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From giacomo.alzetta at gmail.com Tue Aug 14 03:14:54 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Tue, 14 Aug 2012 00:14:54 -0700 (PDT) Subject: in-place exponentiation incongruities In-Reply-To: References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> Message-ID: <75241788-1054-4b22-b8b6-930358dbbe8c@googlegroups.com> Il giorno domenica 12 agosto 2012 23:53:46 UTC+2, Terry Reedy ha scritto: > > Are you actually planning to do this, or is this purely theoretical? > Yes, I do plan to implement ipow. > > Not true. Whether the function is coded in Python or C > > cls.__ipow__(base, exp, mod) # or > > base.__ipow__(exp, mod) > > > > > while he would be able to > > > call the normal version with the third argument. Yes, that's true. But I find that calling a special-method in that way is *really* ugly. I'd think that the pow built-in function was probably inserted to avoid writing base.__pow__(exp, mod). From giacomo.alzetta at gmail.com Tue Aug 14 03:14:54 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Tue, 14 Aug 2012 00:14:54 -0700 (PDT) Subject: in-place exponentiation incongruities In-Reply-To: References: <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> Message-ID: <75241788-1054-4b22-b8b6-930358dbbe8c@googlegroups.com> Il giorno domenica 12 agosto 2012 23:53:46 UTC+2, Terry Reedy ha scritto: > > Are you actually planning to do this, or is this purely theoretical? > Yes, I do plan to implement ipow. > > Not true. Whether the function is coded in Python or C > > cls.__ipow__(base, exp, mod) # or > > base.__ipow__(exp, mod) > > > > > while he would be able to > > > call the normal version with the third argument. Yes, that's true. But I find that calling a special-method in that way is *really* ugly. I'd think that the pow built-in function was probably inserted to avoid writing base.__pow__(exp, mod). From steve+comp.lang.python at pearwood.info Tue Aug 14 03:19:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 07:19:25 GMT Subject: how to call perl script from html using python References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> <8138ce19-e3a6-4a69-bb07-89af0b327c56@googlegroups.com> Message-ID: <5029fbfd$0$29867$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 23:21:34 -0700, Pervez Mulla wrote: > I wanna call perl objects using Python . I checked in internet ,I can > make use of inline function for this, But in HTML......?? You need to explain more about your problem, because I don't understand what you want to do in detail. For example: 1) "I have a URL to a perl script, like this: http://example.com/somewhere/script.pl and I want to download the script, run it, and collect the results." Difficulty: (0 is trivial, 10 is impossible) About 2 or 3. 2) "I have a web page like this: http://example.com/somewhere/homepage.html Inside this web page I have a block of text that is actually Perl code. I want to download the HTML page, extract the Perl code, and run it." Difficulty: (0 is trivial, 10 is impossible) Between 6 and 10, depending on the exact details of how the Perl code is stored. Please explain in more detail what you want to do. Where is the Perl code? In a script? Inside a HTML file? Mixed in with other text, or in a HTML element of its own? Once you know where the Perl code lives, you can write a function to extract it. If you don't know where the code lives, you can't. Once you have the Perl code, you can then run it using the subprocess module, and collect its results. Once you have the results, you can store it in a database. -- Steven From fgnu32 at yahoo.com Tue Aug 14 03:21:37 2012 From: fgnu32 at yahoo.com (Fg Nu) Date: Tue, 14 Aug 2012 00:21:37 -0700 (PDT) Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: References: <5029F159.5090802@fossworkflowguides.com> Message-ID: <1344928897.77094.YahooMailNeo@web122406.mail.ne1.yahoo.com> Lol. Lol. Lol. It just keeps on givin'. ________________________________ From: Anoop Thomas Mathew To: Simon Cropper Cc: python-list at python.org Sent: Tuesday, August 14, 2012 12:11 AM Subject: Re: pylagiarism -- Need help now! Please provide code... On 14 August 2012 12:04, Simon Cropper wrote: Hi Everyone, > >I just had a great idea for a new python module. I haven't bothered googling it or doing any research. > >I need help putting together some code; today preferably, my boss is on my back. Can someone please contribute a functioning module showing me how to do it? > >Once I have all your submissions, I will compile a functioning ?package, which I hope to sell. Don't worry, no one will be at risk of being sued, I don't intend to credit you with the code and you will not know anything about what I have done because I don't intend to post and feedback to the list. Licenses are not a problem either, I don't believe in them and even if you find out I have plagiarized your stuff you have bub-kiss chance of suing me as I am in another jurisdiction. > >So, now you know where I am coming from, I would like to thank you for all your help. Remember though, I need help now, so please stop what you are doing and submit something quickly. I'm waiting... > >Still waiting... > >Hey, stop reading and get on with writing some code, I don't have all day! Let the boss wait. Learn some mailing list?etiquette first. It will help you for sure. > >-- >Simon > >Disclaimer ?:) Please don't flame me, I have written this with my tongue in my cheek and a light hearted take on some people request for assistance on a range of mail lists. It was not meant to target anyone in particular only to exaggerate how some people's requests appear to lurkers and contributors on many fora I frequent. >-- >http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list? From __peter__ at web.de Tue Aug 14 04:19:08 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Aug 2012 10:19:08 +0200 Subject: pylagiarism -- Need help now! Please provide code... References: <5029F159.5090802@fossworkflowguides.com> Message-ID: Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > > I need help putting together some code; today preferably, my boss is on > my back. Can someone please contribute a functioning module showing me > how to do it? > > Once I have all your submissions, I will compile a functioning package, > which I hope to sell. Don't worry, no one will be at risk of being sued, > I don't intend to credit you with the code and you will not know > anything about what I have done because I don't intend to post and > feedback to the list. Licenses are not a problem either, I don't believe > in them and even if you find out I have plagiarized your stuff you have > bub-kiss chance of suing me as I am in another jurisdiction. > > So, now you know where I am coming from, I would like to thank you for > all your help. Remember though, I need help now, so please stop what you > are doing and submit something quickly. I'm waiting... > > Still waiting... > > Hey, stop reading and get on with writing some code, I don't have all day! You're close, but I prefer to help out the guy with the brilliant idea (I know it's brilliant because he says so) who is offering me a fraction of the fortune he is going to make once I've done all the work... From alain at dpt-info.u-strasbg.fr Tue Aug 14 05:06:31 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 14 Aug 2012 11:06:31 +0200 Subject: print(....,file=sys.stderr) buffered? References: <50291a41$0$3122$ba620e4c@news.skynet.be> <50292b78$0$3122$ba620e4c@news.skynet.be> Message-ID: <871uj9rgfc.fsf@dpt-info.u-strasbg.fr> Helmut Jarausch writes: > On Mon, 13 Aug 2012 15:43:31 +0000, Grant Edwards wrote: > >> On 2012-08-13, Helmut Jarausch wrote: >>> Hi, >>> >>> for tracing purposes I have added some print outs like >>> >>> print('+++ before calling foo',file=sys.stderr) >>> x=foo(..) >>> print('--- after calling foo', > > Sorry, this is a cut'n paste error. I did use > print('--- after calling foo',file=sys.stderr) > >>> >>> and within 'foo' >>> print('>>> entering foo ...',file=sys.stderr) >>> >>> Now, when executing this, I always get >>> >>> +++ before calling foo >>> --- after calling foo >>>>>> entering foo ... This can't happen with "normal" code. Are you playing with lambdas or generators here? Or anything else that could introduce lazyness? -- Alain. From andrea.crotti.0 at gmail.com Tue Aug 14 05:10:27 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 14 Aug 2012 10:10:27 +0100 Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: 2012/8/13 Rob Day : > I'd just create a module - called shared_utils.py or similar - and import > that in both projects. It might be a bit messy if there's no 'unifying > theme' to the module - but surely it'd be a lot less messy than your > TempDirectory class, and anyone else who knows Python will understand > 'import shared_utils' much more easily. > > I realise you might not want to say, but if you could give some idea what > sort of projects these are, and what sorts of code you're trying to share, > it might make things a bit clearer. > > I'm not really sure what your concerns about 'versioning and how to link > different pieces together' are - what d you think could go wrong here? > It's actually not so simple.. Because the two projects live in different parts of the repository with different people allowed to work on them, and they have to run on different machines.. In plus I'm using perforce which doesn't have any svn:externals-like thing as far as I know.. The thing I should do probably is to set up workspace (which contains *absolute* paths of the machines) with the right setting to make module available in the right position. Second problem is that one of the two projects has a quite insane requirement, which is to be able to re-run itself on a specific version depending on a value fetched from the database. This becomes harder if divide code around, but in theory I can use the changeset number which is like a SVN revision so this should be fine. The third problem is that from the moment is not just me using these things, how can I be sure that changing something will not break someone else code? I have unit tests on both projects plus the tests for the utils, but as soon as I separate them it becomes harder to test everything.. So well everything can have a solution probably, I just hope it's worth the effort.. Another thing which would be quite cool might be a import hook which fetches things from the repository when needed, with a simple bootstrap script for every project to be able to use this feature, but it only makes sense if I need this kind of feature in many projects. From humingqiang5262131 at gmail.com Tue Aug 14 05:23:30 2012 From: humingqiang5262131 at gmail.com (mingqiang hu) Date: Tue, 14 Aug 2012 17:23:30 +0800 Subject: something about split()??? Message-ID: I have a question about the split function? surpose a = "|",and when I use a.split("|") , I got the list ['"",""] ,but I want to get the empty list,what should I do ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From simoncropper at fossworkflowguides.com Tue Aug 14 05:32:10 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Tue, 14 Aug 2012 19:32:10 +1000 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: References: <5029F159.5090802@fossworkflowguides.com> Message-ID: <502A1B1A.4060505@fossworkflowguides.com> On 14/08/12 18:19, Peter Otten wrote: > Simon Cropper wrote: > >> Hi Everyone, >> >> I just had a great idea for a new python module. I haven't bothered >> googling it or doing any research. >> >> I need help putting together some code; today preferably, my boss is on >> my back. Can someone please contribute a functioning module showing me >> how to do it? >> >> Once I have all your submissions, I will compile a functioning package, >> which I hope to sell. Don't worry, no one will be at risk of being sued, >> I don't intend to credit you with the code and you will not know >> anything about what I have done because I don't intend to post and >> feedback to the list. Licenses are not a problem either, I don't believe >> in them and even if you find out I have plagiarized your stuff you have >> bub-kiss chance of suing me as I am in another jurisdiction. >> >> So, now you know where I am coming from, I would like to thank you for >> all your help. Remember though, I need help now, so please stop what you >> are doing and submit something quickly. I'm waiting... >> >> Still waiting... >> >> Hey, stop reading and get on with writing some code, I don't have all day! > > You're close, but I prefer to help out the guy with the brilliant idea (I > know it's brilliant because he says so) who is offering me a fraction of the > fortune he is going to make once I've done all the work... > Peter, You are right. Quite remiss of me. Anyone willing to contribute money to help with the compilation of the code will get a portion of the profits. Just send me your account details, name and address; and I will ensure, once I have been paid, that I will send you your cut! :) -- Simon From damon.w.register at lmco.com Tue Aug 14 05:43:27 2012 From: damon.w.register at lmco.com (Damon Register) Date: Tue, 14 Aug 2012 05:43:27 -0400 Subject: EXTERNAL: Re: pylagiarism -- Need help now! Please provide code... In-Reply-To: <502A1B1A.4060505@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> Message-ID: <502A1DBF.2010906@lmco.com> Thanks, I needed something to start the day on the positive side. On 8/14/2012 5:32 AM, Simon Cropper wrote: > Anyone willing to contribute money to help with the compilation of the code will get a portion of > the profits. Just send me your account details, name and address; and I will ensure, once I have > been paid, that I will send you your cut! :) You forgot about the part where you have leukemia and have only a month to live so you will leave all the profits to me. Damon Register From andreas.tawn at ubisoft.com Tue Aug 14 05:44:14 2012 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 14 Aug 2012 11:44:14 +0200 Subject: something about split()??? In-Reply-To: References: Message-ID: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> > I have a question about the split function? surpose a = "|",and when I use a.split("|") , I got the list > ['"",""] ,but I want to get the empty list,what should I do ? Something like... >>> [x for x in "|".split("|") if x] [] Cheers, Drea From __peter__ at web.de Tue Aug 14 06:27:36 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Aug 2012 12:27:36 +0200 Subject: pylagiarism -- Need help now! Please provide code... References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> Message-ID: Simon Cropper wrote: > Anyone willing to contribute money to help with the compilation of the > code will get a portion of the profits. Just send me your account > details, name and address; and I will ensure, once I have been paid, > that I will send you your cut! :) This is starting to look like a worthy endeavour... From breamoreboy at yahoo.co.uk Tue Aug 14 07:33:20 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 12:33:20 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: <5029bdfd$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> <5029bdfd$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/08/2012 03:54, Steven D'Aprano wrote: > On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: > >> On 13/08/2012 17:14, alex23 wrote: >>> On Aug 13, 10:37 pm, Mark Lawrence wrote: >>>> Why on your say so? >>> >>> My mistake, I didn't realise you wanted to sound so tedious. Knock >>> yourself out. >>> >>> >>> >> Yes m'lud. Do I lick your boots or polish them? > > > Children children, if you won't play nice don't play at all. You're > scaring away the people who are here to learn about Python. > Steven thanks for your comments, seriously for once, you've helped get my feet back on the ground where they belong. Everybody please accept my apologies for having gone OTT once again :( In my defence for mitigating circumstances I offer a combination of Asperger Syndrome and a new girl friend. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Aug 14 07:38:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 12:38:24 +0100 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/08/2012 04:00, Steven D'Aprano wrote: > On Tue, 14 Aug 2012 01:34:46 +0100, Mark Lawrence wrote: > >> When did you seek my permission to call me by my forename? > > Sheesh. It's 2012, not 1812. If you sign your posts with your full name, > you have to expect that people will call you "Mark" rather than "Mr > Lawrence" or "Lord High Mucky-Muck Grand Poohbar Lawrence" -- even if > they haven't been formally introduced. > > Mark, we're all human and the occasional snark is only to be expected, > but demanding that people ask permission to call you by your first name > in an informal forum like this crosses the line to total dickishness. > Chill out before you get yourself kill-filed into irrelevance. > > > For the record I was asked to use my full name rather than my user name on Python mailing lists. But see also my earlier reply to you on the "save dictionary to a file without brackets" thread. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Aug 14 07:46:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 12:46:12 +0100 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: <5029F159.5090802@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> Message-ID: On 14/08/2012 07:34, Simon Cropper wrote: > Hi Everyone, > > I just had a great idea for a new python module. I haven't bothered > googling it or doing any research. > [snip similar] > Well I fell for it, there I was thinking you were serious and right at the bottom you have a disclaimer saying it was tongue in cheek. You got me hook, line and sinker. :) -- Cheers. Mark Lawrence. From sagarnikam123 at gmail.com Tue Aug 14 07:49:05 2012 From: sagarnikam123 at gmail.com (sagarnikam123) Date: Tue, 14 Aug 2012 04:49:05 -0700 (PDT) Subject: how to fix error "Requires python(abi)=2.4" Message-ID: <1344944944950-4985031.post@n6.nabble.com> i am installing numpy on fedora with python 2.6,2.7 & 3.1 -- View this message in context: http://python.6.n6.nabble.com/how-to-fix-error-Requires-python-abi-2-4-tp4985031.html Sent from the Python - python-list mailing list archive at Nabble.com. From ben+python at benfinney.id.au Tue Aug 14 07:50:12 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 14 Aug 2012 21:50:12 +1000 Subject: EXTERNAL: Re: pylagiarism -- Need help now! Please provide code... References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> Message-ID: <877gt1g0az.fsf@benfinney.id.au> Damon Register writes: > On 8/14/2012 5:32 AM, Simon Cropper wrote: > > Anyone willing to contribute money to help with the compilation of > > the code will get a portion of the profits. Just send me your > > account details, name and address; and I will ensure, once I have > > been paid, that I will send you your cut! :) > You forgot about the part where you have leukemia and have only a > month to live so you will leave all the profits to me. Surely he is the heir of a member of the royal family? And all he needs is 5% of the total amount deposited to open the account, after which the full amount of the inheritance will be transferred. -- \ ?I may disagree with what you say, but I will defend to the | `\ death your right to mis-attribute this quote to Voltaire.? | _o__) ?Avram Grumer, rec.arts.sf.written, 2000-05-30 | Ben Finney From rosuav at gmail.com Tue Aug 14 07:50:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Aug 2012 21:50:34 +1000 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: References: <5029F159.5090802@fossworkflowguides.com> Message-ID: On Tue, Aug 14, 2012 at 9:46 PM, Mark Lawrence wrote: > Well I fell for it, there I was thinking you were serious and right at the > bottom you have a disclaimer saying it was tongue in cheek. You got me > hook, line and sinker. :) At least you had the grace to admit that you were tricked :) I would fain have attached a Youtube link to my post, but couldn't find the clip I wanted. But I daresay most of you know the scene I quoted above, where Gaston kicks "crazy old Maurice" out of his tavern in Beauty and the Beast. ChrisA From breamoreboy at yahoo.co.uk Tue Aug 14 07:53:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 12:53:40 +0100 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: <502A1B1A.4060505@fossworkflowguides.com> References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> Message-ID: On 14/08/2012 10:32, Simon Cropper wrote: > On 14/08/12 18:19, Peter Otten wrote: >> Simon Cropper wrote: >> >>> Hi Everyone, >>> >>> I just had a great idea for a new python module. I haven't bothered >>> googling it or doing any research. >>> >>> I need help putting together some code; today preferably, my boss is on >>> my back. Can someone please contribute a functioning module showing me >>> how to do it? >>> >>> Once I have all your submissions, I will compile a functioning package, >>> which I hope to sell. Don't worry, no one will be at risk of being sued, >>> I don't intend to credit you with the code and you will not know >>> anything about what I have done because I don't intend to post and >>> feedback to the list. Licenses are not a problem either, I don't believe >>> in them and even if you find out I have plagiarized your stuff you have >>> bub-kiss chance of suing me as I am in another jurisdiction. >>> >>> So, now you know where I am coming from, I would like to thank you for >>> all your help. Remember though, I need help now, so please stop what you >>> are doing and submit something quickly. I'm waiting... >>> >>> Still waiting... >>> >>> Hey, stop reading and get on with writing some code, I don't have all >>> day! >> >> You're close, but I prefer to help out the guy with the brilliant idea (I >> know it's brilliant because he says so) who is offering me a fraction >> of the >> fortune he is going to make once I've done all the work... >> > > Peter, > > You are right. Quite remiss of me. > > Anyone willing to contribute money to help with the compilation of the > code will get a portion of the profits. Just send me your account > details, name and address; and I will ensure, once I have been paid, > that I will send you your cut! :) > Password as well just to be sure? Details of your security setup? How do I write a Python code snippet to calculate any number in any currency times zero? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Aug 14 07:55:47 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 12:55:47 +0100 Subject: pylagiarism -- Need help now! Please provide code... In-Reply-To: References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> Message-ID: On 14/08/2012 11:27, Peter Otten wrote: > Simon Cropper wrote: > >> Anyone willing to contribute money to help with the compilation of the >> code will get a portion of the profits. Just send me your account >> details, name and address; and I will ensure, once I have been paid, >> that I will send you your cut! :) > > This is starting to look like a worthy endeavour... > > I've just worked out what's going on, its the PSU trying to raise more funds. What a devious scheme, I love it!!! -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Tue Aug 14 08:44:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 12:44:13 GMT Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502a481d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Aug 2012 12:38:24 +0100, Mark Lawrence wrote: > On 14/08/2012 04:00, Steven D'Aprano wrote: [...] > For the record I was asked to use my full name rather than my user name > on Python mailing lists. But see also my earlier reply to you on the > "save dictionary to a file without brackets" thread. And thank you for your reasonable reply. I don't remember anything about this request to use your full name. I won't speak for others, but I support the right of people to be known by whatever (reasonable, non-offensive) name or names they choose on informal mailing lists like this, so long as they give *some* moniker that others can refer to them by. If somebody here wants to be known as "Mr Smith", or "Professor Jones", or "Tomato Girl the Boy Wonder" for that matter, then they need only sign their posts that way and give that in their From address, and I will use it. The pattern "Personal-Name Family-Name" is not the only naming system in the world. http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ (However, I don't promise not to roll my eyes if they choose a silly moniker, and I am the final arbitrator as to what counts as silly.) -- Steven From maniandram01 at gmail.com Tue Aug 14 09:31:08 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 14 Aug 2012 19:01:08 +0530 Subject: EXTERNAL: Re: pylagiarism -- Need help now! Please provide code... In-Reply-To: <877gt1g0az.fsf@benfinney.id.au> References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> <877gt1g0az.fsf@benfinney.id.au> Message-ID: Yes. On 14 August 2012 17:20, Ben Finney wrote: > Damon Register writes: > > > On 8/14/2012 5:32 AM, Simon Cropper wrote: > > > Anyone willing to contribute money to help with the compilation of > > > the code will get a portion of the profits. Just send me your > > > account details, name and address; and I will ensure, once I have > > > been paid, that I will send you your cut! :) > > You forgot about the part where you have leukemia and have only a > > month to live so you will leave all the profits to me. > > Surely he is the heir of a member of the royal family? And all he needs > is 5% of the total amount deposited to open the account, after which the > full amount of the inheritance will be transferred. > > -- > \ ?I may disagree with what you say, but I will defend to the | > `\ death your right to mis-attribute this quote to Voltaire.? | > _o__) ?Avram Grumer, rec.arts.sf.written, 2000-05-30 | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Tue Aug 14 09:31:28 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 14 Aug 2012 19:01:28 +0530 Subject: EXTERNAL: Re: pylagiarism -- Need help now! Please provide code... In-Reply-To: References: <5029F159.5090802@fossworkflowguides.com> <502A1B1A.4060505@fossworkflowguides.com> <877gt1g0az.fsf@benfinney.id.au> Message-ID: On 14 August 2012 19:01, Ramchandra Apte wrote: > Yes. > > > On 14 August 2012 17:20, Ben Finney wrote: > >> Damon Register writes: >> >> > On 8/14/2012 5:32 AM, Simon Cropper wrote: >> > > Anyone willing to contribute money to help with the compilation of >> > > the code will get a portion of the profits. Just send me your >> > > account details, name and address; and I will ensure, once I have >> > > been paid, that I will send you your cut! :) >> > You forgot about the part where you have leukemia and have only a >> > month to live so you will leave all the profits to me. >> >> Surely he is the heir of a member of the royal family? And all he needs >> is 5% of the total amount deposited to open the account, after which the >> full amount of the inheritance will be transferred. >> >> -- >> \ ?I may disagree with what you say, but I will defend to the | >> `\ death your right to mis-attribute this quote to Voltaire.? | >> _o__) ?Avram Grumer, rec.arts.sf.written, 2000-05-30 | >> Ben Finney >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Sorry for top-posting. -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Tue Aug 14 09:34:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 14 Aug 2012 19:04:17 +0530 Subject: something about split()??? In-Reply-To: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> Message-ID: (Much) more Pythonic solution: >>> filter(None,"|".split("|")) On 14 August 2012 15:14, Andreas Tawn wrote: > > I have a question about the split function? surpose a = "|",and when I > use a.split("|") , I got the list > > ['"",""] ,but I want to get the empty list,what should I do ? > > Something like... > > >>> [x for x in "|".split("|") if x] > [] > > Cheers, > > Drea > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Aug 14 10:34:23 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 14 Aug 2012 16:34:23 +0200 Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: <502A61EF.9070803@sequans.com> andrea crotti wrote: > I am in the situation where I am working on different projects that > might potentially share a lot of code. > > I started to work on project A, then switched completely to project B > and in the transiction I copied over a lot of code with the > corresponding tests, and I started to modify it. > > Now it's time to work again on project A, but I don't want to copy > things over again. > > I would like to design a simple and nice way to share between projects, > where the things I want to share are simple but useful things as for > example: > > class TempDirectory: > """Create a temporary directory and cd to it on enter, cd back to > the original position and remove it on exit > """ > def __init__(self): > self.oldcwd = getcwd() > self.temp_dir = mkdtemp() > > def __enter__(self): > logger.debug("create and move to temp directory %s" % self.temp_dir) > return self.temp_dir > > def __exit__(self, type, value, traceback): > # I first have to move out > chdir(self.oldcwd) > logger.debug("removing the temporary directory and go back to > the original position %s" % self.temp_dir) > rmtree(self.temp_dir) > > > The problem is that there are functions/classes from many domains, so it > would not make much sense to create a real project, and the only name I > could give might be "utils or utilities".. > > In plus the moment the code is shared I must take care of versioning and > how to link different pieces together (we use perforce by the way). > > If then someone else except me will want to use these functions then of > course I'll have to be extra careful, designing really good API's and so > on, so I'm wondering where I should set the trade-off between ability to > share and burden to maintain.. > > Anyone has suggestions/real world experiences about this? > I can think of logilab-common (http://www.logilab.org/848/) Having a company-wide python module properly distributed is one to achieve your goal. Without distributing your module to the public, there's a way to have a pypi-like server runnning on your private network : http://pypi.python.org/pypi/pypiserver/ JM Note : looks like pypi.python.org is having some trouble, the above link is broken. Search for recent announcement about pypiserver. From alister.ware at ntlworld.com Tue Aug 14 11:05:14 2012 From: alister.ware at ntlworld.com (Alister) Date: Tue, 14 Aug 2012 15:05:14 GMT Subject: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <502429C3.5000600@tim.thechases.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> <5029bdfd$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 14 Aug 2012 12:33:20 +0100, Mark Lawrence wrote: > On 14/08/2012 03:54, Steven D'Aprano wrote: >> On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: >> >>> On 13/08/2012 17:14, alex23 wrote: >>>> On Aug 13, 10:37 pm, Mark Lawrence wrote: >>>>> Why on your say so? >>>> >>>> My mistake, I didn't realise you wanted to sound so tedious. Knock >>>> yourself out. >>>> >>>> >>>> >>> Yes m'lud. Do I lick your boots or polish them? >> >> >> Children children, if you won't play nice don't play at all. You're >> scaring away the people who are here to learn about Python. >> >> > Steven thanks for your comments, seriously for once, you've helped get > my feet back on the ground where they belong. > > Everybody please accept my apologies for having gone OTT once again :( > In my defence for mitigating circumstances I offer a combination of > Asperger Syndrome and a new girl friend. if you have a new girlfriend why on earth are you posting here, I can think of much more interesting things to do. (apologies for continuing off topic) -- Don't despair; your ideal lover is waiting for you around the corner. From steve+comp.lang.python at pearwood.info Tue Aug 14 11:35:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 15:35:53 GMT Subject: Sharing code between different projects? References: Message-ID: <502a7058$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Aug 2012 17:53:32 +0100, andrea crotti wrote: > I started to work on project A, then switched completely to project B > and in the transiction I copied over a lot of code with the > corresponding tests, and I started to modify it. > > Now it's time to work again on project A, but I don't want to copy > things over again. > > I would like to design a simple and nice way to share between projects, > where the things I want to share are simple but useful things as for > example: [...] > The problem is that there are functions/classes from many domains, so it > would not make much sense to create a real project, and the only name I > could give might be "utils or utilities".. I feel your pain. "Copy and paste" is perhaps the simplest, most seductive, and *worst* of the developer anti-patterns. I wish I had a solution to share with you, because I'm in the same position, but I don't. The best I have come up with is a combination of: 1) For really small code snippets, just forget about sharing code. If you need a five-line function Foo in ten projects, just re-write them (well, copy and paste them...) each time. Forget about trying to keep them syncronised. 2) For bigger functions/classes, put them in their own module which you can share across multiple projects. 3) Consider having a "utilities" module to include all the assorted bits and pieces. If your projects are in-house, then a utilities module makes more sense. If you're writing libraries for independent release, not so much. -- Steven From light1quark at gmail.com Tue Aug 14 11:38:15 2012 From: light1quark at gmail.com (light1quark at gmail.com) Date: Tue, 14 Aug 2012 08:38:15 -0700 (PDT) Subject: Strange behavior Message-ID: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. If I comment out 'startingList.remove(str);' the code runs with both strings beginning with 'x' being put in the xOnlyList. Using the print statement I noticed that the second string that begins with 'x' isn't even identified by the function. Why does this happen? def testFunc(startingList): xOnlyList = []; for str in startingList: if (str[0] == 'x'): print str; xOnlyList.append(str) startingList.remove(str) #this seems to be the problem print xOnlyList; print startingList testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) #Thanks for your help! From alain at dpt-info.u-strasbg.fr Tue Aug 14 11:59:42 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 14 Aug 2012 17:59:42 +0200 Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: <87lihhpiq9.fsf@dpt-info.u-strasbg.fr> light1quark at gmail.com writes: > However if you run the code you will notice only one of the strings > beginning with 'x' is removed from the startingList. > > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remove(str) #this seems to be the problem > print xOnlyList; > print startingList > testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) > > #Thanks for your help! Try with ['xasd', 'sefwr', 'xjkl', 'dfsews'] and you'll understand what happens. Also, have a look at: http://docs.python.org/reference/compound_stmts.html#the-for-statement You can't modify the list you're iterating on, better use another list to collect the result. -- Alain. P/S: str is a builtin, you'd better avoid assigning to it. From hansmu at xs4all.nl Tue Aug 14 12:32:38 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 14 Aug 2012 18:32:38 +0200 Subject: Arithmetic with Boolean values In-Reply-To: References: <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com> <7x4no96ib3.fsf@ruckus.brouhaha.com> <502791ea$0$29978$c3e8da3$5496439d@news.astraweb.com> <5027b852$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x393sxcz9.fsf@ruckus.brouhaha.com> Message-ID: <502a7da3$0$6936$e4fe514c@news2.news.xs4all.nl> On 12/08/12 22:13:20, Alister wrote: > On Sun, 12 Aug 2012 19:20:26 +0100, Mark Lawrence wrote: > >> On 12/08/2012 17:59, Paul Rubin wrote: >>>> which can be simplified to: >>>> for x in range(len(L)//2 + len(L)%2): >>> >>> for x in range(sum(divmod(len(L), 2))): ... >>> >>> >> So who's going to be first in with "and thou shalt not count to 4..."? > > Five is right out Neither count thou two, excepting that thou then proceed to three -- HansM From jeanmichel at sequans.com Tue Aug 14 13:09:50 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 14 Aug 2012 19:09:50 +0200 Subject: something about split()??? In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <502A865E.4030504@sequans.com> Ramchandra Apte wrote: > (Much) more Pythonic solution: > >>> filter(None,"|".split("|")) > > On 14 August 2012 15:14, Andreas Tawn > wrote: > > > I have a question about the split function? surpose a = "|",and > when I use a.split("|") , I got the list > > ['"",""] ,but I want to get the empty list,what should I do ? > > Something like... > > >>> [x for x in "|".split("|") if x] > [] > > Cheers, > > Drea > -- > http://mail.python.org/mailman/listinfo/python-list > > A pythonic answer would be bottom-posted :p JM PS : pylint raises a low warning about *filter* being non pythonic, http://pylint-messages.wikidot.com/messages:w0141 "les go?ts et les couleurs ne se discutent pas" From benjamin.kaplan at case.edu Tue Aug 14 13:16:59 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Aug 2012 10:16:59 -0700 Subject: how to fix error "Requires python(abi)=2.4" In-Reply-To: <1344944944950-4985031.post@n6.nabble.com> References: <1344944944950-4985031.post@n6.nabble.com> Message-ID: On Aug 14, 2012 4:51 AM, "sagarnikam123" wrote: > > i am installing numpy on fedora with python 2.6,2.7 & 3.1 > > > > -- Python bytecode and C interface are not compatible across versions. If you're trying to install a numpy binary that was compiled against 2.4, it won't work with newer versions. You either need to find binaries compiled against a version of python you have or compile numpy yourself -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Tue Aug 14 13:19:39 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 14 Aug 2012 18:19:39 +0100 Subject: Sharing code between different projects? In-Reply-To: <502A61EF.9070803@sequans.com> References: <502A61EF.9070803@sequans.com> Message-ID: 2012/8/14 Jean-Michel Pichavant : > > I can think of logilab-common (http://www.logilab.org/848/) > > Having a company-wide python module properly distributed is one to achieve > your goal. Without distributing your module to the public, there's a way to > have a pypi-like server runnning on your private network : > > http://pypi.python.org/pypi/pypiserver/ > > JM > > Note : looks like pypi.python.org is having some trouble, the above link is > broken. Search for recent announcement about pypiserver. > Thanks, yes we need something like this.. I'll copy the name probably, I prefer "common" to "utils/utilities".. From breamoreboy at yahoo.co.uk Tue Aug 14 14:15:27 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Aug 2012 19:15:27 +0100 Subject: save dictionary to a file without brackets. In-Reply-To: References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <5024cc52$0$29978$c3e8da3$5496439d@news.astraweb.com> <4a233182-7a94-4919-a315-fbabbc3ff5a2@hq10g2000pbc.googlegroups.com> <24898464-66a7-4d4d-bbf4-2ebc72fb8749@hq10g2000pbc.googlegroups.com> <5029bdfd$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 14/08/2012 16:05, Alister wrote: > On Tue, 14 Aug 2012 12:33:20 +0100, Mark Lawrence wrote: > >> On 14/08/2012 03:54, Steven D'Aprano wrote: >>> On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: >>> >>>> On 13/08/2012 17:14, alex23 wrote: >>>>> On Aug 13, 10:37 pm, Mark Lawrence wrote: >>>>>> Why on your say so? >>>>> >>>>> My mistake, I didn't realise you wanted to sound so tedious. Knock >>>>> yourself out. >>>>> >>>>> >>>>> >>>> Yes m'lud. Do I lick your boots or polish them? >>> >>> >>> Children children, if you won't play nice don't play at all. You're >>> scaring away the people who are here to learn about Python. >>> >>> >> Steven thanks for your comments, seriously for once, you've helped get >> my feet back on the ground where they belong. >> >> Everybody please accept my apologies for having gone OTT once again :( >> In my defence for mitigating circumstances I offer a combination of >> Asperger Syndrome and a new girl friend. > > if you have a new girlfriend why on earth are you posting here, I can > think of much more interesting things to do. > (apologies for continuing off topic) > Nothing is off topic here and I take your point, why am I posting here, I haven't played pat a cake in years :) -- Cheers. Mark Lawrence. From lists at cheimes.de Tue Aug 14 14:22:54 2012 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Aug 2012 20:22:54 +0200 Subject: New image and color management library for Python 2+3 Message-ID: Hello fellow Pythonistas, I'm looking for co-developers, testers, documentation writers and users for a new image library I created. The code is available at https://bitbucket.org/tiran/smc.freeimage Background story: I'm working for a company that creates Python based solutions for libraries -- these large buildings containg millions of books. One major area of operation is the digitalization of books, prints and manuscripts from the last millennium. We are a major player in the German speaking countries with several hundred Terabytes of images on all our installations. Several years ago I began to write a Python interface for FreeImage because I was unhappy with the speed and capabilities of PIL. We had to check and convert several hundred GB of TIFF images to up to 15 sizes each and store them as JPEG every week. FreeImage offered more features and speed. Cython made it possible to integrate FreeImage into our software stack nicely. Later LittleCMS was integrated as color management solution to convert images from the scanners' color space into sRGB. During the development of smc.freeimage I also created a fork of FreeImage that wraps libjpeg-turbo instead of libjpeg. In my opinion the project is useful for other people because it has some benefits over PIL. For example it supports modern file formats that aren't supported by PIL, for example JPEG 2000, HDR formats and RAW camera formats. Contrary to PIL it even supports G3 and G4 compressed TIIFs as well as multipage TIFFs. In some areas it's also much faster than PIL, especially JPEG performance and NumPy buffer access. However it's not going to replace PIL as neither FreeImage nor my code supports drawing, text composition or extended filters. Excerpt from the README: Features of FreeImage ===================== FreeImage wraps mature and widely-used libraries like LibJPEG, LibOpenJPEG,LibPNG, LibRaw, LibTIFF4, OpenEXR and zlib in a consistent, well documented and powerful set of APIs. http://freeimage.sourceforge.net/ Reading of 35 file formats and writing of more than 19 file formats as of FreeImage 3.15.3, including JPEG 2000, multiple subformats of TIFF with G3/G4 fax compression and JPEG subsampling. pixel depths from 1-32 bpp standard images up to formats like RGBAF and 2x64complex. multi page images Metadata (e.g. EXIF, IPTC/NAA, GeoTIFF, XMP) and ICC Color adjustment, conversion and channel processing Image resizing and rotation High Dynamic Range (HDR) image processing and tone mapping RAW camera files Contrary to PIL it doesn't contain advanced image filters or drawing functions. FreeImage focuses on file formats Features of LCMS2 ================= LCMS2 is a color management engine that implements V2 and V4 ICC profiles up to V4.3. It supports transformation, proofing and introspection of profiles for a large variety of color formats and targets. http://www.littlecms.com/ Features of smc.freeimage ========================= smc.freeimage is developed as part of the closed source Visual Library framework. mostly written with Cython with some lines of handwritten C Code and some Python helpers. fast, it avoids copying large amounts of data and releases the GIL whenever possible. 64bit safe, tested on i386/X86 and AMD64/X86_64 systems thread safe wraps a large subset of FreeImage features Compatible with Python 2.6 to 3.3. Performance =========== smc.freeimage with libjpeg-turbo read JPEGs about three to six times faster than PIL and writes JPEGs more than five times faster. JPEG's restart markers are not compatible with libjpeg-turbo's Huffman decoder optimization and reduce performance a lot. Please read the section "Restart Makers" on the page http://www.libjpeg-turbo.org/About/Performance for more information. Python 2.7.3 read / write cycles: 300 test image: 1210x1778 24bpp JPEG (pon.jpg) platform: Ubuntu 12.04 X86_64 hardware: Intel Xeon hexacore W3680 at 3.33GHz with 24 GB RAM smc.freeimage, FreeImage 3.15.3 standard - read JPEG 12.857 sec - read JPEG 6.629 sec (resaved) - write JPEG 21.817 sec smc.freeimage, FreeImage 3.15.3 with jpeg turbo - read JPEG 9.297 sec - read JPEG 3.909 sec (resaved) - write JPEG 5.857 sec - read LZW TIFF 17.947 sec - read biton G4 TIFF 2.068 sec - resize 3.850 sec (box) - resize 5.022 sec (bilinear) - resize 7.942 sec (bspline) - resize 7.222 sec (bicubic) - resize 7.941 sec (catmull rom spline) - resize 10.232 sec (lanczos3) - tiff numpy.asarray() with bytescale() 0.006 sec - tiff load + numpy.asarray() with bytescale() 18.043 sec PIL 1.1.7 - read JPEG 30.389 sec - read JPEG 23.118 sec (resaved) - write JPEG 34.405 sec - read LZW TIFF 21.596 sec - read biton G4 TIFF: decoder group4 not available - resize 0.032 sec (nearest) - resize 1.074 sec (bilinear) - resize 2.924 sec (bicubic) - resize 8.056 sec (antialias) - tiff scipy fromimage() with bytescale() 1.165 sec - tiff scipy imread() with bytescale() 22.939 sec Comparison to PIL (Pros and Cons) ================================= Pros of smc.freeimage --------------------- Faster! JPEG performance is about 3 to 6 times faster than PIL, numpy buffer access is more than 100 times faster and consumes less memory due to zero copy design. Modern file formats! smc.freeimage supports JPEG 2000, HDR and EXR high dynamic range images and raw camera data (RAW). Full baseline TIFF support! Contrary to PIL smc.freeimage supports all flavors of baseline TIFF like G3 and G4 compression and multipage TIFFs. PEP 3118 buffer interface that exports images as 2d or 3d non-contiguous buffer. Correct and optimized integration of a color management system (LittleCMS2)instead of lcms1 integration including caching of optimized transformations, in-place transformation and introspection of profiles. Structured metadata access to EXIF, XMP and IPTC information, also supports fast loading of metadata without loading pixel data. Lot's of color types! Bitmap (8bit) with 1, 4, 8, 16, 24 and 32 bits per pixel, (unsigned) int 16 and 32, float, double gray scale, complex, RGBA 16bit and RGBA floats. Static build support, no need for "make install". You just need a C99 compatible C/C++ compiler, make and nasm (for FreeImage-Turob). Cons of smc.freeimage ---------------------- Few image filters, no support for complex image filters in FreeImage Low quality resize filters are slower than PIL's filters No drawing API for primitives (lines, circles, boxes) No text drawing support and libfreetype integration. Still not feature complete and under development. FreeImage + libjpeg-turbo ========================= An experimental fork of FreeImage with libjpeg-turbo is available at https://bitbucket.org/tiran/freeimageturbo Feel free to contact me if you are interested in the library or want to get involved! Christian From tjreedy at udel.edu Tue Aug 14 15:05:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 14 Aug 2012 15:05:43 -0400 Subject: Strange behavior In-Reply-To: <87lihhpiq9.fsf@dpt-info.u-strasbg.fr> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <87lihhpiq9.fsf@dpt-info.u-strasbg.fr> Message-ID: On 8/14/2012 11:59 AM, Alain Ketterlin wrote: > light1quark at gmail.com writes: > >> However if you run the code you will notice only one of the strings >> beginning with 'x' is removed from the startingList. > >> >> def testFunc(startingList): >> xOnlyList = []; >> for str in startingList: >> if (str[0] == 'x'): >> print str; >> xOnlyList.append(str) >> startingList.remove(str) #this seems to be the problem >> print xOnlyList; >> print startingList >> testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) >> >> #Thanks for your help! > > Try with ['xasd', 'sefwr', 'xjkl', 'dfsews'] and you'll understand what > happens. Also, have a look at: > > http://docs.python.org/reference/compound_stmts.html#the-for-statement > > You can't modify the list you're iterating on, Except he obviously did ;-). (Modifying set or dict raises SomeError.) Indeed, people routine *replace* items while iterating. def squarelist(lis): for i, n in enumerate(lis): lis[i] = n*n return lis print(squarelist([0,1,2,3,4,5])) # [0, 1, 4, 9, 16, 25] Removals can be handled by iterating in reverse. This works even with duplicates because if the item removed is not the one tested, the one tested gets retested. def removeodd(lis): for n in reversed(lis): if n % 2: lis.remove(n) print(n, lis) ll = [0,1, 5, 5, 4, 5] removeodd(ll) >>> 5 [0, 1, 5, 4, 5] 5 [0, 1, 4, 5] 5 [0, 1, 4] 4 [0, 1, 4] 1 [0, 4] 0 [0, 4] > better use another list to collect the result. If there are very many removals, a new list will be faster, even if one needs to copy the new list back into the original, as k removals from len n list is O(k*n) versus O(n) for new list and copy. > P/S: str is a builtin, you'd better avoid assigning to it. Agreed. People have actually posted code doing something like ... list = [1,2,3] ... z = list(x) ... and wondered and asked why it does not work. -- Terry Jan Reedy From light1quark at gmail.com Tue Aug 14 15:20:24 2012 From: light1quark at gmail.com (light1quark at gmail.com) Date: Tue, 14 Aug 2012 12:20:24 -0700 (PDT) Subject: Strange behavior In-Reply-To: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: <03e72fb4-ca09-403f-b742-a884f8316809@googlegroups.com> I got my answer by reading your posts and referring to: http://docs.python.org/reference/compound_stmts.html#the-for-statement (particularly the shaded grey box) I guess I should have (obviously) looked at the doc's before posting here; but im a noob. Thanks for your help. From vs at it.uu.se Tue Aug 14 15:34:00 2012 From: vs at it.uu.se (Virgil Stokes) Date: Tue, 14 Aug 2012 21:34:00 +0200 Subject: Fwd: Re: Strange behavior In-Reply-To: <502AA7C0.4040803@it.uu.se> References: <502AA7C0.4040803@it.uu.se> Message-ID: <502AA828.1070008@it.uu.se> -------- Original Message -------- Subject: Re: Strange behavior Date: Tue, 14 Aug 2012 21:32:16 +0200 From: Virgil Stokes To: light1quark at gmail.com On 2012-08-14 17:38, light1quark at gmail.com wrote: > Hi, I am migrating from PHP to Python and I am slightly confused. > > I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. > > However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. > If I comment out 'startingList.remove(str);' the code runs with both strings beginning with 'x' being put in the xOnlyList. > Using the print statement I noticed that the second string that begins with 'x' isn't even identified by the function. Why does this happen? > > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remove(str) #this seems to be the problem > print xOnlyList; > print startingList > testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) > > #Thanks for your help! You might find the following useful: def testFunc(startingList): xOnlyList = []; j = -1 for xl in startingList: if (xl[0] == 'x'): xOnlyList.append(xl) else: j += 1 startingList[j] = xl if j == -1: startingList = [] else: del startingList[j:-1] return(xOnlyList) testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] xOnlyList = testFunc(testList1) print 'xOnlyList = ',xOnlyList print 'testList = ',testList1 xOnlyList = testFunc(testList2) print 'xOnlyList = ',xOnlyList print 'testList = ',testList2 xOnlyList = testFunc(testList3) print 'xOnlyList = ',xOnlyList print 'testList = ',testList3 xOnlyList = testFunc(testList4) print 'xOnlyList = ',xOnlyList print 'testList = ',testList4 And here is another version using list comprehension that I prefer testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] def testFunc2(startingList): return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) xOnlyList,testList = testFunc2(testList1) print xOnlyList print testList xOnlyList,testList = testFunc2(testList2) print xOnlyList print testList xOnlyList,testList = testFunc2(testList3) print xOnlyList print testList xOnlyList,testList = testFunc2(testList4) print xOnlyList print testList -------------- next part -------------- An HTML attachment was scrubbed... URL: From vs at it.uu.se Tue Aug 14 15:40:10 2012 From: vs at it.uu.se (Virgil Stokes) Date: Tue, 14 Aug 2012 21:40:10 +0200 Subject: Strange behavior In-Reply-To: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: <502AA99A.2050807@it.uu.se> On 2012-08-14 17:38, light1quark at gmail.com wrote: > Hi, I am migrating from PHP to Python and I am slightly confused. > > I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. > > However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. > If I comment out 'startingList.remove(str);' the code runs with both strings beginning with 'x' being put in the xOnlyList. > Using the print statement I noticed that the second string that begins with 'x' isn't even identified by the function. Why does this happen? > > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remove(str) #this seems to be the problem > print xOnlyList; > print startingList > testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) > > #Thanks for your help! You might find the following useful: def testFunc(startingList): xOnlyList = []; j = -1 for xl in startingList: if (xl[0] == 'x'): xOnlyList.append(xl) else: j += 1 startingList[j] = xl if j == -1: startingList = [] else: del startingList[j:-1] return(xOnlyList) testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] xOnlyList = testFunc(testList1) print 'xOnlyList = ',xOnlyList print 'testList = ',testList1 xOnlyList = testFunc(testList2) print 'xOnlyList = ',xOnlyList print 'testList = ',testList2 xOnlyList = testFunc(testList3) print 'xOnlyList = ',xOnlyList print 'testList = ',testList3 xOnlyList = testFunc(testList4) print 'xOnlyList = ',xOnlyList print 'testList = ',testList4 And here is another version using list comprehension that I prefer testList1 = ['xasd', 'xjkl', 'sefwr', 'dfsews'] testList2 = ['xasd', 'xjkl', 'xsefwr', 'xdfsews'] testList3 = ['xasd', 'jkl', 'sefwr', 'dfsews'] testList4 = ['asd', 'jkl', 'sefwr', 'dfsews'] def testFunc2(startingList): return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) xOnlyList,testList = testFunc2(testList1) print xOnlyList print testList xOnlyList,testList = testFunc2(testList2) print xOnlyList print testList xOnlyList,testList = testFunc2(testList3) print xOnlyList print testList xOnlyList,testList = testFunc2(testList4) print xOnlyList print testList From PointedEars at web.de Tue Aug 14 16:47:57 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 14 Aug 2012 22:47:57 +0200 Subject: [OT] A short Usenet primer (was: How to uncompress a VOB file? (Win XP)) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> Message-ID: <2662730.2zdq91zsVA@PointedEars.de> Mark Lawrence wrote: > On 14/08/2012 00:00, Xantipius wrote: >> On Aug 13, 3:40 pm, Mark Lawrence wrote: >>> On 13/08/2012 11:18, Xantipius wrote: >>>> subj >>> >>> Either >>> >>> a) write some code and when and if it fails give us a small code snippet >>> that demonstates the problem with the complete traceback. >>> >>> or >>> >>> b) state how much you are willing to pay for someone here to come up >>> with a solution for you. >> >> Mark, in regard your last remark: >> it's just a recreation for me. Nothing more in it. >> I like to put some weird and useless problems before myself. > > Is it [?] normal practice to communicate with yourself via a public > mailing list/news group? No, it is not. However, I would not expect too much from a Google Groups user who posts under pseudonym without a reasonable message body. Probably they are not even aware that they are on Usenet, thinking that they are posting to a Web forum instead. > When did you seek my permission to call me by my forename? AIUI, in English (which is not my native language), it is customary that peers call themselves by their first names (in other languages, too). This does not necessarily indicate familiarity. We are all peers on/in this mailing list/newsgroup working on different aspects of the same problem: learning how to write good Python programs. So you should not be surprised to be called and referred to by your first name or nick name. In fact, on Usenet it is usually considered an appreciation of the person so addressed *not* to use their last name. If you are called by someone by your last name only, you probably did that someone very wrong (or encountered a hypersensitive entity, or you are being trolled; depends). However, communication that really only concerns two people should be limited to private e-mail (which is what the mandatory address header fields are for). (I think this one should be public, for other newbies.) HTH. And trim your quotes to the relevant minimum, please. -- PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From dihedral88888 at googlemail.com Tue Aug 14 17:08:46 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 14 Aug 2012 14:08:46 -0700 (PDT) Subject: looking for a neat solution to a nested loop problem In-Reply-To: References: Message-ID: <0207a924-6c0c-42eb-9f1e-3a07bb3097b1@googlegroups.com> Nobody? 2012?8?7????UTC+8??11?32?55???? > On Mon, 06 Aug 2012 21:02:33 -0700, Larry Hudson wrote: > > > > >> for i in range(N,N+100): > > >> for j in range(M,M+100): > > >> do_something(i % 100 ,j % 100) > > >> > > >> Emile > > > > > > How about... > > > > > > for i in range(100): > > > for j in range(100): > > > do_something((i + N) % 100, (j + M) % 100) > > > > Both of these approaches move the modifications to the sequence into the > > body of the loop. It may be preferable to iterate over the desired > > sequence directly. E.g. > > > > for i in ((N + ii) % 100 for ii in xrange(100)): > > for j in ((M + jj) % 100 for jj in xrange(100)): > > do_something(i, j) I'll contrubute another version by the xrange function in python. for i in xrange(N, N+100): # not list based if i<100: i2=i else: i2=i-100 # not in the inner most loop for j in xrange(M, M+100): if j<100: j2=j else: j2=j-100 do_something(i2,j2) From PointedEars at web.de Tue Aug 14 17:12:30 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 14 Aug 2012 23:12:30 +0200 Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1726797.uF9SroCjta@PointedEars.de> Mark Lawrence wrote: > On 14/08/2012 04:00, Steven D'Aprano wrote: >> On Tue, 14 Aug 2012 01:34:46 +0100, Mark Lawrence wrote: >>> When did you seek my permission to call me by my forename? >> Sheesh. It's 2012, not 1812. If you sign your posts with your full name, >> you have to expect that people will call you "Mark" rather than "Mr >> Lawrence" or "Lord High Mucky-Muck Grand Poohbar Lawrence" -- even if >> they haven't been formally introduced. >> >> Mark, we're all human and the occasional snark is only to be expected, >> but demanding that people ask permission to call you by your first name >> in an informal forum like this crosses the line to total dickishness. >> Chill out before you get yourself kill-filed into irrelevance. > > For the record I was asked to use my full name rather than my user name > on Python mailing lists. Apples and oranges. Probably you were asked that so that your postings could be distinguished from that of the other potential Marks around here. Some people, including me, also consider posting under real name a basic act of politeness and form towards the reader, equivalent of an introduction of oneself. Important enouth that, if not showed, will reduce the probability for an answer (sometimes down to zero). For the record shows that if one aspect of politeness is ignored, other aspects are usually ignored as well. People tend to hide behind pseudo-anonymity; they tend to write impolite things *intentionally* which they would not do if their real name was known and so their reputation IRL would be at stake. Here endeth the lesson ;-) -- PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Tue Aug 14 17:46:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 07:46:31 +1000 Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) In-Reply-To: <1726797.uF9SroCjta@PointedEars.de> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> Message-ID: On Wed, Aug 15, 2012 at 7:12 AM, Thomas 'PointedEars' Lahn wrote: > Probably you were asked that so that your postings could be distinguished > from that of the other potential Marks around here. I have my surname in my From address, but I tend to sign my posts "ChrisA" (no relation, btw, to DaveA, though our surnames are similar). That's generally been sufficient for distinguishing purposes, though if anyone wants a truly unique handle for me, "Rosuav" is more effective than my real name. > Some people, including > me, also consider posting under real name a basic act of politeness... People > tend to hide behind pseudo-anonymity; they tend to write impolite things > *intentionally* which they would not do if their real name was known and so > their reputation IRL would be at stake. Agreed. Sometimes that's a good thing; there are places where anonymity protection is important. But with these sorts of lists, there's the potential to acquire a strong positive or strong negative reputation; people who want a positive reputation usually want it associated with *them*, not with some pseudonym. Though I'm now not so sure about your name, PointedEars. Are you a Vulcan or an elf? ChrisA From cs at zip.com.au Tue Aug 14 17:51:18 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 15 Aug 2012 07:51:18 +1000 Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: <20120814215118.GA19167@cskk.homeip.net> On 13Aug2012 17:53, andrea crotti wrote: | I am in the situation where I am working on different projects that | might potentially share a lot of code. | | I started to work on project A, then switched completely to project B | and in the transiction I copied over a lot of code with the | corresponding tests, and I started to modify it. | | Now it's time to work again on project A, but I don't want to copy | things over again. [...] | The problem is that there are functions/classes from many domains, so it | would not make much sense to create a real project, and the only name I | could give might be "utils or utilities".. | | In plus the moment the code is shared I must take care of versioning and | how to link different pieces together (we use perforce by the way). [...] Having just skimmed this thread, one thing I haven't quite seen suggested is this: Really do make a third "utilities" project, and treat "the project" and "deploy" as separate notions. So to actually run/deploy project A's code you'd have a short script that copied project A and the utilities project code into a tree and ran off that. Or even a simple process/script to update the copy of "utilities" in "project A"'s area. So you don't "share" code on an even handed basis but import the "utilities" library into each project as needed. I do this (one my own very small scale) in one of two ways: - as needed, copy the desired revision of utilities into the project's library space and do perforce's equivalent of Mercurial's addremove on that library tree (comment "update utilities to revision X"). - keep a perforce work area for the utilities in your project A area, where your working project A can hook into it with a symlink or some deploy/copy procedure as suggested above. With this latter one you can push back into the utilities library from your "live" project, because you have a real checkout. So: projectAdir projectA-perforce-checkout utilities-perforce-checkout projectBdir projectB-perforce-checkout utilities-perforce-checkout Personally I become more and more resistent to cut/paste even for small things as soon as multiple people use it; you will never get to backport updates to even trivial code to all the copies. Cheers, -- Cameron Simpson The mere existence of a problem is no proof of the existence of a solution. - Yiddish Proverb From rosuav at gmail.com Tue Aug 14 17:55:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 07:55:58 +1000 Subject: Strange behavior In-Reply-To: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: On Wed, Aug 15, 2012 at 1:38 AM, wrote: > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remove(str) #this seems to be the problem > print xOnlyList; > print startingList > testFunc(['xasd', 'xjkl', 'sefwr', 'dfsews']) Other people have explained the problem with your code. I'll take this example as a way of introducing you to one of Python's handy features - it's an idea borrowed from functional languages, and is extremely handy. It's called the "list comprehension", and can be looked up in the docs under that name, def testFunc(startingList): xOnlyList = [strng for strng in startingList if strng[0] == 'x'] startingList = [strng for strng in startingList if strng[0] != 'x'] print(xOnlyList) print(startingList) It's a compact notation for building a list from another list. (Note that I changed "str" to "strng" to avoid shadowing the built-in name "str", as others suggested.) (Unrelated side point: Putting parentheses around the print statements makes them compatible with Python 3, in which 'print' is a function. Unless something's binding you to Python 2, consider working with the current version - Python 2 won't get any more features added to it any more.) Python's an awesome language. You may have to get your head around a few new concepts as you shift thinking from PHP's, but it's well worth while. Chris Angelico From steve+comp.lang.python at pearwood.info Tue Aug 14 19:55:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Aug 2012 23:55:03 GMT Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> Message-ID: <502ae557$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 07:46:31 +1000, Chris Angelico wrote: > I have my surname in my From address, but I tend to sign my posts > "ChrisA" (no relation, btw, to DaveA, though our surnames are similar). > That's generally been sufficient for distinguishing purposes, though if > anyone wants a truly unique handle for me, "Rosuav" is more effective > than my real name. Mom? Is that you? -- Steven From steve+comp.lang.python at pearwood.info Tue Aug 14 20:19:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Aug 2012 00:19:55 GMT Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: > You might find the following useful: > > def testFunc(startingList): > xOnlyList = []; j = -1 > for xl in startingList: > if (xl[0] == 'x'): That's going to fail in the starting list contains an empty string. Use xl.startswith('x') instead. > xOnlyList.append(xl) > else: > j += 1 > startingList[j] = xl Very cunning, but I have to say that your algorithm fails the "is this obviously correct without needing to study it?" test. Sometimes that is unavoidable, but for something like this, there are simpler ways to solve the same problem. > if j == -1: > startingList = [] > else: > del startingList[j:-1] > return(xOnlyList) > And here is another version using list comprehension that I prefer > def testFunc2(startingList): > return([x for x in startingList if x[0] == 'x'], [x for x in > startingList if x[0] != 'x']) This walks over the starting list twice, doing essentially the same thing both times. It also fails to meet the stated requirement that startingList is modified in place, by returning a new list instead. Here's an example of what I mean: py> mylist = mylist2 = ['a', 'x', 'b', 'xx', 'cx'] # two names for one list py> result, mylist = testFunc2(mylist) py> mylist ['a', 'b', 'cx'] py> mylist2 # should be same as mylist ['a', 'x', 'b', 'xx', 'cx'] Here is the obvious algorithm for extracting and removing words starting with 'x'. It walks the starting list only once, and modifies it in place. The only trick needed is list slice assignment at the end. def extract_x_words(words): words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) words[:] = words_without_x # slice assignment return words_with_x The only downside of this is that if the list of words is so enormous that you can fit it in memory *once* but not *twice*, this may fail. But the same applies to the list comprehension solution. -- Steven From rosuav at gmail.com Tue Aug 14 21:44:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 11:44:29 +1000 Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) In-Reply-To: <502ae557$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <502ae557$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 15, 2012 at 9:55 AM, Steven D'Aprano wrote: > On Wed, 15 Aug 2012 07:46:31 +1000, Chris Angelico wrote: > >> I have my surname in my From address, but I tend to sign my posts >> "ChrisA" (no relation, btw, to DaveA, though our surnames are similar). >> That's generally been sufficient for distinguishing purposes, though if >> anyone wants a truly unique handle for me, "Rosuav" is more effective >> than my real name. > > Mom? Is that you? Eh? I'm guessing that's a reference to something that I'm not familiar with? ChrisA From PointedEars at web.de Tue Aug 14 22:06:08 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 15 Aug 2012 04:06:08 +0200 Subject: [OT] Posting under ones full name References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> Message-ID: <12344088.tLP8bKVGp5@PointedEars.de> Chris Angelico wrote: > Thomas 'PointedEars' Lahn wrote: >> Probably you were asked that so that your postings could be distinguished >> from that of the other potential Marks around here. > > I have my surname in my From address, but I tend to sign my posts > "ChrisA" (no relation, btw, to DaveA, though our surnames are > similar). That's generally been sufficient for distinguishing > purposes, though if anyone wants a truly unique handle for me, > "Rosuav" is more effective than my real name. For one to read your signature, one has to download and read your entire posting first. >> Some people, including me, also consider posting under real name a basic >> act of politeness... Please use `[...]' or `[?]' to indicate omission instead. I could have written `politeness...' myself. >> People tend to hide behind pseudo-anonymity; they tend to write impolite >> things *intentionally* which they would not do if their real name was >> known and so their reputation IRL would be at stake. > > Agreed. Sometimes that's a good thing; there are places where > anonymity protection is important. But with these sorts of lists, > there's the potential to acquire a strong positive or strong negative > reputation; people who want a positive reputation usually want it > associated with *them*, not with some pseudonym. ACK. > Though I'm now not so sure about your name, PointedEars. Are you a > Vulcan or an elf? That is a stupid question. -- F'up2 PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From dreadpiratejeff at gmail.com Tue Aug 14 22:55:27 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 14 Aug 2012 22:55:27 -0400 Subject: Flushing buffer on file copy on linux Message-ID: I was hoping someone could give me some ideas for a particular problem. I've got a python program that is used for basic testing of removable storage devices (usb, mmc, firewire, etc). Essentially, it looks for a mounted device (either user specified, or if not, the program loops through all removable disks), generates a file of random data of a predetermined size, does a md5sum of the parent, uses shutil copy() to copy the file to the device, then does a md5sum of the copy on removable media, compares, cleans up and Bob's your uncle. Now, I'm working on enhancements and one enhancement is a threaded "stress test" that will perform the exact same operations, but in individual threads. So if you the script to do 10 iterations using 10MB files, instead of doing 10 loops, it does 10 concurrent threads (I'm new to doing threads so this is a learning experience there as well). Now, the problem I have is that linux tends to buffer data writes to a device, and I want to work around that. When run in normal non-stress mode, the program is slow enough that the linux buffers flush and put the file on disk before the hash occurs. However, when run in stress mode, what I'm finding is that it appears that the files are possibly being hashed while still in the buffer, before being flushed to disk. So ultimately, I wanted to see if there were some ideas for working around this issue. One idea I had was to do the following: Generate the parent data file hash parent instead of copy, open parent and write to a new file object on disk with a 0 size buffer or flush() before close() hash the copy. Does that seem reasonable? or is there a cleaner way to copy a file from one place to another and ensure the buffers are properly flushed (maybe something in os or sys that forces file buffers to be flushed?) Anyway, I'd appreciate any suggestions with that. I'll try implementing the idea mentioned above tomorrow, but if there's a cleaner way I'd be interested in learning it. Cheers, jeff From cs at zip.com.au Tue Aug 14 23:09:59 2012 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 15 Aug 2012 13:09:59 +1000 Subject: Flushing buffer on file copy on linux In-Reply-To: References: Message-ID: <20120815030959.GA7546@cskk.homeip.net> On 14Aug2012 22:55, J wrote: | Now, the problem I have is that linux tends to buffer data writes to a | device, and I want to work around that. To what _specific_ purpose? Benchmarking? Ensuring the device can be pulled? Ensuring another program can see the data? (The last should be taken care of regardless of the Linux OS level buffering.) | When run in normal non-stress | mode, the program is slow enough that the linux buffers flush and put | the file on disk before the hash occurs. However, when run in stress | mode, what I'm finding is that it appears that the files are possibly | being hashed while still in the buffer, before being flushed to disk. You're probably right, but how are you inferring this? | Generate the parent data file | hash parent | instead of copy, open parent and write to a new file object on disk | with a 0 size buffer | or flush() before close() | hash the copy. | | Does that seem reasonable? or is there a cleaner way to copy a file | from one place to another and ensure the buffers are properly flushed | (maybe something in os or sys that forces file buffers to be flushed?) For OS buffers you either want to call sync() (flushes _all_ OS buffers to disc before returning) or fsync(open-file-handle), which flushes at least the blocks for that file (in practice, typically everything outstanding for the same filesystem, alas). So look at os.fsync in python. You will need to do this after a python-level data flush but before file close: with open("output-file", "w") as fp: fp.write(lots of stuff)... fp.flush() os.fsync(fp.fileno) But be clear about your purpose: why do you care that the disc writes themselve are complete? There are legitimate reasons for this, but unless it is benchmarking or utterly mad (eg database) data integrity, they generally aren't:-) Cheers, -- Cameron Simpson English is a living language, but simple illiteracy is no basis for linguistic evolution. - Dwight MacDonald From rosuav at gmail.com Tue Aug 14 23:16:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 13:16:19 +1000 Subject: [OT] Posting under ones full name In-Reply-To: <12344088.tLP8bKVGp5@PointedEars.de> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> I have my surname in my From address, but I tend to sign my posts >> "ChrisA" (no relation, btw, to DaveA, though our surnames are >> similar). That's generally been sufficient for distinguishing >> purposes, though if anyone wants a truly unique handle for me, >> "Rosuav" is more effective than my real name. > > For one to read your signature, one has to download and read your entire > posting first. And my signature has less information than the headers. So you're not deprived of anything. >>> Some people, including me, also consider posting under real name a basic >>> act of politeness... > > Please use `[...]' or `[?]' to indicate omission instead. I could have > written `politeness...' myself. You might, indeed. But since the triple-period is a standard rendition of the grammatical notion of ellipsis, it's a generally-understood notation to indicate the possible omission of quoted text. >> Though I'm now not so sure about your name, PointedEars. Are you a >> Vulcan or an elf? > > That is a stupid question. Of course, my bad. The difference is obvious, I should have known which without asking. ChrisA From rosuav at gmail.com Tue Aug 14 23:18:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 13:18:11 +1000 Subject: [OT] Posting under ones full name In-Reply-To: <12344088.tLP8bKVGp5@PointedEars.de> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn wrote: > Please use `[...]' or `[?]' to indicate omission instead. I could have > written `politeness...' myself. Incidentally, how _do_ the square brackets help? Can a reader know that you put square-bracketed dots and that I didn't omit a lengthy quoted string? Perhaps you said "Please use `m4-style quotes rather than matching ASCII quotes' or `something else' to indicate omission instead". ChrisA From ben+python at benfinney.id.au Tue Aug 14 23:31:40 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 15 Aug 2012 13:31:40 +1000 Subject: How to uncompress a VOB file? (Win XP) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <502a481d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y5lgespv.fsf@benfinney.id.au> Steven D'Aprano writes: > (However, I don't promise not to roll my eyes if they choose a silly > moniker, and I am the final arbitrator as to what counts as silly.) I also don't promise to remember or comply with their request to be known by an egregiously silly moniker, with me as the sole arbiter of what counts as ?egregiously silly?. People have the right to ask to be known by a particular name, but they are obliged to be reasonable about how successful their request will be when they ask. -- \ ?I watched the Indy 500, and I was thinking that if they left | `\ earlier they wouldn't have to go so fast.? ?Steven Wright | _o__) | Ben Finney From rosuav at gmail.com Tue Aug 14 23:43:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 13:43:07 +1000 Subject: How to uncompress a VOB file? (Win XP) In-Reply-To: <87y5lgespv.fsf@benfinney.id.au> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <502a481d$0$29978$c3e8da3$5496439d@news.astraweb.com> <87y5lgespv.fsf@benfinney.id.au> Message-ID: On Wed, Aug 15, 2012 at 1:31 PM, Ben Finney wrote: > People have the right to ask to be known by a particular name, but they > are obliged to be reasonable about how successful their request will be > when they ask. Reminds me of what Torhelm said during one of our Dungeons and Dragons campaigns: Ancient D&D saying: "People who don't like nicknames shouldn't pick multisyllabic names." ChrisA From steve+comp.lang.python at pearwood.info Tue Aug 14 23:43:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Aug 2012 03:43:30 GMT Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <502ae557$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502b1ae1$0$29867$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 11:44:29 +1000, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 9:55 AM, Steven D'Aprano > wrote: >> On Wed, 15 Aug 2012 07:46:31 +1000, Chris Angelico wrote: >> >>> I have my surname in my From address, but I tend to sign my posts >>> "ChrisA" (no relation, btw, to DaveA, though our surnames are >>> similar). That's generally been sufficient for distinguishing >>> purposes, though if anyone wants a truly unique handle for me, >>> "Rosuav" is more effective than my real name. >> >> Mom? Is that you? > > Eh? > > I'm guessing that's a reference to something that I'm not familiar with? It was a joke, implying that my mother uses the same "truly unique" handle as you. With over 7 billion people on the planet, and no upper limit on the number of handles anyone can take, together with the lack of any definitive central registry, I wouldn't put money on any one of them being unique. It wouldn't surprise me to learn that now you have claimed Rosuav is unique to you, some wag (or wags) have rushed out and registered it on whatever Internet forums you haven't already done so on and are already posting "I am [insert childish insult of your choice]" in your name. -- Steven From ben+python at benfinney.id.au Tue Aug 14 23:56:59 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 15 Aug 2012 13:56:59 +1000 Subject: [OT] Posting under ones full name References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: <87txw4erjo.fsf@benfinney.id.au> Chris Angelico writes: > On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn > wrote: > > Please use `[...]' or `[?]' to indicate omission instead. I could > > have written `politeness...' myself. > > Incidentally, how _do_ the square brackets help? They are a long-standing convention for marking an editorial addition or clarification. Square brackets ? also called simply brackets (US) ? are mainly used to enclose explanatory or missing material usually added by someone other than the original author, especially in quoted text. -- \ ?What I resent is that the range of your vision should be the | `\ limit of my action.? ?Henry James | _o__) | Ben Finney From rosuav at gmail.com Wed Aug 15 00:07:55 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 14:07:55 +1000 Subject: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP)) In-Reply-To: <502b1ae1$0$29867$c3e8da3$5496439d@news.astraweb.com> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <502ae557$0$29978$c3e8da3$5496439d@news.astraweb.com> <502b1ae1$0$29867$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Aug 15, 2012 at 1:43 PM, Steven D'Aprano wrote: > It was a joke, implying that my mother uses the same "truly unique" > handle as you. > > With over 7 billion people on the planet, and no upper limit on the > number of handles anyone can take, together with the lack of any > definitive central registry, I wouldn't put money on any one of them > being unique. > > It wouldn't surprise me to learn that now you have claimed Rosuav is > unique to you, some wag (or wags) have rushed out and registered it on > whatever Internet forums you haven't already done so on and are already > posting "I am [insert childish insult of your choice]" in your name. Ah. Sure. I get that. But "Rosuav" is, as far as I know, unique to me in the entire English language. (I checked once, and there's something in Italian that uses the same letter combination. Not a person, though.) Yes, it's entirely possible that someone will deliberately try to sully my name like that, but I can't imagine that anyone would accidentally hit on it as an internet username, given that it hasn't happened yet. And sure, someone might be using it offline that I'm unaware of. I'm prepared to chance that. :) So yeah, I probably shouldn't have said "truly unique", but "effectively unique". Pretty much anything you find on google.com or duckduckgo.com with the name "rosuav" has come from me, or is referencing me (and this would include the wag/s you describe, though I've not seen that happen, and I've been using and claiming this name for a decade or so - and that's only counting on the internet). ChrisA From rosuav at gmail.com Wed Aug 15 00:10:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 14:10:40 +1000 Subject: [OT] Posting under ones full name In-Reply-To: <87txw4erjo.fsf@benfinney.id.au> References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> <87txw4erjo.fsf@benfinney.id.au> Message-ID: On Wed, Aug 15, 2012 at 1:56 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn >> wrote: >> > Please use `[...]' or `[?]' to indicate omission instead. I could >> > have written `politeness...' myself. >> >> Incidentally, how _do_ the square brackets help? > > They are a long-standing convention for marking an editorial addition or > clarification. > > Square brackets ? also called simply brackets (US) ? are mainly used > to enclose explanatory or missing material usually added by someone > other than the original author, especially in quoted text. > > Right, as is often done with dangling pronouns. "[Square brackets] are a long-standing convention..." would be a valid way of quoting your above statement. What I mean is that putting brackets around the ellipsis adds nothing, and certainly doesn't eliminate ambiguity; the only advantage is that [...] cannot be confused for a written-in pause. ChrisA From levinie001 at gmail.com Wed Aug 15 01:07:01 2012 From: levinie001 at gmail.com (levi nie) Date: Wed, 15 Aug 2012 13:07:01 +0800 Subject: it's really strange.how does it work? Message-ID: ok,what does "start, stop = 0, start" in the code mean? it's really strange.how does it work? code: def interval(start, stop=None, step=1): 'Imitates range() for step > 0' if stop is None: start, stop = 0, start result = [] i = start while i < stop: result.append(i) i += step return result print interval(10) -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfianjana90 at gmail.com Wed Aug 15 01:15:04 2012 From: sfianjana90 at gmail.com (sfi anjana) Date: Tue, 14 Aug 2012 22:15:04 -0700 (PDT) Subject: Order Before the Offer Wipe outs!!! Message-ID: Bear Gift Card Holder $7.79 Retail Price: $12.99 You Save: $5.20 (40%) Item No: 54899 Ships From: CANADA Condition / Status: New / 1 Available https://www.tripleclicks.com/detail.php?item=54899/10288668/ Bear carries a handbag perfectly sized to fill with gift cards (not included). Comes with 4 gift coupons you can personalize for ?free? hugs, chores, & more! Available in English only. 18 cm H. From maniandram01 at gmail.com Wed Aug 15 01:18:32 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 15 Aug 2012 10:48:32 +0530 Subject: it's really strange.how does it work? In-Reply-To: References: Message-ID: Even I got confused a bit: explaination: this is called iterable unpacking `start, stop = 0, start` is the same as: temp = start start = 0 stop = temp On 15 August 2012 10:37, levi nie wrote: > ok,what does "start, stop = 0, start" in the code mean? > it's really strange.how does it work? > > code: > def interval(start, stop=None, step=1): > 'Imitates range() for step > 0' > if stop is None: > start, stop = 0, start > result = [] > i = start > while i < stop: > result.append(i) > i += step > return result > > print interval(10) > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Aug 15 01:24:04 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 14 Aug 2012 22:24:04 -0700 Subject: it's really strange.how does it work? In-Reply-To: References: Message-ID: On Tue, Aug 14, 2012 at 10:07 PM, levi nie wrote: > ok,what does "start, stop = 0, start" in the code mean? > it's really strange.how does it work? It's just parallel assignment (http://en.wikipedia.org/wiki/Assignment_%28computer_science%29#Parallel_assignment ). As to exactly how it works: http://docs.python.org/reference/simple_stmts.html#assignment-statements : "If the target [of the assignment] is a comma-separated list: The [value being stored] must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets." [not a completely direct quote] Tuples are iterable (e.g. we can write `for item in some_tuple:`; in laymen's terms, it's similar to being a sequence). Recall that commas, and not parentheses, are what create tuples according to Python's syntax: $ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) Type "help", "copyright", "credits" or "license" for more information. >>> x = 1,2 >>> x (1, 2) >>> type(x) >>> So, your code snippet creates an anonymous temporary tuple of length 2 [i.e. (0, start) ], and the assignment then unpacks that tuple into the 2 respective variables. Cheers, Chris From maniandram01 at gmail.com Wed Aug 15 01:33:51 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Wed, 15 Aug 2012 11:03:51 +0530 Subject: something about split()??? In-Reply-To: <502A865E.4030504@sequans.com> References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: filter is bad when you use lambda with it there are (good) cases for filter On 14 August 2012 22:39, Jean-Michel Pichavant wrote: > Ramchandra Apte wrote: > >> (Much) more Pythonic solution: >> >>> filter(None,"|".split("|")) >> >> On 14 August 2012 15:14, Andreas Tawn > andreas.tawn at ubisoft.**com >> wrote: >> >> > I have a question about the split function? surpose a = "|",and >> when I use a.split("|") , I got the list >> > ['"",""] ,but I want to get the empty list,what should I do ? >> >> Something like... >> >> >>> [x for x in "|".split("|") if x] >> [] >> >> Cheers, >> >> Drea >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> >> >> A pythonic answer would be bottom-posted :p > > JM > > > PS : pylint raises a low warning about *filter* being non pythonic, > http://pylint-messages.**wikidot.com/messages:w0141 > "les go?ts et les couleurs ne se discutent pas" > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robertmiles at teranews.com Wed Aug 15 02:19:22 2012 From: robertmiles at teranews.com (Robert Miles) Date: Wed, 15 Aug 2012 01:19:22 -0500 Subject: Python Interview Questions In-Reply-To: <1f94963b-a538-41e2-8c00-8df4f2629e63@googlegroups.com> References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> <3e0ef383-9615-4b4d-89c1-e5519971189f@googlegroups.com> <35e7a860-fd41-4018-82f6-aabc3261064d@googlegroups.com> <4ffbdae7$0$1796$c3e8da3$76491128@news.astraweb.com> <6joov7lirmr9hiqk8rq9ojqj4jlt3kp8pu@invalid.netcom.com> <1f94963b-a538-41e2-8c00-8df4f2629e63@googlegroups.com> Message-ID: On 7/10/2012 1:08 PM, Demian Brecht wrote: > I also judge candidates on their beards (http://www.wired.com/wiredenterprise/2012/06/beard-gallery/). If the beard's awesome enough, no questions needed. They're pro. You should hire me quickly, then, since I have a beard, already turning partly gray. Never mind that the computer languages I have studied enough to write even one program don't yet include Python. From ian.g.kelly at gmail.com Wed Aug 15 03:28:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 15 Aug 2012 01:28:32 -0600 Subject: [OT] Posting under ones full name In-Reply-To: References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On Tue, Aug 14, 2012 at 9:18 PM, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn > wrote: >> Please use `[...]' or `[?]' to indicate omission instead. I could have >> written `politeness...' myself. > > Incidentally, how _do_ the square brackets help? The square brackets clarify that the ellipsis was not part of the original quotation but was added at some later point. > Can a reader know > that you put square-bracketed dots and that I didn't omit a lengthy > quoted string? Irrelevant. Why would an author adhering to common principles of style ever use square-bracketed dots in a statement that he authored himself? And if instead your quotation had been of Thomas also quoting a third party, then it would not be important whether you or Thomas had added the omission -- the main point is that it wasn't there originally. Be that as it may, the MLA no longer requires square brackets around an ellipsis of omission, so at least from a scholarly standpoint you're off the hook. From rosuav at gmail.com Wed Aug 15 03:41:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Aug 2012 17:41:20 +1000 Subject: [OT] Posting under ones full name In-Reply-To: References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On Wed, Aug 15, 2012 at 5:28 PM, Ian Kelly wrote: > Irrelevant. Why would an author adhering to common principles of > style ever use square-bracketed dots in a statement that he authored > himself? You mean exactly the way he did in the post you quoted me as quoting? ChrisA From breamoreboy at yahoo.co.uk Wed Aug 15 03:45:37 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 15 Aug 2012 08:45:37 +0100 Subject: something about split()??? In-Reply-To: <502A865E.4030504@sequans.com> References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: On 14/08/2012 18:09, Jean-Michel Pichavant wrote: > Ramchandra Apte wrote: > A pythonic answer would be bottom-posted :p > > JM He or she is still top posting. I'm given up asking. -- Cheers. Mark Lawrence. From andrea.crotti.0 at gmail.com Wed Aug 15 05:05:52 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 15 Aug 2012 10:05:52 +0100 Subject: Sharing code between different projects? In-Reply-To: <20120814215118.GA19167@cskk.homeip.net> References: <20120814215118.GA19167@cskk.homeip.net> Message-ID: 2012/8/14 Cameron Simpson : > > Having just skimmed this thread, one thing I haven't quite seen suggested is > this: > > Really do make a third "utilities" project, and treat "the project" and > "deploy" as separate notions. So to actually run/deploy project A's code > you'd have a short script that copied project A and the utilities project > code into a tree and ran off that. Or even a simple process/script to > update the copy of "utilities" in "project A"'s area. > > So you don't "share" code on an even handed basis but import the > "utilities" library into each project as needed. > > I do this (one my own very small scale) in one of two ways: > > - as needed, copy the desired revision of utilities into the project's > library space and do perforce's equivalent of Mercurial's addremove > on that library tree (comment "update utilities to revision X"). > > - keep a perforce work area for the utilities in your project A area, > where your working project A can hook into it with a symlink or some > deploy/copy procedure as suggested above. > With this latter one you can push back into the utilities library > from your "live" project, because you have a real checkout. So: > > projectAdir > projectA-perforce-checkout > utilities-perforce-checkout > projectBdir > projectB-perforce-checkout > utilities-perforce-checkout > Thanks, is more or less what I was going to do.. But I would not use symlinks and similar things, because then every user should set it up accordingly. Potentially we could instead use the perforce API to change the workspace mappings at run-time, and thus "force" perforce to checkout the files in the right place.. There is still the problem that people should checkout things from two places all the time instead of one.. > Personally I become more and more resistent to cut/paste even for small > things as soon as multiple people use it; you will never get to backport > updates to even trivial code to all the copies. > > Cheers, Well sure, but on the other end as soon as multiple people use it you can't change any of the public functions signatures without being afraid that you'll break something.. From steve+comp.lang.python at pearwood.info Wed Aug 15 05:37:48 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Aug 2012 09:37:48 GMT Subject: [OT] Posting under ones full name References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: <502b6dec$0$29867$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 17:41:20 +1000, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 5:28 PM, Ian Kelly > wrote: >> Irrelevant. Why would an author adhering to common principles of style >> ever use square-bracketed dots in a statement that he authored himself? > > You mean exactly the way he did in the post you quoted me as quoting? That's the usual problem with markup. How do you distinguish markup used as markup from the same characters used as text? English has a bunch of ad-hoc rules like sticking things in quotation marks, square brackets or angle brackets, but no systematic way of escaping markup in general. There's no standard way to distinguish my writing [...] deliberately (as here) from an editor trimming it, except from context, and that is notoriously ambiguous. "Godel, Escher and Bach" by Douglas Hofstadter discusses this sort of quoting, meta-quoting, etc. in detail. A good read if you want your brain stretched to the point it starts leaking out of your ears. -- Steven From alain at dpt-info.u-strasbg.fr Wed Aug 15 05:50:34 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 15 Aug 2012 11:50:34 +0200 Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> Message-ID: <87has4pjpx.fsf@dpt-info.u-strasbg.fr> Chris Angelico writes: > Other people have explained the problem with your code. I'll take this > example as a way of introducing you to one of Python's handy features > - it's an idea borrowed from functional languages, and is extremely > handy. It's called the "list comprehension", and can be looked up in > the docs under that name, > > def testFunc(startingList): > xOnlyList = [strng for strng in startingList if strng[0] == 'x'] > startingList = [strng for strng in startingList if strng[0] != 'x'] > print(xOnlyList) > print(startingList) > > It's a compact notation for building a list from another list. (Note > that I changed "str" to "strng" to avoid shadowing the built-in name > "str", as others suggested.) Fully agree with you: list comprehension is, imo, the most useful program construct ever. Extremely useful. But not when it makes the program traverse twice the same list, where one traversal is enough. -- Alain. From alain at dpt-info.u-strasbg.fr Wed Aug 15 05:57:59 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 15 Aug 2012 11:57:59 +0200 Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <03e72fb4-ca09-403f-b742-a884f8316809@googlegroups.com> Message-ID: <87d32spjdk.fsf@dpt-info.u-strasbg.fr> light1quark at gmail.com writes: > I got my answer by reading your posts and referring to: > http://docs.python.org/reference/compound_stmts.html#the-for-statement > (particularly the shaded grey box) Not that the problem is not specific to python (if you erase the current element when traversing a STL list in C++ you'll get a crash as well). > I guess I should have (obviously) looked at the doc's before posting > here; but im a noob. Python has several surprising features. I think it is a good idea to take some time to read the language reference, from cover to cover (before or after the various tutorials, depending on your background). -- Alain. From andrea.crotti.0 at gmail.com Wed Aug 15 07:43:38 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 15 Aug 2012 12:43:38 +0100 Subject: Sharing code between different projects? In-Reply-To: References: <20120814215118.GA19167@cskk.homeip.net> Message-ID: Also looking at logilab-common I thought that it would be great if we could actually make this "common" library even open source, and use it as one of the other many external libraries. Since Python code is definitively not the the core business of this company I might even convince them, but the problem is that then all the internal people working on it would not be able to use the standard tools that they use with everything else.. Did anyone manage to convince his company to do something similar? From PointedEars at web.de Wed Aug 15 07:54:13 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 15 Aug 2012 13:54:13 +0200 Subject: [OT] Posting under ones full name References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: <7435785.XlRUa0Ptbj@PointedEars.de> Chris Angelico wrote: > Thomas 'PointedEars' Lahn wrote: >> Chris Angelico wrote: >>> I have my surname in my From address, but I tend to sign my posts >>> "ChrisA" (no relation, btw, to DaveA, though our surnames are >>> similar). That's generally been sufficient for distinguishing >>> purposes, though if anyone wants a truly unique handle for me, >>> "Rosuav" is more effective than my real name. >> >> For one to read your signature, one has to download and read your entire >> posting first. > > And my signature has less information than the headers. So you're not > deprived of anything. With NNTP and IMAP4 it is possible to retrieve only the message header. Therefore, messages are easier to filter by message header than by message body. So the former is done, to keep one's input stream's S/N high. >>> Though I'm now not so sure about your name, PointedEars. Are you a >>> Vulcan or an elf? >> That is a stupid question. > > Of course, my bad. The difference is obvious, I should have known > which without asking. -- F'up2 PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From jarausch at igpm.rwth-aachen.de Wed Aug 15 08:16:44 2012 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 15 Aug 2012 12:16:44 GMT Subject: email with a non-ascii charset in Python3 ? Message-ID: Hi, I'm sorry to ask such a FAQ but still I couldn't find an answer - neither in the docs nor the web. What's wrong with the following script? Many thanks for a hint, Helmut. #!/usr/bin/python3 #_*_ coding: latin1 _*_ import smtplib from email.message import Message import datetime msg= Message() msg.set_charset('latin-1') msg['Subject'] = "*** Email Test ***" msg['From'] = "Email_Tester at numa-sv.igpm.rwth-aachen.de" msg['To'] = "jarausch at igpm.rwth-aachen.de" msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') server= smtplib.SMTP("igpm.igpm.rwth-aachen.de") msg.set_payload("Gedanken ?ber einen Test","iso-8859-1") ## I have tried msg.set_payload("Gedanken ?ber einen Test".encode("iso-8859-1"),"iso-8859-1") ## which fails, as well server.send_message(msg) Traceback (most recent call last): File "./Test_EMail_Py3.py", line 17, in server.send_message(msg) File "/usr/lib64/python3.2/smtplib.py", line 812, in send_message g.flatten(msg_copy, linesep='\r\n') File "/usr/lib64/python3.2/email/generator.py", line 91, in flatten self._write(msg) File "/usr/lib64/python3.2/email/generator.py", line 137, in _write self._dispatch(msg) File "/usr/lib64/python3.2/email/generator.py", line 163, in _dispatch meth(msg) File "/usr/lib64/python3.2/email/generator.py", line 396, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/lib64/python3.2/email/generator.py", line 201, in _handle_text self.write(payload) File "/usr/lib64/python3.2/email/generator.py", line 357, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 9: ordinal not in range(128) server.quit() This is Python 3.2.4 (GIT 20120805) From lists at cheimes.de Wed Aug 15 08:48:40 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 15 Aug 2012 14:48:40 +0200 Subject: email with a non-ascii charset in Python3 ? In-Reply-To: References: Message-ID: Am 15.08.2012 14:16, schrieb Helmut Jarausch: > Hi, > > I'm sorry to ask such a FAQ but still I couldn't find an answer - neither in the docs nor the web. > > What's wrong with the following script? > > Many thanks for a hint, > Helmut. > > #!/usr/bin/python3 > #_*_ coding: latin1 _*_ > > import smtplib > from email.message import Message > import datetime > > msg= Message() > msg.set_charset('latin-1') > msg['Subject'] = "*** Email Test ***" > msg['From'] = "Email_Tester at numa-sv.igpm.rwth-aachen.de" > msg['To'] = "jarausch at igpm.rwth-aachen.de" > msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') > > server= smtplib.SMTP("igpm.igpm.rwth-aachen.de") > msg.set_payload("Gedanken ?ber einen Test","iso-8859-1") You mustn't combine set_charset() with set_payload() with a charset. That results into invalid output: >>> msg = Message() >>> msg.set_payload("Gedanken ?ber einen Test", "iso-8859-1") >>> msg.as_string() 'MIME-Version: 1.0\nContent-Type: text/plain; charset="iso-8859-1"\nContent-Transfer-Encoding: quoted-printable\n\nGedanken =FCber einen Test' >>> msg2 = Message() >>> msg2.set_charset("iso-8859-1") >>> msg2.set_payload("Gedanken ?ber einen Test", "iso-8859-1") >>> msg2.as_string() 'MIME-Version: 1.0\nContent-Type: text/plain; charset="iso-8859-1"\nContent-Transfer-Encoding: quoted-printable\n\nGedanken ?ber einen Test' Christian From dmarsentev at gmail.com Wed Aug 15 08:49:04 2012 From: dmarsentev at gmail.com (Dmitry Arsentiev) Date: Wed, 15 Aug 2012 05:49:04 -0700 (PDT) Subject: python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' Message-ID: Hello. Has anybody already meet the problem like this? - AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run scrapy, I get File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", line 14, in libxml2.HTML_PARSE_NOERROR + \ AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run python -c 'import libxml2; libxml2.HTML_PARSE_RECOVER' I get Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' How can I cure it? Python 2.7 libxml2-python 2.6.9 2.6.11-gentoo-r6 I will be grateful for any help. DETAILS: scrapy crawl lgz -o items.json -t json Traceback (most recent call last): File "/usr/local/bin/scrapy", line 4, in execute() File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 112, in execute cmds = _get_commands_dict(inproject) File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 37, in _get_commands_dict cmds = _get_commands_from_module('scrapy.commands', inproject) File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 30, in _get_commands_from_module for cmd in _iter_command_classes(module): File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 21, in _iter_command_classes for module in walk_modules(module_name): File "/usr/local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 65, in walk_modules submod = __import__(fullpath, {}, {}, ['']) File "/usr/local/lib/python2.7/site-packages/scrapy/commands/shell.py", line 8, in from scrapy.shell import Shell File "/usr/local/lib/python2.7/site-packages/scrapy/shell.py", line 14, in from scrapy.selector import XPathSelector, XmlXPathSelector, HtmlXPathSelector File "/usr/local/lib/python2.7/site-packages/scrapy/selector/__init__.py", line 30, in from scrapy.selector.libxml2sel import * File "/usr/local/lib/python2.7/site-packages/scrapy/selector/libxml2sel.py", line 12, in from .factories import xmlDoc_from_html, xmlDoc_from_xml File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", line 14, in libxml2.HTML_PARSE_NOERROR + \ AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' From xs.nepaul at gmail.com Wed Aug 15 09:30:26 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 06:30:26 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host Message-ID: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> The code: import MySQLDB strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' (11004)") From invalid at invalid.invalid Wed Aug 15 09:59:53 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 15 Aug 2012 13:59:53 +0000 (UTC) Subject: [OT] Posting under ones full name References: <5f8605fd-f2b6-4673-9c98-72c111cfd050@googlegroups.com> <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On 2012-08-15, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 12:06 PM, Thomas 'PointedEars' Lahn > wrote: >> Please use `[...]' or `[?]' to indicate omission instead. I could have >> written `politeness...' myself. > > Incidentally, how _do_ the square brackets help? Because that's the standard method for denoting text that was inserted by an editor and not written by the original author. > Can a reader know that you put square-bracketed dots and that I > didn't omit a lengthy quoted string? Generally, yes. That's the convention for Usenet and mailing lists. > Perhaps you said "Please use `m4-style quotes rather than matching > ASCII quotes' or `something else' to indicate omission instead". -- Grant Edwards grant.b.edwards Yow! As President I have at to go vacuum my coin gmail.com collection! From jarausch at skynet.be Wed Aug 15 10:04:51 2012 From: jarausch at skynet.be (Helmut Jarausch) Date: 15 Aug 2012 14:04:51 GMT Subject: email with a non-ascii charset in Python3 ? References: Message-ID: <502bac83$0$3117$ba620e4c@news.skynet.be> On Wed, 15 Aug 2012 14:48:40 +0200, Christian Heimes wrote: > Am 15.08.2012 14:16, schrieb Helmut Jarausch: >> Hi, >> >> I'm sorry to ask such a FAQ but still I couldn't find an answer - >> neither in the docs nor the web. >> >> What's wrong with the following script? >> >> Many thanks for a hint, >> Helmut. >> >> #!/usr/bin/python3 #_*_ coding: latin1 _*_ >> >> import smtplib from email.message import Message import datetime >> >> msg= Message() >> msg.set_charset('latin-1') >> msg['Subject'] = "*** Email Test ***" >> msg['From'] = "Email_Tester at numa-sv.igpm.rwth-aachen.de" >> msg['To'] = "jarausch at igpm.rwth-aachen.de" >> msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S >> %p') >> >> server= smtplib.SMTP("igpm.igpm.rwth-aachen.de") >> msg.set_payload("Gedanken ?ber einen Test","iso-8859-1") > > You mustn't combine set_charset() with set_payload() with a charset. > That results into invalid output: > >>>> msg = Message() >>>> msg.set_payload("Gedanken ?ber einen Test", "iso-8859-1") >>>> msg.as_string() > 'MIME-Version: 1.0\nContent-Type: text/plain; > charset="iso-8859-1"\nContent-Transfer-Encoding: > quoted-printable\n\nGedanken =FCber einen Test' > >>>> msg2 = Message() >>>> msg2.set_charset("iso-8859-1") >>>> msg2.set_payload("Gedanken ?ber einen Test", "iso-8859-1") >>>> msg2.as_string() > 'MIME-Version: 1.0\nContent-Type: text/plain; > charset="iso-8859-1"\nContent-Transfer-Encoding: > quoted-printable\n\nGedanken ?ber einen Test' > Thanks! Just, one mustn't use server.send_message(msg.as_string()) But what if msg['From'] contains a non-ASCII character? I wonder what the usage of msg.set_charset('latin-1') is. With msg.set_charset('latin-1') msg.set_payload("Gedanken ?ber einen Test") # is accepted BUT server.send_message(msg) gives Traceback (most recent call last): File "Test_EMail_Py3_2.py", line 21, in server.send_message(msg) File "/usr/lib64/python3.2/smtplib.py", line 812, in send_message g.flatten(msg_copy, linesep='\r\n') File "/usr/lib64/python3.2/email/generator.py", line 91, in flatten self._write(msg) File "/usr/lib64/python3.2/email/generator.py", line 137, in _write self._dispatch(msg) File "/usr/lib64/python3.2/email/generator.py", line 163, in _dispatch meth(msg) File "/usr/lib64/python3.2/email/generator.py", line 396, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/lib64/python3.2/email/generator.py", line 201, in _handle_text self.write(payload) File "/usr/lib64/python3.2/email/generator.py", line 357, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 9: ordinal not in range(128) Helmut. From breamoreboy at yahoo.co.uk Wed Aug 15 10:23:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 15 Aug 2012 15:23:24 +0100 Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> Message-ID: On 15/08/2012 14:30, nepaul wrote: > The code: > import MySQLDB > strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' (11004)") > My highly paid team of consultants suggest that you're trying to connect to a MySQL server host that doesn't exist. However I'm sure that people on this list with more knowledge of MySQLDB than my consultants will be able to give you more detailed data. -- Cheers. Mark Lawrence. From dotancohen at gmail.com Wed Aug 15 10:41:44 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 15 Aug 2012 17:41:44 +0300 Subject: OT: Monty Python in Syria Message-ID: And now for something completely different. Not programming related, but at 1:20 I was expecting a different question: http://www.aljazeera.com/news/middleeast/2012/08/2012813103922872697.html I figured if anybody could appreciate that, it would be the folks here. Enjoy! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From dotancohen at gmail.com Wed Aug 15 10:42:49 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 15 Aug 2012 17:42:49 +0300 Subject: OT: Monty Python in Syria In-Reply-To: References: Message-ID: On Wed, Aug 15, 2012 at 5:41 PM, Dotan Cohen wrote: > And now for something completely different. > > Not programming related, but at 1:20 I was expecting a different question: > http://www.aljazeera.com/news/middleeast/2012/08/2012813103922872697.html > > I figured if anybody could appreciate that, it would be the folks here. Enjoy! > For context, start the video at 1:00. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From xs.nepaul at gmail.com Wed Aug 15 10:53:50 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 07:53:50 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> Message-ID: ? 2012?8?15????UTC+8??10?23?24??Mark Lawrence??? > On 15/08/2012 14:30, nepaul wrote: > > > The code: > > > import MySQLDB > > > strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > > > > > _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > > > > > > My highly paid team of consultants suggest that you're trying to connect > > to a MySQL server host that doesn't exist. However I'm sure that people > > on this list with more knowledge of MySQLDB than my consultants will be > > able to give you more detailed data. > > > > -- > > Cheers. > > > > Mark Lawrence. if i use MySQLdb.connect(strCmd) -> wrong, but if use MySQLdb.connect(user = 'root', passwd = '123456', db = 'test', host = 'localhost'),it work. and the strCmd is read from a xml file. From xs.nepaul at gmail.com Wed Aug 15 10:53:50 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 07:53:50 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> Message-ID: ? 2012?8?15????UTC+8??10?23?24??Mark Lawrence??? > On 15/08/2012 14:30, nepaul wrote: > > > The code: > > > import MySQLDB > > > strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > > > > > _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > > > > > > My highly paid team of consultants suggest that you're trying to connect > > to a MySQL server host that doesn't exist. However I'm sure that people > > on this list with more knowledge of MySQLDB than my consultants will be > > able to give you more detailed data. > > > > -- > > Cheers. > > > > Mark Lawrence. if i use MySQLdb.connect(strCmd) -> wrong, but if use MySQLdb.connect(user = 'root', passwd = '123456', db = 'test', host = 'localhost'),it work. and the strCmd is read from a xml file. From rudsonalves67 at gmail.com Wed Aug 15 10:59:15 2012 From: rudsonalves67 at gmail.com (rudson alves) Date: Wed, 15 Aug 2012 07:59:15 -0700 (PDT) Subject: Verify the integrity of the tar file with tarfile module? Message-ID: <0e274ee0-3a9b-4013-b6e5-151c578455ce@googlegroups.com> Hello, I took a Slackware package file .tar (uncompressed) and edited with random characters to generate any error in its structure, as shown in the test bash below: $ tar -tf zoo.tar ./ install/ install/slack-desc tar: Pulando para o pr?ximo cabe?alho tar: Exiting with failure status due to previous errors $ echo $? 2 How can I verify the integrity of the tar file with tarfile module without having to expand it? To be more precise, even expanding this file it not generated any error message. From hansmu at xs4all.nl Wed Aug 15 11:02:59 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 15 Aug 2012 17:02:59 +0200 Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> Message-ID: <502bba24$0$6979$e4fe514c@news2.news.xs4all.nl> On 15/08/12 15:30:26, nepaul wrote: > The code: > import MySQLDB > strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > > > _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', > passwd = '123456', db = 'test', host = 'localhost'' (11004)") This message means that the MySQL connector cannot find 'localhost'. That's odd, since localhost should be your own computer. Which OS are you using? Is TCP/IP installed and enabled? Can you find an entry for 'localhost' in your /etc/hosts file? Can you ping it? What happens if you try host='127.0.0.1'? Incidentally, connecting as 'root' for non-administrative purposes is considered bad practice. Consider creating a 'test' account that only has access to the 'test' database. Oh, and I hope that '123456' is not really the password for 'root'. Hope this helps, -- HansM From iurisilvio at gmail.com Wed Aug 15 11:06:34 2012 From: iurisilvio at gmail.com (Iuri) Date: Wed, 15 Aug 2012 12:06:34 -0300 Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> Message-ID: MySQLdb.connect does not accept a "connection string" parameter. On Wed, Aug 15, 2012 at 11:53 AM, nepaul wrote: > ? 2012?8?15????UTC+8??10?23?24??Mark Lawrence??? > > On 15/08/2012 14:30, nepaul wrote: > > > > > The code: > > > > > import MySQLDB > > > > > strCmd = "user = 'root', passwd = '123456', db = 'test', host = > 'localhost'" > > > > > > > > > > _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host > 'user = 'root', passwd = '123456', db = 'test', host = 'localhost'' > (11004)") > > > > > > > > > > > > > My highly paid team of consultants suggest that you're trying to connect > > > > to a MySQL server host that doesn't exist. However I'm sure that people > > > > on this list with more knowledge of MySQLDB than my consultants will be > > > > able to give you more detailed data. > > > > > > > > -- > > > > Cheers. > > > > > > > > Mark Lawrence. > > if i use MySQLdb.connect(strCmd) -> wrong, but if use MySQLdb.connect(user > = 'root', passwd = '123456', db = 'test', host = 'localhost'),it work. and > the strCmd is read from a xml file. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Wed Aug 15 11:22:49 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 15 Aug 2012 17:22:49 +0200 Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> <502bba24$0$6979$e4fe514c@news2.news.xs4all.nl> Message-ID: <878vdgp4c6.fsf@dpt-info.u-strasbg.fr> Hans Mulder writes: > On 15/08/12 15:30:26, nepaul wrote: >> The code: >> import MySQLDB >> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" >> >> >> >> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', >> passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > This message means that the MySQL connector cannot find 'localhost'. No, it means that connect received a single string "user = 'root'..." instead of a set of individual keyword parameters, and took the whole string to be the name of the host (its first parameter). Of course, there is no host with such a name. The solution is to parse the string into individual values, and pass these in the correct order. -- Alain. From solipsis at pitrou.net Wed Aug 15 11:26:02 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 15 Aug 2012 15:26:02 +0000 (UTC) Subject: Flushing buffer on file copy on linux References: Message-ID: J gmail.com> writes: > > Now, the problem I have is that linux tends to buffer data writes to a > device, and I want to work around that. When run in normal non-stress > mode, the program is slow enough that the linux buffers flush and put > the file on disk before the hash occurs. However, when run in stress > mode, what I'm finding is that it appears that the files are possibly > being hashed while still in the buffer, before being flushed to disk. Your analysis is partly wrong. It is right that the files can be hashed from in-memory buffers; but even if you flush the buffers to disk using standard techniques (such as fsync()), those buffers still exist in memory, and therefore the file will still be hashed from memory (for obvious efficiency reasons). I don't think there's a portable solution to get away entirely with the in-memory buffers, but under Linux you can write "1" to the special file /proc/sys/vm/drop_caches: $ sudo sh -c "echo 1 > /proc/sys/vm/drop_caches" Or, to quote the /proc man page: /proc/sys/vm/drop_caches (since Linux 2.6.16) Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that mem? ory to become free. To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches; to free pagecache, dentries and inodes, use echo 3 > /proc/sys/vm/drop_caches. Because this is a nondestructive operation and dirty objects are not freeable, the user should run sync(8) first. Regards Antoine. -- Software development and contracting: http://pro.pitrou.net From xs.nepaul at gmail.com Wed Aug 15 12:50:34 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 09:50:34 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: <878vdgp4c6.fsf@dpt-info.u-strasbg.fr> References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> <502bba24$0$6979$e4fe514c@news2.news.xs4all.nl> <878vdgp4c6.fsf@dpt-info.u-strasbg.fr> Message-ID: ? 2012?8?15????UTC+8??11?22?49??Alain Ketterlin??? > Hans Mulder writes: > > > > > On 15/08/12 15:30:26, nepaul wrote: > > >> The code: > > >> import MySQLDB > > >> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > >> > > >> > > >> > > >> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', > > >> passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > > > > > This message means that the MySQL connector cannot find 'localhost'. > > > > No, it means that connect received a single string "user = 'root'..." > > instead of a set of individual keyword parameters, and took the whole > > string to be the name of the host (its first parameter). Of course, > > there is no host with such a name. > > > > The solution is to parse the string into individual values, and pass > > these in the correct order. > > > > -- Alain. Yeah!Great!Thanks! From python at mrabarnett.plus.com Wed Aug 15 12:57:47 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Aug 2012 17:57:47 +0100 Subject: email with a non-ascii charset in Python3 ? In-Reply-To: References: Message-ID: <502BD50B.8080004@mrabarnett.plus.com> On 15/08/2012 13:16, Helmut Jarausch wrote: > Hi, > > I'm sorry to ask such a FAQ but still I couldn't find an answer - neither in the docs nor the web. > > What's wrong with the following script? > > Many thanks for a hint, > Helmut. > > #!/usr/bin/python3 > #_*_ coding: latin1 _*_ > Aw well as the other replies, the "coding" line should be: #-*- coding: latin1 -*- From miki.tebeka at gmail.com Wed Aug 15 14:07:36 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 15 Aug 2012 11:07:36 -0700 (PDT) Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: <916d308f-1d68-469d-a7f3-2491636c3896@googlegroups.com> > In plus I'm using perforce which doesn't have any svn:externals-like You can probably use views to this (http://www.perforce.com/perforce/r12.1/manuals/cmdref/o.views.html). > Second problem is that one of the two projects has a quite insane > requirement, which is to be able to re-run itself on a specific > version depending on a value fetched from the database. You can probably play with PYTHONPATH to do that. > The third problem is that from the moment is not just me using these > things, how can I be sure that changing something will not break > someone else code? That's always a problem with libraries you distribute, no matter what is the mechanism for distribution. If you go the views/link way. You can link to tags instead of trunk (or the perforce equivalent) and then client can still to know "good" version. If you go the PyPi route, you can specify package version in setup.py dependencies (foo==0.10.2) From miki.tebeka at gmail.com Wed Aug 15 14:07:36 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 15 Aug 2012 11:07:36 -0700 (PDT) Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: <916d308f-1d68-469d-a7f3-2491636c3896@googlegroups.com> > In plus I'm using perforce which doesn't have any svn:externals-like You can probably use views to this (http://www.perforce.com/perforce/r12.1/manuals/cmdref/o.views.html). > Second problem is that one of the two projects has a quite insane > requirement, which is to be able to re-run itself on a specific > version depending on a value fetched from the database. You can probably play with PYTHONPATH to do that. > The third problem is that from the moment is not just me using these > things, how can I be sure that changing something will not break > someone else code? That's always a problem with libraries you distribute, no matter what is the mechanism for distribution. If you go the views/link way. You can link to tags instead of trunk (or the perforce equivalent) and then client can still to know "good" version. If you go the PyPi route, you can specify package version in setup.py dependencies (foo==0.10.2) From th982a at googlemail.com Wed Aug 15 15:15:39 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Wed, 15 Aug 2012 21:15:39 +0200 Subject: OT: Monty Python in Syria In-Reply-To: References: Message-ID: <502BF55B.6030506@googlemail.com> Exactly! NOT PROGRAMMING related has NOTHING TODO HERE! Tamer Am 15.08.2012 16:42, schrieb Dotan Cohen: > On Wed, Aug 15, 2012 at 5:41 PM, Dotan Cohen wrote: >> And now for something completely different. >> >> Not programming related, but at 1:20 I was expecting a different question: >> http://www.aljazeera.com/news/middleeast/2012/08/2012813103922872697.html >> >> I figured if anybody could appreciate that, it would be the folks here. Enjoy! >> > > For context, start the video at 1:00. > > From hobson42 at gmail.com Wed Aug 15 15:39:34 2012 From: hobson42 at gmail.com (Ian) Date: Wed, 15 Aug 2012 20:39:34 +0100 Subject: Help needed installing easy_install and lxml2 Message-ID: <502BFAF6.9060502@gmail.com> Hi, On a reasonably fresh (3 day old) install of 64 bit windows 7, I have installed the 64 bit Python 2.7.3 from http://www.python.org/download/ Then I installed the 64 bit version of easy_install using http://pypi.python.org/pypi/setuptools And then install lxml 2.3.5, for which I use the instructions at http://lxml.de/installation.html#installation This ends with: Processing lxml-2.3.5.tgz Running lxml-2.3.5\setup.py -q bdist_egg --dist-dir c:\users\ian\appdata\local\temp\easy_install-9__rq7\lxml-2.3.5\egg-dist-tmp-uj_v_2 Building lxml version 2.3.5. Building without Cython. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt error: Setup script exited with error: Unable to find vcvarsall.bat C:\Users\ian> Now what? I thought I was installing the binary package do I would not need any development versions. What do these errors mean, and how can I overcome them? Thanks Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From missive at hotmail.com Wed Aug 15 17:08:25 2012 From: missive at hotmail.com (Lee Harr) Date: Thu, 16 Aug 2012 01:38:25 +0430 Subject: [ANNC] pybotwar-0.8 Message-ID: pybotwar is a fun and educational game where players write computer programs to control simulated robots. http://pybotwar.googlecode.com/ The focus of this release is making all functionality available from the PyQt interface and making PyQt the default interface. pybotwar uses pybox2d for the physical simulation. It can be run in text-only mode -- useful for longer tournaments -- or use pyqt or pygame for a graphical interface and visualization of the action. pybotwar is released under GPLv3. Changes in pybotwar-0.8: ??? - pybox2d-2.0.2b2 is now the required version ??? API ??? - Robot.turret() now takes turret speed instead of angle ??? - PING sensor now differentiates own bullets from enemy bullets ??? - PING differentiates dead robots when remove_dead_robots=False ??? - made internal Robot state variables less likely to conflict with user code ??? Settings ??? - added "robots dir" setting to make it easier to run pybotwar ??????? from an installed copy, rather than from the unpacked folder ??????? - logs, lineups, and db all go in robots dir ??????? - robot modules are now loaded by full path ??? - If using Qt settings, remembers most recently used set of robots ??? PyQt4 Interface ??? - PyQt4 view mode is now the default ??????? - (text mode and pygame/pygsear still available) ??? - all settings are available from PyQt interface ??? - remembers most recently used set of robots ??? - added debug window showing sensor values, commands, and logs ??? - can now start tournaments (and multiple battles) from pyqt ??? - can also start tournaments to run in background ??? - editor automatically adds .py to robot filename if needed ??? Other changes ??? - made template.py a valid robot program ??? - single battles are now run as 1-battle tournaments ??? - renamed kill stat to outlasted ??? - started tracking kills as dealing final damage to other robot ??? - commandline can now take a list of robots to load ??? - added "Super Tournaments" ??????? - runs tournaments with all possible combinations of robots ??? Fixes: ??? - made POSition sensor scale same as PING sensor ??? - fixed editor backspace between left edge and start of text ??? - fixed inability to re-open file once its window was closed ??? - fixed crash when cancelling file-open dialog ??? - limited motor speed on turret ??? - log messages in testmode when using qt4 view ??? - fall back to :memory: database if unable to open db file From worldpeaceagentforchange at gmail.com Wed Aug 15 17:12:01 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Wed, 15 Aug 2012 14:12:01 -0700 (PDT) Subject: A difficulty with lists In-Reply-To: References: Message-ID: <16702a22-6ce3-4120-bbcc-9649e1717130@googlegroups.com> On Monday, August 6, 2012 3:50:13 PM UTC-4, Mok-Kong Shen wrote: > I ran the following code: > > > > def xx(nlist): > > print("begin: ",nlist) > > nlist+=[999] > > print("middle:",nlist) > > nlist=nlist[:-1] > > print("final: ",nlist) > > > > u=[1,2,3,4] > > print(u) > > xx(u) > > print(u) > > > > and obtained the following result: > > > > [1, 2, 3, 4] > > begin: [1, 2, 3, 4] > > middle: [1, 2, 3, 4, 999] > > final: [1, 2, 3, 4] > > [1, 2, 3, 4, 999] > > > > As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. > > Could someone kindly help? > > > > M. K. Shen The list nlist inside of function xx is not the same as the variable u outside of the function: nlist and u refer to two separate list objects. When you modify nlist, you are not modifying u. If you wanted the last line to be [1, 2, 3, 4], you could use the code below: #BEGIN CODE def xx(nlist): print("begin: ",nlist) nlist+=[999] print("middle:",nlist) nlist=nlist[:-1] print("final: ",nlist) return nlist u=[1,2,3,4] print(u) u = xx(u) print(u) #END CODE Notice that I changed two things. First, the function xx(nlist) returns nlist. Secondly, u is reassigned to the result of xx(nlist). From thbach at students.uni-mainz.de Wed Aug 15 17:17:41 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Wed, 15 Aug 2012 23:17:41 +0200 Subject: Dynamically determine base classes on instantiation Message-ID: <20120815211740.GA5570@roku> Hi list, I'm confronted with a strang problem I cannot find a clean solution for. To me it seems like I need meta-classes. Anyway, I stucked a bit deeper in that topic and couldn't find a proper solution neither. But, judge for yourselve. I want a class that determines on instantiating its base classes dynamically. Consider the following two use cases a = Foo(['a', 'list']) # returns an instance that behaves like a list assert len(a) == 2 assert a[0] == 'a' assert a == ['a', 'list'] assert isinstance(a, list) # This would be nice, but no must-have b = Foo({'blah': 8}) # returns an instance that behaves like a dict assert b['blah'] == 'blah' assert b == {'blah': 8} assert isinstance(b, dict) # again, no must-have a.do_something() # common function to both instances as defined b.do_something() # in the Foo class What I'm currently doing something like the following: class Foo(object): def __init__(self, obj): self._obj = obj def __len__(self): return len(self._obj) def __getitem__(self, name): return self._obj[name] # ? def do_something(self): # do something on self._obj pass Which seems ugly. Is there a way to provide the functions of `list' and `dict' in Foo's look-up path without having to write all the stubs myself? Regards, Thomas Bach. From python at mrabarnett.plus.com Wed Aug 15 17:36:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Aug 2012 22:36:11 +0100 Subject: Dynamically determine base classes on instantiation In-Reply-To: <20120815211740.GA5570@roku> References: <20120815211740.GA5570@roku> Message-ID: <502C164B.9070907@mrabarnett.plus.com> On 15/08/2012 22:17, Thomas Bach wrote: > Hi list, > > I'm confronted with a strang problem I cannot find a clean solution > for. To me it seems like I need meta-classes. Anyway, I stucked a bit > deeper in that topic and couldn't find a proper solution neither. But, > judge for yourselve. > > I want a class that determines on instantiating its base classes > dynamically. Consider the following two use cases > > a = Foo(['a', 'list']) # returns an instance that behaves like a list > assert len(a) == 2 > assert a[0] == 'a' > assert a == ['a', 'list'] > assert isinstance(a, list) # This would be nice, but no must-have > > b = Foo({'blah': 8}) # returns an instance that behaves like a dict > assert b['blah'] == 'blah' > assert b == {'blah': 8} > assert isinstance(b, dict) # again, no must-have > > a.do_something() # common function to both instances as defined > b.do_something() # in the Foo class > > > What I'm currently doing something like the following: > > class Foo(object): > > def __init__(self, obj): > self._obj = obj > > def __len__(self): > return len(self._obj) > > def __getitem__(self, name): > return self._obj[name] > > # ? > > def do_something(self): > # do something on self._obj > pass > > Which seems ugly. Is there a way to provide the functions of `list' > and `dict' in Foo's look-up path without having to write all the > stubs myself? > Does Foo have to be a class? Couldn't it just be a factory function? From robert.day at merton.oxon.org Wed Aug 15 17:58:34 2012 From: robert.day at merton.oxon.org (Rob Day) Date: Wed, 15 Aug 2012 22:58:34 +0100 Subject: A difficulty with lists In-Reply-To: References: <16702a22-6ce3-4120-bbcc-9649e1717130@googlegroups.com> Message-ID: > The list nlist inside of function xx is not the same as the variable u > outside of the function: nlist and u refer to two separate list objects. > When you modify nlist, you are not modifying u. > Well - that's not quite true. Before calling the function, u is [1, 2, 3, 4] - but after calling the function, u is [1, 2, 3, 4, 999]. This is a result of using 'nlist += [999]' - the same thing doesn't happen if you use 'nlist = nlist+[999]' instead. I'm not completely aware of what's going on behind the scenes here, but I think the problem is that 'nlist' is actually a reference to a list object - it points to the same place as u. When you assign to it within the function, then it becomes separate from u - which is why nlist = nlist+[999] and nlist = nlist[:-1] don't modify u - but if you modify nlist in place before doing that, such as by using +=, then it's still pointing to u, and so u gets modified as well. So, for example: >>> def blank_list(nlist): ... nlist[:] = [] # modifies the list in-place ... >>> u [1, 2, 3, 4] >>> blank_list(u) >>> u [] # u has been changed by our change to nlist! But if we change it so that it assigns to nlist rather than modifying it: >>> def dont_blank_list(nlist): ... nlist = [] # creates a new list object rather than modifying the current one ... >>> u = [1, 2, 3, 4] >>> u [1, 2, 3, 4] >>> dont_blank_list(u) >>> u [1, 2, 3, 4] # u is completely unaffected! -- Robert K. Day robert.day at merton.oxon.org -- Robert K. Day robert.day at merton.oxon.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Aug 15 18:07:32 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 15 Aug 2012 23:07:32 +0100 Subject: OT: Monty Python in Syria In-Reply-To: <502BF55B.6030506@googlemail.com> References: <502BF55B.6030506@googlemail.com> Message-ID: On 15/08/2012 20:15, Tamer Higazi wrote: > Exactly! > NOT PROGRAMMING related has NOTHING TODO HERE! > Please don't shout, please don't top post and what gives you the right to determine what is or is not on topic here? The subject is also clearly marked OT or did that escape your attention? -- Cheers. Mark Lawrence. From dihedral88888 at googlemail.com Wed Aug 15 19:25:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 15 Aug 2012 16:25:09 -0700 (PDT) Subject: New image and color management library for Python 2+3 In-Reply-To: References: Message-ID: Christian Heimes? 2012?8?15????UTC+8??2?22?54???? > Hello fellow Pythonistas, > > > > I'm looking for co-developers, testers, documentation writers and users > > for a new image library I created. The code is available at > > https://bitbucket.org/tiran/smc.freeimage > > > > > > Background story: > > I'm working for a company that creates Python based solutions for > > libraries -- these large buildings containg millions of books. One major > > area of operation is the digitalization of books, prints and manuscripts > > from the last millennium. We are a major player in the German speaking > > countries with several hundred Terabytes of images on all our installations. > > > > Several years ago I began to write a Python interface for FreeImage > > because I was unhappy with the speed and capabilities of PIL. We had to > > check and convert several hundred GB of TIFF images to up to 15 sizes > > each and store them as JPEG every week. FreeImage offered more features > > and speed. Cython made it possible to integrate FreeImage into our > > software stack nicely. Later LittleCMS was integrated as color > > management solution to convert images from the scanners' color space > > into sRGB. > > > > During the development of smc.freeimage I also created a fork of > > FreeImage that wraps libjpeg-turbo instead of libjpeg. > > > > > > In my opinion the project is useful for other people because it has some > > benefits over PIL. For example it supports modern file formats that > > aren't supported by PIL, for example JPEG 2000, HDR formats and RAW > > camera formats. Contrary to PIL it even supports G3 and G4 compressed > > TIIFs as well as multipage TIFFs. In some areas it's also much faster > > than PIL, especially JPEG performance and NumPy buffer access. > > > > However it's not going to replace PIL as neither FreeImage nor my code > > supports drawing, text composition or extended filters. > > > > > > Excerpt from the README: > > > > Features of FreeImage > > ===================== > > > > FreeImage wraps mature and widely-used libraries like LibJPEG, > > LibOpenJPEG,LibPNG, LibRaw, LibTIFF4, OpenEXR and zlib in a consistent, > > well documented and powerful set of APIs. > > > > http://freeimage.sourceforge.net/ > > > > Reading of 35 file formats and writing of more than 19 file formats as > > of FreeImage 3.15.3, including JPEG 2000, multiple subformats of TIFF > > with G3/G4 fax compression and JPEG subsampling. > > > > pixel depths from 1-32 bpp standard images up to formats like RGBAF and > > 2x64complex. > > > > multi page images > > > > Metadata (e.g. EXIF, IPTC/NAA, GeoTIFF, XMP) and ICC > > > > Color adjustment, conversion and channel processing > > > > Image resizing and rotation > > > > High Dynamic Range (HDR) image processing and tone mapping > > > > RAW camera files > > > > Contrary to PIL it doesn't contain advanced image filters or drawing > > functions. FreeImage focuses on file formats > > > > > > Features of LCMS2 > > ================= > > > > LCMS2 is a color management engine that implements V2 and V4 ICC > > profiles up to V4.3. It supports transformation, proofing and > > introspection of profiles for a large variety of color formats and targets. > > > > http://www.littlecms.com/ > > > > > > Features of smc.freeimage > > ========================= > > > > smc.freeimage is developed as part of the closed source Visual Library > > framework. > > > > mostly written with Cython with some lines of handwritten C Code and > > some Python helpers. > > > > fast, it avoids copying large amounts of data and releases the GIL > > whenever possible. > > > > 64bit safe, tested on i386/X86 and AMD64/X86_64 systems > > > > thread safe > > > > wraps a large subset of FreeImage features > > > > Compatible with Python 2.6 to 3.3. > > > > > > Performance > > =========== > > > > smc.freeimage with libjpeg-turbo read JPEGs about three to six times > > faster than PIL and writes JPEGs more than five times faster. > > > > JPEG's restart markers are not compatible with libjpeg-turbo's Huffman > > decoder optimization and reduce performance a lot. Please read the > > section "Restart Makers" on the page > > http://www.libjpeg-turbo.org/About/Performance for more information. > > > > Python 2.7.3 > > read / write cycles: 300 > > test image: 1210x1778 24bpp JPEG (pon.jpg) > > platform: Ubuntu 12.04 X86_64 > > hardware: Intel Xeon hexacore W3680 at 3.33GHz with 24 GB RAM > > > > smc.freeimage, FreeImage 3.15.3 standard > > - read JPEG 12.857 sec > > - read JPEG 6.629 sec (resaved) > > - write JPEG 21.817 sec > > smc.freeimage, FreeImage 3.15.3 with jpeg turbo > > - read JPEG 9.297 sec > > - read JPEG 3.909 sec (resaved) > > - write JPEG 5.857 sec > > - read LZW TIFF 17.947 sec > > - read biton G4 TIFF 2.068 sec > > - resize 3.850 sec (box) > > - resize 5.022 sec (bilinear) > > - resize 7.942 sec (bspline) > > - resize 7.222 sec (bicubic) > > - resize 7.941 sec (catmull rom spline) > > - resize 10.232 sec (lanczos3) > > - tiff numpy.asarray() with bytescale() 0.006 sec > > - tiff load + numpy.asarray() with bytescale() 18.043 sec > > PIL 1.1.7 > > - read JPEG 30.389 sec > > - read JPEG 23.118 sec (resaved) > > - write JPEG 34.405 sec > > - read LZW TIFF 21.596 sec > > - read biton G4 TIFF: decoder group4 not available > > - resize 0.032 sec (nearest) > > - resize 1.074 sec (bilinear) > > - resize 2.924 sec (bicubic) > > - resize 8.056 sec (antialias) > > - tiff scipy fromimage() with bytescale() 1.165 sec > > - tiff scipy imread() with bytescale() 22.939 sec > > > > > > Comparison to PIL (Pros and Cons) > > ================================= > > > > Pros of smc.freeimage > > --------------------- > > > > Faster! JPEG performance is about 3 to 6 times faster than PIL, numpy > > buffer access is more than 100 times faster and consumes less memory due > > to zero copy design. > > > > Modern file formats! smc.freeimage supports JPEG 2000, HDR and EXR high > > dynamic range images and raw camera data (RAW). > > > > Full baseline TIFF support! Contrary to PIL smc.freeimage supports all > > flavors of baseline TIFF like G3 and G4 compression and multipage TIFFs. > > > > PEP 3118 buffer interface that exports images as 2d or 3d non-contiguous > > buffer. > > > > Correct and optimized integration of a color management system > > (LittleCMS2)instead of lcms1 integration including caching of optimized > > transformations, in-place transformation and introspection of profiles. > > > > Structured metadata access to EXIF, XMP and IPTC information, also > > supports fast loading of metadata without loading pixel data. > > > > Lot's of color types! Bitmap (8bit) with 1, 4, 8, 16, 24 and 32 bits per > > pixel, (unsigned) int 16 and 32, float, double gray scale, complex, RGBA > > 16bit and RGBA floats. > > > > Static build support, no need for "make install". You just need a C99 > > compatible C/C++ compiler, make and nasm (for FreeImage-Turob). > > > > > > Cons of smc.freeimage > > ---------------------- > > > > Few image filters, no support for complex image filters in FreeImage > > > > Low quality resize filters are slower than PIL's filters > > > > No drawing API for primitives (lines, circles, boxes) > > > > No text drawing support and libfreetype integration. > > > > Still not feature complete and under development. > > > > > > FreeImage + libjpeg-turbo > > ========================= > > > > An experimental fork of FreeImage with libjpeg-turbo is available at > > https://bitbucket.org/tiran/freeimageturbo > > > > > > Feel free to contact me if you are interested in the library or want to > > get involved! > > > > Christian Do you need to work out edge dection maps that trace edge contours to be scallable funtional curves from control points obtained after image segmentations? curve by control points from From dihedral88888 at googlemail.com Wed Aug 15 19:25:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 15 Aug 2012 16:25:09 -0700 (PDT) Subject: New image and color management library for Python 2+3 In-Reply-To: References: Message-ID: Christian Heimes? 2012?8?15????UTC+8??2?22?54???? > Hello fellow Pythonistas, > > > > I'm looking for co-developers, testers, documentation writers and users > > for a new image library I created. The code is available at > > https://bitbucket.org/tiran/smc.freeimage > > > > > > Background story: > > I'm working for a company that creates Python based solutions for > > libraries -- these large buildings containg millions of books. One major > > area of operation is the digitalization of books, prints and manuscripts > > from the last millennium. We are a major player in the German speaking > > countries with several hundred Terabytes of images on all our installations. > > > > Several years ago I began to write a Python interface for FreeImage > > because I was unhappy with the speed and capabilities of PIL. We had to > > check and convert several hundred GB of TIFF images to up to 15 sizes > > each and store them as JPEG every week. FreeImage offered more features > > and speed. Cython made it possible to integrate FreeImage into our > > software stack nicely. Later LittleCMS was integrated as color > > management solution to convert images from the scanners' color space > > into sRGB. > > > > During the development of smc.freeimage I also created a fork of > > FreeImage that wraps libjpeg-turbo instead of libjpeg. > > > > > > In my opinion the project is useful for other people because it has some > > benefits over PIL. For example it supports modern file formats that > > aren't supported by PIL, for example JPEG 2000, HDR formats and RAW > > camera formats. Contrary to PIL it even supports G3 and G4 compressed > > TIIFs as well as multipage TIFFs. In some areas it's also much faster > > than PIL, especially JPEG performance and NumPy buffer access. > > > > However it's not going to replace PIL as neither FreeImage nor my code > > supports drawing, text composition or extended filters. > > > > > > Excerpt from the README: > > > > Features of FreeImage > > ===================== > > > > FreeImage wraps mature and widely-used libraries like LibJPEG, > > LibOpenJPEG,LibPNG, LibRaw, LibTIFF4, OpenEXR and zlib in a consistent, > > well documented and powerful set of APIs. > > > > http://freeimage.sourceforge.net/ > > > > Reading of 35 file formats and writing of more than 19 file formats as > > of FreeImage 3.15.3, including JPEG 2000, multiple subformats of TIFF > > with G3/G4 fax compression and JPEG subsampling. > > > > pixel depths from 1-32 bpp standard images up to formats like RGBAF and > > 2x64complex. > > > > multi page images > > > > Metadata (e.g. EXIF, IPTC/NAA, GeoTIFF, XMP) and ICC > > > > Color adjustment, conversion and channel processing > > > > Image resizing and rotation > > > > High Dynamic Range (HDR) image processing and tone mapping > > > > RAW camera files > > > > Contrary to PIL it doesn't contain advanced image filters or drawing > > functions. FreeImage focuses on file formats > > > > > > Features of LCMS2 > > ================= > > > > LCMS2 is a color management engine that implements V2 and V4 ICC > > profiles up to V4.3. It supports transformation, proofing and > > introspection of profiles for a large variety of color formats and targets. > > > > http://www.littlecms.com/ > > > > > > Features of smc.freeimage > > ========================= > > > > smc.freeimage is developed as part of the closed source Visual Library > > framework. > > > > mostly written with Cython with some lines of handwritten C Code and > > some Python helpers. > > > > fast, it avoids copying large amounts of data and releases the GIL > > whenever possible. > > > > 64bit safe, tested on i386/X86 and AMD64/X86_64 systems > > > > thread safe > > > > wraps a large subset of FreeImage features > > > > Compatible with Python 2.6 to 3.3. > > > > > > Performance > > =========== > > > > smc.freeimage with libjpeg-turbo read JPEGs about three to six times > > faster than PIL and writes JPEGs more than five times faster. > > > > JPEG's restart markers are not compatible with libjpeg-turbo's Huffman > > decoder optimization and reduce performance a lot. Please read the > > section "Restart Makers" on the page > > http://www.libjpeg-turbo.org/About/Performance for more information. > > > > Python 2.7.3 > > read / write cycles: 300 > > test image: 1210x1778 24bpp JPEG (pon.jpg) > > platform: Ubuntu 12.04 X86_64 > > hardware: Intel Xeon hexacore W3680 at 3.33GHz with 24 GB RAM > > > > smc.freeimage, FreeImage 3.15.3 standard > > - read JPEG 12.857 sec > > - read JPEG 6.629 sec (resaved) > > - write JPEG 21.817 sec > > smc.freeimage, FreeImage 3.15.3 with jpeg turbo > > - read JPEG 9.297 sec > > - read JPEG 3.909 sec (resaved) > > - write JPEG 5.857 sec > > - read LZW TIFF 17.947 sec > > - read biton G4 TIFF 2.068 sec > > - resize 3.850 sec (box) > > - resize 5.022 sec (bilinear) > > - resize 7.942 sec (bspline) > > - resize 7.222 sec (bicubic) > > - resize 7.941 sec (catmull rom spline) > > - resize 10.232 sec (lanczos3) > > - tiff numpy.asarray() with bytescale() 0.006 sec > > - tiff load + numpy.asarray() with bytescale() 18.043 sec > > PIL 1.1.7 > > - read JPEG 30.389 sec > > - read JPEG 23.118 sec (resaved) > > - write JPEG 34.405 sec > > - read LZW TIFF 21.596 sec > > - read biton G4 TIFF: decoder group4 not available > > - resize 0.032 sec (nearest) > > - resize 1.074 sec (bilinear) > > - resize 2.924 sec (bicubic) > > - resize 8.056 sec (antialias) > > - tiff scipy fromimage() with bytescale() 1.165 sec > > - tiff scipy imread() with bytescale() 22.939 sec > > > > > > Comparison to PIL (Pros and Cons) > > ================================= > > > > Pros of smc.freeimage > > --------------------- > > > > Faster! JPEG performance is about 3 to 6 times faster than PIL, numpy > > buffer access is more than 100 times faster and consumes less memory due > > to zero copy design. > > > > Modern file formats! smc.freeimage supports JPEG 2000, HDR and EXR high > > dynamic range images and raw camera data (RAW). > > > > Full baseline TIFF support! Contrary to PIL smc.freeimage supports all > > flavors of baseline TIFF like G3 and G4 compression and multipage TIFFs. > > > > PEP 3118 buffer interface that exports images as 2d or 3d non-contiguous > > buffer. > > > > Correct and optimized integration of a color management system > > (LittleCMS2)instead of lcms1 integration including caching of optimized > > transformations, in-place transformation and introspection of profiles. > > > > Structured metadata access to EXIF, XMP and IPTC information, also > > supports fast loading of metadata without loading pixel data. > > > > Lot's of color types! Bitmap (8bit) with 1, 4, 8, 16, 24 and 32 bits per > > pixel, (unsigned) int 16 and 32, float, double gray scale, complex, RGBA > > 16bit and RGBA floats. > > > > Static build support, no need for "make install". You just need a C99 > > compatible C/C++ compiler, make and nasm (for FreeImage-Turob). > > > > > > Cons of smc.freeimage > > ---------------------- > > > > Few image filters, no support for complex image filters in FreeImage > > > > Low quality resize filters are slower than PIL's filters > > > > No drawing API for primitives (lines, circles, boxes) > > > > No text drawing support and libfreetype integration. > > > > Still not feature complete and under development. > > > > > > FreeImage + libjpeg-turbo > > ========================= > > > > An experimental fork of FreeImage with libjpeg-turbo is available at > > https://bitbucket.org/tiran/freeimageturbo > > > > > > Feel free to contact me if you are interested in the library or want to > > get involved! > > > > Christian Do you need to work out edge dection maps that trace edge contours to be scallable funtional curves from control points obtained after image segmentations? curve by control points from From ethan at stoneleaf.us Wed Aug 15 19:26:09 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Aug 2012 16:26:09 -0700 Subject: dbf.py API question concerning Index.index_search() Message-ID: <502C3011.7070103@stoneleaf.us> Indexes have a new method (rebirth of an old one, really): .index_search( match, start=None, stop=None, nearest=False, partial=False ) The defaults are to search the entire index for exact matches and raise NotFoundError if it can't find anything. match is the search criteria start and stop is the range to search in nearest returns where the match should be instead of raising an error partial will find partial matches The question is what should the return value be? I don't like the usual pattern of -1 meaning not found (as in 'nothere'.find('a')), so I thought a fun and interesting way would be to subclass long and override the __nonzero__ method to return True/False based on whether the (partial) match was found. The main problems I see here is that the special return value reverts to a normal int/long if anything is done to it (adding, subtracting, etc), and the found status is lost. The other option is returning a (number, bool) tuple -- safer, yet more boring... ;) Thoughts? ~Ethan~ From python.list at tim.thechases.com Wed Aug 15 19:38:44 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Aug 2012 18:38:44 -0500 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C3011.7070103@stoneleaf.us> References: <502C3011.7070103@stoneleaf.us> Message-ID: <502C3304.70805@tim.thechases.com> On 08/15/12 18:26, Ethan Furman wrote: > .index_search( > match, > start=None, > stop=None, > nearest=False, > partial=False ) > > The defaults are to search the entire index for exact matches and raise > NotFoundError if it can't find anything. > > The question is what should the return value be? > > I don't like the usual pattern of -1 meaning not found (as in > 'nothere'.find('a')), so I thought a fun and interesting way would be to > subclass long and override the __nonzero__ method to return True/False > based on whether the (partial) match was found. The main problems I see > here is that the special return value reverts to a normal int/long if > anything is done to it (adding, subtracting, etc), and the found status > is lost. > > The other option is returning a (number, bool) tuple -- safer, yet more > boring... ;) I'm not quite sure I follow...you start off by saying that it will "raise NotFoundError" if it can't find anything. So if it finds something, just return it. Because if it found the item, it gives it to you; if it didn't find the item, it raised an error. That sounds like a good (easy to understand) interface, similar to how string.index() works. -tkc From steve+comp.lang.python at pearwood.info Wed Aug 15 19:54:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Aug 2012 23:54:54 GMT Subject: email with a non-ascii charset in Python3 ? References: Message-ID: <502c36ce$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 17:57:47 +0100, MRAB wrote: >> #!/usr/bin/python3 >> #_*_ coding: latin1 _*_ >> > Aw well as the other replies, the "coding" line should be: > > #-*- coding: latin1 -*- I don't believe that actually matters to Python. It may matter to Emacs or some other editors, but Python simply matches on this regex: coding[=:]\s*([-\w.]+) http://docs.python.org/py3k/reference/lexical_analysis.html#encoding-declarations -- Steven From worldpeaceagentforchange at gmail.com Wed Aug 15 19:56:26 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Wed, 15 Aug 2012 16:56:26 -0700 (PDT) Subject: A difficulty with lists In-Reply-To: References: Message-ID: <275392ae-09e2-469d-a9e3-43a9f50eece5@googlegroups.com> On Monday, August 6, 2012 3:50:13 PM UTC-4, Mok-Kong Shen wrote: > I ran the following code: > > > > def xx(nlist): > > print("begin: ",nlist) > > nlist+=[999] > > print("middle:",nlist) > > nlist=nlist[:-1] > > print("final: ",nlist) > > > > u=[1,2,3,4] > > print(u) > > xx(u) > > print(u) > > > > and obtained the following result: > > > > [1, 2, 3, 4] > > begin: [1, 2, 3, 4] > > middle: [1, 2, 3, 4, 999] > > final: [1, 2, 3, 4] > > [1, 2, 3, 4, 999] > > > > As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. > > Could someone kindly help? > > > > M. K. Shen I've modified your code slightly so you can see what's happening with u in the middle of function xx. Take a look: u=[1,2,3,4] def xx(nlist): print("xx(u)\n") print("At first, u and nlist refer to the same list") print("nlist: %s u: %s\n" % (nlist, u)) nlist+=[999] print("nlist+=[999]\n") print("The list has been modified in place. u and nlist are still equal") print("nlist: %s u: %s\n" %(nlist, u)) nlist=nlist[:-1] print("nlist=nlist[:1]\n") print("Now nlist refers to a new list object in memory that was created by") print("taking a slice of u. u and nlist are no longer equal.") print("nlist: %s u: %s" %(nlist, u)) xx(u) Here's the output: xx(u) At first, u and nlist refer to the same list nlist: [1, 2, 3, 4] u: [1, 2, 3, 4] nlist+=[999] The list has been modified in place. u and nlist are still equal nlist: [1, 2, 3, 4, 999] u: [1, 2, 3, 4, 999] nlist=nlist[:1] Now nlist refers to a new list object in memory that was created by taking a slice of u. u and nlist are no longer equal. nlist: [1, 2, 3, 4] u: [1, 2, 3, 4, 999] Thank you, Rob Day, for explaining a some of what's happening behind the scenes. From tjreedy at udel.edu Wed Aug 15 20:01:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Aug 2012 20:01:46 -0400 Subject: OT: Monty Python in Syria In-Reply-To: References: <502BF55B.6030506@googlemail.com> Message-ID: On 8/15/2012 6:07 PM, Mark Lawrence wrote: > On 15/08/2012 20:15, Tamer Higazi wrote: >> Exactly! >> NOT PROGRAMMING related has NOTHING TODO HERE! >> > > Please don't shout, please don't top post agreed. > and what gives you the right > to determine what is or is not on topic here? The same right as anyone. > The subject is also > clearly marked OT or did that escape your attention? But it has nothing to do with Monty Python either, that I can see. Nor is there a video to see the context of (OP said "For context, start the video at 1:00.") Perhaps link is erroneous. Marking something OT does not excuse it. It should still be related. We cannot allow 1000s of OT posts a day, marked OT or not. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Aug 15 20:16:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 00:16:03 GMT Subject: Dynamically determine base classes on instantiation References: Message-ID: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 23:17:41 +0200, Thomas Bach wrote: > Hi list, > > I'm confronted with a strang problem I cannot find a clean solution for. > I want a class that determines on instantiating its base classes > dynamically. Consider the following two use cases Some comments: 1) What you show are not "use cases", but "examples". A use-case is a description of an actual real-world problem that needs to be solved. A couple of asserts is not a use-case. 2) You stated that you have a "strange problem", but you haven't told us what that problem is, you went directly to what you think is the solution: "a class that determines on instantiating its base classes dynamically". How about you tell us the problem, and we'll suggest a solution? I'm pretty sure it isn't going to be what you asked for, because that goes completely against the fundamentals of object-oriented design. Consider your two examples: a = Foo(['a', 'list']) b = Foo({'blah': 8}) According to your design: a is a Foo b is a Foo therefore a and b are the same type So far so good: this is perfectly normal object-oriented design. But you also have a is a list, but not a dict b is a dict, but not a list therefore a and b are different types So you contradict yourself: at the same time, a and b are both the same and different types. So now you see why you shouldn't do what you ask for. Now let me tell you why you *can't* do what you ask for: Python's classes don't work like that. You can't set the base classes of an instance individually. All instances of a class share the same base classes. I think that the right solution here is not inheritance, but composition and delegation. You're already on the right track when you give your Foo instances an attribute _obj and then operate on that, but you are wrong to focus on inheritance. Instead, Foo should implement only the shared operations, and everything else should be delegated to _obj. Automatic delegation is trivially easy (except see below): http://code.activestate.com/recipes/52295 This is a *really old* recipe, from ancient days before you could inherit from built-in types like list, dict etc., so the description of the problem is no longer accurate. But the technique is still good, with unfortunately one complication: If you inherit from builtins, you cannot use automatic delegation on the magic "double-underscore" (dunder) methods like __eq__, __len__, etc. See this thread here for one possible solution: http://www.velocityreviews.com/forums/t732798-automatic-delegation-in-python-3-a.html -- Steven From ethan at stoneleaf.us Wed Aug 15 20:21:15 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Aug 2012 17:21:15 -0700 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C3304.70805@tim.thechases.com> References: <502C3011.7070103@stoneleaf.us> <502C3304.70805@tim.thechases.com> Message-ID: <502C3CFB.8080504@stoneleaf.us> Tim Chase wrote: > On 08/15/12 18:26, Ethan Furman wrote: >> .index_search( >> match, >> start=None, >> stop=None, >> nearest=False, >> partial=False ) >> >> The defaults are to search the entire index for exact matches and raise >> NotFoundError if it can't find anything. >> >> The question is what should the return value be? >> >> I don't like the usual pattern of -1 meaning not found (as in >> 'nothere'.find('a')), so I thought a fun and interesting way would be to >> subclass long and override the __nonzero__ method to return True/False >> based on whether the (partial) match was found. The main problems I see >> here is that the special return value reverts to a normal int/long if >> anything is done to it (adding, subtracting, etc), and the found status >> is lost. >> >> The other option is returning a (number, bool) tuple -- safer, yet more >> boring... ;) > > I'm not quite sure I follow...you start off by saying that it will > "raise NotFoundError" if it can't find anything. So if it finds > something, just return it. Because if it found the item, it gives > it to you; if it didn't find the item, it raised an error. That > sounds like a good (easy to understand) interface, similar to how > string.index() works. Indeed, it's even less clear without the part you snipped. ;) Which wasn't very. The well-hidden clue was this line: nearest returns where the match should be instead of raising an error And my question should have been: What should the return value be when nearest == True? My bit of fun was this class: class IndexLocation(long): """used by Index.index_search -- represents the index where the match criteria is if True, or would be if False""" def __new__(cls, value, found): "value is the number, found is True/False" result = long.__new__(cls, value) result.found = found return result def __nonzero__(self): return self.found ~Ethan~ From tjreedy at udel.edu Wed Aug 15 20:21:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Aug 2012 20:21:22 -0400 Subject: A difficulty with lists In-Reply-To: References: <16702a22-6ce3-4120-bbcc-9649e1717130@googlegroups.com> Message-ID: On 8/15/2012 5:58 PM, Rob Day wrote: > Madison May wrote: > The list nlist inside of function xx is not the same as the variable > u outside of the function: nlist and u refer to two separate list > objects. When you modify nlist, you are not modifying u. > This is confused and wrong. The parameter *name* 'nlist' of function xx is not the same as the *name* 'u' outside the function. The call xx(u) binds nlist to the same object that u is bound to. At that point, the two name *are* bound to the same list object. The statement "nlist+=[999]" dodifying nlist *does* modify u. The subsequent assignment statement "nlist=nlist[:-1]" rebinds 'nlist' to a *new* list object. That new object gets deleted when the function returns. So the rebinding is completely useless. This sequence, modifying the input argument and then rebinding to a new object, is bad code. > Well - that's not quite true. Before calling the function, u is [1, 2, > 3, 4] - but after calling the function, u is [1, 2, 3, 4, 999]. This is > a result of using 'nlist += [999]' - the same thing doesn't happen if > you use 'nlist = nlist+[999]' instead. > > I'm not completely aware of what's going on behind the scenes here, but you got it right. > I think the problem is that 'nlist' is actually a reference to a list > object - it points to the same place as u. Calling a python function binds parameter names to argument objects or (for *args and **kwds parameters) a collection based on argument objects. > When you assign to it within > the function, then it becomes separate from u - which is why nlist = > nlist+[999] and nlist = nlist[:-1] don't modify u - but if you modify > nlist in place before doing that, such as by using +=, then it's still > pointing to u, and so u gets modified as well. -- Terry Jan Reedy From robertmiles at teranews.com Wed Aug 15 20:26:21 2012 From: robertmiles at teranews.com (Robert Miles) Date: Wed, 15 Aug 2012 19:26:21 -0500 Subject: lambda in list comprehension acting funny In-Reply-To: References: <4ffe4a1f$0$1781$c3e8da3$76491128@news.astraweb.com> Message-ID: On 7/11/2012 11:39 PM, Dennis Lee Bieber wrote: > On 12 Jul 2012 03:53:03 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> "ALU class"? >> >> Googling gives me no clue. > > Arithmetic/Logic Unit > > http://en.wikipedia.org/wiki/Arithmetic_logic_unit > http://en.wikipedia.org/wiki/74181 > {diversion: http://en.wikipedia.org/wiki/VAX-11/780 -- incredible... > that used to be considered a "super-mini" when I worked on them; and now > would be shamed by most laptops except for the ability to support so > many users concurrently (let me know when a Windows laptop supports 32 > VT-100 class connections )} Installing Cygwin (a Linux emulation) under Windows appears to add some VT-100 support but without an easy way to find documentation on whether it can support 32 of them or not. I used to work on a VAX 11/780 and also a VAX 8600. Cygwin has a version of Python available, in case you're interested. Robert Miles From python.list at tim.thechases.com Wed Aug 15 20:28:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Aug 2012 19:28:31 -0500 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C3CFB.8080504@stoneleaf.us> References: <502C3011.7070103@stoneleaf.us> <502C3304.70805@tim.thechases.com> <502C3CFB.8080504@stoneleaf.us> Message-ID: <502C3EAF.5050802@tim.thechases.com> On 08/15/12 19:21, Ethan Furman wrote: > The well-hidden clue was this line: > > nearest returns where the match should be instead of raising an error > > And my question should have been: > > What should the return value be when nearest == True? Ah, well that's somewhat clearer. Return the closest and not bother to let the user know it was inexact. Upon requesting it with nearest=True, they *knew* that the result might be a nearest match. Though if they ask for nearest, an exact match *better* be the nearest if it exists. :-P I'd say the API-user shouldn't ask for what they don't want. -tkc From steve+comp.lang.python at pearwood.info Wed Aug 15 20:52:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 00:52:10 GMT Subject: dbf.py API question concerning Index.index_search() References: Message-ID: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Aug 2012 16:26:09 -0700, Ethan Furman wrote: > Indexes have a new method (rebirth of an old one, really): > > .index_search( > match, > start=None, > stop=None, > nearest=False, > partial=False ) [...] Why "index_search" rather than just "search"? > The question is what should the return value be? > > I don't like the usual pattern of -1 meaning not found (as in > 'nothere'.find('a')) And you are right not to. The problem with returning -1 as a "not found" sentinel is that if it is mistakenly used where you would use a "found" result, your code silently does the wrong thing instead of giving an exception. So pick a sentinel value which *cannot* be used as a successful found result. Since successful searches return integer offsets (yes?), one possible sentinel might be None. (That's what re.search and re.match return instead of a MatchObject.) But first ensure that None is *not* valid input to any of your methods that take an integer. For example, if str.find was changed to return None instead of -1 that would not solve the problem, because None is a valid argument for slices: p = mystring.find(":") print(mystring[p:-1]) # Oops, no better with None You don't have to predict every imaginable failure mode or defend against utterly incompetent programmers, just against the obvious failure modes. If None is not suitable as a sentinel, create a constant value that can't be mistaken for anything else: class NotFoundType(object): def __repr__(self): return "Not Found" __str__ = __repr__ NOTFOUND = NotFoundType() del NotFoundType and then return that. (By the way, I'm assuming that negative offsets are valid for your application. If they aren't, then using -1 as sentinel is perfectly safe, since passing a "not found" -1 as offset to another method will result in an immediate exception.) > The other option is returning a (number, bool) tuple -- safer, yet more > boring... ;) Boring is good, but it is also a PITA to use, and that's not good. I never remember whether the signature is (offset, flag) or (flag, offset), and if you get it wrong, your code will probably fail silently: py> flag, offset = (23, False) # Oops, I got it wrong. py> if flag: ... print("hello world"[offset+1:]) ... ello world -- Steven From amc96 at cam.ac.uk Wed Aug 15 20:52:37 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Thu, 16 Aug 2012 01:52:37 +0100 Subject: OT: Monty Python in Syria In-Reply-To: References: <502BF55B.6030506@googlemail.com> Message-ID: On 16/08/2012 01:01, Terry Reedy wrote: > On 8/15/2012 6:07 PM, Mark Lawrence wrote: >> On 15/08/2012 20:15, Tamer Higazi wrote: >>> Exactly! >>> NOT PROGRAMMING related has NOTHING TODO HERE! >>> >> >> Please don't shout, please don't top post > > agreed. > >> and what gives you the right >> to determine what is or is not on topic here? > > The same right as anyone. > >> The subject is also >> clearly marked OT or did that escape your attention? > > But it has nothing to do with Monty Python either, that I can see. Then I humbly suggest you re-watch The Holy Grail. ~Andrew > Nor is there a video to see the context of (OP said "For context, start > the video at 1:00.") Perhaps link is erroneous. > > Marking something OT does not excuse it. It should still be related. We > cannot allow 1000s of OT posts a day, marked OT or not. > From amc96 at cam.ac.uk Wed Aug 15 20:56:50 2012 From: amc96 at cam.ac.uk (Andrew Cooper) Date: Thu, 16 Aug 2012 01:56:50 +0100 Subject: OT: Monty Python in Syria In-Reply-To: References: <502BF55B.6030506@googlemail.com> Message-ID: On 16/08/2012 01:52, Andrew Cooper wrote: > On 16/08/2012 01:01, Terry Reedy wrote: >> On 8/15/2012 6:07 PM, Mark Lawrence wrote: >>> On 15/08/2012 20:15, Tamer Higazi wrote: >>>> Exactly! >>>> NOT PROGRAMMING related has NOTHING TODO HERE! >>>> >>> >>> Please don't shout, please don't top post >> >> agreed. >> >>> and what gives you the right >>> to determine what is or is not on topic here? >> >> The same right as anyone. >> >>> The subject is also >>> clearly marked OT or did that escape your attention? >> >> But it has nothing to do with Monty Python either, that I can see. > > Then I humbly suggest you re-watch The Holy Grail. > > ~Andrew > >> Nor is there a video to see the context of (OP said "For context, start >> the video at 1:00.") Perhaps link is erroneous. P.S. - There is certainly a video. It just takes an obnoxiously long time to load. >> >> Marking something OT does not excuse it. It should still be related. We >> cannot allow 1000s of OT posts a day, marked OT or not. >> > From ethan at stoneleaf.us Wed Aug 15 21:22:02 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Aug 2012 18:22:02 -0700 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502C4B3A.6000603@stoneleaf.us> Steven D'Aprano wrote: > On Wed, 15 Aug 2012 16:26:09 -0700, Ethan Furman wrote: > >> Indexes have a new method (rebirth of an old one, really): >> >> .index_search( >> match, >> start=None, >> stop=None, >> nearest=False, >> partial=False ) > [...] > > Why "index_search" rather than just "search"? Because "search" already exists and returns a dbf.List of all matching records. ~Ethan~ From xs.nepaul at gmail.com Wed Aug 15 21:52:29 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 18:52:29 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> <502bba24$0$6979$e4fe514c@news2.news.xs4all.nl> <878vdgp4c6.fsf@dpt-info.u-strasbg.fr> Message-ID: <7c2f8e49-e15f-43c5-8488-70309c08a4da@googlegroups.com> ? 2012?8?16????UTC+8??12?58?07??Dennis Lee Bieber??? > On Wed, 15 Aug 2012 17:22:49 +0200, Alain Ketterlin > > declaimed the following in > > gmane.comp.python.general: > > > > > Hans Mulder writes: > > > > Right? > > > On 15/08/12 15:30:26, nepaul wrote: > > > >> The code: > > > >> import MySQLDB > > > >> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > > >> > > > >> > > > >> > > > >> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', > > > >> passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > > > > > > > This message means that the MySQL connector cannot find 'localhost'. > > > > > > No, it means that connect received a single string "user = 'root'..." > > > instead of a set of individual keyword parameters, and took the whole > > > string to be the name of the host (its first parameter). Of course, > > > there is no host with such a name. > > > > > > The solution is to parse the string into individual values, and pass > > > these in the correct order. > > > > MySQLdb code itself recommends to always use keyword parameters, so > > the order shouldn't be significant... (and when one sees the list of > > optional keywords, using null commas to space positional arguments would > > be insane) > > > > Parsing that string into separate fields (preferably a dictionary so > > **conectitems could be used) OTOH is critical. > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ From xs.nepaul at gmail.com Wed Aug 15 21:52:29 2012 From: xs.nepaul at gmail.com (nepaul) Date: Wed, 15 Aug 2012 18:52:29 -0700 (PDT) Subject: _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host In-Reply-To: References: <6a5212e3-4ff9-4cec-afe5-8b81e231eb67@googlegroups.com> <502bba24$0$6979$e4fe514c@news2.news.xs4all.nl> <878vdgp4c6.fsf@dpt-info.u-strasbg.fr> Message-ID: <7c2f8e49-e15f-43c5-8488-70309c08a4da@googlegroups.com> ? 2012?8?16????UTC+8??12?58?07??Dennis Lee Bieber??? > On Wed, 15 Aug 2012 17:22:49 +0200, Alain Ketterlin > > declaimed the following in > > gmane.comp.python.general: > > > > > Hans Mulder writes: > > > > Right? > > > On 15/08/12 15:30:26, nepaul wrote: > > > >> The code: > > > >> import MySQLDB > > > >> strCmd = "user = 'root', passwd = '123456', db = 'test', host = 'localhost'" > > > >> > > > >> > > > >> > > > >> _mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'user = 'root', > > > >> passwd = '123456', db = 'test', host = 'localhost'' (11004)") > > > > > > > > This message means that the MySQL connector cannot find 'localhost'. > > > > > > No, it means that connect received a single string "user = 'root'..." > > > instead of a set of individual keyword parameters, and took the whole > > > string to be the name of the host (its first parameter). Of course, > > > there is no host with such a name. > > > > > > The solution is to parse the string into individual values, and pass > > > these in the correct order. > > > > MySQLdb code itself recommends to always use keyword parameters, so > > the order shouldn't be significant... (and when one sees the list of > > optional keywords, using null commas to space positional arguments would > > be insane) > > > > Parsing that string into separate fields (preferably a dictionary so > > **conectitems could be used) OTOH is critical. > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ From gbaratto at gmail.com Wed Aug 15 21:57:32 2012 From: gbaratto at gmail.com (Gustavo Baratto) Date: Wed, 15 Aug 2012 18:57:32 -0700 Subject: SSLSocket.getpeercert() doesn't return issuer, serial number, etc Message-ID: Hello there, SSL.Socket.getpeercert() doesn't return essential information present in the client certificate (issuer, serial number, not before, etc), and it looks it is by design: http://docs.python.org/library/ssl.html#ssl.SSLSocket.getpeercert http://hg.python.org/cpython/file/b878df1d23b1/Modules/_ssl.c#l866 By deliberately removing all that information, further verification/manipulation of the cert becomes impossible. Revocation lists, OCSP, and any other extra layers of certificate checking cannot be done properly without all the information in the cert being available. Is there anyway around this? There should be at least a flag for folks that need all the information in the certificate. Thanks! g. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Aug 15 22:20:04 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Aug 2012 03:20:04 +0100 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C3EAF.5050802@tim.thechases.com> References: <502C3011.7070103@stoneleaf.us> <502C3304.70805@tim.thechases.com> <502C3CFB.8080504@stoneleaf.us> <502C3EAF.5050802@tim.thechases.com> Message-ID: <502C58D4.906@mrabarnett.plus.com> On 16/08/2012 01:28, Tim Chase wrote: > On 08/15/12 19:21, Ethan Furman wrote: >> The well-hidden clue was this line: >> >> nearest returns where the match should be instead of raising an error >> >> And my question should have been: >> >> What should the return value be when nearest == True? > > Ah, well that's somewhat clearer. Return the closest and not bother > to let the user know it was inexact. Upon requesting it with > nearest=True, they *knew* that the result might be a nearest match. > Though if they ask for nearest, an exact match *better* be the > nearest if it exists. :-P > > I'd say the API-user shouldn't ask for what they don't want. > +1 From python at mrabarnett.plus.com Wed Aug 15 22:21:18 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Aug 2012 03:21:18 +0100 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C4B3A.6000603@stoneleaf.us> References: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> <502C4B3A.6000603@stoneleaf.us> Message-ID: <502C591E.2060700@mrabarnett.plus.com> On 16/08/2012 02:22, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Wed, 15 Aug 2012 16:26:09 -0700, Ethan Furman wrote: >> >>> Indexes have a new method (rebirth of an old one, really): >>> >>> .index_search( >>> match, >>> start=None, >>> stop=None, >>> nearest=False, >>> partial=False ) >> [...] >> >> Why "index_search" rather than just "search"? > > Because "search" already exists and returns a dbf.List of all matching > records. > Perhaps that should've been called "find_all"! From suziemrezitti at gmail.com Wed Aug 15 22:26:19 2012 From: suziemrezitti at gmail.com (Suzi Mrezutttii) Date: Wed, 15 Aug 2012 19:26:19 -0700 (PDT) Subject: Google the video "9/11 Missing Links". 9/11 was a Jew Job! Message-ID: <49a0e437-ed34-4ec3-86c7-5ae66c3d6d6c@n19g2000yqc.googlegroups.com> COPY THIS MESSAGE FAST BECAUSE JEWS AND TRAITORS DELETE IT FAST! After Jews created Israel illegally, Israel became the main base of criminal operations for the most insane type of Jews called Zionists. Israeli Jews murdered JFK in 1963 because JFK did not allow them to have atomic bombs. Read the book "Final Judgment" by Michael Piper, available online in pdf, also google for video presentation by the author. Since Americans let the Jews get away with JFK murder, just four years later in 1967, Israeli Jews slaughtered 34 servicemen of American Navy, and seriously wounded 174, when Jews tried repeatedly to sink the USS Liberty and blame Egypt for it. Watch online the video interviews with the actual survivors, then compare the facts to the lies spread by Jews through their propaganda outlets like wikipedia. One interview with a survivor should have been enough to turn all responsible Jews and American Traitors into fertilizer within 24 hours. Since Americans let Jews get away with JFK and USS Liberty murders, Israeli Jews slaughtered 3000 Americans in 9/11, this time to make USA invade Afghanistan/Iraq for Jews, and to enable Jews to impose their Jew Laws (Jaws) like "Patriot Act". Watch online the video "9/11 Missing Links" made in cooperation with contacts inside FBI, CIA, National Security Agency, US Military, who are still loyal to USA. All Jews covered up for Israeli Zionists, with the help from Traitors in Washington DC, because all Jews always protect themselves as single Jew Tribe. Jews are not the sweet/smart/suffering individuals as they present themselves using their own Jew propaganda machines. Jews are full of hate and suffer from a whole range of genetic mental diseases like psychopathy, genocidal/homicidal tendencies, schizophrenia, paranoia, sexual perversions like pedophilia/homosexuality/etc, and many others, that make them prone to criminal/parasitic/corruptive/destructive behavior. Banking Jews started their corruption of USA in 1913 with creation of the Fed. The Great Depression of 1930's was the direct result of Jew corruption. Jews used Great Depression as an opportunity to corrupt/ expand the federal government because parasites like Jews exploit host organisms through central systems. After Hitler came to power in 1933 and removed Jews from all important positions, Germany experienced unprecedented economic growth while the rest of the world controlled by Jews suffered through Great Depression. Jews did not like this precedent and immediately in 1933 Jews declared economic war on Germany. Hitler invaded Poland in 1939 only because Poland was infested with five million Jews who constantly were harassing Germany. Jews used their media power to brainwash White Americans to fight White Germans for Jews. All the official "history" has been written by lying Jews and it should be called Jewstory instead of History. Jews are not Whites but insane mongrels who hate Whites. Jews started all the jokes about Whites like Dumb Blondes, Rednecks, Polish Jokes. The sheeple merely parroted after the Jew media. Jews are the ones who promote all those Blacks you see in the media, sports, schools, or business. Jews constantly stir up conflicts between Whites and Blacks by propagandizing the shootings of Blacks in order to take your attention away from all Jew scams. Since 9/11 Jews intensified their "Racism" tactics and their famous "Holocaust" tactics because more Americans learn every day that Jews did 9/11. Jews know they are the biggest Criminals on Earth, and that is why Jews manufactured the "Holocaust" Scam where Jews masquerade as the biggest Victims on Earth. Jews are Masters of biggest Lies and Deceptions. Without their control of brainwashing media, Jews would be nothing more than insane rats. Only Jew scams enabled many Jews to masquerade with Ivy League diplomas, Nobel Prizes, Oscars. Jews run their college/ Awards scams like Wall Street or elections scams. Independent investigations of all Ivy League colleges would show that most Jew students are frauds with standardized tests taken by somebody else or their test results falsified by corrupt admissions offices. Jews corrupted all top universities into factories printing diplomas for Jews and Jew clones. The biggest Jew Nobel Prize winner Albert Einstein was a fraud and plagiarist. All you know about famous Jew "scientists" is what Jews told you, the same Jews who made you believe the "Manned Moon Landings" or "Man-Made Global Warming". Jews never invented anything but Scams and Hoaxes. Jews in Israel rank well below average in IQ scores among all nations. Basically, Israel is a hellhole where tens of billions of dollars of American taxpayers' money are wasted on worthless Jews each year. Jews control the US Government illegally. The American democracy is a myth. Most of "US Presidents" since 1913 were crypto Jews (FDR, Eisenhower, LBJ, Obama with Jew mother) or Jew puppets/clones. Recently, Jews in US Congress imposed on Americans yet another Jew Law (Jaw) called "National Defense Authorization Act" that threatens any American who tries to defend The US Constitution with its Bill of Rights. All the Jaws out of Washington DC are meant to protect Jews and only Jews. However, the ultimate power lies in the economies, now all mortally wounded by Jews. Jews were too greedy by exporting all real American jobs and forcing Americans to live on debt for too long. Once enough good Americans reach poverty levels, the game will be over for Jews, especially if their psychotic relatives in Israel pull another USS Liberty or 9/11. How can Jews control the US Government with such a small Jew population? How can Jews amass so much wealth if Jews are not very intelligent? In order to answer such questions you have to look at the Big Picture painted for you by Mother Nature a long time ago. For thousands of years, each society had a small parasitic ruling class and a large working class needed to sustain the society. Mother Nature created such a social order to facilitate the evolutionary process because living conditions for humans were very tough. Mother Nature knew that a ruling class does not have to be very intelligent because any substantial intellect leads automatically to creativity needed only by working class. Instead, Mother Nature developed our human psychology in such a way that a ruling class could rule merely by displaying symbols of power like ornamental clothes, big buildings, rituals, propaganda, and so on. For this to work, a ruling class had to be filled with psychopaths only smart enough to band together for this scam to go on, and a working class had to be filled with intelligent people busy with doing all the creative work. At least the ruling and working classes were ethnically related until around 18th century when the biggest parasitic psychopaths called Jews learned enough about the game played by ruling classes. At that time, Jews decided to have a piece of the ruling action for themselves by creating central banks or starting revolutions. Jews have been around for thousands of years. Clearly, Mother Nature created Jews on her bad hair day because Jews hated all non-Jews including her best creations. This hatred made Jews the perfect tool to exploit the weaknesses of both ruling and working classes of all normal societies. By destroying the old social orders, Jews have acted like maggots decomposing dead animals. Mother Nature has kept Jews around for thousands of years because She needed them to change slowly the old social orders. Otherwise, Mother Nature would abort Jews a long time ago because Jews are genetically unable to have a productively working class of their own. Jews can live only as parasites in non-Jew societies. Jews were always close to the ruling classes because all parasitic psychopaths band together to exploit working classes, and that is why Jews were allowed to live as parasites. Since Mother Nature instilled so much hatred among Jews towards all non-Jews, Jews resisted miscegenation with non-Jews and thus Jews were able to carry their genetic mental diseases like parasitic psychopathy through the ages. Decomposition of the old social orders was largely completed by Jews in early 20th century, at least in the Western World. Since then, Jews have been trying to become the ruling class for the whole world. Jews corrupted everything to the bone including politics, media, economies, military, sciences, business, medicine and healthcare, education, agriculture, and all others. Through their insanity, Jews started two world wars and are about to start the third one, Jews killed millions with their invention of communism, Jews committed the biggest terrorist acts in history and always blamed others, Jews polluted the whole world with nuclear technologies, Jews destroyed agriculture and food supplies with GMO crops and other poisons, Jews killed millions with the poisons produced by their pharmaceutical companies, Jews imposed on societies their sexual perversions like pedophilia and homosexuality, Jews run all organized crime including illegal drugs and prostitution, Jews own most of the pornography business, and on and on. The old ruling classes would not be able to do so much harm to the working classes because there were many different societies with different ruling classes and the classes within each society were ethnically related. This means that fraudulent ruling classes could last forever without the working classes ever waking up. However, Mother Nature wants to make all psychopathic rulers extinct once they served their purpose in Nature. Mankind cannot live forever while locked in the old psychology addicted to psychopathic rulers, Jews or non-Jews. That is why Mother Nature used the biggest parasitic psychopaths Jews to force out the old parasitic ruling classes first, and now Mother Nature is using the same Jews to exploit/harm the working classes in order to initiate the next evolutionary step. Many people are already ready to deal with the Jew problem. However, most people still refuse to deal with it because they are still locked in the old psychology developed by Mother Nature thousands of years ago. The latter group of people will wake up at the latest when the economies collapse. Realize that Mother Nature made Jews screw up the attack on USS Liberty so that the survivors could tell you the truth about the US Government controlled by Jews. Mother Nature created the Internet for you so that you can research all Scams and Hoaxes done by Jews. In other words, Mother Nature realizes that it is time for you to change and Jews have to go before Jews do too much damage. Mother Nature keeps Jews around so that you can see for yourself with your own eyes that something is wrong with you. Just put yourself in the shoes of Mother Nature. How would you make your own children abandon their old bad habits? You would let the bad habits hurt your own children just enough to teach them a lesson. This is exactly what Mother Nature is doing to you except Mother Nature is willing to get many of her children killed in order for other children to live better in the future. If you have any doubts about Jews then watch the USS Liberty survivors describing how their fellow crewmen were slaughtered by Jews, or watch the videos of non-Jews jumping from the 9/11 Towers blown up by Jews. Help Mother Nature by not watching any Jew brainwashing media that makes you lose your own common sense! Otherwise, Mother Nature will bring the change violently! From ben+python at benfinney.id.au Thu Aug 16 00:38:22 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Aug 2012 14:38:22 +1000 Subject: email with a non-ascii charset in Python3 ? References: <502c36ce$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k3wze9j5.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 15 Aug 2012 17:57:47 +0100, MRAB wrote: > > >> #!/usr/bin/python3 > >> #_*_ coding: latin1 _*_ > >> > > Aw well as the other replies, the "coding" line should be: > > > > #-*- coding: latin1 -*- > > I don't believe that actually matters to Python. It may matter to > Emacs or some other editors I think that is sufficient for MRAB's ?should?. Especially since Python's specification is designed so that people can write a valid Emacs or Vim editor hint and have it work for Python. -- \ ?The best mind-altering drug is truth.? ?Jane Wagner, via Lily | `\ Tomlin | _o__) | Ben Finney From dan at tombstonezero.net Thu Aug 16 01:01:21 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 15 Aug 2012 22:01:21 -0700 Subject: [OT] Posting under ones full name In-Reply-To: References: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: <20120816050121.GA335@particle> On 2012-08-15 at 13:59:53 +0000, Grant Edwards wrote: > On 2012-08-15, Chris Angelico wrote: > > Perhaps you said "Please use `m4-style quotes rather than matching > > ASCII quotes' or `something else' to indicate omission instead". When I've got these antlers on I am dictating and when I take them off I am not dictating. -- Dan (who doesn't mind whether you use my last name or not) From dieter at handshake.de Thu Aug 16 01:19:11 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 16 Aug 2012 07:19:11 +0200 Subject: python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' References: Message-ID: <87a9xve7n4.fsf@handshake.de> Dmitry Arsentiev writes: > Has anybody already meet the problem like this? - > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > When I run scrapy, I get > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", > line 14, in > libxml2.HTML_PARSE_NOERROR + \ > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' Apparently, the versions of "scrapy" and "libxml2" do not fit. Check with which "libxml2" versions, your "scrapy" version can work and then install one of them. From dieter at handshake.de Thu Aug 16 01:24:50 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 16 Aug 2012 07:24:50 +0200 Subject: SSLSocket.getpeercert() doesn't return issuer, serial number, etc References: Message-ID: <87628je7dp.fsf@handshake.de> Gustavo Baratto writes: > SSL.Socket.getpeercert() doesn't return essential information present in the > client certificate (issuer, serial number, not before, etc), and it looks it > is by design: > > > > http://docs.python.org/library/ssl.html#ssl.SSLSocket.getpeercert > > http://hg.python.org/cpython/file/b878df1d23b1/Modules/_ssl.c#l866 > > > > By deliberately removing all that information, further > verification/manipulation of the cert becomes impossible. > > Revocation lists, OCSP, and any other extra layers of certificate checking > cannot be done properly without all the information in the cert being > available. I agree with you that the information should not be discarded. > Is there anyway around this??There should be at least a flag for folks that > need all the information in the certificate. You could use the parameter "binary_form=True". In this case, you get the DER-encoded certificate and can analyse it with (e.g.) "openssl". From noreply at python.org Thu Aug 16 02:14:53 2012 From: noreply at python.org (Bounced mail) Date: Thu, 16 Aug 2012 09:14:53 +0300 Subject: vfwlupcyftx Message-ID: The original message was received at Thu, 16 Aug 2012 09:14:53 +0300 from python.org [95.83.175.119] ----- The following addresses had permanent fatal errors ----- -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: RemovedAttachments660.txt URL: From stefan_ml at behnel.de Thu Aug 16 03:01:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 16 Aug 2012 09:01:33 +0200 Subject: Help needed installing easy_install and lxml2 In-Reply-To: <502BFAF6.9060502@gmail.com> References: <502BFAF6.9060502@gmail.com> Message-ID: Ian, 15.08.2012 21:39: > On a reasonably fresh (3 day old) install of 64 bit windows 7, I have > installed the 64 bit Python 2.7.3 from http://www.python.org/download/ > > Then I installed the 64 bit version of easy_install using > http://pypi.python.org/pypi/setuptools > > And then install lxml 2.3.5, for which I use the instructions at > http://lxml.de/installation.html#installation > > This ends with: > Processing lxml-2.3.5.tgz > Running lxml-2.3.5\setup.py -q bdist_egg --dist-dir > c:\users\ian\appdata\local\temp\easy_install-9__rq7\lxml-2.3.5\egg-dist-tmp-uj_v_2 > > Building lxml version 2.3.5. > Building without Cython. > ERROR: 'xslt-config' is not recognized as an internal or external command, > operable program or batch file. > > ** make sure the development packages of libxml2 and libxslt are installed ** > > Using build configuration of libxslt > error: Setup script exited with error: Unable to find vcvarsall.bat > > C:\Users\ian> > > Now what? I thought I was installing the binary package do I would not need > any development versions. > > What do these errors mean, and how can I overcome them? http://lxml.de/FAQ.html#where-are-the-binary-builds Stefan From johan at jvz.co.za Thu Aug 16 03:17:43 2012 From: johan at jvz.co.za (Johan van Zyl) Date: Thu, 16 Aug 2012 09:17:43 +0200 Subject: Installing Python 3.2.3 on Win 7 Message-ID: Hi I installed Python 3.2.3 successfully on my work laptop (XP) but cannot seem to do it on my home PC (Win7) I click the button to install and the window just disappears o the screen. So how do I in fact install Python 3.2.3 on Win 7? -- Johan van Zyl PMB - Box 21673, Mayors Walk, 3208 Pretoria - Box 2667, Brooklyn Square, 0075 FAX: 086 622 9554 The answer my friend is blowin in the wind... If you forward messages, Please use the BCC area, and Please REMOVE all email addresses and all the useless info at the bottom of the message, before you send it on. ONLY send out CLEAN and TIDY emails. Thank you. From mullapervez at gmail.com Thu Aug 16 03:23:05 2012 From: mullapervez at gmail.com (Pervez Mulla) Date: Thu, 16 Aug 2012 00:23:05 -0700 (PDT) Subject: how to call perl script from html using python In-Reply-To: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> Message-ID: <18ec5f51-ceca-4ecb-82b4-c472ea2faa22@googlegroups.com> On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, Pervez Mulla wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, Pervez Mulla wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, Pervez Mulla wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez On Tuesday, August 14, 2012 10:42:48 AM UTC+5:30, Pervez Mulla wrote: > Hi, > > > > I wanna call perl script in HTML form n store that data in DB using Python. > > > > How can i do this.......?? > > > > Please help me > > > > Thank you > > Pervez Hey Steven , Thank you for your response, I will in detail now about my project, Actually the project entire backend in PERL language , Am using Django framework for my front end . I have written code for signup page in python , which is working perfectly . In HTml when user submit POST method, it calling Python code ....Instead of this I wanna call perl script for sign up ...... below in form for sign up page in python .... form.py from django import forms from django.contrib.auth.models import User from django.forms import ModelForm from user_profile.models import Profile class RegistrationForm(ModelForm): username = forms.CharField(label=(u'User Name')) email = forms.EmailField(label=(u'E-mail')) password = forms.CharField(label=(u'Password'),widget=forms.PasswordInput(render_value=False)) password1 = forms.CharField(label=(u'Verify Password'),widget=forms.PasswordInput(render_value=False)) class Meta: model = Profile exclude = ('user',) def clean_username(self): username = self.cleaned_data['username'] try: User.objects.get(username==username) except User.DoesNotExist: return username raise forms.ValidationError("That username is already taken. Please select another.") def clean_password(self): if self.cleaned_data['password'] != self.cleaned_data['password1']: raise forms.ValidationError("Password didnt match... Please try again") return self.cleaned_data ----------------------------------------------------------------------------- view.py def ProfileRegistration(request): if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') if request.method =="POST": form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user(username = form.cleaned_data['username'], email = form.cleaned_data['email'], password = form.cleaned_data['password']) user.save() profile = Profile(user=user, firstname=form.cleaned_data['firstname'], lastname=form.cleaned_data['lastname'], phone=form.cleaned_data['phone'], title=form.cleaned_data['title'], companyname=form.cleaned_data['companyname']) profile.save() return HttpResponseRedirect('/profile/') else: return render_to_response ('register.html',{'form':form},context_instance=RequestContext(request)) else: form = RegistrationForm() context = {'form':form} return render_to_response('register.html', context, context_instance=RequestContext(request)) In view instead invoking python script I wanna invoke Perl script .....for the signup page Thank You From hobson42 at gmail.com Thu Aug 16 04:08:19 2012 From: hobson42 at gmail.com (Ian) Date: Thu, 16 Aug 2012 09:08:19 +0100 Subject: Help needed installing easy_install and lxml2 In-Reply-To: References: <502BFAF6.9060502@gmail.com> Message-ID: <502CAA73.8070605@gmail.com> On 16/08/2012 08:01, Stefan Behnel wrote: > http://lxml.de/FAQ.html#where-are-the-binary-builds Stefan Hi Stefan, Thanks Stefan, everything is working fine now. Regards Ian From jeanmichel at sequans.com Thu Aug 16 04:49:42 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Aug 2012 10:49:42 +0200 Subject: Sharing code between different projects? In-Reply-To: References: <20120814215118.GA19167@cskk.homeip.net> Message-ID: <502CB426.9040302@sequans.com> andrea crotti wrote: > 2012/8/14 Cameron Simpson : > >> Having just skimmed this thread, one thing I haven't quite seen suggested is >> this: >> >> Really do make a third "utilities" project, and treat "the project" and >> "deploy" as separate notions. So to actually run/deploy project A's code >> you'd have a short script that copied project A and the utilities project >> code into a tree and ran off that. Or even a simple process/script to >> update the copy of "utilities" in "project A"'s area. >> >> So you don't "share" code on an even handed basis but import the >> "utilities" library into each project as needed. >> >> I do this (one my own very small scale) in one of two ways: >> >> - as needed, copy the desired revision of utilities into the project's >> library space and do perforce's equivalent of Mercurial's addremove >> on that library tree (comment "update utilities to revision X"). >> >> - keep a perforce work area for the utilities in your project A area, >> where your working project A can hook into it with a symlink or some >> deploy/copy procedure as suggested above. >> With this latter one you can push back into the utilities library >> from your "live" project, because you have a real checkout. So: >> >> projectAdir >> projectA-perforce-checkout >> utilities-perforce-checkout >> projectBdir >> projectB-perforce-checkout >> utilities-perforce-checkout >> >> > > Thanks, is more or less what I was going to do.. But I would not use > symlinks and similar things, because then every user should set it up > accordingly. > > Potentially we could instead use the perforce API to change the > workspace mappings at run-time, and thus "force" perforce to checkout > the files in the right place.. > > There is still the problem that people should checkout things from two > places all the time instead of one.. > > SVN allows to define external dependencies, where one repository will actually checkout another one at a specific version. If SVN does it, I guess any decent SCM also provide such feature. Assuming our project is named 'common', and you have 2 projects A and B : A - common at rev1 B - common at rev2 Project A references the lib as "A.common", B as "B.common". You need to be extra carefull to never reference common as 'common' in any place. JM From python at rgbaz.eu Thu Aug 16 04:51:15 2012 From: python at rgbaz.eu (PythonAB) Date: Thu, 16 Aug 2012 10:51:15 +0200 Subject: OT: Monty Python in Syria In-Reply-To: References: <502BF55B.6030506@googlemail.com> Message-ID: <22E7A76E-5C43-4D8C-B8FA-F26AEA6375BA@rgbaz.eu> On 16 aug 2012, at 02:56, Andrew Cooper wrote: > On 16/08/2012 01:52, Andrew Cooper wrote: >> On 16/08/2012 01:01, Terry Reedy wrote: >>> On 8/15/2012 6:07 PM, Mark Lawrence wrote: >>>> On 15/08/2012 20:15, Tamer Higazi wrote: >>>>> Exactly! >>>>> NOT PROGRAMMING related has NOTHING TODO HERE! >>>>> >>>> >>>> Please don't shout, please don't top post >>> >>> agreed. >>> >>>> and what gives you the right >>>> to determine what is or is not on topic here? >>> >>> The same right as anyone. >>> >>>> The subject is also >>>> clearly marked OT or did that escape your attention? >>> >>> But it has nothing to do with Monty Python either, that I can see. >> >> Then I humbly suggest you re-watch The Holy Grail. >> >> ~Andrew >> >>> Nor is there a video to see the context of (OP said "For context, start >>> the video at 1:00.") Perhaps link is erroneous. > > P.S. - There is certainly a video. It just takes an obnoxiously long > time to load. > >>> >>> Marking something OT does not excuse it. It should still be related. We >>> cannot allow 1000s of OT posts a day, marked OT or not. >>> >> > I agree, adding "OT" shouldn't be an excuse to just post anything people want, should it? The URL has absolutely nothing to do with python whatsoever. At least not here as I can view it in The Netherlands. It's a news item about the 'rebels' in Syria who supposedly shot down this fighterplane. How someone can link that to Monty Python is worth a oscar for storytelling i think... gr arno From jeanmichel at sequans.com Thu Aug 16 05:29:43 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Aug 2012 11:29:43 +0200 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: Message-ID: <502CBD87.8030704@sequans.com> Lee Harr wrote: > pybotwar is a fun and educational game where players > write computer programs to control simulated robots. > > http://pybotwar.googlecode.com/ > > > The focus of this release is making all functionality > available from the PyQt interface and making PyQt > the default interface. > > pybotwar uses pybox2d for the physical simulation. > It can be run in text-only mode -- useful for longer > tournaments -- or use pyqt or pygame for a graphical > interface and visualization of the action. > > pybotwar is released under GPLv3. > > > Changes in pybotwar-0.8: > - pybox2d-2.0.2b2 is now the required version > > API > - Robot.turret() now takes turret speed instead of angle > - PING sensor now differentiates own bullets from enemy bullets > - PING differentiates dead robots when remove_dead_robots=False > - made internal Robot state variables less likely to conflict with user code > > Settings > - added "robots dir" setting to make it easier to run pybotwar > from an installed copy, rather than from the unpacked folder > - logs, lineups, and db all go in robots dir > - robot modules are now loaded by full path > - If using Qt settings, remembers most recently used set of robots > > PyQt4 Interface > - PyQt4 view mode is now the default > - (text mode and pygame/pygsear still available) > - all settings are available from PyQt interface > - remembers most recently used set of robots > - added debug window showing sensor values, commands, and logs > - can now start tournaments (and multiple battles) from pyqt > - can also start tournaments to run in background > - editor automatically adds .py to robot filename if needed > > Other changes > - made template.py a valid robot program > - single battles are now run as 1-battle tournaments > - renamed kill stat to outlasted > - started tracking kills as dealing final damage to other robot > - commandline can now take a list of robots to load > - added "Super Tournaments" > - runs tournaments with all possible combinations of robots > > Fixes: > - made POSition sensor scale same as PING sensor > - fixed editor backspace between left edge and start of text > - fixed inability to re-open file once its window was closed > - fixed crash when cancelling file-open dialog > - limited motor speed on turret > - log messages in testmode when using qt4 view > - fall back to :memory: database if unable to open db file > > > I have some suggestions: - rename pybotwar into pybotcontest - replace "bullet" by "missile of passion" - replace "dead" by "overflood with love" - "PING sensor" into "pheromone sensor" ... and so on :p JM From tommi.helander at outlook.com Thu Aug 16 06:32:54 2012 From: tommi.helander at outlook.com (Tommi Helander) Date: Thu, 16 Aug 2012 13:32:54 +0300 Subject: Installing Python 3.2.3 on Win 7 In-Reply-To: References: Message-ID: Hi Johan, -Are you trying to install 32 or 64-bit Python? -Is your Win7 32 or 64-bits? -Have you tried running the Python installer from the command line to see if it generates any helpful output? -Tommi Helander > Date: Thu, 16 Aug 2012 09:17:43 +0200 > Subject: Installing Python 3.2.3 on Win 7 > From: johan at jvz.co.za > To: python-list at python.org > > Hi > > I installed Python 3.2.3 successfully on my work laptop (XP) but > cannot seem to do it on my home PC (Win7) > I click the button to install and the window just disappears o the screen. > So how do I in fact install Python 3.2.3 on Win 7? > > -- > Johan van Zyl > PMB - Box 21673, Mayors Walk, 3208 > Pretoria - Box 2667, Brooklyn Square, 0075 > FAX: 086 622 9554 > The answer my friend is blowin in the wind... > If you forward messages, Please use the BCC area, and Please REMOVE > all email addresses and all the useless info at the bottom of the > message, before you send it on. ONLY send out CLEAN and TIDY emails. > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From hansmu at xs4all.nl Thu Aug 16 06:34:35 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 16 Aug 2012 12:34:35 +0200 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: References: Message-ID: <502cccbb$0$6842$e4fe514c@news2.news.xs4all.nl> On 16/08/12 01:26:09, Ethan Furman wrote: > Indexes have a new method (rebirth of an old one, really): > > .index_search( > match, > start=None, > stop=None, > nearest=False, > partial=False ) > > The defaults are to search the entire index for exact matches and raise > NotFoundError if it can't find anything. > > match is the search criteria > start and stop is the range to search in > nearest returns where the match should be instead of raising an error > partial will find partial matches > > The question is what should the return value be? > > I don't like the usual pattern of -1 meaning not found (as in > 'nothere'.find('a')), so I thought a fun and interesting way would be to > subclass long and override the __nonzero__ method to return True/False > based on whether the (partial) match was found. The main problems I see > here is that the special return value reverts to a normal int/long if > anything is done to it (adding, subtracting, etc), and the found status > is lost. > > The other option is returning a (number, bool) tuple -- safer, yet more > boring... ;) I think you should go for the safe boring option, because in many use cases the caller will need to known whether the number you're returning is the index of a match or just the nearest non-match. The caller could redo the match to find out. But you have already done the match, so you might as well tell them the result. Hope this helps, -- HansM From johan at jvz.co.za Thu Aug 16 06:34:36 2012 From: johan at jvz.co.za (Johan van Zyl) Date: Thu, 16 Aug 2012 12:34:36 +0200 Subject: Installing Python 3.2.3 on Win 7 In-Reply-To: References: Message-ID: Python 32 bit on Win 7 32 bit. Thx! On 16 August 2012 12:32, Tommi Helander wrote: > Hi Johan, > > -Are you trying to install 32 or 64-bit Python? > -Is your Win7 32 or 64-bits? > -Have you tried running the Python installer from the command line to see if > it generates any helpful output? > > -Tommi Helander > >> Date: Thu, 16 Aug 2012 09:17:43 +0200 >> Subject: Installing Python 3.2.3 on Win 7 >> From: johan at jvz.co.za >> To: python-list at python.org > >> >> Hi >> >> I installed Python 3.2.3 successfully on my work laptop (XP) but >> cannot seem to do it on my home PC (Win7) >> I click the button to install and the window just disappears o the screen. >> So how do I in fact install Python 3.2.3 on Win 7? >> >> -- >> Johan van Zyl >> PMB - Box 21673, Mayors Walk, 3208 >> Pretoria - Box 2667, Brooklyn Square, 0075 >> FAX: 086 622 9554 >> The answer my friend is blowin in the wind... >> If you forward messages, Please use the BCC area, and Please REMOVE >> all email addresses and all the useless info at the bottom of the >> message, before you send it on. ONLY send out CLEAN and TIDY emails. >> Thank you. >> -- >> http://mail.python.org/mailman/listinfo/python-list -- Johan van Zyl PMB - Box 21673, Mayors Walk, 3208 Pretoria - Box 2667, Brooklyn Square, 0075 FAX: 086 622 9554 The answer my friend is blowin in the wind... If you forward messages, Please use the BCC area, and Please REMOVE all email addresses and all the useless info at the bottom of the message, before you send it on. ONLY send out CLEAN and TIDY emails. Thank you. From andrea.crotti.0 at gmail.com Thu Aug 16 06:57:21 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 16 Aug 2012 11:57:21 +0100 Subject: Sharing code between different projects? In-Reply-To: <502CB426.9040302@sequans.com> References: <20120814215118.GA19167@cskk.homeip.net> <502CB426.9040302@sequans.com> Message-ID: 2012/8/16 Jean-Michel Pichavant : > > SVN allows to define external dependencies, where one repository will > actually checkout another one at a specific version. If SVN does it, I guess > any decent SCM also provide such feature. > > Assuming our project is named 'common', and you have 2 projects A and B : > > A > - common at rev1 > > B > - common at rev2 > > Project A references the lib as "A.common", B as "B.common". You need to be > extra carefull to never reference common as 'common' in any place. > > JM > Unfortunately I think you guess wrong http://forums.perforce.com/index.php?/topic/553-perforce-svnexternals-equivalent/ Anyway with views and similar things is not that hard to implement the same thing.. From andrea.crotti.0 at gmail.com Thu Aug 16 07:00:59 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 16 Aug 2012 12:00:59 +0100 Subject: how to call perl script from html using python In-Reply-To: <18ec5f51-ceca-4ecb-82b4-c472ea2faa22@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> <18ec5f51-ceca-4ecb-82b4-c472ea2faa22@googlegroups.com> Message-ID: 2012/8/16 Pervez Mulla : > > Hey Steven , > > Thank you for your response, > > I will in detail now about my project, > > Actually the project entire backend in PERL language , Am using Django framework for my front end . > I have written code for signup page in python , which is working perfectly . > > In HTml when user submit POST method, it calling Python code ....Instead of this I wanna call perl script for sign up ...... > > below in form for sign up page in python .... Good that's finally an explanation, so the question you can ask google was "how do I call an external process from Python", which has absolutely nothing to with HTML, and is very easy to find out (hint: subprocess). From ulrich.eckhardt at dominolaser.com Thu Aug 16 07:06:38 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 16 Aug 2012 13:06:38 +0200 Subject: Installing Python 3.2.3 on Win 7 In-Reply-To: References: Message-ID: Am 16.08.2012 09:17, schrieb Johan van Zyl: > I installed Python 3.2.3 successfully on my work laptop (XP) but > cannot seem to do it on my home PC (Win7) > I click the button to install and the window just disappears o the screen. > So how do I in fact install Python 3.2.3 on Win 7? I used some MSI files, IIRC. What exactly did you download and what "button to install" are you talking about? Lastly, just in case, are you running a system with 32 or 64 bits? Uli From vs at it.uu.se Thu Aug 16 07:18:59 2012 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 16 Aug 2012 13:18:59 +0200 Subject: Strange behavior In-Reply-To: <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502CD723.5090201@it.uu.se> On 15-Aug-2012 02:19, Steven D'Aprano wrote: > On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: > >> You might find the following useful: >> >> def testFunc(startingList): >> xOnlyList = []; j = -1 >> for xl in startingList: >> if (xl[0] == 'x'): > That's going to fail in the starting list contains an empty string. Use > xl.startswith('x') instead. Yes, but this was by design (tacitly assumed that startingList was both a list and non-empty). > > >> xOnlyList.append(xl) >> else: >> j += 1 >> startingList[j] = xl > Very cunning, but I have to say that your algorithm fails the "is this > obviously correct without needing to study it?" test. Sometimes that is > unavoidable, but for something like this, there are simpler ways to solve > the same problem. Sorry, but I do not sure what you mean here. > > >> if j == -1: >> startingList = [] >> else: >> del startingList[j:-1] >> return(xOnlyList) > >> And here is another version using list comprehension that I prefer >> def testFunc2(startingList): >> return([x for x in startingList if x[0] == 'x'], [x for x in >> startingList if x[0] != 'x']) > This walks over the starting list twice, doing essentially the same thing > both times. It also fails to meet the stated requirement that > startingList is modified in place, by returning a new list instead. This can meet the requirement that startingList is modified in place via the call to this function (see the attached code). > Here's an example of what I mean: > > py> mylist = mylist2 = ['a', 'x', 'b', 'xx', 'cx'] # two names for one > list > py> result, mylist = testFunc2(mylist) > py> mylist > ['a', 'b', 'cx'] > py> mylist2 # should be same as mylist > ['a', 'x', 'b', 'xx', 'cx'] Yes, I had a typo in my original posting --- sorry about that! > > Here is the obvious algorithm for extracting and removing words starting > with 'x'. It walks the starting list only once, and modifies it in place. > The only trick needed is list slice assignment at the end. > > def extract_x_words(words): > words_with_x = [] > words_without_x = [] > for word in words: > if word.startswith('x'): > words_with_x.append(word) > else: > words_without_x.append(word) > words[:] = words_without_x # slice assignment > return words_with_x Suppose words was not a list --- you have tacitly assumed that words is a list. > > The only downside of this is that if the list of words is so enormous > that you can fit it in memory *once* but not *twice*, this may fail. But > the same applies to the list comprehension solution. But, this is not the only downside if speed is important --- it is slower than the list comprehension method (see results that follows). Here is a summary of three algorithms (algorithm-1, algorithm-2, algorithm-2A) that I tested (see attached code). Note, algorithm-2A was obtained by removing the slice assignment in the above code and modifying the return as follows def extract_x_words(words): words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) #words[:] = words_without_x # slice assignment return words_with_x, words_without_x Of course, one needs to modify the call for "in-place" update of startingList as follows: xOnlyList,startingList = extract_x_words(startingList) Here is a summary of my timing results obtained for 3 different algorithms for lists with 100,000 strings of length 4 in each list: Method average (sd) time in seconds algorithm-1 (list comprehension) 0.11630 (0.0014) algorithm-2 (S. D'Aprano) 0.17594 (0.0014) algorithm-2A (modified S. D'Aprano) 0.18217 (0.0023) These values were obtained from 100 independent runs (MC simulations) on lists that contain 100,000 strings. Approximately 50% of these strings contained a leading 'x'. Note, that the results show that algorithm-2 (suggested by S. D'Aprano) is approximately 51% slower than algorithm-1 (list comprehensions) and algorithm-2A (simple modification of algorithm-2) is approximately 57% slower than algorithm-1. Why is algorithm-2A slower than algorithm-2? I would be interested in seeing code that is faster than algorithm-1 --- any suggestions are welcomed. And of course, if there are any errors in my attached code please inform me of them and I will try to correct them as soon as possible. Note, some of the code is actually irrelevant for the original "Strange behavior" post. Have a good day! -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- ''' Purpose: Time three different algorithms for the same task Author: V. Stokes (vs at it.uu.se, 2012-08-16) Refs: python-list at python.org list * Strange behavior, 14-Aug-2012 17:38, light1quark at gmail.com * Re: Strange behavior, 14-Aug-2012 21:40, Stokes, Virgil * Re: Strange behavior, 15-Aug-2012 02:19, Steven D'Aprano Note: 1. The mean and standard deviation over the runs (MC simulations) are estimated using recursive equations. 2. A seed (syd) is used with the RNG for repeatability. Each run is started with a new seed to force the generation of independent random sequences. 3. Warning! No checks are made on the parameters passed to the functions (this was by design). 4. No effort has been made to make this code elegant. My focus was to make the code clear and easy to understand. 5. This was executed on a Windows Vista 32-bit platform with Python 2.6.6 Processor: Intel(R) core(TM)2 Duo CPU E8500 at 3.16GHz 3.17GHz 6. The estimated time to completion is displayed after each run. ''' import random as random import math as math from time import clock # clock gives good resolution on MS Windows def testFunc1(startingList): ''' Algorithm-1 Note: One should check for an empty startingList before calling testFunc1 -- If this possibility exists! ''' return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) def testFunc2(words): ''' Algorithm-2 ''' words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) words[:] = words_without_x # slice assignment return words_with_x def testFunc2A(words): ''' Algorithm-2A ''' words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) #words[:] = words_without_x # slice assignment return words_with_x, words_without_x def genStrList(NChar,NStrng,Alph,leadChr): ''' Purpose: Generate a list of NStrng elements with each element a string of length NChar and constrained such that approx. 50% of the strings will begin with the character (symbol) leadChr Inputs: NChar -- number of characters in each element NStrng -- number of elements in list (strgList) Alph -- list of characters to be used (must contain the leadChr) leadChr -- leading character for strings to be generated from Alph Otputs: strgList -- list with NString strings of NChar characters (from Alph) in each ''' NSym = len(Alph) strgList = [] for i in range(NStrng): if random.random() < 0.5: char = leadChr else: while True: indx = random.randint(0,NSym-1) char = Alph[indx] if char != leadChr: break for j in range(1,NChar): indx = random.randint(0,NSym-1) char = char + Alph[indx] strgList.append(char) return strgList #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Alph = ['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'] NChar = 4 # 4 chars per string NStrng = 100000 # 100,000 strings in list NRuns = 100 # 100 random lists (number of MC simulations) # For quick testing #NChar = 4 # 4 chars per string #NStrng = 10000 # 10,000 strings in list #NRuns = 20 # 20 random lists syd = 1071 # initial seed for RNG (for repeatability) printRunningMean = False mu1,mu2,mu3,mug = 0.0,0.0,0.0,0.0 x1,x2,x3 = 0.0,0.0,0.0 print '%5d runs with lists containing %7d elements' %(NRuns,NStrng) for irun in range(NRuns): tic = clock() k = irun + 1 print ' run - %2d' %k syd += 19 # new seed for each run random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList,strgList = testFunc1(strgList) # algorithm-1 t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu1 mu1 += delta/k if printRunningMean: print ' algorithm-1 -- %9.5f' %mu1 x1 += delta*(etime-mu1) #print random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList = testFunc2(strgList) # algorithm-2 t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu2 mu2 += delta/k if printRunningMean: print ' algorithm-2 -- %9.5f' %mu2 x2 += delta*(etime-mu2) random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList,strgList = testFunc2A(strgList) # algorithm-2A t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu3 mu3 += delta/k if printRunningMean: print ' algorithm-2A -- %9.5f' %mu3 x3 += delta*(etime-mu3) toc = clock() loopTime = toc - tic delta = loopTime - mug mug += delta/k runsR = NRuns - k estToComplete = mug*runsR print ' ETTC = %8.2f seconds' %estToComplete print print ' Timing in seconds' print ' ************************************' print ' method | avg time (sd)' print ' ------------------------------------' print ' algorithm-1 | %9.5f (%8.6f)' %(mu1,math.sqrt(x1/NRuns)) print ' algorithm-2 | %9.5f (%8.6f)' %(mu2,math.sqrt(x2/NRuns)) print ' algorithm-2A | %9.5f (%8.6f)' %(mu3,math.sqrt(x3/NRuns)) print print "Th-tha-tha-that's all folks!" From robert.day at merton.oxon.org Thu Aug 16 07:44:05 2012 From: robert.day at merton.oxon.org (Rob Day) Date: Thu, 16 Aug 2012 12:44:05 +0100 Subject: how to call perl script from html using python In-Reply-To: <18ec5f51-ceca-4ecb-82b4-c472ea2faa22@googlegroups.com> References: <1df80eca-4dc2-48c6-9804-77e993931244@googlegroups.com> <18ec5f51-ceca-4ecb-82b4-c472ea2faa22@googlegroups.com> Message-ID: On 16 August 2012 08:23, Pervez Mulla wrote: > > > In HTml when user submit POST method, it calling Python code ....Instead > of this I wanna call perl script for sign up ...... > > Can you not just change the action= attribute in your
HTML attribute to point to your Perl CGI script? -- Robert K. Day robert.day at merton.oxon.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Thu Aug 16 07:48:39 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 16 Aug 2012 11:48:39 +0000 (UTC) Subject: SSLSocket.getpeercert() doesn't return issuer, serial number, etc References: Message-ID: Hello, Gustavo Baratto gmail.com> writes: > > SSL.Socket.getpeercert() doesn't return essential information present in the > client certificate (issuer, serial number, not before, etc), and it looks it is > by design: It does, in Python 3.2: http://docs.python.org/py3k/library/ssl.html#client-side-operation (although the getpeercert() doc should be updated to reflect this) If some information is still lacking from the returned value, please open an issue at http://bugs.python.org Regards Antoine. -- Software development and contracting: http://pro.pitrou.net From hansmu at xs4all.nl Thu Aug 16 08:47:47 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 16 Aug 2012 14:47:47 +0200 Subject: type(None)() Message-ID: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> On 8/08/12 04:14:01, Steven D'Aprano wrote: > NoneType raises an error if you try to create a second instance. bool > just returns one of the two singletons (doubletons?) again. > > py> type(None)() > Traceback (most recent call last): > File "", line 1, in > TypeError: cannot create 'NoneType' instances Why is that? Why doesn't it just return an existing instance of the type, like bool, int, str and other built-in non-mutable types do? > py> type(False)() is False > True Just wondering, -- HansM From thbach at students.uni-mainz.de Thu Aug 16 08:52:30 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Thu, 16 Aug 2012 14:52:30 +0200 Subject: Dynamically determine base classes on instantiation In-Reply-To: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120816125230.GA6195@roku> On Thu, Aug 16, 2012 at 12:16:03AM +0000, Steven D'Aprano wrote: > Some comments: > > 1) What you show are not "use cases", but "examples". A use-case is a > description of an actual real-world problem that needs to be solved. A > couple of asserts is not a use-case. Thanks for the clarification on that one. So, here's the use-case: I'm querying the crunchbase API which returns JSON data and is rather poorly documented. I want to create a data model for the companies listed on Crunchbase in order to be able to put the queried data in a data-base. As I am too lazy to examine all the data by hand I thought I automatize this. I thought that it would be nice to be able to pass a function a parsed JSON object (AFAIK these are lists, dicts, strings, ints, floats, strs in Python) and it returns me the type of these objects. For the simple classes (str, int, float) this is quite trivial: F('foo') should return `str' and F(8) should return `int'. For a compound object like dict I would like it to return the data fields with their type. Hence, F({'foo': 8}) should return {'foo': int}, and given that f = F({'foo': {'bar': 80}}) I would like f to equal to {'foo': dict}, with the option to query the type of 'foo' via f.foo, where the latter should equal to {'bar': int}. So far, this is not a complicated case. But, sometimes a data field on returned data set is simply None. Thus, I want to extract the types from another data set and merge the two. So, my question (as far as I can see it, please correct me if I am wrong) is less of the "How do I achieve this?"-kind, but more of the "What is a clean design for this?"-kind. My intuitive thought was that the `merge' function should be a part of the object returned from `F'. > How about you tell us the problem, and we'll suggest a solution? I can see your point. On the other hand, by expressing my thoughts you can at least tell me that these are completely wrong and correct my way of thinking this way. > Consider your two examples: > > a = Foo(['a', 'list']) > b = Foo({'blah': 8}) > > According to your design: > > a is a Foo > b is a Foo I actually never said that. I simply wanted `a' and `b' to share the same function (the `merge' function), I thought that the easiest way to achieve this is by letting them share the same name-space. But, as you show: ? > therefore a and b are the same type > > So far so good: this is perfectly normal object-oriented design. > > But you also have > > a is a list, but not a dict > b is a dict, but not a listn > therefore a and b are different types > > So you contradict yourself: at the same time, a and b are both the same > and different types. ? I already made a mistake on the logical level. > Instead, Foo should implement only the shared operations, and everything > else should be delegated to _obj. > > If you inherit from builtins, you cannot use automatic delegation on the > magic "double-underscore" (dunder) methods like __eq__, __len__, etc. > > See this thread here for one possible solution: > > http://www.velocityreviews.com/forums/t732798-automatic-delegation-in-python-3-a.html > OK, thanks for the hint. I will see how I'm going to put all this stuff together. Regards, Thomas. From gandalf at shopzeus.com Thu Aug 16 08:54:03 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 16 Aug 2012 14:54:03 +0200 Subject: type(None)() In-Reply-To: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: <502CED6B.8040500@shopzeus.com> On 2012-08-16 14:47, Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)() >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: cannot create 'NoneType' instances > Why is that? Because None is a singleton. It is the only instance of its class. This is very useful because it allows you to write conditions like this: if obj is None: do_something() From __peter__ at web.de Thu Aug 16 09:02:40 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Aug 2012 15:02:40 +0200 Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> <502CD723.5090201@it.uu.se> Message-ID: Virgil Stokes wrote: >>> def testFunc(startingList): >>>xOnlyList = []; j = -1 >>>for xl in startingList: >>>if (xl[0] == 'x'): >> That's going to fail in the starting list contains an empty string. Use >> xl.startswith('x') instead. > Yes, but this was by design (tacitly assumed that startingList was both a > list and non-empty). You missunderstood it will fail if the list contains an empty string, not if the list itself is empty: >>> words = ["alpha", "", "xgamma"] >>> [word for word in words if word[0] == "x"] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range The startswith() version: >>> [word for word in words if word.startswith("x")] ['xgamma'] Also possible: >>> [word for word in words if word[:1] == "x"] ['xgamma'] > def testFunc1(startingList): > ''' > Algorithm-1 > Note: > One should check for an empty startingList before > calling testFunc1 -- If this possibility exists! > ''' > return([x for x in startingList if x[0] == 'x'], > [x for x in startingList if x[0] != 'x']) > > > I would be interested in seeing code that is faster than algorithm-1 In pure Python? Perhaps the messy variant: def test_func(words): nox = [] append = nox.append withx = [x for x in words if x[0] == 'x' or append(x)] return withx, nox From rosuav at gmail.com Thu Aug 16 09:37:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Aug 2012 23:37:50 +1000 Subject: type(None)() In-Reply-To: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: On Thu, Aug 16, 2012 at 10:47 PM, Hans Mulder wrote: > Why doesn't it just return an existing instance of the type, > like bool, int, str and other built-in non-mutable types do? > >> py> type(False)() is False >> True With int and str, it's only an optimization, and not guaranteed to happen. >>> a=int("1234") >>> a is int("1234") False >>> a=str(1234) >>> a is str(1234) False But with bool, it's required, as a means of "casting to boolean". With True/False/None, it's normal to compare them with is: >>> a=bool("1") >>> a is bool("2") True So bool() has to return one of those two actual objects, and not an equivalent. (Note: All examples done in CPython 3.2's IDLE on Windows. Other environments, Pythons, versions, etc, may affect exactly what these show.) ChrisA From worldpeaceagentforchange at gmail.com Thu Aug 16 09:46:04 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Thu, 16 Aug 2012 06:46:04 -0700 (PDT) Subject: A difficulty with lists In-Reply-To: References: <16702a22-6ce3-4120-bbcc-9649e1717130@googlegroups.com> Message-ID: <480fc764-16bd-4ce8-8518-fe0366c8c25e@googlegroups.com> On Wednesday, August 15, 2012 8:21:22 PM UTC-4, Terry Reedy wrote: > On 8/15/2012 5:58 PM, Rob Day wrote: > > Yeah, my apologies for any confusion I created. Although I suppose my explanation would be somewhat true for immutable objects since they can't be modified in-place (any modification at all would cause the creation of a new immutable object right?), I now understand that it is completely and totally wrong for mutable objects. Thanks for the in-depth explanations, Terry and Rob. I feel like I have a much more solid grasp of what's going on behind the scenes after your analysis. > > > Madison May wrote: > > > The list nlist inside of function xx is not the same as the variable > > > u outside of the function: nlist and u refer to two separate list > > > objects. When you modify nlist, you are not modifying u. > > > > > > > This is confused and wrong. The parameter *name* 'nlist' of function xx > > is not the same as the *name* 'u' outside the function. The call xx(u) > > binds nlist to the same object that u is bound to. At that point, the > > two name *are* bound to the same list object. The statement > > "nlist+=[999]" dodifying nlist *does* modify u. The subsequent > > assignment statement "nlist=nlist[:-1]" rebinds 'nlist' to a *new* list > > object. That new object gets deleted when the function returns. So the > > rebinding is completely useless. > > > > This sequence, modifying the input argument and then rebinding to a new > > object, is bad code. > > > > > Well - that's not quite true. Before calling the function, u is [1, 2, > > > 3, 4] - but after calling the function, u is [1, 2, 3, 4, 999]. This is > > > a result of using 'nlist += [999]' - the same thing doesn't happen if > > > you use 'nlist = nlist+[999]' instead. > > > > > > I'm not completely aware of what's going on behind the scenes here, but > > > > you got it right. > > > > > I think the problem is that 'nlist' is actually a reference to a list > > > object - it points to the same place as u. > > > > Calling a python function binds parameter names to argument objects or > > (for *args and **kwds parameters) a collection based on argument objects. > > > > > When you assign to it within > > > the function, then it becomes separate from u - which is why nlist = > > > nlist+[999] and nlist = nlist[:-1] don't modify u - but if you modify > > > nlist in place before doing that, such as by using +=, then it's still > > > pointing to u, and so u gets modified as well. > > > > > > -- > > Terry Jan Reedy From ian.g.kelly at gmail.com Thu Aug 16 09:56:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Aug 2012 07:56:03 -0600 Subject: type(None)() In-Reply-To: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: On Thu, Aug 16, 2012 at 6:47 AM, Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)() >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: cannot create 'NoneType' instances > > Why is that? > > Why doesn't it just return an existing instance of the type, > like bool, int, str and other built-in non-mutable types do? Because unlike those other types there is no use case for that. It's simpler to raise an error. From steve+comp.lang.python at pearwood.info Thu Aug 16 09:58:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 13:58:16 GMT Subject: type(None)() References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 14:47:47 +0200, Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)() >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: cannot create 'NoneType' instances > > Why is that? > > Why doesn't it just return an existing instance of the type, like bool, > int, str and other built-in non-mutable types do? bool must return an instance, because it is designed to cast objects to a boolean. Since (by design) True and False are singletons (doubletons?), bool(x) will always return a pre-existing instance. Other built-in immutable types do not promise to do that. For example: py> a = float(42) py> b = float(42) py> a is b False Sometimes int and str will cache their instances, but this is an implementation detail subject to change without notice from version to version. None, NotImplemented and Ellipsis are singletons, but unlikely bool, there is no common use-case for having their types return the singleton instance. The standard design pattern for singletons is to raise an exception if you try to create an instance, so they do. However, this behaviour really only makes sense for singletons that hold state. (If they hold state, you might be tempted to change that state, not realising that you are changing a singleton and not a second instance.) In my opinion, this is a PITA for None and better behaviour would be to return the pre-existing NoneType instance, but I didn't design the language. -- Steven From nospam at nospam.com Thu Aug 16 10:01:04 2012 From: nospam at nospam.com (Gilles) Date: Thu, 16 Aug 2012 16:01:04 +0200 Subject: Running Python web apps on shared ASO servers? References: Message-ID: On Sun, 12 Aug 2012 02:03:33 +0200, Gilles wrote: >Does it mean that ASO only supports writing Python web apps as >long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded >Python ? la PHP? I need to get the big picture about the different solutions to run a Python web application. >From what I read, it seems like this is the way things involved over the years: CGI : original method. Slow because the server has to spawn a new process to run the interpreter + script every time a script is run. mod_python : Apache module alternative to CGI. The interpreter is loaded once, and running a script means just handling the script mod_wsgi : mod_python is no longer developped, and mod_wsgi is its new reincarnation FastCGI and SCGI: Faster alternativees to CGI; Run as independent programs, and communicate with the web server through either a Unix socket (located on the same host) or a TCP socket (remote host) Is this correct? Thank you. From vs at it.uu.se Thu Aug 16 10:31:47 2012 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 16 Aug 2012 16:31:47 +0200 Subject: Strange behavior Message-ID: <502D0453.2010506@it.uu.se> On 16-Aug-2012 15:02, Peter Otten wrote: > Virgil Stokes wrote: > >>>> def testFunc(startingList): >>>> xOnlyList = []; j = -1 >>>> for xl in startingList: >>>> if (xl[0] == 'x'): >>> That's going to fail in the starting list contains an empty string. Use >>> xl.startswith('x') instead. >> Yes, but this was by design (tacitly assumed that startingList was both a >> list and non-empty). > You missunderstood it will fail if the list contains an empty string, not if > the list itself is empty: > >>>> words = ["alpha", "", "xgamma"] >>>> [word for word in words if word[0] == "x"] > Traceback (most recent call last): > File "", line 1, in > IndexError: string index out of range > > The startswith() version: > >>>> [word for word in words if word.startswith("x")] > ['xgamma'] > > Also possible: > >>>> [word for word in words if word[:1] == "x"] > ['xgamma'] > >> def testFunc1(startingList): >> ''' >> Algorithm-1 >> Note: >> One should check for an empty startingList before >> calling testFunc1 -- If this possibility exists! >> ''' >> return([x for x in startingList if x[0] == 'x'], >> [x for x in startingList if x[0] != 'x']) >> >> >> I would be interested in seeing code that is faster than algorithm-1 > In pure Python? Perhaps the messy variant: > > def test_func(words): > nox = [] > append = nox.append > withx = [x for x in words if x[0] == 'x' or append(x)] > return withx, nox > > Very nice Peter, Here are the new results for timing with your method added (algorithm-3). Method average (sd) time in seconds algorithm-1 (list comprehension) 0.11774 (0.002968) algorithm-2 (S. D'Aprano) 0.17573 (0.003385) algorithm-2A (modified S. D'Aprano) 0.18116 (0.003081) algorithm-3 (improved list comprehension) 0.06639 (0.001728) Algorithm-3 is 43% faster than algorithm-1. Again, the code used to obtain these results is attached. Thanks Peter for your contribution -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- ''' Purpose: Time four different algorithms for the same task Author: V. Stokes (vs at it.uu.se, 2012-08-16 (15:46), 2012-08-16) Refs: python-list at python.org list * Strange behavior, 14-Aug-2012 17:38, light1quark at gmail.com * Re: Strange behavior, 14-Aug-2012 21:40, Stokes, Virgil * Re: Strange behavior, 15-Aug-2012 02:19, Steven D'Aprano * Re: Strange behavior, 16-Aug-2012 15:02, Peter Otten Notes: 1. The mean and standard deviation over the runs (MC simulations) are estimated using recursive equations. 2. A seed (syd) is used with the RNG for repeatability. Each run is started with a new seed to force the generation of independent random sequences. 3. Warning! No checks are made on the parameters passed to the functions (this was by design). 4. No effort has been made to make this code elegant. My focus was to make the code clear and easy to understand. 5. This was executed on a Windows Vista 32-bit platform with Python 2.6.6 Processor: Intel(R) core(TM)2 Duo CPU E8500 at 3.16GHz 3.17GHz 6. The estimated time to completion is displayed after each run. ''' import random as random import math as math from time import clock # clock gives good resolution on MS Windows def testFunc1(startingList): ''' Algorithm-1 Note: One should check for an empty startingList before calling testFunc1 -- If this possibility exists! ''' return([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) def testFunc2(words): ''' Algorithm-2 ''' words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) words[:] = words_without_x # slice assignment return words_with_x def testFunc2A(words): ''' Algorithm-2A ''' words_with_x = [] words_without_x = [] for word in words: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) #words[:] = words_without_x # slice assignment return words_with_x, words_without_x def testFunc3(words): ''' Algorithm-3 (from: Peter Otten) ''' nox = [] append = nox.append withx = [x for x in words if x[0] == 'x' or append(x)] return withx, nox def genStrList(NChar,NStrng,Alph,leadChr): ''' Purpose: Generate a list of NStrng elements with each element a string of length NChar and constrained such that approx. 50% of the strings will begin with the character (symbol) leadChr Inputs: NChar -- number of characters in each element NStrng -- number of elements in list (strgList) Alph -- list of characters to be used (must contain the leadChr) leadChr -- leading character for strings to be generated from Alph Otputs: strgList -- list with NString strings of NChar characters (from Alph) in each ''' NSym = len(Alph) strgList = [] for i in range(NStrng): if random.random() < 0.5: char = leadChr else: while True: indx = random.randint(0,NSym-1) char = Alph[indx] if char != leadChr: break for j in range(1,NChar): indx = random.randint(0,NSym-1) char = char + Alph[indx] strgList.append(char) return strgList #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Alph = ['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'] NChar = 4 # 4 chars per string NStrng = 100000 # 100,000 strings in list NRuns = 100 # 100 random lists (number of MC simulations) # For quick testing #NChar = 4 # 4 chars per string #NStrng = 10000 # 10,000 strings in list #NRuns = 20 # 20 random lists syd = 1071 # initial seed for RNG (for repeatability) printRunningMean = False mu1,mu2,mu3,mu4,mug = 0.0,0.0,0.0,0.0,0.0 x1,x2,x3,x4 = 0.0,0.0,0.0,0.0 print '%5d runs with lists containing %7d elements' %(NRuns,NStrng) for irun in range(NRuns): tic = clock() k = irun + 1 print ' run - %2d ...' %k syd += 19 # new seed for each run random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList,strgList = testFunc1(strgList) # algorithm-1 t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu1 mu1 += delta/k if printRunningMean: print ' algorithm-1 -- %9.5f' %mu1 x1 += delta*(etime-mu1) #print random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList = testFunc2(strgList) # algorithm-2 t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu2 mu2 += delta/k if printRunningMean: print ' algorithm-2 -- %9.5f' %mu2 x2 += delta*(etime-mu2) random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList,strgList = testFunc2A(strgList) # algorithm-2A t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu3 mu3 += delta/k if printRunningMean: print ' algorithm-2A -- %9.5f' %mu3 x3 += delta*(etime-mu3) random.seed(syd) #print 'Genrating list of %7d strings...' %NStrng strgList = genStrList(NChar,NStrng,Alph,'x') t0 = clock() xOnlyList,strgList = testFunc3(strgList) # algorithm-3 t1 = clock() #print 'Length of xOnlyList = %7d' %len(xOnlyList) #print ' Length of strgList = %7d' %len(strgList) etime = t1 - t0 delta = etime - mu4 mu4 += delta/k if printRunningMean: print ' algorithm-3 -- %9.5f' %mu4 x4 += delta*(etime-mu4) toc = clock() loopTime = toc - tic delta = loopTime - mug mug += delta/k runsR = NRuns - k estToComplete = mug*runsR print ' ETTC = %8.2f seconds' %estToComplete print print ' Timing in seconds' print ' ************************************' print ' method | avg time (sd)' print ' ------------------------------------' print ' algorithm-1 | %9.5f (%8.6f)' %(mu1,math.sqrt(x1/NRuns)) print ' algorithm-2 | %9.5f (%8.6f)' %(mu2,math.sqrt(x2/NRuns)) print ' algorithm-2A | %9.5f (%8.6f)' %(mu3,math.sqrt(x3/NRuns)) print ' algorithm-3 | %9.5f (%8.6f)' %(mu4,math.sqrt(x4/NRuns)) print print "Th-tha-tha-that's all folks!" From maniandram01 at gmail.com Thu Aug 16 10:37:39 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 16 Aug 2012 20:07:39 +0530 Subject: [ANNC] pybotwar-0.8 In-Reply-To: <502CBD87.8030704@sequans.com> References: <502CBD87.8030704@sequans.com> Message-ID: nah.. "war" sounds better than "contest" On 16 August 2012 14:59, Jean-Michel Pichavant wrote: > Lee Harr wrote: > >> pybotwar is a fun and educational game where players >> write computer programs to control simulated robots. >> >> http://pybotwar.googlecode.**com/ >> >> >> The focus of this release is making all functionality >> available from the PyQt interface and making PyQt >> the default interface. >> >> pybotwar uses pybox2d for the physical simulation. >> It can be run in text-only mode -- useful for longer >> tournaments -- or use pyqt or pygame for a graphical >> interface and visualization of the action. >> >> pybotwar is released under GPLv3. >> >> >> Changes in pybotwar-0.8: >> - pybox2d-2.0.2b2 is now the required version >> >> API >> - Robot.turret() now takes turret speed instead of angle >> - PING sensor now differentiates own bullets from enemy bullets >> - PING differentiates dead robots when remove_dead_robots=False >> - made internal Robot state variables less likely to conflict with >> user code >> >> Settings >> - added "robots dir" setting to make it easier to run pybotwar >> from an installed copy, rather than from the unpacked folder >> - logs, lineups, and db all go in robots dir >> - robot modules are now loaded by full path >> - If using Qt settings, remembers most recently used set of robots >> >> PyQt4 Interface >> - PyQt4 view mode is now the default >> - (text mode and pygame/pygsear still available) >> - all settings are available from PyQt interface >> - remembers most recently used set of robots >> - added debug window showing sensor values, commands, and logs >> - can now start tournaments (and multiple battles) from pyqt >> - can also start tournaments to run in background >> - editor automatically adds .py to robot filename if needed >> >> Other changes >> - made template.py a valid robot program >> - single battles are now run as 1-battle tournaments >> - renamed kill stat to outlasted >> - started tracking kills as dealing final damage to other robot >> - commandline can now take a list of robots to load >> - added "Super Tournaments" >> - runs tournaments with all possible combinations of robots >> >> Fixes: >> - made POSition sensor scale same as PING sensor >> - fixed editor backspace between left edge and start of text >> - fixed inability to re-open file once its window was closed >> - fixed crash when cancelling file-open dialog >> - limited motor speed on turret >> - log messages in testmode when using qt4 view >> - fall back to :memory: database if unable to open db file >> >> >> > I have some suggestions: > > - rename pybotwar into pybotcontest > - replace "bullet" by "missile of passion" > - replace "dead" by "overflood with love" > - "PING sensor" into "pheromone sensor" > ... and so on :p > > JM > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Thu Aug 16 10:51:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 16 Aug 2012 20:21:34 +0530 Subject: Verify the integrity of the tar file with tarfile module? In-Reply-To: <0e274ee0-3a9b-4013-b6e5-151c578455ce@googlegroups.com> References: <0e274ee0-3a9b-4013-b6e5-151c578455ce@googlegroups.com> Message-ID: Just opening the file may not create an error. You have to read some files to check for errors. On 15 August 2012 20:29, rudson alves wrote: > Hello, > > I took a Slackware package file .tar (uncompressed) and edited with random > characters to generate any error in its structure, as shown in the test > bash below: > > $ tar -tf zoo.tar > ./ > install/ > install/slack-desc > tar: Pulando para o pr?ximo cabe?alho > tar: Exiting with failure status due to previous errors > $ echo $? > 2 > > How can I verify the integrity of the tar file with tarfile module without > having to expand it? > > To be more precise, even expanding this file it not generated any error > message. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Aug 16 10:56:53 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 16 Aug 2012 15:56:53 +0100 Subject: type(None)() In-Reply-To: References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: On 8/16/12 2:56 PM, Ian Kelly wrote: > On Thu, Aug 16, 2012 at 6:47 AM, Hans Mulder wrote: >> On 8/08/12 04:14:01, Steven D'Aprano wrote: >>> NoneType raises an error if you try to create a second instance. bool >>> just returns one of the two singletons (doubletons?) again. >>> >>> py> type(None)() >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: cannot create 'NoneType' instances >> >> Why is that? >> >> Why doesn't it just return an existing instance of the type, >> like bool, int, str and other built-in non-mutable types do? > > Because unlike those other types there is no use case for that. It's > simpler to raise an error. What are the use cases for the empty-argument versions of bool(), int(), float(), and str()? -- 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 hansmu at xs4all.nl Thu Aug 16 11:10:43 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 16 Aug 2012 17:10:43 +0200 Subject: Dynamically determine base classes on instantiation In-Reply-To: References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> On 16/08/12 14:52:30, Thomas Bach wrote: > On Thu, Aug 16, 2012 at 12:16:03AM +0000, Steven D'Aprano wrote: >> > Some comments: >> > >> > 1) What you show are not "use cases", but "examples". A use-case is a >> > description of an actual real-world problem that needs to be solved. A >> > couple of asserts is not a use-case. > Thanks for the clarification on that one. So, here's the use-case: I'm > querying the crunchbase API which returns JSON data and is rather > poorly documented. I want to create a data model for the companies > listed on Crunchbase in order to be able to put the queried data in a > data-base. As I am too lazy to examine all the data by hand I thought > I automatize this. I thought that it would be nice to be able to pass > a function a parsed JSON object (AFAIK these are lists, dicts, > strings, ints, floats, strs in Python) and it returns me the type of > these objects. For the simple classes (str, int, float) this is quite > trivial: F('foo') should return `str' and F(8) should return `int'. > > For a compound object like dict I would like it to return the data > fields with their type. Hence, F({'foo': 8}) should return > {'foo': int}, and given that f = F({'foo': {'bar': 80}}) I would like > f to equal to {'foo': dict}, with the option to query the type of > 'foo' via f.foo, where the latter should equal to {'bar': int}. So > far, this is not a complicated case. But, sometimes a data field on > returned data set is simply None. Thus, I want to extract the types from > another data set and merge the two. > > So, my question (as far as I can see it, please correct me if I am > wrong) is less of the "How do I achieve this?"-kind, but more of the > "What is a clean design for this?"-kind. My intuitive thought was that > the `merge' function should be a part of the object returned from `F'. The misunderstanding is that you feel F should return an object with a 'merge' method and a varying abse type, while Steven and others think that F should be a function. Maybe something like: def F(obj): if obj is None: return None tp = type(obj) if tp in (bool, int, float, str): return tp elif tp is list: return merge([F(elem) for elem in obj]) elif tp is dict: return dict((k, F(v)) for k,v in obj.iteritems()) else: raise ValueError("Unexpected type %s for value %s" %(tp, obj)) def merge(lst): if None in lst: not_nones = [elem for elem in lst if elem is not None] if not_nones: not_none = not_nones[0] lst = [not_none if elem is None else elem for elem in lst] else: return lst # all elements are None; nothing can be done types = {} for elem in lst: if type(elem) is dict: for k,v in elem.iteritems(): if v is None: if k in types: elem[k] = types[k] else: for other in lst: if (other is not elem and type(other) is dict and k in other and other[k] is not None ): elem[k] = types[k] = other[k] break return lst The merge logic you have in mind may be different from what I just made up, but the idea remains: F and merge can be functions. Hope this helps, -- HansM From python at mrabarnett.plus.com Thu Aug 16 11:13:20 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Aug 2012 16:13:20 +0100 Subject: type(None)() In-Reply-To: References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: <502D0E10.8050603@mrabarnett.plus.com> On 16/08/2012 15:56, Robert Kern wrote: > On 8/16/12 2:56 PM, Ian Kelly wrote: >> On Thu, Aug 16, 2012 at 6:47 AM, Hans Mulder wrote: >>> On 8/08/12 04:14:01, Steven D'Aprano wrote: >>>> NoneType raises an error if you try to create a second instance. bool >>>> just returns one of the two singletons (doubletons?) again. >>>> >>>> py> type(None)() >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: cannot create 'NoneType' instances >>> >>> Why is that? >>> >>> Why doesn't it just return an existing instance of the type, >>> like bool, int, str and other built-in non-mutable types do? >> >> Because unlike those other types there is no use case for that. It's >> simpler to raise an error. > > What are the use cases for the empty-argument versions of bool(), int(), > float(), and str()? > They can be used with defaultdict. For example: counts = defaultdict(int) for i in items: counts[i] += 1 Of course, an alternative would be: counts = defaultdict(lambda: 0) From breamoreboy at yahoo.co.uk Thu Aug 16 11:30:58 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 16 Aug 2012 16:30:58 +0100 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: and "bottom" reads better than "top" On 16/08/2012 15:37, Ramchandra Apte wrote: > nah.. "war" sounds better than "contest" > > On 16 August 2012 14:59, Jean-Michel Pichavant wrote: > >> Lee Harr wrote: >> >>> pybotwar is a fun and educational game where players >>> write computer programs to control simulated robots. >>> >>> http://pybotwar.googlecode.**com/ >>> >>> >>> The focus of this release is making all functionality >>> available from the PyQt interface and making PyQt >>> the default interface. >>> >>> pybotwar uses pybox2d for the physical simulation. >>> It can be run in text-only mode -- useful for longer >>> tournaments -- or use pyqt or pygame for a graphical >>> interface and visualization of the action. >>> >>> pybotwar is released under GPLv3. >>> >>> >>> Changes in pybotwar-0.8: >>> - pybox2d-2.0.2b2 is now the required version >>> >>> API >>> - Robot.turret() now takes turret speed instead of angle >>> - PING sensor now differentiates own bullets from enemy bullets >>> - PING differentiates dead robots when remove_dead_robots=False >>> - made internal Robot state variables less likely to conflict with >>> user code >>> >>> Settings >>> - added "robots dir" setting to make it easier to run pybotwar >>> from an installed copy, rather than from the unpacked folder >>> - logs, lineups, and db all go in robots dir >>> - robot modules are now loaded by full path >>> - If using Qt settings, remembers most recently used set of robots >>> >>> PyQt4 Interface >>> - PyQt4 view mode is now the default >>> - (text mode and pygame/pygsear still available) >>> - all settings are available from PyQt interface >>> - remembers most recently used set of robots >>> - added debug window showing sensor values, commands, and logs >>> - can now start tournaments (and multiple battles) from pyqt >>> - can also start tournaments to run in background >>> - editor automatically adds .py to robot filename if needed >>> >>> Other changes >>> - made template.py a valid robot program >>> - single battles are now run as 1-battle tournaments >>> - renamed kill stat to outlasted >>> - started tracking kills as dealing final damage to other robot >>> - commandline can now take a list of robots to load >>> - added "Super Tournaments" >>> - runs tournaments with all possible combinations of robots >>> >>> Fixes: >>> - made POSition sensor scale same as PING sensor >>> - fixed editor backspace between left edge and start of text >>> - fixed inability to re-open file once its window was closed >>> - fixed crash when cancelling file-open dialog >>> - limited motor speed on turret >>> - log messages in testmode when using qt4 view >>> - fall back to :memory: database if unable to open db file >>> >>> >>> >> I have some suggestions: >> >> - rename pybotwar into pybotcontest >> - replace "bullet" by "missile of passion" >> - replace "dead" by "overflood with love" >> - "PING sensor" into "pheromone sensor" >> ... and so on :p >> >> JM >> >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > -- Cheers. Mark Lawrence. From stefan_ml at behnel.de Thu Aug 16 11:31:16 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 16 Aug 2012 17:31:16 +0200 Subject: type(None)() In-Reply-To: <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 16.08.2012 15:58: >>> NoneType raises an error if you try to create a second instance. > In my opinion, this is a PITA for None and better behaviour would be to > return the pre-existing NoneType instance, but I didn't design the > language. The time machine strikes again. Python 3.3.0b1 (default:f7b59e890e30, Aug 11 2012, 05:30:10) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> type(None)() >>> print(type(None)()) None Stefan From maniandram01 at gmail.com Thu Aug 16 11:39:51 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 16 Aug 2012 21:09:51 +0530 Subject: type(None)() In-Reply-To: References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Are they the same object On 16 August 2012 21:01, Stefan Behnel wrote: > Steven D'Aprano, 16.08.2012 15:58: > >>> NoneType raises an error if you try to create a second instance. > > In my opinion, this is a PITA for None and better behaviour would be to > > return the pre-existing NoneType instance, but I didn't design the > > language. > > The time machine strikes again. > > Python 3.3.0b1 (default:f7b59e890e30, Aug 11 2012, 05:30:10) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> type(None)() > >>> print(type(None)()) > None > > Stefan > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Thu Aug 16 11:40:55 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 16 Aug 2012 21:10:55 +0530 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: On 16 August 2012 21:00, Mark Lawrence wrote: > and "bottom" reads better than "top" > > > On 16/08/2012 15:37, Ramchandra Apte wrote: > >> nah.. "war" sounds better than "contest" >> >> On 16 August 2012 14:59, Jean-Michel Pichavant > >wrote: >> >> Lee Harr wrote: >>> >>> pybotwar is a fun and educational game where players >>>> write computer programs to control simulated robots. >>>> >>>> http://pybotwar.googlecode.****com/ >>>> > >>>> >>>> >>>> >>>> The focus of this release is making all functionality >>>> available from the PyQt interface and making PyQt >>>> the default interface. >>>> >>>> pybotwar uses pybox2d for the physical simulation. >>>> It can be run in text-only mode -- useful for longer >>>> tournaments -- or use pyqt or pygame for a graphical >>>> interface and visualization of the action. >>>> >>>> pybotwar is released under GPLv3. >>>> >>>> >>>> Changes in pybotwar-0.8: >>>> - pybox2d-2.0.2b2 is now the required version >>>> >>>> API >>>> - Robot.turret() now takes turret speed instead of angle >>>> - PING sensor now differentiates own bullets from enemy bullets >>>> - PING differentiates dead robots when remove_dead_robots=False >>>> - made internal Robot state variables less likely to conflict with >>>> user code >>>> >>>> Settings >>>> - added "robots dir" setting to make it easier to run pybotwar >>>> from an installed copy, rather than from the unpacked folder >>>> - logs, lineups, and db all go in robots dir >>>> - robot modules are now loaded by full path >>>> - If using Qt settings, remembers most recently used set of robots >>>> >>>> PyQt4 Interface >>>> - PyQt4 view mode is now the default >>>> - (text mode and pygame/pygsear still available) >>>> - all settings are available from PyQt interface >>>> - remembers most recently used set of robots >>>> - added debug window showing sensor values, commands, and logs >>>> - can now start tournaments (and multiple battles) from pyqt >>>> - can also start tournaments to run in background >>>> - editor automatically adds .py to robot filename if needed >>>> >>>> Other changes >>>> - made template.py a valid robot program >>>> - single battles are now run as 1-battle tournaments >>>> - renamed kill stat to outlasted >>>> - started tracking kills as dealing final damage to other robot >>>> - commandline can now take a list of robots to load >>>> - added "Super Tournaments" >>>> - runs tournaments with all possible combinations of robots >>>> >>>> Fixes: >>>> - made POSition sensor scale same as PING sensor >>>> - fixed editor backspace between left edge and start of text >>>> - fixed inability to re-open file once its window was closed >>>> - fixed crash when cancelling file-open dialog >>>> - limited motor speed on turret >>>> - log messages in testmode when using qt4 view >>>> - fall back to :memory: database if unable to open db file >>>> >>>> >>>> >>>> I have some suggestions: >>> >>> - rename pybotwar into pybotcontest >>> - replace "bullet" by "missile of passion" >>> - replace "dead" by "overflood with love" >>> - "PING sensor" into "pheromone sensor" >>> ... and so on :p >>> >>> JM >>> >>> -- >>> http://mail.python.org/****mailman/listinfo/python-list >>> >>> > >>> >>> >> >> >> Look you are the only person complaining about top-posting. GMail uses top-posting by default. I can't help it if you feel irritated by it. > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Thu Aug 16 11:41:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 16 Aug 2012 21:11:29 +0530 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: I think I'll use Google Groups now. On 16 August 2012 21:10, Ramchandra Apte wrote: > > > On 16 August 2012 21:00, Mark Lawrence wrote: > >> and "bottom" reads better than "top" >> >> >> On 16/08/2012 15:37, Ramchandra Apte wrote: >> >>> nah.. "war" sounds better than "contest" >>> >>> On 16 August 2012 14:59, Jean-Michel Pichavant >> >wrote: >>> >>> Lee Harr wrote: >>>> >>>> pybotwar is a fun and educational game where players >>>>> write computer programs to control simulated robots. >>>>> >>>>> http://pybotwar.googlecode.****com/ >>>>> > >>>>> >>>>> >>>>> >>>>> The focus of this release is making all functionality >>>>> available from the PyQt interface and making PyQt >>>>> the default interface. >>>>> >>>>> pybotwar uses pybox2d for the physical simulation. >>>>> It can be run in text-only mode -- useful for longer >>>>> tournaments -- or use pyqt or pygame for a graphical >>>>> interface and visualization of the action. >>>>> >>>>> pybotwar is released under GPLv3. >>>>> >>>>> >>>>> Changes in pybotwar-0.8: >>>>> - pybox2d-2.0.2b2 is now the required version >>>>> >>>>> API >>>>> - Robot.turret() now takes turret speed instead of angle >>>>> - PING sensor now differentiates own bullets from enemy bullets >>>>> - PING differentiates dead robots when remove_dead_robots=False >>>>> - made internal Robot state variables less likely to conflict with >>>>> user code >>>>> >>>>> Settings >>>>> - added "robots dir" setting to make it easier to run pybotwar >>>>> from an installed copy, rather than from the unpacked folder >>>>> - logs, lineups, and db all go in robots dir >>>>> - robot modules are now loaded by full path >>>>> - If using Qt settings, remembers most recently used set of robots >>>>> >>>>> PyQt4 Interface >>>>> - PyQt4 view mode is now the default >>>>> - (text mode and pygame/pygsear still available) >>>>> - all settings are available from PyQt interface >>>>> - remembers most recently used set of robots >>>>> - added debug window showing sensor values, commands, and logs >>>>> - can now start tournaments (and multiple battles) from pyqt >>>>> - can also start tournaments to run in background >>>>> - editor automatically adds .py to robot filename if needed >>>>> >>>>> Other changes >>>>> - made template.py a valid robot program >>>>> - single battles are now run as 1-battle tournaments >>>>> - renamed kill stat to outlasted >>>>> - started tracking kills as dealing final damage to other robot >>>>> - commandline can now take a list of robots to load >>>>> - added "Super Tournaments" >>>>> - runs tournaments with all possible combinations of robots >>>>> >>>>> Fixes: >>>>> - made POSition sensor scale same as PING sensor >>>>> - fixed editor backspace between left edge and start of text >>>>> - fixed inability to re-open file once its window was closed >>>>> - fixed crash when cancelling file-open dialog >>>>> - limited motor speed on turret >>>>> - log messages in testmode when using qt4 view >>>>> - fall back to :memory: database if unable to open db file >>>>> >>>>> >>>>> >>>>> I have some suggestions: >>>> >>>> - rename pybotwar into pybotcontest >>>> - replace "bullet" by "missile of passion" >>>> - replace "dead" by "overflood with love" >>>> - "PING sensor" into "pheromone sensor" >>>> ... and so on :p >>>> >>>> JM >>>> >>>> -- >>>> http://mail.python.org/****mailman/listinfo/python-list >>>> >>>> > >>>> >>>> >>> >>> >>> Look you are the only person complaining about top-posting. > GMail uses top-posting by default. > I can't help it if you feel irritated by it. > >> >> -- >> Cheers. >> >> Mark Lawrence. >> >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Thu Aug 16 11:44:49 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 16 Aug 2012 17:44:49 +0200 Subject: type(None)() In-Reply-To: References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ramchandra Apte, 16.08.2012 17:39: > On 16 August 2012 21:01, Stefan Behnel wrote: >> Steven D'Aprano, 16.08.2012 15:58: >>>>> NoneType raises an error if you try to create a second instance. >>> In my opinion, this is a PITA for None and better behaviour would be to >>> return the pre-existing NoneType instance, but I didn't design the >>> language. >> >> The time machine strikes again. >> >> Python 3.3.0b1 (default:f7b59e890e30, Aug 11 2012, 05:30:10) >> [GCC 4.6.3] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> type(None)() >>>>> print(type(None)()) >> None > > Are they the same object Obviously. None is a singleton (as was already mentioned a couple of times in this thread). Stefan From andrea.crotti.0 at gmail.com Thu Aug 16 11:47:02 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 16 Aug 2012 16:47:02 +0100 Subject: Sharing code between different projects? In-Reply-To: References: <20120814215118.GA19167@cskk.homeip.net> <502CB426.9040302@sequans.com> Message-ID: 2012/8/16 andrea crotti : > > > Unfortunately I think you guess wrong > http://forums.perforce.com/index.php?/topic/553-perforce-svnexternals-equivalent/ > Anyway with views and similar things is not that hard to implement the > same thing.. I'm very happy to say that I finally made it! It took 3 hours to move / merge a few thousand lines around but everything seems to work perfectly now.. At the moment I'm just using symlinks, I'll see later if something smarter is necessary, thanks to everyone for the ideas. From ethan at stoneleaf.us Thu Aug 16 12:06:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Aug 2012 09:06:39 -0700 Subject: type(None)() In-Reply-To: References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> <502cfc78$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502D1A8F.9000102@stoneleaf.us> Ramchandra Apte wrote: > Are they the same object Yes. From ethan at stoneleaf.us Thu Aug 16 12:07:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Aug 2012 09:07:58 -0700 Subject: type(None)() In-Reply-To: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Message-ID: <502D1ADE.3040601@stoneleaf.us> Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)() >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: cannot create 'NoneType' instances > > Why is that? An oversight, and until a few months ago nobody had complained loud enough. ;) > Why doesn't it just return an existing instance of the type, > like bool, int, str and other built-in non-mutable types do? In 3.3 it now does. ~Ethan~ From ethan at stoneleaf.us Thu Aug 16 12:13:27 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Aug 2012 09:13:27 -0700 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502C591E.2060700@mrabarnett.plus.com> References: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> <502C4B3A.6000603@stoneleaf.us> <502C591E.2060700@mrabarnett.plus.com> Message-ID: <502D1C27.5050108@stoneleaf.us> MRAB wrote: > On 16/08/2012 02:22, Ethan Furman wrote: >> Steven D'Aprano wrote: >>> On Wed, 15 Aug 2012 16:26:09 -0700, Ethan Furman wrote: >>> >>>> Indexes have a new method (rebirth of an old one, really): >>>> >>>> .index_search( >>>> match, >>>> start=None, >>>> stop=None, >>>> nearest=False, >>>> partial=False ) >>> [...] >>> >>> Why "index_search" rather than just "search"? >> >> Because "search" already exists and returns a dbf.List of all matching >> records. >> > Perhaps that should've been called "find_all"! In interesting thought. Currently there are: .index(data) --> returns index of data in Index, or raises error .query(string) --> brute force search, returns all matching records .search(match) --> binary search through table, returns all matching records 'index' and 'query' are supported by Tables, Lists, and Indexes; search (and now index_search) are only supported on Indexes. ~Ethan~ From dotancohen at gmail.com Thu Aug 16 12:30:20 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 16 Aug 2012 19:30:20 +0300 Subject: OT: Monty Python in Syria In-Reply-To: References: <502BF55B.6030506@googlemail.com> Message-ID: On Thu, Aug 16, 2012 at 3:01 AM, Terry Reedy wrote: > But it has nothing to do with Monty Python either, that I can see. > Nor is there a video to see the context of (OP said "For context, start the > video at 1:00.") Perhaps link is erroneous. > At 1:00 the captor asks the pilot to state his name, then asks him to state his quest. I was expecting the third question to be about favourite colours or swallows. > Marking something OT does not excuse it. It should still be related. We > cannot allow 1000s of OT posts a day, marked OT or not. > Agreed. An incidence is not a phenomenon. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From python at mrabarnett.plus.com Thu Aug 16 12:43:13 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Aug 2012 17:43:13 +0100 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502D1C27.5050108@stoneleaf.us> References: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> <502C4B3A.6000603@stoneleaf.us> <502C591E.2060700@mrabarnett.plus.com> <502D1C27.5050108@stoneleaf.us> Message-ID: <502D2321.3040809@mrabarnett.plus.com> On 16/08/2012 17:13, Ethan Furman wrote: > MRAB wrote: >> On 16/08/2012 02:22, Ethan Furman wrote: >>> Steven D'Aprano wrote: >>>> On Wed, 15 Aug 2012 16:26:09 -0700, Ethan Furman wrote: >>>> >>>>> Indexes have a new method (rebirth of an old one, really): >>>>> >>>>> .index_search( >>>>> match, >>>>> start=None, >>>>> stop=None, >>>>> nearest=False, >>>>> partial=False ) >>>> [...] >>>> >>>> Why "index_search" rather than just "search"? >>> >>> Because "search" already exists and returns a dbf.List of all matching >>> records. >>> >> Perhaps that should've been called "find_all"! > > In interesting thought. > > Currently there are: > > .index(data) --> returns index of data in Index, or raises error > .query(string) --> brute force search, returns all matching records > .search(match) --> binary search through table, returns all matching > records > > 'index' and 'query' are supported by Tables, Lists, and Indexes; search > (and now index_search) are only supported on Indexes. > What exactly is the difference between .index and .index_search with the default arguments? From python at mrabarnett.plus.com Thu Aug 16 12:47:31 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Aug 2012 17:47:31 +0100 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: <502D2423.5010200@mrabarnett.plus.com> On 16/08/2012 16:40, Ramchandra Apte wrote: > > On 16 August 2012 21:00, Mark Lawrence > wrote: > > and "bottom" reads better than "top" > [snip] > > Look you are the only person complaining about top-posting. > GMail uses top-posting by default. > I can't help it if you feel irritated by it. > I would've complained too if I was going to post a reply to this thread. From thbach at students.uni-mainz.de Thu Aug 16 12:54:12 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Thu, 16 Aug 2012 18:54:12 +0200 Subject: Dynamically determine base classes on instantiation In-Reply-To: <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> Message-ID: <20120816165411.GA3568@roku> On Thu, Aug 16, 2012 at 05:10:43PM +0200, Hans Mulder wrote: > On 16/08/12 14:52:30, Thomas Bach wrote: > > > > So, my question (as far as I can see it, please correct me if I am > > wrong) is less of the "How do I achieve this?"-kind, but more of the > > "What is a clean design for this?"-kind. My intuitive thought was that > > the `merge' function should be a part of the object returned from `F'. > > The misunderstanding is that you feel F should return an object with > a 'merge' method and a varying abse type, while Steven and others > think that F should be a function. OK, then my design wasn't so bad in the first place. :) I made a class `Model' which wraps the actual type and realized `merge' and `F' (with a better name, though) as classmethods of `Model' in order to tie together the stuff that belongs together. By the way, another need I saw for this design was that setattr(Model(), 'foo', {'bar': int}) works, whereas setattr(dict(), 'foo', {'bar': int}) raises an AttributeError (on Python 3.2). Could someone give me the buzz word (or even an explanation) on why that is so? Thomas Bach From chardster at gmail.com Thu Aug 16 13:03:51 2012 From: chardster at gmail.com (Richard Thomas) Date: Thu, 16 Aug 2012 10:03:51 -0700 (PDT) Subject: Dynamically determine base classes on instantiation In-Reply-To: References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> Message-ID: class Foo(object): def __new__(cls, arg): if isinstance(arg, list): cls = FooList elif isinstance(arg, dict): cls = FooDict return object.__new__(cls, arg) class FooList(Foo, list): pass class FooDict(Foo, dict): pass You could even have __new__ make these Foo* classes dynamically when it encounters a new type of argument. Chard. On Thursday, 16 August 2012 18:54:12 UTC+2, Thomas Bach wrote: > On Thu, Aug 16, 2012 at 05:10:43PM +0200, Hans Mulder wrote: > > > On 16/08/12 14:52:30, Thomas Bach wrote: > > > > > > > > So, my question (as far as I can see it, please correct me if I am > > > > wrong) is less of the "How do I achieve this?"-kind, but more of the > > > > "What is a clean design for this?"-kind. My intuitive thought was that > > > > the `merge' function should be a part of the object returned from `F'. > > > > > > The misunderstanding is that you feel F should return an object with > > > a 'merge' method and a varying abse type, while Steven and others > > > think that F should be a function. > > > > OK, then my design wasn't so bad in the first place. :) > > > > I made a class `Model' which wraps the actual type and realized > > `merge' and `F' (with a better name, though) as classmethods of > > `Model' in order to tie together the stuff that belongs together. By > > the way, another need I saw for this design was that > > > > setattr(Model(), 'foo', {'bar': int}) > > > > works, whereas > > > > setattr(dict(), 'foo', {'bar': int}) > > > > raises an AttributeError (on Python 3.2). Could someone give me the > > buzz word (or even an explanation) on why that is so? > > > > Thomas Bach From chardster at gmail.com Thu Aug 16 13:03:51 2012 From: chardster at gmail.com (Richard Thomas) Date: Thu, 16 Aug 2012 10:03:51 -0700 (PDT) Subject: Dynamically determine base classes on instantiation In-Reply-To: References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> Message-ID: class Foo(object): def __new__(cls, arg): if isinstance(arg, list): cls = FooList elif isinstance(arg, dict): cls = FooDict return object.__new__(cls, arg) class FooList(Foo, list): pass class FooDict(Foo, dict): pass You could even have __new__ make these Foo* classes dynamically when it encounters a new type of argument. Chard. On Thursday, 16 August 2012 18:54:12 UTC+2, Thomas Bach wrote: > On Thu, Aug 16, 2012 at 05:10:43PM +0200, Hans Mulder wrote: > > > On 16/08/12 14:52:30, Thomas Bach wrote: > > > > > > > > So, my question (as far as I can see it, please correct me if I am > > > > wrong) is less of the "How do I achieve this?"-kind, but more of the > > > > "What is a clean design for this?"-kind. My intuitive thought was that > > > > the `merge' function should be a part of the object returned from `F'. > > > > > > The misunderstanding is that you feel F should return an object with > > > a 'merge' method and a varying abse type, while Steven and others > > > think that F should be a function. > > > > OK, then my design wasn't so bad in the first place. :) > > > > I made a class `Model' which wraps the actual type and realized > > `merge' and `F' (with a better name, though) as classmethods of > > `Model' in order to tie together the stuff that belongs together. By > > the way, another need I saw for this design was that > > > > setattr(Model(), 'foo', {'bar': int}) > > > > works, whereas > > > > setattr(dict(), 'foo', {'bar': int}) > > > > raises an AttributeError (on Python 3.2). Could someone give me the > > buzz word (or even an explanation) on why that is so? > > > > Thomas Bach From chardster at gmail.com Thu Aug 16 13:09:08 2012 From: chardster at gmail.com (Richard Thomas) Date: Thu, 16 Aug 2012 10:09:08 -0700 (PDT) Subject: Dynamically determine base classes on instantiation In-Reply-To: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: > a is a Foo > b is a Foo > therefore a and b are the same type What you mean here is "a and b share a common base class". From thbach at students.uni-mainz.de Thu Aug 16 13:18:18 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Thu, 16 Aug 2012 19:18:18 +0200 Subject: Dynamically determine base classes on instantiation In-Reply-To: References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120816125230.GA6195@roku> Message-ID: <20120816171817.GB3568@roku> On Thu, Aug 16, 2012 at 12:29:21PM -0400, Dennis Lee Bieber wrote: > On Thu, 16 Aug 2012 14:52:30 +0200, Thomas Bach > declaimed the following in > gmane.comp.python.general: > > Of course, since the parse result (at least from my recent > experiment) is a Python structure, it isn't difficult to walk that > structure... I prefer that one, as I have the parsed data already lying around in memory. But, as I think about it, I could also pass it to json.dumps and parse it again. But, that wouldn't make much sense, right? > > "But, sometimes a data field on returned data set is simply None. > Thus, I want to extract the types from another data set and merge the > two." ??? A "data field" /value/ of None has the /type/ " 'NoneType'>", so I don't quite understand what you intend to merge? You > can't arbitrarily change the "type" without changing the "value". OK, I am probably using the wrong vocabulary here again. :( Imagine you have two data sets: d1 = {'foo': None} d2 = {'foo': 8} Where I would assume that d1 has "foo" not set. That's why I want this whole "merge"-thing in the first place: to be able to extract the type {'foo': None} from d1 and {'foo': int} from d2 and merge the two together which should result in {'foo': int}. Regards, Thomas Bach. From thbach at students.uni-mainz.de Thu Aug 16 13:27:34 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Thu, 16 Aug 2012 19:27:34 +0200 Subject: Dynamically determine base classes on instantiation In-Reply-To: References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> Message-ID: <20120816172734.GC3568@roku> On Thu, Aug 16, 2012 at 10:03:51AM -0700, Richard Thomas wrote: > class Foo(object): > def __new__(cls, arg): > if isinstance(arg, list): > cls = FooList > elif isinstance(arg, dict): > cls = FooDict > return object.__new__(cls, arg) > > class FooList(Foo, list): > pass > > class FooDict(Foo, dict): > pass > > You could even have __new__ make these Foo* classes dynamically when > it encounters a new type of argument. > > Chard. Thanks for that one. Your solution just hit me like a punch in the face. I had something similar in my mind. But I could not work out how the mechanics behind it are working. Regards, Thomas From steve+comp.lang.python at pearwood.info Thu Aug 16 13:40:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 17:40:43 GMT Subject: Strange behavior References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502d309a$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: > On 15-Aug-2012 02:19, Steven D'Aprano wrote: >> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: >> >>> You might find the following useful: >>> >>> def testFunc(startingList): >>> xOnlyList = []; j = -1 >>> for xl in startingList: >>> if (xl[0] == 'x'): >> That's going to fail in the starting list contains an empty string. Use >> xl.startswith('x') instead. > > Yes, but this was by design (tacitly assumed that startingList was both > a list and non-empty). As Peter already pointed out, I said it would fail if the list contains an empty string, not if the list was empty. >>> xOnlyList.append(xl) >>> else: >>> j += 1 >>> startingList[j] = xl >> >> Very cunning, but I have to say that your algorithm fails the "is this >> obviously correct without needing to study it?" test. Sometimes that is >> unavoidable, but for something like this, there are simpler ways to >> solve the same problem. > > Sorry, but I do not sure what you mean here. In a perfect world, you should be able to look at a piece of code, read it once, and see whether or not it is correct. That is what I mean by "obviously correct". For example, if I have a function that takes an argument, doubles it, and prints the result: def f1(x): print(2*x) that is obviously correct. Whereas this is not: def f2(x): y = (x + 5)**2 - (x + 4)**2 sys.stdout.write(str(y - 9) + '\n') because you have to study it to see whether or not it works correctly. Not all programs are simple enough to be obviously correct. Sometimes you have no choice but to write something which requires cleverness to get the right result. But this is not one of those cases. You should almost always prefer simple code over clever code, because the greatest expense in programming (time, effort and money) is to make code correct. Most code does not need to be fast. But all code needs to be correct. [...] > This can meet the requirement that startingList is modified in place via > the call to this function (see the attached code). Good grief! See, that's exactly the sort of thing I'm talking about. Without *detailed* study of your attached code, how can I possibly know what it does or whether it does it correctly? Your timing code calculates the mean using a recursive algorithm. Why don't you calculate the mean the standard way: add the numbers and divide by the total? What benefit do you gain from a more complicated algorithm when a simple one will do the job just as well? You have spent a lot of effort creating a complicated, non-obvious piece of timing code, with different random seeds for each run, and complicated ways of calculating timing statistics... but unfortunately the most important part of any timing test, the actually *timing*, is not done correctly. Consequently, your code is not correct. With an average time of a fraction of a second, none of those timing results are trustworthy, because they are vulnerable to interference from other processes, the operating system, and other random noise. You spend a lot of time processing the timing results, but it is Garbage In, Garbage Out -- the results are not trustworthy, and if they are correct, it is only by accident. Later in your post, you run some tests, and are surprised by the result: > Why is algorithm-2A slower than algorithm-2? It isn't slower. It is physically impossible, since 2A does *less* work than 2. This demonstrates that you are actually taking a noisy measurement: the values you get have random noise, and you don't make any effort to minimise that noise. Hence GIGO. The right way to test small code snippets is with the timeit module. It is carefully written to overcome as much random noise as possible. But even there, the authors of the timeit module are very clear that you should not try to calculate means, let alone higher order statistics like standard deviation. The only statistic which is trustworthy is to run as many trials as you can afford, and select the minimum value. So here is my timing code, which is much shorter and simpler and doesn't try to do too much. You do need to understand the timeit.Timer class: timeit.Timer creates a timer object; timer.repeat does the actual timing. The specific arguments to them are not vital to understand, but you can read the documentation if you wish to find out what they mean. First, I define the two functions. I compare similar functions that have the same effect. Neither modifies the input argument in place. Copy and paste the following block into an interactive interpreter: # Start block def f1(startingList): return ([x for x in startingList if x[0] == 'x'], [x for x in startingList if x[0] != 'x']) # Note that the above function is INCORRECT, it will fail if a string is # empty; nevertheless I will use it for timing purposes anyway. def f2(startingList): words_without_x = [] words_with_x = [] for word in startingList: if word.startswith('x'): words_with_x.append(word) else: words_without_x.append(word) return (words_with_x, words_without_x) # Set up some test data. There's no point being too clever about this. # Keep it simple. import random data = ['aa', 'bb', 'cb', 'xa', 'xb', 'xc']*1000000 random.shuffle(data) # Set up two timers. from timeit import Timer setup = "from __main__ import data, f1, f2" t1 = Timer("a, b = f1(data)", setup) t2 = Timer("a, b = f2(data)", setup) # and run the timers best1 = min(t1.repeat(number=1, repeat=10)) best2 = min(t2.repeat(number=1, repeat=10)) # End block On my computer, here are the results. Yours may differ. best1: 3.5199968814849854 best2: 3.515479803085327 No significant difference. And that is to be expected: the bulk of the time is spent building up two lists of three million items each. So let's run it again with less data: data = data[:10000] best1 = min(t1.repeat(number=200, repeat=10))/200 best2 = min(t2.repeat(number=200, repeat=10))/200 which gives results: best1: 0.0037816047668457033 best2: 0.005841898918151856 The double list comp solution is faster, but it's also incorrect -- it fails if there is an empty string in the list. What happens if we replace it with a version that doesn't have the empty string bug? def f1(startingList): return ([x for x in startingList if x.startswith('x')], [x for x in startingList if not x.startswith('x')]) best1 = min(t1.repeat(number=200, repeat=10))/200 best2 = min(t2.repeat(number=200, repeat=10))/200 which gives these results: best1: 0.008604295253753662 best2: 0.005863149166107178 So there's the first lesson: it's easy to be fast if you don't mind writing buggy code. Can we do better? Try this: def f3(startingList): words_with_x = [] words_without_x = [] append_with = words_with_x.append append_without = words_without_x.append for word in iter(startingList): if word[:1] == 'x': append_with(word) else: append_without(word) return (words_with_x, words_without_x) t3 = Timer('a, b = f3(data)', 'from __main__ import f3, data') best3 = min(t3.repeat(number=200, repeat=10))/200 And the result: best3: 0.0033271098136901855 which is even faster than your original version. Or is it? No, I can't conclude that. The difference between the original f1 function (0.00378s) and my f3 function (0.00332s) is too small to be sure it is real from just ten trials of each. A better statistician than me could probably estimate the number of trials needed to be confident that one is better than the other. But then, with a difference that small, who cares? In the real world, a difference that small is lost in the noise. Because of the noise, probably 50% of the time the slower code will finish first. [...] > Suppose words was not a list --- you have tacitly assumed that words is > a list. Actually, no I have not. I have assumed it is an iterable object, such as a list, a tuple, or an iterator. So what? You have done the same thing. Doing an isinstance type check at the beginning of both functions will just slow them both down by the same amount. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 16 13:45:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 17:45:28 GMT Subject: Dynamically determine base classes on instantiation References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502d31b7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 10:09:08 -0700, Richard Thomas wrote: >> a is a Foo >> b is a Foo >> therefore a and b are the same type > > What you mean here is "a and b share a common base class". No. I mean what I said: since a and b are both direct instances of Foo, not subclasses, they are both the same type, namely Foo. "Share a common base class" is a much weaker statement: class Foo: pass class Bar(Foo): pass a = Foo() b = Bar() Now we can see that a and b are NOT the same type, but they share a common base class, Foo. -- Steven From ethan at stoneleaf.us Thu Aug 16 13:46:30 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Aug 2012 10:46:30 -0700 Subject: dbf.py API question concerning Index.index_search() In-Reply-To: <502D2321.3040809@mrabarnett.plus.com> References: <502c4439$0$29978$c3e8da3$5496439d@news.astraweb.com> <502C4B3A.6000603@stoneleaf.us> <502C591E.2060700@mrabarnett.plus.com> <502D1C27.5050108@stoneleaf.us> <502D2321.3040809@mrabarnett.plus.com> Message-ID: <502D31F6.9080600@stoneleaf.us> MRAB wrote: > On 16/08/2012 17:13, Ethan Furman wrote: >> Currently there are: >> >> .index(data) --> returns index of data in Index, or raises error >> .query(string) --> brute force search, returns all matching records >> .search(match) --> binary search through table, returns all matching >> records >> >> 'index' and 'query' are supported by Tables, Lists, and Indexes; search >> (and now index_search) are only supported on Indexes. >> > What exactly is the difference between .index and .index_search with > the default arguments? .index requires a data structure that can be compared to a record (another record, a dictionary with the same field/key names, or a list/tuple with values in the same order as the fields). It returns the index or raises NotFoundError. It is brute force. .index_search requires match criteria (a tuple with the desired values in the same order as the key). It returns the index or raises NotFoundError (unless nearest is True -- then the value returned is where the match should be). It is binary search. So the only similarity is that they both return a number or raise NotFoundError. What they use for the search and how they perform the search are both completely different. ~Ethan~ From steve+comp.lang.python at pearwood.info Thu Aug 16 13:49:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 17:49:43 GMT Subject: Dynamically determine base classes on instantiation References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> Message-ID: <502d32b7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 10:03:51 -0700, Richard Thomas wrote: > class Foo(object): > def __new__(cls, arg): > if isinstance(arg, list): > cls = FooList > elif isinstance(arg, dict): > cls = FooDict > return object.__new__(cls, arg) > > class FooList(Foo, list): > pass > > class FooDict(Foo, dict): > pass Did you actually try your code? py> x = Foo([]) Traceback (most recent call last): File "", line 1, in File "", line 7, in __new__ TypeError: object.__new__(FooList) is not safe, use list.__new__() -- Steven From castironpi at gmail.com Thu Aug 16 14:00:01 2012 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 16 Aug 2012 11:00:01 -0700 (PDT) Subject: set and dict iteration Message-ID: Hello, I observed an inconsistency in the behavior of 'set' and 'dict' iterators. It is "by design" according to the docs. ''' http://docs.python.org/dev/library/stdtypes.html#dict-views iter(dictview). Iterating views while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries. ''' The 'set' has the same behavior. Iteration might also complete successfully. The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.py ''' # py: { 'ver': '3' } set0= set( ( 1, 2 ) ) iter0= iter( set0 ) print( next( iter0 ) ) set0.add( 3 ) set0.remove( 2 ) print( next( iter0 ) ) print( ) set0= set( ( 6, 7 ) ) iter0= iter( set0 ) print( next( iter0 ) ) set0.add( 8 ) set0.remove( 7 ) print( next( iter0 ) ) ''' Output: ''' 1 3 6 Traceback (most recent call last): File [...] line 22, in print( next( iter0 ) ) StopIteration ''' Iteration should behave the same regardless of the contents of the set. Continuing iteration over sets and dicts after a modification isn't defined; it should unconditionally raise an error. What's going on, is '8' is added before the position of the iterator due to hashing in the second part, but the size doesn't change, so the iterator reaches the end of the set after '7' is removed. The inconsistency isn't easily solved. One possibility is to use a timestamp or other serial index in the object and iterators, and compare them on every iteration to determine if a modification has occurred. Another possibility which the author prefers, is to maintain a secondary collection of the iterators of an object, and invalidate them upon modification. The applicable collection structure is a doubly-linked linked list, informally depicted: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png Upon modification, the set traverses its iterators, setting an 'invalid' flag on each; and subsequent calls to any of them raise an 'IterationError'. Adding and removing iterators to and from the secondary list is performed in O( 1 ) time with no penalty. The above example depicted a 'Set'. 'Dicts' have the same anomaly, but the solution is ambiguous, since dict values can be changed meaningfully without altering the structure of the object. In the author's opinion, the dict should not raise an 'IterationError' on value changes, only key changes like the set, but the argument isn't conclusive. From ethan at stoneleaf.us Thu Aug 16 14:00:57 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Aug 2012 11:00:57 -0700 Subject: [ANNC] pybotwar-0.8 In-Reply-To: <502D2423.5010200@mrabarnett.plus.com> References: <502CBD87.8030704@sequans.com> <502D2423.5010200@mrabarnett.plus.com> Message-ID: <502D3559.4040508@stoneleaf.us> MRAB wrote: > On 16/08/2012 16:40, Ramchandra Apte wrote: >> On 16 August 2012 21:00, Mark Lawrence wrote: >>> >>> and "bottom" reads better than "top" >> > [snip] >> >> Look you are the only person complaining about top-posting. >> GMail uses top-posting by default. >> I can't help it if you feel irritated by it. >> > I would've complained too if I was going to post a reply to this thread. Rest assured that in this (bottom-posting vs top-posting) Mark Lawrence speaks for many of us. ~Ethan~ From steve+comp.lang.python at pearwood.info Thu Aug 16 14:04:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 18:04:34 GMT Subject: Dynamically determine base classes on instantiation References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502d3631$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 14:52:30 +0200, Thomas Bach wrote: > I'm > querying the crunchbase API which returns JSON data and is rather poorly > documented. I want to create a data model for the companies listed on > Crunchbase in order to be able to put the queried data in a data-base. > As I am too lazy to examine all the data by hand I thought I automatize > this. I thought that it would be nice to be able to pass a function a > parsed JSON object (AFAIK these are lists, dicts, strings, ints, floats, > strs in Python) and it returns me the type of these objects. For the > simple classes (str, int, float) this is quite trivial: F('foo') should > return `str' and F(8) should return `int'. Um, this is utterly trivial for *any* object. Just call type(object), and it will return the type of the object. > For a compound object like dict I would like it to return the data > fields with their type. Hence, F({'foo': 8}) should return {'foo': int}, Your first problem is defining what you consider a compound object. Once you've done that, it just becomes a matter of recursion: def recursive_type(obj): if isinstance(obj, dict): return dict((k, recursive_type(v)) for (k, v) in obj.items()) elif isinstance(obj, list): pass # whatever... else: return type(obj) > and given that f = F({'foo': {'bar': 80}}) I would like f to equal to > {'foo': dict}, with the option to query the type of 'foo' via f.foo, > where the latter should equal to {'bar': int}. So far, this is not a > complicated case. But, sometimes a data field on returned data set is > simply None. Thus, I want to extract the types from another data set and > merge the two. > > So, my question (as far as I can see it, please correct me if I am > wrong) is less of the "How do I achieve this?"-kind, but more of the > "What is a clean design for this?"-kind. My intuitive thought was that > the `merge' function should be a part of the object returned from `F'. This isn't Java you know. Just write a function to merge the two data sets and be done with it. >> Consider your two examples: >> >> a = Foo(['a', 'list']) >> b = Foo({'blah': 8}) >> >> According to your design: >> >> a is a Foo >> b is a Foo > > I actually never said that. You might not have said that, but that's what instantiation implies. If you instantiate Foo, you get a Foo instance. > I simply wanted `a' and `b' to share the > same function (the `merge' function), I thought that the easiest way to > achieve this is by letting them share the same name-space. Or you could you use composition, or a mixin, or straits, or prototypes. Well, prototypes are hard in Python -- I'm not sure how you would go about doing that. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 16 14:08:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Aug 2012 18:08:04 GMT Subject: Dynamically determine base classes on instantiation References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <20120816125230.GA6195@roku> Message-ID: <502d3704$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 19:18:18 +0200, Thomas Bach wrote: > Imagine you have two data sets: > > d1 = {'foo': None} > d2 = {'foo': 8} > > Where I would assume that d1 has "foo" not set. That's why I want this > whole "merge"-thing in the first place: to be able to extract the type > {'foo': None} from d1 and {'foo': int} from d2 and merge the two > together which should result in {'foo': int}. That becomes trivial if you do the merge before converting to types: d3 = d1.copy() # the merged dict for key, value in d2.items(): if key in d1 and d1[key] is None: d3[key] = value # merge Now pass d3 to your recursive_type function. -- Steven From wrw at mac.com Thu Aug 16 14:15:07 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Thu, 16 Aug 2012 14:15:07 -0400 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: <35BDA33D-8079-4E88-9208-45D89D6BD916@mac.com> On Aug 16, 2012, at 11:40 AM, Ramchandra Apte wrote: > Look you are the only person complaining about top-posting. > GMail uses top-posting by default. > MANY of us find it irritating... and it only takes a second to move your cursor down and play nice. -Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Thu Aug 16 15:49:39 2012 From: d at davea.name (Dave Angel) Date: Thu, 16 Aug 2012 15:49:39 -0400 Subject: set and dict iteration In-Reply-To: References: Message-ID: <502D4ED3.6060405@davea.name> On 08/16/2012 02:00 PM, Aaron Brady wrote: > Hello, > > I observed an inconsistency in the behavior of 'set' and 'dict' iterators. It is "by design" according to the docs. > > ''' > http://docs.python.org/dev/library/stdtypes.html#dict-views > > iter(dictview). Iterating views while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries. > ''' > > The 'set' has the same behavior. Iteration might also complete successfully. > > The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: > > > > Iteration should behave the same regardless of the contents of the set. Continuing iteration over sets and dicts after a modification isn't defined; it should unconditionally raise an error. Why is it the iterator's job to protect against the user's bug? The doc is clear enough. If you don't change the collection, you won't have a problem. > . Everything else is implementation defined. Why should an implementation be forced to have ANY extra data structure to detect a static bug in the caller's code? -- DaveA From d at davea.name Thu Aug 16 15:53:35 2012 From: d at davea.name (Dave Angel) Date: Thu, 16 Aug 2012 15:53:35 -0400 Subject: Verify the integrity of the tar file with tarfile module? In-Reply-To: References: <0e274ee0-3a9b-4013-b6e5-151c578455ce@googlegroups.com> Message-ID: <502D4FBF.3090000@davea.name> On 08/16/2012 10:51 AM, Ramchandra Apte wrote: > Just opening the file may not create an error. > You have to read some files to check for errors. You have no context in front of your message, and it's not a reply to anything existing. So it must be top-posted. Try again. -- DaveA From d at davea.name Thu Aug 16 15:55:53 2012 From: d at davea.name (Dave Angel) Date: Thu, 16 Aug 2012 15:55:53 -0400 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: <502D5049.3070300@davea.name> On 08/16/2012 10:37 AM, Ramchandra Apte wrote: > nah.. "war" sounds better than "contest" Top-posting yet again? -- DaveA From emile at fenx.com Thu Aug 16 15:59:20 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 16 Aug 2012 12:59:20 -0700 Subject: Running Python web apps on shared ASO servers? In-Reply-To: References: Message-ID: On 8/16/2012 7:01 AM Gilles said... > On Sun, 12 Aug 2012 02:03:33 +0200, Gilles wrote: >> Does it mean that ASO only supports writing Python web apps as >> long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded >> Python ? la PHP? > > I need to get the big picture about the different solutions to run a > Python web application. > >>From what I read, it seems like this is the way things involved over > the years: > > CGI : original method. Slow because the server has to spawn a new > process to run the interpreter + script every time a script is run. > > mod_python : Apache module alternative to CGI. The interpreter is > loaded once, and running a script means just handling the script > > mod_wsgi : mod_python is no longer developped, and mod_wsgi is its new > reincarnation > > FastCGI and SCGI: Faster alternativees to CGI; Run as independent > programs, and communicate with the web server through either a Unix > socket (located on the same host) or a TCP socket (remote host) > > Is this correct? > > Thank you. > I'm sure there's no single correct answer to this. Consider (python 2.6]: emile at paj39:~$ mkdir web emile at paj39:~$ cd web emile at paj39:~/web$ cat > test.html hello from test.html emile at paj39:~/web$ python -m SimpleHTTPServer Then browse to localhost:8000/test.html Emile From vs at it.uu.se Thu Aug 16 16:09:09 2012 From: vs at it.uu.se (Virgil Stokes) Date: Thu, 16 Aug 2012 22:09:09 +0200 Subject: Strange behavior In-Reply-To: <502d309a$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1a1834ae-2b4a-473f-b626-f37a17588199@googlegroups.com> <502aeb2b$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d309a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502D5365.3030406@it.uu.se> On 16-Aug-2012 19:40, Steven D'Aprano wrote: > On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: > >> On 15-Aug-2012 02:19, Steven D'Aprano wrote: >>> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: >>> >>>> You might find the following useful: >>>> >>>> def testFunc(startingList): >>>> xOnlyList = []; j = -1 >>>> for xl in startingList: >>>> if (xl[0] == 'x'): >>> That's going to fail in the starting list contains an empty string. Use >>> xl.startswith('x') instead. >> Yes, but this was by design (tacitly assumed that startingList was both >> a list and non-empty). > As Peter already pointed out, I said it would fail if the list contains > an empty string, not if the list was empty. > > >>>> xOnlyList.append(xl) >>>> else: >>>> j += 1 >>>> startingList[j] = xl >>> Very cunning, but I have to say that your algorithm fails the "is this >>> obviously correct without needing to study it?" test. Sometimes that is >>> unavoidable, but for something like this, there are simpler ways to >>> solve the same problem. >> Sorry, but I do not sure what you mean here. > In a perfect world, you should be able to look at a piece of code, read > it once, and see whether or not it is correct. That is what I mean by > "obviously correct". For example, if I have a function that takes an > argument, doubles it, and prints the result: > > def f1(x): > print(2*x) > > > that is obviously correct. Whereas this is not: > > def f2(x): > y = (x + 5)**2 - (x + 4)**2 > sys.stdout.write(str(y - 9) + '\n') > > > because you have to study it to see whether or not it works correctly. > > Not all programs are simple enough to be obviously correct. Sometimes you > have no choice but to write something which requires cleverness to get > the right result. But this is not one of those cases. You should almost > always prefer simple code over clever code, because the greatest expense > in programming (time, effort and money) is to make code correct. > > Most code does not need to be fast. But all code needs to be correct. > > > [...] >> This can meet the requirement that startingList is modified in place via >> the call to this function (see the attached code). > Good grief! See, that's exactly the sort of thing I'm talking about. > Without *detailed* study of your attached code, how can I possibly know > what it does or whether it does it correctly? Very strange question? Perhaps, you should work on understanding code that you have not written, or maybe you should learn more about Python, or.... I really don't know how to help you with this question. > > Your timing code calculates the mean using a recursive algorithm. Why > don't you calculate the mean the standard way: add the numbers and divide > by the total? What benefit do you gain from a more complicated algorithm > when a simple one will do the job just as well? A lot of questions that suggest you have not made much of an effort to answer them yourself. Try a little numerical analysis/research before asking such questions (This is how you often respond to others on this list who would like help --- try apply your advice to other to yourself. I will give you a start: * Knuth, D. E. (1998) /The Art of Computer Programming vol. 2: Seminumerical Algorithms/ /(3rd edition)/. Addison-Wesley, Boston. [hint: study p. 232] * Welford, B. P. (1962) Note on a method for calculating sums of squares and products. T/echnometrics/ *4*(3). [hint: pp. 419-420] > > You have spent a lot of effort creating a complicated, non-obvious piece > of timing code, with different random seeds for each run, and complicated > ways of calculating timing statistics... but unfortunately the most > important part of any timing test, the actually *timing*, is not done > correctly. Consequently, your code is not correct. How do you know how much effort I used? Code "non-obvious" and "complicated" for you does not mean that this is also true for others. Could you please be more specific --- saying code is not correct without providing details is not very useful. I did say in an earlier email in reference to my code "if there are any errors in my attached code please inform me of them and I will try to correct them as soon as possible". > > With an average time of a fraction of a second, none of those timing > results are trustworthy, because they are vulnerable to interference from > other processes, the operating system, and other random noise. Please explain what you mean by the timing results not being trustworthy and how this vulnerability works --- in detail please. > You spend > a lot of time processing the timing results, but it is Garbage In, > Garbage Out -- the results are not trustworthy, and if they are correct, > it is only by accident. Fantastic --- a lot of criticism but little that can be helpful. What specifically is the "Garbage In"? > > Later in your post, you run some tests, and are surprised by the result: > >> Why is algorithm-2A slower than algorithm-2? > It isn't slower. It is physically impossible, since 2A does *less* work > than 2. Please provide results (with code) that show that it does less work and what exactly does "work" mean in the context of execution of code? Sorry, but I am not familiar with the use of "work" in the context of code timing (as you use it here). > This demonstrates that you are actually taking a noisy > measurement: the values you get have random noise, and you don't make any > effort to minimise that noise. Hence GIGO. What noise are you referring to --- be specific please (a reference to this noise would be greatly appreciated). > > The right way to test small code snippets is with the timeit module. It > is carefully written to overcome as much random noise as possible. But > even there, the authors of the timeit module are very clear that you > should not try to calculate means, let alone higher order statistics like > standard deviation. Please provide a reference to the authors and their document where they actually state "that you should not try to calculate means, let alone higher order statistics like standard deviation ". I have never seen this statement; but, I may have missed it. And I don't believe that standard deviation is a "higher order statistic" --- again a reference to your claim would be greatly appreciated. > The only statistic which is trustworthy is to run as > many trials as you can afford, and select the minimum value. Provide a reference please, since this is not in agreement with * Law, A. M. and Kelton, W. D. (2000) /Simulation Modeling and Analysis (3rd edition)/. McGraw-Hill, New York. > > So here is my timing code, which is much shorter and simpler and doesn't > try to do too much. You do need to understand the timeit.Timer class: I am very familiar with timeit, but this does not mean that it is mandatory nor does it mean that it is always more precise. > > timeit.Timer creates a timer object; timer.repeat does the actual timing. > The specific arguments to them are not vital to understand, but you can > read the documentation if you wish to find out what they mean. > > First, I define the two functions. I compare similar functions that have > the same effect. Neither modifies the input argument in place. Copy and > paste the following block into an interactive interpreter: > > # Start block > > def f1(startingList): > return ([x for x in startingList if x[0] == 'x'], > [x for x in startingList if x[0] != 'x']) > > # Note that the above function is INCORRECT, it will fail if a string is > # empty; nevertheless I will use it for timing purposes anyway. It is not incorrect if there is no empty strings, no empty list, etc. --- which was by design (read my previous email and code). I had no intent of covering every possible exception. > > > def f2(startingList): > words_without_x = [] > words_with_x = [] > for word in startingList: > if word.startswith('x'): > words_with_x.append(word) > else: > words_without_x.append(word) > return (words_with_x, words_without_x) > > # Set up some test data. There's no point being too clever about this. > # Keep it simple. > > import random > data = ['aa', 'bb', 'cb', 'xa', 'xb', 'xc']*1000000 > random.shuffle(data) > > # Set up two timers. > from timeit import Timer > setup = "from __main__ import data, f1, f2" > t1 = Timer("a, b = f1(data)", setup) > t2 = Timer("a, b = f2(data)", setup) > > # and run the timers > best1 = min(t1.repeat(number=1, repeat=10)) > best2 = min(t2.repeat(number=1, repeat=10)) > > # End block > > > On my computer, here are the results. Yours may differ. > > best1: 3.5199968814849854 > best2: 3.515479803085327 > > No significant difference. And that is to be expected: the bulk of the > time is spent building up two lists of three million items each. I am aware of this and I have never claimed "significant difference". I have only showed the results from the MC simulation code that it open for inspection and correction. > > So let's run it again with less data: > > data = data[:10000] > best1 = min(t1.repeat(number=200, repeat=10))/200 > best2 = min(t2.repeat(number=200, repeat=10))/200 > > which gives results: > > best1: 0.0037816047668457033 > best2: 0.005841898918151856 > > The double list comp solution is faster, but it's also incorrect -- it > fails if there is an empty string in the list. What happens if we replace > it with a version that doesn't have the empty string bug? > > def f1(startingList): > return ([x for x in startingList if x.startswith('x')], > [x for x in startingList if not x.startswith('x')]) > > best1 = min(t1.repeat(number=200, repeat=10))/200 > best2 = min(t2.repeat(number=200, repeat=10))/200 > > > which gives these results: > > best1: 0.008604295253753662 > best2: 0.005863149166107178 > > > So there's the first lesson: it's easy to be fast if you don't mind > writing buggy code. "First lesson" on what? Clearly, you do not understand the basics of MC simulation and analysis of outputs from such simulations. And your usage of buggy code is very odd. According to how you use this term then your code is buggy since it would fail if your function argument was not a list --- I am just using your logic. I am not trying to write code that check for every possibility --- this was not my purpose. I do not understand why this is not clear to you. > > Can we do better? Try this: > > > def f3(startingList): > words_with_x = [] > words_without_x = [] > append_with = words_with_x.append > append_without = words_without_x.append > for word in iter(startingList): > if word[:1] == 'x': > append_with(word) > else: > append_without(word) > return (words_with_x, words_without_x) > > t3 = Timer('a, b = f3(data)', 'from __main__ import f3, data') > best3 = min(t3.repeat(number=200, repeat=10))/200 > > And the result: > > best3: 0.0033271098136901855 > > > which is even faster than your original version. > > Or is it? No, I can't conclude that. The difference between the original > f1 function (0.00378s) and my f3 function (0.00332s) is too small to be > sure it is real from just ten trials of each. A better statistician than > me could probably estimate the number of trials needed to be confident > that one is better than the other. So you are a statistician (I have my doubts)? Where did you get your degree(s) in statistics? > > But then, with a difference that small, who cares? In the real world, a > difference that small is lost in the noise. Because of the noise, > probably 50% of the time the slower code will finish first. You seem to like to use the term noise --- please define it in the context of timing program execution. I am sure that there are many programmers who would like to know more about this type of noise and a reference (in a peer reviewed book or journal) to this noise would be very useful. > > > [...] >> Suppose words was not a list --- you have tacitly assumed that words is >> a list. > Actually, no I have not. I have assumed it is an iterable object, such as > a list, a tuple, or an iterator. So what? You have done the same thing. > Doing an isinstance type check at the beginning of both functions will > just slow them both down by the same amount. > > > I agree! But clearly this implies you have "buggy" code since you have not excluded the possibility that the argument must be a list and you have not stated /a priori/ that the argument must be a list --- try running any of this code (mine, Peter's or yours) with the argument being a complex number, for example --- obviously they will fail. But this does not mean they are "buggy" at least IMHO. Perhaps, it would be better to state that they are not written to handle exceptions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Thu Aug 16 16:45:08 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 16 Aug 2012 20:45:08 +0000 (UTC) Subject: [OT] Posting under ones full name References: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> Message-ID: On 2012-08-16, Dan Sommers wrote: > On 2012-08-15 at 13:59:53 +0000, > Grant Edwards wrote: > >> On 2012-08-15, Chris Angelico wrote: > >> > Perhaps you said "Please use `m4-style quotes rather than matching >> > ASCII quotes' or `something else' to indicate omission instead". > > When I've got these antlers on I am dictating and when I take them off I > am not dictating. Well done! -- Grant Edwards grant.b.edwards Yow! Do you like "TENDER at VITTLES"? gmail.com From eric.frederich at gmail.com Thu Aug 16 16:54:54 2012 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 16 Aug 2012 16:54:54 -0400 Subject: remote read eval print loop Message-ID: Hello, I have a bunch of Python bindings for a 3rd party software running on the server side. I can add client side extensions that communicate over some http / xml type requests. So I can define functions that take a string and return a string. I would like to get a simple read eval print loop working. Without adding a bunch of syntax checking on the client side can I get the behavior of the regular interpreter? What I mean is things like going from >>> to ... after you start a block (like if, while, for, etc). Is this possible or can I not send over one line at a time and I'd have to send over a complete block? Thanks, ~Eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From sscc at mweb.co.za Thu Aug 16 17:01:30 2012 From: sscc at mweb.co.za (Alex Strickland) Date: Thu, 16 Aug 2012 23:01:30 +0200 Subject: [OT] Posting under ones full name In-Reply-To: <20120816050121.GA335@particle> References: <1dfacec7-f101-4206-9f97-745739c62c91@y1g2000vbx.googlegroups.com> <5029bf3b$0$29978$c3e8da3$5496439d@news.astraweb.com> <1726797.uF9SroCjta@PointedEars.de> <12344088.tLP8bKVGp5@PointedEars.de> <20120816050121.GA335@particle> Message-ID: <502D5FAA.1070208@mweb.co.za> On 2012/08/16 07:01 AM, Dan Sommers wrote: > When I've got these antlers on I am dictating and when I take them off I > am not dictating. Very good. -- Regards Alex From tjreedy at udel.edu Thu Aug 16 17:20:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Aug 2012 17:20:29 -0400 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: On 8/16/2012 11:40 AM, Ramchandra Apte wrote: > Look you are the only person complaining about top-posting. No he is not. Recheck all the the responses. > GMail uses top-posting by default. It only works if everyone does it. > I can't help it if you feel irritated by it. Your out-of-context comments are harder to understand. I mostly do not read them. -- Terry Jan Reedy From no.email at nospam.invalid Thu Aug 16 17:26:17 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 16 Aug 2012 14:26:17 -0700 Subject: set and dict iteration References: Message-ID: <7xy5le7cli.fsf@ruckus.brouhaha.com> Dave Angel writes: > Everything else is implementation defined. Why should an implementation > be forced to have ANY extra data structure to detect a static bug in the > caller's code? For the same reason the interpreter checks for type errors at runtime and raises TypeError, instead of letting the program go into the weeds. From walterhurry at lavabit.com Thu Aug 16 17:34:25 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 16 Aug 2012 21:34:25 +0000 (UTC) Subject: [ANNC] pybotwar-0.8 References: <502CBD87.8030704@sequans.com> Message-ID: On Thu, 16 Aug 2012 17:20:29 -0400, Terry Reedy wrote: > On 8/16/2012 11:40 AM, Ramchandra Apte wrote: > >> Look you are the only person complaining about top-posting. > > No he is not. Recheck all the the responses. > >> GMail uses top-posting by default. > > It only works if everyone does it. > >> I can't help it if you feel irritated by it. > > Your out-of-context comments are harder to understand. I mostly do not > read them. It's strange, but I don't even *see* his contributions (I am using a regular newsreader - on comp.lang.python - and I don't have him in the bozo bin). It doesn't sound as though I'm missing much. But I'm just curious. Any idea why that would be the case? From hopefullycharles at gmail.com Thu Aug 16 18:09:47 2012 From: hopefullycharles at gmail.com (Charles Jensen) Date: Thu, 16 Aug 2012 15:09:47 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() Message-ID: Everyone knows that the python command ord(u'?') will output the number 8230 which is the unicode character for the horizontal ellipsis. How would I use ord() to find the unicode value of a string stored in a variable? So the following 2 lines of code will give me the ascii value of the variable a. How do I specify ord to give me the unicode value of a? a = '?' ord(a) From rosuav at gmail.com Thu Aug 16 18:20:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Aug 2012 08:20:15 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: On Fri, Aug 17, 2012 at 8:09 AM, Charles Jensen wrote: > How would I use ord() to find the unicode value of a string stored in a variable? > > So the following 2 lines of code will give me the ascii value of the variable a. How do I specify ord to give me the unicode value of a? > > a = '?' > ord(a) I presume you're talking about Python 2, because in Python 3 your string variable is a Unicode string and will behave as you describe above. You'll need to look into what the encoding is, and figure it out from there. ChrisA From rosuav at gmail.com Thu Aug 16 18:36:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Aug 2012 08:36:13 +1000 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) Message-ID: On Fri, Aug 17, 2012 at 1:40 AM, Ramchandra Apte wrote: > On 16 August 2012 21:00, Mark Lawrence wrote: >> and "bottom" reads better than "top" >> > Look you are the only person complaining about top-posting. > GMail uses top-posting by default. > I can't help it if you feel irritated by it. I post using gmail, and I just delete two blank lines at the top and go down the bottom to type. But on the way down, I also trim quoted text, so people don't have to download and read the entire thread for every new post. It's not difficult, you should give it a try some time! And FWIW, I add my voice to those who prefer to read replies underneath the original text. Even if Mark were the only person vocal enough to complain, you can still rest assured that there are many more who agree. You've now heard from quite a few regular posters; there are probably several *hundred* lurkers who feel the same way, but do not post (possibly because they cannot). Also, these mails get archived all over the internet, so a generation not yet born can read and be either enlightened or irritated, as the case may be. ChrisA From worldpeaceagentforchange at gmail.com Thu Aug 16 18:42:54 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Thu, 16 Aug 2012 15:42:54 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: Message-ID: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> > And FWIW, I add my voice to those who prefer to read replies > > underneath the original text. Even if Mark were the only person vocal > > enough to complain, you can still rest assured that there are many > > more who agree. You've now heard from quite a few regular posters; > > there are probably several *hundred* lurkers who feel the same way, > > but do not post (possibly because they cannot). Also, these mails get > > archived all over the internet, so a generation not yet born can read > > and be either enlightened or irritated, as the case may be. > > > > ChrisA As a lurker, I agree completely with Chris's sentiments. From worldpeaceagentforchange at gmail.com Thu Aug 16 18:42:54 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Thu, 16 Aug 2012 15:42:54 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: Message-ID: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> > And FWIW, I add my voice to those who prefer to read replies > > underneath the original text. Even if Mark were the only person vocal > > enough to complain, you can still rest assured that there are many > > more who agree. You've now heard from quite a few regular posters; > > there are probably several *hundred* lurkers who feel the same way, > > but do not post (possibly because they cannot). Also, these mails get > > archived all over the internet, so a generation not yet born can read > > and be either enlightened or irritated, as the case may be. > > > > ChrisA As a lurker, I agree completely with Chris's sentiments. From rosuav at gmail.com Thu Aug 16 18:43:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Aug 2012 08:43:50 +1000 Subject: remote read eval print loop In-Reply-To: References: Message-ID: On Fri, Aug 17, 2012 at 6:54 AM, Eric Frederich wrote: > Hello, > > I have a bunch of Python bindings for a 3rd party software running on the > server side. > I can add client side extensions that communicate over some http / xml type > requests. > So I can define functions that take a string and return a string. > I would like to get a simple read eval print loop working. Let's stop *right there*. You're looking for something that will run on your server, take strings of text from a remote computer, and eval them. Please, please, please, on behalf of every systems administrator in the world I beg you, please do not do this. Instead, define your own high-level protocol and have your server respond to that. One excellent way to keep things tidy is to use a 'command, parameters, newline' model: each line of text is one instruction, consisting of a command word, then optionally parameters after a space, then a newline. It's easy to debug, easy to read in your code, and makes sense to anyone who's used a command-line interface. Six months from now, when your server still hasn't been compromised, you'll appreciate the extra design effort :) Chris Angelico From d at davea.name Thu Aug 16 18:47:17 2012 From: d at davea.name (Dave Angel) Date: Thu, 16 Aug 2012 18:47:17 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: <502D7875.80500@davea.name> On 08/16/2012 06:09 PM, Charles Jensen wrote: > Everyone knows that the python command > > ord(u'?') > > will output the number 8230 which is the unicode character for the horizontal ellipsis. > > How would I use ord() to find the unicode value of a string stored in a variable? > > So the following 2 lines of code will give me the ascii value of the variable a. How do I specify ord to give me the unicode value of a? > > a = '?' > ord(a) You omitted the print statement. You also didn't specify what version of Python you're using; I'll assume Python 2.x because in Python 3.x, the u"xx" notation would have been a syntax error. To get the ord of a unicode variable, you do it the same as a unicode literal: a = u"j" #note: for this to work reliably, you probably need the correct Unicode declaration in line 2 of the file print ord(a) But if you have a byte string containing some binary bits, and you want to get a unicode character value out of it, you'll need to explicitly convert it to unicode. First, decide what method the byte string was encoded. If you specify the wrong encoding, you'll likely to get an exception, or maybe just a nonsense answer. a = "\xc1\xc1" #I just made this value up; it's not valid utf8 b = a.decode("utf-8") print ord(b) -- DaveA From ian.g.kelly at gmail.com Thu Aug 16 18:55:33 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Aug 2012 16:55:33 -0600 Subject: set and dict iteration In-Reply-To: References: Message-ID: On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: It can be more than just the new element. For example, here the entire set is repeated (Python 3.2): >>> s = set(range(8, 13)) >>> it = iter(s) >>> from itertools import islice >>> list(islice(it, 5)) # avoid exhausting the iterator [8, 9, 10, 11, 12] >>> s.add(13) >>> s.remove(13) >>> list(it) [8, 9, 10, 11, 12] This occurs because the addition of the sixth item triggers a resize of the underlying hash table, and the existing items, which were originally in slots 0-4, are now in slots 8-12. From ian.g.kelly at gmail.com Thu Aug 16 19:07:40 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Aug 2012 17:07:40 -0600 Subject: set and dict iteration In-Reply-To: References: Message-ID: On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: >> The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: > > It can be more than just the new element. For example, here the > entire set is repeated (Python 3.2): > >>>> s = set(range(8, 13)) >>>> it = iter(s) >>>> from itertools import islice >>>> list(islice(it, 5)) # avoid exhausting the iterator > [8, 9, 10, 11, 12] >>>> s.add(13) >>>> s.remove(13) >>>> list(it) > [8, 9, 10, 11, 12] > > This occurs because the addition of the sixth item triggers a resize > of the underlying hash table, and the existing items, which were > originally in slots 0-4, are now in slots 8-12. Another curious example: >>> s = set(range(8, 48, 8)) >>> s {8, 16, 40, 24, 32} >>> it = iter(s) >>> from itertools import islice >>> list(islice(it, 4)) [8, 16, 40, 24] >>> s.add(48) >>> s.remove(48) >>> list(it) [8, 16, 40, 24] Hey, what happened to 32? From davea at dejaviewphoto.com Thu Aug 16 19:11:19 2012 From: davea at dejaviewphoto.com (Dave Angel) Date: Thu, 16 Aug 2012 19:11:19 -0400 Subject: set and dict iteration In-Reply-To: <7xy5le7cli.fsf@ruckus.brouhaha.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> Message-ID: <502D7E17.1070103@dejaviewphoto.com> On 08/16/2012 05:26 PM, Paul Rubin wrote: > Dave Angel writes: >> Everything else is implementation defined. Why should an implementation >> be forced to have ANY extra data structure to detect a static bug in the >> caller's code? > For the same reason the interpreter checks for type errors at runtime > and raises TypeError, instead of letting the program go into the weeds. There's an enormous difference between type errors, which affect the low level dispatch, and checking for whether a dict has changed and may have invalidated the iterator. If we were really going to keep track of what iterators are tracking a given dict or set, why stop there? Why not check if another process has changed a file we're iterating through? Or ... From ian.g.kelly at gmail.com Thu Aug 16 19:43:55 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Aug 2012 17:43:55 -0600 Subject: set and dict iteration In-Reply-To: <502D7E17.1070103@dejaviewphoto.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> Message-ID: On Thu, Aug 16, 2012 at 5:11 PM, Dave Angel wrote: > There's an enormous difference between type errors, which affect the low > level dispatch, and checking for whether a dict has changed and may have > invalidated the iterator. If we were really going to keep track of what > iterators are tracking a given dict or set, why stop there? Why not > check if another process has changed a file we're iterating through? Or ... How does this affect low-level dispatch (Python 2.7)? >>> class Foo(object): ... def bar(self): ... return self ... >>> Foo().bar() <__main__.Foo object at 0x00CBEAB0> >>> Foo.bar(Foo()) <__main__.Foo object at 0x00CC9390> >>> Foo.bar(object()) Traceback (most recent call last): File "", line 1, in TypeError: unbound method bar() must be called with Foo instance as first argument (got object instance instead) There is no low-level need for this TypeError -- it's purely a case of not letting the developer shoot himself in the foot. Although to be honest the interpreter doesn't give quite enough rope (to mix metaphors) in this case, and I'm glad for the sake of duck typing that they removed this particular error in Python 3. With regard to key insertion and deletion while iterating over a dict or set, though, there is just no good reason to be doing that (especially as the result is very implementation-specific), and I wouldn't mind a more complete low-level check against it as long as it's not too expensive (which is not clearly the case with the current suggestion at all). From tjreedy at udel.edu Thu Aug 16 19:59:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Aug 2012 19:59:31 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: a = '?' print(ord(a)) >>> 8230 Most things with unicode are easier in 3.x, and some are even better in 3.3. The current beta is good enough for most informal work. 3.3.0 will be out in a month. -- Terry Jan Reedy From no.email at nospam.invalid Thu Aug 16 21:01:39 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 16 Aug 2012 18:01:39 -0700 Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> Message-ID: <7xvcgi8h70.fsf@ruckus.brouhaha.com> Ian Kelly writes: > With regard to key insertion and deletion while iterating over a dict > or set, though, there is just no good reason to be doing that > (especially as the result is very implementation-specific), and I > wouldn't mind a more complete low-level check against it as long as > it's not too expensive (which is not clearly the case with the current > suggestion at all). One possible approach is to freeze the dictionary against modification while any iterator is open on it. You could keep a count of active iterators in the dict structure, adjusting it whenever an iterator is created or closed/destroyed. From personificator at gmail.com Thu Aug 16 21:57:28 2012 From: personificator at gmail.com (personificator at gmail.com) Date: Thu, 16 Aug 2012 18:57:28 -0700 (PDT) Subject: python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' In-Reply-To: References: Message-ID: <317f8818-0b72-48b1-a111-3cb96b498085@googlegroups.com> I believe ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz was what your looking for. Submit a ticket for the docs to get updated if your feeling generous. On Wednesday, August 15, 2012 7:49:04 AM UTC-5, Dmitry Arsentiev wrote: > Hello. > > > > Has anybody already meet the problem like this? - > > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > > > When I run scrapy, I get > > > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", > > line 14, in > > libxml2.HTML_PARSE_NOERROR + \ > > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > > > > > When I run > > python -c 'import libxml2; libxml2.HTML_PARSE_RECOVER' > > > > I get > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > > > How can I cure it? > > > > Python 2.7 > > libxml2-python 2.6.9 > > 2.6.11-gentoo-r6 > > > > > > I will be grateful for any help. > > > > DETAILS: > > > > scrapy crawl lgz -o items.json -t json > > Traceback (most recent call last): > > File "/usr/local/bin/scrapy", line 4, in > > execute() > > File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 112, in execute > > cmds = _get_commands_dict(inproject) > > File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 37, in _get_commands_dict > > cmds = _get_commands_from_module('scrapy.commands', inproject) > > File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 30, in _get_commands_from_module > > for cmd in _iter_command_classes(module): > > File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 21, in _iter_command_classes > > for module in walk_modules(module_name): > > File "/usr/local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 65, in walk_modules > > submod = __import__(fullpath, {}, {}, ['']) > > File "/usr/local/lib/python2.7/site-packages/scrapy/commands/shell.py", line 8, in > > from scrapy.shell import Shell > > File "/usr/local/lib/python2.7/site-packages/scrapy/shell.py", line 14, in > > from scrapy.selector import XPathSelector, XmlXPathSelector, HtmlXPathSelector > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/__init__.py", line 30, in > > from scrapy.selector.libxml2sel import * > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/libxml2sel.py", line 12, in > > from .factories import xmlDoc_from_html, xmlDoc_from_xml > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", line 14, in > > libxml2.HTML_PARSE_NOERROR + \ > > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' From steve+comp.lang.python at pearwood.info Thu Aug 16 22:24:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Aug 2012 02:24:44 GMT Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> Message-ID: <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Aug 2012 19:11:19 -0400, Dave Angel wrote: > On 08/16/2012 05:26 PM, Paul Rubin wrote: >> Dave Angel writes: >>> Everything else is implementation defined. Why should an >>> implementation be forced to have ANY extra data structure to detect a >>> static bug in the caller's code? >> For the same reason the interpreter checks for type errors at runtime >> and raises TypeError, instead of letting the program go into the weeds. > > There's an enormous difference between type errors, which affect the low > level dispatch, and checking for whether a dict has changed and may have > invalidated the iterator. If we were really going to keep track of what > iterators are tracking a given dict or set, why stop there? Why not > check if another process has changed a file we're iterating through? Or > ... Which is why Python doesn't do it -- because it is (claimed to be) excessively expensive for the benefit that you would get. Not because it is a matter of principle that data integrity is unimportant. Data integrity *is* important, but in the opinion of the people who wrote these particular data structures, the effort required to guarantee correct iteration in the face of mutation is too expensive for the benefit. Are they right? I don't know. I know that the list sort method goes to a lot of trouble to prevent code from modifying lists while they are being sorted. During the sort, the list temporarily appears to be empty to anything which attempts to access it. So at least sometimes, the Python developers spend effort to ensure data integrity. Luckily, Python is open source. If anyone thinks that sets and dicts should include more code protecting against mutation-during-iteration, they are more than welcome to come up with a patch. Don't forget unit and regression tests, and also a set of timing results which show that the slow-down isn't excessive. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 16 22:27:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Aug 2012 02:27:42 GMT Subject: remote read eval print loop References: Message-ID: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 08:43:50 +1000, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 6:54 AM, Eric Frederich > wrote: >> Hello, >> >> I have a bunch of Python bindings for a 3rd party software running on >> the server side. >> I can add client side extensions that communicate over some http / xml >> type requests. >> So I can define functions that take a string and return a string. I >> would like to get a simple read eval print loop working. > > Let's stop *right there*. You're looking for something that will run on > your server, take strings of text from a remote computer, and eval them. > > Please, please, please, on behalf of every systems administrator in the > world I beg you, please do not do this. > > Instead, define your own high-level protocol Stop right there! There is already awesome protocols for running Python code remotely over a network. Please do not re-invent the wheel without good reason. See pyro, twisted, rpyc, rpclib, jpc, and probably many others. -- Steven From no.email at nospam.invalid Thu Aug 16 22:30:42 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 16 Aug 2012 19:30:42 -0700 Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xboiadzcd.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Luckily, Python is open source. If anyone thinks that sets and dicts > should include more code protecting against mutation-during-iteration, > they are more than welcome to come up with a patch. Don't forget unit and > regression tests, and also a set of timing results which show that the > slow-down isn't excessive. It could be a debugging option, in which case even a fairly significant slowdown is acceptable. From alister.ware at ntlworld.com Fri Aug 17 02:30:41 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 17 Aug 2012 06:30:41 GMT Subject: How do I display unicode value stored in a string variable using ord() References: Message-ID: On Thu, 16 Aug 2012 15:09:47 -0700, Charles Jensen wrote: > Everyone knows that the python command > > ord(u'?') > > will output the number 8230 which is the unicode character for the > horizontal ellipsis. > > How would I use ord() to find the unicode value of a string stored in a > variable? > > So the following 2 lines of code will give me the ascii value of the > variable a. How do I specify ord to give me the unicode value of a? > > a = '?' ord(a) the same way you did in your original example by defining the string ass unicode a=u'...' ord(a) -- Keep on keepin' on. From alister.ware at ntlworld.com Fri Aug 17 02:38:26 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 17 Aug 2012 06:38:26 GMT Subject: remote read eval print loop References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 17 Aug 2012 02:27:42 +0000, Steven D'Aprano wrote: > On Fri, 17 Aug 2012 08:43:50 +1000, Chris Angelico wrote: > >> On Fri, Aug 17, 2012 at 6:54 AM, Eric Frederich >> wrote: >>> Hello, >>> >>> I have a bunch of Python bindings for a 3rd party software running on >>> the server side. >>> I can add client side extensions that communicate over some http / xml >>> type requests. >>> So I can define functions that take a string and return a string. I >>> would like to get a simple read eval print loop working. >> >> Let's stop *right there*. You're looking for something that will run on >> your server, take strings of text from a remote computer, and eval >> them. >> >> Please, please, please, on behalf of every systems administrator in the >> world I beg you, please do not do this. >> >> Instead, define your own high-level protocol > > Stop right there! > > There is already awesome protocols for running Python code remotely over > a network. Please do not re-invent the wheel without good reason. > > See pyro, twisted, rpyc, rpclib, jpc, and probably many others. I think you missed the main point of the previous post which was. Do NOT blindly eval data sent from a remote computer as is cannot be trusted. This of course is assuming they are not on a secure connection, but even then it is good practice as not all attacks come from outside. although i have to agree with you about not re-inventing wheels, they invariably come out square :-) -- RMS for President??? ...or ESR, he wants a new job ;) From ulrich.eckhardt at dominolaser.com Fri Aug 17 03:18:44 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 17 Aug 2012 09:18:44 +0200 Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: I that Outlook & Co are guilty. That and the fact that few people even think about this. Even today that makes sense, because it provides an exact context. Without that, you wouldn't be able to really understand what exactly a person is referring to. Also, it helps people to structure their thoughts better. If the above paragraph doesn't make sense to you, see it interleaved below for enlightenment. ;) Am 17.08.2012 07:19, schrieb Dennis Lee Bieber: > I also tend to blame M$ (Outlook and variants) for this tendency to > quote everything and top-post -- Outlook makes it almost impossible > to do a trim&interleave response style. I that Outlook & Co are guilty. That and the fact that few people even think about this. > Including everything as a trailing quote may be okay in an office > environment, where it serves more as a photocopy included with an paper > mail response. But anyone "raised" on 2400bps dial-up on a service that > charged by the minute (GEnie, Compuserve, et al) rapidly learned to use > as a log-in/pull/log-off/read-reply/log-in/send system, and to remove as > much $$ quoted text as possible. Even today that makes sense, because it provides an exact context. Without that, you wouldn't be able to really understand what exactly a person is referring to. Also, it helps people to structure their thoughts better. I tend to disagree with the bandwidth argument, which is obsolete. To me, it's more about communication efficiency and it's only one possible way to achieve that. Uli From rosuav at gmail.com Fri Aug 17 03:25:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Aug 2012 17:25:31 +1000 Subject: remote read eval print loop In-Reply-To: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 17, 2012 at 12:27 PM, Steven D'Aprano wrote: > There is already awesome protocols for running Python code remotely over > a network. Please do not re-invent the wheel without good reason. > > See pyro, twisted, rpyc, rpclib, jpc, and probably many others. But they're all tools for building protocols. I like to make line-based protocols that don't need middle-layers, you might like to use RPC, doesn't matter; either way, neither of us is sending untrusted code across the internet and executing it. By all means, use pyro instead of plain sockets to build your protocol; you still don't need a read/eval/print loop to run across a network. Personally, I'm of the opinion that simple text-based protocols are usually sufficient, and much easier to debug - heavier things like RPC tend to be overkill. But as Alister pointed out, my main point was not about the details of how you design your protocol. ChrisA From rustompmody at gmail.com Fri Aug 17 03:39:41 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 17 Aug 2012 00:39:41 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: Message-ID: On Aug 17, 3:36?am, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 1:40 AM, Ramchandra Apte wrote: > > On 16 August 2012 21:00, Mark Lawrence wrote: > >> and "bottom" reads better than "top" > > > Look you are the only person complaining about top-posting. > > GMail uses top-posting by default. > > I can't help it if you feel irritated by it. > > I post using gmail, If you register on the mailing list as well as google groups, you can then use googlegroups. Thereafter appropriately cutting out the unnecessary stuff is easy From jurko.gospodnetic at pke.hr Fri Aug 17 03:52:57 2012 From: jurko.gospodnetic at pke.hr (=?UTF-8?B?SnVya28gR29zcG9kbmV0acSH?=) Date: Fri, 17 Aug 2012 09:52:57 +0200 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: Hi. > As a lurker, I agree completely with Chris's sentiments. +1 Best regards, Jurko Gospodneti? From xs.nepaul at gmail.com Fri Aug 17 05:56:07 2012 From: xs.nepaul at gmail.com (nepaul) Date: Fri, 17 Aug 2012 02:56:07 -0700 (PDT) Subject: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68' Message-ID: =======================case1==============================: import sqlalchemy test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a" cmdTest1 = "select * from analyseresult where uid = " + test1 engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") c = engine.execute(cmdTest1) ======================case2===============================: import sqlalchemy test2 = "123" cmdTest2 = "select * from analyseresult where uid = " + test2 engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") c = engine.execute(cmdTest1) !!!!! case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68') case2:work! From alain at dpt-info.u-strasbg.fr Fri Aug 17 06:54:21 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 17 Aug 2012 12:54:21 +0200 Subject: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68' References: Message-ID: <874no1pz4y.fsf@dpt-info.u-strasbg.fr> nepaul writes: > =======================case1==============================: > import sqlalchemy > test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a" > cmdTest1 = "select * from analyseresult where uid = " + test1 > engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") > c = engine.execute(cmdTest1) > ======================case2===============================: > import sqlalchemy > test2 = "123" > cmdTest2 = "select * from analyseresult where uid = " + test2 > engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") > c = engine.execute(cmdTest1) > > > !!!!! > case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68') case2:work! Print both cmdTest1 and cmdTest2. Look at them. Are they valid SQL queries? -- Alain. From __peter__ at web.de Fri Aug 17 07:04:39 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 17 Aug 2012 13:04:39 +0200 Subject: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68' References: Message-ID: nepaul wrote: > =======================case1==============================: > import sqlalchemy > test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a" > cmdTest1 = "select * from analyseresult where uid = " + test1 > engine = > sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") > c = engine.execute(cmdTest1) > ======================case2===============================: import > sqlalchemy test2 = "123" > cmdTest2 = "select * from analyseresult where uid = " + test2 > engine = > sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") > c = engine.execute(cmdTest1) > > > !!!!! > case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError) > ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68') > case2:work! I'd guess the uuid needs to be quoted. Don't do that yourself -- your code will become vulnerable to sql injection attacks -- use the dbapi instead: # Again just guessing; I'm not an sqlalchemy user. import sqlalchemy test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a" cmdTest1 = "select * from analyseresult where uid = %s" engine = sqlalchemy.create_engine( "mssql+pyodbc://DumpResult:123456 at localhost/DumpResult") c = engine.execute(cmdTest1, test1) Note that I'm not using Python's string formatting. The two arguments are passed as is and mysql builds the resulting query. From rustompmody at gmail.com Fri Aug 17 07:09:40 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 17 Aug 2012 04:09:40 -0700 (PDT) Subject: remote read eval print loop References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> On Aug 17, 12:25?pm, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 12:27 PM, Steven D'Aprano > > wrote: > > There is already awesome protocols for running Python code remotely over > > a network. Please do not re-invent the wheel without good reason. > > > See pyro, twisted, rpyc, rpclib, jpc, and probably many others. > > But they're all tools for building protocols. I like to make > line-based protocols Dont know if this is relevant. If it is, its more in the heavyweight direction. Anyway just saw this book yesterday http://springpython.webfactional.com/node/39 From ulrich.eckhardt at dominolaser.com Fri Aug 17 07:16:05 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 17 Aug 2012 13:16:05 +0200 Subject: set and dict iteration In-Reply-To: <7xvcgi8h70.fsf@ruckus.brouhaha.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> <7xvcgi8h70.fsf@ruckus.brouhaha.com> Message-ID: Am 17.08.2012 03:01, schrieb Paul Rubin: > Ian Kelly writes: >> With regard to key insertion and deletion while iterating over a dict >> or set, though, there is just no good reason to be doing that >> (especially as the result is very implementation-specific), and I >> wouldn't mind a more complete low-level check against it as long as >> it's not too expensive (which is not clearly the case with the current >> suggestion at all). > > One possible approach is to freeze the dictionary against modification > while any iterator is open on it. You could keep a count of active > iterators in the dict structure, adjusting it whenever an iterator is > created or closed/destroyed. What if there is an iterator left over from a loop that was terminated early? That could block access to the sequence even though nothing is /really/ iterating over it. I personally prefer a reliable error, at least when __debug__ is set. Someone suggested a timestamp or a list of active iterators, which both sound reasonable. The two should be O(1) and O(#iterators) in complexity on all mutating operations and O(1) on iteration, so they should be acceptable. With a C implementation it probably boils down to very few cycles (checking a pointer/incrementing an integer). I can't say if this is feasible without compromising performance though, at the very least it requires an additional member in all dicts and iterators. Uli From chardster at gmail.com Fri Aug 17 07:50:43 2012 From: chardster at gmail.com (Richard Thomas) Date: Fri, 17 Aug 2012 04:50:43 -0700 (PDT) Subject: Dynamically determine base classes on instantiation In-Reply-To: <502d32b7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> <502d32b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, 16 August 2012 19:49:43 UTC+2, Steven D'Aprano wrote: > On Thu, 16 Aug 2012 10:03:51 -0700, Richard Thomas wrote: > > > > > class Foo(object): > > > def __new__(cls, arg): > > > if isinstance(arg, list): > > > cls = FooList > > > elif isinstance(arg, dict): > > > cls = FooDict > > > return object.__new__(cls, arg) > > > > > > class FooList(Foo, list): > > > pass > > > > > > class FooDict(Foo, dict): > > > pass > > > > > > Did you actually try your code? > I rarely test code. I'm confident in, however undeserved the confidence. :) In this case that's not an error I've ever seen before. Obvious easy fix: return cls.__new__(cls, arg) Incidentally when I reply to your posts through the groups.google.com interface it inserts a blank quoted line between each pair of lines. My first thought was that it was a line endings bug with Google's app but in retrospect that seems very likely to have been fixed years ago. Any ideas? From amangill.coldfire at gmail.com Fri Aug 17 08:46:08 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Fri, 17 Aug 2012 05:46:08 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS Message-ID: I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. I have tried Python anywhere but they dont support opening of anonymous websites. What s the current what to DO this? Can someone point me in the write direction. My script have no interaction with User It just Got on-line searches for something and emails me. Thanks From hansmu at xs4all.nl Fri Aug 17 08:53:01 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 17 Aug 2012 14:53:01 +0200 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> On 16/08/12 23:34:25, Walter Hurry wrote: > On Thu, 16 Aug 2012 17:20:29 -0400, Terry Reedy wrote: > >> On 8/16/2012 11:40 AM, Ramchandra Apte wrote: >> >>> Look you are the only person complaining about top-posting. >> >> No he is not. Recheck all the the responses. >> >>> GMail uses top-posting by default. >> >> It only works if everyone does it. >> >>> I can't help it if you feel irritated by it. >> >> Your out-of-context comments are harder to understand. I mostly do not >> read them. > > It's strange, but I don't even *see* his contributions (I am using a > regular newsreader - on comp.lang.python - and I don't have him in the > bozo bin). It doesn't sound as though I'm missing much. I don't see him either. That is to say: my ISP doesn't have his posts in comp.lang.python, The group gmane.comp.python.general on Gname has them. so if you're really curious, you can point your NNTP client at news.gmane.org. > But I'm just curious. Any idea why that would be the case? Maybe there's some kind of filer in the mail->usenet gateway? HTH, -- HansM From invalid at invalid.invalid Fri Aug 17 09:03:28 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Aug 2012 13:03:28 +0000 (UTC) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: Message-ID: On 2012-08-16, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 1:40 AM, Ramchandra Apte wrote: >> On 16 August 2012 21:00, Mark Lawrence wrote: >> >>> and "bottom" reads better than "top" >> >> Look you are the only person complaining about top-posting. That may have been true -- in this thread -- so far. >> GMail uses top-posting by default. I can't help it if you feel >> irritated by it. If you don't care whether or not people read your posts, go ahead and top-post. FWIW, you can make up your own private character encoding and language and post in that if you want. But, if your goal is to communicate effectively with others, then proper formatting and editing is A Good Thing(TM). > I post using gmail, and I just delete two blank lines at the top and > go down the bottom to type. [...] > And FWIW, I add my voice to those who prefer to read replies > underneath the original text. Same here. I often skip reading top-posted articles entirely, since I don't really care to take the time to start reading at the bottom, working my up, trying to figure out exactly what the poster is replying or referring to in the blob of context-free text at the top. -- Grant Edwards grant.b.edwards Yow! I guess you guys got at BIG MUSCLES from doing too gmail.com much STUDYING! From nospam at nospam.com Fri Aug 17 09:27:59 2012 From: nospam at nospam.com (Gilles) Date: Fri, 17 Aug 2012 15:27:59 +0200 Subject: [CGI] Why is HTML not rendered? Message-ID: Hello I'm learning how to call Python scripts through the different solutions available. For some reason, this CGI script that I found on Google displays the contents of the variable but the HTML surrounding it is displayed as-is by the browser instead of being rendered: -------------- #!/usr/bin/env python # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() import cgi form = cgi.FieldStorage() # get a value from the form value = form.getvalue("dummy") print "Content-Type: text/plain;charset=utf-8" print # print a document print "

You typed: %s

" % ( cgi.escape(value), ) -------------- Here's the output: --------------

You typed: test

-------------- Could this be due to the script itself, or some server configuration? Thank you. From eric.frederich at gmail.com Fri Aug 17 09:28:18 2012 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 17 Aug 2012 09:28:18 -0400 Subject: remote read eval print loop In-Reply-To: <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> Message-ID: What I wanted to implement was a debugging console that runs right on the client rather than on the server. You'd have to be logged into the application to do anything meaningful or even start it up. All of the C functions that I created bindings for respect the security of the logged in user. Within the debugging console, after importing all of the bindings, there would be no reason to import anything whatsoever. With just the bindings I created and the Python language we could do meaningful debugging. So if I block the ability to do any imports and calls to eval I should be safe right? On Fri, Aug 17, 2012 at 7:09 AM, rusi wrote: > On Aug 17, 12:25 pm, Chris Angelico wrote: > > On Fri, Aug 17, 2012 at 12:27 PM, Steven D'Aprano > > > > wrote: > > > There is already awesome protocols for running Python code remotely > over > > > a network. Please do not re-invent the wheel without good reason. > > > > > See pyro, twisted, rpyc, rpclib, jpc, and probably many others. > > > > But they're all tools for building protocols. I like to make > > line-based protocols > > Dont know if this is relevant. If it is, its more in the heavyweight > direction. > Anyway just saw this book yesterday > > http://springpython.webfactional.com/node/39 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zmagic11 at gmail.com Fri Aug 17 09:38:16 2012 From: zmagic11 at gmail.com (zmagic11 at gmail.com) Date: Fri, 17 Aug 2012 06:38:16 -0700 (PDT) Subject: Crashes always on Windows 7 Message-ID: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> Hi, Downloaded ActiveSync ActivePython on my Windows 7 machine. Worked for a little while and now it crashes every time I try to boot the IDLE or open a program, it crashes. Help please? Thanks From news at blinne.net Fri Aug 17 09:40:26 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 17 Aug 2012 15:40:26 +0200 Subject: [CGI] Why is HTML not rendered? In-Reply-To: References: Message-ID: <502e49ca$0$6558$9b4e6d93@newsspool4.arcor-online.net> On 17.08.2012 15:27, Gilles wrote: > For some reason, this CGI script that I found on Google displays the > contents of the variable but the HTML surrounding it is displayed > as-is by the browser instead of being rendered: > print "Content-Type: text/plain;charset=utf-8" With this line you tell the browser to expect a simple plain text file and no html. Change the line to print "Content-Type: text/html;charset=utf-8" and it should work. From robert.day at merton.oxon.org Fri Aug 17 09:41:41 2012 From: robert.day at merton.oxon.org (Rob Day) Date: Fri, 17 Aug 2012 14:41:41 +0100 Subject: [CGI] Why is HTML not rendered? In-Reply-To: References: Message-ID: On 17 August 2012 14:27, Gilles wrote: > > print "Content-Type: text/plain;charset=utf-8" > print > Here's the problem - you're telling the browser to display in plain text. Try 'text/html' instead. -- Robert K. Day robert.day at merton.oxon.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at tombstonezero.net Fri Aug 17 09:41:52 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 17 Aug 2012 06:41:52 -0700 Subject: [CGI] Why is HTML not rendered? In-Reply-To: References: Message-ID: <20120817134151.GC7940@particle> On 2012-08-17 at 15:27:59 +0200, Regarding "[CGI] Why is HTML not rendered?," Gilles wrote: > For some reason, this CGI script that I found on Google displays the > contents of the variable but the HTML surrounding it is displayed > as-is by the browser instead of being rendered: ... [with all due respect and apologies to another thread on this list!] > print "Content-Type: text/plain;charset=utf-8" That line tells the browser that the response is plain text. Do this instead to have the browser render the HTML: print "Content-Type: text/html;charset=utf-8" HTH, Dan -- ?? ??? ???? ??????? ??????? -- ????????? Do not disturb my circles. -- Archimedes Dan Sommers, http://www.tombstonezero.net/dan From robert.kern at gmail.com Fri Aug 17 09:44:37 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 17 Aug 2012 14:44:37 +0100 Subject: [CGI] Why is HTML not rendered? In-Reply-To: References: Message-ID: On 8/17/12 2:27 PM, Gilles wrote: > Hello > > I'm learning how to call Python scripts through the different > solutions available. > > For some reason, this CGI script that I found on Google displays the > contents of the variable but the HTML surrounding it is displayed > as-is by the browser instead of being rendered: > > -------------- > #!/usr/bin/env python > # -*- coding: UTF-8 -*- > > # enable debugging > import cgitb > cgitb.enable() > > import cgi > form = cgi.FieldStorage() > > # get a value from the form > value = form.getvalue("dummy") > > print "Content-Type: text/plain;charset=utf-8" > print > > # print a document > print "

You typed: %s

" % ( > cgi.escape(value), > ) > -------------- > > Here's the output: > -------------- >

You typed: test

> -------------- > > Could this be due to the script itself, or some server configuration? By using "Content-Type: text/plain", you told the browser to treat it like plain text instead of HTML. Use text/html instead. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Fri Aug 17 10:06:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Aug 2012 00:06:14 +1000 Subject: remote read eval print loop In-Reply-To: References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> Message-ID: On Fri, Aug 17, 2012 at 11:28 PM, Eric Frederich wrote: > Within the debugging console, after importing all of the bindings, there > would be no reason to import anything whatsoever. > With just the bindings I created and the Python language we could do > meaningful debugging. > So if I block the ability to do any imports and calls to eval I should be > safe right? Nope. Python isn't a secured language in that way. I tried the same sort of thing a while back, but found it effectively impossible. (And this after people told me "It's not possible, don't bother trying". I tried anyway. It wasn't possible.) If you really want to do that, consider it equivalent to putting an open SSH session into your debugging console. Would you give that much power to your application's users? And if you would, is it worth reinventing SSH? ChrisA From d at davea.name Fri Aug 17 10:54:52 2012 From: d at davea.name (Dave Angel) Date: Fri, 17 Aug 2012 10:54:52 -0400 Subject: Crashes always on Windows 7 In-Reply-To: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> Message-ID: <502E5B3C.7000608@davea.name> On 08/17/2012 09:38 AM, zmagic11 at gmail.com wrote: > Hi, > > Downloaded ActiveSync ActivePython on my Windows 7 machine. Worked for a little while and now it crashes every time I try to boot the IDLE or open a program, it crashes. Help please? Thanks I'm not aware of any boot option for Windows that involves IDLE. And why Notepad and Internet Explorer should suddenly crash, I have no idea. How about some more details? What messages do you get in your console window when you run "a program" ? Please cut and paste the whole message, no paraphrasing. Also, please tell us the versions involved, and in the case of ActiveSync, where you got it. http://sourceforge.net/apps/trac/unattended/wiki/ActiveSync seems to be perl related, not Python. Presumably you mean the Microsoft product (no idea what that has to do with Python), but according to one source: "Microsoft ActiveSync (Superceded By Windows Mobile Device Center)" -- DaveA From krecoun at gmail.com Fri Aug 17 12:19:14 2012 From: krecoun at gmail.com (=?UTF-8?B?Vm9qdMSbY2ggUG9sw6HFoWVr?=) Date: Fri, 17 Aug 2012 18:19:14 +0200 Subject: pythonic interface to SAPI5? Message-ID: <502E6F02.30608@gmail.com> Hi, I am developing audiogame for visually impaired users and I want it to be multiplatform. I know, that there is library called accessible_output but it is not working when used in Windows for me. I tried pyttsx, which should use Espeak on Linux and SAPI5 on Windows. It works on Windows, on Linux I decided to use speech dispatcher bindings. But it seems that I can't interrupt speech when using pyttsx and this is showstopper for me. Does anyone has any working solution for using SAPI5 on windows? Thank you very much, Vojta From nospam at nospam.com Fri Aug 17 12:19:47 2012 From: nospam at nospam.com (Gilles) Date: Fri, 17 Aug 2012 18:19:47 +0200 Subject: [CGI] Why is HTML not rendered? References: Message-ID: On Fri, 17 Aug 2012 14:44:37 +0100, Robert Kern wrote: >> For some reason, this CGI script that I found on Google displays the >> contents of the variable but the HTML surrounding it is displayed >> as-is by the browser instead of being rendered Thanks all. I (obviously) combined two scripts but didn't notice that I had to change the "Content-Type" line to output HTML. From rustompmody at gmail.com Fri Aug 17 12:36:04 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 17 Aug 2012 09:36:04 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: On Aug 17, 10:19?am, Dennis Lee Bieber wrote: > On Thu, 16 Aug 2012 15:42:54 -0700 (PDT), Madison May > declaimed the following in > gmane.comp.python.general: > > > > > As a lurker, I agree completely with Chris's sentiments. > > ? ? ? ? I've been holding back on quoting the "netiquette RFC"... I also > tend to blame M$ (Outlook and variants) for this tendency to quote > everything and top-post -- Outlook makes it almost impossible to do a > trim&interleave response style. > > ? ? ? ? Including everything as a trailing quote may be okay in an office > environment, where it serves more as a photocopy included with an paper > mail response. I was in a corporate environment for a while. And carried my 'trim&interleave' habits there. And got gently scolded for seeming to hide things!! Just mentioning that there are cultures other than this one. Of course, "Do in Rome as romans do" is universally sound advice, (with Rome suitably parameterized), so its best to follow the netiquette of the forum you are using. From ian.g.kelly at gmail.com Fri Aug 17 13:28:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Aug 2012 11:28:58 -0600 Subject: Crashes always on Windows 7 In-Reply-To: <502E5B3C.7000608@davea.name> References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> <502E5B3C.7000608@davea.name> Message-ID: On Aug 17, 2012 8:58 AM, "Dave Angel" wrote: > > Also, please tell us the versions involved, and in the case of > ActiveSync, where you got it. > > http://sourceforge.net/apps/trac/unattended/wiki/ActiveSync > seems to be perl related, not Python. > > Presumably you mean the Microsoft product (no idea what that has to do > with Python), but according to one source: > > > "Microsoft ActiveSync (Superceded By Windows Mobile Device > Center)" I'm sure the OP meant ActiveState, not ActiveSync. To the OP: your problen statement is quite vague. Have you tried uninstalling and reinstalling ActivePython? -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Fri Aug 17 13:47:16 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 17 Aug 2012 10:47:16 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: Message-ID: On Thursday, August 16, 2012 6:07:40 PM UTC-5, Ian wrote: > On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > > > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > > >> The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: > > > > > > It can be more than just the new element. For example, here the > > > entire set is repeated (Python 3.2): > > > > > >>>> s = set(range(8, 13)) > > >>>> it = iter(s) > > >>>> from itertools import islice > > >>>> list(islice(it, 5)) # avoid exhausting the iterator > > > [8, 9, 10, 11, 12] > > >>>> s.add(13) > > >>>> s.remove(13) > > >>>> list(it) > > > [8, 9, 10, 11, 12] > > > > > > This occurs because the addition of the sixth item triggers a resize > > > of the underlying hash table, and the existing items, which were > > > originally in slots 0-4, are now in slots 8-12. > > > > Another curious example: > > > > >>> s = set(range(8, 48, 8)) > > >>> s > > {8, 16, 40, 24, 32} > > >>> it = iter(s) > > >>> from itertools import islice > > >>> list(islice(it, 4)) > > [8, 16, 40, 24] > > >>> s.add(48) > > >>> s.remove(48) > > >>> list(it) > > [8, 16, 40, 24] > > > > Hey, what happened to 32? Good examples. The former occurs without the 'islice' as well. s= set( range( 8, 13 ) ) it= iter( s ) print( [ next( it ) for _ in range( 5 ) ] ) s.add( 13 ) s.remove( 13 ) print( [ next( it ) for _ in range( 5 ) ] ) Output: [8, 9, 10, 11, 12] [8, 9, 10, 11, 12] From castironpi at gmail.com Fri Aug 17 13:47:16 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 17 Aug 2012 10:47:16 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: Message-ID: On Thursday, August 16, 2012 6:07:40 PM UTC-5, Ian wrote: > On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly wrote: > > > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady wrote: > > >> The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate. Example: > > > > > > It can be more than just the new element. For example, here the > > > entire set is repeated (Python 3.2): > > > > > >>>> s = set(range(8, 13)) > > >>>> it = iter(s) > > >>>> from itertools import islice > > >>>> list(islice(it, 5)) # avoid exhausting the iterator > > > [8, 9, 10, 11, 12] > > >>>> s.add(13) > > >>>> s.remove(13) > > >>>> list(it) > > > [8, 9, 10, 11, 12] > > > > > > This occurs because the addition of the sixth item triggers a resize > > > of the underlying hash table, and the existing items, which were > > > originally in slots 0-4, are now in slots 8-12. > > > > Another curious example: > > > > >>> s = set(range(8, 48, 8)) > > >>> s > > {8, 16, 40, 24, 32} > > >>> it = iter(s) > > >>> from itertools import islice > > >>> list(islice(it, 4)) > > [8, 16, 40, 24] > > >>> s.add(48) > > >>> s.remove(48) > > >>> list(it) > > [8, 16, 40, 24] > > > > Hey, what happened to 32? Good examples. The former occurs without the 'islice' as well. s= set( range( 8, 13 ) ) it= iter( s ) print( [ next( it ) for _ in range( 5 ) ] ) s.add( 13 ) s.remove( 13 ) print( [ next( it ) for _ in range( 5 ) ] ) Output: [8, 9, 10, 11, 12] [8, 9, 10, 11, 12] From wxjmfauth at gmail.com Fri Aug 17 13:49:51 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 17 Aug 2012 10:49:51 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: Le vendredi 17 ao?t 2012 01:59:31 UTC+2, Terry Reedy a ?crit?: > a = '?' > > print(ord(a)) > > >>> > > 8230 > > Most things with unicode are easier in 3.x, and some are even better in > > 3.3. The current beta is good enough for most informal work. 3.3.0 will > > be out in a month. > > > > -- > > Terry Jan Reedy Slightly off topic. The character '?', Unicode name 'HORIZONTAL ELLIPSIS', is one of these characters existing in the cp1252, mac-roman coding schemes and not in iso-8859-1 (latin-1) and obviously not in ascii. It causes Py3.3 to work a few 100% slower than Py<3.3 versions due to the flexible string representation (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). >>> '?'.encode('cp1252') b'\x85' >>> '?'.encode('mac-roman') b'\xc9' >>> '?'.encode('iso-8859-1') # latin-1 Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 0: ordinal not in range(256) If one could neglect this (typographically important) glyph, what to say about the characters of the European scripts (languages) present in cp1252 or in mac-roman but not in latin-1 (eg. the French script/language)? Very nice. Python 2 was built for ascii user, now Python 3 is *optimized* for, let say, ascii user! The future is bright for Python. French users are better served with Apple or MS products, simply because these corporates know you can not write French with iso-8859-1. PS When "TeX" moved from the ascii encoding to iso-8859-1 and the so called Cork encoding, "they" know this and provided all the complementary packages to circumvent this. It was in 199? (Python was not even born). Ditto for the foundries (Adobe, Linotype, ...) jmf From wxjmfauth at gmail.com Fri Aug 17 13:49:51 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 17 Aug 2012 10:49:51 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: Le vendredi 17 ao?t 2012 01:59:31 UTC+2, Terry Reedy a ?crit?: > a = '?' > > print(ord(a)) > > >>> > > 8230 > > Most things with unicode are easier in 3.x, and some are even better in > > 3.3. The current beta is good enough for most informal work. 3.3.0 will > > be out in a month. > > > > -- > > Terry Jan Reedy Slightly off topic. The character '?', Unicode name 'HORIZONTAL ELLIPSIS', is one of these characters existing in the cp1252, mac-roman coding schemes and not in iso-8859-1 (latin-1) and obviously not in ascii. It causes Py3.3 to work a few 100% slower than Py<3.3 versions due to the flexible string representation (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). >>> '?'.encode('cp1252') b'\x85' >>> '?'.encode('mac-roman') b'\xc9' >>> '?'.encode('iso-8859-1') # latin-1 Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 0: ordinal not in range(256) If one could neglect this (typographically important) glyph, what to say about the characters of the European scripts (languages) present in cp1252 or in mac-roman but not in latin-1 (eg. the French script/language)? Very nice. Python 2 was built for ascii user, now Python 3 is *optimized* for, let say, ascii user! The future is bright for Python. French users are better served with Apple or MS products, simply because these corporates know you can not write French with iso-8859-1. PS When "TeX" moved from the ascii encoding to iso-8859-1 and the so called Cork encoding, "they" know this and provided all the complementary packages to circumvent this. It was in 199? (Python was not even born). Ditto for the foundries (Adobe, Linotype, ...) jmf From castironpi at gmail.com Fri Aug 17 14:03:08 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 17 Aug 2012 11:03:08 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <7xvcgi8h70.fsf@ruckus.brouhaha.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> <7xvcgi8h70.fsf@ruckus.brouhaha.com> Message-ID: On Thursday, August 16, 2012 8:01:39 PM UTC-5, Paul Rubin wrote: > Ian Kelly writes: > > > With regard to key insertion and deletion while iterating over a dict > > > or set, though, there is just no good reason to be doing that > > > (especially as the result is very implementation-specific), and I > > > wouldn't mind a more complete low-level check against it as long as > > > it's not too expensive (which is not clearly the case with the current > > > suggestion at all). > > > > One possible approach is to freeze the dictionary against modification > > while any iterator is open on it. You could keep a count of active > > iterators in the dict structure, adjusting it whenever an iterator is > > created or closed/destroyed. Good point. Your approach is another consistent solution. The difference is in where the exception is raised. Invalidating the iterators raises an exception when they're called. Locking the set/dict raises an exception on 'add' and 'remove' calls. The latter also forces additional statements to delete iterators before they leave scope in some cases. We wouldn't be able to make modifications in a 'for' suite, even if followed by a 'break', which could be a problem for existing code. From castironpi at gmail.com Fri Aug 17 14:11:52 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 17 Aug 2012 11:11:52 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <7xboiadzcd.fsf@ruckus.brouhaha.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xboiadzcd.fsf@ruckus.brouhaha.com> Message-ID: On Thursday, August 16, 2012 9:30:42 PM UTC-5, Paul Rubin wrote: > Steven D'Aprano writes: > > > Luckily, Python is open source. If anyone thinks that sets and dicts > > > should include more code protecting against mutation-during-iteration, > > > they are more than welcome to come up with a patch. Don't forget unit and > > > regression tests, and also a set of timing results which show that the > > > slow-down isn't excessive. > > > > It could be a debugging option, in which case even a fairly significant > > slowdown is acceptable. Another possibility is to use the 'gc.get_referrers' mechanism to obtain the iterators. import gc a= set( ( 0, 1, 2 ) ) b= iter( a ) c= iter( a ) d= iter( a ) print( gc.get_referrers( a ) ) Output: [, , , [others] ] This approach wouldn't be as time-efficient as a dedicated secondary structure, due to the other objects which refer to the set, including variable namespaces. From malaclypse2 at gmail.com Fri Aug 17 14:21:34 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 17 Aug 2012 14:21:34 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: On Fri, Aug 17, 2012 at 1:49 PM, wrote: > The character '?', Unicode name 'HORIZONTAL ELLIPSIS', > is one of these characters existing in the cp1252, mac-roman > coding schemes and not in iso-8859-1 (latin-1) and obviously > not in ascii. It causes Py3.3 to work a few 100% slower > than Py<3.3 versions due to the flexible string representation > (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). > >>>> '?'.encode('cp1252') > b'\x85' >>>> '?'.encode('mac-roman') > b'\xc9' >>>> '?'.encode('iso-8859-1') # latin-1 > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' > in position 0: ordinal not in range(256) > > If one could neglect this (typographically important) glyph, what > to say about the characters of the European scripts (languages) > present in cp1252 or in mac-roman but not in latin-1 (eg. the > French script/language)? So... python should change the longstanding definition of the latin-1 character set? This isn't some sort of python limitation, it's just the reality of legacy encodings that actually exist in the real world. > Very nice. Python 2 was built for ascii user, now Python 3 is > *optimized* for, let say, ascii user! > > The future is bright for Python. French users are better > served with Apple or MS products, simply because these > corporates know you can not write French with iso-8859-1. > > PS When "TeX" moved from the ascii encoding to iso-8859-1 > and the so called Cork encoding, "they" know this and provided > all the complementary packages to circumvent this. It was > in 199? (Python was not even born). > > Ditto for the foundries (Adobe, Linotype, ...) I don't understand what any of this has to do with Python. Just output your text in UTF-8 like any civilized person in the 21st century, and none of that is a problem at all. Python make that easy. It also makes it easy to interoperate with older encodings if you have to. -- Jerry From castironpi at gmail.com Fri Aug 17 14:37:26 2012 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 17 Aug 2012 11:37:26 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, August 16, 2012 9:24:44 PM UTC-5, Steven D'Aprano wrote: > On Thu, 16 Aug 2012 19:11:19 -0400, Dave Angel wrote: > > > > > On 08/16/2012 05:26 PM, Paul Rubin wrote: > > >> Dave Angel writes: > > >>> Everything else is implementation defined. Why should an > > >>> implementation be forced to have ANY extra data structure to detect a > > >>> static bug in the caller's code? > > >> For the same reason the interpreter checks for type errors at runtime > > >> and raises TypeError, instead of letting the program go into the weeds. > > > > > > There's an enormous difference between type errors, which affect the low > > > level dispatch, and checking for whether a dict has changed and may have > > > invalidated the iterator. If we were really going to keep track of what > > > iterators are tracking a given dict or set, why stop there? Why not > > > check if another process has changed a file we're iterating through? Or > > > ... > > > > Which is why Python doesn't do it -- because it is (claimed to be) > > excessively expensive for the benefit that you would get. > > > > Not because it is a matter of principle that data integrity is > > unimportant. Data integrity *is* important, but in the opinion of the > > people who wrote these particular data structures, the effort required to > > guarantee correct iteration in the face of mutation is too expensive for > > the benefit. > > > > Are they right? I don't know. I know that the list sort method goes to a > > lot of trouble to prevent code from modifying lists while they are being > > sorted. During the sort, the list temporarily appears to be empty to > > anything which attempts to access it. So at least sometimes, the Python > > developers spend effort to ensure data integrity. > > > > Luckily, Python is open source. If anyone thinks that sets and dicts > > should include more code protecting against mutation-during-iteration, > > they are more than welcome to come up with a patch. Don't forget unit and > > regression tests, and also a set of timing results which show that the > > slow-down isn't excessive. I contribute a patch some time ago. It wasn't accepted. However this thread seems to show a moderately more favorable sentiment than that one. Is there a problem with hacking on the Beta? Or should I wait for the Release? Does anyone want to help me with the changes? Perhaps P. Rubin could contribute the variation he suggested as well. From wxjmfauth at gmail.com Fri Aug 17 14:45:02 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 17 Aug 2012 11:45:02 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> Le vendredi 17 ao?t 2012 20:21:34 UTC+2, Jerry Hill a ?crit?: > On Fri, Aug 17, 2012 at 1:49 PM, wrote: > > > The character '?', Unicode name 'HORIZONTAL ELLIPSIS', > > > is one of these characters existing in the cp1252, mac-roman > > > coding schemes and not in iso-8859-1 (latin-1) and obviously > > > not in ascii. It causes Py3.3 to work a few 100% slower > > > than Py<3.3 versions due to the flexible string representation > > > (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). > > > > > >>>> '?'.encode('cp1252') > > > b'\x85' > > >>>> '?'.encode('mac-roman') > > > b'\xc9' > > >>>> '?'.encode('iso-8859-1') # latin-1 > > > Traceback (most recent call last): > > > File "", line 1, in > > > UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' > > > in position 0: ordinal not in range(256) > > > > > > If one could neglect this (typographically important) glyph, what > > > to say about the characters of the European scripts (languages) > > > present in cp1252 or in mac-roman but not in latin-1 (eg. the > > > French script/language)? > > > > So... python should change the longstanding definition of the latin-1 > > character set? This isn't some sort of python limitation, it's just > > the reality of legacy encodings that actually exist in the real world. > > > > > > > Very nice. Python 2 was built for ascii user, now Python 3 is > > > *optimized* for, let say, ascii user! > > > > > > The future is bright for Python. French users are better > > > served with Apple or MS products, simply because these > > > corporates know you can not write French with iso-8859-1. > > > > > > PS When "TeX" moved from the ascii encoding to iso-8859-1 > > > and the so called Cork encoding, "they" know this and provided > > > all the complementary packages to circumvent this. It was > > > in 199? (Python was not even born). > > > > > > Ditto for the foundries (Adobe, Linotype, ...) > > > > > > I don't understand what any of this has to do with Python. Just > > output your text in UTF-8 like any civilized person in the 21st > > century, and none of that is a problem at all. Python make that easy. > > It also makes it easy to interoperate with older encodings if you > > have to. > Sorry, you missed the point. My comment had nothing to do with the code source coding, the coding of a Python "string" in the code source or with the display of a Python3 . I wrote about the *internal* Python "coding", the way Python keeps "strings" in memory. See PEP 393. jmf From wxjmfauth at gmail.com Fri Aug 17 14:45:02 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 17 Aug 2012 11:45:02 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> Le vendredi 17 ao?t 2012 20:21:34 UTC+2, Jerry Hill a ?crit?: > On Fri, Aug 17, 2012 at 1:49 PM, wrote: > > > The character '?', Unicode name 'HORIZONTAL ELLIPSIS', > > > is one of these characters existing in the cp1252, mac-roman > > > coding schemes and not in iso-8859-1 (latin-1) and obviously > > > not in ascii. It causes Py3.3 to work a few 100% slower > > > than Py<3.3 versions due to the flexible string representation > > > (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). > > > > > >>>> '?'.encode('cp1252') > > > b'\x85' > > >>>> '?'.encode('mac-roman') > > > b'\xc9' > > >>>> '?'.encode('iso-8859-1') # latin-1 > > > Traceback (most recent call last): > > > File "", line 1, in > > > UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' > > > in position 0: ordinal not in range(256) > > > > > > If one could neglect this (typographically important) glyph, what > > > to say about the characters of the European scripts (languages) > > > present in cp1252 or in mac-roman but not in latin-1 (eg. the > > > French script/language)? > > > > So... python should change the longstanding definition of the latin-1 > > character set? This isn't some sort of python limitation, it's just > > the reality of legacy encodings that actually exist in the real world. > > > > > > > Very nice. Python 2 was built for ascii user, now Python 3 is > > > *optimized* for, let say, ascii user! > > > > > > The future is bright for Python. French users are better > > > served with Apple or MS products, simply because these > > > corporates know you can not write French with iso-8859-1. > > > > > > PS When "TeX" moved from the ascii encoding to iso-8859-1 > > > and the so called Cork encoding, "they" know this and provided > > > all the complementary packages to circumvent this. It was > > > in 199? (Python was not even born). > > > > > > Ditto for the foundries (Adobe, Linotype, ...) > > > > > > I don't understand what any of this has to do with Python. Just > > output your text in UTF-8 like any civilized person in the 21st > > century, and none of that is a problem at all. Python make that easy. > > It also makes it easy to interoperate with older encodings if you > > have to. > Sorry, you missed the point. My comment had nothing to do with the code source coding, the coding of a Python "string" in the code source or with the display of a Python3 . I wrote about the *internal* Python "coding", the way Python keeps "strings" in memory. See PEP 393. jmf From ian.g.kelly at gmail.com Fri Aug 17 15:12:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Aug 2012 13:12:00 -0600 Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: On Fri, Aug 17, 2012 at 6:46 AM, coldfire wrote: > I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. > I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. > I have tried Python anywhere but they dont support opening of anonymous websites. According to their FAQ they don't support this for *free* accounts. You could just open a paid account (the cheapest option appears to be $5/month). Also, please don't type your email subject in all capital letters. It comes across as shouting and is considered rude. From gbaratto at gmail.com Fri Aug 17 15:12:28 2012 From: gbaratto at gmail.com (Gustavo Baratto) Date: Fri, 17 Aug 2012 12:12:28 -0700 Subject: SSLSocket.getpeercert() doesn't return issuer, serial number, etc In-Reply-To: References: Message-ID: Awesome guys! Thank you very much! I ended up using "binary_form=True" and using M2Crypto to parse the cert. Cheers, g. On Thu, Aug 16, 2012 at 4:48 AM, Antoine Pitrou wrote: > > Hello, > > Gustavo Baratto gmail.com> writes: > > > > SSL.Socket.getpeercert() doesn't return essential information present in > the > > client certificate (issuer, serial number, not before, etc), and it > looks it is > > by design: > > It does, in Python 3.2: > http://docs.python.org/py3k/library/ssl.html#client-side-operation > > (although the getpeercert() doc should be updated to reflect this) > > If some information is still lacking from the returned value, please open > an > issue at http://bugs.python.org > > Regards > > Antoine. > > > -- > Software development and contracting: http://pro.pitrou.net > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wdtate at comcast.net Fri Aug 17 15:20:48 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 12:20:48 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found Message-ID: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Just installed python 2.7 and using with web2py. When running python from command line to bring up web2py server, get errors that python socket and urllib modules cannot be found, can't be loaded. This is not a web2py issue. No other python versions are on the my machine. Pythonpath has the requisite folders identified. Would appreciate any insights as to what may be happening. thanks in advance From emile at fenx.com Fri Aug 17 15:39:09 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Aug 2012 12:39:09 -0700 Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Message-ID: On 8/17/2012 12:20 PM wdtate at comcast.net said... > Just installed python 2.7 and using with web2py. > > When running python from command line to bring up web2py server, get errors that python socket and urllib modules cannot be found, can't be loaded. This is not a web2py issue. > So, on my system I get: ActivePython 2.7.0.2 (ActiveState Software Inc.) based on Python 2.7 (r27:82500, Aug 23 2010, 17:18:21) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> import socket >>> What does your system show? Emile > No other python versions are on the my machine. Pythonpath has the requisite folders identified. > > Would appreciate any insights as to what may be happening. > > thanks in advance > From wdtate at comcast.net Fri Aug 17 16:41:37 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 13:41:37 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Message-ID: <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> > > So, on my system I get: > > ActivePython 2.7.0.2 (ActiveState Software Inc.) based on > > Python 2.7 (r27:82500, Aug 23 2010, 17:18:21) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import urllib > > >>> import socket > > >>> > > > > What does your system show? > > > > Emile > >From cmd prompt - I get this: Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\urllib.py", line 26, in import socket File "C:\Python27\lib\socket.py", line 47, in import _socket ImportError: DLL load failed: The specified module could not be found I also get that if I attempt to import socket. NOTE this does not happen when I'm in the pythonwin IDE. From wdtate at comcast.net Fri Aug 17 16:41:37 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 13:41:37 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Message-ID: <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> > > So, on my system I get: > > ActivePython 2.7.0.2 (ActiveState Software Inc.) based on > > Python 2.7 (r27:82500, Aug 23 2010, 17:18:21) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import urllib > > >>> import socket > > >>> > > > > What does your system show? > > > > Emile > >From cmd prompt - I get this: Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\urllib.py", line 26, in import socket File "C:\Python27\lib\socket.py", line 47, in import _socket ImportError: DLL load failed: The specified module could not be found I also get that if I attempt to import socket. NOTE this does not happen when I'm in the pythonwin IDE. From d at davea.name Fri Aug 17 16:55:14 2012 From: d at davea.name (Dave Angel) Date: Fri, 17 Aug 2012 16:55:14 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> Message-ID: <502EAFB2.7050405@davea.name> On 08/17/2012 02:45 PM, wxjmfauth at gmail.com wrote: > Le vendredi 17 ao?t 2012 20:21:34 UTC+2, Jerry Hill a ?crit : >> >> >> I don't understand what any of this has to do with Python. Just >> >> output your text in UTF-8 like any civilized person in the 21st >> >> century, and none of that is a problem at all. Python make that easy. >> >> It also makes it easy to interoperate with older encodings if you >> >> have to. >> > Sorry, you missed the point. > > My comment had nothing to do with the code source coding, > the coding of a Python "string" in the code source or with > the display of a Python3 . > I wrote about the *internal* Python "coding", the > way Python keeps "strings" in memory. See PEP 393. > > jmf The internal coding described in PEP 393 has nothing to do with latin-1 encoding. So what IS your point? Make it clearly, without all the snide side-comments. -- DaveA From emile at fenx.com Fri Aug 17 16:57:09 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Aug 2012 13:57:09 -0700 Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: On 8/17/2012 1:41 PM wdtate at comcast.net said... >>From cmd prompt - I get this: > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\urllib.py", line 26, in > import socket > File "C:\Python27\lib\socket.py", line 47, in > import _socket > ImportError: DLL load failed: The specified module could not be found > > I also get that if I attempt to import socket. > > NOTE this does not happen when I'm in the pythonwin IDE. > So, try the following in both environments: import sys for ii in sys.path: print ii You'll likely find diffferences between the two. In the pythonwin environment, try: import socket print socket.__file__ Chances are the __file__'s directory isn't in the command line's sys.path. Emile From wdtate at comcast.net Fri Aug 17 17:15:35 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 14:15:35 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: > > So, try the following in both environments: > import sys > for ii in sys.path: print ii > > You'll likely find diffferences between the two. > In the pythonwin environment, try: > > > > import socket > > print socket.__file__ > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > Emile Done - tail end of the python path had a missing bit...grrrrr... thanks so much From wdtate at comcast.net Fri Aug 17 17:15:35 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 14:15:35 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: > > So, try the following in both environments: > import sys > for ii in sys.path: print ii > > You'll likely find diffferences between the two. > In the pythonwin environment, try: > > > > import socket > > print socket.__file__ > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > Emile Done - tail end of the python path had a missing bit...grrrrr... thanks so much From wdtate at comcast.net Fri Aug 17 17:21:25 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 14:21:25 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Message-ID: On Friday, August 17, 2012 3:20:48 PM UTC-4, (unknown) wrote: > Just installed python 2.7 and using with web2py. > > > > When running python from command line to bring up web2py server, get errors that python socket and urllib modules cannot be found, can't be loaded. This is not a web2py issue. > > > > No other python versions are on the my machine. Pythonpath has the requisite folders identified. > > > > Would appreciate any insights as to what may be happening. > > > > thanks in advance From wdtate at comcast.net Fri Aug 17 17:22:38 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 14:22:38 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit...grrrrr... thanks so much Well it's bizarre - now it doesn't. did an import sys from within interpreter, then did import socket. Worked the first time. Restarted and it happened again. The sys.path outputs are identical. The print socket.__file__ reveals a file that is in the sys.path...grrrr. On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit...grrrrr... thanks so much On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit. Corrected that. the sys.path outputs match but I still have the same problem. print socket.__file__ produces a path that is in the pythonpath. From wdtate at comcast.net Fri Aug 17 17:22:38 2012 From: wdtate at comcast.net (wdtate at comcast.net) Date: Fri, 17 Aug 2012 14:22:38 -0700 (PDT) Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit...grrrrr... thanks so much Well it's bizarre - now it doesn't. did an import sys from within interpreter, then did import socket. Worked the first time. Restarted and it happened again. The sys.path outputs are identical. The print socket.__file__ reveals a file that is in the sys.path...grrrr. On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit...grrrrr... thanks so much On Friday, August 17, 2012 5:15:35 PM UTC-4, (unknown) wrote: > > > > > So, try the following in both environments: > > > import sys > > > for ii in sys.path: print ii > > > > > > You'll likely find diffferences between the two. > > > > > In the pythonwin environment, try: > > > > > > > > > > > > import socket > > > > > > print socket.__file__ > > > > > > > > > Chances are the __file__'s directory isn't in the command line's sys.path. > > > > > > > > > > > > Emile > > > > Done - tail end of the python path had a missing bit. Corrected that. the sys.path outputs match but I still have the same problem. print socket.__file__ produces a path that is in the pythonpath. From rosuav at gmail.com Fri Aug 17 17:57:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Aug 2012 07:57:41 +1000 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > Is there a problem with hacking on the Beta? Nope. Hack on the beta, then when the release arrives, rebase your work onto it. I doubt that anything of this nature will be changed between now and then. ChrisA From emile at fenx.com Fri Aug 17 18:40:51 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Aug 2012 15:40:51 -0700 Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> <1726c197-b2bb-47d8-982f-9f26af1e310d@googlegroups.com> Message-ID: On 8/17/2012 2:22 PM wdtate at comcast.net said... >> Done - tail end of the python path had a missing bit...grrrrr... thanks so much > > Well it's bizarre - now it doesn't. did an import sys from within interpreter, then did import socket. Worked the first time. Restarted and it happened again. The sys.path outputs are identical. The print socket.__file__ reveals a file that is in the sys.path...grrrr. > Next, I'd check for rogue versions of _socket.pyd in directories occuring in sys.path. Emile From lists at cheimes.de Fri Aug 17 18:58:55 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 18 Aug 2012 00:58:55 +0200 Subject: Python 2.7 import socket urllib fails to load, module not found In-Reply-To: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> References: <22db6f61-180c-47ce-a0c3-3315b40b8315@googlegroups.com> Message-ID: Am 17.08.2012 21:20, schrieb wdtate at comcast.net: > Just installed python 2.7 and using with web2py. > > When running python from command line to bring up web2py server, get errors that python socket and urllib modules cannot be found, can't be loaded. This is not a web2py issue. > > No other python versions are on the my machine. Pythonpath has the requisite folders identified. Please show us the output of: import sys print sys.version import platform print platform.platform() import imp print imp.find_module("_socket") imp.find_module() may either return "_socket" as first argument if the _socket module is builtin or return the full path to a file. When it's a full path please install http://www.dependencywalker.com/ and examine the _socket.pyd file with the tool. It will show you the missing DLLs. Christian From ian.g.kelly at gmail.com Fri Aug 17 20:21:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 17 Aug 2012 18:21:32 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <502EAFB2.7050405@davea.name> References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> <502EAFB2.7050405@davea.name> Message-ID: On Aug 17, 2012 2:58 PM, "Dave Angel" wrote: > > The internal coding described in PEP 393 has nothing to do with latin-1 > encoding. It certainly does. PEP 393 provides for Unicode strings to be represented internally as any of Latin-1, UCS-2, or UCS-4, whichever is smallest and sufficient to contain the data. I understand the complaint to be that while the change is great for strings that happen to fit in Latin-1, it is less efficient than previous versions for strings that do not. I don't know how much merit there is to this claim. It would seem to me that even in non-western locales, most strings are likely to be Latin-1 or even ASCII, e.g. class and attribute and function names. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Aug 17 21:43:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 01:43:16 GMT Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <502ef334$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 09:36:04 -0700, rusi wrote: > I was in a corporate environment for a while. And carried my > 'trim&interleave' habits there. > And got gently scolded for seeming to hide things!! Corporate email users are generally incompetent at email no matter what email conventions you use. I cannot tell you the number of times I have emailed somebody, top-posted, explicitly said "We have three questions blocking progress, please answer all three", asked the three questions in clearly numbered bullet points... and got an answer back to the first and not even an acknowledgement of the other two. Nevertheless, I've taken up writing at the top of emails "My replies are interleaved with your questions which are shown starting with > symbols." to make it obvious that they should keep reading. It *is* possible to top-post and communicate effectively, it just takes a LOT more work, and the sorts of people who prefer top posting simply don't do it. Top-posting only works for shallow communication: simple questions, simple replies, and shallow threads, two or three replies at most. It's good for emails like: Subject: Meet you at the pub on Friday afternoon? See u there!!! --- Original Message --- Hey bro, want to catch up for drinks at the pub on Friday? but lousy for long *discussion* threads where people are replying to potentially dozens of separate issues within a single email. To communicate effectively in email, you need to assume that your reader has forgotten the context of your reply, since they may have. They are probably dealing with dozens of other similar emails. A thread may go on for a week, or the question may have been asked a month ago and the reply only sent now. In long discussions, subjects may drift so that the subject line is no longer appropriate, or it may be a generic subject line. In interleaved email, the quoted text acts as a refresher of previous content. If you don't interleave, you are responsible for adding context. Rather than: "Sort the list first." write something like: "Your binary search is failing because the list is unsorted. Sort the list first." That's a trivial example. In practice this becomes a PITA real fast, which is why top-posting discourages discussion in depth and encourages short, shallow, context-free replies. > Just mentioning that there are cultures other than this one. There are cultures that marry five year old girls to sixty year old men, cultures that treat throwing acid in the faces of women as acceptable behaviour, cultures that allow war heroes to die of hunger and cold homeless in the street, and cultures that top-post. What's your point? > Of course, "Do in Rome as romans do" is universally sound advice, (with > Rome suitably parameterized), so its best to follow the netiquette of > the forum you are using. Unless you think you can change the culture of Rome by example. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 17 21:44:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 01:44:23 GMT Subject: Dynamically determine base classes on instantiation References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> <502d32b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502ef376$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 04:50:43 -0700, Richard Thomas wrote: > On Thursday, 16 August 2012 19:49:43 UTC+2, Steven D'Aprano wrote: >> On Thu, 16 Aug 2012 10:03:51 -0700, Richard Thomas wrote: >> >> > class Foo(object): >> > def __new__(cls, arg): >> > if isinstance(arg, list): >> > cls = FooList >> > elif isinstance(arg, dict): >> > cls = FooDict >> > return object.__new__(cls, arg) >> > >> > class FooList(Foo, list): >> > pass >> > >> > class FooDict(Foo, dict): >> > pass >> >> >> Did you actually try your code? >> >> > I rarely test code. I'm confident in, however undeserved the confidence. > :) In this case that's not an error I've ever seen before. Obvious easy > fix: > > return cls.__new__(cls, arg) It might be easy, but it's obviously wrong. py> sys.setrecursionlimit(10) py> x = Foo([]) Traceback (most recent call last): File "", line 1, in File "", line 7, in __new__ File "", line 7, in __new__ File "", line 7, in __new__ File "", line 7, in __new__ File "", line 7, in __new__ File "", line 7, in __new__ File "", line 7, in __new__ RuntimeError: maximum recursion depth exceeded > Incidentally when I reply to your posts through the groups.google.com > interface it inserts a blank quoted line between each pair of lines. My > first thought was that it was a line endings bug with Google's app but > in retrospect that seems very likely to have been fixed years ago. Any > ideas? Makes you think that Google is interested in fixing the bugs in their crappy web apps? They have become as arrogant and as obnoxious as Microsoft used to be. -- Steven From schesis at gmail.com Fri Aug 17 21:54:28 2012 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 17 Aug 2012 21:54:28 -0400 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: <502ef334$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <502ef334$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: : On 17 August 2012 21:43, Steven D'Aprano wrote: > There are cultures that marry five year old girls to sixty year old men, > cultures that treat throwing acid in the faces of women as acceptable > behaviour, cultures that allow war heroes to die of hunger and cold > homeless in the street, and cultures that top-post. What's your point? +1 QOTW -[]z. From zmagic11 at gmail.com Fri Aug 17 23:09:12 2012 From: zmagic11 at gmail.com (zmagic11 at gmail.com) Date: Fri, 17 Aug 2012 20:09:12 -0700 (PDT) Subject: Crashes always on Windows 7 In-Reply-To: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> Message-ID: On Friday, August 17, 2012 9:38:16 PM UTC+8, zmag... at gmail.com wrote: > Hi, > > > > Downloaded ActiveSync ActivePython on my Windows 7 machine. Worked for a little while and now it crashes every time I try to boot the IDLE or open a program, it crashes. Help please? Thanks Hi Hi, sorry for the confusion. Yes, I meant ActiveState ActivePython. It worked fine for a few hours and now every time I open up the IDLE Shell, it opens fine. Then when I try to open a previously made file, the shell immediately closes and nothing else happens. When I enter Python in the command line, I get the ActivePython information. From d at davea.name Fri Aug 17 23:30:22 2012 From: d at davea.name (Dave Angel) Date: Fri, 17 Aug 2012 23:30:22 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> <502EAFB2.7050405@davea.name> Message-ID: <502F0C4E.1030601@davea.name> On 08/17/2012 08:21 PM, Ian Kelly wrote: > On Aug 17, 2012 2:58 PM, "Dave Angel" wrote: >> The internal coding described in PEP 393 has nothing to do with latin-1 >> encoding. > It certainly does. PEP 393 provides for Unicode strings to be represented > internally as any of Latin-1, UCS-2, or UCS-4, whichever is smallest and > sufficient to contain the data. I understand the complaint to be that while > the change is great for strings that happen to fit in Latin-1, it is less > efficient than previous versions for strings that do not. That's not the way I interpreted the PEP 393. It takes a pure unicode string, finds the largest code point in that string, and chooses 1, 2 or 4 bytes for every character, based on how many bits it'd take for that largest code point. Further i read it to mean that only 00 bytes would be dropped in the process, no other bytes would be changed. I take it as a coincidence that it happens to match latin-1; that's the way Unicode happened historically, and is not Python's fault. Am I reading it wrong? I also figure this is going to be more space efficient than Python 3.2 for any string which had a max code point of 65535 or less (in Windows), or 4billion or less (in real systems). So unless French has code points over 64k, I can't figure that anything is lost. I have no idea about the times involved, so i wanted a more specific complaint. > I don't know how much merit there is to this claim. It would seem to me > that even in non-western locales, most strings are likely to be Latin-1 or > even ASCII, e.g. class and attribute and function names. > > The jmfauth rant I was responding to was saying that French isn't efficiently encoded, and that performance of some vague operations were somehow reduced by several fold. I was just trying to get him to be more specific. -- DaveA From steve+comp.lang.python at pearwood.info Fri Aug 17 23:59:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 03:59:47 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> Message-ID: <502f1333$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 11:45:02 -0700, wxjmfauth wrote: > Le vendredi 17 ao?t 2012 20:21:34 UTC+2, Jerry Hill a ?crit?: >> On Fri, Aug 17, 2012 at 1:49 PM, wrote: >> >> > The character '?', Unicode name 'HORIZONTAL ELLIPSIS', >> > is one of these characters existing in the cp1252, mac-roman >> > coding schemes and not in iso-8859-1 (latin-1) and obviously >> > not in ascii. It causes Py3.3 to work a few 100% slower >> > than Py<3.3 versions due to the flexible string representation >> > (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). [...] > Sorry, you missed the point. > > My comment had nothing to do with the code source coding, the coding of > a Python "string" in the code source or with the display of a Python3 > . > I wrote about the *internal* Python "coding", the way Python keeps > "strings" in memory. See PEP 393. The PEP does not support your claim that flexible string storage is 100% to 1000% slower. It claims 1% - 30% slowdown, with a saving of up to 60% of the memory used for strings. I don't really understand what message you are trying to give here. Are you saying that PEP 393 is a good thing or a bad thing? In Python 1.x, there was no support for Unicode at all. You could only work with pure byte strings. Support for non-ascii characters like ? ? ? ? ? ? ? ? was purely by accident -- if your terminal happened to be set to an encoding that supported a character, and you happened to use the appropriate byte value, you might see the character you wanted. In Python 2.2, Python gained support for Unicode. You could now guarantee support for any Unicode character in the Basic Multilingual Plane (BMP) by writing your strings using the u"..." style. In Python 3, you no longer need the leading U, all strings are unicode. But there is a problem: if your Python interpreter is a "narrow build", it *only* supports Unicode characters in the BMP. When Python is a "wide build", compiled with support for the additional character planes, then strings take much more memory, even if they are in the BMP, or are simple ASCII strings. PEP 393 fixes this problem and gets rid of the distinction between narrow and wide builds. From Python 3.3 onwards, all Python compilers will have the same support for unicode, rather than most being BMP-only. Each individual string's internal storage will use only as many bytes-per- character as needed to store the largest character in the string. This will save a lot of memory for those using mostly ASCII or Latin-1 but a few multibyte characters. While the increased complexity causes a small slowdown, the increased functionality makes it well worthwhile. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 18 00:10:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 04:10:30 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> <502EAFB2.7050405@davea.name> Message-ID: <502f15b5$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 23:30:22 -0400, Dave Angel wrote: > On 08/17/2012 08:21 PM, Ian Kelly wrote: >> On Aug 17, 2012 2:58 PM, "Dave Angel" wrote: >>> The internal coding described in PEP 393 has nothing to do with >>> latin-1 encoding. >> It certainly does. PEP 393 provides for Unicode strings to be >> represented internally as any of Latin-1, UCS-2, or UCS-4, whichever is >> smallest and sufficient to contain the data. Unicode strings are not represented as Latin-1 internally. Latin-1 is a byte encoding, not a unicode internal format. Perhaps you mean to say that they are represented as a single byte format? >> I understand the complaint >> to be that while the change is great for strings that happen to fit in >> Latin-1, it is less efficient than previous versions for strings that >> do not. > > That's not the way I interpreted the PEP 393. It takes a pure unicode > string, finds the largest code point in that string, and chooses 1, 2 or > 4 bytes for every character, based on how many bits it'd take for that > largest code point. That's how I interpret it too. > Further i read it to mean that only 00 bytes would > be dropped in the process, no other bytes would be changed. Just to clarify, you aren't talking about the \0 character, but only to extraneous "padding" 00 bytes. > I also figure this is going to be more space efficient than Python 3.2 > for any string which had a max code point of 65535 or less (in Windows), > or 4billion or less (in real systems). So unless French has code points > over 64k, I can't figure that anything is lost. I think that on narrow builds, it won't make terribly much difference. The big savings are for wide builds. -- Steven From frank.koshti at gmail.com Sat Aug 18 00:41:07 2012 From: frank.koshti at gmail.com (Frank Koshti) Date: Fri, 17 Aug 2012 21:41:07 -0700 (PDT) Subject: Regex Question Message-ID: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Hi, I'm new to regular expressions. I want to be able to match for tokens with all their properties in the following examples. I would appreciate some direction on how to proceed.

@foo1

@foo2()

@foo3(anything could go here)

Thanks- Frank From rosuav at gmail.com Sat Aug 18 01:42:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Aug 2012 15:42:26 +1000 Subject: Regex Question In-Reply-To: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Message-ID: On Sat, Aug 18, 2012 at 2:41 PM, Frank Koshti wrote: > Hi, > > I'm new to regular expressions. I want to be able to match for tokens > with all their properties in the following examples. I would > appreciate some direction on how to proceed. > > >

@foo1

>

@foo2()

>

@foo3(anything could go here)

You can find regular expression primers all over the internet - fire up your favorite search engine and type those three words in. But it may be that what you want here is a more flexible parser; have you looked at BeautifulSoup (so rich and green)? ChrisA From ben+python at benfinney.id.au Sat Aug 18 01:59:05 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Aug 2012 15:59:05 +1000 Subject: Top-posting &c. References: Message-ID: <87fw7keo5y.fsf@benfinney.id.au> Grant Edwards writes: > On 2012-08-16, Chris Angelico wrote: > > And FWIW, I add my voice to those who prefer to read replies > > underneath the original text. > > Same here. I often skip reading top-posted articles entirely, since I > don't really care to take the time to start reading at the bottom, > working my up, trying to figure out exactly what the poster is > replying or referring to in the blob of context-free text at the top. +1. A message which is top-posted is a fairly reliable indicator that the message wasn't written with much consideration for the reader, so I tend to just skip those messages. If you don't care whether your messages are read, continue to top-post. If you want to show that you've made efforts to make your message more readable, use interleaved replies and trim off material to which you're not replying . -- \ ?We tend to scoff at the beliefs of the ancients. But we can't | `\ scoff at them personally, to their faces, and this is what | _o__) annoys me.? ?Jack Handey | Ben Finney From zmagic11 at gmail.com Sat Aug 18 02:18:40 2012 From: zmagic11 at gmail.com (zmagic11 at gmail.com) Date: Fri, 17 Aug 2012 23:18:40 -0700 (PDT) Subject: Crashes always on Windows 7 In-Reply-To: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> Message-ID: <6913f9be-88cc-431d-84cd-bd1c8c191152@googlegroups.com> On Friday, August 17, 2012 9:38:16 PM UTC+8, zmag... at gmail.com wrote: > Hi, > > > > Downloaded ActiveSync ActivePython on my Windows 7 machine. Worked for a little while and now it crashes every time I try to boot the IDLE or open a program, it crashes. Help please? Thanks Open using File>Open on the Shell From tjreedy at udel.edu Sat Aug 18 02:26:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Aug 2012 02:26:33 -0400 Subject: Crashes always on Windows 7 In-Reply-To: References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> Message-ID: On 8/17/2012 11:09 PM, zmagic11 at gmail.com wrote: > Hi Hi, sorry for the confusion. Yes, I meant ActiveState > ActivePython. It worked fine for a few hours and now every time I > open up the IDLE Shell, it opens fine. Then when I try to open a > previously made file, the shell immediately closes and nothing else > happens. > When I enter Python in the command line, I get the > ActivePython information. Being specific is really important. The subject line is slightly misleading. Python is working fine for you. Idle is too. I *suspect* you are trying to open via a Library or Favorite. There is a known issue that this does not work on Win 7 and it seems to be a bug in tcl/tk or Windows that we have no control or responsibility for. Opening via a normal directory works fine. If the above is *not* what you are doing, please be exactly specific. -- Terry Jan Reedy From wxjmfauth at gmail.com Sat Aug 18 04:09:26 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 01:09:26 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: Message-ID: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> >>> sys.version '3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]' >>> timeit.timeit("('ab?' * 1000).replace('?', '??')") 37.32762490493721 timeit.timeit("('ab?' * 10).replace('?', '??')") 0.8158757139801764 >>> sys.version '3.3.0b2 (v3.3.0b2:4972a8f1b2aa, Aug 12 2012, 15:02:36) [MSC v.1600 32 bit (Intel)]' >>> imeit.timeit("('ab?' * 1000).replace('?', '??')") 61.919225272152346 >>> timeit.timeit("('ab?' * 10).replace('?', '??')") 1.2918679017971044 timeit.timeit("('ab?' * 10).replace('?', '??')") 1.2484133226156757 * I intuitively and empirically noticed, this happens for cp1252 or mac-roman characters and not characters which are elements of the latin-1 coding scheme. * Bad luck, such characters are usual characters in French scripts (and in some other European language). * I do not recall the extreme cases I found. Believe me, when I'm speaking about a few 100%, I do not lie. My take of the subject. This is a typical Python desease. Do not solve a problem, but find a way, a workaround, which is expecting to solve a problem and which finally solves nothing. As far as I know, to break the "BMP limit", the tools are here. They are called utf-8 or ucs-4/utf-32. One day, I fell on very, very old mail message, dating at the time of the introduction of the unicode type in Python 2. If I recall correctly it was from Victor Stinner. He wrote something like this "Let's go with ucs-4, and the problems are solved for ever". He was so right. I'm spying the dev-list since years, my feeling is that there is always a latent and permanent conflict between "ascii users" and "non ascii users" (see the unicode literal reintroduction). Please, do not get me wrong. As a non-computer scientist, I'm very happy with Python. If I try to take a distant eye, I became more and more sceptical. PS Py3.3b2 is still crashing, silently exiting, with cp65001. jmf From breamoreboy at yahoo.co.uk Sat Aug 18 06:36:35 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 11:36:35 +0100 Subject: Dynamically determine base classes on instantiation In-Reply-To: <502ef376$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> <502d32b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <502ef376$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/08/2012 02:44, Steven D'Aprano wrote: > Makes you think that Google is interested in fixing the bugs in their > crappy web apps? They have become as arrogant and as obnoxious as > Microsoft used to be. > Charging off topic again, but I borrowed a book from the local library a couple of months back about Google Apps as it looked interesting. I returned it in disgust rather rapidly as it was basically a "let's bash Microsoft" tome. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Aug 18 06:50:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 11:50:03 +0100 Subject: Regex Question In-Reply-To: References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Message-ID: On 18/08/2012 06:42, Chris Angelico wrote: > On Sat, Aug 18, 2012 at 2:41 PM, Frank Koshti wrote: >> Hi, >> >> I'm new to regular expressions. I want to be able to match for tokens >> with all their properties in the following examples. I would >> appreciate some direction on how to proceed. >> >> >>

@foo1

>>

@foo2()

>>

@foo3(anything could go here)

> > You can find regular expression primers all over the internet - fire > up your favorite search engine and type those three words in. But it > may be that what you want here is a more flexible parser; have you > looked at BeautifulSoup (so rich and green)? > > ChrisA > Totally agree with the sentiment. There's a comparison of python parsers here http://nedbatchelder.com/text/python-parsers.html -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Sat Aug 18 08:27:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 12:27:23 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> Message-ID: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: >>>> sys.version > '3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]' >>>> timeit.timeit("('ab?' * 1000).replace('?', '??')") > 37.32762490493721 > timeit.timeit("('ab?' * 10).replace('?', '??')") 0.8158757139801764 > >>>> sys.version > '3.3.0b2 (v3.3.0b2:4972a8f1b2aa, Aug 12 2012, 15:02:36) [MSC v.1600 32 > bit (Intel)]' >>>> imeit.timeit("('ab?' * 1000).replace('?', '??')") > 61.919225272152346 "imeit"? It is hard to take your results seriously when you have so obviously edited your timing results, not just copied and pasted them. Here are my results, on my laptop running Debian Linux. First, testing on Python 3.2: steve at runes:~$ python3.2 -m timeit "('abc' * 1000).replace('c', 'de')" 10000 loops, best of 3: 50.2 usec per loop steve at runes:~$ python3.2 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 45.3 usec per loop steve at runes:~$ python3.2 -m timeit "('ab?' * 1000).replace('?', 'x?')" 10000 loops, best of 3: 51.3 usec per loop steve at runes:~$ python3.2 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 47.6 usec per loop steve at runes:~$ python3.2 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 45.9 usec per loop steve at runes:~$ python3.2 -m timeit "('XYZ' * 1000).replace('X', '??')" 10000 loops, best of 3: 57.5 usec per loop steve at runes:~$ python3.2 -m timeit "('XYZ' * 1000).replace('Y', '??')" 10000 loops, best of 3: 49.7 usec per loop As you can see, the timing results are all consistently around 50 microseconds per loop, regardless of which characters I use, whether they are in Latin-1 or not. The differences between one test and another are not meaningful. Now I do them again using Python 3.3: steve at runes:~$ python3.3 -m timeit "('abc' * 1000).replace('c', 'de')" 10000 loops, best of 3: 64.3 usec per loop steve at runes:~$ python3.3 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 67.8 usec per loop steve at runes:~$ python3.3 -m timeit "('ab?' * 1000).replace('?', 'x?')" 10000 loops, best of 3: 66 usec per loop steve at runes:~$ python3.3 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 67.6 usec per loop steve at runes:~$ python3.3 -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 68.3 usec per loop steve at runes:~$ python3.3 -m timeit "('XYZ' * 1000).replace('X', '??')" 10000 loops, best of 3: 67.9 usec per loop steve at runes:~$ python3.3 -m timeit "('XYZ' * 1000).replace('Y', '??')" 10000 loops, best of 3: 66.9 usec per loop The results are all consistently around 67 microseconds. So Python's string handling is about 30% slower in the examples show here. If you can consistently replicate a 100% to 1000% slowdown in string handling, please report it as a performance bug: http://bugs.python.org/ Don't forget to report your operating system. > My take of the subject. > > This is a typical Python desease. Do not solve a problem, but find a > way, a workaround, which is expecting to solve a problem and which > finally solves nothing. As far as I know, to break the "BMP limit", the > tools are here. They are called utf-8 or ucs-4/utf-32. The problem with UCS-4 is that every character requires four bytes. Every. Single. One. So under UCS-4, the pure-ascii string "hello world" takes 44 bytes plus the object overhead. Under UCS-2, it takes half that space: 22 bytes, but of course UCS-2 can only represent characters in the BMP. A pure ASCII string would only take 11 bytes, but we're not going back to pure ASCII. (There is an extension to UCS-2, UTF-16, which encodes non-BMP characters using two code points. This is fragile and doesn't work very well, because string-handling methods can break the surrogate pairs apart, leaving you with invalid unicode string. Not good.) The difference between 44 bytes and 22 bytes for one little string is not very important, but when you double the memory required for every single string it becomes huge. Remember that every class, function and method has a name, which is a string; every attribute and variable has a name, all strings; functions and classes have doc strings, all strings. Strings are used everywhere in Python, and doubling the memory needed by Python means that it will perform worse. With PEP 393, each Python string will be stored in the most efficient format possible: - if it only contains ASCII characters, it will be stored using 1 byte per character; - if it only contains characters in the BMP, it will be stored using UCS-2 (2 bytes per character); - if it contains non-BMP characters, the string will be stored using UCS-4 (4 bytes per character). -- Steven From roy at panix.com Sat Aug 18 09:08:11 2012 From: roy at panix.com (Roy Smith) Date: Sat, 18 Aug 2012 09:08:11 -0400 Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Message-ID: In article <385e732e-1c02-4dd0-ab12-b92890bbed66 at o3g2000yqp.googlegroups.com>, Frank Koshti wrote: > I'm new to regular expressions. I want to be able to match for tokens > with all their properties in the following examples. I would > appreciate some direction on how to proceed. > > >

@foo1

>

@foo2()

>

@foo3(anything could go here)

Don't try to parse HTML with regexes. Use a real HTML parser, such as lxml (http://lxml.de/). From maniandram01 at gmail.com Sat Aug 18 09:29:35 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 18 Aug 2012 18:59:35 +0530 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: Message-ID: I am aware of this. I'm just to lazy to use Google Groups! "Come on Ramchandra, you can switch to Google Groups." On 17 August 2012 13:09, rusi wrote: > On Aug 17, 3:36 am, Chris Angelico wrote: > > On Fri, Aug 17, 2012 at 1:40 AM, Ramchandra Apte > wrote: > > > On 16 August 2012 21:00, Mark Lawrence > wrote: > > >> and "bottom" reads better than "top" > > > > > Look you are the only person complaining about top-posting. > > > GMail uses top-posting by default. > > > I can't help it if you feel irritated by it. > > > > I post using gmail, > > If you register on the mailing list as well as google groups, you can > then use googlegroups. > Thereafter appropriately cutting out the unnecessary stuff is easy > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sat Aug 18 09:39:46 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 18 Aug 2012 19:09:46 +0530 Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: Please don't use all caps. On 17 August 2012 18:16, coldfire wrote: > I would like to know that where can a python script be stored on-line from > were it keep running and can be called any time when required using > internet. > I have used mechanize module which creates a webbroswer instance to open a > website and extract data and email me. > I have tried Python anywhere but they dont support opening of anonymous > websites. > What s the current what to DO this? > Can someone point me in the write direction. > My script have no interaction with User It just Got on-line searches for > something and emails me. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sat Aug 18 09:44:38 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 18 Aug 2012 19:14:38 +0530 Subject: pythonic interface to SAPI5? In-Reply-To: <502E6F02.30608@gmail.com> References: <502E6F02.30608@gmail.com> Message-ID: A simple workaround is to use: speak = subprocess.Popen("espeak",stdin = subprocess.PIPE) speak.stdin.write("Hello world!") time.sleep(1) speak.terminate() #end the speaking On 17 August 2012 21:49, Vojt?ch Pol??ek wrote: > Hi, > I am developing audiogame for visually impaired users and I want it to > be multiplatform. I know, that there is library called accessible_output > but it is not working when used in Windows for me. > I tried pyttsx, which should use Espeak on Linux and SAPI5 on Windows. > It works on Windows, on Linux I decided to use speech dispatcher bindings. > But it seems that I can't interrupt speech when using pyttsx and this is > showstopper for me. > Does anyone has any working solution for using SAPI5 on windows? > Thank you very much, > Vojta > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sat Aug 18 09:48:57 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 18 Aug 2012 19:18:57 +0530 Subject: remote read eval print loop In-Reply-To: References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> Message-ID: Not really. Try modifying ast.literal_eval. This will be quite secure. On 17 August 2012 19:36, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 11:28 PM, Eric Frederich > wrote: > > Within the debugging console, after importing all of the bindings, there > > would be no reason to import anything whatsoever. > > With just the bindings I created and the Python language we could do > > meaningful debugging. > > So if I block the ability to do any imports and calls to eval I should be > > safe right? > > Nope. Python isn't a secured language in that way. I tried the same > sort of thing a while back, but found it effectively impossible. (And > this after people told me "It's not possible, don't bother trying". I > tried anyway. It wasn't possible.) > > If you really want to do that, consider it equivalent to putting an > open SSH session into your debugging console. Would you give that much > power to your application's users? And if you would, is it worth > reinventing SSH? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Sat Aug 18 09:51:03 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 18 Aug 2012 19:21:03 +0530 Subject: [ANNC] pybotwar-0.8 In-Reply-To: <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> References: <502CBD87.8030704@sequans.com> <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: On 17 August 2012 18:23, Hans Mulder wrote: > On 16/08/12 23:34:25, Walter Hurry wrote: > > On Thu, 16 Aug 2012 17:20:29 -0400, Terry Reedy wrote: > > > >> On 8/16/2012 11:40 AM, Ramchandra Apte wrote: > >> > >>> Look you are the only person complaining about top-posting. > >> > >> No he is not. Recheck all the the responses. > >> > >>> GMail uses top-posting by default. > >> > >> It only works if everyone does it. > >> > >>> I can't help it if you feel irritated by it. > >> > >> Your out-of-context comments are harder to understand. I mostly do not > >> read them. > > > > It's strange, but I don't even *see* his contributions (I am using a > > regular newsreader - on comp.lang.python - and I don't have him in the > > bozo bin). It doesn't sound as though I'm missing much. > > I don't see him either. That is to say: my ISP doesn't have his > posts in comp.lang.python, The group gmane.comp.python.general > on Gname has them. so if you're really curious, you can point > your NNTP client at news.gmane.org. > > > But I'm just curious. Any idea why that would be the case? > > Maybe there's some kind of filer in the mail->usenet gateway? > > HTH, > > -- HansM > > > Let's not go overkill. I'll be using Google Groups (hopefully it won't top-post by default) to post stuff. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank.koshti at gmail.com Sat Aug 18 10:21:20 2012 From: frank.koshti at gmail.com (Frank Koshti) Date: Sat, 18 Aug 2012 07:21:20 -0700 (PDT) Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Message-ID: I think the point was missed. I don't want to use an XML parser. The point is to pick up those tokens, and yes I've done my share of RTFM. This is what I've come up with: '\$\w*\(?.*?\)' Which doesn't work well on the above example, which is partly why I reached out to the group. Can anyone help me with the regex? Thanks, Frank From steve+comp.lang.python at pearwood.info Sat Aug 18 10:22:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 14:22:29 GMT Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> Message-ID: <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Aug 2012 21:41:07 -0700, Frank Koshti wrote: > Hi, > > I'm new to regular expressions. I want to be able to match for tokens > with all their properties in the following examples. I would appreciate > some direction on how to proceed. Others have already given you excellent advice to NOT use regular expressions to parse HTML files, but to use a proper HTML parser instead. However, since I remember how hard it was to get started with regexes, I'm going to ignore that advice and show you how to abuse regexes to search for text, and pretend that they aren't HTML tags. Here's your string you want to search for: >

@foo1

You want to find a piece of text that starts with "

@", followed by any alphanumeric characters, followed by "

". We start by compiling a regex: import re pattern = r"

@\w+

" regex = re.compile(pattern, re.I) First we import the re module. Then we define a pattern string. Note that I use a "raw string" instead of a regular string -- this is not compulsory, but it is very common. The difference between a raw string and a regular string is how they handle backslashes. In Python, some (but not all!) backslashes are special. For example, the regular string "\n" is not two characters, backslash-n, but a single character, Newline. The Python string parser converts backslash combinations as special characters, e.g.: \n => newline \t => tab \0 => ASCII Null character \\ => a single backslash etc. We often call these "backslash escapes". Regular expressions use a lot of backslashes, and so it is useful to disable the interpretation of backlash escapes when writing regex patterns. We do that with a "raw string" -- if you prefix the string with the letter r, the string is raw and backslash-escapes are ignored: # ordinary "cooked" string: "abc\n" => a b c newline # raw string r"abc\n" => a b c backslash n Here is our pattern again: pattern = r"

@\w+

" which is thirteen characters: less-than h 1 greater-than at-sign backslash w plus-sign less-than slash h 1 greater-than Most of the characters shown just match themselves. For example, the @ sign will only match another @ sign. But some have special meaning to the regex: \w doesn't match "backslash w", but any alphanumeric character; + doesn't match a plus sign, but tells the regex to match the previous symbol one or more times. Since it immediately follows \w, this means "match at least one alphanumeric character". Now we feed that string into the re.compile, to create a pre-compiled regex. (This step is optional: any function which takes a compiled regex will also accept a string pattern. But pre-compiling regexes which you are going to use repeatedly is a good idea.) regex = re.compile(pattern, re.I) The second argument to re.compile is a flag, re.I which is a special value that tells the regular expression to ignore case, so "h" will match both "h" and "H". Now on to use the regex. Here's a bunch of text to search: text = """Now is the time for all good men blah blah blah

spam

and more text here blah blah blah and some more

@victory

blah blah blah""" And we search it this way: mo = re.search(regex, text) "mo" stands for "Match Object", which is returned if the regular expression finds something that matches your pattern. If nothing matches, then None is returned instead. if mo is not None: print(mo.group(0)) => prints

@victory

So far so good. But we can do better. In this case, we don't really care about the tags

, we only care about the "victory" part. Here's how to use grouping to extract substrings from the regex: pattern = r"

@(\w+)

" # notice the round brackets () regex = re.compile(pattern, re.I) mo = re.search(regex, text) if mo is not None: print(mo.group(0)) print(mo.group(1)) This prints:

@victory

victory Hope this helps. -- Steven From frank.koshti at gmail.com Sat Aug 18 10:53:32 2012 From: frank.koshti at gmail.com (Frank Koshti) Date: Sat, 18 Aug 2012 07:53:32 -0700 (PDT) Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Hey Steven, Thank you for the detailed (and well-written) tutorial on this very issue. I actually learned a few things! Though, I still have unresolved questions. The reason I don't want to use an XML parser is because the tokens are not always placed in HTML, and even in HTML, they may appear in strange places, such as

Hello

. My specific issue is I need to match, process and replace $foo(x=3), knowing that (x=3) is optional, and the token might appear simply as $foo. To do this, I decided to use: re.compile('\$\w*\(?.*?\)').findall(mystring) the issue with this is it doesn't match $foo by itself, and requires there to be () at the end. Thanks, Frank From wxjmfauth at gmail.com Sat Aug 18 11:07:05 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 08:07:05 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit?: > [...] > The problem with UCS-4 is that every character requires four bytes. > [...] I'm aware of this (and all the blah blah blah you are explaining). This always the same song. Memory. Let me ask. Is Python an 'american" product for us-users or is it a tool for everybody [*]? Is there any reason why non ascii users are somehow penalized compared to ascii users? This flexible string representation is a regression (ascii users or not). I recognize in practice the real impact is for many users closed to zero (including me) but I have shown (I think) that this flexible representation is, by design, not as optimal as it is supposed to be. This is in my mind the relevant point. [*] This not even true, if we consider the ?uro currency symbol used all around the world (banking, accounting applications). jmf From ian.g.kelly at gmail.com Sat Aug 18 11:18:39 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 18 Aug 2012 09:18:39 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <253ddd61-4bb5-4f46-b58c-525e55b27558@googlegroups.com> <502EAFB2.7050405@davea.name> <502f15b5$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: (Resending this to the list because I previously sent it only to Steven by mistake. Also showing off a case where top-posting is reasonable, since this bit requires no context. :-) On Sat, Aug 18, 2012 at 1:41 AM, Ian Kelly wrote: > > On Aug 17, 2012 10:17 PM, "Steven D'Aprano" > wrote: >> >> Unicode strings are not represented as Latin-1 internally. Latin-1 is a >> byte encoding, not a unicode internal format. Perhaps you mean to say >> that they are represented as a single byte format? > > They are represented as a single-byte format that happens to be equivalent > to Latin-1, because Latin-1 is a proper subset of Unicode; every character > representable in Latin-1 has a byte value equal to its Unicode codepoint. > This talk of whether it's a byte encoding or a 1-byte Unicode representation > is then just semantics. Even the PEP refers to the 1-byte representation as > Latin-1. > >> >> >> I understand the complaint >> >> to be that while the change is great for strings that happen to fit in >> >> Latin-1, it is less efficient than previous versions for strings that >> >> do not. >> > >> > That's not the way I interpreted the PEP 393. It takes a pure unicode >> > string, finds the largest code point in that string, and chooses 1, 2 or >> > 4 bytes for every character, based on how many bits it'd take for that >> > largest code point. >> >> That's how I interpret it too. > > I don't see how this is any different from what I described. Using all 4 > bytes of the code point, you get UCS-4. Truncating to 2 bytes, you get > UCS-2. Truncating to 1 byte, you get Latin-1. From no.email at please.post Sat Aug 18 11:19:59 2012 From: no.email at please.post (kj) Date: Sat, 18 Aug 2012 15:19:59 +0000 (UTC) Subject: How to get initial absolute working dir reliably? Message-ID: What's the most reliable way for "module code" to determine the absolute path of the working directory at the start of execution? (By "module code" I mean code that lives in a file that is not meant to be run as a script, but rather it is meant to be loaded as the result of some import statement. In other words, "module code" is code that must operate under the assumption that it can be loaded at any time after the start of execution.) Functions like os.path.abspath produce wrong results if the working directory is changed, e.g. through os.chdir, so it is not terribly reliable for determining the initial working directory. Basically, I'm looking for a read-only variable (or variables) initialized by Python at the start of execution, and from which the initial working directory may be read or computed. Thanks! From breamoreboy at yahoo.co.uk Sat Aug 18 11:25:47 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 16:25:47 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/08/2012 16:07, wxjmfauth at gmail.com wrote: > Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit : >> [...] >> The problem with UCS-4 is that every character requires four bytes. >> [...] > > I'm aware of this (and all the blah blah blah you are > explaining). This always the same song. Memory. > > Let me ask. Is Python an 'american" product for us-users > or is it a tool for everybody [*]? > Is there any reason why non ascii users are somehow penalized > compared to ascii users? > > This flexible string representation is a regression (ascii users > or not). > > I recognize in practice the real impact is for many users > closed to zero (including me) but I have shown (I think) that > this flexible representation is, by design, not as optimal > as it is supposed to be. This is in my mind the relevant point. > > [*] This not even true, if we consider the ?uro currency > symbol used all around the world (banking, accounting > applications). > > jmf > Sorry but you've got me completely baffled. Could you please explain in words of one syllable or less so I can attempt to grasp what the hell you're on about? -- Cheers. Mark Lawrence. From invalid at invalid.invalid Sat Aug 18 11:34:12 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 18 Aug 2012 15:34:12 +0000 (UTC) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: On 2012-08-17, rusi wrote: > I was in a corporate environment for a while. And carried my > 'trim&interleave' habits there. And got gently scolded for seeming to > hide things!! I have, rarely, gotten the opposite raction from "corporate e-mailers" used to top posting. I got one comment something like "That's cool how you interleaved your reponses -- it's like having a real conversation." -- Grant Edwards grant.b.edwards Yow! Somewhere in Tenafly, at New Jersey, a chiropractor gmail.com is viewing "Leave it to Beaver"! From rosuav at gmail.com Sat Aug 18 11:36:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 01:36:01 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 19, 2012 at 1:07 AM, wrote: > I'm aware of this (and all the blah blah blah you are > explaining). This always the same song. Memory. > > Let me ask. Is Python an 'american" product for us-users > or is it a tool for everybody [*]? > Is there any reason why non ascii users are somehow penalized > compared to ascii users? Regardless of your own native language, "len" is the name of a popular Python function. And "dict" is a well-used class. Both those names are representable in ASCII, even if every quoted string in your code requires more bytes to store. And memory usage has significance in many other areas, too. CPU cache utilization turns a space saving into a time saving. That's why structure packing still exists, even though member alignment has other advantages. You'd be amazed how many non-USA strings still fit inside seven bits, too. Are you appending a space to something? Splitting on newlines? You'll have lots of strings that are going now to be space-optimized. Of course, the performance gains from shortening some of the strings may be offset by costs when comparing one-byte and multi-byte strings, but presumably that's all been gone into in great detail elsewhere. ChrisA From __peter__ at web.de Sat Aug 18 11:48:42 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Aug 2012 17:48:42 +0200 Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Message-ID: Frank Koshti wrote: > I need to match, process and replace $foo(x=3), knowing that (x=3) is > optional, and the token might appear simply as $foo. > > To do this, I decided to use: > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > the issue with this is it doesn't match $foo by itself, and requires > there to be () at the end. >>> s = """ ...

$foo1

...

$foo2()

...

$foo3(anything could go here)

... """ >>> re.compile("(\$\w+(?:\(.*?\))?)").findall(s) ['$foo1', '$foo2()', '$foo3(anything could go here)'] From vlastimil.brom at gmail.com Sat Aug 18 11:50:17 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 18 Aug 2012 17:50:17 +0200 Subject: Regex Question In-Reply-To: <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Message-ID: 2012/8/18 Frank Koshti : > Hey Steven, > > Thank you for the detailed (and well-written) tutorial on this very > issue. I actually learned a few things! Though, I still have > unresolved questions. > > The reason I don't want to use an XML parser is because the tokens are > not always placed in HTML, and even in HTML, they may appear in > strange places, such as

Hello

. My specific issue is > I need to match, process and replace $foo(x=3), knowing that (x=3) is > optional, and the token might appear simply as $foo. > > To do this, I decided to use: > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > the issue with this is it doesn't match $foo by itself, and requires > there to be () at the end. > > Thanks, > Frank > -- > http://mail.python.org/mailman/listinfo/python-list Hi, Although I don't quite get the pattern you are using (with respect to the specified task), you most likely need raw string syntax for the pattern, e.g.: r"...", instead of "...", or you have to double all backslashes (which should be escaped), i.e. \\w etc. I am likely misunderstanding the specification, as the following: >>> re.sub(r"\$foo\(x=3\)", "bar", "

Hello

") '

Hello

' >>> is probably not the desired output. For some kind of "processing" the matched text, you can use the replace function instead of the replace pattern in re.sub too. see http://docs.python.org/library/re.html#re.sub hth, vbr From ian.g.kelly at gmail.com Sat Aug 18 11:51:37 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 18 Aug 2012 09:51:37 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 18, 2012 at 9:07 AM, wrote: > Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit : >> [...] >> The problem with UCS-4 is that every character requires four bytes. >> [...] > > I'm aware of this (and all the blah blah blah you are > explaining). This always the same song. Memory. > > Let me ask. Is Python an 'american" product for us-users > or is it a tool for everybody [*]? > Is there any reason why non ascii users are somehow penalized > compared to ascii users? The change does not just benefit ASCII users. It primarily benefits anybody using a wide unicode build with strings mostly containing only BMP characters. Even for narrow build users, there is the benefit that with approximately the same amount of memory usage in most cases, they no longer have to worry about non-BMP characters sneaking in and breaking their code. There is some additional benefit for Latin-1 users, but this has nothing to do with Python. If Python is going to have the option of a 1-byte representation (and as long as we have the flexible representation, I can see no reason not to), then it is going to be Latin-1 by definition, because that's what 1-byte Unicode (UCS-1, if you will) is. If you have an issue with that, take it up with the designers of Unicode. > > This flexible string representation is a regression (ascii users > or not). > > I recognize in practice the real impact is for many users > closed to zero (including me) but I have shown (I think) that > this flexible representation is, by design, not as optimal > as it is supposed to be. This is in my mind the relevant point. You've shown nothing of the sort. You've demonstrated only one out of many possible benchmarks, and other users on this list can't even reproduce that. From frank.koshti at gmail.com Sat Aug 18 11:56:26 2012 From: frank.koshti at gmail.com (Frank Koshti) Date: Sat, 18 Aug 2012 08:56:26 -0700 (PDT) Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Message-ID: On Aug 18, 11:48?am, Peter Otten <__pete... at web.de> wrote: > Frank Koshti wrote: > > I need to match, process and replace $foo(x=3), knowing that (x=3) is > > optional, and the token might appear simply as $foo. > > > To do this, I decided to use: > > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > > the issue with this is it doesn't match $foo by itself, and requires > > there to be () at the end. > >>> s = """ > > ...

$foo1

> ...

$foo2()

> ...

$foo3(anything could go here)

> ... """>>> re.compile("(\$\w+(?:\(.*?\))?)").findall(s) > > ['$foo1', '$foo2()', '$foo3(anything could go here)'] PERFECT- From 0emcveefft8qzaq4oy6impe8fdtezbga at user.narkive.com Sat Aug 18 12:00:00 2012 From: 0emcveefft8qzaq4oy6impe8fdtezbga at user.narkive.com (numnumnum) Date: Sat, 18 Aug 2012 16:00:00 +0000 Subject: =?UTF-8?Q?Welcome=20to:=20=3D=3D=20(((?==?UTF-8?Q?=20http?= =?UTF-8?Q?://blueshoptrade.com/?==?UTF-8?Q?=20)))=20=3D=3D=3D=3D=20?= =?UTF-8?Q?=20Air=20jord0n(1-24)shoe?==?UTF-8?Q?s=20$33=20=20=20?= =?UTF-8?Q?=20Hand=20bags(C0ach=20l=20v=20?==?UTF-8?Q?f=20e=20n=20?= =?UTF-8?Q?d=20i=20d&g)=20$35=20=20=20=20Tshir?==?UTF-8?Q?ts=20(e?= =?UTF-8?Q?d=20hardy,lacoste)=20$16=20?==?UTF-8?Q?=20=20=20Jean(?= =?UTF-8?Q?True=20Religion, ed=20hard?==?UTF-8?Q?y, coogi)?==?UTF-8?Q?=20$?= =?UTF-8?Q?30=20=20=20=20Sun=20glasses(Oak?==?UTF-8?Q?ey,C0a?= =?UTF-8?Q?ch,gucci,A=20r=20m=20a=20i=20n=20?==?UTF-8?Q?i)=20$16?= =?UTF-8?Q?=20=20=20=20New=20era=20cap=20$15=20=20?==?UTF-8?Q?=20=20Bi?= =?UTF-8?Q?kini=20(Ed=20hardy)=20$25=20=20?==?UTF-8?Q?=20=20Jewe?= =?UTF-8?Q?l=20ry=20(Tiffany, Pondora?==?UTF-8?Q?, Chanel.?==?UTF-8?Q?..?= =?UTF-8?Q?)$20=20=20=20=20FREE=20sHIPPING?==?UTF-8?Q?,ACCEP?= =?UTF-8?Q?T=20PYAPAL=20PAYMENT=20AND=20?==?UTF-8?Q?CREDIT=20?= =?UTF-8?Q?CARDS=20DELIVERY=20TO=20YOU?==?UTF-8?Q?=20DOOR=20TO?= =?UTF-8?Q?=20DOOR.=20=20=20=20=3D=3D=20(((=20http?==?UTF-8?Q?://w?= =?UTF-8?Q?ww.blueshoptrade.com/?==?UTF-8?Q?=20)))=20=3D=3D=3D=3D=20?= =?UTF-8?Q?=20=20=20=3D=3D=20(((=20http://www.?==?UTF-8?Q?blues?= =?UTF-8?Q?hoptrade.com/=20)))=20=3D=3D=3D?==?UTF-8?Q?=3D=20=20=20=20=3D?= =?UTF-8?Q?=3D=20(((=20http://www.blue?==?UTF-8?Q?shoptrad?= =?UTF-8?Q?e.com/=20)))=20=3D=3D=3D=3D=20=20=20=20=3D=3D?==?UTF-8?Q?=20(?= =?UTF-8?Q?((=20http://www.bluesho?==?UTF-8?Q?ptrade.co?==?UTF-8?Q?m/?= =?UTF-8?Q?=20)))=20=3D=3D=3D=3D=20=20=20=20=3D=3D=20(((=20h?= =?UTF-8?Q?ttp://www.blueshoptra?==?UTF-8?Q?de.com/=20))?==?UTF-8?Q?)=20?= =?UTF-8?Q?=3D=3D=3D=3D=20=20=20=20=3D=3D=20(((=20http:/?==?UTF-8?Q?/w?= =?UTF-8?Q?ww.blueshoptrade.com/?==?UTF-8?Q?=20)))=20=3D=3D=3D=3D=20?= =?UTF-8?Q?=20=20=20=3D=3D=20(((=20http://www.?==?UTF-8?Q?blues?= =?UTF-8?Q?hoptrade.com/=20)))=20=3D=3D=3D?==?UTF-8?Q?=3D=20=20=20=20=3D?= =?UTF-8?Q?=3D=20(((=20http://www.blue?==?UTF-8?Q?shoptrad?= =?UTF-8?Q?e.com/=20)))=20=3D=3D=3D=3D?= Message-ID: Welcome to: == ((( http://blueshoptrade.com/ ))) ==== Air jord0n(1-24)shoes $33 Hand bags(C0ach l v f e n d i d&g) $35 Tshirts (ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sun glasses(Oakey,C0ach,gucci,A r m a i n i) $16 New era cap $15 Bikini (Ed hardy) $25 Jewel ry (Tiffany,Pondora,Chanel...)$20 FREE sHIPPING,ACCEPT PYAPAL PAYMENT AND CREDIT CARDS DELIVERY TO YOU DOOR TO DOOR. == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== -- View on Narkive: http://narkive.com/gtBCr0SN From r9lqmap94flle7xjbnk3fj8vc7wtvlkk at user.narkive.com Sat Aug 18 12:00:26 2012 From: r9lqmap94flle7xjbnk3fj8vc7wtvlkk at user.narkive.com (numnumnum) Date: Sat, 18 Aug 2012 16:00:26 +0000 Subject: =?UTF-8?Q?Re:=20Welcome=20to:=20=3D=3D?==?UTF-8?Q?=20(((=20?= =?UTF-8?Q?http://blueshoptrade.?==?UTF-8?Q?com/=20)))=20=3D?= =?UTF-8?Q?=3D=3D=3D=20=20Air=20jord0n(1-24)?==?UTF-8?Q?shoes=20?= =?UTF-8?Q?$33=20=20=20=20Hand=20bags(C0ac?==?UTF-8?Q?h=20l=20v=20?= =?UTF-8?Q?f=20e=20n=20d=20i=20d& g)=20$3?==?UTF-8?Q?5=20=20=20=20T?= =?UTF-8?Q?shirts=20(ed=20hardy,laco?==?UTF-8?Q?ste)=20$16?= =?UTF-8?Q?=20=20=20=20Jean(True=20Religio?==?UTF-8?Q?n,ed=20h?= =?UTF-8?Q?ardy,coogi)=20$30=20=20=20=20Su?==?UTF-8?Q?n=20glas?= =?UTF-8?Q?ses(Oakey,C0ach,gucci?==?UTF-8?Q?,A=20r=20m=20a=20i?= =?UTF-8?Q?=20n=20i)=20$16=20=20=20=20New=20era=20?==?UTF-8?Q?cap=20?= =?UTF-8?Q?$15=20=20=20=20Bikini=20(Ed=20har?==?UTF-8?Q?dy)=20$2?= =?UTF-8?Q?5=20=20=20=20Jewel=20ry=20(Tiffan?==?UTF-8?Q?y,Pond?= =?UTF-8?Q?ora,Chanel...)$20=20=20=20=20?==?UTF-8?Q?FREE=20sH?= =?UTF-8?Q?IPPING,ACCEPT=20PYAPAL=20?==?UTF-8?Q?PAYMENT=20?= =?UTF-8?Q?AND=20CREDIT=20CARDS=20DELI?==?UTF-8?Q?VERY=20TO=20?= =?UTF-8?Q?YOU=20DOOR=20TO=20DOOR.=20=20=20=20?==?UTF-8?Q?=3D=3D=20((?= =?UTF-8?Q?(=20http://www.blueshop?==?UTF-8?Q?trade.com?==?UTF-8?Q?/=20?= =?UTF-8?Q?)))=20=3D=3D=3D=3D=20=20=20=20=3D=3D=20(((=20ht?= =?UTF-8?Q?tp://www.blueshoptrad?==?UTF-8?Q?e.com/=20)))?==?UTF-8?Q?=20=3D?= =?UTF-8?Q?=3D=3D=3D=20=20=20=20=3D=3D=20(((=20http://?==?UTF-8?Q?ww?= =?UTF-8?Q?w.blueshoptrade.com/=20?==?UTF-8?Q?)))=20=3D=3D=3D=3D=20?= =?UTF-8?Q?=20=20=20=3D=3D=20(((=20http://www.?==?UTF-8?Q?blues?= =?UTF-8?Q?hoptrade.com/=20)))=20=3D=3D=3D?==?UTF-8?Q?=3D=20=20=20=20=3D?= =?UTF-8?Q?=3D=20(((=20http://www.blue?==?UTF-8?Q?shoptrad?= =?UTF-8?Q?e.com/=20)))=20=3D=3D=3D=3D=20=20=20=20=3D=3D?==?UTF-8?Q?=20(?= =?UTF-8?Q?((=20http://www.bluesho?==?UTF-8?Q?ptrade.co?==?UTF-8?Q?m/?= =?UTF-8?Q?=20)))=20=3D=3D=3D=3D=20=20=20=20=3D=3D=20(((=20h?= =?UTF-8?Q?ttp://www.blueshoptra?==?UTF-8?Q?de.com/=20))?==?UTF-8?Q?)=20?= =?UTF-8?Q?=3D=3D=3D=3D=20=20=20=20=3D=3D=20(((=20http:/?==?UTF-8?Q?/w?= =?UTF-8?Q?ww.blueshoptrade.com/?==?UTF-8?Q?=20)))=20=3D=3D=3D=3D?= References: Message-ID: Welcome to: == ((( http://blueshoptrade.com/ ))) ==== Air jord0n(1-24)shoes $33 Hand bags(C0ach l v f e n d i d&g) $35 Tshirts (ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sun glasses(Oakey,C0ach,gucci,A r m a i n i) $16 New era cap $15 Bikini (Ed hardy) $25 Jewel ry (Tiffany,Pondora,Chanel...)$20 FREE sHIPPING,ACCEPT PYAPAL PAYMENT AND CREDIT CARDS DELIVERY TO YOU DOOR TO DOOR. == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== == ((( http://www.blueshoptrade.com/ ))) ==== -- View on Narkive: http://narkive.com/gtBCr0SN From jpiitula at ling.helsinki.fi Sat Aug 18 12:22:37 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Aug 2012 19:22:37 +0300 Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Message-ID: Frank Koshti writes: > not always placed in HTML, and even in HTML, they may appear in > strange places, such as

Hello

. My specific issue > is I need to match, process and replace $foo(x=3), knowing that > (x=3) is optional, and the token might appear simply as $foo. > > To do this, I decided to use: > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > the issue with this is it doesn't match $foo by itself, and requires > there to be () at the end. Adding a ? after the meant-to-be-optional expression would let the regex engine know what you want. You can also separate the mandatory and the optional part in the regex to receive pairs as matches. The test program below prints this: >$foo()$foo(bar=3)$$$foo($)$foo($bar(v=0))etc$foo()$foo(bar=3)$$$foo($)$foo($bar(v=0))etc References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1345307805.6585.140661116501385.66B8AFD3@webmail.messagingengine.com> Steven, Well done!!! Regards, Malcolm From wxjmfauth at gmail.com Sat Aug 18 12:38:09 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 09:38:09 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Sorry guys, I'm not stupid (I think). I can open IDLE with Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is always slower. Period. Now, the reason. I think it is due the "flexible represention". Deeper reason. The "boss" do not wish to hear from a (pure) ucs-4/utf-32 "engine" (this has been discussed I do not know how many times). jmf From wxjmfauth at gmail.com Sat Aug 18 12:38:09 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 09:38:09 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Sorry guys, I'm not stupid (I think). I can open IDLE with Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is always slower. Period. Now, the reason. I think it is due the "flexible represention". Deeper reason. The "boss" do not wish to hear from a (pure) ucs-4/utf-32 "engine" (this has been discussed I do not know how many times). jmf From rosuav at gmail.com Sat Aug 18 12:57:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 02:57:33 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: On Sun, Aug 19, 2012 at 2:38 AM, wrote: > Sorry guys, I'm not stupid (I think). I can open IDLE with > Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is > always slower. Period. Ah, but what about all those other operations that use strings under the covers? As mentioned, namespace lookups do, among other things. And how is performance in the (very real) case where a C routine wants to return a value to Python as a string, where the data is currently guaranteed to be ASCII (previously using PyUnicode_FromString, now able to use PyUnicode_FromKindAndData)? Again, I'm sure this has been gone into in great detail before the PEP was accepted (am I negative-bikeshedding here? "atomic reactoring"???), and I'm sure that the gains outweigh the costs. ChrisA From rustompmody at gmail.com Sat Aug 18 13:27:10 2012 From: rustompmody at gmail.com (rusi) Date: Sat, 18 Aug 2012 10:27:10 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: On Aug 18, 8:34?pm, Grant Edwards wrote: > On 2012-08-17, rusi wrote: > > > I was in a corporate environment for a while. ?And carried my > > 'trim&interleave' habits there. And got gently scolded for seeming to > > hide things!! > > I have, rarely, gotten the opposite raction from "corporate e-mailers" > used to top posting. ?I got one comment something like "That's cool > how you interleaved your reponses -- it's like having a real > conversation." Well sure. If I could civilize people around me, God (or Darwin?) would give me a medal. Usually though, I find it expedient to remember G.B. Shaw's: "The reasonable man adapts himself to the world: the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man." and then decide exactly how (un)reasonable to be in a given context. [No claims to always succeed in these calibrations :-) ] And which brings me back to the question of how best to tell new folk about the netiquette around here. I was once teaching C to a batch of first year students. I was younger then and being more passionate and less reasonable, I made a rule that students should indent their programs correctly. [Nothing like python in sight those days!] A few days later there was a commotion. Students appeared in class with black-badges, complained to the head-of-department and what not. Very perplexed I said: "Why?! I allowed you to indent in any which way you like as long as you have some rules and follow them." I imagined that I had been perfectly reasonable and lenient! Only later did I realize that students did not understand - how to indent - why to indent - what program structure meant So when people top-post it seems reasonable to assume that they dont know better before jumping to conclusions of carelessness, rudeness, inattention etc. For example, my sister recently saw some of my mails and was mystified that I had sent back 'blank mails' until I explained and pointed out that my answers were interleaved into what was originally sent! Clearly she had only ever seen (and therefore expected) top-posted mail-threads. Like your 'corporate-emailer' she found it damn neat, after the initiation. Whether such simple unfamiliarity with culture is the case in the particular case (this thread's discussion) I am not sure. Good to remember Hanlon's razor... From breamoreboy at yahoo.co.uk Sat Aug 18 13:28:26 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 18:28:26 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: On 18/08/2012 17:38, wxjmfauth at gmail.com wrote: > Sorry guys, I'm not stupid (I think). I can open IDLE with > Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is > always slower. Period. Proof that is acceptable to everybody please, not just yourself. > > Now, the reason. I think it is due the "flexible represention". > > Deeper reason. The "boss" do not wish to hear from a (pure) > ucs-4/utf-32 "engine" (this has been discussed I do not know > how many times). > > jmf > -- Cheers. Mark Lawrence. From tjreedy at udel.edu Sat Aug 18 13:32:36 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Aug 2012 13:32:36 -0400 Subject: Crashes always on Windows 7 In-Reply-To: <6913f9be-88cc-431d-84cd-bd1c8c191152@googlegroups.com> References: <4c344999-81c3-4c46-a6a8-eb5dc2fcc988@googlegroups.com> <6913f9be-88cc-431d-84cd-bd1c8c191152@googlegroups.com> Message-ID: On 8/18/2012 2:18 AM, zmagic11 at gmail.com wrote: > Open using File>Open on the Shell The important question, as I said in my previous post, is *exactly* what you do in the OpenFile dialog. Some things work, others do not. And we (Python) have no control. -- Terry Jan Reedy From stefan_ml at behnel.de Sat Aug 18 13:56:42 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 18 Aug 2012 19:56:42 +0200 Subject: python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' In-Reply-To: References: Message-ID: Dmitry Arsentiev, 15.08.2012 14:49: > Has anybody already meet the problem like this? - > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > When I run scrapy, I get > > File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", > line 14, in > libxml2.HTML_PARSE_NOERROR + \ > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > > When I run > python -c 'import libxml2; libxml2.HTML_PARSE_RECOVER' > > I get > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' > > How can I cure it? > > Python 2.7 > libxml2-python 2.6.9 > 2.6.11-gentoo-r6 That version of libxml2 is way too old and doesn't support parsing real-world HTML. IIRC, that started with 2.6.21 and got improved a bit after that. Get a 2.8.0 installation, as someone pointed out already. Stefan From steve+comp.lang.python at pearwood.info Sat Aug 18 13:59:18 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Aug 2012 17:59:18 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: > Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit?: >> [...] >> The problem with UCS-4 is that every character requires four bytes. >> [...] > > I'm aware of this (and all the blah blah blah you are explaining). This > always the same song. Memory. Exactly. The reason it is always the same song is because it is an important song. > Let me ask. Is Python an 'american" product for us-users or is it a tool > for everybody [*]? It is a product for everyone, which is exactly why PEP 393 is so important. PEP 393 means that users who have only a few non-BMP characters don't have to pay the cost of UCS-4 for every single string in their application, only for the ones that actually require it. PEP 393 means that using Unicode strings is now cheaper for everybody. You seem to be arguing that the way forward is not to make Unicode cheaper for everyone, but to make ASCII strings more expensive so that everyone suffers equally. I reject that idea. > Is there any reason why non ascii users are somehow penalized compared > to ascii users? Of course there is a reason. If you want to represent 1114111 different characters in a string, as Unicode supports, you can't use a single byte per character, or even two bytes. That is a fact of basic mathematics. Supporting 1114111 characters must be more expensive than supporting 128 of them. But why should you carry the cost of 4-bytes per character just because someday you *might* need a non-BMP character? > This flexible string representation is a regression (ascii users or > not). No it is not. It is a great step forward to more efficient Unicode. And it means that now Python can correctly deal with non-BMP characters without the nonsense of UTF-16 surrogates: steve at runes:~$ python3.3 -c "print(len(chr(1114000)))" # Right! 1 steve at runes:~$ python3.2 -c "print(len(chr(1114000)))" # Wrong! 2 without doubling the storage of every string. This is an important step towards making the full range of Unicode available more widely. > I recognize in practice the real impact is for many users closed to zero Then what's the problem? > (including me) but I have shown (I think) that this flexible > representation is, by design, not as optimal as it is supposed to be. You have not shown any real problem at all. You have shown untrustworthy, edited timing results that don't match what other people are reporting. Even if your timing results are genuine, you haven't shown that they make any difference for real code that does useful work. -- Steven From krecoun at gmail.com Sat Aug 18 14:03:11 2012 From: krecoun at gmail.com (=?UTF-8?B?Vm9qdMSbY2ggUG9sw6HFoWVr?=) Date: Sat, 18 Aug 2012 20:03:11 +0200 Subject: pythonic interface to SAPI5? In-Reply-To: References: <502E6F02.30608@gmail.com> Message-ID: <502FD8DF.7040702@gmail.com> Thank you very much, I have found a DLL which is designed exactly for us and I use it through ctypes. Vojta On 18.8.2012 15:44, Ramchandra Apte wrote: > A simple workaround is to use: > speak = subprocess.Popen("espeak",stdin = subprocess.PIPE) > speak.stdin.write("Hello world!") > time.sleep(1) > speak.terminate() #end the speaking > > > > On 17 August 2012 21:49, Vojt?ch Pol??ek > wrote: > > Hi, > I am developing audiogame for visually impaired users and I want it to > be multiplatform. I know, that there is library called > accessible_output > but it is not working when used in Windows for me. > I tried pyttsx, which should use Espeak on Linux and SAPI5 on Windows. > It works on Windows, on Linux I decided to use speech dispatcher > bindings. > But it seems that I can't interrupt speech when using pyttsx and > this is > showstopper for me. > Does anyone has any working solution for using SAPI5 on windows? > Thank you very much, > Vojta > -- > http://mail.python.org/mailman/listinfo/python-list > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Sat Aug 18 14:05:07 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 11:05:07 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: Le samedi 18 ao?t 2012 19:28:26 UTC+2, Mark Lawrence a ?crit?: > > Proof that is acceptable to everybody please, not just yourself. > > I cann't, I'm only facing the fact it works slower on my Windows platform. As I understand (I think) the undelying mechanism, I can only say, it is not a surprise that it happens. Imagine an editor, I type an "a", internally the text is saved as ascii, then I type en "?", the text can only be saved in at least latin-1. Then I enter an "?", the text become an internal ucs-4 "string". The remove the "?" and so on. Intuitively I expect there is some kind slow down between all these "strings" conversion. When I tested this flexible representation, a few months ago, at the first alpha release. This is precisely what, I tested. String manipulations which are forcing this internal change and I concluded the result is not brillant. Realy, a factor 0.n up to 10. This are simply my conclusions. Related question. Does any body know a way to get the size of the internal "string" in bytes? In the narrow or wide build it is easy, I can encode with the "unicode_internal" codec. In Py 3.3, I attempted to toy with sizeof and stuct, but without success. jmf From wxjmfauth at gmail.com Sat Aug 18 14:05:07 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 11:05:07 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: Le samedi 18 ao?t 2012 19:28:26 UTC+2, Mark Lawrence a ?crit?: > > Proof that is acceptable to everybody please, not just yourself. > > I cann't, I'm only facing the fact it works slower on my Windows platform. As I understand (I think) the undelying mechanism, I can only say, it is not a surprise that it happens. Imagine an editor, I type an "a", internally the text is saved as ascii, then I type en "?", the text can only be saved in at least latin-1. Then I enter an "?", the text become an internal ucs-4 "string". The remove the "?" and so on. Intuitively I expect there is some kind slow down between all these "strings" conversion. When I tested this flexible representation, a few months ago, at the first alpha release. This is precisely what, I tested. String manipulations which are forcing this internal change and I concluded the result is not brillant. Realy, a factor 0.n up to 10. This are simply my conclusions. Related question. Does any body know a way to get the size of the internal "string" in bytes? In the narrow or wide build it is easy, I can encode with the "unicode_internal" codec. In Py 3.3, I attempted to toy with sizeof and stuct, but without success. jmf From no.email at nospam.invalid Sat Aug 18 14:26:21 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Aug 2012 11:26:21 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xehn4vyya.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > (There is an extension to UCS-2, UTF-16, which encodes non-BMP characters > using two code points. This is fragile and doesn't work very well, > because string-handling methods can break the surrogate pairs apart, > leaving you with invalid unicode string. Not good.) ... > With PEP 393, each Python string will be stored in the most efficient > format possible: Can you explain the issue of "breaking surrogate pairs apart" a little more? Switching between encodings based on the string contents seems silly at first glance. Strings are immutable so I don't understand why not use UTF-8 or UTF-16 for everything. UTF-8 is more efficient in Latin-based alphabets and UTF-16 may be more efficient for some other languages. I think even UCS-4 doesn't completely fix the surrogate pair issue if it means the only thing I can think of. From wxjmfauth at gmail.com Sat Aug 18 14:30:19 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 18 Aug 2012 11:30:19 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le samedi 18 ao?t 2012 19:59:18 UTC+2, Steven D'Aprano a ?crit?: > On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: > > > > > Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit?: > > >> [...] > > >> The problem with UCS-4 is that every character requires four bytes. > > >> [...] > > > > > > I'm aware of this (and all the blah blah blah you are explaining). This > > > always the same song. Memory. > > > > Exactly. The reason it is always the same song is because it is an > > important song. > > No offense here. But this is an *american* answer. The same story as the coding of text files, where "utf-8 == ascii" and the rest of the world doesn't count. jmf From python at mrabarnett.plus.com Sat Aug 18 14:34:50 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 18 Aug 2012 19:34:50 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: <502FE04A.2020906@mrabarnett.plus.com> On 18/08/2012 19:05, wxjmfauth at gmail.com wrote: > Le samedi 18 ao?t 2012 19:28:26 UTC+2, Mark Lawrence a ?crit : >> >> Proof that is acceptable to everybody please, not just yourself. >> >> > I cann't, I'm only facing the fact it works slower on my > Windows platform. > > As I understand (I think) the undelying mechanism, I > can only say, it is not a surprise that it happens. > > Imagine an editor, I type an "a", internally the text is > saved as ascii, then I type en "?", the text can only > be saved in at least latin-1. Then I enter an "?", the text > become an internal ucs-4 "string". The remove the "?" and so > on. > [snip] "a" will be stored as 1 byte/codepoint. Adding "?", it will still be stored as 1 byte/codepoint. Adding "?", it will still be stored as 2 bytes/codepoint. But then you wouldn't be adding them one at a time in Python, you'd be building a list and then joining them together in one operation. From rustompmody at gmail.com Sat Aug 18 14:40:23 2012 From: rustompmody at gmail.com (rusi) Date: Sat, 18 Aug 2012 11:40:23 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 18, 10:59?pm, Steven D'Aprano wrote: > On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: > > Is there any reason why non ascii users are somehow penalized compared > > to ascii users? > > Of course there is a reason. > > If you want to represent 1114111 different characters in a string, as > Unicode supports, you can't use a single byte per character, or even two > bytes. That is a fact of basic mathematics. Supporting 1114111 characters > must be more expensive than supporting 128 of them. > > But why should you carry the cost of 4-bytes per character just because > someday you *might* need a non-BMP character? I am reminded of: http://answers.microsoft.com/thread/720108ee-0a9c-4090-b62d-bbd5cb1a7605 Original above does not open for me but here's a copy that does: http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html From python at mrabarnett.plus.com Sat Aug 18 14:59:32 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 18 Aug 2012 19:59:32 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xehn4vyya.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> Message-ID: <502FE614.8050106@mrabarnett.plus.com> On 18/08/2012 19:26, Paul Rubin wrote: > Steven D'Aprano writes: >> (There is an extension to UCS-2, UTF-16, which encodes non-BMP characters >> using two code points. This is fragile and doesn't work very well, >> because string-handling methods can break the surrogate pairs apart, >> leaving you with invalid unicode string. Not good.) > ... >> With PEP 393, each Python string will be stored in the most efficient >> format possible: > > Can you explain the issue of "breaking surrogate pairs apart" a little > more? Switching between encodings based on the string contents seems > silly at first glance. Strings are immutable so I don't understand why > not use UTF-8 or UTF-16 for everything. UTF-8 is more efficient in > Latin-based alphabets and UTF-16 may be more efficient for some other > languages. I think even UCS-4 doesn't completely fix the surrogate pair > issue if it means the only thing I can think of. > On a narrow build, codepoints outside the BMP are stored as a surrogate pair (2 codepoints). On a wide build, all codepoints can be represented without the need for surrogate pairs. The problem with strings containing surrogate pairs is that you could inadvertently slice the string in the middle of the surrogate pair. From breamoreboy at yahoo.co.uk Sat Aug 18 15:45:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 20:45:53 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/08/2012 19:30, wxjmfauth at gmail.com wrote: > Le samedi 18 ao?t 2012 19:59:18 UTC+2, Steven D'Aprano a ?crit : >> On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: >> >> >> >>> Le samedi 18 ao?t 2012 14:27:23 UTC+2, Steven D'Aprano a ?crit : >> >>>> [...] >> >>>> The problem with UCS-4 is that every character requires four bytes. >> >>>> [...] >> >>> >> >>> I'm aware of this (and all the blah blah blah you are explaining). This >> >>> always the same song. Memory. >> >> >> >> Exactly. The reason it is always the same song is because it is an >> >> important song. >> >> > No offense here. But this is an *american* answer. > > The same story as the coding of text files, where "utf-8 == ascii" > and the rest of the world doesn't count. > > jmf > Thinking about it I entirely agree with you. Steven D'Aprano strikes me as typically American, in the same way that I'm typically Brazilian :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Aug 18 15:50:58 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 20:50:58 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/08/2012 19:40, rusi wrote: > On Aug 18, 10:59 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: >>> Is there any reason why non ascii users are somehow penalized compared >>> to ascii users? >> >> Of course there is a reason. >> >> If you want to represent 1114111 different characters in a string, as >> Unicode supports, you can't use a single byte per character, or even two >> bytes. That is a fact of basic mathematics. Supporting 1114111 characters >> must be more expensive than supporting 128 of them. >> >> But why should you carry the cost of 4-bytes per character just because >> someday you *might* need a non-BMP character? > > I am reminded of: http://answers.microsoft.com/thread/720108ee-0a9c-4090-b62d-bbd5cb1a7605 > > Original above does not open for me but here's a copy that does: > > http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html > ROFLMAO doesn't adequately some up how much I laughed. -- Cheers. Mark Lawrence. From tjreedy at udel.edu Sat Aug 18 16:09:14 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Aug 2012 16:09:14 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: On 8/18/2012 12:38 PM, wxjmfauth at gmail.com wrote: > Sorry guys, I'm not stupid (I think). I can open IDLE with > Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is > always slower. Period. You have not tried enough tests ;-). On my Win7-64 system: from timeit import timeit print(timeit(" 'a'*10000 ")) 3.3.0b2: .5 3.2.3: .8 print(timeit("c in a", "c = '?'; a = 'a'*10000")) 3.3: .05 (independent of len(a)!) 3.2: 5.8 100 times slower! Increase len(a) and the ratio can be made as high as one wants! print(timeit("a.encode()", "a = 'a'*1000")) 3.2: 1.5 3.3: .26 Similar with encoding='utf-8' added to call. Jim, please stop the ranting. It does not help improve Python. utf-32 is not a panacea; it has problems of time, space, and system compatibility (Windows and others). Victor Stinner, whatever he may have once thought and said, put a *lot* of effort into making the new implementation both correct and fast. On your replace example >>> imeit.timeit("('ab?' * 1000).replace('?', '??')") > 61.919225272152346 >>> timeit.timeit("('ab?' * 10).replace('?', '??')") > 1.2918679017971044 I do not see the point of changing both length and replacement. For me, the time is about the same for either replacement. I do see about the same slowdown ratio for 3.3 versus 3.2 I also see it for pure search without replacement. print(timeit("c in a", "c = '?'; a = 'a'*1000+c")) # .6 in 3.2.3, 1.2 in 3.3.0 This does not make sense to me and I will ask about it. -- Terry Jan Reedy From frank.koshti at gmail.com Sat Aug 18 16:18:52 2012 From: frank.koshti at gmail.com (Frank Koshti) Date: Sat, 18 Aug 2012 13:18:52 -0700 (PDT) Subject: Regex Question References: <385e732e-1c02-4dd0-ab12-b92890bbed66@o3g2000yqp.googlegroups.com> <502fa524$0$29978$c3e8da3$5496439d@news.astraweb.com> <79aaa167-296a-4a0c-8a06-c4e67cf53597@j19g2000yqi.googlegroups.com> Message-ID: On Aug 18, 12:22?pm, Jussi Piitulainen wrote: > Frank Koshti writes: > > not always placed in HTML, and even in HTML, they may appear in > > strange places, such as

Hello

. My specific issue > > is I need to match, process and replace $foo(x=3), knowing that > > (x=3) is optional, and the token might appear simply as $foo. > > > To do this, I decided to use: > > > re.compile('\$\w*\(?.*?\)').findall(mystring) > > > the issue with this is it doesn't match $foo by itself, and requires > > there to be () at the end. > > Adding a ? after the meant-to-be-optional expression would let the > regex engine know what you want. You can also separate the mandatory > and the optional part in the regex to receive pairs as matches. The > test program below prints this: > > >$foo()$foo(bar=3)$$$foo($)$foo($bar(v=0))etc > ('$foo', '') > ('$foo', '(bar=3)') > ('$foo', '($)') > ('$foo', '') > ('$bar', '(v=0)') > > Here is the program: > > import re > > def grab(text): > ? ? p = re.compile(r'([$]\w+)([(][^()]+[)])?') > ? ? return re.findall(p, text) > > def test(html): > ? ? print(html) > ? ? for hit in grab(html): > ? ? ? ? print(hit) > > if __name__ == '__main__': > ? ? test('>$foo()$foo(bar=3)$$$foo($)$foo($bar(v=0))etc References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e235732-39e4-4877-a860-466e433cde5e@googlegroups.com> Le samedi 18 ao?t 2012 20:40:23 UTC+2, rusi a ?crit?: > On Aug 18, 10:59?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > > > On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: > > > > Is there any reason why non ascii users are somehow penalized compared > > > > to ascii users? > > > > > > Of course there is a reason. > > > > > > If you want to represent 1114111 different characters in a string, as > > > Unicode supports, you can't use a single byte per character, or even two > > > bytes. That is a fact of basic mathematics. Supporting 1114111 characters > > > must be more expensive than supporting 128 of them. > > > > > > But why should you carry the cost of 4-bytes per character just because > > > someday you *might* need a non-BMP character? > > > > I am reminded of: http://answers.microsoft.com/thread/720108ee-0a9c-4090-b62d-bbd5cb1a7605 > > > > Original above does not open for me but here's a copy that does: > > > > http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html I thing it's time to leave the discussion and to go to bed. You can take the problem the way you wish, Python 3.3 is "slower" than Python 3.2. If you see the present status as an optimisation, I'm condidering this as a regression. I'm pretty sure a pure ucs-4/utf-32 can only be, by nature, the correct solution. To be extreme, tools using pure utf-16 or utf-32 are, at least, considering all the citizen on this planet in the same way. jmf From castironpi at gmail.com Sat Aug 18 16:29:13 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 18 Aug 2012 13:29:13 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > > Is there a problem with hacking on the Beta? > > > > Nope. Hack on the beta, then when the release arrives, rebase your > > work onto it. I doubt that anything of this nature will be changed > > between now and then. > > > > ChrisA Thanks Chris, your post was encouraging. I have a question about involving the 'tp_clear' field of the types. http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear ''' ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. ''' I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? From castironpi at gmail.com Sat Aug 18 16:29:13 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 18 Aug 2012 13:29:13 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > > Is there a problem with hacking on the Beta? > > > > Nope. Hack on the beta, then when the release arrives, rebase your > > work onto it. I doubt that anything of this nature will be changed > > between now and then. > > > > ChrisA Thanks Chris, your post was encouraging. I have a question about involving the 'tp_clear' field of the types. http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear ''' ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. ''' I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? From jason.swails at gmail.com Sat Aug 18 16:53:44 2012 From: jason.swails at gmail.com (Jason Swails) Date: Sat, 18 Aug 2012 16:53:44 -0400 Subject: How to get initial absolute working dir reliably? In-Reply-To: References: Message-ID: On Sat, Aug 18, 2012 at 11:19 AM, kj wrote: > > Basically, I'm looking for a read-only variable (or variables) > initialized by Python at the start of execution, and from which > the initial working directory may be read or computed. > This will work for Linux and Mac OS X (and maybe Cygwin, but unlikely for native Windows): try the PWD environment variable. >>> import os >>> os.getcwd() '/Users/swails' >>> os.getenv('PWD') '/Users/swails' >>> os.chdir('..') >>> os.getcwd() '/Users' >>> os.getenv('PWD') '/Users/swails' Of course this environment variable can still be messed with, but there isn't much reason to do so generally (if I'm mistaken here, someone please correct me). Hopefully this is of some help, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sat Aug 18 17:37:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Aug 2012 22:37:13 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <3e235732-39e4-4877-a860-466e433cde5e@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> <3e235732-39e4-4877-a860-466e433cde5e@googlegroups.com> Message-ID: On 18/08/2012 21:22, wxjmfauth at gmail.com wrote: > Le samedi 18 ao?t 2012 20:40:23 UTC+2, rusi a ?crit : >> On Aug 18, 10:59 pm, Steven D'Aprano > >> +comp.lang.pyt... at pearwood.info> wrote: >> >>> On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: >> >>>> Is there any reason why non ascii users are somehow penalized compared >> >>>> to ascii users? >> >>> >> >>> Of course there is a reason. >> >>> >> >>> If you want to represent 1114111 different characters in a string, as >> >>> Unicode supports, you can't use a single byte per character, or even two >> >>> bytes. That is a fact of basic mathematics. Supporting 1114111 characters >> >>> must be more expensive than supporting 128 of them. >> >>> >> >>> But why should you carry the cost of 4-bytes per character just because >> >>> someday you *might* need a non-BMP character? >> >> >> >> I am reminded of: http://answers.microsoft.com/thread/720108ee-0a9c-4090-b62d-bbd5cb1a7605 >> >> >> >> Original above does not open for me but here's a copy that does: >> >> >> >> http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html > > I thing it's time to leave the discussion and to go to bed. In plain English, duck out cos I'm losing. > > You can take the problem the way you wish, Python 3.3 is "slower" > than Python 3.2. I'll ask for the second time. Provide proof that is acceptable to everybody and not just yourself. > > If you see the present status as an optimisation, I'm condidering > this as a regression. Considering does not equate to proof. Where are the figures which back up your claim? > > I'm pretty sure a pure ucs-4/utf-32 can only be, by nature, > the correct solution. I look forward to seeing your patch on the bug tracker. If and only if you can find something that needs patching, which from the course of this thread I think is highly unlikely. > > To be extreme, tools using pure utf-16 or utf-32 are, at least, > considering all the citizen on this planet in the same way. > > jmf > -- Cheers. Mark Lawrence. From python at mrabarnett.plus.com Sat Aug 18 18:14:05 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 18 Aug 2012 23:14:05 +0100 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503013AD.6000607@mrabarnett.plus.com> On 18/08/2012 21:29, Aaron Brady wrote: > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: >> >> > Is there a problem with hacking on the Beta? >> >> >> >> Nope. Hack on the beta, then when the release arrives, rebase your >> >> work onto it. I doubt that anything of this nature will be changed >> >> between now and then. >> >> >> >> ChrisA > > Thanks Chris, your post was encouraging. > > I have a question about involving the 'tp_clear' field of the types. > > http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear > > ''' > ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. > ''' > > I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. > > Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png > > In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. > > Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? > In simple terms, when you create an immutable object it can contain only references to pre-existing objects, but in order to create a cycle you need to make an object refer to another which is created later, so it's not possible to create a cycle out of immutable objects. However, using Python's C API it _is_ possible to create such a cycle, by mutating an otherwise-immutable tuple (see PyTuple_SetItem and PyTuple_SET_ITEM). From rosuav at gmail.com Sat Aug 18 20:46:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 10:46:18 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xehn4vyya.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 4:26 AM, Paul Rubin wrote: > Can you explain the issue of "breaking surrogate pairs apart" a little > more? Switching between encodings based on the string contents seems > silly at first glance. Strings are immutable so I don't understand why > not use UTF-8 or UTF-16 for everything. UTF-8 is more efficient in > Latin-based alphabets and UTF-16 may be more efficient for some other > languages. I think even UCS-4 doesn't completely fix the surrogate pair > issue if it means the only thing I can think of. UTF-8 is highly inefficient for indexing. Given a buffer of (say) a few thousand bytes, how do you locate the 273rd character? You have to scan from the beginning. The same applies when surrogate pairs are used to represent single characters, unless the representation leaks and a surrogate is indexed as two - which is where the breaking-apart happens. ChrisA From brent.blog at gmail.com Sat Aug 18 21:18:41 2012 From: brent.blog at gmail.com (Brent Marshall) Date: Sat, 18 Aug 2012 18:18:41 -0700 (PDT) Subject: [pyxl] xlrd 0.8.0 released! In-Reply-To: References: <501944E4.2090902@simplistix.co.uk> Message-ID: <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> My compliments to John and Chris and to any others who contributed to the new xlsx capability. This is a most welcome development. Thank you. Brent -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sat Aug 18 22:11:38 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Aug 2012 19:11:38 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> Message-ID: <7xfw7j3a1x.fsf@ruckus.brouhaha.com> Chris Angelico writes: > UTF-8 is highly inefficient for indexing. Given a buffer of (say) a > few thousand bytes, how do you locate the 273rd character? How often do you need to do that, as opposed to traversing the string by iteration? Anyway, you could use a rope-like implementation, or an index structure over the string. From rosuav at gmail.com Sat Aug 18 22:19:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 12:19:00 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xfw7j3a1x.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 12:11 PM, Paul Rubin wrote: > Chris Angelico writes: >> UTF-8 is highly inefficient for indexing. Given a buffer of (say) a >> few thousand bytes, how do you locate the 273rd character? > > How often do you need to do that, as opposed to traversing the string by > iteration? Anyway, you could use a rope-like implementation, or an > index structure over the string. Well, imagine if Python strings were stored in UTF-8. How would you slice it? >>> "asdfqwer"[4:] 'qwer' That's a not uncommon operation when parsing strings or manipulating data. You'd need to completely rework your algorithms to maintain a position somewhere. ChrisA From castironpi at gmail.com Sat Aug 18 22:28:32 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 18 Aug 2012 19:28:32 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5325fd9d-e7d8-4549-9e36-aa0553870308@googlegroups.com> On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > On 18/08/2012 21:29, Aaron Brady wrote: > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > >> > > >> > Is there a problem with hacking on the Beta? > > >> > > >> > > >> > > >> Nope. Hack on the beta, then when the release arrives, rebase your > > >> > > >> work onto it. I doubt that anything of this nature will be changed > > >> > > >> between now and then. > > >> > > >> > > >> > > >> ChrisA > > > > > > Thanks Chris, your post was encouraging. > > > > > > I have a question about involving the 'tp_clear' field of the types. > > > > > > http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear > > > > > > ''' > > > ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. > > > ''' > > > > > > I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. > > > > > > Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png > > > > > > In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. > > > > > > Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? > > > > > In simple terms, when you create an immutable object it can contain > > only references to pre-existing objects, but in order to create a cycle > > you need to make an object refer to another which is created later, so > > it's not possible to create a cycle out of immutable objects. > > > > However, using Python's C API it _is_ possible to create such a cycle, > > by mutating an otherwise-immutable tuple (see PyTuple_SetItem and > > PyTuple_SET_ITEM). Are there any precedents for storing uncounted references to PyObject's? One apparent problematic case is creating an iterator to a set, then adding it to the set. However the operation is a modification, and causes the iterator to be removed from the secondary list before the set is examined for collection. Otherwise, the iterator keeps a counted reference to the set, but the set does not keep a counted reference to the iterator, so the iterator will always be freed first. Therefore, the set's secondary list will be empty when the set is freed. Concurrent addition and deletion of iterators should be disabled, and the iterators should remove themselves from the set's secondary list before they decrement their references to the set. Please refresh the earlier diagram; counted references are distinguished separately. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png From castironpi at gmail.com Sat Aug 18 22:28:32 2012 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 18 Aug 2012 19:28:32 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5325fd9d-e7d8-4549-9e36-aa0553870308@googlegroups.com> On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > On 18/08/2012 21:29, Aaron Brady wrote: > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > >> > > >> > Is there a problem with hacking on the Beta? > > >> > > >> > > >> > > >> Nope. Hack on the beta, then when the release arrives, rebase your > > >> > > >> work onto it. I doubt that anything of this nature will be changed > > >> > > >> between now and then. > > >> > > >> > > >> > > >> ChrisA > > > > > > Thanks Chris, your post was encouraging. > > > > > > I have a question about involving the 'tp_clear' field of the types. > > > > > > http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear > > > > > > ''' > > > ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. > > > ''' > > > > > > I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. > > > > > > Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png > > > > > > In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. > > > > > > Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? > > > > > In simple terms, when you create an immutable object it can contain > > only references to pre-existing objects, but in order to create a cycle > > you need to make an object refer to another which is created later, so > > it's not possible to create a cycle out of immutable objects. > > > > However, using Python's C API it _is_ possible to create such a cycle, > > by mutating an otherwise-immutable tuple (see PyTuple_SetItem and > > PyTuple_SET_ITEM). Are there any precedents for storing uncounted references to PyObject's? One apparent problematic case is creating an iterator to a set, then adding it to the set. However the operation is a modification, and causes the iterator to be removed from the secondary list before the set is examined for collection. Otherwise, the iterator keeps a counted reference to the set, but the set does not keep a counted reference to the iterator, so the iterator will always be freed first. Therefore, the set's secondary list will be empty when the set is freed. Concurrent addition and deletion of iterators should be disabled, and the iterators should remove themselves from the set's secondary list before they decrement their references to the set. Please refresh the earlier diagram; counted references are distinguished separately. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png From no.email at nospam.invalid Sat Aug 18 22:35:44 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Aug 2012 19:35:44 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> Message-ID: <7xtxvzehhb.fsf@ruckus.brouhaha.com> Chris Angelico writes: >>>> "asdfqwer"[4:] > 'qwer' > > That's a not uncommon operation when parsing strings or manipulating > data. You'd need to completely rework your algorithms to maintain a > position somewhere. Scanning 4 characters (or a few dozen, say) to peel off a token in parsing a UTF-8 string is no big deal. It gets more expensive if you want to index far more deeply into the string. I'm asking how often that is done in real code. Obviously one can concoct hypothetical examples that would suffer. From rosuav at gmail.com Sat Aug 18 23:01:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 13:01:46 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xtxvzehhb.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 12:35 PM, Paul Rubin wrote: > Chris Angelico writes: >>>>> "asdfqwer"[4:] >> 'qwer' >> >> That's a not uncommon operation when parsing strings or manipulating >> data. You'd need to completely rework your algorithms to maintain a >> position somewhere. > > Scanning 4 characters (or a few dozen, say) to peel off a token in > parsing a UTF-8 string is no big deal. It gets more expensive if you > want to index far more deeply into the string. I'm asking how often > that is done in real code. Obviously one can concoct hypothetical > examples that would suffer. Sure, four characters isn't a big deal to step through. But it still makes indexing and slicing operations O(N) instead of O(1), plus you'd have to zark the whole string up to where you want to work. It'd be workable, but you'd have to redo your algorithms significantly; I don't have a Python example of parsing a huge string, but I've done it in other languages, and when I can depend on indexing being a cheap operation, I'll happily do exactly that. ChrisA From no.email at nospam.invalid Sat Aug 18 23:10:35 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Aug 2012 20:10:35 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> Message-ID: <7x7gsv4lw4.fsf@ruckus.brouhaha.com> Chris Angelico writes: > Sure, four characters isn't a big deal to step through. But it still > makes indexing and slicing operations O(N) instead of O(1), plus you'd > have to zark the whole string up to where you want to work. I know some systems chop the strings into blocks of (say) a few hundred chars, so you can immediately get to the correct block, then scan into the block to get to the desired char offset. > I don't have a Python example of parsing a huge string, but I've done > it in other languages, and when I can depend on indexing being a cheap > operation, I'll happily do exactly that. I'd be interested to know what the context was, where you parsed a big unicode string in a way that required random access to the nth character in the string. From tjreedy at udel.edu Sat Aug 18 23:12:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Aug 2012 23:12:50 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: On 8/18/2012 4:09 PM, Terry Reedy wrote: > print(timeit("c in a", "c = '?'; a = 'a'*1000+c")) > # .6 in 3.2.3, 1.2 in 3.3.0 > > This does not make sense to me and I will ask about it. I did ask on pydef list and paraphrased responses include: 1. 'My system gives opposite ratios.' 2. 'With a default of 1000000 repetitions in a loop, the reported times are microseconds per operation and thus not practically significant.' 3. 'There is a stringbench.py with a large number of such micro benchmarks.' I believe there are also whole-application benchmarks that try to mimic real-world mixtures of operations. People making improvements must consider performance on multiple systems and multiple benchmarks. If someone wants to work on search speed, they cannot just optimize that one operation on one system. -- Terry Jan Reedy From rosuav at gmail.com Sat Aug 18 23:31:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 13:31:21 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7x7gsv4lw4.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <7x7gsv4lw4.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 1:10 PM, Paul Rubin wrote: > Chris Angelico writes: >> I don't have a Python example of parsing a huge string, but I've done >> it in other languages, and when I can depend on indexing being a cheap >> operation, I'll happily do exactly that. > > I'd be interested to know what the context was, where you parsed > a big unicode string in a way that required random access to > the nth character in the string. It's something I've done in C/C++ fairly often. Take one big fat buffer, slice it and dice it as you get the information you want out of it. I'll retain and/or calculate indices (when I'm not using pointers, but that's a different kettle of fish). Generally, I'm working with pure ASCII, but port those same algorithms to Python and you'll easily be able to read in a file in some known encoding and manipulate it as Unicode. It's not so much 'random access to the nth character' as an efficient way of jumping forward. For instance, if I know that the next thing is a literal string of n characters (that I don't care about), I want to skip over that and keep parsing. The Adobe Message Format is particularly noteworthy in this, but it's a stupid format and I don't recommend people spend too much time reading up on it (unless you like that sensation of your brain trying to escape through your ear). ChrisA From robertmiles at teranews.com Sun Aug 19 01:21:48 2012 From: robertmiles at teranews.com (Robert Miles) Date: Sun, 19 Aug 2012 00:21:48 -0500 Subject: Encapsulation, inheritance and polymorphism In-Reply-To: References: <5006b48a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 7/23/2012 11:18 AM, Albert van der Horst wrote: > In article <5006b48a$0$29978$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > > Even with a break, why bother continuing through the body of the function >> when you already have the result? When your calculation is done, it's >> done, just return for goodness sake. You wouldn't write a search that >> keeps going after you've found the value that you want, out of some >> misplaced sense that you have to look at every value. Why write code with >> unnecessary guard values and temporary variables out of a misplaced sense >> that functions must only have one exit? > > Example from recipee's: > > Stirr until the egg white is stiff. > > Alternative: > Stirr egg white for half an hour, > but if the egg white is stiff keep your spoon still. > > (Cooking is not my field of expertise, so the wording may > not be quite appropriate. ) > >> -- >> Steven > > Groetjes Albert Note that you forgot applying enough heat to do the cooking. From no.email at nospam.invalid Sun Aug 19 01:58:14 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 18 Aug 2012 22:58:14 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <7x7gsv4lw4.fsf@ruckus.brouhaha.com> Message-ID: <7xfw7jv2x5.fsf@ruckus.brouhaha.com> Chris Angelico writes: > Generally, I'm working with pure ASCII, but port those same algorithms > to Python and you'll easily be able to read in a file in some known > encoding and manipulate it as Unicode. If it's pure ASCII, you can use the bytes or bytearray type. > It's not so much 'random access to the nth character' as an efficient > way of jumping forward. For instance, if I know that the next thing is > a literal string of n characters (that I don't care about), I want to > skip over that and keep parsing. I don't understand how this is supposed to work. You're going to read a large unicode text file (let's say it's UTF-8) into a single big string? So the runtime library has to scan the encoded contents to find the highest numbered codepoint (let's say it's mostly ascii but has a few characters outside the BMP), expand it all (in this case) to UCS-4 giving 4x memory bloat and requiring decoding all the UTF-8 regardless, and now we should worry about the efficiency of skipping n characters? Since you have to decode the n characters regardless, I'd think this skipping part should only be an issue if you have to do it a lot of times. From john_ladasky at sbcglobal.net Sun Aug 19 02:05:46 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 18 Aug 2012 23:05:46 -0700 (PDT) Subject: Encapsulation, inheritance and polymorphism In-Reply-To: References: <3vnfd9-343.ln1@satorlaser.homedns.org> <-8SdnVrXGqie25jNnZ2dnUVZ7qKdnZ2d@bt.com> <4YudnY5tG-6-IJjNnZ2dnUVZ8gidnZ2d@bt.com> Message-ID: <07735348-b1a7-434e-b622-bdf29f17d9ff@googlegroups.com> On Tuesday, July 17, 2012 12:39:53 PM UTC-7, Mark Lawrence wrote: > I would like to spend more time on this thread, but unfortunately the 44 > ton artic carrying "Java in a Nutshell Volume 1 Part 1 Chapter 1 > Paragraph 1 Sentence 1" has just arrived outside my abode and needs > unloading :-) That reminds me of a remark I made nearly 10 years ago: "Well, I followed one friend's advice and investigated Java, perhaps a little too quickly. I purchased Ivor Horton's _Beginning_Java_2_ book. It is reasonably well-written. But how many pages did I have to read before I got through everything I needed to know, in order to read and write files? Four hundred! I need to keep straight detailed information about objects, inheritance, exceptions, buffers, and streams, just to read data from a text file??? I haven't actually sat down to program in Java yet. But at first glance, it would seem to be a step backwards even from the procedural C programming that I was doing a decade ago. I was willing to accept the complexity of the Windows GUI, and program with manuals open on my lap. It is a lot harder for me to accept that I will need to do this in order to process plain old text, perhaps without even any screen output." https://groups.google.com/d/topic/bionet.software/kk-EGGTHN1M/discussion Some things never change! :^) From john_ladasky at sbcglobal.net Sun Aug 19 02:05:46 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 18 Aug 2012 23:05:46 -0700 (PDT) Subject: Encapsulation, inheritance and polymorphism In-Reply-To: References: <3vnfd9-343.ln1@satorlaser.homedns.org> <-8SdnVrXGqie25jNnZ2dnUVZ7qKdnZ2d@bt.com> <4YudnY5tG-6-IJjNnZ2dnUVZ8gidnZ2d@bt.com> Message-ID: <07735348-b1a7-434e-b622-bdf29f17d9ff@googlegroups.com> On Tuesday, July 17, 2012 12:39:53 PM UTC-7, Mark Lawrence wrote: > I would like to spend more time on this thread, but unfortunately the 44 > ton artic carrying "Java in a Nutshell Volume 1 Part 1 Chapter 1 > Paragraph 1 Sentence 1" has just arrived outside my abode and needs > unloading :-) That reminds me of a remark I made nearly 10 years ago: "Well, I followed one friend's advice and investigated Java, perhaps a little too quickly. I purchased Ivor Horton's _Beginning_Java_2_ book. It is reasonably well-written. But how many pages did I have to read before I got through everything I needed to know, in order to read and write files? Four hundred! I need to keep straight detailed information about objects, inheritance, exceptions, buffers, and streams, just to read data from a text file??? I haven't actually sat down to program in Java yet. But at first glance, it would seem to be a step backwards even from the procedural C programming that I was doing a decade ago. I was willing to accept the complexity of the Windows GUI, and program with manuals open on my lap. It is a lot harder for me to accept that I will need to do this in order to process plain old text, perhaps without even any screen output." https://groups.google.com/d/topic/bionet.software/kk-EGGTHN1M/discussion Some things never change! :^) From steve+comp.lang.python at pearwood.info Sun Aug 19 02:09:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 06:09:49 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> Message-ID: <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> This is a long post. If you don't feel like reading an essay, skip to the very bottom and read my last few paragraphs, starting with "To recap". On Sat, 18 Aug 2012 11:26:21 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> (There is an extension to UCS-2, UTF-16, which encodes non-BMP >> characters using two code points. This is fragile and doesn't work very >> well, because string-handling methods can break the surrogate pairs >> apart, leaving you with invalid unicode string. Not good.) > ... >> With PEP 393, each Python string will be stored in the most efficient >> format possible: > > Can you explain the issue of "breaking surrogate pairs apart" a little > more? Switching between encodings based on the string contents seems > silly at first glance. Forget encodings! We're not talking about encodings. Encodings are used for converting text as bytes for transmission over the wire or storage on disk. PEP 393 talks about the internal representation of text within Python, the C-level data structure. In 3.2, that data structure depends on a compile-time switch. In a "narrow build", text is stored using two-bytes per character, so the string "len" (as in the name of the built-in function) will be stored as 006c 0065 006e (or possibly 6c00 6500 6e00, depending on whether your system is LittleEndian or BigEndian), plus object-overhead, which I shall ignore. Since most identifiers are ASCII, that's already using twice as much memory as needed. This standard data structure is called UCS-2, and it only handles characters in the Basic Multilingual Plane, the BMP (roughly the first 64000 Unicode code points). I'll come back to that. In a "wide build", text is stored as four-bytes per character, so "len" is stored as either: 0000006c 00000065 0000006e 6c000000 65000000 6e000000 Now memory is cheap, but it's not *that* cheap, and no matter how much memory you have, you can always use more. This system is called UCS-4, and it can handle the entire Unicode character set, for now and forever. (If we ever need more that four-bytes worth of characters, it won't be called Unicode.) Remember I said that UCS-2 can only handle the 64K characters [technically: code points] in the Basic Multilingual Plane? There's an extension to UCS-2 called UTF-16 which extends it to the entire Unicode range. Yes, that's the same name as the UTF-16 encoding, because it's more or less the same system. UTF-16 says "let's represent characters in the BMP by two bytes, but characters outside the BMP by four bytes." There's a neat trick to this: the BMP doesn't use the entire two-byte range, so there are some byte pairs which are illegal in UCS-2 -- they don't correspond to *any* character. UTF-16 used those byte pairs to signal "this is half a character, you need to look at the next pair for the rest of the character". Nifty hey? These pairs-of-pseudocharacters are called "surrogate pairs". Except this comes at a big cost: you can no longer tell how long a string is by counting the number of bytes, which is fast, because sometimes four bytes is two characters and sometimes it's one and you can't tell which it will be until you actually inspect all four bytes. Copying sub-strings now becomes either slow, or buggy. Say you want to grab the 10th characters in a string. The fast way using UCS-2 is to simply grab bytes 8 and 9 (remember characters are pairs of bytes and we start counting at zero) and you're done. Fast and safe if you're willing to give up the non-BMP characters. It's also fast and safe if you use USC-4, but then everything takes twice as much space, so you probably end up spending so much time copying null bytes that you're probably slower anyway. Especially when your OS starts paging memory like mad. But in UTF-16, indexing can be fast or safe but not both. Maybe bytes 8 and 9 are half of a surrogate pair, and you've now split the pair and ended up with an invalid string. That's what Python 3.2 does, it fails to handle surrogate pairs properly: py> s = chr(0xFFFF + 1) py> a, b = s py> a '\ud800' py> b '\udc00' I've just split a single valid Unicode character into two invalid characters. Python3.2 will (probably) mindless process those two non- characters, and the only sign I have that I did something wrong is that my data is now junk. Since any character can be a surrogate pair, you have to scan every pair of bytes in order to index a string, or work out it's length, or copy a substring. It's not enough to just check if the last pair is a surrogate. When you don't, you have bugs like this from Python 3.2: py> s = "01234" + chr(0xFFFF + 1) + "6789" py> s[9] == '9' False py> s[9], len(s) ('8', 11) Which is now fixed in Python 3.3. So variable-width data structures like UTF-8 or UTF-16 are crap for the internal representation of strings -- they are either fast or correct but cannot be both. But UCS-2 is sub-optimal, because it can only handle the BMP, and UCS-4 is too because ASCII-only strings like identifiers end up being four times as big as they need to be. 1-byte schemes like Latin-1 are unspeakable because they only handle 256 characters, fewer if you don't count the C0 and C1 control codes. PEP 393 to the rescue! What if you could encode pure-ASCII strings like "len" using one byte per character, and BMP strings using two bytes per character (UCS-2), and fall back to four bytes (UCS-4) only when you really need it? The benefits are: * Americans and English-Canadians and Australians and other barbarians of that ilk who only use ASCII save a heap of memory; * people who mostly use non-BMP characters only pay the cost of four- bytes per character for strings that actually *need* four-bytes per character; * people who use lots of non-BMP characters are no worse off. The costs are: * string routines need to be smarter -- they have to handle three different data structures (ASCII, UCS-2, UCS-4) instead of just one; * there's a certain amount of overhead when creating a string -- you have to work out which in-memory format to use, and that's not necessarily trivial, but at least it's a once-off cost when you create the string; * people who misunderstand what's going on get all upset over micro- benchmarks. > Strings are immutable so I don't understand why > not use UTF-8 or UTF-16 for everything. UTF-8 is more efficient in > Latin-based alphabets and UTF-16 may be more efficient for some other > languages. I think even UCS-4 doesn't completely fix the surrogate pair > issue if it means the only thing I can think of. To recap: * Variable-byte formats like UTF-8 and UTF-16 mean that basic string operations are not O(1) but are O(N). That means they are slow, or buggy, pick one. * Fixed width UCS-2 doesn't handle the full Unicode range, only the BMP. That's better than it sounds: the BMP supports most character sets, but not all. Still, there are people who need the supplementary planes, and UCS-2 lets them down. * Fixed width UCS-4 does handle the full Unicode range, without surrogates, but at the cost of using 2-4 times more string memory for the vast majority of users. * PEP 393 doesn't use variable-width characters, but variable-width strings. Instead of choosing between 1, 2 and 4 bytes per character, it chooses *per string*. This keeps basic string operations O(1) instead of O(N), saves memory where possible, while still supporting the full Unicode range without a compile-time option. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 02:13:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 06:13:29 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <502fd7f6$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50308409$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 11:30:19 -0700, wxjmfauth wrote: >> > I'm aware of this (and all the blah blah blah you are explaining). >> > This always the same song. Memory. >> >> >> >> Exactly. The reason it is always the same song is because it is an >> important song. >> >> > No offense here. But this is an *american* answer. I am not American. I am not aware that computers outside of the USA, and Australia, have unlimited amounts of memory. You must be very lucky. > The same story as the coding of text files, where "utf-8 == ascii" and > the rest of the world doesn't count. UTF-8 is not ASCII. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 02:30:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 06:30:54 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: <5030881d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 11:05:07 -0700, wxjmfauth wrote: > As I understand (I think) the undelying mechanism, I can only say, it is > not a surprise that it happens. > > Imagine an editor, I type an "a", internally the text is saved as ascii, > then I type en "?", the text can only be saved in at least latin-1. Then > I enter an "?", the text become an internal ucs-4 "string". The remove > the "?" and so on. Firstly, that is not what Python does. For starters, ? is in the BMP, and so is nearly every character you're ever going to use unless you are Asian or a historian using some obscure ancient script. NONE of the examples you have shown in your emails have included 4-byte characters, they have all been ASCII or UCS-2. You are suffering from a misunderstanding about what is going on and misinterpreting what you have seen. In *both* Python 3.2 and 3.3, both ? and ? are represented by two bytes. That will not change. There is a tiny amount of fixed overhead for strings, and that overhead is slightly different between the versions, but you'll never notice the difference. Secondly, how a text editor or word processor chooses to store the text that you type is not the same as how Python does it. A text editor is not going to be creating a new immutable string after every key press. That will be slow slow SLOW. The usual way is to keep a buffer for each paragraph, and add and subtract characters from the buffer. > Intuitively I expect there is some kind slow down between all these > "strings" conversion. Your intuition is wrong. Strings are not converted from ASCII to USC-2 to USC-4 on the fly, they are converted once, when the string is created. The tests we ran earlier, e.g.: ('ab?' * 1000).replace('?', '??') show the *worst possible case* for the new string handling, because all we do is create new strings. First we create a string 'ab?', then we create another string 'ab?'*1000, then we create two new strings '?' and '??', and finally we call replace and create yet another new string. But in real applications, once you have created a string, you don't just immediately create a new one and throw the old one away. You likely do work with that string: steve at runes:~$ python3.2 -m timeit "s = 'abc??'*1000; n = len(s); flag = s.startswith(('*', 'a'))" 100000 loops, best of 3: 2.41 usec per loop steve at runes:~$ python3.3 -m timeit "s = 'abc??'*1000; n = len(s); flag = s.startswith(('*', 'a'))" 100000 loops, best of 3: 2.29 usec per loop Once you start doing *real work* with the strings, the overhead of deciding whether they should be stored using 1, 2 or 4 bytes begins to fade into the noise. > When I tested this flexible representation, a few months ago, at the > first alpha release. This is precisely what, I tested. String > manipulations which are forcing this internal change and I concluded the > result is not brillant. Realy, a factor 0.n up to 10. Like I said, if you really think that there is a significant, repeatable slow-down on Windows, report it as a bug. > Does any body know a way to get the size of the internal "string" in > bytes? sys.getsizeof(some_string) steve at runes:~$ python3.2 -c "from sys import getsizeof as size; print(size ('abc??'*1000))" 10030 steve at runes:~$ python3.3 -c "from sys import getsizeof as size; print(size ('abc??'*1000))" 10038 As I said, there is a *tiny* overhead difference. But identifiers will generally be smaller: steve at runes:~$ python3.2 -c "from sys import getsizeof as size; print(size (size.__name__))" 48 steve at runes:~$ python3.3 -c "from sys import getsizeof as size; print(size (size.__name__))" 34 You can check the object overhead by looking at the size of the empty string. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 02:33:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 06:33:28 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 09:51:37 -0600, Ian Kelly wrote about PEP 393: > The change does not just benefit ASCII users. It primarily benefits > anybody using a wide unicode build with strings mostly containing only > BMP characters. Just to be clear: If you have many strings which are *mostly* BMP, but have one or two non- BMP characters in *each* string, you will see no benefit. But if you have many strings which are all BMP, and only a few strings containing non-BMP characters, then you will see a big benefit. > Even for narrow build users, there is the benefit that > with approximately the same amount of memory usage in most cases, they > no longer have to worry about non-BMP characters sneaking in and > breaking their code. Yes! +1000 on that. > There is some additional benefit for Latin-1 users, but this has nothing > to do with Python. If Python is going to have the option of a 1-byte > representation (and as long as we have the flexible representation, I > can see no reason not to), The PEP explicitly states that it only uses a 1-byte format for ASCII strings, not Latin-1: "ASCII-only Unicode strings will again use only one byte per character" and later: "If the maximum character is less than 128, they use the PyASCIIObject structure" and: "The data and utf8 pointers point to the same memory if the string uses only ASCII characters (using only Latin-1 is not sufficient)." > then it is going to be Latin-1 by definition, Certainly not, either in fact or in principle. There are a large number of 1-byte encodings, Latin-1 is hardly the only one. > because that's what 1-byte Unicode (UCS-1, if you will) is. If you have > an issue with that, take it up with the designers of Unicode. The designers of Unicode have never created a standard "1-byte Unicode" or UCS-1, as far as I can determine. The Unicode standard refers to some multiple million code points, far too many to fit in a single byte. There is some historical justification for using "Unicode" to mean UCS-2, but with the standard being extended beyond the BMP, that is no longer valid. See http://www.cl.cam.ac.uk/~mgk25/unicode.html for more details. I think what you are trying to say is that the Unicode designers deliberately matched the Latin-1 standard for Unicode's first 256 code points. That's not the same thing though: there is no Unicode standard mapping to a single byte format. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 02:35:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 06:35:11 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> Message-ID: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 19:34:50 +0100, MRAB wrote: > "a" will be stored as 1 byte/codepoint. > > Adding "?", it will still be stored as 1 byte/codepoint. Wrong. It will be 2 bytes, just like it already is in Python 3.2. I don't know where people are getting this myth that PEP 393 uses Latin-1 internally, it does not. Read the PEP, it explicitly states that 1-byte formats are only used for ASCII strings. > Adding "?", it will still be stored as 2 bytes/codepoint. That is correct. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 03:15:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 07:15:36 GMT Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 10:27:10 -0700, rusi wrote: > For example, my sister recently saw some of my mails and was mystified > that I had sent back 'blank mails' until I explained and pointed out > that my answers were interleaved into what was originally sent! No offence to your sister, who I'm sure is probably a really great person and kind to small animals and furry children, but didn't she, you know, *investigate further* upon seeing something weird, namely a "blank" email? As in, "Gosh, dearest brother has sent me an email without saying anything. That's weird. I hope he's alright? Maybe there's something a bit further down? Or a funny picture of a cat at the end? Or something? I better scroll down a bit further and see." I'm not talking about "complicated tech stuff" like View > Message Source and trying to determine whether perhaps the MIME type is broken and there's an invisible attachment. I'm talking about almost the simplest thing in the friggin' world, *scrolling down and looking at what's there*. The software equivalent of somebody handing you a "blank" piece of paper and turning it around to see if maybe there's something on the back. Because that's what I do, and I don't think I'm some sort of hyper- evolved mega-genius with a brain the size of a planet, I'm just some guy. Nobody needed to tell me "Hey dummy, the text you are looking for is a bit further down, keep reading." I just looked on my own, and saw the text on my own, and actually read it without being told to, and a little light bulb went on over my head and I went "Wow! People can actually write stuff in between other stuff! How did they do that?" Now sure, I make allowances for 70 year olds who have never touched a computer before and have to ask "What's a scroll bar?" and "How do I use this mousey-pointer thing?" I assume your sister has minimal skills like "can scroll" and "knows how to read". I'm not sure which is worse -- that perhaps I *am* some sort of mega- genius and keep overestimating the difficulty of scroll-down-and-read for normal people, or that others have such short attention spans that anything that they can't see immediately in front of them might as well not exist. Either thought is rather depressing. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 03:17:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 07:17:10 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> Message-ID: <503092f6$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 19:59:32 +0100, MRAB wrote: > The problem with strings containing surrogate pairs is that you could > inadvertently slice the string in the middle of the surrogate pair. That's the *least* of the problems with surrogate pairs. That would be easy to fix: check the point of the slice, and back up or forward if you're on a surrogate pair. But that's not good enough, because the surrogates could be anywhere in the string. You have to touch every single character in order to know how many there are. The problem with surrogate pairs is that they make basic string operations O(N) instead of O(1). -- Steven From __peter__ at web.de Sun Aug 19 03:43:13 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Aug 2012 09:43:13 +0200 Subject: New internal string format in 3.3, was Re: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 18 Aug 2012 19:34:50 +0100, MRAB wrote: > >> "a" will be stored as 1 byte/codepoint. >> >> Adding "?", it will still be stored as 1 byte/codepoint. > > Wrong. It will be 2 bytes, just like it already is in Python 3.2. > > I don't know where people are getting this myth that PEP 393 uses Latin-1 > internally, it does not. Read the PEP, it explicitly states that 1-byte > formats are only used for ASCII strings. From Python 3.3.0a4+ (default:10a8ad665749, Jun 9 2012, 08:57:51) [GCC 4.6.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> [sys.getsizeof("?"*i) for i in range(10)] [49, 74, 75, 76, 77, 78, 79, 80, 81, 82] >>> [sys.getsizeof("e"*i) for i in range(10)] [49, 50, 51, 52, 53, 54, 55, 56, 57, 58] >>> sys.getsizeof("?"*101)-sys.getsizeof("?") 100 >>> sys.getsizeof("e"*101)-sys.getsizeof("e") 100 >>> sys.getsizeof("?"*101)-sys.getsizeof("?") 200 I infer that (1) both ASCII and Latin1 strings require one byte per character. (2) Latin1 strings have a constant overhead of 24 bytes (on a 64bit system) over ASCII-only. From rosuav at gmail.com Sun Aug 19 03:46:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 17:46:14 +1000 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 19, 2012 at 5:15 PM, Steven D'Aprano wrote: > The software equivalent of somebody handing you a "blank" piece of paper > and turning it around to see if maybe there's something on the back. Straight out of a Goon Show, that is. Heh. ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 19 04:01:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 08:01:46 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> Message-ID: <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Aug 2012 19:35:44 -0700, Paul Rubin wrote: > Scanning 4 characters (or a few dozen, say) to peel off a token in > parsing a UTF-8 string is no big deal. It gets more expensive if you > want to index far more deeply into the string. I'm asking how often > that is done in real code. It happens all the time. Let's say you've got a bunch of text, and you use a regex to scan through it looking for a match. Let's ignore the regular expression engine, since it has to look at every character anyway. But you've done your search and found your matching text and now want everything *after* it. That's not exactly an unusual use-case. mo = re.search(pattern, text) if mo: start, end = mo.span() result = text[end:] Easy-peasy, right? But behind the scenes, you have a problem: how does Python know where text[end:] starts? With fixed-size characters, that's O(1): Python just moves forward end*width bytes into the string. Nice and fast. With a variable-sized characters, Python has to start from the beginning again, and inspect each byte or pair of bytes. This turns the slice operation into O(N) and the combined op (search + slice) into O(N**2), and that starts getting *horrible*. As always, "everything is fast for small enough N", but you *really* don't want O(N**2) operations when dealing with large amounts of data. Insisting that the regex functions only ever return offsets to valid character boundaries doesn't help you, because the string slice method cannot know where the indexes came from. I suppose you could have a "fast slice" and a "slow slice" method, but really, that sucks, and besides all that does is pass responsibility for tracking character boundaries to the developer instead of the language, and you know damn well that they will get it wrong and their code will silently do the wrong thing and they'll say that Python sucks and we never used to have this problem back in the good old days with ASCII. Boo sucks to that. UCS-4 is an option, since that's fixed-width. But it's also bulky. For typical users, you end up wasting memory. That is the complaint driving PEP 393 -- memory is cheap, but it's not so cheap that you can afford to multiply your string memory by four just in case somebody someday gives you a character in one of the supplementary planes. If you have oodles of memory and small data sets, then UCS-4 is probably all you'll ever need. I hear that the club for people who have all the memory they'll ever need is holding their annual general meeting in a phone-booth this year. You could say "Screw the full Unicode standard, who needs more than 64K different characters anyway?" Well apart from Asians, and historians, and a bunch of other people. If you can control your data and make sure no non-BMP characters are used, UCS-2 is fine -- except Python doesn't actually use that. You could do what Python 3.2 narrow builds do: use UTF-16 and leave it up to the individual programmer to track character boundaries, and we know how well that works. Luckily the supplementary planes are only rarely used, and people who need them tend to buy more memory and use wide builds. People who only need a few non-BMP characters in a narrow build generally just cross their fingers and hope for the best. You could add a whole lot more heavyweight infrastructure to strings, turn them into suped-up ropes-on-steroids. All those extra indexes mean that you don't save any memory. Because the objects are so much bigger and more complex, your CPU cache goes to the dogs and your code still runs slow. Which leaves us right back where we started, PEP 393. > Obviously one can concoct hypothetical examples that would suffer. If you think "slicing at arbitrary indexes" is a hypothetical example, I don't know what to say. -- Steven From no.email at nospam.invalid Sun Aug 19 04:04:25 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 01:04:25 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x8vdbmho6.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > This is a long post. If you don't feel like reading an essay, skip to the > very bottom and read my last few paragraphs, starting with "To recap". I'm very flattered that you took the trouble to write that excellent exposition of different Unicode encodings in response to my post. I can only hope some readers will benefit from it. I regret that I wasn't more clear about the perspective I posted from, i.e. that I'm already familiar with how those encodings work. After reading all of it, I still have the same skepticism on the main point as before, but I think I see what the issue in contention is, and some differences in perspectice. First of all, you wrote: > This standard data structure is called UCS-2 ... There's an extension > to UCS-2 called UTF-16 My own understanding is UCS-2 simply shouldn't be used any more. Unicode was historically supposed to be a 16-bit character set, but that turned out to not be enough, so the supplementary planes were added. UCS-2 thus became obsolete and UTF-16 superseded it in 1996. UTF-16 in turn is rather clumsy and the later UTF-8 is better in a lot of ways, but both of these are at least capable of encoding all the character codes. On to the main issue: > * Variable-byte formats like UTF-8 and UTF-16 mean that basic string > operations are not O(1) but are O(N). That means they are slow, or buggy, > pick one. This I don't see. What are the basic string operations? * Examine the first character, or first few characters ("few" = "usually bounded by a small constant") such as to parse a token from an input stream. This is O(1) with either encoding. * Slice off the first N characters. This is O(N) with either encoding if it involves copying the chars. I guess you could share references into the same string, but if the slice reference persists while the big reference is released, you end up not freeing the memory until later than you really should. * Concatenate two strings. O(N) either way. * Find length of string. O(1) either way since you'd store it in the string header when you build the string in the first place. Building the string has to have been an O(N) operation in either representation. And finally: * Access the nth char in the string for some large random n, or maybe get a small slice from some random place in a big string. This is where fixed-width representation is O(1) while variable-width is O(N). What I'm not convinced of, is that the last thing happens all that often. Meanwhile, an example of the 393 approach failing: I was involved in a project that dealt with terabytes of OCR data of mostly English text. So the chars were mostly ascii, but there would be occasional non-ascii chars including supplementary plane characters, either because of special symbols that were really in the text, or the typical OCR confusion emitting those symbols due to printing imprecision. That's a natural for UTF-8 but the PEP-393 approach would bloat up the memory requirements by a factor of 4. py> s = chr(0xFFFF + 1) py> a, b = s That looks like Python 3.2 is buggy and that sample should just throw an error. s is a one-character string and should not be unpackable. I realize the folks who designed and implemented PEP 393 are very smart cookies and considered stuff carefully, while I'm just an internet user posting an immediate impression of something I hadn't seen before (I still use Python 2.6), but I still have to ask: if the 393 approach makes sense, why don't other languages do it? Ropes of UTF-8 segments seems like the most obvious approach and I wonder if it was considered. By that I mean pick some implementation constant k (say k=128) and represent the string as a UTF-8 encoded byte array, accompanied by a vector n//k pointers into the byte array, where n is the number of codepoints in the string. Then you can reach any offset analogously to reading a random byte on a disk, by seeking to the appropriate block, and then reading the block and getting the char you want within it. Random access is then O(1) though the constant is higher than it would be with fixed width encoding. From no.email at nospam.invalid Sun Aug 19 04:11:56 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 01:11:56 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x4nnzmhbn.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > result = text[end:] if end not near the end of the original string, then this is O(N) even with fixed-width representation, because of the char copying. if it is near the end, by knowing where the string data area ends, I think it should be possible to scan backwards from the end, recognizing what bytes can be the beginning of code points and counting off the appropriate number. This is O(1) if "near the end" means "within a constant". > You could say "Screw the full Unicode standard, who needs more than 64K No if you're claiming the language supports unicode it should be the whole standard. > You could do what Python 3.2 narrow builds do: use UTF-16 and leave it > up to the individual programmer to track character boundaries, I'm surprised the Python 3 implementers even considered that approach much less went ahead with it. It's obviously wrong. > You could add a whole lot more heavyweight infrastructure to strings, > turn them into suped-up ropes-on-steroids. I'm not persuaded that PEP 393 isn't even worse. From rosuav at gmail.com Sun Aug 19 04:24:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 18:24:57 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7x4nnzmhbn.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 6:11 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> result = text[end:] > > if end not near the end of the original string, then this is O(N) > even with fixed-width representation, because of the char copying. > > if it is near the end, by knowing where the string data area > ends, I think it should be possible to scan backwards from > the end, recognizing what bytes can be the beginning of code points and > counting off the appropriate number. This is O(1) if "near the end" > means "within a constant". Only if you know exactly where the end is (which requires storing and maintaining a character length - this may already be happening, I don't know). But that approach means you need to have code for both ways (forward search or reverse), and of course it relies on your encoding being reverse-scannable in this way (as UTF-8 is, but not all). And of course, taking the *entire* rest of the string isn't the only thing you do. What if you want to take the next six characters after that index? That would be constant time with a fixed-width storage format. ChrisA From no.email at nospam.invalid Sun Aug 19 04:44:44 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 01:44:44 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> Message-ID: <7xy5lb9soz.fsf@ruckus.brouhaha.com> Chris Angelico writes: > And of course, taking the *entire* rest of the string isn't the only > thing you do. What if you want to take the next six characters after > that index? That would be constant time with a fixed-width storage > format. How often is this an issue in practice? I wonder how other languages deal with this. The examples I can think of are poor role models: 1. C/C++ - unicode impaired, other than a wchar type 2. Java - bogus UCS-2-like(?) representation for historical reasons Also has some modified UTF=8 for reasons that made no sense and that I don't remember 3. Haskell - basic string type is a linked list of code points. "hello" is five list nodes. New Data.Text library (much more efficient) uses something like ropes, I think, with UTF-16 underneath. 4. Erlang - I think like Haskell. Efficiently handles byte blocks. 5. Perl 6 -- ??? 6. Ruby - ??? (but probably quite slow like the rest of Ruby) 7. Objective C -- ??? 8, 9 ... (any other important ones?) From wxjmfauth at gmail.com Sun Aug 19 04:54:44 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 01:54:44 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xy5lb9soz.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> <7xy5lb9soz.fsf@ruckus.brouhaha.com> Message-ID: About the exemples contested by Steven: eg: timeit.timeit("('ab?' * 10).replace('?', '??')") And it is good enough to show the problem. Period. The rest (you have to do this, you should not do this, why are you using these characters - amazing and stupid question -) does not count. The real problem is elsewhere. *Americans* do not wish a character occupies 4 bytes in *their* memory. The rest of the world does not count. The same thing happens with the utf-8 coding scheme. Technically, it is fine. But after n years of usage, one should recognize it just became an ascii2. Especially for those who undestand nothing in that field and are not even aware, characters are "coded". I'm the first to think, this is legitimate. Memory or "ability to treat all text in the same and equal way"? End note. This kind of discussion is not specific to Python, it always happen when there is some kind of conflict between ascii and non ascii users. Have a nice day. jmf From breamoreboy at yahoo.co.uk Sun Aug 19 04:55:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 09:55:18 +0100 Subject: Encapsulation, inheritance and polymorphism In-Reply-To: References: <5006b48a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/08/2012 06:21, Robert Miles wrote: > On 7/23/2012 11:18 AM, Albert van der Horst wrote: >> In article <5006b48a$0$29978$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >> Even with a break, why bother continuing through the body of the >>> function >>> when you already have the result? When your calculation is done, it's >>> done, just return for goodness sake. You wouldn't write a search that >>> keeps going after you've found the value that you want, out of some >>> misplaced sense that you have to look at every value. Why write code >>> with >>> unnecessary guard values and temporary variables out of a misplaced >>> sense >>> that functions must only have one exit? >> >> Example from recipee's: >> >> Stirr until the egg white is stiff. >> >> Alternative: >> Stirr egg white for half an hour, >> but if the egg white is stiff keep your spoon still. >> >> (Cooking is not my field of expertise, so the wording may >> not be quite appropriate. ) >> >>> -- >>> Steven >> >> Groetjes Albert > > Note that you forgot applying enough heat to do the cooking. > > Surely the first check is your filing system to make sure that you've paid the utilties bills so you've got gas and or electricity to apply the heat. Either that or you hire Ray Mears to produce the spark needed to light the fire :) -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Sun Aug 19 04:56:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 08:56:36 GMT Subject: New internal string format in 3.3, was Re: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 09:43:13 +0200, Peter Otten wrote: > Steven D'Aprano wrote: >> I don't know where people are getting this myth that PEP 393 uses >> Latin-1 internally, it does not. Read the PEP, it explicitly states >> that 1-byte formats are only used for ASCII strings. > > From > > Python 3.3.0a4+ (default:10a8ad665749, Jun 9 2012, 08:57:51) [GCC > 4.6.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> [sys.getsizeof("?"*i) for i in range(10)] > [49, 74, 75, 76, 77, 78, 79, 80, 81, 82] Interesting. Say, I don't suppose you're using a 64-bit build? Because that would explain why your sizes are so larger than mine: py> [sys.getsizeof("?"*i) for i in range(10)] [25, 38, 39, 40, 41, 42, 43, 44, 45, 46] py> [sys.getsizeof("?"*i) for i in range(10)] [25, 40, 42, 44, 46, 48, 50, 52, 54, 56] py> c = chr(0xFFFF + 1) py> [sys.getsizeof(c*i) for i in range(10)] [25, 44, 48, 52, 56, 60, 64, 68, 72, 76] On re-reading the PEP more closely, it looks like I did misunderstand the internal implementation, and strings which fit exactly in Latin-1 will also use 1 byte per character. There are three structures used: PyASCIIObject PyCompactUnicodeObject PyUnicodeObject and the third one comes in three variant forms, for 1-byte, 2-byte and 4- byte data. So I stand corrected. -- Steven From rebekkamaries at googlemail.com Sun Aug 19 05:04:20 2012 From: rebekkamaries at googlemail.com (Rebekka-Marie) Date: Sun, 19 Aug 2012 02:04:20 -0700 (PDT) Subject: Branch and Bound Algorithm / Module for Python? Message-ID: <4a2d7df3-7415-4c4b-82de-856190b296ce@googlegroups.com> Hello everybody, I would like to solve a Mixed Integer Optimization Problem with the Branch-And-Bound Algorithm. I designed my Minimizing function and the constraints. I tested them in a small program in AIMMS. So I already know that they are solvable. Now I want to solve them using Python. Is there a module / methods that I can download or a ready-made program text that you know about, where I can put my constraints and minimization function in? Rebekka From wxjmfauth at gmail.com Sun Aug 19 05:24:04 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 02:24:04 -0700 (PDT) Subject: New internal string format in 3.3, was Re: How do I display unicode value stored in a string variable using ord() In-Reply-To: <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <729f511f-c6d7-46c8-adbd-94957d8f6ab6@googlegroups.com> Le dimanche 19 ao?t 2012 10:56:36 UTC+2, Steven D'Aprano a ?crit?: > > internal implementation, and strings which fit exactly in Latin-1 will > And this is the crucial point. latin-1 is an obsolete and non usable coding scheme (esp. for european languages). We fall on the point I mentionned above. Microsoft know this, ditto for Apple, ditto for "TeX", ditto for the foundries. Even, "ISO" has recognized its error and produced iso-8859-15. The question? Why is it still used? jmf From __peter__ at web.de Sun Aug 19 05:37:09 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Aug 2012 11:37:09 +0200 Subject: New internal string format in 3.3 References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 19 Aug 2012 09:43:13 +0200, Peter Otten wrote: > >> Steven D'Aprano wrote: > >>> I don't know where people are getting this myth that PEP 393 uses >>> Latin-1 internally, it does not. Read the PEP, it explicitly states >>> that 1-byte formats are only used for ASCII strings. >> >> From >> >> Python 3.3.0a4+ (default:10a8ad665749, Jun 9 2012, 08:57:51) [GCC >> 4.6.1] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import sys >>>>> [sys.getsizeof("?"*i) for i in range(10)] >> [49, 74, 75, 76, 77, 78, 79, 80, 81, 82] > > Interesting. Say, I don't suppose you're using a 64-bit build? Because > that would explain why your sizes are so larger than mine: > > py> [sys.getsizeof("?"*i) for i in range(10)] > [25, 38, 39, 40, 41, 42, 43, 44, 45, 46] > > > py> [sys.getsizeof("?"*i) for i in range(10)] > [25, 40, 42, 44, 46, 48, 50, 52, 54, 56] Yes, I am using a 64-bit build. I thought that >> (2) Latin1 strings have a constant overhead of 24 bytes (on a 64bit >> system) over ASCII-only. would convey that. The corresponding data structure typedef struct { PyASCIIObject _base; Py_ssize_t utf8_length; char *utf8; Py_ssize_t wstr_length; } PyCompactUnicodeObject; makes for 12 extra bytes on 32 bit, and both Py_ssize_t and pointers double in size (from 4 to 8 bytes) on 64 bit. I'm sure you can do the maths for the embedded PyASCIIObject yourself. From steve+comp.lang.python at pearwood.info Sun Aug 19 06:04:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 10:04:37 GMT Subject: Branch and Bound Algorithm / Module for Python? References: <4a2d7df3-7415-4c4b-82de-856190b296ce@googlegroups.com> Message-ID: <5030ba34$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 02:04:20 -0700, Rebekka-Marie wrote: > I would like to solve a Mixed Integer Optimization Problem with the > Branch-And-Bound Algorithm. [...] > Is there a module / methods that I can download or a ready-made program > text that you know about, where I can put my constraints and > minimization function in? Sounds like it might be something from Numpy or Scipy? http://numpy.scipy.org/ http://www.scipy.org/ This might be useful too: http://telliott99.blogspot.com.au/2010/03/branch-and-bound.html Good luck! If you do find something, come back and tell us please. -- Steven From lipskathekat at yahoo.co.uk Sun Aug 19 06:13:11 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Sun, 19 Aug 2012 11:13:11 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/08/12 07:09, Steven D'Aprano wrote: > This is a long post. If you don't feel like reading an essay, skip to the > very bottom and read my last few paragraphs, starting with "To recap". Thank you for this excellent post, it has certainly cleared up a few things for me [snip] incidentally > But in UTF-16, ... [snip] > py> s = chr(0xFFFF + 1) > py> a, b = s > py> a > '\ud800' > py> b > '\udc00' in IDLE Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "copyright", "credits" or "license()" for more information. ==== No Subprocess ==== >>> s = chr(0xFFFF + 1) >>> a, b = s Traceback (most recent call last): File "", line 1, in a, b = s ValueError: need more than 1 value to unpack At a terminal prompt [lipska at ubuntu ~]$ python3.2 Python 3.2.3 (default, Jul 17 2012, 14:23:10) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = chr(0xFFFF + 1) >>> a, b = s >>> a '\ud800' >>> b '\udc00' >>> The date stamp is different but the Python version is the same No idea why this is happening, I just thought it was interesting lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From rosuav at gmail.com Sun Aug 19 06:19:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 20:19:11 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 19, 2012 at 8:13 PM, lipska the kat wrote: > The date stamp is different but the Python version is the same Check out what 'sys.maxunicode' is in each of those Pythons. It's possible that one is a wide build and the other narrow. ChrisA From wxjmfauth at gmail.com Sun Aug 19 06:19:23 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 03:19:23 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> Le dimanche 19 ao?t 2012 11:37:09 UTC+2, Peter Otten a ?crit?: You know, the techincal aspect is one thing. Understanding the coding of the characters as a whole is something else. The important point is not the coding per se, the relevant point is the set of characters a coding may represent. You can build the most sophisticated mechanism you which, if it does not take that point into account, it will always fail or be not optimal. This is precicely the weak point of this flexible representation. It uses latin-1 and latin-1 is for most users simply unusable. Fascinating, isn't it? Devs are developing sophisticed tools based on a non working basis. jmf From wxjmfauth at gmail.com Sun Aug 19 06:19:23 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 03:19:23 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> Le dimanche 19 ao?t 2012 11:37:09 UTC+2, Peter Otten a ?crit?: You know, the techincal aspect is one thing. Understanding the coding of the characters as a whole is something else. The important point is not the coding per se, the relevant point is the set of characters a coding may represent. You can build the most sophisticated mechanism you which, if it does not take that point into account, it will always fail or be not optimal. This is precicely the weak point of this flexible representation. It uses latin-1 and latin-1 is for most users simply unusable. Fascinating, isn't it? Devs are developing sophisticed tools based on a non working basis. jmf From rosuav at gmail.com Sun Aug 19 06:26:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Aug 2012 20:26:44 +1000 Subject: New internal string format in 3.3 In-Reply-To: <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> Message-ID: On Sun, Aug 19, 2012 at 8:19 PM, wrote: > This is precicely the weak point of this flexible > representation. It uses latin-1 and latin-1 is for > most users simply unusable. No, it uses Unicode, and as an optimization, attempts to store the codepoints in less than four bytes for most strings. The fact that a one-byte storage format happens to look like latin-1 is rather coincidental. ChrisA From breamoreboy at yahoo.co.uk Sun Aug 19 06:39:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 11:39:49 +0100 Subject: Branch and Bound Algorithm / Module for Python? In-Reply-To: <5030ba34$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4a2d7df3-7415-4c4b-82de-856190b296ce@googlegroups.com> <5030ba34$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/08/2012 11:04, Steven D'Aprano wrote: > On Sun, 19 Aug 2012 02:04:20 -0700, Rebekka-Marie wrote: > >> I would like to solve a Mixed Integer Optimization Problem with the >> Branch-And-Bound Algorithm. > [...] >> Is there a module / methods that I can download or a ready-made program >> text that you know about, where I can put my constraints and >> minimization function in? > > Sounds like it might be something from Numpy or Scipy? > > http://numpy.scipy.org/ > http://www.scipy.org/ > > > This might be useful too: > > http://telliott99.blogspot.com.au/2010/03/branch-and-bound.html > > > Good luck! If you do find something, come back and tell us please. > > In addition to the above there's always the Python Package Index at http://pypi.python.org/pypi -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sun Aug 19 06:46:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 11:46:14 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> <7xy5lb9soz.fsf@ruckus.brouhaha.com> Message-ID: On 19/08/2012 09:54, wxjmfauth at gmail.com wrote: > About the exemples contested by Steven: > > eg: timeit.timeit("('ab?' * 10).replace('?', '??')") > > > And it is good enough to show the problem. Period. The > rest (you have to do this, you should not do this, why > are you using these characters - amazing and stupid > question -) does not count. > > The real problem is elsewhere. *Americans* do not wish > a character occupies 4 bytes in *their* memory. The rest > of the world does not count. > > The same thing happens with the utf-8 coding scheme. > Technically, it is fine. But after n years of usage, > one should recognize it just became an ascii2. Especially > for those who undestand nothing in that field and are > not even aware, characters are "coded". I'm the first > to think, this is legitimate. > > Memory or "ability to treat all text in the same and equal > way"? > > End note. This kind of discussion is not specific to > Python, it always happen when there is some kind of > conflict between ascii and non ascii users. > > Have a nice day. > > jmf > Roughly translated. "I've been shot to pieces and having seen Monty Python and the Holy Grail I know what to do. Run away, run away" -- Cheers. Mark Lawrence. From lipskathekat at yahoo.co.uk Sun Aug 19 06:49:21 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Sun, 19 Aug 2012 11:49:21 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/08/12 11:19, Chris Angelico wrote: > On Sun, Aug 19, 2012 at 8:13 PM, lipska the kat > wrote: >> The date stamp is different but the Python version is the same > > Check out what 'sys.maxunicode' is in each of those Pythons. It's > possible that one is a wide build and the other narrow. Ah ... I built my local version from source and no, I didn't read the makefile so I didn't configure for a wide build :-( not that I would have known the difference at that time. [lipska at ubuntu ~]$ python3.2 Python 3.2.3 (default, Jul 17 2012, 14:23:10) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.maxunicode 65535 >>> Later, I did an apt-get install idle3 which pulled down a precompiled IDLE from the Ubuntu repos This was obviously compiled 'wide' Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6.3] on linux2 Type "copyright", "credits" or "license()" for more information. ==== No Subprocess ==== >>> import sys >>> sys.maxunicode 1114111 >>> All very interesting and enlightening Thanks lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From steve+comp.lang.python at pearwood.info Sun Aug 19 06:51:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 10:51:26 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> Message-ID: <5030c52d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 01:11:56 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> result = text[end:] > > if end not near the end of the original string, then this is O(N) even > with fixed-width representation, because of the char copying. Technically, yes. But it's a straight copy of a chunk of memory, which means it's fast: your OS and hardware tries to make straight memory copies as fast as possible. Big-Oh analysis frequently glosses over implementation details like that. Of course, that assumption gets shaky when you start talking about extra large blocks, and it falls apart completely when your OS starts paging memory to disk. But if it helps to avoid irrelevant technical details, change it to text[end:end+10] or something. > if it is near the end, by knowing where the string data area ends, I > think it should be possible to scan backwards from the end, recognizing > what bytes can be the beginning of code points and counting off the > appropriate number. This is O(1) if "near the end" means "within a > constant". You know, I think you are misusing Big-Oh analysis here. It really wouldn't be helpful for me to say "Bubble Sort is O(1) if you only sort lists with a single item". Well, yes, that is absolutely true, but that's a special case that doesn't give you any insight into why using Bubble Sort as your general purpose sort routine is a terrible idea. Using variable-sized strings like UTF-8 and UTF-16 for in-memory representations is a terrible idea because you can't assume that people will only every want to index the first or last character. On average, you need to scan half the string, one character at a time. In Big-Oh, we can ignore the factor of 1/2 and just say we scan the string, O(N). That's why languages tend to use fixed character arrays for strings. Haskell is an exception, using linked lists which require traversing the string to jump to an index. The manual even warns: [quote] If you think of a Text value as an array of Char values (which it is not), you run the risk of writing inefficient code. An idiom that is common in some languages is to find the numeric offset of a character or substring, then use that number to split or trim the searched string. With a Text value, this approach would require two O(n) operations: one to perform the search, and one to operate from wherever the search ended. [end quote] http://hackage.haskell.org/packages/archive/text/0.11.2.2/doc/html/Data-Text.html -- Steven From lipskathekat at yahoo.co.uk Sun Aug 19 07:50:51 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Sun, 19 Aug 2012 12:50:51 +0100 Subject: Encapsulation, inheritance and polymorphism In-Reply-To: References: <5006b48a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0cKdnbVR39CGTq3NnZ2dnUVZ8jWdnZ2d@bt.com> On 19/08/12 09:55, Mark Lawrence wrote: > On 19/08/2012 06:21, Robert Miles wrote: >> On 7/23/2012 11:18 AM, Albert van der Horst wrote: >>> In article <5006b48a$0$29978$c3e8da3$5496439d at news.astraweb.com>, >>> Steven D'Aprano wrote: [snip] >>>> that functions must only have one exit? [snip[ > > Surely the first check is your filing system to make sure that you've > paid the utilties bills so you've got gas and or electricity to apply > the heat. Either that or you hire Ray Mears to produce the spark needed > to light the fire :) I was wondering how long it would be ... lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From breamoreboy at yahoo.co.uk Sun Aug 19 08:06:52 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 13:06:52 +0100 Subject: Encapsulation, inheritance and polymorphism In-Reply-To: <0cKdnbVR39CGTq3NnZ2dnUVZ8jWdnZ2d@bt.com> References: <5006b48a$0$29978$c3e8da3$5496439d@news.astraweb.com> <0cKdnbVR39CGTq3NnZ2dnUVZ8jWdnZ2d@bt.com> Message-ID: On 19/08/2012 12:50, lipska the kat wrote: > On 19/08/12 09:55, Mark Lawrence wrote: >> On 19/08/2012 06:21, Robert Miles wrote: >>> On 7/23/2012 11:18 AM, Albert van der Horst wrote: >>>> In article <5006b48a$0$29978$c3e8da3$5496439d at news.astraweb.com>, >>>> Steven D'Aprano wrote: > > [snip] > >>>>> that functions must only have one exit? > > [snip[ > >> >> Surely the first check is your filing system to make sure that you've >> paid the utilties bills so you've got gas and or electricity to apply >> the heat. Either that or you hire Ray Mears to produce the spark needed >> to light the fire :) > > I was wondering how long it would be ... > > lipska > Six days shalt thou labour... :) -- Cheers. Mark Lawrence. From wxjmfauth at gmail.com Sun Aug 19 08:14:21 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 05:14:21 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> Message-ID: <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Le dimanche 19 ao?t 2012 12:26:44 UTC+2, Chris Angelico a ?crit?: > On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > > This is precicely the weak point of this flexible > > > representation. It uses latin-1 and latin-1 is for > > > most users simply unusable. > > > > No, it uses Unicode, and as an optimization, attempts to store the > > codepoints in less than four bytes for most strings. The fact that a > > one-byte storage format happens to look like latin-1 is rather > > coincidental. > And this this is the common basic mistake. You do not push your argumentation far enough. A character may "fall" accidentally in a latin-1. The problem lies in these european characters, which can not fall in this coding. This *is* the cause of the negative side effects. If you are using a correct coding scheme, like cp1252, mac-roman or iso-8859-15, you will never see such a negative side effect. Again, the problem is not the result, the encoded character. The critical part is the character which may cause this side effect. You should think "character set" and not encoded "code point", considering this kind of expression has a sense in 8-bits coding scheme. jmf From wxjmfauth at gmail.com Sun Aug 19 08:14:21 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 05:14:21 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> Message-ID: <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Le dimanche 19 ao?t 2012 12:26:44 UTC+2, Chris Angelico a ?crit?: > On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > > This is precicely the weak point of this flexible > > > representation. It uses latin-1 and latin-1 is for > > > most users simply unusable. > > > > No, it uses Unicode, and as an optimization, attempts to store the > > codepoints in less than four bytes for most strings. The fact that a > > one-byte storage format happens to look like latin-1 is rather > > coincidental. > And this this is the common basic mistake. You do not push your argumentation far enough. A character may "fall" accidentally in a latin-1. The problem lies in these european characters, which can not fall in this coding. This *is* the cause of the negative side effects. If you are using a correct coding scheme, like cp1252, mac-roman or iso-8859-15, you will never see such a negative side effect. Again, the problem is not the result, the encoded character. The critical part is the character which may cause this side effect. You should think "character set" and not encoded "code point", considering this kind of expression has a sense in 8-bits coding scheme. jmf From d at davea.name Sun Aug 19 08:29:17 2012 From: d at davea.name (Dave Angel) Date: Sun, 19 Aug 2012 08:29:17 -0400 Subject: New internal string format in 3.3 In-Reply-To: <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Message-ID: <5030DC1D.6030903@davea.name> On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > Le dimanche 19 ao?t 2012 12:26:44 UTC+2, Chris Angelico a ?crit : >> On Sun, Aug 19, 2012 at 8:19 PM, wrote: >> >>> This is precicely the weak point of this flexible >>> representation. It uses latin-1 and latin-1 is for >>> most users simply unusable. >> >> >> No, it uses Unicode, and as an optimization, attempts to store the >> >> codepoints in less than four bytes for most strings. The fact that a >> >> one-byte storage format happens to look like latin-1 is rather >> >> coincidental. >> > And this this is the common basic mistake. You do not push your > argumentation far enough. A character may "fall" accidentally in a latin-1. > The problem lies in these european characters, which can not fall in this > coding. This *is* the cause of the negative side effects. > If you are using a correct coding scheme, like cp1252, mac-roman or > iso-8859-15, you will never see such a negative side effect. > Again, the problem is not the result, the encoded character. The critical > part is the character which may cause this side effect. > You should think "character set" and not encoded "code point", considering > this kind of expression has a sense in 8-bits coding scheme. > > jmf But that choice was made decades ago when Unicode picked its second 128 characters. The internal form used in this PEP is simply the low-order byte of the Unicode code point. Trying to scan the string deciding if converting to cp1252 (for example) would be a much more expensive operation than seeing how many bytes it'd take for the largest code point. -- DaveA From d at davea.name Sun Aug 19 08:35:23 2012 From: d at davea.name (Dave Angel) Date: Sun, 19 Aug 2012 08:35:23 -0400 Subject: New internal string format in 3.3 In-Reply-To: <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Message-ID: <5030DD8B.3000805@davea.name> (pardon the resend, but I accidentally omitted a couple of words) On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > Le dimanche 19 ao?t 2012 12:26:44 UTC+2, Chris Angelico a ?crit : >> >> >> >> No, it uses Unicode, and as an optimization, attempts to store the >> codepoints in less than four bytes for most strings. The fact that a >> one-byte storage format happens to look like latin-1 is rather >> coincidental. >> > And this this is the common basic mistake. You do not push your > argumentation far enough. A character may "fall" accidentally in a latin-1. > The problem lies in these european characters, which can not fall in this > coding. This *is* the cause of the negative side effects. > If you are using a correct coding scheme, like cp1252, mac-roman or > iso-8859-15, you will never see such a negative side effect. > Again, the problem is not the result, the encoded character. The critical > part is the character which may cause this side effect. > You should think "character set" and not encoded "code point", considering > this kind of expression has a sense in 8-bits coding scheme. > > jmf But that choice was made decades ago when Unicode picked its second 128 characters. The internal form used in this PEP is simply the low-order byte of the Unicode code point. Trying to scan the string deciding if converting to cp1252 (for example) would work, would be a much more expensive operation than seeing how many bytes it'd take for the largest code point. The 8 bit form is used if all the code points are less than 256. That is a simple description, and simple code. As several people have said, the fact that this byte matches on of the DECODED forms is coincidence. -- DaveA From python at bdurham.com Sun Aug 19 08:43:19 2012 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Aug 2012 08:43:19 -0400 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1345380199.15284.140661116740237.1427F643@webmail.messagingengine.com> Hi Steve, > I don't think I'm some sort of hyper-evolved mega-genius with a brain the size of a planet, I'm just some guy. Based on reading thousands of your posts over the past 4 years, I'll have to respectfully disagree with you on your assertion that you are not some hyper-evolved genius with a brain the size of a planet. :) I've learned a ton from reading your posts - so much so that I think my brain is getting heavier[1]. Thank you and cheers! Malcolm >From a recent thread on this mailing list (hilarious) http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html From wxjmfauth at gmail.com Sun Aug 19 08:59:51 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 05:59:51 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Message-ID: <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Le dimanche 19 ao?t 2012 14:29:17 UTC+2, Dave Angel a ?crit?: > On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > > > Le dimanche 19 ao???t 2012 12:26:44 UTC+2, Chris Angelico a ???crit : > > >> On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > >> > > >>> This is precicely the weak point of this flexible > > >>> representation. It uses latin-1 and latin-1 is for > > >>> most users simply unusable. > > >> > > >> > > >> No, it uses Unicode, and as an optimization, attempts to store the > > >> > > >> codepoints in less than four bytes for most strings. The fact that a > > >> > > >> one-byte storage format happens to look like latin-1 is rather > > >> > > >> coincidental. > > >> > > > And this this is the common basic mistake. You do not push your > > > argumentation far enough. A character may "fall" accidentally in a latin-1. > > > The problem lies in these european characters, which can not fall in this > > > coding. This *is* the cause of the negative side effects. > > > If you are using a correct coding scheme, like cp1252, mac-roman or > > > iso-8859-15, you will never see such a negative side effect. > > > Again, the problem is not the result, the encoded character. The critical > > > part is the character which may cause this side effect. > > > You should think "character set" and not encoded "code point", considering > > > this kind of expression has a sense in 8-bits coding scheme. > > > > > > jmf > > > > But that choice was made decades ago when Unicode picked its second 128 > > characters. The internal form used in this PEP is simply the low-order > > byte of the Unicode code point. Trying to scan the string deciding if > > converting to cp1252 (for example) would be a much more expensive > > operation than seeing how many bytes it'd take for the largest code point. > > You are absoletely right. (I'm quite comfortable with Unicode). If Python wish to perpetuate this, lets call it, design mistake or ennoyement, it will continue to live with problems. People (tools) who chose pure utf-16 or utf-32 are not suffering from this issue. *My* final comment on this thread. In August 2012, after 20 years of development, Python is not able to display a piece of text correctly on a Windows console (eg cp65001). I downloaded the go language, zero experience, I did not succeed to display incorrecly a piece of text. (This is by the way *the* reason why I tested it). Where the problems are coming from, I have no idea. I find this situation quite comic. Python is able to produce this: >>> (1.1).hex() '0x1.199999999999ap+0' but it is not able to display a piece of text! Try to convince end users IEEE 754 is more important than the ability to read/wirite a piece a text, a 6-years kid has learned at school :-) (I'm not suffering from this kind of effect, as a Windows user, I'm always working via gui, it still remains, the problem exists. Regards, jmf From wxjmfauth at gmail.com Sun Aug 19 08:59:51 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 05:59:51 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> Message-ID: <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Le dimanche 19 ao?t 2012 14:29:17 UTC+2, Dave Angel a ?crit?: > On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > > > Le dimanche 19 ao???t 2012 12:26:44 UTC+2, Chris Angelico a ???crit : > > >> On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > >> > > >>> This is precicely the weak point of this flexible > > >>> representation. It uses latin-1 and latin-1 is for > > >>> most users simply unusable. > > >> > > >> > > >> No, it uses Unicode, and as an optimization, attempts to store the > > >> > > >> codepoints in less than four bytes for most strings. The fact that a > > >> > > >> one-byte storage format happens to look like latin-1 is rather > > >> > > >> coincidental. > > >> > > > And this this is the common basic mistake. You do not push your > > > argumentation far enough. A character may "fall" accidentally in a latin-1. > > > The problem lies in these european characters, which can not fall in this > > > coding. This *is* the cause of the negative side effects. > > > If you are using a correct coding scheme, like cp1252, mac-roman or > > > iso-8859-15, you will never see such a negative side effect. > > > Again, the problem is not the result, the encoded character. The critical > > > part is the character which may cause this side effect. > > > You should think "character set" and not encoded "code point", considering > > > this kind of expression has a sense in 8-bits coding scheme. > > > > > > jmf > > > > But that choice was made decades ago when Unicode picked its second 128 > > characters. The internal form used in this PEP is simply the low-order > > byte of the Unicode code point. Trying to scan the string deciding if > > converting to cp1252 (for example) would be a much more expensive > > operation than seeing how many bytes it'd take for the largest code point. > > You are absoletely right. (I'm quite comfortable with Unicode). If Python wish to perpetuate this, lets call it, design mistake or ennoyement, it will continue to live with problems. People (tools) who chose pure utf-16 or utf-32 are not suffering from this issue. *My* final comment on this thread. In August 2012, after 20 years of development, Python is not able to display a piece of text correctly on a Windows console (eg cp65001). I downloaded the go language, zero experience, I did not succeed to display incorrecly a piece of text. (This is by the way *the* reason why I tested it). Where the problems are coming from, I have no idea. I find this situation quite comic. Python is able to produce this: >>> (1.1).hex() '0x1.199999999999ap+0' but it is not able to display a piece of text! Try to convince end users IEEE 754 is more important than the ability to read/wirite a piece a text, a 6-years kid has learned at school :-) (I'm not suffering from this kind of effect, as a Windows user, I'm always working via gui, it still remains, the problem exists. Regards, jmf From steve+comp.lang.python at pearwood.info Sun Aug 19 09:25:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 13:25:14 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: <5030e939$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 01:04:25 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> This standard data structure is called UCS-2 ... There's an extension >> to UCS-2 called UTF-16 > > My own understanding is UCS-2 simply shouldn't be used any more. Pretty much. But UTF-16 with lax support for surrogates (that is, surrogates are included but treated as two characters) is essentially UCS-2 with the restriction against surrogates lifted. That's what Python currently does, and Javascript. http://mathiasbynens.be/notes/javascript-encoding The reality is that support for the Unicode supplementary planes is pretty poor. Even when applications support it, most fonts don't have glyphs for the characters. Anything which makes handling of Unicode supplementary characters better is a step forward. >> * Variable-byte formats like UTF-8 and UTF-16 mean that basic string >> operations are not O(1) but are O(N). That means they are slow, or >> buggy, pick one. > > This I don't see. What are the basic string operations? The ones I'm specifically referring to are indexing and copying substrings. There may be others. > * Examine the first character, or first few characters ("few" = "usually > bounded by a small constant") such as to parse a token from an input > stream. This is O(1) with either encoding. That's actually O(K), for K = "a few", whatever "a few" means. But we know that anything is fast for small enough N (or K in this case). > * Slice off the first N characters. This is O(N) with either encoding > if it involves copying the chars. I guess you could share references > into the same string, but if the slice reference persists while the > big reference is released, you end up not freeing the memory until > later than you really should. As a first approximation, memory copying is assumed to be free, or at least constant time. That's not strictly true, but Big Oh analysis is looking at algorithmic complexity. It's not a substitute for actual benchmarks. > Meanwhile, an example of the 393 approach failing: I was involved in a > project that dealt with terabytes of OCR data of mostly English text. I assume that this wasn't one giant multi-terrabyte string. > So > the chars were mostly ascii, but there would be occasional non-ascii > chars including supplementary plane characters, either because of > special symbols that were really in the text, or the typical OCR > confusion emitting those symbols due to printing imprecision. That's a > natural for UTF-8 but the PEP-393 approach would bloat up the memory > requirements by a factor of 4. Not necessarily. Presumably you're scanning each page into a single string. Then only the pages containing a supplementary plane char will be bloated, which is likely to be rare. Especially since I don't expect your OCR application would recognise many non-BMP characters -- what does U+110F3, "SORA SOMPENG DIGIT THREE", look like? If the OCR software doesn't recognise it, you can't get it in your output. (If you do, the OCR software has a nasty bug.) Anyway, in my ignorant opinion the proper fix here is to tell the OCR software not to bother trying to recognise Imperial Aramaic, Domino Tiles, Phaistos Disc symbols, or Egyptian Hieroglyphs if you aren't expecting them in your source material. Not only will the scanning go faster, but you'll get fewer wrong characters. [...] > I realize the folks who designed and implemented PEP 393 are very smart > cookies and considered stuff carefully, while I'm just an internet user > posting an immediate impression of something I hadn't seen before (I > still use Python 2.6), but I still have to ask: if the 393 approach > makes sense, why don't other languages do it? There has to be a first time for everything. > Ropes of UTF-8 segments seems like the most obvious approach and I > wonder if it was considered. Ropes have been considered and rejected because while they are asymptotically fast, in common cases the added complexity actually makes them slower. Especially for immutable strings where you aren't inserting into the middle of a string. http://mail.python.org/pipermail/python-dev/2000-February/002321.html PyPy has revisited ropes and uses, or at least used, ropes as their native string data structure. But that's ropes of *bytes*, not UTF-8. http://morepypy.blogspot.com.au/2007/11/ropes-branch-merged.html -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 09:33:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 13:33:05 GMT Subject: New internal string format in 3.3 References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5030eb10$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 03:19:23 -0700, wxjmfauth wrote: > This is precicely the weak point of this flexible representation. It > uses latin-1 and latin-1 is for most users simply unusable. That's very funny. Are you aware that your post is entirely Latin-1? > Fascinating, isn't it? Devs are developing sophisticed tools based on a > non working basis. At the end of the day, PEP 393 fixes some major design limitations of the Unicode implementation in the "narrow build" Python, while saving memory for people using the "wide build". Everybody wins here. Your objection appears to be based on some sort of philosophical objection to Latin-1 than on any genuine problem. -- Steven From breamoreboy at yahoo.co.uk Sun Aug 19 09:46:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 14:46:34 +0100 Subject: New internal string format in 3.3 In-Reply-To: <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> References: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On 19/08/2012 13:59, wxjmfauth at gmail.com wrote: > Le dimanche 19 ao?t 2012 14:29:17 UTC+2, Dave Angel a ?crit : >> On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: >> >>> Le dimanche 19 ao???t 2012 12:26:44 UTC+2, Chris Angelico a ???crit : >> >>>> On Sun, Aug 19, 2012 at 8:19 PM, wrote: >> >>>> >> >>>>> This is precicely the weak point of this flexible >> >>>>> representation. It uses latin-1 and latin-1 is for >> >>>>> most users simply unusable. >> >>>> >> >>>> >> >>>> No, it uses Unicode, and as an optimization, attempts to store the >> >>>> >> >>>> codepoints in less than four bytes for most strings. The fact that a >> >>>> >> >>>> one-byte storage format happens to look like latin-1 is rather >> >>>> >> >>>> coincidental. >> >>>> >> >>> And this this is the common basic mistake. You do not push your >> >>> argumentation far enough. A character may "fall" accidentally in a latin-1. >> >>> The problem lies in these european characters, which can not fall in this >> >>> coding. This *is* the cause of the negative side effects. >> >>> If you are using a correct coding scheme, like cp1252, mac-roman or >> >>> iso-8859-15, you will never see such a negative side effect. >> >>> Again, the problem is not the result, the encoded character. The critical >> >>> part is the character which may cause this side effect. >> >>> You should think "character set" and not encoded "code point", considering >> >>> this kind of expression has a sense in 8-bits coding scheme. >> >>> >> >>> jmf >> >> >> >> But that choice was made decades ago when Unicode picked its second 128 >> >> characters. The internal form used in this PEP is simply the low-order >> >> byte of the Unicode code point. Trying to scan the string deciding if >> >> converting to cp1252 (for example) would be a much more expensive >> >> operation than seeing how many bytes it'd take for the largest code point. >> >> > > You are absoletely right. (I'm quite comfortable with Unicode). > If Python wish to perpetuate this, lets call it, design mistake > or ennoyement, it will continue to live with problems. Please give a precise description of the design mistake and what you would do to correct it. > > People (tools) who chose pure utf-16 or utf-32 are not suffering > from this issue. > > *My* final comment on this thread. > > In August 2012, after 20 years of development, Python is not > able to display a piece of text correctly on a Windows console > (eg cp65001). Examples please. > > I downloaded the go language, zero experience, I did not succeed > to display incorrecly a piece of text. (This is by the way *the* > reason why I tested it). Where the problems are coming from, I have > no idea. > > I find this situation quite comic. Python is able to > produce this: > >>>> (1.1).hex() > '0x1.199999999999ap+0' > > but it is not able to display a piece of text! So you keep saying, but when asked for examples or evidence nothing gets produced. > > Try to convince end users IEEE 754 is more important than the > ability to read/wirite a piece a text, a 6-years kid has learned > at school :-) > > (I'm not suffering from this kind of effect, as a Windows user, > I'm always working via gui, it still remains, the problem exists. Windows is a law unto itself. Its problems are hardly specific to Python. > > Regards, > jmf > Now two or three times you've said you're going but have come back. If you come again could you please provide examples and or evidence of what you're on about, because you still have me baffled. -- Cheers. Mark Lawrence. From wxjmfauth at gmail.com Sun Aug 19 10:09:14 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 07:09:14 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: Le dimanche 19 ao?t 2012 15:46:34 UTC+2, Mark Lawrence a ?crit?: > On 19/08/2012 13:59, wxjmfauth at gmail.com wrote: > > > Le dimanche 19 ao???t 2012 14:29:17 UTC+2, Dave Angel a ???crit : > > >> On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > > >> > > >>> Le dimanche 19 ao???t 2012 12:26:44 UTC+2, Chris Angelico a ???crit : > > >> > > >>>> On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > >> > > >>>> > > >> > > >>>>> This is precicely the weak point of this flexible > > >> > > >>>>> representation. It uses latin-1 and latin-1 is for > > >> > > >>>>> most users simply unusable. > > >> > > >>>> > > >> > > >>>> > > >> > > >>>> No, it uses Unicode, and as an optimization, attempts to store the > > >> > > >>>> > > >> > > >>>> codepoints in less than four bytes for most strings. The fact that a > > >> > > >>>> > > >> > > >>>> one-byte storage format happens to look like latin-1 is rather > > >> > > >>>> > > >> > > >>>> coincidental. > > >> > > >>>> > > >> > > >>> And this this is the common basic mistake. You do not push your > > >> > > >>> argumentation far enough. A character may "fall" accidentally in a latin-1. > > >> > > >>> The problem lies in these european characters, which can not fall in this > > >> > > >>> coding. This *is* the cause of the negative side effects. > > >> > > >>> If you are using a correct coding scheme, like cp1252, mac-roman or > > >> > > >>> iso-8859-15, you will never see such a negative side effect. > > >> > > >>> Again, the problem is not the result, the encoded character. The critical > > >> > > >>> part is the character which may cause this side effect. > > >> > > >>> You should think "character set" and not encoded "code point", considering > > >> > > >>> this kind of expression has a sense in 8-bits coding scheme. > > >> > > >>> > > >> > > >>> jmf > > >> > > >> > > >> > > >> But that choice was made decades ago when Unicode picked its second 128 > > >> > > >> characters. The internal form used in this PEP is simply the low-order > > >> > > >> byte of the Unicode code point. Trying to scan the string deciding if > > >> > > >> converting to cp1252 (for example) would be a much more expensive > > >> > > >> operation than seeing how many bytes it'd take for the largest code point. > > >> > > >> > > > > > > You are absoletely right. (I'm quite comfortable with Unicode). > > > If Python wish to perpetuate this, lets call it, design mistake > > > or ennoyement, it will continue to live with problems. > > > > Please give a precise description of the design mistake and what you > > would do to correct it. > > > > > > > > People (tools) who chose pure utf-16 or utf-32 are not suffering > > > from this issue. > > > > > > *My* final comment on this thread. > > > > > > In August 2012, after 20 years of development, Python is not > > > able to display a piece of text correctly on a Windows console > > > (eg cp65001). > > > > Examples please. > > > > > > > > I downloaded the go language, zero experience, I did not succeed > > > to display incorrecly a piece of text. (This is by the way *the* > > > reason why I tested it). Where the problems are coming from, I have > > > no idea. > > > > > > I find this situation quite comic. Python is able to > > > produce this: > > > > > >>>> (1.1).hex() > > > '0x1.199999999999ap+0' > > > > > > but it is not able to display a piece of text! > > > > So you keep saying, but when asked for examples or evidence nothing gets > > produced. > > > > > > > > Try to convince end users IEEE 754 is more important than the > > > ability to read/wirite a piece a text, a 6-years kid has learned > > > at school :-) > > > > > > (I'm not suffering from this kind of effect, as a Windows user, > > > I'm always working via gui, it still remains, the problem exists. > > > > Windows is a law unto itself. Its problems are hardly specific to Python. > > > > > > > > Regards, > > > jmf > > > > > > > Now two or three times you've said you're going but have come back. If > > you come again could you please provide examples and or evidence of what > > you're on about, because you still have me baffled. > > > > -- > > Cheers. > > > > Mark Lawrence. Yesterday, I went to bed. More seriously. I can not give you more numbers than those I gave. As a end user, I noticed and experimented my random tests are always slower in Py3.3 than in Py3.2 on my Windows platform. It is up to you, the core developers to give an explanation about this behaviour. As I understand a little bit the coding of the characters, I pointed out, this is most probably due to this flexible string representation (with arguments appearing randomly in the misc. messages, mainly latin-1). I can not do more. (I stupidly spoke about factors 0.1 to ..., you should read of course, 1.1, to ...) jmf From wxjmfauth at gmail.com Sun Aug 19 10:09:14 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 07:09:14 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: Le dimanche 19 ao?t 2012 15:46:34 UTC+2, Mark Lawrence a ?crit?: > On 19/08/2012 13:59, wxjmfauth at gmail.com wrote: > > > Le dimanche 19 ao???t 2012 14:29:17 UTC+2, Dave Angel a ???crit : > > >> On 08/19/2012 08:14 AM, wxjmfauth at gmail.com wrote: > > >> > > >>> Le dimanche 19 ao???t 2012 12:26:44 UTC+2, Chris Angelico a ???crit : > > >> > > >>>> On Sun, Aug 19, 2012 at 8:19 PM, wrote: > > >> > > >>>> > > >> > > >>>>> This is precicely the weak point of this flexible > > >> > > >>>>> representation. It uses latin-1 and latin-1 is for > > >> > > >>>>> most users simply unusable. > > >> > > >>>> > > >> > > >>>> > > >> > > >>>> No, it uses Unicode, and as an optimization, attempts to store the > > >> > > >>>> > > >> > > >>>> codepoints in less than four bytes for most strings. The fact that a > > >> > > >>>> > > >> > > >>>> one-byte storage format happens to look like latin-1 is rather > > >> > > >>>> > > >> > > >>>> coincidental. > > >> > > >>>> > > >> > > >>> And this this is the common basic mistake. You do not push your > > >> > > >>> argumentation far enough. A character may "fall" accidentally in a latin-1. > > >> > > >>> The problem lies in these european characters, which can not fall in this > > >> > > >>> coding. This *is* the cause of the negative side effects. > > >> > > >>> If you are using a correct coding scheme, like cp1252, mac-roman or > > >> > > >>> iso-8859-15, you will never see such a negative side effect. > > >> > > >>> Again, the problem is not the result, the encoded character. The critical > > >> > > >>> part is the character which may cause this side effect. > > >> > > >>> You should think "character set" and not encoded "code point", considering > > >> > > >>> this kind of expression has a sense in 8-bits coding scheme. > > >> > > >>> > > >> > > >>> jmf > > >> > > >> > > >> > > >> But that choice was made decades ago when Unicode picked its second 128 > > >> > > >> characters. The internal form used in this PEP is simply the low-order > > >> > > >> byte of the Unicode code point. Trying to scan the string deciding if > > >> > > >> converting to cp1252 (for example) would be a much more expensive > > >> > > >> operation than seeing how many bytes it'd take for the largest code point. > > >> > > >> > > > > > > You are absoletely right. (I'm quite comfortable with Unicode). > > > If Python wish to perpetuate this, lets call it, design mistake > > > or ennoyement, it will continue to live with problems. > > > > Please give a precise description of the design mistake and what you > > would do to correct it. > > > > > > > > People (tools) who chose pure utf-16 or utf-32 are not suffering > > > from this issue. > > > > > > *My* final comment on this thread. > > > > > > In August 2012, after 20 years of development, Python is not > > > able to display a piece of text correctly on a Windows console > > > (eg cp65001). > > > > Examples please. > > > > > > > > I downloaded the go language, zero experience, I did not succeed > > > to display incorrecly a piece of text. (This is by the way *the* > > > reason why I tested it). Where the problems are coming from, I have > > > no idea. > > > > > > I find this situation quite comic. Python is able to > > > produce this: > > > > > >>>> (1.1).hex() > > > '0x1.199999999999ap+0' > > > > > > but it is not able to display a piece of text! > > > > So you keep saying, but when asked for examples or evidence nothing gets > > produced. > > > > > > > > Try to convince end users IEEE 754 is more important than the > > > ability to read/wirite a piece a text, a 6-years kid has learned > > > at school :-) > > > > > > (I'm not suffering from this kind of effect, as a Windows user, > > > I'm always working via gui, it still remains, the problem exists. > > > > Windows is a law unto itself. Its problems are hardly specific to Python. > > > > > > > > Regards, > > > jmf > > > > > > > Now two or three times you've said you're going but have come back. If > > you come again could you please provide examples and or evidence of what > > you're on about, because you still have me baffled. > > > > -- > > Cheers. > > > > Mark Lawrence. Yesterday, I went to bed. More seriously. I can not give you more numbers than those I gave. As a end user, I noticed and experimented my random tests are always slower in Py3.3 than in Py3.2 on my Windows platform. It is up to you, the core developers to give an explanation about this behaviour. As I understand a little bit the coding of the characters, I pointed out, this is most probably due to this flexible string representation (with arguments appearing randomly in the misc. messages, mainly latin-1). I can not do more. (I stupidly spoke about factors 0.1 to ..., you should read of course, 1.1, to ...) jmf From oscar.j.benjamin at gmail.com Sun Aug 19 10:30:04 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 19 Aug 2012 15:30:04 +0100 Subject: New internal string format in 3.3 In-Reply-To: References: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On 19 August 2012 15:09, wrote: > I can not give you more numbers than those I gave. > As a end user, I noticed and experimented my random tests > are always slower in Py3.3 than in Py3.2 on my Windows platform. > Do the problems have a significant impact on any real application (rather than random tests)? Any significant change in implementation such as this is likely to have both positive and negative performance costs. The important thing is how it affects a real application as a whole. > > It is up to you, the core developers to give an explanation > about this behaviour. Unless others are unable to reproduce your observations. If there is a big performance hit for text heavy applications then it's worth reporting but you should focus your energy on distilling a *meaningful* test case (rather than ranting about Americans, unicode, latin-1 and so on). Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Aug 19 10:48:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 15:48:48 +0100 Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On 19/08/2012 15:09, wxjmfauth at gmail.com wrote: > > I can not give you more numbers than those I gave. > As a end user, I noticed and experimented my random tests > are always slower in Py3.3 than in Py3.2 on my Windows platform. Once again you refuse to supply anything to back up what you say. > > It is up to you, the core developers to give an explanation > about this behaviour. Core developers cannot give an explanation for something that doesn't exist, except in your imagination. Unless you can produce the evidence that supports your claims, including details of OS, benchmarks used and so on and so forth. > > As I understand a little bit the coding of the characters, > I pointed out, this is most probably due to this flexible > string representation (with arguments appearing randomly > in the misc. messages, mainly latin-1). > > I can not do more. > > (I stupidly spoke about factors 0.1 to ..., you should > read of course, 1.1, to ...) > > jmf > I suspect that I'll be dead and buried long before you can produce anything concrete in the way of evidence. I've thrown down the gauntlet several times, do you now have the courage to pick it up, or are you going to resort to the FUD approach that you've been using throughout this thread? -- Cheers. Mark Lawrence. From djc at news.invalid Sun Aug 19 11:32:06 2012 From: djc at news.invalid (DJC) Date: Sun, 19 Aug 2012 17:32:06 +0200 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <5030e939$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <5030e939$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/08/12 15:25, Steven D'Aprano wrote: > Not necessarily. Presumably you're scanning each page into a single > string. Then only the pages containing a supplementary plane char will be > bloated, which is likely to be rare. Especially since I don't expect your > OCR application would recognise many non-BMP characters -- what does > U+110F3, "SORA SOMPENG DIGIT THREE", look like? If the OCR software > doesn't recognise it, you can't get it in your output. (If you do, the > OCR software has a nasty bug.) > > Anyway, in my ignorant opinion the proper fix here is to tell the OCR > software not to bother trying to recognise Imperial Aramaic, Domino > Tiles, Phaistos Disc symbols, or Egyptian Hieroglyphs if you aren't > expecting them in your source material. Not only will the scanning go > faster, but you'll get fewer wrong characters. Consider the automated recognition of a CAPTCHA. As the chars have to be entered by the user on a keyboard, only the most basic charset can be used, so the problem of which chars are possible is quite limited. From wxjmfauth at gmail.com Sun Aug 19 12:19:31 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 09:19:31 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: Le dimanche 19 ao?t 2012 16:48:48 UTC+2, Mark Lawrence a ?crit?: > On 19/08/2012 15:09, wxjmfauth at gmail.com wrote: > > > > > > > > I can not give you more numbers than those I gave. > > > As a end user, I noticed and experimented my random tests > > > are always slower in Py3.3 than in Py3.2 on my Windows platform. > > > > Once again you refuse to supply anything to back up what you say. > > > > > > > > It is up to you, the core developers to give an explanation > > > about this behaviour. > > > > Core developers cannot give an explanation for something that doesn't > > exist, except in your imagination. Unless you can produce the evidence > > that supports your claims, including details of OS, benchmarks used and > > so on and so forth. > > > > > > > > As I understand a little bit the coding of the characters, > > > I pointed out, this is most probably due to this flexible > > > string representation (with arguments appearing randomly > > > in the misc. messages, mainly latin-1). > > > > > > I can not do more. > > > > > > (I stupidly spoke about factors 0.1 to ..., you should > > > read of course, 1.1, to ...) > > > > > > jmf > > > > > > > I suspect that I'll be dead and buried long before you can produce > > anything concrete in the way of evidence. I've thrown down the gauntlet > > several times, do you now have the courage to pick it up, or are you > > going to resort to the FUD approach that you've been using throughout > > this thread? > > > > -- > > Cheers. > > > > Mark Lawrence. I do not remember the tests I'have done at the 1st alpha release time. It was with an interactive interpreter. I precisely pay attention to test these chars you can find in the range 128..256 in all 8-bits coding schemes. Chars I suspected to be problematic. Here a short test again, a random single test, the first idea coming in my mind. Py 3.2.3 >>> timeit.timeit("('a??'*100).replace('a', '???')") 4.99396356635981 Py 3.3b2 >>> timeit.timeit("('a??'*100).replace('a', '???')") 7.560455708007855 Maybe, not so demonstative. It shows at least, we are far away from the 10-30% "annouced". >>> 7.56 / 5 1.512 >>> 5 / (7.56 - 5) * 100 195.31250000000003 jmf From wxjmfauth at gmail.com Sun Aug 19 12:19:31 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 09:19:31 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: Le dimanche 19 ao?t 2012 16:48:48 UTC+2, Mark Lawrence a ?crit?: > On 19/08/2012 15:09, wxjmfauth at gmail.com wrote: > > > > > > > > I can not give you more numbers than those I gave. > > > As a end user, I noticed and experimented my random tests > > > are always slower in Py3.3 than in Py3.2 on my Windows platform. > > > > Once again you refuse to supply anything to back up what you say. > > > > > > > > It is up to you, the core developers to give an explanation > > > about this behaviour. > > > > Core developers cannot give an explanation for something that doesn't > > exist, except in your imagination. Unless you can produce the evidence > > that supports your claims, including details of OS, benchmarks used and > > so on and so forth. > > > > > > > > As I understand a little bit the coding of the characters, > > > I pointed out, this is most probably due to this flexible > > > string representation (with arguments appearing randomly > > > in the misc. messages, mainly latin-1). > > > > > > I can not do more. > > > > > > (I stupidly spoke about factors 0.1 to ..., you should > > > read of course, 1.1, to ...) > > > > > > jmf > > > > > > > I suspect that I'll be dead and buried long before you can produce > > anything concrete in the way of evidence. I've thrown down the gauntlet > > several times, do you now have the courage to pick it up, or are you > > going to resort to the FUD approach that you've been using throughout > > this thread? > > > > -- > > Cheers. > > > > Mark Lawrence. I do not remember the tests I'have done at the 1st alpha release time. It was with an interactive interpreter. I precisely pay attention to test these chars you can find in the range 128..256 in all 8-bits coding schemes. Chars I suspected to be problematic. Here a short test again, a random single test, the first idea coming in my mind. Py 3.2.3 >>> timeit.timeit("('a??'*100).replace('a', '???')") 4.99396356635981 Py 3.3b2 >>> timeit.timeit("('a??'*100).replace('a', '???')") 7.560455708007855 Maybe, not so demonstative. It shows at least, we are far away from the 10-30% "annouced". >>> 7.56 / 5 1.512 >>> 5 / (7.56 - 5) * 100 195.31250000000003 jmf From ryniek90 at gmail.com Sun Aug 19 12:25:03 2012 From: ryniek90 at gmail.com (crispy) Date: Sun, 19 Aug 2012 09:25:03 -0700 (PDT) Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? Message-ID: I have an example: def pairwiseScore(seqA, seqB): prev = -1 score = 0 length = len(seqA) similarity = [] relative_similarity = [] for x in xrange(length): if seqA[x] == seqB[x]: if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): score += 3 similarity.append(x) else: score += 1 similarity.append(x) else: score -= 1 for x in similarity: relative_similarity.append(x - prev) prev = x return ''.join((seqA, '\n', ''.join(['|'.rjust(x) for x in relative_similarity]), '\n', seqB, '\n', 'Score: ', str(score))) print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA"), '\n', '\n', pairwiseScore('AGCG', 'ATCG'), '\n', '\n', pairwiseScore('ATCG', 'ATCG') which returns: ATTCGT || | ATCTAT Score: 2 GATAAATCTGGTCT || ||| | CATTCATCATGCAA Score: 4 AGCG | || ATCG Score: 4 ATCG |||| ATCG Score: 10 But i created this with some help from one person. Earlier, this code was devoided of these few lines: prev = -1 relative_similarity = [] for x in similarity: relative_similarity.append(x - prev) prev = x The method looked liek this: def pairwiseScore(seqA, seqB): score = 0 length = len(seqA) similarity = [] for x in xrange(length): if seqA[x] == seqB[x]: if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): score += 3 similarity.append(x) else: score += 1 similarity.append(x) else: score -= 1 return ''.join((seqA, '\n', ''.join(['|'.rjust(x) for x in similarity]), '\n', seqB, '\n', 'Score: ', str(score))) and produced this output: ATTCGT || | ATCTAT Score: 2 GATAAATCTGGTCT | | | | | | CATTCATCATGCAA Score: 4 AGCG | | | ATCG Score: 4 ATCG || | | ATCG Score: 10 So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones - NOT to first, most to left placed, character. Why it works like that? What builtn-in function can format output, to make every character be placed as i need - relative to the first character, placed most to left side of screen. Cheers From tjreedy at udel.edu Sun Aug 19 12:31:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 12:31:50 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> <7xy5lb9soz.fsf@ruckus.brouhaha.com> Message-ID: On 8/19/2012 4:54 AM, wxjmfauth at gmail.com wrote: > About the exemples contested by Steven: > eg: timeit.timeit("('ab?' * 10).replace('?', '??')") > And it is good enough to show the problem. Period. Repeating a false claim over and over does not make it true. Two people on pydev claim that 3.3 is *faster* on their systems (one unspecified, one OSX10.8). -- Terry Jan Reedy From ryniek90 at gmail.com Sun Aug 19 12:35:02 2012 From: ryniek90 at gmail.com (crispy) Date: Sun, 19 Aug 2012 09:35:02 -0700 (PDT) Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? In-Reply-To: References: Message-ID: Here's first code -> http://codepad.org/RcKTTiYa And here's second -> http://codepad.org/zwEQKKeV From oscar.j.benjamin at gmail.com Sun Aug 19 12:49:52 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 19 Aug 2012 17:49:52 +0100 Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On Aug 19, 2012 5:22 PM, wrote > > Py 3.2.3 > >>> timeit.timeit("('a??'*100).replace('a', '???')") > 4.99396356635981 > > Py 3.3b2 > >>> timeit.timeit("('a??'*100).replace('a', '???')") > 7.560455708007855 > > Maybe, not so demonstative. It shows at least, we > are far away from the 10-30% "annouced". > > >>> 7.56 / 5 > 1.512 > >>> 5 / (7.56 - 5) * 100 > 195.31250000000003 Maybe the problem is that your understanding of a percentage differs from that of others. I make that a 51% increase. I don't really understand what your 195 figure is demonstrating. Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: From noname at nowhere.com Sun Aug 19 13:03:34 2012 From: noname at nowhere.com (Blind Anagram) Date: Sun, 19 Aug 2012 18:03:34 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: [...] If you can consistently replicate a 100% to 1000% slowdown in string handling, please report it as a performance bug: http://bugs.python.org/ Don't forget to report your operating system. ==================================================== For interest, I ran your code snippets on my laptop (Intel core-i7 1.8GHz) running Windows 7 x64. Running Python from a Windows command prompt, I got the following on Python 3.2.3 and 3.3 beta 2: python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" 10000 loops, best of 3: 39.3 usec per loop python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 51.8 usec per loop python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" 10000 loops, best of 3: 52 usec per loop python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 50.3 usec per loop python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 51.6 usec per loop python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" 10000 loops, best of 3: 38.3 usec per loop python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" 10000 loops, best of 3: 50.3 usec per loop python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" 10000 loops, best of 3: 24.5 usec per loop python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 24.7 usec per loop python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" 10000 loops, best of 3: 24.8 usec per loop python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 24 usec per loop python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" 10000 loops, best of 3: 24.1 usec per loop python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" 10000 loops, best of 3: 24.4 usec per loop python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" 10000 loops, best of 3: 24.3 usec per loop This is an average slowdown by a factor of close to 2.3 on 3.3 when compared with 3.2. I am not posting this to perpetuate this thread but simply to ask whether, as you suggest, I should report this as a possible problem with the beta? From d at davea.name Sun Aug 19 13:31:30 2012 From: d at davea.name (Dave Angel) Date: Sun, 19 Aug 2012 13:31:30 -0400 Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? In-Reply-To: References: Message-ID: <503122F2.3090503@davea.name> On 08/19/2012 12:25 PM, crispy wrote: > > So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones - NOT to first, most to left placed, character. rjust() does not print to the console, it just produces a string. So if you want to know how it works, you need to either read about it, or experiment with it. Try help("".rjust) to see a simple description of it. (If you're not familiar with the interactive interpreter's help() function, you owe it to yourself to learn it). Playing with it: print "abcd".rjust(8, "-") produces ----abcd for i in range(5): print "a".rjust(i, "-") produces: a a -a --a ---a In each case, the number of characters produced is no larger than i. No consideration is made to other strings outside of the literal passed into the method. > Why it works like that? In your code, you have the rjust() method inside a loop, inside a join, inside a print. it makes a nice, impressive single line, but clearly you don't completely understand what the pieces are, nor how they work together. Since the join is combining (concatenating) strings that are each being produced by rjust(), it's the join() that's making this look "relative" to you. > What builtn-in function can format output, to make every character be placed as i need - relative to the first character, placed most to left side of screen. If you want to randomly place characters on the screen, you either want a curses-like package, or a gui. i suspect that's not at all what you want. if you want to randomly change characters in a pre-existing string, which will then be printed to the console, then I could suggest an approach (untested) res = [" "] * length for column in similarity: res[column] = "|" res = "".join(res) -- DaveA From wxjmfauth at gmail.com Sun Aug 19 13:33:25 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 10:33:25 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5dfd1779-9442-4858-9161-8f1a06d56829@googlegroups.com> Le dimanche 19 ao?t 2012 19:03:34 UTC+2, Blind Anagram a ?crit?: > "Steven D'Aprano" wrote in message > > news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... > > > > On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: > > > > [...] > > If you can consistently replicate a 100% to 1000% slowdown in string > > handling, please report it as a performance bug: > > > > http://bugs.python.org/ > > > > Don't forget to report your operating system. > > > > ==================================================== > > For interest, I ran your code snippets on my laptop (Intel core-i7 1.8GHz) > > running Windows 7 x64. > > > > Running Python from a Windows command prompt, I got the following on Python > > 3.2.3 and 3.3 beta 2: > > > > python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 39.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.8 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 52 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 50.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.6 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 38.3 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 50.3 usec per loop > > > > python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 24.5 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.7 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 24.8 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.1 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 24.4 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 24.3 usec per loop > > > > This is an average slowdown by a factor of close to 2.3 on 3.3 when compared > > with 3.2. > > > > I am not posting this to perpetuate this thread but simply to ask whether, > > as you suggest, I should report this as a possible problem with the beta? I use win7 pro 32bits in intel? Thanks for reporting these numbers. To be clear: I'm not complaining, but the fact that there is a slow down is a clear indication (in my mind), there is a point somewhere. jmf From tjreedy at udel.edu Sun Aug 19 13:34:09 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 13:34:09 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7x8vdbmho6.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: On 8/19/2012 4:04 AM, Paul Rubin wrote: > Meanwhile, an example of the 393 approach failing: I am completely baffled by this, as this example is one where the 393 approach potentially wins. > I was involved in a > project that dealt with terabytes of OCR data of mostly English text. > So the chars were mostly ascii, 3.3 stores ascii pages 1 byte/char rather than 2 or 4. > but there would be occasional non-ascii > chars including supplementary plane characters, either because of > special symbols that were really in the text, or the typical OCR > confusion emitting those symbols due to printing imprecision. I doubt that there are really any non-bmp chars. As Steven said, reject such false identifications. > That's a natural for UTF-8 3.3 would convert to utf-8 for storage on disk. > but the PEP-393 approach would bloat up the memory > requirements by a factor of 4. 3.2- wide builds would *always* use 4 bytes/char. Is not occasionally better than always? > py> s = chr(0xFFFF + 1) > py> a, b = s > > That looks like Python 3.2 is buggy and that sample should just throw an > error. s is a one-character string and should not be unpackable. That looks like a 3.2- narrow build. Such which treat unicode strings as sequences of code units rather than sequences of codepoints. Not an implementation bug, but compromise design that goes back about a decade to when unicode was added to Python. At that time, there were only a few defined non-BMP chars and their usage was extremely rare. There are now more extended chars than BMP chars and usage will become more common even in English text. Pre 3.3, there are really 2 sub-versions of every Python version: a narrow build and a wide build version, with not very well documented different behaviors for any string with extended chars. That is and would have become an increasing problem as extended chars are increasingly used. If you want to say that what was once a practical compromise has become a design bug, I would not argue. In any case, 3.3 fixes that split and returns Python to being one cross-platform language. > I realize the folks who designed and implemented PEP 393 are very smart > cookies and considered stuff carefully, while I'm just an internet user > posting an immediate impression of something I hadn't seen before (I > still use Python 2.6), but I still have to ask: if the 393 approach > makes sense, why don't other languages do it? Python has often copied or borrowed, with adjustments. This time it is the first. We will see how it goes, but it has been tested for nearly a year already. > Ropes of UTF-8 segments seems like the most obvious approach and I > wonder if it was considered. By that I mean pick some implementation > constant k (say k=128) and represent the string as a UTF-8 encoded byte > array, accompanied by a vector n//k pointers into the byte array, where > n is the number of codepoints in the string. Then you can reach any > offset analogously to reading a random byte on a disk, by seeking to the > appropriate block, and then reading the block and getting the char you > want within it. Random access is then O(1) though the constant is > higher than it would be with fixed width encoding. I would call it O(k), where k is a selectable constant. Slowing access by a factor of 100 is hardly acceptable to me. For strings less than k, access is O(len). I believe slicing would require re-indexing. As 393 was near adoption, I proposed a scheme using utf-16 (narrow builds) with a supplementary index of extended chars when there are any. That makes access O(1) if there are none and O(log(k)), where k is the number of extended chars in the string, if there are some. -- Terry Jan Reedy From janpeterr at freenet.de Sun Aug 19 13:35:54 2012 From: janpeterr at freenet.de (Jan Riechers) Date: Sun, 19 Aug 2012 20:35:54 +0300 Subject: New image and color management library for Python 2+3 In-Reply-To: References: Message-ID: <503123FA.4040301@freenet.de> On 14.08.2012 21:22, Christian Heimes wrote: > Hello fellow Pythonistas, > > > Performance > =========== > > smc.freeimage with libjpeg-turbo read JPEGs about three to six times > faster than PIL and writes JPEGs more than five times faster. > [....] > > Python 2.7.3 > read / write cycles: 300 > test image: 1210x1778 24bpp JPEG (pon.jpg) > platform: Ubuntu 12.04 X86_64 > hardware: Intel Xeon hexacore W3680 at 3.33GHz with 24 GB RAM > > smc.freeimage, FreeImage 3.15.3 standard > - read JPEG 12.857 sec > - read JPEG 6.629 sec (resaved) > - write JPEG 21.817 sec > smc.freeimage, FreeImage 3.15.3 with jpeg turbo > - read JPEG 9.297 sec > - read JPEG 3.909 sec (resaved) > - write JPEG 5.857 sec > - read LZW TIFF 17.947 sec > - read biton G4 TIFF 2.068 sec > - resize 3.850 sec (box) > - resize 5.022 sec (bilinear) > - resize 7.942 sec (bspline) > - resize 7.222 sec (bicubic) > - resize 7.941 sec (catmull rom spline) > - resize 10.232 sec (lanczos3) > - tiff numpy.asarray() with bytescale() 0.006 sec > - tiff load + numpy.asarray() with bytescale() 18.043 sec > PIL 1.1.7 > - read JPEG 30.389 sec > - read JPEG 23.118 sec (resaved) > - write JPEG 34.405 sec > - read LZW TIFF 21.596 sec > - read biton G4 TIFF: decoder group4 not available > - resize 0.032 sec (nearest) > - resize 1.074 sec (bilinear) > - resize 2.924 sec (bicubic) > - resize 8.056 sec (antialias) > - tiff scipy fromimage() with bytescale() 1.165 sec > - tiff scipy imread() with bytescale() 22.939 sec > > > > Christian > Hello Christian, I'm sorry for getting out of your initial question/request, but did you try out ImageMagick before making use of FreeImage - do you even perhaps can deliver a comparison between your project and ImageMagick (if regular Python is used)? I ask cause: Im in the process of creating a web-app which also requires image processing and just switching from PIL (because it is unfortunately not that quick as it should be) to ImageMagick and the speeds are much better compared to it, but I didn't take measurements of that. Can you perhaps test your solution with ImageMagick (as it is used widely) it would be interesting so. :) But no offence by that and respect for you work so! Jan From no.email at nospam.invalid Sun Aug 19 13:48:06 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 10:48:06 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: <7xfw7ilqnd.fsf@ruckus.brouhaha.com> Terry Reedy writes: >> Meanwhile, an example of the 393 approach failing: > I am completely baffled by this, as this example is one where the 393 > approach potentially wins. What? The 393 approach is supposed to avoid memory bloat and that does the opposite. >> I was involved in a project that dealt with terabytes of OCR data of >> mostly English text. So the chars were mostly ascii, > 3.3 stores ascii pages 1 byte/char rather than 2 or 4. But they are not ascii pages, they are (as stated) MOSTLY ascii. E.g. the characters are 99% ascii but 1% non-ascii, so 393 chooses a much more memory-expensive encoding than UTF-8. > I doubt that there are really any non-bmp chars. You may be right about this. I thought about it some more after posting and I'm not certain that there were supplemental characters. > As Steven said, reject such false identifications. Reject them how? >> That's a natural for UTF-8 > 3.3 would convert to utf-8 for storage on disk. They are already in utf-8 on disk though that doesn't matter since they are also compressed. >> but the PEP-393 approach would bloat up the memory >> requirements by a factor of 4. > 3.2- wide builds would *always* use 4 bytes/char. Is not occasionally > better than always? The bloat is in comparison with utf-8, in that example. > That looks like a 3.2- narrow build. Such which treat unicode strings > as sequences of code units rather than sequences of codepoints. Not an > implementation bug, but compromise design that goes back about a > decade to when unicode was added to Python. I thought the whole point of Python 3's disruptive incompatibility with Python 2 was to clean up past mistakes and compromises, of which unicode headaches was near the top of the list. So I'm surprised they seem to repeated a mistake there. > I would call it O(k), where k is a selectable constant. Slowing access > by a factor of 100 is hardly acceptable to me. If k is constant then O(k) is the same as O(1). That is how O notation works. I wouldn't believe the 100x figure without seeing it measured in real-world applications. From tjreedy at udel.edu Sun Aug 19 13:48:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 13:48:35 -0400 Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On 8/19/2012 10:09 AM, wxjmfauth at gmail.com wrote: > I can not give you more numbers than those I gave. > As a end user, I noticed and experimented my random tests > are always slower in Py3.3 than in Py3.2 on my Windows platform. And I gave other examples where 3.3 is *faster* on my Windows, which you have thus far not even acknowledged, let alone try. > It is up to you, the core developers to give an explanation > about this behaviour. System variation, unimportance of sub-microsecond variations, and attention to more important issues. Other developer say 3.3 is generally faster on their sy stems (OSX 10.8, and unspecified). To talk about speed sensibly, one must run the full stringbench.py benchmark and real applications on multiple Windows, *nix, and Mac systems. Python is not optimized for your particular current computer. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Aug 19 13:50:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Aug 2012 11:50:12 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 19, 2012 at 12:33 AM, Steven D'Aprano wrote: > On Sat, 18 Aug 2012 09:51:37 -0600, Ian Kelly wrote about PEP 393: >> There is some additional benefit for Latin-1 users, but this has nothing >> to do with Python. If Python is going to have the option of a 1-byte >> representation (and as long as we have the flexible representation, I >> can see no reason not to), > > The PEP explicitly states that it only uses a 1-byte format for ASCII > strings, not Latin-1: I think you misunderstand the PEP then, because that is empirically false. Python 3.3.0b2 (v3.3.0b2:4972a8f1b2aa, Aug 12 2012, 15:23:35) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getsizeof(bytes(range(256)).decode('latin1')) 329 The constructed string contains all 256 Latin-1 characters, so if Latin-1 strings must be stored in the 2-byte format, then the size should be at least 512 bytes. It is not, so I think it must be using the 1-byte encoding. > "ASCII-only Unicode strings will again use only one byte per character" This says nothing one way or the other about non-ASCII Latin-1 strings. > "If the maximum character is less than 128, they use the PyASCIIObject > structure" Note that this only describes the structure of "compact" string objects, which I have to admit I do not fully understand from the PEP. The wording suggests that it only uses the PyASCIIObject structure, not the derived structures. It then says that for compact ASCII strings "the UTF-8 data, the UTF-8 length and the wstr length are the same as the length of the ASCII data." But these fields are part of the PyCompactUnicodeObject structure, not the base PyASCIIObject structure, so they would not exist if only PyASCIIObject were used. It would also imply that compact non-ASCII strings are stored internally as UTF-8, which would be surprising. > and: > > "The data and utf8 pointers point to the same memory if the string uses > only ASCII characters (using only Latin-1 is not sufficient)." This says that if the data are ASCII, then the 1-byte representation and the utf8 pointer will share the same memory. It does not imply that the 1-byte representation is not used for Latin-1, only that it cannot also share memory with the utf8 pointer. From wxjmfauth at gmail.com Sun Aug 19 13:51:08 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 10:51:08 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Just for the story. Five minutes after a closed my interactive interpreters windows, the day I tested this stuff. I though: "Too bad I did not noted the extremely bad cases I found, I'm pretty sure, this problem will arrive on the table". jmf From wxjmfauth at gmail.com Sun Aug 19 13:51:08 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 10:51:08 -0700 (PDT) Subject: New internal string format in 3.3 In-Reply-To: References: <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Just for the story. Five minutes after a closed my interactive interpreters windows, the day I tested this stuff. I though: "Too bad I did not noted the extremely bad cases I found, I'm pretty sure, this problem will arrive on the table". jmf From tjreedy at udel.edu Sun Aug 19 13:56:24 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 13:56:24 -0400 Subject: New internal string format in 3.3 In-Reply-To: <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> References: <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <4c62a649-bc21-4e47-9c0f-acb1b1e70e36@googlegroups.com> <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> Message-ID: On 8/19/2012 8:59 AM, wxjmfauth at gmail.com wrote: > In August 2012, after 20 years of development, Python is not able to > display a piece of text correctly on a Windows console (eg cp65001). cp65001 is known to not work right. It has been very frustrating. Bug Microsoft about it, and indeed their whole policy of still dividing the world into code page regions, even in their next version, instead of moving toward unicode and utf-8, at least as an option. > I downloaded the go language, zero experience, I did not succeed to > display incorrecly a piece of text. (This is by the way *the* reason > why I tested it). Where the problems are coming from, I have no > idea. If go can display all unicode chars on a Windows console, perhaps you can do some research and find out how they do so. Then we could consider copying it. -- Terry Jan Reedy From tjreedy at udel.edu Sun Aug 19 14:04:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 14:04:45 -0400 Subject: Branch and Bound Algorithm / Module for Python? In-Reply-To: <4a2d7df3-7415-4c4b-82de-856190b296ce@googlegroups.com> References: <4a2d7df3-7415-4c4b-82de-856190b296ce@googlegroups.com> Message-ID: On 8/19/2012 5:04 AM, Rebekka-Marie wrote: > Hello everybody, > > I would like to solve a Mixed Integer Optimization Problem with the > Branch-And-Bound Algorithm. > > I designed my Minimizing function and the constraints. I tested them > in a small program in AIMMS. So I already know that they are > solvable. > > Now I want to solve them using Python. > > Is there a module / methods that I can download or a ready-made > program text that you know about, where I can put my constraints and > minimization function in? Search 'Python constraint solver' and you should find at least two programs. -- Terry Jan Reedy From noname at nowhere.com Sun Aug 19 14:04:49 2012 From: noname at nowhere.com (Blind Anagram) Date: Sun, 19 Aug 2012 19:04:49 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <5dfd1779-9442-4858-9161-8f1a06d56829@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <5dfd1779-9442-4858-9161-8f1a06d56829@googlegroups.com> Message-ID: wrote in message news:5dfd1779-9442-4858-9161-8f1a06d56829 at googlegroups.com... Le dimanche 19 ao?t 2012 19:03:34 UTC+2, Blind Anagram a ?crit : > "Steven D'Aprano" wrote in message > > news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... > > > > On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: > > > > [...] > > If you can consistently replicate a 100% to 1000% slowdown in string > > handling, please report it as a performance bug: > > > > http://bugs.python.org/ > > > > Don't forget to report your operating system. > > > > ==================================================== > > For interest, I ran your code snippets on my laptop (Intel core-i7 1.8GHz) > > running Windows 7 x64. > > > > Running Python from a Windows command prompt, I got the following on > Python > > 3.2.3 and 3.3 beta 2: > > > > python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 39.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.8 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 52 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 50.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.6 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 38.3 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 50.3 usec per loop > > > > python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 24.5 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.7 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 24.8 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.1 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 24.4 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 24.3 usec per loop > > > > This is an average slowdown by a factor of close to 2.3 on 3.3 when > compared > > with 3.2. > > > > I am not posting this to perpetuate this thread but simply to ask whether, > > as you suggest, I should report this as a possible problem with the beta? I use win7 pro 32bits in intel? Thanks for reporting these numbers. To be clear: I'm not complaining, but the fact that there is a slow down is a clear indication (in my mind), there is a point somewhere. ==================================== I may be reading your input wrongly, but it seems to me that you are not only reporting a slowdown but you are also suggesting that this slowdown is the result of bad design decisions by the Python development team. I don't want to get involved in the latter part of your argument because I am convinced that the Python team are doing their very best to find a good compromise between the various design constraints that they face in meeting these needs. Nevertheless, the post that I responded to contained the suggestion that slowdowns above 100% (which I took as a factor of 2) would be worth reporting as a possible bug. So I thought that it was worth asking about this as I may have misunderstood the level of slowdown that is worth reporting. There is also a potential problem in timings on laptops with turbo-boost (as I have), although the times look fairly consistent. From d at davea.name Sun Aug 19 14:05:48 2012 From: d at davea.name (Dave Angel) Date: Sun, 19 Aug 2012 14:05:48 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50312AFC.8020905@davea.name> On 08/19/2012 01:03 PM, Blind Anagram wrote: > "Steven D'Aprano" wrote in message > news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... > > On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: > > [...] > If you can consistently replicate a 100% to 1000% slowdown in string > handling, please report it as a performance bug: > > http://bugs.python.org/ > > Don't forget to report your operating system. > > ==================================================== > For interest, I ran your code snippets on my laptop (Intel core-i7 > 1.8GHz) running Windows 7 x64. > > Running Python from a Windows command prompt, I got the following on > Python 3.2.3 and 3.3 beta 2: > > python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" > 10000 loops, best of 3: 39.3 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 51.8 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > 10000 loops, best of 3: 52 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 50.3 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 51.6 usec per loop > python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > 10000 loops, best of 3: 38.3 usec per loop > python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > 10000 loops, best of 3: 50.3 usec per loop > > python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" > 10000 loops, best of 3: 24.5 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24.7 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > 10000 loops, best of 3: 24.8 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24.1 usec per loop > python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > 10000 loops, best of 3: 24.4 usec per loop > python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > 10000 loops, best of 3: 24.3 usec per loop > > This is an average slowdown by a factor of close to 2.3 on 3.3 when > compared with 3.2. > Using your measurement numbers, I get an average of 1.95, not 2.3 -- DaveA From breamoreboy at yahoo.co.uk Sun Aug 19 14:09:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 19:09:38 +0100 Subject: New internal string format in 3.3 In-Reply-To: <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: On 19/08/2012 18:51, wxjmfauth at gmail.com wrote: > Just for the story. > > Five minutes after a closed my interactive interpreters windows, > the day I tested this stuff. I though: > "Too bad I did not noted the extremely bad cases I found, I'm pretty > sure, this problem will arrive on the table". > > jmf > How convenient. -- Cheers. Mark Lawrence. From wxjmfauth at gmail.com Sun Aug 19 14:11:21 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 19 Aug 2012 11:11:21 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xfw7ilqnd.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> Message-ID: <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> Le dimanche 19 ao?t 2012 19:48:06 UTC+2, Paul Rubin a ?crit?: > > > But they are not ascii pages, they are (as stated) MOSTLY ascii. > > E.g. the characters are 99% ascii but 1% non-ascii, so 393 chooses > > a much more memory-expensive encoding than UTF-8. > > Imagine an us banking application, everything in ascii, except ... the ? currency symbole, code point 0x20ac. Well, it seems some software producers know what they are doing. >>> '?'.encode('cp1252') b'\x80' >>> '?'.encode('mac-roman') b'\xdb' >>> '?'.encode('iso-8859-1') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'latin-1' codec can't encode character '\u20ac' in position 0: ordinal not in range(256) jmf From noname at nowhere.com Sun Aug 19 14:18:41 2012 From: noname at nowhere.com (Blind Anagram) Date: Sun, 19 Aug 2012 19:18:41 +0100 Subject: How do I display unicode value stored in a string variable usingord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com><502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Dave Angel" wrote in message news:mailman.3519.1345399574.4697.python-list at python.org... [...] > > This is an average slowdown by a factor of close to 2.3 on 3.3 when > compared with 3.2. > Using your measurement numbers, I get an average of 1.95, not 2.3 ================ Yes - you are right - my apologies. But it is close enough to 2 to still be worth asking. From no.email at nospam.invalid Sun Aug 19 14:20:11 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 11:20:11 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xobm6u4kk.fsf@ruckus.brouhaha.com> Ian Kelly writes: >>>> sys.getsizeof(bytes(range(256)).decode('latin1')) > 329 Please try: print (type(bytes(range(256)).decode('latin1'))) to make sure that what comes back is actually a unicode string rather than a byte string. From ian.g.kelly at gmail.com Sun Aug 19 14:31:09 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Aug 2012 12:31:09 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xobm6u4kk.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xobm6u4kk.fsf@ruckus.brouhaha.com> Message-ID: On Sun, Aug 19, 2012 at 12:20 PM, Paul Rubin wrote: > Ian Kelly writes: >>>>> sys.getsizeof(bytes(range(256)).decode('latin1')) >> 329 > > Please try: > > print (type(bytes(range(256)).decode('latin1'))) > > to make sure that what comes back is actually a unicode string rather > than a byte string. As I understand it, the decode method never returns a byte string in Python 3, but if you insist: >>> print (type(bytes(range(256)).decode('latin1'))) From ian.g.kelly at gmail.com Sun Aug 19 14:46:27 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Aug 2012 12:46:27 -0600 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 19, 2012 at 11:50 AM, Ian Kelly wrote: > Note that this only describes the structure of "compact" string > objects, which I have to admit I do not fully understand from the PEP. > The wording suggests that it only uses the PyASCIIObject structure, > not the derived structures. It then says that for compact ASCII > strings "the UTF-8 data, the UTF-8 length and the wstr length are the > same as the length of the ASCII data." But these fields are part of > the PyCompactUnicodeObject structure, not the base PyASCIIObject > structure, so they would not exist if only PyASCIIObject were used. > It would also imply that compact non-ASCII strings are stored > internally as UTF-8, which would be surprising. Oh, now I get it. I had missed the part where it says "character data immediately follow the base structure". And the bit about the "UTF-8 data, the UTF-8 length and the wstr length" are not describing the contents of those fields, but rather where the data can be alternatively found since the fields don't exist. From breamoreboy at yahoo.co.uk Sun Aug 19 14:50:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 19:50:13 +0100 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> Message-ID: On 19/08/2012 19:11, wxjmfauth at gmail.com wrote: > Le dimanche 19 ao?t 2012 19:48:06 UTC+2, Paul Rubin a ?crit : >> >> >> But they are not ascii pages, they are (as stated) MOSTLY ascii. >> >> E.g. the characters are 99% ascii but 1% non-ascii, so 393 chooses >> >> a much more memory-expensive encoding than UTF-8. >> >> > > Imagine an us banking application, everything in ascii, > except ... the ? currency symbole, code point 0x20ac. > > Well, it seems some software producers know what they > are doing. > >>>> '?'.encode('cp1252') > b'\x80' >>>> '?'.encode('mac-roman') > b'\xdb' >>>> '?'.encode('iso-8859-1') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'latin-1' codec can't encode character '\u20ac' > in position 0: ordinal not in range(256) > > jmf > Well that's it then, the world stock markets will all collapse tonight when the news leaks out that those stupid Americans haven't yet realised that much of Europe (with at least one very noticeable and sensible exception :) uses Euros. I'd better sell all my stock holdings fast. -- Cheers. Mark Lawrence. From no.email at nospam.invalid Sun Aug 19 15:23:32 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 12:23:32 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xobm6u4kk.fsf@ruckus.brouhaha.com> Message-ID: <7xsjbiele3.fsf@ruckus.brouhaha.com> Ian Kelly writes: >>>> print (type(bytes(range(256)).decode('latin1'))) > Thanks. From ryniek90 at gmail.com Sun Aug 19 15:25:35 2012 From: ryniek90 at gmail.com (crispy) Date: Sun, 19 Aug 2012 12:25:35 -0700 (PDT) Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? In-Reply-To: References: Message-ID: <45524fc1-12df-4201-8c0a-9f27f41bc402@googlegroups.com> W dniu niedziela, 19 sierpnia 2012 19:31:30 UTC+2 u?ytkownik Dave Angel napisa?: > On 08/19/2012 12:25 PM, crispy wrote: > > > > > > So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones - NOT to first, most to left placed, character. > > > > rjust() does not print to the console, it just produces a string. So if > > you want to know how it works, you need to either read about it, or > > experiment with it. > > > > Try help("".rjust) to see a simple description of it. (If you're > > not familiar with the interactive interpreter's help() function, you owe > > it to yourself to learn it). > > > > Playing with it: > > > > print "abcd".rjust(8, "-") produces ----abcd > > > > for i in range(5): print "a".rjust(i, "-") > > produces: > > > > a > > a > > -a > > --a > > ---a > > > > In each case, the number of characters produced is no larger than i. No > > consideration is made to other strings outside of the literal passed > > into the method. > > > > > > > Why it works like that? > > > > In your code, you have the rjust() method inside a loop, inside a join, > > inside a print. it makes a nice, impressive single line, but clearly > > you don't completely understand what the pieces are, nor how they work > > together. Since the join is combining (concatenating) strings that are > > each being produced by rjust(), it's the join() that's making this look > > "relative" to you. > > > > > > > What builtn-in function can format output, to make every character be placed as i need - relative to the first character, placed most to left side of screen. > > > > If you want to randomly place characters on the screen, you either want > > a curses-like package, or a gui. i suspect that's not at all what you want. > > > > if you want to randomly change characters in a pre-existing string, > > which will then be printed to the console, then I could suggest an > > approach (untested) > > > > res = [" "] * length > > for column in similarity: > > res[column] = "|" > > res = "".join(res) > > > > > > > > -- > > > > DaveA Thanks, i've finally came to solution. Here it is -> http://codepad.org/Q70eGkO8 def pairwiseScore(seqA, seqB): score = 0 bars = [str(' ') for x in seqA] #create a list filled with number of spaces equal to length of seqA string. It could be also seqB, because both are meant to have same length length = len(seqA) similarity = [] for x in xrange(length): if seqA[x] == seqB[x]: #check if for every index 'x', corresponding character is same in both seqA and seqB strings if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): #if 'x' is greater than or equal to 1 and characters under the previous index, were same in both seqA and seqB strings, do.. score += 3 similarity.append(x) else: score += 1 similarity.append(x) else: score -= 1 for x in similarity: bars[x] = '|' #for every index 'x' in 'bars' list, replace space with '|' (pipe/vertical bar) character return ''.join((seqA, '\n', ''.join(bars), '\n', seqB, '\n', 'Score: ', str(score))) print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA"), '\n', '\n', pairwiseScore('AGCG', 'ATCG'), '\n', '\n', pairwiseScore('ATCG', 'ATCG') From ryniek90 at gmail.com Sun Aug 19 15:25:35 2012 From: ryniek90 at gmail.com (crispy) Date: Sun, 19 Aug 2012 12:25:35 -0700 (PDT) Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? In-Reply-To: References: Message-ID: <45524fc1-12df-4201-8c0a-9f27f41bc402@googlegroups.com> W dniu niedziela, 19 sierpnia 2012 19:31:30 UTC+2 u?ytkownik Dave Angel napisa?: > On 08/19/2012 12:25 PM, crispy wrote: > > > > > > So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones - NOT to first, most to left placed, character. > > > > rjust() does not print to the console, it just produces a string. So if > > you want to know how it works, you need to either read about it, or > > experiment with it. > > > > Try help("".rjust) to see a simple description of it. (If you're > > not familiar with the interactive interpreter's help() function, you owe > > it to yourself to learn it). > > > > Playing with it: > > > > print "abcd".rjust(8, "-") produces ----abcd > > > > for i in range(5): print "a".rjust(i, "-") > > produces: > > > > a > > a > > -a > > --a > > ---a > > > > In each case, the number of characters produced is no larger than i. No > > consideration is made to other strings outside of the literal passed > > into the method. > > > > > > > Why it works like that? > > > > In your code, you have the rjust() method inside a loop, inside a join, > > inside a print. it makes a nice, impressive single line, but clearly > > you don't completely understand what the pieces are, nor how they work > > together. Since the join is combining (concatenating) strings that are > > each being produced by rjust(), it's the join() that's making this look > > "relative" to you. > > > > > > > What builtn-in function can format output, to make every character be placed as i need - relative to the first character, placed most to left side of screen. > > > > If you want to randomly place characters on the screen, you either want > > a curses-like package, or a gui. i suspect that's not at all what you want. > > > > if you want to randomly change characters in a pre-existing string, > > which will then be printed to the console, then I could suggest an > > approach (untested) > > > > res = [" "] * length > > for column in similarity: > > res[column] = "|" > > res = "".join(res) > > > > > > > > -- > > > > DaveA Thanks, i've finally came to solution. Here it is -> http://codepad.org/Q70eGkO8 def pairwiseScore(seqA, seqB): score = 0 bars = [str(' ') for x in seqA] #create a list filled with number of spaces equal to length of seqA string. It could be also seqB, because both are meant to have same length length = len(seqA) similarity = [] for x in xrange(length): if seqA[x] == seqB[x]: #check if for every index 'x', corresponding character is same in both seqA and seqB strings if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): #if 'x' is greater than or equal to 1 and characters under the previous index, were same in both seqA and seqB strings, do.. score += 3 similarity.append(x) else: score += 1 similarity.append(x) else: score -= 1 for x in similarity: bars[x] = '|' #for every index 'x' in 'bars' list, replace space with '|' (pipe/vertical bar) character return ''.join((seqA, '\n', ''.join(bars), '\n', seqB, '\n', 'Score: ', str(score))) print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA"), '\n', '\n', pairwiseScore('AGCG', 'ATCG'), '\n', '\n', pairwiseScore('ATCG', 'ATCG') From steve+comp.lang.python at pearwood.info Sun Aug 19 16:15:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 20:15:37 GMT Subject: Abuse of Big Oh notation [was Re: How do I display unicode value stored in a string variable using ord()] References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> Message-ID: <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 10:48:06 -0700, Paul Rubin wrote: > Terry Reedy writes: >> I would call it O(k), where k is a selectable constant. Slowing access >> by a factor of 100 is hardly acceptable to me. > > If k is constant then O(k) is the same as O(1). That is how O notation > works. You might as well say that if N is constant, O(N**2) is constant too and just like magic you have now made Bubble Sort a constant-time sort function! That's not how it works. Of course *if* k is constant, O(k) is constant too, but k is not constant. In context we are talking about string indexing and slicing. There is no value of k, say, k = 2, for which you can say "People will sometimes ask for string[2] but never ask for string[3]". That is absurd. Since k can vary from 0 to N-1, we can say that the average string index lookup is k = (N-1)//2 which clearly depends on N. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 16:16:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 20:16:59 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <503088b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503149bb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 11:50:12 -0600, Ian Kelly wrote: > On Sun, Aug 19, 2012 at 12:33 AM, Steven D'Aprano > wrote: [...] >> The PEP explicitly states that it only uses a 1-byte format for ASCII >> strings, not Latin-1: > > I think you misunderstand the PEP then, because that is empirically > false. Yes I did misunderstand. Thank you for the clarification. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 19 16:31:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Aug 2012 20:31:35 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50314d27$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 18:03:34 +0100, Blind Anagram wrote: > "Steven D'Aprano" wrote in message > news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... > > > If you can consistently replicate a 100% to 1000% slowdown in string > > handling, please report it as a performance bug: > > > > http://bugs.python.org/ > > > > Don't forget to report your operating system. [...] > This is an average slowdown by a factor of close to 2.3 on 3.3 when > compared with 3.2. > > I am not posting this to perpetuate this thread but simply to ask > whether, as you suggest, I should report this as a possible problem with > the beta? Possibly, if it is consistent and non-trivial. Serious performance regressions are bugs. Trivial ones, not so much. Thanks to Terry Reedy, who has already asked the Python Devs about this issue, they have made it clear that they aren't hugely interested in micro-benchmarks in isolation. If you want the bug report to be taken seriously, you would need to run the full Python string benchmark. The results of that would be interesting to see. -- Steven From no.email at please.post Sun Aug 19 16:42:16 2012 From: no.email at please.post (kj) Date: Sun, 19 Aug 2012 20:42:16 +0000 (UTC) Subject: Why doesn't Python remember the initial directory? Message-ID: As far as I've been able to determine, Python does not remember (immutably, that is) the working directory at the program's start-up, or, if it does, it does not officially expose this information. Does anyone know why this is? Is there a PEP stating the rationale for it? Thanks! From giacomo.alzetta at gmail.com Sun Aug 19 17:01:15 2012 From: giacomo.alzetta at gmail.com (Giacomo Alzetta) Date: Sun, 19 Aug 2012 14:01:15 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: Il giorno domenica 19 agosto 2012 22:42:16 UTC+2, kj ha scritto: > As far as I've been able to determine, Python does not remember > > (immutably, that is) the working directory at the program's start-up, > > or, if it does, it does not officially expose this information. > > > > Does anyone know why this is? Is there a PEP stating the rationale > > for it? > > > > Thanks! You can obtain the working directory with os.getcwd(). giacomo at jack-laptop:~$ echo 'import os; print os.getcwd()' > testing-dir.py giacomo at jack-laptop:~$ python testing-dir.py /home/giacomo giacomo at jack-laptop:~$ cd Documenti giacomo at jack-laptop:~/Documenti$ python ../testing-dir.py /home/giacomo/Documenti giacomo at jack-laptop:~/Documenti$ Obviously using os.chdir() will change the working directory, and the os.getcwd() will not be the start-up working directory, but if you need the start-up working directory you can get it at start-up and save it in some constant. From roy at panix.com Sun Aug 19 17:03:11 2012 From: roy at panix.com (Roy Smith) Date: Sun, 19 Aug 2012 17:03:11 -0400 Subject: Why doesn't Python remember the initial directory? References: Message-ID: In article , kj wrote: > As far as I've been able to determine, Python does not remember > (immutably, that is) the working directory at the program's start-up, > or, if it does, it does not officially expose this information. Why would you expect that it would? What would it (or you) do with this information? More to the point, doing a chdir() is not something any library code would do (at least not that I'm aware of), so if the directory changed, it's because some application code did it. In which case, you could have just stored the working directory yourself. From tjreedy at udel.edu Sun Aug 19 17:03:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 17:03:46 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/19/2012 1:03 PM, Blind Anagram wrote: > Running Python from a Windows command prompt, I got the following on > Python 3.2.3 and 3.3 beta 2: > > python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" > 10000 loops, best of 3: 39.3 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 51.8 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > 10000 loops, best of 3: 52 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 50.3 usec per loop > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 51.6 usec per loop > python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > 10000 loops, best of 3: 38.3 usec per loop > python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > 10000 loops, best of 3: 50.3 usec per loop > > python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" > 10000 loops, best of 3: 24.5 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24.7 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > 10000 loops, best of 3: 24.8 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24 usec per loop > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > 10000 loops, best of 3: 24.1 usec per loop > python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > 10000 loops, best of 3: 24.4 usec per loop > python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > 10000 loops, best of 3: 24.3 usec per loop This is one test repeated 7 times with essentially irrelevant variations. The difference is less on my system (50%). Others report seeing 3.3 as faster. When I asked on pydev, the answer was don't bother making a tracker issue unless I was personally interested in investigating why search is relatively slow in 3.3 on Windows. Any change would have to not slow other operations or severely impact search on other systems. I suggest the same answer to you. If you seriously want to compare old and new unicode, go to http://hg.python.org/cpython/file/tip/Tools/stringbench/stringbench.py and click raw to download. Run on 3.2 and 3.3, ignoring the bytes times. Here is a version of the first comparison from stringbench: print(timeit('''('NOW IS THE TIME FOR ALL GOOD PEOPLE TO COME TO THE AID OF PYTHON'* 10).lower()''')) Results are 5.6 for 3.2 and .8 for 3.3. WOW! 3.3 is 7 times faster! OK, not fair. I cherry picked. The 7 times speedup in 3.3 likely is at least partly independent of the 393 unicode change. The same test in stringbench for bytes is twice as fast in 3.3 as 3.2, but only 2x, not 7x. In fact, it may have been the bytes/unicode comparison in 3.2 that suggested that unicode case conversion of ascii chrs might be made faster. The sum of the 3.3 unicode times is 109 versus 110 for 3.3 bytes and 125 for 3.2 unicode. This unweighted sum is not really fair since the raw times vary by a factor of at least 100. But is does suggest that anyone claiming that 3.3 unicode is overall 'slower' than 3.2 unicode has some work to do. There is also this. On my machine, the lowest bytes-time/unicode-time for 3.3 is .71. This suggests that there is not a lot of fluff left in the unicode code, and that not much is lost by the bytes to unicode switch for strings. -- Terry Jan Reedy From gandalf at shopzeus.com Sun Aug 19 17:05:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 19 Aug 2012 23:05:10 +0200 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: <50315506.5010206@shopzeus.com> On 2012-08-19 22:42, kj wrote: > > As far as I've been able to determine, Python does not remember > (immutably, that is) the working directory at the program's start-up, > or, if it does, it does not officially expose this information. > > Does anyone know why this is? Is there a PEP stating the rationale > for it? > > Thanks! When you start the program, you have a current directory. When you change it, then it is changed. How do you want Python to remember a directory? For example, you can put it into a variable, and use it later. Can you please show us some example code that demonstrates your actual problem? From breamoreboy at yahoo.co.uk Sun Aug 19 17:18:52 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Aug 2012 22:18:52 +0100 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On 19/08/2012 21:42, kj wrote: > > > As far as I've been able to determine, Python does not remember > (immutably, that is) the working directory at the program's start-up, > or, if it does, it does not officially expose this information. > > Does anyone know why this is? Is there a PEP stating the rationale > for it? > > Thanks! > Why would you have a Python Enhancement Proposal to state the rationale for this? -- Cheers. Mark Lawrence. From rosuav at gmail.com Sun Aug 19 17:50:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Aug 2012 07:50:49 +1000 Subject: New internal string format in 3.3 In-Reply-To: References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: On Mon, Aug 20, 2012 at 4:09 AM, Mark Lawrence wrote: > On 19/08/2012 18:51, wxjmfauth at gmail.com wrote: >> >> Just for the story. >> >> Five minutes after a closed my interactive interpreters windows, >> the day I tested this stuff. I though: >> "Too bad I did not noted the extremely bad cases I found, I'm pretty >> sure, this problem will arrive on the table". > > How convenient. Not really. Even if he HAD copied-and-pasted those worst-cases, it'd prove nothing. Maybe his system just chose to glitch right then. It's always possible to find statistical outliers that take way way longer than everything else. Watch this. Python 3.2 on Windows is optimized for adding 1 to numbers. C:\Documents and Settings\M>\python32\python -m timeit -r 1 "a=1+1" 10000000 loops, best of 1: 0.0654 usec per loop C:\Documents and Settings\M>\python32\python -m timeit -r 1 "a=1+1" 10000000 loops, best of 1: 0.0654 usec per loop C:\Documents and Settings\M>\python32\python -m timeit -r 1 "a=1+1" 10000000 loops, best of 1: 0.0654 usec per loop C:\Documents and Settings\M>\python32\python -m timeit -r 1 "a=1+2" 10000000 loops, best of 1: 0.0711 usec per loop Now, as long as I don't tell you that during the last test I had quite a few other processes running, including VLC playing a movie and two Python processes running "while True: pass", this will look like a significant performance difference. So now, I'm justified in complaining about how suboptimal Python is when adding 2 to a number, which I can assure you is a VERY common case. ChrisA From tjreedy at udel.edu Sun Aug 19 17:59:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 17:59:43 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> Message-ID: On 8/19/2012 2:11 PM, wxjmfauth at gmail.com wrote: > Well, it seems some software producers know what they > are doing. > >>>> '?'.encode('cp1252') > b'\x80' >>>> '?'.encode('mac-roman') > b'\xdb' >>>> '?'.encode('iso-8859-1') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'latin-1' codec can't encode character '\u20ac' > in position 0: ordinal not in range(256) Yes, Python lets you choose your byte encoding from those and a hundred others. I believe all the codecs are now tested in both directions. It was not an easy task. As to the examples: Latin-1 dates to 1985 and before and the 1988 version was published as a standard in 1992. https://en.wikipedia.org/wiki/Latin-1 "The name euro was officially adopted on 16 December 1995." https://en.wikipedia.org/wiki/Euro No wonder Latin-1 does not contain the Euro sign. International standards organizations standards are relatively fixed. (The unicode consortium will not even correct misspelled character names.) Instead, new standards with a new number are adopted. For better or worse, private mappings are more flexible. In its Mac mapping Apple "replaced the generic currency sign ? with the euro sign ?". (See Latin-1 reference.) Great if you use Euros, not so great if you were using the previous sign for something else. Microsoft changed an unneeded code to the Euro for Windows cp-1252. https://en.wikipedia.org/wiki/Windows-1252 "It is very common to mislabel Windows-1252 text with the charset label ISO-8859-1. A common result was that all the quotes and apostrophes (produced by "smart quotes" in Microsoft software) were replaced with question marks or boxes on non-Windows operating systems, making text difficult to read. Most modern web browsers and e-mail clients treat the MIME charset ISO-8859-1 as Windows-1252 in order to accommodate such mislabeling. This is now standard behavior in the draft HTML 5 specification, which requires that documents advertised as ISO-8859-1 actually be parsed with the Windows-1252 encoding.[1]" Lots of fun. Too bad Microsoft won't push utf-8 so we can all communicate text with much less chance of ambiguity. -- Terry Jan Reedy From amangill.coldfire at gmail.com Sun Aug 19 18:27:24 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Sun, 19 Aug 2012 15:27:24 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> On Saturday, 18 August 2012 00:42:00 UTC+5:30, Ian wrote: > On Fri, Aug 17, 2012 at 6:46 AM, coldfire wrote: > > > I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. > > > I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. > > > I have tried Python anywhere but they dont support opening of anonymous websites. > > > > According to their FAQ they don't support this for *free* accounts. > > You could just open a paid account (the cheapest option appears to be > > $5/month). > > > > Also, please don't type your email subject in all capital letters. It > > comes across as shouting and is considered rude. Got it and sorry for typing it CAPs I will take care of it next time for sure. Also Could u help me out with the websites. Also I have no idea how to deploy a python script online. I have done that on my local PC using Apache server and cgi but it Works fine. Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. I use Python And i am not getting any lead. From amangill.coldfire at gmail.com Sun Aug 19 18:27:24 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Sun, 19 Aug 2012 15:27:24 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> On Saturday, 18 August 2012 00:42:00 UTC+5:30, Ian wrote: > On Fri, Aug 17, 2012 at 6:46 AM, coldfire wrote: > > > I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. > > > I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. > > > I have tried Python anywhere but they dont support opening of anonymous websites. > > > > According to their FAQ they don't support this for *free* accounts. > > You could just open a paid account (the cheapest option appears to be > > $5/month). > > > > Also, please don't type your email subject in all capital letters. It > > comes across as shouting and is considered rude. Got it and sorry for typing it CAPs I will take care of it next time for sure. Also Could u help me out with the websites. Also I have no idea how to deploy a python script online. I have done that on my local PC using Apache server and cgi but it Works fine. Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. I use Python And i am not getting any lead. From amangill.coldfire at gmail.com Sun Aug 19 18:28:25 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Sun, 19 Aug 2012 15:28:25 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: <34cb5dc2-7013-4463-b3cc-5753f98771ed@googlegroups.com> On Friday, 17 August 2012 18:16:08 UTC+5:30, coldfire wrote: > I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. > > I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. > > I have tried Python anywhere but they dont support opening of anonymous websites. > > What s the current what to DO this? > > Can someone point me in the write direction. > > My script have no interaction with User It just Got on-line searches for something and emails me. > > > > Thanks Sorry I never wanted to be rude. From rosuav at gmail.com Sun Aug 19 18:42:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Aug 2012 08:42:53 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Aug 20, 2012 at 3:34 AM, Terry Reedy wrote: > On 8/19/2012 4:04 AM, Paul Rubin wrote: >> I realize the folks who designed and implemented PEP 393 are very smart >> cookies and considered stuff carefully, while I'm just an internet user >> posting an immediate impression of something I hadn't seen before (I >> still use Python 2.6), but I still have to ask: if the 393 approach >> makes sense, why don't other languages do it? > > Python has often copied or borrowed, with adjustments. This time it is the > first. We will see how it goes, but it has been tested for nearly a year > already. Maybe it wasn't consciously borrowed, but whatever innovation is done, there's usually an obscure beardless language that did it earlier. :) Pike has a single string type, which can use the full Unicode range. If all codepoints are <256, the string width is 8 (measured in bits); if <65536, width is 16; otherwise 32. Using the inbuilt count_memory function (similar to the Python function used somewhere earlier in this thread, but which I can't at present put my finger to), I find that for strings of 16 bytes or more, there's a fixed 20-byte header plus the string content, stored in the correct number of bytes. (Pike strings, like Python ones, are immutable and do not need expansion room.) However, Python goes a bit further by making it VERY clear that this is a mere optimization, and that Unicode strings and bytes strings are completely different beasts. In Pike, it's possible to forget to encode something before (say) writing it to a socket. Everything works fine while you have only ASCII characters in the string, and then breaks when you have a >255 codepoint - or perhaps worse, when you have a 127 <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: In article , Chris Angelico wrote: > Really, the only viable alternative to PEP 393 is a fixed 32-bit > representation - it's the only way that's guaranteed to provide > equivalent semantics. The new storage format is guaranteed to take no > more memory than that, and provide equivalent functionality. In the primordial days of computing, using 8 bits to store a character was a profligate waste of memory. What on earth did people need with TWO cases of the alphabet (not to mention all sorts of weird punctuation)? Eventually, memory became cheap enough that the convenience of using one character per byte (not to mention 8-bit bytes) outweighed the costs. And crazy things like sixbit and rad-50 got swept into the dustbin of history. So it may be with utf-8 someday. Clearly, the world has moved to a 32-bit character set. Not all parts of the world know that yet, or are willing to admit it, but that doesn't negate the fact that it's true. Equally clearly, the concept of one character per byte is a big win. The obvious conclusion is that eventually, when memory gets cheap enough, we'll all be doing utf-32 and all this transcoding nonsense will look as antiquated as rad-50 does today. From no.email at nospam.invalid Sun Aug 19 19:42:03 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 16:42:03 -0700 Subject: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Of course *if* k is constant, O(k) is constant too, but k is not > constant. In context we are talking about string indexing and slicing. > There is no value of k, say, k = 2, for which you can say "People will > sometimes ask for string[2] but never ask for string[3]". That is absurd. The context was parsing, e.g. recognizing a token like "a" or "foo" in a human-written chunk of text. Occasionally it might be "sesquipidalian" or some even worse outlier, but one can reasonably put a fixed and relatively small upper bound on the expected value of k. That makes the amortized complexity O(1), I think. From wuwei23 at gmail.com Sun Aug 19 19:58:40 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 16:58:40 -0700 (PDT) Subject: How to get initial absolute working dir reliably? In-Reply-To: References: Message-ID: On Sunday, 19 August 2012 01:19:59 UTC+10, kj wrote: > What's the most reliable way for "module code" to determine the > absolute path of the working directory at the start of execution? Here's some very simple code that relies on the singleton nature of modules that might be enough for your needs: import os _workingdir = None def set(): global _workingdir _workingdir = os.getcwd() def get(): return _workingdir At the start of your application, import workingdir and do a workingdir.set(). Then when you need to retrieve it, import it again and use workingdir.get(): a.py: import workingdir workingdir.set() b.py: import workingdir print workingdir.get() test.py: import a import b You could also remove the need to call the .set() by implicitly assigning on the first import: if '_workingdir' not in locals(): _workingdir = os.getcwd() But I like the explicitness. From dihedral88888 at googlemail.com Sun Aug 19 20:32:55 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 19 Aug 2012 17:32:55 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <719badd5-c5ff-4c93-bda8-7e4ab92ec40e@googlegroups.com> On Monday, August 20, 2012 1:03:34 AM UTC+8, Blind Anagram wrote: > "Steven D'Aprano" wrote in message > > news:502f8a2a$0$29978$c3e8da3$5496439d at news.astraweb.com... > > > > On Sat, 18 Aug 2012 01:09:26 -0700, wxjmfauth wrote: > > > > [...] > > If you can consistently replicate a 100% to 1000% slowdown in string > > handling, please report it as a performance bug: > > > > http://bugs.python.org/ > > > > Don't forget to report your operating system. > > > > ==================================================== > > For interest, I ran your code snippets on my laptop (Intel core-i7 1.8GHz) > > running Windows 7 x64. > > > > Running Python from a Windows command prompt, I got the following on Python > > 3.2.3 and 3.3 beta 2: > > > > python33\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 39.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.8 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 52 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 50.3 usec per loop > > python33\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 51.6 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 38.3 usec per loop > > python33\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 50.3 usec per loop > > > > python32\python" -m timeit "('abc' * 1000).replace('c', 'de')" > > 10000 loops, best of 3: 24.5 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.7 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', 'x?')" > > 10000 loops, best of 3: 24.8 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24 usec per loop > > python32\python" -m timeit "('ab?' * 1000).replace('?', '??')" > > 10000 loops, best of 3: 24.1 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('X', '??')" > > 10000 loops, best of 3: 24.4 usec per loop > > python32\python" -m timeit "('XYZ' * 1000).replace('Y', 'p?')" > > 10000 loops, best of 3: 24.3 usec per loop > > > > This is an average slowdown by a factor of close to 2.3 on 3.3 when compared > > with 3.2. > > > > I am not posting this to perpetuate this thread but simply to ask whether, > > as you suggest, I should report this as a possible problem with the beta? Un, another set of functions for seeding up ASCII string othe pertions might be needed. But it is better that Python 3.3 supports unicode strings to be easy to be used by people in different languages first. Anyway I think Cython and Pyrex can be used to tackle this problem. From tjreedy at udel.edu Sun Aug 19 20:35:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Aug 2012 20:35:30 -0400 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: On 8/19/2012 6:42 PM, Chris Angelico wrote: > On Mon, Aug 20, 2012 at 3:34 AM, Terry Reedy wrote: >> Python has often copied or borrowed, with adjustments. This time it is the >> first. I should have added 'that I know of' ;-) > Maybe it wasn't consciously borrowed, but whatever innovation is done, > there's usually an obscure beardless language that did it earlier. :) > > Pike has a single string type, which can use the full Unicode range. > If all codepoints are <256, the string width is 8 (measured in bits); > if <65536, width is 16; otherwise 32. Using the inbuilt count_memory > function (similar to the Python function used somewhere earlier in > this thread, but which I can't at present put my finger to), I find > that for strings of 16 bytes or more, there's a fixed 20-byte header > plus the string content, stored in the correct number of bytes. (Pike > strings, like Python ones, are immutable and do not need expansion > room.) It is even possible that someone involved was even vaguely aware that there was an antecedent. The PEP makes no claim that I can see, but lays out the problem and goes right to details of a Python implementation. > However, Python goes a bit further by making it VERY clear that this > is a mere optimization, and that Unicode strings and bytes strings are > completely different beasts. In Pike, it's possible to forget to > encode something before (say) writing it to a socket. Everything works > fine while you have only ASCII characters in the string, and then > breaks when you have a >255 codepoint - or perhaps worse, when you > have a 127 Message-ID: On Sun, 19 Aug 2012 14:01:15 -0700, Giacomo Alzetta wrote: > You can obtain the working directory with os.getcwd(). Maybe. On Unix, it's possible that the current directory no longer has a pathname. As with files, directories can be "deleted" (i.e. unlinked) even while they're still in use. Similarly, a directory can be renamed while it's in use, so the current directory's pathname may have changed even while the current directory itself hasn't. From dihedral88888 at googlemail.com Sun Aug 19 20:54:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 19 Aug 2012 17:54:35 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Monday, August 20, 2012 4:42:16 AM UTC+8, kj wrote: > As far as I've been able to determine, Python does not remember > > (immutably, that is) the working directory at the program's start-up, > > or, if it does, it does not officially expose this information. > > > > Does anyone know why this is? Is there a PEP stating the rationale > > for it? > > > > Thanks! Immutable data can be frozen and saved in somewhere off the main memory. Perative and imperative programming are different. Please check Erlang. From malaclypse2 at gmail.com Sun Aug 19 21:35:27 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sun, 19 Aug 2012 21:35:27 -0400 Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> References: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> Message-ID: On Sun, Aug 19, 2012 at 6:27 PM, coldfire wrote: > Also I have no idea how to deploy a python script online. > I have done that on my local PC using Apache server and cgi but it Works fine. > Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. > I use Python And i am not getting any lead. If you want to host web pages, like your're doing on your local pc with Apache and cgi, then you need an account with a web server, and a way to deploy your scripts and other content. This is often known as a 'web hosting service'[1]. The exact capabilities and restrictions will vary from provider to provider. If you just want an alway-on, internet accessable place to store and run your python scripts, you may be interested in a 'shell account'[2], or if you need more control over the environment, a 'virtual private server'[3]. That may give you a few terms to google, and see what kind of service you need. 1 http://en.wikipedia.org/wiki/Shell_account 2 http://en.wikipedia.org/wiki/Web_host 3 http://en.wikipedia.org/wiki/Virtual_private_server -- Jerry From no.email at please.post Sun Aug 19 21:57:46 2012 From: no.email at please.post (kj) Date: Mon, 20 Aug 2012 01:57:46 +0000 (UTC) Subject: Why doesn't Python remember the initial directory? References: Message-ID: In Roy Smith writes: >In article , kj >wrote: >> As far as I've been able to determine, Python does not remember >> (immutably, that is) the working directory at the program's start-up, >> or, if it does, it does not officially expose this information. >Why would you expect that it would? What would it (or you) do with this >information? >More to the point, doing a chdir() is not something any library code >would do (at least not that I'm aware of), so if the directory changed, >it's because some application code did it. In which case, you could >have just stored the working directory yourself. This means that no library code can ever count on, for example, being able to reliably find the path to the file that contains the definition of __main__. That's a weakness, IMO. One manifestation of this weakness is that os.chdir breaks inspect.getmodule, at least on Unix. If you have some Unix system handy, you can try the following. First change the argument to os.chdir below to some valid directory other than your working directory. Then, run the script, making sure that you refer to it using a relative path. When I do this on my system (OS X + Python 2.7.3), the script bombs at the last print statement, because the second call to inspect.getmodule (though not the first one) returns None. import inspect import os frame = inspect.currentframe() print inspect.getmodule(frame).__name__ os.chdir('/some/other/directory') # where '/some/other/directory' is # different from the initial directory print inspect.getmodule(frame).__name__ ............... % python demo.py python demo.py __main__ Traceback (most recent call last): File "demo.py", line 11, in print inspect.getmodule(frame).__name__ AttributeError: 'NoneType' object has no attribute '__name__' I don't know of any way to fix inspect.getmodule that does not involve, directly or indirectly, keeping a stable record of the starting directory. But, who am I kidding? What needs fixing, right? That's not a bug, that's a feature! Etc. By now I have learned to expect that 99.99% of Python programmers will find that there's nothing wrong with behavior like the one described above, that it is in fact exactly As It Should Be, because, you see, since Python is the epitome of perfection, it follows inexorably that any flaw or shortcoming one may *perceive* in Python is only an *illusion*: the flaw or shortcoming is really in the benighted programmer, for having stupid ideas about programming (i.e. any idea that may entail that Python is not *gasp* perfect). Pardon my cynicism, but the general vibe from the replies I've gotten to my post (i.e. "if Python ain't got it, it means you don't need it") is entirely in line with these expectations. From malaclypse2 at gmail.com Sun Aug 19 22:05:51 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sun, 19 Aug 2012 22:05:51 -0400 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Sun, Aug 19, 2012 at 9:57 PM, kj wrote: > By now I have learned to expect that 99.99% of Python programmers > will find that there's nothing wrong with behavior like the one > described above, that it is in fact exactly As It Should Be, because, > you see, since Python is the epitome of perfection, it follows > inexorably that any flaw or shortcoming one may *perceive* in Python > is only an *illusion*: the flaw or shortcoming is really in the > benighted programmer, for having stupid ideas about programming > (i.e. any idea that may entail that Python is not *gasp* perfect). > Pardon my cynicism, but the general vibe from the replies I've > gotten to my post (i.e. "if Python ain't got it, it means you don't > need it") is entirely in line with these expectations. Since you have no respect for the people you're writing to, why bother? I know I certainly have no desire to spend any time at all on your problem when you say things like that. Perhaps you're looking for for the argument clinic instead? http://www.youtube.com/watch?v=RDjCqjzbvJY -- Jerry From matthewzipf at gmail.com Sun Aug 19 22:13:49 2012 From: matthewzipf at gmail.com (Matthew Zipf) Date: Sun, 19 Aug 2012 22:13:49 -0400 Subject: Legal: Introduction to Programming App Message-ID: Good evening, I am considering developing an iOS application that would teach average people how to program in Python. The app will be sold on the Apple app store. May I develop this app? To what extent do I need to receive permission from the Python Software Foundation? To what extent do I need to recognize the Python Software Foundation in my app? Thank you, Matthew Zipf -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Sun Aug 19 22:57:44 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 19:57:44 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Monday, 20 August 2012 11:57:46 UTC+10, kj wrote: > This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. That's a weakness, IMO. No, it's not. It's a _strength_. If you've written a library that requires absolute knowledge of its installed location in order for its internals to work, then I'm not installing your library. > When I do this on my system (OS X + Python 2.7.3), the script bombs > at the last print statement, because the second call to inspect.getmodule > (though not the first one) returns None. So, uh, do something sane like test for the result of inspect.getmodule _before_ trying to do something invalid to it? > I don't know of any way to fix inspect.getmodule that does not > involve, directly or indirectly, keeping a stable record of the > starting directory. Then _that is the answer_. YOU need to keep "a stable record": import inspect import os THIS_FILE = os.path.join(os.getcwd(), '.py') frame = inspect.currentframe() print inspect.getmodule(frame).__name__ os.chdir('/some/other/directory') print inspect.getmodule(frame, _filename=THIS_FILE).__name__ > But, who am I kidding? What needs fixing, right? That's not a > bug, that's a feature! Etc. Right. Because that sort of introspection of objects is rare, why burden the _entire_ language with an obligation that is only required in a few places? > By now I have learned to expect that 99.99% of Python programmers > will find that [blah blah blah, whine whine whine]. > Pardon my cynicism, but the general vibe from the replies I've > gotten to my post (i.e. "if Python ain't got it, it means you don't > need it") is entirely in line with these expectations. Oh my god, how DARE people with EXPERIENCE in a language challenge the PRECONCEPTIONS of an AMATEUR!!! HOW DARE THEY?!?! From wuwei23 at gmail.com Sun Aug 19 22:59:54 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 19:59:54 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Monday, 20 August 2012 12:57:44 UTC+10, alex23 wrote: > If you've written a library that requires absolute > knowledge of its installed location in order for its > internals to work, then I'm not installing your library. That should read: "requires the ability to derive absolute knowledge of its installed location for an application's current working directory". There's nothing wrong with a library knowing where shit is. But again, that should in NO WAY be bound to the application working directory. From wuwei23 at gmail.com Sun Aug 19 23:03:13 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 20:03:13 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Monday, 20 August 2012 12:57:44 UTC+10, alex23 wrote: > a library that requires absolute knowledge of its > installed location in order for its internals to work That should read: "a library that requires derivation of its installed location from the current working directory in order" etc From wuwei23 at gmail.com Sun Aug 19 23:04:29 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 20:04:29 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: My apologies for any double-ups and bad formatting. The new Google Groups interface seems to have effectively shat away decades of UX for something that I can only guess was generated randomly. From steve+comp.lang.python at pearwood.info Sun Aug 19 23:38:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Aug 2012 03:38:03 GMT Subject: Why doesn't Python remember the initial directory? References: Message-ID: <5031b11a$0$29972$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Aug 2012 01:57:46 +0000, kj wrote: > In Roy Smith > writes: > >>In article , kj >>wrote: > >>> As far as I've been able to determine, Python does not remember >>> (immutably, that is) the working directory at the program's start-up, >>> or, if it does, it does not officially expose this information. [...] > This means that no library code can ever count on, for example, being > able to reliably find the path to the file that contains the definition > of __main__. Possibly not in the face of chmod. > That's a weakness, IMO. Certainly. > One manifestation of this > weakness is that os.chdir breaks inspect.getmodule, at least on Unix. At the very least, it can do so under some circumstances. By the way, inspect.currentframe is quite problematic. Although it is given a public name, it is just a thin wrapper around sys._getframe which is not just *named* as a private function, but also states clearly in the documentation: "This function should be used for internal and specialized purposes only." So I'm not sure that fixing problems with inspect.currentframe will be high on anyone's priority. [...] > I don't know of any way to fix inspect.getmodule that does not involve, > directly or indirectly, keeping a stable record of the starting > directory. I'm not convinced that this is necessary for the example you give. Perhaps modules need to store absolute pathnames rather than relative ones? os.chdir probably breaks a lot of things. Python operates under the assumption that the working directory does not change. If you change it, it's your responsibility to deal with it. Apart from shell scripting languages, do other languages cope well with having the working directory changed? > But, who am I kidding? What needs fixing, right? That's not a bug, > that's a feature! Etc. Not so much. More of, "yes, that's a bug, but it's not an important bug. If you have a patch for fixing it, we'll consider it, but if you don't, we've got about two thousand more important bugs and features to get through first." Your chances of getting this fixed will be *much* improved if you can demonstrate a genuine problem that can't easily be fixed by just telling the programmer "don't change working directories, or if you do, you need to change back again before doing X, Y or Z". Personally, I think that trying to fix all the things that break if you chdir is not worthwhile, but having Python record the directory you started with in (say) sys.startingdirectory might be a worthwhile feature request. -- Steven From wuwei23 at gmail.com Sun Aug 19 23:43:18 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 19 Aug 2012 20:43:18 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: <5031b11a$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <5031b11a$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ed6a721-377a-49ed-a656-bf67a48b2561@googlegroups.com> On Monday, 20 August 2012 13:38:03 UTC+10, Steven D'Aprano wrote: > Not so much. More of, "yes, that's a bug, but it's not an important bug. > If you have a patch for fixing it, we'll consider it, but if you don't, > we've got about two thousand more important bugs and features to get > through first." I'm not really convinced it's a bug, though. The issue only happens if the module is the main application, so wrapping this behind a launcher will resolve the issue. Given that you can manually provide the filepath to inspect, I'd say it's a known limitation with a workaround. From rosuav at gmail.com Mon Aug 20 00:07:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Aug 2012 14:07:39 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Aug 20, 2012 at 10:35 AM, Terry Reedy wrote: > On 8/19/2012 6:42 PM, Chris Angelico wrote: >> However, Python goes a bit further by making it VERY clear that this >> is a mere optimization, and that Unicode strings and bytes strings are >> completely different beasts. In Pike, it's possible to forget to >> encode something before (say) writing it to a socket. Everything works >> fine while you have only ASCII characters in the string, and then >> breaks when you have a >255 codepoint - or perhaps worse, when you >> have a 127 > Python writes strings to file objects, including open sockets, without > creating a bytes object -- IF the file is opened in text mode, which always > has an associated encoding, even if the default 'ascii'. From what you say, > this is what Pike is missing. In text mode, the library does the encoding, but an encoding still happens. > I am pretty sure that the obvious optimization has already been done. The > internal bytes of all-ascii text can safely be sent to a file with ascii (or > ascii-compatible) encoding without intermediate 'decoding'. I remember > several patches of that sort. If a string is internally ucs2 and the file is > declared usc2 or utf-16 encoding, then again, pairs of bytes can go directly > (possibly with a byte swap). Maybe it doesn't take any memory change, but there is a data type change. A Unicode string cannot be sent over the network; an encoding is needed. In Pike, I can take a string like "\x20AC" (or "\u20ac" or "\U000020ac", same thing) and manipulate it as a one-character string, but I cannot write it to a file or file-like object. I can, however, pass it through a codec (and there's string_to_utf8() for the convenience of the common case), and get back something like "\xe2\x82\xac", which is a three-byte string. The thing is, though, that this new string is of exactly the same data type as the original: 'string'. Which means that I could have a string containing Latin-1 but not ASCII characters, and Pike will happily write it to a socket without raising a compile-time or run-time error. Python, under the same circumstances, would either raise an error or quietly (and correctly) encode the data. But this is a relatively trivial point, in the scheme of things. Python has an excellent model now for handling Unicode strings, and I would STRONGLY recommend everyone to upgrade to 3.3. ChrisA From steve+comp.lang.python at pearwood.info Mon Aug 20 00:21:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Aug 2012 04:21:04 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> Message-ID: <5031bb2f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Aug 2012 19:24:30 -0400, Roy Smith wrote: > In the primordial days of computing, using 8 bits to store a character > was a profligate waste of memory. What on earth did people need with > TWO cases of the alphabet That's obvious, surely? We need two cases so that we can distinguish helping Jack off a horse from helping jack off a horse. > (not to mention all sorts of weird > punctuation)? Eventually, memory became cheap enough that the > convenience of using one character per byte (not to mention 8-bit bytes) > outweighed the costs. And crazy things like sixbit and rad-50 got swept > into the dustbin of history. 8 bit bytes are much older than 8 bit characters. For a long time, ASCII characters used only 7 bits out of the 8. > So it may be with utf-8 someday. Only if you believe that people's ability to generate data will remain lower than people's ability to install more storage. Every few years, new sizes for storage media comes out. The first thing that happens is that people say "40 megabytes? I'll NEVER fill this hard drive up!". The second thing that happens is that they say "Dammit, my 40 MB hard drive is full, and a new one is too expensive, better delete some files." Followed shortly by "400 megabytes? I'll NEVER use that much space!" -- wash, rinse, repeat, through megabytes, gigabytes, terrabytes, and it will happen for petabytes next. So long as our ability to outstrip storage continues, compression and memory-efficient storage schemes will remain in demand. -- Steven From skippy.hammond at gmail.com Mon Aug 20 00:29:08 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 20 Aug 2012 14:29:08 +1000 Subject: Legal: Introduction to Programming App In-Reply-To: References: Message-ID: <5031BD14.5040009@gmail.com> Your only concern from the Python world will (probably; IANAL) be around use of trademarks owned by the PSF - see http://www.python.org/psf/trademarks/ for more. Mark On 20/08/2012 12:13 PM, Matthew Zipf wrote: > Good evening, > > I am considering developing an iOS application that would teach average > people how to program in Python. The app will be sold on the Apple app > store. > > May I develop this app? To what extent do I need to receive permission > from the Python Software Foundation? To what extent do I need to > recognize the Python Software Foundation in my app? > > Thank you, > Matthew Zipf > > From roy at panix.com Mon Aug 20 00:44:22 2012 From: roy at panix.com (Roy Smith) Date: Mon, 20 Aug 2012 00:44:22 -0400 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <5031bb2f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5031bb2f$0$29972$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > So it may be with utf-8 someday. > > Only if you believe that people's ability to generate data will remain > lower than people's ability to install more storage. We're not talking *data*, we're talking *text*. Most of those whatever-bytes people are generating are images, video, and music. Text is a pittance compared to those. In any case, text on disk can easily be stored compressed. I would expect the UTF-8 and UTF-32 versions of a text file to compress to just about the same size. From torriem at gmail.com Mon Aug 20 01:38:58 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 19 Aug 2012 23:38:58 -0600 Subject: New internal string format in 3.3 In-Reply-To: <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: <5031CD72.6030309@gmail.com> On 08/19/2012 11:51 AM, wxjmfauth at gmail.com wrote: > Five minutes after a closed my interactive interpreters windows, > the day I tested this stuff. I though: > "Too bad I did not noted the extremely bad cases I found, I'm pretty > sure, this problem will arrive on the table". Reading through this thread (which is entertaining), I am reminded of the old saying, "premature optimization is the root of all evil." This "problem" that you have discovered, if fixed the way you propose, (4-byte USC-4 representation internally always) would be just such a premature optimization. It would come at a high cost with very little real-world impact. As others have made abundantly clear, the overhead of changing internal string representations is a cost that's only manifest during the creation of the immutable string object. If your code is doing a lot of operations on immutable strings, which by definition creates new immutable string objects, then the real speed problem is in your algorithm. If you are working on a string as if it were a buffer, doing many searches, replaces, etc, then you need to work on an object designed for IO, such as io.StringIO. If implemented half correctly, I imagine that StringIO uses internally the widest possible character representation in the buffer. I could be wrong here. As to your other problem, Python generally tries to follow unicode encoding rules to the letter. Thus if a piece of text cannot be represented in the character set of the terminal, then Python will properly err out. Other languages you have tried, likely fudge it somehow. Display what they can, or something similar. In general the Windows command window is an outdated thing that no serious programmer can rely on to display unicode text. Use a proper GUI api, or use a better terminal that can handle utf-8. The TLDR version: You're right that converting string representations internally incurs overhead, but if your program is slow because of this you're doing it wrong. It's not symptomatic of some python disease. From steve+comp.lang.python at pearwood.info Mon Aug 20 01:56:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Aug 2012 05:56:10 GMT Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <5031bb2f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5031d17a$0$1645$c3e8da3$76491128@news.astraweb.com> On Mon, 20 Aug 2012 00:44:22 -0400, Roy Smith wrote: > In article <5031bb2f$0$29972$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> > So it may be with utf-8 someday. >> >> Only if you believe that people's ability to generate data will remain >> lower than people's ability to install more storage. > > We're not talking *data*, we're talking *text*. Most of those > whatever-bytes people are generating are images, video, and music. Text > is a pittance compared to those. Paul Rubin already told you about his experience using OCR to generate multiple terrabytes of text, and how he would not be happy if that was stored in UCS-4. HTML is text. XML is text. SVG is text. Source code is text. Email is text. (Well, it's actually bytes, but it looks like ASCII text.) Log files are text, and they can fill a hard drive pretty quickly. Lots of data is text. Pittance or not, I do not believe that people will widely abandon compact storage formats like UTF-8 and Latin-1 for UCS-4 any time soon. Given that we're still trying to convince people to use UTF-8 over ASCII, I reckon it will be at least 40 years before there's even a slim chance of migrating from UTF-8 to UCS-4 in a widespread manner. In the IT world, that's close enough to "never" -- we might not even be using Unicode in 2052. In any case, time will tell who is right. -- Steven From rustompmody at gmail.com Mon Aug 20 02:13:24 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 19 Aug 2012 23:13:24 -0700 (PDT) Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <28f35cee-3e55-43af-afc8-1ded199c53d9@googlegroups.com> Message-ID: <7e85ae06-9340-4677-bde8-a7bd4aec8a0b@j2g2000pbg.googlegroups.com> On Aug 19, 11:11?pm, wxjmfa... at gmail.com wrote: > Le dimanche 19 ao?t 2012 19:48:06 UTC+2, Paul Rubin a ?crit?: > > > > > But they are not ascii pages, they are (as stated) MOSTLY ascii. > > > E.g. the characters are 99% ascii but 1% non-ascii, so 393 chooses > > > a much more memory-expensive encoding than UTF-8. > > > Well, it seems some software producers know what they > are doing. > > >>> '?'.encode('cp1252') > b'\x80' > >>> '?'.encode('mac-roman') > b'\xdb' > >>> '?'.encode('iso-8859-1') > > Traceback (most recent call last): > ? File "", line 1, in > UnicodeEncodeError: 'latin-1' codec can't encode character '\u20ac' > in position 0: ordinal not in range(256) You want the Euro-sign in iso-8859-1?? I object. I want the rupee sign ( ? ) http://en.wikipedia.org/wiki/Indian_rupee_sign And while we are at it, why not move it (both?) into ASCII? The problem(s) are: 1. We dont really understand what you are objecting to. 2. Utf-8 like Huffman coding is a prefix code http://en.wikipedia.org/wiki/Prefix_code#Prefix_codes_in_use_today Like Huffman coding, it compresses based on a statistical argument. 3. Unlike Huffman coding the statistics is very political: "Is the Euro more important or Chinese ideograms?" depends on whom you ask From no.email at nospam.invalid Mon Aug 20 02:24:55 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Aug 2012 23:24:55 -0700 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <5031bb2f$0$29972$c3e8da3$5496439d@news.astraweb.com> <5031d17a$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <7xzk5qjd1k.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Paul Rubin already told you about his experience using OCR to generate > multiple terrabytes of text, and how he would not be happy if that was > stored in UCS-4. That particular text was stored on disk as compressed XML that had UTF-8 in the data fields, but I think Roy is right that it would have compressed to around the same size in UCS-4. Converting it to UCS-4 on input would have bloated up the memory footprint and that was the issue of concern to me. > Pittance or not, I do not believe that people will widely abandon compact > storage formats like UTF-8 and Latin-1 for UCS-4 any time soon. Looking at http://www.icu-project.org/ the C++ classes seem to use UTF-16 sort like Python 3.2 :(. I'm not certain of this though. From amangill.coldfire at gmail.com Mon Aug 20 03:03:55 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Mon, 20 Aug 2012 00:03:55 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> Message-ID: On Monday, 20 August 2012 07:05:27 UTC+5:30, Jerry Hill wrote: > On Sun, Aug 19, 2012 at 6:27 PM, coldfire wrote: > > > Also I have no idea how to deploy a python script online. > > > I have done that on my local PC using Apache server and cgi but it Works fine. > > > Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. > > > I use Python And i am not getting any lead. > > > > If you want to host web pages, like your're doing on your local pc > > with Apache and cgi, then you need an account with a web server, and a > > way to deploy your scripts and other content. This is often known as > > a 'web hosting service'[1]. The exact capabilities and restrictions > > will vary from provider to provider. > > > > If you just want an alway-on, internet accessable place to store and > > run your python scripts, you may be interested in a 'shell > > account'[2], or if you need more control over the environment, a > > 'virtual private server'[3]. > > > > That may give you a few terms to google, and see what kind of service you need. > > > > 1 http://en.wikipedia.org/wiki/Shell_account > > 2 http://en.wikipedia.org/wiki/Web_host > > 3 http://en.wikipedia.org/wiki/Virtual_private_server > > > > -- > > Jerry Thanks a ton I will look into these and Get back to u From amangill.coldfire at gmail.com Mon Aug 20 03:03:55 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Mon, 20 Aug 2012 00:03:55 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> Message-ID: On Monday, 20 August 2012 07:05:27 UTC+5:30, Jerry Hill wrote: > On Sun, Aug 19, 2012 at 6:27 PM, coldfire wrote: > > > Also I have no idea how to deploy a python script online. > > > I have done that on my local PC using Apache server and cgi but it Works fine. > > > Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. > > > I use Python And i am not getting any lead. > > > > If you want to host web pages, like your're doing on your local pc > > with Apache and cgi, then you need an account with a web server, and a > > way to deploy your scripts and other content. This is often known as > > a 'web hosting service'[1]. The exact capabilities and restrictions > > will vary from provider to provider. > > > > If you just want an alway-on, internet accessable place to store and > > run your python scripts, you may be interested in a 'shell > > account'[2], or if you need more control over the environment, a > > 'virtual private server'[3]. > > > > That may give you a few terms to google, and see what kind of service you need. > > > > 1 http://en.wikipedia.org/wiki/Shell_account > > 2 http://en.wikipedia.org/wiki/Web_host > > 3 http://en.wikipedia.org/wiki/Virtual_private_server > > > > -- > > Jerry Thanks a ton I will look into these and Get back to u From breamoreboy at yahoo.co.uk Mon Aug 20 03:10:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Aug 2012 08:10:14 +0100 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On 20/08/2012 02:57, kj wrote: > In Roy Smith writes: > >> In article , kj >> wrote: > >>> As far as I've been able to determine, Python does not remember >>> (immutably, that is) the working directory at the program's start-up, >>> or, if it does, it does not officially expose this information. > >> Why would you expect that it would? What would it (or you) do with this >> information? > >> More to the point, doing a chdir() is not something any library code >> would do (at least not that I'm aware of), so if the directory changed, >> it's because some application code did it. In which case, you could >> have just stored the working directory yourself. > > This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. That's a weakness, IMO. One manifestation > of this weakness is that os.chdir breaks inspect.getmodule, at > least on Unix. If you have some Unix system handy, you can try > the following. First change the argument to os.chdir below to some > valid directory other than your working directory. Then, run the > script, making sure that you refer to it using a relative path. > When I do this on my system (OS X + Python 2.7.3), the script bombs > at the last print statement, because the second call to inspect.getmodule > (though not the first one) returns None. > > import inspect > import os > > frame = inspect.currentframe() > > print inspect.getmodule(frame).__name__ > > os.chdir('/some/other/directory') # where '/some/other/directory' is > # different from the initial directory > > print inspect.getmodule(frame).__name__ > > ............... > > % python demo.py > python demo.py > __main__ > Traceback (most recent call last): > File "demo.py", line 11, in > print inspect.getmodule(frame).__name__ > AttributeError: 'NoneType' object has no attribute '__name__' > > > > I don't know of any way to fix inspect.getmodule that does not > involve, directly or indirectly, keeping a stable record of the > starting directory. > > But, who am I kidding? What needs fixing, right? That's not a > bug, that's a feature! Etc. > > By now I have learned to expect that 99.99% of Python programmers > will find that there's nothing wrong with behavior like the one > described above, that it is in fact exactly As It Should Be, because, > you see, since Python is the epitome of perfection, it follows > inexorably that any flaw or shortcoming one may *perceive* in Python > is only an *illusion*: the flaw or shortcoming is really in the > benighted programmer, for having stupid ideas about programming > (i.e. any idea that may entail that Python is not *gasp* perfect). > Pardon my cynicism, but the general vibe from the replies I've > gotten to my post (i.e. "if Python ain't got it, it means you don't > need it") is entirely in line with these expectations. > I see, I see, I get the picture. You're in the "The OS is flawed so I expect the Python core developers to do my work for me by producing code that gets around every known flaw in every supported OS" club. Somehow I don't think that will happen. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Aug 20 03:11:32 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Aug 2012 08:11:32 +0100 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On 20/08/2012 04:04, alex23 wrote: > My apologies for any double-ups and bad formatting. The new Google Groups interface seems to have effectively shat away decades of UX for something that I can only guess was generated randomly. > It's very useful for reporting spam. Otherwise Thunderbird is go :) -- Cheers. Mark Lawrence. From rustompmody at gmail.com Mon Aug 20 03:31:41 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 20 Aug 2012 00:31:41 -0700 (PDT) Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Aug 19, 12:15?pm, Steven D'Aprano wrote: > is probably a really great person and kind to small animals and furry children, but... ROFL! The first we're all familiar with. Furry children? Something to do with heads the size of a planet? From breamoreboy at yahoo.co.uk Mon Aug 20 03:39:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Aug 2012 08:39:18 +0100 Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: <080534b4-828e-4e29-9d8e-e1c68378e9fa@googlegroups.com> Message-ID: On 20/08/2012 08:03, coldfire wrote: > > Thanks a ton I will look into these and Get back to u > Could we have plain English please and not text speech, thanks. If nothing else that should help the people whose English is a second or higher numbered language. -- Cheers. Mark Lawrence. From rosuav at gmail.com Mon Aug 20 03:46:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Aug 2012 17:46:46 +1000 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 20, 2012 at 5:31 PM, rusi wrote: > On Aug 19, 12:15 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> is probably a really great person and kind to small animals and furry children, but... > > ROFL! > > The first we're all familiar with. > > Furry children? > > Something to do with heads the size of a planet? Or it's a Wonka-esque "Wait. Scratch that. Reverse it" moment. Of course Steven is a bit egotistical. That sort of happens when you're better than 95% of the human population of this planet. ChrisA From gianpycea at gmail.com Mon Aug 20 03:50:53 2012 From: gianpycea at gmail.com (gianpycea at gmail.com) Date: Mon, 20 Aug 2012 00:50:53 -0700 (PDT) Subject: How to convert base 10 to base 2? Message-ID: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Hi, as you can argue from the subject, i'm really,really new to python. What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work! From benjamin.kaplan at case.edu Mon Aug 20 04:04:22 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 20 Aug 2012 01:04:22 -0700 Subject: How to convert base 10 to base 2? In-Reply-To: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: On Mon, Aug 20, 2012 at 12:50 AM, wrote: > Hi, > as you can argue from the subject, i'm really,really new to python. > What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work! That syntax goes the other way- from a string representing a number in the given base into an integer (which doesn't have a base, although it's stored in base 2). You get the binary by doing bin(x), where x is an integer. >>> bin(12) '0b1100' If you want to go from a string in base-10 to a string in base-2, you have to do the conversion to integer first. >>> bin(int('5',10)) '0b101' Although you don't need to specify the 10 because that's the default. >>> bin(int('5')) '0b101' From breamoreboy at yahoo.co.uk Mon Aug 20 04:10:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Aug 2012 09:10:25 +0100 Subject: How to convert base 10 to base 2? In-Reply-To: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: On 20/08/2012 08:50, gianpycea at gmail.com wrote: > Hi, > as you can argue from the subject, i'm really,really new to python. > What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work! > When you have a problem please cut and paste the exact thing that you tried with the entire traceback. "Doesn't seem to work" doesn't tell us a lot. Your OS and Python version is usually needed as well but we might be able to skip those details in this case :) How much general programming experience do you have? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Aug 20 04:12:41 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Aug 2012 09:12:41 +0100 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <50309297$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 20/08/2012 08:46, Chris Angelico wrote: > On Mon, Aug 20, 2012 at 5:31 PM, rusi wrote: >> On Aug 19, 12:15 pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >>> is probably a really great person and kind to small animals and furry children, but... >> >> ROFL! >> >> The first we're all familiar with. >> >> Furry children? >> >> Something to do with heads the size of a planet? > > Or it's a Wonka-esque "Wait. Scratch that. Reverse it" moment. > > Of course Steven is a bit egotistical. That sort of happens when > you're better than 95% of the human population of this planet. > > ChrisA > He's a long way to go to catch up with me then :) -- Cheers. Mark Lawrence. From oscar.j.benjamin at gmail.com Mon Aug 20 04:24:33 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 20 Aug 2012 09:24:33 +0100 Subject: Abuse of Big Oh notation In-Reply-To: <7xwr0ua1pw.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 19 Aug 2012 16:42:03 -0700, Paul Rubin wrote: > Steven D'Aprano writes: > > Of course *if* k is constant, O(k) is constant too, but k is not > > constant. In context we are talking about string indexing and slicing. > > There is no value of k, say, k = 2, for which you can say "People will > > sometimes ask for string[2] but never ask for string[3]". That is absurd. > The context was parsing, e.g. recognizing a token like "a" or "foo" in a > human-written chunk of text. Occasionally it might be "sesquipidalian" > or some even worse outlier, but one can reasonably put a fixed and > relatively small upper bound on the expected value of k. That makes the > amortized complexity O(1), I think. No it doen't. It is still O(k). The point of big O notation is to understand the asymptotic behaviour of one variable as it becomes large because of changes in other variables. If k is small then you can often guess that O(k) is small. To say that an operation is O(k), however, is a statement about what happens when k is big (and is not refuted by saying that k is typically not big). Oscar From lipskathekat at yahoo.co.uk Mon Aug 20 04:26:35 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Mon, 20 Aug 2012 09:26:35 +0100 Subject: How to convert base 10 to base 2? In-Reply-To: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: <9q2dncu3dbomaazNnZ2dnUVZ8jKdnZ2d@bt.com> On 20/08/12 08:50, gianpycea at gmail.com wrote: > Hi, > as you can argue from the subject, i'm really,really new to python. > What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work >>> x = bin(30)[2:] >>> x '11110' >>> int(x, 2) 30 >>> lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From gianpycea at gmail.com Mon Aug 20 04:57:43 2012 From: gianpycea at gmail.com (gianpycea at gmail.com) Date: Mon, 20 Aug 2012 01:57:43 -0700 (PDT) Subject: How to convert base 10 to base 2? In-Reply-To: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> On Monday, August 20, 2012 9:50:53 AM UTC+2, (unknown) wrote: > Hi, > > as you can argue from the subject, i'm really,really new to python. > > What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work! Thank you all for the big help! @Mark Lawrence Yes, you're definetely right: i should have posted my OS and the version but being a very rough question on syntax i thought it didn't really matter. I've quite a good general programming experience. I know Java,Visual Basic.NET,Pascal and Mathematica. From guillaume.comte10 at gmail.com Mon Aug 20 05:14:01 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Mon, 20 Aug 2012 02:14:01 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? Message-ID: Hello everyone, I want to use socket.create_connection(...) to set a source address in a ping implementation in python. But how can I then set the type and the protocol? Because, before, I did: icmp = socket.getprotobyname("icmp") my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp) But now, I do: src_addr = socket.gethostbyname(src_addr) dest_addr = socket.gethostbyname(dest_addr) my_socket = socket.create_connection(dest_addr, socket.getdefaulttimeout(), src_addr) Is there something like my_socket.setproto()? I haven't found such a function in the documentation. Thank you, Guillaume From nospam at nospam.com Mon Aug 20 07:41:20 2012 From: nospam at nospam.com (Gilles) Date: Mon, 20 Aug 2012 13:41:20 +0200 Subject: [CGI] Basic newbie error or server configuration error? Message-ID: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> Hello Apache fails running this basic CGI script that I found on the Net: www.acme.com/cgi-bin/test.py?name=myname =========== #!/usr/bin/env python # Import modules for CGI handling import cgi, cgitb cgitb.enable() # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from field 'name' #name = form['name'].value name = form.getvalue('name') =========== This is what I get: =========== "Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request." =========== FWIW, the script lives in www/cgi-bin/ where it should, was chmoded to 755, and I put the following .htaccess file: =========== Options +ExecCGI AddHandler cgi-script .py =========== I'm not sure where to look for an error. Could it be some non-printed, bad characters that prevent Python from compiling the source code? Thanks for any help. From nospam at nospam.com Mon Aug 20 07:56:23 2012 From: nospam at nospam.com (Gilles) Date: Mon, 20 Aug 2012 13:56:23 +0200 Subject: [CGI] Basic newbie error or server configuration error? References: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> Message-ID: <8d9438d5f3j9ljtk5lphkvsvn3bundurnm@4ax.com> Found it: The script MUST return something to the browser. I was missing this: ======== print "Content-Type: text/html;charset=utf-8" print # print a document print "Name is %s" % ( cgi.escape(name), ) ======== Sorry about that. From andrea.crotti.0 at gmail.com Mon Aug 20 07:56:42 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Mon, 20 Aug 2012 12:56:42 +0100 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: 2012/8/20 kj : > In Roy Smith writes> This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. That's a weakness, IMO. One manifestation > of this weakness is that os.chdir breaks inspect.getmodule, at > least on Unix. If you have some Unix system handy, you can try > the following. First change the argument to os.chdir below to some > valid directory other than your working directory. Then, run the > script, making sure that you refer to it using a relative path. > When I do this on my system (OS X + Python 2.7.3), the script bombs > at the last print statement, because the second call to inspect.getmodule > (though not the first one) returns None. > > import inspect > import os > > frame = inspect.currentframe() > > print inspect.getmodule(frame).__name__ > > os.chdir('/some/other/directory') # where '/some/other/directory' is > # different from the initial directory > > print inspect.getmodule(frame).__name__ > > ............... > > % python demo.py > python demo.py > __main__ > Traceback (most recent call last): > File "demo.py", line 11, in > print inspect.getmodule(frame).__name__ > AttributeError: 'NoneType' object has no attribute '__name__' > >.. As in many other cases the programming language can't possibly act safely on all the possible stupid things that the programmer wants to do, and not understanding how an operating system works doesn't help either.. In the specific case there is absolutely no use of os.chdir, since you can: - use absolute paths - things like subprocess.Popen accept a cwd argument - at worst you can chdir back to the previous position right after the broken thing that require a certain path that you are calling is run From rodperson at rodperson.com Mon Aug 20 07:59:39 2012 From: rodperson at rodperson.com (Rod Person) Date: Mon, 20 Aug 2012 07:59:39 -0400 Subject: [CGI] Basic newbie error or server configuration error? In-Reply-To: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> References: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> Message-ID: <20120820075939.00006f6f@unknown> On Mon, 20 Aug 2012 13:41:20 +0200 Gilles wrote: > Hello > > Apache fails running this basic CGI script that I found on the Net: > > www.acme.com/cgi-bin/test.py?name=myname > =========== > #!/usr/bin/env python > > # Import modules for CGI handling > import cgi, cgitb > > cgitb.enable() > > # Create instance of FieldStorage > form = cgi.FieldStorage() > > # Get data from field 'name' > #name = form['name'].value > name = form.getvalue('name') > =========== > > This is what I get: > =========== > "Internal Server Error > > The server encountered an internal error or misconfiguration and was > unable to complete your request. > > Additionally, a 404 Not Found error was encountered while trying to > use an ErrorDocument to handle the request." > =========== > > FWIW, the script lives in www/cgi-bin/ where it should, was chmoded to > 755, and I put the following .htaccess file: > =========== > Options +ExecCGI > AddHandler cgi-script .py > =========== > > I'm not sure where to look for an error. Could it be some non-printed, > bad characters that prevent Python from compiling the source code? > > Thanks for any help. Check the Apache error log, there should be more information there. -- Rod Person http://www.rodperson.com rodperson at rodperson.com Sent From Claws Mail 3.8.0cvs30 Win7 x86 GTK+ 2.16.6/GLib 2.24.0 From guillaume.comte10 at gmail.com Mon Aug 20 08:36:58 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Mon, 20 Aug 2012 05:36:58 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: Message-ID: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> In fact, socket.create_connection is for TCP only so I cannot use it for a ping implementation. Does anyone have an idea about how to be able to set a source address for ICMP messages? From info at egenix.com Mon Aug 20 08:37:06 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 20 Aug 2012 14:37:06 +0200 Subject: ANN: eGenix mxODBC Connect - Python Database Interface 2.0.0 Message-ID: <50322F72.6060903@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python Database Interface Version 2.0.0 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly cross-platform way. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.0-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS mxODBC Connect 2.0.0 is a new major release of our successful mxODBC Connect product. Enhanced API * mxODBC Connect Server now uses mxODBC 3.2 internally and makes its API available in the mxODBC Connect Client. This is a major step forward from the mxODBC 3.0 version used in mxODBC Connect Server 1.0. * mxODBC Connect Client comes with all the mxODBC enhancements, including: - connection and cursor objects can be used as context managers - adjustable parameter styles (qmark or named) - connection .autocommit attribute to easily switch on autocommit - adjustable timestamp resolution - new possibilities to set connection and cursor options to adjust the ODBC objects to your application needs, e.g. set a connection read-only or set a query timeout - adjustable decimal, datetime and string formats - adjustable warning format to be able to handle server warnings without client interaction - greatly improved result set scrolling support - Unicode support for all catalog methods - Access to additional result set meta data via cursor.getcolattribute() Updated Compatibility * The server now features all the ODBC driver compatibility enhancements provided by mxODBC 3.2, including improved and updated support for MS SQL Server Native Client, Oracle Instant Client, Sybase ASE, IBM DB2, Teradata and Netezza. * Native Windows x64 builds with signed executables and a tray app rewritten in C are available for Windows 2008R2, Vista and 7 x64, so you can benefit from better performance, fewer UAC dialogs and smaller memory footprint. Asynchronous Execution * mxODBC Connect Client now integrates directly with gevent, allowing client applications to run asynchronous tasks while performing remote database queries. Better Integration * mxODBC Connect now uses the official IANA registered port 6632 for both plain text and SSL-encrypted communication. * mxODBC Connect Client now allows selecting the used SSL module from two available options: Python standard lib ssl module and pyOpenSSL. For the full set of changes, please check the mxODBC Connect change log. http://www.egenix.com/products/python/mxODBCConnect/changelog.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 2.0 licenses can request 20% discount coupons for upgrade purchases. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 20 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-08-25: FrOSCon, St. Augustin, Germany ... 5 days to go ::: 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 __peter__ at web.de Mon Aug 20 08:45:28 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Aug 2012 14:45:28 +0200 Subject: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? References: <45524fc1-12df-4201-8c0a-9f27f41bc402@googlegroups.com> Message-ID: crispy wrote: > Thanks, i've finally came to solution. > > Here it is -> http://codepad.org/Q70eGkO8 > > def pairwiseScore(seqA, seqB): > > score = 0 > bars = [str(' ') for x in seqA] # ... > length = len(seqA) > similarity = [] > > for x in xrange(length): > > if seqA[x] == seqB[x]: # ... > if (x >= 1) and (seqA[x - 1] == seqB[x - 1]): # ... > score += 3 > similarity.append(x) > else: > score += 1 > similarity.append(x) > else: > score -= 1 > > for x in similarity: > bars[x] = '|' # ... > > return ''.join((seqA, '\n', ''.join(bars), '\n', seqB, '\n', 'Score: ', str(score))) > Python has a function zip() that lets you iterate over multiple sequences simultaneously. Instead of for i in xrange(len(a)): x = a[i] y = b[i] ... you can write for x, y in zip(a, b): ... Also, you can build the bar list immediately and avoid the similarity list. With these changes: def pairwise_score(a, b): score = 0 was_equal = False bars = [] for x, y in zip(a, b): equal = x == y if equal: bars.append("|") if was_equal: score += 3 else: score += 1 else: bars.append(" ") score -= 1 was_equal = equal print a print "".join(bars) print b print "Score:", score If you want to take this even further you can use a score matrix instead of if ... else: def pairwise_score(a, b): score = 0 was_equal = False bars = [] matrix = [[-1, 1], [-1, 3]] for x, y in zip(a, b): equal = x == y score += matrix[was_equal][equal] bars.append(" |"[equal]) was_equal = equal print a print "".join(bars) print b print "Score:", score From steve+comp.lang.python at pearwood.info Mon Aug 20 09:14:02 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Aug 2012 13:14:02 GMT Subject: Why doesn't Python remember the initial directory? References: Message-ID: <5032381a$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Aug 2012 12:56:42 +0100, andrea crotti wrote: > In the specific case there is absolutely no use of os.chdir, since you > can: > - use absolute paths > - things like subprocess.Popen accept a cwd argument - at worst you can > chdir back to the previous position right after the broken thing that > require a certain path that you are calling is run I wouldn't say so much that there's "absolutely no use", it's more that there are other, safer, ways to get the same result. As I understand it, os.chdir is more for the convenience of sys admins who want to write quick scripts in Python than a function intended to be used in libraries or major applications. An interesting question is, what do other languages do in this case? -- Steven From roy at panix.com Mon Aug 20 09:17:07 2012 From: roy at panix.com (Roy Smith) Date: Mon, 20 Aug 2012 09:17:07 -0400 Subject: New internal string format in 3.3 References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: In article , Michael Torrie wrote: > Python generally tries to follow unicode > encoding rules to the letter. Thus if a piece of text cannot be > represented in the character set of the terminal, then Python will > properly err out. Other languages you have tried, likely fudge it > somehow. And if you want the "fudge it somehow" behavior (which is often very useful!), there's always http://pypi.python.org/pypi/Unidecode/ From ganeshreddyk at gmail.com Mon Aug 20 09:31:53 2012 From: ganeshreddyk at gmail.com (Ganesh Reddy K) Date: Mon, 20 Aug 2012 19:01:53 +0530 Subject: python 6 compilation failure on RHEL Message-ID: Hi All, We are trying python 2.6 installation on an RHEL PC , whose 'uname -a' is (Linux 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux ) But, python compilation is not successfully done and showing a failure log. Below is the capture of the same. Please see failure log shown in the bottom of this mail. How to solve the failure modules mentioned in the log ( bsddb185, dl , imageop, sunaudiodev ) Please guide me to proceed further. ============== capture begin ================================= cd Python- 2.6.6 # ./configure checking for --enable-universalsdk... no checking for --with-universal-archs... 32-bit checking MACHDEP... linux2 checking EXTRAPLATDIR... checking machine type as reported by uname -m... x86_64 checking for --without-gcc... no checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for --with-cxx-main=... no checking for g++... g++ configure: WARNING: By default, distutils will build C++ extension modules with "g++". If this is not intended, then set CXX on the configure command line. checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking minix/config.h usability... no checking minix/config.h presence... no checking for minix/config.h... no checking whether it is safe to define __EXTENSIONS__... yes checking for --with-suffix... checking for case-insensitive build directory... no checking LIBRARY... libpython$(VERSION).a checking LINKCC... $(PURIFY) $(MAINCC) checking for --enable-shared... no checking for --enable-profiling... checking LDLIBRARY... libpython$(VERSION).a checking for ranlib... ranlib checking for ar... ar checking for svnversion... found checking for a BSD-compatible install... /usr/bin/install -c checking for --with-pydebug... no checking whether gcc accepts -fno-strict-aliasing... yes checking whether gcc accepts -OPT:Olimit=0... no checking whether gcc accepts -Olimit 1500... no checking whether gcc supports ParseTuple __format__... no checking whether pthreads are available without options... no checking whether gcc accepts -Kpthread... no checking whether gcc accepts -Kthread... no checking whether gcc accepts -pthread... yes checking whether g++ also accepts flags for thread support... yes checking for ANSI C header files... (cached) yes checking asm/types.h usability... yes checking asm/types.h presence... yes checking for asm/types.h... yes checking conio.h usability... no checking conio.h presence... no checking for conio.h... no checking curses.h usability... yes checking curses.h presence... yes checking for curses.h... yes checking direct.h usability... no checking direct.h presence... no checking for direct.h... no checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking errno.h usability... yes checking errno.h presence... yes checking for errno.h... yes checking fcntl.h usability... yes checking fcntl.h presence... yes checking for fcntl.h... yes checking grp.h usability... yes checking grp.h presence... yes checking for grp.h... yes checking ieeefp.h usability... no checking ieeefp.h presence... no checking for ieeefp.h... no checking io.h usability... no checking io.h presence... no checking for io.h... no checking langinfo.h usability... yes checking langinfo.h presence... yes checking for langinfo.h... yes checking libintl.h usability... yes checking libintl.h presence... yes checking for libintl.h... yes checking ncurses.h usability... yes checking ncurses.h presence... yes checking for ncurses.h... yes checking poll.h usability... yes checking poll.h presence... yes checking for poll.h... yes checking process.h usability... no checking process.h presence... no checking for process.h... no checking pthread.h usability... yes checking pthread.h presence... yes checking for pthread.h... yes checking shadow.h usability... yes checking shadow.h presence... yes checking for shadow.h... yes checking signal.h usability... yes checking signal.h presence... yes checking for signal.h... yes checking for stdint.h... (cached) yes checking stropts.h usability... yes checking stropts.h presence... yes checking for stropts.h... yes checking termios.h usability... yes checking termios.h presence... yes checking for termios.h... yes checking thread.h usability... no checking thread.h presence... no checking for thread.h... no checking for unistd.h... (cached) yes checking utime.h usability... yes checking utime.h presence... yes checking for utime.h... yes checking sys/audioio.h usability... no checking sys/audioio.h presence... no checking for sys/audioio.h... no checking sys/bsdtty.h usability... no checking sys/bsdtty.h presence... no checking for sys/bsdtty.h... no checking sys/epoll.h usability... yes checking sys/epoll.h presence... yes checking for sys/epoll.h... yes checking sys/event.h usability... no checking sys/event.h presence... no checking for sys/event.h... no checking sys/file.h usability... yes checking sys/file.h presence... yes checking for sys/file.h... yes checking sys/loadavg.h usability... no checking sys/loadavg.h presence... no checking for sys/loadavg.h... no checking sys/lock.h usability... no checking sys/lock.h presence... no checking for sys/lock.h... no checking sys/mkdev.h usability... no checking sys/mkdev.h presence... no checking for sys/mkdev.h... no checking sys/modem.h usability... no checking sys/modem.h presence... no checking for sys/modem.h... no checking sys/param.h usability... yes checking sys/param.h presence... yes checking for sys/param.h... yes checking sys/poll.h usability... yes checking sys/poll.h presence... yes checking for sys/poll.h... yes checking sys/select.h usability... yes checking sys/select.h presence... yes checking for sys/select.h... yes checking sys/socket.h usability... yes checking sys/socket.h presence... yes checking for sys/socket.h... yes checking sys/statvfs.h usability... yes checking sys/statvfs.h presence... yes checking for sys/statvfs.h... yes checking for sys/stat.h... (cached) yes checking sys/termio.h usability... no checking sys/termio.h presence... no checking for sys/termio.h... no checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking sys/times.h usability... yes checking sys/times.h presence... yes checking for sys/times.h... yes checking for sys/types.h... (cached) yes checking sys/un.h usability... yes checking sys/un.h presence... yes checking for sys/un.h... yes checking sys/utsname.h usability... yes checking sys/utsname.h presence... yes checking for sys/utsname.h... yes checking sys/wait.h usability... yes checking sys/wait.h presence... yes checking for sys/wait.h... yes checking pty.h usability... yes checking pty.h presence... yes checking for pty.h... yes checking libutil.h usability... no checking libutil.h presence... no checking for libutil.h... no checking sys/resource.h usability... yes checking sys/resource.h presence... yes checking for sys/resource.h... yes checking netpacket/packet.h usability... yes checking netpacket/packet.h presence... yes checking for netpacket/packet.h... yes checking sysexits.h usability... yes checking sysexits.h presence... yes checking for sysexits.h... yes checking bluetooth.h usability... no checking bluetooth.h presence... no checking for bluetooth.h... no checking bluetooth/bluetooth.h usability... yes checking bluetooth/bluetooth.h presence... yes checking for bluetooth/bluetooth.h... yes checking linux/tipc.h usability... yes checking linux/tipc.h presence... yes checking for linux/tipc.h... yes checking for dirent.h that defines DIR... yes checking for library containing opendir... none required checking whether sys/types.h defines makedev... yes checking for term.h... yes checking for linux/netlink.h... yes checking for clock_t in time.h... yes checking for makedev... yes checking Solaris LFS bug... no checking for mode_t... yes checking for off_t... yes checking for pid_t... yes checking return type of signal handlers... void checking for size_t... yes checking for uid_t in sys/types.h... yes checking for ssize_t... yes checking size of int... 4 checking size of long... 8 checking size of void *... 8 checking size of short... 2 checking size of float... 4 checking size of double... 8 checking size of fpos_t... 16 checking size of size_t... 8 checking size of pid_t... 4 checking for long long support... yes checking size of long long... 8 checking for long double support... yes checking size of long double... 16 checking for _Bool support... yes checking size of _Bool... 1 checking for uintptr_t... yes checking size of uintptr_t... 8 checking size of off_t... 8 checking whether to enable large file support... no checking size of time_t... 8 checking for pthread_t... yes checking size of pthread_t... 8 checking for --enable-toolbox-glue... no checking for --enable-framework... no checking for dyld... no checking SO... .so checking LDSHARED... $(CC) -shared checking CCSHARED... -fPIC checking LINKFORSHARED... -Xlinker -export-dynamic checking CFLAGSFORSHARED... checking SHLIBS... $(LIBS) checking for dlopen in -ldl... yes checking for shl_load in -ldld... no checking for library containing sem_init... -lpthread checking for textdomain in -lintl... no checking for t_open in -lnsl... no checking for socket in -lsocket... no checking for --with-libs... no checking for --with-system-ffi... checking for --with-signal-module... yes checking for --with-dec-threads... no checking for --with-threads... yes checking if PTHREAD_SCOPE_SYSTEM is supported... yes checking for pthread_sigmask... yes checking if --enable-ipv6 is specified... no checking for OSX 10.5 SDK or later... no checking for --with-doc-strings... yes checking for --with-tsc... no checking for --with-pymalloc... yes checking for --with-wctype-functions... no checking for dlopen... yes checking DYNLOADFILE... dynload_shlib.o checking MACHDEP_OBJS... MACHDEP_OBJS checking for alarm... yes checking for setitimer... yes checking for getitimer... yes checking for bind_textdomain_codeset... yes checking for chown... yes checking for clock... yes checking for confstr... yes checking for ctermid... yes checking for execv... yes checking for fchmod... yes checking for fchown... yes checking for fork... yes checking for fpathconf... yes checking for ftime... yes checking for ftruncate... yes checking for gai_strerror... yes checking for getgroups... yes checking for getlogin... yes checking for getloadavg... yes checking for getpeername... yes checking for getpgid... yes checking for getpid... yes checking for getpriority... yes checking for getpwent... yes checking for getspnam... yes checking for getspent... yes checking for getsid... yes checking for getwd... yes checking for kill... yes checking for killpg... yes checking for lchmod... no checking for lchown... yes checking for lstat... yes checking for mkfifo... yes checking for mknod... yes checking for mktime... yes checking for mremap... yes checking for nice... yes checking for pathconf... yes checking for pause... yes checking for plock... no checking for poll... yes checking for pthread_init... no checking for putenv... yes checking for readlink... yes checking for realpath... yes checking for select... yes checking for setegid... yes checking for seteuid... yes checking for setgid... yes checking for setlocale... yes checking for setregid... yes checking for setreuid... yes checking for setsid... yes checking for setpgid... yes checking for setpgrp... yes checking for setuid... yes checking for setvbuf... yes checking for snprintf... yes checking for sigaction... yes checking for siginterrupt... yes checking for sigrelse... yes checking for strftime... yes checking for sysconf... yes checking for tcgetpgrp... yes checking for tcsetpgrp... yes checking for tempnam... yes checking for timegm... yes checking for times... yes checking for tmpfile... yes checking for tmpnam... yes checking for tmpnam_r... yes checking for truncate... yes checking for uname... yes checking for unsetenv... yes checking for utimes... yes checking for waitpid... yes checking for wait3... yes checking for wait4... yes checking for wcscoll... yes checking for _getpty... no checking for chroot... yes checking for link... yes checking for symlink... yes checking for fchdir... yes checking for fsync... yes checking for fdatasync... yes checking for epoll... yes checking for kqueue... no checking for ctermid_r... no checking for flock... yes checking for getpagesize... yes checking for true... true checking for inet_aton in -lc... yes checking for chflags... no checking for lchflags... no checking for inflateCopy in -lz... yes checking for hstrerror... yes checking for inet_aton... yes checking for inet_pton... yes checking for setgroups... yes checking for openpty... no checking for openpty in -lutil... yes checking for forkpty... yes checking for memmove... yes checking for fseek64... no checking for fseeko... yes checking for fstatvfs... yes checking for ftell64... no checking for ftello... yes checking for statvfs... yes checking for dup2... yes checking for getcwd... yes checking for strdup... yes checking for getpgrp... yes checking for setpgrp... (cached) yes checking for gettimeofday... yes checking for major... yes checking for getaddrinfo... yes checking getaddrinfo bug... good checking for getnameinfo... yes checking whether time.h and sys/time.h may both be included... yes checking whether struct tm is in sys/time.h or time.h... time.h checking for struct tm.tm_zone... yes checking for struct stat.st_rdev... yes checking for struct stat.st_blksize... yes checking for struct stat.st_flags... no checking for struct stat.st_gen... no checking for struct stat.st_birthtime... no checking for struct stat.st_blocks... yes checking for time.h that defines altzone... no checking whether sys/select.h and sys/time.h may both be included... yes checking for addrinfo... yes checking for sockaddr_storage... yes checking whether char is unsigned... no checking for an ANSI C-conforming const... yes checking for working volatile... yes checking for working signed char... yes checking for prototypes... yes checking for variable length prototypes and stdarg.h... yes checking for socketpair... yes checking if sockaddr has sa_len member... no checking whether va_list is an array... yes checking for gethostbyname_r... yes checking gethostbyname_r with 6 args... yes checking for __fpu_control... yes checking for --with-fpectl... no checking for --with-libm=STRING... default LIBM="-lm" checking for --with-libc=STRING... default LIBC="" checking for x87-style double rounding... no checking whether tanh preserves the sign of zero... yes checking for acosh... yes checking for asinh... yes checking for atanh... yes checking for copysign... yes checking for expm1... yes checking for finite... yes checking for hypot... yes checking for log1p... yes checking whether isinf is declared... yes checking whether isnan is declared... yes checking whether isfinite is declared... yes checking wchar.h usability... yes checking wchar.h presence... yes checking for wchar.h... yes checking size of wchar_t... 4 checking for UCS-4 tcl... no checking whether wchar_t is signed... yes checking what type to use for unicode... unsigned short checking whether byte ordering is bigendian... no checking whether right shift extends the sign bit... yes checking for getc_unlocked() and friends... yes checking how to link readline libs... -lreadline -lncursesw checking for rl_callback_handler_install in -lreadline... yes checking for rl_pre_input_hook in -lreadline... yes checking for rl_completion_display_matches_hook in -lreadline... yes checking for rl_completion_matches in -lreadline... yes checking for broken nice()... no checking for broken poll()... no checking for struct tm.tm_zone... (cached) yes checking for working tzset()... yes checking for tv_nsec in struct stat... yes checking for tv_nsec2 in struct stat... no checking whether mvwdelch is an expression... yes checking whether WINDOW has _flags... yes checking for is_term_resized... yes checking for resize_term... yes checking for resizeterm... yes checking for /dev/ptmx... yes checking for /dev/ptc... no checking for %zd printf() format support... yes checking for socklen_t... yes checking for build directories... done configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating Makefile [root at 117mc214 Python-2.6.6]# make .. . /Modules/_ctypes/malloc_closure.o build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/prep_cif.o build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/ffi64.o build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/unix64.o build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/ffi.o build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/sysv.o -L/usr/local/lib -o build/lib.linux-x86_64-2.6/_ctypes.so Failed to find the necessary bits to build these modules: bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. running build_scripts creating build/scripts-2.6 copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/pydoc -> build/scripts-2.6 copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/idle -> build/scripts-2.6 copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/2to3 -> build/scripts-2.6 copying and adjusting /home/b38514/Python-2.6.6/Lib/smtpd.py -> build/scripts-2.6 changing mode of build/scripts-2.6/pydoc from 644 to 755 changing mode of build/scripts-2.6/idle from 644 to 755 changing mode of build/scripts-2.6/2to3 from 644 to 755 changing mode of build/scripts-2.6/smtpd.py from 644 to 755 [root at 117mc214 Python-2.6.6]# ============== capture end ==================== From hansmu at xs4all.nl Mon Aug 20 09:38:14 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 20 Aug 2012 15:38:14 +0200 Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> Message-ID: <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> On 20/08/12 14:36:58, Guillaume Comte wrote: > In fact, socket.create_connection is for TCP only so I cannot use it for a ping implementation. Why are you trying to reimplement ping? All OS'es I am aware of come with a working ping implementation. > Does anyone have an idea about how to be able to set a source address for ICMP messages? Did you try not setting it? The default is probably your own IP address, which is the only sensible value anyway. Or are you trying to cause confusion by sending ICMP packets with a forged source address? -- HansM From walterhurry at lavabit.com Mon Aug 20 09:49:04 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 20 Aug 2012 13:49:04 +0000 (UTC) Subject: Why doesn't Python remember the initial directory? References: <5032381a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 20 Aug 2012 13:14:02 +0000, Steven D'Aprano wrote: > On Mon, 20 Aug 2012 12:56:42 +0100, andrea crotti wrote: > >> In the specific case there is absolutely no use of os.chdir, since you >> can: >> - use absolute paths - things like subprocess.Popen accept a cwd >> argument - at worst you can chdir back to the previous position right >> after the broken thing that require a certain path that you are calling >> is run > > > I wouldn't say so much that there's "absolutely no use", it's more that > there are other, safer, ways to get the same result. > > As I understand it, os.chdir is more for the convenience of sys admins > who want to write quick scripts in Python than a function intended to be > used in libraries or major applications. > I don't disagree, but in my experience few sysadmins use Python; they use shell scripts. And these seldom do a 'cd' anyway - they will normally operate irrespective of the current working directory. It is difficult to think of a sensible use for os.chdir, IMHO. > An interesting question is, what do other languages do in this case? From emile at fenx.com Mon Aug 20 09:50:05 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Aug 2012 06:50:05 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 6:31 AM Ganesh Reddy K said... > But, python compilation is not successfully done and showing a failure > log. Below is the capture of the same. Please see failure log shown > in the bottom of this mail. > How to solve the failure modules mentioned in the log ( bsddb185, > dl , imageop, sunaudiodev ) > > Please guide me to proceed further. You're done, unless you specifically need support for any of those specific modules. Emile From nospam at nospam.com Mon Aug 20 09:50:43 2012 From: nospam at nospam.com (Gilles) Date: Mon, 20 Aug 2012 15:50:43 +0200 Subject: [CGI] Basic newbie error or server configuration error? References: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> Message-ID: On Mon, 20 Aug 2012 07:59:39 -0400, Rod Person wrote: >Check the Apache error log, there should be more information there. It's a shared account, so I only have access to what's in cPanel, which didn't display anything. Problem solved. Thank you. From roy at panix.com Mon Aug 20 09:58:15 2012 From: roy at panix.com (Roy Smith) Date: Mon, 20 Aug 2012 09:58:15 -0400 Subject: Why doesn't Python remember the initial directory? References: <5032381a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Walter Hurry wrote: > It is difficult to think of a sensible use for os.chdir, IMHO. It is true that you can mostly avoid chdir() by building absolute pathnames, but it's often more convenient to just cd somewhere and use names relative to that. Fabric (a very cool tool for writing remote sysadmin scripts), gives you a cd() command which is a context manager, making it extra convenient. Also, core files get created in the current directory. Sometimes daemons will cd to some fixed location to make sure that if they dump core, it goes in the right place. On occasion, you run into (poorly designed, IMHO) utilities which insist of reading or writing a file in the current directory. If you're invoking one of those, you may have no choice but to chdir() to the right place before running them. From levinie001 at gmail.com Mon Aug 20 10:01:12 2012 From: levinie001 at gmail.com (Levi Nie) Date: Mon, 20 Aug 2012 22:01:12 +0800 Subject: Does Polymorphism mean python can create object? Message-ID: Does Polymorphism mean python can create object? -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Mon Aug 20 10:15:37 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Mon, 20 Aug 2012 15:15:37 +0100 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: <5032381a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2012/8/20 Roy Smith : > In article , > Walter Hurry wrote: > >> It is difficult to think of a sensible use for os.chdir, IMHO. > > It is true that you can mostly avoid chdir() by building absolute > pathnames, but it's often more convenient to just cd somewhere and use > names relative to that. Fabric (a very cool tool for writing remote > sysadmin scripts), gives you a cd() command which is a context manager, > making it extra convenient. > > Also, core files get created in the current directory. Sometimes > daemons will cd to some fixed location to make sure that if they dump > core, it goes in the right place. > > On occasion, you run into (poorly designed, IMHO) utilities which insist > of reading or writing a file in the current directory. If you're > invoking one of those, you may have no choice but to chdir() to the > right place before running them. > -- > http://mail.python.org/mailman/listinfo/python-list I've done quite a lot of system programming as well, and changing directory is only a source of possible troubles in general. If I really have to for some reasons I do this class TempCd: """Change temporarily the current directory """ def __init__(self, newcwd): self.newcwd = newcwd self.oldcwd = getcwd() def __enter__(self): chdir(self.newcwd) return self def __exit__(self, type, value, traceback): chdir(self.oldcwd) with TempCd('/tmp'): # now working in /tmp # now in the original So it's not that hard to avoid problems.. From rosuav at gmail.com Mon Aug 20 10:24:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Aug 2012 00:24:56 +1000 Subject: Does Polymorphism mean python can create object? In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: > Does Polymorphism mean python can create object? I'm not sure what your question means. Could you rephrase, please? Also, this document may be useful to you: http://www.catb.org/~esr/faqs/smart-questions.html Chris Angelico From jeanmichel at sequans.com Mon Aug 20 10:39:47 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 20 Aug 2012 16:39:47 +0200 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: <50324C33.7020103@sequans.com> kj wrote: > 99.99% of Python programmers > will find that there's nothing wrong with behavior [snip] > Pardon my cynicism, but the general vibe from the replies I've > gotten to my post (i.e. "if Python ain't got it, it means you don't > need it") > [snip] Don't you find there's something wrong in applying your observation from 2 or 3 replies to your post to 99% of python programmer ? Moreover, flaming people on their own mailing list won't do you any good, ever, in any list. To get back to your original question, > inspect.getmodule? Docstring: Return the module an object was defined in, or None if not found. As getmodule may return None if not found, you need too handle that case. There's possibly a weakness in the inspect module when changing the current directory however nothing wrong with Python having the remember the intial directory. If you need to remember it, do it youself (or file a bug to inspect module authors). JM From jeanmichel at sequans.com Mon Aug 20 10:52:42 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 20 Aug 2012 16:52:42 +0200 Subject: How to convert base 10 to base 2? In-Reply-To: <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> Message-ID: <50324F3A.7040001@sequans.com> gianpycea at gmail.com wrote: > On Monday, August 20, 2012 9:50:53 AM UTC+2, (unknown) wrote: > >> Hi, >> >> as you can argue from the subject, i'm really,really new to python. >> >> What is the best way to achieve that with python? Because the syntax int('30',2) doesn't seem to work! >> > > Thank you all for the big help! > @Mark Lawrence > Yes, you're definetely right: i should have posted my OS and the version but being a very rough question on syntax i thought it didn't really matter. > I've quite a good general programming experience. I know Java,Visual Basic.NET,Pascal and Mathematica. > note that the builtin bin function is not available with python ver < 2.6 def Denary2Binary(n): '''convert denary integer n to binary string bStr''' bStr = '' if n < 0: raise ValueError, "must be a positive integer" if n == 0: return '0' while n > 0: bStr = str(n % 2) + bStr n = n >> 1 return bStr JM (not my function but I can't remember who I stole from) From hansmu at xs4all.nl Mon Aug 20 10:56:14 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 20 Aug 2012 16:56:14 +0200 Subject: [CGI] Basic newbie error or server configuration error? In-Reply-To: References: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> Message-ID: <5032500e$0$6925$e4fe514c@news2.news.xs4all.nl> On 20/08/12 15:50:43, Gilles wrote: > On Mon, 20 Aug 2012 07:59:39 -0400, Rod Person > wrote: >> Check the Apache error log, there should be more information there. > > It's a shared account, so I only have access to what's in cPanel, > which didn't display anything. Most such panels have a button to show the error log for your own site. If you can't find it, ask the help desk of the web hosting company. If there really is no way for you to see the error log, ask the help desk to mail you the error message. -- HansM From guillaume.comte10 at gmail.com Mon Aug 20 11:04:40 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Mon, 20 Aug 2012 08:04:40 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> Message-ID: Le lundi 20 ao?t 2012 15:38:14 UTC+2, Hans Mulder a ?crit?: > On 20/08/12 14:36:58, Guillaume Comte wrote: > > > In fact, socket.create_connection is for TCP only so I cannot use it for a ping implementation. > > > > Why are you trying to reimplement ping? Because I work on a network emulator and I want to check biterros patterns so I need to access the data of the packets. An dsince my test program is written in Python, it's easier to do it in Python. > > > > All OS'es I am aware of come with a working ping implementation. > > > > > > > Does anyone have an idea about how to be able to set a source address for ICMP messages? > > > > Did you try not setting it? > > > > The default is probably your own IP address, which is the only > > sensible value anyway. Or are you trying to cause confusion > > by sending ICMP packets with a forged source address? No, I want to do it on a machine with aliases as in: ifconfig em0 10.0.1.1 netmask 255.255.255.0 alias ifconfig em0 10.0.2.1 netmask 255.255.255.0 alias ping -c4 -S 10.0.1.1 10.0.2.1 But I think I've found the solution: my_socket.bind((src_addr, 1)) > > > > -- HansM From jeanmichel at sequans.com Mon Aug 20 11:09:12 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 20 Aug 2012 17:09:12 +0200 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <502ef334$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50325318.3020507@sequans.com> Zero Piraeus wrote: > : > > On 17 August 2012 21:43, Steven D'Aprano > wrote: > >> There are cultures that marry five year old girls to sixty year old men, >> cultures that treat throwing acid in the faces of women as acceptable >> behaviour, cultures that allow war heroes to die of hunger and cold >> homeless in the street, and cultures that top-post. What's your point? >> > > +1 QOTW > > -[]z. > We're closer to the +1 godwin point JM From rosuav at gmail.com Mon Aug 20 11:38:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Aug 2012 01:38:03 +1000 Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> Message-ID: On Mon, Aug 20, 2012 at 11:38 PM, Hans Mulder wrote: > Why are you trying to reimplement ping? > > All OS'es I am aware of come with a working ping implementation. For some definition of "working", at least. I've never managed to get MS Windows to ping broadcast, for instance. A Google search for 'python ping' comes up with a few good answers, though. You may want to have a look at some of them; if nothing else, you'll get confirmation that what you're doing corresponds to what someone else has done (which isn't proof you're doing the right thing, but it does suggest it). ChrisA From nospam at nospam.com Mon Aug 20 11:51:44 2012 From: nospam at nospam.com (Gilles) Date: Mon, 20 Aug 2012 17:51:44 +0200 Subject: [CGI] Basic newbie error or server configuration error? References: <6c84389rqmrj01cppc0ppiedqd44o4mfdf@4ax.com> <5032500e$0$6925$e4fe514c@news2.news.xs4all.nl> Message-ID: <02n43856s6jcnkis3oempcftn1fiq67nnl@4ax.com> On Mon, 20 Aug 2012 16:56:14 +0200, Hans Mulder wrote: >Most such panels have a button to show the error log for your own site. > >If you can't find it, ask the help desk of the web hosting company. > >If there really is no way for you to see the error log, ask the help >desk to mail you the error message. Thanks. the cPanel at my provider only has a Logs > Error Log icon, but the error I was having didn't result in anything in the log file. I'll set up a Linux host at home and test Python scripts before uploading them to my ISP. Thank you. From no.email at nospam.invalid Mon Aug 20 12:01:21 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 20 Aug 2012 09:01:21 -0700 Subject: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: <7xr4r1pn72.fsf@ruckus.brouhaha.com> Oscar Benjamin writes: > No it doen't. It is still O(k). The point of big O notation is to > understand the asymptotic behaviour of one variable as it becomes > large because of changes in other variables. Actually, two separate problems got mixed together late at night. In neither case is k an independent variable that ranges over all possible values. In both cases it is selected or observed by measurement (i.e. it is a dependent variable determined by something that is itself not independent). 1) Access in a rope: here, k is basically determined by the pointer size of the computer, which in CPython (the implementation we're discussing) the pointer size is 4 or 8 bytes (constants) in all instances AFAIK. k should be a big enough that the pointer and allocation overhead is small compared to bloating the strings with UCS-2 or UCS-4, and small enough to not add much scan time. It seems realistic to say k<=128 for this (several times smaller is probably fine). 128 is of course a constant and not a variable. We are not concerned about hypothetical computers with billion bit pointers. 2) Parsing tokens: here, k is drawn from a fixed probability distribution such that its expectation value is again a small constant (this is an assertion about the data looks like in typical parsing applications in the real world, not what is mathematically possible). The average-case complexity (I said "amortized" earlier but should have said "average-case") is proportional to that constant, which is to say, O(1). Of course there is still more wiggle room about what is "typical". Analogy: how big a box is required to hold a pair of shoes? In a purely theoretical sense we might say O(S) where S is the shoe size, treating shoe size as an arbitrary independent variable. But in the real world, shoe size is controlled by the size of human feet, which is bounded by a constant for biological reasons. You don't have to consider shoes the size of Jupiter. So it is O(1). From rosuav at gmail.com Mon Aug 20 12:09:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Aug 2012 02:09:18 +1000 Subject: Abuse of Big Oh notation In-Reply-To: <7xr4r1pn72.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> Message-ID: On Tue, Aug 21, 2012 at 2:01 AM, Paul Rubin wrote: > Analogy: how big a box is required to hold a pair of shoes? In a purely > theoretical sense we might say O(S) where S is the shoe size, treating > shoe size as an arbitrary independent variable. But in the real world, > shoe size is controlled by the size of human feet, which is bounded by a > constant for biological reasons. You don't have to consider shoes the > size of Jupiter. So it is O(1). By that argument, everything is amortized O(1), because there's a limit on every variable. You can't possibly be working with a data set greater than the total sum of storage space in the entire world. That still doesn't mean that bubble sort and heap sort are equivalently efficient. ChrisA From bv8bv8bv8 at gmail.com Mon Aug 20 12:10:27 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Mon, 20 Aug 2012 09:10:27 -0700 (PDT) Subject: woman in islam Message-ID: woman in islam http://www.youtube.com/watch?v=ZXEScVFANvA&feature=related Thank you From invalid at invalid.invalid Mon Aug 20 12:28:59 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 20 Aug 2012 16:28:59 +0000 (UTC) Subject: Why doesn't Python remember the initial directory? References: Message-ID: On 2012-08-20, kj wrote: > In Roy Smith writes: > >>In article , kj >>wrote: > >>> As far as I've been able to determine, Python does not remember >>> (immutably, that is) the working directory at the program's start-up, >>> or, if it does, it does not officially expose this information. > >>Why would you expect that it would? What would it (or you) do with this >>information? > > This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. What makes you think that the file that contains the definition of __main__ is the working directory on program startup? That's almost never the case in my experience. 2) Why should a library expect to be able to access the file containing the definition of __main__. > That's a weakness, IMO. You must be in possession of some rather odd use cases. I've been writing Python programs for something like 13 years, and I've never felt any need to have either an immutable record of the startup directory or access to the file containing the definition of __main__. > I don't know of any way to fix inspect.getmodule that does not > involve, directly or indirectly, keeping a stable record of the > starting directory. If what you really want is access to the definition of __main__, what does that have to do with the startup directory? If you want to know where __main__ is, you can probably figure it out from /proc/self/ -- Grant Edwards grant.b.edwards Yow! Am I having fun yet? at gmail.com From oscar.benjamin at bristol.ac.uk Mon Aug 20 12:53:05 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Mon, 20 Aug 2012 17:53:05 +0100 Subject: Abuse of Big Oh notation In-Reply-To: <7xr4r1pn72.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> Message-ID: On 20 August 2012 17:01, Paul Rubin wrote: > Oscar Benjamin writes: > > No it doen't. It is still O(k). The point of big O notation is to > > understand the asymptotic behaviour of one variable as it becomes > > large because of changes in other variables. > > Actually, two separate problems got mixed together late at night. In > neither case is k an independent variable that ranges over all possible > values. In both cases it is selected or observed by measurement (i.e. > it is a dependent variable determined by something that is itself not > independent). > > 1) Access in a rope: here, k is basically determined by the pointer size > of the computer, which in CPython (the implementation we're discussing) > the pointer size is 4 or 8 bytes (constants) in all instances AFAIK. k > should be a big enough that the pointer and allocation overhead is small > compared to bloating the strings with UCS-2 or UCS-4, and small enough > to not add much scan time. It seems realistic to say k<=128 for this > (several times smaller is probably fine). 128 is of course a constant > and not a variable. We are not concerned about hypothetical computers > with billion bit pointers. > Okay, I see what you mean. If k is a hard-coded constant then it's not unreasonable to say that O(k) is constant time in relation to the input data (however big k is). Oscar. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Mon Aug 20 13:12:05 2012 From: kwpolska at gmail.com (Kwpolska) Date: Mon, 20 Aug 2012 19:12:05 +0200 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On Mon, Aug 20, 2012 at 3:31 PM, Ganesh Reddy K wrote: > Hi All, > > We are trying python 2.6 installation on an RHEL PC , > > whose 'uname -a' is (Linux 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 > EST 2008 x86_64 x86_64 x86_64 GNU/Linux ) > > > But, python compilation is not successfully done and showing a failure > log. Below is the capture of the same. Please see failure log shown > in the bottom of this mail. > How to solve the failure modules mentioned in the log ( bsddb185, > dl , imageop, sunaudiodev ) > > Please guide me to proceed further. > > ============== capture begin ================================= > cd Python- 2.6.6 > > # ./configure > checking for --enable-universalsdk... no > checking for --with-universal-archs... 32-bit > checking MACHDEP... linux2 > checking EXTRAPLATDIR... > checking machine type as reported by uname -m... x86_64 > checking for --without-gcc... no > checking for gcc... gcc > checking whether the C compiler works... yes > checking for C compiler default output file name... a.out > checking for suffix of executables... > checking whether we are cross compiling... no > checking for suffix of object files... o > checking whether we are using the GNU C compiler... yes > checking whether gcc accepts -g... yes > checking for gcc option to accept ISO C89... none needed > checking for --with-cxx-main=... no > checking for g++... g++ > configure: WARNING: > > By default, distutils will build C++ extension modules with "g++". > If this is not intended, then set CXX on the configure command line. > > checking how to run the C preprocessor... gcc -E > checking for grep that handles long lines and -e... /bin/grep > checking for egrep... /bin/grep -E > checking for ANSI C header files... yes > checking for sys/types.h... yes > checking for sys/stat.h... yes > checking for stdlib.h... yes > checking for string.h... yes > checking for memory.h... yes > checking for strings.h... yes > checking for inttypes.h... yes > checking for stdint.h... yes > checking for unistd.h... yes > checking minix/config.h usability... no > checking minix/config.h presence... no > checking for minix/config.h... no > checking whether it is safe to define __EXTENSIONS__... yes > checking for --with-suffix... > checking for case-insensitive build directory... no > checking LIBRARY... libpython$(VERSION).a > checking LINKCC... $(PURIFY) $(MAINCC) > checking for --enable-shared... no > checking for --enable-profiling... > checking LDLIBRARY... libpython$(VERSION).a > checking for ranlib... ranlib > checking for ar... ar > checking for svnversion... found > checking for a BSD-compatible install... /usr/bin/install -c > checking for --with-pydebug... no > checking whether gcc accepts -fno-strict-aliasing... yes > checking whether gcc accepts -OPT:Olimit=0... no > checking whether gcc accepts -Olimit 1500... no > checking whether gcc supports ParseTuple __format__... no > checking whether pthreads are available without options... no > checking whether gcc accepts -Kpthread... no > checking whether gcc accepts -Kthread... no > checking whether gcc accepts -pthread... yes > checking whether g++ also accepts flags for thread support... yes > checking for ANSI C header files... (cached) yes > checking asm/types.h usability... yes > checking asm/types.h presence... yes > checking for asm/types.h... yes > checking conio.h usability... no > checking conio.h presence... no > checking for conio.h... no > checking curses.h usability... yes > checking curses.h presence... yes > checking for curses.h... yes > checking direct.h usability... no > checking direct.h presence... no > checking for direct.h... no > checking dlfcn.h usability... yes > checking dlfcn.h presence... yes > checking for dlfcn.h... yes > checking errno.h usability... yes > checking errno.h presence... yes > checking for errno.h... yes > checking fcntl.h usability... yes > checking fcntl.h presence... yes > checking for fcntl.h... yes > checking grp.h usability... yes > checking grp.h presence... yes > checking for grp.h... yes > checking ieeefp.h usability... no > checking ieeefp.h presence... no > checking for ieeefp.h... no > checking io.h usability... no > checking io.h presence... no > checking for io.h... no > checking langinfo.h usability... yes > checking langinfo.h presence... yes > checking for langinfo.h... yes > checking libintl.h usability... yes > checking libintl.h presence... yes > checking for libintl.h... yes > checking ncurses.h usability... yes > checking ncurses.h presence... yes > checking for ncurses.h... yes > checking poll.h usability... yes > checking poll.h presence... yes > checking for poll.h... yes > checking process.h usability... no > checking process.h presence... no > checking for process.h... no > checking pthread.h usability... yes > checking pthread.h presence... yes > checking for pthread.h... yes > checking shadow.h usability... yes > checking shadow.h presence... yes > checking for shadow.h... yes > checking signal.h usability... yes > checking signal.h presence... yes > checking for signal.h... yes > checking for stdint.h... (cached) yes > checking stropts.h usability... yes > checking stropts.h presence... yes > checking for stropts.h... yes > checking termios.h usability... yes > checking termios.h presence... yes > checking for termios.h... yes > checking thread.h usability... no > checking thread.h presence... no > checking for thread.h... no > checking for unistd.h... (cached) yes > checking utime.h usability... yes > checking utime.h presence... yes > checking for utime.h... yes > checking sys/audioio.h usability... no > checking sys/audioio.h presence... no > checking for sys/audioio.h... no > checking sys/bsdtty.h usability... no > checking sys/bsdtty.h presence... no > checking for sys/bsdtty.h... no > checking sys/epoll.h usability... yes > checking sys/epoll.h presence... yes > checking for sys/epoll.h... yes > checking sys/event.h usability... no > checking sys/event.h presence... no > checking for sys/event.h... no > checking sys/file.h usability... yes > checking sys/file.h presence... yes > checking for sys/file.h... yes > checking sys/loadavg.h usability... no > checking sys/loadavg.h presence... no > checking for sys/loadavg.h... no > checking sys/lock.h usability... no > checking sys/lock.h presence... no > checking for sys/lock.h... no > checking sys/mkdev.h usability... no > checking sys/mkdev.h presence... no > checking for sys/mkdev.h... no > checking sys/modem.h usability... no > checking sys/modem.h presence... no > checking for sys/modem.h... no > checking sys/param.h usability... yes > checking sys/param.h presence... yes > checking for sys/param.h... yes > checking sys/poll.h usability... yes > checking sys/poll.h presence... yes > checking for sys/poll.h... yes > checking sys/select.h usability... yes > checking sys/select.h presence... yes > checking for sys/select.h... yes > checking sys/socket.h usability... yes > checking sys/socket.h presence... yes > checking for sys/socket.h... yes > checking sys/statvfs.h usability... yes > checking sys/statvfs.h presence... yes > checking for sys/statvfs.h... yes > checking for sys/stat.h... (cached) yes > checking sys/termio.h usability... no > checking sys/termio.h presence... no > checking for sys/termio.h... no > checking sys/time.h usability... yes > checking sys/time.h presence... yes > checking for sys/time.h... yes > checking sys/times.h usability... yes > checking sys/times.h presence... yes > checking for sys/times.h... yes > checking for sys/types.h... (cached) yes > checking sys/un.h usability... yes > checking sys/un.h presence... yes > checking for sys/un.h... yes > checking sys/utsname.h usability... yes > checking sys/utsname.h presence... yes > checking for sys/utsname.h... yes > checking sys/wait.h usability... yes > checking sys/wait.h presence... yes > checking for sys/wait.h... yes > checking pty.h usability... yes > checking pty.h presence... yes > checking for pty.h... yes > checking libutil.h usability... no > checking libutil.h presence... no > checking for libutil.h... no > checking sys/resource.h usability... yes > checking sys/resource.h presence... yes > checking for sys/resource.h... yes > checking netpacket/packet.h usability... yes > checking netpacket/packet.h presence... yes > checking for netpacket/packet.h... yes > checking sysexits.h usability... yes > checking sysexits.h presence... yes > checking for sysexits.h... yes > checking bluetooth.h usability... no > checking bluetooth.h presence... no > checking for bluetooth.h... no > checking bluetooth/bluetooth.h usability... yes > checking bluetooth/bluetooth.h presence... yes > checking for bluetooth/bluetooth.h... yes > checking linux/tipc.h usability... yes > checking linux/tipc.h presence... yes > checking for linux/tipc.h... yes > checking for dirent.h that defines DIR... yes > checking for library containing opendir... none required > checking whether sys/types.h defines makedev... yes > checking for term.h... yes > checking for linux/netlink.h... yes > checking for clock_t in time.h... yes > checking for makedev... yes > checking Solaris LFS bug... no > checking for mode_t... yes > checking for off_t... yes > checking for pid_t... yes > checking return type of signal handlers... void > checking for size_t... yes > checking for uid_t in sys/types.h... yes > checking for ssize_t... yes > checking size of int... 4 > checking size of long... 8 > checking size of void *... 8 > checking size of short... 2 > checking size of float... 4 > checking size of double... 8 > checking size of fpos_t... 16 > checking size of size_t... 8 > checking size of pid_t... 4 > checking for long long support... yes > checking size of long long... 8 > checking for long double support... yes > checking size of long double... 16 > checking for _Bool support... yes > checking size of _Bool... 1 > checking for uintptr_t... yes > checking size of uintptr_t... 8 > checking size of off_t... 8 > checking whether to enable large file support... no > checking size of time_t... 8 > checking for pthread_t... yes > checking size of pthread_t... 8 > checking for --enable-toolbox-glue... no > checking for --enable-framework... no > checking for dyld... no > checking SO... .so > checking LDSHARED... $(CC) -shared > checking CCSHARED... -fPIC > checking LINKFORSHARED... -Xlinker -export-dynamic > checking CFLAGSFORSHARED... > checking SHLIBS... $(LIBS) > checking for dlopen in -ldl... yes > checking for shl_load in -ldld... no > checking for library containing sem_init... -lpthread > checking for textdomain in -lintl... no > checking for t_open in -lnsl... no > checking for socket in -lsocket... no > checking for --with-libs... no > checking for --with-system-ffi... > checking for --with-signal-module... yes > checking for --with-dec-threads... no > checking for --with-threads... yes > checking if PTHREAD_SCOPE_SYSTEM is supported... yes > checking for pthread_sigmask... yes > checking if --enable-ipv6 is specified... no > checking for OSX 10.5 SDK or later... no > checking for --with-doc-strings... yes > checking for --with-tsc... no > checking for --with-pymalloc... yes > checking for --with-wctype-functions... no > checking for dlopen... yes > checking DYNLOADFILE... dynload_shlib.o > checking MACHDEP_OBJS... MACHDEP_OBJS > checking for alarm... yes > checking for setitimer... yes > checking for getitimer... yes > checking for bind_textdomain_codeset... yes > checking for chown... yes > checking for clock... yes > checking for confstr... yes > checking for ctermid... yes > checking for execv... yes > checking for fchmod... yes > checking for fchown... yes > checking for fork... yes > checking for fpathconf... yes > checking for ftime... yes > checking for ftruncate... yes > checking for gai_strerror... yes > checking for getgroups... yes > checking for getlogin... yes > checking for getloadavg... yes > checking for getpeername... yes > checking for getpgid... yes > checking for getpid... yes > checking for getpriority... yes > checking for getpwent... yes > checking for getspnam... yes > checking for getspent... yes > checking for getsid... yes > checking for getwd... yes > checking for kill... yes > checking for killpg... yes > checking for lchmod... no > checking for lchown... yes > checking for lstat... yes > checking for mkfifo... yes > checking for mknod... yes > checking for mktime... yes > checking for mremap... yes > checking for nice... yes > checking for pathconf... yes > checking for pause... yes > checking for plock... no > checking for poll... yes > checking for pthread_init... no > checking for putenv... yes > checking for readlink... yes > checking for realpath... yes > checking for select... yes > checking for setegid... yes > checking for seteuid... yes > checking for setgid... yes > checking for setlocale... yes > checking for setregid... yes > checking for setreuid... yes > checking for setsid... yes > checking for setpgid... yes > checking for setpgrp... yes > checking for setuid... yes > checking for setvbuf... yes > checking for snprintf... yes > checking for sigaction... yes > checking for siginterrupt... yes > checking for sigrelse... yes > checking for strftime... yes > checking for sysconf... yes > checking for tcgetpgrp... yes > checking for tcsetpgrp... yes > checking for tempnam... yes > checking for timegm... yes > checking for times... yes > checking for tmpfile... yes > checking for tmpnam... yes > checking for tmpnam_r... yes > checking for truncate... yes > checking for uname... yes > checking for unsetenv... yes > checking for utimes... yes > checking for waitpid... yes > checking for wait3... yes > checking for wait4... yes > checking for wcscoll... yes > checking for _getpty... no > checking for chroot... yes > checking for link... yes > checking for symlink... yes > checking for fchdir... yes > checking for fsync... yes > checking for fdatasync... yes > checking for epoll... yes > checking for kqueue... no > checking for ctermid_r... no > checking for flock... yes > checking for getpagesize... yes > checking for true... true > checking for inet_aton in -lc... yes > checking for chflags... no > checking for lchflags... no > checking for inflateCopy in -lz... yes > checking for hstrerror... yes > checking for inet_aton... yes > checking for inet_pton... yes > checking for setgroups... yes > checking for openpty... no > checking for openpty in -lutil... yes > checking for forkpty... yes > checking for memmove... yes > checking for fseek64... no > checking for fseeko... yes > checking for fstatvfs... yes > checking for ftell64... no > checking for ftello... yes > checking for statvfs... yes > checking for dup2... yes > checking for getcwd... yes > checking for strdup... yes > checking for getpgrp... yes > checking for setpgrp... (cached) yes > checking for gettimeofday... yes > checking for major... yes > checking for getaddrinfo... yes > checking getaddrinfo bug... good > checking for getnameinfo... yes > checking whether time.h and sys/time.h may both be included... yes > checking whether struct tm is in sys/time.h or time.h... time.h > checking for struct tm.tm_zone... yes > checking for struct stat.st_rdev... yes > checking for struct stat.st_blksize... yes > checking for struct stat.st_flags... no > checking for struct stat.st_gen... no > checking for struct stat.st_birthtime... no > checking for struct stat.st_blocks... yes > checking for time.h that defines altzone... no > checking whether sys/select.h and sys/time.h may both be included... yes > checking for addrinfo... yes > checking for sockaddr_storage... yes > checking whether char is unsigned... no > checking for an ANSI C-conforming const... yes > checking for working volatile... yes > checking for working signed char... yes > checking for prototypes... yes > checking for variable length prototypes and stdarg.h... yes > checking for socketpair... yes > checking if sockaddr has sa_len member... no > checking whether va_list is an array... yes > checking for gethostbyname_r... yes > checking gethostbyname_r with 6 args... yes > checking for __fpu_control... yes > checking for --with-fpectl... no > checking for --with-libm=STRING... default LIBM="-lm" > checking for --with-libc=STRING... default LIBC="" > checking for x87-style double rounding... no > checking whether tanh preserves the sign of zero... yes > checking for acosh... yes > checking for asinh... yes > checking for atanh... yes > checking for copysign... yes > checking for expm1... yes > checking for finite... yes > checking for hypot... yes > checking for log1p... yes > checking whether isinf is declared... yes > checking whether isnan is declared... yes > checking whether isfinite is declared... yes > checking wchar.h usability... yes > checking wchar.h presence... yes > checking for wchar.h... yes > checking size of wchar_t... 4 > checking for UCS-4 tcl... no > checking whether wchar_t is signed... yes > checking what type to use for unicode... unsigned short > checking whether byte ordering is bigendian... no > checking whether right shift extends the sign bit... yes > checking for getc_unlocked() and friends... yes > checking how to link readline libs... -lreadline -lncursesw > checking for rl_callback_handler_install in -lreadline... yes > checking for rl_pre_input_hook in -lreadline... yes > checking for rl_completion_display_matches_hook in -lreadline... yes > checking for rl_completion_matches in -lreadline... yes > checking for broken nice()... no > checking for broken poll()... no > checking for struct tm.tm_zone... (cached) yes > checking for working tzset()... yes > checking for tv_nsec in struct stat... yes > checking for tv_nsec2 in struct stat... no > checking whether mvwdelch is an expression... yes > checking whether WINDOW has _flags... yes > checking for is_term_resized... yes > checking for resize_term... yes > checking for resizeterm... yes > checking for /dev/ptmx... yes > checking for /dev/ptc... no > checking for %zd printf() format support... yes > checking for socklen_t... yes > checking for build directories... done > configure: creating ./config.status > config.status: creating Makefile.pre > config.status: creating Modules/Setup.config > config.status: creating pyconfig.h > creating Modules/Setup > creating Modules/Setup.local > creating Makefile > [root at 117mc214 Python-2.6.6]# make > .. > . > /Modules/_ctypes/malloc_closure.o > build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/prep_cif.o > build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/ffi64.o > build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/unix64.o > build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/ffi.o > build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/libffi/src/x86/sysv.o > -L/usr/local/lib -o build/lib.linux-x86_64-2.6/_ctypes.so > > Failed to find the necessary bits to build these modules: > bsddb185 dl imageop > sunaudiodev > To find the necessary bits, look in setup.py in detect_modules() for > the module's name. > > running build_scripts > creating build/scripts-2.6 > copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/pydoc -> > build/scripts-2.6 > copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/idle -> > build/scripts-2.6 > copying and adjusting /home/b38514/Python-2.6.6/Tools/scripts/2to3 -> > build/scripts-2.6 > copying and adjusting /home/b38514/Python-2.6.6/Lib/smtpd.py -> > build/scripts-2.6 > changing mode of build/scripts-2.6/pydoc from 644 to 755 > changing mode of build/scripts-2.6/idle from 644 to 755 > changing mode of build/scripts-2.6/2to3 from 644 to 755 > changing mode of build/scripts-2.6/smtpd.py from 644 to 755 > > [root at 117mc214 Python-2.6.6]# > ============== capture end ==================== > -- > http://mail.python.org/mailman/listinfo/python-list Do you really need to compile python2.6? RHEL has packages for python, and it's better to use pre-compiled packages rather than compile them yourself. Also, 2.6 is an old version that you should not be using 99% of the time. -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From ian.g.kelly at gmail.com Mon Aug 20 13:12:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Aug 2012 11:12:22 -0600 Subject: Abuse of Big Oh notation In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Aug 20, 2012 at 10:09 AM, Chris Angelico wrote: > On Tue, Aug 21, 2012 at 2:01 AM, Paul Rubin wrote: >> Analogy: how big a box is required to hold a pair of shoes? In a purely >> theoretical sense we might say O(S) where S is the shoe size, treating >> shoe size as an arbitrary independent variable. But in the real world, >> shoe size is controlled by the size of human feet, which is bounded by a >> constant for biological reasons. You don't have to consider shoes the >> size of Jupiter. So it is O(1). > > By that argument, everything is amortized O(1), because there's a > limit on every variable. You can't possibly be working with a data set > greater than the total sum of storage space in the entire world. That > still doesn't mean that bubble sort and heap sort are equivalently > efficient. The difference between the two is that the former is bounded by a constant that is fundamental to the algorithm at hand, whereas the latter is bounded only by available resources. By any practical consideration the latter must be considered a variable, but the former need not be. Paul discusses above the asymptotic growth of a variable as O(S) where S is shoe size, but really this measure makes no sense in the first place. The question that this notation seeks to answer is, "What is the big-Oh behaviour of this variable as shoe size increases indefinitely (i.e. to infinity)?" and the answer in this case is "Shoe size does not increase indefinitely"; the question is invalid. A more logical question might be, "How much material do I need to construct N shoes of size S?" The answer to this question would presumably be some constant factor of N * S**2, which is O(N * S**2). Although N can be assumed to vary freely (up to nonsensical quantities like the mass of the entire universe), S is clearly bounded by the constraints of actual shoes, so we can safely treat S as a constant and call it O(N). From walterhurry at lavabit.com Mon Aug 20 13:20:03 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 20 Aug 2012 17:20:03 +0000 (UTC) Subject: python 6 compilation failure on RHEL References: Message-ID: On Mon, 20 Aug 2012 19:12:05 +0200, Kwpolska wrote: > On Mon, Aug 20, 2012 at 3:31 PM, Ganesh Reddy K > wrote: >> Hi All, >> >> We are trying python 2.6 installation on an RHEL PC , >> >> whose 'uname -a' is (Linux 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 >> EST 2008 x86_64 x86_64 x86_64 GNU/Linux ) >> >> >> But, python compilation is not successfully done and showing a failure >> log. Below is the capture of the same. Please see failure log shown >> in the bottom of this mail. >> How to solve the failure modules mentioned in the log ( bsddb185, >> dl , imageop, sunaudiodev ) >> >> Please guide me to proceed further. >> >> ============== capture begin ================================= >> cd Python- 2.6.6 >> >> # ./configure checking for --enable-universalsdk... no checking for >> --with-universal-archs... 32-bit checking MACHDEP... linux2 checking >> EXTRAPLATDIR... >> checking machine type as reported by uname -m... x86_64 checking for >> --without-gcc... no checking for gcc... gcc checking whether the C >> compiler works... yes checking for C compiler default output file >> name... a.out checking for suffix of executables... >> checking whether we are cross compiling... no checking for suffix of >> object files... o checking whether we are using the GNU C compiler... >> yes checking whether gcc accepts -g... yes checking for gcc option to >> accept ISO C89... none needed checking for >> --with-cxx-main=... no checking for g++... g++ >> configure: WARNING: >> >> By default, distutils will build C++ extension modules with "g++". If >> this is not intended, then set CXX on the configure command line. >> >> checking how to run the C preprocessor... gcc -E checking for grep that >> handles long lines and -e... /bin/grep checking for egrep... /bin/grep >> -E checking for ANSI C header files... yes checking for sys/types.h... >> yes checking for sys/stat.h... yes checking for stdlib.h... yes >> checking for string.h... yes checking for memory.h... yes checking for >> strings.h... yes checking for inttypes.h... yes checking for >> stdint.h... yes checking for unistd.h... yes checking minix/config.h >> usability... no checking minix/config.h presence... no checking for >> minix/config.h... no checking whether it is safe to define >> __EXTENSIONS__... yes checking for --with-suffix... >> checking for case-insensitive build directory... no checking LIBRARY... >> libpython$(VERSION).a checking LINKCC... $(PURIFY) $(MAINCC) >> checking for --enable-shared... no checking for --enable-profiling... >> checking LDLIBRARY... libpython$(VERSION).a checking for ranlib... >> ranlib checking for ar... ar checking for svnversion... found checking >> for a BSD-compatible install... /usr/bin/install -c checking for >> --with-pydebug... no checking whether gcc accepts >> -fno-strict-aliasing... yes checking whether gcc accepts >> -OPT:Olimit=0... no checking whether gcc accepts -Olimit 1500... no >> checking whether gcc supports ParseTuple __format__... no checking >> whether pthreads are available without options... no checking whether >> gcc accepts -Kpthread... no checking whether gcc accepts -Kthread... no >> checking whether gcc accepts -pthread... yes checking whether g++ also >> accepts flags for thread support... yes checking for ANSI C header >> files... (cached) yes checking asm/types.h usability... yes checking >> asm/types.h presence... yes checking for asm/types.h... yes checking >> conio.h usability... no checking conio.h presence... no checking for >> conio.h... no checking curses.h usability... yes checking curses.h >> presence... yes checking for curses.h... yes checking direct.h >> usability... no checking direct.h presence... no checking for >> direct.h... no checking dlfcn.h usability... yes checking dlfcn.h >> presence... yes checking for dlfcn.h... yes checking errno.h >> usability... yes checking errno.h presence... yes checking for >> errno.h... yes checking fcntl.h usability... yes checking fcntl.h >> presence... yes checking for fcntl.h... yes checking grp.h usability... >> yes checking grp.h presence... yes checking for grp.h... yes checking >> ieeefp.h usability... no checking ieeefp.h presence... no checking for >> ieeefp.h... no checking io.h usability... no checking io.h presence... >> no checking for io.h... no checking langinfo.h usability... yes >> checking langinfo.h presence... yes checking for langinfo.h... yes >> checking libintl.h usability... yes checking libintl.h presence... yes >> checking for libintl.h... yes checking ncurses.h usability... yes >> checking ncurses.h presence... yes checking for ncurses.h... yes >> checking poll.h usability... yes checking poll.h presence... yes >> checking for poll.h... yes checking process.h usability... no checking >> process.h presence... no checking for process.h... no checking >> pthread.h usability... yes checking pthread.h presence... yes checking >> for pthread.h... yes checking shadow.h usability... yes checking >> shadow.h presence... yes checking for shadow.h... yes checking signal.h >> usability... yes checking signal.h presence... yes checking for >> signal.h... yes checking for stdint.h... (cached) yes checking >> stropts.h usability... yes checking stropts.h presence... yes checking >> for stropts.h... yes checking termios.h usability... yes checking >> termios.h presence... yes checking for termios.h... yes checking >> thread.h usability... no checking thread.h presence... no checking for >> thread.h... no checking for unistd.h... (cached) yes checking utime.h >> usability... yes checking utime.h presence... yes checking for >> utime.h... yes checking sys/audioio.h usability... no checking >> sys/audioio.h presence... no checking for sys/audioio.h... no checking >> sys/bsdtty.h usability... no checking sys/bsdtty.h presence... no >> checking for sys/bsdtty.h... no checking sys/epoll.h usability... yes >> checking sys/epoll.h presence... yes checking for sys/epoll.h... yes >> checking sys/event.h usability... no checking sys/event.h presence... >> no checking for sys/event.h... no checking sys/file.h usability... yes >> checking sys/file.h presence... yes checking for sys/file.h... yes >> checking sys/loadavg.h usability... no checking sys/loadavg.h >> presence... no checking for sys/loadavg.h... no checking sys/lock.h >> usability... no checking sys/lock.h presence... no checking for >> sys/lock.h... no checking sys/mkdev.h usability... no checking >> sys/mkdev.h presence... no checking for sys/mkdev.h... no checking >> sys/modem.h usability... no checking sys/modem.h presence... no >> checking for sys/modem.h... no checking sys/param.h usability... yes >> checking sys/param.h presence... yes checking for sys/param.h... yes >> checking sys/poll.h usability... yes checking sys/poll.h presence... >> yes checking for sys/poll.h... yes checking sys/select.h usability... >> yes checking sys/select.h presence... yes checking for sys/select.h... >> yes checking sys/socket.h usability... yes checking sys/socket.h >> presence... yes checking for sys/socket.h... yes checking sys/statvfs.h >> usability... yes checking sys/statvfs.h presence... yes checking for >> sys/statvfs.h... yes checking for sys/stat.h... (cached) yes checking >> sys/termio.h usability... no checking sys/termio.h presence... no >> checking for sys/termio.h... no checking sys/time.h usability... yes >> checking sys/time.h presence... yes checking for sys/time.h... yes >> checking sys/times.h usability... yes checking sys/times.h presence... >> yes checking for sys/times.h... yes checking for sys/types.h... >> (cached) yes checking sys/un.h usability... yes checking sys/un.h >> presence... yes checking for sys/un.h... yes checking sys/utsname.h >> usability... yes checking sys/utsname.h presence... yes checking for >> sys/utsname.h... yes checking sys/wait.h usability... yes checking >> sys/wait.h presence... yes checking for sys/wait.h... yes checking >> pty.h usability... yes checking pty.h presence... yes checking for >> pty.h... yes checking libutil.h usability... no checking libutil.h >> presence... no checking for libutil.h... no checking sys/resource.h >> usability... yes checking sys/resource.h presence... yes checking for >> sys/resource.h... yes checking netpacket/packet.h usability... yes >> checking netpacket/packet.h presence... yes checking for >> netpacket/packet.h... yes checking sysexits.h usability... yes checking >> sysexits.h presence... yes checking for sysexits.h... yes checking >> bluetooth.h usability... no checking bluetooth.h presence... no >> checking for bluetooth.h... no checking bluetooth/bluetooth.h >> usability... yes checking bluetooth/bluetooth.h presence... yes >> checking for bluetooth/bluetooth.h... yes checking linux/tipc.h >> usability... yes checking linux/tipc.h presence... yes checking for >> linux/tipc.h... yes checking for dirent.h that defines DIR... yes >> checking for library containing opendir... none required checking >> whether sys/types.h defines makedev... yes checking for term.h... yes >> checking for linux/netlink.h... yes checking for clock_t in time.h... >> yes checking for makedev... yes checking Solaris LFS bug... no checking >> for mode_t... yes checking for off_t... yes checking for pid_t... yes >> checking return type of signal handlers... void checking for size_t... >> yes checking for uid_t in sys/types.h... yes checking for ssize_t... >> yes checking size of int... 4 checking size of long... 8 checking size >> of void *... 8 checking size of short... 2 checking size of float... 4 >> checking size of double... 8 checking size of fpos_t... 16 checking >> size of size_t... 8 checking size of pid_t... 4 checking for long long >> support... yes checking size of long long... 8 checking for long double >> support... yes checking size of long double... 16 checking for _Bool >> support... yes checking size of _Bool... 1 checking for uintptr_t... >> yes checking size of uintptr_t... 8 checking size of off_t... 8 >> checking whether to enable large file support... no checking size of >> time_t... 8 checking for pthread_t... yes checking size of pthread_t... >> 8 checking for --enable-toolbox-glue... no checking for >> --enable-framework... no checking for dyld... no checking SO... .so >> checking LDSHARED... $(CC) -shared checking CCSHARED... -fPIC checking >> LINKFORSHARED... -Xlinker -export-dynamic checking CFLAGSFORSHARED... >> checking SHLIBS... $(LIBS) >> checking for dlopen in -ldl... yes checking for shl_load in -ldld... no >> checking for library containing sem_init... -lpthread checking for >> textdomain in -lintl... no checking for t_open in -lnsl... no checking >> for socket in -lsocket... no checking for --with-libs... no checking >> for --with-system-ffi... >> checking for --with-signal-module... yes checking for >> --with-dec-threads... no checking for --with-threads... yes checking if >> PTHREAD_SCOPE_SYSTEM is supported... yes checking for >> pthread_sigmask... yes checking if --enable-ipv6 is specified... no >> checking for OSX 10.5 SDK or later... no checking for >> --with-doc-strings... yes checking for --with-tsc... no checking for >> --with-pymalloc... yes checking for --with-wctype-functions... no >> checking for dlopen... yes checking DYNLOADFILE... dynload_shlib.o >> checking MACHDEP_OBJS... MACHDEP_OBJS checking for alarm... yes >> checking for setitimer... yes checking for getitimer... yes checking >> for bind_textdomain_codeset... yes checking for chown... yes checking >> for clock... yes checking for confstr... yes checking for ctermid... >> yes checking for execv... yes checking for fchmod... yes checking for >> fchown... yes checking for fork... yes checking for fpathconf... yes >> checking for ftime... yes checking for ftruncate... yes checking for >> gai_strerror... yes checking for getgroups... yes checking for >> getlogin... yes checking for getloadavg... yes checking for >> getpeername... yes checking for getpgid... yes checking for getpid... >> yes checking for getpriority... yes checking for getpwent... yes >> checking for getspnam... yes checking for getspent... yes checking for >> getsid... yes checking for getwd... yes checking for kill... yes >> checking for killpg... yes checking for lchmod... no checking for >> lchown... yes checking for lstat... yes checking for mkfifo... yes >> checking for mknod... yes checking for mktime... yes checking for >> mremap... yes checking for nice... yes checking for pathconf... yes >> checking for pause... yes checking for plock... no checking for poll... >> yes checking for pthread_init... no checking for putenv... yes checking >> for readlink... yes checking for realpath... yes checking for select... >> yes checking for setegid... yes checking for seteuid... yes checking >> for setgid... yes checking for setlocale... yes checking for >> setregid... yes checking for setreuid... yes checking for setsid... yes >> checking for setpgid... yes checking for setpgrp... yes checking for >> setuid... yes checking for setvbuf... yes checking for snprintf... yes >> checking for sigaction... yes checking for siginterrupt... yes checking >> for sigrelse... yes checking for strftime... yes checking for >> sysconf... yes checking for tcgetpgrp... yes checking for tcsetpgrp... >> yes checking for tempnam... yes checking for timegm... yes checking for >> times... yes checking for tmpfile... yes checking for tmpnam... yes >> checking for tmpnam_r... yes checking for truncate... yes checking for >> uname... yes checking for unsetenv... yes checking for utimes... yes >> checking for waitpid... yes checking for wait3... yes checking for >> wait4... yes checking for wcscoll... yes checking for _getpty... no >> checking for chroot... yes checking for link... yes checking for >> symlink... yes checking for fchdir... yes checking for fsync... yes >> checking for fdatasync... yes checking for epoll... yes checking for >> kqueue... no checking for ctermid_r... no checking for flock... yes >> checking for getpagesize... yes checking for true... true checking for >> inet_aton in -lc... yes checking for chflags... no checking for >> lchflags... no checking for inflateCopy in -lz... yes checking for >> hstrerror... yes checking for inet_aton... yes checking for >> inet_pton... yes checking for setgroups... yes checking for openpty... >> no checking for openpty in -lutil... yes checking for forkpty... yes >> checking for memmove... yes checking for fseek64... no checking for >> fseeko... yes checking for fstatvfs... yes checking for ftell64... no >> checking for ftello... yes checking for statvfs... yes checking for >> dup2... yes checking for getcwd... yes checking for strdup... yes >> checking for getpgrp... yes checking for setpgrp... (cached) yes >> checking for gettimeofday... yes checking for major... yes checking for >> getaddrinfo... yes checking getaddrinfo bug... good checking for >> getnameinfo... yes checking whether time.h and sys/time.h may both be >> included... yes checking whether struct tm is in sys/time.h or >> time.h... time.h checking for struct tm.tm_zone... yes checking for >> struct stat.st_rdev... yes checking for struct stat.st_blksize... yes >> checking for struct stat.st_flags... no checking for struct >> stat.st_gen... no checking for struct stat.st_birthtime... no checking >> for struct stat.st_blocks... yes checking for time.h that defines >> altzone... no checking whether sys/select.h and sys/time.h may both be >> included... yes checking for addrinfo... yes checking for >> sockaddr_storage... yes checking whether char is unsigned... no >> checking for an ANSI C-conforming const... yes checking for working >> volatile... yes checking for working signed char... yes checking for >> prototypes... yes checking for variable length prototypes and >> stdarg.h... yes checking for socketpair... yes checking if sockaddr has >> sa_len member... no checking whether va_list is an array... yes >> checking for gethostbyname_r... yes checking gethostbyname_r with 6 >> args... yes checking for __fpu_control... yes checking for >> --with-fpectl... no checking for --with-libm=STRING... default >> LIBM="-lm" >> checking for --with-libc=STRING... default LIBC="" >> checking for x87-style double rounding... no checking whether tanh >> preserves the sign of zero... yes checking for acosh... yes checking >> for asinh... yes checking for atanh... yes checking for copysign... yes >> checking for expm1... yes checking for finite... yes checking for >> hypot... yes checking for log1p... yes checking whether isinf is >> declared... yes checking whether isnan is declared... yes checking >> whether isfinite is declared... yes checking wchar.h usability... yes >> checking wchar.h presence... yes checking for wchar.h... yes checking >> size of wchar_t... 4 checking for UCS-4 tcl... no checking whether >> wchar_t is signed... yes checking what type to use for unicode... >> unsigned short checking whether byte ordering is bigendian... no >> checking whether right shift extends the sign bit... yes checking for >> getc_unlocked() and friends... yes checking how to link readline >> libs... -lreadline -lncursesw checking for rl_callback_handler_install >> in -lreadline... yes checking for rl_pre_input_hook in -lreadline... >> yes checking for rl_completion_display_matches_hook in -lreadline... >> yes checking for rl_completion_matches in -lreadline... yes checking >> for broken nice()... no checking for broken poll()... no checking for >> struct tm.tm_zone... (cached) yes checking for working tzset()... yes >> checking for tv_nsec in struct stat... yes checking for tv_nsec2 in >> struct stat... no checking whether mvwdelch is an expression... yes >> checking whether WINDOW has _flags... yes checking for >> is_term_resized... yes checking for resize_term... yes checking for >> resizeterm... yes checking for /dev/ptmx... yes checking for >> /dev/ptc... no checking for %zd printf() format support... yes checking >> for socklen_t... yes checking for build directories... done configure: >> creating ./config.status config.status: creating Makefile.pre >> config.status: creating Modules/Setup.config config.status: creating >> pyconfig.h creating Modules/Setup creating Modules/Setup.local creating >> Makefile [root at 117mc214 Python-2.6.6]# make .. >> . >> /Modules/_ctypes/malloc_closure.o >> build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/ libffi/src/prep_cif.o >> build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/ libffi/src/x86/ffi64.o >> build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/ libffi/src/x86/unix64.o >> build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/ libffi/src/x86/ffi.o >> build/temp.linux-x86_64-2.6/home/b38514/Python-2.6.6/Modules/_ctypes/ libffi/src/x86/sysv.o >> -L/usr/local/lib -o build/lib.linux-x86_64-2.6/_ctypes.so >> >> Failed to find the necessary bits to build these modules: >> bsddb185 dl imageop sunaudiodev To find the >> necessary bits, look in setup.py in detect_modules() for the module's >> name. >> >> running build_scripts creating build/scripts-2.6 copying and adjusting >> /home/b38514/Python-2.6.6/Tools/scripts/pydoc -> >> build/scripts-2.6 copying and adjusting >> /home/b38514/Python-2.6.6/Tools/scripts/idle -> >> build/scripts-2.6 copying and adjusting >> /home/b38514/Python-2.6.6/Tools/scripts/2to3 -> >> build/scripts-2.6 copying and adjusting >> /home/b38514/Python-2.6.6/Lib/smtpd.py -> >> build/scripts-2.6 changing mode of build/scripts-2.6/pydoc from 644 to >> 755 changing mode of build/scripts-2.6/idle from 644 to 755 changing >> mode of build/scripts-2.6/2to3 from 644 to 755 changing mode of >> build/scripts-2.6/smtpd.py from 644 to 755 >> >> [root at 117mc214 Python-2.6.6]# >> ============== capture end ==================== >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Do you really need to compile python2.6? RHEL has packages for python, > and it's better to use pre-compiled packages rather than compile them > yourself. I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP should stick with that unless there is a pressing reason. From d at davea.name Mon Aug 20 13:27:06 2012 From: d at davea.name (Dave Angel) Date: Mon, 20 Aug 2012 13:27:06 -0400 Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> Message-ID: <5032736A.4010205@davea.name> On 08/20/2012 11:04 AM, Guillaume Comte wrote: > > Because I work on a network emulator and I want to check biterros patterns so I need to access the data of the packets. An dsince my test program is written in Python, it's easier to do it in Python. You should look up scapy. http://www.secdev.org/projects/scapy/ -- DaveA From lists at cheimes.de Mon Aug 20 13:34:31 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 20 Aug 2012 19:34:31 +0200 Subject: New image and color management library for Python 2+3 In-Reply-To: <503123FA.4040301@freenet.de> References: <503123FA.4040301@freenet.de> Message-ID: Am 19.08.2012 19:35, schrieb Jan Riechers: > I'm sorry for getting out of your initial question/request, but did you > try out ImageMagick before making use of FreeImage - do you even perhaps > can deliver a comparison between your project and ImageMagick (if > regular Python is used)? > > I ask cause: > Im in the process of creating a web-app which also requires image > processing and just switching from PIL (because it is unfortunately not > that quick as it should be) to ImageMagick and the speeds are much > better compared to it, but I didn't take measurements of that. Hello Jan, we decided against ImageMagick and pgmagick for several reasons. For one we were already using FreeImage in other projects (Delphi projects and through ctypes binding with FreeImagePy). Also FreeImage is much easier to install and deploy than ImageMagick, Boost and all its dependencies. We are deploying our software on several systems (Windows, Linux) and some of the Linux servers have old enterprise distributions (RHEL 4 just went out of commission). In order to support all platforms and to get reliable libraries we have to install every dependency in our own environment. The Python bindings for ImageMagick weren't that good and today they are still buggy. For example I'm not able to set the resize filter to a high quality setting like Catmull-Rom-Spline with the most recent version of pgmagick. filterType() doesn't do anything. The output image still has the same MD5 hash. ImageMagick and PIL were missing important features, too. For example both libraries don't support color management with lcms2 nor cached color transformations nor introspection of ICC profiles. They use lcms1. > Can you perhaps test your solution with ImageMagick (as it is used > widely) it would be interesting so. :) I've added some more benchmark results to the README.txt (PIL with non-standard libjpeg-turbo and pgmagick). The results are available at https://bitbucket.org/tiran/smc.freeimage Spoiler: pgmagick isn't faster and its resize filter settings don't work. Christian From awilliam at whitemice.org Mon Aug 20 13:37:53 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 20 Aug 2012 13:37:53 -0400 Subject: pycups In-Reply-To: References: Message-ID: <1345484273.5924.1.camel@linux-nysu.site> On Thu, 2012-08-09 at 04:30 -0700, loial wrote: > I am looking to monitor print jobs on linux via python. > pycups looks a possibility, but I cannot find any useful tutorial, examples of how to use it. > Can anyone help? Modern CUPs can provide event notifications via RSS; perhaps that would work? I to would really like to find an IPP client implementation, but pycups seems to be the closest thing, doesn't do much, and is terribly documented. -------------- 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 joel.goldstick at gmail.com Mon Aug 20 13:57:59 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 20 Aug 2012 13:57:59 -0400 Subject: How to convert base 10 to base 2? In-Reply-To: References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> <50324F3A.7040001@sequans.com> Message-ID: On Mon, Aug 20, 2012 at 1:29 PM, Dennis Lee Bieber wrote: > On Mon, 20 Aug 2012 16:52:42 +0200, Jean-Michel Pichavant > declaimed the following in > gmane.comp.python.general: > >> note that the builtin bin function is not available with python ver < 2.6 >> >> def Denary2Binary(n): >> '''convert denary integer n to binary string bStr''' >> bStr = '' >> if n < 0: raise ValueError, "must be a positive integer" >> if n == 0: return '0' >> while n > 0: >> bStr = str(n % 2) + bStr >> n = n >> 1 >> return bStr >> >> JM >> >> (not my function but I can't remember who I stole from) > > I think I typically have done this by going through a hex > representation. > > H2B_Lookup = { "0" : "0000", "1" : "0001", > "2" : "0010", "3" : "0011", > "4" : "0100", "5" : "0101", > "6" : "0110", "7" : "0111", > "8" : "1000", "9" : "1001", > "A" : "1010", "B" : "1011", > "C" : "1100", "D" : "1101", > "D" : "1110", "F" : "1111" } > > def I2B(i): > sgn = " " > if i < 0: > sgn = "-" > i = -i > h = ("%X" % i) > return sgn + "".join([H2B_Lookup[c] for c in h]) > >>>> from i2b import I2B >>>> I2B(10) > ' 1010' >>>> I2B(1238) > ' 010011100110' >>>> I2B(-6) > '-0110' >>>> > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list This may be moving off topic, but since you encode -6 as -0110 I thought I'd chime in on 'two's complement' with binary number, you can represent 0 to 255 in a byte, or you can represent numbers from 127 to -128. To get the negative you complement each bit (0s to 1s, 1s to 0s), then add one to the result. So: 3 --> 00000011 ~3 -> 111111100 add 1 1 result 111111101 The nice thing about this representation is that arithmetic works just fine with a mixture of negative and positive numbers. eg 8 + (-3) ----> 00001000 111111101 gives: 00000101 which is 5! -- Joel Goldstick From ian.g.kelly at gmail.com Mon Aug 20 14:00:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Aug 2012 12:00:21 -0600 Subject: How to convert base 10 to base 2? In-Reply-To: References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> <50324F3A.7040001@sequans.com> Message-ID: On Mon, Aug 20, 2012 at 11:29 AM, Dennis Lee Bieber wrote: > I think I typically have done this by going through a hex > representation. > > H2B_Lookup = { "0" : "0000", "1" : "0001", > "2" : "0010", "3" : "0011", > "4" : "0100", "5" : "0101", > "6" : "0110", "7" : "0111", > "8" : "1000", "9" : "1001", > "A" : "1010", "B" : "1011", > "C" : "1100", "D" : "1101", > "D" : "1110", "F" : "1111" } > > def I2B(i): > sgn = " " > if i < 0: > sgn = "-" > i = -i > h = ("%X" % i) > return sgn + "".join([H2B_Lookup[c] for c in h]) > >>>> from i2b import I2B >>>> I2B(10) > ' 1010' >>>> I2B(1238) > ' 010011100110' >>>> I2B(-6) > '-0110' >>>> I would throw a .lstrip('0') in there to get rid of the ugly leading zeroes (and also add a special case for i == 0). Everybody should know the generic algorithm, though: from itertools import chain def convert(n, base): digits = [chr(x) for x in chain(range(ord('0'), ord('9')+1), range(ord('A'), ord('Z')+1))] if not 2 <= base <= len(digits): raise ValueError("invalid base") output = [] sign = "" if n < 0: n = -n sign = "-" while n > 0: n, r = divmod(n, base) output.append(digits[r]) return sign + ''.join(reversed(output)) or '0' From massimo.dipierro at gmail.com Mon Aug 20 14:01:36 2012 From: massimo.dipierro at gmail.com (Massimo Di Pierro) Date: Mon, 20 Aug 2012 11:01:36 -0700 (PDT) Subject: Class.__class__ magic trick help Message-ID: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> I discovered I can do this: class A(object): pass class B(object): __class__ = A # <<<< magic b = B() isinstance(b,A) # returns True (as if B derived from A) isinstance(b,B) # also returns True I have some reasons I may want to do this (I an object with same methods as a dict but it is not derived from dict and I want isinstance(x,dict)==True to use it in place of dict in some other code). What are the problems with the magic trick above? Why does it work? massimo From emile at fenx.com Mon Aug 20 14:02:25 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Aug 2012 11:02:25 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 10:20 AM Walter Hurry said... > On Mon, 20 Aug 2012 19:12:05 +0200, Kwpolska wrote: >> >Do you really need to compile python2.6? RHEL has packages for python, >> >and it's better s/better/sometimes easier >> > to use pre-compiled packages rather than compile them yourself. > I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP > should stick with that unless there is a pressing reason. Hence, the 2.6 install. Learn-to-trim-ly y'rs, Emile From ian.g.kelly at gmail.com Mon Aug 20 14:10:18 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Aug 2012 12:10:18 -0600 Subject: How to convert base 10 to base 2? In-Reply-To: References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> <50324F3A.7040001@sequans.com> Message-ID: On Mon, Aug 20, 2012 at 11:57 AM, Joel Goldstick wrote: > This may be moving off topic, but since you encode -6 as -0110 I > thought I'd chime in on 'two's complement' > > with binary number, you can represent 0 to 255 in a byte, or you can > represent numbers from 127 to -128. To get the negative you > complement each bit (0s to 1s, 1s to 0s), then add one to the result. > So: > 3 --> 00000011 > ~3 -> 111111100 > add 1 1 > result 111111101 > > The nice thing about this representation is that arithmetic works just > fine with a mixture of negative and positive numbers. > > eg 8 + (-3) ----> 00001000 > 111111101 > gives: 00000101 > which is 5! The main reason to use two's complement is when you need to encode the negative sign of the number as a bit in a format of fixed width, e.g. within a byte or word. In a string representation, unless you are specifically trying to represent computer memory, it is usually better to just use a minus sign, to be more consistent with how we usually represent numerals. Otherwise, note that complement representations are not specific to binary. For example, with decimal numbers we could use "ten's complement": individually subtract each digit from 9, and add 1 to the result. A leading digit between 5 and 9 would be considered negative. So, for example: -(042) --> 958 -(958) --> 042 958 + 042 == 000 Cheers, Ian From steve+comp.lang.python at pearwood.info Mon Aug 20 14:21:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Aug 2012 18:21:53 GMT Subject: Class.__class__ magic trick help References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> Message-ID: <50328040$0$6574$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Aug 2012 11:01:36 -0700, Massimo Di Pierro wrote: > I discovered I can do this: > > class A(object): pass > class B(object): > __class__ = A # <<<< magic Why do you think that's magic? > b = B() > isinstance(b,A) # returns True (as if B derived from A) b.__class__ is A, so naturally isinstance(b, A) will return True. > isinstance(b,B) # also returns True type(b) is B, so naturally isinstance(b, B) will return True. > I have some reasons I may want to do this (I an object with same methods > as a dict but it is not derived from dict and I want > isinstance(x,dict)==True to use it in place of dict in some other code). Be aware that some parts of Python will insist on real dicts, not just subclasses or fake dicts. -- Steven From walterhurry at lavabit.com Mon Aug 20 14:37:49 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 20 Aug 2012 18:37:49 +0000 (UTC) Subject: python 6 compilation failure on RHEL References: Message-ID: On Mon, 20 Aug 2012 11:02:25 -0700, Emile van Sebille wrote: > On 8/20/2012 10:20 AM Walter Hurry said... >> On Mon, 20 Aug 2012 19:12:05 +0200, Kwpolska wrote: > > > >>> >Do you really need to compile python2.6? RHEL has packages for >>> >python, >>> >and it's better > > s/better/sometimes easier > >>> > to use pre-compiled packages rather than compile them yourself. > > >> I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP >> should stick with that unless there is a pressing reason. > > Hence, the 2.6 install. First, sorry for my omission to trim. Second, the reason for recommending that OP stick to the Red Hat provided version (unless there is a pressing reason) is the question of the already-paid-for Red Hat support. And for that matter, if OP is forced to a later Python 2 version than 2.4, why not 2.7.3? From ian.g.kelly at gmail.com Mon Aug 20 14:39:38 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Aug 2012 12:39:38 -0600 Subject: Class.__class__ magic trick help In-Reply-To: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> Message-ID: On Mon, Aug 20, 2012 at 12:01 PM, Massimo Di Pierro wrote: > I discovered I can do this: > > class A(object): pass > class B(object): > __class__ = A # <<<< magic > > b = B() > isinstance(b,A) # returns True (as if B derived from A) > isinstance(b,B) # also returns True > > I have some reasons I may want to do this (I an object with same > methods as a dict but it is not derived from dict and I want > isinstance(x,dict)==True to use it in place of dict in some other > code). > > What are the problems with the magic trick above? Why does it work? Normally with __class__ assignment, you would assign to the __class__ attribute of the *instance*, not the class declaration. This actually changes the class of the object, and so isinstance(b, B) would no longer return True. I've never heard of assigning it in the class declaration, and as far as I know, this behavior isn't documented anywhere. I expect that what's happening here is that Python is not actually updating the class of the instance, but that A is merely assigned to the "__class__" attribute in the class dict, and that isinstance is somehow (perhaps accidentally) finding this. So I think this is probably a bug, and I would not rely on it to work correctly in all cases. In any event, the use case that you're looking for is usually accomplished using abstract base classes. Instead of "isinstance(x, dict)", you should use "isinstance(x, collections.MutableMapping)", and then inherit your class from or register it with the MutableMapping ABC. From wxjmfauth at gmail.com Mon Aug 20 14:42:48 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 20 Aug 2012 11:42:48 -0700 (PDT) Subject: Abuse of Big Oh notation In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: By chance and luckily, first attempt. IDLE, Windows 7.0 Pro 32, Pentium Dual Core 2.6, RAM 2 Go Py 3.2.3 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.6939567134893707, 1.672874290786993, 1.6761219212298073] Py 3.3.0b2 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [7.924470733910917, 7.8554985620787345, 7.878623849091914] Console c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' , '?')" 1000000 loops, best of 3: 1.48 usec per loop c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' , '?')" 100000 loops, best of 3: 7.62 usec per loop Note The used characters are not members of the latin-1 coding scheme (btw an *unusable* coding). They are however charaters in cp1252 and mac-roman. jmf From wxjmfauth at gmail.com Mon Aug 20 14:42:48 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 20 Aug 2012 11:42:48 -0700 (PDT) Subject: Abuse of Big Oh notation In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: By chance and luckily, first attempt. IDLE, Windows 7.0 Pro 32, Pentium Dual Core 2.6, RAM 2 Go Py 3.2.3 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.6939567134893707, 1.672874290786993, 1.6761219212298073] Py 3.3.0b2 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [7.924470733910917, 7.8554985620787345, 7.878623849091914] Console c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' , '?')" 1000000 loops, best of 3: 1.48 usec per loop c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' , '?')" 100000 loops, best of 3: 7.62 usec per loop Note The used characters are not members of the latin-1 coding scheme (btw an *unusable* coding). They are however charaters in cp1252 and mac-roman. jmf From emile at fenx.com Mon Aug 20 15:19:23 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Aug 2012 12:19:23 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 11:37 AM Walter Hurry said... > On Mon, 20 Aug 2012 11:02:25 -0700, Emile van Sebille wrote: > >> On 8/20/2012 10:20 AM Walter Hurry said... >>> I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP >>> should stick with that unless there is a pressing reason. >> >> Hence, the 2.6 install. > > First, sorry for my omission to trim. > > Second, the reason for recommending that OP stick to the Red Hat provided > version (unless there is a pressing reason) is the question of the > already-paid-for Red Hat support. Generally, when you compile from source the binaries will install to /usr/local/bin and not be in conflict with RH's install version. > And for that matter, if OP is forced to a later Python 2 version than > 2.4, why not 2.7.3? Package dependencies. If the OP intends to install a package that doesn't support other than 2.6, you install 2.6. Emile From massimo.dipierro at gmail.com Mon Aug 20 15:28:51 2012 From: massimo.dipierro at gmail.com (Massimo Di Pierro) Date: Mon, 20 Aug 2012 12:28:51 -0700 (PDT) Subject: Class.__class__ magic trick help References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> Message-ID: The fact is this works: >>> class B(object): ... __class__ = dict >>> b=B() but this does not >>> class B(object): ... def __init__(self): ... self.__class__ = dict >>> b=B() Traceback (most recent call last): File "", line 1, in File "", line 3, in __init__ TypeError: __class__ assignment: only for heap types On Aug 20, 1:39?pm, Ian Kelly wrote: > On Mon, Aug 20, 2012 at 12:01 PM, Massimo Di Pierro > > wrote: > > I discovered I can do this: > > > ? ? class A(object): pass > > ? ? class B(object): > > ? ? ? ? __class__ = A # <<<< magic > > > ? ? b = B() > > ? ? isinstance(b,A) # returns True (as if B derived from A) > > ? ? isinstance(b,B) # also returns True > > > I have some reasons I may want to do this (I an object with same > > methods as a dict but it is not derived from dict and I want > > isinstance(x,dict)==True to use it in place of dict in some other > > code). > > > What are the problems with the magic trick above? Why does it work? > > Normally with __class__ assignment, you would assign to the __class__ > attribute of the *instance*, not the class declaration. ?This actually > changes the class of the object, and so isinstance(b, B) would no > longer return True. > > I've never heard of assigning it in the class declaration, and as far > as I know, this behavior isn't documented anywhere. ?I expect that > what's happening here is that Python is not actually updating the > class of the instance, but that A is merely assigned to the > "__class__" attribute in the class dict, and that isinstance is > somehow (perhaps accidentally) finding this. ?So I think this is > probably a bug, and I would not rely on it to work correctly in all > cases. > > In any event, the use case that you're looking for is usually > accomplished using abstract base classes. ?Instead of "isinstance(x, > dict)", you should use "isinstance(x, collections.MutableMapping)", > and then inherit your class from or register it with the > MutableMapping ABC. From no.email at nospam.invalid Mon Aug 20 15:29:12 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 20 Aug 2012 12:29:12 -0700 Subject: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> Message-ID: <7xfw7hl5vb.fsf@ruckus.brouhaha.com> Ian Kelly writes: > The difference between the two is that the former is bounded by a > constant that is fundamental to the algorithm at hand,... S is > clearly bounded by the constraints of actual shoes, so we can safely > treat S as a constant and call it O(N). Thanks, that is a good explain of what I was trying to get at. One quibble is in the parsing example, the constant is inherent in the distribution of input data one expects to normally encounter, rather than in the algorithm itself. It's sort of like saying dictionary access (based on hashing) is O(1), based on the variety of input data that is normally used. There is such a thing as pathological (e.g. malicious) input data that causes a lot of hash collisions, making O(n) access in the size of the dictionary. I suppose abnormal input should also be taken into account in examples involving parsing if one parses potentially hostile data. From piet at vanoostrum.org Mon Aug 20 16:06:33 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 20 Aug 2012 16:06:33 -0400 Subject: Why doesn't Python remember the initial directory? References: Message-ID: kj writes: > This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. That's a weakness, IMO. On Unix based systems there is no reliable way to find out this information. So how could Python reliably supply this? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From chbeh88 at googlemail.com Mon Aug 20 16:43:54 2012 From: chbeh88 at googlemail.com (Cheng) Date: Mon, 20 Aug 2012 13:43:54 -0700 (PDT) Subject: A difficulty with lists In-Reply-To: References: Message-ID: <66aafdc3-7ea5-4401-859b-89cd5bf268a8@googlegroups.com> On Monday, August 6, 2012 12:50:13 PM UTC-7, Mok-Kong Shen wrote: > I ran the following code: > > > > def xx(nlist): > > print("begin: ",nlist) > > nlist+=[999] > > print("middle:",nlist) > > nlist=nlist[:-1] > > print("final: ",nlist) > > > > u=[1,2,3,4] > > print(u) > > xx(u) > > print(u) > > > > and obtained the following result: > > > > [1, 2, 3, 4] > > begin: [1, 2, 3, 4] > > middle: [1, 2, 3, 4, 999] > > final: [1, 2, 3, 4] > > [1, 2, 3, 4, 999] > > > > As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. > > Could someone kindly help? > > > > M. K. Shen When you pass a list (mutable object) to a function, the pointer to the list is passed to the function and the corresponding argument points to the same memory location as the pointer passed in. So in this case, nlist points to the same memory location which u points to when xx is called, i.e. nlist and u points to same memory location which contains [1,2,3,4]. nlist += [999] is equivalent to nlist.extend([999]). This statement adds the argument list to the original list, i.e. the memory location pointed by nlist and u now contains [1,2,3,4,999]. So, print(u) after calling xx will print [1,2,3,4,999]. nlist += [999] is not the same as nlist = nlist + [999]. In the later case, nlist + [999] will create a new memory location containing the two lists combined and rebind nlist to the new location, i.e. nlist points to a new memory location that has [1,2,3,4,999]. So if nlist = nlist +[999] is used, the original memory location containing [1,2,3,4] is untouched, and print(u) after calling xx will print [1,2,3,4] From walterhurry at lavabit.com Mon Aug 20 16:55:04 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 20 Aug 2012 20:55:04 +0000 (UTC) Subject: python 6 compilation failure on RHEL References: Message-ID: On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: > Package dependencies. If the OP intends to install a package that > doesn't support other than 2.6, you install 2.6. It would be a pretty poor third party package which specified Python 2.6 exactly, rather than (say) "Python 2.6 or later, but not Python 3" From piet at vanoostrum.org Mon Aug 20 17:20:44 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 20 Aug 2012 17:20:44 -0400 Subject: How do I display unicode value stored in a string variable using ord() References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Blind Anagram" writes: > This is an average slowdown by a factor of close to 2.3 on 3.3 when > compared with 3.2. > > I am not posting this to perpetuate this thread but simply to ask > whether, as you suggest, I should report this as a possible problem with > the beta? Being a beta release, is it certain that this release has been compiled with the same optimization level as 3.2? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From emile at fenx.com Mon Aug 20 17:50:55 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Aug 2012 14:50:55 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 1:55 PM Walter Hurry said... > On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: > >> Package dependencies. If the OP intends to install a package that >> doesn't support other than 2.6, you install 2.6. > > It would be a pretty poor third party package which specified Python 2.6 > exactly, rather than (say) "Python 2.6 or later, but not Python 3" It doesn't need to be a poorly supported third party package to require a non-current version of python -- just something as simple as an up and running application. Suppose you're migrating an application to new hardware. To make it interesting, assume it's a 10 year old zope application. It's likely that to minimize effort you'll gather (assuming you didn't save your sources - you do install from source, right?) and install the versions prescribed. Of course, if you're comfortable upgrading to the latest release then then, by all means, do so. For me, python is used for for dozens of rather significant one-offs that I prefer not to upgrade. Why mess with a working app. Emile From dihedral88888 at googlemail.com Mon Aug 20 18:16:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 20 Aug 2012 15:16:56 -0700 (PDT) Subject: Abuse of Big Oh notation In-Reply-To: <7xfw7hl5vb.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> <7xfw7hl5vb.fsf@ruckus.brouhaha.com> Message-ID: <464d6549-7fc5-4405-92ec-285bc2afdb7b@googlegroups.com> Paul Rubin? 2012?8?21????UTC+8??3?29?12???? > Ian Kelly writes: > > > The difference between the two is that the former is bounded by a > > > constant that is fundamental to the algorithm at hand,... S is > > > clearly bounded by the constraints of actual shoes, so we can safely > > > treat S as a constant and call it O(N). > > > > Thanks, that is a good explain of what I was trying to get at. One > > quibble is in the parsing example, the constant is inherent in the > > distribution of input data one expects to normally encounter, rather > > than in the algorithm itself. It's sort of like saying dictionary > > access (based on hashing) is O(1), based on the variety of input data > > that is normally used. There is such a thing as pathological > > (e.g. malicious) input data that causes a lot of hash collisions, making > > O(n) access in the size of the dictionary. > > > > I suppose abnormal input should also be taken into account in examples > > involving parsing if one parses potentially hostile data. OK, the hash key function has to be seeded with some randomization in the begining of a hash table from some data independent factors. Also for those items hashed to the same key with a length >=16 I think an insertion sort is good in soring a sorted list of items hashed to the same key of a length 16 to 256 or even larger which indicates the hash function should be changed from time to time in the occasions of resizing the hash table when the table is under a lot operations of item inserstions and deletions which are much greater than the number of item searches in the same period. From dihedral88888 at googlemail.com Mon Aug 20 18:20:44 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 20 Aug 2012 15:20:44 -0700 (PDT) Subject: Abuse of Big Oh notation In-Reply-To: <7xfw7hl5vb.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> <7xfw7hl5vb.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin? 2012?8?21????UTC+8??3?29?12???? > Ian Kelly writes: > > > The difference between the two is that the former is bounded by a > > > constant that is fundamental to the algorithm at hand,... S is > > > clearly bounded by the constraints of actual shoes, so we can safely > > > treat S as a constant and call it O(N). > > > > Thanks, that is a good explain of what I was trying to get at. One > > quibble is in the parsing example, the constant is inherent in the > > distribution of input data one expects to normally encounter, rather > > than in the algorithm itself. It's sort of like saying dictionary > > access (based on hashing) is O(1), based on the variety of input data > > that is normally used. There is such a thing as pathological > > (e.g. malicious) input data that causes a lot of hash collisions, making > > O(n) access in the size of the dictionary. > > > > I suppose abnormal input should also be taken into account in examples > > involving parsing if one parses potentially hostile data. OK, the hash key function has to be seeded with some randomization in the creation of a hash table from some data independent factors. Also for those items hashed to the same key with a length >=16 I think an insertion sort and a heap sort are good in storing a sorted list of items hashed to the same key of a length 16 to 256 or even larger which indicates the hash function should be changed from time to time in the occasions of resizing the hash table when the table is under a lot operations of item insertions and deletions which are operated much frequently than the number of item searches in the same period. From cs at zip.com.au Mon Aug 20 18:25:44 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 21 Aug 2012 08:25:44 +1000 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: <20120820222544.GA12949@cskk.homeip.net> On 20Aug2012 12:19, Emile van Sebille wrote: | On 8/20/2012 11:37 AM Walter Hurry said... | > On Mon, 20 Aug 2012 11:02:25 -0700, Emile van Sebille wrote: | >> On 8/20/2012 10:20 AM Walter Hurry said... | >>> I concur, but FYI the version of Python with RHEL5 is 2.4. Still, OP | >>> should stick with that unless there is a pressing reason. | >> | >> Hence, the 2.6 install. | > | > First, sorry for my omission to trim. | > | > Second, the reason for recommending that OP stick to the Red Hat provided | > version (unless there is a pressing reason) is the question of the | > already-paid-for Red Hat support. | | Generally, when you compile from source the binaries will install to | /usr/local/bin and not be in conflict with RH's install version. I was going to chime in with this anyway had the thread said nothing; I strongly prefer to specify --prefix explicitly with configure. My personal habit to to build with (adjust to match): --prefix=/usr/local/python-2.6.4 and put some symlinks in /usr/local/bin afterwards (python2.6, etc). That way one doesn't tread on the system Python (after all the OS vendor distro is also a collection of packages with coordinated versions) and one can easily put in another python beside it. | > And for that matter, if OP is forced to a later Python 2 version than | > 2.4, why not 2.7.3? | | Package dependencies. If the OP intends to install a package that | doesn't support other than 2.6, you install 2.6. Indeed. And this is a strong reason to keep out of the vendor's /usr filesystem space, also. Cheers, -- Cameron Simpson From drsalists at gmail.com Mon Aug 20 18:43:27 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 20 Aug 2012 22:43:27 +0000 Subject: python 6 compilation failure on RHEL In-Reply-To: <20120820222544.GA12949@cskk.homeip.net> References: <20120820222544.GA12949@cskk.homeip.net> Message-ID: On Mon, Aug 20, 2012 at 10:25 PM, Cameron Simpson wrote: > I was going to chime in with this anyway had the thread said nothing; I > strongly prefer to specify --prefix explicitly with configure. > > My personal habit to to build with (adjust to match): > > --prefix=/usr/local/python-2.6.4 > > and put some symlinks in /usr/local/bin afterwards (python2.6, etc). > > That way one doesn't tread on the system Python (after all the OS vendor > distro is also a collection of packages with coordinated versions) > and one can easily put in another python beside it. +1. I like to build a bunch of representative python versions, and test code on some subset of them - often all of them. I usually do 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 and 3.3, but sometimes I get more specific than that. I'll also do a couple of jython's and pypy's normally. It's remarkable how revealing such a simple thing can be for portability. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Mon Aug 20 18:49:24 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 20 Aug 2012 22:49:24 +0000 Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416602BAE@SCACMX008.exchad.jpmchase.net> > > I also tend to blame M$ (Outlook and variants) for this tendency to > > quote everything and top-post -- Outlook makes it almost impossible > > to do a trim&interleave response style. > > I that Outlook & Co are guilty. That and the fact that few people even > think about this. Nonsense, I post only from Outlook. You can do it and it is not hard. It is just requires a little effort. Top posting makes more sense in a corporate setting for a couple reasons. Seeing the exact email trail rather than what someone considers "relevant" context can be very useful. Not to mention that frequently corporate email is more like slow instant messaging; I need less context (e.g. conversation history) and get all the information I need from what the sender is writing. I find inline (and to a lesser extent bottom) posting to be a mixed bag. Some people do it well and it is easy to read, but there are others who do not make it as easy (for me) to read. Lots of posts are not trimmed enough, or trimmed too much. I am not advocating top-posting. I just think that different styles are good for different cases/environments. Blame the person, not the application for having poor habits and/or being inconsiderate of the community. :) Ramit P.S. Ironically, I do blame Outlook for making it hard (impossible?) to find/see the 80 char boundary. 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 ramit.prasad at jpmorgan.com Mon Aug 20 19:16:36 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 20 Aug 2012 23:16:36 +0000 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416602C4A@SCACMX008.exchad.jpmchase.net> >Look you are the only person complaining about top-posting. >GMail uses top-posting by default. >I can't help it if you feel irritated by it. He is most certainly not the only person to feel irritated nor even the only person who has requested you not to top post. He does happen to be the most persistent though. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Mon Aug 20 19:19:13 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 20 Aug 2012 23:19:13 +0000 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416602C79@SCACMX008.exchad.jpmchase.net> > I'll be using Google Groups (hopefully it won't top-post by default) to post stuff. Thanks for not top-posting. Even if it is the default, it is not difficult to change. :) Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From wuwei23 at gmail.com Mon Aug 20 20:20:41 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 20 Aug 2012 17:20:41 -0700 (PDT) Subject: Does Polymorphism mean python can create object? In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: > Does Polymorphism mean python can create object? No. This isn't D&D. Polymorphism has a distinct meaning in computer science, one which you would've found in less time searching Wikipedia than asking this question here. From wuwei23 at gmail.com Mon Aug 20 20:20:41 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 20 Aug 2012 17:20:41 -0700 (PDT) Subject: Does Polymorphism mean python can create object? In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: > Does Polymorphism mean python can create object? No. This isn't D&D. Polymorphism has a distinct meaning in computer science, one which you would've found in less time searching Wikipedia than asking this question here. From nad at acm.org Mon Aug 20 21:19:29 2012 From: nad at acm.org (Ned Deily) Date: Mon, 20 Aug 2012 18:19:29 -0700 Subject: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: In article , wxjmfauth at gmail.com wrote: > Note > The used characters are not members of the latin-1 coding > scheme (btw an *unusable* coding). > They are however charaters in cp1252 and mac-roman. mac-roman is an obsolete encoding that was used in MacOS 9 and MacOS Classic systems of previous decades. Except in a very small and shrinking number of legacy applications, it isn't used in modern systems and hasn't been widely used for a long time. MacOS X systems generally use standard Unicode encodings, usually UTF-8, for external representations. Forget about mac-roman; it is not relevant. -- Ned Deily, nad at acm.org From nhodgson at iinet.net.au Mon Aug 20 21:39:19 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 21 Aug 2012 11:39:19 +1000 Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: Nobody: > Maybe. On Unix, it's possible that the current directory no longer > has a pathname. Its also possible that you do not have permission to successfully call getcwd. One example of this I have experienced is the OS X sandbox where you can run Python starting in a directory where you have only limited permissions. getcwd works by calling readdir and lstat and looping up from the current directory to the root to build the whole path so will break without read permissions on directories: http://www.opensource.apple.com/source/Libc/Libc-763.13/gen/FreeBSD/getcwd.c Neil From steve+comp.lang.python at pearwood.info Mon Aug 20 23:43:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Aug 2012 03:43:31 GMT Subject: Top-posting &c. References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <503303e3$0$6574$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Aug 2012 22:49:24 +0000, Prasad, Ramit wrote: >> > I also tend to blame M$ (Outlook and variants) for this tendency to >> > quote everything and top-post -- Outlook makes it almost impossible >> > to do a trim&interleave response style. >> >> I that Outlook & Co are guilty. That and the fact that few people even >> think about this. > > Nonsense, I post only from Outlook. You can do it and it is not hard. It > is just requires a little effort. > > Top posting makes more sense in a corporate setting for a couple > reasons. Seeing the exact email trail rather than what someone considers > "relevant" context can be very useful. That's what your email archive, and the threading information in the email headers, is for. When people used to correspond by paper mail, they did not photocopy the entire past correspondence and staple it to the back of their letter. And then the person responding didn't photocopy the photocopies and post them back with his response. If somebody did, that would be stupid -- did he think the sender posted the originals and didn't keep a copy? If there was a business requirement to make copies of copies of copies, people would have done it. But there wasn't, and it was stupid and costly and so they didn't. With email, it's less costly, but it's equally stupid. Email programs reduce the cost of making and posting those photocopies to essentially zero, at least zero for the person pressing Send. It might be almost free for the sender, but it's still stupid. Nobody looks at those deep email trails. When you want to find out the order of correspondence, you sort your mail folder by Thread or by Date and look at it there, not by trying to interpret the copies of copies of copies of past discussions. Nobody uses them. They just bulk up email and get in the way of communication and make searching for relevant emails harder. I've had to dig through email archives for legal purposes, looking for evidence in legal cases, and having to read past copies of copies of copies of copies (down to ten or twelve levels deep!!!) makes the process much, much, much harder than it should be. Top posting in and of itself is not always bad. But the practice of leaving copies of copies of copies in the body of the email is beyond stupid. If they were *attachments* that could be ignored when printed, that would be *almost* sane, but putting them in the body of the email is insane. > Not to mention that frequently > corporate email is more like slow instant messaging; I need less context > (e.g. conversation history) and get all the information I need from > what the sender is writing. In my experience, if you ask a question in corporate environments by email, you're lucky to get an answer within a day. Slow indeed. -- Steven From no.email at nospam.invalid Tue Aug 21 00:05:45 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 20 Aug 2012 21:05:45 -0700 Subject: How to convert base 10 to base 2? References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> <28b3f583-fad1-46da-a6b5-933f966eb401@googlegroups.com> <50324F3A.7040001@sequans.com> Message-ID: <7xpq6kga92.fsf@ruckus.brouhaha.com> Ian Kelly writes: > Everybody should know the generic algorithm, though: > from itertools import chain ... For n>0, assuming you just want the converted digits and not a string. String conversion and minus sign for n<0 left as exercise. Note this returns a generator that you can convert to a list with list(...). def convert(n, base): a,b = divmod(n,base) if a > 0: for e in convert(a,base): yield e yield b From massimo.dipierro at gmail.com Tue Aug 21 00:17:15 2012 From: massimo.dipierro at gmail.com (Massimo Di Pierro) Date: Mon, 20 Aug 2012 21:17:15 -0700 (PDT) Subject: Class.__class__ magic trick help References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> Message-ID: <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Consider this code: class SlowStorage(dict): def __getattr__(self,key): return self[key] def __setattr__(self,key): self[key]=value class FastStorage(dict): def __init__(self, __d__=None, **kwargs): self.update(__d__,**kwargs) def __getitem__(self,key): return self.__dict__.get(key,None) def __setitem__(self,key,value): self.__dict__[key] = value def __delitem__(self,key): delattr(self,key) def __copy__(self): return Storage(self) def __nonzero__(self): return len(self.__dict__)>0 def pop(self,key,default=None): if key in self: default = getattr(self,key) delattr(self,key) return default def clear(self): self.__dict__.clear() def __repr__(self): return repr(self.__dict__) def keys(self): return self.__dict__.keys() def values(self): return self.__dict__.values() def items(self): return self.__dict__.items() def iterkeys(self): return self.__dict__.iterkeys() def itervalues(self): return self.__dict__.itervalues() def iteritems(self): return self.__dict__.iteritems() def viewkeys(self): return self.__dict__.viewkeys() def viewvalues(self): return self.__dict__.viewvalues() def viewitems(self): return self.__dict__.viewitems() def fromkeys(self,S,v=None): return self.__dict__.fromkeys(S,v) def setdefault(self, key, default=None): try: return getattr(self,key) except AttributeError: setattr(self,key,default) return default def clear(self): self.__dict__.clear() def len(self): return len(self.__dict__) def __iter__(self): return self.__dict__.__iter__() def has_key(self,key): return key in self.__dict__ def __contains__(self,key): return key in self.__dict__ def update(self,__d__=None,**kwargs): if __d__: for key in __d__: kwargs[key] = __d__[key] self.__dict__.update(**kwargs) def get(self,key,default=None): return getattr(self,key) if key in self else default >>> s=SlowStorage() >>> a.x=1 ### (1) >>> a.x ### (2) 1 # ok >>> isinstance(a,dict) True # ok >>> print dict(a) {'x':1} # ok (3) >>> s=FastStorage() >>> a.x=1 ### (4) >>> a.x ### (5) 1 # ok >>> isinstance(a,dict) True # ok >>> print dict(a) {} # not ok (6) Lines (4) and (5) are about 10x faster then lines (1) and (2). I like FastStorage better but while (3) behaves ok, (6) does not behave as I want. I intuitively understand why FastStorage is cannot cast into dict properly. What I do not know is how to make it do the casting properly without losing the 10x speedup of FastStorage over SlowStorage. Any idea? From torriem at gmail.com Tue Aug 21 00:18:38 2012 From: torriem at gmail.com (Michael Torrie) Date: Mon, 20 Aug 2012 22:18:38 -0600 Subject: New internal string format in 3.3 In-Reply-To: References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: <50330C1E.3040801@gmail.com> On 08/20/2012 07:17 AM, Roy Smith wrote: > In article , > Michael Torrie wrote: > >> Python generally tries to follow unicode >> encoding rules to the letter. Thus if a piece of text cannot be >> represented in the character set of the terminal, then Python will >> properly err out. Other languages you have tried, likely fudge it >> somehow. > > And if you want the "fudge it somehow" behavior (which is often very > useful!), there's always http://pypi.python.org/pypi/Unidecode/ Sweet tip, thanks! I often want to process text that has smart quotes, emdashes, etc, and convert them to plain old ascii quotes, dashes, ticks, etc. This will do that for me without resorting to a bunch of regexes. Bravo. From no.email at nospam.invalid Tue Aug 21 00:20:26 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 20 Aug 2012 21:20:26 -0700 Subject: Why doesn't Python remember the initial directory? References: Message-ID: <7xehn0q3jp.fsf@ruckus.brouhaha.com> alex23 writes: > Oh my god, how DARE people with EXPERIENCE in a language challenge the > PRECONCEPTIONS of an AMATEUR!!! HOW DARE THEY?!?! +1 QOTW :) From nagle at animats.com Tue Aug 21 00:34:43 2012 From: nagle at animats.com (John Nagle) Date: Mon, 20 Aug 2012 21:34:43 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 2:50 PM, Emile van Sebille wrote: > On 8/20/2012 1:55 PM Walter Hurry said... >> On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: >> >>> Package dependencies. If the OP intends to install a package that >>> doesn't support other than 2.6, you install 2.6. >> >> It would be a pretty poor third party package which specified Python 2.6 >> exactly, rather than (say) "Python 2.6 or later, but not Python 3" After a thread of clueless replies, it's clear that nobody responding actually read the build log. Here's the problem: Failed to find the necessary bits to build these modules: bsddb185 dl imageop sunaudiodev What's wrong is that the Python 2.6 build script is looking for some antiquated packages that aren't in a current RHEL. Those need to be turned off. This is a known problem (see http://pythonstarter.blogspot.com/2010/08/bsddb185-sunaudiodev-python-26-ubuntu.html) but, unfortunately, the site with the patch for it (http://www.lysium.de/sw/python2.6-disable-old-modules.patch) is no longer in existence. But someone archived it on Google Code, at http://code.google.com/p/google-earth-enterprise-compliance/source/browse/trunk/googleclient/geo/earth_enterprise/src/third_party/python/python2.6-disable-old-modules.patch so if you apply that patch to the setup.py file for Python 2.6, that ought to help. You might be better off building Python 2.7, but you asked about 2.6. John Nagle From __peter__ at web.de Tue Aug 21 01:43:00 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Aug 2012 07:43 +0200 Subject: python 6 compilation failure on RHEL References: Message-ID: John Nagle wrote: > On 8/20/2012 2:50 PM, Emile van Sebille wrote: >> On 8/20/2012 1:55 PM Walter Hurry said... >>> On Mon, 20 Aug 2012 12:19:23 -0700, Emile van Sebille wrote: >>> >>>> Package dependencies. If the OP intends to install a package that >>>> doesn't support other than 2.6, you install 2.6. >>> >>> It would be a pretty poor third party package which specified Python 2.6 >>> exactly, rather than (say) "Python 2.6 or later, but not Python 3" > > After a thread of clueless replies, it's clear that nobody > responding actually read the build log. Here's the problem: There are a lot of clueless statements on websites around the world. I'll just quote the one significant comment on the lysium.de page: """ There's actually no need to apply your patch to setup.py. Python complains about not being able to build those modules, but it will still build and install just fine without them. #6 Alexander Fairley on 2009-01-19 01:43 """ which is unfortunately burried under an avalanche of "satisfied customer" replies. Alexander, you're my hero ;) > > Failed to find the necessary bits to build these modules: > bsddb185 > dl > imageop > sunaudiodev > > What's wrong is that the Python 2.6 build script is looking for > some antiquated packages that aren't in a current RHEL. Those > need to be turned off. > > This is a known problem (see > http://pythonstarter.blogspot.com/2010/08/bsddb185-sunaudiodev-python-26- ubuntu.html) > but, unfortunately, the site with the patch for it > (http://www.lysium.de/sw/python2.6-disable-old-modules.patch) > is no longer in existence. > > But someone archived it on Google Code, at > > http://code.google.com/p/google-earth-enterprise- compliance/source/browse/trunk/googleclient/geo/earth_enterprise/src/third_party/python/python2.6- disable-old-modules.patch > > so if you apply that patch to the setup.py file for Python 2.6, that > ought to help. That patch prevents setup.py from adding a few names of rarely needed/available modules to the list of missing modules. That's snakeoil. OP: You can safely ignore the error message, the patch has no real-world effect. From sscc at mweb.co.za Tue Aug 21 02:07:33 2012 From: sscc at mweb.co.za (Alex Strickland) Date: Tue, 21 Aug 2012 08:07:33 +0200 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <503325A5.4090705@mweb.co.za> On 2012/08/17 12:42 AM, Madison May wrote: > As a lurker, I agree completely with Chris's sentiments. I too, but I'd prefer something top-posted than have to skip through 38 pages of quoted e-mail to get to a (generally) 1 liner at the bottom. -- Regards Alex From emile at fenx.com Tue Aug 21 02:11:49 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Aug 2012 23:11:49 -0700 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On 8/20/2012 9:34 PM John Nagle said... > After a thread of clueless replies, s/clueless/unread Emile From nhodgson at iinet.net.au Tue Aug 21 03:03:33 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 21 Aug 2012 17:03:33 +1000 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <5030c52d$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <7xfw7j3a1x.fsf@ruckus.brouhaha.com> <7xtxvzehhb.fsf@ruckus.brouhaha.com> <50309d69$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x4nnzmhbn.fsf@ruckus.brouhaha.com> <5030c52d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3bOdnbu1sNbdrq7NnZ2dnUVZ_vWdnZ2d@westnet.com.au> Steven D'Aprano: > Using variable-sized strings like UTF-8 and UTF-16 for in-memory > representations is a terrible idea because you can't assume that people > will only every want to index the first or last character. On average, > you need to scan half the string, one character at a time. In Big-Oh, we > can ignore the factor of 1/2 and just say we scan the string, O(N). In the majority of cases you can remove excessive scanning by caching the most recent index->offset result. If the next index request is nearer the cached index than to the beginning then iterate from that offset. This converts many operations from quadratic to linear. Locality of reference is common and can often be reasonably exploited. However, exposing the variable length nature of UTF-8 allows the application to choose efficient techniques for more cases. Neil From jamie at kode5.net Tue Aug 21 03:11:39 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Tue, 21 Aug 2012 08:11:39 +0100 Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: <20120821071139.GA66140@kontrol.kode5.net> [ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ] > I'll be using Google Groups (hopefully it won't top-post by default) to > post stuff. You are encouraged to get used to it i'm afraid as any mailing list you use, its users will prefer you to use the correct formatting of responses. You can change the settings in Gmail web interface or use an MUA and configure that. From oscar.j.benjamin at gmail.com Tue Aug 21 03:40:40 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 21 Aug 2012 08:40:40 +0100 Subject: Class.__class__ magic trick help In-Reply-To: <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro wrote: > Consider this code: > class SlowStorage(dict): > def __getattr__(self,key): > return self[key] > def __setattr__(self,key): > self[key]=value > class FastStorage(dict): > def __init__(self, __d__=None, **kwargs): > self.update(__d__,**kwargs) > def __getitem__(self,key): > return self.__dict__.get(key,None) > def __setitem__(self,key,value): > self.__dict__[key] = value > def __delitem__(self,key): > delattr(self,key) > def __copy__(self): > return Storage(self) > def __nonzero__(self): > return len(self.__dict__)>0 > def pop(self,key,default=None): > if key in self: > default = getattr(self,key) > delattr(self,key) > return default > def clear(self): > self.__dict__.clear() > def __repr__(self): > return repr(self.__dict__) > def keys(self): > return self.__dict__.keys() > def values(self): > return self.__dict__.values() > def items(self): > return self.__dict__.items() > def iterkeys(self): > return self.__dict__.iterkeys() > def itervalues(self): > return self.__dict__.itervalues() > def iteritems(self): > return self.__dict__.iteritems() > def viewkeys(self): > return self.__dict__.viewkeys() > def viewvalues(self): > return self.__dict__.viewvalues() > def viewitems(self): > return self.__dict__.viewitems() > def fromkeys(self,S,v=None): > return self.__dict__.fromkeys(S,v) > def setdefault(self, key, default=None): > try: > return getattr(self,key) > except AttributeError: > setattr(self,key,default) > return default > def clear(self): > self.__dict__.clear() > def len(self): > return len(self.__dict__) > def __iter__(self): > return self.__dict__.__iter__() > def has_key(self,key): > return key in self.__dict__ > def __contains__(self,key): > return key in self.__dict__ > def update(self,__d__=None,**kwargs): > if __d__: > for key in __d__: > kwargs[key] = __d__[key] > self.__dict__.update(**kwargs) > def get(self,key,default=None): > return getattr(self,key) if key in self else default > >>> s=SlowStorage() > >>> a.x=1 ### (1) > >>> a.x ### (2) > 1 # ok > >>> isinstance(a,dict) > True # ok > >>> print dict(a) > {'x':1} # ok (3) Try: >>> a.items() What does that show? > >>> s=FastStorage() > >>> a.x=1 ### (4) > >>> a.x ### (5) > 1 # ok > >>> isinstance(a,dict) > True # ok > >>> print dict(a) > {} # not ok (6) > Lines (4) and (5) are about 10x faster then lines (1) and (2). I like > FastStorage better but while (3) behaves ok, (6) does not behave as I > want. > I intuitively understand why FastStorage is cannot cast into dict > properly. > What I do not know is how to make it do the casting properly without > losing the 10x speedup of FastStorage over SlowStorage. > Any idea? I don't really understand what your trying to do but since you didn't add the __setattr__ method to FastStorage the item is not added to the dictionary when you do a.x = 1 Oscar From __peter__ at web.de Tue Aug 21 03:52:09 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Aug 2012 09:52:09 +0200 Subject: Abuse of subject, was Re: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: wxjmfauth at gmail.com wrote: > By chance and luckily, first attempt. > c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' > , '?')" > 1000000 loops, best of 3: 1.48 usec per loop > c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' > , '?')" > 100000 loops, best of 3: 7.62 usec per loop OK, that is roughly factor 5. Let's see what I get: $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' 100000 loops, best of 3: 1.8 usec per loop $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' 10000 loops, best of 3: 9.11 usec per loop That is factor 5, too. So I can replicate your measurement on an AMD64 Linux system with self-built 3.3 versus system 3.2. > Note > The used characters are not members of the latin-1 coding > scheme (btw an *unusable* coding). > They are however charaters in cp1252 and mac-roman. You seem to imply that the slowdown is connected to the inability of latin-1 to encode "?" and "?" (to take the examples relevant to the above microbench). So let's repeat with latin-1 characters: $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' 100000 loops, best of 3: 1.76 usec per loop $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' 10000 loops, best of 3: 10.3 usec per loop Hm, the slowdown is even a tad bigger. So we can safely dismiss your theory that an unfortunate choice of the 8 bit encoding is causing it. Do you agree? From steve+comp.lang.python at pearwood.info Tue Aug 21 03:59:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Aug 2012 07:59:13 GMT Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <50333fd1$0$1645$c3e8da3$76491128@news.astraweb.com> On Tue, 21 Aug 2012 08:07:33 +0200, Alex Strickland wrote: > On 2012/08/17 12:42 AM, Madison May wrote: > >> As a lurker, I agree completely with Chris's sentiments. > > I too, but I'd prefer something top-posted than have to skip through 38 > pages of quoted e-mail to get to a (generally) 1 liner at the bottom. +1000 People with Hotmail accounts used to be known as "Metoobees" because of their tendency to reply to long posts with a single line at the very end, "Me too!". -- Steven From ulrich.eckhardt at dominolaser.com Tue Aug 21 04:15:37 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 21 Aug 2012 10:15:37 +0200 Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> Message-ID: <9msbg9-dop.ln1@satorlaser.homedns.org> Am 21.08.2012 00:49, schrieb Prasad, Ramit: >>> I also tend to blame M$ (Outlook and variants) for this tendency to >>> quote everything and top-post -- Outlook makes it almost impossible >>> to do a trim&interleave response style. >> >> I [think] that Outlook & Co are guilty. That and the fact that few >> people even think about this. > > Nonsense, I post only from Outlook. You can do it and it is not hard. > It is just requires a little effort. A good tool would reduce the effort and guide users, like e.g. giving them a hint if they leave the whole mail they're replying to as copy. Several corporate email solutions (like MS Outlook/Exchange) put very little emphasis on communication efficiency but only on eye-candy features. Their popularity and the resulting influence on people has caused decay in average communication culture, and that is what I blame them for. BTW: You omitted the attribution line for the text you quoted, whom do you blame for that? That said, "Nonsense" is a strong enough word to start a flamewar... not nice. ;^) Uli From namenobodywants at gmail.com Tue Aug 21 04:38:33 2012 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Tue, 21 Aug 2012 01:38:33 -0700 (PDT) Subject: color coding for numbers Message-ID: <57f81534-03af-475f-91c1-aee554e71ab6@googlegroups.com> hello what is the best way of using color/shading on a tkinter canvas as a visualization for a two-dimensional grid of numbers? so far my best idea is to use the same value for R,G and B (fill = '#xyxyxy'), which gives shades of gray. if possible i'd like to have a larger number of visually distinct values. i've seen visualizations that seem to use some kind of hot-versus-cold color coding. does anybody know how to do this? thanks if you can help. peace stm From rosuav at gmail.com Tue Aug 21 05:00:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Aug 2012 19:00:29 +1000 Subject: Does Polymorphism mean python can create object? In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 10:20 AM, alex23 wrote: > On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: >> Does Polymorphism mean python can create object? > > No. This isn't D&D. Polymorphism has a distinct meaning in computer science, one which you would've found in less time searching Wikipedia than asking this question here. That said, though, I wouldn't be against someone casting Baleful Polymorph on the odd troll... ChrisA From kevin.misc.10 at gmail.com Tue Aug 21 05:09:21 2012 From: kevin.misc.10 at gmail.com (Kevin Zhang) Date: Tue, 21 Aug 2012 17:09:21 +0800 Subject: unittest - sort cases to be run Message-ID: Hi all, I want to sort the order of the unittest cases to be run, but found such statement in Python doc, "Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings." s.addTest(BTest()) s.addTest(ATest()) TextTestRunner().run(ts) I need BTest() to be run prior to ATest(), is there any natural/beautiful way to achieve this? Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Aug 21 05:34:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Aug 2012 05:34:33 -0400 Subject: unittest - sort cases to be run In-Reply-To: References: Message-ID: On 8/21/2012 5:09 AM, Kevin Zhang wrote: > Hi all, > > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "Note that the order in which the various test cases will be run is > determined by sorting the test function names with respect to the > built-in ordering for strings." > > s.addTest(BTest()) > s.addTest(ATest()) > TextTestRunner().run(ts) > > I need BTest() to be run prior to ATest(), is there any > natural/beautiful way to achieve this? Thanks, Rename it @BTest. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Aug 21 05:53:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Aug 2012 09:53:45 GMT Subject: Abuse of Big Oh notation References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> <7xr4r1pn72.fsf@ruckus.brouhaha.com> Message-ID: <50335aa8$0$1645$c3e8da3$76491128@news.astraweb.com> On Mon, 20 Aug 2012 11:12:22 -0600, Ian Kelly wrote: > On Mon, Aug 20, 2012 at 10:09 AM, Chris Angelico > wrote: >> On Tue, Aug 21, 2012 at 2:01 AM, Paul Rubin >> wrote: >>> Analogy: how big a box is required to hold a pair of shoes? In a >>> purely theoretical sense we might say O(S) where S is the shoe size, >>> treating shoe size as an arbitrary independent variable. But in the >>> real world, shoe size is controlled by the size of human feet, which >>> is bounded by a constant for biological reasons. You don't have to >>> consider shoes the size of Jupiter. So it is O(1). >> >> By that argument, everything is amortized O(1), because there's a limit >> on every variable. You can't possibly be working with a data set >> greater than the total sum of storage space in the entire world. That >> still doesn't mean that bubble sort and heap sort are equivalently >> efficient. > > The difference between the two is that the former is bounded by a > constant that is fundamental to the algorithm at hand, whereas the > latter is bounded only by available resources. By any practical > consideration the latter must be considered a variable, but the former > need not be. > > Paul discusses above the asymptotic growth of a variable as O(S) where S > is shoe size, but really this measure makes no sense in the first place. > The question that this notation seeks to answer is, "What is the big-Oh > behaviour of this variable as shoe size increases indefinitely (i.e. to > infinity)?" and the answer in this case is "Shoe size does not increase > indefinitely"; the question is invalid. > > A more logical question might be, "How much material do I need to > construct N shoes of size S?" The answer to this question would > presumably be some constant factor of N * S**2, which is O(N * S**2). > Although N can be assumed to vary freely (up to nonsensical quantities > like the mass of the entire universe), S is clearly bounded by the > constraints of actual shoes, so we can safely treat S as a constant and > call it O(N). Why the hell are we talking about shoe sizes? Let's not lose sight of the actual question in hand: how expensive is it to fetch a character at some arbitrary index in a string? With fixed-width characters, average time is O(1), best-case time is O(1) and worst-case time is O(1). With non-fixed width characters, average time and worst-case time are both O(N), and best-case ("give me the character at index 0") is O(1). But that's a degenerate case that gives us absolutely no insight into the cost of the operation. It's like the observation that "sorting a list of one item takes constant time, regardless of the algorithm". Um, yes, it does. So what? Invented constraints like "people only care about indexes really close to zero, or to the end of the string", effectively confuse the best possible case for the average case. In real life, people do care about random access to strings and the average case is more important than the best case. That's why strings are typically implemented as arrays of fixed- width characters rather than linked lists, and Haskell (which doesn't) explicitly warns you that they don't and that your string-handling code is likely to be slow. Of course, you can swap space and complexity for time, e.g. ropes, or use cached pointers to character locations in the hope that indexes will be clustered rather than scattered randomly. These more complex implementations typically use as much memory than, and performance is often no better than, a dead simple implementation that uses a simple array of fixed width characters. Most harmful, it means that a simple indexing operation may be fast on average, and occasionally degenerate to slow. The only thing worse than "This program is slow" is "This program is *occasionally* slow, and I can't predict when". Not surprising, almost all programming languages in common usage use arrays of fixed-width characters as their native string type. Python 3.3 will now do the same thing, with the memory optimization that the fixed- width will be per string and selected from 1, 2, or 4 bytes according to the minimum width needed, rather than choosing between 2 and 4 bytes when you build the Python compiler. This is a big positive step forward with a pretty simple algorithm and will strongly help encourage the use of Unicode by taking much of the sting out of the perennial complaints that "Unicode wastes space". Not so wasteful any more. -- Steven From ulrich.eckhardt at dominolaser.com Tue Aug 21 06:55:09 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 21 Aug 2012 12:55:09 +0200 Subject: color coding for numbers In-Reply-To: <57f81534-03af-475f-91c1-aee554e71ab6@googlegroups.com> References: <57f81534-03af-475f-91c1-aee554e71ab6@googlegroups.com> Message-ID: Am 21.08.2012 10:38, schrieb namenobodywants at gmail.com: > what is the best way Define "best" before asking such questions. ;) > using color/shading on a tkinter canvas as a visualization for a > two-dimensional grid of numbers? so far my best idea is to use the > same value for R,G and B (fill = '#xyxyxy'), which gives shades of > gray. if possible i'd like to have a larger number of visually > distinct values. The basic idea behind this is that you first normalize the values to a value between zero and one and then use that to look up an according color in an array. Of course you can also do both in one step or compute the colors in the array on the fly (like you did), but it helps keeping things simple at least for a start, and it also allows testing different approaches separately. If the different number of resulting colors isn't good enough then, it could be that the array is too small (its size determines the maximum number of different colours), that the normalization only uses a small range between zero and one (reducing the effectively used number of colours) or simply that your screen doesn't support that many different colors. > i've seen visualizations that seem to use some kind > of hot-versus-cold color coding. does anybody know how to do this? The colour-coding is just the way that above mentioned array is filled. For the hot/cold coding, you could define a dark blue for low values and a bright red for high values and then simply interpolate the RGB triple for values in between. Uli From roy at panix.com Tue Aug 21 07:48:51 2012 From: roy at panix.com (Roy Smith) Date: Tue, 21 Aug 2012 07:48:51 -0400 Subject: New internal string format in 3.3 References: <5030891f$0$29978$c3e8da3$5496439d@news.astraweb.com> <5030aa44$0$29978$c3e8da3$5496439d@news.astraweb.com> <11931ec9-1858-4ae8-8a61-1d154d105229@googlegroups.com> <73c85f3b-a4a9-4812-bc41-132b5126874c@googlegroups.com> <1f22cebc-71aa-4881-bac5-d97d72fe2633@googlegroups.com> <5570714c-59e7-4149-b2bd-89d7628774e3@googlegroups.com> Message-ID: In article , Michael Torrie wrote: > > And if you want the "fudge it somehow" behavior (which is often very > > useful!), there's always http://pypi.python.org/pypi/Unidecode/ > > Sweet tip, thanks! I often want to process text that has smart quotes, > emdashes, etc, and convert them to plain old ascii quotes, dashes, > ticks, etc. This will do that for me without resorting to a bunch of > regexes. Bravo. Yup, that's one of the things it's good for. We mostly use it to help map search terms, i.e. if you search for "beyonce", you're probably expecting it to match "Beyonc?". We also special-case some weird stuff like "kesha" matching "ke$ha", but we have to hand-code those. From roy at panix.com Tue Aug 21 07:51:50 2012 From: roy at panix.com (Roy Smith) Date: Tue, 21 Aug 2012 07:51:50 -0400 Subject: Does Polymorphism mean python can create object? References: Message-ID: In article , Chris Angelico wrote: > On Tue, Aug 21, 2012 at 10:20 AM, alex23 wrote: > > On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: > >> Does Polymorphism mean python can create object? > > > > No. This isn't D&D. Polymorphism has a distinct meaning in computer > > science, one which you would've found in less time searching Wikipedia than > > asking this question here. > > That said, though, I wouldn't be against someone casting Baleful > Polymorph on the odd troll... Won't work. Trolls always make their random.saving_throw(). From malaclypse2 at gmail.com Tue Aug 21 08:06:43 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 21 Aug 2012 08:06:43 -0400 Subject: python 6 compilation failure on RHEL In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 12:34 AM, John Nagle wrote: > After a thread of clueless replies, it's clear that nobody > responding actually read the build log. Here's the problem: The very first reply, Emile's, pointed out that these were optional modules, and that python did, in fact build successfully. > Failed to find the necessary bits to build these modules: > bsddb185 > dl > imageop > sunaudiodev > > What's wrong is that the Python 2.6 build script is looking for > some antiquated packages that aren't in a current RHEL. Those > need to be turned off. They don't need to be turned off. They can either be ignored (because they aren't needed, and did not cause the build to fail), or the development libraries for those pieces can be installed and python recompiled. The rest of the thread has been commenting on the OP's choice of python version and operating system. That's not exactly on topic, but the original question was answered in the very first response. -- Jerry From massimo.dipierro at gmail.com Tue Aug 21 08:52:31 2012 From: massimo.dipierro at gmail.com (Massimo Di Pierro) Date: Tue, 21 Aug 2012 05:52:31 -0700 (PDT) Subject: Class.__class__ magic trick help References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: On Aug 21, 2:40?am, Oscar Benjamin wrote: > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > wrote: > > Consider this code: > > class SlowStorage(dict): > > ? ? def __getattr__(self,key): > > ? ? ? ? ? return self[key] > > ? ? def __setattr__(self,key): > > ? ? ? ? ? self[key]=value > > class FastStorage(dict): > > ? ? def __init__(self, __d__=None, **kwargs): > > ? ? ? ? self.update(__d__,**kwargs) > > ? ? def __getitem__(self,key): > > ? ? ? ? return self.__dict__.get(key,None) > > ? ? def __setitem__(self,key,value): > > ? ? ? ? self.__dict__[key] = value > > ? ? def __delitem__(self,key): > > ? ? ? ? delattr(self,key) > > ? ? def __copy__(self): > > ? ? ? ? return Storage(self) > > ? ? def __nonzero__(self): > > ? ? ? ? return len(self.__dict__)>0 > > ? ? def pop(self,key,default=None): > > ? ? ? ? if key in self: > > ? ? ? ? ? ? default = getattr(self,key) > > ? ? ? ? ? ? delattr(self,key) > > ? ? ? ? return default > > ? ? def clear(self): > > ? ? ? ? self.__dict__.clear() > > ? ? def __repr__(self): > > ? ? ? ? return repr(self.__dict__) > > ? ? def keys(self): > > ? ? ? ? return self.__dict__.keys() > > ? ? def values(self): > > ? ? ? ? return self.__dict__.values() > > ? ? def items(self): > > ? ? ? ? return self.__dict__.items() > > ? ? ? def iterkeys(self): > > ? ? ? ? return self.__dict__.iterkeys() > > ? ? def itervalues(self): > > ? ? ? ? return self.__dict__.itervalues() > > ? ? def iteritems(self): > > ? ? ? ? return self.__dict__.iteritems() > > ? ? def viewkeys(self): > > ? ? ? ? return self.__dict__.viewkeys() > > ? ? def viewvalues(self): > > ? ? ? ? return self.__dict__.viewvalues() > > ? ? def viewitems(self): > > ? ? ? ? return self.__dict__.viewitems() > > ? ? def fromkeys(self,S,v=None): > > ? ? ? ? return self.__dict__.fromkeys(S,v) > > ? ? def setdefault(self, key, default=None): > > ? ? ? ? try: > > ? ? ? ? ? ? return getattr(self,key) > > ? ? ? ? except AttributeError: > > ? ? ? ? ? ? setattr(self,key,default) > > ? ? ? ? ? ? return default > > ? ? def clear(self): > > ? ? ? ? self.__dict__.clear() > > ? ? def len(self): > > ? ? ? ? return len(self.__dict__) > > ? ? def __iter__(self): > > ? ? ? ? return self.__dict__.__iter__() > > ? ? def has_key(self,key): > > ? ? ? ? return key in self.__dict__ > > ? ? def __contains__(self,key): > > ? ? ? ? return key in self.__dict__ > > ? ? def update(self,__d__=None,**kwargs): > > ? ? ? ? if __d__: > > ? ? ? ? ? ? for key in __d__: > > ? ? ? ? ? ? ? ? kwargs[key] = __d__[key] > > ? ? ? ? self.__dict__.update(**kwargs) > > ? ? def get(self,key,default=None): > > ? ? ? ? return getattr(self,key) if key in self else default > > >>> s=SlowStorage() > > >>> a.x=1 ?### (1) > > >>> a.x ? ?### (2) > > 1 # ok > > >>> isinstance(a,dict) > > True # ok > > >>> print dict(a) > > {'x':1} # ok (3) > > Try: > > >>> a.items() > > What does that show? > > > > > > > > > > > > > >>> s=FastStorage() > > >>> a.x=1 ?### (4) > > >>> a.x ? ?### (5) > > 1 # ok > > >>> isinstance(a,dict) > > True # ok > > >>> print dict(a) > > {} # not ok (6) > > Lines (4) and (5) are about 10x faster then lines (1) and (2). I > like > > FastStorage better but while (3) behaves ok, (6) does not behave as > I > > want. > > I intuitively understand why FastStorage is cannot cast into dict > > properly. > > What I do not know is how to make it do the casting properly without > > losing the 10x speedup of FastStorage over SlowStorage. > > Any idea? > > I don't really understand what your trying to do but since you didn't > add the __setattr__ method to FastStorage the item is not added to > the dictionary when you do a.x = 1 > > Oscar >>> a.items() [('x',1')] all the APIs work as expected except casting to dict. From oscar.benjamin at bristol.ac.uk Tue Aug 21 09:17:03 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Tue, 21 Aug 2012 14:17:03 +0100 Subject: Class.__class__ magic trick help In-Reply-To: References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: On 21 August 2012 13:52, Massimo Di Pierro wrote: > On Aug 21, 2:40 am, Oscar Benjamin wrote: > > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > > > > > > > > > > > wrote: > > > Consider this code: > > > class SlowStorage(dict): > > > def __getattr__(self,key): > > > return self[key] > > > def __setattr__(self,key): > > > self[key]=value > > > class FastStorage(dict): > > > def __init__(self, __d__=None, **kwargs): > > > self.update(__d__,**kwargs) > > > def __getitem__(self,key): > > > return self.__dict__.get(key,None) > > > def __setitem__(self,key,value): > > > self.__dict__[key] = value > > > def __delitem__(self,key): > > > delattr(self,key) > > > def __copy__(self): > > > return Storage(self) > > > def __nonzero__(self): > > > return len(self.__dict__)>0 > > > def pop(self,key,default=None): > > > if key in self: > > > default = getattr(self,key) > > > delattr(self,key) > > > return default > > > def clear(self): > > > self.__dict__.clear() > > > def __repr__(self): > > > return repr(self.__dict__) > > > def keys(self): > > > return self.__dict__.keys() > > > def values(self): > > > return self.__dict__.values() > > > def items(self): > > > return self.__dict__.items() > > > def iterkeys(self): > > > return self.__dict__.iterkeys() > > > def itervalues(self): > > > return self.__dict__.itervalues() > > > def iteritems(self): > > > return self.__dict__.iteritems() > > > def viewkeys(self): > > > return self.__dict__.viewkeys() > > > def viewvalues(self): > > > return self.__dict__.viewvalues() > > > def viewitems(self): > > > return self.__dict__.viewitems() > > > def fromkeys(self,S,v=None): > > > return self.__dict__.fromkeys(S,v) > > > def setdefault(self, key, default=None): > > > try: > > > return getattr(self,key) > > > except AttributeError: > > > setattr(self,key,default) > > > return default > > > def clear(self): > > > self.__dict__.clear() > > > def len(self): > > > return len(self.__dict__) > > > def __iter__(self): > > > return self.__dict__.__iter__() > > > def has_key(self,key): > > > return key in self.__dict__ > > > def __contains__(self,key): > > > return key in self.__dict__ > > > def update(self,__d__=None,**kwargs): > > > if __d__: > > > for key in __d__: > > > kwargs[key] = __d__[key] > > > self.__dict__.update(**kwargs) > > > def get(self,key,default=None): > > > return getattr(self,key) if key in self else default > > > >>> s=SlowStorage() > > > >>> a.x=1 ### (1) > > > >>> a.x ### (2) > > > 1 # ok > > > >>> isinstance(a,dict) > > > True # ok > > > >>> print dict(a) > > > {'x':1} # ok (3) > > > > Try: > > > > >>> a.items() > > > > What does that show? > > > > > > > > > > > > > > > > > > > > > > > > > >>> s=FastStorage() > > > >>> a.x=1 ### (4) > > > >>> a.x ### (5) > > > 1 # ok > > > >>> isinstance(a,dict) > > > True # ok > > > >>> print dict(a) > > > {} # not ok (6) > > > Lines (4) and (5) are about 10x faster then lines (1) and (2). I > > like > > > FastStorage better but while (3) behaves ok, (6) does not behave as > > I > > > want. > > > I intuitively understand why FastStorage is cannot cast into dict > > > properly. > > > What I do not know is how to make it do the casting properly without > > > losing the 10x speedup of FastStorage over SlowStorage. > > > Any idea? > > > > I don't really understand what your trying to do but since you didn't > > add the __setattr__ method to FastStorage the item is not added to > > the dictionary when you do a.x = 1 > > > > Oscar > > >>> a.items() > [('x',1')] > > all the APIs work as expected except casting to dict. > -- > http://mail.python.org/mailman/listinfo/python-list > Sorry, I see what you're doing now. Because you've subclassed dict the dict constructor is not using any of the python methods you have defined to create a new dict. It is copying directly from the builtin instance that your instance is wrapping, but you haven't actually passed your values on to the superclass so it hasn't stored them in the builtin data structure. Either subclass object so that your methods are called, or do something like: def __setitem__(self,key,value): self.__dict__[key] = value dict.__setitem__(self, key, value) I still don't see the point of this but that should work. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.frederich at gmail.com Tue Aug 21 09:22:42 2012 From: eric.frederich at gmail.com (Eric Frederich) Date: Tue, 21 Aug 2012 09:22:42 -0400 Subject: remote read eval print loop In-Reply-To: References: <502dac1e$0$29978$c3e8da3$5496439d@news.astraweb.com> <9b7aa68b-3103-42b4-b2d5-41a577ef388f@j2g2000pbg.googlegroups.com> Message-ID: This isn't really for users. It is for developers like me. Yes it is a security hole but again, it is a debugger. The people who will be using it can all ssh into the server machine with the same ID that the server process is running on. In fact, this is quite normal. As it is right now, we log into these machines and start an interactive Python and use the bindings to debug things. This works well most of the time but when you do that you need to start another session of the application. It is useful to run code interactively from within an actual client session where something has gone wrong. In any case.... I got this working with a rudimentary SWT Java client (yuck, but the application is based on Eclipse). Below is the code I used. It has a singleton interactive console object. I sub-classed it and defined another method "process" which simply calls the "push" method after wrapping stdout and stderr. It returns anything that was printed to stdout, stderr, and the return value of the "push" method. So now from the client I can process one line at a time and it behaves much like the real interactive console... you wouldn't even realize there is all this client / server / WSDL / xml / https junk going on. ############ BEGIN CODE import sys from code import InteractiveConsole class MyBuffer(object): def __init__(self): self.buffer = [] def write(self, data): self.buffer.append(data) def get(self): ret = ''.join(self.buffer) self.buffer = [] return ret class MyInteractiveConsole(InteractiveConsole): def __init__(self, *args, **kwargs): InteractiveConsole.__init__(self, *args, **kwargs) self.mb_out = MyBuffer() self.mb_err = MyBuffer() def process(self, s): sys.stdout, sys.stderr = self.mb_out, self.mb_err more = self.push(s) sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__ return self.mb_out.get(), self.mb_err.get(), more print 'creating new interactive console' mic = MyInteractiveConsole() On Fri, Aug 17, 2012 at 10:06 AM, Chris Angelico wrote: > On Fri, Aug 17, 2012 at 11:28 PM, Eric Frederich > wrote: > > Within the debugging console, after importing all of the bindings, there > > would be no reason to import anything whatsoever. > > With just the bindings I created and the Python language we could do > > meaningful debugging. > > So if I block the ability to do any imports and calls to eval I should be > > safe right? > > Nope. Python isn't a secured language in that way. I tried the same > sort of thing a while back, but found it effectively impossible. (And > this after people told me "It's not possible, don't bother trying". I > tried anyway. It wasn't possible.) > > If you really want to do that, consider it equivalent to putting an > open SSH session into your debugging console. Would you give that much > power to your application's users? And if you would, is it worth > reinventing SSH? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From massimo.dipierro at gmail.com Tue Aug 21 09:50:17 2012 From: massimo.dipierro at gmail.com (Massimo Di Pierro) Date: Tue, 21 Aug 2012 06:50:17 -0700 (PDT) Subject: Class.__class__ magic trick help References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: Hello Oscar, thanks for your help but your proposal of adding: def __setitem__(self,key,value): self.__dict__[key] = value dict.__setitem__(self, key, value) does not help me. What I have today is a class that works like SlowStorage. I want to replace it with NewStorage because it is 10x faster. That is the only reason. NewStorage does everything I want and all the APIs work like SlowStorage except casting to dict. By defining __setitem__ as you propose, you solve the casting to dict issue but you have two unwanted effects: each key,value is store twice (in different places), accessing the elements becomes slower the SlowStprage which is my problem in the first place. The issue for me is understanding how the casting dict(obj) works and how to change its behavior so that is uses methods exposed by obj to do the casting, if all possible. Massimo From oscar.benjamin at bristol.ac.uk Tue Aug 21 10:14:43 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Tue, 21 Aug 2012 15:14:43 +0100 Subject: Class.__class__ magic trick help In-Reply-To: References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: On 21 August 2012 14:50, Massimo Di Pierro wrote: > Hello Oscar, > > thanks for your help but your proposal of adding: > > def __setitem__(self,key,value): > self.__dict__[key] = value > dict.__setitem__(self, key, value) > > does not help me. > > What I have today is a class that works like SlowStorage. I want to > replace it with NewStorage because it is 10x faster. That is the only > reason. NewStorage does everything I want and all the APIs work like > SlowStorage except casting to dict. > > By defining __setitem__ as you propose, you solve the casting to dict > issue but you have two unwanted effects: each key,value is store twice > (in different places), accessing the elements becomes slower the > SlowStprage which is my problem in the first place. > > The issue for me is understanding how the casting dict(obj) works and > how to change its behavior so that is uses methods exposed by obj to > do the casting, if all possible. > Then you have two options: 1) subclass object instead of dict - you're not using any of the features of the dict superclass and the fact that it is a superclass is confusing the dict() constructor. 2) use a different "cast" e.g. d = dict(a.items()) Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From massimo.dipierro at gmail.com Tue Aug 21 10:42:11 2012 From: massimo.dipierro at gmail.com (Massimo DiPierro) Date: Tue, 21 Aug 2012 09:42:11 -0500 Subject: Class.__class__ magic trick help In-Reply-To: References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> Message-ID: <670B5110-A816-4AE7-801F-E6025D887646@gmail.com> Thanks again Oscar. I cannot do that. I have tight constraints. I am not at liberty to modify the code that uses the class. The exposed API cannot change including a.x, dict(a), is isinstance(a,dict). My goal it so change the definition of this class to make it faster. Where is in the Python source code is the casting to dict defined? Where can I try understand what it does? Massimo On Aug 21, 2012, at 9:14 AM, Oscar Benjamin wrote: > On 21 August 2012 14:50, Massimo Di Pierro wrote: > Hello Oscar, > > thanks for your help but your proposal of adding: > > def __setitem__(self,key,value): > self.__dict__[key] = value > dict.__setitem__(self, key, value) > > does not help me. > > What I have today is a class that works like SlowStorage. I want to > replace it with NewStorage because it is 10x faster. That is the only > reason. NewStorage does everything I want and all the APIs work like > SlowStorage except casting to dict. > > By defining __setitem__ as you propose, you solve the casting to dict > issue but you have two unwanted effects: each key,value is store twice > (in different places), accessing the elements becomes slower the > SlowStprage which is my problem in the first place. > > The issue for me is understanding how the casting dict(obj) works and > how to change its behavior so that is uses methods exposed by obj to > do the casting, if all possible. > > Then you have two options: > 1) subclass object instead of dict - you're not using any of the features of the dict superclass and the fact that it is a superclass is confusing the dict() constructor. > 2) use a different "cast" e.g. d = dict(a.items()) > > Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.benjamin at bristol.ac.uk Tue Aug 21 11:43:21 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Tue, 21 Aug 2012 16:43:21 +0100 Subject: Class.__class__ magic trick help In-Reply-To: References: <21067364-7b9c-4415-bad1-947961497343@u20g2000yqc.googlegroups.com> <8dc49931-de0d-4ce3-8b0d-8789bc8c07c8@w9g2000yqe.googlegroups.com> <670B5110-A816-4AE7-801F-E6025D887646@gmail.com> Message-ID: On 21 August 2012 16:19, Oscar Benjamin wrote: > > On Aug 21, 2012 3:42 PM, "Massimo DiPierro" > wrote: > > > > Thanks again Oscar. I cannot do that. I have tight constraints. I am not > at liberty to modify the code that uses the class. The exposed API cannot > change including a.x, dict(a), is isinstance(a,dict). > > > > My goal it so change the definition of this class to make it faster. > > > > Where is in the Python source code is the casting to dict defined? Where > can I try understand what it does? > > help(dict) > > There is no cast, there is only the dict constructor. If the dict > constructor finds a dict instance (including from a subclass) then it will > efficiently create the new dict from the old dict's underlying data without > calling your methods. If you want dict(a) and isinstance(dict) to work them > you need to tell the dict superclass to store the data using > dict.__setitem__. > > You have three options: > 1) use SlowStorage > 2) duplicate the data in self and self.__dict__ (this will probably end up > slowing down FastStorage) > 3) change the requirement to isinstance(Mapping) > > Oscar > Okay, there is a way to solve your problem: >>> class Storage(dict): ... def __init__(self, *args, **kwargs): ... dict.__init__(self, *args, **kwargs) ... self.__dict__ = self ... >>> s = Storage() >>> s {} >>> s.x = 1 >>> s {'x': 1} >>> dict(s) {'x': 1} >>> isinstance(s, dict) True But it's a stupid idea unless you know that the keys of your dict will *never* have any of the following values: >>> dir({}) ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues'] To see what goes wrong: >>> s['items'] = [1,2,3] >>> s.items() Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Tue Aug 21 12:22:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 21 Aug 2012 09:22:48 -0700 (PDT) Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: On Tuesday, 21 August 2012 12:41:39 UTC+5:30, Jamie Paul Griffin wrote: > [ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ] > > > > > I'll be using Google Groups (hopefully it won't top-post by default) to > > > post stuff. > > > > You are encouraged to get used to it i'm afraid as any mailing list you use, its users will prefer you to use the correct formatting of responses. > > > > You can change the settings in Gmail web interface or use an MUA and configure that. Enough of OT. From maniandram01 at gmail.com Tue Aug 21 12:22:48 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 21 Aug 2012 09:22:48 -0700 (PDT) Subject: [ANNC] pybotwar-0.8 In-Reply-To: References: <502CBD87.8030704@sequans.com> <502e3eae$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: On Tuesday, 21 August 2012 12:41:39 UTC+5:30, Jamie Paul Griffin wrote: > [ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ] > > > > > I'll be using Google Groups (hopefully it won't top-post by default) to > > > post stuff. > > > > You are encouraged to get used to it i'm afraid as any mailing list you use, its users will prefer you to use the correct formatting of responses. > > > > You can change the settings in Gmail web interface or use an MUA and configure that. Enough of OT. From miki.tebeka at gmail.com Tue Aug 21 12:23:00 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 21 Aug 2012 09:23:00 -0700 (PDT) Subject: How to convert base 10 to base 2? In-Reply-To: References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: <5fb03f8e-e910-4d86-8e34-a7561385ab88@googlegroups.com> > You get the binary by doing bin(x), where x is an integer. Note that Python also support binary number literals (prefixed with 0b): In [1]: 0b101 Out[1]: 5 From miki.tebeka at gmail.com Tue Aug 21 12:23:00 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 21 Aug 2012 09:23:00 -0700 (PDT) Subject: How to convert base 10 to base 2? In-Reply-To: References: <1cedbf80-117b-48aa-a9f2-754293203408@googlegroups.com> Message-ID: <5fb03f8e-e910-4d86-8e34-a7561385ab88@googlegroups.com> > You get the binary by doing bin(x), where x is an integer. Note that Python also support binary number literals (prefixed with 0b): In [1]: 0b101 Out[1]: 5 From miki.tebeka at gmail.com Tue Aug 21 12:44:10 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 21 Aug 2012 09:44:10 -0700 (PDT) Subject: Why does dynamic doc string do not work? Message-ID: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Greetings, >>> class A: ... '''a doc string''' ... >>> A.__doc__ 'a doc string' >>> class B: ... '''a {} string'''.format('doc') ... >>> B.__doc__ >>> Is there's a reason for this? I know I can do: >>> class B: ... __doc__ = '''a {} string'''.format('doc') And it'll work, but I wonder why the first B docstring is empty. Thanks, -- Miki From guillaume.comte10 at gmail.com Tue Aug 21 13:00:28 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Tue, 21 Aug 2012 10:00:28 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> Message-ID: <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of the code: import socket import os import struct import time import select ICMP_ECHO_REQUEST = 8 PACKET_SIZE = 64 # Bytes TIMEOUT = 0.5 # Seconds def do_one(src_addr, dest_addr): my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) if src_addr != None: src_addr = socket.gethostbyname(src_addr) my_socket.bind((src_addr, 1)) my_id = os.getpid() & 0xFFFF print "id: " + str(my_id) print "sending..." send_one(dest_addr, my_socket, my_id) print "receiving..." id = receive_one(my_socket) if id == None: print "nothing received !" else: print "received id: " + str(id) my_socket.close() def checksum(source_string): ... def send_one(addr, my_socket, id): # Header: type (8), code (8), checksum (16), id (16), sequence number (16) cs = 0 header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, cs, socket.htons(id), 0) data = PACKET_SIZE * "G" cs = checksum(header + data) header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, socket.htons(cs), socket.htons(id), 0) packet = header + data my_socket.sendto(packet, (socket.gethostbyname(addr), 1)) def receive_one(my_socket): while True: what_ready = select.select([my_socket], [], [], TIMEOUT) if what_ready[0] == []: return None received_packet = my_socket.recvfrom(1024)[0] header = received_packet[20:28] id = struct.unpack("bbHHh", header)[3] return socket.ntohs(id) if __name__ == "__main__": import sys dst = sys.argv[1] print "dst: " + dst try: src = sys.argv[2] print "src: " + src except IndexError: src = None do_one(src, dst) But when I try to set a source address, I still get the same error message... Does anyone know how I could build the IP header (I don't even know if it can be the solution but it's worth a try...)? From guillaume.comte10 at gmail.com Tue Aug 21 13:00:28 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Tue, 21 Aug 2012 10:00:28 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> Message-ID: <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of the code: import socket import os import struct import time import select ICMP_ECHO_REQUEST = 8 PACKET_SIZE = 64 # Bytes TIMEOUT = 0.5 # Seconds def do_one(src_addr, dest_addr): my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) if src_addr != None: src_addr = socket.gethostbyname(src_addr) my_socket.bind((src_addr, 1)) my_id = os.getpid() & 0xFFFF print "id: " + str(my_id) print "sending..." send_one(dest_addr, my_socket, my_id) print "receiving..." id = receive_one(my_socket) if id == None: print "nothing received !" else: print "received id: " + str(id) my_socket.close() def checksum(source_string): ... def send_one(addr, my_socket, id): # Header: type (8), code (8), checksum (16), id (16), sequence number (16) cs = 0 header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, cs, socket.htons(id), 0) data = PACKET_SIZE * "G" cs = checksum(header + data) header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, socket.htons(cs), socket.htons(id), 0) packet = header + data my_socket.sendto(packet, (socket.gethostbyname(addr), 1)) def receive_one(my_socket): while True: what_ready = select.select([my_socket], [], [], TIMEOUT) if what_ready[0] == []: return None received_packet = my_socket.recvfrom(1024)[0] header = received_packet[20:28] id = struct.unpack("bbHHh", header)[3] return socket.ntohs(id) if __name__ == "__main__": import sys dst = sys.argv[1] print "dst: " + dst try: src = sys.argv[2] print "src: " + src except IndexError: src = None do_one(src, dst) But when I try to set a source address, I still get the same error message... Does anyone know how I could build the IP header (I don't even know if it can be the solution but it's worth a try...)? From djc at news.invalid Tue Aug 21 13:07:04 2012 From: djc at news.invalid (DJC) Date: Tue, 21 Aug 2012 19:07:04 +0200 Subject: color coding for numbers In-Reply-To: References: <57f81534-03af-475f-91c1-aee554e71ab6@googlegroups.com> Message-ID: On 21/08/12 12:55, Ulrich Eckhardt wrote: > Am 21.08.2012 10:38, schrieb namenobodywants at gmail.com: >> what is the best way > > Define "best" before asking such questions. ;) matplotlib.colors A module for converting numbers or color arguments to RGB or RGBA RGB and RGBA are sequences of, respectively, 3 or 4 floats in the range 0-1. This module includes functions and classes for color specification conversions, and for mapping numbers to colors in a 1-D array of colors called a colormap. see > > >> using color/shading on a tkinter canvas as a visualization for a >> two-dimensional grid of numbers? so far my best idea is to use the >> same value for R,G and B (fill = '#xyxyxy'), which gives shades of >> gray. if possible i'd like to have a larger number of visually >> distinct values. > > The basic idea behind this is that you first normalize the values to a > value between zero and one and then use that to look up an according > color in an array. Of course you can also do both in one step or compute > the colors in the array on the fly (like you did), but it helps keeping > things simple at least for a start, and it also allows testing different > approaches separately. > > If the different number of resulting colors isn't good enough then, it > could be that the array is too small (its size determines the maximum > number of different colours), that the normalization only uses a small > range between zero and one (reducing the effectively used number of > colours) or simply that your screen doesn't support that many different > colors. > > > > i've seen visualizations that seem to use some kind > > of hot-versus-cold color coding. does anybody know how to do this? > > The colour-coding is just the way that above mentioned array is filled. > For the hot/cold coding, you could define a dark blue for low values and > a bright red for high values and then simply interpolate the RGB triple > for values in between. > > Uli From ian.g.kelly at gmail.com Tue Aug 21 13:09:58 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Aug 2012 11:09:58 -0600 Subject: Why does dynamic doc string do not work? In-Reply-To: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: > Greetings, > >>>> class A: > ... '''a doc string''' > ... >>>> A.__doc__ > 'a doc string' >>>> class B: > ... '''a {} string'''.format('doc') > ... >>>> B.__doc__ >>>> > > Is there's a reason for this? > > I know I can do: >>>> class B: > ... __doc__ = '''a {} string'''.format('doc') > > And it'll work, but I wonder why the first B docstring is empty. The docstring is built at compile-time, not at run-time, so it must be a literal, not an arbitrary expression. From wxjmfauth at gmail.com Tue Aug 21 13:16:06 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 21 Aug 2012 10:16:06 -0700 (PDT) Subject: Abuse of subject, was Re: Abuse of Big Oh notation In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: <31b05198-4ce0-41c8-8f25-8253a885dff0@googlegroups.com> Le mardi 21 ao?t 2012 09:52:09 UTC+2, Peter Otten a ?crit?: > wxjmfauth at gmail.com wrote: > > > > > By chance and luckily, first attempt. > > > > > c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' > > > , '?')" > > > 1000000 loops, best of 3: 1.48 usec per loop > > > c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' > > > , '?')" > > > 100000 loops, best of 3: 7.62 usec per loop > > > > OK, that is roughly factor 5. Let's see what I get: > > > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 100000 loops, best of 3: 1.8 usec per loop > > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 10000 loops, best of 3: 9.11 usec per loop > > > > That is factor 5, too. So I can replicate your measurement on an AMD64 Linux > > system with self-built 3.3 versus system 3.2. > > > > > Note > > > The used characters are not members of the latin-1 coding > > > scheme (btw an *unusable* coding). > > > They are however charaters in cp1252 and mac-roman. > > > > You seem to imply that the slowdown is connected to the inability of latin-1 > > to encode "?" and "?" (to take the examples relevant to the above > > microbench). So let's repeat with latin-1 characters: > > > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 100000 loops, best of 3: 1.76 usec per loop > > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 10000 loops, best of 3: 10.3 usec per loop > > > > Hm, the slowdown is even a tad bigger. So we can safely dismiss your theory > > that an unfortunate choice of the 8 bit encoding is causing it. Do you > > agree? - I do not care too much about the numbers. It's an attempt to show the principles. - The fact, considering latin-1 as a bad coding, lies on the point that is is simply unsuable for some scripts / languages. It has mainly to do with source/text files coding. This is not really the point here. - Now, the technical aspect. This "coding" (latin-1) may be considered somehow as the pseudo-coding covering the unicode code points range 128..255. Unfortunatelly, this "coding" is not very optimal (or can be see as) when you work with a full range of Unicode, but is is fine when one works only in pure latin-1, with only 256 characters. This range 128..255 is always the critical part (all codings considered). And probably represents the most used characters. I hope, it was not too confused. I have no proof for my theory. With my experience on that field, I highly suspect this as the bottleneck. Some os as before. Py 3.2.3 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.5384088242603358, 1.532421642233382, 1.5327445924545433] >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.561762063667686, 1.5443503206462594, 1.5458670051605168] 3.3.0b2 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [7.701523104134512, 7.720358191179441, 7.614549852683501]>>> >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [4.887939423990709, 4.868787294350611, 4.865697999795991] Quite mysterious! In any way it is a regression. jmf From wxjmfauth at gmail.com Tue Aug 21 13:16:06 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 21 Aug 2012 10:16:06 -0700 (PDT) Subject: Abuse of subject, was Re: Abuse of Big Oh notation In-Reply-To: References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> <50314968$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xwr0ua1pw.fsf@ruckus.brouhaha.com> Message-ID: <31b05198-4ce0-41c8-8f25-8253a885dff0@googlegroups.com> Le mardi 21 ao?t 2012 09:52:09 UTC+2, Peter Otten a ?crit?: > wxjmfauth at gmail.com wrote: > > > > > By chance and luckily, first attempt. > > > > > c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' > > > , '?')" > > > 1000000 loops, best of 3: 1.48 usec per loop > > > c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' > > > , '?')" > > > 100000 loops, best of 3: 7.62 usec per loop > > > > OK, that is roughly factor 5. Let's see what I get: > > > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 100000 loops, best of 3: 1.8 usec per loop > > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 10000 loops, best of 3: 9.11 usec per loop > > > > That is factor 5, too. So I can replicate your measurement on an AMD64 Linux > > system with self-built 3.3 versus system 3.2. > > > > > Note > > > The used characters are not members of the latin-1 coding > > > scheme (btw an *unusable* coding). > > > They are however charaters in cp1252 and mac-roman. > > > > You seem to imply that the slowdown is connected to the inability of latin-1 > > to encode "?" and "?" (to take the examples relevant to the above > > microbench). So let's repeat with latin-1 characters: > > > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 100000 loops, best of 3: 1.76 usec per loop > > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > > 10000 loops, best of 3: 10.3 usec per loop > > > > Hm, the slowdown is even a tad bigger. So we can safely dismiss your theory > > that an unfortunate choice of the 8 bit encoding is causing it. Do you > > agree? - I do not care too much about the numbers. It's an attempt to show the principles. - The fact, considering latin-1 as a bad coding, lies on the point that is is simply unsuable for some scripts / languages. It has mainly to do with source/text files coding. This is not really the point here. - Now, the technical aspect. This "coding" (latin-1) may be considered somehow as the pseudo-coding covering the unicode code points range 128..255. Unfortunatelly, this "coding" is not very optimal (or can be see as) when you work with a full range of Unicode, but is is fine when one works only in pure latin-1, with only 256 characters. This range 128..255 is always the critical part (all codings considered). And probably represents the most used characters. I hope, it was not too confused. I have no proof for my theory. With my experience on that field, I highly suspect this as the bottleneck. Some os as before. Py 3.2.3 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.5384088242603358, 1.532421642233382, 1.5327445924545433] >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [1.561762063667686, 1.5443503206462594, 1.5458670051605168] 3.3.0b2 >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [7.701523104134512, 7.720358191179441, 7.614549852683501]>>> >>> timeit.repeat("('?'*100+'?'*100).replace('?', '?')") [4.887939423990709, 4.868787294350611, 4.865697999795991] Quite mysterious! In any way it is a regression. jmf From python at mrabarnett.plus.com Tue Aug 21 13:16:45 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Aug 2012 18:16:45 +0100 Subject: Why does dynamic doc string do not work? In-Reply-To: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: <5033C27D.3050709@mrabarnett.plus.com> On 21/08/2012 17:44, Miki Tebeka wrote: > Greetings, > >>>> class A: > ... '''a doc string''' > ... >>>> A.__doc__ > 'a doc string' >>>> class B: > ... '''a {} string'''.format('doc') > ... >>>> B.__doc__ >>>> > > Is there's a reason for this? > > I know I can do: >>>> class B: > ... __doc__ = '''a {} string'''.format('doc') > > And it'll work, but I wonder why the first B docstring is empty. > I think what's happening is that it's being parsed and then checked to see whether it's a string literal. This: "doc string" is OK, as is this: "doc" "string" (implied concatenation) and this: ("doc string") but this isn't: "doc" + " string" because its syntax is: ADD(STRING_LITERAL, STRING_LITERAL) In other words, it's looking at the syntax, not the resulting value. From ian.g.kelly at gmail.com Tue Aug 21 13:21:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Aug 2012 11:21:10 -0600 Subject: Why does dynamic doc string do not work? In-Reply-To: References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: On Tue, Aug 21, 2012 at 11:09 AM, Ian Kelly wrote: > On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: >> Greetings, >> >>>>> class A: >> ... '''a doc string''' >> ... >>>>> A.__doc__ >> 'a doc string' >>>>> class B: >> ... '''a {} string'''.format('doc') >> ... >>>>> B.__doc__ >>>>> >> >> Is there's a reason for this? >> >> I know I can do: >>>>> class B: >> ... __doc__ = '''a {} string'''.format('doc') >> >> And it'll work, but I wonder why the first B docstring is empty. > > The docstring is built at compile-time, not at run-time, so it must be > a literal, not an arbitrary expression. Also, if it did allow arbitrary expressions, then the syntax would be ambiguous. def a(): foo() do_stuff() Is "foo()" intended to return a doc string? If so, then it should be called when the function object is built, not when the function is called. On the other hand, maybe it's intended to be part of the function's code, in which case it should be called only when the function itself is called. From steve+comp.lang.python at pearwood.info Tue Aug 21 13:22:24 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Aug 2012 17:22:24 GMT Subject: Why does dynamic doc string do not work? References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: <5033c3d0$0$6574$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Aug 2012 09:44:10 -0700, Miki Tebeka wrote: > Greetings, > >>>> class A: > ... '''a doc string''' > ... >>>> A.__doc__ > 'a doc string' >>>> class B: > ... '''a {} string'''.format('doc') ... >>>> B.__doc__ >>>> >>>> > Is there's a reason for this? Yes. Python only generates docstrings automatically from string literals, not arbitrary expressions. Arbitrary expressions are evaluated and then garbage collected, so: class B: '''a {} string'''.format('doc') is equivalent to: class B: __doc__ = None _tmp = '''a {} string'''.format('doc') del _tmp except that the name "_tmp" doesn't actually get used. -- Steven From goon12 at gmail.com Tue Aug 21 13:27:33 2012 From: goon12 at gmail.com (goon12) Date: Tue, 21 Aug 2012 10:27:33 -0700 (PDT) Subject: unittest - sort cases to be run In-Reply-To: References: Message-ID: On Tuesday, August 21, 2012 5:34:33 AM UTC-4, Terry Reedy wrote: > On 8/21/2012 5:09 AM, Kevin Zhang wrote: > > > Hi all, > > > > > > I want to sort the order of the unittest cases to be run, but found such > > > statement in Python doc, > > > "Note that the order in which the various test cases will be run is > > > determined by sorting the test function names with respect to the > > > built-in ordering for strings." > > > > > > s.addTest(BTest()) > > > s.addTest(ATest()) > > > TextTestRunner().run(ts) > > > > > > I need BTest() to be run prior to ATest(), is there any > > > natural/beautiful way to achieve this? Thanks, If BTest *has* to run prior to ATest, it could be a code smell. From goon12 at gmail.com Tue Aug 21 13:27:33 2012 From: goon12 at gmail.com (goon12) Date: Tue, 21 Aug 2012 10:27:33 -0700 (PDT) Subject: unittest - sort cases to be run In-Reply-To: References: Message-ID: On Tuesday, August 21, 2012 5:34:33 AM UTC-4, Terry Reedy wrote: > On 8/21/2012 5:09 AM, Kevin Zhang wrote: > > > Hi all, > > > > > > I want to sort the order of the unittest cases to be run, but found such > > > statement in Python doc, > > > "Note that the order in which the various test cases will be run is > > > determined by sorting the test function names with respect to the > > > built-in ordering for strings." > > > > > > s.addTest(BTest()) > > > s.addTest(ATest()) > > > TextTestRunner().run(ts) > > > > > > I need BTest() to be run prior to ATest(), is there any > > > natural/beautiful way to achieve this? Thanks, If BTest *has* to run prior to ATest, it could be a code smell. From d at davea.name Tue Aug 21 13:30:39 2012 From: d at davea.name (Dave Angel) Date: Tue, 21 Aug 2012 13:30:39 -0400 Subject: Why does dynamic doc string do not work? In-Reply-To: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: <5033C5BF.9080402@davea.name> On 08/21/2012 12:44 PM, Miki Tebeka wrote: > >>> class B: > ... '''a {} string'''.format('doc') > ... >>>> B.__doc__ >>>> > I wonder why the first B docstring is empty. Thanks, -- Miki According to some early documentation: "convenient initialization of the |__doc__| attribute of modules, classes and functions by placing a string literal by itself as the first statement in the suite. It must be a literal -- an expression yielding a string object is not accepted as a documentation string, since future tools may need to derive documentation from source by parsing." -- DaveA From miki.tebeka at gmail.com Tue Aug 21 13:40:04 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 21 Aug 2012 10:40:04 -0700 (PDT) Subject: Why does dynamic doc string do not work? In-Reply-To: References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: <3578881d-21f4-48c3-b1a0-3b647395b072@googlegroups.com> Thanks! > On 08/21/2012 12:44 PM, Miki Tebeka wrote: > > > > > >>> class B: > > > ... '''a {} string'''.format('doc') > > > ... > > >>>> B.__doc__ > > >>>> > > > I wonder why the first B docstring is empty. Thanks, -- Miki > > > > According to some early documentation: > > > > "convenient initialization of the |__doc__| attribute of modules, > > classes and functions by placing a string literal by itself as the first > > statement in the suite. It must be a literal -- an expression yielding a > > string object is not accepted as a documentation string, since future > > tools may need to derive documentation from source by parsing." > > > > -- > > > > DaveA From miki.tebeka at gmail.com Tue Aug 21 13:40:04 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 21 Aug 2012 10:40:04 -0700 (PDT) Subject: Why does dynamic doc string do not work? In-Reply-To: References: <3a128081-7f5d-4641-bc5d-8cffe64f5eee@googlegroups.com> Message-ID: <3578881d-21f4-48c3-b1a0-3b647395b072@googlegroups.com> Thanks! > On 08/21/2012 12:44 PM, Miki Tebeka wrote: > > > > > >>> class B: > > > ... '''a {} string'''.format('doc') > > > ... > > >>>> B.__doc__ > > >>>> > > > I wonder why the first B docstring is empty. Thanks, -- Miki > > > > According to some early documentation: > > > > "convenient initialization of the |__doc__| attribute of modules, > > classes and functions by placing a string literal by itself as the first > > statement in the suite. It must be a literal -- an expression yielding a > > string object is not accepted as a documentation string, since future > > tools may need to derive documentation from source by parsing." > > > > -- > > > > DaveA From __peter__ at web.de Tue Aug 21 14:00:26 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Aug 2012 20:00:26 +0200 Subject: unittest - sort cases to be run References: Message-ID: Kevin Zhang wrote: > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "Note that the order in which the various test cases will be run is > determined by sorting the test function names with respect to the built-in > ordering for strings." > > s.addTest(BTest()) > s.addTest(ATest()) > TextTestRunner().run(ts) > > I need BTest() to be run prior to ATest(), is there any natural/beautiful > way to achieve this? Thanks, Did you try the above? I think BTest *will* run before ATest. The sorting is performed by the TestLoader if there is one, i. e. if you don't build a test suite manually. If you *do* use a TestLoader you can still influence the sort order by defining a sortTestMethodsUsing static method. Here's a fairly complex example: [Ordering tests in a testsuite] http://mail.python.org/pipermail/python-list/2010-October/589058.html From johnroth1 at gmail.com Tue Aug 21 16:35:16 2012 From: johnroth1 at gmail.com (John Roth) Date: Tue, 21 Aug 2012 13:35:16 -0700 (PDT) Subject: Why doesn't Python remember the initial directory? In-Reply-To: References: Message-ID: On Sunday, August 19, 2012 7:57:46 PM UTC-6, kj wrote: > This means that no library code can ever count on, for example, > > being able to reliably find the path to the file that contains the > > definition of __main__. If you want to find that, look up __main__ in sys.modules and then look at the __file__ attribute. You need to be a bit careful with this; the import machinery was rewritten for the upcoming 3.3 release, and there were several changes to the module information. John Roth From drsalists at gmail.com Tue Aug 21 17:51:40 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 21 Aug 2012 21:51:40 +0000 Subject: Reimporting modules, and sandboxing? Message-ID: I know I've seen this discussed before, and I came away from observing the discussion thinking "Python doesn't do that very well...", but we have some people here who really would like to do this, and I need to better understand the pros and cons now. Is there a good way of reimporting an _independent_ set of CPython modules? I'm aware of these issues: http://stackoverflow.com/questions/1254370/reimport-a-module-in-python-while-interactive http://docs.python.org/library/functions.html#reload Are there more? Does sandboxing Python code help in some way? If yes, then what kind of sandbox? Note that this isn't sandboxing to prevent execution of malicious code, it's sandboxing to preserve reimportability, which may be an easier constraint to satisfy. The modules are friendly to each other, they aren't trying to break into each other, we just have to be careful that they don't step on each other's ability to reimport accidentally. Although I love Pypy, I don't think we'll be able to use Pypy sandboxes this time around. Also, if we need to reload 3 modules at once, can reload() reimport them atomically, as a set? Or would it need to do them one at a time? In short, we're talking about having some code that allows automatically re-importing changed modules. These modules will be pretty independent of each other in the Python world, but might interact with each other in the REST world even though they're written in CPython. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From pedro.larroy.lists at gmail.com Tue Aug 21 17:55:10 2012 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Tue, 21 Aug 2012 23:55:10 +0200 Subject: protobuf + pypy Message-ID: Hi Anyone knows if it's possible to use protobuffers with pypy? Seems there isn't much info on the web about this. Pedro. From breamoreboy at yahoo.co.uk Tue Aug 21 18:16:57 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 21 Aug 2012 23:16:57 +0100 Subject: protobuf + pypy In-Reply-To: References: Message-ID: On 21/08/2012 22:55, Pedro Larroy wrote: > Hi > > Anyone knows if it's possible to use protobuffers with pypy? Seems > there isn't much info on the web about this. > > Pedro. > Did you mean this, in which case there loads on the web http://code.google.com/p/protobuf/ ? -- Cheers. Mark Lawrence. From anonymous42311324 at gmail.com Tue Aug 21 21:36:50 2012 From: anonymous42311324 at gmail.com (Anonymous Group) Date: Tue, 21 Aug 2012 18:36:50 -0700 (PDT) Subject: Books? Message-ID: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> What books do you recomend for learning python? Preferably free and/or online. From roy at panix.com Tue Aug 21 21:39:53 2012 From: roy at panix.com (Roy Smith) Date: Tue, 21 Aug 2012 21:39:53 -0400 Subject: Books? References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: In article <5203ee16-5a80-4cd9-9434-ee2efb64515e at kg10g2000pbc.googlegroups.com>, Anonymous Group wrote: > What books do you recomend for learning python? Preferably free and/or > online. I would start with http://docs.python.org/tutorial/ From rosuav at gmail.com Tue Aug 21 22:04:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Aug 2012 12:04:09 +1000 Subject: Books? In-Reply-To: References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: On Wed, Aug 22, 2012 at 11:39 AM, Roy Smith wrote: > In article > <5203ee16-5a80-4cd9-9434-ee2efb64515e at kg10g2000pbc.googlegroups.com>, > Anonymous Group wrote: > >> What books do you recomend for learning python? Preferably free and/or >> online. > > I would start with http://docs.python.org/tutorial/ Agreed. And for anything beyond that, I would recommend the anonymous OP offer some more information, such as current programming skill level and languages known. But the tutorial is a good start regardless. ChrisA From anonymous42311324 at gmail.com Tue Aug 21 22:12:12 2012 From: anonymous42311324 at gmail.com (Anonymous Group) Date: Tue, 21 Aug 2012 19:12:12 -0700 (PDT) Subject: Books? References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: <5ff4ff35-e4ce-4908-8078-1bd88c173270@ou2g2000pbc.googlegroups.com> On Aug 21, 7:04?pm, Chris Angelico wrote: > On Wed, Aug 22, 2012 at 11:39 AM, Roy Smith wrote: > > In article > > <5203ee16-5a80-4cd9-9434-ee2efb645... at kg10g2000pbc.googlegroups.com>, > > ?Anonymous Group wrote: > > >> What books do you recomend for learning python? Preferably free and/or > >> online. > > > I would start withhttp://docs.python.org/tutorial/ > > Agreed. And for anything beyond that, I would recommend the anonymous > OP offer some more information, such as current programming skill > level and languages known. > > But the tutorial is a good start regardless. > > ChrisA Thanks From anonymous42311324 at gmail.com Tue Aug 21 22:12:14 2012 From: anonymous42311324 at gmail.com (Anonymous Group) Date: Tue, 21 Aug 2012 19:12:14 -0700 (PDT) Subject: Books? References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: On Aug 21, 6:39?pm, Roy Smith wrote: > In article > <5203ee16-5a80-4cd9-9434-ee2efb645... at kg10g2000pbc.googlegroups.com>, > ?Anonymous Group wrote: > > > What books do you recomend for learning python? Preferably free and/or > > online. > > I would start withhttp://docs.python.org/tutorial/ Thanks From humingqiang5262131 at gmail.com Tue Aug 21 22:57:34 2012 From: humingqiang5262131 at gmail.com (mingqiang hu) Date: Wed, 22 Aug 2012 10:57:34 +0800 Subject: asking Message-ID: can I use just one statement to figure out if substring ?a? ,"b" "c" are in string "adfbdfc" ? not use the statement like ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) ,because if I have lots of substring, this could sucks -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at feete.org Tue Aug 21 23:42:55 2012 From: ian at feete.org (Ian Foote) Date: Wed, 22 Aug 2012 04:42:55 +0100 Subject: asking In-Reply-To: References: Message-ID: <5034553F.4080904@feete.org> On 22/08/12 03:57, mingqiang hu wrote: > can I use just one statement to figure out if substring ?a? ,"b" "c" > are in string "adfbdfc" ? not use the statement like > > ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) > ,because if I have lots of substring, this could sucks This might not be the most efficient way, but: >>> set("abc") <= set("adfbdfc") True >>> set("abce") <= set("adfbdfc") False If you want to check for substrings longer than one character, this won't work. A solution then is to define a custom function: def all_in(string, substrings): for substring in substrings: if substring not in string: return False return True Ian From humingqiang5262131 at gmail.com Tue Aug 21 23:43:59 2012 From: humingqiang5262131 at gmail.com (mingqiang hu) Date: Wed, 22 Aug 2012 11:43:59 +0800 Subject: something about split()??? In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: why filter is bad when use lambda ?actually I think I can use lambda like this? filter(lambda x:x==None,"|",split("|")) On Wed, Aug 15, 2012 at 1:33 PM, Ramchandra Apte wrote: > filter is bad when you use lambda with it > there are (good) cases for filter > > > On 14 August 2012 22:39, Jean-Michel Pichavant wrote: > >> Ramchandra Apte wrote: >> >>> (Much) more Pythonic solution: >>> >>> filter(None,"|".split("|")) >>> >>> On 14 August 2012 15:14, Andreas Tawn >> andreas.tawn at ubisoft.**com >> wrote: >>> >>> > I have a question about the split function? surpose a = "|",and >>> when I use a.split("|") , I got the list >>> > ['"",""] ,but I want to get the empty list,what should I do ? >>> >>> Something like... >>> >>> >>> [x for x in "|".split("|") if x] >>> [] >>> >>> Cheers, >>> >>> Drea >>> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >>> >>> A pythonic answer would be bottom-posted :p >> >> JM >> >> >> PS : pylint raises a low warning about *filter* being non pythonic, >> http://pylint-messages.**wikidot.com/messages:w0141 >> "les go?ts et les couleurs ne se discutent pas" >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at feete.org Wed Aug 22 00:17:46 2012 From: ian at feete.org (Ian Foote) Date: Wed, 22 Aug 2012 05:17:46 +0100 Subject: asking In-Reply-To: <5034553F.4080904@feete.org> References: <5034553F.4080904@feete.org> Message-ID: <50345D6A.1080505@feete.org> Oops, hopefully this with indent correctly: def all_in(string, substrings): for substring in substrings: if substring not in string: return False return True From d at davea.name Wed Aug 22 01:17:21 2012 From: d at davea.name (Dave Angel) Date: Wed, 22 Aug 2012 01:17:21 -0400 Subject: asking In-Reply-To: <50345D6A.1080505@feete.org> References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> Message-ID: <50346B61.4020000@davea.name> On 08/22/2012 12:17 AM, Ian Foote wrote: > Oops, hopefully this with indent correctly: > > def all_in(string, substrings): > for substring in substrings: > if substring not in string: > return False > return True The POP's question was ambiguous (did he want to match any of the substrings, or all of the substrings), but his example code: ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) implements the opposite sense of what you have. So perhaps he'd want: def any_in(string, substrings): for substring in substrings: if substring in string: return True: return False -- DaveA From tjreedy at udel.edu Wed Aug 22 01:42:09 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Aug 2012 01:42:09 -0400 Subject: asking In-Reply-To: References: Message-ID: On 8/21/2012 10:57 PM, mingqiang hu wrote: > can I use just one statement to figure out if substring ?a? ,"b" "c" > are in string "adfbdfc" ? not use the statement like > > ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) > ,because if I have lots of substring, this could sucks >>> import re # single chars >>> print(re.search('[abc]', 'defgh')) None >>> print(re.search('[abc]', 'defgha')) <_sre.SRE_Match object at 0x0000000003251098> # multichar strings >>> print(re.search('ab|ha]', 'defgha')) None >>> print(re.search('ab|ha', 'defgha')) <_sre.SRE_Match object at 0x0000000003251098> -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 22 01:46:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Aug 2012 01:46:31 -0400 Subject: something about split()??? In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: On 8/21/2012 11:43 PM, mingqiang hu wrote: > why filter is bad when use lambda ? Inefficient, not 'bad'. Because the equivalent comprehension or generator expression does not require a function call. -- Terry Jan Reedy From wuwei23 at gmail.com Wed Aug 22 01:51:04 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 21 Aug 2012 22:51:04 -0700 (PDT) Subject: asking References: Message-ID: <224a0790-ecf8-4fac-bad0-7258e1b02444@j2g2000pbg.googlegroups.com> On 22/08/12 03:57, mingqiang hu wrote: > can I use just one statement to figure out if substring ?a? ,"b" "c" > are in string "adfbdfc" ? not use the statement like > ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) > ,because if I have lots of substring, this could sucks subs = ['a', 'b', 'c'] string = 'abcdef' def all_in(string, substrings): return all(map(string.__contains__, subs)) From sntshkmr60 at gmail.com Wed Aug 22 02:21:47 2012 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Wed, 22 Aug 2012 11:51:47 +0530 Subject: help me debug my "word capitalizer" script Message-ID: Here is the script I am using: from os import linesep from string import punctuation from sys import argv script, givenfile = argv with open(givenfile) as file: # List to store the capitalised lines. lines = [] for line in file: # Split words by spaces. words = line.split(' ') for i, word in enumerate(words): if len(word.strip(punctuation)) > 3: # Capitalise and replace words longer than 3 (without punctuation) words[i] = word.capitalize() # Join the capitalised words with spaces. lines.append(' '.join(words)) # Join the capitalised lines by the line separator capitalised = linesep.join(lines) # Optionally, write the capitalised words back to the file. print(capitalised) Purpose of the script: To capitalize the first letter of any word in a given file, leaving words which have 3 or less letters. Bugs: I know it has many bugs or/and it can be improved by cutting down the code, but my current focus is to fix this bug: 1. When I pass it any file, it does it stuff but inserts a blank line everytime it processes a new line. (Please notice that I don't want the output in an another file, I want it on screen). From bob.martin at excite.com Wed Aug 22 07:25:17 2012 From: bob.martin at excite.com (Bob Martin) Date: Wed, 22 Aug 2012 07:25:17 BST Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) References: Message-ID: in 679182 20120821 181439 Dennis Lee Bieber wrote: >On Tue, 21 Aug 2012 08:07:33 +0200, Alex Strickland >declaimed the following in gmane.comp.python.general: > >> On 2012/08/17 12:42 AM, Madison May wrote: >> >> > As a lurker, I agree completely with Chris's sentiments. >> >> I too, but I'd prefer something top-posted than have to skip through 38 >> pages of quoted e-mail to get to a (generally) 1 liner at the bottom. > >Doesn't help me though... Agent shows quoted material as blue, fresh >text as black. > >I tend to not see a one-liner at the top (since it is next to the >attribution line) and if the rest of the page is all blue text I hit >page down... and down, down, down... looking for black text... Then end >up going "Wha', where's the new stuff?" and having to scroll back up to >find a one-liner cuddling up with the attribution line. Yep, and the only solution is for everyone to top-post. From michael.poeltl at univie.ac.at Wed Aug 22 02:57:54 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Wed, 22 Aug 2012 08:57:54 +0200 Subject: Books? In-Reply-To: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: <20120822065754.GB1262@terra.cms.at> I would recommend "Dive into Python3" just goole-search "dive into python3" filetype:pdf and you got it! regards Michael * Anonymous Group [2012-08-22 03:40]: > What books do you recomend for learning python? Preferably free and/or > online. > -- > 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 ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From humingqiang5262131 at gmail.com Wed Aug 22 03:17:24 2012 From: humingqiang5262131 at gmail.com (mingqiang hu) Date: Wed, 22 Aug 2012 15:17:24 +0800 Subject: asking In-Reply-To: <50346B61.4020000@davea.name> References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> <50346B61.4020000@davea.name> Message-ID: I mean any of "a","b","c" in string "adfbdfc" makes the statement true,can I not use a function? suppose I got lots of substring let's say s1="a",s2="b",s3="c" ...,not wrap them as a tuple or a list , just make the statement as simple as possible to check if any of the value is the substring of S="fasfasdfgbefve". On Wed, Aug 22, 2012 at 1:17 PM, Dave Angel wrote: > On 08/22/2012 12:17 AM, Ian Foote wrote: > > Oops, hopefully this with indent correctly: > > > > def all_in(string, substrings): > > for substring in substrings: > > if substring not in string: > > return False > > return True > > The POP's question was ambiguous (did he want to match any of the > substrings, or all of the substrings), but his example code: > > > ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) > > implements the opposite sense of what you have. So perhaps he'd want: > > > def any_in(string, substrings): > for substring in substrings: > if substring in string: > return True: > return False > > > -- > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From guillaume.comte10 at gmail.com Wed Aug 22 03:29:37 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Wed, 22 Aug 2012 00:29:37 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> Message-ID: <4416da62-a6ba-4264-b33d-6015f9b2e582@googlegroups.com> Le mercredi 22 ao?t 2012 04:10:43 UTC+2, Dennis Lee Bieber a ?crit?: > On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte > > declaimed the following in > > gmane.comp.python.general: > > > > A later follow-up > > > Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... > > > > > > > Since .bind() is used to set up a /listener/, the network stack > > (LINK layer) probably has to be tied to the IP address; that is, a valid > > "source" address needs to be supplied to .bind. > Do you mean that an alias is not a valid source address? Because ping.c can do it... I've also tried changing the port to 3333 or 8080 but the same error happens. > > > > > > But when I try to set a source address, I still get the same error message... > > > > > > Does anyone know how I could build the IP header (I don't even know if it can be the solution but it's worth a try...)? > > > > Based upon http://linux.die.net/man/7/raw "Raw sockets allow new > > IPv4 protocols to be implemented in user space. A raw socket receives or > > sends the raw datagram not including link level headers. " implies that > > you need to build the entire IP packet for your ICMP message... That > > means you do NOT use socket methods to set fields -- you'll probably > > have to use something like the struct module to lay out the entire IP > > packet /including/ header contents, and then pass that as-is to the > > socket. > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ From guillaume.comte10 at gmail.com Wed Aug 22 03:29:37 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Wed, 22 Aug 2012 00:29:37 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> Message-ID: <4416da62-a6ba-4264-b33d-6015f9b2e582@googlegroups.com> Le mercredi 22 ao?t 2012 04:10:43 UTC+2, Dennis Lee Bieber a ?crit?: > On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte > > declaimed the following in > > gmane.comp.python.general: > > > > A later follow-up > > > Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... > > > > > > > Since .bind() is used to set up a /listener/, the network stack > > (LINK layer) probably has to be tied to the IP address; that is, a valid > > "source" address needs to be supplied to .bind. > Do you mean that an alias is not a valid source address? Because ping.c can do it... I've also tried changing the port to 3333 or 8080 but the same error happens. > > > > > > But when I try to set a source address, I still get the same error message... > > > > > > Does anyone know how I could build the IP header (I don't even know if it can be the solution but it's worth a try...)? > > > > Based upon http://linux.die.net/man/7/raw "Raw sockets allow new > > IPv4 protocols to be implemented in user space. A raw socket receives or > > sends the raw datagram not including link level headers. " implies that > > you need to build the entire IP packet for your ICMP message... That > > means you do NOT use socket methods to set fields -- you'll probably > > have to use something like the struct module to lay out the entire IP > > packet /including/ header contents, and then pass that as-is to the > > socket. > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ From breamoreboy at yahoo.co.uk Wed Aug 22 03:30:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 08:30:30 +0100 Subject: something about split()??? In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: On 22/08/2012 06:46, Terry Reedy wrote: > On 8/21/2012 11:43 PM, mingqiang hu wrote: >> why filter is bad when use lambda ? > > Inefficient, not 'bad'. Because the equivalent comprehension or > generator expression does not require a function call. > A case of premature optimisation? :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Aug 22 03:35:58 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 08:35:58 +0100 Subject: Top-posting &c. (was Re: [ANNC] pybotwar-0.8) In-Reply-To: References: Message-ID: On 22/08/2012 07:25, Bob Martin wrote: > in 679182 20120821 181439 Dennis Lee Bieber wrote: >> On Tue, 21 Aug 2012 08:07:33 +0200, Alex Strickland >> declaimed the following in gmane.comp.python.general: >> >>> On 2012/08/17 12:42 AM, Madison May wrote: >>> >>>> As a lurker, I agree completely with Chris's sentiments. >>> >>> I too, but I'd prefer something top-posted than have to skip through 38 >>> pages of quoted e-mail to get to a (generally) 1 liner at the bottom. >> >> Doesn't help me though... Agent shows quoted material as blue, fresh >> text as black. >> >> I tend to not see a one-liner at the top (since it is next to the >> attribution line) and if the rest of the page is all blue text I hit >> page down... and down, down, down... looking for black text... Then end >> up going "Wha', where's the new stuff?" and having to scroll back up to >> find a one-liner cuddling up with the attribution line. > > Yep, and the only solution is for everyone to top-post. > The only solution is for people to use common sense. At least one snag is that Voltaire said common sense is not so common. -- Cheers. Mark Lawrence. From andipersti at gmail.com Wed Aug 22 03:42:23 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Wed, 22 Aug 2012 09:42:23 +0200 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <50348D5F.3070402@gmail.com> On 22.08.2012 08:21, Santosh Kumar wrote: > with open(givenfile) as file: > # List to store the capitalised lines. > lines = [] > for line in file: > # Split words by spaces. > words = line.split(' ') The last element in your "words" list will still have a newline character appended to it. You could probably use line.split(). See also the docs: http://docs.python.org/py3k/library/stdtypes.html#str.split > for i, word in enumerate(words): > if len(word.strip(punctuation)) > 3: > # Capitalise and replace words longer than 3 (without > punctuation) > words[i] = word.capitalize() > # Join the capitalised words with spaces. > lines.append(' '.join(words)) This rebuilds the line including a newline character at the end. > # Join the capitalised lines by the line separator > capitalised = linesep.join(lines) Because you haven't removed the newline character from each line, joining them with "linesep" introduces a second newline character after each line. Bye, Andreas From rosuav at gmail.com Wed Aug 22 03:43:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Aug 2012 17:43:33 +1000 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 4:21 PM, Santosh Kumar wrote: > Purpose of the script: > To capitalize the first letter of any word in a given file, leaving > words which have 3 or less letters. > > Bugs: > I know it has many bugs or/and it can be improved by cutting down the > code, but my current focus is to fix this bug: > 1. When I pass it any file, it does it stuff but inserts a blank > line everytime it processes a new line. (Please notice that I don't > want the output in an another file, I want it on screen). Firstly, THANK YOU for making your question so easy to work with! I'll start with a quick answer to your immediate question, then add some other comments about the code. If you print(repr(words[-1])) somewhere in there, you'll notice that the lines you're iterating over actually have a \n at the end. That's where your duplication is coming from; you're adding a line separator, but one's already being added for you. Since you're working in text, you can just let \n be your line separator; input and output should both translate as required. Probably the easiest fix is to simply ignore os.linesep and keep the newlines on the last words of the lines; all you care about is the beginning of the word. However, this might raise another odd issue, in that a two-letter word at the end of a line would be capitalized. This can be fixed by adding '\n' to the set of characters that you strip. Alternatively, trim off the newlines and then join then back in again. Not difficult and I'm sure you'll see where that needs to be done :) So! Unsolicited comments follow. > Here is the script I am using: > > from os import linesep > from string import punctuation > from sys import argv I would be inclined instead to simply "import os" "import string" "import sys" and then use the qualified names. It's not something you're doing a lot of - each of these is used in precisely one place in the script - so the adorned names aren't going to get much in the way. > script, givenfile = argv > > with open(givenfile) as file: Presumably you don't need a full-on arg parser. I'd actually just inline this as "open(argv[1])" rather than unpack into separate variables; that way, if the user provides more args, the extras will be ignored (instead of throwing an exception). Something you may want to look into at some point is list comprehensions. Whenever you have a loop that iterates over a list and builds another list, consider a more functional notation. For instance, your inner loop could become: words = [(word.capitalize if len(word.strip(punctuation)) > 3 else word) for word in line.split(' ')] The parentheses are optional, but may help you see how the interpreter parses that. Code looks pretty good though, and again, a big thank you for making your question so clear :) It's a pleasure to help you. Chris Angelico From breamoreboy at yahoo.co.uk Wed Aug 22 03:43:58 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 08:43:58 +0100 Subject: Books? In-Reply-To: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: On 22/08/2012 02:36, Anonymous Group wrote: > What books do you recomend for learning python? Preferably free and/or > online. > Search for the Alan Gauld tutorial. I've never used it myself, but OTOH I've never heard anybody complain about it!!! As someone else has already mentioned it, I'd highly recommend Dive Into Python -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Aug 22 04:13:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 09:13:30 +0100 Subject: Reimporting modules, and sandboxing? In-Reply-To: References: Message-ID: On 21/08/2012 22:51, Dan Stromberg wrote: > I know I've seen this discussed before, and I came away from observing the > discussion thinking "Python doesn't do that very well...", but we have some > people here who really would like to do this, and I need to better > understand the pros and cons now. > > Is there a good way of reimporting an _independent_ set of CPython modules? > > I'm aware of these issues: > http://stackoverflow.com/questions/1254370/reimport-a-module-in-python-while-interactive > http://docs.python.org/library/functions.html#reload > > Are there more? > > Does sandboxing Python code help in some way? If yes, then what kind of > sandbox? Note that this isn't sandboxing to prevent execution of malicious > code, it's sandboxing to preserve reimportability, which may be an easier > constraint to satisfy. The modules are friendly to each other, they aren't > trying to break into each other, we just have to be careful that they don't > step on each other's ability to reimport accidentally. > > Although I love Pypy, I don't think we'll be able to use Pypy sandboxes > this time around. > > Also, if we need to reload 3 modules at once, can reload() reimport them > atomically, as a set? Or would it need to do them one at a time? > > In short, we're talking about having some code that allows automatically > re-importing changed modules. These modules will be pretty independent of > each other in the Python world, but might interact with each other in the > REST world even though they're written in CPython. > > Thanks! > > > As there are no other replies, and my apologies if I'm teaching granny to suck eggs, but there are a load of threads on python-dev discussing sandboxing. Whether there are any tie ins with importing is for me not to know and for you to find out :) I'll also wonder out loud if the reworking of the import mechanism for 3.3 has any impact at all on your question. -- Cheers. Mark Lawrence. From hansmu at xs4all.nl Wed Aug 22 04:20:57 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 22 Aug 2012 10:20:57 +0200 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <50349669$0$6846$e4fe514c@news2.news.xs4all.nl> On 22/08/12 08:21:47, Santosh Kumar wrote: > Here is the script I am using: > > from os import linesep > from string import punctuation > from sys import argv > > script, givenfile = argv > > with open(givenfile) as file: > # List to store the capitalised lines. > lines = [] > for line in file: > # Split words by spaces. > words = line.split(' ') > for i, word in enumerate(words): > if len(word.strip(punctuation)) > 3: > # Capitalise and replace words longer than 3 (without > punctuation) > words[i] = word.capitalize() > # Join the capitalised words with spaces. > lines.append(' '.join(words)) > # Join the capitalised lines by the line separator > capitalised = linesep.join(lines) > # Optionally, write the capitalised words back to the file. > > print(capitalised) > > > Purpose of the script: > To capitalize the first letter of any word in a given file, leaving > words which have 3 or less letters. > > Bugs: > I know it has many bugs or/and it can be improved by cutting down the > code, but my current focus is to fix this bug: > 1. When I pass it any file, it does it stuff but inserts a blank > line every time it processes a new line. (Please notice that I don't > want the output in an another file, I want it on screen). The lines you read from your input file end in a line separator. When you print them, the 'print' command adds another line separator. This results in two line separators in a row, in other words, a blank line. The best way to solve this is usually to remove the line separator right after you've read in the line. You could do that by inserting after line 10: line = line.rstrip() That will remove all whitespace characters (spaces, tabs, carriage returns, newlines) from the end of the line. Alternatively, if you want to remove only the line separator, you could do: if line.endswith(linesep): line = line[:-len(linesep)] The 'if' command is only necessary for the last line, which may or may not end in a linesep. All earlier lines are guaranteed to end with a linesep. Hope this helps, -- HansM From d at davea.name Wed Aug 22 04:36:49 2012 From: d at davea.name (Dave Angel) Date: Wed, 22 Aug 2012 04:36:49 -0400 Subject: asking In-Reply-To: References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> <50346B61.4020000@davea.name> Message-ID: <50349A21.3030409@davea.name> On 08/22/2012 03:17 AM, mingqiang hu wrote: > I mean any of "a","b","c" in string "adfbdfc" makes the statement true,can > I not use a function? suppose I got lots of substring let's say > s1="a",s2="b",s3="c" ...,not wrap them as a tuple or a list , just make the > statement as simple as possible to check if any of the value is the > substring of S="fasfasdfgbefve". > You top-posted. And you're not bothering to really read the responses you're getting. Your problem statement is still ambiguous, and you're really asking for someone to write a custom language for you. So I'm done here. -- DaveA From guillaume.comte10 at gmail.com Wed Aug 22 04:43:19 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Wed, 22 Aug 2012 01:43:19 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: Message-ID: <32176aa4-4b9d-44a6-8729-958e3c251955@googlegroups.com> I've managed to build the IP header. I've put the source and destination addresses in this header but it doesn't change the real source address... I'm trying to read the ping source code but I'm lost... From hansmu at xs4all.nl Wed Aug 22 05:03:11 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 22 Aug 2012 11:03:11 +0200 Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> Message-ID: <5034a050$0$6904$e4fe514c@news2.news.xs4all.nl> On 22/08/12 09:29:37, Guillaume Comte wrote: > Le mercredi 22 ao?t 2012 04:10:43 UTC+2, Dennis Lee Bieber a ?crit : >> On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte >> declaimed the following in >> gmane.comp.python.general: >> A later follow-up >>> Unfortunately, my_socket.bind((src_addr, 1)) doesn't work. I get the >>> error message: "socket.error: [Errno 49] Can't assign requested address"... >> Since .bind() is used to set up a /listener/, the network stack Not necessarily. That is, a listener is normally bound to a specific port, since otherwise the client doesn't know what port to connect to (unless you provide that factoid on another port). But nothing prevents a client from binding its socket to a specific port number. These days, that doesn't buy you much, but in the old days, some services would only talk to clients using privileged port numbers (<1024). >> (LINK layer) probably has to be tied to the IP address; that is, a valid >> "source" address needs to be supplied to .bind. > Do you mean that an alias is not a valid source address? Because ping.c can do it... > I've also tried changing the port to 3333 or 8080 but the same error happens. On my laptop, 0 appears to be the only port number that bind accepts for a raw socket. Other numbers I tried all raise "socket.error: [Errno 49] Can't assign requested address". But this might depend on your OS. What OS are you using? Hope this helps, -- HansM From guillaume.comte10 at gmail.com Wed Aug 22 05:21:39 2012 From: guillaume.comte10 at gmail.com (Guillaume Comte) Date: Wed, 22 Aug 2012 02:21:39 -0700 (PDT) Subject: How to set the socket type and the protocol of a socket using create_connection? In-Reply-To: <5034a050$0$6904$e4fe514c@news2.news.xs4all.nl> References: <4edc5ccb-9121-47b0-8ad4-2bf106735532@googlegroups.com> <50323dc7$0$6841$e4fe514c@news2.news.xs4all.nl> <7e4fbbae-a70f-42fc-82c9-a03f1a118136@googlegroups.com> <5034a050$0$6904$e4fe514c@news2.news.xs4all.nl> Message-ID: <5cb21fea-1550-4c4f-8157-8193c4ebd9d7@googlegroups.com> Le mercredi 22 ao?t 2012 11:03:11 UTC+2, Hans Mulder a ?crit?: > > On my laptop, 0 appears to be the only port number that bind accepts > > for a raw socket. Other numbers I tried all raise "socket.error: > > [Errno 49] Can't assign requested address". > > > > But this might depend on your OS. What OS are you using? > I'm using FreeBSD 7.3 From wuwei23 at gmail.com Wed Aug 22 05:42:16 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 22 Aug 2012 02:42:16 -0700 (PDT) Subject: asking References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> <50346B61.4020000@davea.name> Message-ID: <96c30ade-3963-4bf3-9729-36e4d1fc7ca8@wi5g2000pbc.googlegroups.com> On 08/22/2012 03:17 AM, mingqiang hu wrote: > I mean any of "a","b","c" in string "adfbdfc" ?makes the statement true,can > I not use a function? any(map(string.__contains__, substrings)) From jamie at kode5.net Wed Aug 22 06:25:03 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Wed, 22 Aug 2012 11:25:03 +0100 Subject: Books? In-Reply-To: References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: <20120822102503.GA90966@kontrol.kode5.net> [ Mark Lawrence wrote on Wed 22.Aug'12 at 8:43:58 +0100 ] > On 22/08/2012 02:36, Anonymous Group wrote: > > What books do you recomend for learning python? Preferably free and/or > > online. > > > > Search for the Alan Gauld tutorial. I've never used it myself, but OTOH > I've never heard anybody complain about it!!! > > As someone else has already mentioned it, I'd highly recommend Dive Into > Python I bought "Beginning Python - Using Python 2.6 and 3.1" by James Payne, published by Wrox www.wrox.com. I've found it quite good so far, it's pretty comprehensive. From kamil.kuduk at gmail.com Wed Aug 22 06:28:18 2012 From: kamil.kuduk at gmail.com (Kamil Kuduk) Date: Wed, 22 Aug 2012 12:28:18 +0200 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: > Purpose of the script: > To capitalize the first letter of any word in a given file, leaving > words which have 3 or less letters. First or all? If first and this is the only purpose of the script you can easily use sed: less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" From rosuav at gmail.com Wed Aug 22 06:41:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Aug 2012 20:41:42 +1000 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 8:28 PM, Kamil Kuduk wrote: >> Purpose of the script: >> To capitalize the first letter of any word in a given file, leaving >> words which have 3 or less letters. > > First or all? If first and this is the only purpose of the script you > can easily use sed: > less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" Why less? Why not just redirect input? Though, this isn't really on topic for Python. ChrisA From ulrich.eckhardt at dominolaser.com Wed Aug 22 06:56:17 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 22 Aug 2012 12:56:17 +0200 Subject: color coding for numbers In-Reply-To: References: <57f81534-03af-475f-91c1-aee554e71ab6@googlegroups.com> Message-ID: Am 21.08.2012 19:07, schrieb DJC: > On 21/08/12 12:55, Ulrich Eckhardt wrote: >> Am 21.08.2012 10:38, schrieb namenobodywants at gmail.com: >>> what is the best way >> >> Define "best" before asking such questions. ;) > > Sorry, that one must have been unclear. The point was that when asking for a _best_ solution to a problem, the criteria for evaluating a solution must be known. If you don't define them and they are not implicit, there is no possible answer to the question. Uli From python.list at tim.thechases.com Wed Aug 22 06:59:01 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 22 Aug 2012 05:59:01 -0500 Subject: asking In-Reply-To: <96c30ade-3963-4bf3-9729-36e4d1fc7ca8@wi5g2000pbc.googlegroups.com> References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> <50346B61.4020000@davea.name> <96c30ade-3963-4bf3-9729-36e4d1fc7ca8@wi5g2000pbc.googlegroups.com> Message-ID: <5034BB75.7030801@tim.thechases.com> On 08/22/12 04:42, alex23 wrote: > On 08/22/2012 03:17 AM, mingqiang hu wrote: >> I mean any of "a","b","c" in string "adfbdfc" makes the statement true,can >> I not use a function? > > any(map(string.__contains__, substrings)) As map()/reduce() vs. list-comprehension discussions are going on in another thread, I find it more readable to write any(letter in "abfbdfc" for letter in "abc") or all(letter in "abfbdfc" for letter in "abc") depending on what the OP wants (a matter clarity which the OP seems to be a little vague on). Alternatively, if they're actual sub-strings rather than just letters, it can be written as substrings = [ "abf", "bfb", "fbd", ] target = "abfdbfc" any(substring in target for substring in substrings) all(substring in target for substring in substrings) which is about as close to English as it gets. If the target is exceptionally long, I'd be tempted to go with Terry's suggestion of a regular expression which should be able to do the checks in one search pass of the target haystack. -tkc From kamil.kuduk at gmail.com Wed Aug 22 07:06:06 2012 From: kamil.kuduk at gmail.com (Kamil Kuduk) Date: Wed, 22 Aug 2012 13:06:06 +0200 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 12:41 PM, Chris Angelico wrote: > Why less? Why not just redirect input? Yeah, my bad, I somehow used to do it, for grep too, and I know that this is slower > Though, this isn't really on topic for Python. I would still go with regexp, something like: with open('myfile.txt', 'rw) as file: print "".join(re.sub(r'\w{3,}', lambda(match): match.group(0).title(), line) for line in file) From sajuptpm at gmail.com Wed Aug 22 08:03:48 2012 From: sajuptpm at gmail.com (sajuptpm) Date: Wed, 22 Aug 2012 05:03:48 -0700 (PDT) Subject: psphere: how to make thread safe Message-ID: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> Hi, psphere: Python interface for the VMware vSphere Web Services SDK I already developed an app using https://bitbucket.org/jkinred/psphere. But getting lot of errors since psphere is not thread safe (I think). So i wrote couple of scripts to test it (See attached files) and found that caching mechanism used by psphere is not thread safe. Could someone please give me some suggestion to make it thread safe. =======Test Code ======== import psphere from psphere.client import Client from psphere.managedobjects import HostSystem, VirtualMachine, ComputeResource client = Client("192.168.0.114", "root", "vmware1") ##vCenter print "\nSucessfully connected to vCenter.\n" from threading import Thread def myfunc(i): host1 = HostSystem.get(client, name="192.168.0.134") host2 = HostSystem.get(client, name="192.168.0.113") print "----i------",i while True: #host1.update(properties=["config", "vm"]) #host2.update(properties=["config", "vm"]) c = type(host1.config.network) v = type(host2.config.network) for vm in host1.vm: k = vm.config.template for vm in host2.vm: p = vm.config.template for i in range(10): t = Thread(target=myfunc, args=(i,)) t.start() """ OUTPUT ======= Sucessfully connected to vCenter. ----i------ 1 ----i------ 3 ----i------ 5 ----i------ 0 ----i------ 4 ----i------ 2----i------ 7 ----i------ 9 ----i------ 6 ----i------ 8 Exception in thread Thread-4: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "vcenter_test1.py", line 19, in myfunc k = vm.config.template File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 79, in __get__ value = self.fget(inst) File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/managedobjects.py", line 1236, in config return self._get_dataobject("config", False) File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 116, in _get_dataobject return self._cache[name][0] KeyError: 'config' Exception in thread Thread-6: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) File "vcenter_test1.py", line 17, in myfunc v = type(host2.config.network) AttributeError: VirtualMachineConfigInfo instance has no attribute 'network' """ From sntshkmr60 at gmail.com Wed Aug 22 09:00:59 2012 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Wed, 22 Aug 2012 18:30:59 +0530 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: OK! The bug one fixed. Thanks to Andreas Perstinger. Let's move to Bug #2: 2. How do I escape the words that are already in uppercase? For example: The input file has this: NASA The script changes this to: Nasa Is it possible to make this script look at a word, see if its first character is capitalized, if capitalized then skip that word. If not do the processing? I don't wan to use regex? Do I need it? From steve+comp.lang.python at pearwood.info Wed Aug 22 09:56:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Aug 2012 13:56:00 GMT Subject: asking References: <5034553F.4080904@feete.org> <50345D6A.1080505@feete.org> <50346B61.4020000@davea.name> <96c30ade-3963-4bf3-9729-36e4d1fc7ca8@wi5g2000pbc.googlegroups.com> Message-ID: <5034e4f0$0$6574$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Aug 2012 02:42:16 -0700, alex23 wrote: > On 08/22/2012 03:17 AM, mingqiang hu wrote: >> I mean any of "a","b","c" in string "adfbdfc" ?makes the statement >> true,can I not use a function? > > any(map(string.__contains__, substrings)) Nice. However, be aware that in Python 2, map() is eager and produces a full list ahead of time. In Python 3, map() is lazy and only produces results as needed. Since any returns as soon as it sees a true value, Python 3 can be significantly faster here under some circumstances. For example, consider: string = "a"*10000000 substrings = "abcdefghijklmnopqrstuvwxyz" map(string.__contains__, substrings) in Python 2 produces a list of 26 values: [True, False, False, False, False, ..., False] up front, before passing that list to any() which stops as soon as it sees the first value. Generating those 25 False values was a waste of time. In Python 3, map() produces a lazy iterator object that doesn't calculate the values until required. So map(string.__contains__, substrings) doesn't do anything straight away. It waits for any() to request a value, then returns True. any() then immediately returns, and the other 25 False values never get calculated. In Python 2, you can use itertools.imap for a lazy version. In Python 3, you can use list(map( ... )) for an eager version. Here is a version which is lazy in both Python 2 and 3. I expect it to be more or less equally as efficient, and I find it easier to read: any(sub in string for sub in substrings) There's also an all() function that works similarly to any(), except that it stops as soon as it sees a false value. -- Steven From hubert.holin at free.fr Wed Aug 22 10:03:38 2012 From: hubert.holin at free.fr (Hubert Holin) Date: Wed, 22 Aug 2012 07:03:38 -0700 (PDT) Subject: xlrd 0.8.0 released! In-Reply-To: <501944E4.2090902@simplistix.co.uk> References: <501944E4.2090902@simplistix.co.uk> Message-ID: <2af06b96-21cd-4646-a433-fab4dadfb8b0@googlegroups.com> La D?fense, le 22/08/2012 Hi Congratulations for the work well done, and thanks for the help xlrd brings to my work. I would like to keep up with the development but would like to know which is the repo to follow. The Python-Excel website points to https://github.com/python-excel/xlrd, but that one does not have a 0.8.0 tag (or at least did not have one when I looked a few days ago, and I unfortunately can't check now, from work). Merci Hubert Holin Le mercredi 1 ao?t 2012 17:01:56 UTC+2, Chris Withers a ?crit : > > Hi All, > > I'm pleased to announce the release of xlrd 0.8.0: > > http://pypi.python.org/pypi/xlrd/0.8.0 > > This release finally lands the support for both .xls and .xlsx files. > Many thanks to John Machin for all his work on making this happen. > Opening of .xlsx files is seamless, just use xlrd as you did before and > it all should "just work". > > xlrd 0.8.0 is also the first release that that targets Python 2.6 and > 2.7, but no Python 3 just yet. Python 2.5 and below may work but are not > supported. If you need to use Python 2.5 or earlier, please stick to > xlrd 0.7.x. > > Speaking of xlrd 0.7.x, that's now in "requested maintenance only" mode > ;-) That means, if possible, use 0.8.x. If you have a really good reason > for sticking with 0.7.x, and you find a bug that you can't work around, > then please make this clear on the python... at googlegroups.comand > we'll see what we can do. > > If you find any problems, please ask about them on the list, or submit > an issue on GitHub: > > https://github.com/python-excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 22 10:04:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Aug 2012 14:04:13 GMT Subject: Books? References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: <5034e6dd$0$6574$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Aug 2012 18:36:50 -0700, Anonymous Group wrote: > What books do you recomend for learning python? Preferably free and/or > online. Completely by coincidence, I have just discovered, and I mean *literally* just a few minutes ago, this book: http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-30292-3 http://codingcat.com/knjige/python/A%20Primer%20on%20Scientific%20Programming%20with%20Python.pdf I wish it had existed when I was a beginner! I haven't read the whole thing, but dammit it looks like exactly the sort of book I would have adored as a newbie. (Your mileage may vary.) -- Steven From shaun.wiseman91 at gmail.com Wed Aug 22 10:13:34 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Wed, 22 Aug 2012 07:13:34 -0700 (PDT) Subject: Objects in Python Message-ID: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> I'm having an issue its my first time using python and i set up a class one of the methods is supposed to return a string but instead returns: > Im very new to python and the object orientated feature doesnt seem to be as well put together as Java. Can anyone help with this problem? From joel.goldstick at gmail.com Wed Aug 22 10:29:09 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 22 Aug 2012 10:29:09 -0400 Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 9:00 AM, Santosh Kumar wrote: > OK! The bug one fixed. Thanks to Andreas Perstinger. > > Let's move to Bug #2: > 2. How do I escape the words that are already in uppercase? For example: > > The input file has this: > NASA > > The script changes this to: > Nasa > > Is it possible to make this script look at a word, see if its first > character is capitalized, if capitalized then skip that word. If not > do the processing? I don't wan to use regex? Do I need it? > -- > http://mail.python.org/mailman/listinfo/python-list Go into your python shell and type help(str) or lookup the documentation on the python site about strings http://docs.python.org/library/string.html There are methods to tell if a word is all caps, or if the first letter is capitalized -- Joel Goldstick From joel.goldstick at gmail.com Wed Aug 22 10:31:09 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 22 Aug 2012 10:31:09 -0400 Subject: Objects in Python In-Reply-To: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On Wed, Aug 22, 2012 at 10:13 AM, shaun wrote: > I'm having an issue its my first time using python and i set up a class one of the methods is supposed to return a string but instead returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem to be as well put together as Java. Can anyone help with this problem? > -- > http://mail.python.org/mailman/listinfo/python-list It looks like you didn't add parens to the end of your call. Show us your code. with the traceback -- Joel Goldstick From jpiitula at ling.helsinki.fi Wed Aug 22 10:31:52 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 22 Aug 2012 17:31:52 +0300 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: shaun writes: > I'm having an issue its my first time using python and i set up a > class one of the methods is supposed to return a string but instead > returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem > to be as well put together as Java. Can anyone help with this > problem? I bet you are trying to call the method, returnString, without the parentheses that enclose the parameters (and without any @property stuff in the class). >>> Para('dox').myWev > >>> Para('dox').myWev() 'dox' From chris at python.org Wed Aug 22 10:33:11 2012 From: chris at python.org (Chris Withers) Date: Wed, 22 Aug 2012 15:33:11 +0100 Subject: xlrd 0.8.0 released! In-Reply-To: <2af06b96-21cd-4646-a433-fab4dadfb8b0@googlegroups.com> References: <501944E4.2090902@simplistix.co.uk> <2af06b96-21cd-4646-a433-fab4dadfb8b0@googlegroups.com> Message-ID: <5034EDA7.6070301@python.org> On 22/08/2012 15:03, Hubert Holin wrote: > I would like to keep up with the development but would like to know > which is the repo to follow. The Python-Excel website points to > https://github.com/python-excel/xlrd, but that one does not have a 0.8.0 > tag (or at least did not have one when I looked a few days ago, and I > unfortunately can't check now, from work). Oops, I was very bad... not only did I forget to push the tag (it's annoying that you have to do a "git push --tags" to get tasg pushed) but I actually forgot to commit the final change that stamped on the 0.8.0 version number :-S Fixed and pushed now, thanks for noticing :-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From vs at it.uu.se Wed Aug 22 10:34:40 2012 From: vs at it.uu.se (Virgil Stokes) Date: Wed, 22 Aug 2012 16:34:40 +0200 Subject: Books? In-Reply-To: <5034e6dd$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> <5034e6dd$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5034EE00.7080909@it.uu.se> On 22-Aug-2012 16:04, Steven D'Aprano wrote: > On Tue, 21 Aug 2012 18:36:50 -0700, Anonymous Group wrote: > >> What books do you recomend for learning python? Preferably free and/or >> online. > Completely by coincidence, I have just discovered, and I mean *literally* > just a few minutes ago, this book: > > http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-30292-3 > > http://codingcat.com/knjige/python/A%20Primer%20on%20Scientific%20Programming%20with%20Python.pdf > > > I wish it had existed when I was a beginner! I haven't read the whole > thing, but dammit it looks like exactly the sort of book I would have > adored as a newbie. (Your mileage may vary.) > > > I second this --- this is a very good book IMHO. I have the first edition (2009) and have found it very useful. Good tip! From __peter__ at web.de Wed Aug 22 10:36:00 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Aug 2012 16:36 +0200 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: shaun wrote: > I'm having an issue its my first time using python and i set up a class > one of the methods is supposed to return a string but instead returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem to be > as well put together as Java. It's definitely too early for you to draw conclusions ;) > Can anyone help with this problem? You have successfully created a bound method, now you need to invoke it: >>> class Param(object): ... def returnString(self): ... return "hello" ... >>> p = Param() >>> p.returnString > >>> p.returnString() 'hello' Unlike some other langages Python does not implicitly invoke functions or methods. That makes it easy to pass them around like any other object. From puntabluda at gmail.com Wed Aug 22 10:46:04 2012 From: puntabluda at gmail.com (Rebelo) Date: Wed, 22 Aug 2012 07:46:04 -0700 (PDT) Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> > Let's move to Bug #2: > > 2. How do I escape the words that are already in uppercase? For example: > > > > The input file has this: > > NASA > > > > The script changes this to: > > Nasa > > > > Is it possible to make this script look at a word, see if its first > > character is capitalized, if capitalized then skip that word. If not > > do the processing? I don't wan to use regex? Do I need it? change: words[i] = word.capitalize() into: if word != word.upper() : words[i] = word.capitalize() From puntabluda at gmail.com Wed Aug 22 10:46:04 2012 From: puntabluda at gmail.com (Rebelo) Date: Wed, 22 Aug 2012 07:46:04 -0700 (PDT) Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> > Let's move to Bug #2: > > 2. How do I escape the words that are already in uppercase? For example: > > > > The input file has this: > > NASA > > > > The script changes this to: > > Nasa > > > > Is it possible to make this script look at a word, see if its first > > character is capitalized, if capitalized then skip that word. If not > > do the processing? I don't wan to use regex? Do I need it? change: words[i] = word.capitalize() into: if word != word.upper() : words[i] = word.capitalize() From lipskathekat at yahoo.co.uk Wed Aug 22 10:59:25 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 15:59:25 +0100 Subject: Objects in Python In-Reply-To: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 15:13, shaun wrote: [snip] > Im very new to python and the object orientated feature doesnt seem to be as well put together as Java. Can anyone help with this problem? From one Java head to another I suggest you park what you know about Java and approach Python with a clear mind. Python is not Java and Java is not Python, that much has become clear. Python has actually been around longer than Java and contains many features you will be familiar with, serialization and introspection to name but two. The whole 'everything is an object' thing is a bit strange at first but actually it just means that everything you write is wrapped up in a component that exposes various standard methods and attributes, you treat functions as Objects and modules as Objects and even your classes will automagically sprout new attributes and properties, at least that's what I've discovered so far. There is no real enforced concept of information hiding, no binding of type to variable in fact no concept of typing at all as far as I can see. No interfaces and no subtype polymorphism (Python has 'Duck Type' polymorphism and I haven't really explored all the ramifications of this yet). It does however have multiple inheritance. In trying to get a handle on the language it has helped me to think of Python as a friendly interface onto the C programming language, it may or may not help you There are some very experienced pythonistas here and I'm sure you will get the help you need. There is a tutor mailing list and a great first starter is Dive into Python (google it) I can't say that Python will replace Java for me, I've been using Java since version 1, but it's got a good standard library and good support here and on the mailing list ... and it supports Unicode :-) I like it, give it a chance and you will probably like it too. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From gordon at panix.com Wed Aug 22 11:03:51 2012 From: gordon at panix.com (John Gordon) Date: Wed, 22 Aug 2012 15:03:51 +0000 (UTC) Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: In <18409992-1e28-4721-8e64-60c69668da4e at googlegroups.com> shaun writes: > I'm having an issue its my first time using python and i set up a class one of the methods is supposed to return a string but instead returns: > 389E0>> It looks like you're referencing the method object itself, instead of calling it method. In other words, you've left off the parentheses. I.e. you're doing something like this: print my_object.foo Instead of this: print my_object.foo() -- 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 shaun.wiseman91 at gmail.com Wed Aug 22 11:25:36 2012 From: shaun.wiseman91 at gmail.com (shaun) Date: Wed, 22 Aug 2012 08:25:36 -0700 (PDT) Subject: Objects in Python In-Reply-To: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> Here is some code: //////////////////////////This is the object I want to create: #!/usr/bin/python import cx_Oracle import sys import time import datetime class batchParam: def __init__(self,array): self.array=array def breakuparray(self): for row in self.array: mer = row[0].ljust(25, ' ') merc = row[1].ljust(13, ' ') mertype = row[2] merloc = row[3] mercount = row[4] mersec = row[5] acq = row[6] def returnBatch(self): self.breakuparray() return "\x01001\x0251.%s%s%s%s%s%s%s%s\x03" % (mer, merc, mertype, merloc, mercount, mersec, acq); //////////////////////////////////////Here is the script I want to run the object in: #!/usr/bin/python import cx_Oracle import sys import time import datetime sys.path.append("C:\\Documents and Settings\\swiseman\\Desktop") from batchParam import batchParam term = sys.argv[1] batch = sys.argv[2] con = cx_Oracle.connect('databaseInfo') cur = con.cursor() cur.execute("SELECT * FROM SOME_TABLE)) results = cur.fetchall() batchParam(results) Batch=batchParam.returnBatch print Batch cur.close() ////////////////////////////////////// Thanks, Shaun From wrw at mac.com Wed Aug 22 11:38:55 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 22 Aug 2012 11:38:55 -0400 Subject: writelines puzzle Message-ID: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): wd = open(rtt_data, 'w') stat = wd.write(str(i)) stat = wd.writelines(str(x_dates[:i])) stat = wd.writelines(str(y_rtt[:i])) wd.close() The value of i is unknown before I have read through the input log file, but is typically in the neighborhood of 2500. x_dates is a list of time stamps from the date2num method, that is values of the form 734716.72445602, day number plus decimal fraction of a day. y_rtt is a list of three- or four-digit floating point numbers. The x_dates and y_rtt lists are complete and plot correctly using matplotlib. Reading and parsing the input log file and extracting the data I need is time consuming, so I decided to save the data for further analysis without the overhead of reading and parsing it every time. Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: StraylightPro:Logs wrw$ cat RTT_monitor.dat 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] Clearly I'm missing something fundamental about using the writelines method, and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone telling me how to get that data all written out. I certainly don't insist on writelines, but I would like the file to be human-readable. Python 2.7.3 OS-X 10.8 Thanks, Bill From python at mrabarnett.plus.com Wed Aug 22 11:40:34 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Aug 2012 16:40:34 +0100 Subject: help me debug my "word capitalizer" script In-Reply-To: <50349669$0$6846$e4fe514c@news2.news.xs4all.nl> References: <50349669$0$6846$e4fe514c@news2.news.xs4all.nl> Message-ID: <5034FD72.9050502@mrabarnett.plus.com> On 22/08/2012 09:20, Hans Mulder wrote: [snip] > > Alternatively, if you want to remove only the line separator, > you could do: > > if line.endswith(linesep): > line = line[:-len(linesep)] > > The 'if' command is only necessary for the last line, which may or > may not end in a linesep. All earlier lines are guaranteed to end > with a linesep. > Even better is: line = line.rstrip(linesep) The line separator is '\n'. Strictly speaking, the line separator varies according to platform (Windows, *nix, etc), but it's translated to '\n' on reading from a file which has been opened in text mode (the default). From rosuav at gmail.com Wed Aug 22 11:47:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 01:47:46 +1000 Subject: Objects in Python In-Reply-To: <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> Message-ID: On Thu, Aug 23, 2012 at 1:25 AM, shaun wrote: > def breakuparray(self): > for row in self.array: > mer = row[0].ljust(25, ' ') > merc = row[1].ljust(13, ' ') > mertype = row[2] > merloc = row[3] > mercount = row[4] > mersec = row[5] > acq = row[6] The "for ... in ..." construct is a loop. I'm not sure what you're trying to accomplish here, but you're taking the last entry in self.array and unpacking that as a nested array. Perhaps not what you had in mind. For what you're doing there, though, a class is overkill. Remember, Python isn't Java; the most natural way to do everything isn't necessarily to write a class that unpacks things and packs them up again in a different way. ChrisA From d at davea.name Wed Aug 22 11:51:05 2012 From: d at davea.name (Dave Angel) Date: Wed, 22 Aug 2012 11:51:05 -0400 Subject: Objects in Python In-Reply-To: <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> Message-ID: <5034FFE9.5090706@davea.name> On 08/22/2012 11:25 AM, shaun wrote: > Here is some code: > //////////////////////////This is the object I want to create: > #!/usr/bin/python > import cx_Oracle > import sys > import time > import datetime > > > class batchParam: > > def __init__(self,array): > self.array=array > > > def breakuparray(self): > for row in self.array: > mer = row[0].ljust(25, ' ') > merc = row[1].ljust(13, ' ') > mertype = row[2] > merloc = row[3] > mercount = row[4] > mersec = row[5] > acq = row[6] > > > > def returnBatch(self): > self.breakuparray() > return "\x01001\x0251.%s%s%s%s%s%s%s%s\x03" % (mer, merc, mertype, merloc, mercount, mersec, acq); > > > //////////////////////////////////////Here is the script I want to run the object in: > > > #!/usr/bin/python > import cx_Oracle > import sys > import time > import datetime > sys.path.append("C:\\Documents and Settings\\swiseman\\Desktop") > from batchParam import batchParam > > term = sys.argv[1] > batch = sys.argv[2] > > con = cx_Oracle.connect('databaseInfo') > > > cur = con.cursor() > cur.execute("SELECT * FROM SOME_TABLE)) > > results = cur.fetchall() > > batchParam(results) This creates an instance of batchParam, but doesn't save it anywhere. So it's discarded immediately. > Batch=batchParam.returnBatch This tries to returns a reference to a static method of the class. Without an object, you won't get access to normal instance methods; there's no 'self'. And without parentheses, you won't even try to call the method, right or wrong. Probably you wanted something like: obj = batchParam(results) #now obj is an instance mystring = obj.returnBatch() #calls the method, and saves the returned string print mystring > > print Batch > > cur.close() > > Other comments: Don't make the mistake of forcing every class into its own source file. Unlike java, python has no such restrictions. It also has ordinary functions, not part of any class. So if several classes are related, go ahead and put them in a common file. Or keep them separate, Python doesn't mind. There are capitalization conventions: class names start with a capital letter, and source code filenames do not. So the class you've got in batchParam could be called BatchParam. Neither of these matter much, but they make it easier for someone else to see what you were trying to do. It would also be helpful if you posted the complete error message (with traceback), so we could more easily guess where in the code the problem occurs. It can be useful to add a comment in the actual source you post, since you have line numbers in your editor, and we don't in our emails. But don't try to get cute with colors, as this is a text forum. (that last comment may not apply to you, since you already used a plain-text format for your message) Python does have classmethod and staticmethod, but that's not usually what you want, and not here. -- DaveA From python at mrabarnett.plus.com Wed Aug 22 11:58:31 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Aug 2012 16:58:31 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <503501A7.4030204@mrabarnett.plus.com> On 22/08/2012 15:59, lipska the kat wrote: > On 22/08/12 15:13, shaun wrote: > > [snip] > >> Im very new to python and the object orientated feature doesnt seem to be as well put together as Java. Can anyone help with this problem? > > From one Java head to another I suggest you park what you know about > Java and approach Python with a clear mind. > > Python is not Java and Java is not Python, that much has become clear. > Python has actually been around longer than Java and contains many > features you will be familiar with, serialization and introspection to > name but two. The whole 'everything is an object' thing is a bit strange > at first but actually it just means that everything you write is wrapped > up in a component that exposes various standard methods and attributes, > you treat functions as Objects and modules as Objects and even your > classes will automagically sprout new attributes and properties, at > least that's what I've discovered so far. > > There is no real enforced concept of information hiding, no binding of > type to variable in fact no concept of typing at all as far as I can > see. strong typing != static typing Python is strongly typed, but not statically typed. > No interfaces and no subtype polymorphism (Python has 'Duck Type' > polymorphism and I haven't really explored all the ramifications of this > yet). It does however have multiple inheritance. > [snip] Python doesn't have interfaces as in Java because it isn't statically typed. The idea behind Duck Typing is that the actual type doesn't matter; if it supports the required method(s) and returns the expected type, then that's good enough! http://en.wikipedia.org/wiki/Duck_typing From lipskathekat at yahoo.co.uk Wed Aug 22 12:10:51 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 17:10:51 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 16:58, MRAB wrote: > On 22/08/2012 15:59, lipska the kat wrote: >> On 22/08/12 15:13, shaun wrote: >> >> [snip] >> >>> Im very new to python and the object orientated feature doesnt seem >>> to be as well put together as Java. Can anyone help with this problem? >> >> From one Java head to another I suggest you park what you know about >> Java and approach Python with a clear mind. [snip] > > strong typing != static typing > > Python is strongly typed, but not statically typed. > > > No interfaces and no subtype polymorphism (Python has 'Duck Type' >> polymorphism and I haven't really explored all the ramifications of this >> yet). It does however have multiple inheritance. >> [snip] The residents can be pretty defensive as well :-) Once again, no criticism intended. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From breamoreboy at yahoo.co.uk Wed Aug 22 12:13:29 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 17:13:29 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> Message-ID: On 22/08/2012 16:47, Chris Angelico wrote: > > For what you're doing there, though, a class is overkill. Remember, > Python isn't Java; the most natural way to do everything isn't > necessarily to write a class that unpacks things and packs them up > again in a different way. > > ChrisA > This shows just how poor the Python documentation is. I can't find the "overcoming brainwashing" section anywhere!!! -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Aug 22 12:30:11 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 17:30:11 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/2012 17:10, lipska the kat wrote: > On 22/08/12 16:58, MRAB wrote: >> On 22/08/2012 15:59, lipska the kat wrote: >>> On 22/08/12 15:13, shaun wrote: >>> >>> [snip] >>> >>>> Im very new to python and the object orientated feature doesnt seem >>>> to be as well put together as Java. Can anyone help with this problem? >>> >>> From one Java head to another I suggest you park what you know about >>> Java and approach Python with a clear mind. > [snip] >> >> strong typing != static typing >> >> Python is strongly typed, but not statically typed. >> >> > No interfaces and no subtype polymorphism (Python has 'Duck Type' >>> polymorphism and I haven't really explored all the ramifications of this >>> yet). It does however have multiple inheritance. >>> > > [snip] > > The residents can be pretty defensive as well :-) > > Once again, no criticism intended. > > lipska > I'm lost. I see nothing defensive at all. I see a statement of fact. -- Cheers. Mark Lawrence. From tjreedy at udel.edu Wed Aug 22 12:43:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Aug 2012 12:43:04 -0400 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: On 8/22/2012 3:30 AM, Mark Lawrence wrote: > On 22/08/2012 06:46, Terry Reedy wrote: >> On 8/21/2012 11:43 PM, mingqiang hu wrote: >>> why filter is bad when use lambda ? >> >> Inefficient, not 'bad'. Because the equivalent comprehension or >> generator expression does not require a function call. for each item in the iterable. > A case of premature optimisation? :) No, as regards my post. I simply made a factual statement without advocating a particular action. filter(lambda x: , iterable) (x for x in iterable if ) both create iterators that produce the items in iterable such that bool() is true. The following, with output rounded, shows something of the effect of the extra function call. >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(0)") 0.91 >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(20)") 1.28 >>> timeit.timeit("list(filter(lambda i: False, ranger))", "ranger=range(0)") 0.83 >>> timeit.timeit("list(filter(lambda i: False, ranger))", "ranger=range(20)") 2.60 Simply keeping true items is faster with filter -- at least on my particular machine with 3.3.0b2. >>> timeit.timeit("list(filter(None, ranger))", "ranger=range(20)") 1.03 Filter is also faster if the expression is a function call. >>> timeit.timeit("list(filter(f, ranger))", "ranger=range(20); f=lambda i: False") 2.5033614114454394 >>> timeit.timeit("list(i for i in ranger if f(i))", "ranger=range(20); f=lambda i: False") 3.2394095327040304 --- Perhaps or even yes as regards the so-called rule 'always use comprehension'. If one prefers filter as more readable, if one only wants to keep true items, if the expression is a function call, if evaluating the expression takes much more time than the extra function call so the latter does not matter, if the number of items is few enough that the extra time does not matter, then the rule is not needed or even wrong. So I think PyLint should be changed to stop its filter fud. -- Terry Jan Reedy From ckaynor at zindagigames.com Wed Aug 22 12:48:41 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 22 Aug 2012 09:48:41 -0700 Subject: writelines puzzle In-Reply-To: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: Reading your post, I do not see for sure what your actual issue is, so I am taking my best guess: that the file does not contain as much data as would be expected. On Wed, Aug 22, 2012 at 8:38 AM, William R. Wing (Bill Wing) wrote: > In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): > > wd = open(rtt_data, 'w') Here, you are opening the data for write ("w"), which will replace the contents of the file each time the file is opened. I am guessing you want append ("a"). > stat = wd.write(str(i)) > stat = wd.writelines(str(x_dates[:i])) > stat = wd.writelines(str(y_rtt[:i])) > wd.close() Also, rather than opening the file, writing to it, then closing it manually, you would be better off using the with statement (presuming Python 2.5+), like so: with open(rtt_data, 'w') as wd: wd.write(str(i)) wd.writelines(str(x_dates[:i])) wd.writelines(str(y_rtt[:i])) In this case, you can be absolutely certain that the file will be closed at the end, even if one of the commands in the middle fails. The way you had it written, if one of the write/writeline, or any of the formatting, fails, the file would be left open for an indeterminate amount of time (the wd variable may be kept around as part of the exception, preventing it from being garbage collected and thus closed). Not a big deal, but more important if you are doing more work with the file open. > > The value of i is unknown before I have read through the input log file, but is typically in the neighborhood of 2500. x_dates is a list of time stamps from the date2num method, that is values of the form 734716.72445602, day number plus decimal fraction of a day. y_rtt is a list of three- or four-digit floating point numbers. The x_dates and y_rtt lists are complete and plot correctly using matplotlib. Reading and parsing the input log file and extracting the data I need is time consuming, so I decided to save the data for further analysis without the overhead of reading and parsing it every time. > > Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: > > StraylightPro:Logs wrw$ cat RTT_monitor.dat > 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 > 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] > > Clearly I'm missing something fundamental about using the writelines method, and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone telling me how to get that data all written out. I certainly don't insist on writelines, but I would like the file to be human-readable. > > Python 2.7.3 > OS-X 10.8 > > Thanks, > Bill > -- > http://mail.python.org/mailman/listinfo/python-list From joel.goldstick at gmail.com Wed Aug 22 12:49:13 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 22 Aug 2012 12:49:13 -0400 Subject: writelines puzzle In-Reply-To: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing) wrote: > In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): > > wd = open(rtt_data, 'w') > stat = wd.write(str(i)) > stat = wd.writelines(str(x_dates[:i])) > stat = wd.writelines(str(y_rtt[:i])) > wd.close() > > The value of i is unknown before I have read through the input log file, but is typically in the neighborhood of 2500. x_dates is a list of time stamps from the date2num method, that is values of the form 734716.72445602, day number plus decimal fraction of a day. y_rtt is a list of three- or four-digit floating point numbers. The x_dates and y_rtt lists are complete and plot correctly using matplotlib. Reading and parsing the input log file and extracting the data I need is time consuming, so I decided to save the data for further analysis without the overhead of reading and parsing it every time. > > Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: > > StraylightPro:Logs wrw$ cat RTT_monitor.dat > 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 > 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] > > Clearly I'm missing something fundamental about using the writelines method, and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone telling me how to get that data all written out. I certainly don't insist on writelines, but I would like the file to be human-readable. > > Python 2.7.3 > OS-X 10.8 > > Thanks, > Bill > -- > http://mail.python.org/mailman/listinfo/python-list writelines writes a list of strings to a file. you are using this: > stat = wd.writelines(str(x_dates[:i])) which is the same as my second line below If you use map it will perform the first argument over the list. See if that works for you >>> l = [1,2,3] >>> str(l) '[1, 2, 3]' >>> s = map(str, l) >>> s ['1', '2', '3'] -- Joel Goldstick From tjreedy at udel.edu Wed Aug 22 13:01:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Aug 2012 13:01:47 -0400 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 8/22/2012 10:59 AM, lipska the kat wrote: > There is no real enforced concept of information hiding, no binding of > type to variable in fact no concept of typing at all as far as I can > see. Given that type(valid_name) always returns a type(class), that is a slightly strange statement. What is true is that there is no concept of static type for names. In Python (and similar languages) type or class is a property of objects, not names. This goes alone with names being bound to objects rather than linear memory blocks. (Memory block is a machine implementation of the abstraction 'information object'.) And Python objects are more stfongly typed than in some other languages. Names are only dynamically and indirectly typed when they are bound to an object. Except for the few keyword names like None, True, etc, names can be rebound to another object of another type. -- Terry Jan Reedy From lipskathekat at yahoo.co.uk Wed Aug 22 13:06:53 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 18:06:53 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 17:30, Mark Lawrence wrote: > On 22/08/2012 17:10, lipska the kat wrote: >> On 22/08/12 16:58, MRAB wrote: >>> On 22/08/2012 15:59, lipska the kat wrote: >>>> On 22/08/12 15:13, shaun wrote: >>>> >>>> [snip] >>>> >>>>> Im very new to python and the object orientated feature doesnt seem >>>>> to be as well put together as Java. Can anyone help with this problem? >> >> The residents can be pretty defensive as well :-) >> >> Once again, no criticism intended. >> >> lipska >> > > I'm lost. I see nothing defensive at all. I see a statement of fact. You seem to be perpetually lost Mark ... lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From malaclypse2 at gmail.com Wed Aug 22 13:28:38 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 22 Aug 2012 13:28:38 -0400 Subject: writelines puzzle In-Reply-To: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing) wrote: > Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: > > StraylightPro:Logs wrw$ cat RTT_monitor.dat > 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 > 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] If that's the full output, then my guess is that x_dates and y_rtt are not actual python lists. I bet they are, in fact, numpy arrays and that the string representation of those arrays (what you're getting from str(x_dates), etc) include the '...' in the middle instead of the full contents. Am I close? -- Jerry From ian.g.kelly at gmail.com Wed Aug 22 13:29:18 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 22 Aug 2012 11:29:18 -0600 Subject: Objects in Python In-Reply-To: <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <12ee0624-f523-4cf9-b46c-292315ef789e@googlegroups.com> Message-ID: In addition to the excellent feedback that Dave gave you: On Wed, Aug 22, 2012 at 9:25 AM, shaun wrote: > def breakuparray(self): > for row in self.array: > mer = row[0].ljust(25, ' ') > merc = row[1].ljust(13, ' ') > mertype = row[2] > merloc = row[3] > mercount = row[4] > mersec = row[5] > acq = row[6] This loops over each row in self.array and stores the contents in a set of variables called mer, merc, etc. Note that as written these variables are *local* to the breakuparray method, not attributes of the class. Also note that on each iteration, you reassign to the same variables again, wiping out all the work you did on the previous iteration. In the end, only the last row is stored in the local variables, and then even that is wiped out when the method returns. > def returnBatch(self): > self.breakuparray() > return "\x01001\x0251.%s%s%s%s%s%s%s%s\x03" % (mer, merc, mertype, merloc, mercount, mersec, acq); This appears to be trying to use the same local variables from the breakuparray method, but it can't. Those are out of scope here. If you want to share these data between the breakuparray method and the returnBatch method, you should either have breakuparray return them, or you should store them as attributes on the object instance: self.mer, self.merc, self.mertype, etc. (In Python, object attribute storage is always explicit, never implicit as in Java and the rest of the C++ family). From djacobfeuerborn at gmail.com Wed Aug 22 13:29:49 2012 From: djacobfeuerborn at gmail.com (Dennis Jacobfeuerborn) Date: Wed, 22 Aug 2012 10:29:49 -0700 (PDT) Subject: How to properly implement worker processes Message-ID: Hi, I'm trying to implement a system for periodically checking URLs and I've run into problems with some of the implementation details. The URLs are supposed to be checked continuously until the config for an URL is explicitly removed. The plan is to spawn a worker process for each URL that sends the status of the last check to its parent which keeps track of the state of all URLs. When a URL is no longer supposed to be checked the parent process should shutdown/kill the respective worker process. What I've been going for so far is that the parent process creates a global queue that is passed to all children upon creation which they use to send status messages to the parent. Then for each process a dedicated queue is created that the parent uses to issue commands to the child. The issue is that since the child processes spent some time in sleep() when a command from the parent comes they cannot respond immediately which is rather undesirable. What I would rather like to do is have the parent simply kill the child instead which is instantaneous and more reliable. My problem is that according to the multiprocessing docs if I kill the child while it uses the queue to send a status to the parent then the queue becomes corrupted and since that queue is shared that means the whole thing pretty much stops working. How can I get around this problem and receive status updates from all children efficiently without a shared queue and with the ability to simply kill the child process when it's no longer needed? Regards, Dennis From tjreedy at udel.edu Wed Aug 22 13:40:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Aug 2012 13:40:56 -0400 Subject: help me debug my "word capitalizer" script In-Reply-To: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> References: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> Message-ID: On 8/22/2012 10:46 AM, Rebelo wrote: >> Is it possible to make this script look at a word, see if its first >> character is capitalized, if capitalized then skip that word. Unicode has two 'capital' concepts: 'uppercase' and 'titlecase'. They are the same for latin chars but not for all alphabets. >> I don't wan to use regex? Do I need it? No. It may or may not be easier. > change: > words[i] = word.capitalize() > > into: > if word != word.upper() : > words[i] = word.capitalize() Still buggy >>> s = 'CamelCase' >>> if s != s.upper(): s = s.capitalize() >>> s 'Camelcase' use "if not word[0].isupper:..." or "if word[0].islower This will still .capitalize() 'weirdWord' to 'Weirdword'. If you do not want that, only change the first letter. >>> s = 'weirdWord' >>> if s[0].islower(): s = s[0].upper()+s[1:] >>> s 'WeirdWord' -- Terry Jan Reedy From __peter__ at web.de Wed Aug 22 13:44:02 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Aug 2012 19:44:02 +0200 Subject: writelines puzzle References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: William R. Wing (Bill Wing) wrote: > In the middle of a longer program that reads and plots data from a log > file, I have added the following five lines (rtt_data is fully qualified > file name): > > wd = open(rtt_data, 'w') > stat = wd.write(str(i)) > stat = wd.writelines(str(x_dates[:i])) > stat = wd.writelines(str(y_rtt[:i])) > wd.close() > > The value of i is unknown before I have read through the input log file, > but is typically in the neighborhood of 2500. x_dates is a list of time > stamps from the date2num method, that is values of the form > 734716.72445602, day number plus decimal fraction of a day. y_rtt is a > list of three- or four-digit floating point numbers. The x_dates and > y_rtt lists are complete and plot correctly using matplotlib. Reading and > parsing the input log file and extracting the data I need is time > consuming, so I decided to save the data for further analysis without the > overhead of reading and parsing it every time. > > Much to my surprise, when I looked at the output file, it only contained > 160 characters. Catting produces: > > StraylightPro:Logs wrw$ cat RTT_monitor.dat > 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., > 734737.4440162 > 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 > 27.4 26.4] > > Clearly I'm missing something fundamental about using the writelines > method, and I'm sure it will be a DUH moment for me, but I'd sure > appreciate someone telling me how to get that data all written out. I > certainly don't insist on writelines, but I would like the file to be > human-readable. When you apply str() to a numpy array big arrays are helpfully truncated, probably because the functionality is meant to be used in the interactive interpreter rather than to write to a file. The default value is 1000 entries. One way to get the desired output is to increase the threshold: >>> numpy.set_printoptions(threshold=4) >>> print numpy.arange(10) [0 1 2 ..., 7 8 9] >>> numpy.set_printoptions(threshold=10) >>> print numpy.arange(10) [0 1 2 3 4 5 6 7 8 9] Also, in file.writelines(some_str) writelines iterates over the characters of the some_string, so you should instead write the above as file.write(some_str) Your code will become assert numpy.get_printoptions()["threshold"] >= i wd.write(str(x_dates[:i])) If you intended to write one array entry at a time with writelines() here's how to do that: wd.write("[") wd.writelines("%s " % x for x in x_dates[:i]) wd.write("]\n") numpy.savetxt() may also suit your needs. From ian.g.kelly at gmail.com Wed Aug 22 13:46:34 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 22 Aug 2012 11:46:34 -0600 Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 11:29 AM, Dennis Jacobfeuerborn wrote: > Hi, > I'm trying to implement a system for periodically checking URLs and I've run into problems with some of the implementation details. The URLs are supposed to be checked continuously until the config for an URL is explicitly removed. > > The plan is to spawn a worker process for each URL that sends the status of the last check to its parent which keeps track of the state of all URLs. When a URL is no longer supposed to be checked the parent process should shutdown/kill the respective worker process. > > What I've been going for so far is that the parent process creates a global queue that is passed to all children upon creation which they use to send status messages to the parent. Then for each process a dedicated queue is created that the parent uses to issue commands to the child. > > The issue is that since the child processes spent some time in sleep() when a command from the parent comes they cannot respond immediately which is rather undesirable. What I would rather like to do is have the parent simply kill the child instead which is instantaneous and more reliable. > > My problem is that according to the multiprocessing docs if I kill the child while it uses the queue to send a status to the parent then the queue becomes corrupted and since that queue is shared that means the whole thing pretty much stops working. > > How can I get around this problem and receive status updates from all children efficiently without a shared queue and with the ability to simply kill the child process when it's no longer needed? The usual approach to killing worker processes safely is to send them an "exit" command, which they should respond to by terminating cleanly. Instead of using sleep(), have the workers do a blocking get() on the queue with a timeout. This way they'll receive the "exit" message immediately as desired, but they'll still wake up at the desired intervals in order to do their work. From lipskathekat at yahoo.co.uk Wed Aug 22 13:46:43 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 18:46:43 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 18:01, Terry Reedy wrote: > On 8/22/2012 10:59 AM, lipska the kat wrote: > >> There is no real enforced concept of information hiding, no binding of >> type to variable in fact no concept of typing at all as far as I can >> see. > > Given that type(valid_name) always returns a type(class), that is a > slightly strange statement. [snip] Well I'm a beginner so I'm allowed to make strange statements. However I don't think it's that strange and here's why. If, in a language, I find I am able to say a = 1 then later, in the same scope I can say a = "foo" then later again in the same scope I can say a = ([1,2,3], "xyz", True) then, and I may be missing something here, to me, that doesn't say 'strongly typed' that says 'no typing constraints whatsoever' If you can show me a 'type' that cannot be assigned to a in the same scope then I would be most interested to know, I haven't found one yet. We need to separate out the 'view' from the 'implementation' here. Most developers I know, if looking at the code and without the possibly dubious benefit of knowing that in Python 'everything is an object' would not call this 'strong typing' Once again, this is not a criticism, it's an observation It is OK to to make (possibly erroneous) observations isn't it? Thanks for taking the time to reply. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From wrw at mac.com Wed Aug 22 14:00:52 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 22 Aug 2012 14:00:52 -0400 Subject: writelines puzzle In-Reply-To: References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: On Aug 22, 2012, at 12:48 PM, Chris Kaynor wrote: > Reading your post, I do not see for sure what your actual issue is, so > I am taking my best guess: that the file does not contain as much data > as would be expected. > Sorry, I should have been more explicit. The value of "i" in this instance is 2354, so the file should (I thought) have contained the value of "i" followed by 2 x 2354 values of the data. > On Wed, Aug 22, 2012 at 8:38 AM, William R. Wing (Bill Wing) > wrote: >> In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): >> >> wd = open(rtt_data, 'w') > > Here, you are opening the data for write ("w"), which will replace the > contents of the file each time the file is opened. I am guessing you > want append ("a"). > No, I really do want 'w'. In the final package, this will be invoked once at the end of the month, before the log file is compressed and rolled. [big snip] >> >> Much to my surprise, when I looked at the output file, it only contained 160 characters [instead of ~2700 multi-character data values]. Catting produces: >> >> StraylightPro:Logs wrw$ cat RTT_monitor.dat >> 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 >> 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] >> Please look at what cat found in the file. First there is the value of "i" as expected. This is then followed by the first 3 values of the time stamp x-data, then a comma, an ellipsis, another comma, and the last three data values. That patten (3 values, an ellipsis, and 3 final values) is repeated again for the y-data array/list. It is almost as though "writelines" had written an editorial summary of the data rather than the data. >> Clearly I'm missing something fundamental about using the writelines method, and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone telling me how to get that data all written out. I certainly don't insist on writelines, but I would like the file to be human-readable. >> >> Python 2.7.3 >> OS-X 10.8 >> >> Thanks, >> Bill >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list From breamoreboy at yahoo.co.uk Wed Aug 22 14:07:52 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 19:07:52 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/2012 18:06, lipska the kat wrote: > On 22/08/12 17:30, Mark Lawrence wrote: >> On 22/08/2012 17:10, lipska the kat wrote: >>> On 22/08/12 16:58, MRAB wrote: >>>> On 22/08/2012 15:59, lipska the kat wrote: >>>>> On 22/08/12 15:13, shaun wrote: >>>>> >>>>> [snip] >>>>> >>>>>> Im very new to python and the object orientated feature doesnt seem >>>>>> to be as well put together as Java. Can anyone help with this >>>>>> problem? > >>> >>> The residents can be pretty defensive as well :-) >>> >>> Once again, no criticism intended. >>> >>> lipska >>> >> >> I'm lost. I see nothing defensive at all. I see a statement of fact. > > > You seem to be perpetually lost Mark ... > > > lipska > Maybe but I seem to understand Python rather better than some people :) Once again, no criticism intended. -- Cheers. Mark Lawrence. From ian.g.kelly at gmail.com Wed Aug 22 14:15:09 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 22 Aug 2012 12:15:09 -0600 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On Wed, Aug 22, 2012 at 11:46 AM, lipska the kat wrote: > If, in a language, I find I am able to say > > a = 1 > > then later, in the same scope I can say > > a = "foo" > > then later again in the same scope I can say > > a = ([1,2,3], "xyz", True) > > then, and I may be missing something here, to me, that doesn't say 'strongly > typed' that says 'no typing constraints whatsoever' You're conflating "strong typing" with "static typing". Strong typing does not refer to restrictions on what type of data can be stored where, but to restrictions on how operations on that data can be intermixed. The classic example of weak typing is concatenation of strings and numbers, e.g. ("abc" + 123). Weakly typed languages like JavaScript will implicitly coerce the number to a string and perform the concatenation. Strongly typed languages like Python will raise a TypeError instead. Note that statically typed languages can be weakly typed as well. For instance, C is commonly considered to be weakly typed because the casting rules of that language allow you to treat any piece of data as being of any type, even though the variables themselves are all statically typed. From pmfenton33 at gmail.com Wed Aug 22 14:21:54 2012 From: pmfenton33 at gmail.com (bikewave) Date: Wed, 22 Aug 2012 11:21:54 -0700 (PDT) Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: <1345659714032-4986058.post@n6.nabble.com> I also had the unresolved externals problem (not the mdir.h problem, though) and my solution was different. a) reinstall correct python2.6.4, using an Intel-flavor msi vice AMD64-flavor b) source the c:\program files(x86\microsoft visual studio 9.0\vc\bin\vcvars32.bat and shazzaaaam the pycrypto build + install worked fine. My CPU is Intel not AMD so I apparently had a bogus python install. -- View this message in context: http://python.6.n6.nabble.com/PyCrypto-builds-neither-with-MSVC-nor-MinGW-tp4366880p4986058.html Sent from the Python - python-list mailing list archive at Nabble.com. From breamoreboy at yahoo.co.uk Wed Aug 22 14:23:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 19:23:44 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/2012 18:46, lipska the kat wrote: > On 22/08/12 18:01, Terry Reedy wrote: >> On 8/22/2012 10:59 AM, lipska the kat wrote: >> >>> There is no real enforced concept of information hiding, no binding of >>> type to variable in fact no concept of typing at all as far as I can >>> see. >> >> Given that type(valid_name) always returns a type(class), that is a >> slightly strange statement. > > [snip] > > Well I'm a beginner so I'm allowed to make strange statements. > However I don't think it's that strange and here's why. > > If, in a language, I find I am able to say > > a = 1 > > then later, in the same scope I can say > > a = "foo" > > then later again in the same scope I can say > > a = ([1,2,3], "xyz", True) > > then, and I may be missing something here, to me, that doesn't say > 'strongly typed' that says 'no typing constraints whatsoever' > > If you can show me a 'type' that cannot be assigned to > > a > > in the same scope then I would be most interested to know, I haven't > found one yet. You've said nothing above except that any object you like can be bound to a Python name. The name 'a' is never used. What happens when you actually do something with the object that you've bound to 'a'? > > We need to separate out the 'view' from the 'implementation' here. > Most developers I know, if looking at the code and without the possibly > dubious benefit of knowing that in Python 'everything is an object' > would not call this 'strong typing' I really despair that after ten years of using Python people still seem to be incapable of distinguishing strong, static, weak and dynamic typing. Not that it's a specific Python problem of course, just that I always get to read about it here. > > Once again, this is not a criticism, it's an observation > > It is OK to to make (possibly erroneous) observations isn't it? Not if undoes concepts that computer scientists have patiently been trying to explain for years. > > Thanks for taking the time to reply. > > lipska > -- Cheers. Mark Lawrence. From wrw at mac.com Wed Aug 22 14:36:34 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 22 Aug 2012 14:36:34 -0400 Subject: writelines puzzle In-Reply-To: References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: <213147EF-F3D9-41B0-B5C6-199FF3B739C1@mac.com> On Aug 22, 2012, at 1:28 PM, Jerry Hill wrote: > On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing) > wrote: >> Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: >> >> StraylightPro:Logs wrw$ cat RTT_monitor.dat >> 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 >> 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] > > If that's the full output, then my guess is that x_dates and y_rtt are > not actual python lists. I bet they are, in fact, numpy arrays and > that the string representation of those arrays (what you're getting > from str(x_dates), etc) include the '...' in the middle instead of the > full contents. > > Am I close? > > -- > Jerry Yes - bingo. They are numpy arrays. And that was the hint I needed to go look in the numpy docs. Found numpy.set_printoptions(threshold='nan'), which has indeed allowed me to get all the data into the file. I now see Peter Otten made the same suggestion. Thanks to you both. Bill From d at davea.name Wed Aug 22 14:39:20 2012 From: d at davea.name (Dave Angel) Date: Wed, 22 Aug 2012 14:39:20 -0400 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: <1345659714032-4986058.post@n6.nabble.com> References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> <1345659714032-4986058.post@n6.nabble.com> Message-ID: <50352758.5010905@davea.name> On 08/22/2012 02:21 PM, bikewave wrote: > I also had the unresolved externals problem (not the mdir.h problem, though) > and my solution was different. > a) reinstall correct python2.6.4, using an Intel-flavor msi vice > AMD64-flavor > b) source the c:\program files(x86\microsoft visual studio > 9.0\vc\bin\vcvars32.bat > and shazzaaaam the pycrypto build + install worked fine. > My CPU is Intel not AMD so I apparently had a bogus python install. > For most open-software distributions: AMD64 is the 64 bit build for both AMD and Intel. Probably referred to as AMD64 because AMD had a compatible 64 bit processor while Intel was still fooling around with Merced for its 64 bit stuff. X86 is the 32 bit build for both AMD and Intel. -- DaveA From hansmu at xs4all.nl Wed Aug 22 14:53:50 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 22 Aug 2012 20:53:50 +0200 Subject: How do I display unicode value stored in a string variable using ord() In-Reply-To: <7xfw7ilqnd.fsf@ruckus.brouhaha.com> References: <308df2af-abe7-4043-b199-0a39f440e0ab@googlegroups.com> <502f8a2a$0$29978$c3e8da3$5496439d@news.astraweb.com> <7xehn4vyya.fsf@ruckus.brouhaha.com> <5030832d$0$29978$c3e8da3$5496439d@news.astraweb.com> <7x8vdbmho6.fsf@ruckus.brouhaha.com> <7xfw7ilqnd.fsf@ruckus.brouhaha.com> Message-ID: <50352abe$0$6873$e4fe514c@news2.news.xs4all.nl> On 19/08/12 19:48:06, Paul Rubin wrote: > Terry Reedy writes: >> py> s = chr(0xFFFF + 1) >> py> a, b = s > That looks like a 3.2- narrow build. Such which treat unicode strings > as sequences of code units rather than sequences of codepoints. Not an > implementation bug, but compromise design that goes back about a > decade to when unicode was added to Python. Actually, this compromise design was new in 3.0. In 2.x, unicode strings were sequences of code points. Narrow builds rejected any code points > 0xFFFF: 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. >>> s = unichr(0xFFFF + 1) Traceback (most recent call last): File "", line 1, in ValueError: unichr() arg not in range(0x10000) (narrow Python build) -- HansM From lipskathekat at yahoo.co.uk Wed Aug 22 15:03:16 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 20:03:16 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> On 22/08/12 19:15, Ian Kelly wrote: > On Wed, Aug 22, 2012 at 11:46 AM, lipska the kat > wrote: >> If, in a language, I find I am able to say >> >> a = 1 [snip] > > You're conflating "strong typing" with "static typing". Strong typing > does not refer to restrictions on what type of data can be stored > where, but to restrictions on how operations on that data can be > intermixed. Yes of course I am, thank you for pointing that out. I don't know why I have this overwhelming need to see variables explicitly defined ... years of 'same old same old' I suppose. I do seem to remember reading something about Python moving towards static typing and there are tools out there to help avoid run time disasters ... anyway, this has latched now so thanks for taking the time to reply. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From driscoll at cs.wisc.edu Wed Aug 22 15:03:30 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 22 Aug 2012 14:03:30 -0500 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <50352D02.3040702@cs.wisc.edu> On 08/22/2012 12:46 PM, lipska the kat wrote: > If you can show me a 'type' that cannot be assigned to > > a > > in the same scope then I would be most interested to know, I haven't > found one yet. As other people have said, you've just pointed out the difference between static typing and dynamic typing -- and how the former types variables (or "names") and the latter types objects. I just have a few things to add to your post and others. First, from some point of view, you're correct. From a type theory point of view "dynamically typed" is an oxymoron, because *by definition* (from this point of view) types are a property of variables (and expressions). For example, Ben Pierce says (in "Types and Programming Languages"): The word "static" is sometimes added explicitly...to distinguish the sorts of compile-time analyses we are considering here from the dynamic or latent typing found in languages such as Scheme, where run-time type tags are used to distinguish different kinds of structures in the heap. Terms like "dynamically typed" are arguably misnomers and should probably be replaced by "dynamically checked," but the usage is standard. (And the usage is standard because it's just really useful to be able to say "dynamically-typed" instead of "uni-typed with runtime checks of things that act like types". (I don't think Pierce's "dynamically checked" is specific enough. :-)) Second, this concept isn't *so* unfamiliar to you. If I give you the following Java code: void foo(Object o) { ... } and ask what type 'o' is, there are kind of two answers. The first is that 'o' is an 'Object'. But you can't make an Object -- that's an abstract class. (IIRC. If it's not then just bear with me; you get the idea. :-)) So from a strictly static type-theory point of view, 'foo' is unusable because it takes a type which you can never create. But of course that's not the case, because in actual Java 'o' has some dynamic type which is a subclass of 'Object'. Though I'm sure this statement will be *really* popular with this list , if it puts your mind at ease a little, you can imagine that there are no primitive types and Python names all have type 'Object', but that you can refer to the functions in an object's dynamic type without explicitly downcasting. (The analogy isn't perfect.) On 08/22/2012 01:15 PM, Ian Kelly wrote: > The classic example of weak typing is concatenation of strings and > numbers, e.g. ("abc" + 123). Weakly typed languages like JavaScript > will implicitly coerce the number to a string and perform the > concatenation. Strongly typed languages like Python will raise a > TypeError instead. I would also say don't get *too* caught up in categorizing everything into "strong" and "weak"; that's a spectrum, and where things fall is a lot more interesting than just "here or there". Really it's even more complex than just a linear spectrum -- Language A can be stronger than Language B in one respect but weaker in another. In particular, it's possible to have rather stronger typing than Python (especially with respect to Booleans, but in some other respects as well). Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 545 bytes Desc: OpenPGP digital signature URL: From lipskathekat at yahoo.co.uk Wed Aug 22 15:13:59 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 20:13:59 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 19:07, Mark Lawrence wrote: > On 22/08/2012 18:06, lipska the kat wrote: >> On 22/08/12 17:30, Mark Lawrence wrote: >>> On 22/08/2012 17:10, lipska the kat wrote: >>>> On 22/08/12 16:58, MRAB wrote: >>>>> On 22/08/2012 15:59, lipska the kat wrote: >>>>>> On 22/08/12 15:13, shaun wrote: >>>>>> [snip] > > Maybe but I seem to understand Python rather better than some people :) Well I should certainly hope so after '10 years of using Python' I freely admit I don't fully understand Python yet but I will and hopefully it won't take 10 years ;-) Never give up, never surrender !!! > Once again, no criticism intended. None taken lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From d at davea.name Wed Aug 22 15:28:28 2012 From: d at davea.name (Dave Angel) Date: Wed, 22 Aug 2012 15:28:28 -0400 Subject: writelines puzzle In-Reply-To: References: <290CC961-63B7-4B9B-8822-AE7CBB5A5AED@mac.com> Message-ID: <503532DC.3070200@davea.name> On 08/22/2012 02:00 PM, William R. Wing (Bill Wing) wrote: > On Aug 22, 2012, at 12:48 PM, Chris Kaynor wrote: > >> Reading your post, I do not see for sure what your actual issue is, so >> I am taking my best guess: that the file does not contain as much data >> as would be expected. >> > Sorry, I should have been more explicit. The value of "i" in this instance is 2354, so the file should (I thought) have contained the value of "i" followed by 2 x 2354 values of the data. > >> On Wed, Aug 22, 2012 at 8:38 AM, William R. Wing (Bill Wing) >> wrote: >>> In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): >>> >>> wd = open(rtt_data, 'w') >> Here, you are opening the data for write ("w"), which will replace the >> contents of the file each time the file is opened. I am guessing you >> want append ("a"). >> > No, I really do want 'w'. In the final package, this will be invoked once at the end of the month, before the log file is compressed and rolled. > > [big snip] > >>> Much to my surprise, when I looked at the output file, it only contained 160 characters [instead of ~2700 multi-character data values]. Catting produces: >>> >>> StraylightPro:Logs wrw$ cat RTT_monitor.dat >>> 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 >>> 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] >>> > Please look at what cat found in the file. First there is the value of "i" as expected. This is then followed by the first 3 values of the time stamp x-data, then a comma, an ellipsis, another comma, and the last three data values. That patten (3 values, an ellipsis, and 3 final values) is repeated again for the y-data array/list. It is almost as though "writelines" had written an editorial summary of the data rather than the data. This problem has nothing to do with writelines(). You pass writelines() a simple string, it writes it to the file. writelines() normally EXPECTS a list, but you convert it with the str() function. So it iterates through the characters, rather than through the elements of a list. Clearly, the value x_data is not a list either, as you claimed in your original message. Calling str() on a list would have produced a single string representing a list, and assuming the elements are floats, it'd look pretty much what you had except for the ellipses. Is that really what you wanted? If so, i'd fix the code that produced a non-list for that value (and similarly for y_rtt). On the other hand, perhaps you expected the values to be one or two per line, judging from your use of the writelines() function. I suspect you have a numpy array or similar object, not a list. So confirm what you've actually got, and what you want/expect the output to look like, and somebody will (or already has) help out. -- DaveA From djacobfeuerborn at gmail.com Wed Aug 22 15:40:25 2012 From: djacobfeuerborn at gmail.com (Dennis Jacobfeuerborn) Date: Wed, 22 Aug 2012 12:40:25 -0700 (PDT) Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wednesday, August 22, 2012 7:46:34 PM UTC+2, Ian wrote: > On Wed, Aug 22, 2012 at 11:29 AM, Dennis Jacobfeuerborn > > wrote: > > > Hi, > > > I'm trying to implement a system for periodically checking URLs and I've run into problems with some of the implementation details. The URLs are supposed to be checked continuously until the config for an URL is explicitly removed. > > > > > > The plan is to spawn a worker process for each URL that sends the status of the last check to its parent which keeps track of the state of all URLs. When a URL is no longer supposed to be checked the parent process should shutdown/kill the respective worker process. > > > > > > What I've been going for so far is that the parent process creates a global queue that is passed to all children upon creation which they use to send status messages to the parent. Then for each process a dedicated queue is created that the parent uses to issue commands to the child. > > > > > > The issue is that since the child processes spent some time in sleep() when a command from the parent comes they cannot respond immediately which is rather undesirable. What I would rather like to do is have the parent simply kill the child instead which is instantaneous and more reliable. > > > > > > My problem is that according to the multiprocessing docs if I kill the child while it uses the queue to send a status to the parent then the queue becomes corrupted and since that queue is shared that means the whole thing pretty much stops working. > > > > > > How can I get around this problem and receive status updates from all children efficiently without a shared queue and with the ability to simply kill the child process when it's no longer needed? > > > > The usual approach to killing worker processes safely is to send them > > an "exit" command, which they should respond to by terminating > > cleanly. Instead of using sleep(), have the workers do a blocking > > get() on the queue with a timeout. This way they'll receive the > > "exit" message immediately as desired, but they'll still wake up at > > the desired intervals in order to do their work. I was thinking about something like that but the issue is that this really only works when you don't do any actual blocking work. I may be able to get around the sleep() but then I have to fetch the URL or do some other work that might block for a while so the get() trick doesn't work. Also the child process might not be able to deal with such an exit command at all for one reason or another so the only safe way to get rid of it is for the parent to kill it. The better option would be to not use a shared queue for communication and instead use only dedicated pipes/queues for each child process but the doesn't seem to be a way to wait for a message from multiple queues/pipes. If that were the case then I could simply kill the child and get rid of the respective pipes/queues without affecting the other processes or communication channels. Regards, Dennis From djacobfeuerborn at gmail.com Wed Aug 22 15:40:25 2012 From: djacobfeuerborn at gmail.com (Dennis Jacobfeuerborn) Date: Wed, 22 Aug 2012 12:40:25 -0700 (PDT) Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wednesday, August 22, 2012 7:46:34 PM UTC+2, Ian wrote: > On Wed, Aug 22, 2012 at 11:29 AM, Dennis Jacobfeuerborn > > wrote: > > > Hi, > > > I'm trying to implement a system for periodically checking URLs and I've run into problems with some of the implementation details. The URLs are supposed to be checked continuously until the config for an URL is explicitly removed. > > > > > > The plan is to spawn a worker process for each URL that sends the status of the last check to its parent which keeps track of the state of all URLs. When a URL is no longer supposed to be checked the parent process should shutdown/kill the respective worker process. > > > > > > What I've been going for so far is that the parent process creates a global queue that is passed to all children upon creation which they use to send status messages to the parent. Then for each process a dedicated queue is created that the parent uses to issue commands to the child. > > > > > > The issue is that since the child processes spent some time in sleep() when a command from the parent comes they cannot respond immediately which is rather undesirable. What I would rather like to do is have the parent simply kill the child instead which is instantaneous and more reliable. > > > > > > My problem is that according to the multiprocessing docs if I kill the child while it uses the queue to send a status to the parent then the queue becomes corrupted and since that queue is shared that means the whole thing pretty much stops working. > > > > > > How can I get around this problem and receive status updates from all children efficiently without a shared queue and with the ability to simply kill the child process when it's no longer needed? > > > > The usual approach to killing worker processes safely is to send them > > an "exit" command, which they should respond to by terminating > > cleanly. Instead of using sleep(), have the workers do a blocking > > get() on the queue with a timeout. This way they'll receive the > > "exit" message immediately as desired, but they'll still wake up at > > the desired intervals in order to do their work. I was thinking about something like that but the issue is that this really only works when you don't do any actual blocking work. I may be able to get around the sleep() but then I have to fetch the URL or do some other work that might block for a while so the get() trick doesn't work. Also the child process might not be able to deal with such an exit command at all for one reason or another so the only safe way to get rid of it is for the parent to kill it. The better option would be to not use a shared queue for communication and instead use only dedicated pipes/queues for each child process but the doesn't seem to be a way to wait for a message from multiple queues/pipes. If that were the case then I could simply kill the child and get rid of the respective pipes/queues without affecting the other processes or communication channels. Regards, Dennis From lipskathekat at yahoo.co.uk Wed Aug 22 15:45:44 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Wed, 22 Aug 2012 20:45:44 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 20:03, Evan Driscoll wrote: > On 08/22/2012 12:46 PM, lipska the kat wrote: >> If you can show me a 'type' that cannot be assigned to >> >> a >> >> in the same scope then I would be most interested to know, I haven't >> found one yet. > [snip] > > Second, this concept isn't *so* unfamiliar to you. If I give you the > following Java code: > > void foo(Object o) { ... } > > and ask what type 'o' is, there are kind of two answers. The first is > that 'o' is an 'Object'. But you can't make an Object -- that's an > abstract class. (IIRC. If it's not then just bear with me; you get the > idea. :-)) So from a strictly static type-theory point of view, 'foo' is > unusable because it takes a type which you can never create. But of > course that's not the case, because in actual Java 'o' has some dynamic > type which is a subclass of 'Object'. Well I think this is where I'm struggling a bit. looking at this method declaration I can see that the method takes an argument of type Object (and just FYI class Object is not abstract and you can do Object o = new Object()) and does not return a value. I know that for the lifetime of this JVM, whatever o turns out to be it will always be an Object. I can't assign a primitive to o as ints chars floats etc are certainly not Objects. There are certain invariants that give me a warm and comfortable feeling inside. compare this to a function declaration in Python def foo(self): ... I can learn nothing about this function by looking at the first line If I see def foo(self, someVar=1): I can determine that foo takes an argument that, at some time or other is or has been a number of some description but I can't rely on it and I have no idea what is returned and that's where I think I'm having trouble. But I will get over it and I will learn the language and I may look back on these exchanges and say ... I was wrong, this is so much better that what I was used to, or maybe I won't. I'll let you know Thank you for your calm and reasoned response. Disclaimer: None of my comments above should be construed as criticisms they are just observations. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From python at mrabarnett.plus.com Wed Aug 22 16:31:51 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Aug 2012 21:31:51 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <503541B7.2050908@mrabarnett.plus.com> On 22/08/2012 20:45, lipska the kat wrote: > On 22/08/12 20:03, Evan Driscoll wrote: >> On 08/22/2012 12:46 PM, lipska the kat wrote: >>> If you can show me a 'type' that cannot be assigned to >>> >>> a >>> >>> in the same scope then I would be most interested to know, I haven't >>> found one yet. >> > [snip] > >> >> Second, this concept isn't *so* unfamiliar to you. If I give you the >> following Java code: >> >> void foo(Object o) { ... } >> >> and ask what type 'o' is, there are kind of two answers. The first is >> that 'o' is an 'Object'. But you can't make an Object -- that's an >> abstract class. (IIRC. If it's not then just bear with me; you get the >> idea. :-)) So from a strictly static type-theory point of view, 'foo' is >> unusable because it takes a type which you can never create. But of >> course that's not the case, because in actual Java 'o' has some dynamic >> type which is a subclass of 'Object'. > > Well I think this is where I'm struggling a bit. > > looking at this method declaration I can see that the method takes an > argument of type Object (and just FYI class Object is not abstract and > you can do Object o = new Object()) and does not return a value. > I know that for the lifetime of this JVM, whatever o turns out to be it > will always be an Object. I can't assign a primitive to o as ints chars > floats etc are certainly not Objects. There are certain invariants that > give me a warm and comfortable feeling inside. > > compare this to a function declaration in Python > > def foo(self): > [snip] That's not actually a declaration but a definition. :-) The function's body is bound to the name at runtime, so: def double_it(x): return x * 2 is not far from: double_it = lambda x: x * 2 The only declarations are "global" and "nonlocal" (and the latter exists only in recent versions of Python). From breamoreboy at yahoo.co.uk Wed Aug 22 16:46:29 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Aug 2012 21:46:29 +0100 Subject: Objects in Python In-Reply-To: <503541B7.2050908@mrabarnett.plus.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <503541B7.2050908@mrabarnett.plus.com> Message-ID: On 22/08/2012 21:31, MRAB wrote: > On 22/08/2012 20:45, lipska the kat wrote: >> >> compare this to a function declaration in Python >> >> def foo(self): >> > [snip] > That's not actually a declaration but a definition. :-) > > The function's body is bound to the name at runtime, so: > > def double_it(x): > return x * 2 > > is not far from: > > double_it = lambda x: x * 2 > > The only declarations are "global" and "nonlocal" (and the latter > exists only in recent versions of Python). Looking at the self I'm assuming that's a method and not a function. -- Cheers. Mark Lawrence. From ian.g.kelly at gmail.com Wed Aug 22 17:15:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 22 Aug 2012 15:15:10 -0600 Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wed, Aug 22, 2012 at 1:40 PM, Dennis Jacobfeuerborn wrote: > I was thinking about something like that but the issue is that this really only works when you don't do any actual blocking work. I may be able to get around the sleep() but then I have to fetch the URL or do some other work that might block for a while so the get() trick doesn't work. At a lower level, it is possible to poll on both the pipe and the socket simultaneously. At this point though you might want to start looking at an asynchronous or event-driven framework like twisted or gevent. > Also the child process might not be able to deal with such an exit command at all for one reason or another so the only safe way to get rid of it is for the parent to kill it. I think you mean that it is the most "reliable" way. In general, the only "safe" way to cause a process to exit is the cooperative approach, because it may otherwise leave external resources such as file data in an unexpected state that could cause problems later. > The better option would be to not use a shared queue for communication and instead use only dedicated pipes/queues for each child process but the doesn't seem to be a way to wait for a message from multiple queues/pipes. If that were the case then I could simply kill the child and get rid of the respective pipes/queues without affecting the other processes or communication channels. Assuming that you're using a Unix system: from select import select while True: ready, _, _ = select(pipes, [], [], timeout) if not ready: # process timeout else: for pipe in ready: message = pipe.get() # process message From driscoll at cs.wisc.edu Wed Aug 22 17:31:08 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 22 Aug 2012 16:31:08 -0500 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <50354F9C.5090901@cs.wisc.edu> On 08/22/2012 02:45 PM, lipska the kat wrote: > On 22/08/12 20:03, Evan Driscoll wrote: >> Second, this concept isn't *so* unfamiliar to you. If I give you the >> following Java code: >> >> void foo(Object o) { ... } >> > looking at this method declaration I can see that the method takes an > argument of type Object (and just FYI class Object is not abstract and > you can do Object o = new Object()) and does not return a value. > I know that for the lifetime of this JVM, whatever o turns out to be it > will always be an Object. I can't assign a primitive to o as ints chars > floats etc are certainly not Objects. There are certain invariants that > give me a warm and comfortable feeling inside. I'm not saying it's nothing, but "can't assign a primitive" isn't much of an invariant in the broad scheme of things when you can pass items as diverse as lists, GUI buttons, files, etc. I would say it's more like if you see 'int x' then *that* imposes a pretty big invariant, but passing 'Object' imposes almost nothing. This is especially true considering the fact that you actually *can* say 'foo(4)' and Java will go and autobox the 4 into Integer(4) for you. (BTW, this analogy suggests a way that's actually fairly useful for how to look at Python coming from the Java perspective: Python just lacks primitive types and things like integers are always boxed. Thus *all* Python variables are essentially references.) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 545 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Wed Aug 22 19:58:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 23 Aug 2012 09:58:39 +1000 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <87d32i1ntc.fsf@benfinney.id.au> lipska the kat writes: > If, in a language, I find I am able to say > > a = 1 > > then later, in the same scope I can say > > a = "foo" > > then later again in the same scope I can say > > a = ([1,2,3], "xyz", True) > > then, and I may be missing something here, to me, that doesn't say > strongly typed' that says 'no typing constraints whatsoever' You haven't discovered anything about types; what you have discovered is that Python name bindings are not variables. In fact, Python doesn't have variables ? not as C or Java programmers would understand the term. What it has instead are references to objects (with names as one kind of reference). The documentation unfortunately calls these references ?variables? in various places, which IMO compounds the confusion in newcomers experienced with other languages. It's best, I think, to reject the idea that Python has variables, and think in terms of references instead. Any reference (with some very narrow specific exclusions, like ?None?) can be re-bound to any other object without regard to the previous binding. > We need to separate out the 'view' from the 'implementation' here. > Most developers I know, if looking at the code and without the > possibly dubious benefit of knowing that in Python 'everything is an > object' would not call this 'strong typing' Those people are confused, then. Python is strongly typed: objects always know their type, the type is always exact, and the type of an object can't be changed. This is always true regardless of whether the object is referred to zero, one, or many times. Python is dynamically typed: References (and hence names) don't have types. > It is OK to to make (possibly erroneous) observations isn't it? One of our long-time regulars (Aahz, whom I haven't seen for a long time, sadly) quipped that the best way to get correct information on Usenet is not to ask a question, but to post incorrect information. That's not a license for such behaviour, but an observation on its effectiveness. I'd say that so long as you phrase your assertions to indicate the level of confidence and possibility of error, that's okay. -- \ ?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 ian.g.kelly at gmail.com Wed Aug 22 20:10:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 22 Aug 2012 18:10:08 -0600 Subject: Objects in Python In-Reply-To: <87d32i1ntc.fsf@benfinney.id.au> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: On Wed, Aug 22, 2012 at 5:58 PM, Ben Finney wrote: > Those people are confused, then. Python is strongly typed: objects > always know their type, the type is always exact, and the type of an > object can't be changed. Except when it can. >>> class A: pass ... >>> class B: pass ... >>> a = A() >>> type(a) >>> isinstance(a, B) False >>> a.__class__ = B >>> type(a) >>> isinstance(a, A) False >>> isinstance(a, B) True Cheers, Ian From walterhurry at lavabit.com Wed Aug 22 21:19:49 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 23 Aug 2012 01:19:49 +0000 (UTC) Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: > Well I'm a beginner Then maybe you should read more and write less. From rosuav at gmail.com Wed Aug 22 22:02:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 12:02:16 +1000 Subject: Objects in Python In-Reply-To: <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> Message-ID: On Thu, Aug 23, 2012 at 5:03 AM, lipska the kat wrote: > On 22/08/12 19:15, Ian Kelly wrote: >> >> You're conflating "strong typing" with "static typing". Strong typing >> does not refer to restrictions on what type of data can be stored >> where, but to restrictions on how operations on that data can be >> intermixed. > > Yes of course I am, thank you for pointing that out. > I don't know why I have this overwhelming need to see variables explicitly > defined ... years of 'same old same old' I suppose. Python's object model is not fundamentally incompatible with a system of declared variables. I, too, like declaring my variables explicitly. There are quite a few advantages to it: 1) Scoping is extremely clear. (Leaving aside anomalous behaviour like Javascript's "var" declarations applying to a whole function.) You see a declaration, you know that variable exists there and further inside only. In a C-style language, that means it disappears at the corresponding close brace. 2) Related to the above, you can infinitely nest scopes. There's nothing wrong with having six variables called 'q'; you always use the innermost one. Yes, this can hurt readability, especially taken to this sort of stupid extreme, but that's a question for a style guide and not a language design. 3) Variable-name typos can be caught at parse time. In Python, if you misspell a variable, you've just made a new local variable. It has its downsides, too, of course; mainly that it's (in some people's opinion) syntactic salt. Why should I have to tell the interpreter/compiler what it can figure out by itself? It's duplicating information, and that's inefficient. It's like forcing all your integer constants to be given in both decimal and hex, to catch errors. I'm of the opinion that the benefits are worth the effort. Others disagree. It's hugely a matter of taste, and I'm just glad that there are enough languages around that we can all have what we want :) If you like the Python object model but want to add variable declarations, grab me off list and I'll tell you about my personal favorite language... ChrisA From djacobfeuerborn at gmail.com Wed Aug 22 22:28:23 2012 From: djacobfeuerborn at gmail.com (Dennis Jacobfeuerborn) Date: Wed, 22 Aug 2012 19:28:23 -0700 (PDT) Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wednesday, August 22, 2012 11:15:10 PM UTC+2, Ian wrote: > On Wed, Aug 22, 2012 at 1:40 PM, Dennis Jacobfeuerborn > > wrote: > > > I was thinking about something like that but the issue is that this really only works when you don't do any actual blocking work. I may be able to get around the sleep() but then I have to fetch the URL or do some other work that might block for a while so the get() trick doesn't work. > > > > At a lower level, it is possible to poll on both the pipe and the > > socket simultaneously. At this point though you might want to start > > looking at an asynchronous or event-driven framework like twisted or > > gevent. > I was looking at twisted and while the Agent class would allow me to make async request it doesn't seem to support setting a timeout or aborting the running request. That's really the important part since the http request is really the only thing that might block for a while. If I can make the request asynchronously and abort it when I receive a QUIT command from the parent then this would pretty much solve the issue. > > > Also the child process might not be able to deal with such an exit command at all for one reason or another so the only safe way to get rid of it is for the parent to kill it. > > > > I think you mean that it is the most "reliable" way. In general, the > > only "safe" way to cause a process to exit is the cooperative > > approach, because it may otherwise leave external resources such as > > file data in an unexpected state that could cause problems later. > True but the child is doing nothing but making http requests and reporting the result to the parent so killing the process shouldn't be too much of a deal in this case. A segfault in an Apache worker process is very similar in that it's an uncontrolled termination of the process and that works out fine. > > > The better option would be to not use a shared queue for communication and instead use only dedicated pipes/queues for each child process but the doesn't seem to be a way to wait for a message from multiple queues/pipes. If that were the case then I could simply kill the child and get rid of the respective pipes/queues without affecting the other processes or communication channels. > > > > Assuming that you're using a Unix system: > > > > from select import select > > > > while True: > > ready, _, _ = select(pipes, [], [], timeout) > > if not ready: > > # process timeout > > else: > > for pipe in ready: > > message = pipe.get() > > # process message That looks like a workable solution. When I decide to kill a worker process I can remove the pipe from the pipes list and discard it since it's not shared. Regards, Dennis From djacobfeuerborn at gmail.com Wed Aug 22 22:28:23 2012 From: djacobfeuerborn at gmail.com (Dennis Jacobfeuerborn) Date: Wed, 22 Aug 2012 19:28:23 -0700 (PDT) Subject: How to properly implement worker processes In-Reply-To: References: Message-ID: On Wednesday, August 22, 2012 11:15:10 PM UTC+2, Ian wrote: > On Wed, Aug 22, 2012 at 1:40 PM, Dennis Jacobfeuerborn > > wrote: > > > I was thinking about something like that but the issue is that this really only works when you don't do any actual blocking work. I may be able to get around the sleep() but then I have to fetch the URL or do some other work that might block for a while so the get() trick doesn't work. > > > > At a lower level, it is possible to poll on both the pipe and the > > socket simultaneously. At this point though you might want to start > > looking at an asynchronous or event-driven framework like twisted or > > gevent. > I was looking at twisted and while the Agent class would allow me to make async request it doesn't seem to support setting a timeout or aborting the running request. That's really the important part since the http request is really the only thing that might block for a while. If I can make the request asynchronously and abort it when I receive a QUIT command from the parent then this would pretty much solve the issue. > > > Also the child process might not be able to deal with such an exit command at all for one reason or another so the only safe way to get rid of it is for the parent to kill it. > > > > I think you mean that it is the most "reliable" way. In general, the > > only "safe" way to cause a process to exit is the cooperative > > approach, because it may otherwise leave external resources such as > > file data in an unexpected state that could cause problems later. > True but the child is doing nothing but making http requests and reporting the result to the parent so killing the process shouldn't be too much of a deal in this case. A segfault in an Apache worker process is very similar in that it's an uncontrolled termination of the process and that works out fine. > > > The better option would be to not use a shared queue for communication and instead use only dedicated pipes/queues for each child process but the doesn't seem to be a way to wait for a message from multiple queues/pipes. If that were the case then I could simply kill the child and get rid of the respective pipes/queues without affecting the other processes or communication channels. > > > > Assuming that you're using a Unix system: > > > > from select import select > > > > while True: > > ready, _, _ = select(pipes, [], [], timeout) > > if not ready: > > # process timeout > > else: > > for pipe in ready: > > message = pipe.get() > > # process message That looks like a workable solution. When I decide to kill a worker process I can remove the pipe from the pipes list and discard it since it's not shared. Regards, Dennis From steve+comp.lang.python at pearwood.info Thu Aug 23 00:07:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 04:07:00 GMT Subject: Methods versus functions [was Re: Objects in Python] References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <503541B7.2050908@mrabarnett.plus.com> Message-ID: <5035ac63$0$1645$c3e8da3$76491128@news.astraweb.com> On Wed, 22 Aug 2012 21:46:29 +0100, Mark Lawrence wrote: >> On 22/08/2012 20:45, lipska the kat wrote: >>> >>> compare this to a function declaration in Python >>> >>> def foo(self): [...] > Looking at the self I'm assuming that's a method and not a function. Actually, it is a function. It doesn't get turned into a method until you try to use it. The way methods work in Python is this: Function objects are created by the "def" statement, regardless of whether that is inside a class or not. So: class X(object): def spam(self, value): pass creates a single function object which takes one argument, self, and sticks in in the class namespace X.__dict__['spam'] = spam When you look up the name "spam" on an X instance: x = X() x.spam(42) Python does it's usual attribute lookup stuff, finds the name "spam" in the class namespace, and extracts the function object. So far that's just ordinary attribute access. This is where it gets interesting... Function objects are *descriptors*, which means that they have a __get__ method: py> (lambda x: None).__get__ Python sees that __get__ method and calls it with some appropriate arguments (the class object and the instance object, I believe) and the __get__ method constructs a method on the fly, handles the automatic bind- instance-to-self magic, and returns the method object. And then finally Python calls the method object with whatever arguments you provided. As they say, "You can solve any problem in computer science with sufficient layers of indirection". This descriptor protocol, as they call it, is the mechanism behind methods, class methods, static methods, properties, and probably other things as well. You can do all sorts of funky things with descriptors -- google for "descriptor protocol", "data descriptor", "non-data descriptor" etc. if you are interested. Here's a trivial, but useful, one: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 23 00:11:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 04:11:52 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> Message-ID: <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> On Thu, 23 Aug 2012 12:02:16 +1000, Chris Angelico wrote: > 2) Related to the above, you can infinitely nest scopes. There's nothing > wrong with having six variables called 'q'; you always use the innermost > one. Yes, this can hurt readability Well, there you go. There *is* something wrong with having six variables called 'q'. Namespaces and scopes are work-arounds for the fact that, while there are an infinite number of possible names, most of the good ones are already taken. Namespaces and scopes mean that I can use a name "q" even though I've already used it for something else, but there is still cost to re-using names (even if that cost is sometimes trivial). -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 23 00:14:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 04:14:55 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> On Thu, 23 Aug 2012 01:19:49 +0000, Walter Hurry wrote: > On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: > >> Well I'm a beginner > > Then maybe you should read more and write less. I think that's uncalled for. Lipska isn't trolling. He's making observations as he sees them. The fact that they're sometimes wrong is not a reason to effectively tell him to STFU. Better the misconception which is spoken allowed and corrected, then the one which is kept quiet and festers. -- Steven From steve+comp.lang.python at pearwood.info Thu Aug 23 00:34:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 04:34:52 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <5035b2eb$0$1645$c3e8da3$76491128@news.astraweb.com> On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: > We need to separate out the 'view' from the 'implementation' here. Most > developers I know, if looking at the code and without the possibly > dubious benefit of knowing that in Python 'everything is an object' > would not call this 'strong typing' Most developers are wrong :) A very useful resource to read is "What To Know Before Debating Type Systems", which was put on the internet, lost, then found and put back up here: http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ I don't *quite* go so far as to agree that "strong typing" and "weak typing" are meaningless, but they certainly don't mean quite as much as people sometimes think. It also includes this brilliant quote: "I find it amusing when novice programmers believe their main job is preventing programs from crashing. ... More experienced programmers realize that correct code is great, code that crashes could use improvement, but incorrect code that doesn?t crash is a horrible nightmare." In Python's case, we say: 1) objects are strongly typed -- every object has a type, which is usually immutable and sometimes known at compile time; 2) names (what some people insist on calling variables) are not typed at all (with the exception of a handful of keywords like None); 3) most Python built-ins are strongly typed, and users are discouraged from writing excessively weakly-typed operations (you could write an int subclass that can be added to a string or a list, just as you can add it to a float, but you shouldn't); 4) there's a culture of preferring "duck typing", which is kind of an ad hoc form of interfaces, over strict type testing, so users are also discouraged from writing excessively strongly-typed operations (if you just need something you can iterate over, why insist that it must be a list and nothing but a list?). -- Steven From driscoll at cs.wisc.edu Thu Aug 23 00:49:17 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 22 Aug 2012 23:49:17 -0500 Subject: Objects in Python In-Reply-To: <87d32i1ntc.fsf@benfinney.id.au> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: <5035B64D.2080008@cs.wisc.edu> On 8/22/2012 18:58, Ben Finney wrote: > You haven't discovered anything about types; what you have discovered is > that Python name bindings are not variables. > > In fact, Python doesn't have variables ? not as C or Java programmers > would understand the term. What it has instead are references to objects > (with names as one kind of reference). OK, I've seen this said a few times, and I have to ask: what do you mean by this? I consider myself pretty decent at Python and other languages, and I really don't get it. Especially the comparison to Java variables. Java programmers are quite used to variables which are references to objects: everything that's not a primitive type is a reference, and it's kinda hard to determine whether primitives are references or actual primitives. And many other languages have reference behavior and still call their bindings "variables", e.g. Scheme. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Thu Aug 23 01:26:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 15:26:10 +1000 Subject: Objects in Python In-Reply-To: <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Aug 23, 2012 at 2:11 PM, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 12:02:16 +1000, Chris Angelico wrote: > >> 2) Related to the above, you can infinitely nest scopes. There's nothing >> wrong with having six variables called 'q'; you always use the innermost >> one. Yes, this can hurt readability > > Well, there you go. There *is* something wrong with having six variables > called 'q'. But it's the same thing that's wrong with having one variable called 'q', when that variable would be better called 'invoice' because it's iterating over your invoices, or 'item' when it's iterating over the lines of one invoice. Python doesn't stop you from doing that; it's not the language's job to enforce useful variable names. ChrisA From rosuav at gmail.com Thu Aug 23 01:33:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 15:33:33 +1000 Subject: Objects in Python In-Reply-To: <5035B64D.2080008@cs.wisc.edu> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035B64D.2080008@cs.wisc.edu> Message-ID: On Thu, Aug 23, 2012 at 2:49 PM, Evan Driscoll wrote: > On 8/22/2012 18:58, Ben Finney wrote: >> You haven't discovered anything about types; what you have discovered is >> that Python name bindings are not variables. >> >> In fact, Python doesn't have variables ? not as C or Java programmers >> would understand the term. What it has instead are references to objects >> (with names as one kind of reference). > > OK, I've seen this said a few times, and I have to ask: what do you mean > by this? I consider myself pretty decent at Python and other languages, > and I really don't get it. Simple example that'll work in many languages: x = 1; In C, this means: Assign the integer 1 to the variable x (possibly with implicit type casting, eg to floating point). In Java or C++, this means: Assign the integer 1 to the variable x. Ditto, but possibly 'x' is actually a class member etc rather than a simple variable. In Python, this means: Make the name x now refer to the object 1. Whatever x had before is de-referenced by one (in a simple refcounting situation, that may result in the object being destroyed), and the object referred to by the literal 1 is now pointed to by x. Names are just one kind of reference because complex objects can have unnamed references. For instance: foo = [1, 2, 3] foo[1] = "Hello, world!" The second element of foo just got rebound in exactly the same way x did, but it doesn't have a name of its own. Does that sort things out, or just make things more confusing? ChrisA From steve+comp.lang.python at pearwood.info Thu Aug 23 02:55:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 06:55:33 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> On Wed, 22 Aug 2012 23:49:17 -0500, Evan Driscoll wrote: > On 8/22/2012 18:58, Ben Finney wrote: >> You haven't discovered anything about types; what you have discovered >> is that Python name bindings are not variables. >> >> In fact, Python doesn't have variables ? not as C or Java programmers >> would understand the term. What it has instead are references to >> objects (with names as one kind of reference). > > OK, I've seen this said a few times, and I have to ask: what do you mean > by this? I consider myself pretty decent at Python and other languages, > and I really don't get it. I think the point that Ben would like to make is that while "name binding" is a specific kind of "variable", the word "variable" comes with too much baggage from the old-school C, Pascal etc. style of variables- are-named-memory-locations. Most of the time, the differences are unimportant, but when they are important, if your mental image is that Python "variables" (name bindings) are like C or Pascal "variables" (memory locations), you're going to get confused. [...] > And many other languages have reference behavior and still call their > bindings "variables", e.g. Scheme. Yes, well in my opinion, a great deal of the terminology in use is absolutely dire. E.g. both Ruby and Java have the exact same parameter binding strategy as Python, only the Ruby people call theirs "call by reference" and the Java people call theirs "call by value", *both of which are identical*, and NEITHER of which are the same thing that C and Pascal programmers will understand by call by value *or* call by reference. http://mail.python.org/pipermail/tutor/2010-December/080505.html -- Steven From john_ladasky at sbcglobal.net Thu Aug 23 03:34:25 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 23 Aug 2012 00:34:25 -0700 (PDT) Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <5c2b4fbc-ca67-4171-a1aa-480f8d9c6fad@googlegroups.com> On Wednesday, August 22, 2012 3:28:18 AM UTC-7, Kamil Kuduk wrote: > less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" Say what? Yes, you could do a crazy regex at the Linux prompt. But... will you be able to retain that insane syntax in your head until the NEXT time you need to write something like that? Probably not, unless you write awk all day. That, ladies and gentlemen, is why there's Python. I stopped programming for about 18 months a while back. When I came back to Python and needed to do it again, I picked up right where I left off. From john_ladasky at sbcglobal.net Thu Aug 23 03:34:25 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 23 Aug 2012 00:34:25 -0700 (PDT) Subject: help me debug my "word capitalizer" script In-Reply-To: References: Message-ID: <5c2b4fbc-ca67-4171-a1aa-480f8d9c6fad@googlegroups.com> On Wednesday, August 22, 2012 3:28:18 AM UTC-7, Kamil Kuduk wrote: > less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" Say what? Yes, you could do a crazy regex at the Linux prompt. But... will you be able to retain that insane syntax in your head until the NEXT time you need to write something like that? Probably not, unless you write awk all day. That, ladies and gentlemen, is why there's Python. I stopped programming for about 18 months a while back. When I came back to Python and needed to do it again, I picked up right where I left off. From fgnu32 at yahoo.com Thu Aug 23 03:52:13 2012 From: fgnu32 at yahoo.com (Fg Nu) Date: Thu, 23 Aug 2012 00:52:13 -0700 (PDT) Subject: Data cleaning workouts Message-ID: <1345708333.82619.YahooMailNeo@web122405.mail.ne1.yahoo.com> List folk, I am a newbie trying to get used to Python. I was wondering if anyone knows of web resources that teach good practices in data cleaning and management for statistics/analytics/machine learning, particularly using Python. Ideally, these would be exercises of the form: here is some horrible raw data --> here is what it should look like after it has been cleaned. Guidelines about steps that should always be taken, practices that should be avoided; basically, workflow of data analysis in Python with special emphasis on the cleaning part. From janpeterr at freenet.de Thu Aug 23 03:56:31 2012 From: janpeterr at freenet.de (Jan Riechers) Date: Thu, 23 Aug 2012 10:56:31 +0300 Subject: New image and color management library for Python 2+3 In-Reply-To: References: <503123FA.4040301@freenet.de> Message-ID: <5035E22F.2050704@freenet.de> On 20.08.2012 20:34, Christian Heimes wrote: > Am 19.08.2012 19:35, schrieb Jan Riechers: > > Hello Jan, > > we decided against ImageMagick and pgmagick for several reasons. For one > we were already using FreeImage in other projects (Delphi projects and > through ctypes binding with FreeImagePy). > [SNIP] > > The Python bindings for ImageMagick weren't that good and today they are > still buggy. For example I'm not able to set the resize filter to a high > quality setting like Catmull-Rom-Spline with the most recent version of > pgmagick. filterType() doesn't do anything. The output image still has > the same MD5 hash. > > ImageMagick and PIL were missing important features, too. For example > both libraries don't support color management with lcms2 nor cached > color transformations nor introspection of ICC profiles. They use lcms1. > The color profiles explains - perhaps it would be interesting still to test out your library with regular images (without color profiles) against ImageMagick, just to compare the raw speed of both solutions. In my case I really would love to see if there is a even higher performance solution available as I plan to serve a lot of users a time and especially keeping the Input/Output during file writing low would be very helpful. > >> Can you perhaps test your solution with ImageMagick (as it is used >> widely) it would be interesting so. > > I've added some more benchmark results to the README.txt (PIL with > non-standard libjpeg-turbo and pgmagick). The results are available at > https://bitbucket.org/tiran/smc.freeimage > > Spoiler: pgmagick isn't faster and its resize filter settings don't work. > Thank you for the additional benchmarks, nice to read! I will try your library out to see how it compares to old-pendant ImageMagick with Pypy 1.9 | Wand / Pillow (Pil fork for pypy) and Python 2.7.3 PIL / ImageMagick - perhaps I can deliver you those numbers too - for those folks not completely in need of a color profile aware version but to compare raw numbers Perhaps it would also be nice to see if and how it works with Pypy too Jan From lipskathekat at yahoo.co.uk Thu Aug 23 04:03:19 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 23 Aug 2012 09:03:19 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 23/08/12 02:19, Walter Hurry wrote: > On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: > >> Well I'm a beginner > > Then maybe you should read more and write less. Really ? I read all the responses to my posts and learn more from them in less time than I ever have from reading the 'documentation' If you don't like it then don't read it. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From lipskathekat at yahoo.co.uk Thu Aug 23 04:10:55 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 23 Aug 2012 09:10:55 +0100 Subject: Objects in Python In-Reply-To: <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <4ICdnasny6sSeKjNnZ2dnUVZ8t-dnZ2d@bt.com> On 23/08/12 05:14, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 01:19:49 +0000, Walter Hurry wrote: > >> On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: >> >>> Well I'm a beginner >> >> Then maybe you should read more and write less. > > I think that's uncalled for. Lipska isn't trolling. He's making > observations as he sees them. The fact that they're sometimes wrong is > not a reason to effectively tell him to STFU. > > Better the misconception which is spoken allowed and corrected, then the > one which is kept quiet and festers. Excellent advice as usual, but I'm more than capable of looking after myself thank you. Nobody has ever succeeded in making me STFU yet :-) When that day comes I'll retire to the garden lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jamie at kode5.net Thu Aug 23 04:13:04 2012 From: jamie at kode5.net (Jamie Paul Griffin) Date: Thu, 23 Aug 2012 09:13:04 +0100 Subject: Books? In-Reply-To: <5034EE00.7080909@it.uu.se> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> <5034e6dd$0$6574$c3e8da3$5496439d@news.astraweb.com> <5034EE00.7080909@it.uu.se> Message-ID: <20120823081304.GA17762@kontrol.kode5.net> [ Virgil Stokes wrote on Wed 22.Aug'12 at 16:34:40 +0200 ] > On 22-Aug-2012 16:04, Steven D'Aprano wrote: > > On Tue, 21 Aug 2012 18:36:50 -0700, Anonymous Group wrote: > > > >> What books do you recomend for learning python? Preferably free and/or > >> online. > > Completely by coincidence, I have just discovered, and I mean *literally* > > just a few minutes ago, this book: > > > > http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-30292-3 > > > > http://codingcat.com/knjige/python/A%20Primer%20on%20Scientific%20Programming%20with%20Python.pdf > > > > > > I wish it had existed when I was a beginner! I haven't read the whole > > thing, but dammit it looks like exactly the sort of book I would have > > adored as a newbie. (Your mileage may vary.) > > > > > > > I second this --- this is a very good book IMHO. I have the first edition (2009) > and have found it very useful. > > Good tip! absolutely. I've been reading it most of last night, certainly a great learning resource. From jarausch at igpm.rwth-aachen.de Thu Aug 23 04:30:05 2012 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 23 Aug 2012 08:30:05 GMT Subject: Python3.3 email policy date field Message-ID: Hi, in response to a bug report I got the follow helpful comments from R. David Murray. Many thanks to him. (Unfortunately, I don't know his email, so I can write him directly) To generate an email (with non-ascii letters) R. David Murray wrote: >>> But even better, so will this: >>> m = Message(policy=policy.SMTP) >>> m['From'] = "G?nter Wei?e " This works, but now I cannot add a date field Trying m['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') I get Traceback (most recent call last): File "Test_EMail_Py3_4.py", line 23, in msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') File "/usr/lib64/python3.3/email/message.py", line 359, in __setitem__ self._headers.append(self.policy.header_store_parse(name, val)) File "/usr/lib64/python3.3/email/policy.py", line 119, in header_store_parse return (name, self.header_factory(name, value)) File "/usr/lib64/python3.3/email/headerregistry.py", line 583, in __call__ return self[name](name, value) File "/usr/lib64/python3.3/email/headerregistry.py", line 194, in __new__ cls.parse(value, kwds) File "/usr/lib64/python3.3/email/headerregistry.py", line 300, in parse value = utils.parsedate_to_datetime(value) File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime *dtuple, tz = __parsedate_tz(data) TypeError: 'NoneType' object is not iterable Many thanks for a hint, Helmut. From jpiitula at ling.helsinki.fi Thu Aug 23 04:59:56 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 23 Aug 2012 11:59:56 +0300 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 22 Aug 2012 23:49:17 -0500, Evan Driscoll wrote: > > > On 8/22/2012 18:58, Ben Finney wrote: > >> You haven't discovered anything about types; what you have > >> discovered is that Python name bindings are not variables. > >> > >> In fact, Python doesn't have variables ? not as C or Java > >> programmers would understand the term. What it has instead are > >> references to objects (with names as one kind of reference). > > > > OK, I've seen this said a few times, and I have to ask: what do > > you mean by this? I consider myself pretty decent at Python and > > other languages, and I really don't get it. > > I think the point that Ben would like to make is that while "name > binding" is a specific kind of "variable", the word "variable" comes > with too much baggage from the old-school C, Pascal etc. style of > variables- are-named-memory-locations. Most of the time, the > differences are unimportant, but when they are important, if your > mental image is that Python "variables" (name bindings) are like C > or Pascal "variables" (memory locations), you're going to get > confused. I don't get it either. To me the python-has-no-variables campaigners seem confused. As far as I can see, Python can be seen in terms of variables bound to (locations containing) values perfectly well, in a way that should be quite familiar to people who come from Java (or Lisp, Scheme like me). It is very bad that people campaign here against the terminology that is used in the official Python language reference and the Python tutorial. Best would be to simply explain how the variables, values, assignment, and calls work in Python, the way the language reference and tutorial actually do. If the no-variables campaign is to continue, the language reference and the tutorial should be changed to match. I would consider it a mad move, but the current practice of badmouthing the official wording is not healthy either. > [...] > > And many other languages have reference behavior and still call > > their bindings "variables", e.g. Scheme. > > Yes, well in my opinion, a great deal of the terminology in use is > absolutely dire. E.g. both Ruby and Java have the exact same > parameter binding strategy as Python, only the Ruby people call > theirs "call by reference" and the Java people call theirs "call by > value", *both of which are identical*, and NEITHER of which are the > same thing that C and Pascal programmers will understand by call by > value *or* call by reference. That's indeed such a mess that those call-by-* terms may be now best avoided. I would also avoid any distinction between an object and a "reference" to an object, except as an implementation detail. It's not helpful. It only leads to the confusion where it seems that Java (or Python) does not actually have objects at all, only references to objects, which in turn don't exist, so, er, what. The swap function is helpful. Why doesn't it work? Because it assigns to different variables that are local to the function. If I pass it a list, why can it then swap the elements? Because that is the same list, not a copy. Get used to it. Works for me. From alt.mcarter at gmail.com Thu Aug 23 05:05:50 2012 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 23 Aug 2012 02:05:50 -0700 (PDT) Subject: Guarding arithmetic Message-ID: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: def safe(x): # WHAT WOULD DEFINE HERE? print safe(666) # prints 666 print safe(1/0) # prints 42 I don't see how such a function could be defined. Is it possible? From rosuav at gmail.com Thu Aug 23 05:16:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 19:16:08 +1000 Subject: Guarding arithmetic In-Reply-To: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On Thu, Aug 23, 2012 at 7:05 PM, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? That can work ONLY if the division of 1/0 doesn't raise an exception. This is why the concept of NaN exists; I'm not sure if there's a way to tell Python to return NaN instead of bombing, but it's most likely only possible with floating point, not integer. However, there's an easier way. try: print 1/0 except ZeroDivisionError: print 42 Catch the exception and do with it what you will. ChrisA From lipskathekat at yahoo.co.uk Thu Aug 23 05:19:36 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 23 Aug 2012 10:19:36 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: On 22/08/12 22:31, Evan Driscoll wrote: > On 08/22/2012 02:45 PM, lipska the kat wrote: >> On 22/08/12 20:03, Evan Driscoll wrote: >>> Second, this concept isn't *so* unfamiliar to you. If I give you the >>> following Java code: >>> >>> void foo(Object o) { ... } >>> >> looking at this method declaration I can see that the method takes an >> argument of type Object (and just FYI class Object is not abstract and >> you can do Object o = new Object()) and does not return a value. >> I know that for the lifetime of this JVM, whatever o turns out to be it >> will always be an Object. I can't assign a primitive to o as ints chars >> floats etc are certainly not Objects. There are certain invariants that >> give me a warm and comfortable feeling inside. > > I'm not saying it's nothing, but "can't assign a primitive" isn't much > of an invariant in the broad scheme of things Well we don't want to turn this into a language comparison thread do we, that might upset too many people but I can't remember ever writing a method that took an Object as argument, you just can't do that much with an Object. I do however often write methods that take an interface as argument knowing that in future, any classes I write that implement this interface would just work thanks to subtype polymorphism A method 'declaration' such as this in an interface Product getProductByBarcode(Barcode b) throws CrappyProductException; tells me a whole lot about what the 'definition' in an implementing class might do, in fact I might well get away with just reading the interface and using the method without having to delve into the code. And I think this is the nub of the problem at the moment. I'm in a particular mindset, almost 'locked in' you might say and when I see a Python function that doesn't give me what I need straight away I get annoyed. I will get over it. > when you can pass items as > diverse as lists, GUI buttons, files, etc. I would say it's more like if > you see 'int x' then *that* imposes a pretty big invariant, but passing > 'Object' imposes almost nothing. Well you may be able to pass them in but you couldn't really do anything meaningful with them as you are restricted to operations on Object, I suppose you could pepper your code with tests to check the runtime type of a reference but it all gets a bit messy. [snip] > Thus *all* > Python variables are essentially references.) That makes sense Thanks for taking the time to reply. It really is most valuable to me. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From alt.mcarter at gmail.com Thu Aug 23 05:22:30 2012 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 23 Aug 2012 02:22:30 -0700 (PDT) Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On Thursday, 23 August 2012 10:16:08 UTC+1, Chris Angelico wrote: > On Thu, Aug 23, 2012 at 7:05 PM, Mark Carter <> wrote: > > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. > only possible with floating point, not integer. > > try: > print 1/0 > except ZeroDivisionError: > print 42 OK, so it looks like a solution doesn't exist to the problem as specified. I guess it's something that only a language with macros could accommodate. From alt.mcarter at gmail.com Thu Aug 23 05:22:30 2012 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 23 Aug 2012 02:22:30 -0700 (PDT) Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On Thursday, 23 August 2012 10:16:08 UTC+1, Chris Angelico wrote: > On Thu, Aug 23, 2012 at 7:05 PM, Mark Carter <> wrote: > > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. > only possible with floating point, not integer. > > try: > print 1/0 > except ZeroDivisionError: > print 42 OK, so it looks like a solution doesn't exist to the problem as specified. I guess it's something that only a language with macros could accommodate. From gandalf at shopzeus.com Thu Aug 23 05:23:20 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 23 Aug 2012 11:23:20 +0200 Subject: Guarding arithmetic In-Reply-To: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: <5035F688.7020307@shopzeus.com> On 2012-08-23 11:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? You are very vague. "There is an error" - but what kind of error? To catch all possible exceptions you could do: def unsafe(x): # put your code here... def safe(x): try: return unsafe(x) except: return 42 Generally, it is a bad idea. Exception handlers were invented because they give you a way to handle any error in the call chain. When an exception occurs, the interpreter will start searching for an appropriate exception handler traversing up in the call chain. By converting exceptions into return values, you are bypassing this search. Then you will have to write conditions instead of exception handlers inside ALL methods in the call chain, creating a "manual" search for the handler of the exception. In most cases, this will make your code difficult, error prone and hard to read. In some special cases, this can be a good idea to do. Can you please let us know when and how would you like to use it? From gandalf at shopzeus.com Thu Aug 23 05:28:56 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 23 Aug 2012 11:28:56 +0200 Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: <5035F7D8.601@shopzeus.com> > That can work ONLY if the division of 1/0 doesn't raise an exception. > This is why the concept of NaN exists; I'm not sure if there's a way > to tell Python to return NaN instead of bombing, but it's most likely > only possible with floating point, not integer. For integers, Python will always raise an exception when you try to divide by zero. And integers has nothing to do with NaN. Because NaN is meaningful for floating point numbers only. Python can be compiled to raise floating point exceptions. (On Python 2, this is a compile time option: FPECTL. On Python 3, this can be configured runtime: http://docs.python.org/library/fpectl.html ) From rosuav at gmail.com Thu Aug 23 05:29:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 19:29:20 +1000 Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On Thu, Aug 23, 2012 at 7:22 PM, Mark Carter wrote: > OK, so it looks like a solution doesn't exist to the problem as specified. I guess it's something that only a language with macros could accommodate. You're asking for a function to prevent the evaluation of its arguments from throwing an error. That's fundamentally not possible with a function call. Exception handling is a much more normal way of handling it; though if you prefer, you could wrap it up in a function like this: def safe_div(num,denom): try: return num/denom except ZeroDivisionError: return 42 print safe_div(1,0) # still a poor name though ChrisA From rosuav at gmail.com Thu Aug 23 05:30:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Aug 2012 19:30:37 +1000 Subject: Guarding arithmetic In-Reply-To: <5035F7D8.601@shopzeus.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <5035F7D8.601@shopzeus.com> Message-ID: On Thu, Aug 23, 2012 at 7:28 PM, Laszlo Nagy wrote: >> That can work ONLY if the division of 1/0 doesn't raise an exception. >> This is why the concept of NaN exists; I'm not sure if there's a way >> to tell Python to return NaN instead of bombing, but it's most likely >> only possible with floating point, not integer. > > For integers, Python will always raise an exception when you try to divide > by zero. And integers has nothing to do with NaN. Because NaN is meaningful > for floating point numbers only. Python can be compiled to raise floating > point exceptions. (On Python 2, this is a compile time option: FPECTL. On > Python 3, this can be configured runtime: > http://docs.python.org/library/fpectl.html ) Thanks, that's the sort of thing I meant. I'm not familiar enough with Python's floating point handler to know those details. ChrisA From alt.mcarter at gmail.com Thu Aug 23 05:47:38 2012 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 23 Aug 2012 02:47:38 -0700 (PDT) Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: <73b19a13-5c2d-4ee8-b7e3-a9ee3c75ec37@googlegroups.com> On Thursday, 23 August 2012 10:23:20 UTC+1, Laszlo Nagy wrote: > On 2012-08-23 11:05, Mark Carter wrote: > You are very vague. "There is an error" - but what kind of error? Assume that it doesn't matter. > In some special cases, this can be a good idea to do. Those are the cases that I'm interested in. From alt.mcarter at gmail.com Thu Aug 23 05:47:38 2012 From: alt.mcarter at gmail.com (Mark Carter) Date: Thu, 23 Aug 2012 02:47:38 -0700 (PDT) Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: <73b19a13-5c2d-4ee8-b7e3-a9ee3c75ec37@googlegroups.com> On Thursday, 23 August 2012 10:23:20 UTC+1, Laszlo Nagy wrote: > On 2012-08-23 11:05, Mark Carter wrote: > You are very vague. "There is an error" - but what kind of error? Assume that it doesn't matter. > In some special cases, this can be a good idea to do. Those are the cases that I'm interested in. From __peter__ at web.de Thu Aug 23 06:11:21 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Aug 2012 12:11:21 +0200 Subject: Guarding arithmetic References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument > passed if there is no error, and 42 if there is one. So the setup is > something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? 1/0 is evaluated before safe() is called. Therefore safe() has no chance to catch the exception. You have to move the evaluation into the safe() function: >>> def safe(deferred, default=42, exception=Exception): ... try: ... return deferred() ... except exception: ... return default ... >>> print safe(lambda: 666) 666 >>> print safe(lambda: 1/0) 42 From gandalf at shopzeus.com Thu Aug 23 07:01:47 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Thu, 23 Aug 2012 13:01:47 +0200 Subject: Guarding arithmetic In-Reply-To: References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: <50360D9B.30303@shopzeus.com> >>>> def safe(deferred, default=42, exception=Exception): > ... try: > ... return deferred() > ... except exception: > ... return default What a beautiful solution! I was wondering if the following would be possible: def test(thing, default, *exc_classes): try: thing() except *exc_classes: return default But it is syntactically invalid. Here is a workaround that is not so beautiful: def test(thing, default, *exc_classes): try: thing() except Exception, e: for cls in exc_classes: if isinstance(e,cls): return default raise print test( (lambda: 1/0), -1, ValueError, ZeroDivisionError) # prints -1 From python at mrabarnett.plus.com Thu Aug 23 07:21:25 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Aug 2012 12:21:25 +0100 Subject: Guarding arithmetic In-Reply-To: <50360D9B.30303@shopzeus.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <50360D9B.30303@shopzeus.com> Message-ID: <50361235.8060600@mrabarnett.plus.com> On 23/08/2012 12:01, Laszlo Nagy wrote: > >>>>> def safe(deferred, default=42, exception=Exception): >> ... try: >> ... return deferred() >> ... except exception: >> ... return default > > What a beautiful solution! I was wondering if the following would be > possible: > > > def test(thing, default, *exc_classes): > try: > thing() > except *exc_classes: > return default > > > But it is syntactically invalid. > > Here is a workaround that is not so beautiful: > > > def test(thing, default, *exc_classes): > try: > thing() > except Exception, e: > for cls in exc_classes: > if isinstance(e,cls): > return default > raise > > print test( (lambda: 1/0), -1, ValueError, ZeroDivisionError) # prints -1 > The 'except' clause accepts a tuple of exception classes, so this works: def test(thing, default, *exc_classes): try: thing() except exc_classes: return default From laddosingh at gmail.com Thu Aug 23 07:25:34 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Thu, 23 Aug 2012 04:25:34 -0700 (PDT) Subject: Unittest - testing for filenames and filesize Message-ID: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Hi. I need help with an assignment and I hope you guys can guide me in the right direction. This is the code: ------------------ """ Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) def test_1(self): "Verify creation of files is possible" for filename in ("this.txt", "that.txt", "the_other.txt"): f = open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) def test_2(self): "Verify that current directory is empty" self.assertEqual(glob.glob("*"), [], "Directory not empty") def tearDown(self): os.chdir(self.origdir) shutil.rmtree(self.dirname) ------------- I need to modify this code as following: 1. The test_1() method includes code to verify that the test directory contains only the files created by the for loop. Hint: You might create a set containing the list of three filenames, and then create a set from the os.listdir() method. 2. A test_3() method creates a binary file that contains exactly a million bytes, closes it and then uses os.stat to verify that the file on disk is of the correct length (with os.stat, statinfo.st_size returns the size in bytes). I'm new to Python programming so I don't know where to put the set in point 1. Before the test or under test1. Would appreciate pointers and solutions (with explanation)for both point 1 and 2. Thank you in advance. T From __peter__ at web.de Thu Aug 23 07:28:07 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Aug 2012 13:28:07 +0200 Subject: Guarding arithmetic References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <50360D9B.30303@shopzeus.com> Message-ID: Laszlo Nagy wrote: >>>>> def safe(deferred, default=42, exception=Exception): >> ... try: >> ... return deferred() >> ... except exception: >> ... return default > > What a beautiful solution! I was wondering if the following would be > possible: > > > def test(thing, default, *exc_classes): > try: > thing() > except *exc_classes: > return default > > > But it is syntactically invalid. The except clause allows a tuple of exceptions: >>> def safe(deferred, default, *exceptions): ... try: ... return deferred() ... except exceptions: ... return default ... >>> safe(lambda: 1/0, -1, ValueError, ZeroDivisionError) -1 From python at mrabarnett.plus.com Thu Aug 23 07:28:55 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Aug 2012 12:28:55 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <503613F7.7010907@mrabarnett.plus.com> On 23/08/2012 09:59, Jussi Piitulainen wrote: > Steven D'Aprano writes: >> On Wed, 22 Aug 2012 23:49:17 -0500, Evan Driscoll wrote: >> >> > On 8/22/2012 18:58, Ben Finney wrote: >> >> You haven't discovered anything about types; what you have >> >> discovered is that Python name bindings are not variables. >> >> >> >> In fact, Python doesn't have variables ? not as C or Java >> >> programmers would understand the term. What it has instead are >> >> references to objects (with names as one kind of reference). >> > >> > OK, I've seen this said a few times, and I have to ask: what do >> > you mean by this? I consider myself pretty decent at Python and >> > other languages, and I really don't get it. >> >> I think the point that Ben would like to make is that while "name >> binding" is a specific kind of "variable", the word "variable" comes >> with too much baggage from the old-school C, Pascal etc. style of >> variables- are-named-memory-locations. Most of the time, the >> differences are unimportant, but when they are important, if your >> mental image is that Python "variables" (name bindings) are like C >> or Pascal "variables" (memory locations), you're going to get >> confused. > > I don't get it either. To me the python-has-no-variables campaigners > seem confused. As far as I can see, Python can be seen in terms of > variables bound to (locations containing) values perfectly well, in a > way that should be quite familiar to people who come from Java (or > Lisp, Scheme like me). > [snip] In Java a variable exists even when it has not been assigned a value. In Python, on the other hand, the basic model is that a 'variable' doesn't exist until it has been bound to an value (although, for efficiency reasons, that's not entirely true, because at compile time CPython will identify the local variables in a function and allocate a 'slot' for it). From as at sci.fi Thu Aug 23 07:34:38 2012 From: as at sci.fi (Anssi Saari) Date: Thu, 23 Aug 2012 14:34:38 +0300 Subject: python 6 compilation failure on RHEL References: Message-ID: Cameron Simpson writes: > My personal habit to to build with (adjust to match): > > --prefix=/usr/local/python-2.6.4 > > and put some symlinks in /usr/local/bin afterwards (python2.6, etc). There's actually a program for that, it's called stow. From python at mrabarnett.plus.com Thu Aug 23 07:36:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Aug 2012 12:36:01 +0100 Subject: Python3.3 email policy date field In-Reply-To: References: Message-ID: <503615A1.3010305@mrabarnett.plus.com> On 23/08/2012 09:30, Helmut Jarausch wrote: > Hi, > > in response to a bug report I got the follow helpful comments from R. David Murray. > Many thanks to him. (Unfortunately, I don't know his email, so I can write him directly) > > To generate an email (with non-ascii letters) > > R. David Murray wrote: > >>>> But even better, so will this: > >>>> m = Message(policy=policy.SMTP) >>>> m['From'] = "G?nter Wei?e " > > > > > This works, but now I cannot add a date field > > Trying > > m['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') > > I get > > Traceback (most recent call last): > File "Test_EMail_Py3_4.py", line 23, in > msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p') > File "/usr/lib64/python3.3/email/message.py", line 359, in __setitem__ > self._headers.append(self.policy.header_store_parse(name, val)) > File "/usr/lib64/python3.3/email/policy.py", line 119, in header_store_parse > return (name, self.header_factory(name, value)) > File "/usr/lib64/python3.3/email/headerregistry.py", line 583, in __call__ > return self[name](name, value) > File "/usr/lib64/python3.3/email/headerregistry.py", line 194, in __new__ > cls.parse(value, kwds) > File "/usr/lib64/python3.3/email/headerregistry.py", line 300, in parse > value = utils.parsedate_to_datetime(value) > File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime > *dtuple, tz = __parsedate_tz(data) > TypeError: 'NoneType' object is not iterable > From what I've tried, it looks like the date can't be a string: >>> m['Date'] = datetime.datetime.utcnow() >>> m['Date'] 'Thu, 23 Aug 2012 11:33:20 -0000' From oscar.benjamin at bristol.ac.uk Thu Aug 23 08:12:18 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Thu, 23 Aug 2012 13:12:18 +0100 Subject: Guarding arithmetic In-Reply-To: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On 23 August 2012 10:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument > passed if there is no error, and 42 if there is one. So the setup is > something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? > It isn't possible to define a function that will do this as the function will never be called if an exception is raised while evaluating its arguments. Depending on your real problem is a context-manager might do what you want: >>> from contextlib import contextmanager >>> @contextmanager ... def safe(default): ... try: ... yield default ... except: ... pass ... >>> with safe(42) as x: ... x = 1/0 ... >>> x 42 >>> with safe(42) as x: ... x = 'qwe' ... >>> x 'qwe' Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu Aug 23 08:28:55 2012 From: roy at panix.com (Roy Smith) Date: Thu, 23 Aug 2012 08:28:55 -0400 Subject: Unittest - testing for filenames and filesize References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: In article <6b0299df-bc24-406b-8d69-489e990d8e4f at googlegroups.com>, Tigerstyle wrote: > Hi. > > I need help with an assignment and I hope you guys can guide me in the right > direction. > [code elided] > 1. The test_1() method includes code to verify that the test directory > contains only the files created by the for loop. Hint: You might create a set > containing the list of three filenames, and then create a set from the > os.listdir() method. I'm not sure what your question is. The hint you give above pretty much tells you what to do. The basic issue here is that you started out with a list (well, tuple) of filenames. You can use os.listdir() to get a list of filenames that exist in the current directory. The problem is that you can't compare these two lists directly, because lists are ordered. Converting both lists to sets eliminates the ordering and lets you compare them. > I'm new to Python programming so I don't know where to put the set in point > 1. Before the test or under test1. I think you want to end up with something like: def test_1(self): "Verify creation of files is possible" filenames = ("this.txt", "that.txt", "the_other.txt") for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) dir_names = os.listdir() self.assertEqual(set(dir_names), set(filenames)) The above code isn't tested, but it should give you the gist of what you need to do. From jarausch at igpm.rwth-aachen.de Thu Aug 23 08:30:36 2012 From: jarausch at igpm.rwth-aachen.de (Helmut Jarausch) Date: 23 Aug 2012 12:30:36 GMT Subject: Python3.3 email policy date field References: Message-ID: On Thu, 23 Aug 2012 12:36:01 +0100, MRAB wrote: > From what I've tried, it looks like the date can't be a string: > > >>> m['Date'] = datetime.datetime.utcnow() > >>> m['Date'] > 'Thu, 23 Aug 2012 11:33:20 -0000' Many thanks - it's even easier! Waiting for Python 3.3 to become standard! Helmut. From wxjmfauth at gmail.com Thu Aug 23 08:47:29 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 23 Aug 2012 05:47:29 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... Message-ID: This is neither a complaint nor a question, just a comment. In the previous discussion related to the flexible string representation, Roy Smith added this comment: http://groups.google.com/group/comp.lang.python/browse_thread/thread/2645504f459bab50/eda342573381ff42 Not only I agree with his sentence: "Clearly, the world has moved to a 32-bit character set." he used in his comment a very intersting word: "punctuation". There is a point which is, in my mind, not very well understood, "digested", underestimated or neglected by many developers: the relation between the coding of the characters and the typography. Unicode (the consortium), does not only deal with the coding of the characters, it also worked on the characters *classification*. A deliberatly simplistic representation: "letters" in the bottom of the table, lower code points/integers; "typographic characters" like punctuation, common symbols, ... high in the table, high code points/integers. The conclusion is inescapable, if one wish to work in a "unicode mode", one is forced to use the whole palette of the unicode code points, this is the *nature* of Unicode. Technically, believing that it possible to optimize only a subrange of the unicode code points range is simply an illusion. A lot of work, probably quite complicate, which finally solves nothing. Python, in my mind, fell in this trap. "Simple is better than complex." -> hard to maintained "Flat is better than nested." -> code points range "Special cases aren't special enough to break the rules." -> special unicode code points? "Although practicality beats purity." -> or the opposite? "In the face of ambiguity, refuse the temptation to guess." -> guessing a user will only work with the "optimmized" char subrange. ... Small illustration. Take an a4 page containing 50 lines of 80 ascii characters, add a single 'EM DASH' or an 'BULLET' (code points > 0x2000), and you will see all the optimization efforts destroyed. >> sys.getsizeof('a' * 80 * 50) 4025 >>> sys.getsizeof('a' * 80 * 50 + '?') 8040 Just my 2 ? (code point 0x20ac) cents. jmf From invalid at invalid.invalid Thu Aug 23 09:53:43 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 23 Aug 2012 13:53:43 +0000 (UTC) Subject: How to set the socket type and the protocol of a socket using create_connection? References: <32176aa4-4b9d-44a6-8729-958e3c251955@googlegroups.com> Message-ID: On 2012-08-22, Dennis Lee Bieber wrote: > On Wed, 22 Aug 2012 01:43:19 -0700 (PDT), Guillaume Comte > declaimed the following in > gmane.comp.python.general: > >> I've managed to build the IP header. I've put the source and destination addresses in this header but it doesn't change the real source address... > > For all I know (I've done very little network programming, and that > was years ago using plain TCP and UDP -- worse, on a VMS system so it > wasn't the "UNIX style" socket interface), your network stack may still > be overriding the packet at some lower level and inserting the IP > associated with the interface the packet went out on... I've only been intermittently following this thread, but back when I added Python's raw packet support for Unix, the socket module was a _very_ thin wrapper for the underlying OS network socket API. The behavior of various types of sockets was defined entirely by the underlying OS. So, if you're trying to do something obscure (which it seems you are), asking people who know how to do it in C on the relevent OS is probably the best approach. Below are examples of sending and receiving a completely raw packet on Linux (where you provide _all_ the bytes: the MAC addreses, the Ethernet type, everything). ------------------------------send------------------------------ #!/usr/bin/python import sys,os,socket,struct from optparse import OptionParser p = OptionParser() p.add_option("-i","--interface",dest="interface",metavar="",type='str',default="eth0") options,args = p.parse_args() if len(args) != 1: sys.stderr.write("you must provide a destination MAC address\n") sys.exit(1) def toHex(s): return " ".join([("%02x" % ord(c)) for c in s]) ethProto = 0x5678 dstMacStr = args[0] dstMacAddr = "".join(map(chr,[int(x,16) for x in dstMacStr.split(":")])) s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, ethProto) s.bind((options.interface,ethProto)) ifName,ifProto,pktType,hwType,hwAddr = s.getsockname() srcMacAddr = hwAddr ethHeader = struct.pack("!6s6sh",dstMacAddr,srcMacAddr,ethProto) packet = ethHeader + "some ASCII data here" sys.stdout.write("tx: %s\n" % toHex(packet)) s.send(packet) s.close() ----------------------------------------------------------------- ------------------------------recv------------------------------ #!/usr/bin/python import sys,os,socket,struct from optparse import OptionParser p = OptionParser() p.add_option("-i","--interface",dest="interface",metavar="",type='str',default="eth0") options,args = p.parse_args() if len(args) != 0: sys.stderr.write("no arguments accepted\n") sys.exit(1) def toHex(s): return " ".join([("%02x" % ord(c)) for c in s]) ethProto = 0x5678 s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, ethProto) s.bind((options.interface,ethProto)) packet = s.recv(4096) sys.stdout.write("rx: %s\n" % toHex(packet)) s.close() ----------------------------------------------------------------- -- Grant Edwards grant.b.edwards Yow! I'm changing the at CHANNEL ... But all I get gmail.com is commercials for "RONCO MIRACLE BAMBOO STEAMERS"! From nhodgson at iinet.net.au Thu Aug 23 09:57:50 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Thu, 23 Aug 2012 23:57:50 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: Message-ID: wxjmfauth at gmail.com: > Small illustration. Take an a4 page containing 50 lines of 80 ascii > characters, add a single 'EM DASH' or an 'BULLET' (code points> 0x2000), > and you will see all the optimization efforts destroyed. > >>> sys.getsizeof('a' * 80 * 50) > 4025 >>>> sys.getsizeof('a' * 80 * 50 + '?') > 8040 This example is still benefiting from shrinking the number of bytes in half over using 32 bits per character as was the case with Python 3.2: >>> sys.getsizeof('a' * 80 * 50) 16032 >>> sys.getsizeof('a' * 80 * 50 + '?') 16036 >>> Neil From ben+python at benfinney.id.au Thu Aug 23 09:59:47 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 23 Aug 2012 23:59:47 +1000 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> <4ICdnasny6sSeKjNnZ2dnUVZ8t-dnZ2d@bt.com> Message-ID: <878vd51zfw.fsf@benfinney.id.au> lipska the kat writes: > On 23/08/12 05:14, Steven D'Aprano wrote: > > I think that's uncalled for. [?] > Excellent advice as usual, but I'm more than capable of looking after > myself thank you. As is usual, it's not all about you; Steven is demonstrating that we require civil behaviour here, for anyone who may be watching but not saying anything. -- \ ?Skepticism is the highest duty and blind faith the one | `\ unpardonable sin.? ?Thomas Henry Huxley, _Essays on | _o__) Controversial Questions_, 1889 | Ben Finney From breamoreboy at yahoo.co.uk Thu Aug 23 10:11:43 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Aug 2012 15:11:43 +0100 Subject: Guarding arithmetic In-Reply-To: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On 23/08/2012 10:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: > > def safe(x): > # WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print safe(1/0) # prints 42 > > I don't see how such a function could be defined. Is it possible? > Well you've already got lots of answers but I'm not certain about what you're trying to achieve. If you could explicitly state your requirements I'm sure that the numerous MVPs (Most Valuable Pythonistas) here would come up with The Best Solution ? to your problem. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Thu Aug 23 10:18:05 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Aug 2012 15:18:05 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: Message-ID: On 23/08/2012 13:47, wxjmfauth at gmail.com wrote: > This is neither a complaint nor a question, just a comment. > > In the previous discussion related to the flexible > string representation, Roy Smith added this comment: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/2645504f459bab50/eda342573381ff42 > > Not only I agree with his sentence: > "Clearly, the world has moved to a 32-bit character set." > > he used in his comment a very intersting word: "punctuation". > > There is a point which is, in my mind, not very well understood, > "digested", underestimated or neglected by many developers: > the relation between the coding of the characters and the typography. > > Unicode (the consortium), does not only deal with the coding of > the characters, it also worked on the characters *classification*. > > A deliberatly simplistic representation: "letters" in the bottom > of the table, lower code points/integers; "typographic characters" > like punctuation, common symbols, ... high in the table, high code > points/integers. > > The conclusion is inescapable, if one wish to work in a "unicode > mode", one is forced to use the whole palette of the unicode > code points, this is the *nature* of Unicode. > > Technically, believing that it possible to optimize only a subrange > of the unicode code points range is simply an illusion. A lot of > work, probably quite complicate, which finally solves nothing. > > Python, in my mind, fell in this trap. > > "Simple is better than complex." > -> hard to maintained > "Flat is better than nested." > -> code points range > "Special cases aren't special enough to break the rules." > -> special unicode code points? > "Although practicality beats purity." > -> or the opposite? > "In the face of ambiguity, refuse the temptation to guess." > -> guessing a user will only work with the "optimmized" char subrange. > ... > > Small illustration. Take an a4 page containing 50 lines of 80 ascii > characters, add a single 'EM DASH' or an 'BULLET' (code points > 0x2000), > and you will see all the optimization efforts destroyed. > >>> sys.getsizeof('a' * 80 * 50) > 4025 >>>> sys.getsizeof('a' * 80 * 50 + '?') > 8040 > > Just my 2 ? (code point 0x20ac) cents. > > jmf > I'm looking forward to all the patches you are going to provide to correct all these (presumably) cPython deficiencies. When do they start arriving on the bug tracker? -- Cheers. Mark Lawrence. From lipskathekat at yahoo.co.uk Thu Aug 23 10:20:29 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 23 Aug 2012 15:20:29 +0100 Subject: Objects in Python In-Reply-To: <878vd51zfw.fsf@benfinney.id.au> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> <4ICdnasny6sSeKjNnZ2dnUVZ8t-dnZ2d@bt.com> <878vd51zfw.fsf@benfinney.id.au> Message-ID: On 23/08/12 14:59, Ben Finney wrote: > lipska the kat writes: > >> On 23/08/12 05:14, Steven D'Aprano wrote: >>> I think that's uncalled for. > [?] > >> Excellent advice as usual, but I'm more than capable of looking after >> myself thank you. > > As is usual, it's not all about you; Steven is demonstrating that we > require civil behaviour here, for anyone who may be watching but not > saying anything. You 'require civil behaviour here' do you. Well so far I have been very civil. This is a USENET newsgroup, it's a public forum, not your personal domain. Please stop all this 'it's not all about you' meaningless nonsense. It's pointless and wastes mine and no doubt others time. If you want to carry this on please contact me off list. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From ben+python at benfinney.id.au Thu Aug 23 10:24:49 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 24 Aug 2012 00:24:49 +1000 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <5035ae3f$0$1645$c3e8da3$76491128@news.astraweb.com> <4ICdnasny6sSeKjNnZ2dnUVZ8t-dnZ2d@bt.com> <878vd51zfw.fsf@benfinney.id.au> Message-ID: <87zk5lznwu.fsf@benfinney.id.au> lipska the kat writes: > On 23/08/12 14:59, Ben Finney wrote: > > lipska the kat writes: > > > >> On 23/08/12 05:14, Steven D'Aprano wrote: > >>> I think that's uncalled for. > > [?] > > > >> Excellent advice as usual, but I'm more than capable of looking after > >> myself thank you. > > > > As is usual, it's not all about you; Steven is demonstrating that we > > require civil behaviour here, for anyone who may be watching but not > > saying anything. > > You 'require civil behaviour here' do you. Well so far I have been > very civil. And I say again: it's not all about you. Steven's respons was to a different person in this thread. Please stop reacting as if everything said around you is directed at you. -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From malaclypse2 at gmail.com Thu Aug 23 10:43:48 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 23 Aug 2012 10:43:48 -0400 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Aug 23, 2012 at 4:59 AM, Jussi Piitulainen wrote: > I don't get it either. To me the python-has-no-variables campaigners > seem confused. As far as I can see, Python can be seen in terms of > variables bound to (locations containing) values perfectly well, in a > way that should be quite familiar to people who come from Java (or > Lisp, Scheme like me). Personally, when I was learning python I found the idea of python having names and values (rather than variables and references) to clear up a lot of my misconceptions of the python object model. I think it's done the same for other people too, especially those who come from the C world, where a variable is a named and typed location in memory. Perhaps those that come from the Java and Lisp world don't find the name/value paradigm as helpful. Still, it seems silly to excoriate people on the list for trying to explain python fundamentals in several different ways. Sometimes explaining the same idea in different words helps people understand the concept better. -- Jerry From python at mrabarnett.plus.com Thu Aug 23 11:11:05 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Aug 2012 16:11:05 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: Message-ID: <50364809.3060403@mrabarnett.plus.com> On 23/08/2012 14:57, Neil Hodgson wrote: > wxjmfauth at gmail.com: > >> Small illustration. Take an a4 page containing 50 lines of 80 ascii >> characters, add a single 'EM DASH' or an 'BULLET' (code points> 0x2000), >> and you will see all the optimization efforts destroyed. >> >>>> sys.getsizeof('a' * 80 * 50) >> 4025 >>>>> sys.getsizeof('a' * 80 * 50 + '?') >> 8040 > > This example is still benefiting from shrinking the number of bytes > in half over using 32 bits per character as was the case with Python 3.2: > > >>> sys.getsizeof('a' * 80 * 50) > 16032 > >>> sys.getsizeof('a' * 80 * 50 + '?') > 16036 > >>> > Perhaps the solution should've been to just switch between 2/4 bytes instead of 1/2/4 bytes. :-) From ian.g.kelly at gmail.com Thu Aug 23 11:19:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Aug 2012 09:19:23 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <50364809.3060403@mrabarnett.plus.com> References: <50364809.3060403@mrabarnett.plus.com> Message-ID: On Thu, Aug 23, 2012 at 9:11 AM, MRAB wrote: > Perhaps the solution should've been to just switch between 2/4 bytes instead > of 1/2/4 bytes. :-) Why? You don't lose any complexity by doing that. I can see arguments for 1/2/4 or for just 4, but I can't see any advantage of 2/4 over either of those. From roy at panix.com Thu Aug 23 11:30:05 2012 From: roy at panix.com (Roy Smith) Date: Thu, 23 Aug 2012 11:30:05 -0400 Subject: Looking for duplicate modules Message-ID: <377FBB51-D794-4F05-9E51-46A056705E32@panix.com> We got burned yesterday by a scenario which has burned us before. We had multiple copies of a module in sys.path. One (the one we wanted) was in our deployed code tree, the other was in /usr/local/lib/python/ or some such. It was a particularly confusing situation because we *knew* we had uninstalled the copy in /usr/local/lib. What we didn't know was that puppet was set up to check to make sure it was there and reinstalled it automagically if it ever disappeared! What often adds to the confusion in cases like this is that if you use a package manager (such as apt-get) to manage your module deployments, when you uninstall, the .py files get removed, but the .pyc's stay behind. I'm working on a tool which scans all the directories in sys.path and finds any modules which appear multiple times in the path. It'll also call out any .pyc's it finds without matching py's. I know those are not strictly errors, but both of them are, for lack of a better term, "deployment smells" and something to be warned about. Before I invest too much effort into building it, does such a tool already exist? We're slowly moving more of our deployment to using virtualenv (with --no-site-packages), but we're not fully there yet. And even when we get there, there will still be opportunities to make these sorts of mistakes. --- Roy Smith roy at panix.com From driscoll at cs.wisc.edu Thu Aug 23 12:44:01 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 23 Aug 2012 11:44:01 -0500 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <50365DD1.3090301@cs.wisc.edu> On 08/23/2012 04:19 AM, lipska the kat wrote: > Well we don't want to turn this into a language comparison thread do we, > that might upset too many people but I can't remember ever writing a > method that took an Object as argument, you just can't do that much with > an Object. In the pre-Java-1.5 days, functions that took Objects were *very* common; e.g. every collections class. Even now there are probably lingering cases where either there's some code that hasn't been genericized or is too much work to genericize to make it worthwhile. (I do very little Java programming so can't point to any concrete cases if you would (reasonably) reject the example of java.util.collections being used in their non-generic form.) Anyway, the point wasn't that 'foo(Object o)' is common, just that you've probably seen something which is somewhat comparable. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 545 bytes Desc: OpenPGP digital signature URL: From castironpi at gmail.com Thu Aug 23 12:49:41 2012 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 23 Aug 2012 09:49:41 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, August 18, 2012 9:28:32 PM UTC-5, Aaron Brady wrote: > On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > > > On 18/08/2012 21:29, Aaron Brady wrote: > > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > > >> > Is there a problem with hacking on the Beta? > > > >> Nope. Hack on the beta, then when the release arrives, rebase your > > > >> work onto it. I doubt that anything of this nature will be changed > > > >> between now and then. > > > >> ChrisA > > > > Thanks Chris, your post was encouraging. > > > > I have a question about involving the 'tp_clear' field of the types. > > > > http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear > > > > ''' > > > > ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. > > > > ''' > > > > I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. > > > > Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png > > > > In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. > > > > Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? > > > In simple terms, when you create an immutable object it can contain > > > only references to pre-existing objects, but in order to create a cycle > > > you need to make an object refer to another which is created later, so > > > it's not possible to create a cycle out of immutable objects. > > > However, using Python's C API it _is_ possible to create such a cycle, > > > by mutating an otherwise-immutable tuple (see PyTuple_SetItem and > > > PyTuple_SET_ITEM). > > Are there any precedents for storing uncounted references to PyObject's? > > One apparent problematic case is creating an iterator to a set, then adding it to the set. However the operation is a modification, and causes the iterator to be removed from the secondary list before the set is examined for collection. > > Otherwise, the iterator keeps a counted reference to the set, but the set does not keep a counted reference to the iterator, so the iterator will always be freed first. Therefore, the set's secondary list will be empty when the set is freed. > > Concurrent addition and deletion of iterators should be disabled, and the iterators should remove themselves from the set's secondary list before they decrement their references to the set. > > Please refresh the earlier diagram; counted references are distinguished separately. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png The patch for the above is only 40-60 lines. However it introduces two new concepts. The first is a "linked list", a classic dynamic data structure, first developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . Linked lists are absent in Python, including the standard library and CPython implementation, beyond the weak reference mechanism and garbage collector. The "collections.deque" structure shares some of the linked list interface but uses arrays. The second is "uncounted references". The uncounted references are references to "set iterators" exclusively, exist only internally to "set" objects, and are invisible to the rest of the program. The reason for the exception is that iterators are unique in the Python Data Model; iterators consist of a single immutable reference, unlike both immutable types such as strings and numbers, as well as container types. Counted references could be used instead, but would be consistently wasted work for the garbage collector, though the benefit to programmers' peace of mind could be significant. Please share your opinion! Do you agree that the internal list resolves the inconsistency? Do you agree with the strategy? Do you agree that uncounted references are justified to introduce, or are counted references preferable? From castironpi at gmail.com Thu Aug 23 12:49:41 2012 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 23 Aug 2012 09:49:41 -0700 (PDT) Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, August 18, 2012 9:28:32 PM UTC-5, Aaron Brady wrote: > On Saturday, August 18, 2012 5:14:05 PM UTC-5, MRAB wrote: > > > On 18/08/2012 21:29, Aaron Brady wrote: > > > > On Friday, August 17, 2012 4:57:41 PM UTC-5, Chris Angelico wrote: > > > >> On Sat, Aug 18, 2012 at 4:37 AM, Aaron Brady wrote: > > > >> > Is there a problem with hacking on the Beta? > > > >> Nope. Hack on the beta, then when the release arrives, rebase your > > > >> work onto it. I doubt that anything of this nature will be changed > > > >> between now and then. > > > >> ChrisA > > > > Thanks Chris, your post was encouraging. > > > > I have a question about involving the 'tp_clear' field of the types. > > > > http://docs.python.org/dev/c-api/typeobj.html#PyTypeObject.tp_clear > > > > ''' > > > > ...The tuple type does not implement a tp_clear function, because it?s possible to prove that no reference cycle can be composed entirely of tuples. > > > > ''' > > > > I didn't follow the reasoning in the proof; the premise is necessary but IMHO not obviously sufficient. Nevertheless, the earlier diagram contains an overt homogeneous reference cycle. > > > > Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png > > > > In my estimate, the 'tp_traverse' and 'tp_clear' fields of the set doesn't need to visit the auxiliary collection; the same fields of the iterators don't need to visit the primary set or other iterators; and references in the linked list don't need to be included in the iterators' reference counts. > > > > Can someone who is more familiar with the cycle detector and cycle breaker, help prove or disprove the above? > > > In simple terms, when you create an immutable object it can contain > > > only references to pre-existing objects, but in order to create a cycle > > > you need to make an object refer to another which is created later, so > > > it's not possible to create a cycle out of immutable objects. > > > However, using Python's C API it _is_ possible to create such a cycle, > > > by mutating an otherwise-immutable tuple (see PyTuple_SetItem and > > > PyTuple_SET_ITEM). > > Are there any precedents for storing uncounted references to PyObject's? > > One apparent problematic case is creating an iterator to a set, then adding it to the set. However the operation is a modification, and causes the iterator to be removed from the secondary list before the set is examined for collection. > > Otherwise, the iterator keeps a counted reference to the set, but the set does not keep a counted reference to the iterator, so the iterator will always be freed first. Therefore, the set's secondary list will be empty when the set is freed. > > Concurrent addition and deletion of iterators should be disabled, and the iterators should remove themselves from the set's secondary list before they decrement their references to the set. > > Please refresh the earlier diagram; counted references are distinguished separately. Reposting: http://home.comcast.net/~castironpi-misc/clpy-0062%20set%20iterators.png The patch for the above is only 40-60 lines. However it introduces two new concepts. The first is a "linked list", a classic dynamic data structure, first developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . Linked lists are absent in Python, including the standard library and CPython implementation, beyond the weak reference mechanism and garbage collector. The "collections.deque" structure shares some of the linked list interface but uses arrays. The second is "uncounted references". The uncounted references are references to "set iterators" exclusively, exist only internally to "set" objects, and are invisible to the rest of the program. The reason for the exception is that iterators are unique in the Python Data Model; iterators consist of a single immutable reference, unlike both immutable types such as strings and numbers, as well as container types. Counted references could be used instead, but would be consistently wasted work for the garbage collector, though the benefit to programmers' peace of mind could be significant. Please share your opinion! Do you agree that the internal list resolves the inconsistency? Do you agree with the strategy? Do you agree that uncounted references are justified to introduce, or are counted references preferable? From rustompmody at gmail.com Thu Aug 23 13:04:51 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 23 Aug 2012 10:04:51 -0700 (PDT) Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <5035b2eb$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <7380f681-4b76-4500-a79f-83978990e7b6@xd1g2000pbc.googlegroups.com> On Aug 23, 9:34?am, Steven D'Aprano wrote: > On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote: > > We need to separate out the 'view' from the 'implementation' here. Most > > developers I know, if looking at the code and without the possibly > > dubious benefit of knowing that in Python 'everything is an object' > > would not call this 'strong typing' > > Most developers are wrong :) > > A very useful resource to read is "What To Know Before Debating Type > Systems", which was put on the internet, lost, then found and put back up > here: > > http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ Thanks for that article. There was one by Peter Wegner -- exact one I cant find. Here's a good approximation: http://analysis-of-persistence-tools.googlecode.com/files/p7-wegner.pdf Section 5.2.1 in particular has 7 different things that the word 'type' could mean to different types(!) of programmers. From rustompmody at gmail.com Thu Aug 23 13:15:54 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 23 Aug 2012 10:15:54 -0700 (PDT) Subject: Guarding arithmetic References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> Message-ID: On Aug 23, 3:11?pm, Peter Otten <__pete... at web.de> wrote: > Mark Carter wrote: > > Suppose I want to define a function "safe", which returns the argument > > passed if there is no error, and 42 if there is one. So the setup is > > something like: > > > def safe(x): > > ? ?# WHAT WOULD DEFINE HERE? > > > print safe(666) # prints 666 > > print safe(1/0) # prints 42 > > > I don't see how such a function could be defined. Is it possible? > > 1/0 is evaluated before safe() is called. Therefore safe() has no chance to > catch the exception. You have to move the evaluation into the safe() > function: > > >>> def safe(deferred, default=42, exception=Exception): > > ... ? ? try: > ... ? ? ? ? ? ? return deferred() > ... ? ? except exception: > ... ? ? ? ? ? ? return default > ...>>> print safe(lambda: 666) > 666 > >>> print safe(lambda: 1/0) > > 42 Nice! Functional programmers know that once you have a lazy language, you can simulate all control constructs within that framework. eg in Haskell one could define an 'if-function' as iffunc (True, a, b) = a iffunc (False, a, b) = b In most other languages such a definition would not work. What Peter has demonstrated is that for an eager language like python, a bare-lambda is a lazy-fying construct From driscoll at cs.wisc.edu Thu Aug 23 13:17:03 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 23 Aug 2012 12:17:03 -0500 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <5036658F.4090203@cs.wisc.edu> [I have some things to say to a few people so I'm just putting it all in one rather than clutter up your email box even more.] On 08/23/2012 12:33 AM, Chris Angelico wrote: > [Snip discussion on names vs variables] > > Does that sort things out, or just make things more confusing? > > ChrisA I... am not sure. I don't think it really told me anything new. I think it's just that I don't think that any of the distinctions (nor all of them put together) makes it worthwhile to reject a perfectly good term in common use just because the behavior of Python variables is a bit different from the behavior of variables in *some* other languages. For instance, I don't get annoyed that both Java and Python use the terms "class" and "object" for similar but still very different things. And while I think it's worth saying "Python classes and objects are rather different from Java's", I definitely *wouldn't* say "Python classes aren't really classes" -- even though (I assert) Python classes are *far* further from Simula-style (/Java/C++) classes than Python variables are from Java variables. On 08/23/2012 03:59 AM, Jussi Piitulainen wrote: > I would also avoid any distinction between an object and a > "reference" to an object, except as an implementation detail. It's not > helpful. Whaaaa....? How would you describe it then? To me, that distinction is absolutely *fundamental* to understanding how languages like Python/Scheme/Java work, because it tells you how to reason about aliasing behavior in an unconvoluted way (which is essential to understanding how they work). How would *you* suggest dealing with that issue? On 08/23/2012 09:43 AM, Jerry Hill wrote: > On Thu, Aug 23, 2012 at 4:59 AM, Jussi Piitulainen wrote: >> I don't get it either. To me the python-has-no-variables campaigners >> seem confused. As far as I can see, Python can be seen in terms of >> variables bound to (locations containing) values perfectly well, in a >> way that should be quite familiar to people who come from Java (or >> Lisp, Scheme like me). > > ... > > Perhaps those that come from the Java and Lisp world don't find the > name/value paradigm as helpful. Still, it seems silly to excoriate > people on the list for trying to explain python fundamentals in > several different ways. Sometimes explaining the same idea in > different words helps people understand the concept better. I agree with this, and I'm happy that people found it useful. *However*, this thread wasn't really prompted by someone just trying to explain variables in different terms -- it was prompted by one of the many comments you see from time-to-time that "Python doesn't have variables ? not as C or Java programmers would understand the term". That's a different than saying "here's another way of looking at Python variables", and that instance is even toned down compared to a lot of the instances you'll find (which will often omit the qualification at the end). To me, saying "here's an alternative way to look at variables" is great, but saying "Python doesn't have variables" is, IMO, at least as silly as what Jussi said. To me, dancing around the issue just leads to more confusing terminology and makes things worse. (And this is reinforced by the fact that neither I nor Google seems to have really seen "Python doesn't have classes" ever used, when that statement is at least as true as "Python doesn't have variables".) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 545 bytes Desc: OpenPGP digital signature URL: From tjreedy at udel.edu Thu Aug 23 13:17:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Aug 2012 13:17:38 -0400 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On 8/23/2012 10:43 AM, Jerry Hill wrote: > Personally, when I was learning python I found the idea of python > having names and values (rather than variables and references) to > clear up a lot of my misconceptions of the python object model. I > think it's done the same for other people too, especially those who > come from the C world, where a variable is a named and typed location > in memory. There are two important points about C and assembler. First, the named locations (and un-named internal locations like function return addresses) are *contiguous*. Giving a user access to one block may give a user access to other blocks if one is not careful. The other is that the typing is in the code and compiler, but not in the runtime memory. So text input can be read as code and a return jump address to the bytes interpreted as code. -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 23 13:29:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Aug 2012 13:29:19 -0400 Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: On 8/23/2012 8:28 AM, Roy Smith wrote: > I think you want to end up with something like: > > def test_1(self): > "Verify creation of files is possible" > filenames = ("this.txt", "that.txt", "the_other.txt") > for filename in filenames: > f = open(filename, "w") > f.write("Some text\n") > f.close() > self.assertTrue(f.closed) > dir_names = os.listdir() > self.assertEqual(set(dir_names), set(filenames)) > > The above code isn't tested, but it should give you the gist of what you > need to do. One can start with a set rather than tuple of file names. def test_1(self): "Verify creation of files is possible" filenames = {"this.txt", "that.txt", "the_other.txt"} for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) dir_names = set(os.listdir()) self.assertEqual(dir_names, filenames) -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Aug 23 13:56:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 17:56:25 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: > I definitely *wouldn't* say "Python > classes aren't really classes" -- even though (I assert) Python classes > are *far* further from Simula-style (/Java/C++) classes than Python > variables are from Java variables. Well, Python classes are first-class (pun not intended) objects in their own right, and hence are data. Java and C++ classes are not, they are instructions to the compiler rather than data. But other than that, what do you see as the difference between Python classes and Simula-style classes? > On 08/23/2012 03:59 AM, Jussi Piitulainen wrote: >> I would also avoid any distinction between an object and a "reference" >> to an object, except as an implementation detail. It's not helpful. > > Whaaaa....? > > How would you describe it then? To me, that distinction is absolutely > *fundamental* to understanding how languages like Python/Scheme/Java > work, because it tells you how to reason about aliasing behavior in an > unconvoluted way (which is essential to understanding how they work). > > How would *you* suggest dealing with that issue? Given: x = some_object() y = x I could say that x and y are the same object, rather than x and y are references to the same object. Sometimes, when I say "x", I mean the *name* x, which is a reference to some object. Much more often though, when I say "x", I use it as a convenient label for some object. Rather than saying "the object which is referenced to by the name x", I just say "x". Nearly always, the meaning is obvious in context. [...] > *However*, this thread wasn't really prompted by someone just trying to > explain variables in different terms -- it was prompted by one of the > many comments you see from time-to-time that "Python doesn't have > variables ? not as C or Java programmers would understand the term". No offence to Ben Finney, but I think sometimes he's a bit too eager to emphasise the subtle differences between Python and other languages, rather than the similarities. (I used to be like Ben in this regard, but I got better -- or worse, depending on your perspective.) Again, context is important: sometimes I will choose to gloss over the differences by calling x a variable, and sometimes I will emphasise the differences to C or Pascal by referring to name binding. > To me, saying "here's an alternative way to look at variables" is great, > but saying "Python doesn't have variables" is, IMO, at least as silly as > what Jussi said. To me, dancing around the issue just leads to more > confusing terminology and makes things worse. > > (And this is reinforced by the fact that neither I nor Google seems to > have really seen "Python doesn't have classes" ever used, when that > statement is at least as true as "Python doesn't have variables".) I think you are utterly wrong here. Python has classes. They are created by the "class" keyword. Whether those classes are identical to Java classes is irrelevant -- in Python, these whatever-they-are-things are called "classes", and so Python has classes. But Python does not have things called "variables". There is no "variable" keyword to create a variable. It is absolutely fundamental to the programming model of Python that it has objects which are bound to names in namespaces (and other entities, such as list items). That is *critical* -- Python uses name bindings. But name bindings are a kind of variable. Named memory locations are a *different* kind of variable. The behaviour of C variables and Python variables do not follow the Liskov Substitution Principle -- you can't rip out the entire "names bound to objects" machinery of Python and replace it with C-like named memory locations without changing the high- level behaviour of Python. And so by some ways of thinking it is *wrong* to treat name bindings and memory locations as "the same sort of entity". Hence, if C variables are variables, then Python name bindings can't be. I used to agree with that reasoning. I no longer do, not entirely. While I see the differences between them -- for instance, C variables exist before they have a value assigned to them, Python name bindings do not -- I don't think the differences are important enough to *prohibit* use of the word "variable" to describe name bindings. Only to discourage it. -- Steven From lipskathekat at yahoo.co.uk Thu Aug 23 13:56:58 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Thu, 23 Aug 2012 18:56:58 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> Message-ID: <-P6dnTOAEb1w86vNnZ2dnUVZ8rKdnZ2d@bt.com> On 23/08/12 17:44, Evan Driscoll wrote: > On 08/23/2012 04:19 AM, lipska the kat wrote: >> Well we don't want to turn this into a language comparison thread do we, >> that might upset too many people but I can't remember ever writing a >> method that took an Object as argument, you just can't do that much with >> an Object. > > In the pre-Java-1.5 days, functions that took Objects were *very* > common; Well the Collections framework does expose methods that take Objects but generally you override certain methods in class Object when you want to compare Objects, in fact String comparison is a really interesting area due to the way Java internalizes Strings at compile time... but that is way to off topic for here. regards lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From jan.kuiken at quicknet.nl Thu Aug 23 14:02:00 2012 From: jan.kuiken at quicknet.nl (Jan Kuiken) Date: Thu, 23 Aug 2012 20:02:00 +0200 Subject: Objects in Python In-Reply-To: <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On 8/23/12 06:11 , Steven D'Aprano wrote: >> 2) Related to the above, you can infinitely nest scopes. There's nothing >> wrong with having six variables called 'q'; you always use the innermost >> one. Yes, this can hurt readability > > Well, there you go. There *is* something wrong with having six variables > called 'q'. Sometimes you don't want only six variables called 'q' but a hundred of them :-) def fac(q): if q < 1 : return 1 else: return q * fac(q-1) print(fac(100)) Jan Kuiken From steve+comp.lang.python at pearwood.info Thu Aug 23 14:11:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Aug 2012 18:11:14 GMT Subject: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <50367242$0$6574$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: [...] > The patch for the above is only 40-60 lines. However it introduces two > new concepts. > > The first is a "linked list", a classic dynamic data structure, first > developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . > Linked lists are absent in Python They certainly are not. There's merely no named "linked list" class. Linked lists are used by collections.ChainMap, tracebacks, xml.dom, Abstract Syntax Trees, and probably many other places. (Well, technically some of these are trees rather than lists.) You can trivially create a linked list: x = [a, [b, [c, [d, [e, None]]]]] is equivalent to a singly-linked list with five nodes. Only less efficient. > The second is "uncounted references". The uncounted references are > references to "set iterators" exclusively, exist only internally to > "set" objects, and are invisible to the rest of the program. The reason > for the exception is that iterators are unique in the Python Data Model; > iterators consist of a single immutable reference, unlike both immutable > types such as strings and numbers, as well as container types. Counted > references could be used instead, but would be consistently wasted work > for the garbage collector, though the benefit to programmers' peace of > mind could be significant. The usual way to implement "uncounted references" is by using weakrefs. Why invent yet another form of weakref? -- Steven From ian.g.kelly at gmail.com Thu Aug 23 14:17:37 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Aug 2012 12:17:37 -0600 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Aug 23, 2012 at 12:02 PM, Jan Kuiken wrote: > On 8/23/12 06:11 , Steven D'Aprano wrote: > >>> 2) Related to the above, you can infinitely nest scopes. There's nothing >>> wrong with having six variables called 'q'; you always use the innermost >>> one. Yes, this can hurt readability >> >> >> Well, there you go. There *is* something wrong with having six variables >> called 'q'. > > > Sometimes you don't want only six variables called 'q' but a hundred > of them :-) > > def fac(q): > if q < 1 : > return 1 > else: > return q * fac(q-1) > > print(fac(100)) That's only one variable called 'q', instantiated 100 times simultaneously. From wxjmfauth at gmail.com Thu Aug 23 14:33:52 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 23 Aug 2012 11:33:52 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: Message-ID: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> Le jeudi 23 ao?t 2012 15:57:50 UTC+2, Neil Hodgson a ?crit?: > wxjmfauth at gmail.com: > > > > > Small illustration. Take an a4 page containing 50 lines of 80 ascii > > > characters, add a single 'EM DASH' or an 'BULLET' (code points> 0x2000), > > > and you will see all the optimization efforts destroyed. > > > > > >>> sys.getsizeof('a' * 80 * 50) > > > 4025 > > >>>> sys.getsizeof('a' * 80 * 50 + '?') > > > 8040 > > > > This example is still benefiting from shrinking the number of bytes > > in half over using 32 bits per character as was the case with Python 3.2: > > > > >>> sys.getsizeof('a' * 80 * 50) > > 16032 > > >>> sys.getsizeof('a' * 80 * 50 + '?') > > 16036 > Correct, but how many times does it happen? Practically never. In this unicode stuff, I'm fascinated by the obsession to solve a problem which is, due to the nature of Unicode, unsolvable. For every optimization algorithm, for every code point range you can optimize, it is always possible to find a case breaking that optimization. This follows quasi the mathematical logic. To proof a law is valid, you have to proof all the cases are valid. To proof a law is invalid, just find one case showing it. Sure, it is possible to optimize the unicode usage by not using French characters, punctuation, mathematical symbols, currency symbols, CJK characters... (select undesired characters here: http://www.unicode.org/charts/). In that case, why using unicode? (A problematic not specific to Python) jmf From roy at panix.com Thu Aug 23 15:06:29 2012 From: roy at panix.com (Roy Smith) Date: Thu, 23 Aug 2012 12:06:29 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: <37ff0f1f-d36c-4573-8179-2d27ea404f37@googlegroups.com> On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > One can start with a set rather than tuple of file names. > filenames = {"this.txt", "that.txt", "the_other.txt"} Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or above. From roy at panix.com Thu Aug 23 15:06:29 2012 From: roy at panix.com (Roy Smith) Date: Thu, 23 Aug 2012 12:06:29 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: <37ff0f1f-d36c-4573-8179-2d27ea404f37@googlegroups.com> On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > One can start with a set rather than tuple of file names. > filenames = {"this.txt", "that.txt", "the_other.txt"} Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or above. From driscoll at cs.wisc.edu Thu Aug 23 15:22:08 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 23 Aug 2012 14:22:08 -0500 Subject: Variables vs names [was: Objects in Python] In-Reply-To: <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503682E0.4060807@cs.wisc.edu> On 08/23/2012 12:56 PM, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: > >> I definitely *wouldn't* say "Python >> classes aren't really classes" -- even though (I assert) Python classes >> are *far* further from Simula-style (/Java/C++) classes than Python >> variables are from Java variables. > > Well, Python classes are first-class (pun not intended) objects in their > own right, and hence are data. Java and C++ classes are not, they are > instructions to the compiler rather than data. > > But other than that, what do you see as the difference between Python > classes and Simula-style classes? So first, to some extent that's like saying "these two different things are different in this important way, but other than that, what's the difference?" :-) But there are some other differences. (Not all of these are strictly with classes per se, but I would say they all have strong interactions with the object system.) * Explicit 'self'. OK, this sounds just like a minor syntactic difference, and in some respect it is. (For some time I considered it an annoying piece of syntactic salt.) But it has significant interactions with other things which you can do, such as using a method as just a normal function ('type(c).f(c)' ~= 'c.f()') or attaching other functions to an instance or a class (more on that later). This is definitely my weakest argument. :-) * Fields. In Simula-style classes, you can tell easily what fields a class and its objects contain. In Python, that question from some point of view doesn't even make sense (in the absence of __slots__). Fields are a property of the *objects* rather than the class, and two objects of the same class don't necessarily have the same fields. Related to this point we have... * What it means for an object to have a particular class type. With Simula-style classes, if I have an object 'o' of class 'c', then I know that 'o' has the functions and fields defined by 'c'. Now, the virtual functions may have been overriden in base classes and stuff, and maydbe they'll always fail, but I at least know they're *there*. In Python, I know... well, nothing basically. As far as I know, it's possible to make it so that o's only relation to 'c' is what 'type(o)' and 'instanceof' say. (And maybe you can even override those, I dunno!) You can go through and add/remove/replace functions. Two different objects of the same class may have completely disjoint sets of attributes. > Given: > > x = some_object() > y = x > > I could say that x and y are the same object, rather than x and y are > references to the same object. Huh, fair enough. >> To me, saying "here's an alternative way to look at variables" is great, >> but saying "Python doesn't have variables" is, IMO, at least as silly as >> what Jussi said. To me, dancing around the issue just leads to more >> confusing terminology and makes things worse. >> >> (And this is reinforced by the fact that neither I nor Google seems to >> have really seen "Python doesn't have classes" ever used, when that >> statement is at least as true as "Python doesn't have variables".) > > I think you are utterly wrong here. > > Python has classes. They are created by the "class" keyword. Whether > those classes are identical to Java classes is irrelevant -- in Python, > these whatever-they-are-things are called "classes", and so Python has > classes. > > But Python does not have things called "variables". There is no > "variable" keyword to create a variable. OK, let's make a new language. I'll call it 'Python--' because at least *I* wouldn't want to program in it. :-) In Python--, any time you use a name, you have to prefix it with the word 'variable': variable x = 4 print(variable x) Does Python-- have variables? Does Python? To me, the answer to those questions basically has to be the same -- after all, the new 'variable' keyword didn't really change the language, just have it a slightly different concrete syntax. Heck, if I wanted to implement Python--, the only thing I'd have to change in a Python implementation is the lexer! And if you say "no, Python-- doesn't have variables, it just has something that it wrongly calls variables", then it's no contradiction to say "Python doesn't have classes, it just has something that it wrongly calls classes." Think of it as duck-typing the term "variable". :-) To me, Python locals and globals look and quack like a variable. Incidentally, I also realized another reason I don't like the 'names' description. Take 'foo.bar'. (That is, the 'bar' attribute in object 'foo'.) Is 'foo.bar' a name? I'm not sure what the 'names' proponents would say, but to me both answers are problematic. I *really* dislike a 'no' answer because to me, 'foo.bar' absolutely *is* a name for the corresponding object. (This terminology has precedent.) But a 'yes' answer, if you also reject 'variable', means you no longer have an agreed-upon term for the names that are defined in the current scope -- and such a term is a really good thing to have! (I know, let's call them variables. :-)) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 545 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Thu Aug 23 15:22:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Aug 2012 13:22:16 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> References: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> Message-ID: On Thu, Aug 23, 2012 at 12:33 PM, wrote: >> >>> sys.getsizeof('a' * 80 * 50) >> >> > 4025 >> >> >>>> sys.getsizeof('a' * 80 * 50 + '?') >> >> > 8040 >> >> >> >> This example is still benefiting from shrinking the number of bytes >> >> in half over using 32 bits per character as was the case with Python 3.2: >> >> >> >> >>> sys.getsizeof('a' * 80 * 50) >> >> 16032 >> >> >>> sys.getsizeof('a' * 80 * 50 + '?') >> >> 16036 >> > Correct, but how many times does it happen? > Practically never. What are you talking about? Surely it happens the same number of times that your example happens, since it's the same example. By dismissing this example as being too infrequent to be of any importance, you dismiss the validity of your own example as well. > In this unicode stuff, I'm fascinated by the obsession > to solve a problem which is, due to the nature of > Unicode, unsolvable. > > For every optimization algorithm, for every code > point range you can optimize, it is always possible > to find a case breaking that optimization. So what? Similarly, for any generalized data compression algorithm, it is possible to engineer inputs for which the "compressed" output is as large as or larger than the original input (this is easy to prove). Does this mean that compression algorithms are useless? I hardly think so, as evidenced by the widespread popularity of tools like gzip and WinZip. You seem to be saying that because we cannot pack all Unicode strings into 1-byte or 2-byte per character representations, we should just give up and force everybody to use maximum-width representations for all strings. That is absurd. > Sure, it is possible to optimize the unicode usage > by not using French characters, punctuation, mathematical > symbols, currency symbols, CJK characters... > (select undesired characters here: http://www.unicode.org/charts/). > > In that case, why using unicode? > (A problematic not specific to Python) Obviously, it is because I want to have the *ability* to represent all those characters in my strings, even if I am not necessarily going to take advantage of that ability in every single string that I produce. Not all of the strings I use are going to fit into the 1-byte or 2-byte per character representation. Fine, whatever -- that's part of the cost of internationalization. However, *most* of the strings that I work with (this entire email message, for instance) -- and, I think, most of the strings that any developer works with (identifiers in the standard library, for instance) -- will fit into at least the 2-byte per character representation. Why shackle every string everywhere to 4 bytes per character when for a majority of them we can do much better than that? From breamoreboy at yahoo.co.uk Thu Aug 23 15:34:29 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Aug 2012 20:34:29 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> References: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> Message-ID: On 23/08/2012 19:33, wxjmfauth at gmail.com wrote: > Le jeudi 23 ao?t 2012 15:57:50 UTC+2, Neil Hodgson a ?crit : >> wxjmfauth at gmail.com: >> >> >> >>> Small illustration. Take an a4 page containing 50 lines of 80 ascii >> >>> characters, add a single 'EM DASH' or an 'BULLET' (code points> 0x2000), >> >>> and you will see all the optimization efforts destroyed. >> >>> >> >>>>> sys.getsizeof('a' * 80 * 50) >> >>> 4025 >> >>>>>> sys.getsizeof('a' * 80 * 50 + '?') >> >>> 8040 >> >> >> >> This example is still benefiting from shrinking the number of bytes >> >> in half over using 32 bits per character as was the case with Python 3.2: >> >> >> >> >>> sys.getsizeof('a' * 80 * 50) >> >> 16032 >> >> >>> sys.getsizeof('a' * 80 * 50 + '?') >> >> 16036 >> > Correct, but how many times does it happen? > Practically never. > > In this unicode stuff, I'm fascinated by the obsession > to solve a problem which is, due to the nature of > Unicode, unsolvable. > > For every optimization algorithm, for every code > point range you can optimize, it is always possible > to find a case breaking that optimization. > > This follows quasi the mathematical logic. To proof a > law is valid, you have to proof all the cases > are valid. To proof a law is invalid, just find one > case showing it. > > Sure, it is possible to optimize the unicode usage > by not using French characters, punctuation, mathematical > symbols, currency symbols, CJK characters... > (select undesired characters here: http://www.unicode.org/charts/). > > In that case, why using unicode? > (A problematic not specific to Python) > > jmf > What do you propose should be used instead, as you appear to be the resident expert in the field? -- Cheers. Mark Lawrence. From jan.kuiken at quicknet.nl Thu Aug 23 16:43:41 2012 From: jan.kuiken at quicknet.nl (Jan Kuiken) Date: Thu, 23 Aug 2012 22:43:41 +0200 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: On 8/23/12 20:17 , Ian Kelly wrote: ... >>> Well, there you go. There *is* something wrong with having six variables >>> called 'q'. >> Sometimes you don't want only six variables called 'q' but a hundred >> of them :-) >> >> def fac(q): >> if q < 1 : >> return 1 >> else: >> return q * fac(q-1) >> >> print(fac(100)) > That's only one variable called 'q', instantiated 100 times simultaneously. Bare with me, i come from a C world, and think of each variable, whatever its name or scope, as a piece of memory and therefore different. btw. I like the idea of simultaneously instantiation :-) Jan Kuiken From chris at python.org Thu Aug 23 17:46:19 2012 From: chris at python.org (Chris Withers) Date: Thu, 23 Aug 2012 22:46:19 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: <-9130812546080764300@unknownmsgid> References: <-1016624622349492799@unknownmsgid> <5015DAC6.6060803@gmail.com> <-9130812546080764300@unknownmsgid> Message-ID: <5036A4AB.6020005@python.org> On 30/07/2012 03:31, Rodrick Brown wrote: > Hence the reason why no one will seriously look at Python for none > glue work or simple web apps. When it comes to designing complex > applications that need to exploit large multicore systems Python just > isn't an option. > > Its still not possible to be a pure Python developer and find gainful > employment today. Oh come on, are you *actually* serious? Pretty much everything you've said is nothing but inept bullshit. Please stop. Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From rosuav at gmail.com Thu Aug 23 17:48:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Aug 2012 07:48:20 +1000 Subject: Guarding arithmetic In-Reply-To: <34uc389nu5u681tdadp23l8ksnhcrjv0s2@invalid.netcom.com> References: <8b9a5844-66b0-4940-946a-5e626462cdce@googlegroups.com> <34uc389nu5u681tdadp23l8ksnhcrjv0s2@invalid.netcom.com> Message-ID: On Fri, Aug 24, 2012 at 4:49 AM, Dennis Lee Bieber wrote: > By the time you wrap the equation with a lambda all, named, terms, > AND supply the named terms after the lambda, you might as well just wrap > the equation in a plain try/except block. But closures spare you that hassle. >>> a=1 >>> b=0 >>> print(safe(lambda: a/b)) 42 >>> b=2 >>> print(safe(lambda: a/b)) 0.5 (Example done in Python 3 so semantics are a little different) ChrisA From worldpeaceagentforchange at gmail.com Thu Aug 23 17:56:49 2012 From: worldpeaceagentforchange at gmail.com (Madison May) Date: Thu, 23 Aug 2012 14:56:49 -0700 (PDT) Subject: Books? In-Reply-To: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> Message-ID: <6bdda4a4-cdd2-4298-97bc-43742589f4e9@googlegroups.com> I would definitely take a look at Think Python by Allen Downey if you have minimal prior experience with computer programming. It's succinct yet thorough. From rosuav at gmail.com Thu Aug 23 18:00:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Aug 2012 08:00:59 +1000 Subject: Objects in Python In-Reply-To: <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 24, 2012 at 3:56 AM, Steven D'Aprano wrote: > But name bindings are a kind of variable. Named memory locations are a > *different* kind of variable. The behaviour of C variables and Python > variables do not follow the Liskov Substitution Principle -- you can't > rip out the entire "names bound to objects" machinery of Python and > replace it with C-like named memory locations without changing the high- > level behaviour of Python. And so by some ways of thinking it is *wrong* > to treat name bindings and memory locations as "the same sort of entity". > Hence, if C variables are variables, then Python name bindings can't be. Yet Python's variables are extremely close to C's pointer variables. If you allocate all your "real data" on the heap and do everything with pointers, you'll have semantics very similar to Python's (except that things aren't refcounted, so you have massive memory leaks). In fact, that's how the Python-C API handles things - a PyObject* basically _is_ a Python object, as far as C's concerned. But again, that probably doesn't help explain the variables. Unless you've come from (or can at least imagine) an environment in which you use pointers for *everything*. ChrisA From rosuav at gmail.com Thu Aug 23 19:34:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Aug 2012 09:34:19 +1000 Subject: Variables vs names [was: Objects in Python] In-Reply-To: <503682E0.4060807@cs.wisc.edu> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503682E0.4060807@cs.wisc.edu> Message-ID: On Fri, Aug 24, 2012 at 5:22 AM, Evan Driscoll wrote: > In Python--, any time you use a name, you have to prefix it with the > word 'variable': > variable x = 4 > print(variable x) That gets really unwieldy. You should shorten it to a single symbol. And your language could be called Python Hypertext Preprocessor. ChrisA From ben+python at benfinney.id.au Thu Aug 23 19:49:41 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 24 Aug 2012 09:49:41 +1000 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vcg9yxre.fsf@benfinney.id.au> Steven D'Aprano writes: > No offence to Ben Finney, but I think sometimes he's a bit too eager > to emphasise the subtle differences between Python and other > languages, rather than the similarities. No offense taken. > Again, context is important: Indeed. Note that my assertion was in response to someone *already* confused by pre-conceived notions about what ?variable? means, and misguided attempts to apply those to Python. If it's over-eager to attempt to head off such confusion in others who might be reading, then I deny the charge. Others have said it helps, so I'll keep doing it. > I don't think the differences are important enough to *prohibit* use of > the word "variable" to describe name bindings. Only to discourage it. I wholly agree. -- \ ?Facts do not cease to exist because they are ignored.? ?Aldous | `\ Huxley | _o__) | Ben Finney From rosuav at gmail.com Thu Aug 23 20:01:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Aug 2012 10:01:17 +1000 Subject: Objects in Python In-Reply-To: <3jgd381s8te5mq45c2tntu8nih91nk2i5d@invalid.netcom.com> References: <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <3jgd381s8te5mq45c2tntu8nih91nk2i5d@invalid.netcom.com> Message-ID: On Fri, Aug 24, 2012 at 9:54 AM, Dennis Lee Bieber wrote: > On Fri, 24 Aug 2012 08:00:59 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: > >> >> But again, that probably doesn't help explain the variables. Unless >> you've come from (or can at least imagine) an environment in which you >> use pointers for *everything*. >> > ... but can not manipulate the pointer directly Right, obviously pointer arithmetic doesn't make sense in Python. But that's (almost) guaranteed by the fact that there is NOTHING you can do with bare integers. foo q = new q; /* note that 'foo' is a typedef that hides the asterisk */ foo w = q +1; /* Pointer arith! Impossible. */ But! foo e = q + one; /* one is the object representing the integer 1 */ This isn't pointer arithmetic. No C compiler will let you add two pointers. You can subtract one from another, but you get back a bare integer, which won't go into a 'foo', so the only thing you could do that would break stuff is: foo r = q + (w - e); /* Syntactically valid */ So you just won't do pointer arith if everything's a pointer. There, I think I just broke a few minds. My task here is done. ChrisA From roy at panix.com Thu Aug 23 20:36:27 2012 From: roy at panix.com (Roy Smith) Date: Thu, 23 Aug 2012 20:36:27 -0400 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: In article , Evan Driscoll wrote: > > In fact, Python doesn't have variables ? not as C or Java programmers > > would understand the term. What it has instead are references to objects > > (with names as one kind of reference). > > OK, I've seen this said a few times, and I have to ask: what do you mean > by this? I consider myself pretty decent at Python and other languages, > and I really don't get it. I'll take a shot at this. When I execute: a = 4 I'm doing two things. The first is to create an object of type int with a value of 4. I think everybody is OK with that part. The confusing part comes with the LHS. In C, or Java, there's a container called "a" which holds a value. In C, that value is the integer 4, in Java it's an Integer object (well, at least I think it is, I've never fully groked how Java handles integers). In Python, there is no container named "a". There is, however, a dict which exists somewhere in python-space. You can get a reference to this dict by calling globals(). What the assignment does is effectively: globals()["a"] = 4 In fact, I can even write it that way and everything works: >>> globals()["a"] = 42 >>> a 42 Even id() thinks they're the same thing: >>> id(a) 1755402140 >>> id(globals()["a"]) 1755402140 But, notice what happens if I now assign something new to a: >>> a = 123 >>> id(a) 1755403176 The id has changed! Now, we all know that the id of an object is its memory address (that's not guaranteed, but in the standard C implementation of Python, that's what it is). Now, what if I do something similar in C: #include main() { int a = 40; printf("a = %d, &a = %p\n", a, &a); a = 99; printf("a = %d, &a = %p\n", a, &a); } When I compile and run this, it prints: a = 40, &a = 0x7fff1911f5bc a = 99, &a = 0x7fff1911f5bc Notice that the address of the variable "a" didn't change when I assigned it a new value. That's what people mean when they say C has variables and Python doesn't; it just binds names to values. From rosuav at gmail.com Thu Aug 23 21:34:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Aug 2012 11:34:02 +1000 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: On Fri, Aug 24, 2012 at 10:36 AM, Roy Smith wrote: > In fact, I can even write it that way and everything works: > >>>> globals()["a"] = 42 >>>> a > 42 > > Even id() thinks they're the same thing: > >>>> id(a) > 1755402140 >>>> id(globals()["a"]) > 1755402140 Ah, no. What you have there is actually id(4) and nothing to do with a at all. > But, notice what happens if I now assign something new to a: > >>>> a = 123 >>>> id(a) > 1755403176 > > The id has changed! Now, we all know that the id of an object is its > memory address (that's not guaranteed, but in the standard C > implementation of Python, that's what it is). And you now have id(123) - of course, it's possible for there to be two integer objects with the value 123, but what I'm emphasizing is that you're not looking at a here. > Now, what if I do something similar in C: > > #include > > main() { > int a = 40; > printf("a = %d, &a = %p\n", a, &a); > a = 99; > printf("a = %d, &a = %p\n", a, &a); > } > > When I compile and run this, it prints: > > a = 40, &a = 0x7fff1911f5bc > a = 99, &a = 0x7fff1911f5bc > > Notice that the address of the variable "a" didn't change when I > assigned it a new value. That's what people mean when they say C has > variables and Python doesn't; it just binds names to values. Try this instead. It's C++ not C but a much closer match. You could instead play with malloc if you want it to be C. #include main() { int *a=new int(40); printf("a = %d, id(a) = %p\n",*a,a); a=new int(99); printf("a = %d, id(a) = %p\n",*a,a); } I've not tested the code and may have a syntax issue with "new int(40)" (who ever allocates a single int on the heap??) but you get the idea. At no point do you ever look at, or need to look at, &a. That's utterly irrelevant. ChrisA From perry.bhandal at gmail.com Thu Aug 23 23:13:55 2012 From: perry.bhandal at gmail.com (Perry Bhandal) Date: Thu, 23 Aug 2012 23:13:55 -0400 Subject: Books? In-Reply-To: <6bdda4a4-cdd2-4298-97bc-43742589f4e9@googlegroups.com> References: <5203ee16-5a80-4cd9-9434-ee2efb64515e@kg10g2000pbc.googlegroups.com> <6bdda4a4-cdd2-4298-97bc-43742589f4e9@googlegroups.com> Message-ID: I agree with Madison, think Python is a good choice if you have no programming experience. It'll teach you Python while also covering programming fundamentals. If you have prior programming experience, the Python docs/tutorials should be enough to get you started. On Thu, Aug 23, 2012 at 5:56 PM, Madison May < worldpeaceagentforchange at gmail.com> wrote: > I would definitely take a look at Think Python by Allen Downey if you have > minimal prior experience with computer programming. It's succinct yet > thorough. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Thu Aug 23 23:17:14 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 23 Aug 2012 20:17:14 -0700 (PDT) Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> On Aug 24, 11:34?am, Chris Angelico wrote: > On Fri, Aug 24, 2012 at 10:36 AM, Roy Smith wrote: > > Even id() thinks they're the same thing: > >>>> id(a) > > 1755402140 > >>>> id(globals()["a"]) > > 1755402140 > > Ah, no. What you have there is actually id(4) and nothing to do with a at all. Well, nothing expect for the fact that he's demonstrating Python references and how they bind to objects. Sure, id() isn't doing any lookup, but that's missing the point. > > But, notice what happens if I now assign something new to a: > > >>>> a = 123 > >>>> id(a) > > 1755403176 > > > The id has changed! ?Now, we all know that the id of an object is its > > memory address (that's not guaranteed, but in the standard C > > implementation of Python, that's what it is). > > And you now have id(123) - of course, it's possible for there to be > two integer objects with the value 123, but what I'm emphasizing is > that you're not looking at a here. But Roy's point was that referring to 'a' as a 'variable' makes no sense, as it's not an allocated piece of memory. In fact, he even said "the id of an object" and not "the id of 'a'" so I'm not entirely sure what you're objecting to here. You don't need to emphasise anything as _that was the point_: you're _not_ looking at 'a' _ever_, you're only ever looking at the object to which it refers. From marco_u at nsgmail.com Fri Aug 24 00:35:27 2012 From: marco_u at nsgmail.com (Marco) Date: Fri, 24 Aug 2012 06:35:27 +0200 Subject: Built-in open() with buffering > 1 Message-ID: Please, can anyone explain me the meaning of the "buffering > 1" in the built-in open()? The doc says: "...and an integer > 1 to indicate the size of a fixed-size chunk buffer." So I thought this size was the number of bytes or chars, but it is not: >>> f = open('myfile', 'w', buffering=2) >>> f.write('a') 1 >>> open('myfile').read() '' >>> f.write('b') 1 >>> open('myfile').read() '' >>> f.write('cdefghi\n') 8 >>> open('myfile').read() '' >>> f.flush() >>> open('myfile').read() 'abcdefghi\n' Regards, Marco From marco_u at nsgmail.com Fri Aug 24 01:21:36 2012 From: marco_u at nsgmail.com (Marco) Date: Fri, 24 Aug 2012 07:21:36 +0200 Subject: Built-in open() with buffering > 1 References: Message-ID: On 08/24/2012 06:35 AM, Marco wrote: > Please, can anyone explain me the meaning of the > "buffering > 1" in the built-in open()? > The doc says: "...and an integer > 1 to indicate the size > of a fixed-size chunk buffer." Sorry, I get it: >>> f = open('myfile', 'w', buffering=2) >>> f._CHUNK_SIZE = 5 >>> for i in range(6): ... n = f.write(str(i)) ... print(i, open('myfile').read(), sep=':') ... 0: 1: 2: 3: 4: 5:012345 From levinie001 at gmail.com Fri Aug 24 01:37:49 2012 From: levinie001 at gmail.com (Levi Nie) Date: Fri, 24 Aug 2012 13:37:49 +0800 Subject: Does a wxPython program not run on 64bit Windows? Message-ID: Does a wxPython program not run on 64bit Windows? I saw this ? wxPython is a cross-platform toolkit. This means that the same program will run on multiple platforms without modification. Currently supported platforms are 32-bit Microsoft Windows, most Unix or unix-like systems, and Macintosh OS X. ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Aug 24 02:01:00 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 23 Aug 2012 23:01:00 -0700 (PDT) Subject: Data cleaning workouts References: Message-ID: <5042082c-5764-4c87-897a-776793753f55@r1g2000pbq.googlegroups.com> On Aug 23, 12:52?pm, Fg Nu wrote: > List folk, > > I am a newbie trying to get used to Python. I was wondering if anyone knows of web resources that teach good practices in data cleaning and management for statistics/analytics/machine learning, particularly using Python. > > Ideally, these would be exercises of the form: here is some horrible raw data --> here is what it should look like after it has been cleaned. Guidelines about steps that should always be taken, practices that should be avoided; basically, workflow of data analysis in Python with special emphasis on the cleaning part. Since no one has answered, I suggest you narrow your searching from 'python' to 'scipy' (or 'numpy'). Also perhaps ipython. And then perhaps try those specific mailing lists/fora. Since I dont know this area much, not saying more. From fgnu32 at yahoo.com Fri Aug 24 02:48:17 2012 From: fgnu32 at yahoo.com (Fg Nu) Date: Thu, 23 Aug 2012 23:48:17 -0700 (PDT) Subject: Data cleaning workouts In-Reply-To: <5042082c-5764-4c87-897a-776793753f55@r1g2000pbq.googlegroups.com> References: <5042082c-5764-4c87-897a-776793753f55@r1g2000pbq.googlegroups.com> Message-ID: <1345790897.27768.YahooMailNeo@web122401.mail.ne1.yahoo.com> Thanks. I will try the?SciPy?list. It was a bit of a hail mary anyway. Pretty sure elevated Python types don't actually get their hands dirty with data. ;) ----- Original Message ----- From: rusi To: python-list at python.org Cc: Sent: Thursday, August 23, 2012 11:01 PM Subject: Re: Data cleaning workouts On Aug 23, 12:52?pm, Fg Nu wrote: > List folk, > > I am a newbie trying to get used to Python. I was wondering if anyone knows of web resources that teach good practices in data cleaning and management for statistics/analytics/machine learning, particularly using Python. > > Ideally, these would be exercises of the form: here is some horrible raw data --> here is what it should look like after it has been cleaned. Guidelines about steps that should always be taken, practices that should be avoided; basically, workflow of data analysis in Python with special emphasis on the cleaning part. Since no one has answered, I suggest you narrow your searching from 'python' to 'scipy' (or 'numpy'). Also perhaps ipython. And then perhaps try those specific mailing lists/fora. Since I dont know this area much, not saying more. -- http://mail.python.org/mailman/listinfo/python-list From antoon.pardon at rece.vub.ac.be Fri Aug 24 03:38:48 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 24 Aug 2012 09:38:48 +0200 Subject: Objects in Python In-Reply-To: <87d32i1ntc.fsf@benfinney.id.au> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: <50372F88.5000306@rece.vub.ac.be> On 23-08-12 01:58, Ben Finney wrote: > > You haven't discovered anything about types; what you have discovered is > that Python name bindings are not variables. > > In fact, Python doesn't have variables ? not as C or Java programmers > would understand the term. What it has instead are references to objects > (with names as one kind of reference). > > The documentation unfortunately calls these references ?variables? in > various places, which IMO compounds the confusion in newcomers > experienced with other languages. It's best, I think, to reject the idea > that Python has variables, and think in terms of references instead. > Why should we reject the idea that python has variables? Python variables are a lot like scheme or smalltalk variables and I never heard anyone having a problem considering these languages having variables. From antoon.pardon at rece.vub.ac.be Fri Aug 24 04:03:29 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 24 Aug 2012 10:03:29 +0200 Subject: Objects in Python In-Reply-To: <50372F88.5000306@rece.vub.ac.be> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <50372F88.5000306@rece.vub.ac.be> Message-ID: <50373551.9010500@rece.vub.ac.be> On 24-08-12 09:38, Antoon Pardon wrote: > On 23-08-12 01:58, Ben Finney wrote: > >> You haven't discovered anything about types; what you have discovered is >> that Python name bindings are not variables. >> >> In fact, Python doesn't have variables ? not as C or Java programmers >> would understand the term. What it has instead are references to objects >> (with names as one kind of reference). >> >> The documentation unfortunately calls these references ?variables? in >> various places, which IMO compounds the confusion in newcomers >> experienced with other languages. It's best, I think, to reject the idea >> that Python has variables, and think in terms of references instead. >> >> > Why should we reject the idea that python has variables? Python > variables are a lot like scheme or smalltalk variables and I never > heard anyone having a problem considering these languages > having variables. > Never mind. I missed the reactions already dealing with this. -- Antoon Pardon From breamoreboy at yahoo.co.uk Fri Aug 24 04:16:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Aug 2012 09:16:30 +0100 Subject: Data cleaning workouts In-Reply-To: <1345790897.27768.YahooMailNeo@web122401.mail.ne1.yahoo.com> References: <5042082c-5764-4c87-897a-776793753f55@r1g2000pbq.googlegroups.com> <1345790897.27768.YahooMailNeo@web122401.mail.ne1.yahoo.com> Message-ID: Elevated Python types don't get their hands dirty top posting, but I'm certain that they would when talking data or there wouldn't be so many debates on which data type to use :) On 24/08/2012 07:48, Fg Nu wrote: > > > Thanks. I will try the SciPy list. It was a bit of a hail mary anyway. Pretty sure elevated Python types don't actually get their hands dirty with data. ;) > > > > ----- Original Message ----- > From: rusi > To: python-list at python.org > Cc: > Sent: Thursday, August 23, 2012 11:01 PM > Subject: Re: Data cleaning workouts > > On Aug 23, 12:52 pm, Fg Nu wrote: >> List folk, >> >> I am a newbie trying to get used to Python. I was wondering if anyone knows of web resources that teach good practices in data cleaning and management for statistics/analytics/machine learning, particularly using Python. >> >> Ideally, these would be exercises of the form: here is some horrible raw data --> here is what it should look like after it has been cleaned. Guidelines about steps that should always be taken, practices that should be avoided; basically, workflow of data analysis in Python with special emphasis on the cleaning part. > > Since no one has answered, I suggest you narrow your searching from > 'python' to 'scipy' (or 'numpy'). > Also perhaps ipython. > And then perhaps try those specific mailing lists/fora. > > Since I dont know this area much, not saying more. > -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Aug 24 04:25:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Aug 2012 09:25:08 +0100 Subject: Does a wxPython program not run on 64bit Windows? In-Reply-To: References: Message-ID: On 24/08/2012 06:37, Levi Nie wrote: > Does a wxPython program not run on 64bit Windows? > > I saw this ? > wxPython is a cross-platform toolkit. This means that the same program > will run on multiple platforms without modification. Currently > supported platforms are 32-bit Microsoft Windows, most Unix or > unix-like systems, and Macintosh OS X. > ? > > > Why don't you try it and see what happens? -- Cheers. Mark Lawrence. From gandalf at shopzeus.com Fri Aug 24 04:45:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 24 Aug 2012 10:45:10 +0200 Subject: Does a wxPython program not run on 64bit Windows? In-Reply-To: References: Message-ID: <50373F16.1010009@shopzeus.com> On 2012-08-24 07:37, Levi Nie wrote: > Does a wxPython program not run on 64bit Windows? Did you at least try to download wxPython? Because the download page shows the 64bit and the 32bit versions as well. :-) http://wxpython.org/download.php By the way, the 32bit version will gladly run on a 64bit Windows. However, you will have to install the 32bit version of Python for that. (And yes, 32bit Python also runs on 64bit Windows.) wxPython also runs on OS X, and probably on any platform that runs gtk. (Practically, all popular unices.) From driscoll at cs.wisc.edu Fri Aug 24 05:14:27 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Fri, 24 Aug 2012 04:14:27 -0500 Subject: Objects in Python In-Reply-To: <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> Message-ID: <503745F3.2040401@cs.wisc.edu> On 8/23/2012 22:17, alex23 wrote: > But Roy's point was that referring to 'a' as a 'variable' makes no > sense, as it's not an allocated piece of memory. Does the computer just remember what 'a' refers to by keeping notes about it in Narnia? Put it this way. If C removed the & operator -- and thus you couldn't tell what address a variable (or "variable instance", if you prefer) was at -- would "int x;" cease to be a variable? Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From steve+comp.lang.python at pearwood.info Fri Aug 24 06:00:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Aug 2012 10:00:26 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> Message-ID: <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Aug 2012 04:14:27 -0500, Evan Driscoll wrote: > On 8/23/2012 22:17, alex23 wrote: >> But Roy's point was that referring to 'a' as a 'variable' makes no >> sense, as it's not an allocated piece of memory. > > Does the computer just remember what 'a' refers to by keeping notes > about it in Narnia? No. The compiler remembers the address of 'a' by keeping notes about it somewhere in memory during the compilation process. When you run the compiled program, there is no longer any reference to the name 'a'. (Many compilers give you the option to keep variable names, but that's additional debugging data, not an essential part of the execution model.) The mapping of name:address is part of the *compilation* process -- the compiler knows that variable 'x' corresponds to location 12345678, but the compiled code has no concept of anything called 'x'. It only knows about locations. The source code 'x = 42' is compiled into something like 'store 42 into location 12345678'. (Locations may be absolute or relative.) In languages with name bindings, the compiler doesn't need to track name:address pairs. The compiled application knows about names, but not about addresses. The source code 'x = 42' is compiled into something like 'store 42 into the namespace using key "x"'. Python gives you no way to peek at an address. It's not even clear what the address of the variable would be, because there are *at least three* things it could be: 1) the address of the key field in the namespace (where the name lives); 2) the address of the value field in the namespace (where the pointer to the object lives); 3) the address of the object itself. And any of these are free to move around during the lifetime of the application. (E.g. in Jython, which runs under the JVM, objects don't have a fixed location.) > Put it this way. If C removed the & operator -- and thus you couldn't > tell what address a variable (or "variable instance", if you prefer) was > at -- would "int x;" cease to be a variable? Not at all. Just because the public interface of the language doesn't give you any way to view the fixed locations of variables, doesn't mean that variables cease to have fixed locations. -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 24 06:06:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Aug 2012 10:06:33 GMT Subject: Identity function id() [was Re: Objects in Python] References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> Message-ID: <50375228$0$6574$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Aug 2012 20:36:27 -0400, Roy Smith wrote: > The id has changed! Now, we all know that the id of an object is its > memory address (that's not guaranteed, but in the standard C > implementation of Python, that's what it is). It's not only "not guaranteed", it is *explicitly* noted as an implementation detail. The id of the object is an arbitrary number guaranteed to be unique during the lifetime of that object. It just happens that CPython currently uses the memory address as the id. Jython does not: steve at runes:~$ jython Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> id(x) 1 Nor does IronPython: steve at runes:~$ ipy IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET 2.0.50727.1433 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> id(x) 43 -- Steven From vs at it.uu.se Fri Aug 24 06:28:40 2012 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 24 Aug 2012 12:28:40 +0200 Subject: Installation of yappi (timing module) Message-ID: <50375758.5060800@it.uu.se> I have been doing some experiments with different modules for the timing of functions and code segments. One module I would like to test is yappi (thread aware timer) which is listed at PyPI. However, I have been unable to install it on Windows Vista and Windows 7 (Python 2.7 on both). I have tried both easy_install and pip (as suggested at http://code.google.com/p/yappi/). Here is what happens with easy_install C:\Users\Virgil>easy_install yappi Searching for yappi Reading http://pypi.python.org/simple/yappi/ Reading http://yappi.googlecode.com/ Best match: yappi 0.62 Downloading http://yappi.googlecode.com//files/yappi-0.62.tar.gz Processing yappi-0.62.tar.gz Writing c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\setup.cfg Running yappi-0.62\setup.py -q bdist_egg --dist-dir c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\egg-dist-tmp-t3qodo In file included from D:\python27\include\Python.h:8, from config.h:4, from _yappi.c:10: D:\python27\include\pyconfig.h:68: io.h: No such file or directory D:\python27\include\pyconfig.h:296: stdio.h: No such file or directory In file included from config.h:4, from _yappi.c:10: D:\python27\include\Python.h:19: limits.h: No such file or directory D:\python27\include\Python.h:22: #error "Something's broken. UCHAR_MAX should be defined in limits.h." D:\python27\include\Python.h:26: #error "Python's source code assumes C's unsigned char is an 8-bit type." D:\python27\include\Python.h:33: stdio.h: No such file or directory D:\python27\include\Python.h:35: #error "Python.h requires that stdio.h define NULL." D:\python27\include\Python.h:38: string.h: No such file or directory D:\python27\include\Python.h:40: errno.h: No such file or directory D:\python27\include\Python.h:42: stdlib.h: No such file or directory D:\python27\include\Python.h:49: stddef.h: No such file or directory D:\python27\include\Python.h:56: assert.h: No such file or directory In file included from D:\python27\include\Python.h:58, from config.h:4, from _yappi.c:10: D:\python27\include\pyport.h:306: stdlib.h: No such file or directory D:\python27\include\pyport.h:312: math.h: No such file or directory D:\python27\include\pyport.h:325: time.h: No such file or directory D:\python27\include\pyport.h:377: sys\stat.h: No such file or directory In file included from D:\python27\include\Python.h:85, from config.h:4, from _yappi.c:10: D:\python27\include\unicodeobject.h:4: stdarg.h: No such file or directory D:\python27\include\unicodeobject.h:57: ctype.h: No such file or directory D:\python27\include\unicodeobject.h:120: wchar.h: No such file or directory In file included from D:\python27\include\Python.h:94, from config.h:4, from _yappi.c:10: D:\python27\include\stringobject.h:10: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:98, from config.h:4, from _yappi.c:10: D:\python27\include\bytearrayobject.h:9: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:121, from config.h:4, from _yappi.c:10: D:\python27\include\pyerrors.h:319: stdarg.h: No such file or directory In file included from D:\python27\include\Python.h:126, from config.h:4, from _yappi.c:10: D:\python27\include\modsupport.h:10: stdarg.h: No such file or directory In file included from _yappi.c:10: config.h:15: stdint.h: No such file or directory In file included from _yappi.c:23: timing.h:8: windows.h: No such file or directory error: Setup script exited with error: command 'gcc' failed with exit status 1 And pip fails with similar problems (same pyconfig errors where C++ header files are not found). In both cases yappi-0.62.tar.gz was downloaded.Note: 1) I also tried to install from the source which also failed with similar problems, 2) I have both cygwin and MinGW gcc compilers on my systems and they do contain in their include folder these "missing" header files. Any suggestions on how yappi can be installed would be appreciated. --V :-) From lipskathekat at yahoo.co.uk Fri Aug 24 07:03:32 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 24 Aug 2012 12:03:32 +0100 Subject: Is Python a commercial proposition ? In-Reply-To: References: <-1016624622349492799@unknownmsgid> <5015DAC6.6060803@gmail.com> <-9130812546080764300@unknownmsgid> Message-ID: On 23/08/12 22:46, Chris Withers wrote: > On 30/07/2012 03:31, Rodrick Brown wrote: >> Hence the reason why no one will seriously look at Python for none >> glue work or simple web apps. When it comes to designing complex >> applications that need to exploit large multicore systems Python just >> isn't an option. >> >> Its still not possible to be a pure Python developer and find gainful >> employment today. > > Oh come on, are you *actually* serious? > > Pretty much everything you've said is nothing but inept bullshit. > Please stop. OK, well excuse me for butting in but it's obvious from your website that you have some experience with Python in the 'real world' I'd be most interested to hear if you have experience of or have heard of Python being used in any of the following circumstances. Critical Systems: wikipedia does a better job than I on the definition of a critical system although I'm not suggesting that everything in this article refers to a potential software system but it's a good illustration. http://en.wikipedia.org/wiki/Life-critical_system Real time systems: An example of a real time system in this context is an odds arbitrage back end publishing to the WWW via a collection of web services, of course this is just one possible interface, it could publish to another computer system or another HCI This requirement of course implies a complete decoupling of view and implementation. For more on odds arbitrage http://en.wikipedia.org/wiki/Arbitrage_betting It's 'real time' because publishing incorrect odds could cost someone a great deal of money, the odds need to be available for manipulation by the arbitrage engine as soon as they appear on the relevant bookies website (in fact I've had them appearing _before_ this as I managed to process them before the bookies web site did :-). http://www.python.org/about/success/#real-time has a few examples but I'd be interested to hear 'from the horses mouth' Again, wikipedia is your friend http://en.wikipedia.org/wiki/Real-time_computing What is the largest Python project you have experience of, you can use any metric you want, a simple KLOC, function point or cost analysis will be fine. This is a genuine enquiry and not designed to 'diss' Python in any way. Many thanks lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From contropinion at gmail.com Fri Aug 24 07:47:15 2012 From: contropinion at gmail.com (contro opinion) Date: Fri, 24 Aug 2012 07:47:15 -0400 Subject: squeeze install python-gi Message-ID: ???squeeze ????python-gi,??squeeze??? from gi.repository import Gtk def destroy_cb(widget): Gtk.main_quit() w = Gtk.Window() w.connect('destroy', destroy_cb) l = Gtk.Label() l.set_text("Hello World!") w.add(l) w.show_all() Gtk.main() ???????????squeeze????? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Fri Aug 24 07:49:38 2012 From: wuwei23 at gmail.com (wu wei) Date: Fri, 24 Aug 2012 21:49:38 +1000 Subject: Objects in Python In-Reply-To: <503745F3.2040401@cs.wisc.edu> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503745F3.2040401@cs.wisc.edu> Message-ID: On Fri, Aug 24, 2012 at 7:14 PM, Evan Driscoll wrote: > On 8/23/2012 22:17, alex23 wrote: > > But Roy's point was that referring to 'a' as a 'variable' makes no > > sense, as it's not an allocated piece of memory. > > Does the computer just remember what 'a' refers to by keeping notes > about it in Narnia? > You're correct. It will be, on some level, a piece of memory. But I don't recall seeing any guarantee that the memory used to hold the dictionary key of 'a' in one scope would be re-used if 'a' was first deleted and then re-created. It's an implementation detail about the language that we don't care about. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pedro.larroy.lists at gmail.com Fri Aug 24 09:18:05 2012 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Fri, 24 Aug 2012 15:18:05 +0200 Subject: protobuf + pypy In-Reply-To: References: Message-ID: _with pypy_ On Wed, Aug 22, 2012 at 12:16 AM, Mark Lawrence wrote: > On 21/08/2012 22:55, Pedro Larroy wrote: >> >> Hi >> >> Anyone knows if it's possible to use protobuffers with pypy? Seems >> there isn't much info on the web about this. >> >> Pedro. >> > > Did you mean this, in which case there loads on the web > http://code.google.com/p/protobuf/ ? > > -- > Cheers. > > Mark Lawrence. > > -- > http://mail.python.org/mailman/listinfo/python-list From news at blinne.net Fri Aug 24 09:23:29 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 24 Aug 2012 15:23:29 +0200 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035B64D.2080008@cs.wisc.edu> Message-ID: <50378052$0$6573$9b4e6d93@newsspool3.arcor-online.net> On 23.08.2012 20:30, Dennis Lee Bieber wrote: > On Thu, 23 Aug 2012 15:33:33 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: >> x = 1; >> >> In C, this means: Assign the integer 1 to the variable x (possibly >> with implicit type casting, eg to floating point). >> > Or, at an even lower level... > > Convert the decimal literal "1" to binary (including type casting) > to the predeclared type given to the variable "x", and store that binary > value into the predetermined memory associated with "x". Not really the way i would view it. The conversion to binary of the string "1" is part of the parsers and compilers work in order to do what the language reference says about the meaning of x=1;. The resulting code would simply store the binary value of an integer 1 (which is contained in the code as is, nothing has to be converted or typecasted) into the location corresponding to the variable x. So in C x=1; really means store integer 1 to the variable x. From invalid at invalid.invalid Fri Aug 24 09:27:23 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 24 Aug 2012 13:27:23 +0000 (UTC) Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-08-24, Steven D'Aprano wrote: > On Fri, 24 Aug 2012 04:14:27 -0500, Evan Driscoll wrote: > >> On 8/23/2012 22:17, alex23 wrote: >>> But Roy's point was that referring to 'a' as a 'variable' makes no >>> sense, as it's not an allocated piece of memory. >> >> Does the computer just remember what 'a' refers to by keeping notes >> about it in Narnia? > > No. The compiler remembers the address of 'a' by keeping notes about it > somewhere in memory during the compilation process. Ah, but as we are always fond of saying in this group "that's an implementation detail, and not part of the language definition". The model where a compiler is "keeping notes about it in Narnia" is also perfectly valid. However, RAM is easier to find than magic wardrobes, so the "notes" are usually kept in RAM these days. -- Grant Edwards grant.b.edwards Yow! You mean you don't at want to watch WRESTLING gmail.com from ATLANTA? From ramit.prasad at jpmorgan.com Fri Aug 24 09:53:35 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 24 Aug 2012 13:53:35 +0000 Subject: Top-posting &c. In-Reply-To: <9msbg9-dop.ln1@satorlaser.homedns.org> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> Message-ID: <5B80DD153D7D744689F57F4FB69AF47416609F42@SCACMX008.exchad.jpmchase.net> Ulrich Eckhardt wrote: > A good tool would reduce the effort and guide users, like e.g. giving > them a hint if they leave the whole mail they're replying to as copy. > Several corporate email solutions (like MS Outlook/Exchange) put very > little emphasis on communication efficiency but only on eye-candy > features. Their popularity and the resulting influence on people has > caused decay in average communication culture, and that is what I blame > them for. True, but it is by no means impossible or very difficult. It just requires some effort. I blame the user more and the software less because of quotes like below. [ Not Ulrich ] > GMail uses top-posting by default. [ Back to Ulrich ] > BTW: You omitted the attribution line for the text you quoted, whom do > you blame for that? That said, "Nonsense" is a strong enough word to > start a flamewar... not nice. Fair enough. I typically leave off attribution because I would rather to discuss things with quotes instead of he-said and she-said. The focus should be on the idea/conversation and less about attributing "blame" to someone (and it is invariably more often negative attribution than positive). If attribution is preferred, I suppose I could always add it back in. Ironically, this is one of the things I wish Outlook was better about. Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From maniandram01 at gmail.com Fri Aug 24 10:23:35 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:23:35 -0700 (PDT) Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> Message-ID: <90450051-cb5c-49de-b87c-bfc5ef531ef6@googlegroups.com> As BFDL, I hereby command everybody to stop the discussion. lets put time on useful stuff i am using google groups (i think it knows what to do) From maniandram01 at gmail.com Fri Aug 24 10:23:35 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:23:35 -0700 (PDT) Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> Message-ID: <90450051-cb5c-49de-b87c-bfc5ef531ef6@googlegroups.com> As BFDL, I hereby command everybody to stop the discussion. lets put time on useful stuff i am using google groups (i think it knows what to do) From maniandram01 at gmail.com Fri Aug 24 10:27:44 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:27:44 -0700 (PDT) Subject: squeeze install python-gi In-Reply-To: References: Message-ID: On Friday, 24 August 2012 17:17:15 UTC+5:30, contro opinion wrote: > ???squeeze ????python-gi,??squeeze??? > > > from gi.repository import Gtk > > def destroy_cb(widget): > ????Gtk.main_quit() > > w = Gtk.Window() > w.connect('destroy', destroy_cb) > > l = Gtk.Label() > > l.set_text("Hello World!") > w.add(l) > > w.show_all() > Gtk.main() > > ???????????squeeze????? English translation by Google translate (machine translated): I found that the squeeze can not install python-gi, squeeze version from gi.repository import Gtk def destroy_cb(widget): Gtk.main_quit() w = Gtk.Window() w.connect('destroy', destroy_cb) l = Gtk.Label() l.set_text("Hello World!") w.add(l) w.show_all() Gtk.main() This simple code, unable to squeeze inside run? From maniandram01 at gmail.com Fri Aug 24 10:27:44 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:27:44 -0700 (PDT) Subject: squeeze install python-gi In-Reply-To: References: Message-ID: On Friday, 24 August 2012 17:17:15 UTC+5:30, contro opinion wrote: > ???squeeze ????python-gi,??squeeze??? > > > from gi.repository import Gtk > > def destroy_cb(widget): > ????Gtk.main_quit() > > w = Gtk.Window() > w.connect('destroy', destroy_cb) > > l = Gtk.Label() > > l.set_text("Hello World!") > w.add(l) > > w.show_all() > Gtk.main() > > ???????????squeeze????? English translation by Google translate (machine translated): I found that the squeeze can not install python-gi, squeeze version from gi.repository import Gtk def destroy_cb(widget): Gtk.main_quit() w = Gtk.Window() w.connect('destroy', destroy_cb) l = Gtk.Label() l.set_text("Hello World!") w.add(l) w.show_all() Gtk.main() This simple code, unable to squeeze inside run? From maniandram01 at gmail.com Fri Aug 24 10:32:52 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:32:52 -0700 (PDT) Subject: Built-in open() with buffering > 1 In-Reply-To: References: Message-ID: `f._CHUNK_SIZE = 5` is modifying Python's internal variables - don't do that google buffering to find out what it is buffering is how much Python will keep in memory f.read(1) will actually read `buffering` bytes of memory so that when you read later, the reading can be done from memory On Friday, 24 August 2012 10:51:36 UTC+5:30, Marco wrote: > On 08/24/2012 06:35 AM, Marco wrote: > > > Please, can anyone explain me the meaning of the > > > "buffering > 1" in the built-in open()? > > > The doc says: "...and an integer > 1 to indicate the size > > > of a fixed-size chunk buffer." > > > > Sorry, I get it: > > > > >>> f = open('myfile', 'w', buffering=2) > > >>> f._CHUNK_SIZE = 5 > > >>> for i in range(6): > > ... n = f.write(str(i)) > > ... print(i, open('myfile').read(), sep=':') > > ... > > 0: > > 1: > > 2: > > 3: > > 4: > > 5:012345 From maniandram01 at gmail.com Fri Aug 24 10:38:11 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:38:11 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: Message-ID: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> On Thursday, 23 August 2012 18:17:29 UTC+5:30, (unknown) wrote: > This is neither a complaint nor a question, just a comment. > > > > In the previous discussion related to the flexible > > string representation, Roy Smith added this comment: > > > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/2645504f459bab50/eda342573381ff42 > > > > Not only I agree with his sentence: > > "Clearly, the world has moved to a 32-bit character set." > > > > he used in his comment a very intersting word: "punctuation". > > > > There is a point which is, in my mind, not very well understood, > > "digested", underestimated or neglected by many developers: > > the relation between the coding of the characters and the typography. > > > > Unicode (the consortium), does not only deal with the coding of > > the characters, it also worked on the characters *classification*. > > > > A deliberatly simplistic representation: "letters" in the bottom > > of the table, lower code points/integers; "typographic characters" > > like punctuation, common symbols, ... high in the table, high code > > points/integers. > > > > The conclusion is inescapable, if one wish to work in a "unicode > > mode", one is forced to use the whole palette of the unicode > > code points, this is the *nature* of Unicode. > > > > Technically, believing that it possible to optimize only a subrange > > of the unicode code points range is simply an illusion. A lot of > > work, probably quite complicate, which finally solves nothing. > > > > Python, in my mind, fell in this trap. > > > > "Simple is better than complex." > > -> hard to maintained > > "Flat is better than nested." > > -> code points range > > "Special cases aren't special enough to break the rules." > > -> special unicode code points? > > "Although practicality beats purity." > > -> or the opposite? > > "In the face of ambiguity, refuse the temptation to guess." > > -> guessing a user will only work with the "optimmized" char subrange. > > ... > > > > Small illustration. Take an a4 page containing 50 lines of 80 ascii > > characters, add a single 'EM DASH' or an 'BULLET' (code points > 0x2000), > > and you will see all the optimization efforts destroyed. > > > > >> sys.getsizeof('a' * 80 * 50) > > 4025 > > >>> sys.getsizeof('a' * 80 * 50 + '?') > > 8040 > > > > Just my 2 ? (code point 0x20ac) cents. > > > > jmf The zen of python is simply a guideline From breamoreboy at yahoo.co.uk Fri Aug 24 10:43:38 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Aug 2012 15:43:38 +0100 Subject: Top-posting &c. In-Reply-To: <90450051-cb5c-49de-b87c-bfc5ef531ef6@googlegroups.com> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> <90450051-cb5c-49de-b87c-bfc5ef531ef6@googlegroups.com> Message-ID: On 24/08/2012 15:23, Ramchandra Apte wrote: > As BFDL, I hereby command everybody to stop the discussion. > lets put time on useful stuff Well I didn't vote for you :) > > i am using google groups (i think it knows what to do) > -- Cheers. Mark Lawrence. From maniandram01 at gmail.com Fri Aug 24 10:44:27 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:44:27 -0700 (PDT) Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> On Wednesday, 22 August 2012 22:13:04 UTC+5:30, Terry Reedy wrote: > On 8/22/2012 3:30 AM, Mark Lawrence wrote: > > > On 22/08/2012 06:46, Terry Reedy wrote: > > >> On 8/21/2012 11:43 PM, mingqiang hu wrote: > > >>> why filter is bad when use lambda ? > > >> > > >> Inefficient, not 'bad'. Because the equivalent comprehension or > > >> generator expression does not require a function call. > > > > for each item in the iterable. > > > > > A case of premature optimisation? :) > > > > No, as regards my post. I simply made a factual statement without > > advocating a particular action. > > > > filter(lambda x: , iterable) > > (x for x in iterable if ) > > > > both create iterators that produce the items in iterable such that > > bool() is true. The following, with output rounded, shows > > something of the effect of the extra function call. > > > > >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(0)") > > 0.91 > > >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(20)") > > 1.28 > > >>> timeit.timeit("list(filter(lambda i: False, ranger))", > > "ranger=range(0)") > > 0.83 > > >>> timeit.timeit("list(filter(lambda i: False, ranger))", > > "ranger=range(20)") > > 2.60 > > > > Simply keeping true items is faster with filter -- at least on my > > particular machine with 3.3.0b2. > > > > >>> timeit.timeit("list(filter(None, ranger))", "ranger=range(20)") > > 1.03 > > > > Filter is also faster if the expression is a function call. > > > > >>> timeit.timeit("list(filter(f, ranger))", "ranger=range(20); > > f=lambda i: False") > > 2.5033614114454394 > > >>> timeit.timeit("list(i for i in ranger if f(i))", "ranger=range(20); > > f=lambda i: False") > > 3.2394095327040304 > > > > --- > > Perhaps or even yes as regards the so-called rule 'always use > > comprehension'. If one prefers filter as more readable, if one only > > wants to keep true items, if the expression is a function call, if > > evaluating the expression takes much more time than the extra function > > call so the latter does not matter, if the number of items is few enough > > that the extra time does not matter, then the rule is not needed or even > > wrong. > > > > So I think PyLint should be changed to stop its filter fud. > > > > -- > > Terry Jan Reedy When filtering for true values, filter(None,xxx) can be used Your examples with lambda i:False are unrealistic - you are comparing `if False` vs (xx) - function call vs boolean check From maniandram01 at gmail.com Fri Aug 24 10:44:27 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:44:27 -0700 (PDT) Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> On Wednesday, 22 August 2012 22:13:04 UTC+5:30, Terry Reedy wrote: > On 8/22/2012 3:30 AM, Mark Lawrence wrote: > > > On 22/08/2012 06:46, Terry Reedy wrote: > > >> On 8/21/2012 11:43 PM, mingqiang hu wrote: > > >>> why filter is bad when use lambda ? > > >> > > >> Inefficient, not 'bad'. Because the equivalent comprehension or > > >> generator expression does not require a function call. > > > > for each item in the iterable. > > > > > A case of premature optimisation? :) > > > > No, as regards my post. I simply made a factual statement without > > advocating a particular action. > > > > filter(lambda x: , iterable) > > (x for x in iterable if ) > > > > both create iterators that produce the items in iterable such that > > bool() is true. The following, with output rounded, shows > > something of the effect of the extra function call. > > > > >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(0)") > > 0.91 > > >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(20)") > > 1.28 > > >>> timeit.timeit("list(filter(lambda i: False, ranger))", > > "ranger=range(0)") > > 0.83 > > >>> timeit.timeit("list(filter(lambda i: False, ranger))", > > "ranger=range(20)") > > 2.60 > > > > Simply keeping true items is faster with filter -- at least on my > > particular machine with 3.3.0b2. > > > > >>> timeit.timeit("list(filter(None, ranger))", "ranger=range(20)") > > 1.03 > > > > Filter is also faster if the expression is a function call. > > > > >>> timeit.timeit("list(filter(f, ranger))", "ranger=range(20); > > f=lambda i: False") > > 2.5033614114454394 > > >>> timeit.timeit("list(i for i in ranger if f(i))", "ranger=range(20); > > f=lambda i: False") > > 3.2394095327040304 > > > > --- > > Perhaps or even yes as regards the so-called rule 'always use > > comprehension'. If one prefers filter as more readable, if one only > > wants to keep true items, if the expression is a function call, if > > evaluating the expression takes much more time than the extra function > > call so the latter does not matter, if the number of items is few enough > > that the extra time does not matter, then the rule is not needed or even > > wrong. > > > > So I think PyLint should be changed to stop its filter fud. > > > > -- > > Terry Jan Reedy When filtering for true values, filter(None,xxx) can be used Your examples with lambda i:False are unrealistic - you are comparing `if False` vs (xx) - function call vs boolean check From maniandram01 at gmail.com Fri Aug 24 10:45:44 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 24 Aug 2012 07:45:44 -0700 (PDT) Subject: psphere: how to make thread safe In-Reply-To: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> References: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> Message-ID: <85ee8513-648c-4322-af33-0448e7a35c1e@googlegroups.com> On Wednesday, 22 August 2012 17:33:48 UTC+5:30, sajuptpm wrote: > Hi, > > > > psphere: Python interface for the VMware vSphere Web Services SDK > > > > I already developed an app using https://bitbucket.org/jkinred/psphere. But getting lot of errors since psphere is not thread safe (I think). So i wrote couple of scripts to test it (See attached files) and found that caching mechanism used by psphere is not thread safe. Could someone please give me some suggestion to make it thread safe. > > > > > > =======Test Code ======== > > > > import psphere > > from psphere.client import Client > > from psphere.managedobjects import HostSystem, VirtualMachine, ComputeResource > > client = Client("192.168.0.114", "root", "vmware1") ##vCenter > > print "\nSucessfully connected to vCenter.\n" > > > > from threading import Thread > > > > def myfunc(i): > > host1 = HostSystem.get(client, name="192.168.0.134") > > host2 = HostSystem.get(client, name="192.168.0.113") > > print "----i------",i > > while True: > > #host1.update(properties=["config", "vm"]) > > #host2.update(properties=["config", "vm"]) > > c = type(host1.config.network) > > v = type(host2.config.network) > > for vm in host1.vm: > > k = vm.config.template > > for vm in host2.vm: > > p = vm.config.template > > > > > > for i in range(10): > > t = Thread(target=myfunc, args=(i,)) > > t.start() > > > > > > """ > > OUTPUT > > ======= > > Sucessfully connected to vCenter. > > > > ----i------ 1 > > ----i------ 3 > > ----i------ 5 > > ----i------ 0 > > ----i------ 4 > > ----i------ 2----i------ 7 > > ----i------ > > 9 > > ----i------ 6 > > ----i------ 8 > > Exception in thread Thread-4: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/threading.py", line 504, in run > > self.__target(*self.__args, **self.__kwargs) > > File "vcenter_test1.py", line 19, in myfunc > > k = vm.config.template > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 79, in __get__ > > value = self.fget(inst) > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/managedobjects.py", line 1236, in config > > return self._get_dataobject("config", False) > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 116, in _get_dataobject > > return self._cache[name][0] > > KeyError: 'config' > > > > Exception in thread Thread-6: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/threading.py", line 504, in run > > self.__target(*self.__args, **self.__kwargs) > > File "vcenter_test1.py", line 17, in myfunc > > v = type(host2.config.network) > > AttributeError: VirtualMachineConfigInfo instance has no attribute 'network' > > > > > > > > """ use locks please on the cache From gandalf at shopzeus.com Fri Aug 24 10:54:05 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 24 Aug 2012 16:54:05 +0200 Subject: something about split()??? In-Reply-To: References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> Message-ID: <5037958D.2080000@shopzeus.com> On 2012-08-15 07:33, Ramchandra Apte wrote: > filter is bad when you use lambda with it > there are (good) cases for filter > > On 14 August 2012 22:39, Jean-Michel Pichavant > wrote: > > Ramchandra Apte wrote: > > (Much) more Pythonic solution: > >>> filter(None,"|".split("|")) > > On 14 August 2012 15:14, Andreas Tawn > > >> wrote: > > > I have a question about the split function? surpose a = > "|",and > when I use a.split("|") , I got the list > > ['"",""] ,but I want to get the empty list,what should I > do ? > Too many top posters again :-( -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Aug 24 11:58:56 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 24 Aug 2012 08:58:56 -0700 (PDT) Subject: Top-posting &c. References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> Message-ID: <4793f86f-05cd-4e45-b5cf-035be6ce0353@kn3g2000pbc.googlegroups.com> On Aug 24, 7:23?pm, Ramchandra Apte wrote: > As BFDL, I hereby command everybody to stop the discussion. > lets put time on useful stuff > > i am using google groups (i think it knows what to do) Your posts are coming in doubles. And the quoted lines are coming double-spaced! Actually the 'new' google groups is considerably more messed up than the old. And usually its hard to choose the old. No offense intended... Just that since I was the one to recommend you use gg, I feel obliged on conscience to mention this. From tjreedy at udel.edu Fri Aug 24 12:04:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Aug 2012 12:04:54 -0400 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> References: <581D4160B04DF541A763BB8BB60E8CC6A747B70A66@PDC-MAIL-CMS01.ubisoft.org> <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> Message-ID: On 8/24/2012 10:44 AM, Ramchandra Apte wrote: > On Wednesday, 22 August 2012 22:13:04 UTC+5:30, Terry Reedy wrote: >> >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(0)") >> >> 0.91 >> >> >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(20)") >> >> 1.28 >> >> >>> timeit.timeit("list(filter(lambda i: False, ranger))", >> >> "ranger=range(0)") >> >> 0.83 >> >> >>> timeit.timeit("list(filter(lambda i: False, ranger))", >> >> "ranger=range(20)") >> >> 2.60 Your mail agent in inserting blank lines in quotes -- google? See if you can turn that off. > Your examples with lambda i:False are unrealistic - you are comparing > `if False` vs (xx) - function call vs boolean check That is exactly the comparison I wanted to make. The iteration + boolean check takes .37 for 20 items, the iteration + call 1.77. -- Terry Jan Reedy From rustompmody at gmail.com Fri Aug 24 12:06:25 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 24 Aug 2012 09:06:25 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... References: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> Message-ID: On Aug 24, 12:22?am, Ian Kelly wrote: > On Thu, Aug 23, 2012 at 12:33 PM, ? wrote: > >> >>> sys.getsizeof('a' * 80 * 50) > > >> > 4025 > > >> >>>> sys.getsizeof('a' * 80 * 50 + '?') > > >> > 8040 > > >> ? ? This example is still benefiting from shrinking the number of bytes > > >> in half over using 32 bits per character as was the case with Python 3.2: > > >> ?>>> sys.getsizeof('a' * 80 * 50) > > >> 16032 > > >> ?>>> sys.getsizeof('a' * 80 * 50 + '?') > > >> 16036 > > > Correct, but how many times does it happen? > > Practically never. > > What are you talking about? ?Surely it happens the same number of > times that your example happens, since it's the same example. ?By > dismissing this example as being too infrequent to be of any > importance, you dismiss the validity of your own example as well. > > > In this unicode stuff, I'm fascinated by the obsession > > to solve a problem which is, due to the nature of > > Unicode, unsolvable. > > > For every optimization algorithm, for every code > > point range you can optimize, it is always possible > > to find a case breaking that optimization. > > So what? ?Similarly, for any generalized data compression algorithm, > it is possible to engineer inputs for which the "compressed" output is > as large as or larger than the original input (this is easy to prove). > ?Does this mean that compression algorithms are useless? ?I hardly > think so, as evidenced by the widespread popularity of tools like gzip > and WinZip. > > You seem to be saying that because we cannot pack all Unicode strings > into 1-byte or 2-byte per character representations, we should just > give up and force everybody to use maximum-width representations for > all strings. ?That is absurd. > > > Sure, it is possible to optimize the unicode usage > > by not using French characters, punctuation, mathematical > > symbols, currency symbols, CJK characters... > > (select undesired characters here:http://www.unicode.org/charts/). > > > In that case, why using unicode? > > (A problematic not specific to Python) > > Obviously, it is because I want to have the *ability* to represent all > those characters in my strings, even if I am not necessarily going to > take advantage of that ability in every single string that I produce. > Not all of the strings I use are going to fit into the 1-byte or > 2-byte per character representation. ?Fine, whatever -- that's part of > the cost of internationalization. ?However, *most* of the strings that > I work with (this entire email message, for instance) -- and, I think, > most of the strings that any developer works with (identifiers in the > standard library, for instance) -- will fit into at least the 2-byte > per character representation. ?Why shackle every string everywhere to > 4 bytes per character when for a majority of them we can do much > better than that? Actually what exactly are you (jmf) asking for? Its not clear to anybody as best as we can see... From laddosingh at gmail.com Fri Aug 24 12:20:28 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Fri, 24 Aug 2012 09:20:28 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Thank you guys, Roy and Terry. I has been great help. I still need some help. Here is the updated code: Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) def test_1(self): "Verify creation of files is possible" filenames = {"this.txt", "that.txt", "the_other.txt"} for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) dir_names = set(os.listdir('.')) self.assertEqual(set(dir_names), set(filenames)) def test_2(self): "Verify that current directory is empty" self.assertEqual(glob.glob("*"), [], "Directory not empty") def test_3(self): f = open("test.dat", "wb") filesize = b"0"*1000000 f.write(filesize) f.close() self.assertEqual(os.stat, filesize) def tearDown(self): os.chdir(self.origdir) shutil.rmtree(self.dirname The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions? Thanks T kl. 21:06:29 UTC+2 torsdag 23. august 2012 skrev Roy Smith f?lgende: > On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > > > > > One can start with a set rather than tuple of file names. > > > filenames = {"this.txt", "that.txt", "the_other.txt"} > > > > Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or above. From laddosingh at gmail.com Fri Aug 24 12:20:28 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Fri, 24 Aug 2012 09:20:28 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Thank you guys, Roy and Terry. I has been great help. I still need some help. Here is the updated code: Demostration of setUp and tearDown. The tests do not actually test anything - this is a demo. """ import unittest import tempfile import shutil import glob import os class FileTest(unittest.TestCase): def setUp(self): self.origdir = os.getcwd() self.dirname = tempfile.mkdtemp("testdir") os.chdir(self.dirname) def test_1(self): "Verify creation of files is possible" filenames = {"this.txt", "that.txt", "the_other.txt"} for filename in filenames: f = open(filename, "w") f.write("Some text\n") f.close() self.assertTrue(f.closed) dir_names = set(os.listdir('.')) self.assertEqual(set(dir_names), set(filenames)) def test_2(self): "Verify that current directory is empty" self.assertEqual(glob.glob("*"), [], "Directory not empty") def test_3(self): f = open("test.dat", "wb") filesize = b"0"*1000000 f.write(filesize) f.close() self.assertEqual(os.stat, filesize) def tearDown(self): os.chdir(self.origdir) shutil.rmtree(self.dirname The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions? Thanks T kl. 21:06:29 UTC+2 torsdag 23. august 2012 skrev Roy Smith f?lgende: > On Thursday, August 23, 2012 1:29:19 PM UTC-4, Terry Reedy wrote: > > > > > One can start with a set rather than tuple of file names. > > > filenames = {"this.txt", "that.txt", "the_other.txt"} > > > > Yeah, that's even cleaner. Just be aware, the set notation above is only available in (IIRC), 2.7 or above. From rustompmody at gmail.com Fri Aug 24 12:22:43 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 24 Aug 2012 09:22:43 -0700 (PDT) Subject: Looking for duplicate modules References: Message-ID: On Aug 23, 8:30?pm, Roy Smith wrote: > We got burned yesterday by a scenario which has burned us before. ?We had multiple copies of a module in sys.path. ?One (the one we wanted) was in our deployed code tree, the other was in /usr/local/lib/python/ or some such. ?It was a particularly confusing situation because we *knew* we had uninstalled the copy in /usr/local/lib. ?What we didn't know was that puppet was set up to check to make sure it was there and reinstalled it automagically if it ever disappeared! > > What often adds to the confusion in cases like this is that if you use a package manager (such as apt-get) to manage your module deployments, when you uninstall, the .py files get removed, but the .pyc's stay behind. > > I'm working on a tool which scans all the directories in sys.path and finds any modules which appear multiple times in the path. ?It'll also call out any .pyc's it finds without matching py's. > > I know those are not strictly errors, but both of them are, for lack of a better term, "deployment smells" and something to be warned about. ?Before I invest too much effort into building it, does such a tool already exist? Not remotely an answer. emacs has a list-load-path-shadows for the same/similar issue in elisp. As a language moves to being a system (programming) language, it seems to me necessary that such a functionality is built into the language and gets called as part of standard installation procedure. > > We're slowly moving more of our deployment to using virtualenv (with --no-site-packages), but we're not fully there yet. ?And even when we get there, there will still be opportunities to make these sorts of mistakes. > > --- > Roy Smith > r... at panix.com From rustompmody at gmail.com Fri Aug 24 12:39:04 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 24 Aug 2012 09:39:04 -0700 (PDT) Subject: Top-posting &c. References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> <4793f86f-05cd-4e45-b5cf-035be6ce0353@kn3g2000pbc.googlegroups.com> Message-ID: On Aug 24, 8:58?pm, rusi wrote: > On Aug 24, 7:23?pm, Ramchandra Apte wrote: > > > As BFDL, I hereby command everybody to stop the discussion. > > lets put time on useful stuff > > > i am using google groups (i think it knows what to do) > > Your posts are coming in doubles. > And the quoted lines are coming double-spaced! Just saw other double-posts So checked the mailing list archive which does not seem to have them. So please ignore my double-post comment (for now). From breamoreboy at yahoo.co.uk Fri Aug 24 12:47:42 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Aug 2012 17:47:42 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <7eaafbcd-597d-4f8c-98a8-ecb537e6e065@googlegroups.com> Message-ID: On 24/08/2012 17:06, rusi wrote: > > Actually what exactly are you (jmf) asking for? > Its not clear to anybody as best as we can see... > A knee in the temple and a dagger up the ? :) From another Monty Python sketch for those who don't know. -- Cheers. Mark Lawrence. From rosuav at gmail.com Fri Aug 24 13:49:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 03:49:03 +1000 Subject: Top-posting &c. In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47416609F42@SCACMX008.exchad.jpmchase.net> References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> <5B80DD153D7D744689F57F4FB69AF47416609F42@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Aug 24, 2012 at 11:53 PM, Prasad, Ramit wrote: > Ulrich Eckhardt wrote: >> BTW: You omitted the attribution line for the text you quoted, whom do >> you blame for that? That said, "Nonsense" is a strong enough word to >> start a flamewar... not nice. > Fair enough. I typically leave off attribution because I would rather > to discuss things with quotes instead of he-said and she-said. The > focus should be on the idea/conversation and less about attributing > "blame" to someone (and it is invariably more often negative attribution > than positive). If attribution is preferred, I suppose I could always > add it back in. Ironically, this is one of the things I wish Outlook > was better about. PLEASE add attribution back in. It's not about he-said/she-said, it's about honesty and clarity in reporting. It's far easier to understand the conversation when we know who said each part, and the normal opening line that most mail clients put in has a handy condensed set of headers. ChrisA From rosuav at gmail.com Fri Aug 24 14:03:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 04:03:21 +1000 Subject: Looking for duplicate modules In-Reply-To: <377FBB51-D794-4F05-9E51-46A056705E32@panix.com> References: <377FBB51-D794-4F05-9E51-46A056705E32@panix.com> Message-ID: On Fri, Aug 24, 2012 at 1:30 AM, Roy Smith wrote: > I'm working on a tool which scans all the directories in sys.path and finds any modules which appear multiple times in the path. It'll also call out any .pyc's it finds without matching py's. > This is why I love high level languages. The core of your problem is solved by a single dictionary object. ChrisA From roy at panix.com Fri Aug 24 14:46:58 2012 From: roy at panix.com (Roy Smith) Date: Fri, 24 Aug 2012 11:46:58 -0700 (PDT) Subject: Is Python a commercial proposition ? In-Reply-To: References: Message-ID: <5d2e16db-fb11-490b-a548-aabee50bb916@googlegroups.com> On Sunday, July 29, 2012 12:01:00 PM UTC-4, lipska the kat wrote: > How is python used in the real world. songza.com is pretty close to 100% python. The only significant non-python code on the server side are mongodb, haproxy, and nginx. > What sized projects are people involved with We've got 102 KLOC in the application (i.e. code we wrote), plus another 104 KLOC in django and 337 KLOC of other installed packages (i.e. everything in our virtualenv's site-packages directory). Those numbers are just the raw output of doing "find ... -name *.py | xargs wc -l", so they include blank lines and comments. So, all told, roughly a half million lines of python code. From walterhurry at lavabit.com Fri Aug 24 15:03:51 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 24 Aug 2012 19:03:51 +0000 (UTC) Subject: Filter versus comprehension (was Re: something about split()???) References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> Message-ID: On Fri, 24 Aug 2012 14:29:00 -0400, Dennis Lee Bieber wrote: > It appears to be a change Google made in the last month or two... My > hypothesis is that they are replacing hard EOL found in inbound NNTP > with an HTML

, and then on outgoing replacing the

with a pair of > NNTP line endings. In contrast, text composed on Google is coming in as > long single lines (since quoting said text in a response produces on a > ">" at the start of the paragraph. Google Groups sucks. These are computer literate people here. Why don't they just use a proper newsreader? From robertkday at gmail.com Fri Aug 24 15:04:54 2012 From: robertkday at gmail.com (Robert Day) Date: Fri, 24 Aug 2012 20:04:54 +0100 Subject: Unittest - testing for filenames and filesize In-Reply-To: <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: <1345835094.1512.3.camel@rivertam> On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote: > def test_3(self): > f = open("test.dat", "wb") > filesize = b"0"*1000000 > f.write(filesize) > f.close() > self.assertEqual(os.stat, filesize) > The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions? > rob at rivertam:~$ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.stat >>> So that's what 'os.stat' is. Why are you testing whether that's equal to b"0"*1000000? (You may find the documentation on os.stat at http://docs.python.org/library/os.html#os.stat helpful; it's a function which takes a path as its argument, and returns an object with some relevant attributes.) From rosuav at gmail.com Fri Aug 24 15:18:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 05:18:53 +1000 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 24, 2012 at 11:27 PM, Grant Edwards wrote: > Ah, but as we are always fond of saying in this group "that's an > implementation detail, and not part of the language definition". The > model where a compiler is "keeping notes about it in Narnia" is also > perfectly valid. However, RAM is easier to find than magic wardrobes, > so the "notes" are usually kept in RAM these days. Maybe, but once you found that wardrobe, you'd have enough storage for all your needs, AND it takes no time at all to retrieve it! I think we should start developing NarPy at once. ChrisA From ethan at stoneleaf.us Fri Aug 24 15:28:25 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Aug 2012 12:28:25 -0700 Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> <5B80DD153D7D744689F57F4FB69AF47416609F42@SCACMX008.exchad.jpmchase.net> Message-ID: <5037D5D9.7000800@stoneleaf.us> Chris Angelico wrote: > PLEASE add attribution back in. It's not about he-said/she-said, it's > about honesty and clarity in reporting. It's far easier to understand > the conversation when we know who said each part [. . .] +1 From merwin.irc at gmail.com Fri Aug 24 15:41:49 2012 From: merwin.irc at gmail.com (Thibaut) Date: Fri, 24 Aug 2012 21:41:49 +0200 Subject: Coroutines framework for Python 3 Message-ID: <5037D8FD.4060309@gmail.com> Hi, The question is in the title, is there any coroutine framework available for Python 3.2+ ? I checked gevent and eventlet but none of them seems to have a Py3k version. Thanks, From wbrucek at gmail.com Fri Aug 24 15:43:08 2012 From: wbrucek at gmail.com (Willem Krayenhoff) Date: Fri, 24 Aug 2012 12:43:08 -0700 Subject: help with simple print statement! Message-ID: Any idea why print isn't working here? I tried restarting my Command prompt. Also, print doesn't work inside a class. [image: Inline image 2] -- Best Wishes, Bruce C: 604-441-5791 My Availability -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 11319 bytes Desc: not available URL: From tjandacw at cox.net Fri Aug 24 15:45:35 2012 From: tjandacw at cox.net (Tim Williams) Date: Fri, 24 Aug 2012 12:45:35 -0700 (PDT) Subject: calling loaded DLL function expecting POINT * argument Message-ID: <1486b835-f9e5-454b-abb7-a3289b1a4fe1@googlegroups.com> Hello all, I'm trying to use the ctypes module to call functions in a DLL. I've figured out how to modify my path so the library is found, and I can call LoadLibrary on it, but one of the functions expects an array of POINTS. Here is the prototype from the .h file: TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints); I did a from ctypes.wintypes import * Here's my test script: ############## ''' Created on Aug 23, 2012 @author: williams ''' import os import numpy as np import scipy.io from ctypes import * from ctypes.wintypes import * matdata = scipy.io.loadmat(os.path.join(os.environ['userprofile'],'Desktop','S31_f1.mat')) data = matdata['data'] nHeight,nWidth = data.shape pth = os.environ['path'].split(';') pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs')) os.environ['path'] = ';'.join(pth) tck=oledll.LoadLibrary('Tracker') hTrkr = tck.CreateTracker() maskImage = np.zeros((1024,1280),dtype='int32') maskImage[300:305,100:105] = True idx = np.array(maskImage.nonzero()) nPoint = idx.shape[1] ptMaskType = nPoint * POINT pts = zip(idx[1,:],idx[0,:]) ptMasks = ptMaskType(*pts) tck.InitializeMask.argtypes=(HANDLE, c_int, c_int, c_void_p, c_int) InitMaskResult = tck.InitializeMask(hTrkr, nWidth, nHeight, ptMasks, nPoint) if __name__ == '__main__': pass ############## so I have the POINT class, and I've created the array of POINTs. When I try to call this function, I get this message: >>> InitMaskResult = tck.InitializeMask(hTrkr, nWidth, nHeight, ptMasks, nPoint) Traceback (most recent call last): File "", line 1, in ValueError: Procedure probably called with too many arguments (20 bytes in excess) This is the first time that I've tried to use the ctypes module, so any help is appreciated. TIA, From ckaynor at zindagigames.com Fri Aug 24 15:53:52 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 24 Aug 2012 12:53:52 -0700 Subject: help with simple print statement! In-Reply-To: References: Message-ID: On Fri, Aug 24, 2012 at 12:43 PM, Willem Krayenhoff wrote: > Any idea why print isn't working here? > > I tried restarting my Command prompt. Also, print doesn't work inside a > class. > > [image: Inline image 2] > In Python 3, print was made into a function rather than a statement for various reasons (I'll leave it to the reader to find sources as to why). You just need to call it rather than use it as a statement. > -- > Best Wishes, > > Bruce > C: 604-441-5791 > My Availability > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 11319 bytes Desc: not available URL: From rkd at rkd.me.uk Fri Aug 24 15:54:27 2012 From: rkd at rkd.me.uk (Rob Day) Date: Fri, 24 Aug 2012 20:54:27 +0100 Subject: help with simple print statement! In-Reply-To: References: Message-ID: <1345838067.1512.10.camel@rivertam> On Fri, 2012-08-24 at 12:43 -0700, Willem Krayenhoff wrote: > Any idea why print isn't working here? You're using Python 3.2, but trying Python 2.7 syntax - http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function should explain the problem adequately. (Incidentally - you can copy from the Windows console by right-clicking and selecting "Mark". It's a little easier than taking a screenshot!) Rob From schesis at gmail.com Fri Aug 24 15:57:51 2012 From: schesis at gmail.com (Zero Piraeus) Date: Fri, 24 Aug 2012 15:57:51 -0400 Subject: help with simple print statement! In-Reply-To: References: Message-ID: : On 24 August 2012 15:43, Willem Krayenhoff wrote: > Any idea why print isn't working here? http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function Also, pasting images into emails to this list is unlikely to gain you many friends ... -[]z. From ramit.prasad at jpmorgan.com Fri Aug 24 15:59:12 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 24 Aug 2012 19:59:12 +0000 Subject: help with simple print statement! In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF4741660A9A9@SCACMX008.exchad.jpmchase.net> Willem Krayenhoff Any idea why print isn't working here? ? I tried restarting my Command prompt. ?Also, print doesn't work inside a class. -- Best Wishes, ? ?? Bruce ? ?? C: 604-441-5791 ? ? ?My Availability? Just as a note, this is a usenet group that can be accessed via email; a good portion of the people on the list does not receive attachments and images. HTML is also a bad format as it mangles code so please post in plain text and copy/paste from the command line instead of using screenshots. It will be easy for us to run your code if necessary to reproduce the results. Now on to your problem. You are using Python 3 where print was turned from a statement into a function. You need to use the following instead. print('34ki') print(6) 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 Tim.Arnold at sas.com Fri Aug 24 16:25:51 2012 From: Tim.Arnold at sas.com (Tim Arnold) Date: Fri, 24 Aug 2012 16:25:51 -0400 Subject: fabric problem with ssh Message-ID: I am getting started with fabric and trying to connect to any machine in my known hosts file. I want fabric to figure out that it doesn't need me to enter my password. My fabfile.py: from fabric.api import run, env env.disable_known_hosts=False def lsfiles(): run('ls -l ~/') My console result: > fab lsfiles No hosts found. Please specify (single) host string for connection: localhost [localhost] run: ls -l ~/ [localhost] Passphrase for private key: ... file listing follows ... How can I get fabric to use my .ssh/known_hosts file? system details: Python 2.7.3 (default, Aug 22 2012, 13:09:20) [GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2 thanks, --Tim Arnold From wbrucek at gmail.com Fri Aug 24 16:29:59 2012 From: wbrucek at gmail.com (Bruce Krayenhoff) Date: Fri, 24 Aug 2012 13:29:59 -0700 Subject: help with simple print statement! In-Reply-To: References: Message-ID: <04aa01cd8237$3c44dad0$b4ce9070$@gmail.com> Thank-you all, it works now! Best Wishes, Bruce C: 604-441-5791 My Availability From: python-list-bounces+wbrucek=gmail.com at python.org [mailto:python-list-bounces+wbrucek=gmail.com at python.org] On Behalf Of Chris Kaynor Sent: August-24-12 12:54 PM To: python-list at python.org Subject: Re: help with simple print statement! On Fri, Aug 24, 2012 at 12:43 PM, Willem Krayenhoff > wrote: Any idea why print isn't working here? I tried restarting my Command prompt. Also, print doesn't work inside a class. In Python 3, print was made into a function rather than a statement for various reasons (I'll leave it to the reader to find sources as to why). You just need to call it rather than use it as a statement. -- Best Wishes, Bruce C: 604-441-5791 My Availability -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Aug 24 16:31:09 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Aug 2012 13:31:09 -0700 Subject: proper reply format [was Re: help with simple print statement!] In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741660A9A9@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4741660A9A9@SCACMX008.exchad.jpmchase.net> Message-ID: <5037E48D.3090103@stoneleaf.us> Prasad, Ramit wrote: > Willem Krayenhoff > Any idea why print isn't working here? > > I tried restarting my Command prompt. Also, print doesn't work inside a class. > > Ramit, The standard for attribution is something along the lines of: Prasad, Ramit wrote: or Willem Kayenhoff wrote: Just having Willem's name at the top was confusing. Also, because you didn't trim his signature, the rest of your reply looked like a signature to Thunderbird (which uses a line of '--' to figure the start of signatures). As you can see, the rest of your post was trimmed away as signature lines when I hit Reply. ~Ethan~ From lists at cheimes.de Fri Aug 24 17:41:32 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 24 Aug 2012 23:41:32 +0200 Subject: proper reply format In-Reply-To: <5037E48D.3090103@stoneleaf.us> References: <5B80DD153D7D744689F57F4FB69AF4741660A9A9@SCACMX008.exchad.jpmchase.net> <5037E48D.3090103@stoneleaf.us> Message-ID: Am 24.08.2012 22:31, schrieb Ethan Furman: > Just having Willem's name at the top was confusing. Also, because you > didn't trim his signature, the rest of your reply looked like a > signature to Thunderbird (which uses a line of '--' to figure the start > of signatures). As you can see, the rest of your post was trimmed away > as signature lines when I hit Reply. Almost ;) The correct signature separator is "\n-- \n". That's a line made up entirely of dash, dash, space followed by a newline. Christian From tjreedy at udel.edu Fri Aug 24 18:03:27 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Aug 2012 18:03:27 -0400 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> Message-ID: On 8/24/2012 5:56 PM, Dennis Lee Bieber wrote: > On Fri, 24 Aug 2012 19:03:51 +0000 (UTC), Walter Hurry > declaimed the following in > gmane.comp.python.general: > >> >> Google Groups sucks. These are computer literate people here. Why don't >> they just use a proper newsreader? > > Probably because their ISP doesn't offer a free server Python lists are available on the free gmane mail-to-news server. -- Terry Jan Reedy From emile at fenx.com Fri Aug 24 18:15:39 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 24 Aug 2012 15:15:39 -0700 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> Message-ID: On 8/24/2012 3:03 PM Terry Reedy said... > On 8/24/2012 5:56 PM, Dennis Lee Bieber wrote: >> On Fri, 24 Aug 2012 19:03:51 +0000 (UTC), Walter Hurry >> declaimed the following in >> gmane.comp.python.general: >> >>> >>> Google Groups sucks. These are computer literate people here. Why don't >>> they just use a proper newsreader? >> >> Probably because their ISP doesn't offer a free server > > Python lists are available on the free gmane mail-to-news server. I'm getting high load related denials with the gmane connections a lot recently so I'm open to alternatives. Suggestions or recommendations? Emile From list at qtrac.plus.com Fri Aug 24 18:23:33 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 24 Aug 2012 15:23:33 -0700 (PDT) Subject: concurrent.futures inconsistency? Message-ID: <2d5b81a0-10e2-45c9-a560-7fa51e6d4683@gk4g2000vbb.googlegroups.com> Hi, It seems that in concurrent.futures, ProcessPoolExecutor() can be used with no args and default to max_workers=multiprocessing.cpu_count(); but for ThreadPoolExecutor() the max_workers arg is required. Is this intentional? (I'm using Python 3.2.) From breamoreboy at yahoo.co.uk Fri Aug 24 18:28:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Aug 2012 23:28:53 +0100 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> Message-ID: On 24/08/2012 23:03, Terry Reedy wrote: > On 8/24/2012 5:56 PM, Dennis Lee Bieber wrote: >> On Fri, 24 Aug 2012 19:03:51 +0000 (UTC), Walter Hurry >> declaimed the following in >> gmane.comp.python.general: >> >>> >>> Google Groups sucks. These are computer literate people here. Why don't >>> they just use a proper newsreader? >> >> Probably because their ISP doesn't offer a free server > > Python lists are available on the free gmane mail-to-news server. > I don't think the core-mentorship list is available on gmane. Have I missed it, has nobody asked for it to go on there or what? -- Cheers. Mark Lawrence. From foo at email.invalid Fri Aug 24 18:33:52 2012 From: foo at email.invalid (Alex) Date: Fri, 24 Aug 2012 22:33:52 +0000 (UTC) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? Message-ID: I'm new to Python and have been using IDLE 3.2.3 to experiment with code as I learn. Despite being configured to use a 4 space indentation width, sometimes IDLE's "smart" indentation insists upon using width-8 tabs. >From what I've been able to find on Google, this is due to a shortcoming in Tk. While it's not that big a deal in the grand scheme of things, I think it looks like poop, and I'd like to change IDLE to use 4-space indentation instead of tabs for all indentation levels. Is there any way for me to achieve what I want in IDLE, or do I have to start up my full-blown IDE if I want consistent 4-space indentation? Alex From nad at acm.org Fri Aug 24 18:36:33 2012 From: nad at acm.org (Ned Deily) Date: Fri, 24 Aug 2012 15:36:33 -0700 Subject: Filter versus comprehension (was Re: something about split()???) References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> Message-ID: In article , Emile van Sebille wrote: > On 8/24/2012 3:03 PM Terry Reedy said... > > Python lists are available on the free gmane mail-to-news server. > I'm getting high load related denials with the gmane connections a lot > recently so I'm open to alternatives. The high load denials should be a thing of the past as the gmane NNTP server was very recently upgraded to use SSDs instead of standard disks. -- Ned Deily, nad at acm.org From nad at acm.org Fri Aug 24 18:39:56 2012 From: nad at acm.org (Ned Deily) Date: Fri, 24 Aug 2012 15:39:56 -0700 Subject: Filter versus comprehension (was Re: something about split()???) References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> <04uf38le390ikmol02dv59lc6fs29perle@invalid.netcom.com> Message-ID: In article , Mark Lawrence wrote: > I don't think the core-mentorship list is available on gmane. Have I > missed it, has nobody asked for it to go on there or what? core-mentorship is a closed list so it would not be appropriate for it to be mirrored anywhere. http://mail.python.org/mailman/listinfo/core-mentorship -- Ned Deily, nad at acm.org From walterhurry at lavabit.com Fri Aug 24 18:55:41 2012 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 24 Aug 2012 22:55:41 +0000 (UTC) Subject: Filter versus comprehension (was Re: something about split()???) References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> Message-ID: On Fri, 24 Aug 2012 17:56:47 -0400, Dennis Lee Bieber wrote: > On Fri, 24 Aug 2012 19:03:51 +0000 (UTC), Walter Hurry > declaimed the following in > gmane.comp.python.general: > > >> Google Groups sucks. These are computer literate people here. Why don't >> they just use a proper newsreader? > > Probably because their ISP doesn't offer a free server There are plenty of free Usenet providers. From lucretiel at gmail.com Fri Aug 24 19:51:54 2012 From: lucretiel at gmail.com (lucretiel at gmail.com) Date: Fri, 24 Aug 2012 16:51:54 -0700 (PDT) Subject: Unit test discovery with XML Runner? Message-ID: <2e5e0ed9-d6e5-4581-b52b-548a7537f0e0@googlegroups.com> Hey All, I've just started with the unittest module and I love it. I've been using test discovery- "python -m unittest discover" from the command line- so that I can distribute my tests amongst files instead of having tp manage them all. I'd like to publish the test results, though. Googling pointed me to xmlrunner, which seems perfect, but requires me to add the if name=='__main__ line to all my tests, which isn't run my test discovery. Is there a way to use xml runner with test discovery, or another way to solve the problem? -Lucretiel From solipsis at pitrou.net Fri Aug 24 20:24:35 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 25 Aug 2012 00:24:35 +0000 (UTC) Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> Message-ID: Ramchandra Apte gmail.com> writes: > > The zen of python is simply a guideline What's more, the Zen guides the language's design, not its implementation. People who think CPython is a complicated implementation can take a look at PyPy :-) Regards Antoine. -- Software development and contracting: http://pro.pitrou.net From lucretiel at gmail.com Fri Aug 24 20:25:05 2012 From: lucretiel at gmail.com (Lucretiel) Date: Fri, 24 Aug 2012 17:25:05 -0700 (PDT) Subject: Publish unittest results from test discovery Message-ID: So I've started using unittest, and I love it. I use testdiscovery (python -m unittest discover) so that I can distribute my tests and don't have to manage them all manually. I wanted to start publishing my test results to xml, though. I found xmlrunner by googling around, but it requires me to add an if __name__ == '__main__' block to my code, which isn't executed by unittest discover. Is there a way to get unittest disover to work with xmlrunner, or to some other way to solve this without restructuring all my test code? From steve+comp.lang.python at pearwood.info Fri Aug 24 21:03:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Aug 2012 01:03:51 GMT Subject: Publish unittest results from test discovery References: Message-ID: <50382477$0$6574$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Aug 2012 17:25:05 -0700, Lucretiel wrote: [...] > Is there a way to get unittest disover to work with xmlrunner Steady on there! It's only been about an hour and a half since you last asked this exact same question, almost word-for-word identical. The more specialised the question, the longer it may take for somebody who knows the answer to reply. For something like this, I would wait at least a couple of days before replying to your original post. (Don't just re-post the question in a new thread, keep the response in a single thread.) I have no idea about xmlrunner and unittest discovery, sorry. -- Steven From d at davea.name Fri Aug 24 21:37:49 2012 From: d at davea.name (Dave Angel) Date: Fri, 24 Aug 2012 21:37:49 -0400 Subject: Top-posting &c. In-Reply-To: References: <4e0060a6-5cd5-455c-a151-80df9509255d@googlegroups.com> <9msbg9-dop.ln1@satorlaser.homedns.org> <4793f86f-05cd-4e45-b5cf-035be6ce0353@kn3g2000pbc.googlegroups.com> Message-ID: <50382C6D.3070403@davea.name> On 08/24/2012 12:39 PM, rusi wrote: > On Aug 24, 8:58 pm, rusi wrote: >> >> Your posts are coming in doubles. >> And the quoted lines are coming double-spaced! > Just saw other double-posts > So checked the mailing list archive which does not seem to have them. > > So please ignore my double-post comment (for now). I solved nearly all the double-posts here by a simple rule which deletes any message which is either To or CC: to googlegroups. Each such message has another which does not. -- DaveA From steve+comp.lang.python at pearwood.info Fri Aug 24 22:05:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Aug 2012 02:05:29 GMT Subject: Variables vs names [was: Objects in Python] References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503832e8$0$6574$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote: > On 08/23/2012 12:56 PM, Steven D'Aprano wrote: >> On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: >> >>> I definitely *wouldn't* say "Python >>> classes aren't really classes" -- even though (I assert) Python >>> classes are *far* further from Simula-style (/Java/C++) classes than >>> Python variables are from Java variables. >> >> Well, Python classes are first-class (pun not intended) objects in >> their own right, and hence are data. Java and C++ classes are not, they >> are instructions to the compiler rather than data. >> >> But other than that, what do you see as the difference between Python >> classes and Simula-style classes? > > So first, to some extent that's like saying "these two different things > are different in this important way, but other than that, what's the > difference?" :-) Yes, exactly. I acknowledge a difference between the two, and ask you what differences you see. Many languages do not have "first-class functions" -- you cannot pass a function to another function as an argument, or generate them on the fly at runtime. But the ability of functions to be treated as data is not an essential part of being-a-function, so I see no problem with describing both Pascal functions and Python functions as functions. Likewise, being able to pass classes around as data and generate them on the fly is not an essential part of being-a-class, to I see no problem with describing both Java classes and Python classes as classes. > But there are some other differences. (Not all of these are strictly > with classes per se, but I would say they all have strong interactions > with the object system.) I don't believe that any of those differences in behaviour are either critical, or (as you acknowledge) strictly in the concept of *class* itself. I think they're interesting differences, but I don't think they are essential to the nature of "classness" in the same way that having a fixed memory address is essential to the nature of "memory location variable" or a name in a namespace is essential to "name binding variable". [...] >> Python has classes. They are created by the "class" keyword. Whether >> those classes are identical to Java classes is irrelevant -- in Python, >> these whatever-they-are-things are called "classes", and so Python has >> classes. >> >> But Python does not have things called "variables". There is no >> "variable" keyword to create a variable. > > OK, let's make a new language. I'll call it 'Python--' because at least > *I* wouldn't want to program in it. :-) > > In Python--, any time you use a name, you have to prefix it with the > word 'variable': > variable x = 4 > print(variable x) > > Does Python-- have variables? Of course, because that's what Python-- calls them. Whether Python-- is *justified* in calling them variables is a more interesting question. I think it is, in the sense that name bindings are a kind of variable, and fixed memory locations are a different kind of variable. But I also think that it isn't, for exactly the reasons why I prefer to describe Python (without the minuses) as having name bindings rather than variables "in the C or Pascal sense". Ultimately what is important are the semantics of the words, not the words themselves. Objections to use of "variable" are, I believe, *pragmatic* objections that the word comes with too much baggage to be safe to use, not that name bindings aren't a type of variable. > Think of it as duck-typing the term "variable". :-) To me, Python locals > and globals look and quack like a variable. And so they should, since name bindings are a way of implementing the abstract Variable kind, so to speak. > Incidentally, I also realized another reason I don't like the 'names' > description. Take 'foo.bar'. (That is, the 'bar' attribute in object > 'foo'.) Is 'foo.bar' a name? Is "Evan Driscoll" a name? Or is it two names? There is no contradiction to say that "Evan Driscoll" is both a name (a "compound name", if you like, or fully-qualified name) and two names (a personal name plus a family name). foo.bar is both a fully-qualified name and two names: the name of the namespace and the name of the attribute in the namespace. > I'm not sure what the 'names' proponents > would say, but to me both answers are problematic. I *really* dislike a > 'no' answer because to me, 'foo.bar' absolutely *is* a name for the > corresponding object. (This terminology has precedent.) But a 'yes' > answer, if you also reject 'variable', means you no longer have an > agreed-upon term for the names that are defined in the current scope "Local names". We also have "global names" for those in the global scope, "builtin names" for those in the built-ins, and "nonlocal names". -- Steven From steve+comp.lang.python at pearwood.info Fri Aug 24 23:04:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Aug 2012 03:04:38 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Aug 2012 08:00:59 +1000, Chris Angelico wrote: > On Fri, Aug 24, 2012 at 3:56 AM, Steven D'Aprano > wrote: >> But name bindings are a kind of variable. Named memory locations are a >> *different* kind of variable. The behaviour of C variables and Python >> variables do not follow the Liskov Substitution Principle -- you can't >> rip out the entire "names bound to objects" machinery of Python and >> replace it with C-like named memory locations without changing the >> high- level behaviour of Python. And so by some ways of thinking it is >> *wrong* to treat name bindings and memory locations as "the same sort >> of entity". Hence, if C variables are variables, then Python name >> bindings can't be. > > Yet Python's variables are extremely close to C's pointer variables. Not really. Pointer variables are no different from any other variable: you have a named memory location that contains some data. In this case, the data happens to be a link to another chunk of memory. The pointer variable itself is just a named location containing data, same as a char variable, a float variable, etc. The data is a pointer rather than a char or float, and the operations which you can do to pointers are different to those you can do to chars or floats, but that's true of any data type. In languages without pointers, like Fortran 77, you can more or less simulate them with a fixed array of memory as the heap, with integer indexes into that array as pointers. These "pointer variables" are no different from other "integer variables" except in the meaning you, the programmer, gives them. This is no different from how C or Pascal treat pointers, except that those languages have syntactical support for pointer operations and Fortran 77 doesn't. > If > you allocate all your "real data" on the heap and do everything with > pointers, you'll have semantics very similar to Python's You're confusing two different levels of explanation here. On the one hand, you're talking about C semantics, where you are explicitly responsible for managing unnamed data via indirection (pointers). Typically, the *pointers* get given names, the data does not. On the other hand, you talk about Python, where you have no access at all to the pointers and memory addresses. You manage the data you actually care about by giving them names, and then leave it up to the Python virtual machine to transparently manage whatever indirection is needed to make it work. The fact that the end result is the same is hardly surprising -- Python's VM is built on top of C pointer indirection, so of course you can start with pointers and end up with Python semantics. But the practice of coding are very different: * in C, I care about identifiers ("names") in order to explicitly manage addresses and pointers as a means to reach the data I actually care about; * in Python, I care about identifiers in order to reach the data I actually care about. -- Steven From ben+python at benfinney.id.au Sat Aug 25 01:24:29 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 25 Aug 2012 15:24:29 +1000 Subject: Variables vs names References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503832e8$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wr0nee7m.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote: > > > In [the hypothetical language] Python--, any time you use a name, > > you have to prefix it with the word 'variable': > > variable x = 4 > > print(variable x) > > > > Does Python-- have variables? > > Of course, because that's what Python-- calls them. Whether Python-- > is *justified* in calling them variables is a more interesting > question. How many legs does a horse have, if you call the tail a leg? Four. Calling the tail a leg doesn't make it so. Similarly, I don't care that Python-- uses the term ?variable?, it only has variables if it has things which meet a sensible definition of ?variable?. So no, ?because that's what Python-- calls them? is not sufficient. > I think it is, in the sense that name bindings are a kind of variable, > and fixed memory locations are a different kind of variable. But I > also think that it isn't, for exactly the reasons why I prefer to > describe Python (without the minuses) as having name bindings rather > than variables "in the C or Pascal sense". To emphasise what may not be apparent to some newcomers, Steven and I are virtually in exact agreement here. We talk more about where we differ because that's what interests us :-) -- \ ?In the long run, the utility of all non-Free software | `\ approaches zero. All non-Free software is a dead end.? ?Mark | _o__) Pilgrim, 2006 | Ben Finney From jiangwen365 at gmail.com Sat Aug 25 01:29:30 2012 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Sat, 25 Aug 2012 13:29:30 +0800 Subject: PyPyODBC 0.8 released (Pure Python ODBC module) Message-ID: PyPyODBC - A Pure Python ctypes ODBC module Changes in version 0.8: Added the getinfo() method to the connection object Changes in version 0.7: Fixed the ntext/nchar/nvarchar string truncat problem Changes in version 0.6: Added Cursor.commit() and Cursor.rollback(). Added readonly keyword to connect. Features - Pure Python, compatible with PyPy (tested on Win32) - Almost totally same usage as pyodbc You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc <-- Comment out the original pyodbc importing line import pypyodbc as pyodbc # Let pypyodbc "pretend" the pyodbc pyodbc.connect(...) # This is pypyodbc pretending pyodbc! They have same APIs! ... From rosuav at gmail.com Sat Aug 25 02:34:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 16:34:50 +1000 Subject: Objects in Python In-Reply-To: <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 25, 2012 at 1:04 PM, Steven D'Aprano wrote: > You're confusing two different levels of explanation here. On the one > hand, you're talking about C semantics, where you are explicitly > responsible for managing unnamed data via indirection (pointers). > Typically, the *pointers* get given names, the data does not. > > On the other hand, you talk about Python, where you have no access at all > to the pointers and memory addresses. You manage the data you actually > care about by giving them names, and then leave it up to the Python > virtual machine to transparently manage whatever indirection is needed to > make it work. > ... > * in C, I care about identifiers ("names") in order to explicitly manage > addresses and pointers as a means to reach the data I actually care about; > > * in Python, I care about identifiers in order to reach the data I > actually care about. Yet the two are almost the same. Python objects don't have names, they just have their own data. (Leaving aside functions, which have their names as data for the benefit of tracebacks and such.) A C pointer has a name; a Python identifier has (or is, if you like) a name. They're very different in how you use them only because C doesn't naturally work with everything on the heap and pointers everywhere. In fact, when I was interfacing Python and C, there were a few places where I actually handed objects to Python and kept manipulating them, simply because the Python data model suited what I was trying to do; but what I was doing was using PyObject *some_object as though it were a Python variable. I even did up a trivial C++ class that encapsulated the INCREF/DECREF work, so my LocalPyObject really could be treated as a local variable, Python-style. Where's the difference? ChrisA From wxjmfauth at gmail.com Sat Aug 25 03:27:10 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 00:27:10 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> Message-ID: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Le samedi 25 ao?t 2012 02:24:35 UTC+2, Antoine Pitrou a ?crit?: > Ramchandra Apte gmail.com> writes: > > > > > > The zen of python is simply a guideline > > > > What's more, the Zen guides the language's design, not its implementation. > > People who think CPython is a complicated implementation can take a look at PyPy > > :-) Unicode design: a flat table of code points, where all code points are "equals". As soon as one attempts to escape from this rule, one has to "pay" for it. The creator of this machinery (flexible string representation) can not even benefit from it in his native language (I think I'm correctly informed). Hint: Google -> "Das grosse Eszett" jmf From wxjmfauth at gmail.com Sat Aug 25 03:27:10 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 00:27:10 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> Message-ID: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Le samedi 25 ao?t 2012 02:24:35 UTC+2, Antoine Pitrou a ?crit?: > Ramchandra Apte gmail.com> writes: > > > > > > The zen of python is simply a guideline > > > > What's more, the Zen guides the language's design, not its implementation. > > People who think CPython is a complicated implementation can take a look at PyPy > > :-) Unicode design: a flat table of code points, where all code points are "equals". As soon as one attempts to escape from this rule, one has to "pay" for it. The creator of this machinery (flexible string representation) can not even benefit from it in his native language (I think I'm correctly informed). Hint: Google -> "Das grosse Eszett" jmf From ben+python at benfinney.id.au Sat Aug 25 03:54:55 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 25 Aug 2012 17:54:55 +1000 Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> Message-ID: <87sjbbe78w.fsf@benfinney.id.au> wxjmfauth at gmail.com writes: > Unicode design: a flat table of code points, where all code > points are "equals". Yes, Unicode's design entails a flat table of hundreds of thousands of code points, expansible in future. This is in direct conflict with the design of all significant computers we need to write software for: data stored and transported as 8-bit bytes, which can only ever hold 256 different values, no expansion. > As soon as one attempts to escape from this rule, one has to > "pay" for it. Yes, in either direction; the conflict means that trade-offs need to be made. See this presentation by Ned Batchelder, ?Pragmatic Unicode? , which lays out the fundamental conflict of representing human text in computer data; and several practical approaches to deal with it. -- \ ?I busted a mirror and got seven years bad luck, but my lawyer | `\ thinks he can get me five.? ?Steven Wright | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Sat Aug 25 03:57:05 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 08:57:05 +0100 Subject: Publish unittest results from test discovery In-Reply-To: <50382477$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <50382477$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/08/2012 02:03, Steven D'Aprano wrote: > On Fri, 24 Aug 2012 17:25:05 -0700, Lucretiel wrote: > > [...] >> Is there a way to get unittest disover to work with xmlrunner > > Steady on there! It's only been about an hour and a half since you last > asked this exact same question, almost word-for-word identical. The more > specialised the question, the longer it may take for somebody who knows > the answer to reply. For something like this, I would wait at least a > couple of days before replying to your original post. (Don't just re-post > the question in a new thread, keep the response in a single thread.) > > I have no idea about xmlrunner and unittest discovery, sorry. > > I entirely agree with Steven's comments. I'd put a question like this on a specialised list. How about gmane.comp.python.testing.general ? Sorry I've no idea what it's called elsewhere. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Aug 25 04:55:27 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 09:55:27 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/08/2012 07:34, Chris Angelico wrote: > On Sat, Aug 25, 2012 at 1:04 PM, Steven D'Aprano I'm just wondering out aloud if the number of times this type of thread has been debated here will fit into a Python long or float? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Aug 25 04:58:24 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 09:58:24 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On 25/08/2012 08:27, wxjmfauth at gmail.com wrote: > Le samedi 25 ao?t 2012 02:24:35 UTC+2, Antoine Pitrou a ?crit : >> Ramchandra Apte gmail.com> writes: >> >>> >> >>> The zen of python is simply a guideline >> >> >> >> What's more, the Zen guides the language's design, not its implementation. >> >> People who think CPython is a complicated implementation can take a look at PyPy >> >> :-) > > Unicode design: a flat table of code points, where all code > points are "equals". > As soon as one attempts to escape from this rule, one has to > "pay" for it. > The creator of this machinery (flexible string representation) > can not even benefit from it in his native language (I think > I'm correctly informed). > > Hint: Google -> "Das grosse Eszett" > > jmf > It's Saturday morning, I'm stone cold sober, had a good sleep and I'm still baffled as to the point if any. Could someone please enlightem me? -- Cheers. Mark Lawrence. From plr.vincent at gmail.com Sat Aug 25 05:38:47 2012 From: plr.vincent at gmail.com (Vincent Pelletier) Date: Sat, 25 Aug 2012 11:38:47 +0200 Subject: Segfault when setting an instance property on 2.7.3 Message-ID: <201208251138.47725.plr.vincent@gmail.com> Hi. (please keep me in CC for replies, I'm not subscribed) I wrote a ctypes-(wait, read on)-based binding[1] for libusb1, in which I'm triggering a segfault from an application[2] I wrote. I've been through several segfault caused by ctypes mis-usage, this one seems different enough. I think there is something else (maybe ultimately caused by some ctypes effect, but I don't see the relation yet). The Python line causing the segfault: https://github.com/vpelletier/python-libusb1/blob/master/usb1.py#L192 C stack at segfault (with -dbg package installed): http://pastebin.com/rVUPsSrU #0 (gdb) print *op $1 = {ob_refcnt = -4247522206314328575, ob_type = 0xcf0dc50ec50dc50e} (gdb) up #1 (gdb) print *obj $2 = {ob_refcnt = 6, ob_type = 0x9c5f70} (gdb) print obj $3 = The program using python-libusb1 which triggers the segfault: https://github.com/vpelletier/ITI1480A-linux/blob/master/iti1480a/capture.py The event loop is at the bottom: allocate USB transfers, submit them, loop on libusb1 event handling until there is no more submitted transfer, libusb uses callback which resubmits transfer, ... ctypes possible segfault causes checklist: - callback is cast into a ctype CFUNCTYPE type instance See: https://github.com/vpelletier/python-libusb1/blob/master/libusb1.py#L587 https://github.com/vpelletier/python-libusb1/blob/master/usb1.py#L133 - a strong ref to it is kept on USBTransfer instance so it is not GC'ed See: https://github.com/vpelletier/python-libusb1/blob/master/usb1.py#L808 - application is single-threaded (libusb1 doesn't create any C thread either) so even if there were missing GIL acquisitions, it shouldn't be a problem Also, a strong ref to USBTransfer is kept on USBDeviceHandle instance. When an USBDeviceHandle is GC'ed, it cancels any pending transfer, waits for completion (=libusb1 callback is executed) and then allow them to be GC'ed. - we are not accessing unallocated memory in this traceback (although it could be that memory got overwritten somehow) I couldn't trigger the bug while under valgrind (which reported some "Conditional jump or move depends on uninitialized value(s)" & "Use of uninitialized value of size 8" in PyObject_Free, but reading the code I guess they are harmless and unrelated). Any idea of ways to debug this problem further ? Regards, -- Vincent Pelletier From frank at chagford.com Sat Aug 25 05:46:34 2012 From: frank at chagford.com (Frank Millman) Date: Sat, 25 Aug 2012 11:46:34 +0200 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On 25/08/2012 10:58, Mark Lawrence wrote: > On 25/08/2012 08:27, wxjmfauth at gmail.com wrote: >> >> Unicode design: a flat table of code points, where all code >> points are "equals". >> As soon as one attempts to escape from this rule, one has to >> "pay" for it. >> The creator of this machinery (flexible string representation) >> can not even benefit from it in his native language (I think >> I'm correctly informed). >> >> Hint: Google -> "Das grosse Eszett" >> >> jmf >> > > It's Saturday morning, I'm stone cold sober, had a good sleep and I'm > still baffled as to the point if any. Could someone please enlightem me? > Here's what I think he is saying. I am posting this to test the water. I am also confused, and if I have got it wrong hopefully someone will correct me. In python 3.3, unicode strings are now stored as follows - if all characters can be represented by 1 byte, the entire string is composed of 1-byte characters else if all characters can be represented by 1 or 2 bytea, the entire string is composed of 2-byte characters else the entire string is composed of 4-byte characters There is an overhead in making this choice, to detect the lowest number of bytes required. jmfauth believes that this only benefits 'english-speaking' users, as the rest of the world will tend to have strings where at least one character requires 2 or 4 bytes. So they incur the overhead, without getting any benefit. Therefore, I think he is saying that he would have preferred that python standardise on 4-byte characters, on the grounds that the saving in memory does not justify the performance overhead. Frank Millman From rosuav at gmail.com Sat Aug 25 06:23:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 20:23:46 +1000 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Aug 25, 2012 at 6:55 PM, Mark Lawrence wrote: > I'm just wondering out aloud if the number of times this type of thread has > been debated here will fit into a Python long or float? Well, when I have to store currency information, I like to store it as an integer, using the native currency's "small unit" (eg the cent in dollar+cent currencies). In this instance, instead of trying to count the threads (which would be fractional), just count the number of posts. It then is an integer, and I've yet to find any integer that can't be represented as a Python long (or, in 3.x, int). ChrisA From breamoreboy at yahoo.co.uk Sat Aug 25 07:01:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 12:01:07 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/08/2012 11:23, Chris Angelico wrote: > On Sat, Aug 25, 2012 at 6:55 PM, Mark Lawrence wrote: >> I'm just wondering out aloud if the number of times this type of thread has >> been debated here will fit into a Python long or float? > > Well, when I have to store currency information, I like to store it as > an integer, using the native currency's "small unit" (eg the cent in > dollar+cent currencies). In this instance, instead of trying to count > the threads (which would be fractional), just count the number of > posts. It then is an integer, and I've yet to find any integer that > can't be represented as a Python long (or, in 3.x, int). > > ChrisA > That could have been fun in the good old days of pounds, shillings and pence. Why they had to complicate things by going decimal I shall never know. Bring back simplistic imperial measures for everything, that's what I say. Using long just shows I've still got a Python 2 hat on. Still when those fine people who develop Matplotlib deliver 1.2 with its Py3k compliance, aided or hindered by me testing on Windows, Python 3.3 here I come. I suppose an alternative to long (or int) or float would have been the Decimal class from the decimal module? Opinions on this anybody? -- Cheers. Mark Lawrence. From rosuav at gmail.com Sat Aug 25 07:04:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 21:04:10 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On Sat, Aug 25, 2012 at 7:46 PM, Frank Millman wrote: > Therefore, I think he is saying that he would have preferred that python > standardise on 4-byte characters, on the grounds that the saving in memory > does not justify the performance overhead. If that's indeed the argument, then at least it's something to argue. What gets difficult is when people complain about the expansion from a 2-byte narrow build to the current 1/2/4-byte representation, which will indeed use more memory if there are a small number of >0xFFFF codepoints. But there's a correctness difference there. ChrisA From breamoreboy at yahoo.co.uk Sat Aug 25 07:05:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 12:05:08 +0100 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On 25/08/2012 10:46, Frank Millman wrote: > On 25/08/2012 10:58, Mark Lawrence wrote: >> On 25/08/2012 08:27, wxjmfauth at gmail.com wrote: >>> >>> Unicode design: a flat table of code points, where all code >>> points are "equals". >>> As soon as one attempts to escape from this rule, one has to >>> "pay" for it. >>> The creator of this machinery (flexible string representation) >>> can not even benefit from it in his native language (I think >>> I'm correctly informed). >>> >>> Hint: Google -> "Das grosse Eszett" >>> >>> jmf >>> >> >> It's Saturday morning, I'm stone cold sober, had a good sleep and I'm >> still baffled as to the point if any. Could someone please enlightem me? >> > > Here's what I think he is saying. I am posting this to test the water. I > am also confused, and if I have got it wrong hopefully someone will > correct me. > > In python 3.3, unicode strings are now stored as follows - > if all characters can be represented by 1 byte, the entire string is > composed of 1-byte characters > else if all characters can be represented by 1 or 2 bytea, the entire > string is composed of 2-byte characters > else the entire string is composed of 4-byte characters > > There is an overhead in making this choice, to detect the lowest number > of bytes required. > > jmfauth believes that this only benefits 'english-speaking' users, as > the rest of the world will tend to have strings where at least one > character requires 2 or 4 bytes. So they incur the overhead, without > getting any benefit. > > Therefore, I think he is saying that he would have preferred that python > standardise on 4-byte characters, on the grounds that the saving in > memory does not justify the performance overhead. > > Frank Millman > > I thought Terry Reedy had shot down any claims about performance overhead, and that the memory savings in many cases must be substantial and therefore worthwhile. Or have I misread something? Or what? -- Cheers. Mark Lawrence. From vs at it.uu.se Sat Aug 25 07:12:12 2012 From: vs at it.uu.se (Virgil Stokes) Date: Sat, 25 Aug 2012 13:12:12 +0200 Subject: Installation of yappi (timing module) In-Reply-To: <50375758.5060800@it.uu.se> References: <50375758.5060800@it.uu.se> Message-ID: <5038B30C.7080707@it.uu.se> On 24-Aug-2012 12:28, Virgil Stokes wrote: > I have been doing some experiments with different modules for the timing of > functions and code segments. One module I would like to test is yappi (thread > aware timer) which is listed at PyPI. However, I have been unable to install > it on Windows Vista and Windows 7 (Python 2.7 on both). I have tried both > easy_install and pip (as suggested at http://code.google.com/p/yappi/). Here > is what happens with easy_install > > C:\Users\Virgil>easy_install yappi > Searching for yappi > Reading http://pypi.python.org/simple/yappi/ > Reading http://yappi.googlecode.com/ > Best match: yappi 0.62 > Downloading http://yappi.googlecode.com//files/yappi-0.62.tar.gz > Processing yappi-0.62.tar.gz > Writing > c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\setup.cfg > Running yappi-0.62\setup.py -q bdist_egg --dist-dir > c:\users\virgil\appdata\local\temp\easy_install-tzt5gl\yappi-0.62\egg-dist-tmp-t3qodo > In file included from D:\python27\include\Python.h:8, > from config.h:4, > from _yappi.c:10: > D:\python27\include\pyconfig.h:68: io.h: No such file or directory > D:\python27\include\pyconfig.h:296: stdio.h: No such file or directory > In file included from config.h:4, > from _yappi.c:10: > D:\python27\include\Python.h:19: limits.h: No such file or directory > D:\python27\include\Python.h:22: #error "Something's broken. UCHAR_MAX should > be defined in limits.h." > D:\python27\include\Python.h:26: #error "Python's source code assumes C's > unsigned char is an 8-bit type." > D:\python27\include\Python.h:33: stdio.h: No such file or directory > D:\python27\include\Python.h:35: #error "Python.h requires that stdio.h define > NULL." > D:\python27\include\Python.h:38: string.h: No such file or directory > D:\python27\include\Python.h:40: errno.h: No such file or directory > D:\python27\include\Python.h:42: stdlib.h: No such file or directory > D:\python27\include\Python.h:49: stddef.h: No such file or directory > D:\python27\include\Python.h:56: assert.h: No such file or directory > In file included from D:\python27\include\Python.h:58, > from config.h:4, > from _yappi.c:10: > D:\python27\include\pyport.h:306: stdlib.h: No such file or directory > D:\python27\include\pyport.h:312: math.h: No such file or directory > D:\python27\include\pyport.h:325: time.h: No such file or directory > D:\python27\include\pyport.h:377: sys\stat.h: No such file or directory > In file included from D:\python27\include\Python.h:85, > from config.h:4, > from _yappi.c:10: > D:\python27\include\unicodeobject.h:4: stdarg.h: No such file or directory > D:\python27\include\unicodeobject.h:57: ctype.h: No such file or directory > D:\python27\include\unicodeobject.h:120: wchar.h: No such file or directory > In file included from D:\python27\include\Python.h:94, > from config.h:4, > from _yappi.c:10: > D:\python27\include\stringobject.h:10: stdarg.h: No such file or directory > In file included from D:\python27\include\Python.h:98, > from config.h:4, > from _yappi.c:10: > D:\python27\include\bytearrayobject.h:9: stdarg.h: No such file or directory > In file included from D:\python27\include\Python.h:121, > from config.h:4, > from _yappi.c:10: > D:\python27\include\pyerrors.h:319: stdarg.h: No such file or directory > In file included from D:\python27\include\Python.h:126, > from config.h:4, > from _yappi.c:10: > D:\python27\include\modsupport.h:10: stdarg.h: No such file or directory > In file included from _yappi.c:10: > config.h:15: stdint.h: No such file or directory > In file included from _yappi.c:23: > timing.h:8: windows.h: No such file or directory > error: Setup script exited with error: command 'gcc' failed with exit status 1 > > And pip fails with similar problems (same pyconfig errors where C++ header > files are not found). In both cases yappi-0.62.tar.gz was downloaded.Note: 1) > I also tried to install from the source which also failed with similar > problems, 2) I have both cygwin and MinGW gcc compilers on my systems and they > do contain in their include folder these "missing" header files. > > Any suggestions on how yappi can be installed would be appreciated. > > --V :-) > > > Problem solved! The ordering of the gcc compilers in my PATH statement caused this failure. I have ordered these compilers such that the first one contains the required header files and the installation of yappi is now successful. --V From rosuav at gmail.com Sat Aug 25 07:19:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Aug 2012 21:19:38 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On Sat, Aug 25, 2012 at 9:05 PM, Mark Lawrence wrote: > I thought Terry Reedy had shot down any claims about performance overhead, > and that the memory savings in many cases must be substantial and therefore > worthwhile. Or have I misread something? Or what? My reading of the thread(s) is/are that there are two reasons for the debate to continue to rage: 1) Comparisons with a "narrow build" in which most characters take two bytes but there are one or two characters that get encoded with surrogates. The new system will allocate four bytes per character for the whole string. 2) Arguments on the basis of huge strings that represent _all the data_ that your program's working with, forgetting that there are numerous strings all through everything that are ASCII-only. ChrisA From tjreedy at udel.edu Sat Aug 25 07:23:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Aug 2012 07:23:04 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On 8/25/2012 7:05 AM, Mark Lawrence wrote: > I thought Terry Reedy had shot down any claims about performance > overhead, and that the memory savings in many cases must be substantial > and therefore worthwhile. Or have I misread something? No, you have correctly read what I and others have said. Jim appears to not be interested in dialog. Lets leave it at that. -- Terry Jan Reedy From tjreedy at udel.edu Sat Aug 25 07:29:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Aug 2012 07:29:48 -0400 Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: On 8/24/2012 6:33 PM, Alex wrote: > I'm new to Python and have been using IDLE 3.2.3 to experiment with > code as I learn. Despite being configured to use a 4 space indentation That applies to the editor and works in the editor for me and others. A tab becomes 4 space characters, and a backspace in the appropriate place deletes 4 space characters. > width, sometimes IDLE's "smart" indentation insists upon using width-8 > tabs. Only for the simulated interpreter. There is a tracker issue about changing that but no consensus. -- Terry Jan Reedy From jerome.dumonteil at gmail.com Sat Aug 25 08:14:38 2012 From: jerome.dumonteil at gmail.com (jerome.dumonteil at gmail.com) Date: Sat, 25 Aug 2012 05:14:38 -0700 (PDT) Subject: lpod-python In-Reply-To: References: Message-ID: <05e73bf6-c178-42bd-9733-b068cc5cf9da@googlegroups.com> Le dimanche 12 ao?t 2012 21:45:49 UTC+2, Agon Hajdari a ?crit?: > On Fri, 10 Aug 2012 19:37:16 +0200, Francesco wrote: > > > > > I'm trying to use the lpod-python module to programmatically read data > > > from Open Document files. My problem is: i can't download the module > > > from its authors' site, > > > http://download.lpod-project.org/lpod-python/lpod-python-0.9.3.tar.gz. > > > It seems the download site is unavailable, while the main site is > > > working. > > > I also tried to install the module with pip (I read on the site that > > > it's now available), but again, no luck. > > > Do somebody know what's happening to download.lpod-project.org ? It > > > doesn't even ping... > > > > > > Please let me know, thank you very much. > > > Francesco > > > > It seems that they are hosting their project at gitorious.org via git. > > Try this: > > git clone git://gitorious.org/lpod-project/lpod-python.git (u need the > > git client of course) > > > > Agon Hi, The lpod-python code is now at https://github.com/lpod/lpod-python git clone git://github.com/lpod/lpod-python.git We are currently improving source code. There are also new development recipes to help (see the readme on git hub). regards, jd From foo at email.invalid Sat Aug 25 08:50:44 2012 From: foo at email.invalid (Alex) Date: Sat, 25 Aug 2012 12:50:44 +0000 (UTC) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? References: Message-ID: Terry Reedy wrote: > On 8/24/2012 6:33 PM, Alex wrote: > > Despite being configured to use a 4 space > > indentation ... > > sometimes IDLE's "smart" indentation insists upon using > > width-8 tabs. > > [The 4-space indentation setting] applies to the editor and works in > the editor for me and others. > > [The width-8 tabs are inserted] Only for the simulated interpreter. > There is a tracker issue about changing that but no consensus. Yes, it works in the editor. I was referring to the simulated interpreter. I guess I didn't make that clear. In my search for a solution, I did see some of the traffic regarding the tracker issue, but the posts were all several years old and I was hoping maybe there was a fix by now. I guess not. Maybe in Python 4, eh? Thanks. Alex From drobinow at gmail.com Sat Aug 25 08:57:51 2012 From: drobinow at gmail.com (David Robinow) Date: Sat, 25 Aug 2012 08:57:51 -0400 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> Message-ID: On Fri, Aug 24, 2012 at 3:03 PM, Walter Hurry wrote: > On Fri, 24 Aug 2012 14:29:00 -0400, Dennis Lee Bieber wrote: > >> It appears to be a change Google made in the last month or two... My >> hypothesis is that they are replacing hard EOL found in inbound NNTP >> with an HTML

, and then on outgoing replacing the

with a pair of >> NNTP line endings. In contrast, text composed on Google is coming in as >> long single lines (since quoting said text in a response produces on a >> ">" at the start of the paragraph. > > Google Groups sucks. These are computer literate people here. Why don't > they just use a proper newsreader? I haven't used a newsreader in over a decade. I'm quite happy with a mailing list. Am I missing something? From breamoreboy at yahoo.co.uk Sat Aug 25 09:20:35 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 14:20:35 +0100 Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: On 25/08/2012 13:50, Alex wrote: > Terry Reedy wrote: > >> On 8/24/2012 6:33 PM, Alex wrote: >>> Despite being configured to use a 4 space >>> indentation > ... >>> sometimes IDLE's "smart" indentation insists upon using >>> width-8 tabs. >> >> [The 4-space indentation setting] applies to the editor and works in >> the editor for me and others. >> >> [The width-8 tabs are inserted] Only for the simulated interpreter. >> There is a tracker issue about changing that but no consensus. > > Yes, it works in the editor. I was referring to the simulated > interpreter. I guess I didn't make that clear. > > In my search for a solution, I did see some of the traffic regarding > the tracker issue, but the posts were all several years old and I was > hoping maybe there was a fix by now. I guess not. Maybe in Python 4, eh? > > Thanks. > > Alex > For the record issue 7676, yes? -- Cheers. Mark Lawrence. From foo at email.invalid Sat Aug 25 10:17:52 2012 From: foo at email.invalid (Alex) Date: Sat, 25 Aug 2012 14:17:52 +0000 (UTC) Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? References: Message-ID: Mark Lawrence wrote: > On 25/08/2012 13:50, Alex wrote: > > Terry Reedy wrote: > > > > > On 8/24/2012 6:33 PM, Alex wrote: > > > > Despite being configured to use a 4 space > > > > indentation > > ... > > > > sometimes IDLE's "smart" indentation insists upon using > > > > width-8 tabs. > > > > > > [The 4-space indentation setting] applies to the editor and works > > > in the editor for me and others. > > > > > > [The width-8 tabs are inserted] Only for the simulated > > > interpreter. There is a tracker issue about changing that but no > > > consensus. > > > > Yes, it works in the editor. I was referring to the simulated > > interpreter. I guess I didn't make that clear. > > > > In my search for a solution, I did see some of the traffic regarding > > the tracker issue, but the posts were all several years old and I > > was hoping maybe there was a fix by now. I guess not. Maybe in > > Python 4, eh? > > > > Thanks. > > > > Alex > > > > For the record issue 7676, yes? Yes, that appears to be the issue I was talking about and is, in fact, one of the threads I had looked at before posting here. Of course, I didn't pay enough attention to the dates. I see the most recent posting on the issue appears to have been made in January of this year, so I should have realized it's an ongoing issue. From mail at timgolden.me.uk Sat Aug 25 11:31:08 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 25 Aug 2012 16:31:08 +0100 Subject: Filter versus comprehension (was Re: something about split()???) In-Reply-To: References: <502A865E.4030504@sequans.com> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com> Message-ID: <5038EFBC.6000603@timgolden.me.uk> On 25/08/2012 13:57, David Robinow wrote: > On Fri, Aug 24, 2012 at 3:03 PM, Walter Hurry wrote: >> On Fri, 24 Aug 2012 14:29:00 -0400, Dennis Lee Bieber wrote: >> >>> It appears to be a change Google made in the last month or two... My >>> hypothesis is that they are replacing hard EOL found in inbound NNTP >>> with an HTML

, and then on outgoing replacing the

with a pair of >>> NNTP line endings. In contrast, text composed on Google is coming in as >>> long single lines (since quoting said text in a response produces on a >>> ">" at the start of the paragraph. >> >> Google Groups sucks. These are computer literate people here. Why don't >> they just use a proper newsreader? > I haven't used a newsreader in over a decade. I'm quite happy with a > mailing list. Am I missing something? Not really. I'm the same; it just means you can skip over the occasional ggroups-newsreader discussion threads which pop up about 3 times a year on average. :) TJG From wxjmfauth at gmail.com Sat Aug 25 11:47:52 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 08:47:52 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: Le samedi 25 ao?t 2012 11:46:34 UTC+2, Frank Millman a ?crit?: > On 25/08/2012 10:58, Mark Lawrence wrote: > > > On 25/08/2012 08:27, wxjmfauth at gmail.com wrote: > > >> > > >> Unicode design: a flat table of code points, where all code > > >> points are "equals". > > >> As soon as one attempts to escape from this rule, one has to > > >> "pay" for it. > > >> The creator of this machinery (flexible string representation) > > >> can not even benefit from it in his native language (I think > > >> I'm correctly informed). > > >> > > >> Hint: Google -> "Das grosse Eszett" > > >> > > >> jmf > > >> > > > > > > It's Saturday morning, I'm stone cold sober, had a good sleep and I'm > > > still baffled as to the point if any. Could someone please enlightem me? > > > > > > > Here's what I think he is saying. I am posting this to test the water. I > > am also confused, and if I have got it wrong hopefully someone will > > correct me. > > > > In python 3.3, unicode strings are now stored as follows - > > if all characters can be represented by 1 byte, the entire string is > > composed of 1-byte characters > > else if all characters can be represented by 1 or 2 bytea, the entire > > string is composed of 2-byte characters > > else the entire string is composed of 4-byte characters > > > > There is an overhead in making this choice, to detect the lowest number > > of bytes required. > > > > jmfauth believes that this only benefits 'english-speaking' users, as > > the rest of the world will tend to have strings where at least one > > character requires 2 or 4 bytes. So they incur the overhead, without > > getting any benefit. > > > > Therefore, I think he is saying that he would have preferred that python > > standardise on 4-byte characters, on the grounds that the saving in > > memory does not justify the performance overhead. > > > > Frank Millman Very well explained. Thanks. More precisely, affected are not only the 'english-speaking' users, but all the users who are using not latin-1 characters. (See the title of this topic, ... typography). Being at the same time, latin-1 and unicode compliant is a plain absurdity in the mathematical sense. --- For those you do not know, the go language has introduced the rune type. As far as I know, nobody is complaining, I have not even seen a discussion related to this subject. 100% Unicode compliant from the day 0. Congratulations. jmf From wxjmfauth at gmail.com Sat Aug 25 11:47:52 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 08:47:52 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: Le samedi 25 ao?t 2012 11:46:34 UTC+2, Frank Millman a ?crit?: > On 25/08/2012 10:58, Mark Lawrence wrote: > > > On 25/08/2012 08:27, wxjmfauth at gmail.com wrote: > > >> > > >> Unicode design: a flat table of code points, where all code > > >> points are "equals". > > >> As soon as one attempts to escape from this rule, one has to > > >> "pay" for it. > > >> The creator of this machinery (flexible string representation) > > >> can not even benefit from it in his native language (I think > > >> I'm correctly informed). > > >> > > >> Hint: Google -> "Das grosse Eszett" > > >> > > >> jmf > > >> > > > > > > It's Saturday morning, I'm stone cold sober, had a good sleep and I'm > > > still baffled as to the point if any. Could someone please enlightem me? > > > > > > > Here's what I think he is saying. I am posting this to test the water. I > > am also confused, and if I have got it wrong hopefully someone will > > correct me. > > > > In python 3.3, unicode strings are now stored as follows - > > if all characters can be represented by 1 byte, the entire string is > > composed of 1-byte characters > > else if all characters can be represented by 1 or 2 bytea, the entire > > string is composed of 2-byte characters > > else the entire string is composed of 4-byte characters > > > > There is an overhead in making this choice, to detect the lowest number > > of bytes required. > > > > jmfauth believes that this only benefits 'english-speaking' users, as > > the rest of the world will tend to have strings where at least one > > character requires 2 or 4 bytes. So they incur the overhead, without > > getting any benefit. > > > > Therefore, I think he is saying that he would have preferred that python > > standardise on 4-byte characters, on the grounds that the saving in > > memory does not justify the performance overhead. > > > > Frank Millman Very well explained. Thanks. More precisely, affected are not only the 'english-speaking' users, but all the users who are using not latin-1 characters. (See the title of this topic, ... typography). Being at the same time, latin-1 and unicode compliant is a plain absurdity in the mathematical sense. --- For those you do not know, the go language has introduced the rune type. As far as I know, nobody is complaining, I have not even seen a discussion related to this subject. 100% Unicode compliant from the day 0. Congratulations. jmf From __peter__ at web.de Sat Aug 25 11:55:05 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Aug 2012 17:55:05 +0200 Subject: Publish unittest results from test discovery References: Message-ID: Lucretiel wrote: > So I've started using unittest, and I love it. I use testdiscovery (python > -m unittest discover) so that I can distribute my tests and don't have to > manage them all manually. I wanted to start publishing my test results to > xml, though. I found xmlrunner by googling around, but it requires me to > add an if __name__ == '__main__' block to my code, which isn't executed by > unittest discover. Is there a way to get unittest disover to work with > xmlrunner, or to some other way to solve this without restructuring all my > test code? I don't see where you could specify a test runner on the commandline, but you can reuse the discovery code in your own scripts. For the following example I basically copied unittest.__main__.py: $ cat discover.py #!/usr/bin/env python import xmlrunner __unittest = True from unittest.main import main, TestProgram, USAGE_AS_MAIN TestProgram.USAGE = USAGE_AS_MAIN main(module=None, testRunner=xmlrunner.XMLTestRunner(output='test-reports')) $ cat test_alpha.py import unittest class T(unittest.TestCase): def test_alpha(self): pass def test_beta(self): self.assertEquals(["a", "b", "c"], ["a", "B", "c"]) $ ./discover.py discover Running tests... ---------------------------------------------------------------------- .F ====================================================================== FAIL [0.001s]: test_beta (test_alpha.T) ---------------------------------------------------------------------- Traceback (most recent call last): File "/somewhere/over/the/rainbow/discover/test_alpha.py", line 7, in test_beta self.assertEquals(["a", "b", "c"], ["a", "B", "c"]) AssertionError: Lists differ: ['a', 'b', 'c'] != ['a', 'B', 'c'] First differing element 1: b B - ['a', 'b', 'c'] ? ^ + ['a', 'B', 'c'] ? ^ ---------------------------------------------------------------------- Ran 2 tests in 0.002s FAILED (failures=1) Generating XML reports... $ ls discover.py test_alpha.py test_alpha.pyc test-reports $ ls test-reports/ TEST-test_alpha.T.xml $ From yueyoum at gmail.com Sat Aug 25 12:03:07 2012 From: yueyoum at gmail.com (=?UTF-8?B?5pyI5b+n6IyX?=) Date: Sun, 26 Aug 2012 00:03:07 +0800 Subject: Probability Algorithm Message-ID: Hi, All, I have a problem of probability algorithm The goal is obtain a list which contains three items. as the *FinalList* There has Four source lists. * ALIST, BLIST, CLIST, DLIST There are all Unknown length. They contains unique elements* ( In fact, there are all empty at the program beginning, when running, there growing ) Choose items form this source lists. pick up random items to generate the FinalList Ensure The Following Requirements In the FinalList, probability of ALIST's item appeared is 43% probability of BLIST's item appeared is 37% probability of CLIST's item appeared is 19% probability of DLIST's item appeared is 1% I have written some code, but this just for the four lists are have a lots of elements. ---- from random import choice final_list = [] slot = [] a_picked_times = 0 while a_picked_times < 43: item = choice(ALIST) ALIST.remove(item) if item in already_picked_list: continue slot.append(item) a_picked_times += 1 b_picked_times = 0 while_b_picked_times < 37: ... SOME CODE SIMILAR # now slot is a list which contains 100 elements, # in slot, there are 43 elements of ALIST'items, 37 of B, 19 of C, 1 of D for i in range(3): final_list.append( choice(slot) ) ---- So, this can ensure the probability requirements. *BUT only under the condition: this Four lists have a lots of elements. * list.remove( item ) that will not remove all elements in list, so we will correct pick up items with the needs times. But, when A, B, C, D empty OR not enough elements, How could ensure the probability requirements? A, B, C, D list are all get from redis sorted list. Or some solution with redis ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sat Aug 25 12:37:50 2012 From: d at davea.name (Dave Angel) Date: Sat, 25 Aug 2012 12:37:50 -0400 Subject: Probability Algorithm In-Reply-To: References: Message-ID: <5038FF5E.4010301@davea.name> On 08/25/2012 12:03 PM, ??? wrote: > Hi, All, > > I have a problem of probability algorithm > > > The goal is obtain a list which contains three items. as the *FinalList* > > There has Four source lists. * > ALIST, BLIST, CLIST, DLIST > > There are all Unknown length. They contains unique elements* > ( In fact, there are all empty at the program beginning, when running, > there growing ) > > Choose items form this source lists. pick up random items to generate the > FinalList > Ensure The Following Requirements > > In the FinalList, > probability of ALIST's item appeared is 43% > probability of BLIST's item appeared is 37% > probability of CLIST's item appeared is 19% > probability of DLIST's item appeared is 1% > > Would you like to tell us the actual assignment? This looks like it's paraphrased. if you have 3 items, each coming from one of four lists, the four probabilities have to add up to much more than 100%. Perhaps what you meant was that each of the three items had those probabilities of coming from the respective lists. Then it'd add up to 100%. Your code is far more complex than needed, and as you observed, doesn't work if each list doesn't have sufficient members. I'd simply pick a random number from 0 to 99, see if it's less than 43 and if so, use ALIST. Else if it's less than 80, use BLIST. else if it's less than 99, use CLIST. Else DLIST. Then do that 2 more times and you're done. Don't forget to factor the problem into functions, so you can easily repeat similar code. If a list is picked, and it's empty, throw an exception. Or wait till the missing item arrives. And you have to decide whether to remove the selected items from the respective lists. That wasn't specified in the problem statement. -- DaveA From a.m.akingbulu-11 at student.lboro.ac.uk Sat Aug 25 14:34:39 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Sat, 25 Aug 2012 11:34:39 -0700 (PDT) Subject: issue with struct.unpack Message-ID: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? I checked the python documentation for struct and I can seen to find any argument for this. I have data = struct.unpack('char',data) but I still get errors From tjreedy at udel.edu Sat Aug 25 14:36:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Aug 2012 14:36:46 -0400 Subject: Is there a way to configure IDLE to use spaces instead of tabs for indenting? In-Reply-To: References: Message-ID: On 8/25/2012 10:17 AM, Alex wrote: > Yes, that appears to be the issue I was talking about and is, in fact, > one of the threads I had looked at before posting here. Of course, I > didn't pay enough attention to the dates. I see the most recent posting > on the issue appears to have been made in January of this year, so I > should have realized it's an ongoing issue. There have also been a few posts this year on the idle-sig mail list. There are only a few people working on IDLE and we have concentrated this calendar year on fixing crashers, not semi-aesthetic issues. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Aug 25 15:12:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 25 Aug 2012 20:12:13 +0100 Subject: issue with struct.unpack In-Reply-To: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: On 25/08/2012 19:34, 9bizy wrote: > I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? > > I checked the python documentation for struct and I can seen to find any argument for this. > > I have data = struct.unpack('char',data) but I still get errors > We have two options here. Either a) People reading your original request go on a mind reading course or similar in an attempt to find out what the errors are, though I'm confused as to how you get errors from one line of code. Or b) Provide the smallest sample of code that allows the problem to be reproduced together with the complete traceback so we can see exactly what happened. -- Cheers. Mark Lawrence. From python at mrabarnett.plus.com Sat Aug 25 15:16:54 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 25 Aug 2012 20:16:54 +0100 Subject: issue with struct.unpack In-Reply-To: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: <503924A6.9010301@mrabarnett.plus.com> On 25/08/2012 19:34, 9bizy wrote: > I am trying to unpack values from sensor data I am retrieving through > a serial cable, but I get errors while using struct.unpack, how can I > use struct.unpack to unload the data in a readable format? > > I checked the python documentation for struct and I can seen to find > any argument for this. > > I have data = struct.unpack('char',data) but I still get errors > The format strings are described here for Python 3: http://docs.python.org/3.2/library/struct.html and here for Python 2: http://docs.python.org/2.7/library/struct.html From georg at python.org Sat Aug 25 15:36:54 2012 From: georg at python.org (Georg Brandl) Date: Sat, 25 Aug 2012 21:36:54 +0200 Subject: [RELEASED] Python 3.3.0 release candidate 1 Message-ID: <50392956.6030907@python.org> On behalf of the Python development team, I'm delighted to announce the first release candidate of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From tyler at tysdomain.com Sat Aug 25 16:47:35 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sat, 25 Aug 2012 14:47:35 -0600 Subject: modeling complex data with sqlalchemy Message-ID: <503939E7.8080506@tysdomain.com> Hello all: I had a quick question. In my game, I have an is-a setup, where all objects contain data like an id for sqlalchemy, a name, a description and a list of contents. In order to add functionality to an object, you add components. So for example, a player would have the Player and Living component associated with the basic object. It's sort of a way to give myself a way to add functionality without having a lot of multiple inheritance. This creates a problem for me though, since it looks like each component would have it's own table. How would you go about modeling the 1:n relationship between entity and each component? Also, I'm going to have a location property on the object, which is basically it's location (a reference to another Entity), or None if it has no parent. How would you set that up in SA so that location gets translated to an ID and then translated back to the required object? Might there be another easier way to model all this data? It looks like this database could get rather large, extremely quickly. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From ian.g.kelly at gmail.com Sat Aug 25 18:26:56 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 25 Aug 2012 16:26:56 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: On Sat, Aug 25, 2012 at 9:47 AM, wrote: > For those you do not know, the go language has introduced > the rune type. As far as I know, nobody is complaining, I > have not even seen a discussion related to this subject. Python has that also. We call it "int". More seriously, strings in Go are not sequences of runes. They're actually arrays of UTF-8 bytes. That means that they're quite efficient for ASCII strings, at the expense of other characters, like Chinese (wait, this sounds familiar for some reason). It also means that you have to bend over backwards if you want to work with actual runes instead of bytes. Want to know how many characters are in your string? Don't call len() on it -- that will only tell you how many bytes are in it. Don't try to index or slice it either -- that will (accidentally) work for ASCII strings, but for other strings your indexes will be wrong. If you're unlucky you might even split up the string in the middle of a character, and now your string has invalid characters in it. The right way to do it looks something like this: len([]rune("???")) // get the length of the string in characters string([]rune("???")[0:2]) // get the substring containing the first two characters It reminds me of working in Python 2.X, except that instead of an actual unicode type you just have arrays of ints. From rosuav at gmail.com Sat Aug 25 19:27:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Aug 2012 09:27:14 +1000 Subject: Objects in Python In-Reply-To: References: <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 5:56 AM, Dennis Lee Bieber wrote: > On Sat, 25 Aug 2012 09:55:27 +0100, Mark Lawrence > declaimed the following in > gmane.comp.python.general: > >> >> I'm just wondering out aloud if the number of times this type of thread >> has been debated here will fit into a Python long or float? > > Well, since I don't think one can have a fractional debate (maybe if > someone starts a thread and NOBODY ever follows up on it), then float's > don't gain us anything there. > > Presuming a double-precision float, we would have 14-15 significant > digits for the mantissa -- so anything greater than > (9)99,999,999,999,999 will have lost accuracy. In contrast Python longs > have effectively unlimited significant digits. I wonder if some people are applying an alternative form of duck typing - if it quacks like a "should Python have variables" debate, it gets silenced with that universal grey tape... ChrisA From amangill.coldfire at gmail.com Sat Aug 25 20:11:33 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Sat, 25 Aug 2012 17:11:33 -0700 (PDT) Subject: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS In-Reply-To: References: Message-ID: <8fe64d39-8bd3-4b4a-b8c4-5b68ab7a4619@googlegroups.com> On Friday, 17 August 2012 18:16:08 UTC+5:30, coldfire wrote: > I would like to know that where can a python script be stored on-line from were it keep running and can be called any time when required using internet. > > I have used mechanize module which creates a webbroswer instance to open a website and extract data and email me. > > I have tried Python anywhere but they dont support opening of anonymous websites. > > What s the current what to DO this? > > Can someone point me in the write direction. > > My script have no interaction with User It just Got on-line searches for something and emails me. > > > > Thanks I got most of it. I will really appreciate is someone out the address of any of the following for use with python 1>Webhost 2>Shell Account 3>VPS I am really new to all this Got web server and shell account but unable to figure out how to use it or deploy the Code, My problem is that I m using lot of third party Library which are mostly not supported or I don't know How to make it RUN over Internet Plz Help From mccomas.chris at gmail.com Sat Aug 25 22:20:05 2012 From: mccomas.chris at gmail.com (Christopher McComas) Date: Sat, 25 Aug 2012 22:20:05 -0400 Subject: Computing win/loss records in Python Message-ID: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> Greetings, I have code that I run via Django that grabs the results from various sports from formatted text files. The script iterates over every line in the formatted text files, finds the team in the Postgres database updates their w/l record depending on the outcome on that line, saves the team's row in the db, and then moves on to the next line in the file. I'm trying to get away from Django for this project, I want to run the files, get the W/L results and output a formatted text file with the teams and their W/L records. What's confusing me I guess how to store the data/results as the wins and losses tally up. We're talking hundreds of teams, thousands of games, but a quick example would be: Marshall Ohio State Kentucky Indiana Marshall,24,Ohio State,48, Kentucky,14,Indiana,10, Marshall,10,Indiana,7, Ohio State,28,Kentucky,10 That's just a quick example, I can handle seperating the data in the lines, figuring it all out, I just am unsure of how to keep a running total of a team's record. I would do "for line in file:" then on the first line I see that Marshall lost so they would have 1, Ohio State won so they'd have 1 win. It'd go to the next line Kentucky 1 win, Indiana 1 loss, then on the 3rd line, Marshall got a win so they'd have 1 win, but it would have to remember that loss from line 1... Does this make sense? Thanks, From rodrick.brown at gmail.com Sat Aug 25 22:32:22 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sat, 25 Aug 2012 22:32:22 -0400 Subject: Computing win/loss records in Python In-Reply-To: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> References: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> Message-ID: <-835824870088032657@unknownmsgid> On Aug 25, 2012, at 10:22 PM, Christopher McComas wrote: > Greetings, > > I have code that I run via Django that grabs the results from various sports from formatted text files. The script iterates over every line in the formatted text files, finds the team in the Postgres database updates their w/l record depending on the outcome on that line, saves the team's row in the db, and then moves on to the next line in the file. > > I'm trying to get away from Django for this project, I want to run the files, get the W/L results and output a formatted text file with the teams and their W/L records. What's confusing me I guess how to store the data/results as the wins and losses tally up. We're talking hundreds of teams, thousands of games, but a quick example would be: > > Marshall > Ohio State > Kentucky > Indiana > > Marshall,24,Ohio State,48, > Kentucky,14,Indiana,10, > Marshall,10,Indiana,7, > Ohio State,28,Kentucky,10 > > That's just a quick example, I can handle seperating the data in the lines, figuring it all out, I just am unsure of how to keep a running total of a team's record. I would do "for line in file:" then on the first line I see that Marshall lost so they would have 1, Ohio State won so they'd have 1 win. It'd go to the next line Kentucky 1 win, Indiana 1 loss, then on the 3rd line, Marshall got a win so they'd have 1 win, but it would have to remember that loss from line 1... > > Does this make sense? Yes, use a RDBMS, SQLite may be the best fit for your use case its quick and has low overhead. > > Thanks, > -- > http://mail.python.org/mailman/listinfo/python-list From steveo at syslang.net Sat Aug 25 22:42:59 2012 From: steveo at syslang.net (Steven W. Orr) Date: Sat, 25 Aug 2012 22:42:59 -0400 Subject: Computing win/loss records in Python In-Reply-To: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> References: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> Message-ID: <50398D33.50900@syslang.net> On 8/25/2012 10:20 PM, Christopher McComas wrote: > Greetings, > > I have code that I run via Django that grabs the results from various sports from formatted text files. The script iterates over every line in the formatted text files, finds the team in the Postgres database updates their w/l record depending on the outcome on that line, saves the team's row in the db, and then moves on to the next line in the file. > > I'm trying to get away from Django for this project, I want to run the files, get the W/L results and output a formatted text file with the teams and their W/L records. What's confusing me I guess how to store the data/results as the wins and losses tally up. We're talking hundreds of teams, thousands of games, but a quick example would be: > > Marshall > Ohio State > Kentucky > Indiana > > Marshall,24,Ohio State,48, > Kentucky,14,Indiana,10, > Marshall,10,Indiana,7, > Ohio State,28,Kentucky,10 > > That's just a quick example, I can handle seperating the data in the lines, figuring it all out, I just am unsure of how to keep a running total of a team's record. I would do "for line in file:" then on the first line I see that Marshall lost so they would have 1, Ohio State won so they'd have 1 win. It'd go to the next line Kentucky 1 win, Indiana 1 loss, then on the 3rd line, Marshall got a win so they'd have 1 win, but it would have to remember that loss from line 1... > > Does this make sense? > > Thanks, win_count = defaultdict(int) loss_count = defaultdict(int) items = line.split(',') if items[1] > items[3]: windex = 0 lossdex = 2 else: windex = 2 lossdex = 0 win_count[windex] += 1 loss_count[lossdex] += 1 Zat help? -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From steve+comp.lang.python at pearwood.info Sat Aug 25 23:19:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 03:19:23 GMT Subject: Computing win/loss records in Python References: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> Message-ID: <503995ba$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Aug 2012 22:42:59 -0400, Steven W. Orr wrote: > win_count = defaultdict(int) > loss_count = defaultdict(int) When I try that, I get "NameError: name 'defaultdict' is not defined." I think it is rather unfair on beginners to show them code that almost, but not quite, works, and expect them to somehow work out what this mysterious "defaultdict" is. The answer is probably to do this first: from collections import defaultdict > items = line.split(',') > if items[1] > items[3]: > windex = 0 > lossdex = 2 That's not going to work, because you are doing string comparisons instead of numeric comparisons. Consider: Kentucky,6,Indiana,59 '6' > '59' and you will wrongly count that as a win to Kentucky. > else: > windex = 2 > lossdex = 0 > win_count[windex] += 1 > loss_count[lossdex] += 1 And that certainly won't work, because all you are doing is counting how many times the first team beats the second, instead of counting how many times each team wins. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 25 23:38:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 03:38:15 GMT Subject: Computing win/loss records in Python References: Message-ID: <50399a27$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Aug 2012 22:20:05 -0400, Christopher McComas wrote: > Marshall,24,Ohio State,48, > Kentucky,14,Indiana,10, > Marshall,10,Indiana,7, > Ohio State,28,Kentucky,10 > > That's just a quick example, I can handle seperating the data in the > lines, figuring it all out, I just am unsure of how to keep a running > total of a team's record. I would do "for line in file:" then on the > first line I see that Marshall lost so they would have 1, Ohio State won > so they'd have 1 win. It'd go to the next line Kentucky 1 win, Indiana 1 > loss, then on the 3rd line, Marshall got a win so they'd have 1 win, but > it would have to remember that loss from line 1... There are many ways to do this. Here's one: we keep three sets of data, wins, losses and ties. wins = {} losses = {} ties = {} for line in open("datafile.txt"): line = line.strip() # get rid of leading and trailing whitespace line = line.rstrip(',') # and any trailing comma teamA, scoreA, teamB, scoreB = line.split(',') # split on commas teamA = teamA.strip().title() # normalise the case teamB = teamB.strip().title() scoreA = int(scoreA) scoreB = int(scoreB) if scoreA == scoreB: # Handle a draw. ties[teamA] = ties.get(teamA, 0) + 1 ties[teamB] = ties.get(teamB, 0) + 1 else: if scoreA > scoreB: winner = teamA loser = teamB else: winner = teamB loser = teamA wins[winner] = wins.get(winner, 0) + 1 losses[loser] = losses.get(loser, 0) + 1 Once you've done that, you can check the win/loss score of any team: name = 'Marshall' w = wins.get(name, 0) l = losses.get(name, 0) d = ties.get(name, 0) total = w+l+d print( "Team %s played %d games, won %d, lost %d and tied %d." % (name, total, w, l, d) ) If you want to store these results permanently, you need to write them out to file. You can roll your own, but a simpler way might be to use one of the pickle, json, csv or plistlib modules to do it. -- Steven From steve+comp.lang.python at pearwood.info Sat Aug 25 23:47:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 03:47:56 GMT Subject: Probability Algorithm References: Message-ID: <50399c6c$0$6574$c3e8da3$5496439d@news.astraweb.com> On 08/25/2012 12:03 PM, ??? wrote: > In the FinalList, > probability of ALIST's item appeared is 43% probability of BLIST's > item appeared is 37% probability of CLIST's item appeared is 19% > probability of DLIST's item appeared is 1% First, select one of the four lists with those appropriate probabilities. Then once you selected a list, select one of its items randomly. import random def select_list(): x = random.randint(1, 100) if x <= 43: return ALIST elif x <= 80: # 43 + 37 return BLIST elif x <= 99: # + 19 return CLIST else: return DLIST the_list = select_list() the_item = random.choice(the_list) -- Steven From yueyoum at gmail.com Sat Aug 25 23:47:57 2012 From: yueyoum at gmail.com (=?UTF-8?B?5pyI5b+n6IyX?=) Date: Sun, 26 Aug 2012 11:47:57 +0800 Subject: Probability Algorithm In-Reply-To: References: Message-ID: Sorry, missing some conditions *already_picked_list* is get from db. > Why keep a counter? Rather than an iterated loop so , if use a iterated loop: for i in range(43): item = choice( ALIST ) ALIST.remove( item ) if item in already_picked_list: continue slot.append( item ) For example, if we picked item from ALIST 43 times, but all picked items are in already_picked_list What's the slot? It's a empty list, not contains item from ALIST. *This is wrong* > Do you really want to remove an item from the source list? *Yes*, i*tems in slot must be unique* ( This is also a condition, which I have missing... ) > and if you don't want duplicates from within a source list, you should remove them when building the source list * As I mentioned , The source list are all unique elements* Your last code. if B ,C ,D are all empty, result's elements are all from A, A's probability is 100% ? I Know , this problem should treated as two situation: If the four list has not enough elements, There are no way to ensure the probability requirements. If they has enough elements, Your solution is a good way. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sun Aug 26 00:33:16 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 26 Aug 2012 14:33:16 +1000 Subject: Computing win/loss records in Python References: Message-ID: <87fw7ae0hf.fsf@benfinney.id.au> Christopher McComas writes: > I have code that I run via Django that grabs the results from various > sports from formatted text files. The script iterates over every line > in the formatted text files, finds the team in the Postgres database > updates their w/l record depending on the outcome on that line, saves > the team's row in the db, and then moves on to the next line in the > file. It seems that you already have a PostgreSQL database storing this data. > I'm trying to get away from Django for this project That existing database can be accessed without Django. You could talk directly using the ?psycopg2? library, but you don't have to go that far. I would recommend you use SQLAlchemy as a good and flexible way to access existing databases (or make new ones) in a Pythonic manner . If you are using a free-software operating system, you will likely already have packages available to install SQLAlchemy from your operating system's package repositories. -- \ ?True greatness is measured by how much freedom you give to | `\ others, not by how much you can coerce others to do what you | _o__) want.? ?Larry Wall | Ben Finney From yueyoum at gmail.com Sun Aug 26 00:44:00 2012 From: yueyoum at gmail.com (=?UTF-8?B?5pyI5b+n6IyX?=) Date: Sun, 26 Aug 2012 12:44:00 +0800 Subject: Probability Algorithm In-Reply-To: <50399c6c$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <50399c6c$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks for helps This code almost meets my needs . But not accurate probability when not enough source elements. So I give up the not enough elements situation. For source list is growing fast, the bast situation just appear in the program starting 2012/8/26 Steven D'Aprano > On 08/25/2012 12:03 PM, ??? wrote: > > > In the FinalList, > > probability of ALIST's item appeared is 43% probability of BLIST's > > item appeared is 37% probability of CLIST's item appeared is 19% > > probability of DLIST's item appeared is 1% > > First, select one of the four lists with those appropriate probabilities. > Then once you selected a list, select one of its items randomly. > > import random > > def select_list(): > x = random.randint(1, 100) > if x <= 43: > return ALIST > elif x <= 80: # 43 + 37 > return BLIST > elif x <= 99: # + 19 > return CLIST > else: > return DLIST > > the_list = select_list() > the_item = random.choice(the_list) > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From driscoll at cs.wisc.edu Sun Aug 26 01:25:06 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Sun, 26 Aug 2012 00:25:06 -0500 Subject: Objects in Python In-Reply-To: <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <5035d3e4$0$1645$c3e8da3$76491128@news.astraweb.com> <50366ec8$0$6574$c3e8da3$5496439d@news.astraweb.com> <503840c5$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5039B332.7080200@cs.wisc.edu> On 08/24/2012 10:04 PM, Steven D'Aprano wrote: > The fact that the end result is the same is hardly surprising -- Python's > VM is built on top of C pointer indirection, so of course you can start > with pointers and end up with Python semantics. But the practice of > coding are very different: > > * in C, I care about identifiers ("names") in order to explicitly manage > addresses and pointers as a means to reach the data I actually care about; > > * in Python, I care about identifiers in order to reach the data I > actually care about. > So I find this comment very interesting. It makes me wonder if the root cause of our (pretty minor) disagreement is in some sense related to our mental models of *C* variables. I'm actually not much of a C programmer specifically, but I do a lot of C++ stuff. Of those two descriptions, I'd actually say that the Python description sounds more like how I think about variables in C++ most of the time. Obviously there are differences between value and reference semantics between the two languages, but thinking about some variable being located at some address in memory is something that I actually do pretty rarely; I basically think of variables as naming data, and addresses mostly come into play when thinking about points-to and aliasing information at a more abstract level, much the same as I do in Python. Evan From driscoll at cs.wisc.edu Sun Aug 26 01:45:55 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Sun, 26 Aug 2012 00:45:55 -0500 Subject: Objects in Python In-Reply-To: <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5039B813.8020603@cs.wisc.edu> On 08/24/2012 05:00 AM, Steven D'Aprano wrote: > No. The compiler remembers the address of 'a' by keeping notes about it > somewhere in memory during the compilation process. When you run the > compiled program, there is no longer any reference to the name 'a'. > > ... > > The mapping of name:address is part of the *compilation* process -- the > compiler knows that variable 'x' corresponds to location 12345678, but > the compiled code has no concept of anything called 'x'. It only knows > about locations. The source code 'x = 42' is compiled into something like > 'store 42 into location 12345678'. (Locations may be absolute or > relative.) > > In languages with name bindings, the compiler doesn't need to track > name:address pairs. The compiled application knows about names, but not > about addresses. The source code 'x = 42' is compiled into something like > 'store 42 into the namespace using key "x"'. What you describe is sorta correct, but it's also not... you're describing implementations rather than the language. And while the language semantics certainly impose restrictions on the implementation, I think in this case the situation is closer than you acknowledge: From the Python side, I suspect that for most functions, you'd be able to create a Python implementation that behaves more like C, and allocates locals in a more traditional fashion. I don't know much about it, but I'd guess that PyPy already does something along this line; someone also mentioned that Cython (admittedly not a full-blown Python implementation, but close for the purpose of this question) tries to do the same thing. On the C side, imagine a function with locals x, y, and z which never takes the address of any of them. (You said later that "Just because the public interface of the language doesn't give you any way to view the fixed locations of variables, doesn't mean that variables cease to have fixed locations.") First, C variables may not even have a memory address. They can disappear completely during compilation, or live in a register for their entire life. Second, it's possible that those variables *don't* occupy a fixed location. If you never explicitly take an address of a variable (&x), then I can't think of any way that the address can be observed without invoking undefined behavior -- and this means the C compiler is free to transform it to anything that is equivalent under the C semantics. In particular, it can split uses of a variable into multiple ones if there are disjoint live ranges. For instance, in: x = 5 print x x = 10 print x there are two live ranges of x, one consisting of lines 1 and 2, and one consisting of lines 3 and 4. These live ranges could have been different variables; I could just of easily have written x = 5 print x y = 10 print y and these pieces of code are observationally equivalent, so the compiler is allowed to generate the same code for both. In particular, it could either compile the second example to share the same memory address for x and y (meaning that a memory address isn't uniquely named by a single variable) or it could compile the first to put the two live ranges of x into different memory addresses (meaning that a variable doesn't uniquely name a memory address). In fact, I'd *expect* an optimizing compiler to share memory for x and y, and I'd also expect to be able to concoct an example where different live ranges of one variable wind up at different addresses. (The latter I'm less sure of though, and I also expect it'd be a little hard, as you'd have to come up with an example where even at the high optimization levels you'd need to see that, both live ranges would wind up in memory.) Third, and more wackily, you could technically create a C implementation that works like Python, where it stores variables (whose addresses aren't taken) in a dict keyed by name, and generates code that on a variable access looks up the value by accessing that dict using the name of the variable. Evan From dihedral88888 at googlemail.com Sun Aug 26 02:14:52 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 25 Aug 2012 23:14:52 -0700 (PDT) Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <1pidnX71rLNrsajNnZ2dnUVZ8jCdnZ2d@bt.com> <5035ad87$0$1645$c3e8da3$76491128@news.astraweb.com> Message-ID: Jan Kuiken? 2012?8?24????UTC+8??2?02?00???? > On 8/23/12 06:11 , Steven D'Aprano wrote: > > > > >> 2) Related to the above, you can infinitely nest scopes. There's nothing > > >> wrong with having six variables called 'q'; you always use the innermost > > >> one. Yes, this can hurt readability > > > > > > Well, there you go. There *is* something wrong with having six variables > > > called 'q'. > > > > Sometimes you don't want only six variables called 'q' but a hundred > > of them :-) > > > > def fac(q): > > if q < 1 : > > return 1 > > else: > > return q * fac(q-1) > > > > print(fac(100)) > > > > > > Jan Kuiken The long integer arithmetic operations are built in. This makes mathematicians and designers focused on the theory side. From rosuav at gmail.com Sun Aug 26 02:22:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Aug 2012 16:22:05 +1000 Subject: Objects in Python In-Reply-To: <5039B813.8020603@cs.wisc.edu> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> Message-ID: On Sun, Aug 26, 2012 at 3:45 PM, Evan Driscoll wrote: > Third, and more wackily, you could technically create a C implementation > that works like Python, where it stores variables (whose addresses aren't > taken) in a dict keyed by name, and generates code that on a variable access > looks up the value by accessing that dict using the name of the variable. That would be a reasonable way to build a C interactive interpreter. ChrisA From wxjmfauth at gmail.com Sun Aug 26 02:59:34 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 23:59:34 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: <4853fddf-5e4d-4c11-9a19-5a1dbe4cbc20@googlegroups.com> Le dimanche 26 ao?t 2012 00:26:56 UTC+2, Ian a ?crit?: > On Sat, Aug 25, 2012 at 9:47 AM, wrote: > > > For those you do not know, the go language has introduced > > > the rune type. As far as I know, nobody is complaining, I > > > have not even seen a discussion related to this subject. > > > > Python has that also. We call it "int". > > > > More seriously, strings in Go are not sequences of runes. They're > > actually arrays of UTF-8 bytes. That means that they're quite > > efficient for ASCII strings, at the expense of other characters, like > > Chinese (wait, this sounds familiar for some reason). It also means > > that you have to bend over backwards if you want to work with actual > > runes instead of bytes. Want to know how many characters are in your > > string? Don't call len() on it -- that will only tell you how many > > bytes are in it. Don't try to index or slice it either -- that will > > (accidentally) work for ASCII strings, but for other strings your > > indexes will be wrong. If you're unlucky you might even split up the > > string in the middle of a character, and now your string has invalid > > characters in it. The right way to do it looks something like this: > > > > len([]rune("???")) // get the length of the string in characters > > string([]rune("???")[0:2]) // get the substring containing the first > > two characters > > > > It reminds me of working in Python 2.X, except that instead of an > > actual unicode type you just have arrays of ints. Sorry, you do not get it. The rune is an alias for int32. A sequence of runes is a sequence of int32's. Go do not spend its time in using a machinery to work with, to differentiate, to keep in memory this sequence according to the *characers* composing this "array of code points". The message is even stronger. Use runes to work comfortably [*] with unicode: rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be better) [*] Beyond my skill and my kwowloge and if I understood correctly, this rune is even technically optimized to ensure it it always an int32. len() or slices() have nothing to do here. My experience with go is equal to uero + epsilon. jmf From wxjmfauth at gmail.com Sun Aug 26 02:59:34 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Aug 2012 23:59:34 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: <4853fddf-5e4d-4c11-9a19-5a1dbe4cbc20@googlegroups.com> Le dimanche 26 ao?t 2012 00:26:56 UTC+2, Ian a ?crit?: > On Sat, Aug 25, 2012 at 9:47 AM, wrote: > > > For those you do not know, the go language has introduced > > > the rune type. As far as I know, nobody is complaining, I > > > have not even seen a discussion related to this subject. > > > > Python has that also. We call it "int". > > > > More seriously, strings in Go are not sequences of runes. They're > > actually arrays of UTF-8 bytes. That means that they're quite > > efficient for ASCII strings, at the expense of other characters, like > > Chinese (wait, this sounds familiar for some reason). It also means > > that you have to bend over backwards if you want to work with actual > > runes instead of bytes. Want to know how many characters are in your > > string? Don't call len() on it -- that will only tell you how many > > bytes are in it. Don't try to index or slice it either -- that will > > (accidentally) work for ASCII strings, but for other strings your > > indexes will be wrong. If you're unlucky you might even split up the > > string in the middle of a character, and now your string has invalid > > characters in it. The right way to do it looks something like this: > > > > len([]rune("???")) // get the length of the string in characters > > string([]rune("???")[0:2]) // get the substring containing the first > > two characters > > > > It reminds me of working in Python 2.X, except that instead of an > > actual unicode type you just have arrays of ints. Sorry, you do not get it. The rune is an alias for int32. A sequence of runes is a sequence of int32's. Go do not spend its time in using a machinery to work with, to differentiate, to keep in memory this sequence according to the *characers* composing this "array of code points". The message is even stronger. Use runes to work comfortably [*] with unicode: rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be better) [*] Beyond my skill and my kwowloge and if I understood correctly, this rune is even technically optimized to ensure it it always an int32. len() or slices() have nothing to do here. My experience with go is equal to uero + epsilon. jmf From amangill.coldfire at gmail.com Sun Aug 26 03:41:28 2012 From: amangill.coldfire at gmail.com (coldfire) Date: Sun, 26 Aug 2012 00:41:28 -0700 (PDT) Subject: VPS For Python Message-ID: I will really appreciate if someone type the address of any of the following for use with python 1>Webhost 2>Shell Account 3>VPS I am really new to all this Got web server and shell account but unable to figure out how to use it or deploy the Code, My problem is that I m using lot of third party Library which are mostly not supported or I don't know How to make it RUN over Internet From plr.vincent at gmail.com Sun Aug 26 03:43:15 2012 From: plr.vincent at gmail.com (Vincent Pelletier) Date: Sun, 26 Aug 2012 09:43:15 +0200 Subject: Segfault when setting an instance property on 2.7.3 In-Reply-To: <201208251138.47725.plr.vincent@gmail.com> References: <201208251138.47725.plr.vincent@gmail.com> Message-ID: <201208260943.16597.plr.vincent@gmail.com> Le samedi 25 ao?t 2012 11:38:47, Vincent Pelletier a ?crit : > Any idea of ways to debug this problem further ? Trying with pypy ("just to see"), I got even more reproductible segfaults - even with valgrind. Turns out, I was not keeping strong references to ctypes buffers, which get very quickly collected with pypy and memory reused for something else, leading to a quick crash. Now, I don't get yet why cpython was not crashing more often, even if I forced gc.collect() . Less memory recycling maybe ? Regards, -- Vincent Pelletier From hansmu at xs4all.nl Sun Aug 26 04:25:42 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 26 Aug 2012 10:25:42 +0200 Subject: Built-in open() with buffering > 1 In-Reply-To: References: Message-ID: <5039dd87$0$6851$e4fe514c@news2.news.xs4all.nl> On 24/08/12 06:35:27, Marco wrote: > Please, can anyone explain me the meaning of the > "buffering > 1" in the built-in open()? > The doc says: "...and an integer > 1 to indicate the size > of a fixed-size chunk buffer." > So I thought this size was the number of bytes or chars, but > it is not The algorithm is explained at http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE >> io.DEFAULT_BUFFER_SIZE >> >> An int containing the default buffer size used by the >> module?s buffered I/O classes. open() uses the file?s >> blksize (as obtained by os.stat()) if possible. In other words: open() tries to find a suitable size by calling os.stat(your_file).st_blksize and if that fails, it uses io.DEFAULT_BUFFER_SIZE, which is 8192 on my box. Whether you call open with buffering=2 or any larger number, does not matter: the buffer size will be the outcome of this algorithm. Hope this helps, -- HansM From hansmu at xs4all.nl Sun Aug 26 05:01:23 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 26 Aug 2012 11:01:23 +0200 Subject: help with simple print statement! In-Reply-To: References: Message-ID: <5039e5e3$0$6917$e4fe514c@news2.news.xs4all.nl> On 24/08/12 21:59:12, Prasad, Ramit wrote: > Also, print doesn't work inside a class. It works for me: > python3 Python 3.3.0a1 (v3.3.0a1:f1a9a6505731, Mar 4 2012, 12:26:12) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class spam(object): ... print("Hello there!") ... Hello there! >>> I'm not sure why you'd want to call the print function in a class definition, though. The print function is more usually called from within a method definition, not at the class level. What, exactly are you doing? Are you trying python2 syntax in a python3 interpreter, or vice versa? Can you copy a complete session and paste it into a follow-up message? -- HansM From hansmu at xs4all.nl Sun Aug 26 06:00:38 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 26 Aug 2012 12:00:38 +0200 Subject: Computing win/loss records in Python In-Reply-To: References: <0C181E0E-47FA-439C-8320-AC60AB8859AF@gmail.com> Message-ID: <5039f3c6$0$6900$e4fe514c@news2.news.xs4all.nl> On 26/08/12 04:42:59, Steven W. Orr wrote: > On 8/25/2012 10:20 PM, Christopher McComas wrote: >> Greetings, >> >> I have code that I run via Django that grabs the results from various >> sports from formatted text files. The script iterates over every line >> in the formatted text files, finds the team in the Postgres database >> updates their w/l record depending on the outcome on that line, saves >> the team's row in the db, and then moves on to the next line in the file. >> >> I'm trying to get away from Django for this project, I want to run the >> files, get the W/L results and output a formatted text file with the >> teams and their W/L records. What's confusing me I guess how to store >> the data/results as the wins and losses tally up. We're talking >> hundreds of teams, thousands of games, but a quick example would be: >> >> Marshall >> Ohio State >> Kentucky >> Indiana >> >> Marshall,24,Ohio State,48, >> Kentucky,14,Indiana,10, >> Marshall,10,Indiana,7, >> Ohio State,28,Kentucky,10 >> >> That's just a quick example, I can handle seperating the data in the >> lines, figuring it all out, I just am unsure of how to keep a running >> total of a team's record. I would do "for line in file:" then on the >> first line I see that Marshall lost so they would have 1, Ohio State >> won so they'd have 1 win. It'd go to the next line Kentucky 1 win, >> Indiana 1 loss, then on the 3rd line, Marshall got a win so they'd >> have 1 win, but it would have to remember that loss from line 1... >> >> Does this make sense? >> >> Thanks, > > win_count = defaultdict(int) > loss_count = defaultdict(int) > > items = line.split(',') > if items[1] > items[3]: > windex = 0 > lossdex = 2 > else: > windex = 2 > lossdex = 0 > win_count[windex] += 1 > loss_count[lossdex] += 1 I think you meant: win_count[items[windex]] += 1 loss_count[items[windex]] += 1 I think it would be more readable to do: from collections import defaultdict win_count = defaultdict(int) loss_count = defaultdict(int) items = line.split(',') if int(items[1]) > int(items[3]): winner = items[0] loser = items[2] else: winner = items[2] loser = items[0] win_count[winner] += 1 loss_count[loser] += 1 It looks like you're afraid of wasting RAM by needlessly copying strings. However, this fear is unfounded: Python doesn't copy strings, unless you tell it to do so explictly. An assignment like "winner = items[0]" doesn't copy the string; it merely creates a new reference to the existing string. Hope this helps, -- HansM From steve+comp.lang.python at pearwood.info Sun Aug 26 07:49:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 11:49:38 GMT Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> Message-ID: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Aug 2012 23:59:34 -0700, wxjmfauth wrote: > Le dimanche 26 ao?t 2012 00:26:56 UTC+2, Ian a ?crit?: >> More seriously, strings in Go are not sequences of runes. They're >> actually arrays of UTF-8 bytes. Actually, it's worse that that. Strings in Go aren't even proper UTF-8. They are arbitrary bytes, which means you can create strings which are invalid Unicode. Go looks like an interesting language, but it seems to me that they have totally screwed up strings. At least Python had the excuse that it is 20 years old and carrying the old ASCII baggage. Nobody used Unicode in 1992 when Python was invented. What is Google's excuse for getting Unicode wrong? In Go, strings are UTF-8 encoded sequences of bytes, except when they're not, in which case they're arbitrary bytes. You can't tell if a string is valid UTF-8 unless you carefully inspect every single character and decide for yourself if it is valid. Don't know the rules for valid UTF-8? Too bad. This also means that basic string operations like slicing are both *slow* and *wrong* -- they are slow, because you have to track character boundaries yourself. And they are wrong, because most people won't bother, they'll just assume each character is one byte. See here for more information: http://comments.gmane.org/gmane.comp.lang.go.general/56245 Some useful quotes: - "Strings are *not* required to be UTF-8." - "If the string must always be valid UTF-8 then relatively expensive validation is required for many operations. Plus making those operations able to fail complicates the interface." - "In almost all cases strings are just byte arrays." - "Go simply doesn't have 8-bit Unicode strings" - "Python3 can afford the luxury of storing strings in UCS-2/UCS-4, Go can't." I don't question that Go needs a type for arbitrary bytes. But that should be "bytes", not "string", and it should be there for the advanced programmers who *need* to worry about bytes. Programmers who want to include strings in their applications (i.e. all of them) shouldn't need to care that "$" is one byte, "?" is two, "?" is three, and "?" (U+24B62) is four. With Python 3.3, it *just works*. With Go, it doesn't. In my not-so-humble opinion, Go has made a silly design error. Go programmers will be paying for this mistake for at least a decade. What they should have done is create two data types: 1) Strings which are guaranteed to be valid Unicode. That could be UTF-32 or a PEP 393 approach, depending on how much memory you want to use, or even UTF-16 if you don't mind the complication of surrogate pairs. 2) Bytes which are not guaranteed to be valid Unicode but let the programmer work with arbitrary bytes. (If this sounds familiar, it should -- it is exactly what Python 3 does. We have a string type that guarantees to be valid Unicode, and a bytes type that doesn't.) As given, *every single programmer* who wants to use Unicode in Go is now responsible for doing all the hard work of validating UTF-8, converting from bytes to strings, etc. Sure, eventually Go will have libraries to do that, but not yet, and even when it does, many people will not use them and their code will fail to handle Unicode correctly. Right now, every Go programmer who wants Unicode has to pay the cost of the freedom to have arbitrary byte sequences, whether they need those arbitrary bytes or not. The consequence is that instead of Go making Unicode as trivial and easy to use as it should be, it will be hard to get right, annoying, slow and painful. Another generation of programmers will grow up thinking that Unicode is all too difficult and we should stick to just plain ASCII. Since Go doesn't have Unicode strings, you can never trust that a string is valid UTF-8, you can't slice it efficiently, you can't get the length in characters, you can't write it to a file and have other applications to be able to read it. Sure, sometimes it will work, and then somebody will input a Euro sign into your application, and it will blow up. Why am I not surprised that JMF misunderstands both Go byte-strings and Python Unicode strings? > Sorry, you do not get it. > > The rune is an alias for int32. A sequence of runes is a sequence of > int32's. It certainly is not. Runes are variable-width. Here, for example, are a number of Go functions which return a single rune and its width in bytes: http://golang.org/pkg/unicode/utf8/ > Go do not spend its time in using a machinery to work with, to > differentiate, to keep in memory this sequence according to the > *characers* composing this "array of code points". > > The message is even stronger. Use runes to work comfortably [*] with > unicode: > rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be better) Runes are not int32, and int32 is not UTF-32. Whether UTF-32 is the "perfect scheme" for Unicode is a matter of opinion. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 26 08:02:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 12:02:35 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> Message-ID: <503a105b$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Aug 2012 16:22:05 +1000, Chris Angelico wrote: > On Sun, Aug 26, 2012 at 3:45 PM, Evan Driscoll > wrote: >> Third, and more wackily, you could technically create a C >> implementation that works like Python, where it stores variables (whose >> addresses aren't taken) in a dict keyed by name, and generates code >> that on a variable access looks up the value by accessing that dict >> using the name of the variable. > > That would be a reasonable way to build a C interactive interpreter. No it wouldn't. Without fixed addresses, the language wouldn't be able to implement pointers. C without pointers isn't C, it is something else. Possibly called Python :) I suppose you could get pointers in Namespace-C if you somehow mapped names to addresses, and vice versa, but why would you do that? You end up with a hybrid system that doesn't give you any advantage over C but has a much more complicated implementation (and therefore many more new and exciting bugs). But if you want me to agree that you could implement C using name binding, plus some weird scheme to track memory addresses, then yes, I suppose you could. Then the parts of C that don't rely on fixed memory addresses could use the name bindings (with the corresponding loss of performance), and the parts of C which do require them could continue to do so, and we'll have one more language with a confusing, unclear and unclean execution model. Everybody wins! For some definition of win. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 26 08:04:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 12:04:26 GMT Subject: Looking for duplicate modules References: Message-ID: <503a10c9$0$6574$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Aug 2012 11:30:05 -0400, Roy Smith wrote: > I'm working on a tool which scans all the directories in sys.path and > finds any modules which appear multiple times in the path. It'll also > call out any .pyc's it finds without matching py's. This sounds like a useful tool. Please consider releasing it under an appropriate free software licence (e.g. GPL, MIT, or similar compatible licence). -- Steven From jonathan.kinred at gmail.com Sun Aug 26 08:45:25 2012 From: jonathan.kinred at gmail.com (jonathan.kinred at gmail.com) Date: Sun, 26 Aug 2012 05:45:25 -0700 (PDT) Subject: psphere: how to make thread safe In-Reply-To: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> References: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> Message-ID: On Wednesday, 22 August 2012 22:03:48 UTC+10, sajuptpm wrote: > Hi, > > > > psphere: Python interface for the VMware vSphere Web Services SDK > > > > I already developed an app using https://bitbucket.org/jkinred/psphere. But getting lot of errors since psphere is not thread safe (I think). So i wrote couple of scripts to test it (See attached files) and found that caching mechanism used by psphere is not thread safe. Could someone please give me some suggestion to make it thread safe. > > > > > > =======Test Code ======== > > > > import psphere > > from psphere.client import Client > > from psphere.managedobjects import HostSystem, VirtualMachine, ComputeResource > > client = Client("192.168.0.114", "root", "vmware1") ##vCenter > > print "\nSucessfully connected to vCenter.\n" > > > > from threading import Thread > > > > def myfunc(i): > > host1 = HostSystem.get(client, name="192.168.0.134") > > host2 = HostSystem.get(client, name="192.168.0.113") > > print "----i------",i > > while True: > > #host1.update(properties=["config", "vm"]) > > #host2.update(properties=["config", "vm"]) > > c = type(host1.config.network) > > v = type(host2.config.network) > > for vm in host1.vm: > > k = vm.config.template > > for vm in host2.vm: > > p = vm.config.template > > > > > > for i in range(10): > > t = Thread(target=myfunc, args=(i,)) > > t.start() > > > > > > """ > > OUTPUT > > ======= > > Sucessfully connected to vCenter. > > > > ----i------ 1 > > ----i------ 3 > > ----i------ 5 > > ----i------ 0 > > ----i------ 4 > > ----i------ 2----i------ 7 > > ----i------ > > 9 > > ----i------ 6 > > ----i------ 8 > > Exception in thread Thread-4: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/threading.py", line 504, in run > > self.__target(*self.__args, **self.__kwargs) > > File "vcenter_test1.py", line 19, in myfunc > > k = vm.config.template > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 79, in __get__ > > value = self.fget(inst) > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/managedobjects.py", line 1236, in config > > return self._get_dataobject("config", False) > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 116, in _get_dataobject > > return self._cache[name][0] > > KeyError: 'config' > > > > Exception in thread Thread-6: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/threading.py", line 504, in run > > self.__target(*self.__args, **self.__kwargs) > > File "vcenter_test1.py", line 17, in myfunc > > v = type(host2.config.network) > > AttributeError: VirtualMachineConfigInfo instance has no attribute 'network' > > > > > > > > """ I'm the author of psphere. I'd be really interested to get some experienced insight into this as I really don't know the first thing about thread safety. psphere does use a cache, but I'm confused as to how the cache would be thread unsafe as the cache is just a property of an object. What I'm suspecting (and this only came to me while writing this post) is that I have a "client" object which is passed into each object and used to retrieve data from the server. See this gist: https://gist.github.com/3478641 When used in a threaded scenario could the client be used by multiple objects simultaneously and the replies would come in out of order? A couple of years ago I started psphere to learn Python and I always hoped that I would have an experienced developer join me. I did learn Python but I never got that experienced developer so when it comes to issues like this I'm definitely out of my depth! Please if someone could spend the time with me I would really appreciate it! From news at blinne.net Sun Aug 26 08:53:28 2012 From: news at blinne.net (Alexander Blinne) Date: Sun, 26 Aug 2012 14:53:28 +0200 Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: <503a1c4a$0$6555$9b4e6d93@newsspool4.arcor-online.net> On 26.08.2012 01:31, Dennis Lee Bieber wrote: > The struct module relies upon the user knowing the format of the data. > If your problem is that you have some null-terminated string data in a > variable width field, you will have to locate the position of the null > FIRST, and specify the appropriate "count" for the s format. This gave me the idea of an Enhancement of the Struct class with an additional format character (perhaps 'n') which corresponds to a null-terminated string: ----- # -*- coding: utf-8 -*- import struct class Nstr(object): def __init__(self, ncount): self.ncount = ncount def unpack(self, s): s = s.split('\0') return s[:self.ncount], '\0'.join(s[self.ncount:]) def pack(self, *s): if len(s)!=self.ncount: raise ValueError for st in s: if '\0' in st: raise ValueError return '\0'.join(s)+'\0' def __repr__(self): return 'Nstr('+repr(self.ncount)+')' class NStruct(object): def __init__(self, format): self.format = format if format[0] in '!=<>@': self.endianness = format[0] format = format[1:] else: self.endianness = '' self.chunks = [] while len(format)>0: j = format.find('n') if j > -1: k = j-1 while format[k].isdigit(): k-=1 chunkformat, ncount, format = format[:k+1],\ format[k+1:j], format[j+1:] ncount = 1 if len(ncount)==0 else int(ncount) else: chunkformat, ncount, format = format, '', '' ncount = 0 stru = struct.Struct(self.endianness+chunkformat) l = len(stru.unpack("0"*stru.size)) self.chunks.append((stru, l)) if ncount > 0: self.chunks.append((Nstr(ncount), ncount)) def unpack(self, data): res = [] for sth, n in self.chunks: if isinstance(sth, struct.Struct): chunk, data = data[:sth.size], data[sth.size:] res.extend(sth.unpack(chunk)) elif isinstance(sth, Nstr): chunk, data = sth.unpack(data) res.extend(chunk) return res def pack(self, *data): res = [] for sth, n in self.chunks: chunk, data = data[:n], data[n:] res.append(sth.pack(*chunk)) return ''.join(res) def __repr__(self): return 'NStruct('+repr(self.format)+')' if __name__=="__main__": a = NStruct('h b 2n 2h') print repr(a) d = 'asdblah blah\0haha\0asdf' r = a.unpack(d) assert r == [29537, 100, 'blah blah', 'haha', 29537, 26212] print repr(d), repr(r) dd = a.pack(*r) print r, repr(dd) assert dd == d ----- beware of bugs in the above code, i haven't testet it much yet. Alex From jonathan.kinred at gmail.com Sun Aug 26 08:57:43 2012 From: jonathan.kinred at gmail.com (jonathan.kinred at gmail.com) Date: Sun, 26 Aug 2012 05:57:43 -0700 (PDT) Subject: psphere: how to make thread safe In-Reply-To: References: <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> Message-ID: <97692dc5-b8c1-4573-84e9-2bc76b4c188f@googlegroups.com> On Sunday, 26 August 2012 22:45:25 UTC+10, jonatha... at gmail.com wrote: > On Wednesday, 22 August 2012 22:03:48 UTC+10, sajuptpm wrote: > > > Hi, > > > > > > > > > > > > psphere: Python interface for the VMware vSphere Web Services SDK > > > > > > > > > > > > I already developed an app using https://bitbucket.org/jkinred/psphere. But getting lot of errors since psphere is not thread safe (I think). So i wrote couple of scripts to test it (See attached files) and found that caching mechanism used by psphere is not thread safe. Could someone please give me some suggestion to make it thread safe. > > > > > > > > > > > > > > > > > > =======Test Code ======== > > > > > > > > > > > > import psphere > > > > > > from psphere.client import Client > > > > > > from psphere.managedobjects import HostSystem, VirtualMachine, ComputeResource > > > > > > client = Client("192.168.0.114", "root", "vmware1") ##vCenter > > > > > > print "\nSucessfully connected to vCenter.\n" > > > > > > > > > > > > from threading import Thread > > > > > > > > > > > > def myfunc(i): > > > > > > host1 = HostSystem.get(client, name="192.168.0.134") > > > > > > host2 = HostSystem.get(client, name="192.168.0.113") > > > > > > print "----i------",i > > > > > > while True: > > > > > > #host1.update(properties=["config", "vm"]) > > > > > > #host2.update(properties=["config", "vm"]) > > > > > > c = type(host1.config.network) > > > > > > v = type(host2.config.network) > > > > > > for vm in host1.vm: > > > > > > k = vm.config.template > > > > > > for vm in host2.vm: > > > > > > p = vm.config.template > > > > > > > > > > > > > > > > > > for i in range(10): > > > > > > t = Thread(target=myfunc, args=(i,)) > > > > > > t.start() > > > > > > > > > > > > > > > > > > """ > > > > > > OUTPUT > > > > > > ======= > > > > > > Sucessfully connected to vCenter. > > > > > > > > > > > > ----i------ 1 > > > > > > ----i------ 3 > > > > > > ----i------ 5 > > > > > > ----i------ 0 > > > > > > ----i------ 4 > > > > > > ----i------ 2----i------ 7 > > > > > > ----i------ > > > > > > 9 > > > > > > ----i------ 6 > > > > > > ----i------ 8 > > > > > > Exception in thread Thread-4: > > > > > > Traceback (most recent call last): > > > > > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > > > > > self.run() > > > > > > File "/usr/lib/python2.7/threading.py", line 504, in run > > > > > > self.__target(*self.__args, **self.__kwargs) > > > > > > File "vcenter_test1.py", line 19, in myfunc > > > > > > k = vm.config.template > > > > > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 79, in __get__ > > > > > > value = self.fget(inst) > > > > > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/managedobjects.py", line 1236, in config > > > > > > return self._get_dataobject("config", False) > > > > > > File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 116, in _get_dataobject > > > > > > return self._cache[name][0] > > > > > > KeyError: 'config' > > > > > > > > > > > > Exception in thread Thread-6: > > > > > > Traceback (most recent call last): > > > > > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > > > > > self.run() > > > > > > File "/usr/lib/python2.7/threading.py", line 504, in run > > > > > > self.__target(*self.__args, **self.__kwargs) > > > > > > File "vcenter_test1.py", line 17, in myfunc > > > > > > v = type(host2.config.network) > > > > > > AttributeError: VirtualMachineConfigInfo instance has no attribute 'network' > > > > > > > > > > > > > > > > > > > > > > > > """ > > > > I'm the author of psphere. I'd be really interested to get some experienced insight into this as I really don't know the first thing about thread safety. > > > > psphere does use a cache, but I'm confused as to how the cache would be thread unsafe as the cache is just a property of an object. > > > > What I'm suspecting (and this only came to me while writing this post) is that I have a "client" object which is passed into each object and used to retrieve data from the server. See this gist: > > https://gist.github.com/3478641 > > > > When used in a threaded scenario could the client be used by multiple objects simultaneously and the replies would come in out of order? > > > > A couple of years ago I started psphere to learn Python and I always hoped that I would have an experienced developer join me. I did learn Python but I never got that experienced developer so when it comes to issues like this I'm definitely out of my depth! Please if someone could spend the time with me I would really appreciate it! Just to clarify, the real Client is here: https://github.com/jkinred/psphere/blob/master/psphere/client.py#L45 From rosuav at gmail.com Sun Aug 26 09:34:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Aug 2012 23:34:57 +1000 Subject: Objects in Python In-Reply-To: <503a105b$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> <503a105b$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 10:02 PM, Steven D'Aprano wrote: > On Sun, 26 Aug 2012 16:22:05 +1000, Chris Angelico wrote: > >> On Sun, Aug 26, 2012 at 3:45 PM, Evan Driscoll >> wrote: >>> Third, and more wackily, you could technically create a C >>> implementation that works like Python, where it stores variables (whose >>> addresses aren't taken) in a dict keyed by name, and generates code >>> that on a variable access looks up the value by accessing that dict >>> using the name of the variable. >> >> That would be a reasonable way to build a C interactive interpreter. > > No it wouldn't. Without fixed addresses, the language wouldn't be able to > implement pointers. C without pointers isn't C, it is something else. > Possibly called Python :) The insertion of a single rule will do it. Let it stand that &x is the string "x" and there you are, out of your difficulty at once! Okay, that may be a bit of a fairy tale ending and completely illogical. ChrisA From roy at panix.com Sun Aug 26 09:41:07 2012 From: roy at panix.com (Roy Smith) Date: Sun, 26 Aug 2012 09:41:07 -0400 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> Message-ID: In article , Chris Angelico wrote: > On Sun, Aug 26, 2012 at 3:45 PM, Evan Driscoll wrote: > > Third, and more wackily, you could technically create a C implementation > > that works like Python, where it stores variables (whose addresses aren't > > taken) in a dict keyed by name, and generates code that on a variable access > > looks up the value by accessing that dict using the name of the variable. > > That would be a reasonable way to build a C interactive interpreter. Except that lots of C and C++ programs assume they know how data structures are laid out and can index forward and backward over them in ways which the language does not promise work (but are, none the less, useful). Say, the sort of thinks you might use python's struct module for. On the other hand, there is certainly a big subset of C that you could implement that way. But it would only be useful as a simple instructional tool. From steve+comp.lang.python at pearwood.info Sun Aug 26 09:43:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 13:43:33 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Aug 2012 00:45:55 -0500, Evan Driscoll wrote: > On 08/24/2012 05:00 AM, Steven D'Aprano wrote: >> No. The compiler remembers the address of 'a' by keeping notes about it >> somewhere in memory during the compilation process. When you run the >> compiled program, there is no longer any reference to the name 'a'. >> >> ... >> >> The mapping of name:address is part of the *compilation* process -- the >> compiler knows that variable 'x' corresponds to location 12345678, but >> the compiled code has no concept of anything called 'x'. It only knows >> about locations. The source code 'x = 42' is compiled into something >> like 'store 42 into location 12345678'. (Locations may be absolute or >> relative.) >> >> In languages with name bindings, the compiler doesn't need to track >> name:address pairs. The compiled application knows about names, but not >> about addresses. The source code 'x = 42' is compiled into something >> like 'store 42 into the namespace using key "x"'. > > What you describe is sorta correct, but it's also not... you're > describing implementations rather than the language. And while the > language semantics certainly impose restrictions on the implementation, I accept that languages may choose to leave the variable-model unspecified. I don't think they can define behaviour without implying one model or the other. Or at least not easily - far too much language behaviour is tied to the implementation to let us say "it's only implementation". For example, the reason that locals() is not writable inside Python functions is because CPython moves away from the name binding model inside functions as an optimization. This function prints 1 under both CPython and Jython (but not IronPython): def spam(): x = 1 locals()['x'] = 2 print(x) Binding to the local namespace does not work, because functions don't *actually* use a namespace, they use something closer to the C model. So the two models are not interchangable and hence they aren't *just* implementation details, they actually do affect the semantics of the language. I suppose you could arrange for locals() to return a proxy dictionary which knew about the locations of variables. But what happens if you returned that proxy to the caller, which then assigned to it later after the function variables no longer existed? Similarly, there are operations which are no longer allowed simply because of the difference between name binding and locational variables: py> def ham(): ... from math import * ... File "", line 1 SyntaxError: import * only allowed at module level (In some older versions of Python, wildcard imports are allowed, and the function then falls back on a namespace instead of fixed locations. That is no longer the case in Python 3.2 at least.) > I think in this case the situation is closer than you acknowledge: > > From the Python side, I suspect that for most functions, you'd be able > to create a Python implementation that behaves more like C, and > allocates locals in a more traditional fashion. As I discuss above, CPython and Jython actually do something like that inside functions. And there are observable differences in behaviour (not just performance) between function scope and global scope. So an implementation of Python which used fixed memory addresses everywhere, not just in functions, would be detectably different in behaviour than CPython. Whether those differences would be enough to disqualify it from being called "Python" is a matter of opinion. (Probably Guido's opinion is the only one that matters.) [...] > On the C side, imagine a function with locals x, y, and z which never > takes the address of any of them. (You said later that "Just because the > public interface of the language doesn't give you any way to view the > fixed locations of variables, doesn't mean that variables cease to have > fixed locations.") > > First, C variables may not even have a memory address. They can > disappear completely during compilation, or live in a register for their > entire life. Variables that don't exist at runtime don't have an address at all -- in a way, they aren't even a variable any more. They have a name in the source code, but that's all. As for registers, they are memory addresses, of a sort. (I didn't mean to imply that they must live in main motherboard memory.) I call any of these an address: - in the heap at address 12345678 - in the GPU's video memory at address 45678 - 12th entry from the top of the stack - register 4 > Second, it's possible that those variables *don't* occupy a fixed > location. If you never explicitly take an address of a variable (&x), > then I can't think of any way that the address can be observed without > invoking undefined behavior -- and this means the C compiler is free to > transform it to anything that is equivalent under the C semantics. I may have been too emphatic about the "fixed" part. A sufficiently clever compiler may implement its own memory manager (on top of the operating system's memory manager?) and relocate variables during their lifetime. But for my purposes, the important factor is that the compiler knows the address at every moment, even if that address changes from time to time. In contrast, a name binding system *doesn't* know the address of a variable. The analogy I like is making a delivery to a hotel room. C-like languages say: "Deliver this package to room 1234." Pointer semantics are like: "Go to room 1234 and collect an envelope; deliver this package to the room number inside the envelope." On the other hand, name binding languages say: "Go to the concierge at the front desk and ask for Mr Smith's room, wait until he looks it up in the register, then deliver this package to the room number he tells you." Typically, you don't even have any way to store the room number for later use. In Python, name lookups involve calculating a hash and searching a dict. Once you've looked up a name once, there is no way to access the hash table index to bypass that process for future lookups. It gets worse: Python has multiple namespaces that are searched. "Go to the Excelsior Hotel and ask the concierge for Mr Smith. If Mr Smith isn't staying there, go across the road to the Windsor Hotel and ask there. If he's not there, try the Waldorf Astoria, and if he's not there, try the Hyperion." Considering just how much work Python has to do to simply access a named variable, it's amazing how slow it isn't. -- Steven From rosuav at gmail.com Sun Aug 26 09:58:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Aug 2012 23:58:31 +1000 Subject: Objects in Python In-Reply-To: <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 11:43 PM, Steven D'Aprano wrote: > It gets worse: Python has multiple namespaces that are searched. > > "Go to the Excelsior Hotel and ask the concierge for Mr Smith. If Mr > Smith isn't staying there, go across the road to the Windsor Hotel and > ask there. If he's not there, try the Waldorf Astoria, and if he's not > there, try the Hyperion." Does it? I thought the difference between function-scope and module-scope was compiled in, and everything else boils down to one of those. Explicit dot notation is different ("ask for Mr Smith, then ask him where his packages box is, and put this in the box"). Hmm, okay, there's something slightly different with closures. But it's still unambiguous at compile time. >>> x=1 >>> def foo(y): return lambda z: x+y+z >>> foo(2)(3) 6 >>> import dis >>> dis.dis(foo(2)) 2 0 LOAD_GLOBAL 0 (x) 3 LOAD_DEREF 0 (y) 6 BINARY_ADD 7 LOAD_FAST 0 (z) 10 BINARY_ADD 11 RETURN_VALUE What multiple namespaces are you talking about, where things have to get looked up at run time? ChrisA From roy at panix.com Sun Aug 26 10:02:36 2012 From: roy at panix.com (Roy Smith) Date: Sun, 26 Aug 2012 10:02:36 -0400 Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <503a2804$0$6574$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >>> The mapping of name:address is part of the *compilation* process -- >>> the compiler knows that variable 'x' corresponds to location >>> 12345678 Just to pick a nit, the compiler probably doesn't know that, but the linker does (or maybe even the run-time loader). However, we can think of all of those as just part of the compilation tool chain, and then we're good. From breamoreboy at yahoo.co.uk Sun Aug 26 10:02:43 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Aug 2012 15:02:43 +0100 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> <503a105b$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26/08/2012 14:34, Chris Angelico wrote: > > Okay, that may be a bit of a fairy tale ending and completely illogical. > > ChrisA > Then stick to the thread about flexible string representation, unicode and typography :) -- Cheers. Mark Lawrence. From rosuav at gmail.com Sun Aug 26 10:05:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Aug 2012 00:05:47 +1000 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <5039B813.8020603@cs.wisc.edu> <503a105b$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 27, 2012 at 12:02 AM, Mark Lawrence wrote: > On 26/08/2012 14:34, Chris Angelico wrote: >> >> Okay, that may be a bit of a fairy tale ending and completely illogical. >> >> ChrisA > > Then stick to the thread about flexible string representation, unicode and > typography :) Hehe. Probably nobody on this list will recognize what I said, but it's a near-quote from "Iolanthe", an opera about fairies. It's the great denoumont, the solution to everyone's problems. And in the same way, redefining the "take-address-of" operator could be a perfect solution... and, just like in Iolanthe, is a rather fundamental change, and one that would break a lot of things. ChrisA From rosuav at gmail.com Sun Aug 26 10:14:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Aug 2012 00:14:11 +1000 Subject: Objects in Python In-Reply-To: References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 27, 2012 at 12:02 AM, Roy Smith wrote: > In article <503a2804$0$6574$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >>>> The mapping of name:address is part of the *compilation* process -- >>>> the compiler knows that variable 'x' corresponds to location >>>> 12345678 > > Just to pick a nit, the compiler probably doesn't know that, but the > linker does (or maybe even the run-time loader). However, we can think > of all of those as just part of the compilation tool chain, and then > we're good. Hrm. Back when I first started C programming, it was MS-DOS 16-bit work - segmented addressing (one of the most fascinating insanities ever to be perpetrated on unsuspecting consumers - why, oh why, if you want 20-bit addressing, should you invent a system that uses 32 bits of data in such a non-expandable way?). My program would be loaded into whatever segment the loader chose, but offsets within that could be compiled in. With modern x86 systems there are several more layers of complication, but in many cases, you can still hard-code offsets within a logical segment of memory. Set CS to your one code segment and do your jumps and calls at fixed locations. Set [DEFG]S to your single data segment and all your data can be at fixed locations too. (Obviously your stack is referenced relative to SP/BP.) I'm not familiar with other architectures, but it seems likely that there's something similar. The segment / base location may change, but variable 'x' still corresponds to 12345678 within that. Nits can be fun to pick :) ChrisA From steve+comp.lang.python at pearwood.info Sun Aug 26 10:18:58 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 14:18:58 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503a3051$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Aug 2012 23:58:31 +1000, Chris Angelico wrote: > On Sun, Aug 26, 2012 at 11:43 PM, Steven D'Aprano > wrote: >> It gets worse: Python has multiple namespaces that are searched. >> >> "Go to the Excelsior Hotel and ask the concierge for Mr Smith. If Mr >> Smith isn't staying there, go across the road to the Windsor Hotel and >> ask there. If he's not there, try the Waldorf Astoria, and if he's not >> there, try the Hyperion." > > Does it? I thought the difference between function-scope and > module-scope was compiled in, It is. But local and global scope are not the only two scopes. Python has nested scopes. Try these: x = y = -99 def test(): def inner(): x = 23 def even_more_inner(): print "x is", x print "y is", y even_more_inner() x = 1000 y = 42 inner() Also, built-ins require a name lookup too. As you point out, locals are special, but Python will search an arbitrarily deep set of nested nonlocal scopes, then globals, then builtins. See the introduction of nested-scopes: http://www.python.org/dev/peps/pep-0227/ and non-locals: http://www.python.org/dev/peps/pep-3104/ -- Steven From rosuav at gmail.com Sun Aug 26 10:54:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Aug 2012 00:54:05 +1000 Subject: Objects in Python In-Reply-To: <503a3051$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a3051$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Aug 27, 2012 at 12:18 AM, Steven D'Aprano wrote: > Also, built-ins require a name lookup too. As you point out, locals are > special, but Python will search an arbitrarily deep set of nested > nonlocal scopes, then globals, then builtins. Ah, builtins, forgot that. So yes, global scope involves potentially two name lookups. But nonlocals aren't searched at run time. ChrisA From kwpolska at gmail.com Sun Aug 26 11:06:44 2012 From: kwpolska at gmail.com (Kwpolska) Date: Sun, 26 Aug 2012 17:06:44 +0200 Subject: argparse localization support Message-ID: I am using argparse in my project. I want to localize it, but it seems to be impossible to change some things. See this, for example: usage: trash [-h] [-V] [-e] [-l] [-r] [-v] [-w] [PLIK [PLIK ...]] Trashman ? mened?er ?mietnika XDG w Pythonie. positional arguments: PLIK pliki do wyrzucenia optional arguments: -h, --help show this help message and exit -V, --version show program's version number and exit (a snippet of help for Trashman, a Python trash manager, with LANG='pl_PL.UTF-8'; https://github.com/Kwpolska/trashman ) Anyways, you can see that -h and -V (added semi-automatically by argparse),??usage:? and ?positional/optional arguments:? are still in English. It doesn?t look very professional. Also, I want to use fancy UTF-8 characters. Is there a way to fix that? -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From python at bdurham.com Sun Aug 26 11:22:09 2012 From: python at bdurham.com (python at bdurham.com) Date: Sun, 26 Aug 2012 11:22:09 -0400 Subject: VPS For Python In-Reply-To: References: Message-ID: <1345994529.7053.140661119747445.337DC32B@webmail.messagingengine.com> > I will really appreciate if someone type the address of any of the following for use with python > 1>Webhost > 2>Shell Account > 3>VPS Check out webfaction.com - they provide great support for Python. Malcolm From ian.g.kelly at gmail.com Sun Aug 26 11:40:13 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Aug 2012 09:40:13 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 5:49 AM, Steven D'Aprano wrote: >> Sorry, you do not get it. >> >> The rune is an alias for int32. A sequence of runes is a sequence of >> int32's. > > It certainly is not. Runes are variable-width. Here, for example, are a > number of Go functions which return a single rune and its width in bytes: > > http://golang.org/pkg/unicode/utf8/ I think the documentation for those functions is simply badly worded. The "width in bytes" it returns is not the width of the rune (which as jmf notes is simply an alias for int32 that stores a single code point). It means the UTF-8 width of the character, i.e. the number of UTF-8 bytes the function "consumed", presumably so that the caller can then reslice the data with that many bytes fewer. From ian.g.kelly at gmail.com Sun Aug 26 11:50:41 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Aug 2012 09:50:41 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <4853fddf-5e4d-4c11-9a19-5a1dbe4cbc20@googlegroups.com> References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <4853fddf-5e4d-4c11-9a19-5a1dbe4cbc20@googlegroups.com> Message-ID: On Sun, Aug 26, 2012 at 12:59 AM, wrote: > Sorry, you do not get it. > > The rune is an alias for int32. A sequence of runes is a > sequence of int32's. Go do not spend its time in using a > machinery to work with, to differentiate, to keep in memory > this sequence according to the *characers* composing this > "array of code points". > > The message is even stronger. Use runes to work comfortably [*] > with unicode: > rune -> int32 -> utf32 -> unicode (the perfect scheme, cann't be > better) I understand what rune is. I think you've missed my complaint, which is that although rune is the basic building block of Unicode strings -- representing a single Unicode character -- strings in Go are not built from runes but from bytes. If you want to do any actual work with Unicode strings, then you have to first convert them to runes or arrays of runes. The conceptual cost of this is that the object you're working with is no longer a string. You call this the "perfect scheme" for working with Unicode. Why does the "perfect scheme" for Unicode make it *easier* to write buggy code that only works for ASCII than to write correct code that works for all characters? This is IMO where Python 3 gets it right. When you want to work with Unicode strings, you just work with Unicode strings -- none of this nonsense of first explicitly converting the string to an array of ints that looks nothing like a string at a high level. The only place Python 3 makes you worry about converting strings is at the boundaries of your program, where decoding from bytes to strings and back is necessary. From tyler at tysdomain.com Sun Aug 26 12:34:28 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 26 Aug 2012 10:34:28 -0600 Subject: VPS For Python In-Reply-To: References: Message-ID: <503A5014.5000905@tysdomain.com> On 8/26/2012 1:41 AM, coldfire wrote: > I will really appreciate if someone type the address of any of the following for use with python > 1>Webhost > 2>Shell Account > 3>VPS I love Linode, it's amazing and you get decent resources for a decent price. If you sign up, I'd really appreciate it if you used my code. They also have a realloygood library at linode.com/library to show you how to set a lot of stuff up. http://www.linode.com/?r=7858d151c1ea11c0ce9a1398865b1cc7ad28c19f > I am really new to all this Got web server and shell account but unable to figure out how to use it or deploy the Code, > My problem is that I m using lot of third party Library which are mostly not supported or I don't know How to make it RUN over Internet -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tyler at tysdomain.com Sun Aug 26 12:38:09 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 26 Aug 2012 10:38:09 -0600 Subject: modeling complex data with sqlalchemy In-Reply-To: <35oi38lk2am7dd9d3emrkso79uq7ugfeb0@invalid.netcom.com> References: <503939E7.8080506@tysdomain.com> <35oi38lk2am7dd9d3emrkso79uq7ugfeb0@invalid.netcom.com> Message-ID: <503A50F1.3070106@tysdomain.com> Hello: Thanks for the info. IT doesn't really model the data I wanted. The contents was easy enough, I'm just going to set up a 1:n relationship on the Entity to the actual player. But for components, it's a bit different. Each component inherits the actual Component class, and has a number of attributes on it. I can't just put it in it's own. So I was going to set up a table per component and then just store an id and another id for what holds it. But my problem is modeling it. I also need the inherited data from Component. Would there be a way to do this? I could have: id, name, component_id and then SA could use the name as the table's name, and the id as the id of the component in the other table. How would I set this up with SA? Is it a good idea to go this route? On 8/25/2012 5:53 PM, Dennis Lee Bieber wrote: > On Sat, 25 Aug 2012 14:47:35 -0600, "Littlefield, Tyler" > declaimed the following in > gmane.comp.python.general: > >> Hello all: >> I had a quick question. >> In my game, I have an is-a setup, where all objects contain data like an >> id for sqlalchemy, a name, a description and a list of contents. > Well, a "list of contents" comes down to a table of items with a > foreign key to the item "containing" them... > > create table objects > ( > ID integer auto-increment primary key, > name varchar(?), > description varchar(?) > ) > > 1, Wulfraed, something or other > 2, Bag of Holding, whatever > 3, Sword, some cutting comments > 4, Treasure Chest, everyone wants one > > create table holdings > ( > ID integer auto-increment primary key, > holder integer foreign key objects(ID), > holding integer foreign key objects(ID) > ) > > 1, 1, 2 > 2, 1, 3 > 3, 2, 4 > >> In order to add functionality to an object, you add components. So for >> example, a player would have the Player and Living component associated > create table attribute_types > ( > ID integer auto-increment primary key, > name varchar(?), > type char(?), #or an enumeration if supported by the RDBM > #and SQLAlchemy > ) > > 1, Player, Boolean > 2, Living, Boolean > 3, EdgeWeapon, Boolean > 4, Damage, DieRoll > 5, ContainerSize, Integer > 6, Class, Text > > create table attributes > ( > ID integer auto-increment primary key, > describes integer foreign key objects(ID), > attribute integer foreign key attribute_types(ID), > value BLOB(?) > ) > > 1, 1, 1, blob(True) > 2, 1, 2, blob(True) > 3, 3, 3, blob(True) > 4, 3, 4, blob("1D8 + 4") > 5, 2, 5, blob(-1) #-1 being unlimited, bag of holding > 6, 4, 5, blob(6) #treasure chest holds 6 units of objects > 7, 1, 6, blob("Ranger") > > > Now, you could add another layer of indirection -- a table of > pre-defined object /types/ (different types of containers, swords, other > weapons), and have each instance (the ones shown in "objects") refer to > the object type table, and the object type table is what the object > attributes refers to. > > -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From __peter__ at web.de Sun Aug 26 13:21:54 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Aug 2012 19:21:54 +0200 Subject: argparse localization support References: Message-ID: Kwpolska wrote: > I am using argparse in my project. I want to localize it, but it > seems to be impossible to change some things. See this, for example: > > usage: trash [-h] [-V] [-e] [-l] [-r] [-v] [-w] [PLIK [PLIK ...]] > > Trashman ? mened?er ?mietnika XDG w Pythonie. > > positional arguments: > PLIK pliki do wyrzucenia > > optional arguments: > -h, --help show this help message and exit > -V, --version show program's version number and exit > > (a snippet of help for Trashman, a Python trash manager, with > LANG='pl_PL.UTF-8'; https://github.com/Kwpolska/trashman ) > > Anyways, you can see that -h and -V (added semi-automatically by > argparse), ?usage:? and ?positional/optional arguments:? are still in > English. It doesn?t look very professional. Also, I want to use > fancy UTF-8 characters. Is there a way to fix that? I don't know much about gettext, but the following suggests that most strings in argparse are properly wrapped: $ cat localize_argparse.py import gettext def my_gettext(s): return s.upper() gettext.gettext = my_gettext import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-V", action="version") args = parser.parse_args() $ python localize_argparse.py -h USAGE: localize_argparse.py [-h] [-V] OPTIONAL ARGUMENTS: -h, --help SHOW THIS HELP MESSAGE AND EXIT -V show program's version number and exit The workaround for the "-V" option would be to add the help message explicitly parser.add_argument("-V", ..., help=_("show...")) You still have to provide all translations yourself. From laddosingh at gmail.com Sun Aug 26 13:36:03 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Sun, 26 Aug 2012 10:36:03 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: Thanks Rob, I'v modified the test_3 like this: def test_3(self): f = open("test.dat", "wb") filesize = (b'b'*1000000) f.write(filesize) f.close() statinfo = os.stat("test.dat") self.assertEqual(statinfo.st_size, filesize) I'm still getting AssertionError and the error says: 1000000 !=b' Help appreciated. T kl. 21:04:54 UTC+2 fredag 24. august 2012 skrev Robert Day f?lgende: > On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote: > > > > > def test_3(self): > > > f = open("test.dat", "wb") > > > filesize = b"0"*1000000 > > > f.write(filesize) > > > f.close() > > > self.assertEqual(os.stat, filesize) > > > > > The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions? > > > > > > > rob at rivertam:~$ python > > Python 2.7.3 (default, Jul 24 2012, 10:05:38) > > [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import os > > >>> os.stat > > > > >>> > > > > So that's what 'os.stat' is. Why are you testing whether that's equal to > > b"0"*1000000? > > > > (You may find the documentation on os.stat at > > http://docs.python.org/library/os.html#os.stat helpful; it's a function > > which takes a path as its argument, and returns an object with some > > relevant attributes.) From laddosingh at gmail.com Sun Aug 26 13:36:03 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Sun, 26 Aug 2012 10:36:03 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: Thanks Rob, I'v modified the test_3 like this: def test_3(self): f = open("test.dat", "wb") filesize = (b'b'*1000000) f.write(filesize) f.close() statinfo = os.stat("test.dat") self.assertEqual(statinfo.st_size, filesize) I'm still getting AssertionError and the error says: 1000000 !=b' Help appreciated. T kl. 21:04:54 UTC+2 fredag 24. august 2012 skrev Robert Day f?lgende: > On Fri, 2012-08-24 at 09:20 -0700, Tigerstyle wrote: > > > > > def test_3(self): > > > f = open("test.dat", "wb") > > > filesize = b"0"*1000000 > > > f.write(filesize) > > > f.close() > > > self.assertEqual(os.stat, filesize) > > > > > The test_3 is to test if the created binary file har the size of 1 million bytes. Somehow it is not working. Any suggestions? > > > > > > > rob at rivertam:~$ python > > Python 2.7.3 (default, Jul 24 2012, 10:05:38) > > [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import os > > >>> os.stat > > > > >>> > > > > So that's what 'os.stat' is. Why are you testing whether that's equal to > > b"0"*1000000? > > > > (You may find the documentation on os.stat at > > http://docs.python.org/library/os.html#os.stat helpful; it's a function > > which takes a path as its argument, and returns an object with some > > relevant attributes.) From rkd at rkd.me.uk Sun Aug 26 13:51:54 2012 From: rkd at rkd.me.uk (Rob Day) Date: Sun, 26 Aug 2012 18:51:54 +0100 Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: <1346003514.5642.5.camel@rivertam> On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > self.assertEqual(statinfo.st_size, filesize) > > I'm still getting AssertionError and the error says: 1000000 !=b' > > filesize is the character 'b' repeated one million times (the contents of the file, in other words). statinfo.st_size is the number of bytes in the file, i.e. 1,000,000. So when your assertEqual code checks if those two values are equal, what do you think happens? From laddosingh at gmail.com Sun Aug 26 14:37:01 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Sun, 26 Aug 2012 11:37:01 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: Ahhhhhh, thank you very much Rob. Fixed now. Have a great day. T kl. 19:51:54 UTC+2 s?ndag 26. august 2012 skrev Rob Day f?lgende: > On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > > > self.assertEqual(statinfo.st_size, filesize) > > > > > > I'm still getting AssertionError and the error says: 1000000 !=b' > > > > > > > > > > filesize is the character 'b' repeated one million times (the contents > > of the file, in other words). statinfo.st_size is the number of bytes in > > the file, i.e. 1,000,000. So when your assertEqual code checks if those > > two values are equal, what do you think happens? From laddosingh at gmail.com Sun Aug 26 14:37:01 2012 From: laddosingh at gmail.com (Tigerstyle) Date: Sun, 26 Aug 2012 11:37:01 -0700 (PDT) Subject: Unittest - testing for filenames and filesize In-Reply-To: References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> <8447c547-8472-48c6-ad78-87989c1ce288@googlegroups.com> Message-ID: Ahhhhhh, thank you very much Rob. Fixed now. Have a great day. T kl. 19:51:54 UTC+2 s?ndag 26. august 2012 skrev Rob Day f?lgende: > On Sun, 2012-08-26 at 10:36 -0700, Tigerstyle wrote: > > > self.assertEqual(statinfo.st_size, filesize) > > > > > > I'm still getting AssertionError and the error says: 1000000 !=b' > > > > > > > > > > filesize is the character 'b' repeated one million times (the contents > > of the file, in other words). statinfo.st_size is the number of bytes in > > the file, i.e. 1,000,000. So when your assertEqual code checks if those > > two values are equal, what do you think happens? From nicholas.cole at gmail.com Sun Aug 26 14:47:34 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 26 Aug 2012 19:47:34 +0100 Subject: sys.path in python3.3 Message-ID: Dear List, In all previous versions of python, I've been able to install packages into the path: ~/Library/Python/$py_version_short/site-packages but in the rc builds of python 3.3 this is no longer part of sys.path. Before I go hacking the install, is there a reason that this path was removed? Is there a recommended way to get it back, or is this a gentle way of pushing us all to use virtualenv rather than installing user-specific packages? Best wishes, Nicholas From nad at acm.org Sun Aug 26 15:21:15 2012 From: nad at acm.org (Ned Deily) Date: Sun, 26 Aug 2012 12:21:15 -0700 Subject: sys.path in python3.3 References: Message-ID: In article , Nicholas Cole wrote: > In all previous versions of python, I've been able to install packages > into the path: > > ~/Library/Python/$py_version_short/site-packages > > but in the rc builds of python 3.3 this is no longer part of sys.path. > > Before I go hacking the install, is there a reason that this path was > removed? Is there a recommended way to get it back, or is this a > gentle way of pushing us all to use virtualenv rather than installing > user-specific packages? It should be working if you are using an OS X framework build. What is the value of sys.path? -- Ned Deily, nad at acm.org From hansmu at xs4all.nl Sun Aug 26 15:49:10 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sun, 26 Aug 2012 21:49:10 +0200 Subject: sys.path in python3.3 In-Reply-To: References: Message-ID: <503a7db7$0$6864$e4fe514c@news2.news.xs4all.nl> On 26/08/12 21:21:15, Ned Deily wrote: > In article > , > Nicholas Cole wrote: >> In all previous versions of python, I've been able to install packages >> into the path: >> >> ~/Library/Python/$py_version_short/site-packages >> >> but in the rc builds of python 3.3 this is no longer part of sys.path. >> >> Before I go hacking the install, is there a reason that this path was >> removed? Is there a recommended way to get it back, or is this a >> gentle way of pushing us all to use virtualenv rather than installing >> user-specific packages? > > It should be working if you are using an OS X framework build. What is > the value of sys.path? Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 09:42:40) [GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> for d in sys.path: ... print(d) ... /Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3 /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages This is using the Python 3.3 for MacOS binary from python.org. -- HansM From nicholas.cole at gmail.com Sun Aug 26 15:57:53 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 26 Aug 2012 20:57:53 +0100 Subject: sys.path in python3.3 In-Reply-To: References: Message-ID: On Sun, Aug 26, 2012 at 8:21 PM, Ned Deily wrote: > In article > , > Nicholas Cole wrote: >> In all previous versions of python, I've been able to install packages >> into the path: >> >> ~/Library/Python/$py_version_short/site-packages >> >> but in the rc builds of python 3.3 this is no longer part of sys.path. >> >> Before I go hacking the install, is there a reason that this path was >> removed? Is there a recommended way to get it back, or is this a >> gentle way of pushing us all to use virtualenv rather than installing >> user-specific packages? > > It should be working if you are using an OS X framework build. What is > the value of sys.path? I'm using the compiled version supplied by python.org. Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 10:09:29) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages'] >>> This contrasts with (for python3.1) Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python31.zip', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages', '/Users/nicholas/Library/Python/3.1/site-packages'] Best wishes, Nicholas From steve+comp.lang.python at pearwood.info Sun Aug 26 16:13:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 20:13:21 GMT Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: > I think the documentation for those functions is simply badly worded. > The "width in bytes" it returns is not the width of the rune (which as > jmf notes is simply an alias for int32 that stores a single code point). Is this documented somewhere? I can't tell you how long I spent unsuccessfully googling for variations on "go language runes", which unsurprisingly mostly came back with pages about Germanic runes and elf runes but not Go runes. I read the golang FAQs, which mentioned Unicode *once* and runes not at all. Obviously Go language programmers don't care much about Unicode. > It means the UTF-8 width of the character, i.e. the number of UTF-8 > bytes the function "consumed", presumably so that the caller can then > reslice the data with that many bytes fewer. That makes sense, given the lousy string implementation and API they're working with. I note that not all 32-bit ints are valid code points. I suppose I can see sense in having rune be a 32-bit integer value limited to those valid code points. (But, dammit, why not call it a code point?) But if rune is merely an alias for int32, why not just call it int32? -- Steven From dan at tombstonezero.net Sun Aug 26 16:45:09 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Sun, 26 Aug 2012 13:45:09 -0700 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120826204508.GG4714@particle> On 2012-08-26 at 20:13:21 +0000, Steven D'Aprano wrote: > I note that not all 32-bit ints are valid code points. I suppose I can > see sense in having rune be a 32-bit integer value limited to those > valid code points. (But, dammit, why not call it a code point?) But if > rune is merely an alias for int32, why not just call it int32? Having a "code point" type is a good idea. If nothing else, human code readers can tell that you're doing something with characters rather than something with integers. If your language provides any sort of type safety, then you get that, too. Calling your code points int32 is a bad idea for the same reason that it turned out to be a bad idea to call all my old ASCII characters int8. Or all my pointers int (or unsigned int), for n in 16, 20, 24, 32, 36, 48, or 64 (or I'm sure other values of n that I never had the pain or pleasure of using). Dan From nad at acm.org Sun Aug 26 17:23:13 2012 From: nad at acm.org (Ned Deily) Date: Sun, 26 Aug 2012 14:23:13 -0700 Subject: sys.path in python3.3 References: Message-ID: In article , Nicholas Cole wrote: > On Sun, Aug 26, 2012 at 8:21 PM, Ned Deily wrote: > > In article > > , > > Nicholas Cole wrote: > >> In all previous versions of python, I've been able to install packages > >> into the path: > >> > >> ~/Library/Python/$py_version_short/site-packages > >> > >> but in the rc builds of python 3.3 this is no longer part of sys.path. > >> > >> Before I go hacking the install, is there a reason that this path was > >> removed? Is there a recommended way to get it back, or is this a > >> gentle way of pushing us all to use virtualenv rather than installing > >> user-specific packages? > > > > It should be working if you are using an OS X framework build. What is > > the value of sys.path? > > I'm using the compiled version supplied by python.org. The directory needs to exist otherwise the path is not included (see site.py). -- Ned Deily, nad at acm.org From ian.g.kelly at gmail.com Sun Aug 26 17:42:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Aug 2012 15:42:00 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 2:13 PM, Steven D'Aprano wrote: > On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: > >> I think the documentation for those functions is simply badly worded. >> The "width in bytes" it returns is not the width of the rune (which as >> jmf notes is simply an alias for int32 that stores a single code point). > > Is this documented somewhere? http://golang.org/ref/spec#Numeric_types From steve+comp.lang.python at pearwood.info Sun Aug 26 18:47:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 22:47:36 GMT Subject: Objects in Python References: <18409992-1e28-4721-8e64-60c69668da4e@googlegroups.com> <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a3051$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503aa787$0$1555$c3e8da3$76491128@news.astraweb.com> On Mon, 27 Aug 2012 00:54:05 +1000, Chris Angelico wrote: > On Mon, Aug 27, 2012 at 12:18 AM, Steven D'Aprano > wrote: >> Also, built-ins require a name lookup too. As you point out, locals are >> special, but Python will search an arbitrarily deep set of nested >> nonlocal scopes, then globals, then builtins. > > Ah, builtins, forgot that. So yes, global scope involves potentially two > name lookups. But nonlocals aren't searched at run time. Well, whaddyaknow. You're right. x = 'globals' def test(switch): def a(): if switch == 1: x = 'a' def b(): if switch == 2: x = 'b' def c(): print "x found in", x c() b() a() Tried that in Jython, IronPython and Python 2.7, and I get the same result: only test(2) succeeds. I even tried it in Python 2.2, which does the same thing. (2.1 and older don't have nested scopes, so there's no point in going back further.) -- Steven From nicholas.cole at gmail.com Sun Aug 26 18:59:52 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 26 Aug 2012 23:59:52 +0100 Subject: sys.path in python3.3 In-Reply-To: References: Message-ID: On Sun, Aug 26, 2012 at 10:23 PM, Ned Deily wrote: > In article > , > Nicholas Cole wrote: > >> On Sun, Aug 26, 2012 at 8:21 PM, Ned Deily wrote: >> > In article >> > , >> > Nicholas Cole wrote: >> >> In all previous versions of python, I've been able to install packages >> >> into the path: >> >> >> >> ~/Library/Python/$py_version_short/site-packages >> >> >> >> but in the rc builds of python 3.3 this is no longer part of sys.path. >> >> >> >> Before I go hacking the install, is there a reason that this path was >> >> removed? Is there a recommended way to get it back, or is this a >> >> gentle way of pushing us all to use virtualenv rather than installing >> >> user-specific packages? >> > >> > It should be working if you are using an OS X framework build. What is >> > the value of sys.path? >> >> I'm using the compiled version supplied by python.org. > > The directory needs to exist otherwise the path is not included (see > site.py). It certainly does exist. Distutils will happily put packages into it, but import won't find them. N. From nad at acm.org Sun Aug 26 19:18:40 2012 From: nad at acm.org (Ned Deily) Date: Sun, 26 Aug 2012 16:18:40 -0700 Subject: sys.path in python3.3 References: Message-ID: In article , Nicholas Cole wrote: > It certainly does exist. Distutils will happily put packages into it, > but import won't find them. That's odd! It works for me on 10.8 and it worked for me yesterday on 10.7 which I tested just after completing the python.org installer builds. Perhaps there is some permission issue. Or the path name isn't quite correct. Or you have some PYTHON* environment variable set, like PYTHONNOUSERSITE? Here's a simple case I just tried installing Distribute using --user: $ ls -ld Library/ drwx------@ 59 nad staff 2074 Aug 26 15:03 Library// $ ls -ld Library/Python/ drwxr-x--- 5 nad staff 170 Aug 25 14:37 Library/Python// $ ls -ld Library/Python/3.3 drwx------ 4 nad staff 136 Aug 25 14:37 Library/Python/3.3/ $ ls -ld Library/Python/3.3/lib/ drwx------ 3 nad staff 102 Aug 25 14:37 Library/Python/3.3/lib// $ ls -ld Library/Python/3.3/lib/python/ drwx------ 3 nad staff 102 Aug 25 14:37 Library/Python/3.3/lib/python// $ ls -ld Library/Python/3.3/lib/python/site-packages/ drwx------ 6 nad staff 374 Aug 25 14:37 Library/Python/3.3/lib/python/site-packages// $ mv Library/Python/ Library/PythonDis $ /usr/local/bin/python3.3 Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 10:09:29) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> pp(sys.path) ['', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-dar win', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynl oad', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-pac kages'] >>> ^D $ curl -O http://python-distribute.org/distribute_setup.py % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 16295 100 16295 0 0 18199 0 --:--:-- --:--:-- --:--:-- 31518 $ /usr/local/bin/python3.3 distribute_setup.py --user Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar .gz Extracting in /var/folders/fm/9wjgctqx61n796zt88qmmnxc0000gn/T/tmp25bmgw Now working in /var/folders/fm/9wjgctqx61n796zt88qmmnxc0000gn/T/tmp25bmgw/distribute-0.6 .28 Installing Distribute [...] creating dist creating 'dist/distribute-0.6.28-py3.3.egg' and adding 'build/bdist.macosx-10.6-intel/egg' to it removing 'build/bdist.macosx-10.6-intel/egg' (and everything under it) Processing distribute-0.6.28-py3.3.egg creating /Users/nad/Library/Python/3.3/lib/python/site-packages/distribute-0.6.28- py3.3.egg Extracting distribute-0.6.28-py3.3.egg to /Users/nad/Library/Python/3.3/lib/python/site-packages Adding distribute 0.6.28 to easy-install.pth file Installing easy_install-3.3 script to /Users/nad/Library/Python/3.3/bin Installing easy_install script to /Users/nad/Library/Python/3.3/bin Installed /Users/nad/Library/Python/3.3/lib/python/site-packages/distribute-0.6.28- py3.3.egg Processing dependencies for distribute==0.6.28 Finished processing dependencies for distribute==0.6.28 After install bootstrap. Don't have permissions to write /Users/nad/Library/Python/3.3/lib/python/site-packages/setuptools-0.6c11- py3.3.egg-info, skipping Creating /Users/nad/Library/Python/3.3/lib/python/site-packages/setuptools-0.6c11- py3.3.egg-info Creating /Users/nad/Library/Python/3.3/lib/python/site-packages/setuptools.pth $ ls Library/Py Python/ PythonDis/ $ ls Library/Python/3.3/ bin/ lib/ $ ls Library/Python/3.3/lib/python/site-packages/ distribute-0.6.28-py3.3.egg/ setuptools-0.6c11-py3.3.egg-info easy-install.pth setuptools.pth $ ls Library/Python/3.3/lib/python/site-packages/ distribute-0.6.28-py3.3.egg/ setuptools-0.6c11-py3.3.egg-info easy-install.pth setuptools.pth $ /usr/local/bin/python3.3 Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 10:09:29) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> pp(sys.path) ['', '/Users/nad/Library/Python/3.3/lib/python/site-packages/distribute-0.6.28 -py3.3.egg', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-dar win', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynl oad', '/Users/nad/Library/Python/3.3/lib/python/site-packages', '/Users/nad/Library/Python/3.3/lib/python/site-packages/setuptools-0.6c11 -py3.3.egg-info', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-pac kages'] >>> import setuptools >>> setuptools.__file__ '/Users/nad/Library/Python/3.3/lib/python/site-packages/distribute-0.6.28 -py3.3.egg/setuptools/__init__.py' -- Ned Deily, nad at acm.org From steve+comp.lang.python at pearwood.info Sun Aug 26 19:29:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 23:29:06 GMT Subject: Objects in Python References: <87d32i1ntc.fsf@benfinney.id.au> <7df4c317-7ad8-4158-900a-b52f19c3caf2@k9g2000pbr.googlegroups.com> <503750b9$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a2804$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503ab142$0$1555$c3e8da3$76491128@news.astraweb.com> On Sun, 26 Aug 2012 16:12:40 -0400, Dennis Lee Bieber wrote: > On 26 Aug 2012 13:43:33 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > >> (In some older versions of Python, wildcard imports are allowed, and >> the function then falls back on a namespace instead of fixed locations. >> That is no longer the case in Python 3.2 at least.) >> > Must be really old: Not really. You get a SyntaxWarning back to at least 2.2, but the fallback namespace behaviour does work through to 2.7: py> assert 'pi' not in globals() py> def test(): ... from math import * ... print pi ... :1: SyntaxWarning: import * only allowed at module level py> test() 3.14159265359 What I didn't realise until just now is that it's a bit more complicated than that. Using import * in a function you can end up with two distinct sets of locals, those using numbered memory slots (effectively address- based), and those using a dict namespace. If you assign to a name in the function, it still gets turned into a memory slot rather than being in a dict. Decompiling the function shows that such local are still accessed using LOAD_FAST and STORE_FAST op- codes. (That's the case all the way back to Python 1.5 at least.) But if you *don't* assign to the name, Python uses LOAD_NAME instead, which searches namespace. In this case pi is not found in the global or built-in namespaces, so there must be a local, dict-based namespace in addition to the usual LOAD_FAST slots. Hence, two distinct sets of locals. -- Steven From steve+comp.lang.python at pearwood.info Sun Aug 26 19:31:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Aug 2012 23:31:37 GMT Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <503ab1d9$0$1555$c3e8da3$76491128@news.astraweb.com> On Sun, 26 Aug 2012 15:42:00 -0600, Ian Kelly wrote: > On Sun, Aug 26, 2012 at 2:13 PM, Steven D'Aprano > wrote: >> On Sun, 26 Aug 2012 09:40:13 -0600, Ian Kelly wrote: >> >>> I think the documentation for those functions is simply badly worded. >>> The "width in bytes" it returns is not the width of the rune (which as >>> jmf notes is simply an alias for int32 that stores a single code >>> point). >> >> Is this documented somewhere? > > http://golang.org/ref/spec#Numeric_types Thanks. Well that's just plain nuts. -- Steven From no.email at nospam.invalid Sun Aug 26 20:47:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 26 Aug 2012 17:47:02 -0700 Subject: Flexible string representation, unicode, typography, ... References: <1874857c-68ef-4c1b-b15a-46ef47df9445@googlegroups.com> <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <503ab1d9$0$1555$c3e8da3$76491128@news.astraweb.com> Message-ID: <7x6285kvp5.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> http://golang.org/ref/spec#Numeric_types > Thanks. > Well that's just plain nuts. I'm not sure how Rust handles Unicode, but overall I think it is more clueful than Go while having sort of comparable goals. See: http://rust-lang.org . From bruceg113355 at gmail.com Sun Aug 26 21:23:31 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Sun, 26 Aug 2012 18:23:31 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow Message-ID: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> My program uses Python 2.6 and Sqlite3 and connects to a network database 100 miles away. My program reads approx 60 records (4000 bytes) from a Sqlite database in less than a second. Each time the user requests data, my program can continuously read 60 records in less than a second. However, if I access the network drive (e.g. DOS command DIR /S) while my program is running, my program takes 20 seconds to read the same 60 records. If I restart my program, my program once again takes less than a second to read 60 records. Any ideas? Thanks, Bruce From timr at probo.com Sun Aug 26 21:23:49 2012 From: timr at probo.com (Tim Roberts) Date: Sun, 26 Aug 2012 18:23:49 -0700 Subject: calling loaded DLL function expecting POINT * argument References: <1486b835-f9e5-454b-abb7-a3289b1a4fe1@googlegroups.com> Message-ID: Tim Williams wrote: >Hello all, > >I'm trying to use the ctypes module to call functions in a DLL. I've >figured out how to modify my path so the library is found, and I can >call LoadLibrary on it, but one of the functions expects an array of > POINTS. Here is the prototype from the .h file: > > >TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints); How is TRACKER_API defined? You're using ctypes.oledll, which uses the __stdcall calling convention. It's possible your DLL is defined as __cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python.list at tim.thechases.com Sun Aug 26 21:40:55 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 26 Aug 2012 20:40:55 -0500 Subject: Python list archives double-gzipped? Message-ID: <503AD027.7000004@tim.thechases.com> Playing around with the mbox module, I reached into the archives[1] to grab some real-world data files[2]. To successfully unpack the contents to an mbox file, I had to do the following: bash$ gunzip 2012-July.txt.gz bash$ mv 2012-July.txt 2012-July.txt.gz bash$ gunzip 2012-July.txt.gz So it looks like some python-list@ archiving process is double gzip'ing the archives. Can anybody else confirm this and get the info the right people? -tkc [1] http://mail.python.org/pipermail/python-list/ [2] http://mail.python.org/pipermail/python-list/2012-July.txt.gz From steve+comp.lang.python at pearwood.info Sun Aug 26 21:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Aug 2012 01:54:42 GMT Subject: Make error when installing Python 1.5 Message-ID: <503ad362$0$1555$c3e8da3$76491128@news.astraweb.com> Yes, you read the subject line right -- Python 1.5. Yes, I am nuts ;) (I like having old versions of Python around for testing historical behaviour.) On Debian squeeze, when I try to build Python 1.5, I get this error: fileobject.c:590: error: conflicting types for ?getline? /usr/include/stdio.h:651: note: previous declaration of ?getline? was here make[1]: *** [fileobject.o] Error 1 make[1]: Leaving directory `/home/steve/personal/python/Python-1.5.2/ Objects' make: *** [Objects] Error 2 But when I do the same on Centos 5, it builds successfully and I can then run "sudo make altinstall" to install it. What's going on here and what do I need to do to fix this? Grepping stdio.h gives the same content on both Centos and Debian: $ grep getline /usr/include/stdio.h extern _IO_ssize_t getline (char **__restrict __lineptr, For those wanting to play around with it: wget http://www.python.org/ftp/python/src/py152.tgz tar xzf py152.tgz cd Python-1.5.2/ ./configure make sudo make altinstall -- Steven From cs at zip.com.au Sun Aug 26 22:15:46 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 27 Aug 2012 12:15:46 +1000 Subject: Make error when installing Python 1.5 In-Reply-To: <503ad362$0$1555$c3e8da3$76491128@news.astraweb.com> References: <503ad362$0$1555$c3e8da3$76491128@news.astraweb.com> Message-ID: <20120827021546.GA22550@cskk.homeip.net> On 27Aug2012 01:54, Steven D'Aprano wrote: | Yes, you read the subject line right -- Python 1.5. Yes, I am nuts ;) | | (I like having old versions of Python around for testing historical | behaviour.) | | On Debian squeeze, when I try to build Python 1.5, I get this error: | | fileobject.c:590: error: conflicting types for ?getline? | /usr/include/stdio.h:651: note: previous declaration of ?getline? was here | make[1]: *** [fileobject.o] Error 1 | make[1]: Leaving directory `/home/steve/personal/python/Python-1.5.2/ | Objects' | make: *** [Objects] Error 2 [...] I would take the compile line for fileobject.c and supposing it to look like this: gcc -c -blah fileobject.c run it by hand as: gcc -E -blah fileobject.c >fileobject.cpp and examine the preprocessor output (initially with grep, then with vi/emacs). I would expect the lines for getline to be different, with some macro definition occuring between the first and second occurence. Cheers, -- Cameron Simpson From mullapervez at gmail.com Mon Aug 27 02:20:01 2012 From: mullapervez at gmail.com (Pervez Mulla) Date: Sun, 26 Aug 2012 23:20:01 -0700 (PDT) Subject: Calling External (Perl)Script in Python Message-ID: Hi, I am trying to call perl script in my python view.py and store that data in logfile .... On shell I am able to display data. I wanna call that data on logfile , How can i do this .......? I wanna call perl objects in python ... So , How can I pass all that stuff in python(firstname, lastname, username).... Please help Pervez From ben+python at benfinney.id.au Mon Aug 27 03:01:57 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 27 Aug 2012 17:01:57 +1000 Subject: Calling External (Perl)Script in Python References: Message-ID: <873938es2i.fsf@benfinney.id.au> Pervez Mulla writes: > I am trying to call perl script in my python view.py and store that > data in logfile .... To run external programs and connect to their standard streams, use the ?subprocess? module from the Python standard library. -- \ ?If we don't believe in freedom of expression for people we | `\ despise, we don't believe in it at all.? ?Noam Chomsky, | _o__) 1992-11-25 | Ben Finney From nicholas.cole at gmail.com Mon Aug 27 03:03:01 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 27 Aug 2012 08:03:01 +0100 Subject: sys.path in python3.3 In-Reply-To: References: Message-ID: On Mon, Aug 27, 2012 at 12:18 AM, Ned Deily wrote: > In article > , > Nicholas Cole wrote: >> It certainly does exist. Distutils will happily put packages into it, >> but import won't find them. > > That's odd! It works for me on 10.8 and it worked for me yesterday on > 10.7 which I tested just after completing the python.org installer > builds. Perhaps there is some permission issue. Or the path name isn't > quite correct. Or you have some PYTHON* environment variable set, like > PYTHONNOUSERSITE? I'm also on 10.8. NPSC: nicholas$ set | grep PYTHON NPSC: nicholas$ The only user configuration I've done is to create the following configuration file: NPSC:~ nicholas$ cat .pydistutils.cfg [install] install_lib = ~/Library/Python/$py_version_short/site-packages install_scripts = ~/bin I should say, this has been a problem for all of the python3.3 alpha and beta releases, on previous releases of OS X. I can't understand why it works on your setup, though, because I haven't done anything at all (that I can think of) that ought of affect it. I wonder if the logic that adds the directory to sys.path is being too clever for everyone's good? Best wishes, N. From hansmu at xs4all.nl Mon Aug 27 04:39:34 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 27 Aug 2012 10:39:34 +0200 Subject: sys.path in python3.3 In-Reply-To: References: Message-ID: <503b3247$0$6877$e4fe514c@news2.news.xs4all.nl> On 26/08/12 20:47:34, Nicholas Cole wrote: > Dear List, > > In all previous versions of python, I've been able to install packages > into the path: > > ~/Library/Python/$py_version_short/site-packages > > but in the rc builds of python 3.3 this is no longer part of sys.path. It has been changed to ~/Library/Python/$py_version_short/lib/python/site-packages You can find the path it's looking for in site.USER_SITE > Before I go hacking the install, is there a reason that this path was > removed? Is there a recommended way to get it back, or is this a > gentle way of pushing us all to use virtualenv rather than installing > user-specific packages? I don't know why it was changed. It would be nice if there were some magic code you could use for "install_lib" in your .pydistutils.cfg file that worked in both 3.2 and 3.3. -- HansM From nad at acm.org Mon Aug 27 04:52:05 2012 From: nad at acm.org (Ned Deily) Date: Mon, 27 Aug 2012 01:52:05 -0700 Subject: sys.path in python3.3 References: Message-ID: In article , Nicholas Cole wrote: > The only user configuration I've done is to create the following > configuration file: > > NPSC:~ nicholas$ cat .pydistutils.cfg > [install] > install_lib = ~/Library/Python/$py_version_short/site-packages > install_scripts = ~/bin > > I should say, this has been a problem for all of the python3.3 alpha > and beta releases, on previous releases of OS X. > > I can't understand why it works on your setup, though, because I > haven't done anything at all (that I can think of) that ought of > affect it. I wonder if the logic that adds the directory to sys.path > is being too clever for everyone's good? Ah, now I know what the problem is. If you look carefully, you'll see that the path created in the Distribute example, effectively by using setup.py --install, is slightly different from the install_lib path in your .pydistutils.cfg. What happened is that Python 2.7 and Python 3.2 introduced a change in the user site path for OS X framework builds. The rationale was to make the ~/Library/Python user site directory look more like the existing framework structure. This change was somewhat controversial and has not yet been resolved to everyone's satisfaction. (http://bugs.python.org/issue8084) A contributing factor is that feature changes to Distutils have been on hold with the planned introduction of its replacement, packaging. However, late in the 3.3 release cycle, it was decided that packaging wasn't quite ready for release and we never got around to taking another look at other pending Distutils-related issues, like this one. OTOH, this has now been the behavior for the lifetime of 2.7 and 3.2 and now for 3.3 and it is documented if you know where to look: http://docs.python.org/py3k/library/site.html It is not likely that, at this point, it will be changed back to 2.6/3.1 behavior nor to the exact original PEP-370 proposal either. So, for the current Python releases (2.7, 3.2, 3.3), one solution is to change the install_lib definition in .pydistutils.cfg to: install_lib = ~/Library/Python/$py_version_short/lib/python/site-packages Or just user--user on setup.py install commands. I'm sorry that I don't have a better story for now. That said, I think that installation is likely to be a major focus for Python 3.4 and that there will be a push to rationalize things in this rather murky area of Python. -- Ned Deily, nad at acm.org From nad at acm.org Mon Aug 27 05:05:45 2012 From: nad at acm.org (Ned Deily) Date: Mon, 27 Aug 2012 02:05:45 -0700 Subject: sys.path in python3.3 References: <503b3247$0$6877$e4fe514c@news2.news.xs4all.nl> Message-ID: In article <503b3247$0$6877$e4fe514c at news2.news.xs4all.nl>, Hans Mulder wrote: > On 26/08/12 20:47:34, Nicholas Cole wrote: > It has been changed to > > ~/Library/Python/$py_version_short/lib/python/site-packages > > You can find the path it's looking for in site.USER_SITE That is correct. > It would be nice if there were some magic code you could use > for "install_lib" in your .pydistutils.cfg file that worked > in both 3.2 and 3.3. As I explained in my reply that overlapped with yours, I believe you will find that 3.2 and 3.3 behave the same. The difference is with 3.1 (which is no longer supported); likewise, the same change occurred in 2.7. So all of the current actively supported released behave the same way. That's not much help if you need to use 2.6 or 3.1. -- Ned Deily, nad at acm.org From nicholas.cole at gmail.com Mon Aug 27 05:29:10 2012 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 27 Aug 2012 10:29:10 +0100 Subject: sys.path in python3.3 In-Reply-To: References: <503b3247$0$6877$e4fe514c@news2.news.xs4all.nl> Message-ID: On Mon, Aug 27, 2012 at 10:05 AM, Ned Deily wrote: > In article <503b3247$0$6877$e4fe514c at news2.news.xs4all.nl>, > Hans Mulder wrote: >> On 26/08/12 20:47:34, Nicholas Cole wrote: >> It has been changed to >> >> ~/Library/Python/$py_version_short/lib/python/site-packages >> >> You can find the path it's looking for in site.USER_SITE > > That is correct. > >> It would be nice if there were some magic code you could use >> for "install_lib" in your .pydistutils.cfg file that worked >> in both 3.2 and 3.3. > > As I explained in my reply that overlapped with yours, I believe you > will find that 3.2 and 3.3 behave the same. The difference is with 3.1 > (which is no longer supported); likewise, the same change occurred in > 2.7. So all of the current actively supported released behave the same > way. That's not much help if you need to use 2.6 or 3.1. Dear Hans and Ned, Thank you both for your answers, and Ned, thank you especially for answering at such length. I do love the things that are "documented if you know where to look." I'm by no means a stranger to python's documentation, but I am sure that I would never, ever have found it. Now that I come to think of it, I think I probably hit this when I first had a look at 2.7, put in a sym-link and forgot all about it. I suppose that now that 2.7 is the default on OS X, I suppose it is time to move to the correct directory properly. Very best wishes, Nicholas From hussain.a.rasheed at gmail.com Mon Aug 27 05:45:02 2012 From: hussain.a.rasheed at gmail.com (hussain.a.rasheed at gmail.com) Date: Mon, 27 Aug 2012 02:45:02 -0700 (PDT) Subject: Extract Text Format Table Data Message-ID: <0d9a48cc-4ac5-45a1-9471-8b7d95e5ba73@googlegroups.com> Hi, I am trying to extract some data from a log file that outputs tables in text format. I've been trying to accomplish this for some time but without any luck. Hence, appreciate if any of you could help out. Below is a just one block of table from the file. There will be many blocks like this in the log file. ROUTES TRAFFIC RESULTS, LSR TRG MP DATE TIME 37 17 120824 0000 R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW AABBCCO 6.4 204 0.0 115 1.0 113.4 144 AABBCCI 3.0 293 115 1.0 37.0 171 DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 EEFFEEI 0.0 0 59 0.0 0.0 0 HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 HHGGFFI 0.3 15 30 0.0 62.2 4 END Thanks From hussain.a.rasheed at gmail.com Mon Aug 27 05:53:06 2012 From: hussain.a.rasheed at gmail.com (Huso) Date: Mon, 27 Aug 2012 02:53:06 -0700 (PDT) Subject: Extract Text Table From File Message-ID: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Hi, I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. Below is just ONE block of the traffic i have in the log files. There will be more in them with different data. ROUTES TRAFFIC RESULTS, LSR TRG MP DATE TIME 37 17 120824 0000 R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW AABBCCO 6.4 204 0.0 115 1.0 113.4 144 AABBCCI 3.0 293 115 1.0 37.0 171 DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 EEFFEEI 0.0 0 59 0.0 0.0 0 HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 HHGGFFI 0.3 15 30 0.0 62.2 4 END Thanks From gandalf at shopzeus.com Mon Aug 27 06:12:14 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 27 Aug 2012 12:12:14 +0200 Subject: Extract Text Table From File In-Reply-To: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <503B47FE.6050002@shopzeus.com> On 2012-08-27 11:53, Huso wrote: > Hi, > > I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. # # Write test data to test.txt # data = """ ROUTES TRAFFIC RESULTS, LSR TRG MP DATE TIME 37 17 120824 0000 R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW AABBCCO 6.4 204 0.0 115 1.0 113.4 144 AABBCCI 3.0 293 115 1.0 37.0 171 DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 EEFFEEI 0.0 0 59 0.0 0.0 0 HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 HHGGFFI 0.3 15 30 0.0 62.2 4 END """ fout = open("test.txt","wb+") fout.write(data) fout.close() # # This is how you iterate over a file and process its lines # fin = open("test.txt","r") for line in fin: # This is one possible way to extract values. values = line.strip().split() print values This will print: [] ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR'] ['TRG', 'MP', 'DATE', 'TIME'] ['37', '17', '120824', '0000'] [] ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW'] ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144'] ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171'] ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3'] ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0'] ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0'] ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4'] ['END'] The "values" list in the last line contains these values. This will work only if you don't have spaces in your values. Otherwise you can use regular expressions to parse a line. See here: http://docs.python.org/library/re.html Since you did not give any specification on your file format, it would be hard to give a concrete program that parses your file(s) Best, Laszlo From hussain.a.rasheed at gmail.com Mon Aug 27 06:34:03 2012 From: hussain.a.rasheed at gmail.com (Huso) Date: Mon, 27 Aug 2012 03:34:03 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <1a0794ef-2186-4fae-a0be-61e07eb4e9e6@googlegroups.com> On Monday, August 27, 2012 3:12:14 PM UTC+5, Laszlo Nagy wrote: > On 2012-08-27 11:53, Huso wrote: > > > Hi, > > > > > > I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. > > > > # > > # Write test data to test.txt > > # > > > > data = """ > > ROUTES TRAFFIC RESULTS, LSR > > TRG MP DATE TIME > > 37 17 120824 0000 > > > > R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW > > AABBCCO 6.4 204 0.0 115 1.0 113.4 144 > > AABBCCI 3.0 293 115 1.0 37.0 171 > > DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 > > EEFFEEI 0.0 0 59 0.0 0.0 0 > > HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 > > HHGGFFI 0.3 15 30 0.0 62.2 4 > > END > > """ > > fout = open("test.txt","wb+") > > fout.write(data) > > fout.close() > > > > # > > # This is how you iterate over a file and process its lines > > # > > fin = open("test.txt","r") > > for line in fin: > > # This is one possible way to extract values. > > values = line.strip().split() > > print values > > > > > > This will print: > > > > [] > > ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR'] > > ['TRG', 'MP', 'DATE', 'TIME'] > > ['37', '17', '120824', '0000'] > > [] > > ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW'] > > ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144'] > > ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171'] > > ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3'] > > ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0'] > > ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0'] > > ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4'] > > ['END'] > > > > > > The "values" list in the last line contains these values. This will work > > only if you don't have spaces in your values. Otherwise you can use > > regular expressions to parse a line. See here: > > > > http://docs.python.org/library/re.html > > > > Since you did not give any specification on your file format, it would > > be hard to give a concrete program that parses your file(s) > > > > Best, > > > > Laszlo Hi, Thank you for the information. The exact way I want to extract the data is like as below. TRG, MP and DATE and TIME is common for that certain block of traffic. So I am using those and dumping it with the rest of the data into sql. Table will have all headers (TRG, MP, DATE, TIME, R, TRAFF, NBIDS, CCONG, NDV, ANBLO, MHTIME, NBANSW). So from this text, the first data will be 37, 17, 120824, 0000, AABBCCO, 6.4, 204, 0.0, 115, 1.0, 113.4, 144. Thanking, Huso From hussain.a.rasheed at gmail.com Mon Aug 27 06:34:03 2012 From: hussain.a.rasheed at gmail.com (Huso) Date: Mon, 27 Aug 2012 03:34:03 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <1a0794ef-2186-4fae-a0be-61e07eb4e9e6@googlegroups.com> On Monday, August 27, 2012 3:12:14 PM UTC+5, Laszlo Nagy wrote: > On 2012-08-27 11:53, Huso wrote: > > > Hi, > > > > > > I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. > > > > # > > # Write test data to test.txt > > # > > > > data = """ > > ROUTES TRAFFIC RESULTS, LSR > > TRG MP DATE TIME > > 37 17 120824 0000 > > > > R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW > > AABBCCO 6.4 204 0.0 115 1.0 113.4 144 > > AABBCCI 3.0 293 115 1.0 37.0 171 > > DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 > > EEFFEEI 0.0 0 59 0.0 0.0 0 > > HHGGFFO 0.0 0 0.0 30 0.0 0.0 0 > > HHGGFFI 0.3 15 30 0.0 62.2 4 > > END > > """ > > fout = open("test.txt","wb+") > > fout.write(data) > > fout.close() > > > > # > > # This is how you iterate over a file and process its lines > > # > > fin = open("test.txt","r") > > for line in fin: > > # This is one possible way to extract values. > > values = line.strip().split() > > print values > > > > > > This will print: > > > > [] > > ['ROUTES', 'TRAFFIC', 'RESULTS,', 'LSR'] > > ['TRG', 'MP', 'DATE', 'TIME'] > > ['37', '17', '120824', '0000'] > > [] > > ['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW'] > > ['AABBCCO', '6.4', '204', '0.0', '115', '1.0', '113.4', '144'] > > ['AABBCCI', '3.0', '293', '115', '1.0', '37.0', '171'] > > ['DDEEFFO', '0.2', '5', '0.0', '59', '0.0', '107.6', '3'] > > ['EEFFEEI', '0.0', '0', '59', '0.0', '0.0', '0'] > > ['HHGGFFO', '0.0', '0', '0.0', '30', '0.0', '0.0', '0'] > > ['HHGGFFI', '0.3', '15', '30', '0.0', '62.2', '4'] > > ['END'] > > > > > > The "values" list in the last line contains these values. This will work > > only if you don't have spaces in your values. Otherwise you can use > > regular expressions to parse a line. See here: > > > > http://docs.python.org/library/re.html > > > > Since you did not give any specification on your file format, it would > > be hard to give a concrete program that parses your file(s) > > > > Best, > > > > Laszlo Hi, Thank you for the information. The exact way I want to extract the data is like as below. TRG, MP and DATE and TIME is common for that certain block of traffic. So I am using those and dumping it with the rest of the data into sql. Table will have all headers (TRG, MP, DATE, TIME, R, TRAFF, NBIDS, CCONG, NDV, ANBLO, MHTIME, NBANSW). So from this text, the first data will be 37, 17, 120824, 0000, AABBCCO, 6.4, 204, 0.0, 115, 1.0, 113.4, 144. Thanking, Huso From michele.cecere at gmail.com Mon Aug 27 06:59:02 2012 From: michele.cecere at gmail.com (mikcec82) Date: Mon, 27 Aug 2012 03:59:02 -0700 (PDT) Subject: What do I do to read html files on my pc? Message-ID: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Hallo, I have an html file on my pc and I want to read it to extract some text. Can you help on which libs I have to use and how can I do it? thank you so much. Michele From alexander_naumov at opensuse.org Mon Aug 27 07:04:12 2012 From: alexander_naumov at opensuse.org (Alex Naumov) Date: Mon, 27 Aug 2012 13:04:12 +0200 Subject: Your favorite test tool and automation frameworks Message-ID: Hello everybody, I would like to ask about your favorite python test frameworks. I never used it before (beginner in testing) and would like to start to learn Unit- and GUI-testing. I look now at PyUnit/unittest and dogtail. Maybe someone can recommend something better or just share experiences? Thank you, Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Mon Aug 27 07:07:37 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 27 Aug 2012 13:07:37 +0200 Subject: Extract Text Table From File In-Reply-To: <1a0794ef-2186-4fae-a0be-61e07eb4e9e6@googlegroups.com> References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> <1a0794ef-2186-4fae-a0be-61e07eb4e9e6@googlegroups.com> Message-ID: <503B54F9.8090802@shopzeus.com> > Hi, > > Thank you for the information. > The exact way I want to extract the data is like as below. > > TRG, MP and DATE and TIME is common for that certain block of traffic. > So I am using those and dumping it with the rest of the data into sql. > Table will have all headers (TRG, MP, DATE, TIME, R, TRAFF, NBIDS, CCONG, NDV, ANBLO, MHTIME, NBANSW). > > So from this text, the first data will be 37, 17, 120824, 0000, AABBCCO, 6.4, 204, 0.0, 115, 1.0, 113.4, 144. How many blocks do you have in a file? Do you want to create different data sets for those blocks? How do you identify those blocks? (E.g. are they all saved into the same database table the same way?) Anyway here is something: import re # AABBCCO 6.4 204 0.0 115 1.0 113.4 144 pattern = re.compile(r"""([A-Z]{7})"""+7*r"""\s+([\d\.]+)""") # # This is how you iterate over a file and process its lines # fin = open("test.txt","r") blocks = [] block = None for line in fin: # This is one possible way to extract values. values = line.strip().split() if values==['R', 'TRAFF', 'NBIDS', 'CCONG', 'NDV', 'ANBLO', 'MHTIME', 'NBANSW']: if block is not None: blocks.append(block) block = [] elif block is not None: res = pattern.match(line.strip()) if res: values = list(res.groups()) values[1:] = map(float,values[1:]) block.append(values) if block is not None: blocks.append(block) for idx,block in enumerate(blocks): print "BLOCK",idx for values in block: print values This prints: BLOCK 0 ['AABBCCO', 6.4, 204.0, 0.0, 115.0, 1.0, 113.4, 144.0] ['DDEEFFO', 0.2, 5.0, 0.0, 59.0, 0.0, 107.6, 3.0] ['HHGGFFO', 0.0, 0.0, 0.0, 30.0, 0.0, 0.0, 0.0] From hussain.a.rasheed at gmail.com Mon Aug 27 07:23:00 2012 From: hussain.a.rasheed at gmail.com (Huso) Date: Mon, 27 Aug 2012 04:23:00 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <8e48635a-f873-40ce-b886-2ffc058f9eb4@googlegroups.com> Hi, There can be any number of blocks in the log file. I distinguish the block by the start header 'ROUTES TRAFFIC RESULTS, LSR' and ending in 'END'. Each block will have a unique [date + time] value. I tried the code you mentioned, it works for the data part. But I need to get the TRG, MP, DATE and TIME for the block with those data as well. This is the part that i'm really tangled in. Thanking, Huso From hussain.a.rasheed at gmail.com Mon Aug 27 07:23:00 2012 From: hussain.a.rasheed at gmail.com (Huso) Date: Mon, 27 Aug 2012 04:23:00 -0700 (PDT) Subject: Extract Text Table From File In-Reply-To: References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <8e48635a-f873-40ce-b886-2ffc058f9eb4@googlegroups.com> Hi, There can be any number of blocks in the log file. I distinguish the block by the start header 'ROUTES TRAFFIC RESULTS, LSR' and ending in 'END'. Each block will have a unique [date + time] value. I tried the code you mentioned, it works for the data part. But I need to get the TRG, MP, DATE and TIME for the block with those data as well. This is the part that i'm really tangled in. Thanking, Huso From gandalf at shopzeus.com Mon Aug 27 07:55:52 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 27 Aug 2012 13:55:52 +0200 Subject: Extract Text Table From File In-Reply-To: <8e48635a-f873-40ce-b886-2ffc058f9eb4@googlegroups.com> References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> <8e48635a-f873-40ce-b886-2ffc058f9eb4@googlegroups.com> Message-ID: <503B6048.5080306@shopzeus.com> On 2012-08-27 13:23, Huso wrote: > Hi, > > There can be any number of blocks in the log file. > I distinguish the block by the start header 'ROUTES TRAFFIC RESULTS, LSR' and ending in 'END'. Each block will have a unique [date + time] value. > > I tried the code you mentioned, it works for the data part. > But I need to get the TRG, MP, DATE and TIME for the block with those data as well. This is the part that i'm really tangled in. > > Thanking, > Huso Well, I suggest that you try to understand my code and make changes in it. It is not too hard. First you start reading documentation of the "re" module. It is worth learning Python. Especially for mining data out of text files. :-) Best, Laszlo From breamoreboy at yahoo.co.uk Mon Aug 27 07:57:06 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Aug 2012 12:57:06 +0100 Subject: Your favorite test tool and automation frameworks In-Reply-To: References: Message-ID: On 27/08/2012 12:04, Alex Naumov wrote: > Hello everybody, > > I would like to ask about your favorite python test frameworks. I never > used it before (beginner in testing) and would like to start to learn Unit- > and GUI-testing. > > I look now at PyUnit/unittest and dogtail. Maybe someone > can recommend something better or just share experiences? > > > Thank you, > Alex > > > I never test my own code as it's always perfect first time :) For those who lack my talents here's a good starting point http://wiki.python.org/moin/PythonTestingToolsTaxonomy -- Cheers. Mark Lawrence. From rosuav at gmail.com Mon Aug 27 07:58:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Aug 2012 21:58:08 +1000 Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: On Mon, Aug 27, 2012 at 8:59 PM, mikcec82 wrote: > Hallo, > > I have an html file on my pc and I want to read it to extract some text. > Can you help on which libs I have to use and how can I do it? > > thank you so much. Try BeautifulSoup. You can find it at the opposite end of a web search. Not trying to be unhelpful, but without more description of the problem, there's not a lot more to say :) ChrisA From breamoreboy at yahoo.co.uk Mon Aug 27 08:05:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Aug 2012 13:05:55 +0100 Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: On 27/08/2012 11:59, mikcec82 wrote: > Hallo, > > I have an html file on my pc and I want to read it to extract some text. > Can you help on which libs I have to use and how can I do it? > > thank you so much. > > Michele > Type something like "python html parsing" into the box of your favourite search engine, hit return and follow the links it comes back with. Write some code. If you have problems give us the smallest code snippet that reproduces the issue together with the complete traceback and we'll help. -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Mon Aug 27 08:42:52 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 27 Aug 2012 07:42:52 -0500 Subject: Extract Text Table From File In-Reply-To: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> References: <481dc39d-1dee-4ebe-97d5-ccad659f8c74@googlegroups.com> Message-ID: <503B6B4C.7090706@tim.thechases.com> On 08/27/12 04:53, Huso wrote: > Below is just ONE block of the traffic i have in the log files. There will be more in them with different data. > > ROUTES TRAFFIC RESULTS, LSR > TRG MP DATE TIME > 37 17 120824 0000 > > R TRAFF NBIDS CCONG NDV ANBLO MHTIME NBANSW > AABBCCO 6.4 204 0.0 115 1.0 113.4 144 > AABBCCI 3.0 293 115 1.0 37.0 171 > DDEEFFO 0.2 5 0.0 59 0.0 107.6 3 > HHGGFFI 0.3 15 30 0.0 62.2 4 > END In the past I've used something like the following to find columnar data based on some found headers: import re token_re = re.compile(r'\b(\w+)\s*') f = file(FILENAME) headers = f.next() # in your case, you'd # search forward until # you got to a header line # and use that TRAFF... line header_map = dict( # build a map of field-name to slice ( matchobj.group(1).upper(), slice(*matchobj.span()) ) for matchobj in token_re.finditer(headers) ) You can then access your values as you iterate through the rest of the rows: for row in f: if row.startswith("END"): break traff = float(row[header_map["TRAFF"]]) # ... which makes the code pretty easy to read, effectively turning it into a CSV file. It has the advantage that, if for some reason data in the columns have spaces in them, it won't throw off the row as a .split() would. -tkc From michele.cecere at gmail.com Mon Aug 27 09:51:37 2012 From: michele.cecere at gmail.com (mikcec82) Date: Mon, 27 Aug 2012 06:51:37 -0700 (PDT) Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: > Hallo, > > > > I have an html file on my pc and I want to read it to extract some text. > > Can you help on which libs I have to use and how can I do it? > > > > thank you so much. > > > > Michele Hi ChrisA, Hi Mark. Thanks a lot. I have this html data and I want to check if it is present a string "XXXX" or/and a string "NOT PASSED":           XXXX . . . CODE CHECK : NOT PASSED Depending on this check I have to fill a cell in an excel file with answer: NOK (if Not passed or XXXX is present), or OK (if Not passed and XXXX are not present). Thanks again for your help (and sorry for my english) From andipersti at gmail.com Mon Aug 27 09:52:12 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Mon, 27 Aug 2012 15:52:12 +0200 Subject: Python list archives double-gzipped? In-Reply-To: <503AD027.7000004@tim.thechases.com> References: <503AD027.7000004@tim.thechases.com> Message-ID: <503B7B8C.105@gmail.com> On 27.08.2012 03:40, Tim Chase wrote: > So it looks like some python-list@ archiving process is double > gzip'ing the archives. Can anybody else confirm this and get the > info the right people? In January, "random joe" noticed the same problem[1]. I think, Anssi Saari[2] was right in saying that there is something wrong in the browser or server setup, because I notice the same behaviour with Firefox, Chromium, wget and curl. $ ll *July* -rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 748041 Aug 2 03:27 wget_2012-July.txt.gz The browsers get a double gzipped file (size 747850) whereas the download utilities get a normal gzipped file (size 748041). After looking at the HTTP request and response headers I've noticed that the browsers accept compressed data ("Accept-Encoding: gzip, deflate") whereas wget/curl by default don't. After adding that header to wget/curl they get the same double gzipped file as the browsers do: $ ll *July* -rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:40 curl_encoding_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 748041 Aug 2 03:27 wget_2012-July.txt.gz -rw-rw-r-- 1 andreas andreas 747850 Aug 2 03:27 wget_encoding_2012-July.txt.gz I think the following is happening: If you send the "Accept-Encoding: gzip, deflate"-header, the server will gzip the file a second time (which is arguably unnecessary) and responds with "Content-Encoding: gzip" and "Content-Type: application/x-gzip" (which is IMHO correct according to RFC2616/14.11 and 14.17[3]). But because many servers apparently don't set correct headers, the default behaviour of most browsers nowadays is to ignore the content-encoding for gzip files (application/x-gzip - see bug report for firefox[4] and chromium[5]) and don't uncompress the outer layer, leading to a double gzipped file in this case. Bye, Andreas [1] http://mail.python.org/pipermail/python-list/2012-January/617983.html [2] http://mail.python.org/pipermail/python-list/2012-January/618211.html [3] http://www.ietf.org/rfc/rfc2616 [4] https://bugzilla.mozilla.org/show_bug.cgi?id=610679#c5 [5] http://code.google.com/p/chromium/issues/detail?id=47951#c9 From joel.goldstick at gmail.com Mon Aug 27 10:21:31 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 27 Aug 2012 10:21:31 -0400 Subject: What do I do to read html files on my pc? In-Reply-To: <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> Message-ID: On Mon, Aug 27, 2012 at 9:51 AM, mikcec82 wrote: > Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: >> Hallo, >> >> >> >> I have an html file on my pc and I want to read it to extract some text. >> >> Can you help on which libs I have to use and how can I do it? >> >> >> >> thank you so much. >> >> >> >> Michele > > Hi ChrisA, Hi Mark. > Thanks a lot. > > I have this html data and I want to check if it is present a string "XXXX" or/and a string "NOT PASSED": > > > > >   >   >   >   >   > > XXXX > > > > . > . > . > > > > > > > CODE CHECK > > > : NOT PASSED > > > > > > Depending on this check I have to fill a cell in an excel file with answer: NOK (if Not passed or XXXX is present), or OK (if Not passed and XXXX are not present). > > Thanks again for your help (and sorry for my english) > -- > http://mail.python.org/mailman/listinfo/python-list from your example it doesn't seem there is enough information to know where in the html your strings will be. If you just read the whole file into a string you can do this: >>> s = "this is a string" >>> if 'this' in s: ... print 'yes' ... yes >>> Of course you will be testing for 'XXXX' or 'NOT PASSED' -- Joel Goldstick From rosuav at gmail.com Mon Aug 27 10:41:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Aug 2012 00:41:46 +1000 Subject: What do I do to read html files on my pc? In-Reply-To: <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> Message-ID: On Mon, Aug 27, 2012 at 11:51 PM, mikcec82 wrote: > I have this html data and I want to check if it is present a string "XXXX" or/and a string "NOT PASSED": Start by scribbling down some notes in your native language (that is, don't bother trying to write code yet), defining exactly what you're looking for. What constitutes a hit? What would be a false positive that you need to avoid? For instance: * The string XXXX must occur outside of any HTML tag. or: * The string XXXX must occur inside a but not inside . or: * The string XXXX must be in the first inside of a in the that immediately follows the text "abcdefg". Make sure it's clear enough that anybody could follow it, even without knowing everything you know about your files. Once you have that algorithmic description, it's simply a matter of translating it into a language the computer can handle; and that's fairly straight-forward. An hour or two with language/library documentation and you'll quite possibly have working code, or if you don't, you'll at least have something that you can show to the list and ask for help with. But until you have that, advice from this list is going to be fairly vague, and may turn out to be quite misleading. We can't solve your problem until we know what it is, and you can't tell us what the problem is until you know yourself. ChrisA From ulrich.eckhardt at dominolaser.com Mon Aug 27 11:50:15 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 27 Aug 2012 17:50:15 +0200 Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> Message-ID: Am 27.08.2012 03:23, schrieb bruceg113355 at gmail.com: > My program uses Python 2.6 and Sqlite3 and connects to a network > database 100 miles away. Wait, isn't SQLite completely file-based? In that case, SQLite accesses a file, which in turn is stored on a remote filesystem. This means that there are other components involved here, namely your OS, the network (bandwidth & latency), the network filesystem and the filesystem on the remote machine. It would help if you told us what you have there. > My program reads approx 60 records (4000 bytes) from a Sqlite > database in less than a second. Each time the user requests data, my > program can continuously read 60 records in less than a second. > However, if I access the network drive (e.g. DOS command DIR /S) > while my program is running, my program takes 20 seconds to read the > same 60 records. If I restart my program, my program once again takes > less than a second to read 60 records. Questions here: 1. Is each record 4kB or are all 60 records together 4kB? 2. Does the time for reading double when you double the number of records? Typically you have B + C * N, but it would be interesting to know the bias B and the actual time (and size) of each record. 3. How does the timing change when running dir/s? 4. What if you run two instances of your program? 5. Is the duration is only reset by restarting the program or does it also decrease when the dir/s call has finished? What if you close and reopen the database without terminating the program? My guess is that the concurrent access by another program causes the accesses to become synchronized, while before most of the data is cached. That would cause a complete roundtrip between the two machines for every access, which can easily blow up the timing via the latency. In any case, I would try Python 2.7 in case this is a bug that was already fixed. Good luck! Uli From python.list at tim.thechases.com Mon Aug 27 12:53:04 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 27 Aug 2012 11:53:04 -0500 Subject: Python list archives double-gzipped? In-Reply-To: <503B7B8C.105@gmail.com> References: <503AD027.7000004@tim.thechases.com> <503B7B8C.105@gmail.com> Message-ID: <503BA5F0.3020704@tim.thechases.com> On 08/27/12 08:52, Andreas Perstinger wrote: > On 27.08.2012 03:40, Tim Chase wrote: >> So it looks like some python-list@ archiving process is double >> gzip'ing the archives. Can anybody else confirm this and get the >> info the right people? > > If you send the "Accept-Encoding: gzip, deflate"-header, the server will > gzip the file a second time (which is arguably unnecessary) and responds > with "Content-Encoding: gzip" and "Content-Type: application/x-gzip" > (which is IMHO correct according to RFC2616/14.11 and 14.17[3]). > But because many servers apparently don't set correct headers, the > default behaviour of most browsers nowadays is to ignore the > content-encoding for gzip files (application/x-gzip - see bug report for > firefox[4] and chromium[5]) and don't uncompress the outer layer, > leading to a double gzipped file in this case. That corresponds with what I see in various testing. To whomever controls the python.org web-server, is it possible to tweak Apache so that it doesn't try to gzip *.gz files? It may ameliorate the problem, as well as reduce server load (since it's actually taking the time to make the file larger) -tkc From ahsanraza211 at gmail.com Mon Aug 27 12:53:30 2012 From: ahsanraza211 at gmail.com (ahsanraza211 at gmail.com) Date: Mon, 27 Aug 2012 09:53:30 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> Message-ID: On Monday, August 27, 2012 8:50:15 AM UTC-7, Ulrich Eckhardt wrote: > Am 27.08.2012 03:23, schrieb bruceg113355 at gmail.com: > > > My program uses Python 2.6 and Sqlite3 and connects to a network > > > database 100 miles away. > > > > Wait, isn't SQLite completely file-based? In that case, SQLite accesses > > a file, which in turn is stored on a remote filesystem. This means that > > there are other components involved here, namely your OS, the network > > (bandwidth & latency), the network filesystem and the filesystem on the > > remote machine. It would help if you told us what you have there. > > > > > > > My program reads approx 60 records (4000 bytes) from a Sqlite > > > database in less than a second. Each time the user requests data, my > > > program can continuously read 60 records in less than a second. > > > However, if I access the network drive (e.g. DOS command DIR /S) > > > while my program is running, my program takes 20 seconds to read the > > > same 60 records. If I restart my program, my program once again takes > > > less than a second to read 60 records. > > > > Questions here: > > 1. Is each record 4kB or are all 60 records together 4kB? > > 2. Does the time for reading double when you double the number of > > records? Typically you have B + C * N, but it would be interesting to > > know the bias B and the actual time (and size) of each record. > > 3. How does the timing change when running dir/s? > > 4. What if you run two instances of your program? > > 5. Is the duration is only reset by restarting the program or does it > > also decrease when the dir/s call has finished? What if you close and > > reopen the database without terminating the program? > > > > My guess is that the concurrent access by another program causes the > > accesses to become synchronized, while before most of the data is > > cached. That would cause a complete roundtrip between the two machines > > for every access, which can easily blow up the timing via the latency. > > > > In any case, I would try Python 2.7 in case this is a bug that was > > already fixed. > > > > Good luck! > > > > Uli From jeanmichel at sequans.com Mon Aug 27 12:57:11 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 27 Aug 2012 18:57:11 +0200 Subject: What do I do to read html files on my pc? In-Reply-To: <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> <858c2da2-6936-4bd7-8944-f45446fbd3be@googlegroups.com> Message-ID: <503BA6E7.6000002@sequans.com> mikcec82 wrote: > [snip] > > > > > > > 2b) NOT PASSED, in this case I have this code: Note: color in "" can be "red" or "orange" 2c) OK or PASSED 3) Then, I need to fill an excel file following this rules: 3a) If 2a or 2b occurs on htmlfile, I'll write NOK in excel file 3b) If 2c occurs on htmlfile, I'll write OK in excel file Note: 1) In this example, in 2b case, I have "CODE CHECK" in the code, but I could also have "TEXT CHECK" or "CHAR CHECK". 2) The research of occurences can be done either by tag ("") or via (NOT PASSED, PASSED). But I would to use the first method. ================================================== In my script I have used the second way to looking for, i.e.: ** fileorig = "C:\Users\Mike\Desktop\\2012_05_16_1___p0201_13.html" f = open(fileorig, 'r') nomefile = f.read() for x in nomefile: if 'XXXX' in nomefile: print 'NOK' else : print 'OK' ** But this one works on charachters and not on strings (i.e.: in this way I have searched NOT string by string, but charachters-by-charachters). =============================================== I hope I was clear. Thank for your help Michele From oscar.j.benjamin at gmail.com Tue Aug 28 08:31:52 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 28 Aug 2012 13:31:52 +0100 Subject: What do I do to read html files on my pc? In-Reply-To: References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: On Tue, 28 Aug 2012 03:09:11 -0700 (PDT), mikcec82 wrote: > f = open(fileorig, 'r') > nomefile = f.read() > for x in nomefile: > if 'XXXX' in nomefile: > print 'NOK' > else : > print 'OK' You don't need the for loop. Just do: nomefile = f.read() if 'XXXX' in nomefile: print('NOK') > ** > But this one works on charachters and not on strings (i.e.: in this way I h= > ave searched NOT string by string, but charachters-by-charachters). Oscar From michele.cecere at gmail.com Tue Aug 28 10:51:57 2012 From: michele.cecere at gmail.com (mikcec82) Date: Tue, 28 Aug 2012 07:51:57 -0700 (PDT) Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: > Hallo, > > > > I have an html file on my pc and I want to read it to extract some text. > > Can you help on which libs I have to use and how can I do it? > > > > thank you so much. > > > > Michele Hi Oscar, I tried as you said and I've developed the code as you will see. But, when I have a such situation in an html file, in wich there is a repetition of a string (XX in this case): CODE Target: 0201 CODE Read: XXXX CODE CHECK : NOT PASSED TEXT Target: 13 TEXT Read: XX TEXT CHECK : NOT PASSED CHAR Target: AA CHAR Read: XX CHAR CHECK : NOT PASSED With this code (created starting from yours) index = nomefile.find('XXXX') print 'XXXX_ found at location', index index2 = nomefile.find('XX') print 'XX_ found at location', index2 found = nomefile.find('XX') while found > -1: print "XX found at location", found found = nomefile.find('XX', found+1) I have an answer like this: XXXX_ found at location 51315 XX_ found at location 51315 XX found at location 51315 XX found at location 51316 XX found at location 51317 XX found at location 52321 XX found at location 53328 I have done it to find all occurences of 'XXXX' and 'XX' strings. But, as you can see, the script find the occurrences of XX also at locations 51315, 51316 , 51317 corresponding to string XXXX. Is there a way to search all occurences of XX avoiding XXXX location? Thank you. Michele From __peter__ at web.de Tue Aug 28 11:38:22 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Aug 2012 17:38:22 +0200 Subject: What do I do to read html files on my pc? References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: mikcec82 wrote: > Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: >> Hallo, >> >> >> >> I have an html file on my pc and I want to read it to extract some text. >> >> Can you help on which libs I have to use and how can I do it? >> >> >> >> thank you so much. >> >> >> >> Michele > > Hi Oscar, > I tried as you said and I've developed the code as you will see. > But, when I have a such situation in an html file, in wich there is a > repetition of a string (XX in this case): > CODE Target: 0201 > CODE Read: XXXX > CODE CHECK : NOT PASSED > TEXT Target: 13 > TEXT Read: XX > TEXT CHECK : NOT PASSED > CHAR Target: AA > CHAR Read: XX > CHAR CHECK : NOT PASSED > > With this code (created starting from yours) > > index = nomefile.find('XXXX') > print 'XXXX_ found at location', index > > index2 = nomefile.find('XX') > print 'XX_ found at location', index2 > > found = nomefile.find('XX') > while found > -1: > print "XX found at location", found > found = nomefile.find('XX', found+1) > > I have an answer like this: > > XXXX_ found at location 51315 > XX_ found at location 51315 > XX found at location 51315 > XX found at location 51316 > XX found at location 51317 > XX found at location 52321 > XX found at location 53328 > > I have done it to find all occurences of 'XXXX' and 'XX' strings. But, as > you can see, the script find the occurrences of XX also at locations > 51315, 51316 , 51317 corresponding to string XXXX. > > Is there a way to search all occurences of XX avoiding XXXX location? Remove the wrong positives afterwards: start = nomefile.find("XX") while start != -1: if nomefile[start:start+4] == "XXXX": start += 4 else: print "XX found at location", start start += 3 start = nomefile.find("XX", start) By the way, what do you want to do if there are runs of "X" with repeats other than 2 or 4? From bruceg113355 at gmail.com Tue Aug 28 13:25:35 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Tue, 28 Aug 2012 10:25:35 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: References: Message-ID: <36e5f80f-ff34-4f2f-a7e2-1488549f6e9b@googlegroups.com> On Tuesday, August 28, 2012 4:27:48 AM UTC-4, Cameron Simpson wrote: > On 27Aug2012 13:41, bruceg113355 at gmail.com wrote: > > | When using the database on my C Drive, Sqlite performance is great! (<1S) > > | When using the database on a network, Sqlite performance is terrible! (17S) > > > > Let me first echo everyone saying not to use SQLite on a network file. > > > > | I like your idea of trying Python 2.7 > > > > I doubt it will change anything. > > > > | Finally, the way my program is written is: > > | loop for all database records: > > | read a database record > > | process data > > | display data (via wxPython) > > | > > | Perhaps, this is a better approach: > > | read all database records > > | loop for all records: > > | process data > > | display data (via wxPython) > > > > Yes, provided the "read all database records" is a single select > > statement. In general, with any kind of remote resource you want to > > minimise the number of transactions - the to and fro part, because each > > such item tends to have latency while something is sent to and again > > receiving from. So if you can say "gimme all the records" you get one > > "unit" of latency at the start and end, versus latency around each > > record fetch. > > > > Having said all that, because SQLite works directly against the file, if > > you say to it "giev me all the records" and the file is remote, SQLite > > will probably _still_ fetch each record individually internally, gaining > > you little. > > > > This is why people are suggesting a database "server": then you can say > > "get me all the records" over the net, and the server does > > local-to-the-server file access to obtain the data. So all the "per > > record" latency is at its end, and very small. Not to mention any > > cacheing it may do. > > > > Of course, if your requirements are very simple you might be better off > > with a flat text file, possibly in CSV format, and avoid SQLite > > altogether. > > > > Cheers, > > -- > > Cameron Simpson > > > > I do not trust thee, Cage from Hell, / The reason why I cannot tell, / > > But this I know, and know full well: / I do not trust thee, Cage from Hell. > > - Leigh Ann Hussey, leighann at sybase.com, DoD#5913 Cameron, I did some testing and approach #1 is significantly faster than approach #2: Approach #1: read all database records loop for all records: process data display data (via wxPython) Approach #2: loop for all database records: read a database record process data display data (via wxPython) Various test results to read 50 records from a network drive. #1 0:00:00.078000 #2 0:00:04.219000 #1 0:00:00.875000 #2 0:00:08.031000 #1 0:00:00.063000 #2 0:00:06.109000 #1 0:00:00.078000 #2 0:00:05.110000 #1 0:00:00.156000 #2 0:00:02.625000 This explains some of my slowness issues. Note: When the network drive is behaving (not slow), approach #2 is close to approach #1. >From the site: http://www.sqlite.org/different.html ------------------------------------------------------------------------------ Most SQL database engines are implemented as a separate server process. Programs that want to access the database communicate with the server using some kind of interprocess communication (typically TCP/IP) to send requests to the server and to receive back results. SQLite does not work this way. With SQLite, the process that wants to access the database reads and writes directly from the database files on disk. There is no intermediary server process. There are advantages and disadvantages to being serverless. The main advantage is that there is no separate server process to install, setup, configure, initialize, manage, and troubleshoot. This is one reason why SQLite is a "zero-configuration" database engine. Programs that use SQLite require no administrative support for setting up the database engine before they are run. Any program that is able to access the disk is able to use an SQLite database. On the other hand, a database engine that uses a server can provide better protection from bugs in the client application - stray pointers in a client cannot corrupt memory on the server. And because a server is a single persistent process, it is able control database access with more precision, allowing for finer grain locking and better concurrency. Most SQL database engines are client/server based. Of those that are serverless, SQLite is the only one that this author knows of that allows multiple applications to access the same database at the same time. ------------------------------------------------------------------------------ Doesn't the last paragraph imply that SQLite can operate on a network drive. Thanks, Bruce From bruceg113355 at gmail.com Tue Aug 28 13:25:35 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Tue, 28 Aug 2012 10:25:35 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: References: Message-ID: <36e5f80f-ff34-4f2f-a7e2-1488549f6e9b@googlegroups.com> On Tuesday, August 28, 2012 4:27:48 AM UTC-4, Cameron Simpson wrote: > On 27Aug2012 13:41, bruceg113355 at gmail.com wrote: > > | When using the database on my C Drive, Sqlite performance is great! (<1S) > > | When using the database on a network, Sqlite performance is terrible! (17S) > > > > Let me first echo everyone saying not to use SQLite on a network file. > > > > | I like your idea of trying Python 2.7 > > > > I doubt it will change anything. > > > > | Finally, the way my program is written is: > > | loop for all database records: > > | read a database record > > | process data > > | display data (via wxPython) > > | > > | Perhaps, this is a better approach: > > | read all database records > > | loop for all records: > > | process data > > | display data (via wxPython) > > > > Yes, provided the "read all database records" is a single select > > statement. In general, with any kind of remote resource you want to > > minimise the number of transactions - the to and fro part, because each > > such item tends to have latency while something is sent to and again > > receiving from. So if you can say "gimme all the records" you get one > > "unit" of latency at the start and end, versus latency around each > > record fetch. > > > > Having said all that, because SQLite works directly against the file, if > > you say to it "giev me all the records" and the file is remote, SQLite > > will probably _still_ fetch each record individually internally, gaining > > you little. > > > > This is why people are suggesting a database "server": then you can say > > "get me all the records" over the net, and the server does > > local-to-the-server file access to obtain the data. So all the "per > > record" latency is at its end, and very small. Not to mention any > > cacheing it may do. > > > > Of course, if your requirements are very simple you might be better off > > with a flat text file, possibly in CSV format, and avoid SQLite > > altogether. > > > > Cheers, > > -- > > Cameron Simpson > > > > I do not trust thee, Cage from Hell, / The reason why I cannot tell, / > > But this I know, and know full well: / I do not trust thee, Cage from Hell. > > - Leigh Ann Hussey, leighann at sybase.com, DoD#5913 Cameron, I did some testing and approach #1 is significantly faster than approach #2: Approach #1: read all database records loop for all records: process data display data (via wxPython) Approach #2: loop for all database records: read a database record process data display data (via wxPython) Various test results to read 50 records from a network drive. #1 0:00:00.078000 #2 0:00:04.219000 #1 0:00:00.875000 #2 0:00:08.031000 #1 0:00:00.063000 #2 0:00:06.109000 #1 0:00:00.078000 #2 0:00:05.110000 #1 0:00:00.156000 #2 0:00:02.625000 This explains some of my slowness issues. Note: When the network drive is behaving (not slow), approach #2 is close to approach #1. >From the site: http://www.sqlite.org/different.html ------------------------------------------------------------------------------ Most SQL database engines are implemented as a separate server process. Programs that want to access the database communicate with the server using some kind of interprocess communication (typically TCP/IP) to send requests to the server and to receive back results. SQLite does not work this way. With SQLite, the process that wants to access the database reads and writes directly from the database files on disk. There is no intermediary server process. There are advantages and disadvantages to being serverless. The main advantage is that there is no separate server process to install, setup, configure, initialize, manage, and troubleshoot. This is one reason why SQLite is a "zero-configuration" database engine. Programs that use SQLite require no administrative support for setting up the database engine before they are run. Any program that is able to access the disk is able to use an SQLite database. On the other hand, a database engine that uses a server can provide better protection from bugs in the client application - stray pointers in a client cannot corrupt memory on the server. And because a server is a single persistent process, it is able control database access with more precision, allowing for finer grain locking and better concurrency. Most SQL database engines are client/server based. Of those that are serverless, SQLite is the only one that this author knows of that allows multiple applications to access the same database at the same time. ------------------------------------------------------------------------------ Doesn't the last paragraph imply that SQLite can operate on a network drive. Thanks, Bruce From rolfb at personalized-books.com Tue Aug 28 17:35:48 2012 From: rolfb at personalized-books.com (Rolf) Date: Tue, 28 Aug 2012 14:35:48 -0700 (PDT) Subject: ctypes - python2.7.3 vs python3.2.3 Message-ID: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> ctypes works as I would expect with python2.7.3. However, when I upgrade to python3.2.3 things don't seem to work right. Look below for details. I am not sure where I am going wrong. Shared Library ============== #include #include extern "C" { int main(); uint32_t myfunction (char **); } uint32_t myfunction (char ** _mydata) { char mydata[16]; strcpy(mydata, "Hello Dude!"); *_mydata = mydata; return 0; } int main() { return 0; } Python 2.7.3 which works as I would expect ========================================== > python2.7 -V Python 2.7.3 > cat py27.py #!/usr/bin/env python2.7 from __future__ import print_function from __future__ import unicode_literals from ctypes import * lib = CDLL('libtest.so') o_result = c_char_p() lib.myfunction(pointer(o_result)) print(repr(o_result.value)) > ./py27.py 'Hello Dude!' Python 3.2.3 return string gets mangled ======================================= > python3 -V Python 3.2.3 > cat py3.py #!/usr/bin/env python3 from ctypes import * lib = CDLL('libtest.so') o_result = c_char_p() lib.myfunction(pointer(o_result)) print(repr(o_result.value)) > ./py3.py b'\xd8\xb0y\to Dude!' Every time I run it, I get a different set of values. From gordon at panix.com Tue Aug 28 17:51:05 2012 From: gordon at panix.com (John Gordon) Date: Tue, 28 Aug 2012 21:51:05 +0000 (UTC) Subject: ctypes - python2.7.3 vs python3.2.3 References: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> Message-ID: In <18eb8025-7545-4d10-9e76-2e41deaadb69 at googlegroups.com> Rolf writes: > uint32_t myfunction (char ** _mydata) > { > char mydata[16]; > strcpy(mydata, "Hello Dude!"); > *_mydata = mydata; > return 0; > } mydata is an auto variable, which goes out of scope when myfunction() exits. *_mydata ends up pointing to garbage. -- 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 python at mrabarnett.plus.com Tue Aug 28 17:59:16 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Aug 2012 22:59:16 +0100 Subject: ctypes - python2.7.3 vs python3.2.3 In-Reply-To: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> References: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> Message-ID: <503D3F34.20809@mrabarnett.plus.com> On 28/08/2012 22:35, Rolf wrote: > ctypes works as I would expect with python2.7.3. > > However, when I upgrade to python3.2.3 things don't seem to work right. Look below for details. > > I am not sure where I am going wrong. > > Shared Library > ============== > #include > #include > > extern "C" > { > int main(); > uint32_t myfunction (char **); > } > > uint32_t myfunction (char ** _mydata) > { > char mydata[16]; > > strcpy(mydata, "Hello Dude!"); > > *_mydata = mydata; > > return 0; > } > > int main() > { > return 0; > } > [snip] What you're doing in 'myfunction' looks wrong to start with. It's returning the address of the local array 'mydata' which allocated on the stack when the function is entered. When the function is left it's deallocated, so the address becomes a dangling pointer. That it gave a reasonable result with Python 2.7.3 is down to pure luck. From nataliabidart at gmail.com Tue Aug 28 18:01:14 2012 From: nataliabidart at gmail.com (Natalia Bidart) Date: Tue, 28 Aug 2012 19:01:14 -0300 Subject: protobuf + pypy In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 6:55 PM, Pedro Larroy wrote: > Hi > > Anyone knows if it's possible to use protobuffers with pypy? Seems > there isn't much info on the web about this. So, in my experience, the easiest way to confirm if something works with PyPy (when you can't find proper bibliography in the web) is to try to install it in a pypy virtualenv [0]: (my-pypy-env)nessita at dali:~/projects/pypy/my-pypy-env$ pip install protobuf Downloading/unpacking protobuf Downloading protobuf-2.4.1.tar.gz (56Kb): 56Kb downloaded Storing download in cache at /home/nessita/.pip_download_cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fprotobuf%2Fprotobuf-2.4.1.tar.gz Running setup.py egg_info for package protobuf Requirement already satisfied (use --upgrade to upgrade): distribute in ./site-packages/distribute-0.6.24-py2.7.egg (from protobuf) Installing collected packages: protobuf Running setup.py install for protobuf Skipping installation of /home/nessita/projects/pypy/my-pypy-env/site-packages/google/__init__.py (namespace package) Installing /home/nessita/projects/pypy/my-pypy-env/site-packages/protobuf-2.4.1-py2.7-nspkg.pth Successfully installed protobuf Cleaning up... (my-pypy-env)nessita at dali:~/projects/pypy/my-pypy-env$ pypy Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:38:48) [PyPy 1.9.0 with GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``Python 2.x is not dead'' >>>> from google.protobuf import descriptor Seems to work :-) (though I have no app using it right now). Cheers, Natalia. [0] Instructions on how to create a PyPy virtualenv: http://morepypy.blogspot.com.ar/2010/08/using-virtualenv-with-pypy.html From pedro.larroy.lists at gmail.com Tue Aug 28 18:01:33 2012 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Wed, 29 Aug 2012 00:01:33 +0200 Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <9ecq38h3151mcgo92d99r4goagmrm84rm4@invalid.netcom.com> References: <36e5f80f-ff34-4f2f-a7e2-1488549f6e9b@googlegroups.com> <9ecq38h3151mcgo92d99r4goagmrm84rm4@invalid.netcom.com> Message-ID: Try incrementing the variable cursor.arraysize a lot. Pedro. On Tue, Aug 28, 2012 at 11:20 PM, Dennis Lee Bieber wrote: > On Tue, 28 Aug 2012 10:25:35 -0700 (PDT), bruceg113355 at gmail.com > declaimed the following in gmane.comp.python.general: > >> >> Doesn't the last paragraph imply that SQLite can operate on a network drive. >> > > Most anything "can operate" on a network drive... But should it? > > The main thing the documentation is explaining is that one > application accessing the database FILE does NOT LOCK OTHERS from > accessing the file. Nothing about how the file is accessed. A > low-activity web service would allow lots of people to concurrently > access it -- but the processes that are doing said access are all local > to the database file. > > Technically, M$ Access/JET (which is also file server database) also > permits multiple clients -- but the locking becomes a pain. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 18:34:11 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 15:34:11 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> This is what I have to reproduce the challenge I am having below: import csv import struct data = [] for Node in csv.reader(file('s_data.xls')): data.append(list((file('s_data.xls')))) data = struct.unpack('!B4HH', data) print "s_data.csv: ", data I tries so many format for the struct.unpack but I got this errors: Traceback (most recent call last): data = struct.unpack('!B4HH', data) struct.error: unpack requires a string argument of length 11 On Saturday, 25 August 2012 19:34:39 UTC+1, 9bizy wrote: > I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? > > > > I checked the python documentation for struct and I can seen to find any argument for this. > > > > I have data = struct.unpack('char',data) but I still get errors From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 18:35:58 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 15:35:58 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: On Saturday, 25 August 2012 20:16:54 UTC+1, MRAB wrote: > On 25/08/2012 19:34, 9bizy wrote: > > > I am trying to unpack values from sensor data I am retrieving through > > > a serial cable, but I get errors while using struct.unpack, how can I > > > use struct.unpack to unload the data in a readable format? > > > > > > I checked the python documentation for struct and I can seen to find > > > any argument for this. > > > > > > I have data = struct.unpack('char',data) but I still get errors > > > > > The format strings are described here for Python 3: > > > > http://docs.python.org/3.2/library/struct.html > > > > and here for Python 2: > > > > http://docs.python.org/2.7/library/struct.html I used this documents but they do not explain or provide an example on how to use struct.unpack for sensor data from an external source or even data from a excel sheet. From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 18:35:58 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 15:35:58 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: On Saturday, 25 August 2012 20:16:54 UTC+1, MRAB wrote: > On 25/08/2012 19:34, 9bizy wrote: > > > I am trying to unpack values from sensor data I am retrieving through > > > a serial cable, but I get errors while using struct.unpack, how can I > > > use struct.unpack to unload the data in a readable format? > > > > > > I checked the python documentation for struct and I can seen to find > > > any argument for this. > > > > > > I have data = struct.unpack('char',data) but I still get errors > > > > > The format strings are described here for Python 3: > > > > http://docs.python.org/3.2/library/struct.html > > > > and here for Python 2: > > > > http://docs.python.org/2.7/library/struct.html I used this documents but they do not explain or provide an example on how to use struct.unpack for sensor data from an external source or even data from a excel sheet. From python at mrabarnett.plus.com Tue Aug 28 18:49:50 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Aug 2012 23:49:50 +0100 Subject: issue with struct.unpack In-Reply-To: <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: <503D4B0E.6050800@mrabarnett.plus.com> On 28/08/2012 23:34, 9bizy wrote: > This is what I have to reproduce the challenge I am having below: > > > import csv > import struct > > > data = [] > > for Node in csv.reader(file('s_data.xls')): That tries to read the file as CSV, but, judging from the extension, it's in Excel's format. You don't even use what is read, i.e. Node. > data.append(list((file('s_data.xls')))) > That opens the file again and 'list' causes it to read the file as though it were a series of lines in a text file, which, as I've said, it looks like it isn't. The list of 'lines' is appended to the list 'data', so that's a list of lists. > > data = struct.unpack('!B4HH', data) > print "s_data.csv: ", data > > I tries so many format for the struct.unpack but I got this errors: > > Traceback (most recent call last): > > data = struct.unpack('!B4HH', data) > struct.error: unpack requires a string argument of length 11 > [snip] It's complaining because it's expecting a string argument but you're giving it a list instead. From python at mrabarnett.plus.com Tue Aug 28 18:53:29 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Aug 2012 23:53:29 +0100 Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> Message-ID: <503D4BE9.9040000@mrabarnett.plus.com> On 28/08/2012 23:35, 9bizy wrote: > On Saturday, 25 August 2012 20:16:54 UTC+1, MRAB wrote: >> On 25/08/2012 19:34, 9bizy wrote: >> >> > I am trying to unpack values from sensor data I am retrieving through >> >> > a serial cable, but I get errors while using struct.unpack, how can I >> >> > use struct.unpack to unload the data in a readable format? >> >> > >> >> > I checked the python documentation for struct and I can seen to find >> >> > any argument for this. >> >> > >> >> > I have data = struct.unpack('char',data) but I still get errors >> >> > >> >> The format strings are described here for Python 3: >> >> >> >> http://docs.python.org/3.2/library/struct.html >> >> >> >> and here for Python 2: >> >> >> >> http://docs.python.org/2.7/library/struct.html > > I used this documents but they do not explain or provide an example on how to use struct.unpack for sensor data from an external source or even data from a excel sheet. > If you want to read from an Excel file you should be using the 'xlrd' module. You can find it here: http://www.python-excel.org/ From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 19:01:40 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 16:01:40 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: On Tuesday, 28 August 2012 23:49:54 UTC+1, MRAB wrote: > On 28/08/2012 23:34, 9bizy wrote: > > > This is what I have to reproduce the challenge I am having below: > > > > > > > > > import csv > > > import struct > > > > > > > > > data = [] > > > > > > for Node in csv.reader(file('s_data.xls')): > > > > That tries to read the file as CSV, but, judging from the extension, > > it's in Excel's format. You don't even use what is read, i.e. Node. > > > > > data.append(list((file('s_data.xls')))) > > > > > That opens the file again and 'list' causes it to read the file as > > though it were a series of lines in a text file, which, as I've said, > > it looks like it isn't. The list of 'lines' is appended to the list > > 'data', so that's a list of lists. > > > > > > data = struct.unpack('!B4HH', data) > > > print "s_data.csv: ", data > > > > > > I tries so many format for the struct.unpack but I got this errors: > > > > > > Traceback (most recent call last): > > > > > > data = struct.unpack('!B4HH', data) > > > struct.error: unpack requires a string argument of length 11 > > > > > [snip] > > It's complaining because it's expecting a string argument but you're > > giving it a list instead. How do I then convert data to a string argument in this case? From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 19:01:40 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 16:01:40 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: On Tuesday, 28 August 2012 23:49:54 UTC+1, MRAB wrote: > On 28/08/2012 23:34, 9bizy wrote: > > > This is what I have to reproduce the challenge I am having below: > > > > > > > > > import csv > > > import struct > > > > > > > > > data = [] > > > > > > for Node in csv.reader(file('s_data.xls')): > > > > That tries to read the file as CSV, but, judging from the extension, > > it's in Excel's format. You don't even use what is read, i.e. Node. > > > > > data.append(list((file('s_data.xls')))) > > > > > That opens the file again and 'list' causes it to read the file as > > though it were a series of lines in a text file, which, as I've said, > > it looks like it isn't. The list of 'lines' is appended to the list > > 'data', so that's a list of lists. > > > > > > data = struct.unpack('!B4HH', data) > > > print "s_data.csv: ", data > > > > > > I tries so many format for the struct.unpack but I got this errors: > > > > > > Traceback (most recent call last): > > > > > > data = struct.unpack('!B4HH', data) > > > struct.error: unpack requires a string argument of length 11 > > > > > [snip] > > It's complaining because it's expecting a string argument but you're > > giving it a list instead. How do I then convert data to a string argument in this case? From tim at akwebsoft.com Tue Aug 28 19:29:50 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 28 Aug 2012 15:29:50 -0800 Subject: popen4 - get exit status In-Reply-To: <76mo38heqavlv4huh4jvl1si57jb62tnnu@invalid.netcom.com> References: <20120827223938.GZ35917@mail.akwebsoft.com> <20120827234359.GA35917@mail.akwebsoft.com> <76mo38heqavlv4huh4jvl1si57jb62tnnu@invalid.netcom.com> Message-ID: <20120828232950.GE35917@mail.akwebsoft.com> * Dennis Lee Bieber [120828 07:11]: > On Mon, 27 Aug 2012 15:43:59 -0800, Tim Johnson > declaimed the following in gmane.comp.python.general: > > > * Benjamin Kaplan [120827 15:20]: > > > The popen* functions are deprecated. You should use the subprocess module > > > instead. > > No, I'm stuck with py 2.4 on one of the servers I'm using and > > Shouldn't be a problem: > > -=-=-=- > 17.1 subprocess -- Subprocess management > > New in version 2.4. Thanks Dennis, I had misread the docs, you're right - after rereading them I has able to implement subprocess - glad to have it as I no longer have any servers to 'service' with anything older than 2.4. And Ben, please accept my apologies for seeming so dismissive. cheers tj > The subprocess module allows you to spawn new processes, connect to > their input/output/error pipes, and obtain their return codes. This > module intends to replace several other, older modules and functions, > such as: > -=-=-=- > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From python at mrabarnett.plus.com Tue Aug 28 19:36:20 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 Aug 2012 00:36:20 +0100 Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: <503D55F4.4000300@mrabarnett.plus.com> On 29/08/2012 00:01, 9bizy wrote:> On Tuesday, 28 August 2012 23:49:54 UTC+1, MRAB wrote: >> On 28/08/2012 23:34, 9bizy wrote: >> > This is what I have to reproduce the challenge I am having below: >> > >> > import csv >> > import struct >> > >> > data = [] >> > >> > for Node in csv.reader(file('s_data.xls')): >> >> That tries to read the file as CSV, but, judging from the extension, >> it's in Excel's format. You don't even use what is read, i.e. Node. >> >> > data.append(list((file('s_data.xls')))) >> > >> That opens the file again and 'list' causes it to read the file as >> though it were a series of lines in a text file, which, as I've said, >> it looks like it isn't. The list of 'lines' is appended to the list >> 'data', so that's a list of lists. >> > >> > data = struct.unpack('!B4HH', data) >> > print "s_data.csv: ", data >> > >> > I tries so many format for the struct.unpack but I got this errors: >> > >> > Traceback (most recent call last): >> > >> > data = struct.unpack('!B4HH', data) >> > struct.error: unpack requires a string argument of length 11 >> > >> [snip] >> It's complaining because it's expecting a string argument but you're >> giving it a list instead. > > How do I then convert data to a string argument in this case? > The question is: what are you trying to do? If you're trying to read an Excel file, then you should be trying the 'xlrd' module. You can find it here: http://www.python-excel.org/ If your trying to 'decode' a binary file, then you should open it in binary mode (with "rb"), read (some of) it as a byte string and then pass it to struct.unpack. From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 19:55:13 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 16:55:13 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: On Wednesday, 29 August 2012 00:36:40 UTC+1, MRAB wrote: > On 29/08/2012 00:01, 9bizy wrote:> On Tuesday, 28 August 2012 23:49:54 > > UTC+1, MRAB wrote: > > >> On 28/08/2012 23:34, 9bizy wrote: > > >> > This is what I have to reproduce the challenge I am having below: > > >> > > > >> > import csv > > >> > import struct > > >> > > > >> > data = [] > > >> > > > >> > for Node in csv.reader(file('s_data.xls')): > > >> > > >> That tries to read the file as CSV, but, judging from the extension, > > >> it's in Excel's format. You don't even use what is read, i.e. Node. > > >> > > >> > data.append(list((file('s_data.xls')))) > > >> > > > >> That opens the file again and 'list' causes it to read the file as > > >> though it were a series of lines in a text file, which, as I've said, > > >> it looks like it isn't. The list of 'lines' is appended to the list > > >> 'data', so that's a list of lists. > > >> > > > >> > data = struct.unpack('!B4HH', data) > > >> > print "s_data.csv: ", data > > >> > > > >> > I tries so many format for the struct.unpack but I got this errors: > > >> > > > >> > Traceback (most recent call last): > > >> > > > >> > data = struct.unpack('!B4HH', data) > > >> > struct.error: unpack requires a string argument of length 11 > > >> > > > >> [snip] > > >> It's complaining because it's expecting a string argument but you're > > >> giving it a list instead. > > > > > > How do I then convert data to a string argument in this case? > > > > > The question is: what are you trying to do? > > > > If you're trying to read an Excel file, then you should be trying the > > 'xlrd' module. You can find it here: http://www.python-excel.org/ > > > > If your trying to 'decode' a binary file, then you should open it in > > binary mode (with "rb"), read (some of) it as a byte string and then > > pass it to struct.unpack. Thank you MRAB this was helpful. From a.m.akingbulu-11 at student.lboro.ac.uk Tue Aug 28 19:55:13 2012 From: a.m.akingbulu-11 at student.lboro.ac.uk (9bizy) Date: Tue, 28 Aug 2012 16:55:13 -0700 (PDT) Subject: issue with struct.unpack In-Reply-To: References: <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com> <5653b3e0-1e37-4f70-8257-6630eacdce5f@googlegroups.com> Message-ID: On Wednesday, 29 August 2012 00:36:40 UTC+1, MRAB wrote: > On 29/08/2012 00:01, 9bizy wrote:> On Tuesday, 28 August 2012 23:49:54 > > UTC+1, MRAB wrote: > > >> On 28/08/2012 23:34, 9bizy wrote: > > >> > This is what I have to reproduce the challenge I am having below: > > >> > > > >> > import csv > > >> > import struct > > >> > > > >> > data = [] > > >> > > > >> > for Node in csv.reader(file('s_data.xls')): > > >> > > >> That tries to read the file as CSV, but, judging from the extension, > > >> it's in Excel's format. You don't even use what is read, i.e. Node. > > >> > > >> > data.append(list((file('s_data.xls')))) > > >> > > > >> That opens the file again and 'list' causes it to read the file as > > >> though it were a series of lines in a text file, which, as I've said, > > >> it looks like it isn't. The list of 'lines' is appended to the list > > >> 'data', so that's a list of lists. > > >> > > > >> > data = struct.unpack('!B4HH', data) > > >> > print "s_data.csv: ", data > > >> > > > >> > I tries so many format for the struct.unpack but I got this errors: > > >> > > > >> > Traceback (most recent call last): > > >> > > > >> > data = struct.unpack('!B4HH', data) > > >> > struct.error: unpack requires a string argument of length 11 > > >> > > > >> [snip] > > >> It's complaining because it's expecting a string argument but you're > > >> giving it a list instead. > > > > > > How do I then convert data to a string argument in this case? > > > > > The question is: what are you trying to do? > > > > If you're trying to read an Excel file, then you should be trying the > > 'xlrd' module. You can find it here: http://www.python-excel.org/ > > > > If your trying to 'decode' a binary file, then you should open it in > > binary mode (with "rb"), read (some of) it as a byte string and then > > pass it to struct.unpack. Thank you MRAB this was helpful. From AWasilenko at gmail.com Tue Aug 28 20:04:49 2012 From: AWasilenko at gmail.com (Adam W.) Date: Tue, 28 Aug 2012 17:04:49 -0700 (PDT) Subject: Sending USB commands with Python Message-ID: So I'm trying to get as low level as I can with my Dymo label printer, and this method described the PDF http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf seems to be it. I'm unfamiliar with dealing with the USB interface and would greatly appreciate it if someone could tell me how to send and receive these commands with Python. Perhaps if you were feeling generous and wanted to write a bit of sample code, sending the "Get Printer Status" command and receiving the response (page 17 of the PDF) would be perfect to get me on my way. Thanks, Adam From jason.swails at gmail.com Tue Aug 28 21:34:49 2012 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 28 Aug 2012 21:34:49 -0400 Subject: Make error when installing Python 1.5 In-Reply-To: <503ad362$0$1555$c3e8da3$76491128@news.astraweb.com> References: <503ad362$0$1555$c3e8da3$76491128@news.astraweb.com> Message-ID: On Sun, Aug 26, 2012 at 9:54 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Yes, you read the subject line right -- Python 1.5. Yes, I am nuts ;) > > (I like having old versions of Python around for testing historical > behaviour.) > > On Debian squeeze, when I try to build Python 1.5, I get this error: > > fileobject.c:590: error: conflicting types for ?getline? > /usr/include/stdio.h:651: note: previous declaration of ?getline? was here > make[1]: *** [fileobject.o] Error 1 > make[1]: Leaving directory `/home/steve/personal/python/Python-1.5.2/ > Objects' > make: *** [Objects] Error 2 > FWIW, I got the same error when I tried (Gentoo, with both GCC 4.1.2 and 4.5.3), and it worked just fine when I tried it on a CentOS 5 machine (consistent with your observations). There's a reasonably easy fix, though, that appears to work. You will need the compile line for that source file (and you'll need to go into the Objects/ dir). For me it was: gcc -g -O2 -I./../Include -I.. -DHAVE_CONFIG_H -c -o fileobject.o fileobject.c Following Cameron's advice, use the -E flag to produce a pre-processed source file, such as the command below: gcc -E -g -O2 -I./../Include -I.. -DHAVE_CONFIG_H -c -o fileobject_.c fileobject.c Edit this fileobject_.c file and remove the stdio prototype of getline. Then recompile using the original compile line (on fileobject_.c): gcc -g -O2 -I./../Include -I.. -DHAVE_CONFIG_H -c -o fileobject.o fileobject_.c For me this finishes fine. Then go back to the top-level directory and resume "make". It finished for me (and seems to be working): Batman src # python1.5 Python 1.5.2 (#1, Aug 28 2012, 20:13:23) [GCC 4.5.3] on linux3 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import sys >>> dir(sys) ['__doc__', '__name__', '__stderr__', '__stdin__', '__stdout__', 'argv', 'builtin_module_names', 'copyright', 'exc_info', 'exc_type', 'exec_prefix', 'executable', 'exit', 'getrefcount', 'hexversion', 'maxint', 'modules', 'path', 'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setprofile', 'settrace', 'stderr', 'stdin', 'stdout', 'version'] >>> sys.version '1.5.2 (#1, Aug 28 2012, 20:13:23) [GCC 4.5.3]' >>> Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-excel at raf.org Tue Aug 28 22:16:46 2012 From: python-excel at raf.org (python-excel at raf.org) Date: Wed, 29 Aug 2012 12:16:46 +1000 Subject: xlrd-0.8.0 .xlsx formatting_info=True not imlemented In-Reply-To: <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> Message-ID: <20120829021646.GA8163@raf.org> hi, i just tried xlrd-0.8.0 so as to be able to read xlsx files only to discover: NotImplementedError: formatting_info=True not yet implemented there's a post from 2009 stating that the current intention is to not support formatting_info: https://groups.google.com/forum/?fromgroups=#!topic/python-excel/Thso62fdiSk is that still the current intention? if so, is there any other way to tell how many digits excel would round to when displaying a floating point number? that's my only reason for needing formatting_info=True. cheers, raf From rustompmody at gmail.com Tue Aug 28 22:42:25 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 28 Aug 2012 19:42:25 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: On Aug 28, 4:57?am, Neil Hodgson wrote: > wxjmfa... at gmail.com: > > > Go "has" the integers int32 and int64. A rune ensure > > the usage of int32. "Text libs" use runes. Go has only > > bytes and runes. > > ? ? ?Go's text libraries use UTF-8 encoded byte strings. Not arrays of > runes. See, for example,http://golang.org/pkg/regexp/ > > ? ? Are you claiming that UTF-8 is the optimum string representation and > therefore should be used by Python? > > ? ? Neil This whole rune/go business is a red-herring. In the other thread Peter Otten wrote: > wxjmfa... at gmail.com wrote: > > By chance and luckily, first attempt. > > c:\python32\python -m timeit "('?'*100+'?'*100).replace('?' > > , '?')" > > 1000000 loops, best of 3: 1.48 usec per loop > > c:\python33\python -m timeit "('?'*100+'?'*100).replace('?' > > , '?')" > > 100000 loops, best of 3: 7.62 usec per loop > > OK, that is roughly factor 5. Let's see what I get: > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > 100000 loops, best of 3: 1.8 usec per loop > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > 10000 loops, best of 3: 9.11 usec per loop > > That is factor 5, too. So I can replicate your measurement on an AMD64 Linux > system with self-built 3.3 versus system 3.2. > > > Note > > The used characters are not members of the latin-1 coding > > scheme (btw an *unusable* coding). > > They are however charaters in cp1252 and mac-roman. > > You seem to imply that the slowdown is connected to the inability of latin-1 > to encode "?" and "?" (to take the examples relevant to the above > microbench). So let's repeat with latin-1 characters: > > $ python3.2 -m timeit '("?"*100+"?"*100).replace("?", "?")' > 100000 loops, best of 3: 1.76 usec per loop > $ python3.3 -m timeit '("?"*100+"?"*100).replace("?", "?")' > 10000 loops, best of 3: 10.3 usec per loop > > Hm, the slowdown is even a tad bigger. So we can safely dismiss your theory > that an unfortunate choice of the 8 bit encoding is causing it. Do you In summary: 1. The problem is not on jmf's computer 2. It is not windows-only 3. It is not directly related to latin-1 encodable or not The only question which is not yet clear is this: Given a typical string operation that is complexity O(n), in more detail it is going to be O(a + bn) If only a is worse going 3.2 to 3.3, it may be a small issue. If b is worse by even a tiny amount, it is likely to be a significant regression for some use-cases. So doing some arm-chair thinking (I dont know the code and difficulty involved): Clearly there are 3 string-engines in the python 3 world: - 3.2 narrow - 3.2 wide - 3.3 (flexible) How difficult would it be to giving the choice of string engine as a command-line flag? This would avoid the nuisance of having two binaries -- narrow and wide. And it would give the python programmer a choice of efficiency profiles. From jmazzonelli at gmail.com Tue Aug 28 22:53:30 2012 From: jmazzonelli at gmail.com (Jorge Mazzonelli) Date: Tue, 28 Aug 2012 23:53:30 -0300 Subject: Sending USB commands with Python In-Reply-To: References: Message-ID: Hi, I recommend the use of the module PyUSB in sourceforge: http://pyusb.sourceforge.net/ Also take a look to the tutorial : http://pyusb.sourceforge.net/docs/1.0/tutorial.html as far as I can remember, you'll need to first find the device based on the idvendor / idproduct (provided in the pdf). then you'll need to setup the configuration (usually the default but on your case you'll need to check which one, since the doc says there are 2 exposed). then the endpoints. (all of this is on the tutorial) With that you need to write the command and then read the result from the endpoints. The status command you want will be 0x1B 0x41. Hope this helps. Jorge On Tue, Aug 28, 2012 at 9:04 PM, Adam W. wrote: > So I'm trying to get as low level as I can with my Dymo label printer, and > this method described the PDF > http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdfseems to be it. > > I'm unfamiliar with dealing with the USB interface and would greatly > appreciate it if someone could tell me how to send and receive these > commands with Python. Perhaps if you were feeling generous and wanted to > write a bit of sample code, sending the "Get Printer Status" command and > receiving the response (page 17 of the PDF) would be perfect to get me on > my way. > > Thanks, > Adam > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- (\__/) (='.'=)This is Bunny. Copy and paste bunny into your (")_(")signature to help him gain world domination. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hamilton at nothere.com Tue Aug 28 23:03:38 2012 From: hamilton at nothere.com (hamilton) Date: Tue, 28 Aug 2012 21:03:38 -0600 Subject: Sending USB commands with Python In-Reply-To: References: Message-ID: On 8/28/2012 8:54 PM, Dennis Lee Bieber wrote: > 2) does the printer appear as a serial port by the OS? Or as a > printer device? The OP posted the link to the manual. If your not going to at least look it over, ......... USB Printer Interface The LabelWriter 450 series printers all communicate with the host computer using a full-speed USB 2.0 interface. This interface also operates with USB Version 1.1 or later. The printers implement the standard USB Printer Class Device interface for communications (see http://www.usb.org/developers/devclass/). hamilton PS: Page 14 From rosuav at gmail.com Tue Aug 28 23:59:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Aug 2012 13:59:27 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: On Wed, Aug 29, 2012 at 12:42 PM, rusi wrote: > Clearly there are 3 string-engines in the python 3 world: > - 3.2 narrow > - 3.2 wide > - 3.3 (flexible) > > How difficult would it be to giving the choice of string engine as a > command-line flag? > This would avoid the nuisance of having two binaries -- narrow and > wide. > And it would give the python programmer a choice of efficiency > profiles. To what benefit? 3.2 narrow is, I would have to say, buggy. It handles everything up to \uFFFF without problems, but once you have any character beyond that, your indexing and slicing are wrong. 3.2 wide is fine but memory-inefficient. 3.3 is never worse than 3.2 except for some tiny checks, and will be more memory-efficient in many cases. Supporting narrow would require fixing the handling of surrogates. Potentially a huge job, and you'll end up with ridiculous performance in many cases. So what you're really asking for is a command-line option to force all strings to have their 'kind' set to 11, UCS-4 storage. That would be doable, I suppose; it wouldn't require many changes (just a quick check in string creation functions). But what would be the advantage? Every string requires 4 bytes per character to store; an optimization has been lost. ChrisA From robertmiles at teranews.com Wed Aug 29 00:04:15 2012 From: robertmiles at teranews.com (Robert Miles) Date: Tue, 28 Aug 2012 23:04:15 -0500 Subject: the meaning of =?ISO-8859-1?Q?r=3F=2E=2E=2E=2E=2E=2E=2E=EF=BE?= In-Reply-To: References: <500d0632$0$1504$c3e8da3$76491128@news.astraweb.com> Message-ID: <6yg%r.3292$u87.794@newsfe02.iad> On 7/23/2012 1:10 PM, Dennis Lee Bieber wrote: > On Mon, 23 Jul 2012 16:42:51 +0200, Henrik Faber > declaimed the following in gmane.comp.python.general: > >> >> If that was written by my coworkers, I'd strangle them. >> > My first real assignment, 31 years ago, was porting an application > to CDC MP-60 FORTRAN (what I called "FORTRAN MINUS TWO"). This was a > minimal FORTRAN implementation in which one could not do things like: > > ix = 20 > call xyz(ix, ix+2, ix-2) > > forcing us to produce such abominations as > > ix = 20 > > jinx = ix + 2 > minx = ix - 2 > > call xyz(ix, jinx, minx) > One of my first jobs involved helping maintain a Fortran program originally written for an early IBM 360 with only 64 kilobytes of memory. It included an assembler routine to do double precision floating point (that early computer couldn't do it as hardware instructions) and another assembler routine to do dynamic overlays - load one more subroutine into memory just before calling it (and then usually overwriting it with the next subroutine to be called after finishing the first one). Originally, the computer operators had to reload the operating system when this program finished, because it had to overwrite the operating system in order to have enough memory to run. When I worked on it, it ran under IBM's DOS (for mainframes). I never saw any attempts to make it run under Microsoft's DOS (for microcomputers). From ian.g.kelly at gmail.com Wed Aug 29 00:15:31 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Aug 2012 22:15:31 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: On Tue, Aug 28, 2012 at 8:42 PM, rusi wrote: > In summary: > 1. The problem is not on jmf's computer > 2. It is not windows-only > 3. It is not directly related to latin-1 encodable or not > > The only question which is not yet clear is this: > Given a typical string operation that is complexity O(n), in more > detail it is going to be O(a + bn) > If only a is worse going 3.2 to 3.3, it may be a small issue. > If b is worse by even a tiny amount, it is likely to be a significant > regression for some use-cases. As has been pointed out repeatedly already, this is a microbenchmark. jmf is focusing in one one particular area (string construction) where Python 3.3 happens to be slower than Python 3.2, ignoring the fact that real code usually does lots of things other than building strings, many of which are slower to begin with. In the real-world benchmarks that I've seen, 3.3 is as fast as or faster than 3.2. Here's a much more realistic benchmark that nonetheless still focuses on strings: word counting. Source: http://pastebin.com/RDeDsgPd C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc" "wc.wc('unilang8.htm')" 1000 loops, best of 3: 310 usec per loop C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc" "wc.wc('unilang8.htm')" 1000 loops, best of 3: 302 usec per loop "unilang8.htm" is an arbitrary UTF-8 document containing a broad swath of Unicode characters that I pulled off the web. Even though this program is still mostly string processing, Python 3.3 wins. Of course, that's not really a very good test -- since it reads the file on every pass, it probably spends more time in I/O than it does in actual processing. Let's try it again with prepared string data: C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = open('unilang8.htm', 'r', encoding ='utf-8').read()" "wc.wc_str(t)" 10000 loops, best of 3: 87.3 usec per loop C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = open('unilang8.htm', 'r', encoding ='utf-8').read()" "wc.wc_str(t)" 10000 loops, best of 3: 84.6 usec per loop Nope, 3.3 still wins. And just for the sake of my own curiosity, I decided to try it again using str.split() instead of a StringIO. Since str.split() creates more strings, I expect Python 3.2 might actually win this time. C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = open('unilang8.htm', 'r', encoding ='utf-8').read()" "wc.wc_split(t)" 10000 loops, best of 3: 88 usec per loop C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = open('unilang8.htm', 'r', encoding ='utf-8').read()" "wc.wc_split(t)" 10000 loops, best of 3: 76.5 usec per loop Interestingly, although Python 3.2 performs the splits in about the same time as the StringIO operation, Python 3.3 is significantly *faster* using str.split(), at least on this data set. > So doing some arm-chair thinking (I dont know the code and difficulty > involved): > > Clearly there are 3 string-engines in the python 3 world: > - 3.2 narrow > - 3.2 wide > - 3.3 (flexible) > > How difficult would it be to giving the choice of string engine as a > command-line flag? > This would avoid the nuisance of having two binaries -- narrow and > wide. Quite difficult. Even if we avoid having two or three separate binaries, we would still have separate binary representations of the string structs. It makes the maintainability of the software go down instead of up. > And it would give the python programmer a choice of efficiency > profiles. So instead of having just one test for my Unicode-handling code, I'll now have to run that same test *three times* -- once for each possible string engine option. Choice isn't always a good thing. Cheers, Ian From wuwei23 at gmail.com Wed Aug 29 01:04:50 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 28 Aug 2012 22:04:50 -0700 (PDT) Subject: Sending USB commands with Python References: Message-ID: <370e4ff0-80bd-44fb-8b93-00e44f53587c@ou2g2000pbc.googlegroups.com> On Aug 29, 1:03?pm, hamilton wrote: > The OP posted the link to the manual. > If your not going to at least look it over, ......... Speaking for myself, I _don't_ go out of my way to read extra material to help someone with a problem here. If it's worth mentioning, mention it in the question. From hamilton at nothere.com Wed Aug 29 01:18:01 2012 From: hamilton at nothere.com (hamilton) Date: Tue, 28 Aug 2012 23:18:01 -0600 Subject: Sending USB commands with Python In-Reply-To: <370e4ff0-80bd-44fb-8b93-00e44f53587c@ou2g2000pbc.googlegroups.com> References: <370e4ff0-80bd-44fb-8b93-00e44f53587c@ou2g2000pbc.googlegroups.com> Message-ID: On 8/28/2012 11:04 PM, alex23 wrote: > On Aug 29, 1:03 pm, hamilton wrote: >> The OP posted the link to the manual. >> If your not going to at least look it over, ......... > > Speaking for myself, I _don't_ go out of my way to read extra material But, you will give advice that has no value. Anything you post here from now on will be suspect. hamilton From killet at killetsoft.de Wed Aug 29 01:51:12 2012 From: killet at killetsoft.de (Fred) Date: Tue, 28 Aug 2012 22:51:12 -0700 (PDT) Subject: Geodetic functions library GeoDLL 32 Bit and 64 Bit Message-ID: <50b20784-307e-41ba-ab7f-d31ce0396e23@googlegroups.com> Hi developers, who develops programs with geodetic functionality like world-wide coordinate transformations or distance calculations, can use geodetic functions of my GeoDLL. The Dynamic Link Library can easily be used with most of the modern programming languages like C, C++, C#, Basic, Delphi, Pascal, Java, Fortran, Visual-Objects and others to add geodetic functionality to own applications. For many programming languages ?appropriate Interfaces are available. GeoDLL supports 2D and 3D coordinate transformation, geodetic datum shift and reference system convertion with Helmert, Molodenski and NTv2 (e.g. BeTA2007, AT_GIS_GRID, CHENYX06), meridian strip changing, user defined coordinate and reference systems, distance calculation, Digital Elevation Model, INSPIRE support, Direct / Inverse Solutions and a lot of other geodetic functions. The DLL is very fast, save and compact because of forceful development in C++ with Microsoft Visual Studio 2010. The geodetic functions of the current version 12.35 are available in 32bit and 64bit architecture. All functions are prepared for multithreading and server operating. You find a free downloadable test version on http://www.killetsoft.de/p_gdlb_e.htm Notes about the NTv2 support can be found here: http://www.killetsoft.de/p_gdln_e.htm Report on the quality of the coordinate transformations: http://www.killetsoft.de/t_1005_e.htm Fred Email: info_at_killetsoft.de From georger.silva at gmail.com Wed Aug 29 02:01:59 2012 From: georger.silva at gmail.com (George Silva) Date: Wed, 29 Aug 2012 03:01:59 -0300 Subject: Geodetic functions library GeoDLL 32 Bit and 64 Bit In-Reply-To: <50b20784-307e-41ba-ab7f-d31ce0396e23@googlegroups.com> References: <50b20784-307e-41ba-ab7f-d31ce0396e23@googlegroups.com> Message-ID: Hi Fred. Do you know about proj4? proj4 is opensource library that does the coordinate transformations side of geospatial for many many already tested projects. Does your libraries do anything that proj4 does not? On Wed, Aug 29, 2012 at 2:51 AM, Fred wrote: > Hi developers, > > who develops programs with geodetic functionality like world-wide > coordinate transformations or distance calculations, can use geodetic > functions of my GeoDLL. The Dynamic Link Library can easily be used with > most of the modern programming languages like C, C++, C#, Basic, Delphi, > Pascal, Java, Fortran, Visual-Objects and others to add geodetic > functionality to own applications. For many programming languages > appropriate Interfaces are available. > > GeoDLL supports 2D and 3D coordinate transformation, geodetic datum shift > and reference system convertion with Helmert, Molodenski and NTv2 (e.g. > BeTA2007, AT_GIS_GRID, CHENYX06), meridian strip changing, user defined > coordinate and reference systems, distance calculation, Digital Elevation > Model, INSPIRE support, Direct / Inverse Solutions and a lot of other > geodetic functions. > > The DLL is very fast, save and compact because of forceful development in > C++ with Microsoft Visual Studio 2010. The geodetic functions of the > current version 12.35 are available in 32bit and 64bit architecture. All > functions are prepared for multithreading and server operating. > > You find a free downloadable test version on > http://www.killetsoft.de/p_gdlb_e.htm > Notes about the NTv2 support can be found here: > http://www.killetsoft.de/p_gdln_e.htm > Report on the quality of the coordinate transformations: > http://www.killetsoft.de/t_1005_e.htm > > Fred > Email: info_at_killetsoft.de > -- > http://mail.python.org/mailman/listinfo/python-list > -- George R. C. Silva Desenvolvimento em GIS http://geoprocessamento.net http://blog.geoprocessamento.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 29 02:45:16 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 28 Aug 2012 23:45:16 -0700 Subject: Sending USB commands with Python References: Message-ID: "Adam W." wrote: > >So I'm trying to get as low level as I can with my Dymo label printer, >and this method described the PDF >http://sites.dymo.com/Documents/LW450_Series_Technical_Reference.pdf >seems to be it. > >I'm unfamiliar with dealing with the USB interface and would greatly >appreciate it if someone could tell me how to send and receive these >commands with Python. Perhaps if you were feeling generous and >wanted to write a bit of sample code, sending the "Get Printer >Status" command and receiving the response (page 17 of the PDF) >would be perfect to get me on my way. Well, it's more than "a bit of sample code". You would essentially be writing a device driver. Which operating system are you using? If you are on Windows, then the operating system has already loaded a printer driver for this device. You can't talk to the USB pipes without uninstalling that driver. It would be just about as easy for you to learn to use GDI to write to the printer like a normal application, and that way the code would work on the NEXT generation of printer, too. The libusb or libusbx libraries can be used to talk to USB devices. There is a Python binding. On Windows, you still need to have a driver, but the libusbx instructions can help you find an install one. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mablanga2010 at gmail.com Wed Aug 29 03:57:04 2012 From: mablanga2010 at gmail.com (Mario Blanco) Date: Wed, 29 Aug 2012 00:57:04 -0700 Subject: IDE of the all python version installed cant uploaded Message-ID: I have from time ago installed Python 2.6, 2.7, 3.2 and the last 3.3 beta but now I can upload the window version not the prompt command some advice is needed i desintalled and reinstall and nothing!! thanks in advance Mario -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Aug 29 04:05:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Aug 2012 08:05:10 GMT Subject: Flexible string representation, unicode, typography, ... References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: <503dcd35$0$9416$c3e8da3$76491128@news.astraweb.com> On Tue, 28 Aug 2012 22:15:31 -0600, Ian Kelly wrote: > On Tue, Aug 28, 2012 at 8:42 PM, rusi wrote: >> How difficult would it be to giving the choice of string engine as a >> command-line flag? >> This would avoid the nuisance of having two binaries -- narrow and >> wide. > > Quite difficult. Even if we avoid having two or three separate > binaries, we would still have separate binary representations of the > string structs. It makes the maintainability of the software go down > instead of up. In fairness, there are already multiple binary representations of strings in Python 3.3: - ASCII-only strings use a 1-byte format (PyASCIIObject); - Compact Unicode objects (PyCompactObject), which if I'm reading correctly, appears to use a non-fixed width UTF-8 format, but are only used when the string length and maximum character are known ahead of time; - Legacy string objects (PyUnicodeObject), which are not compact, and which may use as their internal format: * 1-byte characters for Latin1-compatible strings; * 2-byte UCS-2 characters for strings in the Basic Multilingual Plane; * 4-byte UCS-4 characters for strings with at least one non-BMP character. http://www.python.org/dev/peps/pep-0393/#specification By my calculations, that makes *five* different internal formats for strings, at least two of which are capable of representing all Unicode characters. I don't think it would add that much additional complexity to have a runtime option --always-wide-strings to always use the UCS-4 format. For, you know, crazy people with more memory than sense. But I don't think there's any point in exposing further runtime options to choose the string representation: - neither the ASCII nor Latin1 representations can store arbitrary Unicode chars, so they're out; - the UTF-8 format is only used under restrictive circumstances, and so is (probably?) unsuitable for all strings. - the UCS-2 format can, by using surrogate pairs, but that's troublesome to get right, some might even say buggy. >> And it would give the python programmer a choice of efficiency >> profiles. > > So instead of having just one test for my Unicode-handling code, I'll > now have to run that same test *three times* -- once for each possible > string engine option. Choice isn't always a good thing. There is that too. -- Steven From rikardhulten at gmail.com Wed Aug 29 06:18:45 2012 From: rikardhulten at gmail.com (rikardhulten at gmail.com) Date: Wed, 29 Aug 2012 03:18:45 -0700 (PDT) Subject: Can I get logging.FileHandler to close the file on each emit? Message-ID: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event. On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event? If not, would the correct thing to do be to write my own LogHandler with this behavior? / Rikard From rakhi4u1234 at gmail.com Wed Aug 29 06:21:49 2012 From: rakhi4u1234 at gmail.com (Rakesh Rocker RuLZzz) Date: Wed, 29 Aug 2012 03:21:49 -0700 (PDT) Subject: Issue installing pyopencv in mac Message-ID: I tried installing pyopencv in mac but i gives me an error I have installed all the dependent softwares like opencv,boost, etc....still unable to fix it. also i have updated xcode and using python 2.7 I also tried using mac port but still no use can anybody help me....Thanks in advance. From michele.cecere at gmail.com Wed Aug 29 06:22:26 2012 From: michele.cecere at gmail.com (mikcec82) Date: Wed, 29 Aug 2012 03:22:26 -0700 (PDT) Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: > Hallo, > > > > I have an html file on my pc and I want to read it to extract some text. > > Can you help on which libs I have to use and how can I do it? > > > > thank you so much. > > > > Michele Hi Peter and thanks for your precious help. Fortunately, there aren't runs of "X" with repeats other than 2 or 4. Starting from your code, I wrote this code (I post it, so it could be helpful for other people): f = open(fileorig, 'r') nomefile = f.read() start = nomefile.find("XX") start2 = nomefile.find("NOT PASSED") c0 = 0 c1 = 0 c2 = 0 while (start != -1) | (start2 != -1): if nomefile[start:start+4] == "XXXX": print "XXXX found at location", start start += 4 c0 +=1 elif nomefile[start:start+2] == "XX": print "XX found at location", start start += 2 c1 +=1 if nomefile[start2:start2+10] == "NOT PASSED": print "NOT PASSED found at location", start2 start2 += 10 c2 +=1 start = nomefile.find("XX", start) start2 = nomefile.find("NOT PASSED", start2) print "XXXX %s founded" % c0, "\nXX %s founded" % c1, "\nNOT PASSED %s founded" % c2 Now, I'm able to find all occurences of strings: "XXXX", "XX" and "NOT PASSED" Thank you so much. From levinie001 at gmail.com Wed Aug 29 06:32:57 2012 From: levinie001 at gmail.com (levinie001 at gmail.com) Date: Wed, 29 Aug 2012 18:32:57 +0800 Subject: Are the property Function really useful? Message-ID: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Aug 29 07:38:21 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 04:38:21 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: Le lundi 27 ao?t 2012 22:37:03 UTC+2, (inconnu) a ?crit?: > Le lundi 27 ao?t 2012 22:14:07 UTC+2, Ian a ?crit?: > > > On Mon, Aug 27, 2012 at 1:16 PM, wrote: > > > > > > > - Why int32 and not uint32? No idea, I tried to find an > > > > > > > answer without asking. > > > > > > > > > > > > UCS-4 is technically only a 31-bit encoding. The sign bit is not used, > > > > > > so the choice of int32 vs. uint32 is inconsequential. > > > > > > > > > > > > (In fact, since they made the decision to limit Unicode to the range 0 > > > > > > - 0x0010FFFF, one might even point out that the *entire high-order > > > > > > byte* as well as 3 bits of the next byte are irrelevant. Truly, > > > > > > UTF-32 is not designed for memory efficiency.) > > > > I know all this. The question is more, why not a uint32 knowing > > there are only positive code points. It seems to me more "natural". Answer found. In short: using negative ints simplifies internal tasks. From wxjmfauth at gmail.com Wed Aug 29 07:38:21 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 04:38:21 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: Le lundi 27 ao?t 2012 22:37:03 UTC+2, (inconnu) a ?crit?: > Le lundi 27 ao?t 2012 22:14:07 UTC+2, Ian a ?crit?: > > > On Mon, Aug 27, 2012 at 1:16 PM, wrote: > > > > > > > - Why int32 and not uint32? No idea, I tried to find an > > > > > > > answer without asking. > > > > > > > > > > > > UCS-4 is technically only a 31-bit encoding. The sign bit is not used, > > > > > > so the choice of int32 vs. uint32 is inconsequential. > > > > > > > > > > > > (In fact, since they made the decision to limit Unicode to the range 0 > > > > > > - 0x0010FFFF, one might even point out that the *entire high-order > > > > > > byte* as well as 3 bits of the next byte are irrelevant. Truly, > > > > > > UTF-32 is not designed for memory efficiency.) > > > > I know all this. The question is more, why not a uint32 knowing > > there are only positive code points. It seems to me more "natural". Answer found. In short: using negative ints simplifies internal tasks. From wxjmfauth at gmail.com Wed Aug 29 07:40:46 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 04:40:46 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Le mercredi 29 ao?t 2012 06:16:05 UTC+2, Ian a ?crit?: > On Tue, Aug 28, 2012 at 8:42 PM, rusi wrote: > > > In summary: > > > 1. The problem is not on jmf's computer > > > 2. It is not windows-only > > > 3. It is not directly related to latin-1 encodable or not > > > > > > The only question which is not yet clear is this: > > > Given a typical string operation that is complexity O(n), in more > > > detail it is going to be O(a + bn) > > > If only a is worse going 3.2 to 3.3, it may be a small issue. > > > If b is worse by even a tiny amount, it is likely to be a significant > > > regression for some use-cases. > > > > As has been pointed out repeatedly already, this is a microbenchmark. > > jmf is focusing in one one particular area (string construction) where > > Python 3.3 happens to be slower than Python 3.2, ignoring the fact > > that real code usually does lots of things other than building > > strings, many of which are slower to begin with. In the real-world > > benchmarks that I've seen, 3.3 is as fast as or faster than 3.2. > > Here's a much more realistic benchmark that nonetheless still focuses > > on strings: word counting. > > > > Source: http://pastebin.com/RDeDsgPd > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc" > > "wc.wc('unilang8.htm')" > > 1000 loops, best of 3: 310 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc" > > "wc.wc('unilang8.htm')" > > 1000 loops, best of 3: 302 usec per loop > > > > "unilang8.htm" is an arbitrary UTF-8 document containing a broad swath > > of Unicode characters that I pulled off the web. Even though this > > program is still mostly string processing, Python 3.3 wins. Of > > course, that's not really a very good test -- since it reads the file > > on every pass, it probably spends more time in I/O than it does in > > actual processing. Let's try it again with prepared string data: > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_str(t)" > > 10000 loops, best of 3: 87.3 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_str(t)" > > 10000 loops, best of 3: 84.6 usec per loop > > > > Nope, 3.3 still wins. And just for the sake of my own curiosity, I > > decided to try it again using str.split() instead of a StringIO. > > Since str.split() creates more strings, I expect Python 3.2 might > > actually win this time. > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_split(t)" > > 10000 loops, best of 3: 88 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_split(t)" > > 10000 loops, best of 3: 76.5 usec per loop > > > > Interestingly, although Python 3.2 performs the splits in about the > > same time as the StringIO operation, Python 3.3 is significantly > > *faster* using str.split(), at least on this data set. > > > > > > > So doing some arm-chair thinking (I dont know the code and difficulty > > > involved): > > > > > > Clearly there are 3 string-engines in the python 3 world: > > > - 3.2 narrow > > > - 3.2 wide > > > - 3.3 (flexible) > > > > > > How difficult would it be to giving the choice of string engine as a > > > command-line flag? > > > This would avoid the nuisance of having two binaries -- narrow and > > > wide. > > > > Quite difficult. Even if we avoid having two or three separate > > binaries, we would still have separate binary representations of the > > string structs. It makes the maintainability of the software go down > > instead of up. > > > > > And it would give the python programmer a choice of efficiency > > > profiles. > > > > So instead of having just one test for my Unicode-handling code, I'll > > now have to run that same test *three times* -- once for each possible > > string engine option. Choice isn't always a good thing. > > Forget Python and all these benchmarks. The problem is on an other level. Coding schemes, typography, usage of characters, ... For a given coding scheme, all code points/characters are equivalent. Expecting to handle a sub-range in a coding scheme without shaking that coding scheme is impossible. If a coding scheme does not give satisfaction, the only valid solution is to create a new coding scheme, cp1252, mac-roman, EBCDIC, ... or the interesting "TeX" case, where the "internal" coding depends on the fonts! Unicode (utf***), as just one another coding scheme, does not escape to this rule. This "Flexible String Representation" fails. Not only it is unable to stick with a coding scheme, it is a mixing of coding schemes, the worst of all possible implementations. jmf From wxjmfauth at gmail.com Wed Aug 29 07:40:46 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 04:40:46 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Le mercredi 29 ao?t 2012 06:16:05 UTC+2, Ian a ?crit?: > On Tue, Aug 28, 2012 at 8:42 PM, rusi wrote: > > > In summary: > > > 1. The problem is not on jmf's computer > > > 2. It is not windows-only > > > 3. It is not directly related to latin-1 encodable or not > > > > > > The only question which is not yet clear is this: > > > Given a typical string operation that is complexity O(n), in more > > > detail it is going to be O(a + bn) > > > If only a is worse going 3.2 to 3.3, it may be a small issue. > > > If b is worse by even a tiny amount, it is likely to be a significant > > > regression for some use-cases. > > > > As has been pointed out repeatedly already, this is a microbenchmark. > > jmf is focusing in one one particular area (string construction) where > > Python 3.3 happens to be slower than Python 3.2, ignoring the fact > > that real code usually does lots of things other than building > > strings, many of which are slower to begin with. In the real-world > > benchmarks that I've seen, 3.3 is as fast as or faster than 3.2. > > Here's a much more realistic benchmark that nonetheless still focuses > > on strings: word counting. > > > > Source: http://pastebin.com/RDeDsgPd > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc" > > "wc.wc('unilang8.htm')" > > 1000 loops, best of 3: 310 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc" > > "wc.wc('unilang8.htm')" > > 1000 loops, best of 3: 302 usec per loop > > > > "unilang8.htm" is an arbitrary UTF-8 document containing a broad swath > > of Unicode characters that I pulled off the web. Even though this > > program is still mostly string processing, Python 3.3 wins. Of > > course, that's not really a very good test -- since it reads the file > > on every pass, it probably spends more time in I/O than it does in > > actual processing. Let's try it again with prepared string data: > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_str(t)" > > 10000 loops, best of 3: 87.3 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_str(t)" > > 10000 loops, best of 3: 84.6 usec per loop > > > > Nope, 3.3 still wins. And just for the sake of my own curiosity, I > > decided to try it again using str.split() instead of a StringIO. > > Since str.split() creates more strings, I expect Python 3.2 might > > actually win this time. > > > > > > C:\Users\Ian\Desktop>c:\python32\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_split(t)" > > 10000 loops, best of 3: 88 usec per loop > > > > C:\Users\Ian\Desktop>c:\python33\python -m timeit -s "import wc; t = > > open('unilang8.htm', 'r', encoding > > ='utf-8').read()" "wc.wc_split(t)" > > 10000 loops, best of 3: 76.5 usec per loop > > > > Interestingly, although Python 3.2 performs the splits in about the > > same time as the StringIO operation, Python 3.3 is significantly > > *faster* using str.split(), at least on this data set. > > > > > > > So doing some arm-chair thinking (I dont know the code and difficulty > > > involved): > > > > > > Clearly there are 3 string-engines in the python 3 world: > > > - 3.2 narrow > > > - 3.2 wide > > > - 3.3 (flexible) > > > > > > How difficult would it be to giving the choice of string engine as a > > > command-line flag? > > > This would avoid the nuisance of having two binaries -- narrow and > > > wide. > > > > Quite difficult. Even if we avoid having two or three separate > > binaries, we would still have separate binary representations of the > > string structs. It makes the maintainability of the software go down > > instead of up. > > > > > And it would give the python programmer a choice of efficiency > > > profiles. > > > > So instead of having just one test for my Unicode-handling code, I'll > > now have to run that same test *three times* -- once for each possible > > string engine option. Choice isn't always a good thing. > > Forget Python and all these benchmarks. The problem is on an other level. Coding schemes, typography, usage of characters, ... For a given coding scheme, all code points/characters are equivalent. Expecting to handle a sub-range in a coding scheme without shaking that coding scheme is impossible. If a coding scheme does not give satisfaction, the only valid solution is to create a new coding scheme, cp1252, mac-roman, EBCDIC, ... or the interesting "TeX" case, where the "internal" coding depends on the fonts! Unicode (utf***), as just one another coding scheme, does not escape to this rule. This "Flexible String Representation" fails. Not only it is unable to stick with a coding scheme, it is a mixing of coding schemes, the worst of all possible implementations. jmf From d at davea.name Wed Aug 29 07:46:48 2012 From: d at davea.name (Dave Angel) Date: Wed, 29 Aug 2012 07:46:48 -0400 Subject: Are the property Function really useful? yes. In-Reply-To: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> References: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> Message-ID: <503E0128.5070805@davea.name> On 08/29/2012 06:32 AM, levinie001 at gmail.com wrote: -- DaveA From usharma01 at gmail.com Wed Aug 29 08:00:36 2012 From: usharma01 at gmail.com (Umesh Sharma) Date: Wed, 29 Aug 2012 05:00:36 -0700 (PDT) Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: <1770147e-cb1f-4100-9220-f3f3f4e23f04@googlegroups.com> You can use httplib library to download the html and then for extracting the text from it either you can use any library (google for it) or you can use regular expression for it . From d at davea.name Wed Aug 29 08:01:34 2012 From: d at davea.name (Dave Angel) Date: Wed, 29 Aug 2012 08:01:34 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Message-ID: <503E049E.9040606@davea.name> On 08/29/2012 07:40 AM, wxjmfauth at gmail.com wrote: > > Forget Python and all these benchmarks. The problem is on an other > level. Coding schemes, typography, usage of characters, ... For a > given coding scheme, all code points/characters are equivalent. > Expecting to handle a sub-range in a coding scheme without shaking > that coding scheme is impossible. If a coding scheme does not give > satisfaction, the only valid solution is to create a new coding > scheme, cp1252, mac-roman, EBCDIC, ... or the interesting "TeX" case, > where the "internal" coding depends on the fonts! Unicode (utf***), as > just one another coding scheme, does not escape to this rule. This > "Flexible String Representation" fails. Not only it is unable to stick > with a coding scheme, it is a mixing of coding schemes, the worst of > all possible implementations. jmf Nonsense. The discussion was not about an encoding scheme, but an internal representation. That representation does not change the programmer's interface in any way other than performance (cpu and memory usage). Most of the rest of your babble is unsupported opinion. Plonk. -- DaveA From rosuav at gmail.com Wed Aug 29 08:34:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Aug 2012 22:34:36 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Message-ID: On Wed, Aug 29, 2012 at 9:40 PM, wrote: > For a given coding scheme, all code points/characters are > equivalent. Expecting to handle a sub-range in a coding > scheme without shaking that coding scheme is impossible. Not all codepoints are equally likely. That's the whole point behind variable-length encodings like Huffman compression (eg deflation as used in zip/gzip), UTF-8, quoted-printable, and Morse code. They handle a sub-range efficiently and the rest of the range less efficiently. > If a coding scheme does not give satisfaction, the only > valid solution is to create a new coding scheme, cp1252, > mac-roman, EBCDIC, ... or the interesting "TeX" case, where > the "internal" coding depends on the fonts! http://xkcd.com/927/ > This "Flexible String Representation" fails. Not only > it is unable to stick with a coding scheme, it is > a mixing of coding schemes, the worst of all possible > implementations. I propose, then, that we abolish files. Who *knows* how many different things might be represented in a file! We need a single coding scheme that can handle everything, without changing representation. This ridiculous state of affairs must not go on; the same representation can be used for bitmapped images or raw audio data! ChrisA From AWasilenko at gmail.com Wed Aug 29 08:47:00 2012 From: AWasilenko at gmail.com (Adam W.) Date: Wed, 29 Aug 2012 05:47:00 -0700 (PDT) Subject: Sending USB commands with Python In-Reply-To: References: Message-ID: <09ec368e-9079-46dc-a70a-3ae345d7996c@googlegroups.com> On Wednesday, August 29, 2012 2:45:17 AM UTC-4, Tim Roberts wrote: > Which operating system are you using? If you are on Windows, then the > > operating system has already loaded a printer driver for this device. > > > The libusb or libusbx libraries can be used to talk to USB devices. There > > is a Python binding. On Windows, you still need to have a driver, but the > > libusbx instructions can help you find an install one. > I am on Windows and have installed a driver using libusb-win32. Using http://pyusb.sourceforge.net/docs/1.0/tutorial.html as a template, this is my code so far: import usb.core import usb.util dev = usb.core.find(idVendor=0x0922, idProduct=0x0021) # set the active configuration. With no arguments, the first # configuration will be the active one dev.set_configuration() # get an endpoint instance cfg = dev.get_active_configuration() interface_number = cfg[(0,0)].bInterfaceNumber alternate_settting = usb.control.get_interface(dev,interface_number) intf = usb.util.find_descriptor( cfg, bInterfaceNumber = interface_number, bAlternateSetting = 0 ) ep = usb.util.find_descriptor( intf, # match the first OUT endpoint custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_OUT ) assert ep is not None I had to manually set bAlternateSetting to 0 for it to run and add dev to usb.control.get_interface(dev,interface_number). Trying to do the status thing mentioned before, in the interpreter I did: >>> ep.write('A') 2 And the manual says 2 is not a valid option... So something isn't adding up. From breamoreboy at yahoo.co.uk Wed Aug 29 08:49:33 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 29 Aug 2012 13:49:33 +0100 Subject: Can I get logging.FileHandler to close the file on each emit? In-Reply-To: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> References: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> Message-ID: On 29/08/2012 11:18, rikardhulten at gmail.com wrote: > I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event. > > On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event? > > If not, would the correct thing to do be to write my own LogHandler with this behavior? > > / Rikard > I know little about the logging module but given that the FileHandler[1] has a close method, can you simply call that, delete the file and reopen where needed? Failing that I'd look at subclassing existing code and not writing your own (Your wording implies to me that you're thinking of writing something from scratch, my apologies should I be wrong on that). [1] http://docs.python.org/dev/library/logging.handlers.html -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Aug 29 08:52:07 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 29 Aug 2012 13:52:07 +0100 Subject: Issue installing pyopencv in mac In-Reply-To: References: Message-ID: On 29/08/2012 11:21, Rakesh Rocker RuLZzz wrote: > I tried installing pyopencv in mac but i gives me an error > I have installed all the dependent softwares like opencv,boost, etc....still unable to fix it. > also i have updated xcode and using python 2.7 > I also tried using mac port but still no use > > can anybody help me....Thanks in advance. > The short answer is no :) Unless you tell us exactly what you've tried and the precise error details nobody can help you. -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Wed Aug 29 08:53:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 29 Aug 2012 13:53:44 +0100 Subject: Are the property Function really useful? In-Reply-To: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> References: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> Message-ID: On 29/08/2012 11:32, levinie001 at gmail.com wrote: Rather more useful than your question :) -- Cheers. Mark Lawrence. From rikardhulten at gmail.com Wed Aug 29 08:57:11 2012 From: rikardhulten at gmail.com (rikardhulten at gmail.com) Date: Wed, 29 Aug 2012 05:57:11 -0700 (PDT) Subject: Can I get logging.FileHandler to close the file on each emit? In-Reply-To: References: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> Message-ID: <33129d14-03d2-473d-a05c-ee49c8653b3b@googlegroups.com> On Wednesday, August 29, 2012 2:48:57 PM UTC+2, Mark Lawrence wrote: > On 29/08/2012 11:18, wrote: > > > I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event. > > > > > > On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event? > > > > > > If not, would the correct thing to do be to write my own LogHandler with this behavior? > > > > > > / Rikard > > > > > > > I know little about the logging module but given that the FileHandler[1] > > has a close method, can you simply call that, delete the file and reopen > > where needed? Failing that I'd look at subclassing existing code and > > not writing your own (Your wording implies to me that you're thinking of > > writing something from scratch, my apologies should I be wrong on that). > > > > [1] http://docs.python.org/dev/library/logging.handlers.html > > > > -- > > Cheers. > > > > Mark Lawrence. I want to delete the file from outside the process while it is running, so in the code I have no idea when that is... I meant subclassing logging.Handler, which I went ahead and tried and it seems to work as I like. Basically in emit I do 1. open log file 2. write msg to it 3. close file / Rikard From rikardhulten at gmail.com Wed Aug 29 08:57:11 2012 From: rikardhulten at gmail.com (rikardhulten at gmail.com) Date: Wed, 29 Aug 2012 05:57:11 -0700 (PDT) Subject: Can I get logging.FileHandler to close the file on each emit? In-Reply-To: References: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> Message-ID: <33129d14-03d2-473d-a05c-ee49c8653b3b@googlegroups.com> On Wednesday, August 29, 2012 2:48:57 PM UTC+2, Mark Lawrence wrote: > On 29/08/2012 11:18, wrote: > > > I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event. > > > > > > On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event? > > > > > > If not, would the correct thing to do be to write my own LogHandler with this behavior? > > > > > > / Rikard > > > > > > > I know little about the logging module but given that the FileHandler[1] > > has a close method, can you simply call that, delete the file and reopen > > where needed? Failing that I'd look at subclassing existing code and > > not writing your own (Your wording implies to me that you're thinking of > > writing something from scratch, my apologies should I be wrong on that). > > > > [1] http://docs.python.org/dev/library/logging.handlers.html > > > > -- > > Cheers. > > > > Mark Lawrence. I want to delete the file from outside the process while it is running, so in the code I have no idea when that is... I meant subclassing logging.Handler, which I went ahead and tried and it seems to work as I like. Basically in emit I do 1. open log file 2. write msg to it 3. close file / Rikard From gallium.arsenide at gmail.com Wed Aug 29 09:27:01 2012 From: gallium.arsenide at gmail.com (John Yeung) Date: Wed, 29 Aug 2012 09:27:01 -0400 Subject: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not imlemented In-Reply-To: <20120829021646.GA8163@raf.org> References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> <20120829021646.GA8163@raf.org> Message-ID: > is there any other way to tell how many digits excel would round to > when displaying a floating point number? that's my only reason for > needing formatting_info=True. I have not personally used it, but OpenPyXL is another option for working with .xlsx files, and it might provide the formatting info you need: http://packages.python.org/openpyxl/index.html http://pypi.python.org/pypi/openpyxl/1.5.8 John Y. From franck at ditter.org Wed Aug 29 11:04:05 2012 From: franck at ditter.org (Franck Ditter) Date: Wed, 29 Aug 2012 17:04:05 +0200 Subject: How to program test(expr) ? Message-ID: Hi ! I use Python 3.2.3 + Idle. Is it possible to program test(e) which takes an expression e and whose execution produces at the toplevel an echo of e and the effects and result of its evaluation ? # file foo.py def foo(x) : print('x =',x) return x+1 test(foo(5)) # RUN ! # produces at the toplevel : ? foo(5) x = 5 --> 6 I know I could put the expression e within a string, but is it possible to avoid the string, like a Lisp macro ? Thanks. franck From wxjmfauth at gmail.com Wed Aug 29 11:43:05 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 08:43:05 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Message-ID: <4676a334-d558-4132-b5ec-1700502dd50f@googlegroups.com> Le mercredi 29 ao?t 2012 14:01:57 UTC+2, Dave Angel a ?crit?: > On 08/29/2012 07:40 AM, wxjmfauth at gmail.com wrote: > > > > > > > > Forget Python and all these benchmarks. The problem is on an other > > > level. Coding schemes, typography, usage of characters, ... For a > > > given coding scheme, all code points/characters are equivalent. > > > Expecting to handle a sub-range in a coding scheme without shaking > > > that coding scheme is impossible. If a coding scheme does not give > > > satisfaction, the only valid solution is to create a new coding > > > scheme, cp1252, mac-roman, EBCDIC, ... or the interesting "TeX" case, > > > where the "internal" coding depends on the fonts! Unicode (utf***), as > > > just one another coding scheme, does not escape to this rule. This > > > "Flexible String Representation" fails. Not only it is unable to stick > > > with a coding scheme, it is a mixing of coding schemes, the worst of > > > all possible implementations. jmf > > > > Nonsense. The discussion was not about an encoding scheme, but an > > internal representation. That representation does not change the > > programmer's interface in any way other than performance (cpu and memory > > usage). Most of the rest of your babble is unsupported opinion. > I can hit the nail a little more. I have even a better idea and I'm serious. If "Python" has found a new way to cover the set of the Unicode characters, why not proposing it to the Unicode consortium? Unicode has already three schemes covering practically all cases: memory consumption, maximum flexibility and an intermediate solution. It would be to bad, to not share it. What do you think? ;-) jmf From wxjmfauth at gmail.com Wed Aug 29 11:43:05 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Aug 2012 08:43:05 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Message-ID: <4676a334-d558-4132-b5ec-1700502dd50f@googlegroups.com> Le mercredi 29 ao?t 2012 14:01:57 UTC+2, Dave Angel a ?crit?: > On 08/29/2012 07:40 AM, wxjmfauth at gmail.com wrote: > > > > > > > > Forget Python and all these benchmarks. The problem is on an other > > > level. Coding schemes, typography, usage of characters, ... For a > > > given coding scheme, all code points/characters are equivalent. > > > Expecting to handle a sub-range in a coding scheme without shaking > > > that coding scheme is impossible. If a coding scheme does not give > > > satisfaction, the only valid solution is to create a new coding > > > scheme, cp1252, mac-roman, EBCDIC, ... or the interesting "TeX" case, > > > where the "internal" coding depends on the fonts! Unicode (utf***), as > > > just one another coding scheme, does not escape to this rule. This > > > "Flexible String Representation" fails. Not only it is unable to stick > > > with a coding scheme, it is a mixing of coding schemes, the worst of > > > all possible implementations. jmf > > > > Nonsense. The discussion was not about an encoding scheme, but an > > internal representation. That representation does not change the > > programmer's interface in any way other than performance (cpu and memory > > usage). Most of the rest of your babble is unsupported opinion. > I can hit the nail a little more. I have even a better idea and I'm serious. If "Python" has found a new way to cover the set of the Unicode characters, why not proposing it to the Unicode consortium? Unicode has already three schemes covering practically all cases: memory consumption, maximum flexibility and an intermediate solution. It would be to bad, to not share it. What do you think? ;-) jmf From rosuav at gmail.com Wed Aug 29 11:54:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Aug 2012 01:54:24 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <4676a334-d558-4132-b5ec-1700502dd50f@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <4676a334-d558-4132-b5ec-1700502dd50f@googlegroups.com> Message-ID: On Thu, Aug 30, 2012 at 1:43 AM, wrote: > If "Python" has found a new way to cover the set > of the Unicode characters, why not proposing it > to the Unicode consortium? Python's open source. If some other language wants to borrow the idea, they can look at the code, or alternatively, just read PEP 393 and implement something similar. It's a free world. By the way, can you please trim the quoted text in your replies? It's rather lengthy. ChrisA From mailinglists at xgm.de Wed Aug 29 12:17:18 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 29 Aug 2012 18:17:18 +0200 Subject: Cut out XML subtree Message-ID: <5184413.thaGFiKO57@horus> Hello, I have a (rather small, memory consumption is not an issue) XML document. The application is still at the planning stage, so none of the XML parsers from the stdlib is choosen yet. I want to cut out an XML subtree like that: Now I want to get the subB note including parent node, but none of sibliblings: Is there a way I can do that using etree or DOM? The first is prefered... Thanks, Florian From andipersti at gmail.com Wed Aug 29 13:31:52 2012 From: andipersti at gmail.com (Andreas Perstinger) Date: Wed, 29 Aug 2012 19:31:52 +0200 Subject: Cut out XML subtree In-Reply-To: <5184413.thaGFiKO57@horus> References: <5184413.thaGFiKO57@horus> Message-ID: <20120829193152.7ad1051892ffe40cb8fecb25@gmail.com> On Wed, 29 Aug 2012 18:17:18 +0200 Florian Lindner wrote: > I want to cut out an XML subtree like that: [snip] > Is there a way I can do that using etree or DOM? The first is > prefered... Python 3.2.2 (default, Sep 5 2011, 22:09:30) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xml.etree.ElementTree as etree >>> test = """ ... ... ... Element A.1 ... Element A.2 ... ... ... Element B.1 ... Element B.2 ... ... """ >>> tree = etree.fromstring(test) >>> subA = tree.find("subA") >>> tree.remove(subA) >>> new = etree.tostring(tree, encoding="unicode") >>> print(new) Element B.1 Element B.2 Bye, Andreas From AWasilenko at gmail.com Wed Aug 29 17:21:30 2012 From: AWasilenko at gmail.com (Adam W.) Date: Wed, 29 Aug 2012 14:21:30 -0700 (PDT) Subject: Sending USB commands with Python In-Reply-To: References: <09ec368e-9079-46dc-a70a-3ae345d7996c@googlegroups.com> Message-ID: <7507d1a4-62ba-46a9-8c6f-fe0ac9dcac5c@googlegroups.com> On Wednesday, August 29, 2012 4:09:49 PM UTC-4, Dennis Lee Bieber wrote: > > Don't the commands require an character? "\x1BA" (or > "\x1B\x41") > > OTOH, if the is issued behind the scenes, I'm not sure which esc char it is asking for, I don't think libusb is providing its own, and it seems like the one you suggested isn't what it wants either.. > ... and you do not need to issue some sort of read() > the "2" you are seeing is the "number of bytes written"; > > you need to issue a read request to retrieve the returned printer > > status. > You are correct about the 2 being the number of bytes written. However when I issue a read command I get: >>> ep.write('\x1BA') 4 >>> ep.read(1) Traceback (most recent call last): File "", line 1, in ep.read(1) File "C:\Python32\lib\site-packages\usb\core.py", line 301, in read return self.device.read(self.bEndpointAddress, size, self.interface, timeout) File "C:\Python32\lib\site-packages\usb\core.py", line 654, in read self.__get_timeout(timeout) File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 483, in bulk_read timeout) File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 568, in __read timeout File "C:\Python32\lib\site-packages\usb\backend\libusb01.py", line 384, in _check raise USBError(errmsg, ret) usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_setup_async] invalid endpoint 0x02\n' Avoiding the read command all together I should be able to write " E" and have it feed some paper, which it is not doing, so obviously there is more to uncover. That said I feel this endeavor has evolved and is no longer pertinent to the Python group so I will let you guys off the hook on this (although responses/suggestions are still welcome). Thanks for all your help! From jan.kuiken at quicknet.nl Wed Aug 29 17:25:47 2012 From: jan.kuiken at quicknet.nl (Jan Kuiken) Date: Wed, 29 Aug 2012 23:25:47 +0200 Subject: ctypes - python2.7.3 vs python3.2.3 In-Reply-To: References: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> Message-ID: <9a74$503e88dd$546bb230$30836@cache80.multikabel.net> On 8/28/12 23:51 , John Gordon wrote: > In <18eb8025-7545-4d10-9e76-2e41deaadb69 at googlegroups.com> Rolf writes: > >> uint32_t myfunction (char ** _mydata) >> { >> char mydata[16]; > >> strcpy(mydata, "Hello Dude!"); > >> *_mydata = mydata; > >> return 0; >> } > > mydata is an auto variable, which goes out of scope when myfunction() > exits. *_mydata ends up pointing to garbage. > I'm not completely sure, but i think this can be solved by using: static char mydata[16]; (Btw.: I don't know why you use char ** _mydata, i would use char * _mydata, but then again, i'm not very familiar with ctypes) Jan Kuiken From tjreedy at udel.edu Wed Aug 29 17:35:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Aug 2012 17:35:20 -0400 Subject: How to program test(expr) ? In-Reply-To: References: Message-ID: On 8/29/2012 11:04 AM, Franck Ditter wrote: > I use Python 3.2.3 + Idle. > Is it possible to program test(e) which takes > an expression e and whose execution produces > at the toplevel an echo of e and the effects > and result of its evaluation ? No, not as Python is delivered. > # file foo.py > def foo(x) : > print('x =',x) > return x+1 > > test(foo(5)) > > # RUN ! > > # produces at the toplevel : > ? foo(5) > x = 5 > --> 6 > > I know I could put the expression e within a string, but > is it possible to avoid the string, like a Lisp macro ? It might be possible to write an IDLE extension that would 'process' interactive input looking for (untested) re pattern something like 'test\((.*)\)'. Given a match, it prints the captured .* part and passes it on to the Python interpreter, and prefixes output with '-->'. (I have not yet looked at how to write extensions.) -- Terry Jan Reedy From cs at zip.com.au Wed Aug 29 18:29:32 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 30 Aug 2012 08:29:32 +1000 Subject: Sending USB commands with Python In-Reply-To: References: Message-ID: <20120829222932.GA18700@cskk.homeip.net> On 29Aug2012 17:57, Dennis Lee Bieber wrote: | On Wed, 29 Aug 2012 14:21:30 -0700 (PDT), "Adam W." | declaimed the following in | gmane.comp.python.general: | > You are correct about the 2 being the number of bytes written. However when I issue a read command I get: | > | > >>> ep.write('\x1BA') | > 4 | | That's interesting -- as if each byte you send is expanding into a | pair of bytes. UTF-16? ISTR that Windows often uses big endian UTF-16 for filenames and text data; could there be some default encoding in ep.write getting in your way? Disclaimer: I'm really not a Windows guy. -- Cameron Simpson There are too many people now for everyone to be entitled to his own opinion. - Dr. Handelman From cs at zip.com.au Wed Aug 29 19:25:12 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 30 Aug 2012 09:25:12 +1000 Subject: Sending USB commands with Python In-Reply-To: <20120829222932.GA18700@cskk.homeip.net> References: <20120829222932.GA18700@cskk.homeip.net> Message-ID: <20120829232512.GA22597@cskk.homeip.net> On 30Aug2012 08:29, I wrote: | UTF-16? ISTR that Windows often uses big endian UTF-16 [...] Sorry, little-endian. Anyway... -- Cameron Simpson Ed Campbell's pointers for long trips: 3. Stop and take a break before you really need it. From piet at vanoostrum.org Wed Aug 29 19:27:10 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 29 Aug 2012 19:27:10 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Ross Ridge writes: > > But it is in fact only stored in one particular way, as a series of bytes. > No, it can be stored in different ways. Certainly in Python 3.3 and beyond. And in 3.2 also, depending on wide/narrow build. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Wed Aug 29 19:39:15 2012 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 29 Aug 2012 19:39:15 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: Heiko Wundram writes: > Reading from stdin/a file gets you bytes, and > not a string, because Python cannot automagically guess what format the > input is in. > Huh? Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 10:09:29) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = input() abcd123 >>> x 'abcd123' >>> type(x) >>> y = sys.stdin.readline() abcd123 >>> y 'abcd123\n' >>> type(y) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From AWasilenko at gmail.com Wed Aug 29 19:45:10 2012 From: AWasilenko at gmail.com (Adam W.) Date: Wed, 29 Aug 2012 16:45:10 -0700 (PDT) Subject: Sending USB commands with Python In-Reply-To: References: <20120829222932.GA18700@cskk.homeip.net> Message-ID: On Wednesday, August 29, 2012 6:56:16 PM UTC-4, Dennis Lee Bieber wrote: > > BUT you do give a possible clue. Is the OP using a 3.x Python where > > strings are Unicode -- in which case the above may need to be explicitly > > declared as a "byte string" rather than text (unicode) string. > Huzzah! I am indeed using 3.x, and slapping on an .encode('utf-8') made my printer try to spit paper at me! Progress. Also, astute observation about the endpoint needing to be an input, with the following modification I get: >>> ep.write('\x1BA'.encode('utf-8')) 2 >>> ep = usb.util.find_descriptor( intf, custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_IN ) >>> ep.read(1) array('B', [163]) >>> Anyone want to venture a guess on how I should interpret that? It seems the [163] is the byte data the manual is talking about, but why is there a 'B' there? If I put paper in it and try again I get: array('B', [3]) Thanks for all your help guys, just about ready to stared coding the fun part! From bbeacham at desanasystems.com Wed Aug 29 20:38:28 2012 From: bbeacham at desanasystems.com (bbeacham at desanasystems.com) Date: Wed, 29 Aug 2012 17:38:28 -0700 (PDT) Subject: Is socket.recvfrom broken in ActiveState Python 3.2? Message-ID: Obviously, this my issue, but I cannot figure out what I am doing wrong. I have the Python echo server example implemented with the server on a Windows 7 computer and the client on a Linux Redhat server. The line 'data = sock.recv(1024)' works as expected on the Linux client. However, the line 'data, senderAddr = sock.recvfrom(1024)' does not set the 'senderAddr' to anything. In the code is this line: print('RECEIVED:', data, "SENDER:", str(senderAddr)) and this is the output. RECEIVED: Hello, world SENDER: None On the Windows 7 server side the line 'data = conn.recv(1024)' works fine. However, the line 'data, remoteAddr = conn.recvfrom(1024)' gives this output; DATA: Hello, world FROM: (0, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') While I expect this to be my issue, I cannot find an example via Google as to what I am doing wrong. All examples are pretty much as above. Any ideas. Is this a bug in 'recvfrom'? From python at mrabarnett.plus.com Wed Aug 29 20:53:17 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Aug 2012 01:53:17 +0100 Subject: Sending USB commands with Python In-Reply-To: References: <20120829222932.GA18700@cskk.homeip.net> Message-ID: <503EB97D.6060600@mrabarnett.plus.com> On 30/08/2012 00:45, Adam W. wrote: > On Wednesday, August 29, 2012 6:56:16 PM UTC-4, Dennis Lee Bieber wrote: >> >> BUT you do give a possible clue. Is the OP using a 3.x Python where >> >> strings are Unicode -- in which case the above may need to be explicitly >> >> declared as a "byte string" rather than text (unicode) string. >> > > Huzzah! I am indeed using 3.x, and slapping on an .encode('utf-8') made my printer try to spit paper at me! Progress. > > Also, astute observation about the endpoint needing to be an input, with the following modification I get: > >>>> ep.write('\x1BA'.encode('utf-8')) > 2 >>>> ep = usb.util.find_descriptor( > intf, > custom_match = \ > lambda e: \ > usb.util.endpoint_direction(e.bEndpointAddress) == \ > usb.util.ENDPOINT_IN > ) >>>> ep.read(1) > array('B', [163]) >>>> > > Anyone want to venture a guess on how I should interpret that? It seems the [163] is the byte data the manual is talking about, but why is there a 'B' there? If I put paper in it and try again I get: array('B', [3]) > > Thanks for all your help guys, just about ready to stared coding the fun part! > The result is an array of bytes ('B'). I think the value means: 0b10100011 ^Ready ^Top of form ^No paper ^Printer error The error is that it's out of paper. From fperez.net at gmail.com Wed Aug 29 22:41:51 2012 From: fperez.net at gmail.com (Fernando Perez) Date: Thu, 30 Aug 2012 02:41:51 +0000 (UTC) Subject: A sad day for the scientific Python community. John Hunter, creator of matplotlib: 1968-2012. Message-ID: Dear friends and colleagues, I am terribly saddened to report that yesterday, August 28 2012 at 10am, John D. Hunter died from complications arising from cancer treatment at the University of Chicago hospital, after a brief but intense battle with this terrible illness. John is survived by his wife Miriam, his three daughters Rahel, Ava and Clara, his sisters Layne and Mary, and his mother Sarah. Note: If you decide not to read any further (I know this is a long message), please go to this page for some important information about how you can thank John for everything he gave in a decade of generous contributions to the Python and scientific communities: http://numfocus.org/johnhunter. Just a few weeks ago, John delivered his keynote address at the SciPy 2012 conference in Austin centered around the evolution of matplotlib: http://www.youtube.com/watch?v=e3lTby5RI54 but tragically, shortly after his return home he was diagnosed with advanced colon cancer. This diagnosis was a terrible discovery to us all, but John took it with his usual combination of calm and resolve, and initiated treatment procedures. Unfortunately, the first round of chemotherapy treatments led to severe complications that sent him to the intensive care unit, and despite the best efforts of the University of Chicago medical center staff, he never fully recovered from these. Yesterday morning, he died peacefully at the hospital with his loved ones at his bedside. John fought with grace and courage, enduring every necessary procedure with a smile on his face and a kind word for all of his caretakers and becoming a loved patient of the many teams that ended up involved with his case. This was no surprise for those of us who knew him, but he clearly left a deep and lasting mark even amongst staff hardened by the rigors of oncology floors and intensive care units. I don't need to explain to this community the impact of John's work, but allow me to briefly recap, in case this is read by some who don't know the whole story. In 2002, John was a postdoc at the University of Chicago hospital working on the analysis of epilepsy seizure data in children. Frustrated with the state of the existing proprietary solutions for this class of problems, he started using Python for his work, back when the scientific Python ecosystem was much, much smaller than it is today and this could have been seen as a crazy risk. Furthermore, he found that there were many half-baked solutions for data visualization in Python at the time, but none that truly met his needs. Undeterred, he went on to create matplotlib (http://matplotlib.org) and thus overcome one of the key obstacles for Python to become the best solution for open source scientific and technical computing. Matplotlib is both an amazing technical achievement and a shining example of open source community building, as John not only created its backbone but also fostered the development of a very strong development team, ensuring that the talent of many others could also contribute to this project. The value and importance of this are now painfully clear: despite having lost John, matplotlib continues to thrive thanks to the leadership of Michael Droetboom, the support of Perry Greenfield at the Hubble Telescope Science Institute, and the daily work of the rest of the team. I want to thank Perry and Michael for putting their resources and talent once more behind matplotlib, securing the future of the project. It is difficult to overstate the value and importance of matplotlib, and therefore of John's contributions (which do not end in matplotlib, by the way; but a biography will have to wait for another day...). Python has become a major force in the technical and scientific computing world, leading the open source offers and challenging expensive proprietary platforms with large teams and millions of dollars of resources behind them. But this would be impossible without a solid data visualization tool that would allow both ad-hoc data exploration and the production of complex, fine-tuned figures for papers, reports or websites. John had the vision to make matplotlib easy to use, but powerful and flexible enough to work in graphical user interfaces and as a server-side library, enabling a myriad use cases beyond his personal needs. This means that now, matplotlib powers everything from plots in dissertations and journal articles to custom data analysis projects and websites. And despite having left his academic career a few years ago for a job in industry, he remained engaged enough that as of today, he is still the top committer to matplotlib; this is the git shortlog of those with more than 1000 commits to the project: 2145 John Hunter 2130 Michael Droettboom 1060 Eric Firing All of this was done by a man who had three children to raise and who still always found the time to help those on the mailing lists, solve difficult technical problems in matplotlib, teach courses and seminars about scientific Python, and more recently help create the NumFOCUS foundation project. Despite the challenges that raising three children in an expensive city like Chicago presented, he never once wavered from his commitment to open source. But unfortunately now he is not here anymore to continue providing for their well-being, and I hope that all those who have so far benefited from his generosity, will thank this wonderful man who always gave far more than he received. Thanks to the rapid action of Travis Oliphant, the NumFOCUS foundation is now acting as an escrow agent to accept donations that will go into a fund to support the education and care of his wonderful girls Rahel, Ava and Clara. If you have benefited from John's many contributions, please say thanks in the way that would matter most to him, by helping Miriam continue the task of caring for and educating Rahel, Ava and Clara. You will find all the information necessary to make a donation here: http://numfocus.org/johnhunter Remember that even a small donation helps! If all those who ever use matplotlib give just a little bit, in the long run I am sure that we can make a difference. If you are a company that benefits in a serious way from matplotlib, remember that John was a staunch advocate of keeping all scientific Python projects under the BSD license so that commercial users could benefit from them without worry. Please say thanks to John in a way commensurate with your resources (and check how much a yearly matlab license would cost you in case you have any doubts about the value you are getting...). John's family is planning a private burial in Tennessee, but (most likely in September) there will also be a memorial service in Chicago that friends and members of the community can attend. We don't have the final scheduling details at this point, but I will post them once we know. I would like to again express my gratitude to Travis Oliphant for moving quickly with the setup of the donation support, and to Eric Jones (the founder of Enthought and another one of the central figures in our community) who immediately upon learning of John's plight contributed resources to support the family with everyday logistics while John was facing treatment as well as my travel to Chicago to assist. This kind of immediate urge to come to the help of others that Eric and Travis displayed is a hallmark of our community. Before closing, I want to take a moment to publicly thank the incredible staff of the University of Chicago medical center. The last two weeks were an intense and brutal ordeal for John and his loved ones, but the hospital staff offered a sometimes hard to believe, unending supply of generosity, care and humanity in addition to their technical competence. The latter is something we expect from a first-rate hospital at a top university, where the attending physicians can be world-renowned specialists in their field. But the former is often forgotten in a world often ruled by a combination of science and concerns about regulations and liability. Instead, we found generous and tireless staff who did everything in their power to ease the pain, always putting our well being ahead of any mindless adherence to protocol, patiently tending to every need we had and working far beyond their stated responsibilities to support us. To name only one person (and many others are equally deserving), I want to thank Dr. Carla Moreira, chief surgical resident, who spent the last few hours of John's life with us despite having just completed a solid night shift of surgical work. Instead of resting she came to the ICU and worked to ensure that those last hours were as comfortable as possible for John; her generous actions helped us through a very difficult moment. It is now time to close this already too long message... John, thanks for everything you gave all of us, and for the privilege of knowing you. Fernando. From python-excel at raf.org Wed Aug 29 22:57:58 2012 From: python-excel at raf.org (python-excel at raf.org) Date: Thu, 30 Aug 2012 12:57:58 +1000 Subject: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented In-Reply-To: References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> <20120829021646.GA8163@raf.org> Message-ID: <20120830025758.GA26856@raf.org> John Yeung wrote: > > is there any other way to tell how many digits excel would round to > > when displaying a floating point number? that's my only reason for > > needing formatting_info=True. > > I have not personally used it, but OpenPyXL is another option for > working with .xlsx files, and it might provide the formatting info you > need: > > http://packages.python.org/openpyxl/index.html > http://pypi.python.org/pypi/openpyxl/1.5.8 > > John Y. thanks but openpyxl doesn't work well enough. most of the spreadsheets i need to read contain dropdown lists with data validation using a named formula like: OFFSET(Data!$K$2,0,0,COUNTA(Data!$K:$K),1) which causes openpyxl to throw a NamedRangeException. i don't even care about the named objects. i just want to know what's in the cell, not what other possible values the cell might have had. :-) apart from that, it does give access to number formats so your suggestion would work for simpler spreadsheets. hopefully the intention that xlrd not support formats in xlsx files will change one day into an intention to support them. :-) until then my users can keep manually saving xlsx files they receive as xls before importing them. :-( maybe i need to investigate some perl modules or pyuno instead. perl's Spreadsheet::XSLX module handles formats. it gets the date formats a bit wrong but it's workaroundable. cheers, raf From AWasilenko at gmail.com Wed Aug 29 23:53:48 2012 From: AWasilenko at gmail.com (Adam W.) Date: Wed, 29 Aug 2012 20:53:48 -0700 (PDT) Subject: Sending USB commands with Python In-Reply-To: References: <20120829222932.GA18700@cskk.homeip.net> Message-ID: <5d063028-3d3f-42f2-8787-b33d58460c35@googlegroups.com> On Wednesday, August 29, 2012 10:07:54 PM UTC-4, Dennis Lee Bieber wrote: > On Wed, 29 Aug 2012 16:45:10 -0700 (PDT), "Adam W." > > I'm a tad curious if using the notation > > > > b'\x1bA' > > > > without the .encode() would work. > > > > My concern is that you may encounter some "string" of data for > > printing which the .encode() ends up /changing/ (don't UTF-8 strings use > > a high-bit to signal a multi-byte encoding of what had been a single > > character?). A pure byte string shouldn't have that problem. > Your notation does work, and I was just coming around to reevaluating the use of the encode because I am getting really odd results when trying to print lines. For example I set the byte length to 10 and sent this 500 times or so expecting to get a solid black bar: ep.write('\x16FFFFFFFFFF'.encode('utf-8')) But what I got was a weird stripped pattern... I feel like a lot of my commands are working by chance, I can't explain to myself why the A in \x1bA isn't being treated as part of the hex. This stuff always confuses me. > > > >>> ep = usb.util.find_descriptor( > > > intf, > > > custom_match = \ > > > lambda e: \ > > > usb.util.endpoint_direction(e.bEndpointAddress) == \ > > > usb.util.ENDPOINT_IN > > > ) > > > > Seems tedious to keep swapping -- does USB support bidirectional > > connections? > I assigned the input to ep2 to resolve the switching issue. From georger.silva at gmail.com Thu Aug 30 00:42:07 2012 From: georger.silva at gmail.com (George Silva) Date: Thu, 30 Aug 2012 01:42:07 -0300 Subject: A sad day for the scientific Python community. John Hunter, creator of matplotlib: 1968-2012. In-Reply-To: References: Message-ID: May he rest in peace. On Wed, Aug 29, 2012 at 11:41 PM, Fernando Perez wrote: > Dear friends and colleagues, > > I am terribly saddened to report that yesterday, August 28 2012 at > 10am, John D. Hunter died from complications arising from cancer > treatment at the University of Chicago hospital, after a brief but > intense battle with this terrible illness. John is survived by his > wife Miriam, his three daughters Rahel, Ava and Clara, his sisters > Layne and Mary, and his mother Sarah. > > Note: If you decide not to read any further (I know this is a long > message), please go to this page for some important information about > how you can thank John for everything he gave in a decade of generous > contributions to the Python and scientific communities: > http://numfocus.org/johnhunter. > > Just a few weeks ago, John delivered his keynote address at the SciPy > 2012 conference in Austin centered around the evolution of matplotlib: > > http://www.youtube.com/watch?v=e3lTby5RI54 > > but tragically, shortly after his return home he was diagnosed with > advanced colon cancer. This diagnosis was a terrible discovery to us > all, but John took it with his usual combination of calm and resolve, > and initiated treatment procedures. Unfortunately, the first round of > chemotherapy treatments led to severe complications that sent him to > the intensive care unit, and despite the best efforts of the > University of Chicago medical center staff, he never fully recovered > from these. Yesterday morning, he died peacefully at the hospital > with his loved ones at his bedside. John fought with grace and > courage, enduring every necessary procedure with a smile on his face > and a kind word for all of his caretakers and becoming a loved patient > of the many teams that ended up involved with his case. This was no > surprise for those of us who knew him, but he clearly left a deep and > lasting mark even amongst staff hardened by the rigors of oncology > floors and intensive care units. > > I don't need to explain to this community the impact of John's work, > but allow me to briefly recap, in case this is read by some who don't > know the whole story. In 2002, John was a postdoc at the University > of Chicago hospital working on the analysis of epilepsy seizure data > in children. Frustrated with the state of the existing proprietary > solutions for this class of problems, he started using Python for his > work, back when the scientific Python ecosystem was much, much smaller > than it is today and this could have been seen as a crazy risk. > Furthermore, he found that there were many half-baked solutions for > data visualization in Python at the time, but none that truly met his > needs. Undeterred, he went on to create matplotlib > (http://matplotlib.org) and thus overcome one of the key obstacles for > Python to become the best solution for open source scientific and > technical computing. Matplotlib is both an amazing technical > achievement and a shining example of open source community building, > as John not only created its backbone but also fostered the > development of a very strong development team, ensuring that the > talent of many others could also contribute to this project. The > value and importance of this are now painfully clear: despite having > lost John, matplotlib continues to thrive thanks to the leadership of > Michael Droetboom, the support of Perry Greenfield at the Hubble > Telescope Science Institute, and the daily work of the rest of the > team. I want to thank Perry and Michael for putting their resources > and talent once more behind matplotlib, securing the future of the > project. > > It is difficult to overstate the value and importance of matplotlib, > and therefore of John's contributions (which do not end in matplotlib, > by the way; but a biography will have to wait for another day...). > Python has become a major force in the technical and scientific > computing world, leading the open source offers and challenging > expensive proprietary platforms with large teams and millions of > dollars of resources behind them. But this would be impossible without > a solid data visualization tool that would allow both ad-hoc data > exploration and the production of complex, fine-tuned figures for > papers, reports or websites. John had the vision to make matplotlib > easy to use, but powerful and flexible enough to work in graphical > user interfaces and as a server-side library, enabling a myriad use > cases beyond his personal needs. This means that now, matplotlib > powers everything from plots in dissertations and journal articles to > custom data analysis projects and websites. And despite having left > his academic career a few years ago for a job in industry, he remained > engaged enough that as of today, he is still the top committer to > matplotlib; this is the git shortlog of those with more than 1000 > commits to the project: > > 2145 John Hunter > 2130 Michael Droettboom > 1060 Eric Firing > > All of this was done by a man who had three children to raise and who > still always found the time to help those on the mailing lists, solve > difficult technical problems in matplotlib, teach courses and seminars > about scientific Python, and more recently help create the NumFOCUS > foundation project. Despite the challenges that raising three > children in an expensive city like Chicago presented, he never once > wavered from his commitment to open source. But unfortunately now he > is not here anymore to continue providing for their well-being, and I > hope that all those who have so far benefited from his generosity, > will thank this wonderful man who always gave far more than he > received. Thanks to the rapid action of Travis Oliphant, the NumFOCUS > foundation is now acting as an escrow agent to accept donations that > will go into a fund to support the education and care of his wonderful > girls Rahel, Ava and Clara. > > If you have benefited from John's many contributions, please say > thanks in the way that would matter most to him, by helping Miriam > continue the task of caring for and educating Rahel, Ava and Clara. > You will find all the information necessary to make a donation here: > > http://numfocus.org/johnhunter > > Remember that even a small donation helps! If all those who ever use > matplotlib give just a little bit, in the long run I am sure that we > can make a difference. > > If you are a company that benefits in a serious way from matplotlib, > remember that John was a staunch advocate of keeping all scientific > Python projects under the BSD license so that commercial users could > benefit from them without worry. Please say thanks to John in a way > commensurate with your resources (and check how much a yearly matlab > license would cost you in case you have any doubts about the value you > are getting...). > > John's family is planning a private burial in Tennessee, but (most > likely in September) there will also be a memorial service in Chicago > that friends and members of the community can attend. We don't have > the final scheduling details at this point, but I will post them once > we know. > > I would like to again express my gratitude to Travis Oliphant for > moving quickly with the setup of the donation support, and to Eric > Jones (the founder of Enthought and another one of the central figures > in our community) who immediately upon learning of John's plight > contributed resources to support the family with everyday logistics > while John was facing treatment as well as my travel to Chicago to > assist. This kind of immediate urge to come to the help of others > that Eric and Travis displayed is a hallmark of our community. > > Before closing, I want to take a moment to publicly thank the > incredible staff of the University of Chicago medical center. The > last two weeks were an intense and brutal ordeal for John and his > loved ones, but the hospital staff offered a sometimes hard to > believe, unending supply of generosity, care and humanity in addition > to their technical competence. The latter is something we expect from > a first-rate hospital at a top university, where the attending > physicians can be world-renowned specialists in their field. But the > former is often forgotten in a world often ruled by a combination of > science and concerns about regulations and liability. Instead, we > found generous and tireless staff who did everything in their power to > ease the pain, always putting our well being ahead of any mindless > adherence to protocol, patiently tending to every need we had and > working far beyond their stated responsibilities to support us. To > name only one person (and many others are equally deserving), I want > to thank Dr. Carla Moreira, chief surgical resident, who spent the > last few hours of John's life with us despite having just completed a > solid night shift of surgical work. Instead of resting she came to > the ICU and worked to ensure that those last hours were as comfortable > as possible for John; her generous actions helped us through a very > difficult moment. > > It is now time to close this already too long message... > > John, thanks for everything you gave all of us, and for the privilege > of knowing you. > > Fernando. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- George R. C. Silva Desenvolvimento em GIS http://geoprocessamento.net http://blog.geoprocessamento.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From robertmiles at teranews.com Thu Aug 30 01:50:04 2012 From: robertmiles at teranews.com (Robert Miles) Date: Thu, 30 Aug 2012 00:50:04 -0500 Subject: catch UnicodeDecodeError In-Reply-To: <17bf754d-b1e9-4bb7-bf42-190325ee969a@q29g2000vby.googlegroups.com> References: <04f7ff8d-9881-4a04-ab2e-b5573b5f3cd1@googlegroups.com> <38f5cdaf-c021-4ccd-8fcb-c68b21d3aeb2@w24g2000vby.googlegroups.com> <17bf754d-b1e9-4bb7-bf42-190325ee969a@q29g2000vby.googlegroups.com> Message-ID: On 7/26/2012 5:51 AM, Jaroslav Dobrek wrote: >> And the cool thing is: you can! :) >> >> In Python 2.6 and later, the new Py3 open() function is a bit more hidden, >> but it's still available: >> >> from io import open >> >> filename = "somefile.txt" >> try: >> with open(filename, encoding="utf-8") as f: >> for line in f: >> process_line(line) # actually, I'd use "process_file(f)" >> except IOError, e: >> print("Reading file %s failed: %s" % (filename, e)) >> except UnicodeDecodeError, e: >> print("Some error occurred decoding file %s: %s" % (filename, e)) > > Thanks. I might use this in the future. > >>> try: >>> for line in f: # here text is decoded implicitly >>> do_something() >>> except UnicodeDecodeError(): >>> do_something_different() >> >>> This isn't possible for syntactic reasons. >> >> Well, you'd normally want to leave out the parentheses after the exception >> type, but otherwise, that's perfectly valid Python code. That's how these >> things work. > > You are right. Of course this is syntactically possible. I was too > rash, sorry. In confused > it with some other construction I once tried. I can't remember it > right now. > > But the code above (without the brackets) is semantically bad: The > exception is not caught. > > >>> The problem is that vast majority of the thousands of files that I >>> process are correctly encoded. But then, suddenly, there is a bad >>> character in a new file. (This is so because most files today are >>> generated by people who don't know that there is such a thing as >>> encodings.) And then I need to rewrite my very complex program just >>> because of one single character in one single file. >> >> Why would that be the case? The places to change should be very local in >> your code. > > This is the case in a program that has many different functions which > open and parse different > types of files. When I read and parse a directory with such different > types of files, a program that > uses > > for line in f: > > will not exit with any hint as to where the error occurred. I just > exits with a UnicodeDecodeError. That > means I have to look at all functions that have some variant of > > for line in f: > > in them. And it is not sufficient to replace the "for line in f" part. > I would have to transform many functions that > work in terms of lines into functions that work in terms of decoded > bytes. > > That is why I usually solve the problem by moving fles around until I > find the bad file. Then I recode or repair > the bad file manually. Would it be reasonable to use pieces of the old program to write a new program that prints the name for an input file, then searches that input file for bad characters? If it doesn't find any, it can then go on to the next input file, or show a message saying that no bad characters were found. From nobody at nowhere.com Thu Aug 30 01:51:11 2012 From: nobody at nowhere.com (Nobody) Date: Thu, 30 Aug 2012 06:51:11 +0100 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On Wed, 29 Aug 2012 19:39:15 -0400, Piet van Oostrum wrote: >> Reading from stdin/a file gets you bytes, and not a string, because >> Python cannot automagically guess what format the input is in. >> > Huh? Oh, it can certainly guess (in the absence of any other information, it uses the current locale). Whether or not that guess is correct is a different matter. Realistically, if you want sensible behaviour from Python 3.x, you need to use an ISO-8859-1 locale. That ensures that conversion between str and bytes will never fail, and an str-bytes-str or bytes-str-bytes round-trip will pass data through unmangled. From robertmiles at teranews.com Thu Aug 30 01:58:32 2012 From: robertmiles at teranews.com (Robert Miles) Date: Thu, 30 Aug 2012 00:58:32 -0500 Subject: Dumping all the sql statements as backup In-Reply-To: References: Message-ID: On 7/25/2012 8:56 AM, andrea crotti wrote: > I have some long running processes that do very long simulations which > at the end need to write things on a database. > > At the moment sometimes there are network problems and we end up with > half the data on the database. > > The half-data problem is probably solved easily with sessions and > sqlalchemy (a db-transaction), but still we would like to be able to > keep a backup SQL file in case something goes badly wrong and we want to > re-run it manually.. > > This might also be useful if we have to rollback the db for some reasons > to a previous day and we don't want to re-run the simulations.. > > Anyone did something similar? > It would be nice to do something like: > > with CachedDatabase('backup.sql'): > # do all your things I'm now starting to do something similar, but in C, not Python. Apparently not using SQL. The simulations this is for often last a month or more. From steve+comp.lang.python at pearwood.info Thu Aug 30 02:55:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Aug 2012 06:55:01 GMT Subject: Flexible string representation, unicode, typography, ... References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> Message-ID: <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> On Wed, 29 Aug 2012 08:43:05 -0700, wxjmfauth wrote: > I can hit the nail a little more. > I have even a better idea and I'm serious. > > If "Python" has found a new way to cover the set of the Unicode > characters, why not proposing it to the Unicode consortium? Because the implementation of the str datatype in a programming language has nothing to do with the Unicode consortium. You might as well propose it to the International Union of Railway Engineers. > Unicode has already three schemes covering practically all cases: memory > consumption, maximum flexibility and an intermediate solution. And Python's solution uses those: UCS-2, UCS-4, and UTF-8. The only thing which is innovative here is that instead of the Python compiler declaring that "all strings will be stored in UCS-2", the compiler chooses an implementation for each string as needed. So some strings will be stored internally as UCS-4, some as UCS-2, and some as ASCII (which is a standard, but not the Unicode consortium's standard). (And possibly some as UTF-8? I'm not entirely sure from reading the PEP.) There's nothing radical here, honest. -- Steven From dieter at handshake.de Thu Aug 30 03:24:09 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 30 Aug 2012 09:24:09 +0200 Subject: Can I get logging.FileHandler to close the file on each emit? References: <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com> Message-ID: <87ipc0j10m.fsf@handshake.de> rikardhulten at gmail.com writes: > I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event. > > On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event? > > If not, would the correct thing to do be to write my own LogHandler with this behavior? Zope is using Python's "logging" module and wants to play well with log rotating (start a new logfile, do something with the old log file (compress, rename, remove)). It does this by registering a signal handler which closes its logfiles when the corresponding signal is received. Maybe, you can do something like this. Signal handling under Windows is limited, but maybe you find a usable signal under Windows (Zope is using "SIGUSR1"). From ulrich.eckhardt at dominolaser.com Thu Aug 30 03:33:58 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 30 Aug 2012 09:33:58 +0200 Subject: How to program test(expr) ? In-Reply-To: References: Message-ID: <6kh3h9-p9o.ln1@satorlaser.homedns.org> Am 29.08.2012 17:04, schrieb Franck Ditter: > I use Python 3.2.3 + Idle. > Is it possible to program test(e) which takes > an expression e and whose execution produces > at the toplevel an echo of e and the effects > and result of its evaluation ? Yes, the key to this is using a lambda expression. > # file foo.py > def foo(x) : > print('x =',x) > return x+1 > > test(foo(5)) def test(exp): global print print_saved = print print = my_print res = exp() print = print_saved return res test(lambda: foo(5)) The idea is to run the callable expression inside a modified environment, in the sketch above it intercepts the calles to print() using a separate my_print() function. Note that the calling syntax is slightly different than the one you would have wanted, don't know if that is important. Things I'll leave to you: - exception handling - exception forwarding - intercepting other environment accesses - putting all that into a context manager :) Good luck! Uli From dieter at handshake.de Thu Aug 30 03:36:46 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 30 Aug 2012 09:36:46 +0200 Subject: Are the property Function really useful? References: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> Message-ID: <87ehmoj0fl.fsf@handshake.de> writes: > Are the property Function really useful? Someone invested time to implement/document/test it. Thus, there are people who have use cases for it... > Where can i use the property function? You can use it when you have parameterless methods which you want to access as if they were simple attributes: i.e. "obj.m" instead of "obj.m()". To phrase is slightly differently: the "property" function allows you to implement "computed" (rather than "stored") attributes. You may find this feature uninteresting: fine, do not use it... However, there are cases where it is helpful, e.g.: You have a base class "B" with an attribute "a". Now, you want to derive a class "D" from "B" where "a" is not fixed but must be computed from other attributes. The "Eiffel" programming language even stipulates that attributes and parameterless methods are essentially the same and application of the "property" function is implicit in "Eiffel" for parameterless methods: to hide implementation details. As you see, "property" can be highly valued ;-) From chris at python.org Thu Aug 30 03:42:30 2012 From: chris at python.org (Chris Withers) Date: Thu, 30 Aug 2012 08:42:30 +0100 Subject: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented In-Reply-To: <20120830025758.GA26856@raf.org> References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> <20120829021646.GA8163@raf.org> <20120830025758.GA26856@raf.org> Message-ID: <503F1966.50802@python.org> On 30/08/2012 03:57, python-excel at raf.org wrote: > > hopefully the intention that xlrd not support formats in xlsx > files will change one day into an intention to support them. :-) The intention is there, sadly the time to work on it is not. John Machin would be the person best placed to do the work, if anyone fancies sponsoring the work, he might be able to direct more time to it.. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From wxjmfauth at gmail.com Thu Aug 30 04:51:40 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 30 Aug 2012 01:51:40 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: Le jeudi 30 ao?t 2012 08:55:01 UTC+2, Steven D'Aprano a ?crit?: You are right. But as soon as you introduce artificially a "latin-1" bottleneck, all this machinery just become useless. This flexible representation is working absurdly. It optimizes the characters you are not using (in one sense), it defaults to a non optimized form for the characters you wish to use. Pick up a random text and see the probability this text match the most optimized case 1 char / 1 byte, practically never. If a user will use exclusively latin-1, she/he is better served by using a dedicated tool for "latin-1" If a user will comfortably work with Unicode, she/he is better served by using one of this tools which is using properly one of the available Unicode schemes. In a funny way, this is what Python was doing and it performs better! (Enough for today, *I* should spend my spare time to toy with Go, this discussion gave *me* the wish to dive in it again). jmf From rosuav at gmail.com Thu Aug 30 04:59:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Aug 2012 18:59:27 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Aug 30, 2012 at 6:51 PM, wrote: > Pick up a random text and see the probability this > text match the most optimized case 1 char / 1 byte, > practically never. Only if you talk about a huge document. Try, instead, every string ever used in a Python script. Practically always. But I'm wasting my time saying this again. It's been said by multiple people multiple times. ChrisA From srimanthula.radhakrishna at gmail.com Thu Aug 30 06:38:26 2012 From: srimanthula.radhakrishna at gmail.com (srimanthula.radhakrishna at gmail.com) Date: Thu, 30 Aug 2012 03:38:26 -0700 (PDT) Subject: Python Logging: Specifying converter attribute of a log formatter in config file Message-ID: <97b8c5f2-eaa9-456a-b766-146ac65b879e@googlegroups.com> I'd like to have all timestamps in my log file to be UTC timestamp. When specified through code, this is done as follows: myHandler = logging.FileHandler('mylogfile.log', 'a') formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)-15s:%(lineno)4s: %(message)-80s') formatter.converter = time.gmtime myLogger = logging.getLogger('MyApp') myLogger.addHandler(myHandler) I'd like to move away from the above 'in-code' configuration to a config file based mechanism. Here's the config file section for the formatter: [handler_MyLogHandler] args=("mylogfile.log", "a",) class=FileHandler level=DEBUG formatter=simpleFormatter Now, how do I specify the converter attribute (time.gmtime) in the above section? From chenwei.address at gmail.com Thu Aug 30 06:55:25 2012 From: chenwei.address at gmail.com (=?UTF-8?B?6ZmI5Lyf?=) Date: Thu, 30 Aug 2012 03:55:25 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? Message-ID: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> when i write code like this: class A(object): d = 'it is a doc.' t = A() print t.__class__.d print t.d the output is same. so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. From roy at panix.com Thu Aug 30 07:02:24 2012 From: roy at panix.com (Roy Smith) Date: Thu, 30 Aug 2012 07:02:24 -0400 Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: In article <503f0e45$0$9416$c3e8da3$76491128 at news.astraweb.com>, Steven D'Aprano wrote: > The only thing which is innovative here is that instead of the Python > compiler declaring that "all strings will be stored in UCS-2", the > compiler chooses an implementation for each string as needed. So some > strings will be stored internally as UCS-4, some as UCS-2, and some as > ASCII (which is a standard, but not the Unicode consortium's standard). Is the implementation smart enough to know that x == y is always False if x and y are using different internal representations? From ulrich.eckhardt at dominolaser.com Thu Aug 30 07:22:19 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 30 Aug 2012 13:22:19 +0200 Subject: class object's attribute is also the instance's attribute? In-Reply-To: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: <503F4CEB.9070408@dominolaser.com> Am 30.08.2012 12:55, schrieb ??: > class A(object): > d = 'it is a doc.' > > t = A() > > print t.__class__.d > print t.d > > the output is same. You could go even further: print id(t.__class__.d) print id(t.d) which should show you that they are not just equal but identical. > so it means class object's attribute is also the instance's > attribute.is it right? Yes. This is even useful sometimes: class Point(object): x = 0 y = 0 This will cause every Point to have two attributes x and y that have a default value 0. Note that setting this attribute on an instance does not change the class' attribute, just in that that was what confused you. However, if the attribute references a mutable type (e.g. a list) this can cause problems because the instance (see id() above) is the same and thus modifications affect both the class and all instances. Uli From d at davea.name Thu Aug 30 07:49:10 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 07:49:10 -0400 Subject: Are the property Function really useful? yes. In-Reply-To: <503E0128.5070805@davea.name> References: <6ab76fcc34adc04a8b113b77c1e85606@pc-20120706ouob> <503E0128.5070805@davea.name> Message-ID: <503F5336.2030609@davea.name> On 08/29/2012 07:46 AM, Dave Angel wrote: > On 08/29/2012 06:32 AM, levinie001 at gmail.com wrote: > > I was trying to point out that your question was empty (no content in the message). Mark also apparently saw an empty message. However, now that Dieter has responded, with apparent quotes from your message, i see what the problem was. You composed an html message and sent it to a text forum. Many people make that mistake, and the problem it usually causes is that source code indentation is messed up. However, most mail programs send a text part as well, and that's what we see. In your case, the text part was empty, so I saw nothing but the subject line. Please tell your mail program to compose TEXT message, not html, or this problem could occur again. Now to your question. >>
 
>>
Where can i use the property function?
In some languages, you get computed properties by writing getter and setter functions, with names to match. Python lets you hide the fact that the "property" is hidden, by letting you use ordinary syntax to access it. For example, suppose you had a Point class, which stored the x and y coordinates of a point on a plane. Suppose also that sometimes you wanted to use polar coordinates. You might like the user of the class to just interchangeably use the real attributes and the computed ones, without having to use parentheses on some of them. (untested) class Point(object): def __init__(self, x, y): self.x = x self.y = y @property def radius(self): return self.sqrt(self.x * self.x, self.y * self.y) @property def theta(self): return math.atan(self.x, self.y) Now, once you have a Point instance, you can use all four attributes pretty much interchangeably. -- DaveA From d at davea.name Thu Aug 30 07:53:19 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 07:53:19 -0400 Subject: class object's attribute is also the instance's attribute? In-Reply-To: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: <503F542F.7060905@davea.name> On 08/30/2012 06:55 AM, ?? wrote: > when i write code like this: > > class A(object): > > d = 'it is a doc.' > > > t = A() > > print t.__class__.d > print t.d > > the output is same. > > so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. In your example, you have no instance attribute. So when you use the syntax to fetch one, the interpreter looks first at the instance, doesn't find it, then looks in the class, and does. That is documented behavior. Some people use it to provide a kind of default value for instances, which can be useful if most instances need the same value, but a few want to overrride it. -- DaveA From boltar2003 at boltar.world Thu Aug 30 07:54:05 2012 From: boltar2003 at boltar.world (boltar2003 at boltar.world) Date: Thu, 30 Aug 2012 11:54:05 +0000 (UTC) Subject: Beginners question Message-ID: Hello I'm slowly teaching myself python so apologies if this is a dumb question. but something has confused me with the os.stat() function: >>> s = os.stat(".") >>> print s posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st _ctime=1346327754) What sort of object is posix.stat_result? Its not a dictionary or list or a class object as far as I can tell. Thanks for any help. B2003 From python at mrabarnett.plus.com Thu Aug 30 08:14:57 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Aug 2012 13:14:57 +0100 Subject: Beginners question In-Reply-To: References: Message-ID: <503F5941.8040309@mrabarnett.plus.com> On 30/08/2012 12:54, boltar2003 at boltar.world wrote: > Hello > > I'm slowly teaching myself python so apologies if this is a dumb question. > but something has confused me with the os.stat() function: > >>>> s = os.stat(".") >>>> print s > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > _ctime=1346327754) > > What sort of object is posix.stat_result? Its not a dictionary or list or a > class object as far as I can tell. Thanks for any help. > What don't you ask Python? I'm sure you'' get something like this: >>> type(s) In other words, it's an instance of the class "stat_result" as defined in the file "posix.py". On my system I get "" because I'm using Windows. From roy at panix.com Thu Aug 30 08:23:23 2012 From: roy at panix.com (Roy Smith) Date: Thu, 30 Aug 2012 08:23:23 -0400 Subject: Beginners question References: Message-ID: In article , MRAB wrote: > What don't you ask Python? I'm sure you'' get something like this: > > >>> type(s) > BTW, this points out one of the really powerful aspects of Python. The combination of introspection and a handy interactive interpreter makes it easy to "just ask the computer". It's often faster to play around with dir(), type(), and pprint() than to find what you're looking for in the docs. From nawijn at gmail.com Thu Aug 30 08:23:43 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 05:23:43 -0700 (PDT) Subject: Beginners question In-Reply-To: References: Message-ID: On Thursday, August 30, 2012 1:54:08 PM UTC+2, (unknown) wrote: > Hello > > > > I'm slowly teaching myself python so apologies if this is a dumb question. > > but something has confused me with the os.stat() function: > > > > >>> s = os.stat(".") > > >>> print s > > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > > _ctime=1346327754) > > > > What sort of object is posix.stat_result? Its not a dictionary or list or a > > class object as far as I can tell. Thanks for any help. > > > > B2003 Hi, So let's try to figure this out. First of all, we can ask Python what object it is. >>> s = os.stat('.') >>> type(s) posix.stat_result So it seems to be a custom type. However types can inherit from builtins like list, tuple and dict, so maybe it still is a dict or a tuple. Let's ask Python again: >>> isinstance(s, dict) False >>> isinstance(s, (tuple, list)) False Ok. So it is neither a list (tuple) nor a dict. So without reverting to the source code, it is probably save to say that the result is a custom class where the attributes can be accessed by the dot '.' notation. This is confirmed when you do: >>> dir(s) ...... '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'n_fields', 'n_sequence_fields', 'n_unnamed_fields', 'st_atime', 'st_blksize', 'st_blocks', 'st_ctime', 'st_dev', 'st_gid', 'st_ino', 'st_mode', 'st_mtime', 'st_nlink', 'st_rdev', 'st_size', 'st_uid'] For example: >>> print s.st_size 4096 In case of Linux I think that the result of os.stat(..) is a wrapping of a C struct (a class with only attributes and no methods). A small additional remark. Besides being a real dict or list (by means of inheritance), custom class can also implement the interface (__getitem__ etc.). If you want to know if an object implements this interface you could use the types defined in the 'abc' and 'collections' standard modules. So instead of checking if a type is a dict like this: >>> isinstance(s, dict) you could also check if it implements the dict interface: >>> isinstance(s, collections.MutableMapping) # or similar Regards, Marco From d at davea.name Thu Aug 30 08:25:33 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 08:25:33 -0400 Subject: Beginners question In-Reply-To: References: Message-ID: <503F5BBD.1090008@davea.name> On 08/30/2012 07:54 AM, boltar2003 at boltar.world wrote: > Hello > > I'm slowly teaching myself python so apologies if this is a dumb question. > but something has confused me with the os.stat() function: > >>>> s = os.stat(".") >>>> print s > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > _ctime=1346327754) > > What sort of object is posix.stat_result? Its not a dictionary or list or a > class object as far as I can tell. Thanks for any help. > posix.stat_result is a class, and s is an instance of that class. You can see that by typing type(s). But you're wondering how print generated all that stuff about the s instance. You can start to learn that with dir(s), which shows the available attributes. All those attributes that have leading and trailing double-underscores are called "special attributes," or "special methods." In particular notice __str__(), which is a method provided for your convenience. print will call that if it's available, when you try to print an instance. It also masquerades as a tuple using __getitem__() and other special methods. Normal use of the instance is done by the attributes like s.st_atime and s.st_size, or by using the object as a tuple. (using the square brackets to fetch individual items or a range of items) You can get more documentation directly from s by simply typing help(s) and/or help(os.stat) Or you can go to the web docs, http://docs.python.org/library/os.html and search downward for os.stat (this link is currently for Python 2.7.3) -- DaveA From rosuav at gmail.com Thu Aug 30 08:32:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Aug 2012 22:32:18 +1000 Subject: Beginners question In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 9:54 PM, wrote: > What sort of object is posix.stat_result? Its not a dictionary or list or a > class object as far as I can tell. Thanks for any help. There's some cool things you can do here. (Note that I'm testing this on a Windows box, so it's marginally different.) >>> import os >>> st=os.stat(".") >>> st nt.stat_result(st_mode=16895, st_ino=36873221949168842, st_dev=0, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1346329853, st_mtime=1311543704, st_ctime=1306188101) >>> help(st) You'll get a couple of pages of help text about the object class that the stat object is. You can do this with any object at all. Notably in this case: | This object may be accessed either as a tuple of | (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) | or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on. So, for instance: >>> st[0] 16895 >>> st.st_mode 16895 Hope that helps! ChrisA From nawijn at gmail.com Thu Aug 30 08:34:51 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 05:34:51 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: On Thursday, August 30, 2012 12:55:25 PM UTC+2, ?? wrote: > when i write code like this: > > > > class A(object): > > > > d = 'it is a doc.' > > > > > > t = A() > > > > print t.__class__.d > > print t.d > > > > the output is same. > > > > so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. I think the best way is to think of it as a global attribute restricted to the class A. Note that you even don't need an instance to get the value of the attribute. You can directly get it from the class itself. >>> class A(object): d = 'my attribute' >>> A.d 'my attribute' >>> aobj = A() >>> aobj.d 'my attribute' Note that if you change 'd' it will change for all instances! >>> bobj = A() >>> bobj.d 'my attribute' >>> A.d = 'oops...attribute changed' >>> aobj.d 'oops...attribute changed' >>> bobj.d 'oops...attribute changed' If you want attributes to be local to the instance, you have to define them in the __init__ section of the class like this: class A(object): def __init__(self): d = 'my attribute' >>> aobj = A() >>> bobj = A() >>> aobj.d 'my attribute' >>> bobj.d 'my attribute' >>> aobj.d = 'oops...attribute changed' >>> aobj.d 'oops...attribute changed' >>> bobj.d 'my attribute' Regards, Marco From ulrich.eckhardt at dominolaser.com Thu Aug 30 08:49:54 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 30 Aug 2012 14:49:54 +0200 Subject: Beginners question In-Reply-To: References: Message-ID: Am 30.08.2012 13:54, schrieb boltar2003 at boltar.world: >>>> s = os.stat(".") >>>> print s > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > _ctime=1346327754) > > What sort of object is posix.stat_result? Use the type() function to find out. I guess that this is a named tuple, which is a tuple where the attributes are not indexed but have a name, see the documentation for the namedtuple() function from the collections library. Uli From boltar2003 at boltar.world Thu Aug 30 08:50:41 2012 From: boltar2003 at boltar.world (boltar2003 at boltar.world) Date: Thu, 30 Aug 2012 12:50:41 +0000 (UTC) Subject: Beginners question References: Message-ID: On Thu, 30 Aug 2012 13:14:57 +0100 MRAB wrote: >On 30/08/2012 12:54, boltar2003 at boltar.world wrote: >> Hello >> >> I'm slowly teaching myself python so apologies if this is a dumb question. >> but something has confused me with the os.stat() function: >> >>>>> s = os.stat(".") >>>>> print s >> posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, >st_u >> id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, >st_mtime=1346327754, st >> _ctime=1346327754) >> >> What sort of object is posix.stat_result? Its not a dictionary or list or a >> class object as far as I can tell. Thanks for any help. >> >What don't you ask Python? I'm sure you'' get something like this: > > >>> type(s) > Umm , no I don't. >>> s = os.stat(".") >>> print s posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st _ctime=1346327754) >>> type(s) Which isn't terrible helpful. >In other words, it's an instance of the class "stat_result" as defined >in the file "posix.py". If its a class , why is it when I create my own class I get a completely different output with print and type? >>> >>> class foo(object): .. def __init__(self): .. pass .. >>> f=foo() >>> print f <__main__.foo object at 0xb743956c> >>> type(f) B2003 From AWasilenko at gmail.com Thu Aug 30 08:51:56 2012 From: AWasilenko at gmail.com (Adam W.) Date: Thu, 30 Aug 2012 05:51:56 -0700 (PDT) Subject: Sending USB commands with Python In-Reply-To: References: <20120829222932.GA18700@cskk.homeip.net> <5d063028-3d3f-42f2-8787-b33d58460c35@googlegroups.com> Message-ID: <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com> On Thursday, August 30, 2012 12:55:14 AM UTC-4, Dennis Lee Bieber wrote: > > How many bytes did it claim to send? > 11, which is what I expected. But I changed the byte value to 16 (because I was having trouble getting single digit hex values working in the command) and sent this command: >>> for x in range(0,500): ep.write(b'\x16\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF') it respond with 500 17's and prints a black bar! So it looks like whatever concern you had with using encode was coming to fruition. > > That's the easy one -- \x in a string introduces an 8-bit byte value > > -- so only two hex digits well be read. The "A" is interpreted as > > regular text. Interesting, so what if I only wanted to send 4bits as a hex value? Also can I somehow throw in some binary alongside of hex? At some point in my program I'm going to need to send some commands preferably in hex along with the binary image data. From oscar.j.benjamin at gmail.com Thu Aug 30 08:52:43 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 30 Aug 2012 13:52:43 +0100 Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: On Thu, 30 Aug 2012 05:34:51 -0700 (PDT), Marco Nawijn wrote: > If you want attributes to be local to the instance, you have to define them in the __init__ section of the class like this: > class A(object): > def __init__(self): > d = 'my attribute' Except that in this case you'd need to do: self.d = 'my attribute' Oscar From boltar2003 at boltar.world Thu Aug 30 08:53:24 2012 From: boltar2003 at boltar.world (boltar2003 at boltar.world) Date: Thu, 30 Aug 2012 12:53:24 +0000 (UTC) Subject: Beginners question References: Message-ID: On Thu, 30 Aug 2012 08:25:33 -0400 Dave Angel wrote: >You can get more documentation directly from s by simply typing >help(s) and/or help(os.stat) I didn't know about help(). Thanks! B2003 From chenwei.address at gmail.com Thu Aug 30 08:57:32 2012 From: chenwei.address at gmail.com (=?UTF-8?B?6ZmI5Lyf?=) Date: Thu, 30 Aug 2012 05:57:32 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: ? 2012?8?30????UTC+8??7?54?35??Dave Angel??? > On 08/30/2012 06:55 AM, ?? wrote: > > > when i write code like this: > > > > > > class A(object): > > > > > > d = 'it is a doc.' > > > > > > > > > t = A() > > > > > > print t.__class__.d > > > print t.d > > > > > > the output is same. > > > > > > so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. > > > > In your example, you have no instance attribute. So when you use the > > syntax to fetch one, the interpreter looks first at the instance, > > doesn't find it, then looks in the class, and does. That is documented > > behavior. Some people use it to provide a kind of default value for > > instances, which can be useful if most instances need the same value, > > but a few want to overrride it. > > > > -- > > > > DaveA thank you very much. From chenwei.address at gmail.com Thu Aug 30 08:57:32 2012 From: chenwei.address at gmail.com (=?UTF-8?B?6ZmI5Lyf?=) Date: Thu, 30 Aug 2012 05:57:32 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: ? 2012?8?30????UTC+8??7?54?35??Dave Angel??? > On 08/30/2012 06:55 AM, ?? wrote: > > > when i write code like this: > > > > > > class A(object): > > > > > > d = 'it is a doc.' > > > > > > > > > t = A() > > > > > > print t.__class__.d > > > print t.d > > > > > > the output is same. > > > > > > so it means class object's attribute is also the instance's attribute. is it right? i can not understand it. > > > > In your example, you have no instance attribute. So when you use the > > syntax to fetch one, the interpreter looks first at the instance, > > doesn't find it, then looks in the class, and does. That is documented > > behavior. Some people use it to provide a kind of default value for > > instances, which can be useful if most instances need the same value, > > but a few want to overrride it. > > > > -- > > > > DaveA thank you very much. From rosuav at gmail.com Thu Aug 30 09:06:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Aug 2012 23:06:34 +1000 Subject: Beginners question In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 10:50 PM, wrote: > On Thu, 30 Aug 2012 13:14:57 +0100 > MRAB wrote: >>What don't you ask Python? I'm sure you'' get something like this: >> >> >>> type(s) >> > > Umm , no I don't. > >>>> type(s) > > > Which isn't terrible helpful. That's actually the same thing, except for a slight difference between Python 2 and Python 3. > If its a class , why is it when I create my own class I get a completely > different output with print and type? > >>>> >>>> class foo(object): > .. def __init__(self): > .. pass > .. >>>> f=foo() >>>> print f > <__main__.foo object at 0xb743956c> >>>> type(f) > Yep, you're using Python 2. A few things are subtly different. Unless you have good reason not to, do consider moving to Python 3; all sorts of things are easier. Python 2 is basically not being developed any more. http://www.python.org/dev/peps/pep-0404/ Alternatively, accept that what people are going to quote to you here may be slightly different from what you see. In any case, Python's introspection facilities and help() features are available on both branches, so most of what has been said in this thread still applies. ChrisA From boltar2003 at boltar.world Thu Aug 30 09:16:51 2012 From: boltar2003 at boltar.world (boltar2003 at boltar.world) Date: Thu, 30 Aug 2012 13:16:51 +0000 (UTC) Subject: Beginners question References: Message-ID: On Thu, 30 Aug 2012 23:06:34 +1000 Chris Angelico wrote: >Yep, you're using Python 2. A few things are subtly different. Unless >you have good reason not to, do consider moving to Python 3; all sorts Noted. Thanks. B2003 From d at davea.name Thu Aug 30 09:23:03 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 09:23:03 -0400 Subject: Beginners question In-Reply-To: References: Message-ID: <503F6937.1060106@davea.name> On 08/30/2012 08:50 AM, boltar2003 at boltar.world wrote: > On Thu, 30 Aug 2012 13:14:57 +0100 > MRAB wrote: > > If its a class , why is it when I create my own class I get a completely > different output with print and type? > >>>> class foo(object): > .. def __init__(self): > .. pass > .. >>>> f=foo() >>>> print f > <__main__.foo object at 0xb743956c> You get that because you didn't provide a __str__() method in your class. As i said in my other message, posix.stat_result is providing that capability for your debugging convenience. There's no requirement to provide it, but that's why the difference. >>>> type(f) > > > > I haven't discovered why sometimes the type output shows type instead of class. There are other ways of defining classes, however, and perhaps this is using one of them. Still, it is a class, and stat() is returning an instance of that class. -- DaveA From hansmu at xs4all.nl Thu Aug 30 09:25:22 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 30 Aug 2012 15:25:22 +0200 Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> Message-ID: <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> On 30/08/12 14:34:51, Marco Nawijn wrote: > Note that if you change 'd' it will change for all instances! That depends on how you change it. >>>> bobj = A() >>>> bobj.d > 'my attribute' > >>>> A.d = 'oops...attribute changed' Here you change the attribute on the class. That will affect all instances: >>>> aobj.d > 'oops...attribute changed' > >>>> bobj.d > 'oops...attribute changed' You can also set the attribute on an instance: >>> bobj.d = 'For bobj only' >>> bobj.d 'For bobj only' >>>> aobj.d > 'oops...attribute changed' So, if you specifically change it on one instance, thenit won't change on other instances of the same class. > If you want attributes to be local to the instance, you have > to define them in the __init__ section of the class like this: That's a good idea, but it's not required. You can set them later, as shown above. > class A(object): > > def __init__(self): > d = 'my attribute' That will just set the global variable d. You want to set the instance attribute: self.d = 'my attribute' >>>> aobj = A() >>>> bobj = A() > >>>> aobj.d > 'my attribute' Note that aobj.d will not find the global variable d, if neither the instance, nor the class nor any of the base classes have that attribute. I don't know where this 'my attribute' comes from, but it's not the instance attribute you tried to set in the __init__ method. Maybe your class A still has a class attribute with that value from an earlier experiment. Hope this helps, -- HansM From nawijn at gmail.com Thu Aug 30 09:27:44 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 06:27:44 -0700 (PDT) Subject: Beginners question In-Reply-To: References: Message-ID: <3f9d7bd0-ff48-42a2-9622-ac56f76041cc@googlegroups.com> On Thursday, August 30, 2012 3:15:03 PM UTC+2, Ulrich Eckhardt wrote: > Am 30.08.2012 13:54, schrieb boltar2003 at boltar.world: > > >>>> s = os.stat(".") > > >>>> print s > > > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, st_u > > > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, st > > > _ctime=1346327754) > > > > > > What sort of object is posix.stat_result? > > > > Use the type() function to find out. I guess that this is a named tuple, > > which is a tuple where the attributes are not indexed but have a name, > > see the documentation for the namedtuple() function from the collections > > library. > > > > Uli It is not a namedtuple. Because a namedtuple "is" a tuple and therefore isinstance(s, tuple) would have returned True. >>> from collections import namedtuple >>> Point = namedtuple('Point', 'x y') >>> p = Point(10,2) >>> isinstance(p, tuple) True From oscar.j.benjamin at gmail.com Thu Aug 30 09:30:29 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 30 Aug 2012 14:30:29 +0100 Subject: Beginners question In-Reply-To: <503F6937.1060106@davea.name> References: <503F6937.1060106@davea.name> Message-ID: On Thu, 30 Aug 2012 09:23:03 -0400, Dave Angel wrote: > I haven't discovered why sometimes the type output shows type instead of > class. There are other ways of defining classes, however, and perhaps > this is using one of them. Still, it is a class, and stat() is > returning an instance of that class. Builtin types show as type and classes defined in python show as class (even if they inherit from builtin types). Oscar From nawijn at gmail.com Thu Aug 30 10:11:06 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 07:11:06 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> Message-ID: <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: > On 30/08/12 14:34:51, Marco Nawijn wrote: > > > > > Note that if you change 'd' it will change for all instances! > > > > That depends on how you change it. > > > > >>>> bobj = A() > > >>>> bobj.d > > > 'my attribute' > > > > > >>>> A.d = 'oops...attribute changed' > > > > Here you change the attribute on the class. > > That will affect all instances: > > > > >>>> aobj.d > > > 'oops...attribute changed' > > > > > >>>> bobj.d > > > 'oops...attribute changed' > > > > You can also set the attribute on an instance: > > > > >>> bobj.d = 'For bobj only' > > >>> bobj.d > > 'For bobj only' > > >>>> aobj.d > > > 'oops...attribute changed' > > > > So, if you specifically change it on one instance, thenit won't > > change on other instances of the same class. > > > > > If you want attributes to be local to the instance, you have > > > to define them in the __init__ section of the class like this: > > > > That's a good idea, but it's not required. You can set them > > later, as shown above. > > > > > > > class A(object): > > > > > > def __init__(self): > > > d = 'my attribute' > > > > That will just set the global variable d. > > You want to set the instance attribute: > > > > self.d = 'my attribute' > > > > >>>> aobj = A() > > >>>> bobj = A() > > > > > >>>> aobj.d > > > 'my attribute' > > > > Note that aobj.d will not find the global variable d, > > if neither the instance, nor the class nor any of the > > base classes have that attribute. > > > > I don't know where this 'my attribute' comes from, but > > it's not the instance attribute you tried to set in the > > __init__ method. Maybe your class A still has a class > > attribute with that value from an earlier experiment. > > > > > > Hope this helps, > > > > -- HansM Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. It is also a little surprising I must say. I always considered them like static variables in C++ (not that I am an expert in C++). I knew of course that you don't have to define a local attribute in the __init__ method of a class, but I consider it good style and since the OP is a self claimed newbie I left out the other option. The missing "self" in the code below was a typo class A(object): def __init__(self): d = 'my attribute' # should be self.d Regards, Marco From d at davea.name Thu Aug 30 10:30:35 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 10:30:35 -0400 Subject: class object's attribute is also the instance's attribute? In-Reply-To: <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> Message-ID: <503F790B.9070901@davea.name> On 08/30/2012 10:11 AM, Marco Nawijn wrote: > On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: >> >> > Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. They're not. They're just visible to the instances, except where the instance has an instance attribute of the same name. Don't be confused by dir(), which shows both instance and class attributes. Please show me an example where you think you observe each instance getting a copy of the class attribute. There's probably some other explanation. -- DaveA From ulrich.eckhardt at dominolaser.com Thu Aug 30 10:41:19 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 30 Aug 2012 16:41:19 +0200 Subject: Beginners question In-Reply-To: <3f9d7bd0-ff48-42a2-9622-ac56f76041cc@googlegroups.com> References: <3f9d7bd0-ff48-42a2-9622-ac56f76041cc@googlegroups.com> Message-ID: Am 30.08.2012 15:27, schrieb Marco Nawijn: > On Thursday, August 30, 2012 3:15:03 PM UTC+2, Ulrich Eckhardt wrote: >> Am 30.08.2012 13:54, schrieb boltar2003 at boltar.world: >>> What sort of object is posix.stat_result? [...] >> I guess that this is a named tuple, which is a tuple where the >> attributes are not indexed but have a name, see the >> documentation for the namedtuple() function from the collections >> library. >> > > It is not a namedtuple. Because a namedtuple "is" a tuple and therefore isinstance(s, tuple) would have returned True. > >>>> from collections import namedtuple >>>> Point = namedtuple('Point', 'x y') >>>> p = Point(10,2) >>>> isinstance(p, tuple) > True Hi Marco, I don't find anything wrong with what you say, the output formatting from using a type created by namedtuple would have been slightly different indeed. However, I also don't understand the point you're trying to make, in particular why it matters that a namedtuple type is derived from tuple, other than perhaps that access by name is available in addition to access by index. Greetings! Uli From nawijn at gmail.com Thu Aug 30 10:48:24 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 07:48:24 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> Message-ID: <721544fd-8734-49cd-b43e-210d61d03f9b@googlegroups.com> On Thursday, August 30, 2012 4:30:59 PM UTC+2, Dave Angel wrote: > On 08/30/2012 10:11 AM, Marco Nawijn wrote: > > > On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: > > >> > > >> > > > Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. > > > > They're not. They're just visible to the instances, except where the > > instance has an instance attribute of the same name. Don't be confused > > by dir(), which shows both instance and class attributes. > > > > Please show me an example where you think you observe each instance > > getting a copy of the class attribute. There's probably some other > > explanation. I don't have an example. It was just what I thought would happen. Consider the following. In a class declaration like this: class A(object): attr_1 = 10 def __init__(self): self.attr_2 = 20 If I instantiated it twice: obj_1 = A() obj_2 = A() For both obj_1 and obj_2 attr_1 equals 10. What I thought would happen after the following statement: obj_1.attr_1 = 12 is that obj_2.attr_1 also equals 12. This is what surprised me a little, that's all. Marco From nawijn at gmail.com Thu Aug 30 10:48:24 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Thu, 30 Aug 2012 07:48:24 -0700 (PDT) Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> Message-ID: <721544fd-8734-49cd-b43e-210d61d03f9b@googlegroups.com> On Thursday, August 30, 2012 4:30:59 PM UTC+2, Dave Angel wrote: > On 08/30/2012 10:11 AM, Marco Nawijn wrote: > > > On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: > > >> > > >> > > > Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. > > > > They're not. They're just visible to the instances, except where the > > instance has an instance attribute of the same name. Don't be confused > > by dir(), which shows both instance and class attributes. > > > > Please show me an example where you think you observe each instance > > getting a copy of the class attribute. There's probably some other > > explanation. I don't have an example. It was just what I thought would happen. Consider the following. In a class declaration like this: class A(object): attr_1 = 10 def __init__(self): self.attr_2 = 20 If I instantiated it twice: obj_1 = A() obj_2 = A() For both obj_1 and obj_2 attr_1 equals 10. What I thought would happen after the following statement: obj_1.attr_1 = 12 is that obj_2.attr_1 also equals 12. This is what surprised me a little, that's all. Marco From solipsis at pitrou.net Thu Aug 30 11:01:33 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 30 Aug 2012 15:01:33 +0000 (UTC) Subject: Flexible string representation, unicode, typography, ... References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: gmail.com> writes: > > Pick up a random text and see the probability this > text match the most optimized case 1 char / 1 byte, > practically never. Funny that you posted a text which does just that: http://mail.python.org/pipermail/python-list/2012-August/629554.html > In a funny way, this is what Python was doing and it > performs better! I honestly suggest you shut up until you have a clue. Regards Antoine. From d at davea.name Thu Aug 30 11:18:26 2012 From: d at davea.name (Dave Angel) Date: Thu, 30 Aug 2012 11:18:26 -0400 Subject: class object's attribute is also the instance's attribute? In-Reply-To: <721544fd-8734-49cd-b43e-210d61d03f9b@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> <721544fd-8734-49cd-b43e-210d61d03f9b@googlegroups.com> Message-ID: <503F8442.40904@davea.name> On 08/30/2012 10:48 AM, Marco Nawijn wrote: > On Thursday, August 30, 2012 4:30:59 PM UTC+2, Dave Angel wrote: >> On 08/30/2012 10:11 AM, Marco Nawijn wrote: >> >>> On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: >> >>>> >> >>>> >> >>> Learned my lesson today. Don't assume you know something. Test it first ;). I have done quite some programming in Python, but did not know that class attributes are still local to the instances. >> >> >> >> They're not. They're just visible to the instances, except where the >> >> instance has an instance attribute of the same name. Don't be confused >> >> by dir(), which shows both instance and class attributes. >> >> >> >> Please show me an example where you think you observe each instance >> >> getting a copy of the class attribute. There's probably some other >> >> explanation. > > I don't have an example. It was just what I thought would happen. Consider the following. In a class declaration like this: > > class A(object): > attr_1 = 10 > > def __init__(self): > self.attr_2 = 20 > > If I instantiated it twice: > > obj_1 = A() > obj_2 = A() > > For both obj_1 and obj_2 attr_1 equals 10. What I thought would happen after the following statement: > > obj_1.attr_1 = 12 > > is that obj_2.attr_1 also equals 12. This is what surprised me a little, that's all. > > Marco > That statement only adds an instance attribute, not modifying the class attribute of the same name. But it does "hide" it from that particular instance. The thing that can be surprising is that if the class attribute is mutable, and you mutate it, rather than assigning it. So for example: class A(object): attr_1 = [10, 9] def __init__(self): self.attr_2 = 20 obj_1 = A() obj_2 = A() obj_1.attr_1.append(3) Then I believe you'll see [10, 9, 3] from both instances. print obj_1.attr_1 print obj_2.attr_1 -- DaveA From hansmu at xs4all.nl Thu Aug 30 11:20:42 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 30 Aug 2012 17:20:42 +0200 Subject: class object's attribute is also the instance's attribute? In-Reply-To: References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> Message-ID: <503f84cb$0$6904$e4fe514c@news2.news.xs4all.nl> On 30/08/12 16:48:24, Marco Nawijn wrote: > On Thursday, August 30, 2012 4:30:59 PM UTC+2, Dave Angel wrote: >> On 08/30/2012 10:11 AM, Marco Nawijn wrote: >>> On Thursday, August 30, 2012 3:25:52 PM UTC+2, Hans Mulder wrote: >>>> >>> Learned my lesson today. Don't assume you know something. Test it first ;). A very important lesson. Next week's lesson will be: if you test it first, then paste it into a message for this forum, then tweak just one unimportant detail, you'll need to test it again. >>> I have done quite some programming in Python, but did not know that class >>> attributes are still local to the instances. >> They're not. They're just visible to the instances, except where the >> instance has an instance attribute of the same name. Don't be confused >> by dir(), which shows both instance and class attributes. >> >> Please show me an example where you think you observe each instance >> getting a copy of the class attribute. There's probably some other >> explanation. > > I don't have an example. It was just what I thought would happen. > Consider the following. In a class declaration like this: > > class A(object): > attr_1 = 10 > > def __init__(self): > self.attr_2 = 20 > > If I instantiated it twice: > > obj_1 = A() > obj_2 = A() > > For both obj_1 and obj_2 attr_1 equals 10. What I thought would happen after the following statement: > > obj_1.attr_1 = 12 > > is that obj_2.attr_1 also equals 12. This is what surprised me a little, that's all. The trick is to look at obj_1.__dict__ to see what is defined locally: >>> obj_1 = A() >>> obj_1.__dict__ {'attr_2': 20} >>> obj_1.attr_1 = 12 >>> obj_1.__dict__ {'attr_2': 20, 'attr_1': 12} Hope this helps, -- HansM From hansmu at xs4all.nl Thu Aug 30 11:38:37 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 30 Aug 2012 17:38:37 +0200 Subject: Beginners question In-Reply-To: References: Message-ID: <503f88fd$0$6989$e4fe514c@news2.news.xs4all.nl> On 30/08/12 14:49:54, Ulrich Eckhardt wrote: > Am 30.08.2012 13:54, schrieb boltar2003 at boltar.world: >>>>> s = os.stat(".") >>>>> print s >> posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, >> st_nlink=2, st_u >> id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, >> st_mtime=1346327754, st >> _ctime=1346327754) >> >> What sort of object is posix.stat_result? > > Use the type() function to find out. I guess that this is a named tuple, > which is a tuple where the attributes are not indexed but have a name, > see the documentation for the namedtuple() function from the collections > library. Named tuples were invented to do this kind of thing. However, stat_result is fairly old, and named tuples had not been invented back then. If named tuples had been invented first, then os.stat would probably have used them. Hope this helps, -- HansM From marco_u at nsgmail.com Thu Aug 30 11:39:17 2012 From: marco_u at nsgmail.com (Marco) Date: Thu, 30 Aug 2012 17:39:17 +0200 Subject: Built-in open() with buffering > 1 References: <5039dd87$0$6851$e4fe514c@news2.news.xs4all.nl> Message-ID: On 08/26/2012 10:25 AM, Hans Mulder wrote: > The algorithm is explained at > http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE Thanks ;) > In other words: open() tries to find a suitable size by > calling os.stat(your_file).st_blksize and if that fails, > it uses io.DEFAULT_BUFFER_SIZE, which is 8192 on my box. Yes, when the parameter `buffering` is a negative integer that is right > Whether you call open with buffering=2 or any larger > number, does not matter: the buffer size will be the > outcome of this algorithm. Mmm, I think it is not right, because in this case the buffer size is not computed but it is the value you assign to the buffering parameter. In fact: >>> f = open('myfile', 'w', buffering=2) >>> f._CHUNK_SIZE = 1 >>> f.write('ab') 2 >>> open('myfile').read() Now two bytes are in the buffer and the buffer is full. If you write another byte, it will not be written in the buffer, because the bytes in the queue will be transferred into the buffer only when they are more than f._CHUNK_SIZE: >>> f.write('c') 1 >>> open('myfile').read() Now, if you write another byte 'd', the chunk 'cd' will be transferred to the buffer, but because it is full, its content 'ab' will be transferred to the disk, and after 'cd' written to the buffer, that still full: >>> f.write('d') 1 >>> open('myfile').read() 'ab' So, the buffer is really of size 2 From ylodis at gmail.com Thu Aug 30 11:51:43 2012 From: ylodis at gmail.com (Ylodis) Date: Thu, 30 Aug 2012 08:51:43 -0700 (PDT) Subject: Basic Question. Deploy new Master/Slave (M/S) datastore Message-ID: Hi, I had an old and deprecated Master/Slave (M/S) datastore and I trying to pass its content to a new Master/Slave (M/S) datastore as is expained here : https://developers.google.com/appengine/docs/adminconsole/migration#Deploying_Your_New_HRD_Application Where it say I have to : "appcfg.py update myapp/" where have I to type that ? From steve+comp.lang.python at pearwood.info Thu Aug 30 12:00:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Aug 2012 16:00:52 GMT Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: > In article <503f0e45$0$9416$c3e8da3$76491128 at news.astraweb.com>, > Steven D'Aprano wrote: > >> The only thing which is innovative here is that instead of the Python >> compiler declaring that "all strings will be stored in UCS-2", the >> compiler chooses an implementation for each string as needed. So some >> strings will be stored internally as UCS-4, some as UCS-2, and some as >> ASCII (which is a standard, but not the Unicode consortium's standard). > > Is the implementation smart enough to know that x == y is always False > if x and y are using different internal representations? But x and y are not necessarily always False just because they have different representations. There may be circumstances where two strings have different internal representations even though their content is the same, so it's an unsafe optimization to automatically treat them as unequal. The closest existing equivalent here is the relationship between ints and longs in Python 2. 42 == 42L even though they have different internal representations and take up a different amount of space. My expectation is that the initial implementation of PEP 393 will be relatively unoptimized, and over the next few releases it will get more efficient. That's usually the way these things go. -- Steven From ian.g.kelly at gmail.com Thu Aug 30 12:27:04 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 30 Aug 2012 10:27:04 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Aug 30, 2012 at 2:51 AM, wrote: > But as soon as you introduce artificially a "latin-1" > bottleneck, all this machinery just become useless. How is this a bottleneck? If you removed the Latin-1 encoding altogether and limited the flexible representation to just UCS-2 / UCS-4, I doubt very much that you would see any significant speed gains. The flexibility is the part that makes string creation slower, not the Latin-1 option in particular. > This flexible representation is working absurdly. > It optimizes the characters you are not using (in one > sense), it defaults to a non optimized form for the > characters you wish to use. I'm sure that if you wanted to you could patch Python to use Latin-9 instead. Just be prepared for it to be slower than UCS-2, since it would mean having to encode the code points rather than merely truncating them. > Pick up a random text and see the probability this > text match the most optimized case 1 char / 1 byte, > practically never. Pick up a random text and see that this text matches the next most optimized case, 1 char / 2 bytes: practically always. > If a user will use exclusively latin-1, she/he is better > served by using a dedicated tool for "latin-1" Speaker as a user who almost exclusively uses Latin-1, I strongly disagree. What you're describing is Python 2.x. The user is always almost better served by not having to worry about the full extent of the character set their program might use. That's why we moved to Unicode strings in Python 3 in the first place. > If a user will comfortably work with Unicode, she/he is > better served by using one of this tools which is using > properly one of the available Unicode schemes. > > In a funny way, this is what Python was doing and it > performs better! Seriously, please show us just one *real world* benchmark in which Python 3.3 performs demonstrably worse than Python 3.2. All you've shown so far is this one microbenchmark of string creation that is utterly irrelevant to actual programs. From breamoreboy at yahoo.co.uk Thu Aug 30 13:27:17 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 30 Aug 2012 18:27:17 +0100 Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: References: Message-ID: On 30/08/2012 16:51, Ylodis wrote: > Hi, > > I had an old and deprecated Master/Slave (M/S) datastore > and I trying to pass its content to a new Master/Slave (M/S) datastore as is expained here : > https://developers.google.com/appengine/docs/adminconsole/migration#Deploying_Your_New_HRD_Application > > Where it say I have to : > > "appcfg.py update myapp/" > > where have I to type that ? > The facetious answer is the keyboard as this isn't really a Python question :) I haven't looked at the link but I assume you need a console or terminal window for your OS, that's cmd for Windows for which you might need administrator privileges as I've no idea what you're doing. -- Cheers. Mark Lawrence. From ylodis at gmail.com Thu Aug 30 13:37:03 2012 From: ylodis at gmail.com (Ylodis) Date: Thu, 30 Aug 2012 10:37:03 -0700 (PDT) Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: References: Message-ID: <9bf206ff-994b-43b8-ba94-a89b7ef0830e@googlegroups.com> I am trying to use a Google public storage that is managed in python. I do web developement, I have very litle idea about python, english is not my natural language and as you can see, I am very lost. I do not even now which group cold help me. The details of what I want to do are in the link. From python.list at tim.thechases.com Thu Aug 30 13:49:36 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 30 Aug 2012 12:49:36 -0500 Subject: mailbox.mbox Status/X-Status flags RFC? Message-ID: <503FA7B0.7090802@tim.thechases.com> Playing around with mailbox.mbox, I noticed the flag get split across Status/X-Status headers. I dug into the source and read at [1] to see the *how* but I'm curious as to the *why*. When I pulled up RFC-4155[2] (mbox), it didn't seem to mention anything about the Status/X-Status stuff, and the MaildirMessage stores flags differently (and with different meanings). Anybody have some insight (or an RFC document) that would help this make sense to me? Thanks, -tkc [1] http://docs.python.org/library/mailbox.html#mboxmessage [2] http://tools.ietf.org/html/rfc4155 From oscar.j.benjamin at gmail.com Thu Aug 30 13:58:14 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 30 Aug 2012 18:58:14 +0100 Subject: class object's attribute is also the instance's attribute? In-Reply-To: <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> Message-ID: On 30 August 2012 15:11, Marco Nawijn wrote: > > > Learned my lesson today. Don't assume you know something. Test it first > ;). I have done quite some programming in Python, but did not know that > class attributes are still local to the instances. It is also a little > surprising I must say. I always considered them like static variables in > C++ (not that I am an expert in C++). > Class attributes are analogous to static variables in C++ provided you only ever assign to them as an attribute of the class. >>> class A(object): ... static = 5 ... >>> a = A() >>> a.static 5 >>> A.static 5 >>> b = A() >>> b.static 5 >>> A.static = 10 >>> a.static 10 >>> b.static 10 An instance attribute with the same name as a class attribute hides the class attribute for that instance only. >>> b.static = -1 >>> a.static 10 >>> b.static -1 >>> del b.static >>> b.static 10 This is analogous to having a local variable in a function that hides a module level variable with the same name: x = 10 def f1(): x = 4 print(x) def f2(): print(x) f2() # 10 f1() # 4 f2() # still 10 If you want f1 to modify the value of x seen by f2 then you should explicitly declare x as global in f1. Likewise if you want to modify an attribute for all instances of a class you should explicitly assign to the class attribute rather than an instance attribute. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Aug 30 14:16:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Aug 2012 14:16:49 -0400 Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: References: Message-ID: On 8/30/2012 11:51 AM, Ylodis wrote: > Hi, > > I had an old and deprecated Master/Slave (M/S) datastore > and I trying to pass its content to a new Master/Slave (M/S) datastore as is expained here : > https://developers.google.com/appengine/docs/adminconsole/migration#Deploying_Your_New_HRD_Application > > Where it say I have to : > > "appcfg.py update myapp/" > > where have I to type that ? I have not used app engine, but ... Since the action needs to happen on the Google servers, rather than on your machine, I would expect that there should be a text box in the Administration Console (looking above Deploying Your New ... . -- Terry Jan Reedy From tjreedy at udel.edu Thu Aug 30 14:22:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Aug 2012 14:22:45 -0400 Subject: Beginners question In-Reply-To: References: <503F6937.1060106@davea.name> Message-ID: On 8/30/2012 9:30 AM, Oscar Benjamin wrote: > On Thu, 30 Aug 2012 09:23:03 -0400, Dave Angel wrote: >> I haven't discovered why sometimes the type output shows type > instead of >> class. There are other ways of defining classes, however, and > perhaps >> this is using one of them. Still, it is a class, and stat() is >> returning an instance of that class. > > Builtin types show as type and classes defined in python show as class > (even if they inherit from builtin types). Only in 2.x, and this goes back to the old user class system, which the OP should not have to learn about. >>> type(1) -- Terry Jan Reedy From jonnojohnson at gmail.com Thu Aug 30 16:11:57 2012 From: jonnojohnson at gmail.com (Jonno) Date: Thu, 30 Aug 2012 15:11:57 -0500 Subject: Making sense of a traceback from py2exe Message-ID: Not sure where the best place to post this is. My app uses wxpython, matplotlib. I'm running Python 2.7 on Windows 7. I have a script app.py that I'm trying to turn into app.exe using py2exe. The exe runs fine on the pc that it was compiled on but on another Win7 machine I get something like the following in the app.exe.log: Traceback (most recent call last): File "app.py", line 1951, in File "wx\_core.pyo", line 7981, in __init__ File "wx\_core.pyo", line 7555, in _BootstrapApp File "app.py", line 1944, in OnInit File "app.py", line 1811, in __init__ File "matplotlib\backends\backend_wxagg.pyo", line 59, in draw File "matplotlib\backends\backend_agg.pyo", line 401, in draw File "matplotlib\artist.pyo", line 55, in draw_wrapper File "matplotlib\figure.pyo", line 884, in draw File "matplotlib\artist.pyo", line 55, in draw_wrapper File "matplotlib\axes.pyo", line 1983, in draw File "matplotlib\artist.pyo", line 55, in draw_wrapper File "matplotlib\text.pyo", line 526, in draw File "matplotlib\text.pyo", line 309, in _get_layout File "matplotlib\backends\backend_agg.pyo", line 179, in get_text_width_height_descent File "matplotlib\mathtext.pyo", line 2974, in parse File "matplotlib\mathtext.pyo", line 2352, in parse File "matplotlib\pyparsing.pyo", line 1048, in parseString File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2559, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2307, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2679, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2307, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2756, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2714, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2373, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2559, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2416, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2559, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2559, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2416, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2293, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2756, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2559, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2373, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache File "matplotlib\pyparsing.pyo", line 2416, in parseImpl File "matplotlib\pyparsing.pyo", line 981, in _parseCache File "matplotlib\pyparsing.pyo", line 950, in _parseNoCache File "matplotlib\mathtext.pyo", line 2469, in symbol File "matplotlib\mathtext.pyo", line 1312, in __init__ File "matplotlib\mathtext.pyo", line 1319, in _update_metrics File "matplotlib\mathtext.pyo", line 485, in get_metrics File "matplotlib\mathtext.pyo", line 618, in _get_info File "matplotlib\mathtext.pyo", line 720, in _get_glyph KeyError: 98 Traceback (most recent call last): File "wx\_core.pyo", line 14669, in File "app.py", line 826, in _init_panels AttributeError: 'MyApp' object has no attribute 'frame' I need some help picking apart the Traceback. Why are there two tracebacks and which is the first to be triggered? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Aug 30 16:44:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Aug 2012 16:44:32 -0400 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8/30/2012 12:00 PM, Steven D'Aprano wrote: > On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: > >> In article <503f0e45$0$9416$c3e8da3$76491128 at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> The only thing which is innovative here is that instead of the Python >>> compiler declaring that "all strings will be stored in UCS-2", the >>> compiler chooses an implementation for each string as needed. So some >>> strings will be stored internally as UCS-4, some as UCS-2, and some as >>> ASCII (which is a standard, but not the Unicode consortium's standard). >> >> Is the implementation smart enough to know that x == y is always False >> if x and y are using different internal representations? Yes, after checking lengths, and in same circumstances, x != y is True. From http://hg.python.org/cpython/file/ab6ab44921b2/Objects/unicodeobject.c PyObject * PyUnicode_RichCompare(PyObject *left, PyObject *right, int op) { int result; if (PyUnicode_Check(left) && PyUnicode_Check(right)) { PyObject *v; if (PyUnicode_READY(left) == -1 || PyUnicode_READY(right) == -1) return NULL; if (PyUnicode_GET_LENGTH(left) != PyUnicode_GET_LENGTH(right) || PyUnicode_KIND(left) != PyUnicode_KIND(right)) { if (op == Py_EQ) { Py_INCREF(Py_False); return Py_False; } if (op == Py_NE) { Py_INCREF(Py_True); return Py_True; } } ... KIND is 1,2,4 bytes/char 'a in s' is also False if a chars are wider than s chars. If s is all ascii, s.encode('ascii') or s.encode('utf-8') is a fast, constant time operation, as I showed earlier in this discussion. This is one thing that is much faster in 3.3. Such things can be tested by timing with different lengths of strings, where the initial string creation is done in setup code rather than in the repeated operation code. > But x and y are not necessarily always False just because they have > different representations. There may be circumstances where two strings > have different internal representations even though their content is the > same, so it's an unsafe optimization to automatically treat them as > unequal. I am sure that str objects are always in canonical form once visible to Python code. Note that unready (non-canonical) objects are rejected by the rich comparison function. > My expectation is that the initial implementation of PEP 393 will be > relatively unoptimized, The initial implementation was a year ago. At least three people have expended considerable effort improving it since, so that the slowdown mentioned in the PEP has mostly disappeared. The things that are still slower are somewhat balanced by things that are faster. -- Terry Jan Reedy From jonnojohnson at gmail.com Thu Aug 30 17:02:46 2012 From: jonnojohnson at gmail.com (Jonno) Date: Thu, 30 Aug 2012 16:02:46 -0500 Subject: Making sense of a traceback from py2exe In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 3:11 PM, Jonno wrote: > Not sure where the best place to post this is. My app uses wxpython, > matplotlib. > I'm running Python 2.7 on Windows 7. > I have a script app.py that I'm trying to turn into app.exe using py2exe. > The exe runs fine on the pc that it was compiled on but on another Win7 > machine I get something like the following in the app.exe.log: > > Traceback (most recent call last): > File "app.py", line 1951, in > File "wx\_core.pyo", line 7981, in __init__ > File "wx\_core.pyo", line 7555, in _BootstrapApp > File "app.py", line 1944, in OnInit > File "app.py", line 1811, in __init__ > File "matplotlib\backends\backend_wxagg.pyo", line 59, in draw > File "matplotlib\backends\backend_agg.pyo", line 401, in draw > File "matplotlib\artist.pyo", line 55, in draw_wrapper > File "matplotlib\figure.pyo", line 884, in draw > File "matplotlib\artist.pyo", line 55, in draw_wrapper > File "matplotlib\axes.pyo", line 1983, in draw > File "matplotlib\artist.pyo", line 55, in draw_wrapper > File "matplotlib\text.pyo", line 526, in draw > File "matplotlib\text.pyo", line 309, in _get_layout > File "matplotlib\backends\backend_agg.pyo", line 179, in > get_text_width_height_descent > File "matplotlib\mathtext.pyo", line 2974, in parse > File "matplotlib\mathtext.pyo", line 2352, in parse > File "matplotlib\pyparsing.pyo", line 1048, in parseString > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2559, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2307, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2679, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2307, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2756, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2714, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2373, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2559, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2416, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2559, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2559, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2416, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2293, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2756, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2559, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2373, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 924, in _parseNoCache > File "matplotlib\pyparsing.pyo", line 2416, in parseImpl > File "matplotlib\pyparsing.pyo", line 981, in _parseCache > File "matplotlib\pyparsing.pyo", line 950, in _parseNoCache > File "matplotlib\mathtext.pyo", line 2469, in symbol > File "matplotlib\mathtext.pyo", line 1312, in __init__ > File "matplotlib\mathtext.pyo", line 1319, in _update_metrics > File "matplotlib\mathtext.pyo", line 485, in get_metrics > File "matplotlib\mathtext.pyo", line 618, in _get_info > File "matplotlib\mathtext.pyo", line 720, in _get_glyph > KeyError: 98 > Traceback (most recent call last): > File "wx\_core.pyo", line 14669, in > File "app.py", line 826, in _init_panels > AttributeError: 'MyApp' object has no attribute 'frame' > > I need some help picking apart the Traceback. > > Why are there two tracebacks and which is the first to be triggered? > Well I managed to figure out that the first traceback is the one causing the problem and that matplotlib/mathtext in my app is the problem. Now to figure out how to get mathtext working. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vasudevram at gmail.com Thu Aug 30 17:57:53 2012 From: vasudevram at gmail.com (vasudevram) Date: Thu, 30 Aug 2012 14:57:53 -0700 (PDT) Subject: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python Message-ID: <229067cc-dee6-4f0c-bcf2-c30f20b4a9be@googlegroups.com> I wrote PipeController recently to experiment with doing UNIX-style pipes in Python. Blog post about it: http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html The blog post has a link to the downloadable PipeController source code. It will be released under the New BSD License, which means you can use it for any purpose, commercial or otherwise, subject to the terms of the license. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram From sjlukacs at gmail.com Thu Aug 30 18:11:11 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 15:11:11 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" Message-ID: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> ok, i am stuck. i tried some test code attempts and i am stuck. so here is some sample code: xx2 = """ def lucas53(): harry = (4+16)/2 rtn = dict(harry=harry) return rtn """ and then i run: env = {} exec xx2 in env lst = env and lst returns a huge dictionary of many types, some excerpts are: {... ...'globals': , ... ...'vars': , ... ...'locals': , ... ...'lucas53': } and i can see my executed function in there as a type function, and local and global vars, but i can not access or find "harry" or "rtn" the variables within the function lucas53. i do not know how to access the local variables within lucas53 or the locals to find harry or rtn. i really just want the return dictionary. make sense? anyway, python impresses me with its graceful and concise code, but i really have not found the solution to this mess. please advise and thank you in advance. lucas From rosuav at gmail.com Thu Aug 30 18:19:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Aug 2012 08:19:12 +1000 Subject: get return or locals from "exec" str in "environment" In-Reply-To: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> Message-ID: On Fri, Aug 31, 2012 at 8:11 AM, lucas wrote: > and i can see my executed function in there as a type function, and local and global vars, but i can not access or find "harry" or "rtn" the variables within the function lucas53. i do not know how to access the local variables within lucas53 or the locals to find harry or rtn. i really just want the return dictionary. make sense? Far as I can see, you never actually called that function anywhere. ChrisA From sjlukacs at gmail.com Thu Aug 30 18:25:17 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 15:25:17 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> Message-ID: <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> > Far as I can see, you never actually called that function anywhere. > ChrisA doesn't the exec command call the function? From sjlukacs at gmail.com Thu Aug 30 18:25:17 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 15:25:17 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> Message-ID: <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> > Far as I can see, you never actually called that function anywhere. > ChrisA doesn't the exec command call the function? From ylodis at gmail.com Thu Aug 30 18:32:56 2012 From: ylodis at gmail.com (Ylodis) Date: Thu, 30 Aug 2012 15:32:56 -0700 (PDT) Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: References: Message-ID: <5661994d-4604-4a13-abfa-3aced0b84c75@googlegroups.com> That is the question, where have I to write, and what have I to write. My old acount was tarot-gratis, the new account is tarot-gratis-hrd. What have I to write, where Google help says "myapp" ? Where should I write appcfg.py update 'myapp'/ From ylodis at gmail.com Thu Aug 30 18:32:56 2012 From: ylodis at gmail.com (Ylodis) Date: Thu, 30 Aug 2012 15:32:56 -0700 (PDT) Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: References: Message-ID: <5661994d-4604-4a13-abfa-3aced0b84c75@googlegroups.com> That is the question, where have I to write, and what have I to write. My old acount was tarot-gratis, the new account is tarot-gratis-hrd. What have I to write, where Google help says "myapp" ? Where should I write appcfg.py update 'myapp'/ From rosuav at gmail.com Thu Aug 30 18:45:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Aug 2012 08:45:14 +1000 Subject: get return or locals from "exec" str in "environment" In-Reply-To: <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> Message-ID: On Fri, Aug 31, 2012 at 8:25 AM, lucas wrote: >> Far as I can see, you never actually called that function anywhere. >> ChrisA > > doesn't the exec command call the function? (Side point: You don't have to post to both comp.lang.python and python-list - they mirror each other.) What you executed included the 'def' statement. That's an executable statement that creates a function object: 'lucas53': In Python, functions are objects just like dictionaries, strings, and integers; you can construct them (usually with 'def' or 'lambda'), pass them around, tinker with their attribututes, and ultimately, call them. But unless you do actually call that function, none of its code will be executed. You can test this by putting a 'print' inside the function; you'll see screen output when the function's called, and your code above won't show that. To access the local variables/names from the function itself, you'll need to put a call to locals() inside that function, because as soon as it finishes, those locals disappear. Try this: >>> xx2 = """ def lucas53(): harry = (4+16) / 2 rtn = dict(harry=harry) return rtn foo = lucas53() """ >>> env = {} >>> exec(xx2,env) (This is Python 3 syntax, exec is now a function - otherwise equivalent to what you did.) You'll now see a name 'foo' in env, with the mapping returned from your function. There's no peeking into locals here, just a straight function return value. Is this what you were looking for? ChrisA From breamoreboy at yahoo.co.uk Thu Aug 30 18:46:02 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 30 Aug 2012 23:46:02 +0100 Subject: Basic Question. Deploy new Master/Slave (M/S) datastore In-Reply-To: <5661994d-4604-4a13-abfa-3aced0b84c75@googlegroups.com> References: <5661994d-4604-4a13-abfa-3aced0b84c75@googlegroups.com> Message-ID: On 30/08/2012 23:32, Ylodis wrote: > That is the question, where have I to write, and what have I to write. > > My old acount was tarot-gratis, the new account is tarot-gratis-hrd. > > What have I to write, where Google help says "myapp" ? Where should I write appcfg.py update 'myapp'/ > Probably where Terry Reedy told you to look some hours ago!!! -- Cheers. Mark Lawrence. From cs at zip.com.au Thu Aug 30 18:47:56 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 31 Aug 2012 08:47:56 +1000 Subject: Sending USB commands with Python In-Reply-To: <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com> References: <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com> Message-ID: <20120830224756.GA28359@cskk.homeip.net> On 30Aug2012 05:51, Adam W. wrote: | On Thursday, August 30, 2012 12:55:14 AM UTC-4, Dennis Lee Bieber wrote: | > How many bytes did it claim to send? | | 11, which is what I expected. But I changed the byte value to 16 | (because I was having trouble getting single digit hex values working | in the command) and sent this command: | | >>> for x in range(0,500): | ep.write(b'\x16\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF') | | it respond with 500 17's and prints a black bar! So it looks like whatever concern you had with using encode was coming to fruition. Yeah. Try 'iso8859-1' instead of 'utf-8'. You want to be not translating the byte values at all. UTF-8 encodes character values over 127 as multibyte sequences. ISO8859-1 is a 256 code set that does no translation - character codes in go directly to byte values out. You're speaking a binary protocol, not text, so you want a one to one mapping. Better still would be to be using a bytes I/O layer instead of one with a text->byte translation; I do not know if the USB library you're using offers such. So try 'iso8859-1'; at least the translation is a no-op. Cheers, -- Cameron Simpson B1FF is an archetype, and all you're showing us is one of the more amusing of his many instantiations. - Howard E. Motteler Ah, perhaps Arthur Clarke anticipated this in his celebrated short story, "The Nine Million Names Of B1FF"? - Nosy From sjlukacs at gmail.com Thu Aug 30 19:54:18 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 16:54:18 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> Message-ID: <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> oh, yeah that was perfect. got it working and it is graceful too. sorry about the double post, i thought i was only posting to this one. one final concern, if this code is running under a function in a multi-threaded, multi-session kind of environment, does exec cross threads or sessions? like, i am afraid that i will get cross-over or bleeding into other threads or sessions. does exec do that kind of common memory space wherein i have to be very very careful about executing such code and my daemon crashing or security holes and the like. lucas From sjlukacs at gmail.com Thu Aug 30 19:54:18 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 16:54:18 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> Message-ID: <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> oh, yeah that was perfect. got it working and it is graceful too. sorry about the double post, i thought i was only posting to this one. one final concern, if this code is running under a function in a multi-threaded, multi-session kind of environment, does exec cross threads or sessions? like, i am afraid that i will get cross-over or bleeding into other threads or sessions. does exec do that kind of common memory space wherein i have to be very very careful about executing such code and my daemon crashing or security holes and the like. lucas From sjlukacs at gmail.com Thu Aug 30 19:56:51 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 16:56:51 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> Message-ID: also, does that environment space, what i am assigning as env, have any such common memory space or cross thread problem with simultaneous threads or sessions? From sjlukacs at gmail.com Thu Aug 30 19:56:51 2012 From: sjlukacs at gmail.com (lucas) Date: Thu, 30 Aug 2012 16:56:51 -0700 (PDT) Subject: get return or locals from "exec" str in "environment" In-Reply-To: <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> Message-ID: also, does that environment space, what i am assigning as env, have any such common memory space or cross thread problem with simultaneous threads or sessions? From ben+python at benfinney.id.au Thu Aug 30 19:58:49 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Aug 2012 09:58:49 +1000 Subject: class object's attribute is also the instance's attribute? References: <3830e549-cb6d-4bcf-af45-f7c83ad2b65e@googlegroups.com> <503f69c2$0$6872$e4fe514c@news2.news.xs4all.nl> <9246f6a0-b570-461d-b3a3-818b7138531a@googlegroups.com> <503f84cb$0$6904$e4fe514c@news2.news.xs4all.nl> Message-ID: <87wr0gaq4m.fsf@benfinney.id.au> Hans Mulder writes: > Next week's lesson will be: if you test it first, then paste it into a > message for this forum, then tweak just one unimportant detail, you'll > need to test it again. +1 QotW -- \ ?Look at it this way: Think of how stupid the average person | `\ is, and then realise half of 'em are stupider than that.? | _o__) ?George Carlin, _Doin' It Again_, 1990 | Ben Finney From rosuav at gmail.com Thu Aug 30 20:13:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Aug 2012 10:13:52 +1000 Subject: get return or locals from "exec" str in "environment" In-Reply-To: <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> References: <5c488ca5-d730-40c4-b860-7a53201f21ae@googlegroups.com> <599e5709-22ab-4e85-8443-181a2ae19c17@googlegroups.com> <1616cffa-23ea-4377-b415-fa143d0c5e5d@googlegroups.com> Message-ID: On Fri, Aug 31, 2012 at 9:54 AM, lucas wrote: > oh, yeah that was perfect. got it working and it is graceful too. sorry about the double post, i thought i was only posting to this one. Hehe, you're still posting to both. I don't see the duplicates myself, but I'm sure others do. Just pick one and ignore the other. > one final concern, if this code is running under a function in a multi-threaded, multi-session kind of environment, does exec cross threads or sessions? like, i am afraid that i will get cross-over or bleeding into other threads or sessions. does exec do that kind of common memory space wherein i have to be very very careful about executing such code and my daemon crashing or security holes and the like. Not that I am aware of, and I would be extremely surprised if there were any. But exec is not the sort of thing you'll normally want to use. What are you trying to accomplish? There's usually an alternative. The only time I've used an exec-like feature is when I'm actually writing something that loads code from the disk at run-time, such as my MUD with room files that look like this: @sdesc Short Description @ldesc This is the long description of the room, blah blah @cmds thwap #do_something_when_user_types_thwap() VERY unusual sort of thing to do - having real code in a data file. ChrisA From bernhard.haslhofer at gmail.com Thu Aug 30 21:44:50 2012 From: bernhard.haslhofer at gmail.com (bernhard.haslhofer at gmail.com) Date: Thu, 30 Aug 2012 18:44:50 -0700 (PDT) Subject: Python Logging: Specifying converter attribute of a log formatter in config file In-Reply-To: <97b8c5f2-eaa9-456a-b766-146ac65b879e@googlegroups.com> References: <97b8c5f2-eaa9-456a-b766-146ac65b879e@googlegroups.com> Message-ID: I have the same problem and couldn't find a solution. It seems that converters can only be set programmatically? On Thursday, August 30, 2012 6:38:27 AM UTC-4, Radha Krishna Srimanthula wrote: > I'd like to have all timestamps in my log file to be UTC timestamp. When specified through code, this is done as follows: > > > > myHandler = logging.FileHandler('mylogfile.log', 'a') > > formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(name)-15s:%(lineno)4s: %(message)-80s') > > formatter.converter = time.gmtime > > > > myLogger = logging.getLogger('MyApp') > > myLogger.addHandler(myHandler) > > > > > > I'd like to move away from the above 'in-code' configuration to a config file based mechanism. > > > > Here's the config file section for the formatter: > > > > [handler_MyLogHandler] > > args=("mylogfile.log", "a",) > > class=FileHandler > > level=DEBUG > > formatter=simpleFormatter > > > > Now, how do I specify the converter attribute (time.gmtime) in the above section? From jonnojohnson at gmail.com Thu Aug 30 21:51:50 2012 From: jonnojohnson at gmail.com (Jonno) Date: Thu, 30 Aug 2012 20:51:50 -0500 Subject: Making sense of a traceback from py2exe In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 4:02 PM, Jonno wrote: > > Well I managed to figure out that the first traceback is the one causing > the problem and that matplotlib/mathtext in my app is the problem. > Now to figure out how to get mathtext working. > Bit more information: I am also seeing warnings in app.exe.log: C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXGeneral'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeOneSym'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=bold:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeThreeSym'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeFourSym'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeFiveSym'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeTwoSym'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=italic:variant=normal:weight=normal:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXNonUnicode'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmb10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmtt10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmmi10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmex10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmsy10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmr10'] not found. Falling back to Bitstream Vera Sans C:\Users\Administrator\Desktop\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmss10'] not found. Falling back to Bitstream Vera Sans I think these are all fonts that matplotlib/mathtext would use so it makes sense that the traceback ends with: File "matplotlib\mathtext.pyo", line 720, in _get_glyph KeyError: 98 I then discovered that both the methods I tried for getting data_files (using glob and matplotlib.get_py2exe_datafiles) were not working and I had nothing in my mpl-data/fonts directory. This directory should contain 3 folders: afm, pdfcorefonts & ttf. The ttf folder is where the mathtext fonts mentioned above are located. I then tried manually copying the entire mpl-data folder into the dist folder after running py2exe on setup.py but still I get the same error. Does data_files do anything other than include files and directories in the dist folder? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason at powerpull.net Thu Aug 30 22:22:43 2012 From: jason at powerpull.net (Jason Friedman) Date: Thu, 30 Aug 2012 20:22:43 -0600 Subject: Dumping all the sql statements as backup In-Reply-To: References: Message-ID: >> I have some long running processes that do very long simulations which >> at the end need to write things on a database. >> >> At the moment sometimes there are network problems and we end up with >> half the data on the database. >> >> The half-data problem is probably solved easily with sessions and >> sqlalchemy (a db-transaction), but still we would like to be able to >> keep a backup SQL file in case something goes badly wrong and we want to >> re-run it manually.. >> >> This might also be useful if we have to rollback the db for some reasons >> to a previous day and we don't want to re-run the simulations.. >> >> Anyone did something similar? >> It would be nice to do something like: >> >> with CachedDatabase('backup.sql'): >> # do all your things > " ... at the end need to write things on a database ... " Is it necessary to write those things during the process, or only at the end? If only at the end, can you write locally first, and then write that local store to your remote database? From ben+python at benfinney.id.au Thu Aug 30 22:36:29 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Aug 2012 12:36:29 +1000 Subject: Context manager to save/restore a name binding Message-ID: <87oblrbxea.fsf@benfinney.id.au> Howdy all, I have written a context manager to save and restore a name binding:: import contextlib @contextlib.contextmanager def preserve_value(namespace, name): """ A context manager to preserve, then restore, the specified binding. :param namespace: The namespace object (e.g. a class or dict) containing the name binding. :param name: The name of the binding to be preserved. :yield: None. When the context manager is entered, the current value bound to `name` in `namespace` is saved. When the context manager is exited, the binding is re-established to the saved value. """ saved_value = getattr(namespace, name) yield setattr(namespace, name, saved_value) The use case is , where it's used like this:: with preserve_value(sys, 'dont_write_bytecode'): sys.dont_write_bytecode = True module = imp.load_module(?) That way, I can set ?sys.dont_write_bytecode? to the value I need in this part of the code, knowing that however the code continues the previous value of that setting will be restored to whatever it was before I touched it. Have I re-invented a context manager which already exists? Is there a better way to do what ?preserve_value? is doing? -- \ ?When a well-packaged web of lies has been sold to the masses | `\ over generations, the truth will seem utterly preposterous and | _o__) its speaker a raving lunatic.? ?Dresden James | Ben Finney From timr at probo.com Thu Aug 30 23:55:37 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 30 Aug 2012 20:55:37 -0700 Subject: Sending USB commands with Python References: <09ec368e-9079-46dc-a70a-3ae345d7996c@googlegroups.com> Message-ID: "Adam W." wrote: > >You are correct about the 2 being the number of bytes written. However when I issue a read command I get: > >>>> ep.write('\x1BA') >4 >>>> ep.read(1) >usb.core.USBError: [Errno None] b'libusb0-dll:err [_usb_setup_async] invalid endpoint 0x02\n' USB endponts only go in one direction. There will be one endpoint for outoging data, and one endpoint for incoming data. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From robertmiles at teranews.com Thu Aug 30 23:56:26 2012 From: robertmiles at teranews.com (Robert Miles) Date: Thu, 30 Aug 2012 22:56:26 -0500 Subject: OT: Text editors In-Reply-To: References: <87pq7fqhlh.fsf@benfinney.id.au> Message-ID: <%BW%r.128$gP6.41@newsfe16.iad> On 7/29/2012 5:28 AM, Mark Lawrence wrote: > On 29/07/2012 06:08, Ben Finney wrote: >> Tim Chase writes: >> >>> On Sat, Jul 28, 2012 at 6:29 PM, Mark Lawrence wrote: >>>> I highly recommend the use of notepad++. If anyone knows of a >>>> better text editor for Windows please let me know :) >> >> I highly recommend not tying your editor skills to a single OS, >> especially one as ornery for programmers as Windows. >> >>> I'll advocate for Vim which is crazy-powerful and works nicely on >>> just about any platform I touch. >>> >>> Others will advocate for Emacs, which I can't say fits the way my >>> brain works but it's also powerful and loved by many. >> >> Right. I'm in Tim's position, but reversed: my preference is for Emacs >> but Vim is a fine choice also. They are mature, well-supported with >> regular updates and a massive library of plug-ins for different uses, >> have a huge community to help you, and work on all major programming >> OSen. >> >>> The ubiquity of these two platforms makes a worthwhile investment of >>> time spent in learning at least one if not both. >> >> I use both frequently in my work for different things, and they are good >> for pretty much any task involving manipulation of text. >> >> Learn one of Emacs or Vim well, and you won't need to worry about text >> editors again. >> > > Point taken, snag being I've never used any nix box in anger. This > thread reminds of the good 'ole days when I were a lad using TPU on VMS. > Have we got any VMS aficionados here? I used to run two VMS superminis. I'm not sure whether I still could, though. Robert Miles From wrw at mac.com Fri Aug 31 00:21:30 2012 From: wrw at mac.com (William Ray Wing) Date: Fri, 31 Aug 2012 00:21:30 -0400 Subject: OT: Text editors In-Reply-To: <%BW%r.128$gP6.41@newsfe16.iad> References: <87pq7fqhlh.fsf@benfinney.id.au> <%BW%r.128$gP6.41@newsfe16.iad> Message-ID: <34C0CE7E-065A-4735-B774-76257FD51626@mac.com> > On 7/29/2012 5:28 AM, Mark Lawrence wrote: >> On 29/07/2012 06:08, Ben Finney wrote: >>> Tim Chase writes: >>> [byte] >> >> Point taken, snag being I've never used any nix box in anger. This >> thread reminds of the good 'ole days when I were a lad using TPU on VMS. >> Have we got any VMS aficionados here? > Absolutely, I used to do real time data acquisition on DEC machines. Started on PDP-8e's, graduated to PDP-12's, then jumped to 780's, and finished up on 8700's. Used CAMAC gear for the actual real-world interfaces; all at a well-known Dept. of Energy lab. Too many years ago. Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Aug 31 02:27:13 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Aug 2012 08:27:13 +0200 Subject: Context manager to save/restore a name binding References: <87oblrbxea.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > I have written a context manager to save and restore a name binding:: > > import contextlib > > @contextlib.contextmanager > def preserve_value(namespace, name): > """ A context manager to preserve, then restore, the specified > binding. > > :param namespace: The namespace object (e.g. a class or dict) > containing the name binding. > :param name: The name of the binding to be preserved. > :yield: None. > > When the context manager is entered, the current value bound > to `name` in `namespace` is saved. When the context manager is > exited, the binding is re-established to the saved value. > > """ > saved_value = getattr(namespace, name) > yield > setattr(namespace, name, saved_value) > > The use case is , where > it's used like this:: > > with preserve_value(sys, 'dont_write_bytecode'): > sys.dont_write_bytecode = True > module = imp.load_module(?) > > That way, I can set ?sys.dont_write_bytecode? to the value I need in > this part of the code, knowing that however the code continues the > previous value of that setting will be restored to whatever it was > before I touched it. > > Have I re-invented a context manager which already exists? Is there a > better way to do what ?preserve_value? is doing? You should wrap yield in a try ... finally. You might allow setting the new value in the manager (untested): import contextlib missing = object() @contextlib.contextmanager def preserve_attr(namespace, name, value=missing): saved_value = getattr(namespace, name) if value is not missing: setattr(namespace, name, value) try: yield finally: setattr(namespace, name, saved_value) From mullapervez at gmail.com Fri Aug 31 04:40:23 2012 From: mullapervez at gmail.com (Mulla) Date: Fri, 31 Aug 2012 01:40:23 -0700 (PDT) Subject: Call perl to store data in DB Message-ID: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> hey, when i submit the form in html , the entered data (fname,lanme,uname.....)all have to come in perl script to store that data in DB. Python View.py def ProfileRegistration(request): if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') if request.method == 'POST': form = RegistrationForm(data=request.POST, files=request.FILES) if form.is_bound and form.is_valid(): user = User.objects.create_user(username=form.cleaned_data['username'], email=form.cleaned_data['email'], password=form.cleaned_data['password'],) new_user= user.save() profile = Profile(user=user,firstname=form.cleaned_data['firstname'], lastname=form.cleaned_data['lastname'], telephone=form.cleaned_data['telephone'], service=form.cleaned_data['service'], servicetype=form.cleaned_data['servicetype'],) new_user = profile.save() # messages.info(request, "Thank you for registration.Please login to continue") # login(request, new_user) return HttpResponseRedirect('/dashboard/') else: return render_to_response('register.html',{'form': form},context_instance=RequestContext(request)) else: form = RegistrationForm() context = {'form':form} return render_to_response('register.html',context, context_instance=RequestContext(request)) Below in my perl script #!/usr/bin/perl use strict; use warnings; use user; my $tempuser = new user (); if ($tempuser->readbyfirstname('Pervez') eq 1) { # Continue processing since we found a match if($tempuser->{lastname} eq 'Noel') { print "Name already exists, \n"; } } my $tempuser1 = new user(); $tempuser1->readbyemail_id('mullapervez at gmail.com'); if($tempuser1->{email_id} eq 'mullapervez at gmail.com') { print "email_id is in use \n"; } my $tempuser2 = new user(); $tempuser2->readbyusername('Tim_sir'); if ($tempuser2->{username} eq 'Mulla') { print "username is already present\n"; } else { print "we have no match\n"; } my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198'); my $string = $tempuser4->{firstname}; my @c = split(//, $string); my $userhash = "00$c[0]$c[-1]"; print "$userhash \n"; #$tempuser4->{userhash} = $userhash; $tempuser4->setuserhash( "$userhash" ); $tempuser4->write; when I submit data , that data must come in place "my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198');" ... how can I do this ...>>? Look forward for hear from you soon Thank You From breamoreboy at yahoo.co.uk Fri Aug 31 05:11:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Aug 2012 10:11:25 +0100 Subject: Call perl to store data in DB In-Reply-To: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> References: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> Message-ID: On 31/08/2012 09:40, Mulla wrote: [snip] > how can I do this ...>>? > > Look forward for hear from you soon > > Thank You > Search the archives as it's the fourth time the question has been asked within a few weeks. -- Cheers. Mark Lawrence. From orasnita at gmail.com Fri Aug 31 05:19:21 2012 From: orasnita at gmail.com (Octavian Rasnita) Date: Fri, 31 Aug 2012 12:19:21 +0300 Subject: Call perl to store data in DB References: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> Message-ID: <2E29B7641A834F1E8DE3255174B37D02@octavian> Maybe I didn't understand well, but if you want your Perl program to get and store the data submitted by the form, then the action of the form should point to the Perl script something like: So your "form" object in Python should set the action as the path to the Perl program. --Octavian ----- Original Message ----- From: "Mulla" Newsgroups: comp.lang.python To: Sent: Friday, August 31, 2012 11:40 AM Subject: Call perl to store data in DB > hey, > > when i submit the form in html , the entered data (fname,lanme,uname.....)all have to come in perl script to store that data in DB. > > > Python View.py > > > def ProfileRegistration(request): > if request.user.is_authenticated(): > return HttpResponseRedirect('/profile/') > if request.method == 'POST': > form = RegistrationForm(data=request.POST, files=request.FILES) > if form.is_bound and form.is_valid(): > user = User.objects.create_user(username=form.cleaned_data['username'], > email=form.cleaned_data['email'], > password=form.cleaned_data['password'],) > new_user= user.save() > profile = Profile(user=user,firstname=form.cleaned_data['firstname'], > lastname=form.cleaned_data['lastname'], > telephone=form.cleaned_data['telephone'], > service=form.cleaned_data['service'], > servicetype=form.cleaned_data['servicetype'],) > new_user = profile.save() > # messages.info(request, "Thank you for registration.Please login to continue") > # login(request, new_user) > return HttpResponseRedirect('/dashboard/') > else: > return render_to_response('register.html',{'form': form},context_instance=RequestContext(request)) > else: > form = RegistrationForm() > context = {'form':form} > return render_to_response('register.html',context, context_instance=RequestContext(request)) > > Below in my perl script > > > #!/usr/bin/perl > > use strict; > use warnings; > use user; > > > > my $tempuser = new user (); > > if ($tempuser->readbyfirstname('Pervez') eq 1) { > # Continue processing since we found a match > if($tempuser->{lastname} eq 'Noel') > { > print "Name already exists, \n"; > } > } > > my $tempuser1 = new user(); > $tempuser1->readbyemail_id('mullapervez at gmail.com'); > if($tempuser1->{email_id} eq 'mullapervez at gmail.com') > { > print "email_id is in use \n"; > } > > > > my $tempuser2 = new user(); > $tempuser2->readbyusername('Tim_sir'); > if ($tempuser2->{username} eq 'Mulla') > { > print "username is already present\n"; > } > else { > print "we have no match\n"; > } > > my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198'); > my $string = $tempuser4->{firstname}; > my @c = split(//, $string); > my $userhash = "00$c[0]$c[-1]"; > print "$userhash \n"; > #$tempuser4->{userhash} = $userhash; > $tempuser4->setuserhash( "$userhash" ); > $tempuser4->write; > > > when I submit data , that data must come in place "my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198');" ... > > how can I do this ...>>? > > Look forward for hear from you soon > > Thank You > -- > http://mail.python.org/mailman/listinfo/python-list From mullapervez at gmail.com Fri Aug 31 05:31:54 2012 From: mullapervez at gmail.com (Mulla) Date: Fri, 31 Aug 2012 02:31:54 -0700 (PDT) Subject: Call perl to store data in DB In-Reply-To: References: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> Message-ID: <02ea1888-7287-4ec4-b47c-04e2e316cd45@googlegroups.com> On Friday, August 31, 2012 2:49:32 PM UTC+5:30, Octavian Rasnita wrote: > Maybe I didn't understand well, but if you want your Perl program to get and store the data submitted by the form, then the action of the form should point to the Perl script something like: > > > > > > > > So your "form" object in Python should set the action as the path to the Perl program. > > > > -- > Octavian > > > ----- Original Message ----- > > From: "Mulla" > > Newsgroups: comp.lang.python > > To: > > Sent: Friday, August 31, 2012 11:40 AM > > Subject: Call perl to store data in DB > > > > > > > hey, > > > > > > when i submit the form in html , the entered data (fname,lanme,uname.....)all have to come in perl script to store that data in DB. > > > > > > > > > Python View.py > > > > > > > > > def ProfileRegistration(request): > > > if request.user.is_authenticated(): > > > return HttpResponseRedirect('/profile/') > > > if request.method == 'POST': > > > form = RegistrationForm(data=request.POST, files=request.FILES) > > > if form.is_bound and form.is_valid(): > > > user = User.objects.create_user(username=form.cleaned_data['username'], > > > email=form.cleaned_data['email'], > > > password=form.cleaned_data['password'],) > > > new_user= user.save() > > > profile = Profile(user=user,firstname=form.cleaned_data['firstname'], > > > lastname=form.cleaned_data['lastname'], > > > telephone=form.cleaned_data['telephone'], > > > service=form.cleaned_data['service'], > > > servicetype=form.cleaned_data['servicetype'],) > > > new_user = profile.save() > > > # messages.info(request, "Thank you for registration.Please login to continue") > > > # login(request, new_user) > > > return HttpResponseRedirect('/dashboard/') > > > else: > > > return render_to_response('register.html',{'form': form},context_instance=RequestContext(request)) > > > else: > > > form = RegistrationForm() > > > context = {'form':form} > > > return render_to_response('register.html',context, context_instance=RequestContext(request)) > > > > > > Below in my perl script > > > > > > > > > #!/usr/bin/perl > > > > > > use strict; > > > use warnings; > > > use user; > > > > > > > > > > > > my $tempuser = new user (); > > > > > > if ($tempuser->readbyfirstname('Pervez') eq 1) { > > > # Continue processing since we found a match > > > if($tempuser->{lastname} eq 'Noel') > > > { > > > print "Name already exists, \n"; > > > } > > > } > > > > > > my $tempuser1 = new user(); > > > $tempuser1->readbyemail_id('mullapervez at gmail.com'); > > > if($tempuser1->{email_id} eq 'mullapervez at gmail.com') > > > { > > > print "email_id is in use \n"; > > > } > > > > > > > > > > > > my $tempuser2 = new user(); > > > $tempuser2->readbyusername('Tim_sir'); > > > if ($tempuser2->{username} eq 'Mulla') > > > { > > > print "username is already present\n"; > > > } > > > else { > > > print "we have no match\n"; > > > } > > > > > > my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198'); > > > my $string = $tempuser4->{firstname}; > > > my @c = split(//, $string); > > > my $userhash = "00$c[0]$c[-1]"; > > > print "$userhash \n"; > > > #$tempuser4->{userhash} = $userhash; > > > $tempuser4->setuserhash( "$userhash" ); > > > $tempuser4->write; > > > > > > > > > when I submit data , that data must come in place "my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198');" ... > > > > > > how can I do this ...>>? > > > > > > Look forward for hear from you soon > > > > > > Thank You > > > -- > > > http://mail.python.org/mailman/listinfo/python-list Thank You Octavian From mullapervez at gmail.com Fri Aug 31 05:31:54 2012 From: mullapervez at gmail.com (Mulla) Date: Fri, 31 Aug 2012 02:31:54 -0700 (PDT) Subject: Call perl to store data in DB In-Reply-To: References: <407771a5-0b1f-4bb6-8548-e5f79908b43d@googlegroups.com> Message-ID: <02ea1888-7287-4ec4-b47c-04e2e316cd45@googlegroups.com> On Friday, August 31, 2012 2:49:32 PM UTC+5:30, Octavian Rasnita wrote: > Maybe I didn't understand well, but if you want your Perl program to get and store the data submitted by the form, then the action of the form should point to the Perl script something like: > > > > > > > > So your "form" object in Python should set the action as the path to the Perl program. > > > > -- > Octavian > > > ----- Original Message ----- > > From: "Mulla" > > Newsgroups: comp.lang.python > > To: > > Sent: Friday, August 31, 2012 11:40 AM > > Subject: Call perl to store data in DB > > > > > > > hey, > > > > > > when i submit the form in html , the entered data (fname,lanme,uname.....)all have to come in perl script to store that data in DB. > > > > > > > > > Python View.py > > > > > > > > > def ProfileRegistration(request): > > > if request.user.is_authenticated(): > > > return HttpResponseRedirect('/profile/') > > > if request.method == 'POST': > > > form = RegistrationForm(data=request.POST, files=request.FILES) > > > if form.is_bound and form.is_valid(): > > > user = User.objects.create_user(username=form.cleaned_data['username'], > > > email=form.cleaned_data['email'], > > > password=form.cleaned_data['password'],) > > > new_user= user.save() > > > profile = Profile(user=user,firstname=form.cleaned_data['firstname'], > > > lastname=form.cleaned_data['lastname'], > > > telephone=form.cleaned_data['telephone'], > > > service=form.cleaned_data['service'], > > > servicetype=form.cleaned_data['servicetype'],) > > > new_user = profile.save() > > > # messages.info(request, "Thank you for registration.Please login to continue") > > > # login(request, new_user) > > > return HttpResponseRedirect('/dashboard/') > > > else: > > > return render_to_response('register.html',{'form': form},context_instance=RequestContext(request)) > > > else: > > > form = RegistrationForm() > > > context = {'form':form} > > > return render_to_response('register.html',context, context_instance=RequestContext(request)) > > > > > > Below in my perl script > > > > > > > > > #!/usr/bin/perl > > > > > > use strict; > > > use warnings; > > > use user; > > > > > > > > > > > > my $tempuser = new user (); > > > > > > if ($tempuser->readbyfirstname('Pervez') eq 1) { > > > # Continue processing since we found a match > > > if($tempuser->{lastname} eq 'Noel') > > > { > > > print "Name already exists, \n"; > > > } > > > } > > > > > > my $tempuser1 = new user(); > > > $tempuser1->readbyemail_id('mullapervez at gmail.com'); > > > if($tempuser1->{email_id} eq 'mullapervez at gmail.com') > > > { > > > print "email_id is in use \n"; > > > } > > > > > > > > > > > > my $tempuser2 = new user(); > > > $tempuser2->readbyusername('Tim_sir'); > > > if ($tempuser2->{username} eq 'Mulla') > > > { > > > print "username is already present\n"; > > > } > > > else { > > > print "we have no match\n"; > > > } > > > > > > my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198'); > > > my $string = $tempuser4->{firstname}; > > > my @c = split(//, $string); > > > my $userhash = "00$c[0]$c[-1]"; > > > print "$userhash \n"; > > > #$tempuser4->{userhash} = $userhash; > > > $tempuser4->setuserhash( "$userhash" ); > > > $tempuser4->write; > > > > > > > > > when I submit data , that data must come in place "my $tempuser4 = new user('pervez', '', 'mulla', 'mullapervez at gmail.com', '193274198');" ... > > > > > > how can I do this ...>>? > > > > > > Look forward for hear from you soon > > > > > > Thank You > > > -- > > > http://mail.python.org/mailman/listinfo/python-list Thank You Octavian From ben+python at benfinney.id.au Fri Aug 31 05:32:26 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Aug 2012 19:32:26 +1000 Subject: Context manager to save/restore a name binding References: <87oblrbxea.fsf@benfinney.id.au> Message-ID: <87k3wfbe51.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > You should wrap yield in a try ... finally. You might allow setting > the new value in the manager (untested): Thank you, both good advice. I would still like to know if Python already has something to make this unnecessary. -- \ ?Compulsory unification of opinion achieves only the unanimity | `\ of the graveyard.? ?Justice Roberts in 319 U.S. 624 (1943) | _o__) | Ben Finney From arnodel at gmail.com Fri Aug 31 06:18:36 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 31 Aug 2012 11:18:36 +0100 Subject: Tkinter bug in Entry widgets on OS X Message-ID: Hi all, I'm writing a small GUI on OS X (v. 10.7.4) using Tkinter. I'm using stock Python. It mostly works fine but there is a bug in Entry widgets: if and Entry widget has focus and I press the UP arrow, a "\uf700" gets inserted in the widget. If I press the DOWN arrow, a "\uf701" gets inserted. I'm very inexperienced with Tkinter (I've never used it before). All I'm looking for is a workaround, i.e. a way to somehow suppress that output. Thanks in advance, -- Arnaud From chris at python.org Fri Aug 31 07:06:04 2012 From: chris at python.org (Chris Withers) Date: Fri, 31 Aug 2012 12:06:04 +0100 Subject: Context manager to save/restore a name binding In-Reply-To: <87oblrbxea.fsf@benfinney.id.au> References: <87oblrbxea.fsf@benfinney.id.au> Message-ID: <50409A9C.507@python.org> Hi Ben, On 31/08/2012 03:36, Ben Finney wrote: > That way, I can set ?sys.dont_write_bytecode? to the value I need in > this part of the code, knowing that however the code continues the > previous value of that setting will be restored to whatever it was > before I touched it. > > Have I re-invented a context manager which already exists? Is there a > better way to do what ?preserve_value? is doing? Depends on the context (ho ho..), but if it's testing, then have a look at: http://packages.python.org/testfixtures/mocking.html#the-context-manager There's plenty of other goodies you may like in there too... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From mailinglists at xgm.de Fri Aug 31 08:03:16 2012 From: mailinglists at xgm.de (Florian Lindner) Date: Fri, 31 Aug 2012 14:03:16 +0200 Subject: XML parser: Element ordering? Message-ID: Hello, I plan to use the etree.ElementTree XML parser to parse a config file in which the order of the elements matter, e.g.: is not equal to: I have found different answers to the question if order matters in XML documents. So my question here: Does it matters (and is more or less guarenteed to matter in the future) for the ElementTree parser of python? Thanks, Florian From stefan_ml at behnel.de Fri Aug 31 08:21:54 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 31 Aug 2012 14:21:54 +0200 Subject: XML parser: Element ordering? In-Reply-To: References: Message-ID: Florian Lindner, 31.08.2012 14:03: > I plan to use the etree.ElementTree XML parser to parse a config file > in which the order of the elements matter, e.g.: > > > > > > is not equal to: > > > > > > I have found different answers to the question if order matters in XML > documents. So my question here: Does it matters (and is more or less > guarenteed to matter in the future) for the ElementTree parser of > python? It matters for XML documents, so, yes, any XML parser will definitely honour the document order (which is actually well defined for an XML document). What you might be referring to is the case of a specific XML document format, where the application (or sometimes specification) can explicitly state that the element order in a given subtree has no meaning for the semantics of the element and that therefore code must ignore the order in which elements occur. But that won't magically make the parser ignore it for you. That's a totally different level of abstraction and a deliberate decision of the code that *uses* the parser. Stefan From d at davea.name Fri Aug 31 08:31:17 2012 From: d at davea.name (Dave Angel) Date: Fri, 31 Aug 2012 08:31:17 -0400 Subject: XML parser: Element ordering? In-Reply-To: References: Message-ID: <5040AE95.9000903@davea.name> On 08/31/2012 08:21 AM, Stefan Behnel wrote: > Florian Lindner, 31.08.2012 14:03: >> I plan to use the etree.ElementTree XML parser to parse a config file >> in which the order of the elements matter, e.g.: >> >> >> >> >> >> is not equal to: >> >> >> >> >> >> I have found different answers to the question if order matters in XML >> documents. So my question here: Does it matters (and is more or less >> guarenteed to matter in the future) for the ElementTree parser of >> python? > It matters for XML documents, so, yes, any XML parser will definitely > honour the document order (which is actually well defined for an XML document). > > What you might be referring to is the case of a specific XML document > format, where the application (or sometimes specification) can explicitly > state that the element order in a given subtree has no meaning for the > semantics of the element and that therefore code must ignore the order in > which elements occur. But that won't magically make the parser ignore it > for you. That's a totally different level of abstraction and a deliberate > decision of the code that *uses* the parser. > > There is a place in xml documents which is defined to be unordered. That's the attributes within one element. is indistinguishable from: -- DaveA From steve+comp.lang.python at pearwood.info Fri Aug 31 08:32:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Aug 2012 12:32:25 GMT Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5040aed8$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Aug 2012 16:44:32 -0400, Terry Reedy wrote: > On 8/30/2012 12:00 PM, Steven D'Aprano wrote: >> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: [...] >>> Is the implementation smart enough to know that x == y is always False >>> if x and y are using different internal representations? > > Yes, after checking lengths, and in same circumstances, x != y is True. [snip C code] Thanks Terry for looking that up. > 'a in s' is also False if a chars are wider than s chars. Now that's a nice optimization! [...] >> But x and y are not necessarily always False just because they have >> different representations. There may be circumstances where two strings >> have different internal representations even though their content is >> the same, so it's an unsafe optimization to automatically treat them as >> unequal. > > I am sure that str objects are always in canonical form once visible to > Python code. Note that unready (non-canonical) objects are rejected by > the rich comparison function. That's one thing that I'm unclear about -- under what circumstances will a string be in compact versus non-compact form? Reading between the lines, I guess that a lot of the complexity of the implementation only occurs while a string is being built. E.g. if you have Python code like this: ''.join(str(x) for x in something) # a generator expression Python can't tell how much space to allocate for the string -- it doesn't know either the overall length of the string or the width of the characters. So I presume that there is string builder code for dealing with that, and that it involves resizing blocks of memory. But if you do this: ''.join([str(x) for x in something]) # a list comprehension Python could scan the list first, find out the widest char, and allocate exactly the amount of space needed for the string. Even in Python 2, joining a list comp is much faster than joining a gen expression. -- Steven From roy at panix.com Fri Aug 31 08:43:55 2012 From: roy at panix.com (Roy Smith) Date: Fri, 31 Aug 2012 08:43:55 -0400 Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <503f8e33$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: > > Is the implementation smart enough to know that x == y is always False > > if x and y are using different internal representations? > > [...] There may be circumstances where two strings have different > internal representations even though their content is the same If there is a deterministic algorithm which maps string content to representation type, then I don't see how it's possible for two strings with different representation types to have the same content. Could you give me an example of when this might happen? From lipskathekat at yahoo.co.uk Fri Aug 31 09:40:09 2012 From: lipskathekat at yahoo.co.uk (lipska the kat) Date: Fri, 31 Aug 2012 14:40:09 +0100 Subject: interfacing with x86_64 assembler Message-ID: Worryingly I was hacking away at some x86_64 assembler today when I found myself obsessively indenting my code by EXACTLY 4 spaces or (multiples thereof) Who'd have thought it. lipska -- Lipska the Kat?: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun From breamoreboy at yahoo.co.uk Fri Aug 31 09:52:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Aug 2012 14:52:14 +0100 Subject: interfacing with x86_64 assembler In-Reply-To: References: Message-ID: On 31/08/2012 14:40, lipska the kat wrote: > Worryingly > > I was hacking away at some x86_64 assembler today > when I found myself obsessively indenting my code > by EXACTLY 4 spaces or (multiples thereof) > > Who'd have thought it. > > lipska > What's wrong with structured assembler? :) -- Cheers. Mark Lawrence. From invalid at invalid.invalid Fri Aug 31 09:58:11 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 31 Aug 2012 13:58:11 +0000 (UTC) Subject: interfacing with x86_64 assembler References: Message-ID: On 2012-08-31, Mark Lawrence wrote: > On 31/08/2012 14:40, lipska the kat wrote: >> I was hacking away at some x86_64 assembler today >> when I found myself obsessively indenting my code >> by EXACTLY 4 spaces or (multiples thereof) > What's wrong with structured assembler? :) Nothing -- it's called "C". -- Grant Edwards grant.b.edwards Yow! Not SENSUOUS ... only at "FROLICSOME" ... and in gmail.com need of DENTAL WORK ... in PAIN!!! From skip at pobox.com Fri Aug 31 10:15:26 2012 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 Aug 2012 14:15:26 +0000 (UTC) Subject: Test message - please ignore Message-ID: We just upgraded the Mailman installation on mail.python.org. Part of that installation includes spam filtering on messages gated from Usenet to the python- list at python.org mailing list. This message is a quick test of that function. You can ignore it. Skip Montanaro From breamoreboy at yahoo.co.uk Fri Aug 31 10:18:25 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Aug 2012 15:18:25 +0100 Subject: interfacing with x86_64 assembler In-Reply-To: References: Message-ID: On 31/08/2012 14:58, Grant Edwards wrote: > On 2012-08-31, Mark Lawrence wrote: >> On 31/08/2012 14:40, lipska the kat wrote: > >>> I was hacking away at some x86_64 assembler today >>> when I found myself obsessively indenting my code >>> by EXACTLY 4 spaces or (multiples thereof) > >> What's wrong with structured assembler? :) > > Nothing -- it's called "C". > You cannot be Cerious -- Cheers. Mark Lawrence. From python.list at tim.thechases.com Fri Aug 31 10:24:58 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 31 Aug 2012 09:24:58 -0500 Subject: thanks! (was "Test message - please ignore") In-Reply-To: References: Message-ID: <5040C93A.4030602@tim.thechases.com> On 08/31/12 09:15, Skip Montanaro wrote: > We just upgraded the Mailman installation on mail.python.org. Part of that > installation includes spam filtering on messages gated from Usenet to the python- > list at python.org mailing list. This message is a quick test of that function. > You can ignore it. Or we can take the opportunity to thank you for all your work on making this a relatively spam-free mailing list. So thanks! -tkc From kw at codebykevin.com Fri Aug 31 10:25:27 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 31 Aug 2012 10:25:27 -0400 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: References: Message-ID: On 8/31/12 6:18 AM, Arnaud Delobelle wrote: > I'm very inexperienced with Tkinter (I've never used it before). All > I'm looking for is a workaround, i.e. a way to somehow suppress that > output. What are you trying to do? Navigate the focus to another widget? You should use the tab bar for that, not the arrow key. The entry widget is a single-line widget, and doesn't have up/down as the text widget does. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From steve+comp.lang.python at pearwood.info Fri Aug 31 10:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Aug 2012 14:54:42 GMT Subject: Flexible string representation, unicode, typography, ... References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5040d032$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Aug 2012 08:43:55 -0400, Roy Smith wrote: > In article <503f8e33$0$30001$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote: >> > Is the implementation smart enough to know that x == y is always >> > False if x and y are using different internal representations? >> >> [...] There may be circumstances where two strings have different >> internal representations even though their content is the same > > If there is a deterministic algorithm which maps string content to > representation type, then I don't see how it's possible for two strings > with different representation types to have the same content. Could you > give me an example of when this might happen? There are deterministic algorithms which can result in the same result with two different internal formats. Here's an example from Python 2: py> sum([1, 2**30, -2**30, 2**30, -2**30]) 1 py> sum([1, 2**30, 2**30, -2**30, -2**30]) 1L The internal representation (int versus long) differs even though the sum is the same. A second example: the order of keys in a dict is deterministic but unpredictable, as it depends on the history of insertions and deletions into the dict. So two dicts could be equal, and yet have radically different internal layout. One final example: list resizing. Here are two lists which are equal but have different sizes: py> a = [0] py> b = range(10000) py> del b[1:] py> a == b True py> sys.getsizeof(a) 36 py> sys.getsizeof(b) 48 Is PEP 393 another example of this? I have no idea. Somebody who is more familiar with the details of the implementation would be able to answer whether or not that is the case. I'm just suggesting that it is possible. -- Steven From ian.g.kelly at gmail.com Fri Aug 31 11:13:40 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 31 Aug 2012 09:13:40 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <5040aed8$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> <62566024-df1d-4948-a27a-45c7820ddc6c@googlegroups.com> <503f0e45$0$9416$c3e8da3$76491128@news.astraweb.com> <503f8e33$0$30001$c3e8da3$5496439d@news.astraweb.com> <5040aed8$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Aug 31, 2012 at 6:32 AM, Steven D'Aprano wrote: > That's one thing that I'm unclear about -- under what circumstances will > a string be in compact versus non-compact form? I understand it to be entirely dependent on which API is used to construct. The legacy API generates legacy strings, and the new API generates compact strings. From the comments in unicodeobject.h: /* ASCII-only strings created through PyUnicode_New use the PyASCIIObject structure. state.ascii and state.compact are set, and the data immediately follow the structure. utf8_length and wstr_length can be found in the length field; the utf8 pointer is equal to the data pointer. */ ... Legacy strings are created by PyUnicode_FromUnicode() and PyUnicode_FromStringAndSize(NULL, size) functions. They become ready when PyUnicode_READY() is called. ... /* Non-ASCII strings allocated through PyUnicode_New use the PyCompactUnicodeObject structure. state.compact is set, and the data immediately follow the structure. */ Since I'm not sure that this is clear, note that compact vs. legacy does not describe which character width is used (except that PyASCIIObject strings are always 1 byte wide). Legacy and compact strings can each use the 1, 2, or 4 byte representations. "Compact" merely denotes that the character data is stored inline with the struct (as opposed to being stored somewhere else and pointed at by the struct), not the relative size of the string data. Again from the comments: Compact strings use only one memory block (structure + characters), whereas legacy strings use one block for the structure and one block for characters. Cheers, Ian From arnodel at gmail.com Fri Aug 31 11:18:12 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 31 Aug 2012 16:18:12 +0100 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: References: Message-ID: On 31 August 2012 15:25, Kevin Walzer wrote: > On 8/31/12 6:18 AM, Arnaud Delobelle wrote: >> >> I'm very inexperienced with Tkinter (I've never used it before). All >> I'm looking for is a workaround, i.e. a way to somehow suppress that >> output. > > > What are you trying to do? Navigate the focus to another widget? You should > use the tab bar for that, not the arrow key. The entry widget is a > single-line widget, and doesn't have up/down as the text widget does. I'm not trying to do anything. When a user presses the UP or DOWN arrow, then a strange character is inserted in the Entry box. I'd rather nothing happened. -- Arnaud From kw at codebykevin.com Fri Aug 31 11:21:14 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 31 Aug 2012 11:21:14 -0400 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: References: Message-ID: On 8/31/12 11:18 AM, Arnaud Delobelle wrote: > > I'm not trying to do anything. When a user presses the UP or DOWN > arrow, then a strange character is inserted in the Entry box. I'd > rather nothing happened. > Why is the user doing that? If they are trying to navigate to a different part of the interface, they need to use the tab key, not the arrow key. It's not a multi-line text widget and shouldn't be expected to work like one. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From alister.ware at ntlworld.com Fri Aug 31 11:41:01 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 31 Aug 2012 15:41:01 GMT Subject: Tkinter bug in Entry widgets on OS X References: Message-ID: On Fri, 31 Aug 2012 11:21:14 -0400, Kevin Walzer wrote: > On 8/31/12 11:18 AM, Arnaud Delobelle wrote: > > >> I'm not trying to do anything. When a user presses the UP or DOWN >> arrow, then a strange character is inserted in the Entry box. I'd >> rather nothing happened. >> > Why is the user doing that? If they are trying to navigate to a > different part of the interface, they need to use the tab key, not the > arrow key. It's not a multi-line text widget and shouldn't be expected > to work like one. I agree that it is unexpected in a single line entry box but isn't the 1st rule of user interface design to assume the user is a moron & will do things they are not supposed to do? Therefore invalid inputs should be handled gracefully (not just insert random characters) which is what I think the original poster is suggesting. -- Walk softly and carry a megawatt laser. From chris at python.org Fri Aug 31 12:19:10 2012 From: chris at python.org (Chris Withers) Date: Fri, 31 Aug 2012 17:19:10 +0100 Subject: Unittest - testing for filenames and filesize In-Reply-To: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> References: <6b0299df-bc24-406b-8d69-489e990d8e4f@googlegroups.com> Message-ID: <5040E3FE.6040004@python.org> On 23/08/2012 12:25, Tigerstyle wrote: > class FileTest(unittest.TestCase): > > def setUp(self): > self.origdir = os.getcwd() > self.dirname = tempfile.mkdtemp("testdir") > os.chdir(self.dirname) I wouldn't change directories like this, it's pretty fragile, just use absolute paths. > def test_1(self): > "Verify creation of files is possible" > for filename in ("this.txt", "that.txt", "the_other.txt"): > f = open(filename, "w") > f.write("Some text\n") > f.close() > self.assertTrue(f.closed) > > def test_2(self): > "Verify that current directory is empty" > self.assertEqual(glob.glob("*"), [], "Directory not empty") > > def tearDown(self): > os.chdir(self.origdir) > shutil.rmtree(self.dirname) Seeing this, you might find the following tools useful: http://packages.python.org/testfixtures/files.html cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jasonveldicott at gmail.com Fri Aug 31 12:44:26 2012 From: jasonveldicott at gmail.com (Jason Veldicott) Date: Fri, 31 Aug 2012 09:44:26 -0700 Subject: Basic python extension producing error: "dynamic module not initialized properly" Message-ID: Hi, I am trying to create an extension to call into a c++ library, a library which simply returns a string, given a string. At first, a quick and simple approach was tried (based on post http://stackoverflow.com/questions/1615813/how-to-use-c-classes-with-ctypes) in which the usual infrastructure for loading extensions is bypassed. A working simple example is shown beneath: myextension.cpp #include extern "C" { int test_func() { return 10; } } To execute in Python: from ctypes import cdll mlib=cdll.LoadLibrary("myextension.dll") print( mlib.test_func() ) This works fine when function return type is a number, but not when a string. C++ code returns char *, which is received by Python as a pointer, which prints as a number, eg1755066468. Apparently, based on web posts viewed, it seems data conversion is required, using a function such as Py_BuildValue("s", str) from python.h. But this gave a similar result, in which a pointer is received by Python instead of a string. The modified function used in this case: PyObject * test_func() { return Py_BuildValue("s", "aString"); } Resort was then made to the conventional approach of defining a method table and initializing method. (Abandoned cdll.LoadLibrary(...) as subsequently test_func was not recognised, and instead put the dll (.dll changed to pyd) in /python26/DLLs.) The revised code: myextension.cpp #include extern "C" { static PyObject * test_func(PyObject *self, PyObject *args) { return (PyObject *) 0; } static PyMethodDef TestMethods[] = { {"test", test_func, METH_VARARGS, "test"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initlibTestExtnModule(void) { (void) Py_InitModule("TestExtnModule", TestMethods); } } Using the import statement "import libTestExtnModule" however produced the following error message: "SystemError: dynamic module not initialized properly" As far as I know there is nothing wrong with the initialisation of the extension code above. Perhaps the error is related to compilation. I have not used distutils, but rather compiled externally and dropped the dll (as pyd) into the /DLLs directory as mentioned. This should work, as far as I know. Related to compilation, both MinGW and Python2.6 are 32 bit versions, and g++ statements used were: mingw32-g++ "-IC:\\Python26\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o myextension.o "..\\myextension.cpp" mingw32-g++ -LC:/Python26/libs -shared -o libTestExtnModule.pyd myextension.o -lpython26 Any suggestions as to why the dynamic module is not initialising properly, or as to how otherwise a string can be returned, would be greatly appreciated. Thanks Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Aug 31 13:18:36 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Aug 2012 10:18:36 -0700 Subject: thanks! (was "Test message - please ignore") In-Reply-To: <5040C93A.4030602@tim.thechases.com> References: <5040C93A.4030602@tim.thechases.com> Message-ID: <5040F1EC.8000205@stoneleaf.us> Tim Chase wrote: > On 08/31/12 09:15, Skip Montanaro wrote: >> We just upgraded the Mailman installation on mail.python.org. Part of that >> installation includes spam filtering on messages gated from Usenet to the python- >> list at python.org mailing list. This message is a quick test of that function. >> You can ignore it. > > Or we can take the opportunity to thank you for all your work on > making this a relatively spam-free mailing list. So thanks! Seconded! :) From gandalf at shopzeus.com Fri Aug 31 15:04:54 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 31 Aug 2012 21:04:54 +0200 Subject: Looking for an IPC solution Message-ID: <50410AD6.7080003@shopzeus.com> There are just so many IPC modules out there. I'm looking for a solution for developing a new a multi-tier application. The core application will be running on a single computer, so the IPC should be using shared memory (or mmap) and have very short response times. But there will be a tier that will hold application state for clients, and there will be lots of clients. So that tier needs to go to different computers. E.g. the same IPC should also be accessed over TCP/IP. Most messages will be simple data structures, nothing complicated. The ability to run on PyPy would, and also to run on both Windows and Linux would be a plus. I have seen a stand alone cross platform IPC server before that could serve "channels", and send/receive messages using these channels. But I don't remember its name and now I cannot find it. Can somebody please help? Thanks, Laszlo From arnodel at gmail.com Fri Aug 31 15:05:14 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 31 Aug 2012 20:05:14 +0100 Subject: Tkinter bug in Entry widgets on OS X In-Reply-To: References: Message-ID: On 31 August 2012 16:41, Alister wrote: > On Fri, 31 Aug 2012 11:21:14 -0400, Kevin Walzer wrote: > >> On 8/31/12 11:18 AM, Arnaud Delobelle wrote: >> >> >>> I'm not trying to do anything. When a user presses the UP or DOWN >>> arrow, then a strange character is inserted in the Entry box. I'd >>> rather nothing happened. >>> >> Why is the user doing that? If they are trying to navigate to a >> different part of the interface, they need to use the tab key, not the >> arrow key. It's not a multi-line text widget and shouldn't be expected >> to work like one. So you make software that only behaves well when the user does what they're supposed to do? > I agree that it is unexpected in a single line entry box but isn't the 1st > rule of user interface design to assume the user is a moron & will do > things they are not supposed to do? > > Therefore invalid inputs should be handled gracefully (not just insert > random characters) which is what I think the original poster is > suggesting. Indeed. -- Arnaud From fomcl at yahoo.com Fri Aug 31 16:12:58 2012 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Fri, 31 Aug 2012 13:12:58 -0700 (PDT) Subject: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented In-Reply-To: <20120830025758.GA26856@raf.org> References: <501944E4.2090902@simplistix.co.uk> <5c84fd3b-c899-4703-867d-ddbc5d1746de@googlegroups.com> <20120829021646.GA8163@raf.org> <20120830025758.GA26856@raf.org> Message-ID: <1346443978.955.YahooMailNeo@web110708.mail.gq1.yahoo.com> Hi, As a work-around, you could use the CRAN R package XLConnect, using RPy or RPy2, to do what you want. IIRC it's based on Java, so it's not extremely fast. http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf This is another package I just saw for the first time http://cran.r-project.org/web/packages/xlsx/xlsx.pdf ? Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~? >________________________________ > From: "python-excel at raf.org" >To: python-excel at googlegroups.com; Python List >Sent: Thursday, August 30, 2012 4:57 AM >Subject: Re: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented > >John Yeung wrote: > >> > is there any other way to tell how many digits excel would round to >> > when displaying a floating point number? that's my only reason for >> > needing formatting_info=True. >> >> I have not personally used it, but OpenPyXL is another option for >> working with .xlsx files, and it might provide the formatting info you >> need: >> >>? http://packages.python.org/openpyxl/index.html >>? http://pypi.python.org/pypi/openpyxl/1.5.8 >> >> John Y. > >thanks but openpyxl doesn't work well enough. >most of the spreadsheets i need to read contain >dropdown lists with data validation using a named >formula like: OFFSET(Data!$K$2,0,0,COUNTA(Data!$K:$K),1) >which causes openpyxl to throw a NamedRangeException. >i don't even care about the named objects. i just want >to know what's in the cell, not what other possible >values the cell might have had. :-) > >apart from that, it does give access to number formats >so your suggestion would work for simpler spreadsheets. > >hopefully the intention that xlrd not support formats in xlsx >files will change one day into an intention to support them. :-) > >until then my users can keep manually saving xlsx files they >receive as xls before importing them. :-( > >maybe i need to investigate some perl modules or pyuno instead. >perl's Spreadsheet::XSLX module handles formats. it gets the >date formats a bit wrong but it's workaroundable. > >cheers, >raf > >-- >You received this message because you are subscribed to the Google Groups "python-excel" group. >To post to this group, send an email to python-excel at googlegroups.com. >To unsubscribe from this group, send email to python-excel+unsubscribe at googlegroups.com. >For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nawijn at gmail.com Fri Aug 31 16:25:11 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Fri, 31 Aug 2012 13:25:11 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: Message-ID: <1aab2052-2cd9-47e8-b72a-5c93d2e87d43@googlegroups.com> On Friday, August 31, 2012 9:22:00 PM UTC+2, Laszlo Nagy wrote: > There are just so many IPC modules out there. I'm looking for a solution > > for developing a new a multi-tier application. The core application will > > be running on a single computer, so the IPC should be using shared > > memory (or mmap) and have very short response times. But there will be a > > tier that will hold application state for clients, and there will be > > lots of clients. So that tier needs to go to different computers. E.g. > > the same IPC should also be accessed over TCP/IP. Most messages will be > > simple data structures, nothing complicated. The ability to run on PyPy > > would, and also to run on both Windows and Linux would be a plus. > > > > I have seen a stand alone cross platform IPC server before that could > > serve "channels", and send/receive messages using these channels. But I > > don't remember its name and now I cannot find it. Can somebody please help? > > > > Thanks, > > > > Laszlo Hi, Are you aware and have you considered zeromq (www.zeromq.org)? It does not provide a messaging system, but you could use things like simple strings (json) or more complicated things like Protobuf. Marco From nawijn at gmail.com Fri Aug 31 16:25:11 2012 From: nawijn at gmail.com (Marco Nawijn) Date: Fri, 31 Aug 2012 13:25:11 -0700 (PDT) Subject: Looking for an IPC solution In-Reply-To: References: Message-ID: <1aab2052-2cd9-47e8-b72a-5c93d2e87d43@googlegroups.com> On Friday, August 31, 2012 9:22:00 PM UTC+2, Laszlo Nagy wrote: > There are just so many IPC modules out there. I'm looking for a solution > > for developing a new a multi-tier application. The core application will > > be running on a single computer, so the IPC should be using shared > > memory (or mmap) and have very short response times. But there will be a > > tier that will hold application state for clients, and there will be > > lots of clients. So that tier needs to go to different computers. E.g. > > the same IPC should also be accessed over TCP/IP. Most messages will be > > simple data structures, nothing complicated. The ability to run on PyPy > > would, and also to run on both Windows and Linux would be a plus. > > > > I have seen a stand alone cross platform IPC server before that could > > serve "channels", and send/receive messages using these channels. But I > > don't remember its name and now I cannot find it. Can somebody please help? > > > > Thanks, > > > > Laszlo Hi, Are you aware and have you considered zeromq (www.zeromq.org)? It does not provide a messaging system, but you could use things like simple strings (json) or more complicated things like Protobuf. Marco From no.email at nospam.invalid Fri Aug 31 16:36:42 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 31 Aug 2012 13:36:42 -0700 Subject: Looking for an IPC solution References: Message-ID: <7x4nni23z9.fsf@ruckus.brouhaha.com> Laszlo Nagy writes: > application will be running on a single computer, so the IPC should be > using shared memory (or mmap) and have very short response times. Zeromq (suggested by someone) is an option since it's pretty fast for most purposes, but I don't think it uses shared memory. The closest thing I can think of to what you're asking is MPI, intended for scientific computation. I don't know of general purpose IPC that uses it though I've thought it would be interesting. There are also some shared memory modules around, including POSH for shared objects, but they don't switch between memory and sockets AFAIK. Based on your description, maybe what you really want is Erlang, or something like it for Python. There would be more stuff to do than just supply an IPC library. From solipsis at pitrou.net Fri Aug 31 17:05:27 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 31 Aug 2012 21:05:27 +0000 (UTC) Subject: Looking for an IPC solution References: <50410AD6.7080003@shopzeus.com> Message-ID: Laszlo Nagy shopzeus.com> writes: > > There are just so many IPC modules out there. I'm looking for a solution > for developing a new a multi-tier application. The core application will > be running on a single computer, so the IPC should be using shared > memory (or mmap) and have very short response times. But there will be a > tier that will hold application state for clients, and there will be > lots of clients. So that tier needs to go to different computers. E.g. > the same IPC should also be accessed over TCP/IP. Most messages will be > simple data structures, nothing complicated. The ability to run on PyPy > would, and also to run on both Windows and Linux would be a plus. How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html Regards Antoine. -- Software development and contracting: http://pro.pitrou.net From gandalf at shopzeus.com Fri Aug 31 17:10:47 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 31 Aug 2012 23:10:47 +0200 Subject: Looking for an IPC solution In-Reply-To: <7x4nni23z9.fsf@ruckus.brouhaha.com> References: <7x4nni23z9.fsf@ruckus.brouhaha.com> Message-ID: <50412857.8030100@shopzeus.com> > Zeromq (suggested by someone) is an option since it's pretty fast for > most purposes, but I don't think it uses shared memory. Interesting question. The documentation says: http://api.zeromq.org/2-1:zmq-ipc The inter-process transport is currently only implemented on operating systems that provide UNIX domain sockets. (OFF: Would it be possible to add local IPC support for Windows using mmap()? I have seen others doing it.) At least, it is functional on Windows, and it excels on Linux. I just need to make transports configureable. Good enough for me. > The closest > thing I can think of to what you're asking is MPI, intended for > scientific computation. I don't know of general purpose IPC that uses > it though I've thought it would be interesting. There are also some > shared memory modules around, including POSH for shared objects, but > they don't switch between memory and sockets AFAIK. > > Based on your description, maybe what you really want is Erlang, or > something like it for Python. There would be more stuff to do than just > supply an IPC library. Yes, although I would really like to do this job in Python. I'm going to make some tests with zeromq. If the speed is good for local inter-process communication, then I'll give it a try. Thanks, Laszlo From ben+python at benfinney.id.au Fri Aug 31 19:02:05 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Sep 2012 09:02:05 +1000 Subject: thanks! References: Message-ID: <87ehmmbr82.fsf@benfinney.id.au> Tim Chase writes: > Or we can take the opportunity to thank you for all your work on > making this a relatively spam-free mailing list. So thanks! Indeed. This forum has a very high signal-to-noise ratio, largely due to efforts that are often invisible to the participants. Thank you! -- \ ?The problem with television is that the people must sit and | `\ keep their eyes glued on a screen: the average American family | _o__) hasn't time for it.? ?_The New York Times_, 1939 | Ben Finney From contropinion at gmail.com Fri Aug 31 21:18:51 2012 From: contropinion at gmail.com (contro opinion) Date: Fri, 31 Aug 2012 21:18:51 -0400 Subject: why i can't set locale? Message-ID: >>> locale.setlocale(locale.LC_ALL, 'gbk') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/locale.py", line 513, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting -------------- next part -------------- An HTML attachment was scrubbed... URL: From contropinion at gmail.com Fri Aug 31 22:21:51 2012 From: contropinion at gmail.com (contro opinion) Date: Fri, 31 Aug 2012 22:21:51 -0400 Subject: how to get character hex number? Message-ID: >>> for i in "english" : ... print(hex((ord(i)))) ... 0x65 0x6e 0x67 0x6c 0x69 0x73 0x68 >>> u"english".encode("utf-8") 'english' >>> u"english".encode("ascii") 'english' how can i get 656e676c697368 in encode method? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Aug 31 22:40:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 31 Aug 2012 20:40:32 -0600 Subject: how to get character hex number? In-Reply-To: References: Message-ID: On Fri, Aug 31, 2012 at 8:21 PM, contro opinion wrote: >>>> for i in "english" : > ... print(hex((ord(i)))) > ... > 0x65 > 0x6e > 0x67 > 0x6c > 0x69 > 0x73 > 0x68 >>>> u"english".encode("utf-8") > 'english' >>>> u"english".encode("ascii") > 'english' > > how can i get 656e676c697368 in encode method? >>> ''.join("%02x" % ord(b) for b in u"english".encode("ascii")) '656e676c697368' From python.list at tim.thechases.com Fri Aug 31 22:42:57 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 31 Aug 2012 21:42:57 -0500 Subject: how to get character hex number? In-Reply-To: References: Message-ID: <50417631.1080508@tim.thechases.com> On 08/31/12 21:21, contro opinion wrote: >>>> for i in "english" : > ... print(hex((ord(i)))) > ... > 0x65 > 0x6e > 0x67 > 0x6c > 0x69 > 0x73 > 0x68 >>>> u"english".encode("utf-8") > 'english' >>>> u"english".encode("ascii") > 'english' > > how can i get 656e676c697368 in encode method? At least in 2.x, you can do: >>> u"english".encode("hex") '656e676c697368' -tkc From python.list at tim.thechases.com Fri Aug 31 23:50:33 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 31 Aug 2012 22:50:33 -0500 Subject: how to get character hex number? In-Reply-To: References: <50417631.1080508@tim.thechases.com> Message-ID: <50418609.8030902@tim.thechases.com> On 08/31/12 22:41, contro opinion wrote: >>>>>> u"english".encode("utf-8") >>> 'english' >>>>>> u"english".encode("ascii") >>> 'english' >>> >>> how can i get 656e676c697368 in encode method? >> >> At least in 2.x, you can do: >> >> >>> u"english".encode("hex") >> '656e676c697368' > > how about in python3.0? Well, in 3.1.3 at least, using the u"..." notation dies on me with an invalid syntax. However, as Ian suggests, you can do my_str = "english" "".join("%02x" % c for c in my_str.encode("ascii")) or whatever other encoding you want instead of "ascii". -tkc
> >
> > CODE CHECK > > : NOT PASSED >
> > Depending on this check I have to fill a cell in an excel file with answer: NOK (if Not passed or XXXX is present), or OK (if Not passed and XXXX are not present). > > Thanks again for your help (and sorry for my english) > Html is not a format you wish to extract data from. Mainly because this is the endpoint of content AND display, meaning, that what is properly parsed today may not be parsed tomorrow because someone changed the background color. You should change your server so he can feed a client with data (xml for instance is quite close from the html syntax, it's based on tags and is suitable for data). JM From nad at acm.org Mon Aug 27 13:21:12 2012 From: nad at acm.org (Ned Deily) Date: Mon, 27 Aug 2012 10:21:12 -0700 Subject: Python list archives double-gzipped? References: <503AD027.7000004@tim.thechases.com> <503B7B8C.105@gmail.com> <503BA5F0.3020704@tim.thechases.com> Message-ID: In article <503BA5F0.3020704 at tim.thechases.com>, Tim Chase wrote: > That corresponds with what I see in various testing. To whomever > controls the python.org web-server, is it possible to tweak Apache > so that it doesn't try to gzip *.gz files? It may ameliorate the > problem, as well as reduce server load (since it's actually taking > the time to make the file larger) http://mail.python.org/mailman/listinfo/pydotorg-www -- Ned Deily, nad at acm.org From castironpi at gmail.com Mon Aug 27 14:10:07 2012 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 27 Aug 2012 11:10:07 -0700 (PDT) Subject: set and dict iteration In-Reply-To: <50367242$0$6574$c3e8da3$5496439d@news.astraweb.com> References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> <50367242$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <27447bd0-f253-4f8c-a7c7-39cef1e39a2d@googlegroups.com> On Thursday, August 23, 2012 1:11:14 PM UTC-5, Steven D'Aprano wrote: > On Thu, 23 Aug 2012 09:49:41 -0700, Aaron Brady wrote: > > > > [...] > > > The patch for the above is only 40-60 lines. However it introduces two > > > new concepts. > > > > > > The first is a "linked list", a classic dynamic data structure, first > > > developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . > > > Linked lists are absent in Python > > > > They certainly are not. There's merely no named "linked list" class. > > > > Linked lists are used by collections.ChainMap, tracebacks, xml.dom, > > Abstract Syntax Trees, and probably many other places. (Well, technically > > some of these are trees rather than lists.) You can trivially create a > > linked list: > > > > x = [a, [b, [c, [d, [e, None]]]]] > > > > is equivalent to a singly-linked list with five nodes. Only less > > efficient. > > > > > > > The second is "uncounted references". The uncounted references are > > > references to "set iterators" exclusively, exist only internally to > > > "set" objects, and are invisible to the rest of the program. The reason > > > for the exception is that iterators are unique in the Python Data Model; > > > iterators consist of a single immutable reference, unlike both immutable > > > types such as strings and numbers, as well as container types. Counted > > > references could be used instead, but would be consistently wasted work > > > for the garbage collector, though the benefit to programmers' peace of > > > mind could be significant. > > > > The usual way to implement "uncounted references" is by using weakrefs. > > Why invent yet another form of weakref? > > > > > > > > -- > > Steven Hello S. D'Aprano. Thanks for your support as always. The semantics of the second collection are equivalent to a WeakSet. The space and time consumption of a WeakSet are higher in comparison to a linked list. However, so long as we iterated over it using the C API instead of creating an iterator, it would be consistent. If we dynamically create the WeakSet on demand and free it when empty, the space consumption would be lower. Typical use cases don't involve creating thousands of iterators, or rapidly creating and destroying them, so the performance impact might not be severe. Regarding the bare weakrefs, if the iterator's destructor hasn't been called, then the pointer is still valid. If it has been called, then it's not present in the list. Unlike Python classes, the destructors of C extension classes are guaranteed to be called. Therefore there are no points during exection at which a node needs to check whether a reference to its neighbor is valid. Are your concerns based on data integrity, future maintainability, or what? From mcepl at redhat.com Mon Aug 27 15:11:50 2012 From: mcepl at redhat.com (Matej Cepl) Date: Mon, 27 Aug 2012 21:11:50 +0200 Subject: VPS For Python In-Reply-To: References: Message-ID: On 26/08/12 09:41, coldfire wrote: > I will really appreciate if someone type the address of any of the following for use with python If you can live just with PaaS (i.e., no shell account in the strict sense of the word, although you have ssh access) then my employer is introducing OpenShift (http://openshift.redhat.com) and I have a very great experience with playing with it. Use #openshift on Freenode for further support. Mat?j From wxjmfauth at gmail.com Mon Aug 27 15:16:27 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 27 Aug 2012 12:16:27 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Le dimanche 26 ao?t 2012 22:45:09 UTC+2, Dan Sommers a ?crit?: > On 2012-08-26 at 20:13:21 +0000, > > Steven D'Aprano wrote: > > > > > I note that not all 32-bit ints are valid code points. I suppose I can > > > see sense in having rune be a 32-bit integer value limited to those > > > valid code points. (But, dammit, why not call it a code point?) But if > > > rune is merely an alias for int32, why not just call it int32? > > > > Having a "code point" type is a good idea. If nothing else, human code > > readers can tell that you're doing something with characters rather than > > something with integers. If your language provides any sort of type > > safety, then you get that, too. > > > > Calling your code points int32 is a bad idea for the same reason that it > > turned out to be a bad idea to call all my old ASCII characters int8. > > Or all my pointers int (or unsigned int), for n in 16, 20, 24, 32, > > 36, 48, or 64 (or I'm sure other values of n that I never had the pain > > or pleasure of using). > And this is precisely the concept of rune, a real int which is a name for Unicode code point. Go "has" the integers int32 and int64. A rune ensure the usage of int32. "Text libs" use runes. Go has only bytes and runes. If you do not like the word "perfection", this mechanism has at least an ideal simplicity (with probably a lot of positive consequences). rune -> int32 -> utf32 -> unicode code points. - Why int32 and not uint32? No idea, I tried to find an answer without asking. - I find the name "rune" elegant. "char" would have been too confusing. End. This is supposed to be a Python forum. jmf From wxjmfauth at gmail.com Mon Aug 27 15:16:27 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 27 Aug 2012 12:16:27 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Le dimanche 26 ao?t 2012 22:45:09 UTC+2, Dan Sommers a ?crit?: > On 2012-08-26 at 20:13:21 +0000, > > Steven D'Aprano wrote: > > > > > I note that not all 32-bit ints are valid code points. I suppose I can > > > see sense in having rune be a 32-bit integer value limited to those > > > valid code points. (But, dammit, why not call it a code point?) But if > > > rune is merely an alias for int32, why not just call it int32? > > > > Having a "code point" type is a good idea. If nothing else, human code > > readers can tell that you're doing something with characters rather than > > something with integers. If your language provides any sort of type > > safety, then you get that, too. > > > > Calling your code points int32 is a bad idea for the same reason that it > > turned out to be a bad idea to call all my old ASCII characters int8. > > Or all my pointers int (or unsigned int), for n in 16, 20, 24, 32, > > 36, 48, or 64 (or I'm sure other values of n that I never had the pain > > or pleasure of using). > And this is precisely the concept of rune, a real int which is a name for Unicode code point. Go "has" the integers int32 and int64. A rune ensure the usage of int32. "Text libs" use runes. Go has only bytes and runes. If you do not like the word "perfection", this mechanism has at least an ideal simplicity (with probably a lot of positive consequences). rune -> int32 -> utf32 -> unicode code points. - Why int32 and not uint32? No idea, I tried to find an answer without asking. - I find the name "rune" elegant. "char" would have been too confusing. End. This is supposed to be a Python forum. jmf From ian.g.kelly at gmail.com Mon Aug 27 15:17:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Aug 2012 13:17:12 -0600 Subject: set and dict iteration In-Reply-To: References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502dab6c$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Aug 23, 2012 at 10:49 AM, Aaron Brady wrote: > The patch for the above is only 40-60 lines. However it introduces two new concepts. Is there a link to the patch? > The first is a "linked list", a classic dynamic data structure, first developed in 1955, cf. http://en.wikipedia.org/wiki/Linked_list . Linked lists are absent in Python, including the standard library and CPython implementation, beyond the weak reference mechanism and garbage collector. The "collections.deque" structure shares some of the linked list interface but uses arrays. > > The second is "uncounted references". The uncounted references are references to "set iterators" exclusively, exist only internally to "set" objects, and are invisible to the rest of the program. The reason for the exception is that iterators are unique in the Python Data Model; iterators consist of a single immutable reference, unlike both immutable types such as strings and numbers, as well as container types. Counted references could be used instead, but would be consistently wasted work for the garbage collector, though the benefit to programmers' peace of mind could be significant. > > Please share your opinion! Do you agree that the internal list resolves the inconsistency? Do you agree with the strategy? Do you agree that uncounted references are justified to introduce, or are counted references preferable? This feature is a hard sell as it is; I think that adding uncounted references into the mix is only going to make that worse. May I suggest an alternate approach? Internally tag each set or dict with a "version", which is just a C int. Every time the hash table is modified, increment the version. When an iterator is created, store the current version on the iterator. When the iterator is advanced, check that the iterator version matches the dict/set version. If they're not equal, raise an error. This should add less overhead than the linked list without any concerns about reference counting. It does introduce a small bug in that an error condition could be "missed", if the version is incremented a multiple of 2**32 or 2**64 times between iterations -- but how often is that really likely to occur? Bearing in mind that this error is meant for debugging and not production error handling, you could even make the version a single byte and I'd still be fine with that. Cheers, Ian From ian.g.kelly at gmail.com Mon Aug 27 16:14:07 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Aug 2012 14:14:07 -0600 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: On Mon, Aug 27, 2012 at 1:16 PM, wrote: > - Why int32 and not uint32? No idea, I tried to find an > answer without asking. UCS-4 is technically only a 31-bit encoding. The sign bit is not used, so the choice of int32 vs. uint32 is inconsequential. (In fact, since they made the decision to limit Unicode to the range 0 - 0x0010FFFF, one might even point out that the *entire high-order byte* as well as 3 bits of the next byte are irrelevant. Truly, UTF-32 is not designed for memory efficiency.) From wxjmfauth at gmail.com Mon Aug 27 16:37:01 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 27 Aug 2012 13:37:01 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: Le lundi 27 ao?t 2012 22:14:07 UTC+2, Ian a ?crit?: > On Mon, Aug 27, 2012 at 1:16 PM, wrote: > > > - Why int32 and not uint32? No idea, I tried to find an > > > answer without asking. > > > > UCS-4 is technically only a 31-bit encoding. The sign bit is not used, > > so the choice of int32 vs. uint32 is inconsequential. > > > > (In fact, since they made the decision to limit Unicode to the range 0 > > - 0x0010FFFF, one might even point out that the *entire high-order > > byte* as well as 3 bits of the next byte are irrelevant. Truly, > > UTF-32 is not designed for memory efficiency.) I know all this. The question is more, why not a uint32 knowing there are only positive code points. It seems to me more "natural". From wxjmfauth at gmail.com Mon Aug 27 16:37:01 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 27 Aug 2012 13:37:01 -0700 (PDT) Subject: Flexible string representation, unicode, typography, ... In-Reply-To: References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: Le lundi 27 ao?t 2012 22:14:07 UTC+2, Ian a ?crit?: > On Mon, Aug 27, 2012 at 1:16 PM, wrote: > > > - Why int32 and not uint32? No idea, I tried to find an > > > answer without asking. > > > > UCS-4 is technically only a 31-bit encoding. The sign bit is not used, > > so the choice of int32 vs. uint32 is inconsequential. > > > > (In fact, since they made the decision to limit Unicode to the range 0 > > - 0x0010FFFF, one might even point out that the *entire high-order > > byte* as well as 3 bits of the next byte are irrelevant. Truly, > > UTF-32 is not designed for memory efficiency.) I know all this. The question is more, why not a uint32 knowing there are only positive code points. It seems to me more "natural". From bruceg113355 at gmail.com Mon Aug 27 16:41:12 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Mon, 27 Aug 2012 13:41:12 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> Message-ID: Uli, Answers to your questions: 1) There are approx 65 records and each record is 68 bytes in length. 2) Not applicable because number of records is fixed. 3) Takes less than a second to read all 65 records when all is well. Takes 17 seconds to read all 65 records when all is NOT WELL 4) Performance is also sluggish, at least 12 seconds. 5) Most likely, I misspoken. Restarting my program does not always help with performance. When using the database on my C Drive, Sqlite performance is great! (<1S) When using the database on a network, Sqlite performance is terrible! (17S) I like your idea of trying Python 2.7 Finally, the way my program is written is: loop for all database records: read a database record process data display data (via wxPython) Perhaps, this is a better approach: read all database records loop for all records: process data display data (via wxPython) Thanks, Bruce On Monday, August 27, 2012 11:50:15 AM UTC-4, Ulrich Eckhardt wrote: > Am 27.08.2012 03:23, schrieb bruceg113355 at gmail.com: > > > My program uses Python 2.6 and Sqlite3 and connects to a network > > > database 100 miles away. > > > > Wait, isn't SQLite completely file-based? In that case, SQLite accesses > > a file, which in turn is stored on a remote filesystem. This means that > > there are other components involved here, namely your OS, the network > > (bandwidth & latency), the network filesystem and the filesystem on the > > remote machine. It would help if you told us what you have there. > > > > > > > My program reads approx 60 records (4000 bytes) from a Sqlite > > > database in less than a second. Each time the user requests data, my > > > program can continuously read 60 records in less than a second. > > > However, if I access the network drive (e.g. DOS command DIR /S) > > > while my program is running, my program takes 20 seconds to read the > > > same 60 records. If I restart my program, my program once again takes > > > less than a second to read 60 records. > > > > Questions here: > > 1. Is each record 4kB or are all 60 records together 4kB? > > 2. Does the time for reading double when you double the number of > > records? Typically you have B + C * N, but it would be interesting to > > know the bias B and the actual time (and size) of each record. > > 3. How does the timing change when running dir/s? > > 4. What if you run two instances of your program? > > 5. Is the duration is only reset by restarting the program or does it > > also decrease when the dir/s call has finished? What if you close and > > reopen the database without terminating the program? > > > > My guess is that the concurrent access by another program causes the > > accesses to become synchronized, while before most of the data is > > cached. That would cause a complete roundtrip between the two machines > > for every access, which can easily blow up the timing via the latency. > > > > In any case, I would try Python 2.7 in case this is a bug that was > > already fixed. > > > > Good luck! > > > > Uli From demianbrecht at gmail.com Mon Aug 27 16:54:06 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 27 Aug 2012 13:54:06 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> Message-ID: <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> Is there a reason that you're using SQLite in a network environment rather than a database server? From python.list at tim.thechases.com Mon Aug 27 16:59:16 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 27 Aug 2012 15:59:16 -0500 Subject: Python list archives double-gzipped? In-Reply-To: References: <503AD027.7000004@tim.thechases.com> <503B7B8C.105@gmail.com> <503BA5F0.3020704@tim.thechases.com> Message-ID: <503BDFA4.7000009@tim.thechases.com> On 08/27/12 12:21, Ned Deily wrote: > In article <503BA5F0.3020704 at tim.thechases.com>, Tim Chase > wrote: >> To whomever controls the python.org web-server, is it possible >> to tweak Apache so that it doesn't try to gzip *.gz files? It >> may ameliorate the problem, as well as reduce server load >> (since it's actually taking the time to make the file larger) > > http://mail.python.org/mailman/listinfo/pydotorg-www At Ned's suggestion, I took it there and Ralf Hildebrandt kindly resolved the matter. Thanks to all involved. -tkc From tim at akwebsoft.com Mon Aug 27 18:39:38 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Mon, 27 Aug 2012 14:39:38 -0800 Subject: popen4 - get exit status Message-ID: <20120827223938.GZ35917@mail.akwebsoft.com> In bash I do the following: linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory linus:journal tim$ echo $? 127 In python, use os.popen4 I do the following: >>> fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') >>> results = fout.readlines() >>> results ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] Well, I got the exit code as the last item in the results, but I'm wondering if there is a better way. From help(os) - I don't find any variables dedicated to holding exit status. Any ideas? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From benjamin.kaplan at case.edu Mon Aug 27 19:02:28 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 27 Aug 2012 16:02:28 -0700 Subject: popen4 - get exit status In-Reply-To: <20120827223938.GZ35917@mail.akwebsoft.com> References: <20120827223938.GZ35917@mail.akwebsoft.com> Message-ID: On Aug 27, 2012 3:47 PM, "Tim Johnson" wrote: > > In bash I do the following: > linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup > -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory > linus:journal tim$ echo $? > 127 > > In python, use os.popen4 I do the following: > >>> fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') > >>> results = fout.readlines() > >>> results > ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] > > Well, I got the exit code as the last item in the results, but I'm wondering if > there is a better way. From help(os) - I don't find any variables dedicated to > holding exit status. > > Any ideas? > thanks > -- > Tim > tim at tee jay forty nine dot com or akwebsoft dot com > http://www.akwebsoft.com The popen* functions are deprecated. You should use the subprocess module instead. -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Aug 27 19:07:53 2012 From: d at davea.name (Dave Angel) Date: Mon, 27 Aug 2012 19:07:53 -0400 Subject: popen4 - get exit status In-Reply-To: <20120827223938.GZ35917@mail.akwebsoft.com> References: <20120827223938.GZ35917@mail.akwebsoft.com> Message-ID: <503BFDC9.7020509@davea.name> On 08/27/2012 06:39 PM, Tim Johnson wrote: > In bash I do the following: > linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup > -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory > linus:journal tim$ echo $? > 127 > > In python, use os.popen4 I do the following: >>>> fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') >>>> results = fout.readlines() >>>> results > ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] > > Well, I got the exit code as the last item in the results, but I'm wondering if > there is a better way. From help(os) - I don't find any variables dedicated to > holding exit status. According to: http://docs.python.org/library/popen2.html " The only way to retrieve the return codes for the child processes is by using the poll() or wait() methods on the Popen3 and Popen4 classes; these are only available on Unix. This information is not available when using the popen2() , popen3() , and popen4() functions,...." However, unless you're using an old version of Python (2.5 or below), you should be using the subprocess module. -- DaveA From tim at akwebsoft.com Mon Aug 27 19:43:59 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Mon, 27 Aug 2012 15:43:59 -0800 Subject: popen4 - get exit status In-Reply-To: References: <20120827223938.GZ35917@mail.akwebsoft.com> Message-ID: <20120827234359.GA35917@mail.akwebsoft.com> * Benjamin Kaplan [120827 15:20]: > The popen* functions are deprecated. You should use the subprocess module > instead. No, I'm stuck with py 2.4 on one of the servers I'm using and there will not be an upgrade for a few months. I'm really trying to set up something portable between linux->python 2.4 and darwin->python 2.7 thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From tim at akwebsoft.com Mon Aug 27 19:44:59 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Mon, 27 Aug 2012 15:44:59 -0800 Subject: popen4 - get exit status In-Reply-To: <503BFDC9.7020509@davea.name> References: <20120827223938.GZ35917@mail.akwebsoft.com> <503BFDC9.7020509@davea.name> Message-ID: <20120827234459.GB35917@mail.akwebsoft.com> * Dave Angel [120827 15:20]: > On 08/27/2012 06:39 PM, Tim Johnson wrote: > > In bash I do the following: > > linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup > > -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory > > linus:journal tim$ echo $? > > 127 > > > > In python, use os.popen4 I do the following: > >>>> fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') > >>>> results = fout.readlines() > >>>> results > > ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] > > > > Well, I got the exit code as the last item in the results, but I'm wondering if > > there is a better way. From help(os) - I don't find any variables dedicated to > > holding exit status. > > According to: > http://docs.python.org/library/popen2.html > > > " The only way to retrieve the return codes for the child processes is > by using the poll() or wait() methods on the Popen3 > and Popen4 > classes; > these are only available on Unix. This information is not available when > using the popen2() > , popen3() > , and popen4() > functions,...." > > However, unless you're using an old version of Python (2.5 or below), > you should be using the subprocess module. Thanks DaveA and see my reply to Benjamin that will do it. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From nhodgson at iinet.net.au Mon Aug 27 19:54:43 2012 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 28 Aug 2012 09:54:43 +1000 Subject: Flexible string representation, unicode, typography, ... In-Reply-To: <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> References: <1cb3f062-eb45-4b0c-977b-76afb099923c@googlegroups.com> <503a0d51$0$6574$c3e8da3$5496439d@news.astraweb.com> <503a8361$0$6574$c3e8da3$5496439d@news.astraweb.com> <2e92da71-fbd2-467f-9088-1c79fa7bcf69@googlegroups.com> Message-ID: wxjmfauth at gmail.com: > Go "has" the integers int32 and int64. A rune ensure > the usage of int32. "Text libs" use runes. Go has only > bytes and runes. Go's text libraries use UTF-8 encoded byte strings. Not arrays of runes. See, for example, http://golang.org/pkg/regexp/ Are you claiming that UTF-8 is the optimum string representation and therefore should be used by Python? Neil From bruceg113355 at gmail.com Mon Aug 27 20:55:47 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Mon, 27 Aug 2012 17:55:47 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> Message-ID: <306b0189-df90-478e-b7d4-420620121ab1@googlegroups.com> Demian, I am not a database expert! I selected sqlite for the following reasons: 1) Ships with Python. 2) Familiar with Python. 3) The Sqlite description at http://www.sqlite.org/whentouse.html appears to meet my requirements: Very low volume and concurrency, small datasets, simple to use. Bruce On Monday, August 27, 2012 4:54:07 PM UTC-4, Demian Brecht wrote: > Is there a reason that you're using SQLite in a network environment rather than a database server? From bryanjugglercryptographer at yahoo.com Mon Aug 27 22:32:47 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Mon, 27 Aug 2012 19:32:47 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> <306b0189-df90-478e-b7d4-420620121ab1@googlegroups.com> Message-ID: <852f8da0-d445-4d35-a144-139ed5d66e0e@ou2g2000pbc.googlegroups.com> bruceg113 wrote: > I selected sqlite for the following reasons: > > 1) Ships with Python. > 2) Familiar with Python. > 3) The Sqlite description athttp://www.sqlite.org/whentouse.htmlappears to meet my requirements: > ? ? Very low volume and concurrency, small datasets, simple to use. All good reasons, but a database file on a network drive is contraindication for SQLite. A Google site-specific search for "network" on www.sqlite.org, finds such warnings as: "We have received reports of implementations of both Windows network filesystems and NFS in which locking was subtly broken. We can not verify these reports, but as locking is difficult to get right on a network filesystem we have no reason to doubt them. You are advised to avoid using SQLite on a network filesystem in the first place, since performance will be slow." That said, I don't know where your 17 seconds is going. -Bryan From bruceg113355 at gmail.com Mon Aug 27 23:09:27 2012 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Mon, 27 Aug 2012 20:09:27 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <852f8da0-d445-4d35-a144-139ed5d66e0e@ou2g2000pbc.googlegroups.com> References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> <306b0189-df90-478e-b7d4-420620121ab1@googlegroups.com> <852f8da0-d445-4d35-a144-139ed5d66e0e@ou2g2000pbc.googlegroups.com> Message-ID: <741a0854-8ea4-460f-a65f-1b0da1183437@googlegroups.com> On Monday, August 27, 2012 10:32:47 PM UTC-4, Bryan wrote: > bruceg113 wrote: > > > I selected sqlite for the following reasons: > > > > > > 1) Ships with Python. > > > 2) Familiar with Python. > > > 3) The Sqlite description athttp://www.sqlite.org/whentouse.htmlappears to meet my requirements: > > > ? ? Very low volume and concurrency, small datasets, simple to use. > > > > All good reasons, but a database file on a network drive is > > contraindication for SQLite. A Google site-specific search > > for "network" on www.sqlite.org, finds such warnings as: > > > > "We have received reports of implementations of both Windows network > > filesystems and NFS in which locking was subtly broken. We can not > > verify these reports, but as locking is difficult to get right on a > > network filesystem we have no reason to doubt them. You are advised to > > avoid using SQLite on a network filesystem in the first place, since > > performance will be slow." > > > > That said, I don't know where your 17 seconds is going. > > > > -Bryan Bryan, Thank you for your reply. Are you saying having a sqlite database file on a shared LOCAL network drive is problematic? Bruce From ian.douglas at iandouglas.com Mon Aug 27 23:16:26 2012 From: ian.douglas at iandouglas.com (ian douglas) Date: Mon, 27 Aug 2012 20:16:26 -0700 Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: <741a0854-8ea4-460f-a65f-1b0da1183437@googlegroups.com> References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> <306b0189-df90-478e-b7d4-420620121ab1@googlegroups.com> <852f8da0-d445-4d35-a144-139ed5d66e0e@ou2g2000pbc.googlegroups.com> <741a0854-8ea4-460f-a65f-1b0da1183437@googlegroups.com> Message-ID: >From the sqlite documentation he quoted, it appears that ANY network filesystem, local or otherwise, should be avoided. On Aug 27, 2012 8:13 PM, wrote: > On Monday, August 27, 2012 10:32:47 PM UTC-4, Bryan wrote: > > bruceg113 wrote: > > > > > I selected sqlite for the following reasons: > > > > > > > > > > 1) Ships with Python. > > > > > 2) Familiar with Python. > > > > > 3) The Sqlite description athttp:// > www.sqlite.org/whentouse.htmlappears to meet my requirements: > > > > > Very low volume and concurrency, small datasets, simple to use. > > > > > > > > All good reasons, but a database file on a network drive is > > > > contraindication for SQLite. A Google site-specific search > > > > for "network" on www.sqlite.org, finds such warnings as: > > > > > > > > "We have received reports of implementations of both Windows network > > > > filesystems and NFS in which locking was subtly broken. We can not > > > > verify these reports, but as locking is difficult to get right on a > > > > network filesystem we have no reason to doubt them. You are advised to > > > > avoid using SQLite on a network filesystem in the first place, since > > > > performance will be slow." > > > > > > > > That said, I don't know where your 17 seconds is going. > > > > > > > > -Bryan > > Bryan, > > Thank you for your reply. > Are you saying having a sqlite database file on a shared LOCAL network > drive is problematic? > > Bruce > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bryanjugglercryptographer at yahoo.com Tue Aug 28 01:26:34 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Mon, 27 Aug 2012 22:26:34 -0700 (PDT) Subject: Python 2.6 and Sqlite3 - Slow References: <7c61db72-0b4a-4105-949d-89f2cc303e78@googlegroups.com> <6807651c-7b42-413e-939f-ec4e11137990@googlegroups.com> <306b0189-df90-478e-b7d4-420620121ab1@googlegroups.com> <852f8da0-d445-4d35-a144-139ed5d66e0e@ou2g2000pbc.googlegroups.com> <741a0854-8ea4-460f-a65f-1b0da1183437@googlegroups.com> Message-ID: bruceg113 wrote: > Thank you for your reply. > Are you saying having a sqlite database file on a > shared LOCAL network drive is problematic? Yes, mostly, I think I am saying that. A "LOCAL network drive" is network drive, and is not a local drive, local as the network may be. We read and write such a drive over a network protocol, in this case a Microsoft protocol and implementation in the SMB/CIFS family. Where are your 17 seconds going? Hard to tell. Is your experience of astonishing filesystem slothfulness rare? Not so much. We could probably diagnose the problem in a few weeks. We'd use some open-source tools, WireShark among them, plus some Microsoft tools for which we might have to pay, plus the SQLite3 project's C library. With that investment I'd bet we could diagnose, but not cure. -Bryan From info at egenix.com Tue Aug 28 03:26:16 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 28 Aug 2012 09:26:16 +0200 Subject: ANN: eGenix mxODBC 3.2.0 - Python ODBC Database Interface Message-ID: <503C7298.20507@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.2.0 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.2.0-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.0 release of our mxODBC is a new release of our popular Python ODBC Interface for Windows, Linux, Mac OS X and FreeBSD. New Features in 3.2 ------------------- * Switched to unixODBC 2.3.1+ API: mxODBC is now compiled against unixODBC 2.3.1, which finally removes the problems with the ABI change between 2.2 and 2.3 by switching to a new library version (libodbc.so.2). * mxODBC connection objects can now be used as context managers to implicitly commit/rollback transactions. * mxODBC cursor objects can now be used as context managers to implicitly close the cursor when leaving the block (regardless of whether an exception was raised or not) * mxODBC added support for adjustable .paramstyles. Both 'qmark' (default) and 'named' styles are supported and can be set on connections and cursors. The 'named' style allows easier porting of e.g. Oracle native interface code to mxODBC. * mxODBC now supports a writable connection.autocommit attribute to easily turn on/off the connection's auto commit mode. * mxODBC added support for adjustable TIMESTAMP precision via the new connection/cursor.timestampresolution attribute. * mxODBC will round to nearest nanosecond fraction instead of truncating the value. This will result in fewer conversion errors due to floating point second values. * mxODBC's connect APIs Connect() and DriverConnect() support setting connection options prior to connecting to the database via a new connection_options parameter. This allows enabling e.g. the MARS feature in SQL Server Native Client. * The connection.cursor() constructor now has a new cursor_options parameters which allows configuring the cursor with a set of cursor options. * The .scroll() method supports far more ODBC drivers than before. * Updated the SQL lookup object to include more ODBC SQL parameter codes, including special ones for SQL Server and IBM DB2. * mx.ODBC.Manager will now prefer unixODBC over iODBC. Previous mxODBC releases used the order iODBC, unixODBC, DataDirect when looking for a suitable ODBC manager on Unix platforms. unixODBC is more widely supported nowadays and provides better Unicode support than iODBC. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features Driver Compatibility Enhancements --------------------------------- * Added work-around for Oracle Instance Client to prevent use of direct execution. cursor.executedirect() will still work, but won't actually use direct execution with the Oracle driver. * Added work-around for Oracle Instant Client to prevent segfaults in the driver when querying the cursor.rowcount or cursor.rownumber. * Added check to make sure that Python type binding mode is not used with Oracle Instance Client as this can cause segfaults with the driver and generally doesn't work. * Added a work-around to have the IBM DB2 driver return correct .rowcount values. * Improved Sybase ASE driver compatibility: this only supports Python type binding, which is now enabled per default. * Added work-around for PostgreSQL driver, which doesn't support scrollable cursors. * Add support for MS SQL Server ODBC Driver 1.0 for Linux to mxODBC * Improved compatibility of the mxODBC native Unicode string format handling with Unix ODBC drivers when running UCS4 builds of Python. * mxODBC 3.2 now always uses direct execution with the FreeTDS ODBC driver. This results in better compatibility with SQL Server and faster execution across the board. * Add work-around to have FreeTDS work with 64-bit integers outside the 32-bit signed integer range. * FreeTDS' .rowcount attribute gave misleading values for SELECTs. This now always returns -1 (until they hopefully fix the driver to return usable data). For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html mxODBC Editions --------------- mxODBC is available in these three editions: * The low-cost Standard Edition which provides data connectivity to a single database type, e.g. just MS SQL Server. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. Compared to mxODBC 3.0, we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. For upgrade purchases, we will give out 20% discount coupons going from mxODBC 2.x to 3.2 and 50% coupons for upgrades from mxODBC 3.x to 3.2. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team at sales at egenix.com with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 28 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-10-23: Python Meeting Duesseldorf ... 56 days to go 2012-08-20: Released mxODBC.Connect 2.0.0 ... http://egenix.com/go30 ::: 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 cs at zip.com.au Tue Aug 28 04:27:37 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 28 Aug 2012 18:27:37 +1000 Subject: Python 2.6 and Sqlite3 - Slow In-Reply-To: References: Message-ID: <20120828082737.GA6771@cskk.homeip.net> On 27Aug2012 13:41, bruceg113355 at gmail.com wrote: | When using the database on my C Drive, Sqlite performance is great! (<1S) | When using the database on a network, Sqlite performance is terrible! (17S) Let me first echo everyone saying not to use SQLite on a network file. | I like your idea of trying Python 2.7 I doubt it will change anything. | Finally, the way my program is written is: | loop for all database records: | read a database record | process data | display data (via wxPython) | | Perhaps, this is a better approach: | read all database records | loop for all records: | process data | display data (via wxPython) Yes, provided the "read all database records" is a single select statement. In general, with any kind of remote resource you want to minimise the number of transactions - the to and fro part, because each such item tends to have latency while something is sent to and again receiving from. So if you can say "gimme all the records" you get one "unit" of latency at the start and end, versus latency around each record fetch. Having said all that, because SQLite works directly against the file, if you say to it "giev me all the records" and the file is remote, SQLite will probably _still_ fetch each record individually internally, gaining you little. This is why people are suggesting a database "server": then you can say "get me all the records" over the net, and the server does local-to-the-server file access to obtain the data. So all the "per record" latency is at its end, and very small. Not to mention any cacheing it may do. Of course, if your requirements are very simple you might be better off with a flat text file, possibly in CSV format, and avoid SQLite altogether. Cheers, -- Cameron Simpson I do not trust thee, Cage from Hell, / The reason why I cannot tell, / But this I know, and know full well: / I do not trust thee, Cage from Hell. - Leigh Ann Hussey, leighann at sybase.com, DoD#5913 From michele.cecere at gmail.com Tue Aug 28 06:09:11 2012 From: michele.cecere at gmail.com (mikcec82) Date: Tue, 28 Aug 2012 03:09:11 -0700 (PDT) Subject: What do I do to read html files on my pc? In-Reply-To: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> References: <1c7cd833-b6ad-4a17-8ffe-a0ce20c8f400@googlegroups.com> Message-ID: Il giorno luned? 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: > Hallo, > > > > I have an html file on my pc and I want to read it to extract some text. > > Can you help on which libs I have to use and how can I do it? > > > > thank you so much. > > > > Michele Thank you to all. Hi Chris, thank you for your hint. I'll try to do as you said and to be clear: I have to work on an HTML File. This file is not a website-file, neither it comes from internet. It is a file created by a local software (where "local" means "on my pc"). On this file, I need to do this operation: 1) Open the file 2) Check the occurences of the strings: 2a) XXXX, in this case I have this code:
DTC CODE Read:           XXXX
CODE CHECK : NOT PASSED