Python-覆盖print() [英] Python - Overridding print()

查看:422
本文介绍了Python-覆盖print()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mod_wsgi,想知道是否有可能覆盖print()命令(因为它没有用).

I'm using mod_wsgi and was wondering if it's possible to over-write the print() command (since it's useless).

这样做不起作用:

print = myPrintFunction

因为这是语法错误. :(

Since it's a syntax error. :(

推荐答案

打印不是Python 2.x中的函数,因此这不可能直接实现.

Print is not a function in Python 2.x, so this is not directly possible.

但是,您可以覆盖sys.stdout .

如果您使用的是Python 3.0,则其中打印现在是一个函数,前提是您具有正确的签名,然后您将可以使用该函数.另请参阅本网站中的相关问题.

If you are on Python 3.0 in which print is now a function what you have would then work, assuming you have the right signature. Also see a related question in this site.

这篇关于Python-覆盖print()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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