(
【1】sys.argv使用:
sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个“外部”很关键,所以那些试图从代码来说明它作用的解释一直没看明白。因为我们从外部取得的参数可以是多个,所以获得的是一个列表(list),也就是说sys.argv其实可以看作是一个列表,所以才能用[]提取其中的元素。其第一个元素是程序本身,随后才依次是外部给予的参数。
运行程序test.py
python test.py ==》文件名是sys.argv[0]
python test.py what ==? sys.argv[1] 第一个参数what
python test.py a,b,c,d,e,f ==>sys.argvv[2:] 是从第二个参数开始b,c,d,e,f
转博客:https://www.cnblogs.com/aland-1415/p/6613449.html
【2】pyperclip复制/粘贴
调用 pyperclip.paste()将返回剪贴板上的所有文本。 pyperclip.copy()粘贴到剪贴板上。
(1) test.txt中的文件,按ctrl+c复制到剪贴板上
Lists of animals
Lists of aquarium life
Lists of biologists by author abbreviation
Lists of cultivars
import pyperclip
text = pyperclip.paste()
# Separate lines and add stars.
lines = text.split('\n')
for i in range(len(lines)): # loop through all indexes in the "lines" list
lines[i] = '* ' + lines[i] # add star to each string in "lines" list
pyperclip.copy(text)
没行前面+‘*’ 粘贴到剪贴板上。若不用剪贴板则要打开文件,处理后要写入文件,更麻烦。
* Lists of animals
* Lists of aquarium life
* Lists of biologists by author abbreviation
* Lists of cultivars