我可以在 python-3.x 中绑定 python-2.7 的 `print`,允许我在 python-3.x 中使用不带括号的 `print` 吗? [英] Can I bind python-2.7's `print` in python-3.x, allowing me to use `print` without parenthesis in python-3.x?

查看:33
本文介绍了我可以在 python-3.x 中绑定 python-2.7 的 `print`,允许我在 python-3.x 中使用不带括号的 `print` 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 python 2print "TEXT"print("TEXT") 相比,它不使用无括号蟒蛇3.

I like python 2's print "TEXT" which does not use without parenthesis, compared to print("TEXT") in python 3.

我可以通过将 python 2 绑定到诸如 pr 之类的东西来保留它以供使用吗?

Can I keep the python 2 print around to use by binding it to something like pr?

我知道在这个线程中已经讨论过,但这没有作为解决方案之一被提及:Python 3 不带括号打印

I understand has been discussed in this thread, but this wasn't mentioned as one of the solutions: Python 3 print without parenthesis

(顺便说一下,我的问题是输入和转义括号.() 键比空格键更难按下.另外,因为我的IDE 会自动将它们放入,然后我需要将光标移出它.)

(By the way, the issue for me is typing and escaping the brackets. The keys ( and ) harder to press than a space bar. Also, because my IDE puts them in automatically, I then need to move my cursor out of it.)

这既不是所指出的问题的重复,也不是我问如何使用没有括号的 python-3.x 打印. 相反,我特别问我是否可以绑定一个python 2 函数(大概是在导入之后).如果答案是否定的,那就是新信息.

This is neither a duplicate of the question as indicated NOR am I asking how to use python-3.x's print without parenthesis. Instead, I'm specifically asking if I can bind a python 2 function (presumably after importing it). If the answer is no, that is new information.

推荐答案

为了实现你想要的你需要定义你自己的关键字,但是你不能这样做,因为你不能定义或重新定义语言关键字没有重写编译器/解释器等.

In order to achieve what you want you need to define your own keyword, but you can't do this as you can't define or redefine language keywords without rewriting a compiler/interpreter/etc.

这篇关于我可以在 python-3.x 中绑定 python-2.7 的 `print`,允许我在 python-3.x 中使用不带括号的 `print` 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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