如何附加此文件以及我做错了什么?

2024-06-03 06:40:44 发布

您现在位置:Python中文网/ 问答频道 /正文

你知道吗 好,所以我试图附加一个文件,但我看不到任何视觉错误和屏幕没有给我错误,但由于某种原因,该文件没有附加。我该怎么办?我是一个初级的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

我该怎么办?你知道吗


Tags: txtcloseshopenactprintsuperoffline
1条回答
网友
1楼 · 发布于 2024-06-03 06:40:44

()放在close()方法上。这是一个语法错误。
虽然我不明白这段话是怎么说的。你知道吗

print()
print()
print("-" * 50)
print("Name:  NuAmen, Period 1, Roster 01")
print("p1 r01 audena nuamen exer 003.py")

相关问题 更多 >