Tuesday, January 31, 2012

Dynamically reloading Python modules

Dynamically reloading Python modules is basically risky as hell.

here're a few lines to start off intrepid investigation.

module = __import__(module_importable_name, fromlist=['*'])
os.system('touch {}'.format(module.__file__))
reload(module)
attribute = getattr(module, attribute_name)

What's the system call to touch doing there? Just something else to throw in the mix when trying to debug why Python seems not to have reloaded such and such an attribute this time around.

Seriously. Much better to avoid reloading altogether.

No comments: