Skip to content

Instantly share code, notes, and snippets.

@leifp
Created December 16, 2024 03:02
Show Gist options
  • Select an option

  • Save leifp/9aba832e0866453d3c489fb7e5d36be2 to your computer and use it in GitHub Desktop.

Select an option

Save leifp/9aba832e0866453d3c489fb7e5d36be2 to your computer and use it in GitHub Desktop.
Perfect Python Readability Enhancer

Python readability enhancer

all prose is written in "space case" (all lowercase, words separated by spaces) for clarity.

inspired by projects like bython and pygyat that attempt to enhance the readability of the python language, i've created a tool to display your python files in a more readable format. i've only tested it on ubuntu x86_64, but it should work on all known or imagined os and cpu combinations. here's how i evolved your new favorite tool.

dict access should use braces to remind you it's a dict. i was inspired here by the famously readable language perl.

tr '[]' '{}'

but now we used brackets, let's replace them with parens

tr '[]{}' '{}()'

and we just used parens, let's replace them with square brackets

tr '[]{}()' '{}()[]'

let's replace colons with semicolons to make things more comfortable for programmers coming from other languages

tr '[]{}():' '{}()[];'

we just used semicolons, technically you can have them in python, so replace with colons

tr '[]{}():;' '{}()[];:'

it's annoying that we can't use keywords as variable names, let's uppercase them. this also makes them easy to spot and gives the language a nice FORTRAN/COBOL retro flair. i did this with a perl one-liner because of misanthropy.

tr '[]{}():;' '{}()[];:' | perl -ne 'my @kws = qw/and as assert break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield/; for my $i (0 .. $#kws) { my $kw = $kws[$i]; my $repl = uc($kw); s/\b$kw\b/$repl/;} print'

and there you have it, the perfect python readability enhancer. save it to an executable file, or for maximum productivity just keep the whole thing in the clipboard so that you can paste it into your command line with a single click of the mouse.

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