If I open an existing project into PyCharm that used tabs instead of spaces can I format all of these files within PyCharm or do I need to manually update all of them?
Asked
Active
Viewed 715 times
1
-
I can't flag this as a duplicate of https://stackoverflow.com/questions/11816147/pycharm-convert-tabs-to-spaces-automatically because I still don't have the reputation but I believe this is what you're after. – goosfraba Oct 24 '17 at 18:03
3 Answers
2
You can, assuming you have PyCharm set to automatically produce spaces instead of tabs (which is default, as far as I know).
In the menu:
Code -> Reformat Code
with the top-level folder selected.

Spaceman1701
- 413
- 5
- 13
0
Just treat it like a text file and replace the tabs:
with open('example.py') as infile:
lines = infile.readlines()
lines = [line.replace('\t', ' ') for line in lines]
with open('example.py', 'w') as outfile:
outfile.writelines(lines)

Evan Nowak
- 895
- 4
- 8
0
Try: Edit -> Convert Indents -> To Spaces
There are also some quick ways to do this from a UNIX shell.

viddik13
- 5,930
- 2
- 14
- 21

Andrew Schenck
- 19
- 4