Rafe wrote:
> I guess, in the end, I'd use getattr() because it feels more pythonic,
> and more basic. I got pretty deep in to learning python before I had
> to learn what the globals() dict could do for me.
Why not store your individual classes inside another class or keep them in a
dict? That w
> 3) using the bare name:
> whatever
> 1) and 2) are useful when the desired name is variable, not a constant like
> "whatever".
I thought that went without saying.
> > I have been using #1 for two reasons. First, I will never run this
> > module directly, so __name__ will always be the module
En Mon, 24 Nov 2008 02:11:49 -0200, Rafe <[EMAIL PROTECTED]> escribió:
What are the pros and cons of these two patterns (and are there any
other)? Which is the best way to dynamically get an attribute from a
module from within the same module?
1) Using the name of the module
this_
What are the pros and cons of these two patterns (and are there any
other)? Which is the best way to dynamically get an attribute from a
module from within the same module?
1) Using the name of the module
this_module = sys.modules[__name__]
attr = getattr(this_module, "whatever"