当前位置: 首页>>代码示例>>Python>>正文


Python __future__.print_function方法代码示例

本文整理汇总了Python中__future__.print_function方法的典型用法代码示例。如果您正苦于以下问题:Python __future__.print_function方法的具体用法?Python __future__.print_function怎么用?Python __future__.print_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在__future__的用法示例。


在下文中一共展示了__future__.print_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fill_outputs

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def fill_outputs(gd):
    """
    Fills the output lists of of a graph of ParsedNode

    Takes a graph in "dict{str, ParsedNode}" form, and returns a new graph.
    """
    # fill outputs
    for k, v in gd.items():
        for i in v.inputs:
            gd[i].outputs.append(v.name)
        for i in v.control_inputs:
            gd[i].control_outputs.append(v.name)
    get_tuple_ops = ["Split", "SplitV", "LSTMBlock"]
    for k, v in gd.items():
        if v.op in get_tuple_ops:
            outputs = [[out, int(gd[out].attr["index"])] for out in v.outputs]
            outputs.sort(key=lambda x: x[1])
            gd[k].outputs = [out for [out, _] in outputs]

    return gd 
开发者ID:apple,项目名称:coremltools,代码行数:22,代码来源:basic_graph_ops.py

示例2: const_elimination

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def const_elimination(prog):
    """
    prog: Program

    # Replace non-const ops that have const Var
    # outputs replaced with const op. Example:
    #
    # Given:
    #   %2, %3 = non_const_op(...)  # %2 is const, %3 isn't const
    #   %4 = other_op(%2, %3)
    #
    # Result:
    #   _, %3 = non_const_op(...)  # _ is the ignored output
    #   %2_const = const(mode=m)  # %2_const name is for illustration only
    #   %4 = other_op(%2_const, %3)
    #
    # where m is 'file_value' / 'immediate_value' depending on heuristics
    # in get_const_mode.
    """
    for f_name, f in prog.functions.items():
        const_elimination_block(f) 
开发者ID:apple,项目名称:coremltools,代码行数:23,代码来源:const_elimination.py

示例3: _check_adc

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def _check_adc():
  """Return whether the application default credential exists and is valid."""
  # google-auth wants to warn the user if no project is set, which makes sense
  # for cloud-only users, but not in our case. We temporarily chnage the logging
  # level here to silence.
  logger = _logging.getLogger()
  log_level = logger.level
  logger.setLevel(_logging.ERROR)
  try:
    creds, _ = _google_auth.default()
  except _google_auth.exceptions.DefaultCredentialsError:
    return False
  finally:
    logger.setLevel(log_level)
  transport = _auth_requests.Request()
  try:
    creds.refresh(transport)
  except Exception as e:  # pylint:disable=broad-except
    _logging.info('Failure refreshing credentials: %s', e)
  return creds.valid 
开发者ID:googlecolab,项目名称:colabtools,代码行数:22,代码来源:auth.py

示例4: fix_future

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def fix_future(self, token):
        """ Fix print_function, absolute_import, with_statement.
        """
        
        status = getattr(self, '_future_status', 0)
        if status == 2:
            return  # Done
        
        if status == 0 and token.type == 'string':
            self._future_status = 1  # docstring
        elif token.type != 'comment':
            self._future_status = 2  # done
            i = max(0, token.find_backward('\n'))
            t = Token(token.total_text, '', i, i)
            t.fix = '\nfrom __future__ import %s\n' % (', '.join(self.FUTURES))
            return t 
开发者ID:flexxui,项目名称:pscript,代码行数:18,代码来源:translate_to_legacy.py

示例5: _run_doctest_for_content

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def _run_doctest_for_content(self, name, content):
        optionflags = (
            doctest.ELLIPSIS
            | doctest.NORMALIZE_WHITESPACE
            | doctest.IGNORE_EXCEPTION_DETAIL
            | _get_allow_unicode_flag()
        )
        runner = doctest.DocTestRunner(
            verbose=None,
            optionflags=optionflags,
            checker=_get_unicode_checker(),
        )
        globs = {"print_function": print_function}
        parser = doctest.DocTestParser()
        test = parser.get_doctest(content, globs, name, name, 0)
        runner.run(test)
        runner.summarize()
        assert not runner.failures 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_tutorials.py

示例6: _patchTestCase

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def _patchTestCase(self, case):
        if case:
            case._dt_test.globs['print_function'] = print_function
            case._dt_checker = _checker
        return case 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:7,代码来源:doctest_nose_plugin.py

示例7: strip_future_imports

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def strip_future_imports(self, code):
        """
        Strips any of these import lines:

            from __future__ import <anything>
            from future <anything>
            from future.<anything>
            from builtins <anything>

        or any line containing:
            install_hooks()
        or:
            install_aliases()

        Limitation: doesn't handle imports split across multiple lines like
        this:

            from __future__ import (absolute_import, division, print_function,
                                    unicode_literals)
        """
        output = []
        # We need .splitlines(keepends=True), which doesn't exist on Py2,
        # so we use this instead:
        for line in code.split('\n'):
            if not (line.startswith('from __future__ import ')
                    or line.startswith('from future ')
                    or line.startswith('from builtins ')
                    or 'install_hooks()' in line
                    or 'install_aliases()' in line
                    # but don't match "from future_builtins" :)
                    or line.startswith('from future.')):
                output.append(line)
        return '\n'.join(output) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:35,代码来源:base.py

示例8: transform

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def transform(self, node, results):
        future_import(u"unicode_literals", node)
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:fix_add_all__future__imports.py

示例9: transform

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def transform(self, node, results):
        # Add the __future__ import first. (Otherwise any shebang or encoding
        # comment line attached as a prefix to the print statement will be
        # copied twice and appear twice.)
        future_import(u'print_function', node)
        n_stmt = super(FixPrintWithImport, self).transform(node, results)
        return n_stmt 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:fix_print_with_import.py

示例10: transform

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def transform(self, node, results):
        # Reverse order:
        future_import(u"print_function", node)
        future_import(u"division", node)
        future_import(u"absolute_import", node) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:fix_add__future__imports_except_unicode_literals.py

示例11: _check_print_function

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def _check_print_function(self, node):
    """Verify print_function is imported"""
    if node.modname == '__future__':
      for name, _ in node.names:
        if name == 'print_function':
          self.seen_print_func = True 
开发者ID:JeetShetty,项目名称:GreenPiThumb,代码行数:8,代码来源:lint.py

示例12: remove_commons

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def remove_commons(module_name, exceptions=[]):
    import sys
    _commons = [
        'absolute_import',
        'division'
        'print_function',
        'remove_commons',
    ]
    module = sys.modules[module_name]
    for _common in _commons:
        if _common not in exceptions:
            try:
                delattr(module, _common)
            except:
                None 
开发者ID:taehoonlee,项目名称:tensornets,代码行数:17,代码来源:utils.py

示例13: main

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def main(unused_argv):
  doc_generator = generate_lib.DocGenerator(
      root_title="TensorFlow Model Optimization",
      py_modules=[("tfmot", tfmot)],
      base_dir=os.path.dirname(tfmot.__file__),
      code_url_prefix=FLAGS.code_url_prefix,
      search_hints=FLAGS.search_hints,
      site_path=FLAGS.site_path,
      # TODO(tfmot): remove this once the next release after 0.3.0 happens.
      # This is needed in the interim because the API docs reflect
      # the latest release and the current release still wildcard imports
      # all of the classes below.
      private_map={
          "tfmot.sparsity.keras": [
              # List of internal classes which get exposed when imported.
              "InputLayer",
              "custom_object_scope",
              "pruning_sched",
              "pruning_wrapper",
              "absolute_import",
              "division",
              "print_function",
              "compat"
          ]
      },
  )

  doc_generator.build(output_dir=FLAGS.output_dir) 
开发者ID:tensorflow,项目名称:model-optimization,代码行数:30,代码来源:build_docs.py

示例14: test_future_print

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def test_future_print(self):
        self.assertParsesSuite(
            [{"ty": "ImportFrom",
              "names": [{"ty": "alias", "name": "print_function", "asname": None}],
              "module": "__future__", "level": 0},
             {"ty": "Expr", "value":
                {"ty": "Call", "func": {"ty": "Name", "id": "print", "ctx": None},
                 "starargs": None, "kwargs": None, "args": [self.ast_x], "keywords": []}}],
            "from __future__ import print_function·print(x)") 
开发者ID:m-labs,项目名称:pythonparser,代码行数:11,代码来源:test_parser.py

示例15: add_flags

# 需要导入模块: import __future__ [as 别名]
# 或者: from __future__ import print_function [as 别名]
def add_flags(self, flags):
        if "print_function" in flags:
            self.lexer.print_function = True
        if "unicode_literals" in flags:
            self.lexer.unicode_literals = True

    # Grammar 
开发者ID:m-labs,项目名称:pythonparser,代码行数:9,代码来源:parser.py


注:本文中的__future__.print_function方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。