No Thoughts about Everything

bblochl bblochl at fh-lausitz.de
Thu Feb 26 03:00:59 EST 2004


I found a solution for the simulation of access modifier "static final " 
in python:


class Mytest:
    LOGE_10=(2.302585092994046,)
    #Klassenkonstante (static final) use a tuple :-)
    #def __init__(self):
        
    def log10(self,x):
        return(log(x)/LOGE_10[0])

testmath=Mytest()
print "LOGE_10=%10.8f"%Mytest.LOGE_10[0]," and 
log10=%f10.8"%testmath.log10(3)
Mytest.LOGE_10[0]=1
#print "LOGE_10=%10.8f"%Mytest.LOGE_10[0]," and 
log10=%f10.8"%testmath.log10(3)


#output:
#LOGE_10=2.30258509  and log10=0.47712110.8
#Traceback (most recent call last):
#  File 
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", 
line 301, in RunScript
#    exec codeObject in __main__.__dict__
#  File "C:\PyProgs\Static.py", line 13, in ?
#    #Mytest.LOGE_10=1
#TypeError: object doesn't support item assignment
#

I think the result is selfexplaining. Unawaited there is another 
argument for tuples! One may use it for the definition of global 
"Constants" as well.

Hopefully that contribution will be of  interest and profit for other 
python users. Thanks for your contributions.

Bernhard

PS: Has everyone tried to use classes as elements of tuples? please give 
me a hint.





More information about the Python-list mailing list