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

2010-03-16 Thread Aahz
In article <42062deb-785a-4955-9ce0-d9fb7a264...@j27g2000yqn.googlegroups.com>, Vinay Sajip wrote: > >I'm reviewing the documentation at the moment, as it happens, and it >still seems hard to be able to put together a structure which is good >for everyone. A full treatment, it seems to me, would

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

2010-03-16 Thread Aahz
In article , Pete Emerson wrote: > >Excellent, this is what I finally discovered, although I was looking >for 'foo' in sys.modules.keys(), which apparently isn't necessary. Actually, `foo in sys.modules.keys()` is double-slow, because first the dict must be scanned to create a list, and then the

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

2010-03-09 Thread Vinay Sajip
On Mar 6, 11:13 pm, Pete Emerson wrote: > > 1) In debug mode, send what would have gone to syslog to STDOUT or > STDERR > 2) In non-debug mode, use /dev/log or localhost:514 depending on what > is set > 3) Allow for multiple levels ofloggingbeyond INFO, WARNING, CRIT ... > essentially allow multip

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

2010-03-09 Thread Vinay Sajip
On Mar 7, 12:34 pm, Steve Holden wrote: > My own impression of theloggingmodule, formed from trying to use its > documentation in the past, is that it's somewhat unapproachable, and > difficult to use for simple purposes. > > I am happy to say that now I see the current (3.1) documentation it has

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

2010-03-08 Thread Jean-Michel Pichavant
Pete Emerson wrote: 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 bas

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

2010-03-07 Thread Steve Holden
Vinay Sajip wrote: [...] > Well, the logging package is available in Python and ready for use and > pretty much battle tested, so why not use that? Are you planning to > use third-party libraries in your Python work, or write everything > yourself? If you are planning to use third party libraries,

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 (to increase verbosity depending on one's

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

2010-03-06 Thread Vinay Sajip
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 (to increase verbosity depending on one's need), or > both. I've looked at theloggingmodule a

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

2010-03-05 Thread Terry Reedy
On 3/5/2010 4:29 PM, Pete Emerson wrote: On Mar 5, 1:14 pm, Chris Rebert wrote: I want to write other modules, and my thinking is that it makes sense for those modules to use the "logger" module to do the logging, if and only if the parent using the other modules is also using the logger modu

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 > >>> based on whether or not anothe

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

2010-03-05 Thread Chris Rebert
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 >>> based on whether or not another module has been loaded? >>> If someone is using

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 foobar > > > print foo() > > print foobar() > > >

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 module, I want to take advantage of its > > fe

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: >> >> import foo >> import foobar >> >> print f

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

2010-03-05 Thread Chris Rebert
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: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo: >retu

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

2010-03-05 Thread Martin P. Hellwig
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 module, I want to take advantage of its features and use it in foobar, otherwise, I want to do something els

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

2010-03-05 Thread MRAB
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() ### foo.py def foo: return 'foo' ### foobar.py d

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

2010-03-05 Thread Steve Holden
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() > By the way, the above statements are never going

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

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 11:24:44 -0800, 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? try: import foo except ImportError: foo = None def function(): if foo: return foo.func() e

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

2010-03-05 Thread Steve Holden
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() > > ### foo.py > def foo: > return 'foo

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() > > ### foo.py > def foo: