-
Notifications
You must be signed in to change notification settings - Fork 2
/
outline
86 lines (42 loc) · 1.86 KB
/
outline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Tips and Tricks
5/1/2014
Matthew Cahn
Goals
1) Getting the job done
2) Maintainability
3) Style
Using if __name__ == '__main__' so your module can be imported.
Documenting with doc strings so help() works.
Command line parsing with optparse (if you're using an older version of Python) (Python < 2.7).
pyversion.py
Command line parsing.
commandline1.py -- Using sys.argv directly -- BAD
commandline2.py -- argparse (Python 2.7 or newer) -- define your options with code
commandline3.py -- docopt (add-on module) -- define your options with documentation
Interleave two or more lists.
The itertools module
zip.py
Produce a counter while iterating.
enumerate.py
The built-in set type -- unions, intersections, etc.
sets.py -- (Python >= 2.6)
List, dictionary, and set comprehensions -- a concise way to create these objects.
comprehensions.py -- (Python >= 3.0.0 for list, dictionary and set comprehensions)
(Python >= 2.0.0 -- list comprehensions only)
The dictionary setdefault method -- set the default value for a key, or return the current value.
The doctest module -- test a module according to the doc string.
Everything in Python is a reference.
dictsAndDoctest.py
The collections module -- Counter, defaultdict
collectionsDemo.py -- (Counter: Python >= 2.7, defaultdict: Python >= 2.5)
Function argument passing -- positional, keyword, and variable number of arguments.
arguments.py -- (Any Python version, but >= 3.0.0 for this particular example)
The logging module -- send messages to the screen, files, email, etc.
loggingDemo.py
loggingDemo.conf
Documentation:
The Global Module index: docs.python.org
docopt.org -- For the docopt module.
Also useful:
The Python Cookbook: http://code.activestate.com/recipes/langs/python/