Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21992 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2012-03-21 17:59 +0100 |
| Last post | 2012-03-21 17:59 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: class checking its own module for an attribute Peter Otten <__peter__@web.de> - 2012-03-21 17:59 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-03-21 17:59 +0100 |
| Subject | Re: class checking its own module for an attribute |
| Message-ID | <mailman.865.1332349198.3037.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web