Python won't write to file

前端 未结 2 1103
不思量自难忘°
不思量自难忘° 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: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

提交回复
热议问题