well this sort of awful hackery will allow you to put read only constants on an existing module

>>> import reportlab
>>> reportlab.__class__
>>> class MyModule(reportlab.__class__):
...     @property
...     def pi(self):
...             return 3
...
>>> z=MyModule('reportlab')
>>> z.__dict__.update(reportlab.__dict__)
>>> z.pi
3
>>> import sys
>>> sys.modules['reportlab']=z
>>> del reportlab
>>> import reportlab
>>> reportlab.pi
3
>>> reportlab.pi=4
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
AttributeError: can't set attribute
>>>

so I guess if you write your own module class and then use a special importer you can create module like objects with read only attributes.


--
Robin Becker

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to