[关闭]
@zhangyu756897669 2017-09-02T09:15:31.000000Z 字数 3431 阅读 531

在此处输入标题

项目:密码储物柜

  1. PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
  2. 'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
  3. 'luggage': '12345'}
  1. PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
  2. 'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
  3. 'luggage': '12345'}
  4. import sys
  5. if len(sys.argv) < 2:
  6. print('Usage: python pw.py [account] - copy account password')
  7. sys.exit()
  8. account = sys.argv[1] # first command line arg is the account name
  1. #! python3
  2. # pw.py - An insecure password locker program.
  3. PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
  4. 'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
  5. 'luggage': '12345'}
  6. import sys, pyperclip
  7. if len(sys.argv) < 2:
  8. print('Usage: py pw.py [account] - copy account password')
  9. sys.exit()
  10. account = sys.argv[1] # first command line arg is the account name
  11. if account in PASSWORDS:
  12. pyperclip.copy(PASSWORDS[account])
  13. print('Password for ' + account + ' copied to clipboard.')
  14. else:
  15. print('There is no account named ' + account)

该新代码在PASSWORDS字典中查找帐户名称。如果帐户名称是字典中的一个键,我们将获得与该键对应的值,将其复制到剪贴板,并打印一条消息,表示我们复制了该值。否则,我们打印一个消息,说没有帐号与该名称。

项目:将* 加入到wiki文章中

  1. Lists of animals
  2. Lists of aquarium life
  3. Lists of biologists by author abbreviation
  4. Lists of cultivars

然后运行bulletPointAdder.py程序,剪贴板将包含以下内容:

* Lists of animals
*
Lists of aquarium life
*Lists of biologists by author abbreviation
*
Lists of cultivars

步骤1:从剪贴板复制和粘贴

您想要bulletPointAdder.py程序执行以下操作:
1. 从剪贴板粘贴文字
2. 运行程序
3. 将新文本复制到剪贴板

  1. #! python3
  2. # bulletPointAdder.py - Adds Wikipedia bullet points to the start
  3. # of each line of text on the clipboard.
  4. import pyperclip
  5. text = pyperclip.paste()
  6. # TODO: Separate lines and add stars.
  7. pyperclip.copy(text)

步骤2:分隔文本行并添加星标

  1. 'Lists of animals\nLists of aquarium life\nLists of biologists by author
  2. abbreviation\nLists of cultivars'
  1. #! python3
  2. # bulletPointAdder.py - Adds Wikipedia bullet points to the start
  3. # of each line of text on the clipboard.
  4. import pyperclip
  5. text = pyperclip.paste()
  6. # Separate lines and add stars.
  7. lines = text.split('\n')
  8. for i in range(len(lines)): # loop through all indexes in the "lines" list
  9. lines[i] = '* ' + lines[i] # add star to each string in "lines" list
  10. pyperclip.copy(text)

步骤3:加入修改行

  1. #! python3
  2. # bulletPointAdder.py - Adds Wikipedia bullet points to the start
  3. # of each line of text on the clipboard.
  4. import pyperclip
  5. text = pyperclip.paste()
  6. # Separate lines and add stars.
  7. lines = text.split('\n')
  8. for i in range(len(lines)): # loop through all indexes for "lines" list
  9. lines[i] = '* ' + lines[i] # add star to each string in "lines" list
  10. text = '\n'.join(lines)
  11. pyperclip.copy(text)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注