In a shell script one might do something like:
myvar='default_value'
source myfile.sh
echo $myvar
where myfile.sh is something like:
echo "myvar='special_value'" > myfile.sh
I know several "safe" ways of doing this in python, but the only way I can think of getting similar behaviour in Python (albeit ugly and unsafe) is the following:
myvar = 'default_value'
myimport = 'from %s import *' % 'myfile'
exec(myimport)
print(myvar)
where myfile.py is in ./ and looks like:
myvar = 'special_value'
I guess I would be happiest doing something like:
m.myvar = 'default_value'
m.update(__import__(myimport))
and have the objects in m updated. I can't think of an easy way of doing this without writing something to loop over the objects.
import myfilethenmyvar = myfile.myvarorfrom myfile import myvar? You need to explain your use case and why that doesn't work.