2
CLI-ize ME
CLI-ize ME
It is what the name means!
It is what the name means!
Slide 3
Slide 3 text
3
Writing A CLI program
Writing A CLI program
●
It is not difficult with a library. (ex. argparse)
●
But it is annoying,
especially for the simple tasks.
Slide 4
Slide 4 text
4
At one midnight ...
At one midnight ...
I was thinking about the schema of the database.
●
initdb.py
●
cleardb.py
●
dropdb.py
...
●
db.py init
●
db.py clear
●
db.py drop
...
Slide 5
Slide 5 text
5
I opened the doc of
I opened the doc of argparse
argparse,
,
Slide 6
Slide 6 text
6
then felt sleepy …
then felt sleepy …
Slide 7
Slide 7 text
7
It shouldn't be long!
It shouldn't be long!
# file: db.py
def init():
pass
def clear():
pass
def drop():
pass
if __name__ == '__main__':
import sys
locals()[sys.argv[1]]()
Slide 8
Slide 8 text
8
But human wants are unlimited!
But human wants are unlimited!
Slide 9
Slide 9 text
9
After hardworking,
After hardworking,
Slide 10
Slide 10 text
10
Clime was released.
Clime was released.
Slide 11
Slide 11 text
11
It converts your program
It converts your program
# file: pyramid.py
def draw(story, squash=1):
ground_len = 1 + (story-1) * squash * 2
for i in range(1, ground_len+1, squash*2):
print ('*'*i).center(ground_len)
Slide 12
Slide 12 text
12
into a CLI program
into a CLI program
$ python pyramid.py --help
usage: [--squash]
or: draw [--squash]
$ python pyramid.py –-squash=5 3
*
***********
*********************
Slide 13
Slide 13 text
13
just by adding this line:
just by adding this line:
import clime.now