Answers for "how to write a file"

3

python write to file

with open("test.txt",'w',encoding = 'utf-8') as f:
   f.write("my first filen")
   f.write("This filenn")
   f.write("contains three linesn")
Posted by: Guest on October-16-2020
5

python write to file

path = "guide/README.txt" # The path of your file should go here
with open(path, "w") as fil: # Opens the file using 'w' method. See below for list of methods.
  fil.write("This is the README. It is reccomended that you read it.") # Writes to the file used .write() method
  fil.close() # Closes file
'''
List of methods:
w* - replace everything with needed text
r^ - read the file
a* - adds to file
x - creates file

* Creates file if the file at that path does not exist
^ Throws error if file does not exist
'''
Posted by: Guest on October-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language