pype

Crates.iopype
lib.rspype
version0.2.1
sourcesrc
created_at2023-02-23 09:52:03.59708
updated_at2023-03-07 20:31:40.015251
descriptionPython oneliner helper
homepage
repository
max_upload_size
id792505
size56,258
Naoya Yamashita (conao3)

documentation

README

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

Commit count: 0

cargo fmt