You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyCharm has built-in support for converting tab indentation to spaces
115
-
"under the hood" for Python code in order to conform to PEP 8.
116
-
So, you can type a tab character and PyCharm will automatically convert it to 4 spaces.
117
-
You can control the amount of spaces that PyCharm uses to replace one tab character
118
-
or you can decide to keep the tab character altogether and prevent automatic conversion.
114
+
IDEs typically let you control text indentation and whether you would like to use spaces or tab stops.
115
+
Such IDEs have built-in support for converting tab indentation to spaces "under the hood" for Python code in order to conform to PEP 8.
116
+
So, you can type a tab character and your IDE will automatically convert it to 4 spaces.
117
+
You can also control the amount of spaces that the IDE uses to replace one tab character or you can decide to keep the tab character altogether and prevent automatic conversion.
118
+
119
+
::: group-tab
120
+
121
+
### PyCharm
122
+
123
+
By default, PyCharm inserts spaces and uses 4 spaces per tab key.
119
124
You can modify these settings in PyCharm's `Settings`\>`Editor`\>`Code Style`\>`Python`.
120
125
121
-
{alt='Python code indentation settings in PyCharm' .image-with-shadow width="800px"}
126
+
{alt='Python code indentation settings in PyCharm' .image-with-shadow width="1000px"}
122
127
123
128
You can also tell the editor to show non-printable characters
124
129
if you are ever unsure what character exactly is being used
125
130
by selecting `Settings` > `Editor` > `General` > `Appearance` then checking "Show whitespaces" option.
126
131
127
132
{alt='Python code whitespace settings in PyCharm' .image-with-shadow width="800px"}
128
133
129
-
There are more complex rules on indenting single units of code that continue over several lines,
130
-
e.g. function, list or dictionary definitions can all take more than one line.
131
-
The preferred way of wrapping such long lines is
132
-
by using Python's implied line continuation inside delimiters such as
133
-
parentheses (`()`),
134
-
brackets (`[]`)
135
-
and braces (`{}`),
136
-
or a hanging indent.
134
+
### VS Code
135
+
136
+
By default, VS Code inserts spaces and uses 4 spaces per tab key.
137
+
You can modify these settings in VS Code's user or workspace settings (`File -> Settings` then search for `tabSize` and enter the value you want).
138
+
You also need to make sure `Editor: Detect Indentation` field is checked.
139
+
140
+
{alt='Python code whitespace settings in VC Code' .image-with-shadow width="1000px"}
141
+
142
+
If you are editing `settings.json` file manually - these are the 2 properties you need to set:
143
+
144
+
```yaml
145
+
"editor.insertSpaces": true,
146
+
"editor.tabSize": 4,
147
+
```
148
+
149
+
:::
150
+
151
+
There are more complex rules on indenting single units of code that continue over several lines, e.g. function, list or dictionary definitions can all take more than one line.
152
+
The preferred way of wrapping such long lines is by using Python's implied line continuation inside delimiters such as parentheses (`()`), brackets (`[]`) and braces (`{}`), or a hanging indent.
137
153
138
154
```python
139
155
# Add an extra level of indentation (extra 4 spaces) to distinguish arguments from the rest of the code that follows
@@ -168,8 +184,7 @@ a_long_list2 = [
168
184
]
169
185
```
170
186
171
-
More details on good and bad practices for continuation lines can be found in
172
-
[PEP 8 guideline on indentation](https://www.python.org/dev/peps/pep-0008/#indentation).
187
+
More details on good and bad practices for continuation lines can be found in [PEP 8 guideline on indentation](https://www.python.org/dev/peps/pep-0008/#indentation).
173
188
174
189
### Maximum Line Length
175
190
@@ -462,8 +477,7 @@ Fix the discovered inconsistencies and commit them to the feature branch.
462
477
463
478
## Solution
464
479
465
-
Modify `inflammation-analysis.py` from PyCharm,
466
-
which is helpfully marking inconsistencies with coding guidelines by underlying them.
480
+
Modify `inflammation-analysis.py` from your IDE, which is helpfully marking inconsistencies with coding guidelines by underlying them.
467
481
There are a few things to fix in `inflammation-analysis.py`, for example:
468
482
469
483
1. Line 30 in `inflammation-analysis.py` is too long and not very readable.
@@ -657,13 +671,10 @@ Functions:
657
671
...
658
672
```
659
673
660
-
The docstring for a function or a module
661
-
is returned when calling the `help` function and passing its name -
662
-
for example from the interactive Python console/terminal available from the command line
663
-
or when rendering code documentation online
664
-
(e.g. see [Python documentation](https://docs.python.org/3.11/library/index.html)).
665
-
PyCharm also displays the docstring for a function/module
666
-
in a little help popup window when using tab-completion.
674
+
The docstring for a function or a module is returned when calling the `help` function and passing its name -
675
+
for example from the interactive Python console/terminal available from the command line or when rendering code documentation online (e.g. see [Python documentation](https://docs.python.org/3.11/library/index.html)).
676
+
677
+
Your IDE will also display the docstring for a function/module in a little help popup window when using tab-completion or when hovering your mouse over the function/module name.
0 commit comments