How do I do monkeypatching in python?

I've had to do some introspection in python and it wasn't pretty:

name = sys._getframe(1).f_code
name = "%s:%d %s()" %(os.path.split(name.co_filename)[1],name.co_firstlineno,name.co_name)

To get something like

foo.py:22 bar() blah blah

In our debugging output.

I'd ideally like to prepend anything to stderr with this sort of information -- Is it possible to change the behaviour of print globally within python?


打印语句通过“sys.stdout.write”执行其IO,因此如果要操作打印流,则可以覆盖sys.stdout。


python inspect模块使得这更容易和更清洁。

链接地址: http://www.djcxy.com/p/41774.html

上一篇: 将“.local”子域重定向到单播DNS

下一篇: 我如何在python中进行monkeypatching?