Confused yet again: Very Newbie Question

mcl mcl.office at googlemail.com
Mon Jul 7 07:30:33 EDT 2008


Why can I not the change the value of a variable in another class,
when I have passed it via a parameter list.

I am sure I am being stupid, but I thought passed objects were Read/
Write

eg
------------------------------------------------------------
#!/usr/bin/python

class one():  #my Global Vars
    fred = 'fred'

class three():
    def createJoe(self, myName):
        c1 = one()
        myName = 'Joe'  #********************* Question why does this
not change variable fred in 'class one'
        print 'Three(Local): ' + myName + '    Three(Global): ' +
c1.fred

def main():
    c1 = one()
    c3 =three()
    c3.createJoe(c1.fred)


if __name__ == '__main__' : main()

Results:
Three(Local): Joe    Three(Global): fred

'fred' in 'class one' does not get changed to 'joe' in 'class three'
'createJoe', even though I have passed 'class one' 'fred' to
'createJoe'

I hope this makes sense.

I did not think you had to make the distinction between 'byvar' and
'byref' as in Basic.

Thanks

Richard



More information about the Python-list mailing list