No project description provided
Project description
Pypthon
Pipes for python3 to be used in shell
Setup
pip install -U pypthon
Usage
pyp 'Pypthon command'
If pypthon is not in your path, you must invoke via
python3 -m pypthon 'Pypthon command
To see the python code being generated, use the --show-python
flag:
pyp --show-python 'Python command'
A Pypthon command consists of the following
source | piped function | piped function | piped function
The source must be any python expression. To have the source be an external command being piped into Pypthon, use stdin
.
Piped functions
Piped functions are any python functions which take the previous value as their last argument. In the example pypthon code,
[2, 1, 3] | sorted | print "Sorted" "list:"
sorted
takes in the iterable [2, 1, 3]
as its last parameter and print
takes the sorted list as its last parameter. When passing other arguments to functions in Pypthon, one must use the space separated syntax. In our example, the strings "Sorted"
and "list:"
are passed as arguments to print
via the syntax of separating each argument with a space.
Sorted list: [1, 2, 3]
will be outputted by the above command.
Lambda expressions
In python, lambdas are of the following structure
lambda arg1, arg2: arg1 + arg2
In pypthon, lambda expressions do not need the lambda
keyword before the arguments. In the example,
['1.', '6.', '2.', '4.'] | map x: int(float(x)) | reduce x, y: x if x > y else y | print
map
converts the strings in the list into integers, and reduce
finds the maximum of the integers.
Environment
The environment is fully customizable with a .pypthonrc.py
. On startup, the pypthonrc will be imported, giving the pypthon command access to custom functions. If you feel like you have general functions that can be used by other pypthon users, do not hesitate to send a pull request to add your customizations to the standard environment as it is still growing. It is advisable to not include heavy imports such as numpy
to the pypthonrc as the startup time will be negatively impacted for each invocation of pypthon.
The documentation for the standard environment is at docs/example.md.
Other
This project idea was heavily inspired by the pied piper package which only works with Python 2 and has virtually disappeared.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pypthon-0.2.0.tar.gz
.
File metadata
- Download URL: pypthon-0.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3cedf9b61e3bb91a880204f37b19e68245d31be15b60ac33db8a65d9a460e32 |
|
MD5 | 02d75be3c610ae93af9f8b3782cc185f |
|
BLAKE2b-256 | 4f52fa78ae850d146be01ec14d7794b1dba59705d165ef4680744cbe00638bcb |
File details
Details for the file pypthon-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pypthon-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca6d128c1a45706333e585f490258f88fed3b0264ddb12fe3d78dad334030f3 |
|
MD5 | 86e7057463e2959795e95782955c0baf |
|
BLAKE2b-256 | ff381d1a7b6208cc213ae29fe782225e0f08cccf176823310f4e73b5cda96fa1 |