[Tutor] how to change some words in a text file

Emile van Sebille emile at fenx.com
Sun Mar 28 23:30:40 CEST 2010

On 3/28/2010 2:23 PM Shurui Liu (Aaron Liu) said...
> Here's the thing, I wanna change some wrong words from a text file like this:
> "I am a studaet." ->  "I am a student."
> I have tried to use this command:
> str = "I am a studaet."
> newstr = str[0:8] + "ent"
> print newstr
> But the system said     TypeError: 'type' object is unsubscriptable
> What's wrong?
str is an unfortunate variable name choice -- try oldstr instead.  What 
you've done is often called shadowing.  I don't get the error here, but 
I'm guessing that's because I'm on 2.6 and you're on 3.x?


More information about the Tutor mailing list