因此,正如标题所暗示的那样,我正在尝试将数组写入文件,但随后我需要调用该数组并向其追加更多内容,然后将其写回同一个文件,然后一遍又一遍地执行相同的过程。
我到目前为止的代码是:
c = open(r"board.txt", "r")
current_position = []
if filesize > 4:
current_position = [c.read()]
print(current_position)
stockfish.set_position(current_position)
else:
stockfish.set_fen_position("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
#There is a lot more code here that appends stuff to the array but I don't want to #add anything that will be irrelevant to the problem
with open('board.txt', 'w') as filehandle:
for listitem in current_position:
filehandle.write('"%s", ' % listitem)
z = open(r"board.txt", "r")
print(z.read())
My array end up looking like this when I read …Run Code Online (Sandbox Code Playgroud) python ×1