skip to navigation
skip to content

python-c 1.0

An alternative to python -c with much less typing, at the price of being dirtier.


An alternative to python -c with much less typing, at the price of being dirtier.


$ pip install python-c


If you have a file named with:

def quite():
   return 5
def loud():
    print 'hello'
def double(arg):
   return arg*2

Instead of:

$ python -c "import foo; foo.loud();"

You can now write:

$ python-c foo 'loud()'

You can load multiple files:

$ python-c foo,foo2 'loud()'

or directories:

$ python-c ./,./dir1,./dir2/ 'loud()'

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()'


Printing is handled for you:

$ python-c foo 'quite()'

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)'

You can execute arbitrary code in your single line:

$ python-c foo '"hot" if double(2) == 4 else "cold"'

This includes printing:

$ python-c 'print "double {} is {}".format(2, double(2))'
double 2 is 4


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.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’.

File Type Py Version Uploaded on Size
python-c-1.0.tar.gz (md5) Source 2017-06-17 3KB