pep 8 constants

Ethan Furman ethan at stoneleaf.us
Tue Feb 24 19:52:20 EST 2009


Steve Holden wrote:
> Brian Allen Vanderburg II wrote:
> 
>>bockman at virgilio.it wrote:
>>
>>>Constants would be a nice addition in python, sure enough.
>>>But I'm not sure that this can be done without a run-time check every
>>>time
>>>the constant is used, and python is already slow enough. Maybe a check
>>>that is disabled when running with optimizing flags ?
>>>
>>>But I'm sure this discussion has been already made and the FINAL WORD has
>>>been already spoken.
>>>
>>>Ciao
>>>----
>>>FB
>>
>>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:
>>
>>@property
>>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.
> 
> regards
>  Steve

--> class tester(object):
...   @property
...   def pi(self):
...     return 3.141596
...
--> testee = tester()
--> testee.pi
3.1415959999999998

Looks like that's how property works, so the same behavior on a module 
level would do as Brian suggests.
--
~Ethan~



More information about the Python-list mailing list