Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21993

Re: class checking its own module for an attribute

Date 2012-03-21 13:06 -0400
From Rod Person <rodperson@rodperson.com>
Subject Re: class checking its own module for an attribute
References <20120321112503.00006eb5@unknown> <CAMZYqRS5YC9xBFfynEVpLDwzOhJwFm4bdj3NdLuat4=C5UApQA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.866.1332349617.3037.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, 21 Mar 2012 09:56:57 -0700
Chris Rebert <clp2@rebertia.com> wrote:

> On Wed, Mar 21, 2012 at 8:25 AM, Rod Person <rodperson@rodperson.com>
> wrote: <snip>
> > The question is there a way I can do this with out having to import
> > constants when what it's doing is importing itself. It would seem
> > to me that there should be a way for a module to reference itself.
> > In that thinking I have tried
> >
> >  if not(hasattr(__file__, value):
> >  if not(hasattr(__name__, value):
> >
> > and even:
> >
> >  this = sys.argv[0]
> >  if not(hasattr(this, value):
> >
> > None of which works.
> 
> http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-current-module
> 
> Cheers,
> Chris

Thank you!

-- 

Rod Person  http://www.rodperson.com  rodperson@rodperson.com

'Silence is a fence around wisdom'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: class checking its own module for an attribute Rod Person <rodperson@rodperson.com> - 2012-03-21 13:06 -0400

csiph-web