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


Python builtins._屬性代碼示例

本文整理匯總了Python中builtins._屬性的典型用法代碼示例。如果您正苦於以下問題:Python builtins._屬性的具體用法?Python builtins._怎麽用?Python builtins._使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在builtins的用法示例。


在下文中一共展示了builtins._屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _verify_pre_check

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _verify_pre_check(filepath):
    """Check student code for certain issues."""
    # Make sure the program doesn't crash for students.
    # Could use some improvement for better logging and error reporting.
    try:
        # Check for inline "pylint:" comment, which may indicate a student
        # trying to disable a check.
        with tokenize.open(os.path.expanduser(filepath)) as f:
            for tok_type, content, _, _, _ in tokenize.generate_tokens(f.readline):
                if tok_type != tokenize.COMMENT:
                    continue
                match = pylint.constants.OPTION_RGX.search(content)
                if match is not None:
                    print('[ERROR] String "pylint:" found in comment. ' +
                          'No check run on file `{}.`\n'.format(filepath))
                    return False
    except IndentationError as e:
        print('[ERROR] python_ta could not check your code due to an ' +
              'indentation error at line {}.'.format(e.lineno))
        return False
    except tokenize.TokenError as e:
        print('[ERROR] python_ta could not check your code due to a ' +
              'syntax error in your file.')
        return False
    return True 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:27,代碼來源:__init__.py

示例2: test_original_displayhook

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def test_original_displayhook(self):
        import builtins
        out = io.StringIO()
        sys.stdout = out

        dh = sys.__displayhook__

        self.assertRaises(TypeError, dh)
        if hasattr(builtins, "_"):
            del builtins._

        dh(None)
        self.assertEqual(out.getvalue(), "")
        self.assertTrue(not hasattr(builtins, "_"))
        dh(42)
        self.assertEqual(out.getvalue(), "42\n")
        self.assertEqual(builtins._, 42)

        del sys.stdout
        self.assertRaises(RuntimeError, dh, 42) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_sys.py

示例3: displayhook

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def displayhook(value):
    """Override standard display hook to use non-locale encoding"""
    if value is None:
        return
    # Set '_' to None to avoid recursion
    builtins._ = None
    text = repr(value)
    try:
        sys.stdout.write(text)
    except UnicodeEncodeError:
        # let's use ascii while utf8-bmp codec doesn't present
        encoding = 'ascii'
        bytes = text.encode(encoding, 'backslashreplace')
        text = bytes.decode(encoding, 'strict')
        sys.stdout.write(text)
    sys.stdout.write("\n")
    builtins._ = value 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:rpc.py

示例4: get_file_paths

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def get_file_paths(rel_path):
    """A generator for iterating python files within a directory.
    `rel_path` is a relative path to a file or directory.
    Returns paths to all files in a directory.
    """
    if not os.path.isdir(rel_path):
        yield rel_path  # Don't do anything; return the file name.
    else:
        for root, _, files in os.walk(rel_path):
            for filename in (f for f in files if f.endswith('.py')):
                yield os.path.join(root, filename)  # Format path, from root. 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:13,代碼來源:__init__.py

示例5: id

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def id(self):
        return '_'.join(self._dt_test.name.split('.')) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:doctest.py

示例6: _test

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _test():
    parser = argparse.ArgumentParser(description="doctest runner")
    parser.add_argument('-v', '--verbose', action='store_true', default=False,
                        help='print very verbose output for all tests')
    parser.add_argument('-o', '--option', action='append',
                        choices=OPTIONFLAGS_BY_NAME.keys(), default=[],
                        help=('specify a doctest option flag to apply'
                              ' to the test run; may be specified more'
                              ' than once to apply multiple options'))
    parser.add_argument('-f', '--fail-fast', action='store_true',
                        help=('stop running tests after first failure (this'
                              ' is a shorthand for -o FAIL_FAST, and is'
                              ' in addition to any other -o options)'))
    parser.add_argument('file', nargs='+',
                        help='file containing the tests to run')
    args = parser.parse_args()
    testfiles = args.file
    # Verbose used to be handled by the "inspect argv" magic in DocTestRunner,
    # but since we are using argparse we are passing it manually now.
    verbose = args.verbose
    options = 0
    for option in args.option:
        options |= OPTIONFLAGS_BY_NAME[option]
    if args.fail_fast:
        options |= FAIL_FAST
    for filename in testfiles:
        if filename.endswith(".py"):
            # It is a module -- insert its dir into sys.path and try to
            # import it. If it is part of a package, that possibly
            # won't work because of package imports.
            dirname, filename = os.path.split(filename)
            sys.path.insert(0, dirname)
            m = __import__(filename[:-3])
            del sys.path[0]
            failures, _ = testmod(m, verbose=verbose, optionflags=options)
        else:
            failures, _ = testfile(filename, module_relative=False,
                                     verbose=verbose, optionflags=options)
        if failures:
            return 1
    return 0 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:43,代碼來源:doctest.py

示例7: _print_help

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _print_help(self, cmd, syntax, explanation):
        print(_('Command %s') % cmd)
        print(_('Syntax: %s') % syntax)
        print('\t', explanation)
        print()


    # predefined commands ##################################################### 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:10,代碼來源:cli.py

示例8: do_help

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def do_help(self, command=None) :
        """base input of the help system"""
        if command in self._command_help:
            self._print_help(*self._command_help[command])
        elif command is None or command not in self._topics:
            print(_("Use help <topic> or help <command>."))
            print(_("Available topics are:"))
            topics = list(self._topics.keys())
            topics.sort()
            for topic in topics:
                print('\t', topic)
            print()
            print(_("Available commands are:"))
            commands = list(self.commands.keys())
            commands.sort()
            for command in commands:
                print('\t', command[len(self.CMD_PREFIX):])
                
        else:
            print(_('Available commands about %s:') % command)
            print()
            for command_help_method in self._topics[command]:
                try:
                    if callable(command_help_method):
                        self._print_help(*command_help_method())
                    else:
                        self._print_help(*command_help_method)
                except:
                    import traceback
                    traceback.print_exc()
                    print('ERROR in help method %s'% (
                        command_help_method.__name__)) 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:34,代碼來源:cli.py

示例9: help_do_quit

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def help_do_quit(self):
        return ("quit", "quit", _("quit the application")) 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:4,代碼來源:cli.py

示例10: install

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def install():
    try:
        get_ipython
    except NameError:
        pass
    else:
        raise ValueError(
            "Don't install the default Python shell integration "
            "if you're using IPython, use the IPython integration with "
            "prettyprinter.install_extras(include=['ipython'])."
        )

    def prettyprinter_displayhook(value):
        if value is None:
            return

        builtins._ = None
        stream = StringIO()
        output = cpprint(
            value,
            width=get_terminal_width(default=79),
            stream=stream,
            end=''
        )
        output = stream.getvalue()

        try:
            sys.stdout.write(output)
        except UnicodeEncodeError:
            encoded = output.encode(sys.stdout.encoding, 'backslashreplace')
            if hasattr(sys.stdout, 'buffer'):
                sys.stdout.buffer.write(encoded)
            else:
                text = encoded.decode(sys.stdout.encoding, 'strict')
                sys.stdout.write(text)

        sys.stdout.write('\n')
        builtins._ = value

    sys.displayhook = prettyprinter_displayhook 
開發者ID:tommikaikkonen,項目名稱:prettyprinter,代碼行數:42,代碼來源:python.py

示例11: _load_plugins_from_path

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _load_plugins_from_path(self, path, prefix):
        load_function_name = "load_plugin"
        for _, module_name, _ in sorted(pkgutil.iter_modules(path, prefix), key=lambda x: x[1]):
            try:
                m = importlib.import_module(module_name)
                if hasattr(m, load_function_name):
                    f = getattr(m, load_function_name)
                    sig = inspect.signature(f)
                    if len(sig.parameters) == 0:
                        f()
                    else:
                        f(self)
            except Exception:
                logger.exception("Failed loading plugin '" + module_name + "'") 
開發者ID:thonny,項目名稱:thonny,代碼行數:16,代碼來源:backend.py

示例12: _install_repl_helper

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _install_repl_helper(self):
        def _handle_repl_value(obj):
            if obj is not None:
                try:
                    obj_repr = repr(obj)
                    if len(obj_repr) > 5000:
                        obj_repr = obj_repr[:5000] + "…"
                except Exception as e:
                    obj_repr = "<repr error: " + str(e) + ">"
                print("%s%s@%s%s" % (OBJECT_LINK_START, obj_repr, id(obj), OBJECT_LINK_END))
                self._heap[id(obj)] = obj
                builtins._ = obj

        setattr(builtins, _REPL_HELPER_NAME, _handle_repl_value) 
開發者ID:thonny,項目名稱:thonny,代碼行數:16,代碼來源:backend.py

示例13: _lookup_frame_by_id

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _lookup_frame_by_id(self, frame_id):
        def lookup_from_stack(frame):
            if frame is None:
                return None
            elif id(frame) == frame_id:
                return frame
            else:
                return lookup_from_stack(frame.f_back)

        def lookup_from_tb(entry):
            if entry is None:
                return None
            elif id(entry.tb_frame) == frame_id:
                return entry.tb_frame
            else:
                return lookup_from_tb(entry.tb_next)

        result = lookup_from_stack(inspect.currentframe())
        if result is not None:
            return result, "stack"

        if getattr(sys, "last_traceback"):
            result = lookup_from_tb(getattr(sys, "last_traceback"))
            if result:
                return result, "last_traceback"

        _, _, tb = sys.exc_info()
        return lookup_from_tb(tb), "current_exception" 
開發者ID:thonny,項目名稱:thonny,代碼行數:30,代碼來源:backend.py

示例14: _is_interesting_module_file

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def _is_interesting_module_file(self, path):
        # interesting files are the files in the same directory as main module
        # or the ones with breakpoints
        # When command is "resume", then only modules with breakpoints are interesting
        # (used to be more flexible, but this caused problems
        # when main script was in ~/. Then user site library became interesting as well)

        result = self._file_interest_cache.get(path, None)
        if result is not None:
            return result

        _, extension = os.path.splitext(path.lower())

        result = (
            self._get_breakpoints_in_file(path)
            or self._main_module_path is not None
            and is_same_path(path, self._main_module_path)
            or extension in (".py", ".pyw")
            and (
                self._current_command.get("allow_stepping_into_libraries", False)
                or (
                    path_startswith(path, os.path.dirname(self._main_module_path))
                    # main module may be at the root of the fs
                    and not path_startswith(path, sys.prefix)
                    and not path_startswith(path, sys.base_prefix)
                    and not path_startswith(path, site.getusersitepackages() or "usersitenotexists")
                )
            )
            and not path_startswith(path, self._thonny_src_dir)
        )

        self._file_interest_cache[path] = result

        return result 
開發者ID:thonny,項目名稱:thonny,代碼行數:36,代碼來源:backend.py

示例15: pytest_configure

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import _ [as 別名]
def pytest_configure(config):
    import builtins

    if not hasattr(builtins, "_"):
        builtins._ = lambda x: x 
開發者ID:jendrikseipp,項目名稱:rednotebook,代碼行數:7,代碼來源:conftest.py


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