Last active
September 13, 2017 17:40
-
-
Save stefco/09448298455df0a389746110eb5a0bf5 to your computer and use it in GitHub Desktop.
Run indented python code in a shell function so that things look nice and readable.
This file contains 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
# a template that does nothing. the actual python script is 100% indented. | |
foo() { | |
python -c 'import textwrap; exec(textwrap.dedent(r""" | |
import sys | |
# remove the first argument, since it will just be '-c' | |
sys.argv.pop(0) | |
# put your actual code below | |
"""+" "*4))' "$@" | |
} | |
# an example that does something | |
foo() { | |
python -c 'import textwrap; exec(textwrap.dedent(r""" | |
import sys, os | |
# remove the first argument, since it will just be '-c' | |
sys.argv.pop(0) | |
sys.stdout.write("this is a test of dedenting a script.") | |
for arg in sys.argv: | |
sys.stdout.write("\nargument passed: " + arg) | |
sys.stdout.write("\ncwd: " + os.getcwd()) | |
"""+" "*4))' "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment