Load module from python string without executing code -
i'm trying similar with: load module string in python
sometimes read source code provided user:
module = imp.new_module('appmodule') exec_(s, module.__dict__) sys.modules['appmodule'] = module return module
and import file
module = __import__(module_name, fromlist=_fromlist) return module
these modules loaded map objects , it'll used inside ide.
my problem is: if there method call outside if __name__ == '__main__':
code being executed , can interact ide.
how can import modules ignoring methods being executed?
the process of importing module requires code executed. interpreter creates new namespace , populates executing module's code new namespace global namespace, after can access values (remember def
, class
statements executable).
so maybe have educate users not write modules interact ide?
Comments
Post a Comment