xml-rpc
Hello, Recenetly we are developing a senior project and decide to use xmlrpclib. However I have some questions. In the documentation I could not find any clue about handling requests? Does the server handles each request in a separate thread? Or is there some queuing mechanism for client calls? Thanks in advance. --erdinc -- http://mail.python.org/mailman/listinfo/python-list
Re: Some PyCon videos won't play
Lee Harr miss...@hotmail.com writes: I am having a great time watching videos from PyCon. Thanks to everyone who presented, and to those who did such a great job putting the videos up at: http://pycon.blip.tv/ My trouble is that, although most of the videos play perfectly, there are a few that refuse to play at all. Like: I also had problems playing some of the videos (using gnash), but if you press files and links, then you can download the talk as an ogv file. Furthermore blip.tv provides an rss-feed with ogv-files for each channel on their site. http://pycon.blip.tv/rss Thanks to the pycon people for putting all their nice videos on the web. Niels -- http://mail.python.org/mailman/listinfo/python-list
Re: how to start a python script only once
On 13 Mar, 19:45, News123 news1...@free.fr wrote: Hi, I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. sqlite and locking quite some time ago I used a mysql table and locking as an inter-host mutex. Perhaps sqlite would be good enough for an inter process mutex for processes on the same host, but I don't know it well enough. interprocess mutex well I even don't know whether something like this exists on linux / windows Thanks in advanced for any tips N Apart from file, a portable solution would be to bind to an unused porta and assume that finding the port busy means that your program is already running on the port. On recent python installations there is the multiprocessing module which provides process-level semaphores, but I don't know how portable they are. Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
Gib Bogle wrote: Mark Lawrence wrote: I'm certain that members of the Guinea Pig Club might have something to say on that one, see :- http://en.wikipedia.org/wiki/Guinea_Pig_Club You mean, something like: That's not funny? No, simply a statement. -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
Steven D'Aprano wrote: On Sun, 14 Mar 2010 11:20:15 +1300, Gib Bogle wrote: Mark Lawrence wrote: I'm certain that members of the Guinea Pig Club might have something to say on that one, see :- http://en.wikipedia.org/wiki/Guinea_Pig_Club You mean, something like: That's not funny? Or possibly That's hilarious!!!. Gallows humour is sometimes hard to predict. Thinking about it can be that's not funny or hilarious depending on context, which is rather difficult to give on this internet/webby thingy. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml-rpc
On 03/14/10 08:14, ahmet erdinc yilmaz wrote: Hello, Recenetly we are developing a senior project and decide to use xmlrpclib. However I have some questions. In the documentation I could not find any clue about handling requests? Does the server handles each request in a separate thread? Or is there some queuing mechanism for client calls? Thanks in advance. --erdinc How I usually tackle stuff like this: [mar...@aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type help, copyright, credits or license for more information. import SimpleXMLRPCServer help(SimpleXMLRPCServer) read it and somewhere at CLASSES it says CLASSES BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) SimpleXMLRPCRequestHandler SimpleXMLRPCDispatcher CGIXMLRPCRequestHandler SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) SocketServer.TCPServer(SocketServer.BaseServer) SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) Aah so it is based on SocketServer, lets have a look at that: import SocketServer help(SocketServer) Help on module SocketServer: reading it and then it says There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: ++ | BaseServer | ++ | v +---++--+ | TCPServer |---| UnixStreamServer | +---++--+ | v +---+++ | UDPServer |---| UnixDatagramServer | +---+++ So the base of all these servers is BaseServer, hmm somebody must have a laugh right now :-) Okay lets have a look at that then: import BaseServer Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named BaseServer Hmmm okay, lets have a look at the SocketServer source itself then, but where is it? SocketServer.__file__ '/usr/local/lib/python2.6/SocketServer.pyc' I bet that the non compiled file is in the same directory, let's have a look at it with less. quit() [mar...@aspire8930 /usr/home/martin]$ less /usr/local/lib/python2.6/SocketServer.py And there it says among other interesting stuff: # The distinction between handling, getting, processing and # finishing a request is fairly arbitrary. Remember: # # - handle_request() is the top-level call. It calls # select, get_request(), verify_request() and process_request() # - get_request() is different for stream or datagram sockets # - process_request() is the place that may fork a new process # or create a new thread to finish the request # - finish_request() instantiates the request handler class; # this constructor will handle the request all by itself def handle_request(self): Handle one request, possibly blocking. Respects self.timeout. # Support people who used socket.settimeout() to escape # handle_request before self.timeout was available. timeout = self.socket.gettimeout() if timeout is None: timeout = self.timeout elif self.timeout is not None: timeout = min(timeout, self.timeout) fd_sets = select.select([self], [], [], timeout) if not fd_sets[0]: self.handle_timeout() return self._handle_request_noblock() def _handle_request_noblock(self): Handle one request, without blocking. I assume that select.select has returned that the socket is readable before this function was called, so there should be no risk of blocking in get_request(). try: request, client_address = self.get_request() except socket.error: return if self.verify_request(request, client_address): try: self.process_request(request, client_address) except: self.handle_error(request, client_address) self.close_request(request) I leave the remaining parts of your question as an exercise :-) -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: xml-rpc
Instead of using the library directly, isn't python-twisted a better choice? happy hacking. Krishnakant. On Sunday 14 March 2010 03:47 PM, Martin P. Hellwig wrote: On 03/14/10 08:14, ahmet erdinc yilmaz wrote: Hello, Recenetly we are developing a senior project and decide to use xmlrpclib. However I have some questions. In the documentation I could not find any clue about handling requests? Does the server handles each request in a separate thread? Or is there some queuing mechanism for client calls? Thanks in advance. --erdinc How I usually tackle stuff like this: [mar...@aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type help, copyright, credits or license for more information. import SimpleXMLRPCServer help(SimpleXMLRPCServer) read it and somewhere at CLASSES it says CLASSES BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) SimpleXMLRPCRequestHandler SimpleXMLRPCDispatcher CGIXMLRPCRequestHandler SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) SocketServer.TCPServer(SocketServer.BaseServer) SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) Aah so it is based on SocketServer, lets have a look at that: import SocketServer help(SocketServer) Help on module SocketServer: reading it and then it says There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: ++ | BaseServer | ++ | v +---++--+ | TCPServer |---| UnixStreamServer | +---++--+ | v +---+++ | UDPServer |---| UnixDatagramServer | +---+++ So the base of all these servers is BaseServer, hmm somebody must have a laugh right now :-) Okay lets have a look at that then: import BaseServer Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named BaseServer Hmmm okay, lets have a look at the SocketServer source itself then, but where is it? SocketServer.__file__ '/usr/local/lib/python2.6/SocketServer.pyc' I bet that the non compiled file is in the same directory, let's have a look at it with less. quit() [mar...@aspire8930 /usr/home/martin]$ less /usr/local/lib/python2.6/SocketServer.py And there it says among other interesting stuff: # The distinction between handling, getting, processing and # finishing a request is fairly arbitrary. Remember: # # - handle_request() is the top-level call. It calls # select, get_request(), verify_request() and process_request() # - get_request() is different for stream or datagram sockets # - process_request() is the place that may fork a new process # or create a new thread to finish the request # - finish_request() instantiates the request handler class; # this constructor will handle the request all by itself def handle_request(self): Handle one request, possibly blocking. Respects self.timeout. # Support people who used socket.settimeout() to escape # handle_request before self.timeout was available. timeout = self.socket.gettimeout() if timeout is None: timeout = self.timeout elif self.timeout is not None: timeout = min(timeout, self.timeout) fd_sets = select.select([self], [], [], timeout) if not fd_sets[0]: self.handle_timeout() return self._handle_request_noblock() def _handle_request_noblock(self): Handle one request, without blocking. I assume that select.select has returned that the socket is readable before this function was called, so there should be no risk of blocking in get_request(). try: request, client_address = self.get_request() except socket.error: return if self.verify_request(request, client_address): try: self.process_request(request, client_address) except: self.handle_error(request, client_address) self.close_request(request) I leave the remaining parts of your question as an exercise :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to start a python script only once
I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. This is the variant I'm using frequently too and I'd recommend to you as well. Simple to implement and largely problem-free. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: xml-rpc
On 03/14/10 10:32, hackingKK wrote: Instead of using the library directly, isn't python-twisted a better choice? cut Why? -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: I passed a fizzbuzz test but failed at recursion.
Am 10.03.2010 16:55, schrieb Bill: def fizzbuzz(num): if num: if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' else : return fizzbuzz(num-1) + ('%d \n' % num) return '' print fizzbuzz(100) While I do understand that this is not a Perl group, and this probably won't help the OP, I just could not resist: for i in range(1,101):print('','fizz')[not i%3]+('','buzz')[not i%5]or i However, when I try to decipher the logic of the function I imagine the solution reversed as buzz fizz 98 97 ...etc... 4 fizz 2 1. No, the function creates the string from right to left. See: fizzbuzz(100) = fizzbuzz(99) + buzz \n = fizzbuzz(98) + fizz \n + buzz \n ... = fizzbuzz(1) + 2 \n + fizz \n + 4 \n + buzz\n + fizz \n + + 97 \n + 98 \n + fizz \n + buzz \n = fizzbuzz(0) + 1 \n + 2 \n + fizz \n + 4 \n + buzz\n + fizz \n + + 97 \n + 98 \n + fizz \n + buzz \n = + 1 \n + 2 \n + fizz \n + 4 \n + buzz\n + fizz \n + + 97 \n + 98 \n + fizz \n + buzz \n Regards, Michael -- http://mail.python.org/mailman/listinfo/python-list
Breaking the __main__ script
Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something likestop, break, end or something similar. What statement can I use? Vicente Soler -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
vsoler wrote: Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something likestop, break, end or something similar. What statement can I use? Vicente Soler Something like import sys sys.exit()? HTH. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Function that knows its argument's variable name
I want to write function that prints a value of a variable, for debugging. Like: with myVariable = parrot otherVariable = dead probe(myVariable) probe(otherVariable) instead of the longer print myVariable = , myVariable print otherVariable = , otherVariable Is that even possible? The function would look like def probe(var): nameOfVar = someMagic(var) print nameOfVar, = , var but can someMagic(var) find the variable name? Is that possible? -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Am 14.03.2010 12:53, schrieb Mark Lawrence: vsoler wrote: I sometimes want to stop the script at a certain point, with something like stop, break, end or something similar. What statement can I use? Something like import sys sys.exit()? Or just raise SystemExit, raise SyntaxError or any other Exception. But you won't have to: If you use IDLE, you can just set breakpoints in your code: enable the debugger in debug-debugger and set breakpoints via right click in your source file. Or you could use a real debugger, like pdb http://docs.python.org/library/pdb.html HTH, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: building a dict
Andreas Waldenburger wrote: On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. Perhaps you can find out yourself: http://www.urbandictionary.com/define.php?term=op Possibly so, and that's a useful site, but I hope you aren't suggesting that Vicente shouldn't have asked. It seemed like a perfectly acceptable question to me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Feeding differeent data types to a class instance?
kuru wrote: Hi I have couple classes in the form of class Vector: def __init__(self,x,y,z): self.x=x self.y=y self.z=z This works fine for me. However I want to be able to provide a list, tuple as well as individual arguments like below myvec=Vector(1,2,3) This works well However I also want to be able to do vect=[1,2,3] myvec=Vec(vect) I want this class to accept multiple data types but process them as they are same when the classs deals with the instances. thanks With your existing class you can use Python's ability to transform a list or tuple into individual arguments using the * notation: class Vector: ... def __init__(self,x,y,z): ...self.x=x ...self.y=y ...self.z=z ... vl = [1, 2, 3] v = Vector(*vl) v.x 1 v.y 2 v.z 3 Will this do? It seems much simpler than rewriting an already satisfactory class. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Mark Lawrence wrote: vsoler wrote: Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something likestop, break, end or something similar. What statement can I use? Vicente Soler Something like import sys sys.exit()? HTH. I think it's less than likely that it will help, since once sys.exit() is called the program is no longer available for inspection. The OP is probably looking for the pdb module in the standard library. The documentation is good enough to get you started. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: building a dict
On Sun, 14 Mar 2010 08:36:55 -0400 Steve Holden st...@holdenweb.com wrote: Andreas Waldenburger wrote: On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler vicente.so...@gmail.com wrote: By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. Perhaps you can find out yourself: http://www.urbandictionary.com/define.php?term=op Possibly so, and that's a useful site, but I hope you aren't suggesting that Vicente shouldn't have asked. It seemed like a perfectly acceptable question to me. I was a bit trigger happy there, I admit. But with vocabulary questions like these, my first reflex is to ask the web rather than people, because it's usually quicker than Usenet (albeit often only by a minute or so). I somehow felt the need to bestow that bit of wisdom on the world. But yeah, the question is fine, of course. /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
On Sat, 13 Mar 2010 23:42:31 -0800 Jonathan Gardner jgard...@jonathangardner.net wrote: On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin no.em...@nospam.invalid wrote: D'Arcy J.M. Cain da...@druid.net writes: Just curious, what database were you using that wouldn't keep up with you? I use PostgreSQL and would never consider going back to flat files. Try making a file with a billion or so names and addresses, then compare the speed of inserting that many rows into a postgres table against the speed of copying the file. That's a straw man argument. Copying an already built database to another copy of the database won't be significantly longer than copying an already built file. In fact, it's the same operation. Also consider how much work it is to partition data from flat files versus PostgreSQL tables. Another straw man. I'm sure you can come up with many contrived examples to show one particular operation faster than another. Benchmark writers (bad ones) do it all the time. I'm saying that in normal, real world situations where you are collecting billions of data points and need to actually use the data that a properly designed database running on a good database engine will generally be better than using flat files. The only thing I can think of that might make flat files faster is that flat files are buffered whereas PG guarantees that your information is written to disk before returning Don't forget all the shadow page operations and the index operations, and that a lot of these operations require reading as well as writing remote parts of the disk, so buffering doesn't help avoid every disk seek. Not sure what a shadow page operation is but index operations are only needed if you have to have fast access to read back the data. If it doesn't matter how long it takes to read the data back then don't index it. I have a hard time believing that anyone would want to save billions of data points and not care how fast they can read selected parts back or organize the data though. Plus the fact that your other DB operations slow down under the load. Not with the database engines that I use. Sure, speed and load are connected whether you use databases or flat files but a proper database will scale up quite well. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
On 14 mar, 12:34, vsoler vicente.so...@gmail.com wrote: Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something like stop, break, end or something similar. What statement can I use? Vicente Soler Hola Vicente, You need a debugger. A practical solution to start with is to use an IDE with an integrated debugger. Stani's Python Editor (SPE) is a lightweight IDE with pdb integrated (with style checker also). It is a very good ide for learning (simple and not cluttered) but also for medium size applications (it is very well designed). atb Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
D'Arcy J.M. Cain wrote: On Sat, 13 Mar 2010 23:42:31 -0800 Jonathan Gardner jgard...@jonathangardner.net wrote: On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin no.em...@nospam.invalid wrote: D'Arcy J.M. Cain da...@druid.net writes: Just curious, what database were you using that wouldn't keep up with you? I use PostgreSQL and would never consider going back to flat files. Try making a file with a billion or so names and addresses, then compare the speed of inserting that many rows into a postgres table against the speed of copying the file. That's a straw man argument. Copying an already built database to another copy of the database won't be significantly longer than copying an already built file. In fact, it's the same operation. Also consider how much work it is to partition data from flat files versus PostgreSQL tables. Another straw man. I'm sure you can come up with many contrived examples to show one particular operation faster than another. Benchmark writers (bad ones) do it all the time. I'm saying that in normal, real world situations where you are collecting billions of data points and need to actually use the data that a properly designed database running on a good database engine will generally be better than using flat files. The only thing I can think of that might make flat files faster is that flat files are buffered whereas PG guarantees that your information is written to disk before returning Don't forget all the shadow page operations and the index operations, and that a lot of these operations require reading as well as writing remote parts of the disk, so buffering doesn't help avoid every disk seek. Not sure what a shadow page operation is but index operations are only needed if you have to have fast access to read back the data. If it doesn't matter how long it takes to read the data back then don't index it. I have a hard time believing that anyone would want to save billions of data points and not care how fast they can read selected parts back or organize the data though. Plus the fact that your other DB operations slow down under the load. Not with the database engines that I use. Sure, speed and load are connected whether you use databases or flat files but a proper database will scale up quite well. A common complaint about large database loads taking a long time comes about because of trying to commit the whole change as a single transaction. Such an approach can indeed causes stresses on the database system, but aren't usually necessary. I don't know about PostgreSQL's capabilities in this area but I do know that Oracle (which claims to be all about performance, though in fact I believe PostgreSQL is its equal in many applications) allows you to switch off the various time-consuming features such as transaction logging in order to make bulk updates faster. I also question how many databases would actually find a need to store addresses for a sixth of the world's population, but this objection is made mostly for comic relief: I understand that tables of such a size are necessary sometimes. There was a talk at OSCON two years ago by someone who was using PostgreSQL to process 15 terabytes of medical data. I'm sure he'd have been interested in suggestions that flat files were the answer to his problem ... Another talk a couple of years before that discussed how PostgreSQL was superior to Oracle in handling a three-terabyte data warehouse (though it conceded Oracle's superiority in handling the production OLTP system on which the warehouse was based - but that's four years ago). http://images.omniti.net/omniti.com/~jesus/misc/BBPostgres.pdf Of course if you only need sequential access to the data then the relational approach may be overkill. I would never argue that relational is the best approach for all data and all applications, but it's often better than its less-informed critics realize. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to start a python script only once
Hi Francesco, Francesco Bochicchio wrote: On 13 Mar, 19:45, News123 news1...@free.fr wrote: Hi, I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. sqlite and locking quite some time ago I used a mysql table and locking as an inter-host mutex. Perhaps sqlite would be good enough for an inter process mutex for processes on the same host, but I don't know it well enough. interprocess mutex well I even don't know whether something like this exists on linux / windows Thanks in advanced for any tips N Apart from file, a portable solution would be to bind to an unused porta and assume that finding the port busy means that your program is already running on the port. Yes, this should work. I assume in this case the bind() function would handle the race condition. On recent python installations there is the multiprocessing module which provides process-level semaphores, but I don't know how portable they are. Yes, there are process level semaphores in multiprocesing, but if I understood well, they would either require a common parent process or one process, which were acting as a manager, but then the question would be how to make sure, that the manager process were started only once. ( bind port? ) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to start a python script only once
Hi Daniel, Daniel Fetchinson wrote: I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. This is the variant I'm using frequently too and I'd recommend to you as well. Simple to implement and largely problem-free. OK, So I'll just have to look in a piece of code, that performs file locking for windows AND for linux and I should be fine. bye N -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
On Sun, 14 Mar 2010 10:16:43 -0400 Steve Holden st...@holdenweb.com wrote: A common complaint about large database loads taking a long time comes about because of trying to commit the whole change as a single transaction. Such an approach can indeed causes stresses on the database system, but aren't usually necessary. True. I don't know about PostgreSQL's capabilities in this area but I do know that Oracle (which claims to be all about performance, though in fact I believe PostgreSQL is its equal in many applications) allows you to switch off the various time-consuming features such as transaction logging in order to make bulk updates faster. Yes, PostgreSQL has a bulk loading option as well. It's usually useful when you are copying data from one database into another and need to do it quickly. I also question how many databases would actually find a need to store addresses for a sixth of the world's population, but this objection is made mostly for comic relief: I understand that tables of such a size are necessary sometimes. How about Microsoft storing it's user base? Oh wait, they only store registered users with legitimate copies. Never mind. Of course if you only need sequential access to the data then the relational approach may be overkill. I would never argue that relational is the best approach for all data and all applications, but it's often better than its less-informed critics realize. As a rule I find that in the real world the larger the dataset the more likely you need a proper database. For smaller datasets it doesn't matter so why not use a DB anyway and be prepared when that throwaway system suddenly becomes your company's core application. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Michael, Or you could use a real debugger, like pdb http://docs.python.org/library/pdb.html Any reason you prefer PDB over WinPDB? http://winpdb.org/ Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Some PyCon videos won't play
On Saturday 13 March 2010 20:01, Terry Reedy wrote: On 3/13/2010 11:23 AM, Lee Harr wrote: I am having a great time watching videos from PyCon. Thanks to everyone who presented, and to those who did such a great job putting the videos up at: http://pycon.blip.tv/ My trouble is that, although most of the videos play perfectly, there are a few that refuse to play at all. Like: [...] Is anyone else having trouble with these? Yes, 'spinner' spins indefinitely, while others load and play. You should still be able to get at the videos themselves by inspecting the page contents, looking for download links like this one: http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv In this case, it's an Ogg Theora video file, so you may want to use a player like VLC to view it: http://www.videolan.org/ David -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator/generator
vsoler wrote: I am working on a script that reads data from an excel workbook. The data is located in a named range whose first row contains the headers. It works!!! I find it superb that python is able to do such things!!! Now my questions. a. My ranges can in practice be quite big, and although I am happy with the speed I get, because I am learning python, I think I could do it still a bit better. I think that the line for i in matriz[1:]: could be improved with an iterator/generator, but I am not quite certain how I should proceed. b. the following lines could be improved by means of a defaultdict, that I know because of a previous post. However you may come up with some other ideas (this b. question is not my main concern, you may discard it if you find the post too long) if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] Can anybody provide some hints? Thank you for your cooperation. +++ + import win32com.client as win32 def agrupar(matriz, c1, c2): a, b = matriz[0].index(c1), matriz[0].index(c2) g = {} for i in matriz[1:]: if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] for k in g: print '%-50s %15d' % (k, g[k]) # Abrir fichero excel xl = win32.gencache.EnsureDispatch('Excel.Application') ##xl.Visible = True wb=xl.Workbooks.Open(r'C:\Users\Vicente\Documents\VS\Python \Presupuesto fijos 10YP 2011-2020 V0.xls') # Obtención de datos datos=wb.Names('Datos').RefersToRange() print agrupar(datos, u'NomCC', u'BGT-09') # Cerrar libro de trabajo wb.Close() print Before you go too far down this road (and congratulations, by the way, on having achieved what you already have!) you might like to consider the xlrd, xlwt and xlutils modules. Not only are they easy to use, they are also (I believe) cross-platform and do not require Excel to be loaded on the machine running the programs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to use re2 from Python?
On Sun, 14 Mar 2010 08:57:36 -0700, _wolf wrote: how can i use re2 from Python? Hello Wolf, There's a recent thread about this on the python-dev list, Unfortunately it seems to suggest that there are no Python bindings at present. Cheers, Kev -- http://mail.python.org/mailman/listinfo/python-list
Re: Feeding differeent data types to a class instance?
Hi Thank you so much for all these great suggestions. I will have time today to try all these and see which one works best for me cheers -- http://mail.python.org/mailman/listinfo/python-list
What does Error: 'module' object is not callable Mean?
The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print Cannot make drawffnet plot. -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
On Mar 13, 1:45 pm, pyt...@bdurham.com wrote: Robin, do you of an alternate compilter it doesn't work (py2exe) on my windows 7 box I can assure you that Py2exe does work on Windows 7 (my firm develops commercial Python applications packaged using Py2exe running on Windows 7), but it does take a bit of fiddling and some patience. Join the py2exe newsgroup and post your problems there.https://lists.sourceforge.net/lists/listinfo/py2exe-users You may also want to google 'Gui2exe'. This is a free front-end to Py2exe that you can use to generate your Py2exe setup.py scripts. Note that Gui2exe requires wxPython (free) to run. Finally, make sure you are trying to compile 32-bit Python 2.x code. I don't think py2exe supports Python 3.x or 64-bit versions of Python yet. Nope; py2exe is pretty much the go-to tool for this. I hear great things about PyInstaller. The project is not dead - make sure you use the latest version in the SVN. Search stackoverflow.com for positive feedback and tips on PyInstaller. Its on our plate to take a good look this product 'one of these days'. Good luck! Malcolm I summarised a all the alternatives to py2exe I could find, here: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput=html Looking for those with a green 'y' in the 'Windows' row, you want to check out cx_freeze, PyInstaller, bbfreeze. Best of luck. -- http://mail.python.org/mailman/listinfo/python-list
problem with variable and function
Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? Thanks! Example: myVar={ 1:myFunc } def myFunc(): myOtherVar=myVar would result in myVar saying myFunc does not exist. Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. I basically cannot win either way, and I need a way to resolve this. If you are curious, the dictionary holds function names and maps to a second dictionary of keystrokes, allowing me to map a keystroke to call a function. Thanks! -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
pyt...@bdurham.com wrote: Or you could use a real debugger, like pdb http://docs.python.org/library/pdb.html Any reason you prefer PDB over WinPDB? http://winpdb.org/ I always count in the standard library as a big plus over any add-ons It's nice to know about alternatives such as WinPDB, but everybody that has python also has pdb already installed. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
On Sun, Mar 14, 2010 at 10:20 AM, Cal Who calwhonos...@roadrunner.comwrote: from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. That said, drawffnet is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? --S -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
Jonathan, I summarised a all the alternatives to py2exe I could find, here: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdgoutput=html Really great work - thanks for sharing this with all of us!!! Regards, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with variable and function
Hi Alex, On Sun, 2010-03-14 at 14:26 -0400, Alex Hall wrote: Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. The code you provided works just fine (as one would expect). If you can provide an example doesn't work, we should be able to explain why and provide advice. Cheers, Jason. -- http://mail.python.org/mailman/listinfo/python-list
Re: Some PyCon videos won't play
On 3/14/2010 11:14 AM, David Boddie wrote: On Saturday 13 March 2010 20:01, Terry Reedy wrote: On 3/13/2010 11:23 AM, Lee Harr wrote: I am having a great time watching videos from PyCon. Thanks to everyone who presented, and to those who did such a great job putting the videos up at: http://pycon.blip.tv/ My trouble is that, although most of the videos play perfectly, there are a few that refuse to play at all. Like: [...] Is anyone else having trouble with these? Yes, 'spinner' spins indefinitely, while others load and play. You should still be able to get at the videos themselves by inspecting the page contents, looking for download links like this one: http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv In this case, it's an Ogg Theora video file, so you may want to use a player like VLC to view it: For people using html5 competant browsers, which, I believe, play .ogv 'in tha page', blip.tv just needs to update site to make html5 pages an alternative to using the flash player. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
On Sun, Mar 14, 2010 at 2:20 PM, Cal Who calwhonos...@roadrunner.comwrote: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print Cannot make drawffnet plot. In Python, everything is an object. Certain objects, like functions, are callable. Other objects, like modules are not. You have a module mapped to the name drawffnet. Python tries to call that object, but it isn't callable. If there is a function drawffnet inside the drawffnet module (I'm not familiar with the package, so I don't know), you need to call that specifically. drawffnet.drawffnet(nn) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
Cal Who wrote: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print Cannot make drawffnet plot. You're importing the module 'drawffnet' and then trying to call it in: drawffnet(nn) but, as the traceback says, modules can't be called. I had a quick look at the documentation and it looks like you should be calling a function called 'drawffnet' that's defined in the module called 'drawffnet'. Try doing: from ffnet.tools.drawffnet import drawffnet instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
On 3/14/2010 2:20 PM, Cal Who wrote: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet is a module initialized from drawffnet.py (or either of the below) drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet here you create drawffnet from one of the files. import pylab drawffnet(nn) #Error: 'module' object is not callable This is an attempt to call the module as if it were a functions, which it is not. You probably want to call a function within the module. pylab.show() except ImportError, e: print Cannot make drawffnet plot. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with variable and function
On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall mehg...@gmail.com wrote: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? snip Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not seeing the dictionary, because the reversed approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type help, copyright, credits or license for more information. def foo(): ... bar = baz ... print bar ... baz = {1:foo} foo() {1: function foo at 0x37b870} Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
- Original Message - From: Stephen Hansen To: Cal Who Cc: python-list@python.org Sent: Sunday, March 14, 2010 2:33 PM Subject: Re: What does Error: 'module' object is not callable Mean? On Sun, Mar 14, 2010 at 10:20 AM, Cal Who calwhonos...@roadrunner.com wrote: from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. I'll keep that in mind but in this instance I simply cut and pasted the message. That said, drawffnet is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? I copied that code from an example and what you suggested fixed it. Thanks. --S -- No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2746 - Release Date: 03/14/10 03:33:00 -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with variable and function
Below is pasted the function which is looking for the funcs dictionary, as well as the dictionary. They appear in my py file in this order, yet I get an error in nextMode() that global name 'funcs' is not defined. Oddly, the keys dictionary works fine; it is defined above the nextMode function. def nextMode(): global HOTKEYS global HOTKEY_ACTIONS global mode global modes global modeNum global modeNames global funcs #mode=mode+1 #check to make sure the newly selected mode is enabled tmp=0 while(tmpmodeNum): mode=(mode+1)%modeNum if(sys.modules[modeNames[mode]].enabled=='True'): break #break on the first enabled mode we find #end if tmp+=1 #end while HOTKEYS=keys[mode] HOTKEY_ACTIONS=funcs[mode] registerHotkeys() speak(Now in +str(modes[mode])+ mode.) #end def #we now have the default mode to be used, but what if it is disabled? if(sys.modules[modeNames[mode]].enabled=='False'): nextMode() #end if funcs=[] #this dict MUST be defined after all the functions it uses have been #ARM function dictionary funcs.append({ 1 : exitProgram, 2 : arm.sayLoad1, 3 : arm.sayLoad2, 4 : arm.sayLoad3, 5 : arm.sayLoad4, 6 : arm.sayProcAvg, 7 : arm.sayUsedRam, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11: clipboard.toClipboard }) #weather function dictionary funcs.append({ 1 : exitProgram, 2 : weather.getCurrent, 3 : weather.getToday, 4 : weather.getTomorrow, 5 : weather.getTwoDays, 6 : weather.getThreeDays, 7 : weather.switchLocation, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11 : clipboard.toClipboard }) funcs.append({ 1 : exitProgram, 2 : network.speed, 3 : arm.sayLoad2, 4 : arm.sayLoad3, 5 : arm.sayLoad4, 6 : arm.sayProcAvg, 7 : arm.sayUsedRam, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11 : clipboard.toClipboard }) HOTKEY_ACTIONS=funcs[mode] On 3/14/10, Chris Rebert c...@rebertia.com wrote: On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall mehg...@gmail.com wrote: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? snip Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not seeing the dictionary, because the reversed approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type help, copyright, credits or license for more information. def foo(): ... bar = baz ... print bar ... baz = {1:foo} foo() {1: function foo at 0x37b870} Cheers, Chris -- http://blog.rebertia.com -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
David Monaghan monaghand.da...@gmail.com writes: of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say Boo to you at any moment. Beware. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less funny. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with variable and function
On 3/14/10, Chris Rebert c...@rebertia.com wrote: On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall mehg...@gmail.com wrote: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? snip Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not seeing the dictionary, because the reversed approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type help, copyright, credits or license for more information. def foo(): ... bar = baz ... print bar ... baz = {1:foo} foo() {1: function foo at 0x37b870} On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall mehg...@gmail.com wrote: Below is pasted the function which is looking for the funcs dictionary, as well as the dictionary. They appear in my py file in this order, yet I get an error in nextMode() that global name 'funcs' is not defined. Oddly, the keys dictionary works fine; it is defined above the nextMode function. Please include the full exception Traceback. Also, please don't top-post in the future. def nextMode(): global HOTKEYS global HOTKEY_ACTIONS global mode You don't need a `global` declaration unless your function needs to rebind the global variable in question. So you can remove the next 4 global declarations; they're unnecessary. global modes global modeNum global modeNames global funcs #mode=mode+1 #check to make sure the newly selected mode is enabled tmp=0 while(tmpmodeNum): mode=(mode+1)%modeNum if(sys.modules[modeNames[mode]].enabled=='True'): break #break on the first enabled mode we find #end if tmp+=1 #end while HOTKEYS=keys[mode] HOTKEY_ACTIONS=funcs[mode] registerHotkeys() speak(Now in +str(modes[mode])+ mode.) #end def #we now have the default mode to be used, but what if it is disabled? if(sys.modules[modeNames[mode]].enabled=='False'): nextMode() How is this call supposed to work when `funcs` (which nextMode() uses) hasn't been defined yet?! Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with variable and function
#we now have the default mode to be used, but what if it is disabled? if(sys.modules[modeNames[mode]].enabled=='False'): nextMode() How is this call supposed to work when `funcs` (which nextMode() uses) hasn't been defined yet?! That seems to have done it, thanks. Sorry about top-posting; inline posting is much harder to read when using a screen reader, as I do, so I am used to top-posting. On 3/14/10, Chris Rebert c...@rebertia.com wrote: On 3/14/10, Chris Rebert c...@rebertia.com wrote: On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall mehg...@gmail.com wrote: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? snip Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not seeing the dictionary, because the reversed approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type help, copyright, credits or license for more information. def foo(): ... bar = baz ... print bar ... baz = {1:foo} foo() {1: function foo at 0x37b870} On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall mehg...@gmail.com wrote: Below is pasted the function which is looking for the funcs dictionary, as well as the dictionary. They appear in my py file in this order, yet I get an error in nextMode() that global name 'funcs' is not defined. Oddly, the keys dictionary works fine; it is defined above the nextMode function. Please include the full exception Traceback. Also, please don't top-post in the future. def nextMode(): global HOTKEYS global HOTKEY_ACTIONS global mode You don't need a `global` declaration unless your function needs to rebind the global variable in question. So you can remove the next 4 global declarations; they're unnecessary. global modes global modeNum global modeNames global funcs #mode=mode+1 #check to make sure the newly selected mode is enabled tmp=0 while(tmpmodeNum): mode=(mode+1)%modeNum if(sys.modules[modeNames[mode]].enabled=='True'): break #break on the first enabled mode we find #end if tmp+=1 #end while HOTKEYS=keys[mode] HOTKEY_ACTIONS=funcs[mode] registerHotkeys() speak(Now in +str(modes[mode])+ mode.) #end def #we now have the default mode to be used, but what if it is disabled? if(sys.modules[modeNames[mode]].enabled=='False'): nextMode() How is this call supposed to work when `funcs` (which nextMode() uses) hasn't been defined yet?! Cheers, Chris -- http://blog.rebertia.com -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: how to start a python script only once
On Mar 13, 8:45 pm, News123 news1...@free.fr wrote: Hi, I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. sqlite and locking quite some time ago I used a mysql table and locking as an inter-host mutex. Perhaps sqlite would be good enough for an inter process mutex for processes on the same host, but I don't know it well enough. interprocess mutex well I even don't know whether something like this exists on linux / windows Thanks in advanced for any tips N I'll just open a port with a TCP socket, it is cross-platform and free from race conditions. -- http://mail.python.org/mailman/listinfo/python-list
sqlite3 is sqlite 2?
gand...@ubuntu:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. import sqlite3 sqlite3.version '2.4.1' Is it possible to install a real sqlite version 3 somehow? I really need it because I have to use savepoint/rollback to. That is only supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know that is not a question about Python itself. But still, it is interesting that a module named sqlite3 can actually be used for something called sqlite 2. Thanks Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Am 14.03.2010 16:03, schrieb pyt...@bdurham.com: Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P -- http://mail.python.org/mailman/listinfo/python-list
messages
For Good messages please visit http://messagezonehere.blogspot.com/2010/03/friendly-messages.html -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma j...@castleamber.com wrote: David Monaghan monaghand.da...@gmail.com writes: of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say Boo to you at any moment. Beware. Sorry. That last comment of mine was uncalled for. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less funny. Good point, although one could argue the unhidden response is just rude, but the masking does make it genuinely funny. DaveM -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P WinPDB runs on non-Windows platforms :) Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 is sqlite 2?
On Fri, 2010-03-12 at 06:48 +0100, Laszlo Nagy wrote: gand...@ubuntu:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. import sqlite3 sqlite3.version '2.4.1' Is it possible to install a real sqlite version 3 somehow? I really need it because I have to use savepoint/rollback to. That is only supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know that is not a question about Python itself. That's the sqlite *bindings* version: sqlite3.version '2.4.1' sqlite3.sqlite_version '3.6.16' So this is pysqlite version 2.4.1, which wraps sqlite version 3.6.16. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
David Monaghan monaghand.da...@gmail.com writes: On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma j...@castleamber.com wrote: David Monaghan monaghand.da...@gmail.com writes: of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say Boo to you at any moment. Beware. Sorry. That last comment of mine was uncalled for. Thanks. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less funny. Good point, although one could argue the unhidden response is just rude, but the masking does make it genuinely funny. One could argue, sure. But to me it's just the same as posting GFY (don't want to upset the tender soulds again with the F-word. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
On 14 mar, 20:35, Michael Rudolf spamfres...@ch3ka.de wrote: Am 14.03.2010 16:03, schrieb pyt...@bdurham.com: Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P WinPdb is crossplatform. Is build with -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 is sqlite 2?
Laszlo Nagy gand...@shopzeus.com writes: gand...@ubuntu:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. import sqlite3 sqlite3.version '2.4.1' Is it possible to install a real sqlite version 3 somehow? I really need it because I have to use savepoint/rollback to. That is only supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know that is not a question about Python itself. But still, it is interesting that a module named sqlite3 can actually be used for something called sqlite 2. You're mistaking the *module* version with the version of the database, unless I am mistaken. -- John Bokma j3b Hacking Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl Python Development -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
On 14 mar, 20:35, Michael Rudolf spamfres...@ch3ka.de wrote: Am 14.03.2010 16:03, schrieb pyt...@bdurham.com: Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P Sorry, i hit the wrong key. Again: winpdb is crossplatform. It uses a wxwindows gui. Names are not really fortunate... I have installed the last winpdb 1.4.6 in SPE today. atb joaquin -- http://mail.python.org/mailman/listinfo/python-list
Python unicode and Windows cmd.exe
Hi, I would appreciate if someone could point out what am I doing wrong here. Basically, I need to save a string containing non-ascii characters to a file encoded in utf-8. If I stay in python, everything seems to work fine, but the moment I try to read the file with another Windows program, everything goes to hell. So here's the script unicode2file.py: === # encoding=utf-8 import codecs f = codecs.open(m.txt,mode=w, encoding=utf8) a = umañana print repr(a) f.write(a) f.close() f = codecs.open(m.txt, mode=r, encoding=utf8) a = f.read() print repr(a) f.close() === That gives the expected output, both calls to repr() yield the same result. But now, if I do type me.txt in cmd.exe, I get garbled characters instead of ñ. I then open the file with my editor (Sublime Text), and I see mañana normally. I save (nothing to be saved, really), go back to the dos prompt, do type m.txt and I get again the same garbled characters. I then open the file m.txt with notepad, and I see mañana normally. I save (again, no actual modifications), go back to the dos prompt, do type m.txt and this time it works! I get mañana. When notepad opens the file, the encoding is already UTF-8, so short of a UTF-8 bom being added to the file, I don't know what happens when I save the unmodified file. Also, I would think that the python script should save a valid utf-8 file in the first place... What's going on here? Regards, Guillermo -- http://mail.python.org/mailman/listinfo/python-list
sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?)
That's the sqlite *bindings* version: sqlite3.version '2.4.1' sqlite3.sqlite_version '3.6.16' Thanks. I tried it and RELEASE command didn't work: import sqlite3 conn = sqlite3.connect(':memory:') with conn: ... conn.execute(BEGIN) ... conn.execute(create table a ( i integer)) ... conn.execute(insert into a values (1)) ... conn.execute(savepoint sp1) ... conn.execute(insert into a values(2)) ... conn.execute(release sp1) ... conn.execute(COMMIT) ... sqlite3.Cursor object at 0xb7e29b30 sqlite3.Cursor object at 0xb7e29b60 sqlite3.Cursor object at 0xb7e29b30 sqlite3.Cursor object at 0xb7e29b60 sqlite3.Cursor object at 0xb7e29b30 Traceback (most recent call last): File stdin, line 7, in module sqlite3.OperationalError: no such savepoint: sp1 The syntax is correct: http://www.sqlite.org/lang_savepoint.html The savepoint was really created. But I get this error, telling no such savepoint. What is wrong here? Maybe it has to do something with transaction isolation? :-s Thank you Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
Am 14.03.2010 21:08, schrieb pyt...@bdurham.com: Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P WinPDB runs on non-Windows platforms :) Uh, OK. Then the name mislead me ;) But yeah, I prefer a console based debugger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to use re2 from Python?
2010/3/14 _wolf wolfgang.l...@gmail.com: ... i would like to use re2 from Python (preferrably Python 3.1) and was excited to see files like make_unicode_groups.py in the distro (maybe just used during the build process?). those however were not deployed on my machine. ... If you would need a re engine with features like unicode rangees, script, and character properties classes and many others, you may try the proposed implementation of the re library currently available in python issue tracker: http://bugs.python.org/issue2636 I am personally more than satisfied with this development version sofar, however, as some new feature like unlimited lookarounds etc. suggest, it is a classic backtracking engine (as opposed to re2, if you need this very implementation). hth vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: Breaking the __main__ script
pyt...@bdurham.com wrote: Any reason you prefer PDB over WinPDB? http://winpdb.org/ Yes. I don't have Windows except one one PC :P WinPDB runs on non-Windows platforms :) One might reasonably argue that it has a pretty couter-intuitive name, then. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
Thanks for the replies. That fixed it but produced another problem. There are two plotting routines below. Either one will work without error. But the combo produces: The exception unknown software exception (0x4015) occurred in the application at location 0x1e05b62a. in a dialog box and the following in the console Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what isa wrong? Second question: Is it common to group all the from statements at the top of the program or to put them by the relavent code as I have here? Thanks a lot try: #Or we can use the two commented statements #from ffnet.tools import drawffnet from ffnet.tools.drawffnet import drawffnet import pylab #drawffnet.drawffnet(nn) drawffnet(nn) pylab.show() except ImportError, e: print Cannot make drawffnet plot.\n%s % e ? ? # Plot adapted from # http://ffnet.sourceforge.net/examples/stock.html # Make plot if matplotlib is avialble try: from pylab import * plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() except ImportError, e: print Cannot make plots. For plotting install matplotlib.\n%s % e ? ? -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?)
On Fri, 2010-03-12 at 07:46 +0100, Laszlo Nagy wrote: import sqlite3 conn = sqlite3.connect(':memory:') with conn: ... conn.execute(BEGIN) ... conn.execute(create table a ( i integer)) ... conn.execute(insert into a values (1)) ... conn.execute(savepoint sp1) ... conn.execute(insert into a values(2)) ... conn.execute(release sp1) ... conn.execute(COMMIT) ... sqlite3.Cursor object at 0xb7e29b30 sqlite3.Cursor object at 0xb7e29b60 sqlite3.Cursor object at 0xb7e29b30 sqlite3.Cursor object at 0xb7e29b60 sqlite3.Cursor object at 0xb7e29b30 Traceback (most recent call last): File stdin, line 7, in module sqlite3.OperationalError: no such savepoint: sp1 The syntax is correct: http://www.sqlite.org/lang_savepoint.html The savepoint was really created. But I get this error, telling no such savepoint. What is wrong here? Maybe it has to do something with transaction isolation? :-s From memory you can't issue a CREATE TABLE statement inside a transaction, at least not at the default isolation level. Such a statement will automatically commit the current transaction. Doesn't help with your current problem but worth pointing out :-) When debugging strange transaction behaviour, I find it easiest to create the connection with isolation_level=None so that are no implicit transactions being created behind your back. Not sure why, but setting this makes your example work for me. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
MRAB pyt...@mrabarnett.plus.com wrote in message news:mailman.745.1268592389.23598.python-l...@python.org... Cal Who wrote: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print Cannot make drawffnet plot. You're importing the module 'drawffnet' and then trying to call it in: drawffnet(nn) but, as the traceback says, modules can't be called. I had a quick look at the documentation and it looks like you should be calling a function called 'drawffnet' that's defined in the module called 'drawffnet'. Try doing: from ffnet.tools.drawffnet import drawffnet instead. Thanks, Works great - please see my other post -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
Terry Reedy tjre...@udel.edu wrote in message news:mailman.746.1268592481.23598.python-l...@python.org... On 3/14/2010 2:20 PM, Cal Who wrote: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet is a module initialized from drawffnet.py (or either of the below) drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what not callable means. Could it be referencing to nn rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet here you create drawffnet from one of the files. import pylab drawffnet(nn) #Error: 'module' object is not callable This is an attempt to call the module as if it were a functions, which it is not. You probably want to call a function within the module. Exactly. Thanks it works now. Please see my other post. pylab.show() except ImportError, e: print Cannot make drawffnet plot. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
Guillermo: I then open the file m.txt with notepad, and I see mañana normally. I save (again, no actual modifications), go back to the dos prompt, do type m.txt and this time it works! I get mañana. When notepad opens the file, the encoding is already UTF-8, so short of a UTF-8 bom being added to the file, That is what happens: the file now starts with a BOM \xEB\xBB\xBF as you can see with a hex editor. I don't know what happens when I save the unmodified file. Also, I would think that the python script should save a valid utf-8 file in the first place... Its just as valid UTF-8 without a BOM. People have different opinions on this but for compatibility, I think it is best to always start UTF-8 files with a BOM. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
On Sun, Mar 14, 2010 at 12:58 PM, Cal Who calwhonos...@roadrunner.com wrote: snip Second question: Is it common to group all the from statements at the top of the program or to put them by the relavent code as I have here? The former. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Some PyCon videos won't play
On 3/14/2010 2:41 PM, Terry Reedy wrote: On 3/14/2010 11:14 AM, David Boddie wrote: You should still be able to get at the videos themselves by inspecting the page contents, looking for download links like this one: http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv In this case, it's an Ogg Theora video file, so you may want to use a player like VLC to view it: For people using html5 competant browsers, which, I believe, play .ogv 'in tha page', blip.tv just needs to update site to make html5 pages an alternative to using the flash player. Actually, for FF3.6, at least, the problem is already solved. I just click on the download button and FF recognizes .ogv as something it can play and it does, replacing the flash player. The FF player lacks a full-screen button, but that is rarely needed for the talks. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
On Mar 14, 4:04 pm, David Monaghan monaghand.da...@gmail.com wrote: On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma j...@castleamber.com wrote: David Monaghan monaghand.da...@gmail.com writes: of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say Boo to you at any moment. Beware. Sorry. That last comment of mine was uncalled for. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less funny. Good point, although one could argue the unhidden response is just rude, but the masking does make it genuinely funny. DaveM I thought the point of LMGTFY was to humorously and innocuously get across the point that a lot of basic questions can be answered instantly, or just a few key terms and a mouse click away (i.e. Was that so hard?) instead of having to write and post a message to a group and then wait for responses. In this sense, using LMGTFY *is* a memorable transmission of information beyond just the answer to the question. It is the meta-information of how to teach a man to fish. If someone LMGTFY'ed me due to my asking a really Googleable question, I'd feel I deserved this gentle ribbing and would make a note to be more diligent in my searches before asking a forum. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
That is what happens: the file now starts with a BOM \xEB\xBB\xBF as you can see with a hex editor. Is this an enforced convention under Windows, then? My head's aching after so much pulling at my hair, but I have the feeling that the problem only arises when text travels through the dos console... Cheers, Guillermo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
On 14 mar, 22:22, Guillermo guillermo.lis...@googlemail.com wrote: That is what happens: the file now starts with a BOM \xEB\xBB\xBF as you can see with a hex editor. Is this an enforced convention under Windows, then? My head's aching after so much pulling at my hair, but I have the feeling that the problem only arises when text travels through the dos console... Cheers, Guillermo search for BOM in wikipedia. There it talks about notepad behavior. ja -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite savepoint problem
From memory you can't issue a CREATE TABLE statement inside a transaction, at least not at the default isolation level. Such a statement will automatically commit the current transaction. Doesn't help with your current problem but worth pointing out :-) Thank you. I'll keep in mind. When debugging strange transaction behaviour, I find it easiest to create the connection with isolation_level=None so that are no implicit transactions being created behind your back. Not sure why, but setting this makes your example work for me. Yes, same for me. But setting it to None means auto commit mode! See here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions But it does not work that way. Look at this example import sqlite3 conn = sqlite3.connect(':memory:') conn.isolation_level = None with conn: conn.execute(create table a ( i integer ) ) with conn: conn.execute(insert into a values (1)) conn.execute(SAVEPOINT sp1) conn.execute(insert into a values (2)) conn.execute(SAVEPOINT sp2) conn.execute(insert into a values (3)) conn.execute(ROLLBACK TO sp2) conn.execute(insert into a values (4)) conn.execute(RELEASE sp1) with conn: for row in conn.execute(select * from a): print row It prints: (1,) (2,) (4,) So everything is working. Nothing is auto commited. But if I change it to DEFERRED or IMMEDIATE or EXCLUSIVE then it won't work. Why? I'm now confused. Also, I could not find anything about these isolation levels on the sqlite website. The only think I could find is PRAGMA read_uncommited. If that is the same as setting isolation_level to None, then I don't want it. L -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
On 3/14/2010 4:40 PM, Guillermo wrote: Hi, I would appreciate if someone could point out what am I doing wrong here. Basically, I need to save a string containing non-ascii characters to a file encoded in utf-8. If I stay in python, everything seems to work fine, but the moment I try to read the file with another Windows program, everything goes to hell. So here's the script unicode2file.py: === # encoding=utf-8 import codecs f = codecs.open(m.txt,mode=w, encoding=utf8) a = umañana print repr(a) f.write(a) f.close() f = codecs.open(m.txt, mode=r, encoding=utf8) a = f.read() print repr(a) f.close() === That gives the expected output, both calls to repr() yield the same result. But now, if I do type me.txt in cmd.exe, I get garbled characters instead of ñ. I then open the file with my editor (Sublime Text), and I see mañana normally. I save (nothing to be saved, really), go back to the dos prompt, do type m.txt and I get again the same garbled characters. I then open the file m.txt with notepad, and I see mañana normally. I save (again, no actual modifications), go back to the dos prompt, do type m.txt and this time it works! I get mañana. When notepad opens the file, the encoding is already UTF-8, so short of a UTF-8 bom being There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron. added to the file, I don't know what happens when I save the unmodified file. Also, I would think that the python script should save a valid utf-8 file in the first place... Adding the byte that some call a 'utf-8 bom' makes the file an invalid utf-8 file. However, I suspect that notepad wrote the file in the system encoding, which can encode n with tilde and which cmd.exe does understand. If you started with a file with encoded cyrillic, arabic, hindi, and chinese characters (for instance), I suspect you would get a different result. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
Guillermo: Is this an enforced convention under Windows, then? My head's aching after so much pulling at my hair, but I have the feeling that the problem only arises when text travels through the dos console... The console is commonly using Code Page 437 which is most compatible with old DOS programs since it can display line drawing characters. You can change the code page to UTF-8 with chcp 65001 Now, type m.txt with the original BOM-less file and it should be OK. You may also need to change the console font to one that is Unicode compatible like Lucida Console. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to use re2 from Python?
i am afraid that thread goes straight perpendicular to what re2 is supposed to be, or do. my suggestion for these folks would be to create a new, clean interface to stop the violence that comes with the Python ``re`` interface, and open the thing up so one can plug in ``re`` implementations as are needed. when i absolutely need a feature, i can always go to the slower machine; simpler regular expressions could be dealt with more efficiently. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to use re2 from Python?
There's a recent thread about this on the python-dev list, pointers? i searched but didn’t find anything. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite savepoint problem
I'm now confused. Also, I could not find anything about these isolation levels on the sqlite website. The only think I could find is PRAGMA read_uncommited. If that is the same as setting isolation_level to None, then I don't want it. Yes, it is. Here is a test: import os import sqlite3 import threading import time FPATH = '/tmp/test.sqlite' if os.path.isfile(FPATH): os.unlink(FPATH) def getconn(): global FPATH conn = sqlite3.connect(FPATH) conn.isolation_level = None return conn class Thr1(threading.Thread): def run(self): conn = getconn() print Thr1: Inserting 0,1,2,3,4,5 with conn: for i in range(6): conn.execute(insert into a values (?),[i]) print Thr1: Commited with conn: print Thr1: Selecting all rows: for row in conn.execute(select * from a): print row print Thr1: Wait some... time.sleep(3) print Thr1: Selecting again, in the same transaction for row in conn.execute(select * from a): print row class Thr2(threading.Thread): def run(self): conn = getconn() with conn: print Thr2: deleting all rows from a conn.execute(delete from a) print Thr2: Now we wait some BEFORE commiting changes. time.sleep(3) print Thr2: Will roll back! raise Exception def main(): with getconn() as conn: conn.execute(create table a ( i integer ) ) thr1 = Thr1() thr1.start() time.sleep(1) thr1 = Thr2() thr1.start() main() And the test result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction Thr2: Will roll back! Exception in thread Thread-2: Traceback (most recent call last): File /usr/lib/python2.6/threading.py, line 525, in __bootstrap_inner self.run() File test.py, line 44, in run raise Exception Exception It means that setting isolation_level to None will really allow uncommited changes to be read by other transactions! This is sad, and of course this is something that I do not want. If I change it to DEFERRED then I get a correct result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction (0,) (1,) (2,) (3,) (4,) (5,) Thr2: Will roll back! However, then savepoints won't work. Is there any way to use read commited (or higher) isolation level, and have savepoints working at the same time? I don't see how would savepoints be useful without at least read commited isolation level. :-( L -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
The console is commonly using Code Page 437 which is most compatible with old DOS programs since it can display line drawing characters. You can change the code page to UTF-8 with chcp 65001 That's another issue in my actual script. A twofold problem, actually: 1) For me chcp gives 850 and I'm relying on that to decode the bytes I get back from the console. I suppose this is bound to fail because another Windows installation might have a different default codepage. 2) My script gets output from a Popen call (to execute a Powershell script [new Windows shell language] from Python; it does make sense!). I suppose changing the Windows codepage for a single Popen call isn't straightforward/possible? Right now, I only get the desired result if I decode the output from Popen as cp850. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite savepoint problem
On Fri, 2010-03-12 at 08:48 +0100, Laszlo Nagy wrote: I'm now confused. Also, I could not find anything about these isolation levels on the sqlite website. The only think I could find is PRAGMA read_uncommited. If that is the same as setting isolation_level to None, then I don't want it. Yes, it is. Here is a test: No it isn't. The magic behind isolation_level is a creation of the python sqlite bindings. You can probably tell that I'm not a fan of it. import os import sqlite3 import threading import time FPATH = '/tmp/test.sqlite' if os.path.isfile(FPATH): os.unlink(FPATH) def getconn(): global FPATH conn = sqlite3.connect(FPATH) conn.isolation_level = None return conn class Thr1(threading.Thread): def run(self): conn = getconn() print Thr1: Inserting 0,1,2,3,4,5 with conn: for i in range(6): conn.execute(insert into a values (?),[i]) print Thr1: Commited with conn: print Thr1: Selecting all rows: for row in conn.execute(select * from a): print row print Thr1: Wait some... time.sleep(3) print Thr1: Selecting again, in the same transaction for row in conn.execute(select * from a): print row class Thr2(threading.Thread): def run(self): conn = getconn() with conn: print Thr2: deleting all rows from a conn.execute(delete from a) print Thr2: Now we wait some BEFORE commiting changes. time.sleep(3) print Thr2: Will roll back! raise Exception def main(): with getconn() as conn: conn.execute(create table a ( i integer ) ) thr1 = Thr1() thr1.start() time.sleep(1) thr1 = Thr2() thr1.start() main() And the test result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction Thr2: Will roll back! Exception in thread Thread-2: Traceback (most recent call last): File /usr/lib/python2.6/threading.py, line 525, in __bootstrap_inner self.run() File test.py, line 44, in run raise Exception Exception It means that setting isolation_level to None will really allow uncommited changes to be read by other transactions! This is sad, and of course this is something that I do not want. No it doesn't. The problem is that using a connection as a context manager doesn't do what you think. It does *not* start a new transaction on __enter__ and commit it on __exit__. As far as I can tell it does nothing on __enter__ and calls con.commit() or con.rollback() on exit. With isolation_level=None, these are no-ops. If you create your own connection wrapper that explicitly creates and commits transactions, you example will work fine with isolation_level=None. Here's the relevant changes: class MyConn(sqlite3.Connection): def __enter__(self): self.execute(BEGIN) return self def __exit__(self,exc_type,exc_info,traceback): if exc_type is None: self.execute(COMMIT) else: self.execute(ROLLBACK) def getconn(): global FPATH conn = sqlite3.connect(FPATH,factory=MyConn) conn.isolation_level = None return conn Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
Guillermo: 2) My script gets output from a Popen call (to execute a Powershell script [new Windows shell language] from Python; it does make sense!). I suppose changing the Windows codepage for a single Popen call isn't straightforward/possible? You could try SetConsoleOutputCP and SetConsoleCP. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
2) My script gets output from a Popen call (to execute a Powershell script [new Windows shell language] from Python; it does make sense!). I suppose changing the Windows codepage for a single Popen call isn't straightforward/possible? Nevermind. I'm able to change Windows' codepage to 65001 from within the Powershell script and I get back a string encoded in UTF-8 with BOM, so problem solved! Thanks for the help, Guillermo -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
I cleaned up the code by moving all the imports to the top. There are two plotting routines shown below. Either one will work without error. But when I include both, running produces: The exception unknown software exception (0x4015) occurred in the application at location 0x1e05b62a. In a dialog box and the following in the console: Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what is wrong? Thanks a lot from pylab import plot, legend, title, grid, show, xlabel, ylabel ...snip #FIRST PLOT plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() #SECOND PLOT drawffnet(nn) show() -- http://mail.python.org/mailman/listinfo/python-list
[ANNC] pynguin-0.4 (python turtle graphics application)
Pynguin is a python-based turtle graphics application. It combines an editor, interactive interpreter, and graphics display area. It is meant to be an easy environment for introducing some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues adding basic functionality and refining the interface. If you are interested, please take a look and let me know what you think. Pynguin is tested with Python 2.6.4 and uses PyQt (4.6) for its GUI elements. Pynguin is released under GPLv3. Changes in pynguin-0.4: - improved document switcher - added easy 'random' color access - added new commands - onscreen - onclick - stamp - viewcoords - winding fill now default - added method to switch between winding/oddeven fill - show file name in window header - more examples - added default values for examples that take parameters - fixed star example for even number of sides - fixed crash when changing to alternate view image - fixed problem running code with blank lines - fixed problem with ctrl key getting stuck on - added bug report option in Help menu - allow keypad Enter same as Return - factored in to multiple files Changes in pynguin-0.3: - added new commands - goto - turnto - lineto - distance - toward - write - added more examples - fixed problem when changing speed while code is running - editor auto-indent improvement _ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite savepoint problem
On Fri, 2010-03-12 at 08:32 +0100, Laszlo Nagy wrote: From memory you can't issue a CREATE TABLE statement inside a transaction, at least not at the default isolation level. Such a statement will automatically commit the current transaction. Doesn't help with your current problem but worth pointing out :-) Thank you. I'll keep in mind. When debugging strange transaction behaviour, I find it easiest to create the connection with isolation_level=None so that are no implicit transactions being created behind your back. Not sure why, but setting this makes your example work for me. Yes, same for me. But setting it to None means auto commit mode! See here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions But it does not work that way. Look at this example import sqlite3 conn = sqlite3.connect(':memory:') conn.isolation_level = None with conn: conn.execute(create table a ( i integer ) ) with conn: conn.execute(insert into a values (1)) conn.execute(SAVEPOINT sp1) conn.execute(insert into a values (2)) conn.execute(SAVEPOINT sp2) conn.execute(insert into a values (3)) conn.execute(ROLLBACK TO sp2) conn.execute(insert into a values (4)) conn.execute(RELEASE sp1) with conn: for row in conn.execute(select * from a): print row It prints: (1,) (2,) (4,) So everything is working. Nothing is auto commited. But if I change it to DEFERRED or IMMEDIATE or EXCLUSIVE then it won't work. Why? I have a theory, based on a quick perusal of the sqlite3 bindings source. The bindings think that SAVEPOINT sp1 is a non-DML, non-query statement. So when isolation_level is something other than None, this statement implicitly commits the current transaction and throws away your savepoints! Annotating your example: # entering this context actually does nothing with conn: # a transaction is magically created before this statement conn.execute(insert into a values (1)) # and is implicitly committed before this statement conn.execute(SAVEPOINT sp1) # a new transaction is magically created conn.execute(insert into a values (2)) # and committed, discarding the first savepoint. conn.execute(SAVEPOINT sp2) # a new transaction is magically created conn.execute(insert into a values (3)) # and committed, discarding the very savepoint we are trying to use. conn.execute(ROLLBACK TO sp2) conn.execute(insert into a values (4)) conn.execute(RELEASE sp1) In your previous multi-threaded example, try adding a SAVEPOINT sp1 statement after deleting the rows in Thread2. You'll see that the delete is immediately committed and the rows cannot be read back by Thread1. (modified version attached for convenience). Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details import os import sqlite3 import threading import time FPATH = '/tmp/test.sqlite' if os.path.isfile(FPATH): os.unlink(FPATH) class MyConn(sqlite3.Connection): def __enter__(self): self.execute(BEGIN) return self def __exit__(self,exc_type,exc_info,traceback): if exc_type is None: self.execute(COMMIT) else: self.execute(ROLLBACK) def getconn(): global FPATH conn = sqlite3.connect(FPATH)#,factory=MyConn) conn.isolation_level = None return conn class Thr1(threading.Thread): def run(self): conn = getconn() print Thr1: Inserting 0,1,2,3,4,5 with conn: for i in range(6): conn.execute(insert into a values (?),[i]) print Thr1: Commited with conn: print Thr1: Selecting all rows: for row in conn.execute(select * from a): print row print Thr1: Wait some... time.sleep(3) print Thr1: Selecting again, in the same transaction for row in conn.execute(select * from a): print row class Thr2(threading.Thread): def run(self): conn = getconn() with conn: print Thr2: deleting all rows from a conn.execute(delete from a) conn.execute(savepoint sp1) print Thr2: Now we wait some BEFORE commiting changes. time.sleep(3) print Thr2: Will roll back! raise Exception def main(): with getconn() as conn: conn.execute(create table a ( i integer ) ) thr1 = Thr1() thr1.start() time.sleep(1) thr1 = Thr2() thr1.start() main() signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: python to exe
On Sun, 14 Mar 2010 14:11:18 -0600, John Bokma wrote: One could argue, sure. But to me it's just the same as posting GFY (don't want to upset the tender soulds again with the F-word. Are you *still* going on about this thing? Sheesh. You've made your point. You don't think posting links to Let Me Google That For You is friendly; you think that hiding those links behind tinyurl is downright hostile; and you think that heaping abuse and obscenities on the person who posted the link is acceptable behaviour. You've made it abundantly clear that your concern about keeping this group friendly only applies to others, not to you. Can we move on now? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Error: 'module' object is not callable Mean?
I found it. Had to use figure to create a new figure! Cal Who calwhonos...@roadrunner.com wrote in message news:hnjp6f$l...@news.eternal-september.org... I cleaned up the code by moving all the imports to the top. There are two plotting routines shown below. Either one will work without error. But when I include both, running produces: The exception unknown software exception (0x4015) occurred in the application at location 0x1e05b62a. In a dialog box and the following in the console: Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what is wrong? Thanks a lot from pylab import plot, legend, title, grid, show, xlabel, ylabel ...snip #FIRST PLOT plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() #SECOND PLOT drawffnet(nn) show() -- http://mail.python.org/mailman/listinfo/python-list
Understanding the CPython dict implementation
I found this PyCon2010 presentation to be excellent: The Mighty Dictionary, Branden Craig Rhodes, 30 min. http://pycon.blip.tv/file/3264041/ Even knowing Python for over a decade, I learned a few things. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
Terry Reedy tjre...@udel.edu wrote in message news:hnjkuo$n1...@dough.gmane.org... On 3/14/2010 4:40 PM, Guillermo wrote: Adding the byte that some call a 'utf-8 bom' makes the file an invalid utf-8 file. Not true. From http://unicode.org/faq/utf_bom.html: Q: When a BOM is used, is it only in 16-bit Unicode text? A: No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising the BOM will be whatever the Unicode character FEFF is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in. Examples: BytesEncoding Form 00 00 FE FF UTF-32, big-endian FF FE 00 00 UTF-32, little-endian FE FFUTF-16, big-endian FF FEUTF-16, little-endian EF BB BF UTF-8 -Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
* Mark Tolonen: Terry Reedy tjre...@udel.edu wrote in message news:hnjkuo$n1...@dough.gmane.org... On 3/14/2010 4:40 PM, Guillermo wrote: Adding the byte that some call a 'utf-8 bom' makes the file an invalid utf-8 file. Not true. From http://unicode.org/faq/utf_bom.html: Q: When a BOM is used, is it only in 16-bit Unicode text? A: No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising the BOM will be whatever the Unicode character FEFF is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in. Examples: BytesEncoding Form 00 00 FE FF UTF-32, big-endian FF FE 00 00 UTF-32, little-endian FE FFUTF-16, big-endian FF FEUTF-16, little-endian EF BB BF UTF-8 Well, technically true, and Terry was wrong about There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron.. It's true that as a descriptive term byte order mark is an oxymoron for UTF-8. But in this particular context it's not a descriptive term, and it's not only technically allowed, as you point out, but sometimes required. However, some tools are unable to process UTF-8 files with BOM. The most annoying example is the GCC compiler suite, in particular g++, which in its Windows MinGW manifestation insists on UTF-8 source code without BOM, while Microsoft's compiler needs the BOM to recognize the file as UTF-8 -- the only way I found to satisfy both compilers, apart from a restriction to ASCII or perhaps Windows ANSI with wide character literals restricted to ASCII (exploiting a bug in g++ that lets it handle narrow character literals with non-ASCII chars) is to preprocess the source code. But that's not a general solution since the g++ preprocessor, via another bug, accepts some constructs (which then compile nicely) which the compiler doesn't accept when explicit preprocessing isn't used. So it's a mess. Cheers, - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator/generator
First of all, as Steve Holden mentioned, do look at xlrd. It's awesome. Second, for your (a) question, if you want an iterator, that's quite easy: matriz = iter(matriz) matriz.next() # Discard the first one for i in matriz: This technique works really well, especially if you have sub-loops. Then, if you use a defaultdict which uses a list for a constructor for i in matriz: if i[a] and i[b]: g[i[a]].append(i[b]) HTH, Pat -- http://mail.python.org/mailman/listinfo/python-list
Re: result of os.times() is different with 'time' command Options
hiral hiralsmaill...@gmail.com wrote: ... Output: real0.0m0.010002421s user0.0m0.0s sys 0.0m0.0s Command: $ time ls Output: real0m0.007s user0m0.000s sys 0m0.000s Is this the intended behaviour? What is it that you are wondering about? The formatting difference is due to your code. The difference between 10 milliseconds and 7 milliseconds could be due to any number of things. First, you have the overhead of Python involved in your measurements. Second, you have the variability of memory caching and disk caching. Your Python code causes /bin/ls to be loaded into memory, and it's probably still in a file cache when you run the second command. You can't really do an analysis like this with a task that only takes a few milliseconds. There are too many variables. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
dll in project?
Hi all, I have a dll I am trying to use, but I get a Windows error 126, the specified module could not be found. Here is the code segment: nvdaController=ctypes.windll.LoadLibrary(nvdaControllerClient32.dll) I have the specified dll file in the same directory as the file trying to use said dll, and this is the only reference I make to the dll. Do I need to register it somehow? If so, does this need to be done once, or each time the application runs? If I need to register it, how would I do so? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?
The HTMLTemplate module is useful for static web page generation. It doesn't do much. It's not a content management system. If you just need to generate a page with some data items filled in, it's fine. If you need more than that, there are bigger packages, but they have more baggage. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding the CPython dict implementation
Terry Reedy wrote: I found this PyCon2010 presentation to be excellent: The Mighty Dictionary, Branden Craig Rhodes, 30 min. http://pycon.blip.tv/file/3264041/ Even knowing Python for over a decade, I learned a few things. Terry Jan Reedy Is this available as a paper? John Nagle -- http://mail.python.org/mailman/listinfo/python-list
File existence check with partial filename
I learned that I can check the existence of a file using os.path.isfile(filename). What if I need to check if there is a file that contains HV in the filename? What should I do? Thank you, Sang-Ho -- http://mail.python.org/mailman/listinfo/python-list
Re: dll in project?
* Alex Hall: Hi all, I have a dll I am trying to use, but I get a Windows error 126, the specified module could not be found. Here is the code segment: nvdaController=ctypes.windll.LoadLibrary(nvdaControllerClient32.dll) I have the specified dll file in the same directory as the file trying to use said dll, and this is the only reference I make to the dll. Do I need to register it somehow? If so, does this need to be done once, or each time the application runs? If I need to register it, how would I do so? Thanks! If 'ctypes.windll.LoadLibrary' just calls the Windows API LoadLibrary function without adding any path, then the directories considered will only be those known to the Windows API, like e.g. the process' current directory (I'm not sure if the current directory is considered, but the details aren't important). And most likely your calling script file is not in any of those directories. Probably it will work to specify the full path to the DLL. You can obtain the path to the calling file's directory by using the __file__ variable and the 'os.path' functions. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: File existence check with partial filename
* Sang-Ho Yun: I learned that I can check the existence of a file using os.path.isfile(filename). What if I need to check if there is a file that contains HV in the filename? What should I do? code from __future__ import print_function import os for filename in os.listdir( . ): if HV in filename.upper(): print( filename ) /code Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: File existence check with partial filename
Alf P. Steinbach wrote: * Sang-Ho Yun: I learned that I can check the existence of a file using os.path.isfile(filename). What if I need to check if there is a file that contains HV in the filename? What should I do? code from __future__ import print_function import os for filename in os.listdir( . ): if HV in filename.upper(): print( filename ) /code Cheers hth., - Alf Or learn the glob module. It allows you to ask for a list of files matching a pattern that can include wildcard characters -- probably *HV* for your case. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: NoSQL Movement?
On Sun, Mar 14, 2010 at 6:55 AM, D'Arcy J.M. Cain da...@druid.net wrote: On Sat, 13 Mar 2010 23:42:31 -0800 Jonathan Gardner jgard...@jonathangardner.net wrote: On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin no.em...@nospam.invalid wrote: D'Arcy J.M. Cain da...@druid.net writes: Just curious, what database were you using that wouldn't keep up with you? I use PostgreSQL and would never consider going back to flat files. Try making a file with a billion or so names and addresses, then compare the speed of inserting that many rows into a postgres table against the speed of copying the file. That's a straw man argument. Copying an already built database to another copy of the database won't be significantly longer than copying an already built file. In fact, it's the same operation. I don't understand what you're trying to get at. Each bit of data follows a particular path through the system. Each bit of data has its own requirements for availability and consistency. No, relational DBs don't have the same performance characteristic as other data systems because they do different things. If you have data that fits a particular style well, then I suggest using that style to manage that data. Let's say I had data that needs to hang around for a little while then disappear into the archives. Let's say you hardly ever do random access on this data because you always work with it serially or in large batches. This is exactly like the recipient d Also consider how much work it is to partition data from flat files versus PostgreSQL tables. Another straw man. I'm sure you can come up with many contrived examples to show one particular operation faster than another. Benchmark writers (bad ones) do it all the time. I'm saying that in normal, real world situations where you are collecting billions of data points and need to actually use the data that a properly designed database running on a good database engine will generally be better than using flat files. You're thinking in the general. Yes, RDBMs do wonderful things in the general cases. However, in very specific circumstances, RDBMS do a whole lot worse. Think of the work involved in sharding an RDBMS instance. You need to properly implement two-phase commit above and beyond the normal work involved. I haven't run into a multi-master replication system that is trivial. When you find one, let me know, because I'm sure there are caveats and corner cases that make things really hard to get right. Compare this to simply distributing flat files to one of many machines. It's a whole lot easier to manage and easier to understand, explain, and implement. You should use the right tool for the job. Sometimes the data doesn't fit the profile of an RDBMs, or the RDBMs overhead makes managing the data more difficult than it needs to be. In those cases, it makes a whole lot of sense to try something else out. The only thing I can think of that might make flat files faster is that flat files are buffered whereas PG guarantees that your information is written to disk before returning Don't forget all the shadow page operations and the index operations, and that a lot of these operations require reading as well as writing remote parts of the disk, so buffering doesn't help avoid every disk seek. Not sure what a shadow page operation is but index operations are only needed if you have to have fast access to read back the data. If it doesn't matter how long it takes to read the data back then don't index it. I have a hard time believing that anyone would want to save billions of data points and not care how fast they can read selected parts back or organize the data though. I don't care how the recipients for the email campaign were indexed. I don't need an index because I don't do random accesses. I simply need the list of people I am going to send the email campaign to, properly filtered and de-duped, of course. This doesn't have to happen within the database. There are wonderful tools like sort and uniq to do this work for me, far faster than an RDBMS can do it. In fact, I don't think you can come up with a faster solution than sort and uniq. Plus the fact that your other DB operations slow down under the load. Not with the database engines that I use. Sure, speed and load are connected whether you use databases or flat files but a proper database will scale up quite well. I know for a fact that sort and uniq are far faster than any RDBMs. The reason why is obvious. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list