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


Groups > comp.lang.python > #21992

Re: class checking its own module for an attribute

From Peter Otten <__peter__@web.de>
Subject Re: class checking its own module for an attribute
Date 2012-03-21 17:59 +0100
Organization None
References <20120321112503.00006eb5@unknown>
Newsgroups comp.lang.python
Message-ID <mailman.865.1332349198.3037.python-list@python.org> (permalink)

Show all headers | View raw


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():
    ...

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


Thread

Re: class checking its own module for an attribute Peter Otten <__peter__@web.de> - 2012-03-21 17:59 +0100

csiph-web