Pep 3105:打印结束? [英] Pep 3105: the end of print?

查看:73
本文介绍了Pep 3105:打印结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python 3.x中使''print''函数的优点和缺点很好

讨论:

http://mail.python.org/pipermail/pyt...er/ 056154.html


唉,看来这个pep的效果是让它变得不可能

来使用''打印这个名字''以向后兼容的方式。实际上,如果要在Python 2.x和Python 3.x中编译

程序,打印函数

(或带括号的print语句)不能使用''sep'',''end''和

''文件'''关键字。这反过来又无法支持在Python 2.x程序中使用尾随逗号打印

的效果,同时保留名称

''print''。


唯一的解决方法是定义另一个函数,名称为

*其他*比''print''。这个函数,比如print2,可以支持实现者想要的任何功能,因为它不会与Python

2.x打印语句冲突。

简而言之,pep 3105将*劝阻*而不是鼓励使用

名称''print''。它不会使大多数Python 2.x程序失效,而是
似乎更优雅的Python 3.x定义[你的名字在这里]函数

可用于另外,而不是排除,打印。


爱德华


PS自动翻译脚本的存在不会以任何方式改变上述

情况。充其量,这样的脚本可以改变打印语句到[你的名字在这里]的功能,但效果仍然是

取消名称''print''所有旨在支持的程序都是支持
Python 2.x和Python 3.x.

EKR

---- -------------------------------------------------- --------------

Edward K. Ream电子邮件: ed *******@charter.net

狮子座: http://webpages.charter.net/edreamleo/front.html

---------------- -------------------------------------------------- -


The pros and cons of making ''print'' a function in Python 3.x are well
discussed at:

http://mail.python.org/pipermail/pyt...er/056154.html

Alas, it appears that the effect of this pep would be to make it impossible
to use the name ''print'' in a backward compatible manner. Indeed, if a
program is to compile in both Python 2.x and Python 3.x, the print function
(or the print statement with parentheses) can not use the ''sep'', ''end'' and
''file'' keywords. This in turn makes it impossible to support the effect of
print with trailing comma in Python 2.x programs while retaining the name
''print''.

The only workaround would be to define yet another function, with a name
*other* than ''print''. This function, say print2, can support whatever
features the implementer wants because it does not collide with the Python
2.x print statement.

In short, pep 3105 will *discourage* rather than encourage the use of the
name ''print''. Rather than invalidating most Python 2.x programs, it would
seem more graceful for Python 3.x to define a [your name here] function that
can be used in addition to, rather than to the exclusion of, print.

Edward

P.S. The existence of an automated translation script does not change the
situation described above in any way. At best, such a script could change
print statements to [your name here] functions, but the effect would still
be the elimination of the name ''print'' in all programs that aim to support
Python 2.x and Python 3.x.

EKR
--------------------------------------------------------------------
Edward K. Ream email: ed*******@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------



推荐答案

Edward K Ream写道:
Edward K Ream wrote:

在Python 3.x中使''print''函数的优点和缺点很好

讨论:

http://mail.python.org/pipermail/pyt...er/056154.html


唉,这个pep的效果似乎是让以后向兼容的方式使用打印这个名字是不可能的。
The pros and cons of making ''print'' a function in Python 3.x are well
discussed at:

http://mail.python.org/pipermail/pyt...er/056154.html

Alas, it appears that the effect of this pep would be to make it impossible
to use the name ''print'' in a backward compatible manner.



您可以为Python 2.6提供补丁,以便您可以从__future__ import print_function

/>

并将''print''语句替换为''print''函数。


那说,为什么你不能使用``file.write()``而不是``print``?

虽然我经常在交互式使用中使用打印,但它几乎是

在我的所有真实代码中都不存在。


STeVe

You could offer up a patch for Python 2.6 so that you can do::

from __future__ import print_function

and have the ''print'' statement replaced by the ''print'' function.

That said, why can''t you use ``file.write()`` instead of ``print``?
While I use print quite frequently in interactive use, it''s pretty much
nonexistent in all my real code.

STeVe


您可以为Python 2.6提供补丁,以便您可以: :
You could offer up a patch for Python 2.6 so that you can do::

来自__future__ import print_function
from __future__ import print_function



这只适用于Python 2.6。开发人员可能希望支持Python

2.3到2.5更长一段时间:-)

This would only work for Python 2.6. Developers might want to support Python
2.3 through 2.5 for awhile longer :-)


为什么你不能使用``文件。 write()``而不是``print``?
why can''t you use ``file.write()`` instead of ``print``?



正是我的观点:pep 3105将强制取消名称''print''。


Edward

-------------------------------------------- ------------------------

Edward K. Ream电子邮件: ed ******* @ charter.net

Leo: http://webpages.charter.net/edreamleo/front.html

------ -------------------------------------------------- ------------

Precisely my point: pep 3105 will force the elimination of the name ''print''.

Edward
--------------------------------------------------------------------
Edward K. Ream email: ed*******@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------


不是主要版本的概念(1.x,2.x,3.x)他们

*可以*与以前的版本不兼容吗?


m。

Isn''t the very concept of major releases (1.x, 2.x, 3.x) that they
*can* be not backwards-compatible with previous releases?

m.


这篇关于Pep 3105:打印结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆