> I'm sorry, perhaps I'm being slow today, but just why are they dangerous?
> More dangerous than, say, mutable lists and mutable dicts? Unless I'm
> missing something, the worst that can happen is that people will write
> inefficient code, and they'll be caught out by the same sort of things
> tha
On Mon, 10 Jul 2006 19:30:09 +0200, Diez B. Roggisch wrote:
[snip]
> So: Yes, mutable strings are dangerous.
I'm sorry, perhaps I'm being slow today, but just why are they dangerous?
More dangerous than, say, mutable lists and mutable dicts? Unless I'm
missing something, the worst that can hap
>>> Arrays of chars are dangerous. If you insist, use Python lists of
>>> Python "chars" (strings of length 1).
>> Why are they more dangerous than a self-written mutable string?
>
> I didn't say that. I meant that arrays in the C++ sense are dangerous.
So what? Python's arrays are backed by arra
tac-tics wrote:
> I didn't say that. I meant that arrays in the C++ sense are dangerous.
so what do you think Python's string type uses on the inside ?
> C++ offers pass by value options. That makes it so you never need to
> worry about messing up data that doesn't belong to you unless you
> exp
> >> What's wrong about arrays of chars?
> >
> > Arrays of chars are dangerous. If you insist, use Python lists of
> > Python "chars" (strings of length 1).
>
> Why are they more dangerous than a self-written mutable string?
I didn't say that. I meant that arrays in the C++ sense are dangerous.
Simon Forman wrote:
> greenflame wrote:
> > Jason wrote:
> > >
> > > There /are/ a few hacks which will do what you want. However, if you
> > > really need it, then you probably need to rethink your program design.
> > > Remember, you can't change a string since a string is immutable! You
> > > c
On Mon, 10 Jul 2006 16:27:03 +0200, Diez B. Roggisch wrote:
>> Of course, another right way would be to have mutable strings in Python.
>> I understand why strings need to be immutable in order to work with dicts,
>> but is there any reason why (hypothetical) mutable strings should be
>> avoided i
On Mon, 10 Jul 2006 15:23:36 +0100, Sion Arrowsmith wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>>Of course, another right way would be to have mutable strings in Python.
>
> What significant advantage would mutable strings have over StringIO
> and wrapping list manipulation in list(s) a
tac-tics wrote:
>
> Diez B. Roggisch wrote:
>> > Of course, another right way would be to have mutable strings in
>> > Python. I understand why strings need to be immutable in order to work
>> > with dicts, but is there any reason why (hypothetical) mutable strings
>> > should be avoided in situa
Diez B. Roggisch wrote:
> > Of course, another right way would be to have mutable strings in Python.
> > I understand why strings need to be immutable in order to work with dicts,
> > but is there any reason why (hypothetical) mutable strings should be
> > avoided in situations where they aren't n
> Of course, another right way would be to have mutable strings in Python.
> I understand why strings need to be immutable in order to work with dicts,
> but is there any reason why (hypothetical) mutable strings should be
> avoided in situations where they aren't needed as dictionary keys? Python
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
>Of course, another right way would be to have mutable strings in Python.
What significant advantage would mutable strings have over StringIO
and wrapping list manipulation in list(s) and ''.join(l). Other than
that pleasing symmetry with sets/frozensets
On Sun, 09 Jul 2006 21:31:00 -0700, placid wrote:
>
> greenflame wrote:
>> I want to make a function that does the following. I will call it
>> thefunc for short.
>>
>> >>> s = "Char"
>> >>> thefunc(s)
>> >>> s
>> '||Char>>'
>>
>> I tried the following
>>
>> def thefunc(s):
>> s = "||" + s +
greenflame wrote:
> Jason wrote:
> >
> > There /are/ a few hacks which will do what you want. However, if you
> > really need it, then you probably need to rethink your program design.
> > Remember, you can't change a string since a string is immutable! You
> > can change a variable to bind to an
placid wrote:
> quick hack
>
> def thefunc(s):
> return s = "||" + s + ">>"
>>> def thefunc(s):
return s = "||" + s + ">>"
SyntaxError: invalid syntax
--
http://mail.python.org/mailman/listinfo/python-list
Jason wrote:
>
> You cannot do what you are trying to do directly. Strings are
> immutable objects. Once a string is created, that string cannot be
> modified. When you operate on a string, you produce a different
> string. Functions which operate on a string should return their value:
>
> >>>
greenflame wrote:
> I want to make a function that does the following. I will call it
> thefunc for short.
>
> >>> s = "Char"
> >>> thefunc(s)
> >>> s
> '||Char>>'
>
> I tried the following
>
> def thefunc(s):
> s = "||" + s + ">>"
>
> The problem is that if I look at the string after I apply
greenflame wrote:
> I want to make a function that does the following. I will call it
> thefunc for short.
>
> >>> s = "Char"
> >>> thefunc(s)
> >>> s
> '||Char>>'
>
> I tried the following
>
> def thefunc(s):
> s = "||" + s + ">>"
>
> The problem is that if I look at the string after I apply t
I want to make a function that does the following. I will call it
thefunc for short.
>>> s = "Char"
>>> thefunc(s)
>>> s
'||Char>>'
I tried the following
def thefunc(s):
s = "||" + s + ">>"
The problem is that if I look at the string after I apply the function
to it, it is not modified. I r
19 matches
Mail list logo