Exiting gracefully from ThreadingTCPServer

2010-03-12 Thread Pete Emerson
I'm trying to get threading going for the first time in python, and I'm trying to modify code I found so that I can have the server close the TCP connections and exit gracefully. Two problems: 1) While the KeyboardInterrupt works, if I make more than 0 curls to the server and then quit, I can't ru

Re: Conditional based on whether or not a module is being used

2010-03-06 Thread Pete Emerson
On Mar 6, 2:38 pm, Vinay Sajip wrote: > On Mar 5, 9:29 pm, Pete Emerson wrote: > > > > > I have written my first module called "logger" that logs to syslog via > > the syslog module but also allows forloggingto STDOUT in debug mode > > at multiple levels (

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 6:26 pm, MRAB wrote: > Pete Emerson wrote: > > I've been wrestling with dicts. I hope at the very least what I > > discovered helps someone else out, but I'm interested in hearing from > > more learned python users. > > > I found out that

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 8:24 pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Why would it be? > > If you look up a key in a dict: > > add

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 6:10 pm, Andreas Waldenburger wrote: > On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson > > > > > > wrote: > > [snip] > > >>> data['one'] = {} > > >>> data['one']['two'] = 'three

best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
I've been wrestling with dicts. I hope at the very least what I discovered helps someone else out, but I'm interested in hearing from more learned python users. I found out that adding a two dimensional element without defining first dimension existing doesn't work: >>> data = {} >>> data['one'][

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 1:14 pm, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > >> On 3/5/10, Pete Emerson wrote: > >>> In a module, how do I create a conditional that will do something

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 11:57 am, MRAB wrote: > Pete Emerson wrote: > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > Suppose I have the following: > > > import foo > > import fo

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 12:06 pm, "Martin P. Hellwig" wrote: > On 03/05/10 19:24, Pete Emerson wrote: > > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > > If someone is using foo

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > On 3/5/10, Pete Emerson wrote: >> In a module, how do I create a conditional that will do something >> based on whether or not another module has been loaded? >> >> Suppose I have the following: >> >>

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 11:24 am, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() &g

Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ### foo.py def foo: return 'foo' ### foobar.py def foobar: if foo.

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 10:19 am, "sjdevn...@yahoo.com" wrote: > On Mar 5, 10:53 am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -08

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 7:00 am, Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > And tell me how not using regexp will ensure the /etc/hosts processing > > is correct ? The non regexp solutions provided in this thread did not > > handled what you rightfully pointed out about host list and commented > >

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle wrote: > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I&#x

Re: Evaluate my first python script, please

2010-03-04 Thread Pete Emerson
Great responses, thank you all very much. I read Jonathan Gardner's solution first and investigated sets. It's clearly superior to my first cut. I love the comment about regular expressions. In perl, I've reached for regexes WAY too much. That's a big lesson learned too, and from my point of view

Evaluate my first python script, please

2010-03-04 Thread Pete Emerson
I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is "perlesque" This script parses /etc/hosts for hostnames, and based on terms given on the command line (argv)