Py学习  »  Python

python tempfile读写

protoneight • 5 年前 • 1779 次点击  

我在读写临时文件时遇到问题:

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"] 我不明白背后的原因,

感谢您的帮助

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50779
 
1779 次点击  
文章 [ 2 ]  |  最新文章 5 年前