Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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()
Source by www.pythontutorial.net #
 
PREVIOUS NEXT
Tagged: #read #file #python
ADD COMMENT
Topic
Name
3+3 =