The shortest way to open a text file is by using “with” command in the following manner:
Example:
- with open(“FILE NAME”, “r”) as fp:
- fileData = fp.read()
- # To print the contents of the file
- print(fileData)
Output:
"The data of the file will be printed."