Constant variable and API

Alex Martelli aleaxit at yahoo.com
Thu Sep 30 07:30:18 EDT 2004


mg <mg.mailing-list at laposte.net> wrote:
   ...
> Then, my question is : how can I implement a constant variable from the
> API in order to the reaffectation (MyModule.NULL = 99) of my variable be
> impossible ?

With a module (a direct instance of types.ModuleType), you can't -- the
module type just doesn't have any functionality to control attribute
setting.  You can subclass the type to do that, and install an instance
of the subclass in sys.modules in the appropriate place...


Alex



More information about the Python-list mailing list