【发布时间】:2022-12-09 07:26:20
【问题描述】:
尝试用 python 编写文件,但每当我打开它时,文件只包含“无”一词
finally:
if ord(position[0]) == 83 or ord(position[0]) == 115:
print("SAVED")
with open('Battleshipsave.txt','w') as f:
#this line writes to a new file and adds the board to the save file.
print("")
f.write(str(print_board(board, True)))
#this is a debugging line to ensure that the file is written correctly
print("")
exit()
【问题讨论】:
-
可能是因为您的
print_board函数返回None。 -
@kaya3 你的意思是肯定的
-
如果
print_board()包含print()声明,那些将不是被写入文件。只有返回结果将写入文件。return有什么功能吗?
标签: python python-3.x