當前位置: 首頁>>代碼示例>>Python>>正文


Python InteractiveInterpreter.showsyntaxerror方法代碼示例

本文整理匯總了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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:PyShell.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:PyShell.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:17,代碼來源:PyShell.py

示例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() 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:29,代碼來源:PyShell.py

示例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) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:17,代碼來源:PyShell.py

示例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) 
開發者ID:marcus-oscarsson,項目名稱:pyqtconsole,代碼行數:8,代碼來源:interpreter.py

示例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) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:17,代碼來源:PyShell.py


注:本文中的code.InteractiveInterpreter.showsyntaxerror方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。