Python newbie: trying to create a script that opens a file and replaces words

Posted by user248959 on Stack Overflow See other posts from Stack Overflow or by user248959
Published on 2010-04-05T09:25:10Z Indexed on 2010/04/05 9:33 UTC
Read the original article Hit count: 401

Filed under:
|

Hi,

im trying to create a script that opens a file and replace every 'hola' with 'hello'.

f=open("kk.txt","w")

for line in f:
  if "hola" in line:
      line=line.replace('hola','hello')

f.close()

But im getting this error:

Traceback (most recent call last):
File "prueba.py", line 3, in for line in f: IOError: [Errno 9] Bad file descriptor

Any idea?

Javi

© Stack Overflow or respective owner

Related posts about python

Related posts about newbie