本文整理汇总了Python中org.python.core.Py.compile_command_flags方法的典型用法代码示例。如果您正苦于以下问题:Python Py.compile_command_flags方法的具体用法?Python Py.compile_command_flags怎么用?Python Py.compile_command_flags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.Py
的用法示例。
在下文中一共展示了Py.compile_command_flags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile_command
# 需要导入模块: from org.python.core import Py [as 别名]
# 或者: from org.python.core.Py import compile_command_flags [as 别名]
def compile_command(source, filename="<input>", symbol="single"):
r"""Compile a command and determine whether it is incomplete.
Arguments:
source -- the source string; may contain \n characters
filename -- optional filename from which source was read; default
"<input>"
symbol -- optional grammar start symbol; "single" (default) or "eval"
Return value / exceptions raised:
- Return a code object if the command is complete and valid
- Return None if the command is incomplete
- Raise SyntaxError, ValueError or OverflowError if the command is a
syntax error (OverflowError and ValueError can be produced by
malformed literals).
"""
if symbol not in ['single','eval']:
raise ValueError,"symbol arg must be either single or eval"
return Py.compile_command_flags(source,filename,symbol,Py.getCompilerFlags(),0)
示例2: execfile
# 需要导入模块: from org.python.core import Py [as 别名]
# 或者: from org.python.core.Py import compile_command_flags [as 别名]
#
# Test for bug 1758838
#
# execfile(<any file>) should not throw a NullPointerException
#
# The error only shows up in interactive interpretation (type "single" for the compilation).
# But we cannot use InteractiveInterpreter here since it catches all Exceptions,
# therefore we do the compilation 'by hand'.
#
from org.python.core import Py
from org.python.core import PySystemState
from org.python.util import PythonInterpreter
PySystemState.initialize()
interp = PythonInterpreter()
code = Py.compile_command_flags("execfile('test401/to_be_executed.py')", "<input>", "single", None, 1)
interp.exec(code)