Original address http://python.net /~ Goodger/projects/pycon/2007/idiomatic/handout.html. I have chosen some important translations. In short,CodeIt is written to people, not to machines.
(1: four spaces are added for each indent level;
(2: Do not use the tab key (I have been using the tab key for a long time, which is very convenient. This is a bit unreasonable );
(3: Do not mix spaces and Tab keys;
(4: An empty line between functions;
(5: two empty rows between classes;
(1) Leave a space after the "," Sign of dicts, lists, tuples, and function functions; leave a space after the ":" sign of dicts;
(2: Leave a space for each assignment and comparison;
(3: Do not leave the parameters that are placed next to the right or left brackets blank, and do not leave them blank before the function parameter list;
(4: Do not leave it white in docstrings
(1: joined_lower, function, method, and attribute usage;
(2: joined_lower or all_caps, suitable for constant definition (Personal tends to all_caps );
(3: studlycaps, class name;
(4: camelcase, which is generally not used unless it is a continuation of the old Code habits;
(5: attribute interface, _ internal, _ private. Do not use _ private as much as possible. The reason is not translated. If it is long, it will be OK.
(1: Keep a row within 80 characters;
(2) (), [], {} contains the hidden cross-row connection function;
-
Def _ init _ (self, First, Second, Third,
-
Fourth, Th, sixth ):
-
Output = (first + second + third
-
+ Fourth + Th + sixth)
(3: In other cases, "\" is used for connection. Note that "\" must be the last letter of this line. The function of connecting any character will be invalid.
(1: the adjacent string is merged into a string by the parser;
(2: strings with the R prefix are not escaped;
(3: "+" is required for string variable connection ";
(4) use "Or ''' for cross-row strings ''''''.
Document string (docstring) is used to describe the purpose and usage of functions (for Users)
(1: Explains functions of a function;
(2: describes parameters, returned values, and possible exceptions;
(3: it is best to describe the call method, especially when this function has a very coupled caller.
Annotations are used to describe the implementation method of functions and maintain code (for developers and maintenance code owners)
(1 :#!!! BUG :...
(2 :#!!! Fix: This is a hack
(3 :#??? Why is this here?