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
"The data of the file will be printed."