当前位置: 首页>>代码示例>>Python>>正文


Python Console.get_locals方法代码示例

本文整理汇总了Python中console.Console.get_locals方法的典型用法代码示例。如果您正苦于以下问题:Python Console.get_locals方法的具体用法?Python Console.get_locals怎么用?Python Console.get_locals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在console.Console的用法示例。


在下文中一共展示了Console.get_locals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute_script

# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import get_locals [as 别名]
def execute_script(script, test_code, extra_locals, files):
    soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
    resource.setrlimit(resource.RLIMIT_CPU, (10, hard))
    checker = Console(locals_=extra_locals, files=files)
    feedback = checker.run_tests(script, test_code)
    output = checker.output
    return_code = 0
    if feedback:
        return_code = 1
    new_locals = checker.get_locals()
    resource.setrlimit(resource.RLIMIT_CPU, (soft, hard))
    return return_code, output, feedback, new_locals
开发者ID:henriquebastos,项目名称:pycursos-console,代码行数:14,代码来源:runner.py

示例2: test_saves_fp_on_locals

# 需要导入模块: from console import Console [as 别名]
# 或者: from console.Console import get_locals [as 别名]
    def test_saves_fp_on_locals(self):
        files = {'dummy.txt': 'oi'}
        console = Console(files=files)
        code = "fd = open('dummy.txt')"
        console.run_tests(code, TEST_CODE)

        locals_ = console.get_locals()
        json_data = pickle.dumps(locals_)
        new_locals = pickle.loads(json_data)
        console = Console(locals_=new_locals)
        code = "print fd.read()"
        console.run_tests(code, TEST_CODE)
        self.assertEqual('oi\n', console.output)
开发者ID:henriquebastos,项目名称:pycursos-console,代码行数:15,代码来源:tests.py


注:本文中的console.Console.get_locals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。