python模块

PyCon 比print()还要方便的q()

2018-08-14  本文已影响4人  布口袋_天晴了

关于PyCon大会,虽然知道 PyCon 的人不多,媒体报道少,但是,它依然是球最盛大也是最高级别的关于 Python 语言的会议了,全世界最牛的 Python 开发者都聚集在这里:PyCon 2018了解更多

q项目主页:https://github.com/zestyping/q

What is q ???

Quick and dirty debugging output for tired programmers.

为疲惫的程序员们创造的一种迅速而又随性的debug输出工具。


1. 安装q :

pip install -U q


2. 使用q模块:

2.1)All output goes to /tmp/q, which you can watch with this shell command:

tail -f /tmp/q

在windows的 命令行中尝试了该命令:-----虽然该命令不能查看,还可以通过其他方法查看。

可以跳过该命令,不影响对q模块的使用

2.2)直接在写Python程序:

使用 import q; q.q( )函数就能替代用print()、logging()语句。

2.3)找q模块的输出文件在哪里???

q.py源码:

这段代码的意思是:debugging日志会放入如下文件中,文件路径是去电脑的系统环境变量中查找  ‘TMPDIR’  or  ‘TEMP’  or  '/tmp',从前往后,先找到谁,就用谁。

通过上图,去相应的目录下查找,可以查到输出文件q

2.4)不想让debugging log输出文件放在我的C盘

方法很多:比如可以创建TMPDIR环境变量,固定q文件输出路径。

可以自己尝试。


3)q模块的其他用法:

To print the value of something in the middle of an expression, insert "q()", "q/", or "q|". For example, give this statement:

file.write(prefix + (sep or ' ').join(items))

...you can print out various values without using any temporary variables:

file.write(prefix + q(sep or '').join(items)) # prints (sep or '')

file.write(q/prefix + (sep or '').join(items)) # prints prefix

file.write(q|prefix + (sep or '').join(items)) # prints the arg to write

To trace a function's arguments and return value, insert this this above the def:

import q

@q

To start an interactive console at any point in your code, call q.d():

import q;  q.d()

The following Lightning Talk shows how powerful using q can be.

上一篇 下一篇

猜你喜欢

热点阅读