Re: setup server from scratch (with or without apache?)
News123, 20.06.2010 13:12: Now I have the opportunity to setup a server from scratch. 90% of the content will be non visual content over https with client AND server certificates. Access privileges will depend on the client certificate. I will only have one IP address and only port 443. 1.) What alternatives would exist compared to apache / mod_python > 5.) What about mod_wsgi vs. mod_python As others have pointed out, mod_wsgi is preferable over mod_python. In any case, you want your code to run on top of WSGI, as it makes it independent of a specific web server environment (i.e. much more future proof). I've read happy comments on nginx as an HTTP/S server for WSGI apps, both for being easy to install and set up, and for being fast, versatile and resource friendly. I'd try that before going for an Apache installation. I'd also second the advice to start with a WSGI setup on top of CGI that's simple to set up, redeploy and test, and then move on to more involved and less agile deployments when you see that you need them. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: setup server from scratch (with or without apache?)
Paul Rubin wrote: > mod_python is pretty dead. It's now totally dead[1]. (Not pining for the fjords, either.) 1: http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html -- http://mail.python.org/mailman/listinfo/python-list
Re: start and kill process by command promt
On Jun 21, 10:41 am, shanti bhushan wrote: > Hi, > I want to invoke local wen server named mogoose, and kill it after > some time by python script. > Then i want to change the argument and invoke it again. > > I am able to do this with below code. > > import subprocess > import time > > def invoke_server1(): > s1ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: > \372\pythonweb\mongoose-2.8.exe >YourOutput.txt"') > print s1ret > > def invoke_server2(): > s2ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: > \372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"') > print s2ret > def invoke_server3(): > s3ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: > \372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"') > print s3ret > > def kill_server(): > killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c > "taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"') > print killret > > kill_server() > time.sleep(5) > invoke_server1() > time.sleep(5) > kill_server() > time.sleep(5) > invoke_server2() > time.sleep(5) > kill_server() > time.sleep(10) > invoke_server3() > time.sleep(5) > kill_server() > > This works fine in python26 ,but when i use this code in one testing > tool, server is invoked 1st time properly.but for second time it says > process already occupied cannot access the process. I am not able to > understand why subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c > "taskkill /F /IM mongoose-2.8.exe is not working second time .Please > guide me in this respect. > > Or please tell me is there any other way,to do same thing with python > script that will start and kill windows process for my requirement. > > Regards > Bhushan i am getting following error message "process cannot acces the file because it is being used by other process" -- http://mail.python.org/mailman/listinfo/python-list
Re: setup server from scratch (with or without apache?)
News123 writes: > 1.) What alternatives would exist compared to apache / mod_python I think you could use stunnel to listen on port 443 and forward it to a local port, where you'd have a python httpd, perhaps using the SimpleHTTPServer module. Stunnel uses OpenSSL which handles client certificates pretty well as far as I can tell. There are various Python openssl bindings that I haven't used and I get they impression that at least some of them are sloppy about certificates at either end. I've never used stunnel but have been wanting to. mod_python is pretty dead. Frankly I've always used apache whenever I've used https for web pages. You could use mod_wsgi (I haven't tried this yet) or again, set it up as a proxy forwarding to a local port for a python httpd to listen to. Or for that matter, you use old-fashioned cgi's. That's what I usually do if there's not a load issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: setup server from scratch (with or without apache?)
I think that apache and mod_python are good enough, but I'm not an expert. but I think that the security aspect for a large part depends on how secure your code is. You can have a very secure server setting, but somewhere a bug in your code that makes it insecure. -- http://mail.python.org/mailman/listinfo/python-list
Re: D-CM; Software Testers
On 21 jun, 05:37, Stephen Hansen wrote: > On 6/19/10 11:52 PM, Kruptein wrote: > > That's better. :) > > I would suggest adding a little more: some bullet points of how they > work together in a way that's new or efficient or what's compelling > about the interaction. And a screenshot or two. > > Either way, I'm now curious enough to actually download it later on. :) > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog:http://meh.ixokai.io/ > > signature.asc > < 1 KWeergevenDownloaden Well in my first release I had a different structure which didn't allow that addons communicate with each other, with this release it is possible and not even that difficult to implement. Examples of the interaction are for example: -Addons can create and join triggers. If addon A updates something,it can say to d-cm "Update that trigger" and all the addons which have joined the trigger will receive an update and can choose weither they do something with it. I use this to sync the file browsers from the ftp-manager and the main file-manager because I hate it when my file-browsers aren't synched up :p So everytime a user changes the directory in one window, it will automaticly also change the directory in an other window if it's registered to the trigger. You can ofcourse disable this if you don't like this An other example would be: -I have a file manager and a text-editor included in d-cm, in the file- manager there is an "Edit" button, if you click on it, the file- manager will first try to connect to deditor(standard included) but if that fails it will use the system default... There are plenty of examples and I hope you understand it a bit :) (My problem is that I can't explain in clear language what it exactly does, which makes it difficult for other people to undersand :s but that is probably because I'm not a native-english speaker and because I'm still young :p -- http://mail.python.org/mailman/listinfo/python-list
start and kill process by command promt
Hi, I want to invoke local wen server named mogoose, and kill it after some time by python script. Then i want to change the argument and invoke it again. I am able to do this with below code. import subprocess import time def invoke_server1(): s1ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: \372\pythonweb\mongoose-2.8.exe >YourOutput.txt"') print s1ret def invoke_server2(): s2ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: \372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"') print s2ret def invoke_server3(): s3ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: \372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"') print s3ret def kill_server(): killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c "taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"') print killret kill_server() time.sleep(5) invoke_server1() time.sleep(5) kill_server() time.sleep(5) invoke_server2() time.sleep(5) kill_server() time.sleep(10) invoke_server3() time.sleep(5) kill_server() This works fine in python26 ,but when i use this code in one testing tool, server is invoked 1st time properly.but for second time it says process already occupied cannot access the process. I am not able to understand why subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c "taskkill /F /IM mongoose-2.8.exe is not working second time .Please guide me in this respect. Or please tell me is there any other way,to do same thing with python script that will start and kill windows process for my requirement. Regards Bhushan -- http://mail.python.org/mailman/listinfo/python-list
tkInter Listbox question
So I'm trying to add a Listbox to my window. I want it to be the width of my window and the height of my window. I'm using the following code ('root' is my toplevel window): gsItems = Listbox(root, width=root.winfo_width(), height=root.winfo_height()) gsItems.pack() While you would think this code would set the height and width of gsItems to the height and width of root, it doesn't. Instead it puts a little tiny listbox in the middle of the form. I've been Googling for almost an hour. Can anyone help me figure this out? Point me in the right direction? Thanks! Anthony -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
Steven D'Aprano writes: > Not that I don't believe you, but that is an extraordinary claim that > would require more evidence than just "Hey, some guy on the Internet > reckons his assembly code can regularly out-perform optimizing C > compilers" before I will change my opinion *wink* It is really true, and it's the opposite claim that would be extraordinary. That's why compilers like gcc include pragmas for assembler intrinsics for when you want include some inline assembly code in your C program. gzip uses it for example, as does Gnu MP and OpenSSL. That's why gmpy is several times faster at multi-precision arithmetic than Python's built-in longs, that are implemented in C. Another reason for wanting dynamic assembly code is so you can embed staged programming in your python code. Think of how slow python regexps are. Now imagine a regexp package that compiles your regexp directly to assembly code instead of to some silly interpreted state machine. Parser generators like pyparsing could similarly generate asm code directly. -- http://mail.python.org/mailman/listinfo/python-list
OT! Python vs... Objective-C!
This is sort of OT. Okay, I consider it completely OT, because I hate these threads. But this isn't that sort of thread. I'm not going to tell you how Python is perfect -- it is, obviously. I'm not going to tell you how Objective-C is horrible -- its not, really. I'm not interested in debating the merits of one language over the other: every language has its place. I'm just learning Objective-C on my spare time, and am having these entirely disturbing feelings of familiarity, where strange swirling thoughts enter my head that sound oddly like, "This feels sorta Pythony, how oddly pleasant." With, of course, a bad smell from the syntax at the same time. So this is more just a quick ramble to a group of folk I respect: any of you used Objective-C in any capacity beyond looking at it and going 'OMG, shoot whoever did that'? Am I completely off my rocker? I tumbled-ish of it on mine tumblelogblogwhateveryoucallit: """I’m just barely starting to learn Objective-C; I’ve only had the first few sessions from iTunes U of the iPhone app development class that Stanford publishes, and a few tutorials (and over the years, a few aborted attempts to vaguely learn that never went anywhere). But this time, I have an idea of something to develop in some spare time over the next, oh, year. And so, I’m learning. Its interesting. The most startling thing about it is how *Pythonic* it feels. I can’t quite put my finger on exactly why: its not the syntax, surely. Somehow the language has taken something perfectly repulsive on its own (Hi, C, I’m looking at you!) and turned it into a shrine to perversity. And yet, after a day or two in it, it doesn’t really bother me so much anymore. Oh, I still can’t ever remember to prepend my Objective-C strings with a @, but XCode is nice about erroring out properly. And I never remember to end my NSDictionary and NSArray initializers with a nil, but XCode is nice about that too (You left off the sentinel again, you idiot, it says to me. Minus idiot, but I swear I hear that tone of its voice. Text. Whatever). I don’t know. There’s something about it. Perhaps its its dynamic nature. Perhaps its the rich base library that seems to have a tool for most things I want to do. Perhaps its because it is the only C-derived language I’ve ever gone near which didn’t seem intent on making me go out of my way to program a hundred lines when only ten (okay, maybe 20— it isn’t /that/ Pythonic) will do. Also strange: its as force-OOP-down-your-throat as Java, and yet I don’t feel a gag reflex. Can’t explain it.""" Anyways. Just curious. Ya'll are all the Python-people I know. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ P.S. And no, I'm actually also not pimping my baby-blog-thing that no one is of yet following: that's why I pasted the contents here, so no one needs to go poke it. signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: plac 0.5 is out!
On Jun 20, 8:26 pm, Andre Alexander Bell wrote: > On 06/20/2010 11:22 AM, Michele Simionato wrote: > > > A few weeks ago I presented on this list my most recent effort, plac. > > http://micheles.googlecode.com/hg/plac/doc/plac_ext.html > > But this one is broken. :( Aagh! The good one is http://micheles.googlecode.com/hg/plac/doc/plac_adv.html. Luckily the one I posted on PyPI is correct. > > Maybe one could even extend to subcommands and so on. > Maybe this is already possible but just not covered by the first link > I've read by now. Indeed this is already possible and covered in the advanced document. See the section containers of commands: http://micheles.googlecode.com/hg/plac/doc/plac_adv.html#containers-of-commands -- http://mail.python.org/mailman/listinfo/python-list
Re: D-CM; Software Testers
On 6/19/10 11:52 PM, Kruptein wrote: >> What does it *do*? > You're perfectly right about not doing that! > > So the program is kind of a platform to which several addons can be > added. > I've made some base addons that work well together. > These addons are tools that you in my opinion need to develop certain > programs/websites > for example I've made a file-manager, a text-editor, ftp-manager, sql- > support > > These are the only ones available for now, but I'm going to offer more > in the future and maybe there will come one day a third party addon :) > > I hope this already cleared it up a bit. > > So I've bundles all those programs in one large program that makes it > easy to interact between eachother and make it easy for the user to > change it to his taste (because he can add or delete other addons) That's better. :) I would suggest adding a little more: some bullet points of how they work together in a way that's new or efficient or what's compelling about the interaction. And a screenshot or two. Either way, I'm now curious enough to actually download it later on. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On Sun, 20 Jun 2010 22:45:14 +0100, Rhodri James wrote: > Mixing Python and assembler is a bizarre thing to want to do in general, > but... > > On Sun, 20 Jun 2010 01:52:15 +0100, Steven D'Aprano > wrote: > >> (3) Modern C compilers can produce better (faster, more efficient) >> machine code than the best assembly code written by hand. > > No. Modern C compilers often produce very good machine code, but the > best hand-written assembly code will be better. I can usually write > *very* marginally better code than GCC achieves at work, though 99% of > the time I don't because it would be a maintenance nightmare. Not that I don't believe you, but that is an extraordinary claim that would require more evidence than just "Hey, some guy on the Internet reckons his assembly code can regularly out-perform optimizing C compilers" before I will change my opinion *wink* Of course, there almost certainly are special cases where the state of the art for optimizing C compilers isn't as good as a clever human, e.g. if you're writing for hardware where no optimizing compiler exists at all, or some tiny CPU without all the pipelines and predictive branching crap^W stuff they do these days. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On Sun, 20 Jun 2010 18:21:43 -0400, Dave Angel wrote: > Something's intrinsically wrong with the argument made in this thread > against generating assembly code. That's exactly what happens every > time you write code in C. I don't know whether C compilers generate assembly mnemonics or direct machine code, but the distinction for this argument is irrelevant. The argument in this thread is that it's not worth the *human coder* writing assembly, not that no assembly code is involved in the process anywhere. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
duncan smith wrote: southof40 wrote: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car object from the original list appears 7 times, each bike 3 times and each truck once. I then pick at random from that list. This works but seems very clunky to me. Can anyone suggest a better data structure which would support the 'weighted randomness' I'm after ? I'm not fixed on the idea of using a list - could be a dictionary, tree whatever . Thanks in advance. Try googling for "alias table". Efficient if you're selecting many random objects from the same mass function. Better than binary search on the cumulative mass function in big-O terms (but maybe not in practical terms for reasonable sized problems). Neither approach is as efficient as the one you outlined, but the required list size might be an issue for some sets of probabilities. Duncan BTW, the alias table approach is basically a means of getting round the problem of needing large lists. Assuming your probabilities should be 0.7, 0.2 and 0.1 you could construct a list of 3 objects. The first would be 100% car, the second would be 60% bike and 40% car, the third would be 30% truck and 70% car. Choose an object at random, then the vehicle type according to the mass function associated with the object. The alias table approach only requires the generation of a single uniform random variate and a single comparison (once you've constructed it). Duncan -- http://mail.python.org/mailman/listinfo/python-list
Re: C interpreter in Lisp/scheme/python
On Jun 13, 7:07 pm, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega Maybe instead of full C, you should try something simplified, like Tiny-C (http://primepuzzle.com/tc/) or Arena, or maybe even Pike (some minimal variant thereof). -- http://mail.python.org/mailman/listinfo/python-list
PyCon Australia 2010 Registration Closes Tomorrow
Hi all, PyCon Australia 2010, to be held at the Sydney Masonic Center over the weekend of June 26 and 27, is only days away. REGISTRATION WILL CLOSE TOMORROW (JUNE 22) AT 1PM! You have until 1PM tomorrow to register and pay. Register here: http://pycon-au.org/reg We will NOT be accepting registrations at the door. We will NOT be accepting money at the door. If you're registered and haven't paid by tomorrow you will not have a seat at the conference dinner. Richard Jones PyCon Australia 2010 -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in parser?
On 6/20/2010 7:22 PM, Neal Becker wrote: Isn't this a bug? print \" SyntaxError: unexpected character after line continuation character This is definitely a syntax error. The message is about as good an interpretation of nonsensical situation as one could expect from an automaton. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in parser?
On 2010-06-20, Neal Becker wrote: > Isn't this a bug? > > print \" > > SyntaxError: unexpected character after line continuation character No. http://www.google.com/search?q=python+line+continuation+character First hit: http://docs.python.org/reference/lexical_analysis.html Section 2.1.5 Two or more physical lines may be joined into logical lines using backslash characters (\), as follows: when a physical line ends in a backslash that is not part of a string literal or comment, [...] [...] A backslash is illegal elsewhere on a line outside a string literal. Anything else we can look up for you? -- Grant -- http://mail.python.org/mailman/listinfo/python-list
bug in parser?
Isn't this a bug? print \" SyntaxError: unexpected character after line continuation character -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
DivX wrote: On 20 lip, 12:46, Steven D'Aprano wrote: On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: On 20 lip, 02:52, Steven D'Aprano wrote: [...] I think that mixing assembly and python is a gimmick of very little practical significance. If you really need the extra performance, check out PyPy, Cython, Pyrex and Psyco. -- Steven I can agree with you about most of the arguments, but why he continues to developing it. What he sees and we do not see? Why ask us? You should ask him. -- Steven Be sure I will ask him, but before, I wanted to know your opinions about it. Hear arguments on both sides... Something's intrinsically wrong with the argument made in this thread against generating assembly code. That's exactly what happens every time you write code in C. The real question is whether the code generator your friend is writing is better than the ones written by dozens of C gurus over the years, and better tuned to the requirements of his particular processor. Naturally, better can be measured in several ways. For example, I have a processor for which no C compiler is available. So if I were to want optimized assembler, I might need to write one myself, or use the language for which such a code generator has been written. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: catching my own exception
Dana Sun, 20 Jun 2010 10:53:08 +0200, Peter Otten <__pete...@web.de> kaze: > Now in your case village.py is first run as the main script and then [...] > In the account module you indirectly raise village.ExceptionWithLongName and > in __main__ you try to catch __main__.ExceptionWithLongName. Phew. I get it now. You're my hero :-D I had to read it twice, but I got it. Thanks a bunch! -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
Mixing Python and assembler is a bizarre thing to want to do in general, but... On Sun, 20 Jun 2010 01:52:15 +0100, Steven D'Aprano wrote: (3) Modern C compilers can produce better (faster, more efficient) machine code than the best assembly code written by hand. No. Modern C compilers often produce very good machine code, but the best hand-written assembly code will be better. I can usually write *very* marginally better code than GCC achieves at work, though 99% of the time I don't because it would be a maintenance nightmare. I wrote more at a previous job, but then the processor had instructions that could not be expressed usefully in C, and having an FFT routine that ran like greased lightning was important. I would agree, though, that the only reason I can think of for wanting to mix Python and assembler is if you are grobbling about with hardware, and if you are doing that, Python wasn't the best place to start from. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: If Not CGI...
On 6/19/2010 11:18 AM, Stephen Hansen wrote: FastCGI is a different kind of approach to the problem; it launches Python alongside Apache, and that Python stays alive forever. It just redirects requests to said process when they come in. I know very little about this model, but believe its meant to sort of mimic a CGI environment so you can sort of migrate to it easier, but I'm not entirely sure. So I can't comment on this directly, but http://docs.python.org/howto/webservers.html seems interesting (Though it speaks of ALL of these options, so is a good read anyways) But the thing is: a WSGI web application looks and is shaped nothing like a CGI application. They're awesome. Btu different. Writing a WSGI app from scratch without a framework is possible, but it seems like a terribly painful thing to go about doing. It's not that difficult. WSGI works as an interface to FCGI in Apache. If you set up programs that way, they'll run either as CGI programs (useful for debug) or WSGI programs. WSGI/FCGI programs look a lot like CGI programs. The main difference is that your transaction program is called as a subroutine, and has to be reusable. Avoid global state and that's easy. When you're called, you get various parameters, and at the end, you return the HTTP content you want sent over the wire. WSGI/FCGI scales well. The FCGI server will fire off extra copies of the application as the load goes up, and will ask unneeded copies to exit when the load goes down. If an FCGI program crashes, the server just restarts a fresh copy. So it's a robust mechanism. Below is "Hello World" for FCGI/WSGI, without a "framework". The biggest headache is getting the "mod_fcgi" module into Apache (or running "lighthttpd"), getting it configured properly, and getting it to find your FCGI program. (Note: if you put an FCGI program in a directory that Apache considers valid for CGI, Apache will run the program with CGI, not FCGI. This works, but at CGI speeds, with a program reload every time.) A FCGI/WSGI module for Python is here: http://svn.saddi.com/py-lib/trunk/fcgi.py John Nagle #!/usr/local/bin/python2.6 import fcgi # # "Hello World" for FCGI/WSGI # def simpleApp(environ, start_response): status = '200 OK' headers = [('Content-type','text/plain')] start_response(status, headers) return ['Hello world from simple_application!\n'] # # Main FCGI program # fcgi.WSGIServer(simpleApp).run() -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb and bits
On 6/19/2010 5:24 PM, voidnothings wrote: On Jun 13, 5:52 am, Dafydd Hughes wrote: Hi there This is my first post to the list - please forgive me if this has been addressed elsewhere. I'm running MySQL 32-bit in Snow Leopard, and had MySQLdb working well. I switched to 64-bit, rebuilt MySQLdb, and again it worked fine within Python, but had to switch back to 32 bit - I'm using a wrapper for Python within Pure Data, and it forces Python to 32-bit. MySQLdb must match the Python in which it is installed, but the MySQL server doesn't have to be of the same architecture as the client. After all, the server and client don't even have to be on the same machine. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: plac 0.5 is out!
On 06/20/2010 11:22 AM, Michele Simionato wrote: > A few weeks ago I presented on this list my most recent effort, plac. > Now there is a *huge* new release: > the size of plac and of its documentation doubled. > [...] > > http://micheles.googlecode.com/hg/plac/doc/plac.html I've read this one... > http://micheles.googlecode.com/hg/plac/doc/plac_ext.html But this one is broken. :( How about hierarchical composition. I've seen several scripts following the format basescript command [options] subcommands [other optiones] ... It would be great if one can compose functions to form the commands. Instead of def main(command, opt1, opt2): """...""" if command == 'cmd1': ... elif command == 'cmd2': ... if __name__=='__main__': import plac plac.call(main) one could then write def cmd1(opt1): """...""" ... def cmd2(opt2): """...""" ... if __name__=='__main__': import plac plac.call(plac.commands(cmd1, cmd2)) This should then produce usage info like this $ basescript --help usage: basescript [-h] command ... commands: cmd1 cmd2 $ basescript cmd1 --help usage basescript cmd1 [cmd1 specific options] ... $ basescript cmd2 --help usage basescript cmd2 [cmd2 specific options] ... Maybe one could even extend to subcommands and so on. Maybe this is already possible but just not covered by the first link I've read by now. Anyway, I very much like this package and it seems like I have a new friend at my disposal. Thanks and best regards Andre -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On 6/20/2010 12:41 PM, Lie Ryan wrote: On 06/20/10 20:57, DivX wrote: On 20 lip, 12:46, Steven D'Aprano wrote: On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: On 20 lip, 02:52, Steven D'Aprano wrote: [...] I think that mixing assembly and python is a gimmick of very little practical significance. If you really need the extra performance, check out PyPy, Cython, Pyrex and Psyco. Of course, Psyco mixes assembly and python, which is why it was originally (not sure now) limited to x86 machines. It does do generically, in small chunks, behind the scenes, so the rest of us can get the benefit without expert assembly knowledge. I can agree with you about most of the arguments, but why he continues to developing it. I presume because he can and enjoys it. That sort of tinkering is what led to Psyco. Ever heard of JIT? Psyco is one form of JIT. You might enjoy reading about how it works. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On 06/20/10 20:57, DivX wrote: > On 20 lip, 12:46, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: >>> On 20 lip, 02:52, Steven D'Aprano >> cybersource.com.au> wrote: >> [...] I think that mixing assembly and python is a gimmick of very little practical significance. If you really need the extra performance, check out PyPy, Cython, Pyrex and Psyco. >> -- Steven >> >>> I can agree with you about most of the arguments, but why he continues >>> to developing it. What he sees and we do not see? >> >> Why ask us? You should ask him. >> >> -- >> Steven > > Be sure I will ask him, but before, I wanted to know your opinions > about it. Hear arguments on both sides... Ever heard of JIT? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
southof40 wrote: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car object from the original list appears 7 times, each bike 3 times and each truck once. I then pick at random from that list. This works but seems very clunky to me. Can anyone suggest a better data structure which would support the 'weighted randomness' I'm after ? I'm not fixed on the idea of using a list - could be a dictionary, tree whatever . Thanks in advance. Try googling for "alias table". Efficient if you're selecting many random objects from the same mass function. Better than binary search on the cumulative mass function in big-O terms (but maybe not in practical terms for reasonable sized problems). Neither approach is as efficient as the one you outlined, but the required list size might be an issue for some sets of probabilities. Duncan -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyxser-1.4.4r --- Python Object to XML serializer/deserializer
Hello Python Community. I'm pleased to announce pyxser-1.4.4r, a python extension which contains functions to serialize and deserialize Python Objects into XML. It is a model based serializer. Here is the ChangeLog entry for this release: ---8<--- 1.4.4r (2010.02.10): Daniel Molina Wegener * src/include/pyxser_collections.h - added set handling function prototypes. Added support for unicode key names, which are converted to the user settings encoding (ie utf-8) inside the XML output. * src/pyxser_serializer.c - removed memory leak. Addded support for unicode object names in dictionary/list types. * src/pyxser_collections.c - added set handling function prototypes. added name property handling algorithm, so non string name properties are not serialized. I shall extend it to other modules. * src/pyxser_tools.c - added set handling prototypes and set type checking function. * test-utf8-leak.py - added serialization of SQL Alchemy objects, so we can test more complex Python objects serialization. * test-utf8-sqlalchemy.py - added sql alchemy object serialization test. * src/pyxser_serializer.c - reduced serialization algorithms, replacing deep nested if statements by flatten ones. * src/pyxser_collections.c - reduced serialization algorithms replacing deep nested if statements by flatten ones. * src/pyxser_typem.c - reduced serialization algorithms, replacing deep nested if statements by flatten ones. Thanks to pyxser users for their feedback. ---8<--- This release contains some bug fixes, mainly related to type checking and type handling. I hope this small extension will help you on your programming tasks. The project is hosted at: http://sourceforge.net/projects/pyxser/ The web page for the project is located at: http://coder.cl/products/pyxser/ PyPi entry is: http://pypi.python.org/pypi/pyxser/1.4.4r For a sample article on how to integrate pyxser with ZSI WebServices: http://coder.cl/2009/10/18/pyxser-and-zsi-webservices/ Thanks and best regards, -- Daniel Molina Wegener Software Architect, System Programmer & Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
southof40 writes: > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. You can do it with one pass through the list using a well-known online algorithm (I don't remember what it's called). Untested code: import random tprob = 0 # total probability for x in vehicle_list: tprob += x.prob # x.prob is 0.7, 0.3, 0.1, or whatever if random.uniform(0, tprob) <= x.prob: selected = x To see why this works, use mathematical induction. It's obviously right if there is just one object in the list: tprob and x.prob are the same thing, so the random number is always in range and that object gets chosen. And suppose it works correctly for n objects. Then it also works correctly for n+1 objects, since the (n+1)th object gets chosen with the correct probility p, and with probability (1-p) one of the earlier n objects is chosen, each with correct probability by the induction hypothesis. So by induction, it does the right thing for all n. This uses one random number per item in the list, but Python's RNG is pretty fast. You can alternatively build a probability map or histogram from the list (using more storage) and then select from it witn a single call to the RNG. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
On Sun, 20 Jun 2010 11:27:30 +, Mel wrote: > southof40 wrote: > >> I have list of of N Vehicle objects - the only possible vehicles are >> cars, bikes, trucks. >> >> I want to select an object from the list with a probability of : cars >> 0.7, bikes 0.3, trucks 0.1. >> >> I've currently implemented this by creating another list in which each >> car object from the original list appears 7 times, each bike 3 times >> and each truck once. I then pick at random from that list. > > This seems about right. It's like a lottery where the more likely > winners have more tickets, but all tickets are the same. Pick one to > pick the winner. It could be expensive to calculate though. Suppose the probabilities were: 0.608729 0.235012 0.156259 > There's a very expensive, but flexible technique that effectively gives > some tickets a better chance than others. You have to examine each > ticket individually, so this algorithm burns random numbers like > kindling: > > > > import random > > #=== > def weighted_choice (candidates, weight): > chosen = None > total = 0 > for c in candidates: > w = weight (c) > total += w > if random.randint (0, total-1) < w: > chosen = c > return chosen > #=== Nice! But instead of randint(0, total-1), you can use randrange(0, total). This only requires N random numbers (for N candidates), which isn't really that excessive, but we can do better, and support non-integer weights as well. def weighted_choice(candidates, weights): """Choose between a list of candidates with a list of weights.""" cumulative_weights = [] running_total = 0 for w in weights: running_total += w cumulative_weights.append(running_total) x = random.uniform(0, running_total) for item, cw in zip(candidates, cumulative_weights): if x <= cw: return item This is O(N) on the number of candidates, and requires one call to random no matter what N is. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
On Sun, 20 Jun 2010 03:19:55 -0700, southof40 wrote: > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. > > I've currently implemented this by creating another list in which each > car object from the original list appears 7 times, each bike 3 times > and each truck once. I then pick at random from that list. > > This works but seems very clunky to me. Can anyone suggest a better > data structure which would support the 'weighted randomness' I'm > after ? Calculate the cumulative probabilities and perform a binary search (e.g. using the bisect module). -- http://mail.python.org/mailman/listinfo/python-list
Re: daemonizing after binding to port
On Sun, 20 Jun 2010 20:00:14 +1000, Ben Finney wrote: >> I'm starting a SocketServer.TCPServer in my program, but since I want >> to report problems to script starting the program, I want to go daemon >> *after* TCPServer has done binding to port. >> >> Is this likely to cause problems? I mean, my client works when I do >> the above, that is, it connects to the server. But I'm not sure if >> above is the Right Thing(tm). > > There is more to becoming a well-behaved daeon process than merely > detaching the process. For details, see PEP 3143 “Standard daemon > process library” http://www.python.org/dev/peps/pep-3143/>. The OP's code does most of what the Linux/BSD daemon() call does, except that it doesn't close or replace inherited descriptors. Many of the recommendations in PEP 3143 are "optional extras". The main "requirement" which cannot reasonably be encapsulated into a daemon() procedure is to avoid subsequently acquiring a controlling terminal (by passing O_NOCTTY to all open() calls). Even if Python was to integrate this into open() (and similar), there's no guarantee that libraries used via extension modules or ctypes will do likewise. -- http://mail.python.org/mailman/listinfo/python-list
question about multiprocessing
first sorry for my poor english. Is there any problem in the follow code? thanks! from multiprocessing.managers import BaseManager import Queue class CrawlerManager(BaseManager): pass downloader_queue = Queue.Queue() downloader_queue.put('hello') CrawlerManager.register('get_downloader_queue', callable=lambda: downloader_queue) mgr = CrawlerManager() mgr.start() q = mgr.get_downloader_queue() error: pickle.PicklingError: Can't pickle at 0x00C02F70>: it's not found as __parents_main__. Traceback (most recent call last): print q.get() -- View this message in context: http://old.nabble.com/question-about-multiprocessing-tp28940614p28940614.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: plac 0.5 is out!
On Jun 20, 12:02 pm, Andre Alexander Bell wrote: > > How about adding some support for internationalization of the generated > usage output? The usage message of plac is actually generated by the underlying argparse library. argparse use gettext internally, so I would say the support is already there. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
southof40 wrote: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. > > I've currently implemented this by creating another list in which each > car object from the original list appears 7 times, each bike 3 times > and each truck once. I then pick at random from that list. This seems about right. It's like a lottery where the more likely winners have more tickets, but all tickets are the same. Pick one to pick the winner. There's a very expensive, but flexible technique that effectively gives some tickets a better chance than others. You have to examine each ticket individually, so this algorithm burns random numbers like kindling: import random #=== def weighted_choice (candidates, weight): chosen = None total = 0 for c in candidates: w = weight (c) total += w if random.randint (0, total-1) < w: chosen = c return chosen #=== def test_weight (c): return {'c':7, 'b':3, 't':1}[c] def item_count (s, target): return sum (1 for x in s if x==target) test_candidates = 'c'*100 + 'b'*100 + 't'*100 for i in xrange (10): test = [weighted_choice (test_candidates, test_weight) for k in xrange (100)] for x in 'cbt': print x, item_count (test, x), '\t', print Mel. -- http://mail.python.org/mailman/listinfo/python-list
setup server from scratch (with or without apache?)
Hi, So far I never really had to ask this question and this is also, why I am stil a little shaky on this topic: So far the typical LAMP server existed already and contained already a lot of existing PHP web applications, which I couldn't remove. Therefore I just used mod_python to implement some minor functionality next to it. Now I have the opportunity to setup a server from scratch. 90% of the content will be non visual content over https with client AND server certificates. Access privileges will depend on the client certificate. I will only have one IP address and only port 443. 1.) What alternatives would exist compared to apache / mod_python 2.) What disadvantage would I have using apache and mod_python compared to other solutions 3.) What's the stability / security aspect of other solutions, especially concerning client / server certificates 4.) How could I prepare for the case, that customer might lateron require PHP? (not very probably, but who knows. 5.) What about mod_wsgi vs. mod_python Thanks a lot for suggestions / ideas. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On 20 lip, 12:46, Steven D'Aprano wrote: > On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: > > On 20 lip, 02:52, Steven D'Aprano > cybersource.com.au> wrote: > [...] > >> I think that mixing assembly and python is a gimmick of very little > >> practical significance. If you really need the extra performance, check > >> out PyPy, Cython, Pyrex and Psyco. > > >> -- > >> Steven > > > I can agree with you about most of the arguments, but why he continues > > to developing it. What he sees and we do not see? > > Why ask us? You should ask him. > > -- > Steven Be sure I will ask him, but before, I wanted to know your opinions about it. Hear arguments on both sides... -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
On 20Jun2010 12:44, Stefan Behnel wrote: | southof40, 20.06.2010 12:19: | >I have list of of N Vehicle objects - the only possible vehicles are | >cars, bikes, trucks. | > | >I want to select an object from the list with a probability of : cars | >0.7, bikes 0.3, trucks 0.1. | > | >I've currently implemented this by creating another list in which each | >car object from the original list appears 7 times, each bike 3 times | >and each truck once. I then pick at random from that list. | > | >This works but seems very clunky to me. | | Why? It's a very simple, generic, easy to understand and fast | solution to the problem. Only 3 out of 4, if you want to be precise in your selections. Supposing he wants probabilities 0.7432, 0.3765, 0.1087654 ? The required list needs to be Very Long to achieve an accurate representation, and thus Very Slow to construct/populate. A faster approach is to make a list represention the sum of the proportions as one counts along the choices, thus 0.7, 1.0, 1.1 in the example given (0.7, 0.7+0.3, 0.7+0.3+0.1). Then choose a value in the range 0.0 to the total (1.1) using the pseudo-random function of your choice, such as that in the random module. Then binary search the list for the matching item. The list scales linearly as the number of choices, not exponentially with the precision of the proportions. The search is logarithmic with the number of choices. Beyond a very small number of choices the former will dominate. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ ... you could spend *all day* customizing the title bar. Believe me. I speak from experience. - Matt Welsh -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
southof40 wrote in news:da3cc892-b6dd-4b37-a6e6- b606ef967...@t26g2000prt.googlegroups.com in gmane.comp.python.general: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. Aside, all your probabilities add up to 1.1, they should add up to 1. > I've currently implemented this by creating another list in which each > car object from the original list appears 7 times, each bike 3 times > and each truck once. I then pick at random from that list. Aside, so 7 / 11 bikes, 3 / 11 cars and 1 / 11 trucks, are your actual probabilities. But to answer your question, you could create 3 list, and then pick the list you draw from based on a random number then pick the item from the list based on another random number: r = ( random() * 11 ) if r < 1: picklist = truck_list elif r < 4: picklist = bike_list else: picklist = car_list # now pick the final item from pick list. Rob. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
On Sun, 20 Jun 2010 03:19:55 -0700, southof40 wrote: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. That adds to a probability of 1.1, which is impossible. I'm going to assume that bikes is a typo and should be 0.2. cars = [car1, car2] bikes = [bike1, bike2, bike3, bike4, bike5, bike6] trucks = [truck1, truck2, truck3, truck4] x = random.random() if x < 0.7: return random.choice(cars) elif x < 0.9: return random.choice(bikes) else: return random.choice(trucks) But surely this is not physically realistic? The probability of selecting a car would normally depend on the number of cars, and not be set before hand. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On Sun, 20 Jun 2010 03:19:48 -0700, DivX wrote: > On 20 lip, 02:52, Steven D'Aprano cybersource.com.au> wrote: [...] >> I think that mixing assembly and python is a gimmick of very little >> practical significance. If you really need the extra performance, check >> out PyPy, Cython, Pyrex and Psyco. >> >> -- >> Steven > > I can agree with you about most of the arguments, but why he continues > to developing it. What he sees and we do not see? Why ask us? You should ask him. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Pick items from list with probability based upon property of list member ?
southof40, 20.06.2010 12:19: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car object from the original list appears 7 times, each bike 3 times and each truck once. I then pick at random from that list. This works but seems very clunky to me. Why? It's a very simple, generic, easy to understand and fast solution to the problem. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Pick items from list with probability based upon property of list member ?
I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car object from the original list appears 7 times, each bike 3 times and each truck once. I then pick at random from that list. This works but seems very clunky to me. Can anyone suggest a better data structure which would support the 'weighted randomness' I'm after ? I'm not fixed on the idea of using a list - could be a dictionary, tree whatever . Thanks in advance. R. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this make sence? Dynamic assembler for python
On 20 lip, 02:52, Steven D'Aprano wrote: > On Sat, 19 Jun 2010 13:36:57 -0700, DivX wrote: > > On 19 lip, 21:18, geremy condra wrote: > >> On Sat, Jun 19, 2010 at 11:53 AM, DivX wrote: > >> > I found on the forum some discussion about crypting text and one guy > >> > did make assembly implementation of crypting algorithm. He > >> > dynamically generates mashine code and call that from python. Here > >> > are impressive > >> > resultshttp://www.daniweb.com/code/snippet216632-5.html > > >> > Is this better approach then writing extensions in c? > > >> No, xor cipher is not suitable for general purpose encryption, and what > >> do you need the speed for? xor is almost certainly not going to be the > >> bottleneck in your application. > > >> Geremy Condra > > > Just asking if this approach is good for example quicksort algoriths or > > some kind of sorting algorithms, or simulations but the point is of > > mixing python and assembler? > > Ask yourself, why aren't programs written in assembly if it's so good? > > (1) It's platform dependent. Do you really need a separate program for > every single hardware platform you want to run Quicksort on? > > (2) Writing assembler is hard, really hard. And even harder to debug. > > (3) Modern C compilers can produce better (faster, more efficient) > machine code than the best assembly code written by hand. > > Honestly, this question has been resolved twenty years ago -- thirty > years ago, maybe there was still a good point in writing general purpose > code in assembly, but now? It's just showing off. Unless you're writing > hardware specific code (e.g. device drivers) it is pointless, in my > opinion. > > I think that mixing assembly and python is a gimmick of very little > practical significance. If you really need the extra performance, check > out PyPy, Cython, Pyrex and Psyco. > > -- > Steven I can agree with you about most of the arguments, but why he continues to developing it. What he sees and we do not see? If you're interested I found a link http://www.tahir007.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: daemonizing after binding to port
mk writes: > I'm starting a SocketServer.TCPServer in my program, but since I want > to report problems to script starting the program, I want to go daemon > *after* TCPServer has done binding to port. > > Is this likely to cause problems? I mean, my client works when I do > the above, that is, it connects to the server. But I'm not sure if > above is the Right Thing(tm). There is more to becoming a well-behaved daeon process than merely detaching the process. For details, see PEP 3143 “Standard daemon process library” http://www.python.org/dev/peps/pep-3143/>. -- \ “Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.” —George Bernard Shaw | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: plac 0.5 is out!
On 06/20/2010 11:22 AM, Michele Simionato wrote: > A few weeks ago I presented on this list my most recent effort, plac. > Now there is a *huge* new release: > the size of plac and of its documentation doubled. How about adding some support for internationalization of the generated usage output? Andre -- http://mail.python.org/mailman/listinfo/python-list
plac 0.5 is out!
A few weeks ago I presented on this list my most recent effort, plac. Now there is a *huge* new release: the size of plac and of its documentation doubled. Now plac is much more than a simple command-line arguments parser: it is also a generic tool to write command languages, similar to the cmd module in the standard library, only better. In particular plac supports a doctests-like functionality for each language you define for it, as well as a plac runner to run your scripts and tests. You define plac commands from Python functions: plac will build a parser from the function signature and interpret the command line accordingly. The documentation contains a lot of simple and not so simple examples: http://micheles.googlecode.com/hg/plac/doc/plac.html http://micheles.googlecode.com/hg/plac/doc/plac_ext.html Plac works in all versions of Python starting from Python 2.3 up to Python 3.1, but the new features require Python 2.5. You can download it from PyPI ($ easy_install -U plac): http://pypi.python.org/pypi/plac Enjoy! Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: catching my own exception
Nikola Skoric wrote: > Dana Fri, 18 Jun 2010 20:01:45 +0200, > Peter Otten <__pete...@web.de> kaze: >> Solution: move your startup code into a separate file and have it import >> the village module. > > Excellent, thanks! Everything works now, but I still don't quite get what > the problem is... > >> You are importing your main script elswhere. Your code then >> effectively becomes >> >> try: >> # in another module >> raise village.SomethingBuiltError >> except __main__.SomethingBeingBuiltError: >>print "caught" >> >> i. e. you get two versions of every class that are built from the same >> code but not (recognized as) identical. > > What I don't get is: what do you mean I'm importing my main script > elsewhere by runing "python village.py"? SomethingBuiltError is > defined in the same script that I'm runing, I didn't import it, did I? > If you could please clear it up for me... or point me to relevant > literature, that's also cool, I couldn't find this thing explained > anywhere. In Python, if you write class A: pass that is executable code just like an if-statement or a for-loop rather than a declaration, and this code creates a new class every time it is run. That's why >>> items = [] >>> for i in range(5): ... class A: pass ... items.append(A) ... >>> issubclass(A, A) True >>> issubclass(items[0], items[1]) False creates 5 distinct classes. The same would go for modules if it weren't for the sys.modules cache: >>> open("tmp.py", "w").write("print 'importing', __name__\n") >>> import tmp importing tmp >>> import tmp # module is looked up in cache, code not run If we clear the cache manually, the code in the module will be executed again: >>> import sys >>> del sys.modules["tmp"] >>> import tmp importing tmp Now in your case village.py is first run as the main script and then imported from within account.py -- but the main script is put into the cache under the key "__main__" regardless of its actual name. Using our simple example: $ python -i tmp.py importing __main__ >>> import tmp importing tmp So you end up with a __main__ module and a village module that contain functions and classes built from the same code but with distinct identities. In the account module you indirectly raise village.ExceptionWithLongName and in __main__ you try to catch __main__.ExceptionWithLongName. Peter -- http://mail.python.org/mailman/listinfo/python-list