Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PyCharm's optimize imports also alphabetize them?

Tags:

python

pycharm

I am enjoying PyCharm's optimizing of Python imports - as well as removing unused imports, following PEP8 gives them a sensible layout and makes them easier to read. Is there any way to get PyCharm to additionally alphabetize them (which would make scanning them faster, for me at least)?

like image 520
lofidevops Avatar asked Dec 09 '13 10:12

lofidevops


People also ask

What does optimize imports do Pycharm?

The Optimize Imports feature helps you remove unused imports and organize import statements in the current file or in all files in a directory at once according to the rules specified in Settings/Preferences | Editor | Code Style | <language> | Imports.

How do you optimize imports?

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.

How do you organize imports in Python?

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 * .

How do I organize imports in IntelliJ?

In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.


1 Answers

PyCharm does this automatically now by use of Code -> Optimize Imports. It also sorts them into groups per PEP 8.

See https://www.jetbrains.com/help/pycharm/optimizing-imports.html for details.

like image 138
Quark Avatar answered Oct 03 '22 11:10

Quark