No Thoughts about Everything

Discussion in 'Python' started by bblochl, Feb 26, 2004.

  1. bblochl

    bblochl Guest

    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.
     
    bblochl, Feb 26, 2004
    #1
    1. Advertising

  2. bblochl

    Paul Rubin Guest

    bblochl <> writes:
    > 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.
     
    Paul Rubin, Feb 26, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zetasum
    Replies:
    0
    Views:
    478
    zetasum
    Feb 18, 2005
  2. zetasum
    Replies:
    0
    Views:
    456
    zetasum
    Feb 18, 2005
  3. New_aspect

    Aspect oriented Everything?

    New_aspect, Aug 22, 2003, in forum: Perl
    Replies:
    5
    Views:
    1,094
    Robert Will
    Aug 31, 2003
  4. b-blochl

    No Thoughts about Everything

    b-blochl, Feb 25, 2004, in forum: Python
    Replies:
    5
    Views:
    355
    Josiah Carlson
    Feb 29, 2004
  5. Dave Brueck

    Re: No Thoughts about Everything

    Dave Brueck, Feb 25, 2004, in forum: Python
    Replies:
    3
    Views:
    290
    Dang Griffith
    Feb 26, 2004
Loading...

Share This Page