Code Style. Python
Use this page to configure formatting options for Python files. When you change these settings, the Preview pane shows how this will affect your code.
Item | Description |
---|---|
Use tab character |
|
Smart tabs |
The Smart Tabs checkbox is available if the Use tab character checkbox is selected. |
Tab size | In this field, specify the number of spaces included in a tab. |
Indent | In this field, specify the number of spaces (or tabs if the Use tab character checkbox is selected) to be inserted for each indent level. |
Continuation indent | In this field, specify the number of spaces (or tabs if the Use tab character checkbox is selected) to be inserted between the elements of an array, in expressions, method declarations and method calls. |
Keep indents on empty lines | If this checkbox is selected, PyCharm will keep indents on the empty lines as if they contained some code. If this checkbox is cleared, PyCharm will delete the tab characters and spaces. |
Spaces
Use this tab to specify where you want spaces in your code. To have PyCharm automatically insert a space at a location, select the checkbox next to this location in the list. The results are displayed in the Preview pane.
Blank lines
Use this tab to define where and how many blank lines you want PyCharm to retain and insert in your code after reformatting. For each type of location, specify the number of blank lines to be inserted. The results are displayed in the Preview pane.
Item | Description |
---|---|
Keep Maximum Blank Lines | In this area, specify the number of blank lines to be kept after reformatting in the specified locations. |
Minimum Blank Lines | In the text boxes in this area, specify the number of blank lines to be present in the specified locations. |
This table lists actions to be performed when imports are optimized.
Item | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Sort import statements | Select or clear this checkbox to enable or disable sorting imports within individual import groups according to PEP 8. The following checkboxes affect the sorting order. | ||||||||||||||||||||
| |||||||||||||||||||||
Structure of "from" imports | |||||||||||||||||||||
Leave as is | If this checkbox is selected, the "from" imports won't be restructured. | ||||||||||||||||||||
Join imports with the same source | If this checkbox is selected, the "from" imports of the same source are combined.
| ||||||||||||||||||||
Always split imports | If this checkbox is selected, the "from" imports are always placed separately.
|
Other
Item | Description |
---|---|
Dict alignment | From the drop-down list, select the type of
|
Add line feed at the end of file | Select this checkbox to add line feed character at the end of file. |
Use continuation indent for | Select the Method call argument checkbox to use continuation indent for list of arguments and the Collections and comprehensions checkbox for multi-line collection literals and comprehensions. The value of the continuation indent is defined in the Tabs and Indents tab. If these checkboxes are not selected, then the indent value is used. |
Click this link to reveal the list of languages to be used as the base for the current language code style. Only the settings that are applicable to the current language are taken. All the other settings are not affected.
This link appears in the upper-right corner of the language-specific code style page, when applicable.
Click Reset to discard changes and return to the initial set of code style settings.