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 ? !
1 Answer
+ 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