Skip to content

Instantly share code, notes, and snippets.

@pktCoder
Created August 18, 2015 00:40
Show Gist options
  • Save pktCoder/f13465b3936ddcbfa656 to your computer and use it in GitHub Desktop.
Save pktCoder/f13465b3936ddcbfa656 to your computer and use it in GitHub Desktop.
#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 ++; }
}
}
@pktCoder
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment