本文整理匯總了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)