In a Python program, why can't I cat a file right after writing it?

前端 未结 1 1374
走了就别回头了
走了就别回头了 2021-01-24 19:32

I tried to cat a file, using Popen(), right after creating and writing to it. It doesn\'t work. Print p gives two empty tuples (\'\',\'\'). Why ? I\'ve used rename to ensure an

相关标签:
1条回答
  • 2021-01-24 19:49

    You did not call close. Use fd.close() (you forgot the parentheses there to make it an actual function call). This could have been prevented by using the with-statement:

    with open("__q", "w") as fd:
        fd.write(t)
    # will automatically be closed here
    
    0 讨论(0)
提交回复
热议问题