我正在尝试将 ISBN-10 到 ISBN-13 的转换写入文本文档,但每次尝试时都会出现此错误。
第 244 行,在 conv10to13FILE outfile.write(ISBN13) TypeError: must be str, not tuple
这是代码:
filename = input("Enter the name of the .txt file: ")
getoutput = input("Name of text file where results will be placed: ")
outfile = open(getoutput, "a")
for line in open(filename, "r"):
if "-" in line:
line = line.replace("-", "")
D1 =int(line[0])*3
D2 =int(line[1])*1
D3 =int(line[2])*3
D4 =int(line[3])*1
D5 =int(line[4])*3
D6 =int(line[5])*1
D7 =int(line[6])*3
D8 =int(line[7])*1
D9 =int(line[8])*3
Sum=(9+21+8+D1+D2+D3+D4+D5+D6+D7+D8+D9)
Mod= Sum % 10
D11= 11 - Mod - 1
if D11 == 10:
D11 = 'X'
ISBN13=(978,"-",line[0],"-",line[1],line[2],"-",line[3],line[4],line[5],line[6],line[7],line[8],"-",D11)
outfile.write(ISBN13)
tomenu = input("Press Enter to return to Menu")
我相信您只是想加入元组中的所有元素:
outfile.write(''.join(str(item) for item in ISBN13))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句