'How do I get each python import on a different line when using Alt+Enter to magically import in Pycharm?
Currently if i do Alt+Enter on a function in a different module which isn't imported yet it simply adds it to a an existing import line.
Say I have:
from my_package.my_module import do_something
my_module.do_something()
Then I type:
from my_package.my_module import do_something
do_something()
do_something_else() # My new line
I love that I can simply Alt+Enter on do_something_else
and it gets imported. But what happens is this:
from my_package.my_module import do_something, do_something_else
do_something()
do_something_else()
While what I would like to happen is this:
from my_package.my_module import do_something
from my_package.my_module import do_something_else
do_something()
do_something_else()
I looked into the settings, but none of the ones I saw seemed right.
These are the ones I've looked at for now:
Where else can I look? Seems like something which should be possible. Maybe one of the options above is the one I'm looking for, but just didn't understand was the right one?
Solution 1:[1]
This can now be done easily:
Settings > Code Style > Python > Imports
Then under Structure of "from" imports
check the Always split imports
option.
Solution 2:[2]
Currently there does not seem to be a way to do this, but there is an open ticket that you can up vote if you would like to have this feature.
Solution 3:[3]
It seems to be possible now in Pycharm 2018.3 according to this comment here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | psarka |
Solution 3 | Ramil Aglyautdinov |