Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!usenetcore.com!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:module': 0.04; 'parameter': 0.05; 'rod': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'constants': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'from:addr:web.de': 0.23; 'command': 0.24; 'parameters': 0.25; 'module': 0.26; 'import': 0.27; 'value.': 0.28; 'constant': 0.29; 'class': 0.29; 'server': 0.30; 'databases,': 0.30; 'header:User-Agent:1': 0.33; 'instead': 0.33; 'header:X-Complaints-To:1': 0.34; 'calling': 0.34; 'to:addr :python-list': 0.35; '...': 0.35; 'received:org': 0.36; 'checks': 0.37; 'created': 0.37; 'files': 0.39; 'called': 0.40; 'to:addr:python.org': 0.40; 'below': 0.62; 'our': 0.63; 'account': 0.66; 'subject:its': 0.84; 'value):': 0.84; 'subject:own': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: class checking its own module for an attribute Date: Wed, 21 Mar 2012 17:59:56 +0100 Organization: None References: <20120321112503.00006eb5@unknown> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b17c.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332349198 news.xs4all.nl 6859 [2001:888:2000:d::a6]:44396 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21992 Rod Person wrote: > We have a module called constants.py, which contains [whatever] related to > server names, databases, service account users and their passwords. Passwords? > In order to be able to use constants as command line parameters for > calling from our batch files I created the class below that checks to > make sure the parameter value is a valid constant and if so return its > value. Instead of > from CCBH import constants ... > if not hasattr(constants, value): ... You can look up the name in the global namespace: if value not in globals(): ...