本文整理汇总了Python中types.ModuleType.__dict__['__file__']方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__dict__['__file__']方法的具体用法?Python ModuleType.__dict__['__file__']怎么用?Python ModuleType.__dict__['__file__']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.__dict__['__file__']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modify_document
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __dict__['__file__'] [as 别名]
def modify_document(self, doc):
if self.failed:
return
from types import ModuleType
module_name = 'bk_script_' + str(uuid.uuid4()).replace('-', '')
module = ModuleType(module_name)
module.__dict__['__file__'] = abspath(self._path)
# This is to prevent the module from being gc'd before the
# document is. A symptom of a gc'd module is that its
# globals become None.
if not hasattr(doc, '_ScriptHandler__modules'):
setattr(doc, '_ScriptHandler__modules', [])
doc.__modules.append(module)
old_doc = curdoc()
set_curdoc(doc)
old_io = self._monkeypatch_io()
try:
exec(self._code, module.__dict__)
newdoc = curdoc()
# script is supposed to edit the doc not replace it
if newdoc is not doc:
raise RuntimeError("Script at '%s' replaced the output document" % (self._path))
except Exception as e:
self._failed = True
import traceback
self._error_detail = traceback.format_exc()
exc_type, exc_value, exc_traceback = sys.exc_info()
filename, line_number, func, txt = traceback.extract_tb(exc_traceback)[-1]
self._error = "%s\nFile \"%s\", line %d, in %s:\n%s" % (str(e), os.path.basename(filename), line_number, func, txt)
finally:
self._unmonkeypatch_io(old_io)
set_curdoc(old_doc)
示例2: new_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __dict__['__file__'] [as 别名]
def new_module(self):
"""Make a fresh module to run in."""
if self.failed:
return None
module_name = 'bk_script_' + str(uuid.uuid4()).replace('-', '')
module = ModuleType(module_name)
module.__dict__['__file__'] = abspath(self._path)
return module
示例3: new_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __dict__['__file__'] [as 别名]
def new_module(self):
''' Make a fresh module to run in.
Returns:
Module
'''
if self.failed:
return None
module_name = 'bk_script_' + make_id().replace('-', '')
module = ModuleType(module_name)
module.__dict__['__file__'] = os.path.abspath(self._path)
return module
示例4: new_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __dict__['__file__'] [as 别名]
def new_module(self):
''' Make a fresh module to run in.
Returns:
Module
'''
self.reset_run_errors()
if self._code is None:
return None
module_name = 'bk_script_' + make_id().replace('-', '')
module = ModuleType(str(module_name)) # str needed for py2.7
module.__dict__['__file__'] = os.path.abspath(self._path)
return module