好的,所以我试图附加一个文件,但我看不到任何视觉错误,屏幕不会给我错误,但由于某种原因文件不附加。我该怎么办?我是一个开始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
我该怎么办?
答案 0 :(得分:0)
将()放在close()方法上。这是语法错误 虽然我不明白这里的内容是什么。
print()
print()
print("-" * 50)
print("Name: NuAmen, Period 1, Roster 01")
print("p1 r01 audena nuamen exer 003.py")