Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:module': 0.04; 'rod': 0.07; '21,': 0.09; 'am,': 0.12; 'constants': 0.16; 'sys.argv[0]': 0.16; '\xa0this': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'cheers,': 0.20; 'header:In- Reply-To:1': 0.22; '-0700': 0.23; 'works.': 0.23; '\xa0if': 0.23; 'cc:2**0': 0.26; 'module': 0.26; 'import': 0.27; 'tried': 0.27; 'importing': 0.29; 'cc:addr:python.org': 0.29; 'seem': 0.29; 'chris': 0.30; 'there': 0.33; 'thank': 0.35; 'none': 0.35; 'question': 0.36; 'reference': 0.37; 'received:128': 0.38; 'doing': 0.38; 'should': 0.38; 'itself.': 0.39; 'subject:its': 0.84; 'value):': 0.84; 'subject:own': 0.91 Date: Wed, 21 Mar 2012 13:06:55 -0400 From: Rod Person To: Chris Rebert Subject: Re: class checking its own module for an attribute In-Reply-To: References: <20120321112503.00006eb5@unknown> X-Mailer: Claws Mail 3.7.10cvs7 (GTK+ 2.16.6; i586-pc-mingw32msvc) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332349617 news.xs4all.nl 6899 [2001:888:2000:d::a6]:49432 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21993 On Wed, 21 Mar 2012 09:56:57 -0700 Chris Rebert wrote: > On Wed, Mar 21, 2012 at 8:25 AM, Rod Person > wrote: > > 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 > > > > =A0if not(hasattr(__file__, value): > > =A0if not(hasattr(__name__, value): > > > > and even: > > > > =A0this =3D sys.argv[0] > > =A0if not(hasattr(this, value): > > > > None of which works. >=20 > http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-c= urrent-module >=20 > Cheers, > Chris Thank you! --=20 Rod Person http://www.rodperson.com rodperson@rodperson.com 'Silence is a fence around wisdom'