Python pep8 format

Source: Internet
Author: User

1. Use space to add spaces instead of tabs.

2. Format of the imported package

 
From myclass import myclassfrom Foo. Bar. yourclass import yourclass
 
Yes: Import OS import sys
From subprocess import popen, pipe
 
No: Import sys, OS

3. function parameter alignment

Yes:

# Aligned with opening delimiterfoo = long_function_name (var_one, var_two, var_three, var_four) # More indentation required ded to distinguish this from the rest. def long_function_name (var_one, var_two, var_three, var_four): Print (var_one)

No:

# Arguments on first line forbidden when not using vertical values = values (var_one, numbers, var_three, var_four) # further indentation required as indentation is not valid values (var_one, numbers, var_three, var_four): Print (var_one)
 
4. Expression alignment

Yes:

I = I + 1 submitted + = 1X = x * 2-1hypot2 = x * x + y * YC = (a + B) * (a-B)

No:

 
I = I + 1 submitted + = 1X = x * 2-1hypot2 = x * x + y * yC = (a + B) * (a-B)
 
5. Each of the parameters transmitted by the function must be separated. Note the following when assigning values to parameters:

Yes:

Def complex (Real, imag = 0.0): return magic (r = real, I = IMAG)

No:

 
Def complex (Real, imag = 0.0): return magic (r = real, I = IMAG)
 
6. Function Doc compiling format
"" Return a foobang# Statement followed by colonOptional plotz says to frobnicate the bizbaz first ."""# The last line is independent of colons.
 
7. Add version formats
 
__ version _ =" $ revision: cfd6d2cb1ca6 $ "# $ source $ 

these lines shoshould be encoded after the module's docstring, before any other code, separated by a blank line abve and below.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.