Automate the Boring Stuff with Python:
Practical Programming for Total Beginners
(No Starch Press)
Al Sweigart (著)
[邦訳]
開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Automate the Boring Stuff with Python: Practical Programming for Total Beginners (Al Sweigart (著)、No Starch Press)のPart 2.(Automating Tasks)、Chapter 8.(Reading and Writing Files)、Practice Projects(Extending the Multiclipboard)を解いてみる。
Practice Projects(Extending the Multiclipboard)
コード(Emacs)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import shelve
import pyperclip
import sys
mcb_shelf = shelve.open('mcb')
if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
mcb_shelf[sys.argv[2]] = pyperclip.paste()
elif len(sys.argv) == 3 and sys.argv[1].lower() == 'delete':
del mcb_shelf[sys.argv[2]]
elif len(sys.argv) == 2:
if sys.argv[1].lower() == 'list':
pyperclip.copy(str(list(mcb_shelf.keys())))
elif sys.argv[1] in mcb_shelf:
pyperclip.copy(mcb_shelf[sys.argv[1]])
mcb_shelf.close()
入出力結果(Terminal, IPython)
$ ./mcb.py list $ echo [] [] $ echo clipboard | pbcopy $ ./mcb.py save key $ ./mcb.py list $ echo ['key'] [key] $ echo clipboard1 | pbcopy $ ./mcb.py save key1 $ ./mcb.py list $ echo ['key1', 'key'] [key1, key] $ ./mcb.py delete key $ ./mcb.py list $ echo ['key1'] [key1] $ ./mcb.py key1 $ echo clipboard1 clipboard1 $
0 コメント:
コメントを投稿