Can't figure this one out and there doesn't seem to be any info on the web either. Tried it with both Python 2 and 3.
def load_settings():
try:
with open('settings.txt', 'r') as f:
return f.read()
except FileNotFoundError:
with open('settings.txt', 'w') as f:
f.write('default_settings')
load_settings()
I would expect the above function to return 'default_settings' given that settings.txt doesn't already exist. Instead it returns None
.