ISBN-10からISBN-13への変換をテキスト文書に書き込もうとしていますが、試行するたびにこのエラーが発生します。ここでタプルをテキストファイルにPythonで書き込む方法は?
line 244, in 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")
[ISBN-13コンバータ(Pythonのレシピ)] (https://code.activestate.com/recipes/498104-isbn-13-converter/)。 – ekhumoro