What is more pythonic ?
import os
import sys
import getopt
...
or
import os,sys,getopt,...
?
Import order does not matter. If a module relies on other modules, it needs to import them itself. Python treats each . py file as a self-contained unit as far as what's visible in that file.
Organize imports into groups: first standard library imports, then third-party imports, and finally local application or library imports. Order imports alphabetically within each group. Prefer absolute imports over relative imports. Avoid wildcard imports like from module import * .
You can write multiple modules separated by commas after the import statement, but this is not recommended in PEP8. Imports should usually be on separate lines. If you use from to import functions, variables, classes, etc., as explained next, you can separate them with a comma.
From PEP 8:
Imports should usually be on separate lines, e.g.:
Yes:
import os
import sys
No:
import sys, os
it's okay to say this though:
from subprocess import Popen, PIPE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With