mod = __import__(modname)
for name in dir(mod):
    original_mod = inspect.getmodule(getattr(mod, name))
if original_mod.__name__ == 'numpy':
    src = src.replace(name, 'numpy.' + name)
elif original_mod.__name__ == 'scipy':
    src = src.replace(name, 'scipy.' + name)
with open(modname + '.tmp') as dstfile:
    dstfile.write(src)
os.rename(modname + '.py', modname + '.bak')
os.rename(modname + '.tmp', modname + '.py')
Отмена импорта модуля *