Output options:
print WHAT, -p WHAT
String specifying what the output should contain:
'H' request headers 'B' request body 'h' response headers 'b' response body
The default behaviour is 'hb' (i.e., the response headers and body is
printed), if standard output is not redirected. If the output is piped
to another program or to a file, then only the response body is printed by
default.
使用
sys.stdout.isatty
判断stdout
是终端(“tty”)还是文件,并根据这一点打印不同的输出,例如:在
http
的手册页上,您可以找到以下内容这表明
http
在重定向输出时故意表现出不同的行为。要获得与未重定向输出相同的行为,可以使用(但还要注意,漂亮的打印与重定向的行为不同。)
相关问题 更多 >
编程相关推荐