Confused about hasattr/getattr/namespaces

Jeff Epler jepler at unpythonic.net
Sun Feb 29 14:00:56 EST 2004


Here's one way:
    def generate(cmd):
        clsname = cmd + "Generator"
        g = globals()
        if g.has_key(clsname): ...
globals() returns the module's dict, not the module.  You could also
    import modulename as self
but this is a kind of circular import, and the re-use of the name "self"
(which will be used in method definitions) smells bad too.

Jeff




More information about the Python-list mailing list