skip to navigation
skip to content

Not Logged In

py1cmd 0.1

Enables one to write Python one-liners.

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.

 
File Type Py Version Uploaded on Size
py1cmd-0.1-py3-none-any.whl (md5) Python Wheel 3.4 2014-08-10 15KB
py1cmd-0.1.tar.gz (md5) Source 2014-08-10 17KB
  • Downloads (All Versions):
  • 7 downloads in the last day
  • 30 downloads in the last week
  • 133 downloads in the last month