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


Groups > comp.lang.python > #21992 > unrolled thread

Re: class checking its own module for an attribute

Started byPeter Otten <__peter__@web.de>
First post2012-03-21 17:59 +0100
Last post2012-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.


Contents

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

#21992 — Re: class checking its own module for an attribute

FromPeter Otten <__peter__@web.de>
Date2012-03-21 17:59 +0100
SubjectRe: 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():
    ...

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web