Python coding standard 03- Base Specification --import statement

1, import statements should write Branch

# Correct wording 
Import os
 Import SYS 

# is not recommended wording 
Import SYS, os 

# correct wording 
from subprocess Import Popen, PIPE

2, import statements should use absolute import

# Correct wording 
from foo.bar Import Bar 

# is not recommended wording 
from ..bar Import Bar

3, import statements should be placed in the file header, after a string of the module comments and documents, before the global variables and constants module;

4, import statements should be arranged in order, separated by a blank line between each

import os
import sys

import msgpack
import zmq

import foo

5. If a naming conflict occurs, you can use the namespace

import bar
import foo.bar

bar.Bar()
foo.bar.Bar()

6, should be introduced in order from most general to least general order of the packet:

  Import Standard Library

  Import third-party libraries

  Application specifies import

Guess you like

Origin www.cnblogs.com/mazhiyong/p/12504317.html