Python won't write to file

前端 未结 2 1090
不思量自难忘°
不思量自难忘° 2021-02-19 18:52

I am attempting to write a pretty printed email to a .txt file so i can better view what I want to parse out of it.

Here is this section of my code:

resu         


        
相关标签:
2条回答
  • 2021-02-19 19:03

    You are missing the brackets at the end of f.close().

    0 讨论(0)
  • 2021-02-19 19:09

    You need to invoke the close method to commit the changes to the file. Add () to the end:

    f.close()
    

    Or even better would be to use with:

    with open("da_email.txt", "w") as f:
        f.write(pretty_email)
    

    which automatically closes the file for you

    0 讨论(0)
提交回复
热议问题