0

reading files in python3

file = open("filename.txt", "r") cont = file.read() print(cont) file.close() in the code above does "filename.txt" exist in the system or it's created by the IDE ? and if it's the case why it prints an error when running the code ? !

15th Aug 2017, 11:41 AM
kazuto
1 Odpowiedź
+ 1
It has to exist and the error might be because the file does not exist. The open function needs a filename path that exist or not depending of the mode : a, r and their derivations (r+,a+,rb, ...) need an existing file w and its derivation doesn't need an existing file
15th Aug 2017, 11:48 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar