Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.4支持带有重定向器的打印操作>&燃气轮机;_Python_Python 3.x - Fatal编程技术网

Python 3.4支持带有重定向器的打印操作>&燃气轮机;

Python 3.4支持带有重定向器的打印操作>&燃气轮机;,python,python-3.x,Python,Python 3.x,我正在复习课本上的一些例子。以下源代码因以下回溯而失败: Traceback (most recent call last): File "make_db_file.py", line 39, in <module> storeDbase(db) File "make_db_file.py", line 12, in storeDbase print >> dbfile, key TypeError: unsupported operand typ

我正在复习课本上的一些例子。以下源代码因以下回溯而失败:

Traceback (most recent call last):
  File "make_db_file.py", line 39, in <module>
    storeDbase(db)
  File "make_db_file.py", line 12, in storeDbase
    print >> dbfile, key
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'
当我在Python2.7下运行这段代码时,它可以正常工作。谁能给我指一下正确的方向吗。在Python3.4中,
print
函数中发生了什么变化,使其无法在Python3.4中工作?

在Python3中,是一个函数,而不是一个关键字。因此,如果要重定向输出,必须设置可选参数
file
(默认值为),如下所示:

print(key, file=dbfile)

请看一看官方文档中关于Python 3中发生了哪些变化的段落。

,这非常有帮助。这在文档中吗?@d_blk是的,我添加了一个指向文档的链接,该链接将
print()
从Python 2更改为Python 3.:)
print(key, file=dbfile)