Parameters etc. are handled by dict.
I want to return the default value if there is no parameter definition (key).
val = None # Set default
if 'filename' in config:
val = config['filename']
Or with one liner
val = config['filename'] if 'filename' in config else None
There is a way to write it, but it is complicated.
I was able to set the default value when there was no key in the second argument of get!
val = config.get('filename', None)
It's easy to understand!
Recommended Posts