José Matos wrote:

> On Tuesday 24 April 2007 2:27:29 am Richard Heck wrote:
>>
>> This is, as someone else said, because strings are immutable:
>> document.body[h] is a string, and you can't change it. You need to do
>> something like
>>     oldstr = document.body[h]
>>     newstr = oldstr[:j-1] + 'a' + oldstr[j+1:]
>>     document.body[h] = newstr
>> though I'm sure I made some syntax error there, and there's probably
>> some simpler way to do it, too.
> 
>   Beware of the limits, and nevertheless the version in a single line is
> easier to read:
> 
> document.body[h] = document.body[h][:j] + '|' + document.body[h][j+1:]
> 
>   Depending on what you are trying to do there are other easier ways to do
> this depending on the specific criteria used to choose j. With more
> information we could give you better advice.
> 

If you need efficiency, avoid a + b + c.  Use ''.join (a,b,c)
(Python cookbook, Alex Martelli)

Reply via email to