How do I get each python import on a different line when using Alt+Enter to magically import in Pycharm?

Viewed 536

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:

Editor > Code Style > Python

Editor > General > Code Folding

Editor > General > Auto Import

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?

3 Answers

This can now be done easily:

Settings > Code Style > Python > Imports

Then under Structure of "from" imports check the Always split imports option.

Image of import settings

Related