Magic Module Methods?

Tim Peters tim.one at home.com
Sat Oct 20 17:40:23 EDT 2001


[Magnus Lie Hetland]
> I just found myself needing (or wanting) a module which
> could have default values for variables that weren't set;

I expect it would be near-infinitely clearer if you simply set the module
variables to their default values explicitly at module initialization time.

> this can be done with Alex's object-as-module trick, but
> it occurred to me, why should this be necessary? All I
> wanted was to add a __getattr__ method to the module...
> Why should I have to replace the module with some other
> object to do that? Can't modules be more like objects in
> this respect?

Probably, with enough code to implement it.  Lists could act more like
integers too, but I doubt I'd fight for that either <wink>.

you-can-subclass-the-module-type-in-2.2-but-hoping-you-don't-ly
    y'rs  - tim





More information about the Python-list mailing list