+ 1

Python File Closing

Hey! I made a python code and every time I'm opening the file, it closes instantly. How can I fix this? Thanks for the answers! Have a nice day :)

28th Oct 2019, 6:36 PM
Wolfie
Wolfie - avatar
6 ответов
+ 2
You might be using the with statement? With the with statement you should know that the file will be automatically closed in the end. with open(filename) as f: #f would be opened here. #f would be closed here. Was that the problem?
28th Oct 2019, 7:36 PM
Seb TheS
Seb TheS - avatar
+ 2
One of the main advantages of using with is that it will automatically close the file, even though there were errors.
28th Oct 2019, 7:38 PM
Seb TheS
Seb TheS - avatar
0
Mirielle🐶 [Inactive] I don't know about those unexpected closes, but confusion about with statement sounded a more likely reason.
28th Oct 2019, 8:07 PM
Seb TheS
Seb TheS - avatar
0
For closing python code ,there is a one best process that is 'exit()'
30th Oct 2019, 12:23 PM
Souvick Mondal
Souvick Mondal - avatar