Problems with string and lists (searching and replaceing)

Anton Vredegoor anton at vredegoor.doge.nl
Sat Sep 20 15:58:00 EDT 2003


"jblazi" <jblazi at hotmail.com> wrote:

>> from UserString import MutableString
>>
>> def test():
>>     s = MutableString("helo world")
>>     print s
>>     x = 'helo'
>>     y = 'hello'
>>     i = s.find(x)
>>     s[i:i+len(x)] = y
>>     print s
>>
>> if __name__=='__main__':
>>     test()
>>
>> #output:
>> #helo world
>> #hello world
>
>Thx.
>It would be quite diffcult to explain this akward procedure to beginners.
>especially when they see that this can be done so simply in C.
>It seems that I have stumbled upon one of the few cases when Python is
>cumbersome and difficult to use.

Interesting. Could you provide an example showing in which way it can
be done so simply in C ? Maybe I could come up with better Python code
if I knew what the problem is with my code. Anyway, it was just
something I typed in without thinking much about it, to show that
strings can be mutated. In Python everything is an object so if some
functionality is needed it is pretty standard to use a subclass. In
this case a fitting subclass already was present in the standard
distribution so it seemed like a piece of cake.

With respect to beginners I suppose it's possible to project ones own
sense of what is easy, instead of really checking what would be easy
for *them*.

Beginners are not supposed to know about C, but possibly you are, and
maybe you are thinking too much from your own perspective in judging
what would be easy.

Anton




More information about the Python-list mailing list