class checking its own module for an attribute

Chris Rebert clp2 at rebertia.com
Wed Mar 21 12:56:57 EDT 2012


On Wed, Mar 21, 2012 at 8:25 AM, Rod Person <rodperson at 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



More information about the Python-list mailing list