如何在python中打开文件并多次写入?
我正在使用语音识别,我希望根据我的说法改变其内容.其他应用程序需要能够读取此文件.有没有办法做到这一点,或者我需要为每次写入打开/关闭?
f = open('myfile.txt','w')
f.write('Hi')
f.write('Hi again!')
f.write('Is this thing on?')
# do this as long as you need to
f.seek(0,0) # return to the beginning of the file if you need to
f.close() # close the file handle
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9789 次 |
| 最近记录: |