9

Possible Duplicate:
HOWTO: Fix Python Indentation

I have Python library where only 2 spaces indentation was used. I need automated way to convert all files to 4 spaces indentation. Is there any tool/script/editor for that?

Plz don't suggest Emacs.

Community
  • 1
  • 1
Pavel Paulau
  • 786
  • 2
  • 7
  • 19
  • 3
    What OS are you on? You could do it with Python, but this sort of thing is usually done with a script in your relevant cli. – Silas Ray Jul 27 '12 at 21:11
  • 1
    http://stackoverflow.com/questions/2625294/how-do-i-autoformat-some-python-code-to-be-correctly-formatted – lollo Jul 27 '12 at 21:13
  • Please check this thread http://stackoverflow.com/questions/1024435/howto-fix-python-indentation. – Maksim Skurydzin Jul 27 '12 at 21:15
  • You also can replace 2-space with 4-space. https://www.reddit.com/r/vscode/comments/c7rs4c/comment/eshi16g/?utm_source=share&utm_medium=web2x&context=3 – RyanC Dec 04 '21 at 00:08

1 Answers1

14

Try the reindent script by Tim Peters, it was designed specifically for converting Python files to 4-space indentation.

For users with Python 3.9 or newer consider using reindent latest version.

Garrett
  • 319
  • 1
  • 13
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306