本文整理汇总了Python中code.InteractiveInterpreter.showsyntaxerror方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveInterpreter.showsyntaxerror方法的具体用法?Python InteractiveInterpreter.showsyntaxerror怎么用?Python InteractiveInterpreter.showsyntaxerror使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code.InteractiveInterpreter
的用法示例。
在下文中一共展示了InteractiveInterpreter.showsyntaxerror方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execfile
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
"Execute an existing file"
if source is None:
with tokenize.open(filename) as fp:
source = fp.read()
try:
code = compile(source, filename, "exec")
except (OverflowError, SyntaxError):
self.tkconsole.resetoutput()
print('*** Error in script or command!\n'
'Traceback (most recent call last):',
file=self.tkconsole.stderr)
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
else:
self.runcode(code)
示例2: showsyntaxerror
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename=None):
"""Override Interactive Interpreter method: Use Colorizing
Color the offending position instead of printing it and pointing at it
with a caret.
"""
tkconsole = self.tkconsole
text = tkconsole.text
text.tag_remove("ERROR", "1.0", "end")
type, value, tb = sys.exc_info()
msg = getattr(value, 'msg', '') or value or "<no detail available>"
lineno = getattr(value, 'lineno', '') or 1
offset = getattr(value, 'offset', '') or 0
if offset == 0:
lineno += 1 #mark end of offending line
if lineno == 1:
pos = "iomark + %d chars" % (offset-1)
else:
pos = "iomark linestart + %d lines + %d chars" % \
(lineno-1, offset-1)
tkconsole.colorize_syntax_error(text, pos)
tkconsole.resetoutput()
self.write("SyntaxError: %s\n" % msg)
tkconsole.showprompt()
示例3: execfile
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
"Execute an existing file"
if source is None:
source = open(filename, "r").read()
try:
code = compile(source, filename, "exec")
except (OverflowError, SyntaxError):
self.tkconsole.resetoutput()
tkerr = self.tkconsole.stderr
print>>tkerr, '*** Error in script or command!\n'
print>>tkerr, 'Traceback (most recent call last):'
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
else:
self.runcode(code)
示例4: showsyntaxerror
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename=None):
"""Extend base class method: Add Colorizing
Color the offending position instead of printing it and pointing at it
with a caret.
"""
text = self.tkconsole.text
stuff = self.unpackerror()
if stuff:
msg, lineno, offset, line = stuff
if lineno == 1:
pos = "iomark + %d chars" % (offset-1)
else:
pos = "iomark linestart + %d lines + %d chars" % \
(lineno-1, offset-1)
text.tag_add("ERROR", pos)
text.see(pos)
char = text.get(pos)
if char and char in IDENTCHARS:
text.tag_add("ERROR", pos + " wordstart", pos)
self.tkconsole.resetoutput()
self.write("SyntaxError: %s\n" % str(msg))
else:
self.tkconsole.resetoutput()
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
示例5: execfile
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
"Execute an existing file"
if source is None:
source = open(filename, "r").read()
try:
code = compile(source, filename, "exec")
except (OverflowError, SyntaxError):
self.tkconsole.resetoutput()
print('*** Error in script or command!\n'
'Traceback (most recent call last):',
file=self.tkconsole.stderr)
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
else:
self.runcode(code)
示例6: showsyntaxerror
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename):
self.stdout.write('\n')
with disabled_excepthook():
InteractiveInterpreter.showsyntaxerror(self, filename)
self.done_signal.emit(False, None)
示例7: execfile
# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
"Execute an existing file"
if source is None:
source = open(filename, "r").read()
try:
code = compile(source, filename, "exec", dont_inherit=True)
except (OverflowError, SyntaxError):
self.tkconsole.resetoutput()
print('*** Error in script or command!\n'
'Traceback (most recent call last):',
file=self.tkconsole.stderr)
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
else:
self.runcode(code)