Re: Modify a string's value

2008-07-16 Thread s0suk3
On Jul 15, 11:55 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > I just came across this unusual situation where I'd like to modify a > > string passed to a function > > Again: Why? The normal way to do this is to create a new string and > return that. > Yes, usually, bu

Re: Modify a string's value

2008-07-15 Thread Ben Finney
[EMAIL PROTECTED] writes: > I just came across this unusual situation where I'd like to modify a > string passed to a function Again: Why? The normal way to do this is to create a new string and return that. > which seems impossible since Python passes arguments by value. No, Python passes argu

Re: Modify a string's value

2008-07-15 Thread s0suk3
On Jul 15, 6:46 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi everyone, > > > I've heard that a 'str' object is immutable. But is there *any* way to > > modify a string's internal value? > > > Thanks, > > Sebastian > > Why would you care? Just create a new string (wi

Re: Modify a string's value

2008-07-15 Thread Larry Bates
[EMAIL PROTECTED] wrote: Hi everyone, I've heard that a 'str' object is immutable. But is there *any* way to modify a string's internal value? Thanks, Sebastian Why would you care? Just create a new string (with the changed contents) and let garbage collection take care of the old one when

Re: Modify a string's value

2008-07-15 Thread MRAB
On Jul 15, 3:06 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > I've heard that a 'str' object is immutable. But is there *any* way to > > modify a string's internal value? > > If there were, it would not be immutable. The 'str' type has only > immutable values. > > You co

Re: Modify a string's value

2008-07-15 Thread Terry Reedy
[EMAIL PROTECTED] wrote: Hi everyone, I've heard that a 'str' object is immutable. But is there *any* way to modify a string's internal value? In 3.0, ascii chars and encoded unicode chars in general can be stored in a mutable bytearray. -- http://mail.python.org/mailman/listinfo/python-l

Re: Modify a string's value

2008-07-15 Thread bearophileHUGS
Sebastian: > I've heard that a 'str' object is immutable. But is there *any* way to > modify a string's internal value? No, but you can use other kind of things: >>> s = "hello" >>> sl = list(s) >>> sl[1] = "a" >>> sl ['h', 'a', 'l', 'l', 'o'] >>> "".join(sl) 'hallo' >>> from array import array >

Re: Modify a string's value

2008-07-15 Thread Ben Finney
[EMAIL PROTECTED] writes: > I've heard that a 'str' object is immutable. But is there *any* way to > modify a string's internal value? If there were, it would not be immutable. The 'str' type has only immutable values. You could implement your own string type, and have it allow mutable values. Y

Modify a string's value

2008-07-15 Thread s0suk3
Hi everyone, I've heard that a 'str' object is immutable. But is there *any* way to modify a string's internal value? Thanks, Sebastian -- http://mail.python.org/mailman/listinfo/python-list