Created
August 18, 2015 00:40
-
-
Save pktCoder/f13465b3936ddcbfa656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this little script will put the right identation for python script if was ill-formated (due to pasting code to web page, say) | |
#perl identPython.pl < ill_formated_python_code > good_python_code | |
$level = 0; | |
while (<STDIN>) { | |
chomp($line = $_); | |
$line =~ s/^\s*//; | |
if ($line eq "") { | |
$level = 0; | |
print "\n"; | |
} else { | |
if ($line =~ /^else:/) { | |
$level --; | |
} | |
print "\t"x$level; | |
print $line,"\n"; | |
if ($line =~ /\:$/) { $level ++; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did this not realizing there is such a tool written in python already! Needed this to run a python script copied from pdf file.