Answers for "file read function python"

48

python read file

with open("file.txt", "r") as txt_file:
  return txt_file.readlines()
Posted by: Guest on November-30-2020
2

read a file python

# read, write, close a file
# catch error if raise
try:
    file = open("tryCatchFile.txt","w") 
    file.write("Hello World")

    file = open("tryCatchFile.txt", "r")
    print(file.read())
except Exception as e:
    print(e)
finally:
    file.close()
Posted by: Guest on November-21-2021

Code answers related to "file read function python"

Python Answers by Framework

Browse Popular Code Answers by Language