3 unstable releases
0.2.1 | Mar 7, 2023 |
---|---|
0.2.0 | Mar 7, 2023 |
0.1.0 | Feb 23, 2023 |
#42 in #cat
38KB
935 lines
rust-pype
Python one-liner helper written in Rust.
Install
cargo install pype
Usage
stdin is opened as f
.
Prepare sample1
file.
cat > sample1
1
2
3
-e option
Execute specified python code.
$ cat sample1 | pype -e 'print(f.read())' | python
1
2
3
$ cat sample1 | pype -e 'print(f.read().splitlines())' | python
['1', '2', '3']
-n option
Execute specified python code per line. You can access via line
variable to each line.
$ cat sample1 | pype -ne 'print("- " + line)' | python
- 1
- 2
- 3
$ cat sample1 | pype -ne 'print("- " + line + "$")' | python
- 1
$- 2
$- 3
-l option
Available when -n
is specified. Removes trailing newlines from the input and adds newlines to print
.
$ cat sample1 | pype -nle 'print("- " + line)' | python
- 1
- 2
- 3
$ cat sample1 | pype -nle 'print("- " + line + "$")' | python
- 1$
- 2$
- 3$
-m option
Import specified module before executing python code.
cat sample1 | pype -m datetime -nle 'print(f"- {line}:", (datetime.date.today() + datetime.timedelta(days=int(line))))' | python
- 1: 2023-03-09
- 2: 2023-03-10
- 3: 2023-03-11
License
Apache License 2.0
Dependencies
~3–12MB
~145K SLoC