if file is not present whether it will be created?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

if file is not present whether it will be created??

in open function

1st Oct 2016, 3:06 PM
Nithish Dongre
Nithish Dongre - avatar
2 Answers
+ 1
If you want to know If the file exists, you can do the following: try: open(filename, 'r') except: do something finally: do something else
1st Oct 2016, 5:53 PM
Serginho2750
Serginho2750 - avatar
+ 1
It will be created only in write mode
21st Oct 2016, 5:58 PM
Dmitrii Sky
Dmitrii Sky - avatar