+ 1

Python - what is the difference between my_file.read() and reader(my_file)

Hi! Sololearn is using read() method for opening files. On one another site for learning Python,, they are using reader() object. What is the difference, when can i use one method and when should I use another method Code; file = open("filename.txt", "r") cont = file.read() print(cont) file.close() from csv import reader oppened_file = open('AppleStore.csv') read_file = reader(oppened_file) apps_data=list(read_file) Thx!

14th May 2019, 8:55 PM
Buzov Igor
Buzov Igor - avatar
2 Answers
+ 6
Look at the file extensions. One is for plain text files, the other for csv files. Btw, "with open(file, "r") as f:" is preferable to just open(file, "r"). The former makes sure that the file gets closed again (whatever happens).
14th May 2019, 9:16 PM
Thoq!
Thoq! - avatar
0
Thoq!, thank you very much!
16th May 2019, 5:36 PM
Buzov Igor
Buzov Igor - avatar