Adding to a module's __dict__?

Mel mwilson at the-wire.com
Tue Mar 2 09:26:06 EST 2010


Roy Smith wrote:
[ ... ]
> Why is it unwise?
> 
> The use case is I'm importing a bunch of #define constants from a C header
> file.  I've got triples that I want to associate; the constant name, the
> value, and a string describing it.  The idea is I want to put in the
> beginning of the module:
> 
> declare('XYZ_FOO', 0, "The foo property")
> declare('XYZ_BAR', 1, "The bar property")
> declare('XYZ_BAZ', 2, "reserved for future use")
> 
> and so on.  I'm going to have hundreds of these, so ease of use, ease of
> maintenance, and niceness of presentation are important.

As long as the header file says what you think it says, you're fine.  If you 
encounter a file that does "#define sys", then the sys module is forever 
masked, and your module can't invoke it.  A header file that contains 
"#define declare" will be fun.

	Mel.





More information about the Python-list mailing list