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

Shurui Liu (Aaron Liu) shurui91 at gmail.com
Sun Mar 28 23:37:50 CEST 2010


Tell me how to do what i want, please.

2010/3/28 Shashwat Anand <anand.shashwat at gmail.com>:
>>>> s = "I am a studaet."
>>>> new_s = s[0:8] + 'ent'
>>>> print new_s
> I am a sent
>
> You are using str as a variable, str is used to convert anything into string
>
>>>> a  = 0
>>>> b = str(a)
>>>> type(b)
> <type 'str'>
>
>
> On Mon, Mar 29, 2010 at 2:53 AM, Shurui Liu (Aaron Liu) <shurui91 at gmail.com>
> wrote:
>>
>> 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?
>>
>> --
>> Shurui Liu (Aaron Liu)
>> Computer Science & Engineering Technology
>> University of Toledo
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Shurui Liu (Aaron Liu)
Computer Science & Engineering Technology
University of Toledo


More information about the Tutor mailing list