Enables one to write Python one-liners.
Project description
Installation
To install from Pypi:
pip install py1cmd
Introduction
One should use the right tool for the right task. But Learning 300 tools is counterproductive, so one needs a fallback. To be generic enough that fallback must be scriptable. So we have AWK, Perl, Sed, TCL… and their read-only languages.
Enters py1, it aims at being a “Python AWK”. It can be used in two modes.
In both modes indents and dedents can be replaced with “{{” and “}}”, line feeds can be replaced with “;”.
Minimalist
To use this mode:
py1 "python_one_liner"
“{{” and “}}” can be used instead of indent/dedent, and “;” instead of line feed eg:
py1 "import sys ; if True: {{ print(sys.version) }}"
AWK-like
In this mode, py1 generates a python script wrapping your code and defining a convenient set of 1&2-letters variables and functions.
To use this mode, pass any of --begin/-b, --each-line/-l, --end/-e.
For example, to count lines matching '$a*^':
py1 --begin "count=0" --each-line "if M('$a*^'): count += 1"
--end "P(count)"
To learn more you can read the list of one letter functions and variables or just look at examples and figure out the rest.
Sustainable hacking
If you find yourself writing a longer than readable one-liner, you can transform it in regular Python code, easily refactored for later reuse. Just add --dump-code.
More!
Interested? You can install with:
pip install py1cmd
To learn more you can read the list of one letter functions and variables or just look at examples and figure out the rest.
How to contribute?
I wrote some advices and documented the internals here. Feel free to just contact unbrice.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.