Just now , I read a piece of code which was written in Python, I feel very doubtful to some python native API. the code as following:
filename = os.path.join(self.root_path, filename)
d = imp.new_module('config')
d.__file__ = filename
try:
with open(filename) as config_file:
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
except IOError as e:
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
return False
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
raise
I have two doubts about the code ,please help to answer them.
doubt 1.
compile(config_file.read(), filename, 'exec')
What's the functions about the compile function's second argument filename ?
doubt 2.
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
What's the functions about the exec function's second argument d.__dict__ ?
Thanks!