Declaring A Function Argument As Global?
Pedro RODRIGUEZ
pedro_rodriguez at club-internet.fr
Thu Jan 16 12:47:29 EST 2003
On Thu, 16 Jan 2003 18:20:08 +0100, Tim Daneliuk wrote:
> I want to be able to write a generic list handling function which slices
> a list, but I don't want to have to return the modified list to do so.
> In other words, I purposely want the function to have a side-effect
> which modifies the list handed to it. For example:
>
> def lhandler(list):
> list = list[1:]
>
So you need to use a method provided by the object in order to modify it.
In your case, you are just creating a new object which will be bound to a
local variable.
Example :
def lhandler(list):
list.pop(0)
or
def lhandler(list):
del list[0]
or
def lhandler(list):
list.__delitem__(0)
Pedro
More information about the Python-list
mailing list