python - Change imported values by values in user-supplied file -


i have package called pgk1. it's __init__.py contains

from defaults.py import * 

defaults.py contains definiton of scalars, lists, dictionaries, i.e.

constant = "c1" special_dirs = {"opt_dir1": "/path/to/dir1", "opt_dir2": "/path/to/dir2"}` 

and main.py contains

import pkg1 print pkg1.special_dirs["opt_dir1"] 

i user able overwrite or of default constant values supling python user.py file in form

special_dirs["opt_dir2"] = "/path/somewhere/else" 

my question is, how dynamically overwrite values defaults.py values user.py can acccesed package constants, i.e.

print pkg1.special_dirs["opt_dir2"] 

would yield

/path/somewhere/else 

file defaults.py contain basic python type , user might want modify 1 key in existing dict.

i can prepare user.py in form

import pkg1 pkg1.special_dirs["opt_dir2"] = "/path/somewhere/else" 

and import in main.py , desired results.

but wonder if there better solution importing file in middle of other code.


Comments