Drowning in a teacup?

Ethan Furman ethan at stoneleaf.us
Fri Apr 1 17:15:49 EDT 2016


On 04/01/2016 01:27 PM, Fillmore wrote:
> notorious pass by reference vs pass by value biting me in the backside
> here. Proceeding in order.

It's only notorious for folks that don't understand that Python uses 
neither. It also doesn't help when folks don't understand how 
name-binding works.
 if orderstring:
 bringOrderStringToFront(Tokens, orderstring)
Tokens has now been passed in to bringOrderStringToFront, and it has 
been assigned the name of `mylist`.
 def bringOrderStringToFront(mylist, key):
At this point `mylist` and `Tokens` are the same object.
 for i in range(len(mylist)):
 if(mylist[i].startswith(key)):
 mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
And now they are not, as you just assigned the name `mylist` to 
something else.
--
~Ethan~


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /