[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Python Question
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Python Question
- From: Terry Hancock <hancock@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 16 May 2006 23:14:47 +0000
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 16 May 2006 19:09:33 -0400
- In-reply-to: <20060430191513.5811.qmail@web38610.mail.mud.yahoo.com>
- References: <20060430191513.5811.qmail@web38610.mail.mud.yahoo.com>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Debian Thunderbird 1.0.2 (X11/20051002)
Geekius Maximus wrote:
I have a general Python language question. I know this is the pygame board, but I don't know who else to ask. I'm trying to alter an argument rect in a method - change it from a Rect to None, but the change doesn't effect the variable in the calling function. What do I do?
Probably the best place to ask a generic Python question is on the
comp.lang.python newsgroup,
which is also the python-list@xxxxxxxxxx mailing list (I'm pretty sure
you don't have to be signed
up to post). The list is quite high-volume, and it's fairly typical
usenet fair, so keep your shields
up, but you can usually get help on this kind of stuff.
I think you've already received your answer -- functions are "call by
object reference" in
Python. You get the reference to the original, reassigning that value
does not affect
other references to the original object.
If you want to change something that is passed to you, you can't
reassign it. What you
can do is mutate it, IF it is mutable (mutable objects include lists,
dictionaries, and
class instances).
So, for example, if I have a control structure modelled as an object:
class settings(object):
spam_quotient = 2
exploding_scotsmen_count = 14
S = settings()
I can write a function which mutates this:
def test_scotsman(S):
S.exploding_scotsmen_count -= 1
if S.exploding_scotsmen_count < 0:
print "All out of exploding scotsmen."
Cheers,
Terry
--
Terry Hancock (hancock@xxxxxxxxxxxxxxxxxxxx)
Anansi Spaceworks http://www.AnansiSpaceworks.com