Clean Python code with Sublime

191 views Asked by At

I would like to clean a long Python code:

  • indentations (sometimes I used 2 whitespaces, sometimes 4 whitespaces), I would like to have 4 everywhre

  • sometimes I have some unwanted whitespaces at the end of a line like this :
    print "hello" <EOL>

Using Sublime Text's Edit > Line > Reindent just doesn't work for Python. Example: doing it on:

for i in range(27):
    if a == b:
        print a
print "finished"

would give

for i in range(27):
    if a == b:
        print a
        print "finished"

which is not the same thing!

What do you use to beautify your Python code?

1

There are 1 answers

0
sachin saxena On

you can use autopep8 to do this : https://pypi.python.org/pypi/autopep8/

$ autopep8 --in-place --aggressive <filename>