我在读写临时文件时遇到问题:
import tempfile
def edit(base):
tmp = tempfile.NamedTemporaryFile(mode='w+')
#fname = tmp.name
tmp.write(base)
#system('nano %s' % fname)
content = tmp.readlines()
tmp.close()
return content
answer = "hi"
print(edit(answer))
输出为
[]
而不是
["hi"]
我不明白背后的原因,
感谢您的帮助