Code: Select all
def load_paras():
# Load operating parameters from default dictionary.
# The function returns a dictionary, which has keys for all parameters needed in the program.
# Any err loading parameters will result in default parameters and False.
try:
f = open(config_file_name, 'r')
par = json.load(f)
f.close()
return (par, False) # Return paras and False for file not found
except FileNotFoundError as e:
print('No configuration file found. Starting interactive session...')
return (paras_default, True) # Return default paras and True for file not found
I was able to run this script on PC so FileNotFoundError apparently exists on PC Python. Does it also exist in MicroPython? The doc says nothing about open():Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Logger_1_3_2.py", line 198, in <module>
File "Logger_1_3_2.py", line 111, in load_paras
NameError: name 'FileNotFoundError' is not defined
http://docs.micropython.org/en/latest/p ... .html#open
How would I go about testing whether a file exists or not? Thanks.