前几天朋友让帮忙解决一个京东商城无法右键另存为图片的问题,写了一个小程序,更简单的解决这个问题,毕竟是个重复性比较高的工作。即便解决了右键问题操作还是非常繁琐,之后会遵循开源代码协议将源码公布。
程序是写好了,但是为了让程序看起来更炫(zhuang)酷(B)一些,想要在程序打开后的头部添加一个颜文字(字符画),并使用动画效果展现出来。让使用者觉得,WK,这author太牛了。哈哈 满满的虚荣。
import sys
from time import sleep
poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''
for char in poem:
sleep(0.1)
sys.stdout.write(char)
这里需要用到sys当中的 stdout 和stdin 重定向功能。
参照一下sys的原注释
28.1. sys — System-specific parameters and functions](//link.zhihu.com/?target=https%3A//docs.python.org/2/library/sys.html%3Fhighlight%3Dsys%23sys.stdout)File objects corresponding to the interpreter’s standard input, output and error streams. stdinis used for all interpreter input except for scripts but including calls to [input()](//link.zhihu.com/?target=https%3A//docs.python.org/2/library/functions.html%23input) and raw_input()**.stdout is used for the output of print** and expression** statements and for the prompts of input()**and raw_input()**. The interpreter’s own prompts and (almost all of) its error messages go tostderr. stdout and stderr needn’t be built-in file objects: any object is acceptable as long as it has a write() method that takes a string argument. (Changing these objects doesn’t affect the standard I/O streams of processes executed by os.popen()**, os.system()** or the exec() family of functions in the [os*](//link.zhihu.com/?target=https%3A//docs.python.org/2/library/os.html%23module-os) module.)