I'm trying to use a python file as a config file. In my real program, I let the user specify the config file at the command line.
Here's my example:
some_randomly_named_file.py
:
import os
from datetime import timedelta
PROJECT = "my project"
ENABLED_FORMATS = ['xml', 'json', 'yaml']
EXPIRATION=3600
#DEBUG = True
#TESTING = False
LOG_FOLDER = os.path.join(os.path.expanduser('~'), 'logs')
The file is stored here: /foo/bar/baz/some_randomly_named_file.py
...and then in myapp.py
:
# parse the command line and get the path
path_to_file = '/foo/bar/baz/some_randomly_named_file.py'
# load the python file at path_to_file into local variable myconfig
# [What do I write here to accomplish this?]
# And now we have a local variable called myconfig
print(myconfig.PROJECT)
Output:
my project