好的,所以我试图追加一个文件,但我看不到任何视觉错误,屏幕没有给我错误,但由于某种原因,文件没有附加。我做什么好?我是一个刚开始的python程序员。这是我的代码:
b = open("games.txt", "r")
c = open("games1.txt", "w")
avar = b.readline()
while avar != "ZZZZ -9999 zzzz ZZZZ ZZZZ ":
c.write(avar)
avar = b.readline()
c.close()
b.close()
d = open("games1.txt", "r")
text = d.read()
print(text)
d.close()
e = open("games1.txt", "a")
newField = ""
newField = input("Enter the field’s data: ")
e.write(newField + "\n")
e.close
f = open("games1.txt", "r")
texto = f.read()
print(texto)
f.close()
print()
print()
print("-" * 50)
print("Name: NuAmen, Period 1, Roster 01")
print("p1 r01 audena nuamen exer 003.py")
blah = input("Press ENTER to quit.")当运行时,它会读到:
Super smash bros 4 2014 F Both Nintendo
Splatoon 2 2017 Sh both Nintendo
Monopoly 1935 M Offline Parker Brothers
Super mario oddysey 2017 P Offline Nintendo
Clash Royale 2016 S Online Supercell
Call of duty 2003 sh/act online Activision
Enter the field’s data: 我输入了一些东西:
Super smash bros 4 2014 F Both Nintendo
Splatoon 2 2017 Sh both Nintendo
Monopoly 1935 M Offline Parker Brothers
Super mario oddysey 2017 P Offline Nintendo
Clash Royale 2016 S Online Supercell
Call of duty 2003 sh/act online Activision
Enter the field’s data: Grand theft auto 1997 act offline DMA Design我要把这个印出来:
Super smash bros 4 2014 F Both Nintendo
Splatoon 2 2017 Sh both Nintendo
Monopoly 1935 M Offline Parker Brothers
Super mario oddysey 2017 P Offline Nintendo
Clash Royale 2016 S Online Supercell
Call of duty 2003 sh/act online Activision
Grand theft auto 1997 act offline DMA Design但是它却打印了这个:
Super smash bros 4 2014 F Both Nintendo
Splatoon 2 2017 Sh both Nintendo
Monopoly 1935 M Offline Parker Brothers
Super mario oddysey 2017 P Offline Nintendo
Clash Royale 2016 S Online Supercell
Call of duty 2003 sh/act online Activision我做什么好?
发布于 2017-12-11 14:58:16
将()放在close()方法上。这是语法错误。
虽然我不明白这段话是怎么回事。
print()
print()
print("-" * 50)
print("Name: NuAmen, Period 1, Roster 01")
print("p1 r01 audena nuamen exer 003.py")https://stackoverflow.com/questions/47755278
复制相似问题