Home  >  Article  >  Backend Development  >  Problems with one-line and multi-line import modules in Python_python

Problems with one-line and multi-line import modules in Python_python

不言
不言Original
2018-04-02 16:13:361958browse

Through this article, we have analyzed why Python does not recommend using one line to import all modules. Friends who are interested can learn more.

Python does not recommend using one line to import all modules. Instead, it is recommended to use multiple lines of import to import modules. More for operational convenience reasons than import barney, betty, wilma, fred, bambam, pebbles are easier to find.

    Easier to search

  • You can search for the location immediately through keywords import fred, and import barney , fred can’t.

    Easier to edit:

  • Faster insertion and removal;

Only declare one module per line, so you don’t need to work hard to find where the module is;

  • When moving a module, just move the entire line;

  • When copying multiple modules to other Python files, you only need to copy and paste a few lines, instead of struggling to find the module you want in a line of import statements.

  • Multi-line import is easier to maintain
  • Once the module is modified, you can directly know which module has the error based on the number of error lines. , and one line of import will be troublesome;

If you miss or add a module, you can also feel it through the number of lines and the changed position.

Summary


Multi-line import is more for the convenience of editing (copying, pasting, deleting) and maintenance, and the ease of Searching seems trivial, since most people would write import at the beginning of a Python file, and searching the front of the file shouldn't be difficult.

Related recommendations:

Analyze the method of importing modules in python at different levels of directories

##

The above is the detailed content of Problems with one-line and multi-line import modules in Python_python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn