【发布时间】:2020-01-24 15:19:25
【问题描述】:
我正在尝试制作一个游戏,您的分数会保存为文本文件。得分(点击次数)必须始终位于第二行并按用户保存。每次用户保存时,我希望将文本文件的第二行替换为新的分数。
我尝试过使用堆栈溢出时建议的大量内容,例如 os.replace 或 os.resub,但没有任何效果。
def save():
global userlog
global clicks
score = open(directory + "/" + userlog + ".txt", "r+")
#### On this line, I want some code that will replace the second line in the text file listed above.
for i in range(random.randint(2,5)):
print("Saving")
time.sleep(0.10)
print("Saving.")
time.sleep(0.10)
print("Saving..")
time.sleep(0.10)
print("Saving...")
time.sleep(0.10)
print("\nGame Saved Sucessfully!")
我没有任何工作。只是收到一些标准错误消息。
任何帮助将不胜感激:)
谢谢:)
【问题讨论】:
标签: python-3.x function file operating-system