How to open file and read | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to open file and read

13th Aug 2017, 7:16 AM
David
David - avatar
3 Answers
+ 2
var = open("filename.extension", "r")
22nd Oct 2018, 2:54 PM
Beyar
Beyar  - avatar
0
By using "with" statement is the safest way to handle a file operation in Python because "with" statement ensures that the file is closed when the block inside with is exited. with open("my_file.txt", "r") as my_file: # do some file operations http://net-informations.com/python/file/open.htm
15th Aug 2019, 6:28 AM
rahul kumar
rahul kumar - avatar