python-c
An alternative to python -c with much less typing, at the price of being dirtier.
Installation:
$ pip install python-c
Usage
If you have a file named foo.py with:
def quite():
return 5
def loud():
print 'hello'
def double(arg):
return arg*2
Instead of:
$ python -c "import foo; foo.loud();" hello
You can now write:
$ python-c foo 'loud()' hello
You can load multiple files:
$ python-c foo,foo2 'loud()' hello
or directories:
$ python-c ./,./dir1,./dir2/test.py 'loud()' hello
In cases where it works (e.g clashes between files are benign), you can minimize your typing and omit the first argument, the current directory is then loaded by default:
$ python-c 'loud()' hello
Printing
Printing is handled for you:
$ python-c foo 'quite()' 5
The result of the call (if any) is printed, even though the function does not call ‘print’.
More examples
You can pass arguments to your functions:
$ python-c foo 'double(2)' 4
You can execute arbitrary code in your single line:
$ python-c foo '"hot" if double(2) == 4 else "cold"' hot
This includes printing:
$ python-c foo.py 'print "double {} is {}".format(2, double(2))'
double 2 is 4
Rationale
Time is our most valuable non-possesion. The python interpreter must be clean and unambiguous, including the way it handls it’s option ‘-c’. However, more often than not, I will accept being dirty (e.g live with benign clashes between files) and simply type python-c ‘test23()’ as opposed to the double as long python -c ‘import foo.py; foo.test23()’. Such dirty functionality should not be built into the interpreter, hence python-c: the tool playfully indicates its motivation by saving you from typing a space between ‘python’ and ‘-c’.
Metadata
Release files for python-c 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-c-1.0.tar.gz | 3.2 kB | Without provenance | Details for python-c-1.0.tar.gz |
Release files / python-c-1.0.tar.gz
| Download URL | python-c-1.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b3c15aad2fba5a1c61e67ad7bb41efdb1e949ce9c08e69ca0d6643ecf066feb
|
|
BLAKE2b-256 checksum How to use checksums |
a6ae59c8ef092cbab8bebad5ddd48e0935981a155fb871f2a1e539be7568cfef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for python-c 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.