Skip to content

Commit d198fec

Browse files
committed
have a try using argparse lib
1 parent 572209f commit d198fec

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

py2016/try_argparse.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
just have a try with argparse.
3+
e.g. python try_argparse.py -v -c 10
4+
'''
5+
import argparse
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument("-v", "--verbose", help="increase output verbosity",
8+
action="store_true")
9+
parser.add_argument("-c", "--copy", help="use * copies")
10+
args = parser.parse_args()
11+
if args.verbose:
12+
print "verbosity turned on"
13+
else:
14+
print "No --verbose arg"
15+
if args.copy:
16+
copies = int(args.copy)
17+
for i in range(0, copies):
18+
print '%d copy' % i

0 commit comments

Comments
 (0)