本文整理汇总了Python中past.builtins.execfile方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.execfile方法的具体用法?Python builtins.execfile怎么用?Python builtins.execfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类past.builtins
的用法示例。
在下文中一共展示了builtins.execfile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_execfile
# 需要导入模块: from past import builtins [as 别名]
# 或者: from past.builtins import execfile [as 别名]
def test_execfile(self):
global numruns
if numruns:
return
numruns += 1
globals = {'a': 1, 'b': 2}
locals = {'b': 200, 'c': 300}
self.assertEqual(self.__class__.z, 2)
globals['z'] = 0
execfile(TESTFN, globals)
self.assertEqual(globals['z'], 2)
locals['z'] = 0
execfile(TESTFN, globals, locals)
self.assertEqual(locals['z'], 2)
# This test only works if we pass in a Mapping type.
class M(dict):
"Test mapping interface versus possible calls from execfile()."
def __init__(self):
self.z = 10
def __getitem__(self, key):
if key == 'z':
return self.z
raise KeyError
def __setitem__(self, key, value):
if key == 'z':
self.z = value
return
raise KeyError
locals = M()
locals['z'] = 0
execfile(TESTFN, globals, locals)
self.assertEqual(locals['z'], 2)
unlink(TESTFN)
self.assertRaises(TypeError, execfile)
self.assertRaises(TypeError, execfile, TESTFN, {}, ())
import os
self.assertRaises(IOError, execfile, os.curdir)
self.assertRaises(IOError, execfile, "I_dont_exist")