Answers for "read write file python"

73

python write to file

file = open(“testfile.txt”,”w”) 
 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
 
file.close() 
Posted by: Guest on December-09-2019
18

open text file in python

f=open("Diabetes.txt",'r')
f.read()
Posted by: Guest on April-25-2020
3

python write to file

with open("test.txt",'w',encoding = 'utf-8') as f:
   f.write("my first file\n")
   f.write("This file\n\n")
   f.write("contains three lines\n")
Posted by: Guest on October-16-2020
4

python write to file

# open a file you can use the function open
file = open("myFile.txt", "w")
#here we have "open", and that's the main function
# that opens the file, next we have 2 arguments
# FILENAME and OPENING MODE
# in the filename argument you just have to write the file's location
# or if the script is in that location just write the filename
# in the opening mode you have to write in which mode you want
# to open your file, i'll list some here:
# "w" for writing to a file
# "r" for reading to a file
# "r+" for both reading and writing
# "a" to append to a file
#to write to the file use "file.write"
file.write("This has been written by a program")
#and finally to close the file when you're done with it
file.close()
# hope this helped and remember that in "w" mode it
#deletes the content of the file and replaces
# it with a new one, if you want to add something
# to a file use "a" mode
Posted by: Guest on November-18-2020
3

python open and read file with

with open('pagehead.section.htm','r') as f:
    output = f.read()
Posted by: Guest on May-15-2020
0

python write to file

with open("testfile.txt", "w") as f:
  # "w" - write into file
  # "r" - read into file
  # "+" - read and write into file
  f.write("Hello World")
Posted by: Guest on January-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language