pep 8 constants
bruno.42.desthuilliers at websiteburo.invalid
Wed Feb 25 10:07:00 CET 2009
Ethan Furman a écrit :
> Steve Holden wrote:
>> Brian Allen Vanderburg II wrote:
>>> One idea to make constants possible would be to extend properties to be
>>> able to exist at the module level as well as the class level:
>>> def pi():
>>> return 3.14159.....
>>> print(pi) # prints 3.14159....
>>> pi=32 # Raise an error Cannot set attribute ...
>> I don't understand why this would print 3.14159 ... instead of <function
>> __math__.pi>, or whatever.
>> property would clearly have to do something very different in module
>> scope in order to make this work.
> --> class tester(object):
> ... @property
> ... def pi(self):
> ... return 3.141596
> --> testee = tester()
> --> testee.pi
> Looks like that's how property works, so the same behavior on a module
> level would do as Brian suggests.
At runtime, modules are instances of the module type - so 'module-level'
names are really instance attributes of the module instance -, and the
descriptor protocol is only invoked for class attributes.
More information about the Python-list