Interesting thread on comp.lang.perl.misc

ze5yr ze5yr at my-deja.com
Fri Aug 13 19:07:04 EDT 1999


In article <Pine.GSO.4.10.9908131047510.3761-100000 at crusoe.crusoe.net>,
  japhy at pobox.com wrote:
> I wish I could change a string in-place with a function.*
> [bobbit]
> * meaning:
>
> def func(str):
>   # something modifying str
>
> str = "foo"
> func(str)
> print str # prints... "bar", for example

Enclose it in a list, which is mutable:

def func(l):
  l[0]="bar"

>>> l=["foo"]
>>> func(l)
>>> print l
['bar']

A little clumsy, but it works!


--
Cliff Crawford                           -><-
http://www.people.cornell.edu/pages/cjc26
                            empty-handed I go,
)O(       and behold the spade is in my hands


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list