即时通讯尝试创建一个脚本来打开一个文件并用'hello'替换每个'hola'。Python新手:试图创建一个脚本来打开一个文件并替换文字
f=open("kk.txt","w")
for line in f:
if "hola" in line:
line=line.replace('hola','hello')
f.close()
但是我得到这个错误:
Traceback (most recent call last):
File "prueba.py", line 3, in for line in f: IOError: [Errno 9] Bad file descriptor
任何想法?
Javi
你为什么要打开与 “W” 模式下的文件?你使用什么教程来学习Python? – 2010-04-05 10:21:30