我为我的项目目的写了以下程序。在
import glob
import os
path = "/home/madhusudan/1/*.txt"
files = glob.glob(path)
s1 = "<add>\n<doc>\n\t<field name = \"id\">"
s2 = "</field>\n"
s3 = "<field name = \"features\">"
s4 = "</doc>\n</add>"
i = 150
for file in files:
f = open(file,"r")
str = f.read()
file1 = "/home/madhusudan/2/"+os.path.splitext(os.path.basename(file))[0] + ".xml"
f1 = open(file1,"w")
content = s1 + str(i) + s2 + s3 + f.read() + s2 + s4
f1.write(content)
i = i + 1
运行此代码时,我收到以下错误:
^{pr2}$有谁能帮我解决这个问题吗?在
str
是处理字符串值的保留名称。 因此可以将其用作局部变量名。选别的。
做
您已将文件内容分配给
str
:这将屏蔽内置函数。在
不要使用
str
作为本地名称;请选择其他名称。在在下一行中,代码用string对象覆盖内置函数
str
。在用不同的名字来防止。在
^{pr2}$
相关问题 更多 >
编程相关推荐