当前位置: 首页>>代码示例>>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;未经允许,请勿转载。