"ex_ottoyuhr" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). > > I've looked around on this newsgroup and elsewhere, and I gather that > this is a very common concern in Python, but one which is ordinarily > answered with "No, you can't. Neat, huh?" A few websites, newsgroup > posts, etc. have recommended that one ask for a more "Pythonic" way of > doing things; so, is there one, or at least one that doesn't involve > using objects as wrappers for mutable arguments? > > And, indeed, would that approach work? Would declaring: > > class FooWrapper : > __init__(fooToLoad) : > self.foo = fooToLoad > > mean that I could now declare a FooWrapper holding a foo, pass the > FooWrapper to a function, and have the function conclude with the foo > within the FooWrapper now modified? > > Thanks in advance for everyone's time; I hope I'm comprehensible. >
Python isn't C++ and there is no need to return multiple values by modifying function parameters: >>> def funct(a,b): ... return a+1,b+1 ... >>> foo,bar=1,2 >>> print foo,bar 2 3 >>> foo,bar=funct(foo,bar) >>> print foo,bar 3 4 >>> -Mark -- http://mail.python.org/mailman/listinfo/python-list
