No Thoughts about Everything

B

bblochl

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.
 
P

Paul Rubin

bblochl said:
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()

But you can still change the value by saying

testmath.LOGE_10 = (3.14159,)

outside the class definition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top