Confused yet again: Very Newbie Question

Jeff jeffober at gmail.com
Mon Jul 7 08:09:34 EDT 2008


When you call c3.createJoe(c1.fred), you are passing a copy of the
value stored in c1.fred to your function.  Python passes function
parameters by value.  The function will not destructively modify its
arguments; you must expliticly state your intention to modify an
object:

class one():
    fred = 'fred'

class three():
    def createJoe(self, myName):
        return "Joe"

def main():
    c1 = one()
    c3 = three()
    c1.fred = c3.createJoe() # Modify c1's attribute, fred, with the
return value from c3.createJoe



More information about the Python-list mailing list