The shortest way to open a text file is by using “with” command in the following manner:
with open(“file-name”, “r”) as fp:
fileData = fp.read()
#to print the contents of the file
print(fileData)
Technical Interview Questions
The shortest way to open a text file is by using “with” command in the following manner:
with open(“file-name”, “r”) as fp:
fileData = fp.read()
#to print the contents of the file
print(fileData)