Python - Write To File

This code snippet shows how to write to a file. The "w" file mode opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.
  1. file = open("file.txt""w")    
  2. file.write("Hello world")    
  3. file.close() 

No comments:

Post a Comment