本文整理汇总了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
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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)")
示例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