@@ -58,18 +58,105 @@ that the code is correct to the best of our knowledge. See
58
58
Python
59
59
------
60
60
61
- We do what others do :
61
+ We do what others in the python community have established :
62
62
63
63
* We follow PEP8 _.
64
64
* We test using check.py _ which combines `pep8.py ` and `pyflakes `.
65
- * Pocoo _ has good guidelines as well, let's steal them .
65
+ * We follow Pocoo _'s extensions of PEP8 _ as they are well thought out .
66
66
67
- Also, spaces matter:
67
+ Import Statements
68
+ ^^^^^^^^^^^^^^^^^
69
+
70
+ We expand on PEP8 _'s suggestions for import statements. These greatly improve
71
+ ones ability to ascertain what is and isn't available in a given file.
72
+
73
+ Import one module per import statement::
74
+
75
+ import os
76
+ import sys
77
+
78
+ not::
79
+
80
+ import os, sys
81
+
82
+ Separate imports into groups with a line of whitespace:
83
+ standard library; Django (or framework); third-party; and local imports::
84
+
85
+ import os
86
+ import sys
87
+
88
+ from django.conf import settings
89
+
90
+ import pyquery
91
+
92
+ from myapp import models, views
93
+
94
+
95
+ Alphabetize your imports, it will make your code easier to scan. See how terrible this is::
96
+
97
+ import cows
98
+ import kittens
99
+ import bears
100
+
101
+ A simple sort::
102
+
103
+ import bears
104
+ import cows
105
+ import kittens
106
+
107
+ Imports on top, ``from ``-imports below::
108
+
109
+ import x
110
+ import y
111
+ import z
112
+ from bears import pandas
113
+ from xylophone import bar
114
+ from zoos import lions
115
+
116
+ That's loads easier to read than::
117
+
118
+ from bears import pandas
119
+ import x
120
+ from xylophone import bar
121
+ import y
122
+ import z
123
+ from zoos import lions
124
+
125
+
126
+ Lastly, when importing things into your namespace from a package use an alphabetized
127
+ ``CONSTANT ``, ``Class ``, ``var `` order::
128
+
129
+ from models import DATE, TIME, Dog, Kitteh, upload_pets
130
+
131
+
132
+ If possible though, it may be easier to import the entire package, especially for methods
133
+ as it help answers the question, "where did ``you `` come from?"
134
+
135
+ Bad::
136
+
137
+ from foo import you
138
+
139
+
140
+ def my_code():
141
+ you() # wait, is this defined in this file?
142
+
143
+
144
+ Good::
145
+
146
+ import foo
147
+
148
+
149
+ def my_code():
150
+ foo.you() # oh you...
151
+
152
+
153
+ Whitespace matters
154
+ ^^^^^^^^^^^^^^^^^^
68
155
69
156
* Use 4 spaces, not 2---it increases legibility considerably.
70
157
* Never use tabs---history has shown that we cannot handle them.
71
158
72
- Use single quotes unless you need double (or triple) quotes::
159
+ Use single quotes unless double (or triple) quotes would be an improvement ::
73
160
74
161
'this is good'
75
162
0 commit comments